[英]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
在您的示例中,沒有任何注釋附加到語句。 requires
和ensures
是功能合同的一部分,並附加到功能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.