2 * Copyright 2012, INRIA
3 * Julia Lawall, Gilles Muller
4 * Copyright 2010-2011, INRIA, University of Copenhagen
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.
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.
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.
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/>.
22 * The authors reserve the right to distribute this or future versions of
23 * Coccinelle under other licenses.
27 #
0 "./insert_befaft.ml"
28 module Past
= Ast_popl
30 (* --------------------------------------------------------------------- *)
32 let rec get_before a
= function
34 let (elem
,ea
) = get_before_element a elem
in
35 let (seq
,sla
) = get_before ea seq
in
36 (Past.Seq
(elem
,seq
),sla
)
37 | Past.Empty
-> (Past.Empty
,a
)
38 | Past.SExists
(var
,seq
) -> failwith
"not possible"
40 and get_before_element a
= function
41 Past.Term
(term
) as s
-> (s
,[s
])
42 | Past.Or
(seq1
,seq2
) ->
43 let (seq1
,seq1a
) = get_before a seq1
in
44 let (seq2
,seq2a
) = get_before a seq2
in
45 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
46 | Past.DInfo
(dots
,_
,seq_aft
) ->
47 let dots = get_before_dots a
dots in
48 (Past.DInfo
(dots,a
,seq_aft
),a
)
49 | Past.EExists
(var
,seq
) -> failwith
"not possible"
51 and get_before_dots a
= function
52 Past.Dots
-> Past.Dots
54 let (seq
,_
) = get_before a seq
in
56 | Past.When
(dots,seq
) ->
57 let dots = get_before_dots a
dots in
58 let (seq
,_
) = get_before [] seq
in
60 | Past.DExists
(var
,dots) -> failwith
"not possible"
62 (* --------------------------------------------------------------------- *)
64 let rec get_after a
= function
66 let (seq
,sla
) = get_after a seq
in
67 let (elem
,ea
) = get_after_element sla elem
in
68 (Past.Seq
(elem
,seq
),ea
)
69 | Past.Empty
-> (Past.Empty
,a
)
70 | Past.SExists
(var
,seq
) -> failwith
"not possible"
72 and get_after_element a
= function
73 Past.Term
(term
) as s
-> (s
,[s
])
74 | Past.Or
(seq1
,seq2
) ->
75 let (seq1
,seq1a
) = get_after a seq1
in
76 let (seq2
,seq2a
) = get_after a seq2
in
77 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
78 | Past.DInfo
(dots,seq_bef
,_
) ->
79 let dots = get_after_dots a
dots in
80 (Past.DInfo
(dots,seq_bef
,a
),a
)
81 | Past.EExists
(var
,seq
) -> failwith
"not possible"
83 and get_after_dots a
= function
84 Past.Dots
-> Past.Dots
86 let (seq
,_
) = get_after (Common.union_set
(get_first
[] seq
) a
) seq
in
88 | Past.When
(dots,seq
) ->
89 let dots = get_after_dots a
dots in
90 let (seq
,_
) = get_after [] seq
in
92 | Past.DExists
(var
,dots) -> failwith
"not possible"
94 (* --------------------------------------------------------------------- *)
95 (* like get_after, but just returns the a component; doesn't modify the term *)
97 and get_first a
= function
99 let sla = get_first a seq
in
100 let ea = get_first_element
sla elem
in
103 | Past.SExists
(var
,seq
) -> failwith
"not possible"
105 and get_first_element a
= function
106 Past.Term
(term
) as s
-> [s
]
107 | Past.Or
(seq1
,seq2
) ->
108 Common.union_set
(get_first a seq1
) (get_first a seq2
)
109 | Past.DInfo
(dots,_
,_
) -> a
110 | Past.EExists
(var
,seq
) -> failwith
"not possible"
112 (* --------------------------------------------------------------------- *)
115 let insert_befaft sl
=
116 let (sl
,_
) = get_before [] sl
in
117 let (sl
,_
) = get_after [] sl
in