1 (* --------------------------------------------------------------------- *)
4 type arity
= OPT
| UNIQUE
| NONE
7 { tline_start
: int; tline_end
: int;
8 left_offset
: int; right_offset
: int }
9 val default_token_info
: token_info
12 MINUS
of (Ast_cocci.anything list list
* token_info
) ref
13 | PLUS
of Ast_cocci.count
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
19 type position_info
= { line_start
: int; line_end
: int;
20 logical_start
: int; logical_end
: int;
21 column
: int; offset
: int; }
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
}
31 'a
* arity
* info
* mcodekind
* meta_pos
ref (* pos, - only *) *
32 int (* adjacency_index *)
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
}
48 NoDots
| AddingBetweenDots
of statement
| DroppingBetweenDots
of statement
50 (* for iso metavariables, true if they can only match nonmodified, unitary
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 *)
56 (* --------------------------------------------------------------------- *)
57 (* --------------------------------------------------------------------- *)
65 and 'a dots
= 'a base_dots wrap
67 (* --------------------------------------------------------------------- *)
72 | MetaId
of Ast_cocci.meta_name mcode
* Ast_cocci.idconstraint
* pure
73 | MetaFunc
of Ast_cocci.meta_name mcode
* Ast_cocci.idconstraint
* pure
74 | MetaLocalFunc
of Ast_cocci.meta_name mcode
* Ast_cocci.idconstraint
* pure
76 | UniqueIdent
of ident
78 and ident
= base_ident wrap
80 (* --------------------------------------------------------------------- *)
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
*
99 | ArrayAccess
of expression
* string mcode
(* [ *) * expression
*
101 | RecordAccess
of expression
* string mcode
(* . *) * ident
102 | RecordPtAccess
of expression
* string mcode
(* -> *) * ident
103 | Cast
of string mcode
(* ( *) * typeC
* string mcode
(* ) *) *
105 | SizeOfExpr
of string mcode
(* sizeof *) * expression
106 | SizeOfType
of string mcode
(* sizeof *) * string mcode
(* ( *) *
107 typeC
* string mcode
(* ) *)
109 | MetaErr
of Ast_cocci.meta_name mcode
* constraints
* pure
110 | MetaExpr
of Ast_cocci.meta_name mcode
* constraints
*
111 Type_cocci.typeC list
option * Ast_cocci.form
* pure
112 | MetaExprList
of Ast_cocci.meta_name mcode
(* only in arglists *) *
114 | EComma
of string mcode
(* only in arglists *)
115 | DisjExpr
of string mcode
* expression list
* string mcode list
*
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
125 and expression
= base_expression wrap
129 | NotIdCstrt
of Ast_cocci.idconstraint
130 | NotExpCstrt
of expression list
132 and listlen
= Ast_cocci.meta_name mcode
option
134 (* --------------------------------------------------------------------- *)
138 ConstVol
of Ast_cocci.const_vol mcode
* typeC
139 | BaseType
of Ast_cocci.baseType
* string mcode list
140 | Signed
of Ast_cocci.sign mcode
* typeC
option
141 | Pointer
of typeC
* string mcode
(* * *)
142 | FunctionPointer
of typeC
*
143 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
144 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
145 | FunctionType
of typeC
option *
146 string mcode
(* ( *) * parameter_list
*
148 | Array
of typeC
* string mcode
(* [ *) *
149 expression
option * string mcode
(* ] *)
150 | EnumName
of string mcode
(*enum*) * ident
(* name *)
151 | StructUnionName
of Ast_cocci.structUnion mcode
* ident
option (* name *)
152 | StructUnionDef
of typeC
(* either StructUnionName or metavar *) *
153 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
154 | TypeName
of string mcode
155 | MetaType
of Ast_cocci.meta_name mcode
* pure
156 | DisjType
of string mcode
* typeC list
* (* only after iso *)
157 string mcode list
(* the |s *) * string mcode
159 | UniqueType
of typeC
161 and typeC
= base_typeC wrap
163 (* --------------------------------------------------------------------- *)
164 (* Variable declaration *)
165 (* Even if the Cocci program specifies a list of declarations, they are
166 split out into multiple declarations of a single variable each. *)
168 and base_declaration
=
169 Init
of Ast_cocci.storage mcode
option * typeC
* ident
*
170 string mcode
(*=*) * initialiser
* string mcode
(*;*)
171 | UnInit
of Ast_cocci.storage mcode
option * typeC
* ident
*
173 | TyDecl
of typeC
* string mcode
(* ; *)
174 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
175 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
176 | Typedef
of string mcode
(* typedef *) * typeC
* typeC
* string mcode
(*;*)
177 | DisjDecl
of string mcode
* declaration list
* string mcode list
*
179 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
180 | OptDecl
of declaration
181 | UniqueDecl
of declaration
183 and declaration
= base_declaration wrap
185 (* --------------------------------------------------------------------- *)
188 and base_initialiser
=
189 MetaInit
of Ast_cocci.meta_name mcode
* pure
190 | InitExpr
of expression
191 | InitList
of string mcode
(*{*) * initialiser_list
* string mcode
(*}*)
193 designator list
(* name *) * string mcode
(*=*) *
194 initialiser
(* gccext: *)
195 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
197 | IComma
of string mcode
198 | Idots
of string mcode
(* ... *) * initialiser
option (* whencode *)
199 | OptIni
of initialiser
200 | UniqueIni
of initialiser
203 DesignatorField
of string mcode
(* . *) * ident
204 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
206 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
207 expression
* string mcode
(* ] *)
209 and initialiser
= base_initialiser wrap
211 and initialiser_list
= initialiser dots
213 (* --------------------------------------------------------------------- *)
216 and base_parameterTypeDef
=
218 | Param
of typeC
* ident
option
219 | MetaParam
of Ast_cocci.meta_name mcode
* pure
220 | MetaParamList
of Ast_cocci.meta_name mcode
* listlen
* pure
221 | PComma
of string mcode
222 | Pdots
of string mcode
(* ... *)
223 | Pcircles
of string mcode
(* ooo *)
224 | OptParam
of parameterTypeDef
225 | UniqueParam
of parameterTypeDef
227 and parameterTypeDef
= base_parameterTypeDef wrap
229 and parameter_list
= parameterTypeDef dots
231 (* --------------------------------------------------------------------- *)
232 (* #define Parameters *)
234 and base_define_param
=
236 | DPComma
of string mcode
237 | DPdots
of string mcode
(* ... *)
238 | DPcircles
of string mcode
(* ooo *)
239 | OptDParam
of define_param
240 | UniqueDParam
of define_param
242 and define_param
= base_define_param wrap
244 and base_define_parameters
=
246 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
248 and define_parameters
= base_define_parameters wrap
250 (* --------------------------------------------------------------------- *)
254 Decl
of (info
* mcodekind
) (* before the decl *) * declaration
255 | Seq
of string mcode
(* { *) * statement dots
*
257 | ExprStatement
of expression
* string mcode
(*;*)
258 | IfThen
of string mcode
(* if *) * string mcode
(* ( *) *
259 expression
* string mcode
(* ) *) *
260 statement
* (info
* mcodekind
)
261 | IfThenElse
of string mcode
(* if *) * string mcode
(* ( *) *
262 expression
* string mcode
(* ) *) *
263 statement
* string mcode
(* else *) * statement
*
265 | While
of string mcode
(* while *) * string mcode
(* ( *) *
266 expression
* string mcode
(* ) *) *
267 statement
* (info
* mcodekind
) (* after info *)
268 | Do
of string mcode
(* do *) * statement
*
269 string mcode
(* while *) * string mcode
(* ( *) *
270 expression
* string mcode
(* ) *) *
272 | For
of string mcode
(* for *) * string mcode
(* ( *) *
273 expression
option * string mcode
(*;*) *
274 expression
option * string mcode
(*;*) *
275 expression
option * string mcode
(* ) *) * statement
*
276 (info
* mcodekind
) (* after info *)
277 | Iterator
of ident
(* name *) * string mcode
(* ( *) *
278 expression dots
* string mcode
(* ) *) *
279 statement
* (info
* mcodekind
) (* after info *)
280 | Switch
of string mcode
(* switch *) * string mcode
(* ( *) *
281 expression
* string mcode
(* ) *) * string mcode
(* { *) *
282 statement
(*decl*) dots
*
283 case_line dots
* string mcode
(* } *)
284 | Break
of string mcode
(* break *) * string mcode
(* ; *)
285 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
286 | Label
of ident
* string mcode
(* : *)
287 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
288 | Return
of string mcode
(* return *) * string mcode
(* ; *)
289 | ReturnExpr
of string mcode
(* return *) * expression
*
291 | MetaStmt
of Ast_cocci.meta_name mcode
* pure
292 | MetaStmtList
of Ast_cocci.meta_name mcode
(*only in statement lists*) *
294 | Exp
of expression
(* only in dotted statement lists *)
295 | TopExp
of expression
(* for macros body *)
296 | Ty
of typeC
(* only at top level *)
297 | TopInit
of initialiser
(* only at top level *)
298 | Disj
of string mcode
* statement dots list
* string mcode list
*
300 | Nest
of string mcode
* statement dots
* string mcode
*
301 (statement dots
,statement
) whencode list
* Ast_cocci.multi
302 | Dots
of string mcode
(* ... *) *
303 (statement dots
,statement
) whencode list
304 | Circles
of string mcode
(* ooo *) *
305 (statement dots
,statement
) whencode list
306 | Stars
of string mcode
(* *** *) *
307 (statement dots
,statement
) whencode list
308 | FunDecl
of (info
* mcodekind
) (* before the function decl *) *
309 fninfo list
* ident
(* name *) *
310 string mcode
(* ( *) * parameter_list
* string mcode
(* ) *) *
311 string mcode
(* { *) * statement dots
*
313 | Include
of string mcode
(* #include *) * Ast_cocci.inc_file mcode
(* file *)
314 | Define
of string mcode
(* #define *) * ident
(* name *) *
315 define_parameters
(*params*) * statement dots
316 | OptStm
of statement
317 | UniqueStm
of statement
320 FStorage
of Ast_cocci.storage mcode
322 | FInline
of string mcode
323 | FAttr
of string mcode
325 and ('a
,'b
) whencode
=
328 | WhenModifier
of Ast_cocci.when_modifier
329 | WhenNotTrue
of expression
330 | WhenNotFalse
of expression
332 and statement
= base_statement wrap
335 Default
of string mcode
(* default *) * string mcode
(*:*) * statement dots
336 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*) *
338 | DisjCase
of string mcode
* case_line list
*
339 string mcode list
(* the |s *) * string mcode
340 | OptCase
of case_line
342 and case_line
= base_case_line wrap
344 (* --------------------------------------------------------------------- *)
348 MetaPos
of Ast_cocci.meta_name mcode
* Ast_cocci.meta_name list
*
349 Ast_cocci.meta_collect
352 (* --------------------------------------------------------------------- *)
357 | CODE
of statement dots
358 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
359 | ERRORWORDS
of expression list
360 | OTHER
of statement
(* temporary, disappears after top_level.ml *)
362 and top_level
= base_top_level wrap
363 and rule
= top_level list
367 (rule
* Ast_cocci.metavar list
*
368 (string list
* string list
* Ast_cocci.dependency
* string *
370 (rule
* Ast_cocci.metavar list
) * Ast_cocci.ruletype
372 string * Ast_cocci.dependency
* (string * Ast_cocci.meta_name
) list
*
374 | InitialScriptRule
of string (*language*) * string (*code*)
375 | FinalScriptRule
of string (*language*) * string (*code*)
377 (* --------------------------------------------------------------------- *)
380 DotsExprTag
of expression dots
381 | DotsInitTag
of initialiser dots
382 | DotsParamTag
of parameterTypeDef dots
383 | DotsStmtTag
of statement dots
384 | DotsDeclTag
of declaration dots
385 | DotsCaseTag
of case_line dots
387 | ExprTag
of expression
388 | ArgExprTag
of expression
(* for isos *)
389 | TestExprTag
of expression
(* for isos *)
391 | ParamTag
of parameterTypeDef
392 | InitTag
of initialiser
393 | DeclTag
of declaration
394 | StmtTag
of statement
395 | CaseLineTag
of case_line
396 | TopTag
of top_level
397 | IsoWhenTag
of Ast_cocci.when_modifier
(*only for when code, in iso phase*)
398 | IsoWhenTTag
of expression
(*only for when code, in iso phase*)
399 | IsoWhenFTag
of expression
(*only for when code, in iso phase*)
400 | MetaPosTag
of meta_pos
(* only in iso phase *)
402 val dotsExpr
: expression dots
-> anything
403 val dotsInit
: initialiser dots
-> anything
404 val dotsParam
: parameterTypeDef dots
-> anything
405 val dotsStmt
: statement dots
-> anything
406 val dotsDecl
: declaration dots
-> anything
407 val dotsCase
: case_line dots
-> anything
408 val ident
: ident
-> anything
409 val expr
: expression
-> anything
410 val typeC
: typeC
-> anything
411 val param
: parameterTypeDef
-> anything
412 val ini
: initialiser
-> anything
413 val decl
: declaration
-> anything
414 val stmt
: statement
-> anything
415 val case_line
: case_line
-> anything
416 val top
: top_level
-> anything
418 (* --------------------------------------------------------------------- *)
420 val undots
: 'a dots
-> 'a list
422 (* --------------------------------------------------------------------- *)
423 (* Avoid cluttering the parser. Calculated in compute_lines.ml. *)
425 val default_info
: unit -> info
426 val default_befaft
: unit -> mcodekind
427 val context_befaft
: unit -> mcodekind
428 val wrap
: 'a
-> 'a wrap
429 val context_wrap
: 'a
-> 'a wrap
430 val unwrap
: 'a wrap
-> 'a
431 val unwrap_mcode
: 'a mcode
-> 'a
432 val rewrap
: 'a wrap
-> 'b
-> 'b wrap
433 val rewrap_mcode
: 'a mcode
-> 'b
-> 'b mcode
434 val copywrap
: 'a wrap
-> 'b
-> 'b wrap
435 val get_pos
: 'a mcode
-> meta_pos
436 val get_pos_ref
: 'a mcode
-> meta_pos
ref
437 val set_pos
: meta_pos
-> 'a mcode
-> 'a mcode
438 val get_info
: 'a wrap
-> info
439 val set_info
: 'a wrap
-> info
-> 'a wrap
440 val get_index
: 'a wrap
-> int
441 val set_index
: 'a wrap
-> int -> unit
442 val get_line
: 'a wrap
-> int
443 val get_line_end
: 'a wrap
-> int
444 val get_mcodekind
: 'a wrap
-> mcodekind
445 val get_mcode_mcodekind
: 'a mcode
-> mcodekind
446 val get_mcodekind_ref
: 'a wrap
-> mcodekind
ref
447 val set_mcodekind
: 'a wrap
-> mcodekind
-> unit
448 val set_type
: 'a wrap
-> Type_cocci.typeC
option -> unit
449 val get_type
: 'a wrap
-> Type_cocci.typeC
option
450 val set_dots_bef_aft
: statement
-> dots_bef_aft
-> statement
451 val get_dots_bef_aft
: 'a wrap
-> dots_bef_aft
452 val set_arg_exp
: expression
-> expression
453 val get_arg_exp
: expression
-> bool
454 val set_test_pos
: expression
-> expression
455 val get_test_pos
: 'a wrap
-> bool
456 val set_test_exp
: expression
-> expression
457 val get_test_exp
: 'a wrap
-> bool
458 val set_iso
: 'a wrap
-> (string*anything
) list
-> 'a wrap
459 val get_iso
: 'a wrap
-> (string*anything
) list
460 val fresh_index
: unit -> int
461 val set_mcode_data
: 'a
-> 'a mcode
-> 'a mcode
462 val make_mcode
: 'a
-> 'a mcode
463 val make_mcode_info
: 'a
-> info
-> 'a mcode
465 val ast0_type_to_type
: typeC
-> Type_cocci.typeC
466 val reverse_type
: Type_cocci.typeC
-> base_typeC
469 val lub_pure
: pure
-> pure
-> pure
471 (* --------------------------------------------------------------------- *)
473 val rule_name
: string ref (* for the convenience of the parser *)