2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
45 (* --------------------------------------------------------------------- *)
48 type arity
= OPT
| UNIQUE
| NONE
51 { tline_start
: int; tline_end
: int;
52 left_offset
: int; right_offset
: int }
53 val default_token_info
: token_info
56 MINUS
of (Ast_cocci.anything list list
* token_info
) ref
57 | PLUS
of Ast_cocci.count
58 | CONTEXT
of (Ast_cocci.anything
Ast_cocci.befaft
*
59 token_info
* token_info
) ref
60 | MIXED
of (Ast_cocci.anything
Ast_cocci.befaft
*
61 token_info
* token_info
) ref
63 type position_info
= { line_start
: int; line_end
: int;
64 logical_start
: int; logical_end
: int;
65 column
: int; offset
: int; }
67 type info
= { pos_info
: position_info
;
68 attachable_start
: bool; attachable_end
: bool;
69 mcode_start
: mcodekind list
; mcode_end
: mcodekind list
;
70 (* the following are only for + code *)
71 strings_before
: (Ast_cocci.added_string
* position_info
) list
;
72 strings_after
: (Ast_cocci.added_string
* position_info
) list
}
75 'a
* arity
* info
* mcodekind
* meta_pos
ref (* pos, - only *) *
76 int (* adjacency_index *)
82 mcodekind
: mcodekind
ref;
83 exp_ty
: Type_cocci.typeC
option ref; (* only for expressions *)
84 bef_aft
: dots_bef_aft
; (* only for statements *)
85 true_if_arg
: bool; (* true if "arg_exp", only for exprs *)
86 true_if_test
: bool; (* true if "test position", only for exprs *)
87 true_if_test_exp
: bool;(* true if "test_exp from iso", only for exprs *)
88 (*nonempty if this represents the use of an iso*)
89 iso_info
: (string*anything
) list
}
92 NoDots
| AddingBetweenDots
of statement
| DroppingBetweenDots
of statement
94 (* for iso metavariables, true if they can only match nonmodified, unitary
96 for SP metavariables, true if the metavariable is unitary (valid up to
97 isomorphism phase only) *)
98 and pure
= Impure
| Pure
| Context
| PureContext
(* pure and only context *)
100 (* --------------------------------------------------------------------- *)
101 (* --------------------------------------------------------------------- *)
109 and 'a dots
= 'a base_dots wrap
111 (* --------------------------------------------------------------------- *)
116 | MetaId
of Ast_cocci.meta_name mcode
* Ast_cocci.idconstraint
* pure
117 | MetaFunc
of Ast_cocci.meta_name mcode
* Ast_cocci.idconstraint
* pure
118 | MetaLocalFunc
of Ast_cocci.meta_name mcode
* Ast_cocci.idconstraint
* pure
120 | UniqueIdent
of ident
122 and ident
= base_ident wrap
124 (* --------------------------------------------------------------------- *)
127 and base_expression
=
129 | Constant
of Ast_cocci.constant mcode
130 | FunCall
of expression
* string mcode
(* ( *) *
131 expression dots
* string mcode
(* ) *)
132 | Assignment
of expression
* Ast_cocci.assignOp mcode
* expression
*
133 bool (* true if it can match an initialization *)
134 | CondExpr
of expression
* string mcode
(* ? *) * expression
option *
135 string mcode
(* : *) * expression
136 | Postfix
of expression
* Ast_cocci.fixOp mcode
137 | Infix
of expression
* Ast_cocci.fixOp mcode
138 | Unary
of expression
* Ast_cocci.unaryOp mcode
139 | Binary
of expression
* Ast_cocci.binaryOp mcode
* expression
140 | Nested
of expression
* Ast_cocci.binaryOp mcode
* expression
141 | Paren
of string mcode
(* ( *) * expression
*
143 | ArrayAccess
of expression
* string mcode
(* [ *) * expression
*
145 | RecordAccess
of expression
* string mcode
(* . *) * ident
146 | RecordPtAccess
of expression
* string mcode
(* -> *) * ident
147 | Cast
of string mcode
(* ( *) * typeC
* string mcode
(* ) *) *
149 | SizeOfExpr
of string mcode
(* sizeof *) * expression
150 | SizeOfType
of string mcode
(* sizeof *) * string mcode
(* ( *) *
151 typeC
* string mcode
(* ) *)
153 | MetaErr
of Ast_cocci.meta_name mcode
* constraints
* pure
154 | MetaExpr
of Ast_cocci.meta_name mcode
* constraints
*
155 Type_cocci.typeC list
option * Ast_cocci.form
* pure
156 | MetaExprList
of Ast_cocci.meta_name mcode
(* only in arglists *) *
158 | EComma
of string mcode
(* only in arglists *)
159 | DisjExpr
of string mcode
* expression list
* string mcode list
*
161 | NestExpr
of string mcode
* expression dots
* string mcode
*
162 expression
option * Ast_cocci.multi
163 | Edots
of string mcode
(* ... *) * expression
option
164 | Ecircles
of string mcode
(* ooo *) * expression
option
165 | Estars
of string mcode
(* *** *) * expression
option
166 | OptExp
of expression
167 | UniqueExp
of expression
169 and expression
= base_expression wrap
173 | NotIdCstrt
of Ast_cocci.reconstraint
174 | NotExpCstrt
of expression list
175 | SubExpCstrt
of Ast_cocci.meta_name list
177 and listlen
= Ast_cocci.meta_name mcode
option
179 (* --------------------------------------------------------------------- *)
183 ConstVol
of Ast_cocci.const_vol mcode
* typeC
184 | BaseType
of Ast_cocci.baseType
* string mcode list
185 | Signed
of Ast_cocci.sign mcode
* typeC
option
186 | Pointer
of typeC
* string mcode
(* * *)
187 | FunctionPointer
of typeC
*
188 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
189 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
190 | FunctionType
of typeC
option *
191 string mcode
(* ( *) * parameter_list
*
193 | Array
of typeC
* string mcode
(* [ *) *
194 expression
option * string mcode
(* ] *)
195 | EnumName
of string mcode
(*enum*) * ident
(* name *)
196 | StructUnionName
of Ast_cocci.structUnion mcode
* ident
option (* name *)
197 | StructUnionDef
of typeC
(* either StructUnionName or metavar *) *
198 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
199 | TypeName
of string mcode
200 | MetaType
of Ast_cocci.meta_name mcode
* pure
201 | DisjType
of string mcode
* typeC list
* (* only after iso *)
202 string mcode list
(* the |s *) * string mcode
204 | UniqueType
of typeC
206 and typeC
= base_typeC wrap
208 (* --------------------------------------------------------------------- *)
209 (* Variable declaration *)
210 (* Even if the Cocci program specifies a list of declarations, they are
211 split out into multiple declarations of a single variable each. *)
213 and base_declaration
=
214 Init
of Ast_cocci.storage mcode
option * typeC
* ident
*
215 string mcode
(*=*) * initialiser
* string mcode
(*;*)
216 | UnInit
of Ast_cocci.storage mcode
option * typeC
* ident
*
218 | TyDecl
of typeC
* string mcode
(* ; *)
219 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
220 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
221 | Typedef
of string mcode
(* typedef *) * typeC
* typeC
* string mcode
(*;*)
222 | DisjDecl
of string mcode
* declaration list
* string mcode list
*
224 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
225 | OptDecl
of declaration
226 | UniqueDecl
of declaration
228 and declaration
= base_declaration wrap
230 (* --------------------------------------------------------------------- *)
233 and base_initialiser
=
234 MetaInit
of Ast_cocci.meta_name mcode
* pure
235 | InitExpr
of expression
236 | InitList
of string mcode
(*{*) * initialiser_list
* string mcode
(*}*)
238 designator list
(* name *) * string mcode
(*=*) *
239 initialiser
(* gccext: *)
240 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
242 | IComma
of string mcode
243 | Idots
of string mcode
(* ... *) * initialiser
option (* whencode *)
244 | OptIni
of initialiser
245 | UniqueIni
of initialiser
248 DesignatorField
of string mcode
(* . *) * ident
249 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
251 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
252 expression
* string mcode
(* ] *)
254 and initialiser
= base_initialiser wrap
256 and initialiser_list
= initialiser dots
258 (* --------------------------------------------------------------------- *)
261 and base_parameterTypeDef
=
263 | Param
of typeC
* ident
option
264 | MetaParam
of Ast_cocci.meta_name mcode
* pure
265 | MetaParamList
of Ast_cocci.meta_name mcode
* listlen
* pure
266 | PComma
of string mcode
267 | Pdots
of string mcode
(* ... *)
268 | Pcircles
of string mcode
(* ooo *)
269 | OptParam
of parameterTypeDef
270 | UniqueParam
of parameterTypeDef
272 and parameterTypeDef
= base_parameterTypeDef wrap
274 and parameter_list
= parameterTypeDef dots
276 (* --------------------------------------------------------------------- *)
277 (* #define Parameters *)
279 and base_define_param
=
281 | DPComma
of string mcode
282 | DPdots
of string mcode
(* ... *)
283 | DPcircles
of string mcode
(* ooo *)
284 | OptDParam
of define_param
285 | UniqueDParam
of define_param
287 and define_param
= base_define_param wrap
289 and base_define_parameters
=
291 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
293 and define_parameters
= base_define_parameters wrap
295 (* --------------------------------------------------------------------- *)
299 Decl
of (info
* mcodekind
) (* before the decl *) * declaration
300 | Seq
of string mcode
(* { *) * statement dots
*
302 | ExprStatement
of expression
* string mcode
(*;*)
303 | IfThen
of string mcode
(* if *) * string mcode
(* ( *) *
304 expression
* string mcode
(* ) *) *
305 statement
* (info
* mcodekind
)
306 | IfThenElse
of string mcode
(* if *) * string mcode
(* ( *) *
307 expression
* string mcode
(* ) *) *
308 statement
* string mcode
(* else *) * statement
*
310 | While
of string mcode
(* while *) * string mcode
(* ( *) *
311 expression
* string mcode
(* ) *) *
312 statement
* (info
* mcodekind
) (* after info *)
313 | Do
of string mcode
(* do *) * statement
*
314 string mcode
(* while *) * string mcode
(* ( *) *
315 expression
* string mcode
(* ) *) *
317 | For
of string mcode
(* for *) * string mcode
(* ( *) *
318 expression
option * string mcode
(*;*) *
319 expression
option * string mcode
(*;*) *
320 expression
option * string mcode
(* ) *) * statement
*
321 (info
* mcodekind
) (* after info *)
322 | Iterator
of ident
(* name *) * string mcode
(* ( *) *
323 expression dots
* string mcode
(* ) *) *
324 statement
* (info
* mcodekind
) (* after info *)
325 | Switch
of string mcode
(* switch *) * string mcode
(* ( *) *
326 expression
* string mcode
(* ) *) * string mcode
(* { *) *
327 statement
(*decl*) dots
*
328 case_line dots
* string mcode
(* } *)
329 | Break
of string mcode
(* break *) * string mcode
(* ; *)
330 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
331 | Label
of ident
* string mcode
(* : *)
332 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
333 | Return
of string mcode
(* return *) * string mcode
(* ; *)
334 | ReturnExpr
of string mcode
(* return *) * expression
*
336 | MetaStmt
of Ast_cocci.meta_name mcode
* pure
337 | MetaStmtList
of Ast_cocci.meta_name mcode
(*only in statement lists*) *
339 | Exp
of expression
(* only in dotted statement lists *)
340 | TopExp
of expression
(* for macros body *)
341 | Ty
of typeC
(* only at top level *)
342 | TopInit
of initialiser
(* only at top level *)
343 | Disj
of string mcode
* statement dots list
* string mcode list
*
345 | Nest
of string mcode
* statement dots
* string mcode
*
346 (statement dots
,statement
) whencode list
* Ast_cocci.multi
347 | Dots
of string mcode
(* ... *) *
348 (statement dots
,statement
) whencode list
349 | Circles
of string mcode
(* ooo *) *
350 (statement dots
,statement
) whencode list
351 | Stars
of string mcode
(* *** *) *
352 (statement dots
,statement
) whencode list
353 | FunDecl
of (info
* mcodekind
) (* before the function decl *) *
354 fninfo list
* ident
(* name *) *
355 string mcode
(* ( *) * parameter_list
* string mcode
(* ) *) *
356 string mcode
(* { *) * statement dots
*
358 | Include
of string mcode
(* #include *) * Ast_cocci.inc_file mcode
(* file *)
359 | Define
of string mcode
(* #define *) * ident
(* name *) *
360 define_parameters
(*params*) * statement dots
361 | OptStm
of statement
362 | UniqueStm
of statement
365 FStorage
of Ast_cocci.storage mcode
367 | FInline
of string mcode
368 | FAttr
of string mcode
370 and ('a
,'b
) whencode
=
373 | WhenModifier
of Ast_cocci.when_modifier
374 | WhenNotTrue
of expression
375 | WhenNotFalse
of expression
377 and statement
= base_statement wrap
380 Default
of string mcode
(* default *) * string mcode
(*:*) * statement dots
381 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*) *
383 | DisjCase
of string mcode
* case_line list
*
384 string mcode list
(* the |s *) * string mcode
385 | OptCase
of case_line
387 and case_line
= base_case_line wrap
389 (* --------------------------------------------------------------------- *)
393 MetaPos
of Ast_cocci.meta_name mcode
* Ast_cocci.meta_name list
*
394 Ast_cocci.meta_collect
397 (* --------------------------------------------------------------------- *)
402 | CODE
of statement dots
403 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
404 | ERRORWORDS
of expression list
405 | OTHER
of statement
(* temporary, disappears after top_level.ml *)
407 and top_level
= base_top_level wrap
408 and rule
= top_level list
412 (rule
* Ast_cocci.metavar list
*
413 (string list
* string list
* Ast_cocci.dependency
* string *
415 (rule
* Ast_cocci.metavar list
) * Ast_cocci.ruletype
417 string * Ast_cocci.dependency
* (string * Ast_cocci.meta_name
) list
*
419 | InitialScriptRule
of
420 string (*language*) * Ast_cocci.dependency
* string (*code*)
422 string (*language*) * Ast_cocci.dependency
* string (*code*)
424 (* --------------------------------------------------------------------- *)
427 DotsExprTag
of expression dots
428 | DotsInitTag
of initialiser dots
429 | DotsParamTag
of parameterTypeDef dots
430 | DotsStmtTag
of statement dots
431 | DotsDeclTag
of declaration dots
432 | DotsCaseTag
of case_line dots
434 | ExprTag
of expression
435 | ArgExprTag
of expression
(* for isos *)
436 | TestExprTag
of expression
(* for isos *)
438 | ParamTag
of parameterTypeDef
439 | InitTag
of initialiser
440 | DeclTag
of declaration
441 | StmtTag
of statement
442 | CaseLineTag
of case_line
443 | TopTag
of top_level
444 | IsoWhenTag
of Ast_cocci.when_modifier
(*only for when code, in iso phase*)
445 | IsoWhenTTag
of expression
(*only for when code, in iso phase*)
446 | IsoWhenFTag
of expression
(*only for when code, in iso phase*)
447 | MetaPosTag
of meta_pos
(* only in iso phase *)
449 val dotsExpr
: expression dots
-> anything
450 val dotsInit
: initialiser dots
-> anything
451 val dotsParam
: parameterTypeDef dots
-> anything
452 val dotsStmt
: statement dots
-> anything
453 val dotsDecl
: declaration dots
-> anything
454 val dotsCase
: case_line dots
-> anything
455 val ident
: ident
-> anything
456 val expr
: expression
-> anything
457 val typeC
: typeC
-> anything
458 val param
: parameterTypeDef
-> anything
459 val ini
: initialiser
-> anything
460 val decl
: declaration
-> anything
461 val stmt
: statement
-> anything
462 val case_line
: case_line
-> anything
463 val top
: top_level
-> anything
465 (* --------------------------------------------------------------------- *)
467 val undots
: 'a dots
-> 'a list
469 (* --------------------------------------------------------------------- *)
470 (* Avoid cluttering the parser. Calculated in compute_lines.ml. *)
472 val default_info
: unit -> info
473 val default_befaft
: unit -> mcodekind
474 val context_befaft
: unit -> mcodekind
475 val wrap
: 'a
-> 'a wrap
476 val context_wrap
: 'a
-> 'a wrap
477 val unwrap
: 'a wrap
-> 'a
478 val unwrap_mcode
: 'a mcode
-> 'a
479 val rewrap
: 'a wrap
-> 'b
-> 'b wrap
480 val rewrap_mcode
: 'a mcode
-> 'b
-> 'b mcode
481 val copywrap
: 'a wrap
-> 'b
-> 'b wrap
482 val get_pos
: 'a mcode
-> meta_pos
483 val get_pos_ref
: 'a mcode
-> meta_pos
ref
484 val set_pos
: meta_pos
-> 'a mcode
-> 'a mcode
485 val get_info
: 'a wrap
-> info
486 val set_info
: 'a wrap
-> info
-> 'a wrap
487 val get_index
: 'a wrap
-> int
488 val set_index
: 'a wrap
-> int -> unit
489 val get_line
: 'a wrap
-> int
490 val get_line_end
: 'a wrap
-> int
491 val get_mcodekind
: 'a wrap
-> mcodekind
492 val get_mcode_mcodekind
: 'a mcode
-> mcodekind
493 val get_mcodekind_ref
: 'a wrap
-> mcodekind
ref
494 val set_mcodekind
: 'a wrap
-> mcodekind
-> unit
495 val set_type
: 'a wrap
-> Type_cocci.typeC
option -> unit
496 val get_type
: 'a wrap
-> Type_cocci.typeC
option
497 val set_dots_bef_aft
: statement
-> dots_bef_aft
-> statement
498 val get_dots_bef_aft
: 'a wrap
-> dots_bef_aft
499 val set_arg_exp
: expression
-> expression
500 val get_arg_exp
: expression
-> bool
501 val set_test_pos
: expression
-> expression
502 val get_test_pos
: 'a wrap
-> bool
503 val set_test_exp
: expression
-> expression
504 val get_test_exp
: 'a wrap
-> bool
505 val set_iso
: 'a wrap
-> (string*anything
) list
-> 'a wrap
506 val get_iso
: 'a wrap
-> (string*anything
) list
507 val fresh_index
: unit -> int
508 val set_mcode_data
: 'a
-> 'a mcode
-> 'a mcode
509 val make_mcode
: 'a
-> 'a mcode
510 val make_mcode_info
: 'a
-> info
-> 'a mcode
512 val ast0_type_to_type
: typeC
-> Type_cocci.typeC
513 val reverse_type
: Type_cocci.typeC
-> base_typeC
516 val lub_pure
: pure
-> pure
-> pure
518 (* --------------------------------------------------------------------- *)
520 val rule_name
: string ref (* for the convenience of the parser *)