f1089b282ecd2ffc4ac1442d3eaf28debc0f5b96
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 NoMark
| BefMark
of string | AftMark
of string
27 | BefAftMark
of string * string
29 let extract_sgrep_marker l
=
30 let rec inner_loop acc
= function
32 | Ast_cocci.SgrepStartTag
(s
)::rest
->
34 NoMark
-> inner_loop (BefMark
(s
)) rest
35 | _
-> failwith
"unexpected mark")
36 | Ast_cocci.SgrepEndTag
(s
)::rest
->
38 NoMark
-> inner_loop (AftMark
(s
)) rest
39 | BefMark
(m
) -> inner_loop (BefAftMark
(m
,s
)) rest
40 | _
-> failwith
"unexpected mark")
42 let (acc
,rest
) = inner_loop acc rest
in
46 (function (acc
,prev
) ->
48 let (acc
,cur
) = inner_loop acc cur
in
53 let process_sgrep ii mck
=
54 let file = Ast_c.file_of_info ii
in
55 let line = Ast_c.line_of_info ii
in
56 let col = Ast_c.col_of_info ii
in
57 let str = Ast_c.str_of_info ii
in
59 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
) ->
60 (match extract_sgrep_marker repl
with
62 | (BefMark
(marker
),repl
) ->
63 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
65 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
66 | (AftMark
(marker
),repl
) ->
67 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
68 marker
file line (col + String.length
str);
69 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
70 | (BefAftMark
(bmarker
,amarker
),repl
) ->
71 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
72 bmarker
file line col;
73 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
74 amarker
file line (col + String.length
str);
75 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
))
76 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
) -> mck
77 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
)) ->
78 (match extract_sgrep_marker bef
with
80 | (BefMark
(marker
),[]) ->
81 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
83 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
84 | (BefMark
(marker
),bef
) ->
85 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
87 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
88 | _
-> failwith
"after not possible")
89 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
)) ->
90 (match extract_sgrep_marker aft
with
92 | (AftMark
(marker
),[]) ->
93 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
94 marker
file line (col + String.length
str);
95 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
96 | (AftMark
(marker
),aft
) ->
97 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
98 marker
file line (col + String.length
str);
99 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
100 | _
-> failwith
"before not possible")
101 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
)) ->
102 (match extract_sgrep_marker bef
with
104 (match extract_sgrep_marker aft
with
106 | (AftMark
(marker
),[]) ->
108 "Match on line %s ending at %s: line %d offset %d\n"
109 marker
file line (col + String.length
str);
110 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
111 | (AftMark
(marker
),aft
) ->
113 "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.BEFOREAFTER
(bef
,aft
,c
))
116 | _
-> failwith
"before not possible")
117 | (BefMark
(marker
),[]) ->
118 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
119 marker
file line col;
120 (match extract_sgrep_marker aft
with
121 (NoMark
,_
) -> Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
122 | (AftMark
(marker
),[]) ->
124 "Match on line %s ending at %s: line %d offset %d\n"
125 marker
file line (col + String.length
str);
126 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
127 | (AftMark
(marker
),aft
) ->
129 "Match on line %s ending at %s: line %d offset %d\n"
130 marker
file line (col + String.length
str);
131 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
132 | _
-> failwith
"before not possible")
133 | (BefMark
(marker
),bef
) ->
134 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
135 marker
file line col;
136 (match extract_sgrep_marker aft
with
138 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
139 | (AftMark
(marker
),[]) ->
141 "Match on line %s ending at %s: line %d offset %d\n"
142 marker
file line (col + String.length
str);
143 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
144 | (AftMark
(marker
),aft
) ->
146 "Match on line %s ending at %s: line %d offset %d\n"
147 marker
file line (col + String.length
str);
148 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
149 | _
-> failwith
"before not possible")
150 | _
-> failwith
"after not possible")
151 | _
-> failwith
"unexpected plus code"