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