2 NoMark
| BefMark
of string | AftMark
of string
3 | BefAftMark
of string * string
5 let extract_sgrep_marker l
=
6 let rec inner_loop acc
= function
8 | Ast_cocci.SgrepStartTag
(s
)::rest
->
10 NoMark
-> inner_loop (BefMark
(s
)) rest
11 | _
-> failwith
"unexpected mark")
12 | Ast_cocci.SgrepEndTag
(s
)::rest
->
14 NoMark
-> inner_loop (AftMark
(s
)) rest
15 | BefMark
(m
) -> inner_loop (BefAftMark
(m
,s
)) rest
16 | _
-> failwith
"unexpected mark")
18 let (acc
,rest
) = inner_loop acc rest
in
22 (function (acc
,prev
) ->
24 let (acc
,cur
) = inner_loop acc cur
in
29 let process_sgrep ii mck
=
30 let file = Ast_c.file_of_info ii
in
31 let line = Ast_c.line_of_info ii
in
32 let col = Ast_c.col_of_info ii
in
33 let str = Ast_c.str_of_info ii
in
35 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
) ->
36 (match extract_sgrep_marker repl
with
38 | (BefMark
(marker
),repl
) ->
39 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
41 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
42 | (AftMark
(marker
),repl
) ->
43 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
44 marker
file line (col + String.length
str);
45 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
)
46 | (BefAftMark
(bmarker
,amarker
),repl
) ->
47 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
48 bmarker
file line col;
49 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
50 amarker
file line (col + String.length
str);
51 Ast_cocci.MINUS
(pos
,inst
,adj
,repl
))
52 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
) -> mck
53 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
)) ->
54 (match extract_sgrep_marker bef
with
56 | (BefMark
(marker
),[]) ->
57 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
59 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
60 | (BefMark
(marker
),bef
) ->
61 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
63 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
64 | _
-> failwith
"after not possible")
65 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
)) ->
66 (match extract_sgrep_marker aft
with
68 | (AftMark
(marker
),[]) ->
69 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
70 marker
file line (col + String.length
str);
71 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
72 | (AftMark
(marker
),aft
) ->
73 Printf.printf
"Match on line %s ending at %s: line %d offset %d\n"
74 marker
file line (col + String.length
str);
75 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
76 | _
-> failwith
"before not possible")
77 | Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
)) ->
78 (match extract_sgrep_marker bef
with
80 (match extract_sgrep_marker aft
with
82 | (AftMark
(marker
),[]) ->
84 "Match on line %s ending at %s: line %d offset %d\n"
85 marker
file line (col + String.length
str);
86 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFORE
(bef
,c
))
87 | (AftMark
(marker
),aft
) ->
89 "Match on line %s ending at %s: line %d offset %d\n"
90 marker
file line (col + String.length
str);
91 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
92 | _
-> failwith
"before not possible")
93 | (BefMark
(marker
),[]) ->
94 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
96 (match extract_sgrep_marker aft
with
97 (NoMark
,_
) -> Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
98 | (AftMark
(marker
),[]) ->
100 "Match on line %s ending at %s: line %d offset %d\n"
101 marker
file line (col + String.length
str);
102 Ast_cocci.CONTEXT
(pos
,Ast_cocci.NOTHING
)
103 | (AftMark
(marker
),aft
) ->
105 "Match on line %s ending at %s: line %d offset %d\n"
106 marker
file line (col + String.length
str);
107 Ast_cocci.CONTEXT
(pos
,Ast_cocci.AFTER
(aft
,c
))
108 | _
-> failwith
"before not possible")
109 | (BefMark
(marker
),bef
) ->
110 Printf.printf
"Match on line %s starting at %s: line %d offset %d\n"
111 marker
file line col;
112 (match extract_sgrep_marker aft
with
114 Ast_cocci.CONTEXT
(pos
,Ast_cocci.BEFOREAFTER
(bef
,aft
,c
))
115 | (AftMark
(marker
),[]) ->
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.BEFORE
(bef
,c
))
120 | (AftMark
(marker
),aft
) ->
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.BEFOREAFTER
(bef
,aft
,c
))
125 | _
-> failwith
"before not possible")
126 | _
-> failwith
"after not possible")
127 | _
-> failwith
"unexpected plus code"