2 * Copyright 2012, INRIA
3 * Julia Lawall, Gilles Muller
4 * Copyright 2010-2011, INRIA, University of Copenhagen
5 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
6 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
7 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
8 * This file is part of Coccinelle.
10 * Coccinelle is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, according to version 2 of the License.
14 * Coccinelle is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
22 * The authors reserve the right to distribute this or future versions of
23 * Coccinelle under other licenses.
27 (* --------------------------------------------------------------------- *)
30 type added_string
= Noindent
of string | Indent
of string | Space
of string
32 type info
= { line
: int; column
: int;
33 strbef
: (added_string
* int (* line *) * int (* col *)) list
;
34 straft
: (added_string
* int (* line *) * int (* col *)) list
}
36 type meta_name
= string * string
37 (* need to be careful about rewrapping, to avoid duplicating pos info
38 currently, the pos info is always None until asttoctl2. *)
42 free_vars
: meta_name list
; (*free vars*)
43 minus_free_vars
: meta_name list
; (*minus free vars*)
44 fresh_vars
: (meta_name
* seed
) list
; (*fresh vars*)
45 inherited
: meta_name list
; (*inherited vars*)
46 saved_witness
: meta_name list
; (*witness vars*)
47 bef_aft
: dots_bef_aft
;
48 (* the following is for or expressions *)
49 pos_info
: meta_name mcode
option; (* pos info, try not to duplicate *)
50 true_if_test_exp
: bool;(* true if "test_exp from iso", only for exprs *)
51 (* the following is only for declarations *)
52 safe_for_multi_decls
: bool;
53 (* isos relevant to the term; ultimately only used for rule_elems *)
54 iso_info
: (string*anything
) list
}
57 BEFORE
of 'a list list
* count
58 | AFTER
of 'a list list
* count
59 | BEFOREAFTER
of 'a list list
* 'a list list
* count
62 and 'a replacement
= REPLACEMENT
of 'a list list
* count
| NOREPLACEMENT
64 and 'a mcode
= 'a
* info
* mcodekind
* meta_pos list
(* pos variables *)
65 (* pos is an offset indicating where in the C code the mcodekind
67 (* int list is the match instances, which are only meaningful in annotated
69 (* adjacency is the adjacency index, which is incremented on context dots *)
70 (* iteration is only allowed on context code, the intuition vaguely being
71 that there is no way to replace something more than once. Actually,
72 allowing iterated additions on minus code would cause problems with some
73 heuristics for adding braces, because one couldn't identify simple
74 replacements with certainty. Anyway, iteration doesn't seem to be needed
75 on - code for the moment. Although it may be confusing that there can be
76 iterated addition of code before context code where the context code is
77 immediately followed by removed code. *)
78 and adjacency
= ALLMINUS
| ADJ
of int
80 MINUS
of pos
* int list
* adjacency
* anything replacement
81 | CONTEXT
of pos
* anything befaft
83 and count
= ONE
(* + *) | MANY
(* ++ *)
85 Real
of int (* charpos *) | Virt
of int * int (* charpos + offset *)
86 and pos
= NoPos
| DontCarePos
| FixPos
of (fixpos
* fixpos
)
90 | AddingBetweenDots
of statement
* int (*index of let var*)
91 | DroppingBetweenDots
of statement
* int (*index of let var*)
93 and inherited
= Type_cocci.inherited
94 and keep_binding
= Type_cocci.keep_binding
95 and multi
= bool (*true if a nest is one or more, false if it is zero or more*)
98 meta_name list
(*free vars*) * (meta_name
* seed
) list
(*fresh*) *
99 meta_name list
(*inherited vars*) * mcodekind
101 (* --------------------------------------------------------------------- *)
104 and arity
= UNIQUE
| OPT
| MULTI
| NONE
107 MetaMetaDecl
of arity
* meta_name
(* name *)
108 | MetaIdDecl
of arity
* meta_name
(* name *)
109 | MetaFreshIdDecl
of meta_name
(* name *) * seed
(* seed *)
110 | MetaTypeDecl
of arity
* meta_name
(* name *)
111 | MetaInitDecl
of arity
* meta_name
(* name *)
112 | MetaInitListDecl
of arity
* meta_name
(* name *) * list_len
(*len*)
113 | MetaListlenDecl
of meta_name
(* name *)
114 | MetaParamDecl
of arity
* meta_name
(* name *)
115 | MetaParamListDecl
of arity
* meta_name
(*name*) * list_len
(*len*)
117 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
118 | MetaErrDecl
of arity
* meta_name
(* name *)
120 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
122 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
123 | MetaLocalIdExpDecl
of
124 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
125 | MetaExpListDecl
of arity
* meta_name
(*name*) * list_len
(*len*)
126 | MetaDeclDecl
of arity
* meta_name
(* name *)
127 | MetaFieldDecl
of arity
* meta_name
(* name *)
128 | MetaFieldListDecl
of arity
* meta_name
(* name *) * list_len
(*len*)
129 | MetaStmDecl
of arity
* meta_name
(* name *)
130 | MetaStmListDecl
of arity
* meta_name
(* name *)
131 | MetaFuncDecl
of arity
* meta_name
(* name *)
132 | MetaLocalFuncDecl
of arity
* meta_name
(* name *)
133 | MetaPosDecl
of arity
* meta_name
(* name *)
134 | MetaDeclarerDecl
of arity
* meta_name
(* name *)
135 | MetaIteratorDecl
of arity
* meta_name
(* name *)
137 and list_len
= AnyLen
| MetaLen
of meta_name
| CstLen
of int
139 and seed
= NoVal
| StringSeed
of string | ListSeed
of seed_elem list
140 and seed_elem
= SeedString
of string | SeedId
of meta_name
142 (* --------------------------------------------------------------------- *)
143 (* --------------------------------------------------------------------- *)
151 and 'a dots
= 'a base_dots wrap
153 (* --------------------------------------------------------------------- *)
158 | MetaId
of meta_name mcode
* idconstraint
* keep_binding
* inherited
159 | MetaFunc
of meta_name mcode
* idconstraint
* keep_binding
* inherited
160 | MetaLocalFunc
of meta_name mcode
* idconstraint
* keep_binding
* inherited
162 | DisjId
of ident list
164 | UniqueIdent
of ident
166 and ident
= base_ident wrap
168 (* --------------------------------------------------------------------- *)
171 and base_expression
=
173 | Constant
of constant mcode
174 | FunCall
of expression
* string mcode
(* ( *) *
175 expression dots
* string mcode
(* ) *)
176 | Assignment
of expression
* assignOp mcode
* expression
*
177 bool (* true if it can match an initialization *)
178 | Sequence
of expression
* string mcode
(* , *) * expression
179 | CondExpr
of expression
* string mcode
(* ? *) * expression
option *
180 string mcode
(* : *) * expression
181 | Postfix
of expression
* fixOp mcode
182 | Infix
of expression
* fixOp mcode
183 | Unary
of expression
* unaryOp mcode
184 | Binary
of expression
* binaryOp mcode
* expression
185 | Nested
of expression
* binaryOp mcode
* expression
186 | ArrayAccess
of expression
* string mcode
(* [ *) * expression
*
188 | RecordAccess
of expression
* string mcode
(* . *) * ident
189 | RecordPtAccess
of expression
* string mcode
(* -> *) * ident
190 | Cast
of string mcode
(* ( *) * fullType
* string mcode
(* ) *) *
192 | SizeOfExpr
of string mcode
(* sizeof *) * expression
193 | SizeOfType
of string mcode
(* sizeof *) * string mcode
(* ( *) *
194 fullType
* string mcode
(* ) *)
195 | TypeExp
of fullType
(*type name used as an expression, only in
198 | Paren
of string mcode
(* ( *) * expression
*
201 | Constructor
of string mcode
(* ( *) * fullType
* string mcode
(* ) *) *
203 | MetaErr
of meta_name mcode
* constraints
* keep_binding
*
205 | MetaExpr
of meta_name mcode
* constraints
* keep_binding
*
206 Type_cocci.typeC list
option * form
* inherited
207 | MetaExprList
of meta_name mcode
* listlen
* keep_binding
*
208 inherited
(* only in arg lists *)
209 | AsExpr
of expression
* expression
(* as expr, always metavar *)
211 | EComma
of string mcode
(* only in arg lists *)
213 | DisjExpr
of expression list
214 | NestExpr
of string mcode
(* <.../<+... *) *
216 string mcode
(* ...>/...+> *) *
217 expression
option * multi
219 (* can appear in arg lists, and also inside Nest, as in:
220 if(< ... X ... Y ...>)
221 In the following, the expression option is the WHEN *)
222 | Edots
of string mcode
(* ... *) * expression
option
223 | Ecircles
of string mcode
(* ooo *) * expression
option
224 | Estars
of string mcode
(* *** *) * expression
option
226 | OptExp
of expression
227 | UniqueExp
of expression
231 | NotIdCstrt
of reconstraint
232 | NotExpCstrt
of expression list
233 | SubExpCstrt
of meta_name list
235 (* Constraints on Meta-* Identifiers, Functions *)
238 | IdNegIdSet
of string list
* meta_name list
239 | IdRegExpConstraint
of reconstraint
242 | IdRegExp
of string * Regexp.regexp
243 | IdNotRegExp
of string * Regexp.regexp
245 (* ANY = int E; ID = idexpression int X; CONST = constant int X; *)
246 and form
= ANY
| ID
| LocalID
| CONST
(* form for MetaExp *)
248 and expression
= base_expression wrap
251 MetaListLen
of meta_name mcode
* keep_binding
* inherited
255 and unaryOp
= GetRef
| GetRefLabel
| DeRef
| UnPlus
| UnMinus
| Tilde
| Not
256 and assignOp
= SimpleAssign
| OpAssign
of arithOp
257 and fixOp
= Dec
| Inc
259 and binaryOp
= Arith
of arithOp
| Logical
of logicalOp
261 Plus
| Minus
| Mul
| Div
| Mod
| DecLeft
| DecRight
| And
| Or
| Xor
262 and logicalOp
= Inf
| Sup
| InfEq
| SupEq
| Eq
| NotEq
| AndLog
| OrLog
270 (* --------------------------------------------------------------------- *)
274 Type
of bool (* true if all minus *) *
275 const_vol mcode
option * typeC
276 | AsType
of fullType
* fullType
(* as type, always metavar *)
277 | DisjType
of fullType list
(* only after iso *)
278 | OptType
of fullType
279 | UniqueType
of fullType
282 BaseType
of baseType
* string mcode list
(* Yoann style *)
283 | SignedT
of sign mcode
* typeC
option
284 | Pointer
of fullType
* string mcode
(* * *)
285 | FunctionPointer
of fullType
*
286 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
287 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
289 (* used for the automatic managment of prototypes *)
290 | FunctionType
of bool (* true if all minus for dropping return type *) *
292 string mcode
(* ( *) * parameter_list
*
295 | Array
of fullType
* string mcode
(* [ *) *
296 expression
option * string mcode
(* ] *)
297 | EnumName
of string mcode
(*enum*) * ident
option (* name *)
298 | EnumDef
of fullType
(* either EnumName or metavar *) *
299 string mcode
(* { *) * expression dots
* string mcode
(* } *)
300 | StructUnionName
of structUnion mcode
* ident
option (* name *)
301 | StructUnionDef
of fullType
(* either StructUnionName or metavar *) *
302 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
303 | TypeName
of string mcode
(* pad: should be 'of ident' ? *)
305 | MetaType
of meta_name mcode
* keep_binding
* inherited
307 and fullType
= base_fullType wrap
308 and typeC
= base_typeC wrap
310 and baseType
= VoidType
| CharType
| ShortType
| ShortIntType
| IntType
311 | DoubleType
| LongDoubleType
| FloatType
312 | LongType
| LongIntType
| LongLongType
| LongLongIntType
313 | SizeType
| SSizeType
| PtrDiffType
315 and structUnion
= Struct
| Union
317 and sign
= Signed
| Unsigned
319 and const_vol
= Const
| Volatile
321 (* --------------------------------------------------------------------- *)
322 (* Variable declaration *)
323 (* Even if the Cocci program specifies a list of declarations, they are
324 split out into multiple declarations of a single variable each. *)
326 and base_declaration
=
327 Init
of storage mcode
option * fullType
* ident
* string mcode
(*=*) *
328 initialiser
* string mcode
(*;*)
329 | UnInit
of storage mcode
option * fullType
* ident
* string mcode
(* ; *)
330 | TyDecl
of fullType
* string mcode
(* ; *)
331 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
332 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
333 | MacroDeclInit
of ident
(* name *) * string mcode
(* ( *) *
334 expression dots
* string mcode
(* ) *) * string mcode
(*=*) *
335 initialiser
* string mcode
(* ; *)
336 | Typedef
of string mcode
(*typedef*) * fullType
*
337 typeC
(* either TypeName or metavar *) * string mcode
(*;*)
338 | DisjDecl
of declaration list
339 (* Ddots is for a structure declaration *)
340 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
342 | MetaDecl
of meta_name mcode
* keep_binding
* inherited
343 | MetaField
of meta_name mcode
* keep_binding
* inherited
344 | MetaFieldList
of meta_name mcode
* listlen
* keep_binding
* inherited
345 | AsDecl
of declaration
* declaration
347 | OptDecl
of declaration
348 | UniqueDecl
of declaration
350 and declaration
= base_declaration wrap
352 (* --------------------------------------------------------------------- *)
355 and base_initialiser
=
356 MetaInit
of meta_name mcode
* keep_binding
* inherited
357 | MetaInitList
of meta_name mcode
* listlen
* keep_binding
* inherited
358 | AsInit
of initialiser
* initialiser
(* as init, always metavar *)
359 | InitExpr
of expression
360 | ArInitList
of string mcode
(*{*) * initialiser dots
* string mcode
(*}*)
361 | StrInitList
of bool (* true if all are - *) *
362 string mcode
(*{*) * initialiser list
* string mcode
(*}*) *
363 initialiser list
(* whencode: elements that shouldn't appear in init *)
365 designator list
(* name *) * string mcode
(*=*) *
366 initialiser
(* gccext: *)
367 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
369 | IComma
of string mcode
(* , *)
370 | Idots
of string mcode
(* ... *) * initialiser
option (* whencode *)
372 | OptIni
of initialiser
373 | UniqueIni
of initialiser
376 DesignatorField
of string mcode
(* . *) * ident
377 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
379 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
380 expression
* string mcode
(* ] *)
382 and initialiser
= base_initialiser wrap
384 (* --------------------------------------------------------------------- *)
387 and base_parameterTypeDef
=
388 VoidParam
of fullType
389 | Param
of fullType
* ident
option
391 | MetaParam
of meta_name mcode
* keep_binding
* inherited
392 | MetaParamList
of meta_name mcode
* listlen
* keep_binding
* inherited
394 | PComma
of string mcode
396 | Pdots
of string mcode
(* ... *)
397 | Pcircles
of string mcode
(* ooo *)
399 | OptParam
of parameterTypeDef
400 | UniqueParam
of parameterTypeDef
402 and parameterTypeDef
= base_parameterTypeDef wrap
404 and parameter_list
= parameterTypeDef dots
406 (* --------------------------------------------------------------------- *)
407 (* #define Parameters *)
409 and base_define_param
=
411 | DPComma
of string mcode
412 | DPdots
of string mcode
(* ... *)
413 | DPcircles
of string mcode
(* ooo *)
414 | OptDParam
of define_param
415 | UniqueDParam
of define_param
417 and define_param
= base_define_param wrap
419 and base_define_parameters
=
420 NoParams
(* not parameter list, not an empty one *)
421 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
423 and define_parameters
= base_define_parameters wrap
425 (* --------------------------------------------------------------------- *)
428 (* PER = keep bindings separate, ALL = collect them *)
429 and meta_collect
= PER
| ALL
432 MetaPos
of meta_name mcode
* meta_name list
*
433 meta_collect
* keep_binding
* inherited
435 (* --------------------------------------------------------------------- *)
436 (* Function declaration *)
438 and storage
= Static
| Auto
| Register
| Extern
440 (* --------------------------------------------------------------------- *)
444 FunHeader
of mcodekind
(* before the function header *) *
445 bool (* true if all minus, for dropping static, etc *) *
446 fninfo list
* ident
(* name *) *
447 string mcode
(* ( *) * parameter_list
*
449 | Decl
of mcodekind
(* before the decl *) *
450 bool (* true if all minus *) * declaration
452 | SeqStart
of string mcode
(* { *)
453 | SeqEnd
of string mcode
(* } *)
455 | ExprStatement
of expression
option * string mcode
(*;*)
456 | IfHeader
of string mcode
(* if *) * string mcode
(* ( *) *
457 expression
* string mcode
(* ) *)
458 | Else
of string mcode
(* else *)
459 | WhileHeader
of string mcode
(* while *) * string mcode
(* ( *) *
460 expression
* string mcode
(* ) *)
461 | DoHeader
of string mcode
(* do *)
462 | WhileTail
of string mcode
(* while *) * string mcode
(* ( *) *
463 expression
* string mcode
(* ) *) *
465 | ForHeader
of string mcode
(* for *) * string mcode
(* ( *) *
466 expression
option * string mcode
(*;*) *
467 expression
option * string mcode
(*;*) *
468 expression
option * string mcode
(* ) *)
469 | IteratorHeader
of ident
(* name *) * string mcode
(* ( *) *
470 expression dots
* string mcode
(* ) *)
471 | SwitchHeader
of string mcode
(* switch *) * string mcode
(* ( *) *
472 expression
* string mcode
(* ) *)
473 | Break
of string mcode
(* break *) * string mcode
(* ; *)
474 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
475 | Label
of ident
* string mcode
(* : *)
476 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
477 | Return
of string mcode
(* return *) * string mcode
(* ; *)
478 | ReturnExpr
of string mcode
(* return *) * expression
*
481 | MetaRuleElem
of meta_name mcode
* keep_binding
* inherited
482 | MetaStmt
of meta_name mcode
* keep_binding
* metaStmtInfo
*
484 | MetaStmtList
of meta_name mcode
* keep_binding
* inherited
486 | Exp
of expression
(* matches a subterm *)
487 | TopExp
of expression
(* for macros body, exp at top level,
489 | Ty
of fullType
(* only at SP top level, matches a subterm *)
490 | TopInit
of initialiser
(* only at top level *)
491 | Include
of string mcode
(*#include*) * inc_file mcode
(*file *)
492 | Undef
of string mcode
(* #define *) * ident
(* name *)
493 | DefineHeader
of string mcode
(* #define *) * ident
(* name *) *
494 define_parameters
(*params*)
495 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*)
496 | Default
of string mcode
(* default *) * string mcode
(*:*)
497 | DisjRuleElem
of rule_elem list
500 FStorage
of storage mcode
502 | FInline
of string mcode
503 | FAttr
of string mcode
506 NotSequencible
| SequencibleAfterDots
of dots_whencode list
| Sequencible
508 and rule_elem
= base_rule_elem wrap
511 Seq
of rule_elem
(* { *) *
512 statement dots
* rule_elem
(* } *)
513 | IfThen
of rule_elem
(* header *) * statement
* end_info
(* endif *)
514 | IfThenElse
of rule_elem
(* header *) * statement
*
515 rule_elem
(* else *) * statement
* end_info
(* endif *)
516 | While
of rule_elem
(* header *) * statement
* end_info
(*endwhile*)
517 | Do
of rule_elem
(* do *) * statement
* rule_elem
(* tail *)
518 | For
of rule_elem
(* header *) * statement
* end_info
(*endfor*)
519 | Iterator
of rule_elem
(* header *) * statement
* end_info
(*enditer*)
520 | Switch
of rule_elem
(* header *) * rule_elem
(* { *) *
521 statement
(*decl*) dots
* case_line list
* rule_elem
(*}*)
522 | Atomic
of rule_elem
523 | Disj
of statement dots list
524 | Nest
of string mcode
(* <.../<+... *) * statement dots
*
525 string mcode
(* ...>/...+> *) *
526 (statement dots
,statement
) whencode list
* multi
*
527 dots_whencode list
* dots_whencode list
528 | FunDecl
of rule_elem
(* header *) * rule_elem
(* { *) *
529 statement dots
* rule_elem
(* } *)
530 | Define
of rule_elem
(* header *) * statement dots
531 | AsStmt
of statement
* statement
(* as statement, always metavar *)
532 | Dots
of string mcode
(* ... *) *
533 (statement dots
,statement
) whencode list
*
534 dots_whencode list
* dots_whencode list
535 | Circles
of string mcode
(* ooo *) *
536 (statement dots
,statement
) whencode list
*
537 dots_whencode list
* dots_whencode list
538 | Stars
of string mcode
(* *** *) *
539 (statement dots
,statement
) whencode list
*
540 dots_whencode list
* dots_whencode list
541 | OptStm
of statement
542 | UniqueStm
of statement
544 and ('a
,'b
) whencode
=
547 | WhenModifier
of when_modifier
548 | WhenNotTrue
of rule_elem
(* useful for fvs *)
549 | WhenNotFalse
of rule_elem
552 (* The following removes the shortest path constraint. It can be used
553 with other when modifiers *)
555 (* The following removes the special consideration of error paths. It
556 can be used with other when modifiers *)
561 (* only used with asttoctl *)
563 WParen
of rule_elem
* meta_name
(*pren_var*)
565 | Other_dots
of statement dots
567 and statement
= base_statement wrap
570 CaseLine
of rule_elem
(* case/default header *) * statement dots
571 | OptCase
of case_line
573 and case_line
= base_case_line wrap
576 Local
of inc_elem list
577 | NonLocal
of inc_elem list
585 | CODE
of statement dots
586 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
587 | ERRORWORDS
of expression list
589 and top_level
= base_top_level wrap
592 CocciRulename
of string option * dependency
*
593 string list
* string list
* exists
* bool
594 | GeneratedRulename
of string option * dependency
*
595 string list
* string list
* exists
* bool
596 | ScriptRulename
of string option (* name *) * string (* language *) *
598 | InitialScriptRulename
of string option (* name *) * string (* language *) *
600 | FinalScriptRulename
of string option (* name *) * string (* language *) *
603 and ruletype
= Normal
| Generated
606 CocciRule
of string (* name *) *
607 (dependency
* string list
(* dropped isos *) * exists
) * top_level list
608 * bool list
* ruletype
609 | ScriptRule
of string (* name *) *
610 (* metaname for python (untyped), metavar for ocaml (typed) *)
611 string * dependency
*
612 (script_meta_name
* meta_name
* metavar
) list
(*inherited vars*) *
613 meta_name list
(*script vars*) * string
614 | InitialScriptRule
of string (* name *) *
615 string (*language*) * dependency
* string (*code*)
616 | FinalScriptRule
of string (* name *) *
617 string (*language*) * dependency
* string (*code*)
619 and script_meta_name
= string option (*string*) * string option (*ast*)
622 Dep
of string (* rule applies for the current binding *)
623 | AntiDep
of string (* rule doesn't apply for the current binding *)
624 | EverDep
of string (* rule applies for some binding *)
625 | NeverDep
of string (* rule never applies for any binding *)
626 | AndDep
of dependency
* dependency
627 | OrDep
of dependency
* dependency
630 and rule_with_metavars
= metavar list
* rule
633 FullTypeTag
of fullType
634 | BaseTypeTag
of baseType
635 | StructUnionTag
of structUnion
638 | ExpressionTag
of expression
639 | ConstantTag
of constant
640 | UnaryOpTag
of unaryOp
641 | AssignOpTag
of assignOp
643 | BinaryOpTag
of binaryOp
644 | ArithOpTag
of arithOp
645 | LogicalOpTag
of logicalOp
646 | DeclarationTag
of declaration
647 | InitTag
of initialiser
648 | StorageTag
of storage
649 | IncFileTag
of inc_file
650 | Rule_elemTag
of rule_elem
651 | StatementTag
of statement
652 | CaseLineTag
of case_line
653 | ConstVolTag
of const_vol
654 | Token
of string * info
option
655 | Pragma
of added_string list
657 | ExprDotsTag
of expression dots
658 | ParamDotsTag
of parameterTypeDef dots
659 | StmtDotsTag
of statement dots
660 | DeclDotsTag
of declaration dots
662 | ParamTag
of parameterTypeDef
663 | SgrepStartTag
of string
664 | SgrepEndTag
of string
666 (* --------------------------------------------------------------------- *)
668 and exists
= Exists
| Forall
| Undetermined
669 (* | ReverseForall - idea: look back on all flow paths; not implemented *)
671 (* --------------------------------------------------------------------- *)
673 let mkToken x
= Token
(x
,None
)
675 (* --------------------------------------------------------------------- *)
677 let lub_count i1 i2
=
682 (* --------------------------------------------------------------------- *)
684 let rewrap model x
= {model
with node
= x
}
685 let rewrap_mcode (_
,a
,b
,c
) x
= (x
,a
,b
,c
)
686 let unwrap x
= x
.node
687 let unwrap_mcode (x
,_
,_
,_
) = x
688 let get_mcodekind (_
,_
,x
,_
) = x
689 let get_line x
= x
.node_line
690 let get_mcode_line (_
,l
,_
,_
) = l
.line
691 let get_mcode_col (_
,l
,_
,_
) = l
.column
692 let get_fvs x
= x
.free_vars
693 let set_fvs fvs x
= {x
with free_vars
= fvs
}
694 let get_mfvs x
= x
.minus_free_vars
695 let set_mfvs mfvs x
= {x
with minus_free_vars
= mfvs
}
696 let get_fresh x
= x
.fresh_vars
697 let get_inherited x
= x
.inherited
698 let get_saved x
= x
.saved_witness
699 let get_dots_bef_aft x
= x
.bef_aft
700 let set_dots_bef_aft d x
= {x
with bef_aft
= d
}
701 let get_pos x
= x
.pos_info
702 let set_pos x pos
= {x
with pos_info
= pos
}
703 let get_test_exp x
= x
.true_if_test_exp
704 let set_test_exp x
= {x
with true_if_test_exp
= true}
705 let get_safe_decl x
= x
.safe_for_multi_decls
706 let get_isos x
= x
.iso_info
707 let set_isos x isos
= {x
with iso_info
= isos
}
708 let get_pos_var (_
,_
,_
,p
) = p
709 let set_pos_var vr
(a
,b
,c
,_
) = (a
,b
,c
,vr
)
710 let drop_pos (a
,b
,c
,_
) = (a
,b
,c
,[])
712 let get_wcfvs (whencode
: ('a wrap
, 'b wrap
) whencode list
) =
716 WhenNot
(a
) -> get_fvs a
717 | WhenAlways
(a
) -> get_fvs a
718 | WhenModifier
(_
) -> []
719 | WhenNotTrue
(e
) -> get_fvs e
720 | WhenNotFalse
(e
) -> get_fvs e
)
723 (* --------------------------------------------------------------------- *)
725 let get_meta_name = function
726 MetaMetaDecl
(ar
,nm
) -> nm
727 | MetaIdDecl
(ar
,nm
) -> nm
728 | MetaFreshIdDecl
(nm
,seed
) -> nm
729 | MetaTypeDecl
(ar
,nm
) -> nm
730 | MetaInitDecl
(ar
,nm
) -> nm
731 | MetaInitListDecl
(ar
,nm
,nm1
) -> nm
732 | MetaListlenDecl
(nm
) -> nm
733 | MetaParamDecl
(ar
,nm
) -> nm
734 | MetaParamListDecl
(ar
,nm
,nm1
) -> nm
735 | MetaConstDecl
(ar
,nm
,ty
) -> nm
736 | MetaErrDecl
(ar
,nm
) -> nm
737 | MetaExpDecl
(ar
,nm
,ty
) -> nm
738 | MetaIdExpDecl
(ar
,nm
,ty
) -> nm
739 | MetaLocalIdExpDecl
(ar
,nm
,ty
) -> nm
740 | MetaExpListDecl
(ar
,nm
,nm1
) -> nm
741 | MetaDeclDecl
(ar
,nm
) -> nm
742 | MetaFieldDecl
(ar
,nm
) -> nm
743 | MetaFieldListDecl
(ar
,nm
,nm1
) -> nm
744 | MetaStmDecl
(ar
,nm
) -> nm
745 | MetaStmListDecl
(ar
,nm
) -> nm
746 | MetaFuncDecl
(ar
,nm
) -> nm
747 | MetaLocalFuncDecl
(ar
,nm
) -> nm
748 | MetaPosDecl
(ar
,nm
) -> nm
749 | MetaDeclarerDecl
(ar
,nm
) -> nm
750 | MetaIteratorDecl
(ar
,nm
) -> nm
752 (* --------------------------------------------------------------------- *)
755 FullTypeTag _
-> "FullTypeTag"
756 | BaseTypeTag _
-> "BaseTypeTag"
757 | StructUnionTag _
-> "StructUnionTag"
758 | SignTag _
-> "SignTag"
759 | IdentTag _
-> "IdentTag"
760 | ExpressionTag _
-> "ExpressionTag"
761 | ConstantTag _
-> "ConstantTag"
762 | UnaryOpTag _
-> "UnaryOpTag"
763 | AssignOpTag _
-> "AssignOpTag"
764 | FixOpTag _
-> "FixOpTag"
765 | BinaryOpTag _
-> "BinaryOpTag"
766 | ArithOpTag _
-> "ArithOpTag"
767 | LogicalOpTag _
-> "LogicalOpTag"
768 | DeclarationTag _
-> "DeclarationTag"
769 | InitTag _
-> "InitTag"
770 | StorageTag _
-> "StorageTag"
771 | IncFileTag _
-> "IncFileTag"
772 | Rule_elemTag _
-> "Rule_elemTag"
773 | StatementTag _
-> "StatementTag"
774 | CaseLineTag _
-> "CaseLineTag"
775 | ConstVolTag _
-> "ConstVolTag"
777 | Pragma _
-> "Pragma"
779 | ExprDotsTag _
-> "ExprDotsTag"
780 | ParamDotsTag _
-> "ParamDotsTag"
781 | StmtDotsTag _
-> "StmtDotsTag"
782 | DeclDotsTag _
-> "DeclDotsTag"
783 | TypeCTag _
-> "TypeCTag"
784 | ParamTag _
-> "ParamTag"
785 | SgrepStartTag _
-> "SgrepStartTag"
786 | SgrepEndTag _
-> "SgrepEndTag"
788 (* --------------------------------------------------------------------- *)
790 let no_info = { line
= 0; column
= -1; strbef
= []; straft
= [] }
796 minus_free_vars
= [];
802 true_if_test_exp
= false;
803 safe_for_multi_decls
= false;
806 let make_inherited_term x inherited
=
810 minus_free_vars
= [];
812 inherited
= inherited
;
816 true_if_test_exp
= false;
817 safe_for_multi_decls
= false;
820 let make_meta_rule_elem s d
(fvs
,fresh
,inh
) =
823 (MetaRuleElem
(((rule,s
),no_info,d
,[]),Type_cocci.Unitary
,false)))
824 with free_vars
= fvs
; fresh_vars
= fresh
; inherited
= inh
}
826 let make_meta_decl s d
(fvs
,fresh
,inh
) =
829 (MetaDecl
(((rule,s
),no_info,d
,[]),Type_cocci.Unitary
,false))) with
830 free_vars
= fvs
; fresh_vars
= fresh
; inherited
= inh
}
832 let make_mcode x
= (x
,no_info,CONTEXT
(NoPos
,NOTHING
),[])
834 (* --------------------------------------------------------------------- *)
836 let equal_pos x y
= x
= y
838 (* --------------------------------------------------------------------- *)