2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
49 module Past
= Ast_popl
51 (* --------------------------------------------------------------------- *)
53 let rec get_before a
= function
55 let (elem
,ea
) = get_before_element a elem
in
56 let (seq
,sla
) = get_before ea seq
in
57 (Past.Seq
(elem
,seq
),sla
)
58 | Past.Empty
-> (Past.Empty
,a
)
59 | Past.SExists
(var
,seq
) -> failwith
"not possible"
61 and get_before_element a
= function
62 Past.Term
(term
) as s
-> (s
,[s
])
63 | Past.Or
(seq1
,seq2
) ->
64 let (seq1
,seq1a
) = get_before a seq1
in
65 let (seq2
,seq2a
) = get_before a seq2
in
66 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
67 | Past.DInfo
(dots
,_
,seq_aft
) ->
68 let dots = get_before_dots a
dots in
69 (Past.DInfo
(dots,a
,seq_aft
),a
)
70 | Past.EExists
(var
,seq
) -> failwith
"not possible"
72 and get_before_dots a
= function
73 Past.Dots
-> Past.Dots
75 let (seq
,_
) = get_before a seq
in
77 | Past.When
(dots,seq
) ->
78 let dots = get_before_dots a
dots in
79 let (seq
,_
) = get_before [] seq
in
81 | Past.DExists
(var
,dots) -> failwith
"not possible"
83 (* --------------------------------------------------------------------- *)
85 let rec get_after a
= function
87 let (seq
,sla
) = get_after a seq
in
88 let (elem
,ea
) = get_after_element sla elem
in
89 (Past.Seq
(elem
,seq
),ea
)
90 | Past.Empty
-> (Past.Empty
,a
)
91 | Past.SExists
(var
,seq
) -> failwith
"not possible"
93 and get_after_element a
= function
94 Past.Term
(term
) as s
-> (s
,[s
])
95 | Past.Or
(seq1
,seq2
) ->
96 let (seq1
,seq1a
) = get_after a seq1
in
97 let (seq2
,seq2a
) = get_after a seq2
in
98 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
99 | Past.DInfo
(dots,seq_bef
,_
) ->
100 let dots = get_after_dots a
dots in
101 (Past.DInfo
(dots,seq_bef
,a
),a
)
102 | Past.EExists
(var
,seq
) -> failwith
"not possible"
104 and get_after_dots a
= function
105 Past.Dots
-> Past.Dots
107 let (seq
,_
) = get_after (Common.union_set
(get_first
[] seq
) a
) seq
in
109 | Past.When
(dots,seq
) ->
110 let dots = get_after_dots a
dots in
111 let (seq
,_
) = get_after [] seq
in
113 | Past.DExists
(var
,dots) -> failwith
"not possible"
115 (* --------------------------------------------------------------------- *)
116 (* like get_after, but just returns the a component; doesn't modify the term *)
118 and get_first a
= function
119 Past.Seq
(elem
,seq
) ->
120 let sla = get_first a seq
in
121 let ea = get_first_element
sla elem
in
124 | Past.SExists
(var
,seq
) -> failwith
"not possible"
126 and get_first_element a
= function
127 Past.Term
(term
) as s
-> [s
]
128 | Past.Or
(seq1
,seq2
) ->
129 Common.union_set
(get_first a seq1
) (get_first a seq2
)
130 | Past.DInfo
(dots,_
,_
) -> a
131 | Past.EExists
(var
,seq
) -> failwith
"not possible"
133 (* --------------------------------------------------------------------- *)
136 let insert_befaft sl
=
137 let (sl
,_
) = get_before [] sl
in
138 let (sl
,_
) = get_after [] sl
in