Release coccinelle-0.1.8
[bpt/coccinelle.git] / parsing_cocci / ast0_cocci.mli
CommitLineData
34e49164
C
1(* --------------------------------------------------------------------- *)
2(* Modified code *)
3
4type arity = OPT | UNIQUE | NONE
5
6type token_info =
7 { tline_start : int; tline_end : int;
8 left_offset : int; right_offset : int }
9val default_token_info : token_info
10
11type 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
0708f913
C
19type position_info = { line_start : int; line_end : int;
20 logical_start : int; logical_end : int;
21 column : int; offset : int; }
22
23type info = { pos_info : position_info;
34e49164
C
24 attachable_start : bool; attachable_end : bool;
25 mcode_start : mcodekind list; mcode_end : mcodekind list;
34e49164 26 (* the following are only for + code *)
0708f913
C
27 strings_before : (string * position_info) list;
28 strings_after : (string * position_info) list }
34e49164 29
708f4980
C
30type 'a mcode =
31 'a * arity * info * mcodekind * meta_pos ref (* pos, - only *) *
32 int (* adjacency_index *)
33
34e49164
C
34and '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
47and 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) *)
54and pure = Impure | Pure | Context | PureContext (* pure and only context *)
55
56(* --------------------------------------------------------------------- *)
57(* --------------------------------------------------------------------- *)
58(* Dots *)
59
60and 'a base_dots =
61 DOTS of 'a list
62 | CIRCLES of 'a list
63 | STARS of 'a list
64
65and 'a dots = 'a base_dots wrap
66
67(* --------------------------------------------------------------------- *)
68(* Identifier *)
69
70and 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
78and ident = base_ident wrap
79
80(* --------------------------------------------------------------------- *)
81(* Expression *)
82
faf9a90c 83and base_expression =
34e49164
C
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
125and expression = base_expression wrap
126
127and listlen = Ast_cocci.meta_name mcode option
128
129(* --------------------------------------------------------------------- *)
130(* Types *)
131
faf9a90c 132and base_typeC =
34e49164 133 ConstVol of Ast_cocci.const_vol mcode * typeC
faf9a90c
C
134 | BaseType of Ast_cocci.baseType * string mcode list
135 | Signed of Ast_cocci.sign mcode * typeC option
34e49164
C
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 (* ] *)
faf9a90c 145 | EnumName of string mcode (*enum*) * ident (* name *)
34e49164
C
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
156and 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
163and 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
178and declaration = base_declaration wrap
179
180(* --------------------------------------------------------------------- *)
181(* Initializers *)
182
183and base_initialiser =
113803cf
C
184 MetaInit of Ast_cocci.meta_name mcode * pure
185 | InitExpr of expression
34e49164 186 | InitList of string mcode (*{*) * initialiser_list * string mcode (*}*)
113803cf
C
187 | InitGccExt of
188 designator list (* name *) * string mcode (*=*) *
34e49164
C
189 initialiser (* gccext: *)
190 | InitGccName of ident (* name *) * string mcode (*:*) *
191 initialiser
34e49164
C
192 | IComma of string mcode
193 | Idots of string mcode (* ... *) * initialiser option (* whencode *)
194 | OptIni of initialiser
195 | UniqueIni of initialiser
196
113803cf
C
197and 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
34e49164
C
204and initialiser = base_initialiser wrap
205
206and initialiser_list = initialiser dots
207
208(* --------------------------------------------------------------------- *)
209(* Parameter *)
210
211and 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
222and parameterTypeDef = base_parameterTypeDef wrap
223
224and parameter_list = parameterTypeDef dots
225
226(* --------------------------------------------------------------------- *)
227(* #define Parameters *)
228
229and 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
237and define_param = base_define_param wrap
238
239and base_define_parameters =
240 NoParams
241 | DParams of string mcode(*( *) * define_param dots * string mcode(* )*)
242
243and define_parameters = base_define_parameters wrap
244
245(* --------------------------------------------------------------------- *)
246(* Statement*)
247
248and 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 *)
1be43e12 291 | TopInit of initialiser (* only at top level *)
34e49164
C
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
313and fninfo =
314 FStorage of Ast_cocci.storage mcode
315 | FType of typeC
316 | FInline of string mcode
317 | FAttr of string mcode
318
319and ('a,'b) whencode =
320 WhenNot of 'a
321 | WhenAlways of 'b
322 | WhenModifier of Ast_cocci.when_modifier
1be43e12
C
323 | WhenNotTrue of expression
324 | WhenNotFalse of expression
34e49164
C
325
326and statement = base_statement wrap
327
328and 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
334and case_line = base_case_line wrap
335
336(* --------------------------------------------------------------------- *)
337(* Positions *)
338
339and 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
347and 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
354and top_level = base_top_level wrap
355and rule = top_level list
356
357and parsed_rule =
358 CocciRule of
359 (rule * Ast_cocci.metavar list *
360 (string list * string list * Ast_cocci.dependency * string *
361 Ast_cocci.exists)) *
faf9a90c 362 (rule * Ast_cocci.metavar list) * Ast_cocci.ruletype
34e49164
C
363 | ScriptRule of
364 string * Ast_cocci.dependency * (string * Ast_cocci.meta_name) list *
365 string
b1b2de81
C
366 | InitialScriptRule of string * string
367 | FinalScriptRule of string * string
34e49164
C
368
369(* --------------------------------------------------------------------- *)
370
371and 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*)
1be43e12
C
390 | IsoWhenTTag of expression(*only for when code, in iso phase*)
391 | IsoWhenFTag of expression(*only for when code, in iso phase*)
34e49164
C
392 | MetaPosTag of meta_pos (* only in iso phase *)
393
394val dotsExpr : expression dots -> anything
395val dotsInit : initialiser dots -> anything
396val dotsParam : parameterTypeDef dots -> anything
397val dotsStmt : statement dots -> anything
398val dotsDecl : declaration dots -> anything
399val dotsCase : case_line dots -> anything
400val ident : ident -> anything
401val expr : expression -> anything
402val typeC : typeC -> anything
403val param : parameterTypeDef -> anything
404val ini : initialiser -> anything
405val decl : declaration -> anything
406val stmt : statement -> anything
407val case_line : case_line -> anything
408val top : top_level -> anything
409
410(* --------------------------------------------------------------------- *)
411
412val undots : 'a dots -> 'a list
413
414(* --------------------------------------------------------------------- *)
415(* Avoid cluttering the parser. Calculated in compute_lines.ml. *)
416
417val default_info : unit -> info
418val default_befaft : unit -> mcodekind
419val context_befaft : unit -> mcodekind
420val wrap : 'a -> 'a wrap
421val context_wrap : 'a -> 'a wrap
422val unwrap : 'a wrap -> 'a
423val unwrap_mcode : 'a mcode -> 'a
424val rewrap : 'a wrap -> 'b -> 'b wrap
425val rewrap_mcode : 'a mcode -> 'b -> 'b mcode
426val copywrap : 'a wrap -> 'b -> 'b wrap
427val get_pos : 'a mcode -> meta_pos
428val get_pos_ref : 'a mcode -> meta_pos ref
429val set_pos : meta_pos -> 'a mcode -> 'a mcode
430val get_info : 'a wrap -> info
431val set_info : 'a wrap -> info -> 'a wrap
432val get_index : 'a wrap -> int
433val set_index : 'a wrap -> int -> unit
434val get_line : 'a wrap -> int
435val get_line_end : 'a wrap -> int
436val get_mcodekind : 'a wrap -> mcodekind
437val get_mcode_mcodekind : 'a mcode -> mcodekind
438val get_mcodekind_ref : 'a wrap -> mcodekind ref
439val set_mcodekind : 'a wrap -> mcodekind -> unit
440val set_type : 'a wrap -> Type_cocci.typeC option -> unit
441val get_type : 'a wrap -> Type_cocci.typeC option
442val set_dots_bef_aft : statement -> dots_bef_aft -> statement
443val get_dots_bef_aft : 'a wrap -> dots_bef_aft
444val set_arg_exp : expression -> expression
445val get_arg_exp : expression -> bool
446val set_test_pos : expression -> expression
447val get_test_pos : 'a wrap -> bool
448val set_test_exp : expression -> expression
449val get_test_exp : 'a wrap -> bool
450val set_iso : 'a wrap -> (string*anything) list -> 'a wrap
451val get_iso : 'a wrap -> (string*anything) list
452val fresh_index : unit -> int
453val set_mcode_data : 'a -> 'a mcode -> 'a mcode
454val make_mcode : 'a -> 'a mcode
455val make_mcode_info : 'a -> info -> 'a mcode
456
457val ast0_type_to_type : typeC -> Type_cocci.typeC
458val reverse_type : Type_cocci.typeC -> base_typeC
459exception TyConv
460
461val lub_pure : pure -> pure -> pure
462
463(* --------------------------------------------------------------------- *)
464
465val rule_name : string ref (* for the convenience of the parser *)