Release coccinelle-0.1.1
[bpt/coccinelle.git] / parsing_cocci / ast_cocci.mli
CommitLineData
34e49164
C
1(* --------------------------------------------------------------------- *)
2(* Modified code *)
3
4type info = { line : int; column : int;
5 strbef : string list; straft : string list }
6type line = int
7type meta_name = string * string
8type 'a wrap =
9 {node : 'a;
10 node_line : line;
11 free_vars : meta_name list; (*free vars*)
12 minus_free_vars : meta_name list; (*minus free vars*)
13 fresh_vars : meta_name list; (*fresh vars*)
14 inherited : meta_name list; (*inherited vars*)
15 saved_witness : meta_name list; (*witness vars*)
16 bef_aft : dots_bef_aft;
17 pos_info : meta_name mcode option; (* pos info, try not to duplicate *)
18 true_if_test_exp : bool;(* true if "test_exp from iso", only for exprs *)
19 (* isos relevant to the term; ultimately only used for rule_elems *)
20 iso_info : (string*anything) list }
21
22and 'a befaft =
23 BEFORE of 'a list list
24 | AFTER of 'a list list
25 | BEFOREAFTER of 'a list list * 'a list list
26 | NOTHING
27
28and 'a mcode = 'a * info * mcodekind * meta_pos (* pos variable *)
29 (* pos is an offset indicating where in the C code the mcodekind has an
30 effect *)
31 and mcodekind =
32 MINUS of pos * anything list list
33 | CONTEXT of pos * anything befaft
34 | PLUS
35 and fixpos =
36 Real of int (* charpos *) | Virt of int * int (* charpos + offset *)
37 and pos = NoPos | DontCarePos | FixPos of (fixpos * fixpos)
38
39and dots_bef_aft =
40 NoDots
41 | AddingBetweenDots of statement * int (*index of let var*)
42 | DroppingBetweenDots of statement * int (*index of let var*)
43
44and inherited = Type_cocci.inherited
45and keep_binding = Type_cocci.keep_binding
46and multi = bool (*true if a nest is one or more, false if it is zero or more*)
47
48and end_info =
49 meta_name list (*free vars*) * meta_name list (*inherited vars*) *
50 meta_name list (*witness vars*) * mcodekind
51
52(* --------------------------------------------------------------------- *)
53(* Metavariables *)
54
55and arity = UNIQUE | OPT | MULTI | NONE
56
57and metavar =
58 MetaIdDecl of arity * meta_name (* name *)
59 | MetaFreshIdDecl of arity * meta_name (* name *)
60 | MetaTypeDecl of arity * meta_name (* name *)
61 | MetaListlenDecl of meta_name (* name *)
62 | MetaParamDecl of arity * meta_name (* name *)
63 | MetaParamListDecl of arity * meta_name (*name*) * meta_name option (*len*)
64 | MetaConstDecl of
65 arity * meta_name (* name *) * Type_cocci.typeC list option
66 | MetaErrDecl of arity * meta_name (* name *)
67 | MetaExpDecl of
68 arity * meta_name (* name *) * Type_cocci.typeC list option
69 | MetaIdExpDecl of
70 arity * meta_name (* name *) * Type_cocci.typeC list option
71 | MetaLocalIdExpDecl of
72 arity * meta_name (* name *) * Type_cocci.typeC list option
73 | MetaExpListDecl of arity * meta_name (*name*) * meta_name option (*len*)
74 | MetaStmDecl of arity * meta_name (* name *)
75 | MetaStmListDecl of arity * meta_name (* name *)
76 | MetaFuncDecl of arity * meta_name (* name *)
77 | MetaLocalFuncDecl of arity * meta_name (* name *)
78 | MetaPosDecl of arity * meta_name (* name *)
79 | MetaDeclarerDecl of arity * meta_name (* name *)
80 | MetaIteratorDecl of arity * meta_name (* name *)
81
82(* --------------------------------------------------------------------- *)
83(* --------------------------------------------------------------------- *)
84(* Dots *)
85
86and 'a base_dots =
87 DOTS of 'a list
88 | CIRCLES of 'a list
89 | STARS of 'a list
90
91and 'a dots = 'a base_dots wrap
92
93(* --------------------------------------------------------------------- *)
94(* Identifier *)
95
96and base_ident =
97 Id of string mcode
98
99 | MetaId of meta_name mcode * ident list * keep_binding * inherited
100 | MetaFunc of meta_name mcode * ident list * keep_binding * inherited
101 | MetaLocalFunc of meta_name mcode * ident list * keep_binding * inherited
102
103 | OptIdent of ident
104 | UniqueIdent of ident
105
106and ident = base_ident wrap
107
108(* --------------------------------------------------------------------- *)
109(* Expression *)
110
111and base_expression =
112 Ident of ident
113 | Constant of constant mcode
114 | FunCall of expression * string mcode (* ( *) *
115 expression dots * string mcode (* ) *)
116 | Assignment of expression * assignOp mcode * expression * bool
117 | CondExpr of expression * string mcode (* ? *) * expression option *
118 string mcode (* : *) * expression
119 | Postfix of expression * fixOp mcode
120 | Infix of expression * fixOp mcode
121 | Unary of expression * unaryOp mcode
122 | Binary of expression * binaryOp mcode * expression
123 | Nested of expression * binaryOp mcode * expression
124 | ArrayAccess of expression * string mcode (* [ *) * expression *
125 string mcode (* ] *)
126 | RecordAccess of expression * string mcode (* . *) * ident
127 | RecordPtAccess of expression * string mcode (* -> *) * ident
128 | Cast of string mcode (* ( *) * fullType * string mcode (* ) *) *
129 expression
130
131 | SizeOfExpr of string mcode (* sizeof *) * expression
132 | SizeOfType of string mcode (* sizeof *) * string mcode (* ( *) *
133 fullType * string mcode (* ) *)
134 | TypeExp of fullType
135
136 | Paren of string mcode (* ( *) * expression *
137 string mcode (* ) *)
138
139 | MetaErr of meta_name mcode * expression list * keep_binding *
140 inherited
141 | MetaExpr of meta_name mcode * expression list * keep_binding *
142 Type_cocci.typeC list option * form * inherited
143 | MetaExprList of meta_name mcode * listlen option *
144 keep_binding * inherited (* only in arg lists *)
145
146 | EComma of string mcode (* only in arg lists *)
147
148 | DisjExpr of expression list
149 | NestExpr of expression dots * expression option * multi
150
151 (* can appear in arg lists, and also inside Nest, as in:
152 if(< ... X ... Y ...>)
153 In the following, the expression option is the WHEN *)
154 | Edots of string mcode (* ... *) * expression option
155 | Ecircles of string mcode (* ooo *) * expression option
156 | Estars of string mcode (* *** *) * expression option
157
158 | OptExp of expression
159 | UniqueExp of expression
160
161and form = ANY | ID | LocalID | CONST (* form for MetaExp *)
162
163and expression = base_expression wrap
164
165and listlen = meta_name mcode * keep_binding * inherited
166
167and unaryOp = GetRef | DeRef | UnPlus | UnMinus | Tilde | Not
168and assignOp = SimpleAssign | OpAssign of arithOp
169and fixOp = Dec | Inc
170
171and binaryOp = Arith of arithOp | Logical of logicalOp
172and arithOp =
173 Plus | Minus | Mul | Div | Mod | DecLeft | DecRight | And | Or | Xor
174and logicalOp = Inf | Sup | InfEq | SupEq | Eq | NotEq | AndLog | OrLog
175
176and constant =
177 String of string
178 | Char of string
179 | Int of string
180 | Float of string
181
182(* --------------------------------------------------------------------- *)
183(* Types *)
184
185and base_fullType =
186 Type of const_vol mcode option * typeC
187 | DisjType of fullType list (* only after iso *)
188 | OptType of fullType
189 | UniqueType of fullType
190
191and base_typeC =
192 BaseType of baseType mcode * sign mcode option
193 | ImplicitInt of sign mcode
194 | Pointer of fullType * string mcode (* * *)
195 | FunctionPointer of fullType *
196 string mcode(* ( *)*string mcode(* * *)*string mcode(* ) *)*
197 string mcode (* ( *)*parameter_list*string mcode(* ) *)
198 | FunctionType of bool (* true if all minus for dropping return type *) *
199 fullType option *
200 string mcode (* ( *) * parameter_list *
201 string mcode (* ) *)
202 | Array of fullType * string mcode (* [ *) *
203 expression option * string mcode (* ] *)
204 | StructUnionName of structUnion mcode * ident option (* name *)
205 | StructUnionDef of fullType (* either StructUnionName or metavar *) *
206 string mcode (* { *) * declaration dots * string mcode (* } *)
207 | TypeName of string mcode
208
209 | MetaType of meta_name mcode * keep_binding * inherited
210
211and fullType = base_fullType wrap
212and typeC = base_typeC wrap
213
214and baseType = VoidType | CharType | ShortType | IntType | DoubleType
215| FloatType | LongType
216
217and structUnion = Struct | Union
218
219and sign = Signed | Unsigned
220
221and const_vol = Const | Volatile
222
223(* --------------------------------------------------------------------- *)
224(* Variable declaration *)
225(* Even if the Cocci program specifies a list of declarations, they are
226 split out into multiple declarations of a single variable each. *)
227
228and base_declaration =
229 Init of storage mcode option * fullType * ident * string mcode (*=*) *
230 initialiser * string mcode (*;*)
231 | UnInit of storage mcode option * fullType * ident * string mcode (* ; *)
232 | TyDecl of fullType * string mcode (* ; *)
233 | MacroDecl of ident (* name *) * string mcode (* ( *) *
234 expression dots * string mcode (* ) *) * string mcode (* ; *)
235 | Typedef of string mcode (*typedef*) * fullType * typeC * string mcode (*;*)
236 | DisjDecl of declaration list
237 | Ddots of string mcode (* ... *) * declaration option (* whencode *)
238
239 | MetaDecl of meta_name mcode * keep_binding * inherited
240
241 | OptDecl of declaration
242 | UniqueDecl of declaration
243
244and declaration = base_declaration wrap
245
246(* --------------------------------------------------------------------- *)
247(* Initializers *)
248
249and base_initialiser =
250 InitExpr of expression
251 | InitList of string mcode (*{*) * initialiser list * string mcode (*}*) *
252 initialiser list (* whencode: elements that shouldn't appear in init *)
253 | InitGccDotName of
254 string mcode (*.*) * ident (* name *) * string mcode (*=*) *
255 initialiser (* gccext: *)
256 | InitGccName of ident (* name *) * string mcode (*:*) *
257 initialiser
258 | InitGccIndex of
259 string mcode (*[*) * expression * string mcode (*]*) *
260 string mcode (*=*) * initialiser
261 | InitGccRange of
262 string mcode (*[*) * expression * string mcode (*...*) *
263 expression * string mcode (*]*) * string mcode (*=*) * initialiser
264 | IComma of string mcode (* , *)
265 | OptIni of initialiser
266 | UniqueIni of initialiser
267
268and initialiser = base_initialiser wrap
269
270(* --------------------------------------------------------------------- *)
271(* Parameter *)
272
273and base_parameterTypeDef =
274 VoidParam of fullType
275 | Param of fullType * ident option
276
277 | MetaParam of meta_name mcode * keep_binding * inherited
278 | MetaParamList of meta_name mcode * listlen option * keep_binding *
279 inherited
280
281 | PComma of string mcode
282
283 | Pdots of string mcode (* ... *)
284 | Pcircles of string mcode (* ooo *)
285
286 | OptParam of parameterTypeDef
287 | UniqueParam of parameterTypeDef
288
289and parameterTypeDef = base_parameterTypeDef wrap
290
291and parameter_list = parameterTypeDef dots
292
293(* --------------------------------------------------------------------- *)
294(* #define Parameters *)
295
296and base_define_param =
297 DParam of ident
298 | DPComma of string mcode
299 | DPdots of string mcode (* ... *)
300 | DPcircles of string mcode (* ooo *)
301 | OptDParam of define_param
302 | UniqueDParam of define_param
303
304and define_param = base_define_param wrap
305
306and base_define_parameters =
307 NoParams
308 | DParams of string mcode(*( *) * define_param dots * string mcode(* )*)
309
310and define_parameters = base_define_parameters wrap
311
312(* --------------------------------------------------------------------- *)
313(* positions *)
314
315(* PER = keep bindings separate, ANY = collect them *)
316and meta_collect = PER | ALL
317
318and meta_pos =
319 MetaPos of meta_name mcode * meta_name list *
320 meta_collect * keep_binding * inherited
321 | NoMetaPos
322
323(* --------------------------------------------------------------------- *)
324(* Function declaration *)
325
326and storage = Static | Auto | Register | Extern
327
328(* --------------------------------------------------------------------- *)
329(* Top-level code *)
330
331and base_rule_elem =
332 FunHeader of mcodekind (* before the function header *) *
333 bool (* true if all minus, for dropping static, etc *) *
334 fninfo list * ident (* name *) *
335 string mcode (* ( *) * parameter_list *
336 string mcode (* ) *)
337 | Decl of mcodekind (* before the decl *) *
338 bool (* true if all minus *) * declaration
339
340 | SeqStart of string mcode (* { *)
341 | SeqEnd of string mcode (* } *)
342
343 | ExprStatement of expression * string mcode (*;*)
344 | IfHeader of string mcode (* if *) * string mcode (* ( *) *
345 expression * string mcode (* ) *)
346 | Else of string mcode (* else *)
347 | WhileHeader of string mcode (* while *) * string mcode (* ( *) *
348 expression * string mcode (* ) *)
349 | DoHeader of string mcode (* do *)
350 | WhileTail of string mcode (* while *) * string mcode (* ( *) *
351 expression * string mcode (* ) *) *
352 string mcode (* ; *)
353 | ForHeader of string mcode (* for *) * string mcode (* ( *) *
354 expression option * string mcode (*;*) *
355 expression option * string mcode (*;*) *
356 expression option * string mcode (* ) *)
357 | IteratorHeader of ident (* name *) * string mcode (* ( *) *
358 expression dots * string mcode (* ) *)
359 | SwitchHeader of string mcode (* switch *) * string mcode (* ( *) *
360 expression * string mcode (* ) *)
361 | Break of string mcode (* break *) * string mcode (* ; *)
362 | Continue of string mcode (* continue *) * string mcode (* ; *)
363 | Label of ident * string mcode (* : *)
364 | Goto of string mcode (* goto *) * ident * string mcode (* ; *)
365 | Return of string mcode (* return *) * string mcode (* ; *)
366 | ReturnExpr of string mcode (* return *) * expression *
367 string mcode (* ; *)
368
369 | MetaRuleElem of meta_name mcode * keep_binding * inherited
370 | MetaStmt of meta_name mcode * keep_binding * metaStmtInfo *
371 inherited
372 | MetaStmtList of meta_name mcode * keep_binding * inherited
373
374 | Exp of expression
375 | TopExp of expression (* for macros body *)
376 | Ty of fullType (* only at top level *)
1be43e12 377 | TopInit of initialiser (* only at top level *)
34e49164
C
378 | Include of string mcode (*#include*) * inc_file mcode (*file *)
379 | DefineHeader of string mcode (* #define *) * ident (* name *) *
380 define_parameters (*params*)
381 | Case of string mcode (* case *) * expression * string mcode (*:*)
382 | Default of string mcode (* default *) * string mcode (*:*)
383 | DisjRuleElem of rule_elem list
384
385and fninfo =
386 FStorage of storage mcode
387 | FType of fullType
388 | FInline of string mcode
389 | FAttr of string mcode
390
391and metaStmtInfo =
392 NotSequencible | SequencibleAfterDots of dots_whencode list | Sequencible
393
394and rule_elem = base_rule_elem wrap
395
396and base_statement =
397 Seq of rule_elem (* { *) * statement dots *
398 statement dots * rule_elem (* } *)
399 | IfThen of rule_elem (* header *) * statement * end_info
400 | IfThenElse of rule_elem (* header *) * statement *
401 rule_elem (* else *) * statement * end_info
402 | While of rule_elem (* header *) * statement * end_info
403 | Do of rule_elem (* do *) * statement * rule_elem (* tail *)
404 | For of rule_elem (* header *) * statement * end_info
405 | Iterator of rule_elem (* header *) * statement * end_info (*enditer*)
406 | Switch of rule_elem (* header *) * rule_elem (* { *) *
407 case_line list * rule_elem (* } *)
408 | Atomic of rule_elem
409 | Disj of statement dots list
410 | Nest of statement dots *
411 (statement dots,statement) whencode list * multi *
412 dots_whencode list * dots_whencode list
413 | FunDecl of rule_elem (* header *) * rule_elem (* { *) *
414 statement dots * statement dots * rule_elem (* } *)
415 | Define of rule_elem (* header *) * statement dots
416 | Dots of string mcode (* ... *) *
417 (statement dots,statement) whencode list *
418 dots_whencode list * dots_whencode list
419 | Circles of string mcode (* ooo *) *
420 (statement dots,statement) whencode list *
421 dots_whencode list * dots_whencode list
422 | Stars of string mcode (* *** *) *
423 (statement dots,statement) whencode list *
424 dots_whencode list * dots_whencode list
425 | OptStm of statement
426 | UniqueStm of statement
427
428and ('a,'b) whencode =
429 WhenNot of 'a
430 | WhenAlways of 'b
431 | WhenModifier of when_modifier
1be43e12
C
432 | WhenNotTrue of rule_elem
433 | WhenNotFalse of rule_elem
34e49164
C
434
435and when_modifier =
436 WhenAny
437 | WhenStrict
438 | WhenForall
439 | WhenExists
440
441and dots_whencode =
442 WParen of rule_elem * meta_name (*pren_var*)
443 | Other of statement
444 | Other_dots of statement dots
445
446and statement = base_statement wrap
447
448and base_case_line =
449 CaseLine of rule_elem (* case/default header *) * statement dots
450 | OptCase of case_line
451
452and case_line = base_case_line wrap
453
454and inc_file =
455 Local of inc_elem list
456 | NonLocal of inc_elem list
457
458and inc_elem =
459 IncPath of string
460 | IncDots
461
462and base_top_level =
463 DECL of statement
464 | CODE of statement dots
465 | FILEINFO of string mcode (* old file *) * string mcode (* new file *)
466 | ERRORWORDS of expression list
467
468and top_level = base_top_level wrap
469
470and rulename =
471 CocciRulename of string option * dependency * string list * string list *
472 exists * bool
473 (* true if the whole thing is an expression *)
474 | ScriptRulename of string * dependency
475
476and rule =
477 CocciRule of string (* name *) *
478 (dependency * string list (* dropped isos *) * exists) *
479 top_level list * bool list (* true if generates an exp *)
480 | ScriptRule of string * dependency * (string * meta_name) list * string
481
482and dependency =
483 Dep of string (* rule applies for the current binding *)
484 | AntiDep of string (* rule doesn't apply for the current binding *)
485 | EverDep of string (* rule applies for some binding *)
486 | NeverDep of string (* rule never applies for any binding *)
487 | AndDep of dependency * dependency
488 | OrDep of dependency * dependency
489 | NoDep
490
491and rule_with_metavars = metavar list * rule
492
493and anything =
494 FullTypeTag of fullType
495 | BaseTypeTag of baseType
496 | StructUnionTag of structUnion
497 | SignTag of sign
498 | IdentTag of ident
499 | ExpressionTag of expression
500 | ConstantTag of constant
501 | UnaryOpTag of unaryOp
502 | AssignOpTag of assignOp
503 | FixOpTag of fixOp
504 | BinaryOpTag of binaryOp
505 | ArithOpTag of arithOp
506 | LogicalOpTag of logicalOp
507 | DeclarationTag of declaration
508 | InitTag of initialiser
509 | StorageTag of storage
510 | IncFileTag of inc_file
511 | Rule_elemTag of rule_elem
512 | StatementTag of statement
513 | CaseLineTag of case_line
514 | ConstVolTag of const_vol
515 | Token of string * info option
516 | Code of top_level
517 | ExprDotsTag of expression dots
518 | ParamDotsTag of parameterTypeDef dots
519 | StmtDotsTag of statement dots
520 | DeclDotsTag of declaration dots
521 | TypeCTag of typeC
522 | ParamTag of parameterTypeDef
523 | SgrepStartTag of string
524 | SgrepEndTag of string
525
526(* --------------------------------------------------------------------- *)
527
528and exists = Exists | Forall | ReverseForall | Undetermined
529
530(* --------------------------------------------------------------------- *)
531
532val mkToken : string -> anything
533
534val undots : 'a dots -> 'a list
535
536(* --------------------------------------------------------------------- *)
537
538val rewrap : 'a wrap -> 'b -> 'b wrap
539val rewrap_mcode : 'a mcode -> 'a -> 'a mcode
540val unwrap : 'a wrap -> 'a
541val unwrap_mcode : 'a mcode -> 'a
542val get_mcodekind : 'a mcode -> mcodekind
543val get_line : 'a wrap -> line
544val get_mcode_line : 'a mcode -> line
545val get_fvs : 'a wrap -> meta_name list
546val get_wcfvs : ('a wrap,'b wrap) whencode list -> meta_name list
547val set_fvs : meta_name list -> 'a wrap -> 'a wrap
548val get_mfvs : 'a wrap -> meta_name list
549val set_mfvs : meta_name list -> 'a wrap -> 'a wrap
550val get_fresh : 'a wrap -> meta_name list
551val get_inherited : 'a wrap -> meta_name list
552val get_saved : 'a wrap -> meta_name list
553val get_dots_bef_aft : statement -> dots_bef_aft
554val set_dots_bef_aft : dots_bef_aft -> statement -> statement
555val get_pos : 'a wrap -> meta_name mcode option
556val set_pos : 'a wrap -> meta_name mcode option -> 'a wrap
557val get_test_exp : 'a wrap -> bool
558val set_test_exp : expression -> expression
559val get_isos : 'a wrap -> (string*anything) list
560val set_isos : 'a wrap -> (string*anything) list -> 'a wrap
561val get_pos_var : 'a mcode -> meta_pos
562val set_pos_var : meta_pos -> 'a mcode -> 'a mcode
563val drop_pos : 'a mcode -> 'a mcode
564
565val get_meta_name : metavar -> meta_name
566
567val no_info : info
568
569val make_meta_rule_elem :
570 string -> mcodekind ->
571 (meta_name list * meta_name list * meta_name list) ->
572 rule_elem
573
574val make_meta_decl :
575 string -> mcodekind ->
576 (meta_name list * meta_name list * meta_name list) ->
577 declaration
578
579val make_term : 'a -> 'a wrap
580val make_mcode : 'a -> 'a mcode
581
582val equal_pos : fixpos -> fixpos -> bool