Skip to content
Snippets Groups Projects
Commit 1b9588f9 authored by Kostyantyn Vorobyov's avatar Kostyantyn Vorobyov
Browse files

Replace keep_initialiser mutable variable (which used to decide to keep

global initialisers or not) with a boolean switch called
is_initialiser used to detect and filter out compound initialisers
and update [global_vars] mapping
parent ae805538
No related branches found
No related tags found
No related merge requests found
...@@ -83,7 +83,9 @@ class e_acsl_visitor prj generate = object (self) ...@@ -83,7 +83,9 @@ class e_acsl_visitor prj generate = object (self)
[None] while the global corresponding to this fundec has not been [None] while the global corresponding to this fundec has not been
visited *) visited *)
val mutable keep_initializer = None val mutable is_initializer = false
(* Global flag set to a [true] value if a currently visited node
belongs to a global initialiser and set to [false] otherwise *)
val global_vars: init option Varinfo.Hashtbl.t = Varinfo.Hashtbl.create 7 val global_vars: init option Varinfo.Hashtbl.t = Varinfo.Hashtbl.create 7
(* A hashtable mapping global variables (as Cil_type.varinfo) to their (* A hashtable mapping global variables (as Cil_type.varinfo) to their
...@@ -335,22 +337,29 @@ you must call function `%s' and `__e_acsl_memory_clean by yourself.@]" ...@@ -335,22 +337,29 @@ you must call function `%s' and `__e_acsl_memory_clean by yourself.@]"
in in
(match g with (match g with
| GVar(vi, _, _) | GVarDecl(vi, _) -> | GVar(vi, _, _) | GVarDecl(vi, _) ->
Varinfo.Hashtbl.replace global_vars vi None Varinfo.Hashtbl.add global_vars vi None
| _ -> ()); | _ -> ());
if generate then Cil.DoChildrenPost(fun g -> List.iter do_it g; g) if generate then Cil.DoChildrenPost(fun g -> List.iter do_it g; g)
else Cil.DoChildren else Cil.DoChildren
method !vinit vi _off _i = (* Process global variable initialisers and add mappings from global
variables to their initialisers to [global_vars]. Note that [add] method
should be used instead [replace]. This is because a single variable can
be assicoated with multiple initialisers and all of them need to be
captured. Also note that the below function captures only [SingleInit]s.
All compound initialisers (which contain single ones) are unrapped and
thrown away. *)
method !vinit vi _off _i =
if generate then if generate then
if Mmodel_analysis.must_model_vi vi then begin if Mmodel_analysis.must_model_vi vi then begin
keep_initializer <- Some true; is_initializer <- true;
Cil.DoChildrenPost Cil.DoChildrenPost
(fun i -> (fun i ->
(match keep_initializer with (match is_initializer with
| Some false -> Varinfo.Hashtbl.replace global_vars vi (Some i) | true -> Varinfo.Hashtbl.add global_vars vi (Some i)
| Some true | None -> ()); | false-> ());
keep_initializer <- None; is_initializer <- false;
i) i)
end else end else
Cil.JustCopy Cil.JustCopy
else else
...@@ -704,20 +713,9 @@ you must call function `%s' and `__e_acsl_memory_clean by yourself.@]" ...@@ -704,20 +713,9 @@ you must call function `%s' and `__e_acsl_memory_clean by yourself.@]"
in in
if generate then Cil.DoChildrenPost handle_memory else Cil.DoChildren if generate then Cil.DoChildrenPost handle_memory else Cil.DoChildren
method !vexpr exp = method !vexpr _ =
if generate then if generate then
match keep_initializer with Cil.DoChildren
| Some false -> Cil.JustCopy
| Some true ->
let keep = match exp.enode with Const(CStr _) -> false | _ -> true in
keep_initializer <- Some keep;
if keep then Cil.DoChildren else Cil.JustCopy
| None ->
Cil.DoChildrenPost
(fun e ->
let e, env = self#literal_string !function_env e in
function_env := env;
e)
else else
Cil.SkipChildren Cil.SkipChildren
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment