ed6dd497453a9bfce4bf1c2b822fe6608bcfab44
2 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
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 NoMark
| BefMark
of string | AftMark
of string
25 | BefAftMark
of string * string
27 let extract_sgrep_marker l
=
28 let rec inner_loop acc
= function
30 | Ast_cocci.SgrepStartTag
(s
)::rest
->
32 NoMark
-> inner_loop (BefMark
(s
)) rest
33 | _
-> failwith
"unexpected mark")
34 | Ast_cocci.SgrepEndTag
(s
)::rest
->
36 NoMark
-> inner_loop (AftMark
(s
)) rest
37 | BefMark
(m
) -> inner_loop (BefAftMark
(m
,s
)) rest
38 | _
-> failwith
"unexpected mark")
40 let (acc
,rest
) = inner_loop acc rest
in
44 (function (acc
,prev
) ->
46 let (acc
,cur
) = inner_loop acc cur
in
51 let process_sgrep ii mck
=
52 let file = Ast_c.file_of_info ii
in
53 let line = Ast_c.line_of_info ii
in
54 let col = Ast_c.col_of_info ii
in
55 let str = Ast_c.str_of_info ii
in
57 Ast_cocci.MINUS
(pos
,repl
) ->
58 (match extract_sgrep_marker repl
with
60 | (BefMark
(marker
),repl
) ->
61 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
63 Ast_cocci.MINUS
(pos
,repl
)
64 | (AftMark
(marker
),repl
) ->
65 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
66 marker
file line (col + String.length
str);
67 Ast_cocci.MINUS
(pos
,repl
)
68 | (BefAftMark
(bmarker
,amarker
),repl
) ->
69 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
70 bmarker
file line col;
71 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
72 amarker
file line (col + String.length
str);
73 Ast_cocci.MINUS
(pos
,repl
))
74 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
) -> mck
75 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
)) ->
76 (match extract_sgrep_marker bef
with
78 | (BefMark
(marker
),[]) ->
79 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
81 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
82 | (BefMark
(marker
),bef
) ->
83 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
85 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
))
86 | _
-> failwith
"after not possible")
87 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
)) ->
88 (match extract_sgrep_marker aft
with
90 | (AftMark
(marker
),[]) ->
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.CONTEXT
(pos
,Ast_cocci.NOTHING
)
94 | (AftMark
(marker
),aft
) ->
95 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
96 marker
file line (col + String.length
str);
97 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
))
98 | _
-> failwith
"before not possible")
99 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
)) ->
100 (match extract_sgrep_marker bef
with
102 (match extract_sgrep_marker aft
with
104 | (AftMark
(marker
),[]) ->
106 "Match on line %s ending at %s: line %d offset %d\n"
107 marker
file line (col + String.length
str);
108 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
))
109 | (AftMark
(marker
),aft
) ->
111 "Match on line %s ending at %s: line %d offset %d\n"
112 marker
file line (col + String.length
str);
113 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
))
114 | _
-> failwith
"before not possible")
115 | (BefMark
(marker
),[]) ->
116 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
117 marker
file line col;
118 (match extract_sgrep_marker aft
with
119 (NoMark
,_
) -> Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
))
120 | (AftMark
(marker
),[]) ->
122 "Match on line %s ending at %s: line %d offset %d\n"
123 marker
file line (col + String.length
str);
124 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
125 | (AftMark
(marker
),aft
) ->
127 "Match on line %s ending at %s: line %d offset %d\n"
128 marker
file line (col + String.length
str);
129 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
))
130 | _
-> failwith
"before not possible")
131 | (BefMark
(marker
),bef
) ->
132 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
133 marker
file line col;
134 (match extract_sgrep_marker aft
with
135 (NoMark
,_
) -> Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
))
136 | (AftMark
(marker
),[]) ->
138 "Match on line %s ending at %s: line %d offset %d\n"
139 marker
file line (col + String.length
str);
140 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
))
141 | (AftMark
(marker
),aft
) ->
143 "Match on line %s ending at %s: line %d offset %d\n"
144 marker
file line (col + String.length
str);
145 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
))
146 | _
-> failwith
"before not possible")
147 | _
-> failwith
"after not possible")
148 | _
-> failwith
"unexpected plus code"