Skip to content
Snippets Groups Projects
Commit f8f9cd0f authored by Allan Blanchard's avatar Allan Blanchard
Browse files

[parser] Narrow froms in case of inclusion

parent a0ada244
No related branches found
No related tags found
No related merge requests found
...@@ -116,16 +116,16 @@ ...@@ -116,16 +116,16 @@
let f ds d = if List.exists (is_same_lexpr d) ds then ds else d :: ds in let f ds d = if List.exists (is_same_lexpr d) ds then ds else d :: ds in
l, From(List.(rev (fold_left f [] ds))) l, From(List.(rev (fold_left f [] ds)))
let concat_froms a1 a2 = let concat_froms cura newa =
let compare_pair (b1,_) (b2,_) = is_same_lexpr b1 b2 in let compare_pair (curb,_) (newb,_) = is_same_lexpr curb newb in
(* NB: the following has an horrible complexity, but the order of (* NB: the following has an horrible complexity, but the order of
clauses in the input is preserved. *) clauses in the input is preserved. *)
let concat_one acc (l, f2) = let concat_one acc (l, newf) =
let (_, f2) as p = filter_from l f2 in let (_, newf) as p = filter_from l newf in
try try
let (_,f1) = List.find (compare_pair p) acc let (_,curf) = List.find (compare_pair p) acc
in in
match (f1, f2) with match (curf, newf) with
| _,FromAny -> | _,FromAny ->
(* the new fundeps does not give more information than the one (* the new fundeps does not give more information than the one
which is already present. Just ignore it. which is already present. Just ignore it.
...@@ -138,12 +138,15 @@ ...@@ -138,12 +138,15 @@
that we get the exact same clause if we try to that we get the exact same clause if we try to
link the original contract with its pretty-printed version. *) link the original contract with its pretty-printed version. *)
Extlib.replace compare_pair p acc Extlib.replace compare_pair p acc
| From _, From _ -> | From curl, From newl ->
(* we keep the two functional dependencies, let incl l lin =
as they have to be proved separately. *) List.(for_all (fun e -> exists (is_same_lexpr e) lin) l)
acc @ [p] in
if incl curl newl then acc
else if incl newl curl then Extlib.replace compare_pair p acc
else acc @ [p]
with Not_found -> acc @ [p] with Not_found -> acc @ [p]
in List.fold_left concat_one a1 a2 in List.fold_left concat_one cura newa
let concat_allocation fa1 fa2 = let concat_allocation fa1 fa2 =
match fa1,fa2 with match fa1,fa2 with
......
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
int choose1(int min, int max); int choose1(int min, int max);
/*@ assigns \result; /*@ assigns \result;
assigns \result \from min, max; assigns \result \from min, max; */
assigns \result \from min, max;
*/
int choose2(int min, int max); int choose2(int min, int max);
int main(void) int main(void)
......
...@@ -2,13 +2,11 @@ ...@@ -2,13 +2,11 @@
[rte] annotating function main [rte] annotating function main
/* Generated by Frama-C */ /* Generated by Frama-C */
/*@ assigns *p; /*@ assigns *p;
assigns *p \from x;
assigns *p \from \nothing; */ assigns *p \from \nothing; */
int f(int *p, int x); int f(int *p, int x);
/*@ assigns *p; /*@ assigns *p;
assigns *p \from \nothing; assigns *p \from \nothing; */
assigns *p \from x; */
int g(int *p, int x); int g(int *p, int x);
int main(void) int main(void)
......
int a, b, c, d, e; int a, b, c, d, e;
// Reminder: assigns are visited in reverse
/*@ assigns a; /*@ assigns a;
assigns a \from a, a, b, c, c; assigns a \from a, a, b, c, c; // more precise so replace the next one
assigns a \from c, b, d, e, a; assigns a \from c, b, d, e, a;
assigns a; assigns a;
assigns b \from a, e, b, d, c; assigns b \from a, e, b, d, c; // is ignored because the next one is more precise
assigns c \from c, c, c, c, c; assigns b \from a, e;
assigns c \from c, c, c, c, c; // both are kept (no inclusion)
assigns c \from d;
*/ */
void function(void) void function(void)
{ {
......
...@@ -7,9 +7,9 @@ int d; ...@@ -7,9 +7,9 @@ int d;
int e; int e;
/*@ assigns a, b, c; /*@ assigns a, b, c;
assigns a \from a, b, c; assigns a \from a, b, c;
assigns a \from c, b, d, e, a; assigns b \from a, e;
assigns b \from a, e, b, d, c;
assigns c \from c; assigns c \from c;
assigns c \from d;
*/ */
void function(void) void function(void)
{ {
......
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