Commit | Line | Data |
---|---|---|
f537ebc4 | 1 | (* |
17ba0788 C |
2 | * Copyright 2012, INRIA |
3 | * Julia Lawall, Gilles Muller | |
4 | * Copyright 2010-2011, INRIA, University of Copenhagen | |
f537ebc4 C |
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. | |
9 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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/>. | |
21 | * | |
22 | * The authors reserve the right to distribute this or future versions of | |
23 | * Coccinelle under other licenses. | |
24 | *) | |
25 | ||
26 | ||
feec80c3 | 27 | # 0 "./sgrep.ml" |
8babbc8f C |
28 | (* no longer used *) |
29 | ||
34e49164 C |
30 | type marker = |
31 | NoMark | BefMark of string | AftMark of string | |
32 | | BefAftMark of string * string | |
33 | ||
34 | let extract_sgrep_marker l = | |
35 | let rec inner_loop acc = function | |
36 | [] -> (acc,[]) | |
37 | | Ast_cocci.SgrepStartTag(s)::rest -> | |
38 | (match acc with | |
39 | NoMark -> inner_loop (BefMark(s)) rest | |
40 | | _ -> failwith "unexpected mark") | |
41 | | Ast_cocci.SgrepEndTag(s)::rest -> | |
42 | (match acc with | |
43 | NoMark -> inner_loop (AftMark(s)) rest | |
44 | | BefMark(m) -> inner_loop (BefAftMark(m,s)) rest | |
45 | | _ -> failwith "unexpected mark") | |
46 | | x::rest -> | |
47 | let (acc,rest) = inner_loop acc rest in | |
48 | (acc,x::rest) in | |
49 | let (acc,l) = | |
50 | List.fold_left | |
51 | (function (acc,prev) -> | |
52 | function cur -> | |
53 | let (acc,cur) = inner_loop acc cur in | |
54 | (acc,cur::prev)) | |
55 | (NoMark,[]) l in | |
56 | (acc,List.rev l) | |
57 | ||
58 | let process_sgrep ii mck = | |
59 | let file = Ast_c.file_of_info ii in | |
60 | let line = Ast_c.line_of_info ii in | |
61 | let col = Ast_c.col_of_info ii in | |
62 | let str = Ast_c.str_of_info ii in | |
63 | match mck with | |
708f4980 | 64 | Ast_cocci.MINUS(pos,inst,adj,repl) -> |
34e49164 C |
65 | (match extract_sgrep_marker repl with |
66 | (NoMark,_) -> mck | |
67 | | (BefMark(marker),repl) -> | |
68 | Printf.printf "Match on line %s starting at %s: line %d offset %d\n" | |
69 | marker file line col; | |
708f4980 | 70 | Ast_cocci.MINUS(pos,inst,adj,repl) |
34e49164 C |
71 | | (AftMark(marker),repl) -> |
72 | Printf.printf "Match on line %s ending at %s: line %d offset %d\n" | |
73 | marker file line (col + String.length str); | |
708f4980 | 74 | Ast_cocci.MINUS(pos,inst,adj,repl) |
34e49164 C |
75 | | (BefAftMark(bmarker,amarker),repl) -> |
76 | Printf.printf "Match on line %s starting at %s: line %d offset %d\n" | |
77 | bmarker file line col; | |
78 | Printf.printf "Match on line %s ending at %s: line %d offset %d\n" | |
79 | amarker file line (col + String.length str); | |
708f4980 | 80 | Ast_cocci.MINUS(pos,inst,adj,repl)) |
34e49164 | 81 | | Ast_cocci.CONTEXT(pos,Ast_cocci.NOTHING) -> mck |
951c7801 | 82 | | Ast_cocci.CONTEXT(pos,Ast_cocci.BEFORE(bef,c)) -> |
34e49164 C |
83 | (match extract_sgrep_marker bef with |
84 | (NoMark,_) -> mck | |
85 | | (BefMark(marker),[]) -> | |
86 | Printf.printf "Match on line %s starting at %s: line %d offset %d\n" | |
87 | marker file line col; | |
88 | Ast_cocci.CONTEXT(pos,Ast_cocci.NOTHING) | |
89 | | (BefMark(marker),bef) -> | |
90 | Printf.printf "Match on line %s starting at %s: line %d offset %d\n" | |
91 | marker file line col; | |
951c7801 | 92 | Ast_cocci.CONTEXT(pos,Ast_cocci.BEFORE(bef,c)) |
34e49164 | 93 | | _ -> failwith "after not possible") |
951c7801 | 94 | | Ast_cocci.CONTEXT(pos,Ast_cocci.AFTER(aft,c)) -> |
34e49164 C |
95 | (match extract_sgrep_marker aft with |
96 | (NoMark,_) -> mck | |
97 | | (AftMark(marker),[]) -> | |
98 | Printf.printf "Match on line %s ending at %s: line %d offset %d\n" | |
99 | marker file line (col + String.length str); | |
100 | Ast_cocci.CONTEXT(pos,Ast_cocci.NOTHING) | |
101 | | (AftMark(marker),aft) -> | |
102 | Printf.printf "Match on line %s ending at %s: line %d offset %d\n" | |
103 | marker file line (col + String.length str); | |
951c7801 | 104 | Ast_cocci.CONTEXT(pos,Ast_cocci.AFTER(aft,c)) |
34e49164 | 105 | | _ -> failwith "before not possible") |
951c7801 | 106 | | Ast_cocci.CONTEXT(pos,Ast_cocci.BEFOREAFTER(bef,aft,c)) -> |
34e49164 C |
107 | (match extract_sgrep_marker bef with |
108 | (NoMark,_) -> | |
109 | (match extract_sgrep_marker aft with | |
110 | (NoMark,_) -> mck | |
111 | | (AftMark(marker),[]) -> | |
112 | Printf.printf | |
113 | "Match on line %s ending at %s: line %d offset %d\n" | |
114 | marker file line (col + String.length str); | |
951c7801 | 115 | Ast_cocci.CONTEXT(pos,Ast_cocci.BEFORE(bef,c)) |
34e49164 C |
116 | | (AftMark(marker),aft) -> |
117 | Printf.printf | |
118 | "Match on line %s ending at %s: line %d offset %d\n" | |
119 | marker file line (col + String.length str); | |
951c7801 | 120 | Ast_cocci.CONTEXT(pos,Ast_cocci.BEFOREAFTER(bef,aft,c)) |
34e49164 C |
121 | | _ -> failwith "before not possible") |
122 | | (BefMark(marker),[]) -> | |
123 | Printf.printf "Match on line %s starting at %s: line %d offset %d\n" | |
124 | marker file line col; | |
125 | (match extract_sgrep_marker aft with | |
951c7801 | 126 | (NoMark,_) -> Ast_cocci.CONTEXT(pos,Ast_cocci.AFTER(aft,c)) |
34e49164 C |
127 | | (AftMark(marker),[]) -> |
128 | Printf.printf | |
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.NOTHING) | |
132 | | (AftMark(marker),aft) -> | |
133 | Printf.printf | |
134 | "Match on line %s ending at %s: line %d offset %d\n" | |
135 | marker file line (col + String.length str); | |
951c7801 | 136 | Ast_cocci.CONTEXT(pos,Ast_cocci.AFTER(aft,c)) |
34e49164 C |
137 | | _ -> failwith "before not possible") |
138 | | (BefMark(marker),bef) -> | |
139 | Printf.printf "Match on line %s starting at %s: line %d offset %d\n" | |
140 | marker file line col; | |
141 | (match extract_sgrep_marker aft with | |
708f4980 | 142 | (NoMark,_) -> |
951c7801 | 143 | Ast_cocci.CONTEXT(pos,Ast_cocci.BEFOREAFTER(bef,aft,c)) |
34e49164 C |
144 | | (AftMark(marker),[]) -> |
145 | Printf.printf | |
146 | "Match on line %s ending at %s: line %d offset %d\n" | |
147 | marker file line (col + String.length str); | |
951c7801 | 148 | Ast_cocci.CONTEXT(pos,Ast_cocci.BEFORE(bef,c)) |
34e49164 C |
149 | | (AftMark(marker),aft) -> |
150 | Printf.printf | |
151 | "Match on line %s ending at %s: line %d offset %d\n" | |
152 | marker file line (col + String.length str); | |
951c7801 | 153 | Ast_cocci.CONTEXT(pos,Ast_cocci.BEFOREAFTER(bef,aft,c)) |
34e49164 C |
154 | | _ -> failwith "before not possible") |
155 | | _ -> failwith "after not possible") | |
156 | | _ -> failwith "unexpected plus code" |