我实际上在编写一个包含这四个文件的个人Frama-C插件:
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
和:
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
和:
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)
最后是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
所以,当我使用make命令编译它时,我实际上得到了:
FILE "analyseTU_core.ml", line 9 :
Error: unbound value out
make : *** [analyseTU_core.cmo] erreur 2
我是这么想的,这是因为事实' out'编译器不知道,我重新推出了#39; out' by'陈'顺便说一下,我遇到了同样的错误。
' out'未在开发人员指南的代码中定义,最后我认为这个错误不是我认为的错误......
你有过见过吗?如果是的话,你是怎么处理它的?答案 0 :(得分:1)
正如camlspotter所说,错误确实只是意味着out
未在环境中定义。您必须将其作为方法的参数提供,或者在某处定义全局out
格式化程序。另一种可能性是使用printf
代替fprintf
,printf
作为stdout
输出,因此不需要格式化程序作为参数。最后,在Frama-C的特定上下文中,您应该考虑使用Analyse_TU_option.Self.feedback
或其中一个同伴(result
,debug
,...)作为输出。