2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
45 module Past
= Ast_popl
47 (* --------------------------------------------------------------------- *)
49 let rec get_before a
= function
51 let (elem
,ea
) = get_before_element a elem
in
52 let (seq
,sla
) = get_before ea seq
in
53 (Past.Seq
(elem
,seq
),sla
)
54 | Past.Empty
-> (Past.Empty
,a
)
55 | Past.SExists
(var
,seq
) -> failwith
"not possible"
57 and get_before_element a
= function
58 Past.Term
(term
) as s
-> (s
,[s
])
59 | Past.Or
(seq1
,seq2
) ->
60 let (seq1
,seq1a
) = get_before a seq1
in
61 let (seq2
,seq2a
) = get_before a seq2
in
62 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
63 | Past.DInfo
(dots
,_
,seq_aft
) ->
64 let dots = get_before_dots a
dots in
65 (Past.DInfo
(dots,a
,seq_aft
),a
)
66 | Past.EExists
(var
,seq
) -> failwith
"not possible"
68 and get_before_dots a
= function
69 Past.Dots
-> Past.Dots
71 let (seq
,_
) = get_before a seq
in
73 | Past.When
(dots,seq
) ->
74 let dots = get_before_dots a
dots in
75 let (seq
,_
) = get_before [] seq
in
77 | Past.DExists
(var
,dots) -> failwith
"not possible"
79 (* --------------------------------------------------------------------- *)
81 let rec get_after a
= function
83 let (seq
,sla
) = get_after a seq
in
84 let (elem
,ea
) = get_after_element sla elem
in
85 (Past.Seq
(elem
,seq
),ea
)
86 | Past.Empty
-> (Past.Empty
,a
)
87 | Past.SExists
(var
,seq
) -> failwith
"not possible"
89 and get_after_element a
= function
90 Past.Term
(term
) as s
-> (s
,[s
])
91 | Past.Or
(seq1
,seq2
) ->
92 let (seq1
,seq1a
) = get_after a seq1
in
93 let (seq2
,seq2a
) = get_after a seq2
in
94 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
95 | Past.DInfo
(dots,seq_bef
,_
) ->
96 let dots = get_after_dots a
dots in
97 (Past.DInfo
(dots,seq_bef
,a
),a
)
98 | Past.EExists
(var
,seq
) -> failwith
"not possible"
100 and get_after_dots a
= function
101 Past.Dots
-> Past.Dots
103 let (seq
,_
) = get_after (Common.union_set
(get_first
[] seq
) a
) seq
in
105 | Past.When
(dots,seq
) ->
106 let dots = get_after_dots a
dots in
107 let (seq
,_
) = get_after [] seq
in
109 | Past.DExists
(var
,dots) -> failwith
"not possible"
111 (* --------------------------------------------------------------------- *)
112 (* like get_after, but just returns the a component; doesn't modify the term *)
114 and get_first a
= function
115 Past.Seq
(elem
,seq
) ->
116 let sla = get_first a seq
in
117 let ea = get_first_element
sla elem
in
120 | Past.SExists
(var
,seq
) -> failwith
"not possible"
122 and get_first_element a
= function
123 Past.Term
(term
) as s
-> [s
]
124 | Past.Or
(seq1
,seq2
) ->
125 Common.union_set
(get_first a seq1
) (get_first a seq2
)
126 | Past.DInfo
(dots,_
,_
) -> a
127 | Past.EExists
(var
,seq
) -> failwith
"not possible"
129 (* --------------------------------------------------------------------- *)
132 let insert_befaft sl
=
133 let (sl
,_
) = get_before [] sl
in
134 let (sl
,_
) = get_after [] sl
in