Skip to content

Commit 3149231

Browse files
committed
CHC: add global-variable attributes
1 parent 28f8cd9 commit 3149231

File tree

7 files changed

+235
-145
lines changed

7 files changed

+235
-145
lines changed

CodeHawk/CHC/cchanalyze/cCHFunctionTranslator.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ open CCHBasicTypes
4545
open CCHContext
4646
open CCHFileContract
4747
open CCHFileEnvironment
48-
open CCHLibTypes
4948
open CCHTypesTransformer
5049
open CCHTypesUtil
5150

@@ -113,17 +112,17 @@ object (self)
113112
| _ -> acc) [] formals
114113

115114
method private assert_global_values globals =
116-
let contractgvars = file_contract#get_global_variables in
115+
let contractgvars = file_contract#get_globalvar_contracts in
117116
let table = H.create 3 in
118117
let tmpProvider = (fun () -> env#mk_num_temp) in
119118
let cstProvider = (fun (n:numerical_t) -> env#mk_num_constant n) in
120-
let _ = List.iter (fun gv -> H.add table gv.cgv_name gv) contractgvars in
119+
let _ = List.iter (fun gv -> H.add table gv#get_name gv) contractgvars in
121120
let _ = env#start_transaction in
122121
let ccmds =
123122
List.fold_left (fun acc (vname, _, _, vInit) ->
124123
if H.mem table vname then
125124
let gcvar = H.find table vname in
126-
match gcvar.cgv_value with
125+
match gcvar#get_value with
127126
| Some i ->
128127
let x = XOp (XEq, [XVar vInit ; int_constant_expr i]) in
129128
let (code,bExp) = xpr2boolexpr tmpProvider cstProvider x in
@@ -142,10 +141,10 @@ object (self)
142141
let globalvars =
143142
List.map f.sdecls#get_varinfo_by_vid (get_block_variables f.sbody) in
144143
let globalvars = List.filter (fun vinfo -> vinfo.vglob) globalvars in
145-
let contractglobals = file_contract#get_global_variables in
144+
let contractglobals = file_contract#get_globalvar_contracts in
146145
let contractglobals =
147146
List.map (fun v ->
148-
file_environment#get_globalvar_by_name v.cgv_name) contractglobals in
147+
file_environment#get_globalvar_by_name v#get_name) contractglobals in
149148
let globalvars =
150149
List.fold_left (fun acc v ->
151150
if List.exists (fun vv ->
@@ -276,10 +275,10 @@ let get_valueset_preamble (env:c_environment_int) fundec =
276275
List.map (fun v ->
277276
(false,env#mk_formal_ptr_base_variable v NUM_VAR_TYPE)) pointerFormals in
278277
let contractglobals =
279-
List.filter (fun v -> v.cgv_notnull) file_contract#get_global_variables in
278+
List.filter (fun v -> v#is_not_null) file_contract#get_globalvar_contracts in
280279
let contractglobals =
281280
List.map (fun v ->
282-
file_environment#get_globalvar_by_name v.cgv_name) contractglobals in
281+
file_environment#get_globalvar_by_name v#get_name) contractglobals in
283282
let contractglobals =
284283
List.map (fun v ->
285284
(true,env#mk_program_var v NoOffset NUM_VAR_TYPE)) contractglobals in

CodeHawk/CHC/cchanalyze/cCHPOQuery.ml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ object (self)
434434
match facts with
435435
| [] ->
436436
begin
437-
self#set_diagnostic
437+
self#set_diagnostic_arg
438+
argindex
438439
("no invariant facts in proof obligation context");
439440
[]
440441
end
@@ -454,8 +455,9 @@ object (self)
454455
match vars with
455456
| [] ->
456457
begin
457-
self#set_diagnostic
458-
("no invariants found on variables that apply to proof obligation");
458+
self#set_diagnostic_arg
459+
argindex
460+
"no corresponding variables with non-relational facts";
459461
[]
460462
end
461463
| _ ->
@@ -470,7 +472,8 @@ object (self)
470472
match invs with
471473
| [] ->
472474
begin
473-
self#set_diagnostic
475+
self#set_diagnostic_arg
476+
argindex
474477
("none of the variables has associated invariants: "
475478
^ (p2s
476479
(pretty_print_list vars (fun v -> v#toPretty) "[" "," "]")));
@@ -1258,10 +1261,18 @@ object (self)
12581261
method get_num_value (e:exp) = get_num_value fenv e
12591262

12601263
method get_gv_lowerbound (name:string):int option =
1261-
file_contract#get_gv_lower_bound name
1264+
if file_contract#has_globalvar_contract name then
1265+
let gvar = file_contract#get_globalvar_contract name in
1266+
gvar#get_lower_bound
1267+
else
1268+
None
12621269

12631270
method get_gv_upperbound (name:string):int option =
1264-
file_contract#get_gv_upper_bound name
1271+
if file_contract#has_globalvar_contract name then
1272+
let gvar = file_contract#get_globalvar_contract name in
1273+
gvar#get_upper_bound
1274+
else
1275+
None
12651276

12661277
(* return a lower bound xpr *)
12671278
method get_lowerbound_xpr (arg:int) (e:exp):(xpr_t * int list) option =

0 commit comments

Comments
 (0)