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
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
* 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
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
* 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 *) *
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
127 and listlen
= Ast_cocci.meta_name mcode
option
129 (* --------------------------------------------------------------------- *)
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
*
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
154 | UniqueType
of typeC
156 and typeC
= base_typeC wrap
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. *)
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
*
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
*
174 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
175 | OptDecl
of declaration
176 | UniqueDecl
of declaration
178 and declaration
= base_declaration wrap
180 (* --------------------------------------------------------------------- *)
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
(*}*)
188 designator list
(* name *) * string mcode
(*=*) *
189 initialiser
(* gccext: *)
190 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
192 | IComma
of string mcode
193 | Idots
of string mcode
(* ... *) * initialiser
option (* whencode *)
194 | OptIni
of initialiser
195 | UniqueIni
of initialiser
198 DesignatorField
of string mcode
(* . *) * ident
199 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
201 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
202 expression
* string mcode
(* ] *)
204 and initialiser
= base_initialiser wrap
206 and initialiser_list
= initialiser dots
208 (* --------------------------------------------------------------------- *)
211 and base_parameterTypeDef
=
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
222 and parameterTypeDef
= base_parameterTypeDef wrap
224 and parameter_list
= parameterTypeDef dots
226 (* --------------------------------------------------------------------- *)
227 (* #define Parameters *)
229 and base_define_param
=
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
237 and define_param
= base_define_param wrap
239 and base_define_parameters
=
241 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
243 and define_parameters
= base_define_parameters wrap
245 (* --------------------------------------------------------------------- *)
249 Decl
of (info
* mcodekind
) (* before the decl *) * declaration
250 | Seq
of string mcode
(* { *) * statement dots
*
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
*
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
(* ) *) *
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
*
285 | MetaStmt
of Ast_cocci.meta_name mcode
* pure
286 | MetaStmtList
of Ast_cocci.meta_name mcode
(*only in statement lists*) *
288 | Exp
of expression
(* only in dotted statement lists *)
289 | TopExp
of expression
(* for macros body *)
290 | Ty
of typeC
(* only at top level *)
291 | TopInit
of initialiser
(* only at top level *)
292 | Disj
of string mcode
* statement dots list
* string mcode list
*
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
*
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
314 FStorage
of Ast_cocci.storage mcode
316 | FInline
of string mcode
317 | FAttr
of string mcode
319 and ('a
,'b
) whencode
=
322 | WhenModifier
of Ast_cocci.when_modifier
323 | WhenNotTrue
of expression
324 | WhenNotFalse
of expression
326 and statement
= base_statement wrap
329 Default
of string mcode
(* default *) * string mcode
(*:*) * statement dots
330 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*) *
332 | OptCase
of case_line
334 and case_line
= base_case_line wrap
336 (* --------------------------------------------------------------------- *)
340 MetaPos
of Ast_cocci.meta_name mcode
* Ast_cocci.meta_name list
*
341 Ast_cocci.meta_collect
344 (* --------------------------------------------------------------------- *)
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 *)
354 and top_level
= base_top_level wrap
355 and rule
= top_level list
359 (rule
* Ast_cocci.metavar list
*
360 (string list
* string list
* Ast_cocci.dependency
* string *
362 (rule
* Ast_cocci.metavar list
) * Ast_cocci.ruletype
364 string * Ast_cocci.dependency
* (string * Ast_cocci.meta_name
) list
*
366 | InitialScriptRule
of string * string
367 | FinalScriptRule
of string * string
369 (* --------------------------------------------------------------------- *)
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
379 | ExprTag
of expression
380 | ArgExprTag
of expression
(* for isos *)
381 | TestExprTag
of expression
(* for isos *)
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*)
390 | IsoWhenTTag
of expression
(*only for when code, in iso phase*)
391 | IsoWhenFTag
of expression
(*only for when code, in iso phase*)
392 | MetaPosTag
of meta_pos
(* only in iso phase *)
394 val dotsExpr
: expression dots
-> anything
395 val dotsInit
: initialiser dots
-> anything
396 val dotsParam
: parameterTypeDef dots
-> anything
397 val dotsStmt
: statement dots
-> anything
398 val dotsDecl
: declaration dots
-> anything
399 val dotsCase
: case_line dots
-> anything
400 val ident
: ident
-> anything
401 val expr
: expression
-> anything
402 val typeC
: typeC
-> anything
403 val param
: parameterTypeDef
-> anything
404 val ini
: initialiser
-> anything
405 val decl
: declaration
-> anything
406 val stmt
: statement
-> anything
407 val case_line
: case_line
-> anything
408 val top
: top_level
-> anything
410 (* --------------------------------------------------------------------- *)
412 val undots
: 'a dots
-> 'a list
414 (* --------------------------------------------------------------------- *)
415 (* Avoid cluttering the parser. Calculated in compute_lines.ml. *)
417 val default_info
: unit -> info
418 val default_befaft
: unit -> mcodekind
419 val context_befaft
: unit -> mcodekind
420 val wrap
: 'a
-> 'a wrap
421 val context_wrap
: 'a
-> 'a wrap
422 val unwrap
: 'a wrap
-> 'a
423 val unwrap_mcode
: 'a mcode
-> 'a
424 val rewrap
: 'a wrap
-> 'b
-> 'b wrap
425 val rewrap_mcode
: 'a mcode
-> 'b
-> 'b mcode
426 val copywrap
: 'a wrap
-> 'b
-> 'b wrap
427 val get_pos
: 'a mcode
-> meta_pos
428 val get_pos_ref
: 'a mcode
-> meta_pos
ref
429 val set_pos
: meta_pos
-> 'a mcode
-> 'a mcode
430 val get_info
: 'a wrap
-> info
431 val set_info
: 'a wrap
-> info
-> 'a wrap
432 val get_index
: 'a wrap
-> int
433 val set_index
: 'a wrap
-> int -> unit
434 val get_line
: 'a wrap
-> int
435 val get_line_end
: 'a wrap
-> int
436 val get_mcodekind
: 'a wrap
-> mcodekind
437 val get_mcode_mcodekind
: 'a mcode
-> mcodekind
438 val get_mcodekind_ref
: 'a wrap
-> mcodekind
ref
439 val set_mcodekind
: 'a wrap
-> mcodekind
-> unit
440 val set_type
: 'a wrap
-> Type_cocci.typeC
option -> unit
441 val get_type
: 'a wrap
-> Type_cocci.typeC
option
442 val set_dots_bef_aft
: statement
-> dots_bef_aft
-> statement
443 val get_dots_bef_aft
: 'a wrap
-> dots_bef_aft
444 val set_arg_exp
: expression
-> expression
445 val get_arg_exp
: expression
-> bool
446 val set_test_pos
: expression
-> expression
447 val get_test_pos
: 'a wrap
-> bool
448 val set_test_exp
: expression
-> expression
449 val get_test_exp
: 'a wrap
-> bool
450 val set_iso
: 'a wrap
-> (string*anything
) list
-> 'a wrap
451 val get_iso
: 'a wrap
-> (string*anything
) list
452 val fresh_index
: unit -> int
453 val set_mcode_data
: 'a
-> 'a mcode
-> 'a mcode
454 val make_mcode
: 'a
-> 'a mcode
455 val make_mcode_info
: 'a
-> info
-> 'a mcode
457 val ast0_type_to_type
: typeC
-> Type_cocci.typeC
458 val reverse_type
: Type_cocci.typeC
-> base_typeC
461 val lub_pure
: pure
-> pure
-> pure
463 (* --------------------------------------------------------------------- *)
465 val rule_name
: string ref (* for the convenience of the parser *)