1 (* Constraints on Meta-* Identifiers, Functions *)
4 | IdNegIdSet
of string list
5 | IdRegExp
of string * Str.regexp
6 | IdNotRegExp
of string * Str.regexp
8 (* --------------------------------------------------------------------- *)
11 type info
= { line
: int; column
: int;
12 strbef
: (string * int (* line *) * int (* col *)) list
;
13 straft
: (string * int (* line *) * int (* col *)) list
}
15 type meta_name
= string * string
19 free_vars
: meta_name list
; (*free vars*)
20 minus_free_vars
: meta_name list
; (*minus free vars*)
21 fresh_vars
: (meta_name
* seed
) list
; (*fresh vars*)
22 inherited
: meta_name list
; (*inherited vars*)
23 saved_witness
: meta_name list
; (*witness vars*)
24 bef_aft
: dots_bef_aft
;
25 pos_info
: meta_name mcode
option; (* pos info, try not to duplicate *)
26 true_if_test_exp
: bool;(* true if "test_exp from iso", only for exprs *)
27 (* isos relevant to the term; ultimately only used for rule_elems *)
28 iso_info
: (string*anything
) list
}
31 BEFORE
of 'a list list
* count
32 | AFTER
of 'a list list
* count
33 | BEFOREAFTER
of 'a list list
* 'a list list
* count
36 and 'a mcode
= 'a
* info
* mcodekind
* meta_pos
(* pos variable *)
37 (* pos is an offset indicating where in the C code the mcodekind has an
40 MINUS
of pos
* int list
* int * anything list list
41 | CONTEXT
of pos
* anything befaft
43 and count
= ONE
(* + *) | MANY
(* ++ *)
45 Real
of int (* charpos *) | Virt
of int * int (* charpos + offset *)
46 and pos
= NoPos
| DontCarePos
| FixPos
of (fixpos
* fixpos
)
50 | AddingBetweenDots
of statement
* int (*index of let var*)
51 | DroppingBetweenDots
of statement
* int (*index of let var*)
53 and inherited
= Type_cocci.inherited
54 and keep_binding
= Type_cocci.keep_binding
55 and multi
= bool (*true if a nest is one or more, false if it is zero or more*)
58 meta_name list
(*free vars*) * (meta_name
* seed
) list
(*fresh*) *
59 meta_name list
(*inherited vars*) * mcodekind
61 (* --------------------------------------------------------------------- *)
64 and arity
= UNIQUE
| OPT
| MULTI
| NONE
67 MetaIdDecl
of arity
* meta_name
(* name *)
68 | MetaFreshIdDecl
of meta_name
(* name *) * seed
(* seed *)
69 | MetaTypeDecl
of arity
* meta_name
(* name *)
70 | MetaInitDecl
of arity
* meta_name
(* name *)
71 | MetaListlenDecl
of meta_name
(* name *)
72 | MetaParamDecl
of arity
* meta_name
(* name *)
73 | MetaParamListDecl
of arity
* meta_name
(*name*) * meta_name
option (*len*)
75 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
76 | MetaErrDecl
of arity
* meta_name
(* name *)
78 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
80 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
81 | MetaLocalIdExpDecl
of
82 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
83 | MetaExpListDecl
of arity
* meta_name
(*name*) * meta_name
option (*len*)
84 | MetaStmDecl
of arity
* meta_name
(* name *)
85 | MetaStmListDecl
of arity
* meta_name
(* name *)
86 | MetaFuncDecl
of arity
* meta_name
(* name *)
87 | MetaLocalFuncDecl
of arity
* meta_name
(* name *)
88 | MetaPosDecl
of arity
* meta_name
(* name *)
89 | MetaDeclarerDecl
of arity
* meta_name
(* name *)
90 | MetaIteratorDecl
of arity
* meta_name
(* name *)
92 and seed
= NoVal
| StringSeed
of string | ListSeed
of seed_elem list
93 and seed_elem
= SeedString
of string | SeedId
of meta_name
95 (* --------------------------------------------------------------------- *)
96 (* --------------------------------------------------------------------- *)
104 and 'a dots
= 'a base_dots wrap
106 (* --------------------------------------------------------------------- *)
111 | MetaId
of meta_name mcode
* idconstraint
* keep_binding
* inherited
112 | MetaFunc
of meta_name mcode
* idconstraint
* keep_binding
* inherited
113 | MetaLocalFunc
of meta_name mcode
* idconstraint
* keep_binding
* inherited
116 | UniqueIdent
of ident
118 and ident
= base_ident wrap
120 (* --------------------------------------------------------------------- *)
123 and base_expression
=
125 | Constant
of constant mcode
126 | FunCall
of expression
* string mcode
(* ( *) *
127 expression dots
* string mcode
(* ) *)
128 | Assignment
of expression
* assignOp mcode
* expression
* bool
129 | CondExpr
of expression
* string mcode
(* ? *) * expression
option *
130 string mcode
(* : *) * expression
131 | Postfix
of expression
* fixOp mcode
132 | Infix
of expression
* fixOp mcode
133 | Unary
of expression
* unaryOp mcode
134 | Binary
of expression
* binaryOp mcode
* expression
135 | Nested
of expression
* binaryOp mcode
* expression
136 | ArrayAccess
of expression
* string mcode
(* [ *) * expression
*
138 | RecordAccess
of expression
* string mcode
(* . *) * ident
139 | RecordPtAccess
of expression
* string mcode
(* -> *) * ident
140 | Cast
of string mcode
(* ( *) * fullType
* string mcode
(* ) *) *
143 | SizeOfExpr
of string mcode
(* sizeof *) * expression
144 | SizeOfType
of string mcode
(* sizeof *) * string mcode
(* ( *) *
145 fullType
* string mcode
(* ) *)
146 | TypeExp
of fullType
148 | Paren
of string mcode
(* ( *) * expression
*
151 | MetaErr
of meta_name mcode
* constraints
* keep_binding
*
153 | MetaExpr
of meta_name mcode
* constraints
* keep_binding
*
154 Type_cocci.typeC list
option * form
* inherited
155 | MetaExprList
of meta_name mcode
* listlen
option *
156 keep_binding
* inherited
(* only in arg lists *)
158 | EComma
of string mcode
(* only in arg lists *)
160 | DisjExpr
of expression list
161 | NestExpr
of expression dots
* expression
option * multi
163 (* can appear in arg lists, and also inside Nest, as in:
164 if(< ... X ... Y ...>)
165 In the following, the expression option is the WHEN *)
166 | Edots
of string mcode
(* ... *) * expression
option
167 | Ecircles
of string mcode
(* ooo *) * expression
option
168 | Estars
of string mcode
(* *** *) * expression
option
170 | OptExp
of expression
171 | UniqueExp
of expression
175 | NotIdCstrt
of idconstraint
176 | NotExpCstrt
of expression list
178 and form
= ANY
| ID
| LocalID
| CONST
(* form for MetaExp *)
180 and expression
= base_expression wrap
182 and listlen
= meta_name mcode
* keep_binding
* inherited
184 and unaryOp
= GetRef
| DeRef
| UnPlus
| UnMinus
| Tilde
| Not
185 and assignOp
= SimpleAssign
| OpAssign
of arithOp
186 and fixOp
= Dec
| Inc
188 and binaryOp
= Arith
of arithOp
| Logical
of logicalOp
190 Plus
| Minus
| Mul
| Div
| Mod
| DecLeft
| DecRight
| And
| Or
| Xor
191 and logicalOp
= Inf
| Sup
| InfEq
| SupEq
| Eq
| NotEq
| AndLog
| OrLog
199 (* --------------------------------------------------------------------- *)
203 Type
of const_vol mcode
option * typeC
204 | DisjType
of fullType list
(* only after iso *)
205 | OptType
of fullType
206 | UniqueType
of fullType
209 BaseType
of baseType
* string mcode list
(* Yoann style *)
210 | SignedT
of sign mcode
* typeC
option
211 | Pointer
of fullType
* string mcode
(* * *)
212 | FunctionPointer
of fullType
*
213 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
214 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
215 | FunctionType
of bool (* true if all minus for dropping return type *) *
217 string mcode
(* ( *) * parameter_list
*
219 | Array
of fullType
* string mcode
(* [ *) *
220 expression
option * string mcode
(* ] *)
221 | EnumName
of string mcode
(*enum*) * ident
(* name *)
222 | StructUnionName
of structUnion mcode
* ident
option (* name *)
223 | StructUnionDef
of fullType
(* either StructUnionName or metavar *) *
224 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
225 | TypeName
of string mcode
227 | MetaType
of meta_name mcode
* keep_binding
* inherited
229 and fullType
= base_fullType wrap
230 and typeC
= base_typeC wrap
232 and baseType
= VoidType
| CharType
| ShortType
| IntType
| DoubleType
233 | FloatType
| LongType
| LongLongType
235 and structUnion
= Struct
| Union
237 and sign
= Signed
| Unsigned
239 and const_vol
= Const
| Volatile
241 (* --------------------------------------------------------------------- *)
242 (* Variable declaration *)
243 (* Even if the Cocci program specifies a list of declarations, they are
244 split out into multiple declarations of a single variable each. *)
246 and base_declaration
=
247 Init
of storage mcode
option * fullType
* ident
* string mcode
(*=*) *
248 initialiser
* string mcode
(*;*)
249 | UnInit
of storage mcode
option * fullType
* ident
* string mcode
(* ; *)
250 | TyDecl
of fullType
* string mcode
(* ; *)
251 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
252 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
253 | Typedef
of string mcode
(*typedef*) * fullType
* typeC
* string mcode
(*;*)
254 | DisjDecl
of declaration list
255 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
257 | MetaDecl
of meta_name mcode
* keep_binding
* inherited
259 | OptDecl
of declaration
260 | UniqueDecl
of declaration
262 and declaration
= base_declaration wrap
264 (* --------------------------------------------------------------------- *)
267 and base_initialiser
=
268 MetaInit
of meta_name mcode
* keep_binding
* inherited
269 | InitExpr
of expression
270 | InitList
of string mcode
(*{*) * initialiser list
* string mcode
(*}*) *
271 initialiser list
(* whencode: elements that shouldn't appear in init *)
273 designator list
(* name *) * string mcode
(*=*) *
274 initialiser
(* gccext: *)
275 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
277 | IComma
of string mcode
(* , *)
278 | OptIni
of initialiser
279 | UniqueIni
of initialiser
282 DesignatorField
of string mcode
(* . *) * ident
283 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
285 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
286 expression
* string mcode
(* ] *)
288 and initialiser
= base_initialiser wrap
290 (* --------------------------------------------------------------------- *)
293 and base_parameterTypeDef
=
294 VoidParam
of fullType
295 | Param
of fullType
* ident
option
297 | MetaParam
of meta_name mcode
* keep_binding
* inherited
298 | MetaParamList
of meta_name mcode
* listlen
option * keep_binding
*
301 | PComma
of string mcode
303 | Pdots
of string mcode
(* ... *)
304 | Pcircles
of string mcode
(* ooo *)
306 | OptParam
of parameterTypeDef
307 | UniqueParam
of parameterTypeDef
309 and parameterTypeDef
= base_parameterTypeDef wrap
311 and parameter_list
= parameterTypeDef dots
313 (* --------------------------------------------------------------------- *)
314 (* #define Parameters *)
316 and base_define_param
=
318 | DPComma
of string mcode
319 | DPdots
of string mcode
(* ... *)
320 | DPcircles
of string mcode
(* ooo *)
321 | OptDParam
of define_param
322 | UniqueDParam
of define_param
324 and define_param
= base_define_param wrap
326 and base_define_parameters
=
328 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
330 and define_parameters
= base_define_parameters wrap
332 (* --------------------------------------------------------------------- *)
335 (* PER = keep bindings separate, ANY = collect them *)
336 and meta_collect
= PER
| ALL
339 MetaPos
of meta_name mcode
* meta_name list
*
340 meta_collect
* keep_binding
* inherited
343 (* --------------------------------------------------------------------- *)
344 (* Function declaration *)
346 and storage
= Static
| Auto
| Register
| Extern
348 (* --------------------------------------------------------------------- *)
352 FunHeader
of mcodekind
(* before the function header *) *
353 bool (* true if all minus, for dropping static, etc *) *
354 fninfo list
* ident
(* name *) *
355 string mcode
(* ( *) * parameter_list
*
357 | Decl
of mcodekind
(* before the decl *) *
358 bool (* true if all minus *) * declaration
360 | SeqStart
of string mcode
(* { *)
361 | SeqEnd
of string mcode
(* } *)
363 | ExprStatement
of expression
* string mcode
(*;*)
364 | IfHeader
of string mcode
(* if *) * string mcode
(* ( *) *
365 expression
* string mcode
(* ) *)
366 | Else
of string mcode
(* else *)
367 | WhileHeader
of string mcode
(* while *) * string mcode
(* ( *) *
368 expression
* string mcode
(* ) *)
369 | DoHeader
of string mcode
(* do *)
370 | WhileTail
of string mcode
(* while *) * string mcode
(* ( *) *
371 expression
* string mcode
(* ) *) *
373 | ForHeader
of string mcode
(* for *) * string mcode
(* ( *) *
374 expression
option * string mcode
(*;*) *
375 expression
option * string mcode
(*;*) *
376 expression
option * string mcode
(* ) *)
377 | IteratorHeader
of ident
(* name *) * string mcode
(* ( *) *
378 expression dots
* string mcode
(* ) *)
379 | SwitchHeader
of string mcode
(* switch *) * string mcode
(* ( *) *
380 expression
* string mcode
(* ) *)
381 | Break
of string mcode
(* break *) * string mcode
(* ; *)
382 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
383 | Label
of ident
* string mcode
(* : *)
384 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
385 | Return
of string mcode
(* return *) * string mcode
(* ; *)
386 | ReturnExpr
of string mcode
(* return *) * expression
*
389 | MetaRuleElem
of meta_name mcode
* keep_binding
* inherited
390 | MetaStmt
of meta_name mcode
* keep_binding
* metaStmtInfo
*
392 | MetaStmtList
of meta_name mcode
* keep_binding
* inherited
395 | TopExp
of expression
(* for macros body *)
396 | Ty
of fullType
(* only at top level *)
397 | TopInit
of initialiser
(* only at top level *)
398 | Include
of string mcode
(*#include*) * inc_file mcode
(*file *)
399 | DefineHeader
of string mcode
(* #define *) * ident
(* name *) *
400 define_parameters
(*params*)
401 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*)
402 | Default
of string mcode
(* default *) * string mcode
(*:*)
403 | DisjRuleElem
of rule_elem list
406 FStorage
of storage mcode
408 | FInline
of string mcode
409 | FAttr
of string mcode
412 NotSequencible
| SequencibleAfterDots
of dots_whencode list
| Sequencible
414 and rule_elem
= base_rule_elem wrap
417 Seq
of rule_elem
(* { *) *
418 statement dots
* rule_elem
(* } *)
419 | IfThen
of rule_elem
(* header *) * statement
* end_info
420 | IfThenElse
of rule_elem
(* header *) * statement
*
421 rule_elem
(* else *) * statement
* end_info
422 | While
of rule_elem
(* header *) * statement
* end_info
423 | Do
of rule_elem
(* do *) * statement
* rule_elem
(* tail *)
424 | For
of rule_elem
(* header *) * statement
* end_info
425 | Iterator
of rule_elem
(* header *) * statement
* end_info
(*enditer*)
426 | Switch
of rule_elem
(* header *) * rule_elem
(* { *) *
427 statement
(*decl*) dots
* case_line list
* rule_elem
(*}*)
428 | Atomic
of rule_elem
429 | Disj
of statement dots list
430 | Nest
of statement dots
*
431 (statement dots
,statement
) whencode list
* multi
*
432 dots_whencode list
* dots_whencode list
433 | FunDecl
of rule_elem
(* header *) * rule_elem
(* { *) *
434 statement dots
* rule_elem
(* } *)
435 | Define
of rule_elem
(* header *) * statement dots
436 | Dots
of string mcode
(* ... *) *
437 (statement dots
,statement
) whencode list
*
438 dots_whencode list
* dots_whencode list
439 | Circles
of string mcode
(* ooo *) *
440 (statement dots
,statement
) whencode list
*
441 dots_whencode list
* dots_whencode list
442 | Stars
of string mcode
(* *** *) *
443 (statement dots
,statement
) whencode list
*
444 dots_whencode list
* dots_whencode list
445 | OptStm
of statement
446 | UniqueStm
of statement
448 and ('a
,'b
) whencode
=
451 | WhenModifier
of when_modifier
452 | WhenNotTrue
of rule_elem
453 | WhenNotFalse
of rule_elem
462 WParen
of rule_elem
* meta_name
(*pren_var*)
464 | Other_dots
of statement dots
466 and statement
= base_statement wrap
469 CaseLine
of rule_elem
(* case/default header *) * statement dots
470 | OptCase
of case_line
472 and case_line
= base_case_line wrap
475 Local
of inc_elem list
476 | NonLocal
of inc_elem list
484 | CODE
of statement dots
485 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
486 | ERRORWORDS
of expression list
488 and top_level
= base_top_level wrap
491 CocciRulename
of string option * dependency
* string list
* string list
*
493 (* true if the whole thing is an expression *)
494 | GeneratedRulename
of string option * dependency
*
495 string list
* string list
* exists
* bool
496 (* true if the whole thing is an expression *)
497 | ScriptRulename
of string * dependency
498 | InitialScriptRulename
of string
499 | FinalScriptRulename
of string
501 and ruletype
= Normal
| Generated
504 CocciRule
of string (* name *) *
505 (dependency
* string list
(* dropped isos *) * exists
) *
506 top_level list
* bool list
(* true if generates an exp *) * ruletype
507 | ScriptRule
of string * dependency
* (string * meta_name
) list
* string
508 | InitialScriptRule
of string * string
509 | FinalScriptRule
of string * string
512 Dep
of string (* rule applies for the current binding *)
513 | AntiDep
of string (* rule doesn't apply for the current binding *)
514 | EverDep
of string (* rule applies for some binding *)
515 | NeverDep
of string (* rule never applies for any binding *)
516 | AndDep
of dependency
* dependency
517 | OrDep
of dependency
* dependency
520 and rule_with_metavars
= metavar list
* rule
523 FullTypeTag
of fullType
524 | BaseTypeTag
of baseType
525 | StructUnionTag
of structUnion
528 | ExpressionTag
of expression
529 | ConstantTag
of constant
530 | UnaryOpTag
of unaryOp
531 | AssignOpTag
of assignOp
533 | BinaryOpTag
of binaryOp
534 | ArithOpTag
of arithOp
535 | LogicalOpTag
of logicalOp
536 | DeclarationTag
of declaration
537 | InitTag
of initialiser
538 | StorageTag
of storage
539 | IncFileTag
of inc_file
540 | Rule_elemTag
of rule_elem
541 | StatementTag
of statement
542 | CaseLineTag
of case_line
543 | ConstVolTag
of const_vol
544 | Token
of string * info
option
545 | Pragma
of string list
547 | ExprDotsTag
of expression dots
548 | ParamDotsTag
of parameterTypeDef dots
549 | StmtDotsTag
of statement dots
550 | DeclDotsTag
of declaration dots
552 | ParamTag
of parameterTypeDef
553 | SgrepStartTag
of string
554 | SgrepEndTag
of string
556 (* --------------------------------------------------------------------- *)
558 and exists
= Exists
| Forall
| Undetermined
560 (* --------------------------------------------------------------------- *)
562 val mkToken
: string -> anything
564 val undots
: 'a dots
-> 'a list
566 val lub_count
: count
-> count
-> count
568 (* --------------------------------------------------------------------- *)
570 val rewrap
: 'a wrap
-> 'b
-> 'b wrap
571 val rewrap_mcode
: 'a mcode
-> 'a
-> 'a mcode
572 val unwrap
: 'a wrap
-> 'a
573 val unwrap_mcode
: 'a mcode
-> 'a
574 val get_mcodekind
: 'a mcode
-> mcodekind
575 val get_line
: 'a wrap
-> line
576 val get_mcode_line
: 'a mcode
-> line
577 val get_mcode_col
: 'a mcode
-> int
578 val get_fvs
: 'a wrap
-> meta_name list
579 val get_wcfvs
: ('a wrap
,'b wrap
) whencode list
-> meta_name list
580 val set_fvs
: meta_name list
-> 'a wrap
-> 'a wrap
581 val get_mfvs
: 'a wrap
-> meta_name list
582 val set_mfvs
: meta_name list
-> 'a wrap
-> 'a wrap
583 val get_fresh
: 'a wrap
-> (meta_name
* seed
) list
584 val get_inherited
: 'a wrap
-> meta_name list
585 val get_saved
: 'a wrap
-> meta_name list
586 val get_dots_bef_aft
: statement
-> dots_bef_aft
587 val set_dots_bef_aft
: dots_bef_aft
-> statement
-> statement
588 val get_pos
: 'a wrap
-> meta_name mcode
option
589 val set_pos
: 'a wrap
-> meta_name mcode
option -> 'a wrap
590 val get_test_exp
: 'a wrap
-> bool
591 val set_test_exp
: expression
-> expression
592 val get_isos
: 'a wrap
-> (string*anything
) list
593 val set_isos
: 'a wrap
-> (string*anything
) list
-> 'a wrap
594 val get_pos_var
: 'a mcode
-> meta_pos
595 val set_pos_var
: meta_pos
-> 'a mcode
-> 'a mcode
596 val drop_pos
: 'a mcode
-> 'a mcode
598 val get_meta_name
: metavar
-> meta_name
600 val tag2c
: anything
-> string
604 val make_meta_rule_elem
:
605 string -> mcodekind
->
606 (meta_name list
* (meta_name
* seed
) list
* meta_name list
) ->
610 string -> mcodekind
->
611 (meta_name list
* (meta_name
* seed
) list
* meta_name list
) ->
614 val make_term
: 'a
-> 'a wrap
615 val make_mcode
: 'a
-> 'a mcode
617 val equal_pos
: fixpos
-> fixpos
-> bool