繁体   English   中英

使用Frama-C脚本打印ACSL注释

[英]Print ACSL Annotations with Frama-C script

我正在学习如何开发Frama-C插件。 在阅读Frama-C Developer手册并执行CFG插件示例后,我尝试执行一个基本脚本,在C文件中打印所有注释。 我想出了这个:

open Cil_types

class print_annot out = object
    inherit Visitor.frama_c_inplace

method vstmt_aux s =
let annots = Annotations.code_annot s in
let anleng = List.length annots in
if anleng <= 0 then Format.fprintf out "Empty List\n"
  else
  Format.fprintf out "Number of Annotations: %d\n" anleng;
  List.iter (fun annot -> Format.fprintf out " -> s%d\n" annot.annot_id) annots;
  Cil.DoChildren
end

let run () =
let chan = open_out "annots.out" in
let fmt = Format.formatter_of_out_channel chan in
Visitor.visitFramacFileSameGlobals (new print_annot fmt) (Ast.get());
close_out chan

let () = Db.Main.extend run

即使输入文件具有ACSL注释并且从不打印注释id,它总是表示列表为空。 我究竟做错了什么?

编辑:

以下代码的示例:

 /*@ requires y >= 0;
 @ ensures \result >= 0;
 */

 int g(int y){
int x=0;

if(y>0){
    x=100;
    x=x+50;
    x=x-100;
}else{
    x = x - 150;
    x=x-100;
    x=x+100;
}
return x;
    }

    void main(){
int a = g(0);

 }

并调用frama-c:

 $ frama-c -load-script annot_script.ml condi.c

给出以下输出:

 Empty List
 Empty List
 Empty List
 Empty List
 Empty List
 Empty List
 Empty List
 Empty List
 Empty List
 Empty List
 Empty List

在您的示例中,没有任何注释附加到语句。 requiresensures是功能合同的一部分,并附加到功能g ,而不是任何g陈述。

附加到语句的注释例如是/*@ assert x == 150; */ /*@ assert x == 150; */x=x+50;

如果我修改condi.c来插入这个断言,那么使用相同的命令行,我得到:

Empty List
Empty List
Empty List
Empty List
Number of Annotations: 1
 -> s1
Empty List
Empty List
Empty List
Empty List
Empty List
Empty List
Empty List

您的脚本似乎正在按预期工作,其值为“expected”,对应于打印附加到语句的注释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM