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.
30 NoMark
| BefMark
of string | AftMark
of string
31 | BefAftMark
of string * string
33 let extract_sgrep_marker l
=
34 let rec inner_loop acc
= function
36 | Ast_cocci.SgrepStartTag
(s
)::rest
->
38 NoMark
-> inner_loop (BefMark
(s
)) rest
39 | _
-> failwith
"unexpected mark")
40 | Ast_cocci.SgrepEndTag
(s
)::rest
->
42 NoMark
-> inner_loop (AftMark
(s
)) rest
43 | BefMark
(m
) -> inner_loop (BefAftMark
(m
,s
)) rest
44 | _
-> failwith
"unexpected mark")
46 let (acc
,rest
) = inner_loop acc rest
in
50 (function (acc
,prev
) ->
52 let (acc
,cur
) = inner_loop acc cur
in
57 let process_sgrep ii mck
=
58 let file = Ast_c.file_of_info ii
in
59 let line = Ast_c.line_of_info ii
in
60 let col = Ast_c.col_of_info ii
in
61 let str = Ast_c.str_of_info ii
in
63 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
) ->
64 (match extract_sgrep_marker repl
with
66 | (BefMark
(marker
),repl
) ->
67 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
69 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
70 | (AftMark
(marker
),repl
) ->
71 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
72 marker
file line (col + String.length
str);
73 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
74 | (BefAftMark
(bmarker
,amarker
),repl
) ->
75 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
76 bmarker
file line col;
77 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
78 amarker
file line (col + String.length
str);
79 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
))
80 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
) -> mck
81 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
)) ->
82 (match extract_sgrep_marker bef
with
84 | (BefMark
(marker
),[]) ->
85 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
87 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
88 | (BefMark
(marker
),bef
) ->
89 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
91 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
92 | _
-> failwith
"after not possible")
93 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
)) ->
94 (match extract_sgrep_marker aft
with
96 | (AftMark
(marker
),[]) ->
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.NOTHING
)
100 | (AftMark
(marker
),aft
) ->
101 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
102 marker
file line (col + String.length
str);
103 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
104 | _
-> failwith
"before not possible")
105 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
)) ->
106 (match extract_sgrep_marker bef
with
108 (match extract_sgrep_marker aft
with
110 | (AftMark
(marker
),[]) ->
112 "Match on line %s ending at %s: line %d offset %d\n"
113 marker
file line (col + String.length
str);
114 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
115 | (AftMark
(marker
),aft
) ->
117 "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.BEFOREAFTER
(bef
,aft
,c
))
120 | _
-> failwith
"before not possible")
121 | (BefMark
(marker
),[]) ->
122 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
123 marker
file line col;
124 (match extract_sgrep_marker aft
with
125 (NoMark
,_
) -> Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
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.NOTHING
)
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.AFTER
(aft
,c
))
136 | _
-> failwith
"before not possible")
137 | (BefMark
(marker
),bef
) ->
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
142 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
143 | (AftMark
(marker
),[]) ->
145 "Match on line %s ending at %s: line %d offset %d\n"
146 marker
file line (col + String.length
str);
147 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
148 | (AftMark
(marker
),aft
) ->
150 "Match on line %s ending at %s: line %d offset %d\n"
151 marker
file line (col + String.length
str);
152 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
153 | _
-> failwith
"before not possible")
154 | _
-> failwith
"after not possible")
155 | _
-> failwith
"unexpected plus code"