2 * Copyright 2005-2010, 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.
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
46 NoMark
| BefMark
of string | AftMark
of string
47 | BefAftMark
of string * string
49 let extract_sgrep_marker l
=
50 let rec inner_loop acc
= function
52 | Ast_cocci.SgrepStartTag
(s
)::rest
->
54 NoMark
-> inner_loop (BefMark
(s
)) rest
55 | _
-> failwith
"unexpected mark")
56 | Ast_cocci.SgrepEndTag
(s
)::rest
->
58 NoMark
-> inner_loop (AftMark
(s
)) rest
59 | BefMark
(m
) -> inner_loop (BefAftMark
(m
,s
)) rest
60 | _
-> failwith
"unexpected mark")
62 let (acc
,rest
) = inner_loop acc rest
in
66 (function (acc
,prev
) ->
68 let (acc
,cur
) = inner_loop acc cur
in
73 let process_sgrep ii mck
=
74 let file = Ast_c.file_of_info ii
in
75 let line = Ast_c.line_of_info ii
in
76 let col = Ast_c.col_of_info ii
in
77 let str = Ast_c.str_of_info ii
in
79 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
) ->
80 (match extract_sgrep_marker repl
with
82 | (BefMark
(marker
),repl
) ->
83 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
85 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
86 | (AftMark
(marker
),repl
) ->
87 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
88 marker
file line (col + String.length
str);
89 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
90 | (BefAftMark
(bmarker
,amarker
),repl
) ->
91 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
92 bmarker
file line col;
93 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
94 amarker
file line (col + String.length
str);
95 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
))
96 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
) -> mck
97 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
)) ->
98 (match extract_sgrep_marker bef
with
100 | (BefMark
(marker
),[]) ->
101 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
102 marker
file line col;
103 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
104 | (BefMark
(marker
),bef
) ->
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.BEFORE
(bef
,c
))
108 | _
-> failwith
"after not possible")
109 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
)) ->
110 (match extract_sgrep_marker aft
with
112 | (AftMark
(marker
),[]) ->
113 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
114 marker
file line (col + String.length
str);
115 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
116 | (AftMark
(marker
),aft
) ->
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.AFTER
(aft
,c
))
120 | _
-> failwith
"before not possible")
121 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
)) ->
122 (match extract_sgrep_marker bef
with
124 (match extract_sgrep_marker aft
with
126 | (AftMark
(marker
),[]) ->
128 "Match on line %s ending at %s: line %d offset %d\n"
129 marker
file line (col + String.length
str);
130 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
131 | (AftMark
(marker
),aft
) ->
133 "Match on line %s ending at %s: line %d offset %d\n"
134 marker
file line (col + String.length
str);
135 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
136 | _
-> failwith
"before not possible")
137 | (BefMark
(marker
),[]) ->
138 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
139 marker
file line col;
140 (match extract_sgrep_marker aft
with
141 (NoMark
,_
) -> Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
142 | (AftMark
(marker
),[]) ->
144 "Match on line %s ending at %s: line %d offset %d\n"
145 marker
file line (col + String.length
str);
146 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
147 | (AftMark
(marker
),aft
) ->
149 "Match on line %s ending at %s: line %d offset %d\n"
150 marker
file line (col + String.length
str);
151 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
152 | _
-> failwith
"before not possible")
153 | (BefMark
(marker
),bef
) ->
154 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
155 marker
file line col;
156 (match extract_sgrep_marker aft
with
158 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
159 | (AftMark
(marker
),[]) ->
161 "Match on line %s ending at %s: line %d offset %d\n"
162 marker
file line (col + String.length
str);
163 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
164 | (AftMark
(marker
),aft
) ->
166 "Match on line %s ending at %s: line %d offset %d\n"
167 marker
file line (col + String.length
str);
168 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
169 | _
-> failwith
"before not possible")
170 | _
-> failwith
"after not possible")
171 | _
-> failwith
"unexpected plus code"