-2

i'm actually on writing a personnal Frama-C plugin wich contains those four files :

analyseTU_core.ml

module Options = AnalyseTU_options

open Cil_types

let rec member x list1 = match list1 with 
    []->false
    |hd :: tl -> if hd = x then true else member x tl

let rec sandr list2 result= match list2 with
    []-> Format.fprintf out "job termine"
    |hd :: tl -> if member hd result = false then begin result::hd ; Format.fprintf out hd; sandr tl result end
        else sandr tl result

class print_analyse out = object 
    inherit Visitor.frama_c_inplace

method vstmt s=
    let listing =[] in
    let impacted = !Db.Impact.compute_pragmas in
    let impacted2= impacted.Stmt.loc in
    sandr impacted2 listing;
    Cil.DoChildren
   end

and :

analyseTU_register.ml

open AnalyseTU_options
open AnalyseTU_core

let run () =
    if Enabled.get () then
    let filename=OutputFile.get () in
    let chan = open_out filename in
    let fmt = Format.formatter_of_out_channel chan in
    Visitor.visitFramacFileSameGlobals (new print_analyse fmt) (Ast.get ());
    close_out chan

let () = Db.Main.extend run

and :

analyseTU_options.ml

module Self = Plugin.register 
(struct
  let name = "analyse TU"
  let shortname = "TU"
  let help = "impacted statements computation from a source code modification and display consequently unit tests to be run in an output file"
end)

module Enabled = Self.False 
(struct
  let optilon_name = "-TU"
  let help = "when on (off by default), give the unit tests to be run"
end)

module OutputFile = Self.String 
(struct
  let option_name = "-TU-output"
  let default = "TUresults.txt"
  let arg_name = "output-file"
  let help = "name of the output file"
end)

and finally the makefile :

FRAMAC_SHARE := $(shell frama-c -print-path)
FRAMAC_LIBDIR := $(shell frama-c -print-libpath)
PLUGIN_NAME = analyseTU
PLUGIN_CMO = analyseTU_options analyseTU_core analyseTU_register
include $(FRAMAC_SHARE)/Makefile.dynamic

so, when i compile it with the make command, i'm actually getting :

FILE "analyseTU_core.ml", line 9 :
Error: unbound value out
make : *** [analyseTU_core.cmo] erreur 2

i was so thinking that it was due to the fact 'out' is unknown to the compiler, and i remplaced 'out' by 'chan'. I was getting by the way the same error.

The fact that 'out' is not defined in the code of the developer's guide's tutorial makes finally me think this error is not what i think it is...

Have you ever encountered it? if yes, how did you deal with it?

nlucaroni
  • 47,556
  • 6
  • 64
  • 86
evoliptic
  • 333
  • 2
  • 11
  • 1
    Simply out is not defined. Before jumping into such complex applications, you should play around more simple OCaml examples. – camlspotter Sep 18 '14 at 09:43

1 Answers1

1

As said by camlspotter, the error indeed simply means that out is not defined in the environment. You either have to provide it as argument of your method, or define a global out formatter somewhere. Another possibility is to use printf instead of fprintf, as printf outputs on stdout, hence does not need a formatter as argument. Finally, in the specific context of Frama-C, you should consider using Analyse_TU_option.Self.feedback or one of its companions (result, debug, ...) for your outputs.

Virgile
  • 9,724
  • 18
  • 42