1 (* --------------------------------------------------------------------- *)
4 type info
= { line
: int; column
: int;
5 strbef
: (string * int (* line *) * int (* col *)) list
;
6 straft
: (string * int (* line *) * int (* col *)) list
}
8 type meta_name
= string * string
12 free_vars
: meta_name list
; (*free vars*)
13 minus_free_vars
: meta_name list
; (*minus free vars*)
14 fresh_vars
: (meta_name
* string (*seed*) option) list
; (*fresh vars*)
15 inherited
: meta_name list
; (*inherited vars*)
16 saved_witness
: meta_name list
; (*witness vars*)
17 bef_aft
: dots_bef_aft
;
18 pos_info
: meta_name mcode
option; (* pos info, try not to duplicate *)
19 true_if_test_exp
: bool;(* true if "test_exp from iso", only for exprs *)
20 (* isos relevant to the term; ultimately only used for rule_elems *)
21 iso_info
: (string*anything
) list
}
24 BEFORE
of 'a list list
25 | AFTER
of 'a list list
26 | BEFOREAFTER
of 'a list list
* 'a list list
29 and 'a mcode
= 'a
* info
* mcodekind
* meta_pos
(* pos variable *)
30 (* pos is an offset indicating where in the C code the mcodekind has an
33 MINUS
of pos
* int list
* int * anything list list
34 | CONTEXT
of pos
* anything befaft
37 Real
of int (* charpos *) | Virt
of int * int (* charpos + offset *)
38 and pos
= NoPos
| DontCarePos
| FixPos
of (fixpos
* fixpos
)
42 | AddingBetweenDots
of statement
* int (*index of let var*)
43 | DroppingBetweenDots
of statement
* int (*index of let var*)
45 and inherited
= Type_cocci.inherited
46 and keep_binding
= Type_cocci.keep_binding
47 and multi
= bool (*true if a nest is one or more, false if it is zero or more*)
50 meta_name list
(*free vars*) * (meta_name
* string option) list
(*fresh*) *
51 meta_name list
(*inherited vars*) * mcodekind
53 (* --------------------------------------------------------------------- *)
56 and arity
= UNIQUE
| OPT
| MULTI
| NONE
59 MetaIdDecl
of arity
* meta_name
(* name *)
60 | MetaFreshIdDecl
of meta_name
(* name *) * string option (* seed *)
61 | MetaTypeDecl
of arity
* meta_name
(* name *)
62 | MetaInitDecl
of arity
* meta_name
(* name *)
63 | MetaListlenDecl
of meta_name
(* name *)
64 | MetaParamDecl
of arity
* meta_name
(* name *)
65 | MetaParamListDecl
of arity
* meta_name
(*name*) * meta_name
option (*len*)
67 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
68 | MetaErrDecl
of arity
* meta_name
(* name *)
70 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
72 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
73 | MetaLocalIdExpDecl
of
74 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
75 | MetaExpListDecl
of arity
* meta_name
(*name*) * meta_name
option (*len*)
76 | MetaStmDecl
of arity
* meta_name
(* name *)
77 | MetaStmListDecl
of arity
* meta_name
(* name *)
78 | MetaFuncDecl
of arity
* meta_name
(* name *)
79 | MetaLocalFuncDecl
of arity
* meta_name
(* name *)
80 | MetaPosDecl
of arity
* meta_name
(* name *)
81 | MetaDeclarerDecl
of arity
* meta_name
(* name *)
82 | MetaIteratorDecl
of arity
* meta_name
(* name *)
84 (* --------------------------------------------------------------------- *)
85 (* --------------------------------------------------------------------- *)
93 and 'a dots
= 'a base_dots wrap
95 (* --------------------------------------------------------------------- *)
101 | MetaId
of meta_name mcode
* ident list
* keep_binding
* inherited
102 | MetaFunc
of meta_name mcode
* ident list
* keep_binding
* inherited
103 | MetaLocalFunc
of meta_name mcode
* ident list
* keep_binding
* inherited
106 | UniqueIdent
of ident
108 and ident
= base_ident wrap
110 (* --------------------------------------------------------------------- *)
113 and base_expression
=
115 | Constant
of constant mcode
116 | FunCall
of expression
* string mcode
(* ( *) *
117 expression dots
* string mcode
(* ) *)
118 | Assignment
of expression
* assignOp mcode
* expression
* bool
119 | CondExpr
of expression
* string mcode
(* ? *) * expression
option *
120 string mcode
(* : *) * expression
121 | Postfix
of expression
* fixOp mcode
122 | Infix
of expression
* fixOp mcode
123 | Unary
of expression
* unaryOp mcode
124 | Binary
of expression
* binaryOp mcode
* expression
125 | Nested
of expression
* binaryOp mcode
* expression
126 | ArrayAccess
of expression
* string mcode
(* [ *) * expression
*
128 | RecordAccess
of expression
* string mcode
(* . *) * ident
129 | RecordPtAccess
of expression
* string mcode
(* -> *) * ident
130 | Cast
of string mcode
(* ( *) * fullType
* string mcode
(* ) *) *
133 | SizeOfExpr
of string mcode
(* sizeof *) * expression
134 | SizeOfType
of string mcode
(* sizeof *) * string mcode
(* ( *) *
135 fullType
* string mcode
(* ) *)
136 | TypeExp
of fullType
138 | Paren
of string mcode
(* ( *) * expression
*
141 | MetaErr
of meta_name mcode
* expression list
* keep_binding
*
143 | MetaExpr
of meta_name mcode
* expression list
* keep_binding
*
144 Type_cocci.typeC list
option * form
* inherited
145 | MetaExprList
of meta_name mcode
* listlen
option *
146 keep_binding
* inherited
(* only in arg lists *)
148 | EComma
of string mcode
(* only in arg lists *)
150 | DisjExpr
of expression list
151 | NestExpr
of expression dots
* expression
option * multi
153 (* can appear in arg lists, and also inside Nest, as in:
154 if(< ... X ... Y ...>)
155 In the following, the expression option is the WHEN *)
156 | Edots
of string mcode
(* ... *) * expression
option
157 | Ecircles
of string mcode
(* ooo *) * expression
option
158 | Estars
of string mcode
(* *** *) * expression
option
160 | OptExp
of expression
161 | UniqueExp
of expression
163 and form
= ANY
| ID
| LocalID
| CONST
(* form for MetaExp *)
165 and expression
= base_expression wrap
167 and listlen
= meta_name mcode
* keep_binding
* inherited
169 and unaryOp
= GetRef
| DeRef
| UnPlus
| UnMinus
| Tilde
| Not
170 and assignOp
= SimpleAssign
| OpAssign
of arithOp
171 and fixOp
= Dec
| Inc
173 and binaryOp
= Arith
of arithOp
| Logical
of logicalOp
175 Plus
| Minus
| Mul
| Div
| Mod
| DecLeft
| DecRight
| And
| Or
| Xor
176 and logicalOp
= Inf
| Sup
| InfEq
| SupEq
| Eq
| NotEq
| AndLog
| OrLog
184 (* --------------------------------------------------------------------- *)
188 Type
of const_vol mcode
option * typeC
189 | DisjType
of fullType list
(* only after iso *)
190 | OptType
of fullType
191 | UniqueType
of fullType
194 BaseType
of baseType
* string mcode list
(* Yoann style *)
195 | SignedT
of sign mcode
* typeC
option
196 | Pointer
of fullType
* string mcode
(* * *)
197 | FunctionPointer
of fullType
*
198 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
199 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
200 | FunctionType
of bool (* true if all minus for dropping return type *) *
202 string mcode
(* ( *) * parameter_list
*
204 | Array
of fullType
* string mcode
(* [ *) *
205 expression
option * string mcode
(* ] *)
206 | EnumName
of string mcode
(*enum*) * ident
(* name *)
207 | StructUnionName
of structUnion mcode
* ident
option (* name *)
208 | StructUnionDef
of fullType
(* either StructUnionName or metavar *) *
209 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
210 | TypeName
of string mcode
212 | MetaType
of meta_name mcode
* keep_binding
* inherited
214 and fullType
= base_fullType wrap
215 and typeC
= base_typeC wrap
217 and baseType
= VoidType
| CharType
| ShortType
| IntType
| DoubleType
218 | FloatType
| LongType
| LongLongType
220 and structUnion
= Struct
| Union
222 and sign
= Signed
| Unsigned
224 and const_vol
= Const
| Volatile
226 (* --------------------------------------------------------------------- *)
227 (* Variable declaration *)
228 (* Even if the Cocci program specifies a list of declarations, they are
229 split out into multiple declarations of a single variable each. *)
231 and base_declaration
=
232 Init
of storage mcode
option * fullType
* ident
* string mcode
(*=*) *
233 initialiser
* string mcode
(*;*)
234 | UnInit
of storage mcode
option * fullType
* ident
* string mcode
(* ; *)
235 | TyDecl
of fullType
* string mcode
(* ; *)
236 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
237 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
238 | Typedef
of string mcode
(*typedef*) * fullType
* typeC
* string mcode
(*;*)
239 | DisjDecl
of declaration list
240 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
242 | MetaDecl
of meta_name mcode
* keep_binding
* inherited
244 | OptDecl
of declaration
245 | UniqueDecl
of declaration
247 and declaration
= base_declaration wrap
249 (* --------------------------------------------------------------------- *)
252 and base_initialiser
=
253 MetaInit
of meta_name mcode
* keep_binding
* inherited
254 | InitExpr
of expression
255 | InitList
of string mcode
(*{*) * initialiser list
* string mcode
(*}*) *
256 initialiser list
(* whencode: elements that shouldn't appear in init *)
258 designator list
(* name *) * string mcode
(*=*) *
259 initialiser
(* gccext: *)
260 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
262 | IComma
of string mcode
(* , *)
263 | OptIni
of initialiser
264 | UniqueIni
of initialiser
267 DesignatorField
of string mcode
(* . *) * ident
268 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
270 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
271 expression
* string mcode
(* ] *)
273 and initialiser
= base_initialiser wrap
275 (* --------------------------------------------------------------------- *)
278 and base_parameterTypeDef
=
279 VoidParam
of fullType
280 | Param
of fullType
* ident
option
282 | MetaParam
of meta_name mcode
* keep_binding
* inherited
283 | MetaParamList
of meta_name mcode
* listlen
option * keep_binding
*
286 | PComma
of string mcode
288 | Pdots
of string mcode
(* ... *)
289 | Pcircles
of string mcode
(* ooo *)
291 | OptParam
of parameterTypeDef
292 | UniqueParam
of parameterTypeDef
294 and parameterTypeDef
= base_parameterTypeDef wrap
296 and parameter_list
= parameterTypeDef dots
298 (* --------------------------------------------------------------------- *)
299 (* #define Parameters *)
301 and base_define_param
=
303 | DPComma
of string mcode
304 | DPdots
of string mcode
(* ... *)
305 | DPcircles
of string mcode
(* ooo *)
306 | OptDParam
of define_param
307 | UniqueDParam
of define_param
309 and define_param
= base_define_param wrap
311 and base_define_parameters
=
313 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
315 and define_parameters
= base_define_parameters wrap
317 (* --------------------------------------------------------------------- *)
320 (* PER = keep bindings separate, ANY = collect them *)
321 and meta_collect
= PER
| ALL
324 MetaPos
of meta_name mcode
* meta_name list
*
325 meta_collect
* keep_binding
* inherited
328 (* --------------------------------------------------------------------- *)
329 (* Function declaration *)
331 and storage
= Static
| Auto
| Register
| Extern
333 (* --------------------------------------------------------------------- *)
337 FunHeader
of mcodekind
(* before the function header *) *
338 bool (* true if all minus, for dropping static, etc *) *
339 fninfo list
* ident
(* name *) *
340 string mcode
(* ( *) * parameter_list
*
342 | Decl
of mcodekind
(* before the decl *) *
343 bool (* true if all minus *) * declaration
345 | SeqStart
of string mcode
(* { *)
346 | SeqEnd
of string mcode
(* } *)
348 | ExprStatement
of expression
* string mcode
(*;*)
349 | IfHeader
of string mcode
(* if *) * string mcode
(* ( *) *
350 expression
* string mcode
(* ) *)
351 | Else
of string mcode
(* else *)
352 | WhileHeader
of string mcode
(* while *) * string mcode
(* ( *) *
353 expression
* string mcode
(* ) *)
354 | DoHeader
of string mcode
(* do *)
355 | WhileTail
of string mcode
(* while *) * string mcode
(* ( *) *
356 expression
* string mcode
(* ) *) *
358 | ForHeader
of string mcode
(* for *) * string mcode
(* ( *) *
359 expression
option * string mcode
(*;*) *
360 expression
option * string mcode
(*;*) *
361 expression
option * string mcode
(* ) *)
362 | IteratorHeader
of ident
(* name *) * string mcode
(* ( *) *
363 expression dots
* string mcode
(* ) *)
364 | SwitchHeader
of string mcode
(* switch *) * string mcode
(* ( *) *
365 expression
* string mcode
(* ) *)
366 | Break
of string mcode
(* break *) * string mcode
(* ; *)
367 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
368 | Label
of ident
* string mcode
(* : *)
369 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
370 | Return
of string mcode
(* return *) * string mcode
(* ; *)
371 | ReturnExpr
of string mcode
(* return *) * expression
*
374 | MetaRuleElem
of meta_name mcode
* keep_binding
* inherited
375 | MetaStmt
of meta_name mcode
* keep_binding
* metaStmtInfo
*
377 | MetaStmtList
of meta_name mcode
* keep_binding
* inherited
380 | TopExp
of expression
(* for macros body *)
381 | Ty
of fullType
(* only at top level *)
382 | TopInit
of initialiser
(* only at top level *)
383 | Include
of string mcode
(*#include*) * inc_file mcode
(*file *)
384 | DefineHeader
of string mcode
(* #define *) * ident
(* name *) *
385 define_parameters
(*params*)
386 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*)
387 | Default
of string mcode
(* default *) * string mcode
(*:*)
388 | DisjRuleElem
of rule_elem list
391 FStorage
of storage mcode
393 | FInline
of string mcode
394 | FAttr
of string mcode
397 NotSequencible
| SequencibleAfterDots
of dots_whencode list
| Sequencible
399 and rule_elem
= base_rule_elem wrap
402 Seq
of rule_elem
(* { *) *
403 statement dots
* rule_elem
(* } *)
404 | IfThen
of rule_elem
(* header *) * statement
* end_info
405 | IfThenElse
of rule_elem
(* header *) * statement
*
406 rule_elem
(* else *) * statement
* end_info
407 | While
of rule_elem
(* header *) * statement
* end_info
408 | Do
of rule_elem
(* do *) * statement
* rule_elem
(* tail *)
409 | For
of rule_elem
(* header *) * statement
* end_info
410 | Iterator
of rule_elem
(* header *) * statement
* end_info
(*enditer*)
411 | Switch
of rule_elem
(* header *) * rule_elem
(* { *) *
412 case_line list
* rule_elem
(* } *)
413 | Atomic
of rule_elem
414 | Disj
of statement dots list
415 | Nest
of statement dots
*
416 (statement dots
,statement
) whencode list
* multi
*
417 dots_whencode list
* dots_whencode list
418 | FunDecl
of rule_elem
(* header *) * rule_elem
(* { *) *
419 statement dots
* rule_elem
(* } *)
420 | Define
of rule_elem
(* header *) * statement dots
421 | Dots
of string mcode
(* ... *) *
422 (statement dots
,statement
) whencode list
*
423 dots_whencode list
* dots_whencode list
424 | Circles
of string mcode
(* ooo *) *
425 (statement dots
,statement
) whencode list
*
426 dots_whencode list
* dots_whencode list
427 | Stars
of string mcode
(* *** *) *
428 (statement dots
,statement
) whencode list
*
429 dots_whencode list
* dots_whencode list
430 | OptStm
of statement
431 | UniqueStm
of statement
433 and ('a
,'b
) whencode
=
436 | WhenModifier
of when_modifier
437 | WhenNotTrue
of rule_elem
438 | WhenNotFalse
of rule_elem
447 WParen
of rule_elem
* meta_name
(*pren_var*)
449 | Other_dots
of statement dots
451 and statement
= base_statement wrap
454 CaseLine
of rule_elem
(* case/default header *) * statement dots
455 | OptCase
of case_line
457 and case_line
= base_case_line wrap
460 Local
of inc_elem list
461 | NonLocal
of inc_elem list
469 | CODE
of statement dots
470 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
471 | ERRORWORDS
of expression list
473 and top_level
= base_top_level wrap
476 CocciRulename
of string option * dependency
* string list
* string list
*
478 (* true if the whole thing is an expression *)
479 | GeneratedRulename
of string option * dependency
*
480 string list
* string list
* exists
* bool
481 (* true if the whole thing is an expression *)
482 | ScriptRulename
of string * dependency
483 | InitialScriptRulename
of string
484 | FinalScriptRulename
of string
486 and ruletype
= Normal
| Generated
489 CocciRule
of string (* name *) *
490 (dependency
* string list
(* dropped isos *) * exists
) *
491 top_level list
* bool list
(* true if generates an exp *) * ruletype
492 | ScriptRule
of string * dependency
* (string * meta_name
) list
* string
493 | InitialScriptRule
of string * string
494 | FinalScriptRule
of string * string
497 Dep
of string (* rule applies for the current binding *)
498 | AntiDep
of string (* rule doesn't apply for the current binding *)
499 | EverDep
of string (* rule applies for some binding *)
500 | NeverDep
of string (* rule never applies for any binding *)
501 | AndDep
of dependency
* dependency
502 | OrDep
of dependency
* dependency
505 and rule_with_metavars
= metavar list
* rule
508 FullTypeTag
of fullType
509 | BaseTypeTag
of baseType
510 | StructUnionTag
of structUnion
513 | ExpressionTag
of expression
514 | ConstantTag
of constant
515 | UnaryOpTag
of unaryOp
516 | AssignOpTag
of assignOp
518 | BinaryOpTag
of binaryOp
519 | ArithOpTag
of arithOp
520 | LogicalOpTag
of logicalOp
521 | DeclarationTag
of declaration
522 | InitTag
of initialiser
523 | StorageTag
of storage
524 | IncFileTag
of inc_file
525 | Rule_elemTag
of rule_elem
526 | StatementTag
of statement
527 | CaseLineTag
of case_line
528 | ConstVolTag
of const_vol
529 | Token
of string * info
option
530 | Pragma
of string list
532 | ExprDotsTag
of expression dots
533 | ParamDotsTag
of parameterTypeDef dots
534 | StmtDotsTag
of statement dots
535 | DeclDotsTag
of declaration dots
537 | ParamTag
of parameterTypeDef
538 | SgrepStartTag
of string
539 | SgrepEndTag
of string
541 (* --------------------------------------------------------------------- *)
543 and exists
= Exists
| Forall
| ReverseForall
| Undetermined
545 (* --------------------------------------------------------------------- *)
547 val mkToken
: string -> anything
549 val undots
: 'a dots
-> 'a list
551 (* --------------------------------------------------------------------- *)
553 val rewrap
: 'a wrap
-> 'b
-> 'b wrap
554 val rewrap_mcode
: 'a mcode
-> 'a
-> 'a mcode
555 val unwrap
: 'a wrap
-> 'a
556 val unwrap_mcode
: 'a mcode
-> 'a
557 val get_mcodekind
: 'a mcode
-> mcodekind
558 val get_line
: 'a wrap
-> line
559 val get_mcode_line
: 'a mcode
-> line
560 val get_mcode_col
: 'a mcode
-> int
561 val get_fvs
: 'a wrap
-> meta_name list
562 val get_wcfvs
: ('a wrap
,'b wrap
) whencode list
-> meta_name list
563 val set_fvs
: meta_name list
-> 'a wrap
-> 'a wrap
564 val get_mfvs
: 'a wrap
-> meta_name list
565 val set_mfvs
: meta_name list
-> 'a wrap
-> 'a wrap
566 val get_fresh
: 'a wrap
-> (meta_name
* string option) list
567 val get_inherited
: 'a wrap
-> meta_name list
568 val get_saved
: 'a wrap
-> meta_name list
569 val get_dots_bef_aft
: statement
-> dots_bef_aft
570 val set_dots_bef_aft
: dots_bef_aft
-> statement
-> statement
571 val get_pos
: 'a wrap
-> meta_name mcode
option
572 val set_pos
: 'a wrap
-> meta_name mcode
option -> 'a wrap
573 val get_test_exp
: 'a wrap
-> bool
574 val set_test_exp
: expression
-> expression
575 val get_isos
: 'a wrap
-> (string*anything
) list
576 val set_isos
: 'a wrap
-> (string*anything
) list
-> 'a wrap
577 val get_pos_var
: 'a mcode
-> meta_pos
578 val set_pos_var
: meta_pos
-> 'a mcode
-> 'a mcode
579 val drop_pos
: 'a mcode
-> 'a mcode
581 val get_meta_name
: metavar
-> meta_name
583 val tag2c
: anything
-> string
587 val make_meta_rule_elem
:
588 string -> mcodekind
->
589 (meta_name list
* (meta_name
* string option) list
* meta_name list
) ->
593 string -> mcodekind
->
594 (meta_name list
* (meta_name
* string option) list
* meta_name list
) ->
597 val make_term
: 'a
-> 'a wrap
598 val make_mcode
: 'a
-> 'a mcode
600 val equal_pos
: fixpos
-> fixpos
-> bool