2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
25 (* --------------------------------------------------------------------- *)
28 type added_string
= Noindent
of string | Indent
of string | Space
of string
30 type info
= { line
: int; column
: int;
31 strbef
: (added_string
* int (* line *) * int (* col *)) list
;
32 straft
: (added_string
* int (* line *) * int (* col *)) list
}
34 type meta_name
= string * string
35 (* need to be careful about rewrapping, to avoid duplicating pos info
36 currently, the pos info is always None until asttoctl2. *)
40 free_vars
: meta_name list
; (*free vars*)
41 minus_free_vars
: meta_name list
; (*minus free vars*)
42 fresh_vars
: (meta_name
* seed
) list
; (*fresh vars*)
43 inherited
: meta_name list
; (*inherited vars*)
44 saved_witness
: meta_name list
; (*witness vars*)
45 bef_aft
: dots_bef_aft
;
46 (* the following is for or expressions *)
47 pos_info
: meta_name mcode
option; (* pos info, try not to duplicate *)
48 true_if_test_exp
: bool;(* true if "test_exp from iso", only for exprs *)
49 (* the following is only for declarations *)
50 safe_for_multi_decls
: bool;
51 (* isos relevant to the term; ultimately only used for rule_elems *)
52 iso_info
: (string*anything
) list
}
55 BEFORE
of 'a list list
* count
56 | AFTER
of 'a list list
* count
57 | BEFOREAFTER
of 'a list list
* 'a list list
* count
60 and 'a replacement
= REPLACEMENT
of 'a list list
* count
| NOREPLACEMENT
62 and 'a mcode
= 'a
* info
* mcodekind
* meta_pos list
(* pos variables *)
63 (* pos is an offset indicating where in the C code the mcodekind
65 (* int list is the match instances, which are only meaningful in annotated
67 (* adjacency is the adjacency index, which is incremented on context dots *)
68 (* iteration is only allowed on context code, the intuition vaguely being
69 that there is no way to replace something more than once. Actually,
70 allowing iterated additions on minus code would cause problems with some
71 heuristics for adding braces, because one couldn't identify simple
72 replacements with certainty. Anyway, iteration doesn't seem to be needed
73 on - code for the moment. Although it may be confusing that there can be
74 iterated addition of code before context code where the context code is
75 immediately followed by removed code. *)
76 and adjacency
= ALLMINUS
| ADJ
of int
78 MINUS
of pos
* int list
* adjacency
* anything replacement
79 | CONTEXT
of pos
* anything befaft
81 and count
= ONE
(* + *) | MANY
(* ++ *)
83 Real
of int (* charpos *) | Virt
of int * int (* charpos + offset *)
84 and pos
= NoPos
| DontCarePos
| FixPos
of (fixpos
* fixpos
)
88 | AddingBetweenDots
of statement
* int (*index of let var*)
89 | DroppingBetweenDots
of statement
* int (*index of let var*)
91 and inherited
= Type_cocci.inherited
92 and keep_binding
= Type_cocci.keep_binding
93 and multi
= bool (*true if a nest is one or more, false if it is zero or more*)
96 meta_name list
(*free vars*) * (meta_name
* seed
) list
(*fresh*) *
97 meta_name list
(*inherited vars*) * mcodekind
99 (* --------------------------------------------------------------------- *)
102 and arity
= UNIQUE
| OPT
| MULTI
| NONE
105 MetaMetaDecl
of arity
* meta_name
(* name *)
106 | MetaIdDecl
of arity
* meta_name
(* name *)
107 | MetaFreshIdDecl
of meta_name
(* name *) * seed
(* seed *)
108 | MetaTypeDecl
of arity
* meta_name
(* name *)
109 | MetaInitDecl
of arity
* meta_name
(* name *)
110 | MetaInitListDecl
of arity
* meta_name
(* name *) * list_len
(*len*)
111 | MetaListlenDecl
of meta_name
(* name *)
112 | MetaParamDecl
of arity
* meta_name
(* name *)
113 | MetaParamListDecl
of arity
* meta_name
(*name*) * list_len
(*len*)
115 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
116 | MetaErrDecl
of arity
* meta_name
(* name *)
118 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
120 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
121 | MetaLocalIdExpDecl
of
122 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
123 | MetaExpListDecl
of arity
* meta_name
(*name*) * list_len
(*len*)
124 | MetaDeclDecl
of arity
* meta_name
(* name *)
125 | MetaFieldDecl
of arity
* meta_name
(* name *)
126 | MetaFieldListDecl
of arity
* meta_name
(* name *) * list_len
(*len*)
127 | MetaStmDecl
of arity
* meta_name
(* name *)
128 | MetaStmListDecl
of arity
* meta_name
(* name *)
129 | MetaFuncDecl
of arity
* meta_name
(* name *)
130 | MetaLocalFuncDecl
of arity
* meta_name
(* name *)
131 | MetaPosDecl
of arity
* meta_name
(* name *)
132 | MetaDeclarerDecl
of arity
* meta_name
(* name *)
133 | MetaIteratorDecl
of arity
* meta_name
(* name *)
135 and list_len
= AnyLen
| MetaLen
of meta_name
| CstLen
of int
137 and seed
= NoVal
| StringSeed
of string | ListSeed
of seed_elem list
138 and seed_elem
= SeedString
of string | SeedId
of meta_name
140 (* --------------------------------------------------------------------- *)
141 (* --------------------------------------------------------------------- *)
149 and 'a dots
= 'a base_dots wrap
151 (* --------------------------------------------------------------------- *)
156 | MetaId
of meta_name mcode
* idconstraint
* keep_binding
* inherited
157 | MetaFunc
of meta_name mcode
* idconstraint
* keep_binding
* inherited
158 | MetaLocalFunc
of meta_name mcode
* idconstraint
* keep_binding
* inherited
160 | DisjId
of ident list
162 | UniqueIdent
of ident
164 and ident
= base_ident wrap
166 (* --------------------------------------------------------------------- *)
169 and base_expression
=
171 | Constant
of constant mcode
172 | FunCall
of expression
* string mcode
(* ( *) *
173 expression dots
* string mcode
(* ) *)
174 | Assignment
of expression
* assignOp mcode
* expression
*
175 bool (* true if it can match an initialization *)
176 | CondExpr
of expression
* string mcode
(* ? *) * expression
option *
177 string mcode
(* : *) * expression
178 | Postfix
of expression
* fixOp mcode
179 | Infix
of expression
* fixOp mcode
180 | Unary
of expression
* unaryOp mcode
181 | Binary
of expression
* binaryOp mcode
* expression
182 | Nested
of expression
* binaryOp mcode
* expression
183 | ArrayAccess
of expression
* string mcode
(* [ *) * expression
*
185 | RecordAccess
of expression
* string mcode
(* . *) * ident
186 | RecordPtAccess
of expression
* string mcode
(* -> *) * ident
187 | Cast
of string mcode
(* ( *) * fullType
* string mcode
(* ) *) *
189 | SizeOfExpr
of string mcode
(* sizeof *) * expression
190 | SizeOfType
of string mcode
(* sizeof *) * string mcode
(* ( *) *
191 fullType
* string mcode
(* ) *)
192 | TypeExp
of fullType
(*type name used as an expression, only in
195 | Paren
of string mcode
(* ( *) * expression
*
198 | Constructor
of string mcode
(* ( *) * fullType
* string mcode
(* ) *) *
200 | MetaErr
of meta_name mcode
* constraints
* keep_binding
*
202 | MetaExpr
of meta_name mcode
* constraints
* keep_binding
*
203 Type_cocci.typeC list
option * form
* inherited
204 | MetaExprList
of meta_name mcode
* listlen
* keep_binding
*
205 inherited
(* only in arg lists *)
207 | EComma
of string mcode
(* only in arg lists *)
209 | DisjExpr
of expression list
210 | NestExpr
of string mcode
(* <.../<+... *) *
212 string mcode
(* ...>/...+> *) *
213 expression
option * multi
215 (* can appear in arg lists, and also inside Nest, as in:
216 if(< ... X ... Y ...>)
217 In the following, the expression option is the WHEN *)
218 | Edots
of string mcode
(* ... *) * expression
option
219 | Ecircles
of string mcode
(* ooo *) * expression
option
220 | Estars
of string mcode
(* *** *) * expression
option
222 | OptExp
of expression
223 | UniqueExp
of expression
227 | NotIdCstrt
of reconstraint
228 | NotExpCstrt
of expression list
229 | SubExpCstrt
of meta_name list
231 (* Constraints on Meta-* Identifiers, Functions *)
234 | IdNegIdSet
of string list
* meta_name list
235 | IdRegExpConstraint
of reconstraint
238 | IdRegExp
of string * Regexp.regexp
239 | IdNotRegExp
of string * Regexp.regexp
241 (* ANY = int E; ID = idexpression int X; CONST = constant int X; *)
242 and form
= ANY
| ID
| LocalID
| CONST
(* form for MetaExp *)
244 and expression
= base_expression wrap
247 MetaListLen
of meta_name mcode
* keep_binding
* inherited
251 and unaryOp
= GetRef
| GetRefLabel
| DeRef
| UnPlus
| UnMinus
| Tilde
| Not
252 and assignOp
= SimpleAssign
| OpAssign
of arithOp
253 and fixOp
= Dec
| Inc
255 and binaryOp
= Arith
of arithOp
| Logical
of logicalOp
257 Plus
| Minus
| Mul
| Div
| Mod
| DecLeft
| DecRight
| And
| Or
| Xor
258 and logicalOp
= Inf
| Sup
| InfEq
| SupEq
| Eq
| NotEq
| AndLog
| OrLog
266 (* --------------------------------------------------------------------- *)
270 Type
of const_vol mcode
option * typeC
271 | DisjType
of fullType list
(* only after iso *)
272 | OptType
of fullType
273 | UniqueType
of fullType
276 BaseType
of baseType
* string mcode list
(* Yoann style *)
277 | SignedT
of sign mcode
* typeC
option
278 | Pointer
of fullType
* string mcode
(* * *)
279 | FunctionPointer
of fullType
*
280 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
281 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
283 (* used for the automatic managment of prototypes *)
284 | FunctionType
of bool (* true if all minus for dropping return type *) *
286 string mcode
(* ( *) * parameter_list
*
289 | Array
of fullType
* string mcode
(* [ *) *
290 expression
option * string mcode
(* ] *)
291 | EnumName
of string mcode
(*enum*) * ident
option (* name *)
292 | EnumDef
of fullType
(* either EnumName or metavar *) *
293 string mcode
(* { *) * expression dots
* string mcode
(* } *)
294 | StructUnionName
of structUnion mcode
* ident
option (* name *)
295 | StructUnionDef
of fullType
(* either StructUnionName or metavar *) *
296 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
297 | TypeName
of string mcode
(* pad: should be 'of ident' ? *)
299 | MetaType
of meta_name mcode
* keep_binding
* inherited
301 and fullType
= base_fullType wrap
302 and typeC
= base_typeC wrap
304 and baseType
= VoidType
| CharType
| ShortType
| ShortIntType
| IntType
305 | DoubleType
| LongDoubleType
| FloatType
306 | LongType
| LongIntType
| LongLongType
| LongLongIntType
307 | SizeType
| SSizeType
| PtrDiffType
309 and structUnion
= Struct
| Union
311 and sign
= Signed
| Unsigned
313 and const_vol
= Const
| Volatile
315 (* --------------------------------------------------------------------- *)
316 (* Variable declaration *)
317 (* Even if the Cocci program specifies a list of declarations, they are
318 split out into multiple declarations of a single variable each. *)
320 and base_declaration
=
321 Init
of storage mcode
option * fullType
* ident
* string mcode
(*=*) *
322 initialiser
* string mcode
(*;*)
323 | UnInit
of storage mcode
option * fullType
* ident
* string mcode
(* ; *)
324 | TyDecl
of fullType
* string mcode
(* ; *)
325 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
326 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
327 | Typedef
of string mcode
(*typedef*) * fullType
*
328 typeC
(* either TypeName or metavar *) * string mcode
(*;*)
329 | DisjDecl
of declaration list
330 (* Ddots is for a structure declaration *)
331 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
333 | MetaDecl
of meta_name mcode
* keep_binding
* inherited
334 | MetaField
of meta_name mcode
* keep_binding
* inherited
335 | MetaFieldList
of meta_name mcode
* listlen
* keep_binding
* inherited
337 | OptDecl
of declaration
338 | UniqueDecl
of declaration
340 and declaration
= base_declaration wrap
342 (* --------------------------------------------------------------------- *)
345 and base_initialiser
=
346 MetaInit
of meta_name mcode
* keep_binding
* inherited
347 | MetaInitList
of meta_name mcode
* listlen
* keep_binding
* inherited
348 | InitExpr
of expression
349 | ArInitList
of string mcode
(*{*) * initialiser dots
* string mcode
(*}*)
350 | StrInitList
of bool (* true if all are - *) *
351 string mcode
(*{*) * initialiser list
* string mcode
(*}*) *
352 initialiser list
(* whencode: elements that shouldn't appear in init *)
354 designator list
(* name *) * string mcode
(*=*) *
355 initialiser
(* gccext: *)
356 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
358 | IComma
of string mcode
(* , *)
359 | Idots
of string mcode
(* ... *) * initialiser
option (* whencode *)
361 | OptIni
of initialiser
362 | UniqueIni
of initialiser
365 DesignatorField
of string mcode
(* . *) * ident
366 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
368 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
369 expression
* string mcode
(* ] *)
371 and initialiser
= base_initialiser wrap
373 (* --------------------------------------------------------------------- *)
376 and base_parameterTypeDef
=
377 VoidParam
of fullType
378 | Param
of fullType
* ident
option
380 | MetaParam
of meta_name mcode
* keep_binding
* inherited
381 | MetaParamList
of meta_name mcode
* listlen
* keep_binding
* inherited
383 | PComma
of string mcode
385 | Pdots
of string mcode
(* ... *)
386 | Pcircles
of string mcode
(* ooo *)
388 | OptParam
of parameterTypeDef
389 | UniqueParam
of parameterTypeDef
391 and parameterTypeDef
= base_parameterTypeDef wrap
393 and parameter_list
= parameterTypeDef dots
395 (* --------------------------------------------------------------------- *)
396 (* #define Parameters *)
398 and base_define_param
=
400 | DPComma
of string mcode
401 | DPdots
of string mcode
(* ... *)
402 | DPcircles
of string mcode
(* ooo *)
403 | OptDParam
of define_param
404 | UniqueDParam
of define_param
406 and define_param
= base_define_param wrap
408 and base_define_parameters
=
409 NoParams
(* not parameter list, not an empty one *)
410 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
412 and define_parameters
= base_define_parameters wrap
414 (* --------------------------------------------------------------------- *)
417 (* PER = keep bindings separate, ALL = collect them *)
418 and meta_collect
= PER
| ALL
421 MetaPos
of meta_name mcode
* meta_name list
*
422 meta_collect
* keep_binding
* inherited
424 (* --------------------------------------------------------------------- *)
425 (* Function declaration *)
427 and storage
= Static
| Auto
| Register
| Extern
429 (* --------------------------------------------------------------------- *)
433 FunHeader
of mcodekind
(* before the function header *) *
434 bool (* true if all minus, for dropping static, etc *) *
435 fninfo list
* ident
(* name *) *
436 string mcode
(* ( *) * parameter_list
*
438 | Decl
of mcodekind
(* before the decl *) *
439 bool (* true if all minus *) * declaration
441 | SeqStart
of string mcode
(* { *)
442 | SeqEnd
of string mcode
(* } *)
444 | ExprStatement
of expression
option * string mcode
(*;*)
445 | IfHeader
of string mcode
(* if *) * string mcode
(* ( *) *
446 expression
* string mcode
(* ) *)
447 | Else
of string mcode
(* else *)
448 | WhileHeader
of string mcode
(* while *) * string mcode
(* ( *) *
449 expression
* string mcode
(* ) *)
450 | DoHeader
of string mcode
(* do *)
451 | WhileTail
of string mcode
(* while *) * string mcode
(* ( *) *
452 expression
* string mcode
(* ) *) *
454 | ForHeader
of string mcode
(* for *) * string mcode
(* ( *) *
455 expression
option * string mcode
(*;*) *
456 expression
option * string mcode
(*;*) *
457 expression
option * string mcode
(* ) *)
458 | IteratorHeader
of ident
(* name *) * string mcode
(* ( *) *
459 expression dots
* string mcode
(* ) *)
460 | SwitchHeader
of string mcode
(* switch *) * string mcode
(* ( *) *
461 expression
* string mcode
(* ) *)
462 | Break
of string mcode
(* break *) * string mcode
(* ; *)
463 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
464 | Label
of ident
* string mcode
(* : *)
465 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
466 | Return
of string mcode
(* return *) * string mcode
(* ; *)
467 | ReturnExpr
of string mcode
(* return *) * expression
*
470 | MetaRuleElem
of meta_name mcode
* keep_binding
* inherited
471 | MetaStmt
of meta_name mcode
* keep_binding
* metaStmtInfo
*
473 | MetaStmtList
of meta_name mcode
* keep_binding
* inherited
475 | Exp
of expression
(* matches a subterm *)
476 | TopExp
of expression
(* for macros body, exp at top level,
478 | Ty
of fullType
(* only at SP top level, matches a subterm *)
479 | TopInit
of initialiser
(* only at top level *)
480 | Include
of string mcode
(*#include*) * inc_file mcode
(*file *)
481 | Undef
of string mcode
(* #define *) * ident
(* name *)
482 | DefineHeader
of string mcode
(* #define *) * ident
(* name *) *
483 define_parameters
(*params*)
484 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*)
485 | Default
of string mcode
(* default *) * string mcode
(*:*)
486 | DisjRuleElem
of rule_elem list
489 FStorage
of storage mcode
491 | FInline
of string mcode
492 | FAttr
of string mcode
495 NotSequencible
| SequencibleAfterDots
of dots_whencode list
| Sequencible
497 and rule_elem
= base_rule_elem wrap
500 Seq
of rule_elem
(* { *) *
501 statement dots
* rule_elem
(* } *)
502 | IfThen
of rule_elem
(* header *) * statement
* end_info
(* endif *)
503 | IfThenElse
of rule_elem
(* header *) * statement
*
504 rule_elem
(* else *) * statement
* end_info
(* endif *)
505 | While
of rule_elem
(* header *) * statement
* end_info
(*endwhile*)
506 | Do
of rule_elem
(* do *) * statement
* rule_elem
(* tail *)
507 | For
of rule_elem
(* header *) * statement
* end_info
(*endfor*)
508 | Iterator
of rule_elem
(* header *) * statement
* end_info
(*enditer*)
509 | Switch
of rule_elem
(* header *) * rule_elem
(* { *) *
510 statement
(*decl*) dots
* case_line list
* rule_elem
(*}*)
511 | Atomic
of rule_elem
512 | Disj
of statement dots list
513 | Nest
of string mcode
(* <.../<+... *) * statement dots
*
514 string mcode
(* ...>/...+> *) *
515 (statement dots
,statement
) whencode list
* multi
*
516 dots_whencode list
* dots_whencode list
517 | FunDecl
of rule_elem
(* header *) * rule_elem
(* { *) *
518 statement dots
* rule_elem
(* } *)
519 | Define
of rule_elem
(* header *) * statement dots
520 | Dots
of string mcode
(* ... *) *
521 (statement dots
,statement
) whencode list
*
522 dots_whencode list
* dots_whencode list
523 | Circles
of string mcode
(* ooo *) *
524 (statement dots
,statement
) whencode list
*
525 dots_whencode list
* dots_whencode list
526 | Stars
of string mcode
(* *** *) *
527 (statement dots
,statement
) whencode list
*
528 dots_whencode list
* dots_whencode list
529 | OptStm
of statement
530 | UniqueStm
of statement
532 and ('a
,'b
) whencode
=
535 | WhenModifier
of when_modifier
536 | WhenNotTrue
of rule_elem
(* useful for fvs *)
537 | WhenNotFalse
of rule_elem
540 (* The following removes the shortest path constraint. It can be used
541 with other when modifiers *)
543 (* The following removes the special consideration of error paths. It
544 can be used with other when modifiers *)
549 (* only used with asttoctl *)
551 WParen
of rule_elem
* meta_name
(*pren_var*)
553 | Other_dots
of statement dots
555 and statement
= base_statement wrap
558 CaseLine
of rule_elem
(* case/default header *) * statement dots
559 | OptCase
of case_line
561 and case_line
= base_case_line wrap
564 Local
of inc_elem list
565 | NonLocal
of inc_elem list
573 | CODE
of statement dots
574 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
575 | ERRORWORDS
of expression list
577 and top_level
= base_top_level wrap
580 CocciRulename
of string option * dependency
*
581 string list
* string list
* exists
* bool
582 | GeneratedRulename
of string option * dependency
*
583 string list
* string list
* exists
* bool
584 | ScriptRulename
of string option (* name *) * string (* language *) *
586 | InitialScriptRulename
of string option (* name *) * string (* language *) *
588 | FinalScriptRulename
of string option (* name *) * string (* language *) *
591 and ruletype
= Normal
| Generated
594 CocciRule
of string (* name *) *
595 (dependency
* string list
(* dropped isos *) * exists
) * top_level list
596 * bool list
* ruletype
597 | ScriptRule
of string (* name *) *
598 (* metaname for python (untyped), metavar for ocaml (typed) *)
599 string * dependency
*
600 (script_meta_name
* meta_name
* metavar
) list
(*inherited vars*) *
601 meta_name list
(*script vars*) * string
602 | InitialScriptRule
of string (* name *) *
603 string (*language*) * dependency
* string (*code*)
604 | FinalScriptRule
of string (* name *) *
605 string (*language*) * dependency
* string (*code*)
607 and script_meta_name
= string option (*string*) * string option (*ast*)
610 Dep
of string (* rule applies for the current binding *)
611 | AntiDep
of string (* rule doesn't apply for the current binding *)
612 | EverDep
of string (* rule applies for some binding *)
613 | NeverDep
of string (* rule never applies for any binding *)
614 | AndDep
of dependency
* dependency
615 | OrDep
of dependency
* dependency
618 and rule_with_metavars
= metavar list
* rule
621 FullTypeTag
of fullType
622 | BaseTypeTag
of baseType
623 | StructUnionTag
of structUnion
626 | ExpressionTag
of expression
627 | ConstantTag
of constant
628 | UnaryOpTag
of unaryOp
629 | AssignOpTag
of assignOp
631 | BinaryOpTag
of binaryOp
632 | ArithOpTag
of arithOp
633 | LogicalOpTag
of logicalOp
634 | DeclarationTag
of declaration
635 | InitTag
of initialiser
636 | StorageTag
of storage
637 | IncFileTag
of inc_file
638 | Rule_elemTag
of rule_elem
639 | StatementTag
of statement
640 | CaseLineTag
of case_line
641 | ConstVolTag
of const_vol
642 | Token
of string * info
option
643 | Pragma
of added_string list
645 | ExprDotsTag
of expression dots
646 | ParamDotsTag
of parameterTypeDef dots
647 | StmtDotsTag
of statement dots
648 | DeclDotsTag
of declaration dots
650 | ParamTag
of parameterTypeDef
651 | SgrepStartTag
of string
652 | SgrepEndTag
of string
654 (* --------------------------------------------------------------------- *)
656 and exists
= Exists
| Forall
| Undetermined
657 (* | ReverseForall - idea: look back on all flow paths; not implemented *)
659 (* --------------------------------------------------------------------- *)
661 let mkToken x
= Token
(x
,None
)
663 (* --------------------------------------------------------------------- *)
665 let lub_count i1 i2
=
670 (* --------------------------------------------------------------------- *)
672 let rewrap model x
= {model
with node
= x
}
673 let rewrap_mcode (_
,a
,b
,c
) x
= (x
,a
,b
,c
)
674 let unwrap x
= x
.node
675 let unwrap_mcode (x
,_
,_
,_
) = x
676 let get_mcodekind (_
,_
,x
,_
) = x
677 let get_line x
= x
.node_line
678 let get_mcode_line (_
,l
,_
,_
) = l
.line
679 let get_mcode_col (_
,l
,_
,_
) = l
.column
680 let get_fvs x
= x
.free_vars
681 let set_fvs fvs x
= {x
with free_vars
= fvs
}
682 let get_mfvs x
= x
.minus_free_vars
683 let set_mfvs mfvs x
= {x
with minus_free_vars
= mfvs
}
684 let get_fresh x
= x
.fresh_vars
685 let get_inherited x
= x
.inherited
686 let get_saved x
= x
.saved_witness
687 let get_dots_bef_aft x
= x
.bef_aft
688 let set_dots_bef_aft d x
= {x
with bef_aft
= d
}
689 let get_pos x
= x
.pos_info
690 let set_pos x pos
= {x
with pos_info
= pos
}
691 let get_test_exp x
= x
.true_if_test_exp
692 let set_test_exp x
= {x
with true_if_test_exp
= true}
693 let get_safe_decl x
= x
.safe_for_multi_decls
694 let get_isos x
= x
.iso_info
695 let set_isos x isos
= {x
with iso_info
= isos
}
696 let get_pos_var (_
,_
,_
,p
) = p
697 let set_pos_var vr
(a
,b
,c
,_
) = (a
,b
,c
,vr
)
698 let drop_pos (a
,b
,c
,_
) = (a
,b
,c
,[])
700 let get_wcfvs (whencode
: ('a wrap
, 'b wrap
) whencode list
) =
704 WhenNot
(a
) -> get_fvs a
705 | WhenAlways
(a
) -> get_fvs a
706 | WhenModifier
(_
) -> []
707 | WhenNotTrue
(e
) -> get_fvs e
708 | WhenNotFalse
(e
) -> get_fvs e
)
711 (* --------------------------------------------------------------------- *)
713 let get_meta_name = function
714 MetaMetaDecl
(ar
,nm
) -> nm
715 | MetaIdDecl
(ar
,nm
) -> nm
716 | MetaFreshIdDecl
(nm
,seed
) -> nm
717 | MetaTypeDecl
(ar
,nm
) -> nm
718 | MetaInitDecl
(ar
,nm
) -> nm
719 | MetaInitListDecl
(ar
,nm
,nm1
) -> nm
720 | MetaListlenDecl
(nm
) -> nm
721 | MetaParamDecl
(ar
,nm
) -> nm
722 | MetaParamListDecl
(ar
,nm
,nm1
) -> nm
723 | MetaConstDecl
(ar
,nm
,ty
) -> nm
724 | MetaErrDecl
(ar
,nm
) -> nm
725 | MetaExpDecl
(ar
,nm
,ty
) -> nm
726 | MetaIdExpDecl
(ar
,nm
,ty
) -> nm
727 | MetaLocalIdExpDecl
(ar
,nm
,ty
) -> nm
728 | MetaExpListDecl
(ar
,nm
,nm1
) -> nm
729 | MetaDeclDecl
(ar
,nm
) -> nm
730 | MetaFieldDecl
(ar
,nm
) -> nm
731 | MetaFieldListDecl
(ar
,nm
,nm1
) -> nm
732 | MetaStmDecl
(ar
,nm
) -> nm
733 | MetaStmListDecl
(ar
,nm
) -> nm
734 | MetaFuncDecl
(ar
,nm
) -> nm
735 | MetaLocalFuncDecl
(ar
,nm
) -> nm
736 | MetaPosDecl
(ar
,nm
) -> nm
737 | MetaDeclarerDecl
(ar
,nm
) -> nm
738 | MetaIteratorDecl
(ar
,nm
) -> nm
740 (* --------------------------------------------------------------------- *)
743 FullTypeTag _
-> "FullTypeTag"
744 | BaseTypeTag _
-> "BaseTypeTag"
745 | StructUnionTag _
-> "StructUnionTag"
746 | SignTag _
-> "SignTag"
747 | IdentTag _
-> "IdentTag"
748 | ExpressionTag _
-> "ExpressionTag"
749 | ConstantTag _
-> "ConstantTag"
750 | UnaryOpTag _
-> "UnaryOpTag"
751 | AssignOpTag _
-> "AssignOpTag"
752 | FixOpTag _
-> "FixOpTag"
753 | BinaryOpTag _
-> "BinaryOpTag"
754 | ArithOpTag _
-> "ArithOpTag"
755 | LogicalOpTag _
-> "LogicalOpTag"
756 | DeclarationTag _
-> "DeclarationTag"
757 | InitTag _
-> "InitTag"
758 | StorageTag _
-> "StorageTag"
759 | IncFileTag _
-> "IncFileTag"
760 | Rule_elemTag _
-> "Rule_elemTag"
761 | StatementTag _
-> "StatementTag"
762 | CaseLineTag _
-> "CaseLineTag"
763 | ConstVolTag _
-> "ConstVolTag"
765 | Pragma _
-> "Pragma"
767 | ExprDotsTag _
-> "ExprDotsTag"
768 | ParamDotsTag _
-> "ParamDotsTag"
769 | StmtDotsTag _
-> "StmtDotsTag"
770 | DeclDotsTag _
-> "DeclDotsTag"
771 | TypeCTag _
-> "TypeCTag"
772 | ParamTag _
-> "ParamTag"
773 | SgrepStartTag _
-> "SgrepStartTag"
774 | SgrepEndTag _
-> "SgrepEndTag"
776 (* --------------------------------------------------------------------- *)
778 let no_info = { line
= 0; column
= -1; strbef
= []; straft
= [] }
784 minus_free_vars
= [];
790 true_if_test_exp
= false;
791 safe_for_multi_decls
= false;
794 let make_meta_rule_elem s d
(fvs
,fresh
,inh
) =
797 (MetaRuleElem
(((rule,s
),no_info,d
,[]),Type_cocci.Unitary
,false)))
798 with free_vars
= fvs
; fresh_vars
= fresh
; inherited
= inh
}
800 let make_meta_decl s d
(fvs
,fresh
,inh
) =
803 (MetaDecl
(((rule,s
),no_info,d
,[]),Type_cocci.Unitary
,false))) with
804 free_vars
= fvs
; fresh_vars
= fresh
; inherited
= inh
}
806 let make_mcode x
= (x
,no_info,CONTEXT
(NoPos
,NOTHING
),[])
808 (* --------------------------------------------------------------------- *)
810 let equal_pos x y
= x
= y
812 (* --------------------------------------------------------------------- *)