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