Release coccinelle-0.1.8
[bpt/coccinelle.git] / parsing_cocci / ast0_cocci.mli
1 (* --------------------------------------------------------------------- *)
2 (* Modified code *)
3
4 type arity = OPT | UNIQUE | NONE
5
6 type token_info =
7 { tline_start : int; tline_end : int;
8 left_offset : int; right_offset : int }
9 val default_token_info : token_info
10
11 type mcodekind =
12 MINUS of (Ast_cocci.anything list list * token_info) ref
13 | PLUS
14 | CONTEXT of (Ast_cocci.anything Ast_cocci.befaft *
15 token_info * token_info) ref
16 | MIXED of (Ast_cocci.anything Ast_cocci.befaft *
17 token_info * token_info) ref
18
19 type position_info = { line_start : int; line_end : int;
20 logical_start : int; logical_end : int;
21 column : int; offset : int; }
22
23 type info = { pos_info : position_info;
24 attachable_start : bool; attachable_end : bool;
25 mcode_start : mcodekind list; mcode_end : mcodekind list;
26 (* the following are only for + code *)
27 strings_before : (string * position_info) list;
28 strings_after : (string * position_info) list }
29
30 type 'a mcode =
31 'a * arity * info * mcodekind * meta_pos ref (* pos, - only *) *
32 int (* adjacency_index *)
33
34 and 'a wrap =
35 { node : 'a;
36 info : info;
37 index : int ref;
38 mcodekind : mcodekind ref;
39 exp_ty : Type_cocci.typeC option ref; (* only for expressions *)
40 bef_aft : dots_bef_aft; (* only for statements *)
41 true_if_arg : bool; (* true if "arg_exp", only for exprs *)
42 true_if_test : bool; (* true if "test position", only for exprs *)
43 true_if_test_exp : bool;(* true if "test_exp from iso", only for exprs *)
44 (*nonempty if this represents the use of an iso*)
45 iso_info : (string*anything) list }
46
47 and dots_bef_aft =
48 NoDots | AddingBetweenDots of statement | DroppingBetweenDots of statement
49
50 (* for iso metavariables, true if they can only match nonmodified, unitary
51 metavariables
52 for SP metavariables, true if the metavariable is unitary (valid up to
53 isomorphism phase only) *)
54 and pure = Impure | Pure | Context | PureContext (* pure and only context *)
55
56 (* --------------------------------------------------------------------- *)
57 (* --------------------------------------------------------------------- *)
58 (* Dots *)
59
60 and 'a base_dots =
61 DOTS of 'a list
62 | CIRCLES of 'a list
63 | STARS of 'a list
64
65 and 'a dots = 'a base_dots wrap
66
67 (* --------------------------------------------------------------------- *)
68 (* Identifier *)
69
70 and base_ident =
71 Id of string mcode
72 | MetaId of Ast_cocci.meta_name mcode * ident list * pure
73 | MetaFunc of Ast_cocci.meta_name mcode * ident list * pure
74 | MetaLocalFunc of Ast_cocci.meta_name mcode * ident list * pure
75 | OptIdent of ident
76 | UniqueIdent of ident
77
78 and ident = base_ident wrap
79
80 (* --------------------------------------------------------------------- *)
81 (* Expression *)
82
83 and base_expression =
84 Ident of ident
85 | Constant of Ast_cocci.constant mcode
86 | FunCall of expression * string mcode (* ( *) *
87 expression dots * string mcode (* ) *)
88 | Assignment of expression * Ast_cocci.assignOp mcode * expression *
89 bool (* true if it can match an initialization *)
90 | CondExpr of expression * string mcode (* ? *) * expression option *
91 string mcode (* : *) * expression
92 | Postfix of expression * Ast_cocci.fixOp mcode
93 | Infix of expression * Ast_cocci.fixOp mcode
94 | Unary of expression * Ast_cocci.unaryOp mcode
95 | Binary of expression * Ast_cocci.binaryOp mcode * expression
96 | Nested of expression * Ast_cocci.binaryOp mcode * expression
97 | Paren of string mcode (* ( *) * expression *
98 string mcode (* ) *)
99 | ArrayAccess of expression * string mcode (* [ *) * expression *
100 string mcode (* ] *)
101 | RecordAccess of expression * string mcode (* . *) * ident
102 | RecordPtAccess of expression * string mcode (* -> *) * ident
103 | Cast of string mcode (* ( *) * typeC * string mcode (* ) *) *
104 expression
105 | SizeOfExpr of string mcode (* sizeof *) * expression
106 | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) *
107 typeC * string mcode (* ) *)
108 | TypeExp of typeC
109 | MetaErr of Ast_cocci.meta_name mcode * expression list * pure
110 | MetaExpr of Ast_cocci.meta_name mcode * expression list *
111 Type_cocci.typeC list option * Ast_cocci.form * pure
112 | MetaExprList of Ast_cocci.meta_name mcode (* only in arglists *) *
113 listlen * pure
114 | EComma of string mcode (* only in arglists *)
115 | DisjExpr of string mcode * expression list * string mcode list *
116 string mcode
117 | NestExpr of string mcode * expression dots * string mcode *
118 expression option * Ast_cocci.multi
119 | Edots of string mcode (* ... *) * expression option
120 | Ecircles of string mcode (* ooo *) * expression option
121 | Estars of string mcode (* *** *) * expression option
122 | OptExp of expression
123 | UniqueExp of expression
124
125 and expression = base_expression wrap
126
127 and listlen = Ast_cocci.meta_name mcode option
128
129 (* --------------------------------------------------------------------- *)
130 (* Types *)
131
132 and base_typeC =
133 ConstVol of Ast_cocci.const_vol mcode * typeC
134 | BaseType of Ast_cocci.baseType * string mcode list
135 | Signed of Ast_cocci.sign mcode * typeC option
136 | Pointer of typeC * string mcode (* * *)
137 | FunctionPointer of typeC *
138 string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
139 string mcode (* ( *)*parameter_list*string mcode(* ) *)
140 | FunctionType of typeC option *
141 string mcode (* ( *) * parameter_list *
142 string mcode (* ) *)
143 | Array of typeC * string mcode (* [ *) *
144 expression option * string mcode (* ] *)
145 | EnumName of string mcode (*enum*) * ident (* name *)
146 | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *)
147 | StructUnionDef of typeC (* either StructUnionName or metavar *) *
148 string mcode (* { *) * declaration dots * string mcode (* } *)
149 | TypeName of string mcode
150 | MetaType of Ast_cocci.meta_name mcode * pure
151 | DisjType of string mcode * typeC list * (* only after iso *)
152 string mcode list (* the |s *) * string mcode
153 | OptType of typeC
154 | UniqueType of typeC
155
156 and typeC = base_typeC wrap
157
158 (* --------------------------------------------------------------------- *)
159 (* Variable declaration *)
160 (* Even if the Cocci program specifies a list of declarations, they are
161 split out into multiple declarations of a single variable each. *)
162
163 and base_declaration =
164 Init of Ast_cocci.storage mcode option * typeC * ident *
165 string mcode (*=*) * initialiser * string mcode (*;*)
166 | UnInit of Ast_cocci.storage mcode option * typeC * ident *
167 string mcode (* ; *)
168 | TyDecl of typeC * string mcode (* ; *)
169 | MacroDecl of ident (* name *) * string mcode (* ( *) *
170 expression dots * string mcode (* ) *) * string mcode (* ; *)
171 | Typedef of string mcode (* typedef *) * typeC * typeC * string mcode (*;*)
172 | DisjDecl of string mcode * declaration list * string mcode list *
173 string mcode
174 | Ddots of string mcode (* ... *) * declaration option (* whencode *)
175 | OptDecl of declaration
176 | UniqueDecl of declaration
177
178 and declaration = base_declaration wrap
179
180 (* --------------------------------------------------------------------- *)
181 (* Initializers *)
182
183 and base_initialiser =
184 MetaInit of Ast_cocci.meta_name mcode * pure
185 | InitExpr of expression
186 | InitList of string mcode (*{*) * initialiser_list * string mcode (*}*)
187 | InitGccExt of
188 designator list (* name *) * string mcode (*=*) *
189 initialiser (* gccext: *)
190 | InitGccName of ident (* name *) * string mcode (*:*) *
191 initialiser
192 | IComma of string mcode
193 | Idots of string mcode (* ... *) * initialiser option (* whencode *)
194 | OptIni of initialiser
195 | UniqueIni of initialiser
196
197 and designator =
198 DesignatorField of string mcode (* . *) * ident
199 | DesignatorIndex of string mcode (* [ *) * expression * string mcode (* ] *)
200 | DesignatorRange of
201 string mcode (* [ *) * expression * string mcode (* ... *) *
202 expression * string mcode (* ] *)
203
204 and initialiser = base_initialiser wrap
205
206 and initialiser_list = initialiser dots
207
208 (* --------------------------------------------------------------------- *)
209 (* Parameter *)
210
211 and base_parameterTypeDef =
212 VoidParam of typeC
213 | Param of typeC * ident option
214 | MetaParam of Ast_cocci.meta_name mcode * pure
215 | MetaParamList of Ast_cocci.meta_name mcode * listlen * pure
216 | PComma of string mcode
217 | Pdots of string mcode (* ... *)
218 | Pcircles of string mcode (* ooo *)
219 | OptParam of parameterTypeDef
220 | UniqueParam of parameterTypeDef
221
222 and parameterTypeDef = base_parameterTypeDef wrap
223
224 and parameter_list = parameterTypeDef dots
225
226 (* --------------------------------------------------------------------- *)
227 (* #define Parameters *)
228
229 and base_define_param =
230 DParam of ident
231 | DPComma of string mcode
232 | DPdots of string mcode (* ... *)
233 | DPcircles of string mcode (* ooo *)
234 | OptDParam of define_param
235 | UniqueDParam of define_param
236
237 and define_param = base_define_param wrap
238
239 and base_define_parameters =
240 NoParams
241 | DParams of string mcode(*( *) * define_param dots * string mcode(* )*)
242
243 and define_parameters = base_define_parameters wrap
244
245 (* --------------------------------------------------------------------- *)
246 (* Statement*)
247
248 and base_statement =
249 Decl of (info * mcodekind) (* before the decl *) * declaration
250 | Seq of string mcode (* { *) * statement dots *
251 string mcode (* } *)
252 | ExprStatement of expression * string mcode (*;*)
253 | IfThen of string mcode (* if *) * string mcode (* ( *) *
254 expression * string mcode (* ) *) *
255 statement * (info * mcodekind)
256 | IfThenElse of string mcode (* if *) * string mcode (* ( *) *
257 expression * string mcode (* ) *) *
258 statement * string mcode (* else *) * statement *
259 (info * mcodekind)
260 | While of string mcode (* while *) * string mcode (* ( *) *
261 expression * string mcode (* ) *) *
262 statement * (info * mcodekind) (* after info *)
263 | Do of string mcode (* do *) * statement *
264 string mcode (* while *) * string mcode (* ( *) *
265 expression * string mcode (* ) *) *
266 string mcode (* ; *)
267 | For of string mcode (* for *) * string mcode (* ( *) *
268 expression option * string mcode (*;*) *
269 expression option * string mcode (*;*) *
270 expression option * string mcode (* ) *) * statement *
271 (info * mcodekind) (* after info *)
272 | Iterator of ident (* name *) * string mcode (* ( *) *
273 expression dots * string mcode (* ) *) *
274 statement * (info * mcodekind) (* after info *)
275 | Switch of string mcode (* switch *) * string mcode (* ( *) *
276 expression * string mcode (* ) *) * string mcode (* { *) *
277 case_line dots * string mcode (* } *)
278 | Break of string mcode (* break *) * string mcode (* ; *)
279 | Continue of string mcode (* continue *) * string mcode (* ; *)
280 | Label of ident * string mcode (* : *)
281 | Goto of string mcode (* goto *) * ident * string mcode (* ; *)
282 | Return of string mcode (* return *) * string mcode (* ; *)
283 | ReturnExpr of string mcode (* return *) * expression *
284 string mcode (* ; *)
285 | MetaStmt of Ast_cocci.meta_name mcode * pure
286 | MetaStmtList of Ast_cocci.meta_name mcode (*only in statement lists*) *
287 pure
288 | Exp of expression (* only in dotted statement lists *)
289 | TopExp of expression (* for macros body *)
290 | Ty of typeC (* only at top level *)
291 | TopInit of initialiser (* only at top level *)
292 | Disj of string mcode * statement dots list * string mcode list *
293 string mcode
294 | Nest of string mcode * statement dots * string mcode *
295 (statement dots,statement) whencode list * Ast_cocci.multi
296 | Dots of string mcode (* ... *) *
297 (statement dots,statement) whencode list
298 | Circles of string mcode (* ooo *) *
299 (statement dots,statement) whencode list
300 | Stars of string mcode (* *** *) *
301 (statement dots,statement) whencode list
302 | FunDecl of (info * mcodekind) (* before the function decl *) *
303 fninfo list * ident (* name *) *
304 string mcode (* ( *) * parameter_list * string mcode (* ) *) *
305 string mcode (* { *) * statement dots *
306 string mcode (* } *)
307 | Include of string mcode (* #include *) * Ast_cocci.inc_file mcode(* file *)
308 | Define of string mcode (* #define *) * ident (* name *) *
309 define_parameters (*params*) * statement dots
310 | OptStm of statement
311 | UniqueStm of statement
312
313 and fninfo =
314 FStorage of Ast_cocci.storage mcode
315 | FType of typeC
316 | FInline of string mcode
317 | FAttr of string mcode
318
319 and ('a,'b) whencode =
320 WhenNot of 'a
321 | WhenAlways of 'b
322 | WhenModifier of Ast_cocci.when_modifier
323 | WhenNotTrue of expression
324 | WhenNotFalse of expression
325
326 and statement = base_statement wrap
327
328 and base_case_line =
329 Default of string mcode (* default *) * string mcode (*:*) * statement dots
330 | Case of string mcode (* case *) * expression * string mcode (*:*) *
331 statement dots
332 | OptCase of case_line
333
334 and case_line = base_case_line wrap
335
336 (* --------------------------------------------------------------------- *)
337 (* Positions *)
338
339 and meta_pos =
340 MetaPos of Ast_cocci.meta_name mcode * Ast_cocci.meta_name list *
341 Ast_cocci.meta_collect
342 | NoMetaPos
343
344 (* --------------------------------------------------------------------- *)
345 (* Top-level code *)
346
347 and base_top_level =
348 DECL of statement
349 | CODE of statement dots
350 | FILEINFO of string mcode (* old file *) * string mcode (* new file *)
351 | ERRORWORDS of expression list
352 | OTHER of statement (* temporary, disappears after top_level.ml *)
353
354 and top_level = base_top_level wrap
355 and rule = top_level list
356
357 and parsed_rule =
358 CocciRule of
359 (rule * Ast_cocci.metavar list *
360 (string list * string list * Ast_cocci.dependency * string *
361 Ast_cocci.exists)) *
362 (rule * Ast_cocci.metavar list) * Ast_cocci.ruletype
363 | ScriptRule of
364 string * Ast_cocci.dependency * (string * Ast_cocci.meta_name) list *
365 string
366 | InitialScriptRule of string * string
367 | FinalScriptRule of string * string
368
369 (* --------------------------------------------------------------------- *)
370
371 and anything =
372 DotsExprTag of expression dots
373 | DotsInitTag of initialiser dots
374 | DotsParamTag of parameterTypeDef dots
375 | DotsStmtTag of statement dots
376 | DotsDeclTag of declaration dots
377 | DotsCaseTag of case_line dots
378 | IdentTag of ident
379 | ExprTag of expression
380 | ArgExprTag of expression (* for isos *)
381 | TestExprTag of expression (* for isos *)
382 | TypeCTag of typeC
383 | ParamTag of parameterTypeDef
384 | InitTag of initialiser
385 | DeclTag of declaration
386 | StmtTag of statement
387 | CaseLineTag of case_line
388 | TopTag of top_level
389 | IsoWhenTag of Ast_cocci.when_modifier (*only for when code, in iso phase*)
390 | IsoWhenTTag of expression(*only for when code, in iso phase*)
391 | IsoWhenFTag of expression(*only for when code, in iso phase*)
392 | MetaPosTag of meta_pos (* only in iso phase *)
393
394 val dotsExpr : expression dots -> anything
395 val dotsInit : initialiser dots -> anything
396 val dotsParam : parameterTypeDef dots -> anything
397 val dotsStmt : statement dots -> anything
398 val dotsDecl : declaration dots -> anything
399 val dotsCase : case_line dots -> anything
400 val ident : ident -> anything
401 val expr : expression -> anything
402 val typeC : typeC -> anything
403 val param : parameterTypeDef -> anything
404 val ini : initialiser -> anything
405 val decl : declaration -> anything
406 val stmt : statement -> anything
407 val case_line : case_line -> anything
408 val top : top_level -> anything
409
410 (* --------------------------------------------------------------------- *)
411
412 val undots : 'a dots -> 'a list
413
414 (* --------------------------------------------------------------------- *)
415 (* Avoid cluttering the parser. Calculated in compute_lines.ml. *)
416
417 val default_info : unit -> info
418 val default_befaft : unit -> mcodekind
419 val context_befaft : unit -> mcodekind
420 val wrap : 'a -> 'a wrap
421 val context_wrap : 'a -> 'a wrap
422 val unwrap : 'a wrap -> 'a
423 val unwrap_mcode : 'a mcode -> 'a
424 val rewrap : 'a wrap -> 'b -> 'b wrap
425 val rewrap_mcode : 'a mcode -> 'b -> 'b mcode
426 val copywrap : 'a wrap -> 'b -> 'b wrap
427 val get_pos : 'a mcode -> meta_pos
428 val get_pos_ref : 'a mcode -> meta_pos ref
429 val set_pos : meta_pos -> 'a mcode -> 'a mcode
430 val get_info : 'a wrap -> info
431 val set_info : 'a wrap -> info -> 'a wrap
432 val get_index : 'a wrap -> int
433 val set_index : 'a wrap -> int -> unit
434 val get_line : 'a wrap -> int
435 val get_line_end : 'a wrap -> int
436 val get_mcodekind : 'a wrap -> mcodekind
437 val get_mcode_mcodekind : 'a mcode -> mcodekind
438 val get_mcodekind_ref : 'a wrap -> mcodekind ref
439 val set_mcodekind : 'a wrap -> mcodekind -> unit
440 val set_type : 'a wrap -> Type_cocci.typeC option -> unit
441 val get_type : 'a wrap -> Type_cocci.typeC option
442 val set_dots_bef_aft : statement -> dots_bef_aft -> statement
443 val get_dots_bef_aft : 'a wrap -> dots_bef_aft
444 val set_arg_exp : expression -> expression
445 val get_arg_exp : expression -> bool
446 val set_test_pos : expression -> expression
447 val get_test_pos : 'a wrap -> bool
448 val set_test_exp : expression -> expression
449 val get_test_exp : 'a wrap -> bool
450 val set_iso : 'a wrap -> (string*anything) list -> 'a wrap
451 val get_iso : 'a wrap -> (string*anything) list
452 val fresh_index : unit -> int
453 val set_mcode_data : 'a -> 'a mcode -> 'a mcode
454 val make_mcode : 'a -> 'a mcode
455 val make_mcode_info : 'a -> info -> 'a mcode
456
457 val ast0_type_to_type : typeC -> Type_cocci.typeC
458 val reverse_type : Type_cocci.typeC -> base_typeC
459 exception TyConv
460
461 val lub_pure : pure -> pure -> pure
462
463 (* --------------------------------------------------------------------- *)
464
465 val rule_name : string ref (* for the convenience of the parser *)