2 * Copyright 2005-2009, 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.
23 module Past
= Ast_popl
25 (* --------------------------------------------------------------------- *)
27 let rec get_before a
= function
29 let (elem
,ea
) = get_before_element a elem
in
30 let (seq
,sla
) = get_before ea seq
in
31 (Past.Seq
(elem
,seq
),sla
)
32 | Past.Empty
-> (Past.Empty
,a
)
33 | Past.SExists
(var
,seq
) -> failwith
"not possible"
35 and get_before_element a
= function
36 Past.Term
(term
) as s
-> (s
,[s
])
37 | Past.Or
(seq1
,seq2
) ->
38 let (seq1
,seq1a
) = get_before a seq1
in
39 let (seq2
,seq2a
) = get_before a seq2
in
40 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
41 | Past.DInfo
(dots
,_
,seq_aft
) ->
42 let dots = get_before_dots a
dots in
43 (Past.DInfo
(dots,a
,seq_aft
),a
)
44 | Past.EExists
(var
,seq
) -> failwith
"not possible"
46 and get_before_dots a
= function
47 Past.Dots
-> Past.Dots
49 let (seq
,_
) = get_before a seq
in
51 | Past.When
(dots,seq
) ->
52 let dots = get_before_dots a
dots in
53 let (seq
,_
) = get_before [] seq
in
55 | Past.DExists
(var
,dots) -> failwith
"not possible"
57 (* --------------------------------------------------------------------- *)
59 let rec get_after a
= function
61 let (seq
,sla
) = get_after a seq
in
62 let (elem
,ea
) = get_after_element sla elem
in
63 (Past.Seq
(elem
,seq
),ea
)
64 | Past.Empty
-> (Past.Empty
,a
)
65 | Past.SExists
(var
,seq
) -> failwith
"not possible"
67 and get_after_element a
= function
68 Past.Term
(term
) as s
-> (s
,[s
])
69 | Past.Or
(seq1
,seq2
) ->
70 let (seq1
,seq1a
) = get_after a seq1
in
71 let (seq2
,seq2a
) = get_after a seq2
in
72 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
73 | Past.DInfo
(dots,seq_bef
,_
) ->
74 let dots = get_after_dots a
dots in
75 (Past.DInfo
(dots,seq_bef
,a
),a
)
76 | Past.EExists
(var
,seq
) -> failwith
"not possible"
78 and get_after_dots a
= function
79 Past.Dots
-> Past.Dots
81 let (seq
,_
) = get_after (Common.union_set
(get_first
[] seq
) a
) seq
in
83 | Past.When
(dots,seq
) ->
84 let dots = get_after_dots a
dots in
85 let (seq
,_
) = get_after [] seq
in
87 | Past.DExists
(var
,dots) -> failwith
"not possible"
89 (* --------------------------------------------------------------------- *)
90 (* like get_after, but just returns the a component; doesn't modify the term *)
92 and get_first a
= function
94 let sla = get_first a seq
in
95 let ea = get_first_element
sla elem
in
98 | Past.SExists
(var
,seq
) -> failwith
"not possible"
100 and get_first_element a
= function
101 Past.Term
(term
) as s
-> [s
]
102 | Past.Or
(seq1
,seq2
) ->
103 Common.union_set
(get_first a seq1
) (get_first a seq2
)
104 | Past.DInfo
(dots,_
,_
) -> a
105 | Past.EExists
(var
,seq
) -> failwith
"not possible"
107 (* --------------------------------------------------------------------- *)
110 let insert_befaft sl
=
111 let (sl
,_
) = get_before [] sl
in
112 let (sl
,_
) = get_after [] sl
in