Commit | Line | Data |
---|---|---|
f537ebc4 | 1 | (* |
17ba0788 C |
2 | * Copyright 2012, INRIA |
3 | * Julia Lawall, Gilles Muller | |
4 | * Copyright 2010-2011, INRIA, University of Copenhagen | |
f537ebc4 C |
5 | * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix |
6 | * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen | |
7 | * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix | |
8 | * This file is part of Coccinelle. | |
9 | * | |
10 | * Coccinelle is free software: you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation, according to version 2 of the License. | |
13 | * | |
14 | * Coccinelle is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>. | |
21 | * | |
22 | * The authors reserve the right to distribute this or future versions of | |
23 | * Coccinelle under other licenses. | |
24 | *) | |
25 | ||
26 | ||
951c7801 C |
27 | module Ast = Ast_cocci |
28 | module Past = Ast_popl | |
29 | ||
30 | (* --------------------------------------------------------------------- *) | |
31 | ||
32 | let rec fvs_sequence = function | |
33 | Past.Seq(elem,seq) -> | |
34 | Common.union_set (fvs_element elem) (fvs_sequence seq) | |
35 | | Past.Empty -> [] | |
36 | | Past.SExists(var,seq) -> failwith "not possible" | |
37 | ||
38 | and fvs_term = function | |
39 | Past.Atomic(term) -> Ast.get_fvs term | |
40 | | Past.IfThen(test,thn,(afvs,_,_,_)) -> | |
41 | Common.union_set afvs | |
42 | (Common.union_set (fvs_term test) (fvs_term thn)) | |
43 | | Past.TExists(var,term) -> failwith "not possible" | |
44 | ||
45 | and fvs_element = function | |
46 | Past.Term(term,_) -> fvs_term term | |
47 | | Past.Or(seq1,seq2) -> | |
48 | Common.union_set (fvs_sequence seq1) (fvs_sequence seq2) | |
49 | | Past.DInfo(dots) -> fvs_dots dots | |
50 | | Past.EExists(var,seq) -> failwith "not possible" | |
51 | ||
52 | and fvs_dots = function | |
53 | Past.Dots -> [] | |
54 | | Past.Nest(seq) -> fvs_sequence seq | |
55 | | Past.When(dots,seq) -> Common.union_set (fvs_dots dots) (fvs_sequence seq) | |
56 | ||
57 | (* --------------------------------------------------------------------- *) | |
58 | ||
59 | let inter_set l1 l2 = List.filter (function l1e -> List.mem l1e l2) l1 | |
60 | ||
61 | let minus_set l1 l2 = List.filter (function l1e -> not (List.mem l1e l2)) l1 | |
62 | ||
63 | let rec quant_sequence bound = function | |
64 | Past.Seq(elem,seq) -> | |
65 | let fe = fvs_element elem in | |
66 | let fs = fvs_sequence seq in | |
67 | let inter = inter_set fe fs in | |
68 | let free = minus_set inter bound in | |
69 | let new_bound = free @ bound in | |
70 | List.fold_right (function cur -> function rest -> Past.SExists(cur,rest)) | |
71 | free (Past.Seq(quant_element new_bound elem, | |
72 | quant_sequence new_bound seq)) | |
73 | | Past.Empty -> Past.Empty | |
74 | | Past.SExists(var,seq) -> failwith "not possible" | |
75 | ||
76 | and quant_term bound = function | |
77 | (Past.Atomic(term)) as x -> | |
78 | let free = minus_set (Ast.get_fvs term) bound in | |
79 | List.fold_right (function cur -> function rest -> Past.TExists(cur,rest)) | |
80 | free x | |
81 | | Past.IfThen(test,thn,((afvs,_,_,_) as aft)) -> | |
82 | let fts = fvs_term test in | |
83 | let fth = fvs_term thn in | |
84 | let inter = inter_set fts fth in | |
85 | let free = minus_set inter bound in | |
86 | let new_bound = free @ bound in | |
87 | List.fold_right (function cur -> function rest -> Past.TExists(cur,rest)) | |
88 | free (Past.IfThen(quant_term new_bound test, | |
89 | quant_term new_bound thn, | |
90 | aft)) | |
91 | | Past.TExists(var,term) -> failwith "not possible" | |
92 | ||
93 | and quant_element bound = function | |
94 | Past.Term(term,ba) -> | |
95 | Past.Term(quant_term bound term,dots_bef_aft bound ba) | |
96 | | Past.Or(seq1,seq2) -> | |
97 | Past.Or(quant_sequence bound seq1,quant_sequence bound seq2) | |
98 | | Past.DInfo(dots) -> | |
99 | Past.DInfo(quant_dots bound dots) | |
100 | | Past.EExists(var,seq) -> failwith "not possible" | |
101 | ||
102 | and dots_bef_aft bound = function | |
103 | Past.AddingBetweenDots (brace_term,n) -> | |
104 | Past.AddingBetweenDots (quant_term bound brace_term,n) | |
105 | | Past.DroppingBetweenDots (brace_term,n) -> | |
106 | Past.DroppingBetweenDots (quant_term bound brace_term,n) | |
107 | | Past.NoDots -> Past.NoDots | |
108 | ||
109 | and quant_dots bound = function | |
110 | Past.Dots -> Past.Dots | |
111 | | Past.Nest(seq) -> Past.Nest(quant_sequence bound seq) | |
112 | | Past.When(dots,seq) -> | |
113 | Past.When(quant_dots bound dots, quant_sequence bound seq) | |
114 | ||
115 | (* --------------------------------------------------------------------- *) | |
116 | ||
117 | let insert_quantifiers x = quant_sequence [] x |