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 module Past
= Ast_popl
29 (* --------------------------------------------------------------------- *)
31 let rec get_before a
= function
33 let (elem
,ea
) = get_before_element a elem
in
34 let (seq
,sla
) = get_before ea seq
in
35 (Past.Seq
(elem
,seq
),sla
)
36 | Past.Empty
-> (Past.Empty
,a
)
37 | Past.SExists
(var
,seq
) -> failwith
"not possible"
39 and get_before_element a
= function
40 Past.Term
(term
) as s
-> (s
,[s
])
41 | Past.Or
(seq1
,seq2
) ->
42 let (seq1
,seq1a
) = get_before a seq1
in
43 let (seq2
,seq2a
) = get_before a seq2
in
44 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
45 | Past.DInfo
(dots
,_
,seq_aft
) ->
46 let dots = get_before_dots a
dots in
47 (Past.DInfo
(dots,a
,seq_aft
),a
)
48 | Past.EExists
(var
,seq
) -> failwith
"not possible"
50 and get_before_dots a
= function
51 Past.Dots
-> Past.Dots
53 let (seq
,_
) = get_before a seq
in
55 | Past.When
(dots,seq
) ->
56 let dots = get_before_dots a
dots in
57 let (seq
,_
) = get_before [] seq
in
59 | Past.DExists
(var
,dots) -> failwith
"not possible"
61 (* --------------------------------------------------------------------- *)
63 let rec get_after a
= function
65 let (seq
,sla
) = get_after a seq
in
66 let (elem
,ea
) = get_after_element sla elem
in
67 (Past.Seq
(elem
,seq
),ea
)
68 | Past.Empty
-> (Past.Empty
,a
)
69 | Past.SExists
(var
,seq
) -> failwith
"not possible"
71 and get_after_element a
= function
72 Past.Term
(term
) as s
-> (s
,[s
])
73 | Past.Or
(seq1
,seq2
) ->
74 let (seq1
,seq1a
) = get_after a seq1
in
75 let (seq2
,seq2a
) = get_after a seq2
in
76 (Past.Or
(seq1
,seq2
),Common.union_set seq1a seq2a
)
77 | Past.DInfo
(dots,seq_bef
,_
) ->
78 let dots = get_after_dots a
dots in
79 (Past.DInfo
(dots,seq_bef
,a
),a
)
80 | Past.EExists
(var
,seq
) -> failwith
"not possible"
82 and get_after_dots a
= function
83 Past.Dots
-> Past.Dots
85 let (seq
,_
) = get_after (Common.union_set
(get_first
[] seq
) a
) seq
in
87 | Past.When
(dots,seq
) ->
88 let dots = get_after_dots a
dots in
89 let (seq
,_
) = get_after [] seq
in
91 | Past.DExists
(var
,dots) -> failwith
"not possible"
93 (* --------------------------------------------------------------------- *)
94 (* like get_after, but just returns the a component; doesn't modify the term *)
96 and get_first a
= function
98 let sla = get_first a seq
in
99 let ea = get_first_element
sla elem
in
102 | Past.SExists
(var
,seq
) -> failwith
"not possible"
104 and get_first_element a
= function
105 Past.Term
(term
) as s
-> [s
]
106 | Past.Or
(seq1
,seq2
) ->
107 Common.union_set
(get_first a seq1
) (get_first a seq2
)
108 | Past.DInfo
(dots,_
,_
) -> a
109 | Past.EExists
(var
,seq
) -> failwith
"not possible"
111 (* --------------------------------------------------------------------- *)
114 let insert_befaft sl
=
115 let (sl
,_
) = get_before [] sl
in
116 let (sl
,_
) = get_after [] sl
in