2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
50 NoMark
| BefMark
of string | AftMark
of string
51 | BefAftMark
of string * string
53 let extract_sgrep_marker l
=
54 let rec inner_loop acc
= function
56 | Ast_cocci.SgrepStartTag
(s
)::rest
->
58 NoMark
-> inner_loop (BefMark
(s
)) rest
59 | _
-> failwith
"unexpected mark")
60 | Ast_cocci.SgrepEndTag
(s
)::rest
->
62 NoMark
-> inner_loop (AftMark
(s
)) rest
63 | BefMark
(m
) -> inner_loop (BefAftMark
(m
,s
)) rest
64 | _
-> failwith
"unexpected mark")
66 let (acc
,rest
) = inner_loop acc rest
in
70 (function (acc
,prev
) ->
72 let (acc
,cur
) = inner_loop acc cur
in
77 let process_sgrep ii mck
=
78 let file = Ast_c.file_of_info ii
in
79 let line = Ast_c.line_of_info ii
in
80 let col = Ast_c.col_of_info ii
in
81 let str = Ast_c.str_of_info ii
in
83 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
) ->
84 (match extract_sgrep_marker repl
with
86 | (BefMark
(marker
),repl
) ->
87 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
89 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
90 | (AftMark
(marker
),repl
) ->
91 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
92 marker
file line (col + String.length
str);
93 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
94 | (BefAftMark
(bmarker
,amarker
),repl
) ->
95 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
96 bmarker
file line col;
97 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
98 amarker
file line (col + String.length
str);
99 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
))
100 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
) -> mck
101 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
)) ->
102 (match extract_sgrep_marker bef
with
104 | (BefMark
(marker
),[]) ->
105 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
106 marker
file line col;
107 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
108 | (BefMark
(marker
),bef
) ->
109 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
110 marker
file line col;
111 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
112 | _
-> failwith
"after not possible")
113 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
)) ->
114 (match extract_sgrep_marker aft
with
116 | (AftMark
(marker
),[]) ->
117 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
118 marker
file line (col + String.length
str);
119 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
120 | (AftMark
(marker
),aft
) ->
121 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
122 marker
file line (col + String.length
str);
123 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
124 | _
-> failwith
"before not possible")
125 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
)) ->
126 (match extract_sgrep_marker bef
with
128 (match extract_sgrep_marker aft
with
130 | (AftMark
(marker
),[]) ->
132 "Match on line %s ending at %s: line %d offset %d\n"
133 marker
file line (col + String.length
str);
134 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
135 | (AftMark
(marker
),aft
) ->
137 "Match on line %s ending at %s: line %d offset %d\n"
138 marker
file line (col + String.length
str);
139 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
140 | _
-> failwith
"before not possible")
141 | (BefMark
(marker
),[]) ->
142 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
143 marker
file line col;
144 (match extract_sgrep_marker aft
with
145 (NoMark
,_
) -> Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
146 | (AftMark
(marker
),[]) ->
148 "Match on line %s ending at %s: line %d offset %d\n"
149 marker
file line (col + String.length
str);
150 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
151 | (AftMark
(marker
),aft
) ->
153 "Match on line %s ending at %s: line %d offset %d\n"
154 marker
file line (col + String.length
str);
155 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
156 | _
-> failwith
"before not possible")
157 | (BefMark
(marker
),bef
) ->
158 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
159 marker
file line col;
160 (match extract_sgrep_marker aft
with
162 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
163 | (AftMark
(marker
),[]) ->
165 "Match on line %s ending at %s: line %d offset %d\n"
166 marker
file line (col + String.length
str);
167 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
168 | (AftMark
(marker
),aft
) ->
170 "Match on line %s ending at %s: line %d offset %d\n"
171 marker
file line (col + String.length
str);
172 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
173 | _
-> failwith
"before not possible")
174 | _
-> failwith
"after not possible")
175 | _
-> failwith
"unexpected plus code"