Commit | Line | Data |
---|---|---|
f537ebc4 | 1 | (* |
17ba0788 C |
2 | * Copyright 2012, INRIA |
3 | * Julia Lawall, Gilles Muller | |
4 | * Copyright 2010-2011, INRIA, University of Copenhagen | |
f537ebc4 C |
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. | |
9 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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/>. | |
21 | * | |
22 | * The authors reserve the right to distribute this or future versions of | |
23 | * Coccinelle under other licenses. | |
24 | *) | |
25 | ||
26 | ||
951c7801 C |
27 | module Past = Ast_popl |
28 | ||
29 | (* --------------------------------------------------------------------- *) | |
30 | ||
31 | let rec get_before a = function | |
32 | Past.Seq(elem,seq) -> | |
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" | |
38 | ||
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" | |
49 | ||
50 | and get_before_dots a = function | |
51 | Past.Dots -> Past.Dots | |
52 | | Past.Nest(seq) -> | |
53 | let (seq,_) = get_before a seq in | |
54 | Past.Nest(seq) | |
55 | | Past.When(dots,seq) -> | |
56 | let dots = get_before_dots a dots in | |
57 | let (seq,_) = get_before [] seq in | |
58 | Past.When(dots,seq) | |
59 | | Past.DExists(var,dots) -> failwith "not possible" | |
60 | ||
61 | (* --------------------------------------------------------------------- *) | |
62 | ||
63 | let rec get_after a = function | |
64 | Past.Seq(elem,seq) -> | |
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" | |
70 | ||
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" | |
81 | ||
82 | and get_after_dots a = function | |
83 | Past.Dots -> Past.Dots | |
84 | | Past.Nest(seq) -> | |
85 | let (seq,_) = get_after (Common.union_set (get_first [] seq) a) seq in | |
86 | Past.Nest(seq) | |
87 | | Past.When(dots,seq) -> | |
88 | let dots = get_after_dots a dots in | |
89 | let (seq,_) = get_after [] seq in | |
90 | Past.When(dots,seq) | |
91 | | Past.DExists(var,dots) -> failwith "not possible" | |
92 | ||
93 | (* --------------------------------------------------------------------- *) | |
94 | (* like get_after, but just returns the a component; doesn't modify the term *) | |
95 | ||
96 | and get_first a = function | |
97 | Past.Seq(elem,seq) -> | |
98 | let sla = get_first a seq in | |
99 | let ea = get_first_element sla elem in | |
100 | ea | |
101 | | Past.Empty -> a | |
102 | | Past.SExists(var,seq) -> failwith "not possible" | |
103 | ||
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" | |
110 | ||
111 | (* --------------------------------------------------------------------- *) | |
112 | (* Entry point *) | |
113 | ||
114 | let insert_befaft sl = | |
115 | let (sl,_) = get_before [] sl in | |
116 | let (sl,_) = get_after [] sl in | |
117 | sl |