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 | ||
34e49164 | 27 | (* create an index for each constructor *) |
17ba0788 | 28 | (* current max is 157 *) |
34e49164 C |
29 | |
30 | (* doesn't really work - requires that identical terms with no token | |
31 | subterms (eg dots) not appear on the same line *) | |
32 | ||
33 | module Ast = Ast_cocci | |
34 | module Ast0 = Ast0_cocci | |
35 | ||
36 | (* if a dot list is empty, add the starting line of the dot list to the | |
37 | address. Otherwise add 0. An empty dot list should only match with another | |
38 | empty one. *) | |
39 | let expression_dots d = | |
0708f913 | 40 | let ln = (Ast0.get_info d).Ast0.pos_info.Ast0.line_start in |
34e49164 C |
41 | match Ast0.unwrap d with |
42 | Ast0.DOTS(l) -> 1::(if l = [] then [ln] else [0]) | |
43 | | Ast0.CIRCLES(l) -> 2::(if l = [] then [ln] else [0]) | |
44 | | Ast0.STARS(l) -> 3::(if l = [] then [ln] else [0]) | |
faf9a90c | 45 | |
34e49164 | 46 | let initialiser_dots d = |
0708f913 | 47 | let ln = (Ast0.get_info d).Ast0.pos_info.Ast0.line_start in |
34e49164 C |
48 | match Ast0.unwrap d with |
49 | Ast0.DOTS(l) -> 113::(if l = [] then [ln] else [0]) | |
50 | | Ast0.CIRCLES(l) -> 114::(if l = [] then [ln] else [0]) | |
51 | | Ast0.STARS(l) -> 115::(if l = [] then [ln] else [0]) | |
faf9a90c | 52 | |
34e49164 | 53 | let parameter_dots d = |
0708f913 | 54 | let ln = (Ast0.get_info d).Ast0.pos_info.Ast0.line_start in |
34e49164 C |
55 | match Ast0.unwrap d with |
56 | Ast0.DOTS(l) -> 4::(if l = [] then [ln] else [0]) | |
57 | | Ast0.CIRCLES(l) -> 5::(if l = [] then [ln] else [0]) | |
58 | | Ast0.STARS(l) -> 6::(if l = [] then [ln] else [0]) | |
faf9a90c | 59 | |
34e49164 | 60 | let statement_dots d = |
0708f913 | 61 | let ln = (Ast0.get_info d).Ast0.pos_info.Ast0.line_start in |
34e49164 C |
62 | match Ast0.unwrap d with |
63 | Ast0.DOTS(l) -> 7::(if l = [] then [ln] else [0]) | |
64 | | Ast0.CIRCLES(l) -> 8::(if l = [] then [ln] else [0]) | |
65 | | Ast0.STARS(l) -> 9::(if l = [] then [ln] else [0]) | |
faf9a90c | 66 | |
34e49164 | 67 | let declaration_dots d = |
0708f913 | 68 | let ln = (Ast0.get_info d).Ast0.pos_info.Ast0.line_start in |
34e49164 C |
69 | match Ast0.unwrap d with |
70 | Ast0.DOTS(l) -> 134::(if l = [] then [ln] else [0]) | |
71 | | Ast0.CIRCLES(l) -> 135::(if l = [] then [ln] else [0]) | |
72 | | Ast0.STARS(l) -> 136::(if l = [] then [ln] else [0]) | |
faf9a90c | 73 | |
34e49164 | 74 | let case_line_dots d = |
0708f913 | 75 | let ln = (Ast0.get_info d).Ast0.pos_info.Ast0.line_start in |
34e49164 C |
76 | match Ast0.unwrap d with |
77 | Ast0.DOTS(l) -> 138::(if l = [] then [ln] else [0]) | |
78 | | Ast0.CIRCLES(l) -> 139::(if l = [] then [ln] else [0]) | |
79 | | Ast0.STARS(l) -> 140::(if l = [] then [ln] else [0]) | |
faf9a90c | 80 | |
34e49164 C |
81 | let ident i = |
82 | match Ast0.unwrap i with | |
951c7801 | 83 | Ast0.Id(name) -> [10] |
8babbc8f | 84 | | Ast0.MetaId(name,_,_,_) -> [11] |
951c7801 C |
85 | | Ast0.MetaFunc(name,_,_) -> [12] |
86 | | Ast0.MetaLocalFunc(name,_,_) -> [13] | |
d3f655c6 | 87 | | Ast0.DisjId(_,id_list,_,_) -> [152] |
951c7801 C |
88 | | Ast0.OptIdent(id) -> [14] |
89 | | Ast0.UniqueIdent(id) -> [15] | |
faf9a90c | 90 | |
34e49164 C |
91 | let expression e = |
92 | match Ast0.unwrap e with | |
93 | Ast0.Ident(id) -> [17] | |
94 | | Ast0.Constant(const) -> [18] | |
95 | | Ast0.FunCall(fn,lp,args,rp) -> [19] | |
96 | | Ast0.Assignment(left,op,right,simple) -> [20] | |
17ba0788 | 97 | | Ast0.Sequence(left,op,right) -> [156] |
34e49164 C |
98 | | Ast0.CondExpr(exp1,why,exp2,colon,exp3) -> [21] |
99 | | Ast0.Postfix(exp,op) -> [22] | |
100 | | Ast0.Infix(exp,op) -> [23] | |
101 | | Ast0.Unary(exp,op) -> [24] | |
102 | | Ast0.Binary(left,op,right) -> [25] | |
103 | | Ast0.Nested(left,op,right) -> failwith "nested in index not possible" | |
104 | | Ast0.Paren(lp,exp,rp) -> [26] | |
105 | | Ast0.ArrayAccess(exp1,lb,exp2,rb) -> [27] | |
106 | | Ast0.RecordAccess(exp,pt,field) -> [28] | |
107 | | Ast0.RecordPtAccess(exp,ar,field) -> [29] | |
108 | | Ast0.Cast(lp,ty,rp,exp) -> [30] | |
109 | | Ast0.SizeOfExpr(szf,exp) -> [98] (* added after *) | |
110 | | Ast0.SizeOfType(szf,lp,ty,rp) -> [99] (* added after *) | |
111 | | Ast0.TypeExp(ty) -> [123] (* added after *) | |
7fe62b65 | 112 | | Ast0.Constructor(lp,ty,rp,init) -> [155] |
34e49164 C |
113 | | Ast0.MetaErr(name,_,_) -> [32] |
114 | | Ast0.MetaExpr(name,_,ty,_,_) -> [33] | |
115 | | Ast0.MetaExprList(name,_,_) -> [34] | |
116 | | Ast0.EComma(cm) -> [35] | |
117 | | Ast0.DisjExpr(_,expr_list,_,_) -> [36] | |
118 | | Ast0.NestExpr(_,expr_dots,_,_,_) -> [37] | |
119 | | Ast0.Edots(dots,whencode) -> [38] | |
120 | | Ast0.Ecircles(dots,whencode) -> [39] | |
121 | | Ast0.Estars(dots,whencode) -> [40] | |
122 | | Ast0.OptExp(exp) -> [41] | |
123 | | Ast0.UniqueExp(exp) -> [42] | |
17ba0788 | 124 | | Ast0.AsExpr _ -> failwith "not possible" |
34e49164 C |
125 | |
126 | let typeC t = | |
127 | match Ast0.unwrap t with | |
128 | Ast0.ConstVol(cv,ty) -> [44] | |
faf9a90c C |
129 | | Ast0.BaseType(ty,strings) -> [48] |
130 | | Ast0.Signed(sign,ty) -> [129] | |
34e49164 C |
131 | | Ast0.Pointer(ty,star) -> [49] |
132 | | Ast0.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) -> [131] | |
133 | | Ast0.FunctionType(ty,lp1,params,rp1) -> [132] | |
134 | | Ast0.Array(ty,lb,size,rb) -> [50] | |
faf9a90c | 135 | | Ast0.EnumName(kind,name) -> [146] |
c491d8ee | 136 | | Ast0.EnumDef(ty,lb,decls,rb) -> [150] |
34e49164 C |
137 | | Ast0.StructUnionName(kind,name) -> [51] |
138 | | Ast0.StructUnionDef(ty,lb,decls,rb) -> [117] | |
139 | | Ast0.TypeName(name) -> [52] | |
140 | | Ast0.MetaType(name,_) -> [53] | |
141 | | Ast0.DisjType(_,type_list,_,_) -> [130] | |
142 | | Ast0.OptType(ty) -> [45] | |
143 | | Ast0.UniqueType(ty) -> [46] | |
17ba0788 | 144 | | Ast0.AsType _ -> failwith "not possible" |
faf9a90c | 145 | |
34e49164 C |
146 | let declaration d = |
147 | match Ast0.unwrap d with | |
413ffc02 C |
148 | Ast0.MetaDecl(name,_) -> [148] |
149 | | Ast0.MetaField(name,_) -> [149] | |
190f1acf | 150 | | Ast0.MetaFieldList(name,_,_) -> [152] |
413ffc02 | 151 | | Ast0.Init(stg,ty,id,eq,exp,sem) -> [54] |
34e49164 C |
152 | | Ast0.UnInit(stg,ty,id,sem) -> [55] |
153 | | Ast0.MacroDecl(name,lp,args,rp,sem) -> [137] | |
17ba0788 | 154 | | Ast0.MacroDeclInit(name,lp,args,rp,eq,ini,sem) -> [157] |
34e49164 C |
155 | | Ast0.TyDecl(ty,sem) -> [116] |
156 | | Ast0.Typedef(stg,ty,id,sem) -> [143] | |
157 | | Ast0.DisjDecl(_,decls,_,_) -> [97] (* added after *) | |
158 | | Ast0.Ddots(dots,whencode) -> [133] | |
159 | | Ast0.OptDecl(decl) -> [56] | |
160 | | Ast0.UniqueDecl(decl) -> [57] | |
17ba0788 | 161 | | Ast0.AsDecl _ -> failwith "not possible" |
34e49164 C |
162 | |
163 | let initialiser i = | |
164 | match Ast0.unwrap i with | |
113803cf | 165 | Ast0.MetaInit(nm,_) -> [106] (* added after *) |
8f657093 | 166 | | Ast0.MetaInitList(nm,_,_) -> [153] (* added after *) |
113803cf | 167 | | Ast0.InitExpr(exp) -> [102] |
c491d8ee | 168 | | Ast0.InitList(lb,initlist,rb,ordered) -> [103] |
113803cf | 169 | | Ast0.InitGccExt(designators,eq,ini) -> [104] |
34e49164 | 170 | | Ast0.InitGccName(name,eq,ini) -> [105] |
34e49164 C |
171 | | Ast0.IComma(cm) -> [108] |
172 | | Ast0.Idots(d,whencode) -> [109] | |
173 | | Ast0.OptIni(id) -> [110] | |
174 | | Ast0.UniqueIni(id) -> [111] | |
17ba0788 | 175 | | Ast0.AsInit _ -> failwith "not possible" |
34e49164 C |
176 | |
177 | let parameterTypeDef p = | |
178 | match Ast0.unwrap p with | |
179 | Ast0.VoidParam(ty) -> [59] | |
180 | | Ast0.Param(ty,id) -> [60] | |
181 | | Ast0.MetaParam(name,_) -> [61] | |
182 | | Ast0.MetaParamList(name,_,_) -> [62] | |
183 | | Ast0.PComma(cm) -> [63] | |
184 | | Ast0.Pdots(dots) -> [64] | |
185 | | Ast0.Pcircles(dots) -> [65] | |
186 | | Ast0.OptParam(param) -> [66] | |
187 | | Ast0.UniqueParam(param) -> [67] | |
faf9a90c | 188 | |
34e49164 C |
189 | let statement s = |
190 | match Ast0.unwrap s with | |
191 | Ast0.FunDecl(bef,fninfo,name,lp,params,rp,lbrace,body,rbrace) -> [68] | |
192 | | Ast0.Decl(bef,decl) -> [69] | |
193 | | Ast0.Seq(lbrace,body,rbrace) -> [70] | |
194 | | Ast0.ExprStatement(exp,sem) -> [71] | |
195 | | Ast0.IfThen(iff,lp,exp,rp,branch1,aft) -> [72] | |
196 | | Ast0.IfThenElse(iff,lp,exp,rp,branch1,els,branch2,aft) -> [73] | |
197 | | Ast0.While(whl,lp,exp,rp,body,_) -> [74] | |
198 | | Ast0.Do(d,body,whl,lp,exp,rp,sem) -> [75] | |
199 | | Ast0.For(fr,lp,e1,sem1,e2,sem2,e3,rp,body,_) -> [76] | |
200 | | Ast0.Iterator(nm,lp,args,rp,body,_) -> [142] | |
fc1ad971 | 201 | | Ast0.Switch(switch,lp,exp,rp,lb,decls,cases,rb) -> [125] |
34e49164 C |
202 | | Ast0.Break(br,sem) -> [100] |
203 | | Ast0.Continue(cont,sem) -> [101] | |
204 | | Ast0.Label(l,dd) -> [144] | |
205 | | Ast0.Goto(goto,l,sem) -> [145] | |
206 | | Ast0.Return(ret,sem) -> [77] | |
207 | | Ast0.ReturnExpr(ret,exp,sem) -> [78] | |
208 | | Ast0.MetaStmt(name,_) -> [79] | |
209 | | Ast0.MetaStmtList(name,_) -> [80] | |
210 | | Ast0.Disj(_,statement_dots_list,_,_) -> [81] | |
211 | | Ast0.Nest(_,stmt_dots,_,_,_) -> [82] | |
212 | | Ast0.Exp(exp) -> [83] | |
213 | | Ast0.TopExp(exp) -> [141] | |
214 | | Ast0.Ty(ty) -> [124] | |
1be43e12 | 215 | | Ast0.TopInit(init) -> [146] |
34e49164 C |
216 | | Ast0.Dots(d,whencode) -> [84] |
217 | | Ast0.Circles(d,whencode) -> [85] | |
218 | | Ast0.Stars(d,whencode) -> [86] | |
219 | | Ast0.Include(inc,name) -> [118] | |
3a314143 | 220 | | Ast0.Undef(def,id) -> [151] |
34e49164 C |
221 | | Ast0.Define(def,id,params,body) -> [119] |
222 | | Ast0.OptStm(re) -> [87] | |
223 | | Ast0.UniqueStm(re) -> [88] | |
17ba0788 | 224 | | Ast0.AsStmt _ -> failwith "not possible" |
34e49164 C |
225 | |
226 | let case_line c = | |
227 | match Ast0.unwrap c with | |
228 | Ast0.Default(def,colon,code) -> [126] | |
229 | | Ast0.Case(case,exp,colon,code) -> [127] | |
fc1ad971 | 230 | | Ast0.DisjCase(_,case_lines,_,_) -> [107] |
34e49164 C |
231 | | Ast0.OptCase(case) -> [128] |
232 | ||
233 | let top_level t = | |
234 | match Ast0.unwrap t with | |
65038c61 | 235 | Ast0.NONDECL(stmt) -> [90] |
34e49164 C |
236 | | Ast0.FILEINFO(old_file,new_file) -> [92] |
237 | | Ast0.CODE(stmt_dots) -> [94] | |
238 | | Ast0.ERRORWORDS(exps) -> [95] | |
239 | | Ast0.OTHER(_) -> [96] | |
65038c61 | 240 | | Ast0.TOPCODE(_) -> [154] |
34e49164 C |
241 | |
242 | (* 99-101 already used *) |