Release coccinelle-0.1.10
[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 statement (*decl*) dots *
278 case_line dots * string mcode (* } *)
279 | Break of string mcode (* break *) * string mcode (* ; *)
280 | Continue of string mcode (* continue *) * string mcode (* ; *)
281 | Label of ident * string mcode (* : *)
282 | Goto of string mcode (* goto *) * ident * string mcode (* ; *)
283 | Return of string mcode (* return *) * string mcode (* ; *)
284 | ReturnExpr of string mcode (* return *) * expression *
285 string mcode (* ; *)
286 | MetaStmt of Ast_cocci.meta_name mcode * pure
287 | MetaStmtList of Ast_cocci.meta_name mcode (*only in statement lists*) *
288 pure
289 | Exp of expression (* only in dotted statement lists *)
290 | TopExp of expression (* for macros body *)
291 | Ty of typeC (* only at top level *)
292 | TopInit of initialiser (* only at top level *)
293 | Disj of string mcode * statement dots list * string mcode list *
294 string mcode
295 | Nest of string mcode * statement dots * string mcode *
296 (statement dots,statement) whencode list * Ast_cocci.multi
297 | Dots of string mcode (* ... *) *
298 (statement dots,statement) whencode list
299 | Circles of string mcode (* ooo *) *
300 (statement dots,statement) whencode list
301 | Stars of string mcode (* *** *) *
302 (statement dots,statement) whencode list
303 | FunDecl of (info * mcodekind) (* before the function decl *) *
304 fninfo list * ident (* name *) *
305 string mcode (* ( *) * parameter_list * string mcode (* ) *) *
306 string mcode (* { *) * statement dots *
307 string mcode (* } *)
308 | Include of string mcode (* #include *) * Ast_cocci.inc_file mcode(* file *)
309 | Define of string mcode (* #define *) * ident (* name *) *
310 define_parameters (*params*) * statement dots
311 | OptStm of statement
312 | UniqueStm of statement
313
314 and fninfo =
315 FStorage of Ast_cocci.storage mcode
316 | FType of typeC
317 | FInline of string mcode
318 | FAttr of string mcode
319
320 and ('a,'b) whencode =
321 WhenNot of 'a
322 | WhenAlways of 'b
323 | WhenModifier of Ast_cocci.when_modifier
324 | WhenNotTrue of expression
325 | WhenNotFalse of expression
326
327 and statement = base_statement wrap
328
329 and base_case_line =
330 Default of string mcode (* default *) * string mcode (*:*) * statement dots
331 | Case of string mcode (* case *) * expression * string mcode (*:*) *
332 statement dots
333 | DisjCase of string mcode * case_line list *
334 string mcode list (* the |s *) * string mcode
335 | OptCase of case_line
336
337 and case_line = base_case_line wrap
338
339 (* --------------------------------------------------------------------- *)
340 (* Positions *)
341
342 and meta_pos =
343 MetaPos of Ast_cocci.meta_name mcode * Ast_cocci.meta_name list *
344 Ast_cocci.meta_collect
345 | NoMetaPos
346
347 (* --------------------------------------------------------------------- *)
348 (* Top-level code *)
349
350 and base_top_level =
351 DECL of statement
352 | CODE of statement dots
353 | FILEINFO of string mcode (* old file *) * string mcode (* new file *)
354 | ERRORWORDS of expression list
355 | OTHER of statement (* temporary, disappears after top_level.ml *)
356
357 and top_level = base_top_level wrap
358 and rule = top_level list
359
360 and parsed_rule =
361 CocciRule of
362 (rule * Ast_cocci.metavar list *
363 (string list * string list * Ast_cocci.dependency * string *
364 Ast_cocci.exists)) *
365 (rule * Ast_cocci.metavar list) * Ast_cocci.ruletype
366 | ScriptRule of
367 string * Ast_cocci.dependency * (string * Ast_cocci.meta_name) list *
368 string
369 | InitialScriptRule of string * string
370 | FinalScriptRule of string * string
371
372 (* --------------------------------------------------------------------- *)
373
374 and anything =
375 DotsExprTag of expression dots
376 | DotsInitTag of initialiser dots
377 | DotsParamTag of parameterTypeDef dots
378 | DotsStmtTag of statement dots
379 | DotsDeclTag of declaration dots
380 | DotsCaseTag of case_line dots
381 | IdentTag of ident
382 | ExprTag of expression
383 | ArgExprTag of expression (* for isos *)
384 | TestExprTag of expression (* for isos *)
385 | TypeCTag of typeC
386 | ParamTag of parameterTypeDef
387 | InitTag of initialiser
388 | DeclTag of declaration
389 | StmtTag of statement
390 | CaseLineTag of case_line
391 | TopTag of top_level
392 | IsoWhenTag of Ast_cocci.when_modifier (*only for when code, in iso phase*)
393 | IsoWhenTTag of expression(*only for when code, in iso phase*)
394 | IsoWhenFTag of expression(*only for when code, in iso phase*)
395 | MetaPosTag of meta_pos (* only in iso phase *)
396
397 val dotsExpr : expression dots -> anything
398 val dotsInit : initialiser dots -> anything
399 val dotsParam : parameterTypeDef dots -> anything
400 val dotsStmt : statement dots -> anything
401 val dotsDecl : declaration dots -> anything
402 val dotsCase : case_line dots -> anything
403 val ident : ident -> anything
404 val expr : expression -> anything
405 val typeC : typeC -> anything
406 val param : parameterTypeDef -> anything
407 val ini : initialiser -> anything
408 val decl : declaration -> anything
409 val stmt : statement -> anything
410 val case_line : case_line -> anything
411 val top : top_level -> anything
412
413 (* --------------------------------------------------------------------- *)
414
415 val undots : 'a dots -> 'a list
416
417 (* --------------------------------------------------------------------- *)
418 (* Avoid cluttering the parser. Calculated in compute_lines.ml. *)
419
420 val default_info : unit -> info
421 val default_befaft : unit -> mcodekind
422 val context_befaft : unit -> mcodekind
423 val wrap : 'a -> 'a wrap
424 val context_wrap : 'a -> 'a wrap
425 val unwrap : 'a wrap -> 'a
426 val unwrap_mcode : 'a mcode -> 'a
427 val rewrap : 'a wrap -> 'b -> 'b wrap
428 val rewrap_mcode : 'a mcode -> 'b -> 'b mcode
429 val copywrap : 'a wrap -> 'b -> 'b wrap
430 val get_pos : 'a mcode -> meta_pos
431 val get_pos_ref : 'a mcode -> meta_pos ref
432 val set_pos : meta_pos -> 'a mcode -> 'a mcode
433 val get_info : 'a wrap -> info
434 val set_info : 'a wrap -> info -> 'a wrap
435 val get_index : 'a wrap -> int
436 val set_index : 'a wrap -> int -> unit
437 val get_line : 'a wrap -> int
438 val get_line_end : 'a wrap -> int
439 val get_mcodekind : 'a wrap -> mcodekind
440 val get_mcode_mcodekind : 'a mcode -> mcodekind
441 val get_mcodekind_ref : 'a wrap -> mcodekind ref
442 val set_mcodekind : 'a wrap -> mcodekind -> unit
443 val set_type : 'a wrap -> Type_cocci.typeC option -> unit
444 val get_type : 'a wrap -> Type_cocci.typeC option
445 val set_dots_bef_aft : statement -> dots_bef_aft -> statement
446 val get_dots_bef_aft : 'a wrap -> dots_bef_aft
447 val set_arg_exp : expression -> expression
448 val get_arg_exp : expression -> bool
449 val set_test_pos : expression -> expression
450 val get_test_pos : 'a wrap -> bool
451 val set_test_exp : expression -> expression
452 val get_test_exp : 'a wrap -> bool
453 val set_iso : 'a wrap -> (string*anything) list -> 'a wrap
454 val get_iso : 'a wrap -> (string*anything) list
455 val fresh_index : unit -> int
456 val set_mcode_data : 'a -> 'a mcode -> 'a mcode
457 val make_mcode : 'a -> 'a mcode
458 val make_mcode_info : 'a -> info -> 'a mcode
459
460 val ast0_type_to_type : typeC -> Type_cocci.typeC
461 val reverse_type : Type_cocci.typeC -> base_typeC
462 exception TyConv
463
464 val lub_pure : pure -> pure -> pure
465
466 (* --------------------------------------------------------------------- *)
467
468 val rule_name : string ref (* for the convenience of the parser *)