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 | MetaErr
of meta_name mcode
* constraints
* keep_binding
*
200 | MetaExpr
of meta_name mcode
* constraints
* keep_binding
*
201 Type_cocci.typeC list
option * form
* inherited
202 | MetaExprList
of meta_name mcode
* listlen
* keep_binding
*
203 inherited
(* only in arg lists *)
205 | EComma
of string mcode
(* only in arg lists *)
207 | DisjExpr
of expression list
208 | NestExpr
of string mcode
(* <.../<+... *) *
210 string mcode
(* ...>/...+> *) *
211 expression
option * multi
213 (* can appear in arg lists, and also inside Nest, as in:
214 if(< ... X ... Y ...>)
215 In the following, the expression option is the WHEN *)
216 | Edots
of string mcode
(* ... *) * expression
option
217 | Ecircles
of string mcode
(* ooo *) * expression
option
218 | Estars
of string mcode
(* *** *) * expression
option
220 | OptExp
of expression
221 | UniqueExp
of expression
225 | NotIdCstrt
of reconstraint
226 | NotExpCstrt
of expression list
227 | SubExpCstrt
of meta_name list
229 (* Constraints on Meta-* Identifiers, Functions *)
232 | IdNegIdSet
of string list
* meta_name list
233 | IdRegExpConstraint
of reconstraint
236 | IdRegExp
of string * Str.regexp
237 | IdNotRegExp
of string * Str.regexp
239 (* ANY = int E; ID = idexpression int X; CONST = constant int X; *)
240 and form
= ANY
| ID
| LocalID
| CONST
(* form for MetaExp *)
242 and expression
= base_expression wrap
245 MetaListLen
of meta_name mcode
* keep_binding
* inherited
249 and unaryOp
= GetRef
| GetRefLabel
| DeRef
| UnPlus
| UnMinus
| Tilde
| Not
250 and assignOp
= SimpleAssign
| OpAssign
of arithOp
251 and fixOp
= Dec
| Inc
253 and binaryOp
= Arith
of arithOp
| Logical
of logicalOp
255 Plus
| Minus
| Mul
| Div
| Mod
| DecLeft
| DecRight
| And
| Or
| Xor
256 and logicalOp
= Inf
| Sup
| InfEq
| SupEq
| Eq
| NotEq
| AndLog
| OrLog
264 (* --------------------------------------------------------------------- *)
268 Type
of const_vol mcode
option * typeC
269 | DisjType
of fullType list
(* only after iso *)
270 | OptType
of fullType
271 | UniqueType
of fullType
274 BaseType
of baseType
* string mcode list
(* Yoann style *)
275 | SignedT
of sign mcode
* typeC
option
276 | Pointer
of fullType
* string mcode
(* * *)
277 | FunctionPointer
of fullType
*
278 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
279 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
281 (* used for the automatic managment of prototypes *)
282 | FunctionType
of bool (* true if all minus for dropping return type *) *
284 string mcode
(* ( *) * parameter_list
*
287 | Array
of fullType
* string mcode
(* [ *) *
288 expression
option * string mcode
(* ] *)
289 | EnumName
of string mcode
(*enum*) * ident
option (* name *)
290 | EnumDef
of fullType
(* either EnumName or metavar *) *
291 string mcode
(* { *) * expression dots
* string mcode
(* } *)
292 | StructUnionName
of structUnion mcode
* ident
option (* name *)
293 | StructUnionDef
of fullType
(* either StructUnionName or metavar *) *
294 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
295 | TypeName
of string mcode
(* pad: should be 'of ident' ? *)
297 | MetaType
of meta_name mcode
* keep_binding
* inherited
299 and fullType
= base_fullType wrap
300 and typeC
= base_typeC wrap
302 and baseType
= VoidType
| CharType
| ShortType
| IntType
| DoubleType
303 | FloatType
| LongType
| LongLongType
| SizeType
| SSizeType
| PtrDiffType
305 and structUnion
= Struct
| Union
307 and sign
= Signed
| Unsigned
309 and const_vol
= Const
| Volatile
311 (* --------------------------------------------------------------------- *)
312 (* Variable declaration *)
313 (* Even if the Cocci program specifies a list of declarations, they are
314 split out into multiple declarations of a single variable each. *)
316 and base_declaration
=
317 Init
of storage mcode
option * fullType
* ident
* string mcode
(*=*) *
318 initialiser
* string mcode
(*;*)
319 | UnInit
of storage mcode
option * fullType
* ident
* string mcode
(* ; *)
320 | TyDecl
of fullType
* string mcode
(* ; *)
321 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
322 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
323 | Typedef
of string mcode
(*typedef*) * fullType
*
324 typeC
(* either TypeName or metavar *) * string mcode
(*;*)
325 | DisjDecl
of declaration list
326 (* Ddots is for a structure declaration *)
327 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
329 | MetaDecl
of meta_name mcode
* keep_binding
* inherited
330 | MetaField
of meta_name mcode
* keep_binding
* inherited
331 | MetaFieldList
of meta_name mcode
* listlen
* keep_binding
* inherited
333 | OptDecl
of declaration
334 | UniqueDecl
of declaration
336 and declaration
= base_declaration wrap
338 (* --------------------------------------------------------------------- *)
341 and base_initialiser
=
342 MetaInit
of meta_name mcode
* keep_binding
* inherited
343 | MetaInitList
of meta_name mcode
* listlen
* keep_binding
* inherited
344 | InitExpr
of expression
345 | ArInitList
of string mcode
(*{*) * initialiser dots
* string mcode
(*}*)
346 | StrInitList
of bool (* true if all are - *) *
347 string mcode
(*{*) * initialiser list
* string mcode
(*}*) *
348 initialiser list
(* whencode: elements that shouldn't appear in init *)
350 designator list
(* name *) * string mcode
(*=*) *
351 initialiser
(* gccext: *)
352 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
354 | IComma
of string mcode
(* , *)
355 | Idots
of string mcode
(* ... *) * initialiser
option (* whencode *)
357 | OptIni
of initialiser
358 | UniqueIni
of initialiser
361 DesignatorField
of string mcode
(* . *) * ident
362 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
364 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
365 expression
* string mcode
(* ] *)
367 and initialiser
= base_initialiser wrap
369 (* --------------------------------------------------------------------- *)
372 and base_parameterTypeDef
=
373 VoidParam
of fullType
374 | Param
of fullType
* ident
option
376 | MetaParam
of meta_name mcode
* keep_binding
* inherited
377 | MetaParamList
of meta_name mcode
* listlen
* keep_binding
* inherited
379 | PComma
of string mcode
381 | Pdots
of string mcode
(* ... *)
382 | Pcircles
of string mcode
(* ooo *)
384 | OptParam
of parameterTypeDef
385 | UniqueParam
of parameterTypeDef
387 and parameterTypeDef
= base_parameterTypeDef wrap
389 and parameter_list
= parameterTypeDef dots
391 (* --------------------------------------------------------------------- *)
392 (* #define Parameters *)
394 and base_define_param
=
396 | DPComma
of string mcode
397 | DPdots
of string mcode
(* ... *)
398 | DPcircles
of string mcode
(* ooo *)
399 | OptDParam
of define_param
400 | UniqueDParam
of define_param
402 and define_param
= base_define_param wrap
404 and base_define_parameters
=
405 NoParams
(* not parameter list, not an empty one *)
406 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
408 and define_parameters
= base_define_parameters wrap
410 (* --------------------------------------------------------------------- *)
413 (* PER = keep bindings separate, ALL = collect them *)
414 and meta_collect
= PER
| ALL
417 MetaPos
of meta_name mcode
* meta_name list
*
418 meta_collect
* keep_binding
* inherited
420 (* --------------------------------------------------------------------- *)
421 (* Function declaration *)
423 and storage
= Static
| Auto
| Register
| Extern
425 (* --------------------------------------------------------------------- *)
429 FunHeader
of mcodekind
(* before the function header *) *
430 bool (* true if all minus, for dropping static, etc *) *
431 fninfo list
* ident
(* name *) *
432 string mcode
(* ( *) * parameter_list
*
434 | Decl
of mcodekind
(* before the decl *) *
435 bool (* true if all minus *) * declaration
437 | SeqStart
of string mcode
(* { *)
438 | SeqEnd
of string mcode
(* } *)
440 | ExprStatement
of expression
option * string mcode
(*;*)
441 | IfHeader
of string mcode
(* if *) * string mcode
(* ( *) *
442 expression
* string mcode
(* ) *)
443 | Else
of string mcode
(* else *)
444 | WhileHeader
of string mcode
(* while *) * string mcode
(* ( *) *
445 expression
* string mcode
(* ) *)
446 | DoHeader
of string mcode
(* do *)
447 | WhileTail
of string mcode
(* while *) * string mcode
(* ( *) *
448 expression
* string mcode
(* ) *) *
450 | ForHeader
of string mcode
(* for *) * string mcode
(* ( *) *
451 expression
option * string mcode
(*;*) *
452 expression
option * string mcode
(*;*) *
453 expression
option * string mcode
(* ) *)
454 | IteratorHeader
of ident
(* name *) * string mcode
(* ( *) *
455 expression dots
* string mcode
(* ) *)
456 | SwitchHeader
of string mcode
(* switch *) * string mcode
(* ( *) *
457 expression
* string mcode
(* ) *)
458 | Break
of string mcode
(* break *) * string mcode
(* ; *)
459 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
460 | Label
of ident
* string mcode
(* : *)
461 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
462 | Return
of string mcode
(* return *) * string mcode
(* ; *)
463 | ReturnExpr
of string mcode
(* return *) * expression
*
466 | MetaRuleElem
of meta_name mcode
* keep_binding
* inherited
467 | MetaStmt
of meta_name mcode
* keep_binding
* metaStmtInfo
*
469 | MetaStmtList
of meta_name mcode
* keep_binding
* inherited
471 | Exp
of expression
(* matches a subterm *)
472 | TopExp
of expression
(* for macros body, exp at top level,
474 | Ty
of fullType
(* only at SP top level, matches a subterm *)
475 | TopInit
of initialiser
(* only at top level *)
476 | Include
of string mcode
(*#include*) * inc_file mcode
(*file *)
477 | Undef
of string mcode
(* #define *) * ident
(* name *)
478 | DefineHeader
of string mcode
(* #define *) * ident
(* name *) *
479 define_parameters
(*params*)
480 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*)
481 | Default
of string mcode
(* default *) * string mcode
(*:*)
482 | DisjRuleElem
of rule_elem list
485 FStorage
of storage mcode
487 | FInline
of string mcode
488 | FAttr
of string mcode
491 NotSequencible
| SequencibleAfterDots
of dots_whencode list
| Sequencible
493 and rule_elem
= base_rule_elem wrap
496 Seq
of rule_elem
(* { *) *
497 statement dots
* rule_elem
(* } *)
498 | IfThen
of rule_elem
(* header *) * statement
* end_info
(* endif *)
499 | IfThenElse
of rule_elem
(* header *) * statement
*
500 rule_elem
(* else *) * statement
* end_info
(* endif *)
501 | While
of rule_elem
(* header *) * statement
* end_info
(*endwhile*)
502 | Do
of rule_elem
(* do *) * statement
* rule_elem
(* tail *)
503 | For
of rule_elem
(* header *) * statement
* end_info
(*endfor*)
504 | Iterator
of rule_elem
(* header *) * statement
* end_info
(*enditer*)
505 | Switch
of rule_elem
(* header *) * rule_elem
(* { *) *
506 statement
(*decl*) dots
* case_line list
* rule_elem
(*}*)
507 | Atomic
of rule_elem
508 | Disj
of statement dots list
509 | Nest
of string mcode
(* <.../<+... *) * statement dots
*
510 string mcode
(* ...>/...+> *) *
511 (statement dots
,statement
) whencode list
* multi
*
512 dots_whencode list
* dots_whencode list
513 | FunDecl
of rule_elem
(* header *) * rule_elem
(* { *) *
514 statement dots
* rule_elem
(* } *)
515 | Define
of rule_elem
(* header *) * statement dots
516 | Dots
of string mcode
(* ... *) *
517 (statement dots
,statement
) whencode list
*
518 dots_whencode list
* dots_whencode list
519 | Circles
of string mcode
(* ooo *) *
520 (statement dots
,statement
) whencode list
*
521 dots_whencode list
* dots_whencode list
522 | Stars
of string mcode
(* *** *) *
523 (statement dots
,statement
) whencode list
*
524 dots_whencode list
* dots_whencode list
525 | OptStm
of statement
526 | UniqueStm
of statement
528 and ('a
,'b
) whencode
=
531 | WhenModifier
of when_modifier
532 | WhenNotTrue
of rule_elem
(* useful for fvs *)
533 | WhenNotFalse
of rule_elem
536 (* The following removes the shortest path constraint. It can be used
537 with other when modifiers *)
539 (* The following removes the special consideration of error paths. It
540 can be used with other when modifiers *)
545 (* only used with asttoctl *)
547 WParen
of rule_elem
* meta_name
(*pren_var*)
549 | Other_dots
of statement dots
551 and statement
= base_statement wrap
554 CaseLine
of rule_elem
(* case/default header *) * statement dots
555 | OptCase
of case_line
557 and case_line
= base_case_line wrap
560 Local
of inc_elem list
561 | NonLocal
of inc_elem list
569 | CODE
of statement dots
570 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
571 | ERRORWORDS
of expression list
573 and top_level
= base_top_level wrap
576 CocciRulename
of string option * dependency
*
577 string list
* string list
* exists
* bool
578 | GeneratedRulename
of string option * dependency
*
579 string list
* string list
* exists
* bool
580 | ScriptRulename
of string option (* name *) * string (* language *) *
582 | InitialScriptRulename
of string option (* name *) * string (* language *) *
584 | FinalScriptRulename
of string option (* name *) * string (* language *) *
587 and ruletype
= Normal
| Generated
590 CocciRule
of string (* name *) *
591 (dependency
* string list
(* dropped isos *) * exists
) * top_level list
592 * bool list
* ruletype
593 | ScriptRule
of string (* name *) *
594 (* metaname for python (untyped), metavar for ocaml (typed) *)
595 string * dependency
*
596 (script_meta_name
* meta_name
* metavar
) list
(*inherited vars*) *
597 meta_name list
(*script vars*) * string
598 | InitialScriptRule
of string (* name *) *
599 string (*language*) * dependency
* string (*code*)
600 | FinalScriptRule
of string (* name *) *
601 string (*language*) * dependency
* string (*code*)
603 and script_meta_name
= string option (*string*) * string option (*ast*)
606 Dep
of string (* rule applies for the current binding *)
607 | AntiDep
of string (* rule doesn't apply for the current binding *)
608 | EverDep
of string (* rule applies for some binding *)
609 | NeverDep
of string (* rule never applies for any binding *)
610 | AndDep
of dependency
* dependency
611 | OrDep
of dependency
* dependency
614 and rule_with_metavars
= metavar list
* rule
617 FullTypeTag
of fullType
618 | BaseTypeTag
of baseType
619 | StructUnionTag
of structUnion
622 | ExpressionTag
of expression
623 | ConstantTag
of constant
624 | UnaryOpTag
of unaryOp
625 | AssignOpTag
of assignOp
627 | BinaryOpTag
of binaryOp
628 | ArithOpTag
of arithOp
629 | LogicalOpTag
of logicalOp
630 | DeclarationTag
of declaration
631 | InitTag
of initialiser
632 | StorageTag
of storage
633 | IncFileTag
of inc_file
634 | Rule_elemTag
of rule_elem
635 | StatementTag
of statement
636 | CaseLineTag
of case_line
637 | ConstVolTag
of const_vol
638 | Token
of string * info
option
639 | Pragma
of added_string list
641 | ExprDotsTag
of expression dots
642 | ParamDotsTag
of parameterTypeDef dots
643 | StmtDotsTag
of statement dots
644 | DeclDotsTag
of declaration dots
646 | ParamTag
of parameterTypeDef
647 | SgrepStartTag
of string
648 | SgrepEndTag
of string
650 (* --------------------------------------------------------------------- *)
652 and exists
= Exists
| Forall
| Undetermined
653 (* | ReverseForall - idea: look back on all flow paths; not implemented *)
655 (* --------------------------------------------------------------------- *)
657 let mkToken x
= Token
(x
,None
)
659 (* --------------------------------------------------------------------- *)
661 let lub_count i1 i2
=
666 (* --------------------------------------------------------------------- *)
668 let rewrap model x
= {model
with node
= x
}
669 let rewrap_mcode (_
,a
,b
,c
) x
= (x
,a
,b
,c
)
670 let unwrap x
= x
.node
671 let unwrap_mcode (x
,_
,_
,_
) = x
672 let get_mcodekind (_
,_
,x
,_
) = x
673 let get_line x
= x
.node_line
674 let get_mcode_line (_
,l
,_
,_
) = l
.line
675 let get_mcode_col (_
,l
,_
,_
) = l
.column
676 let get_fvs x
= x
.free_vars
677 let set_fvs fvs x
= {x
with free_vars
= fvs
}
678 let get_mfvs x
= x
.minus_free_vars
679 let set_mfvs mfvs x
= {x
with minus_free_vars
= mfvs
}
680 let get_fresh x
= x
.fresh_vars
681 let get_inherited x
= x
.inherited
682 let get_saved x
= x
.saved_witness
683 let get_dots_bef_aft x
= x
.bef_aft
684 let set_dots_bef_aft d x
= {x
with bef_aft
= d
}
685 let get_pos x
= x
.pos_info
686 let set_pos x pos
= {x
with pos_info
= pos
}
687 let get_test_exp x
= x
.true_if_test_exp
688 let set_test_exp x
= {x
with true_if_test_exp
= true}
689 let get_safe_decl x
= x
.safe_for_multi_decls
690 let get_isos x
= x
.iso_info
691 let set_isos x isos
= {x
with iso_info
= isos
}
692 let get_pos_var (_
,_
,_
,p
) = p
693 let set_pos_var vr
(a
,b
,c
,_
) = (a
,b
,c
,vr
)
694 let drop_pos (a
,b
,c
,_
) = (a
,b
,c
,[])
696 let get_wcfvs (whencode
: ('a wrap
, 'b wrap
) whencode list
) =
700 WhenNot
(a
) -> get_fvs a
701 | WhenAlways
(a
) -> get_fvs a
702 | WhenModifier
(_
) -> []
703 | WhenNotTrue
(e
) -> get_fvs e
704 | WhenNotFalse
(e
) -> get_fvs e
)
707 (* --------------------------------------------------------------------- *)
709 let get_meta_name = function
710 MetaMetaDecl
(ar
,nm
) -> nm
711 | MetaIdDecl
(ar
,nm
) -> nm
712 | MetaFreshIdDecl
(nm
,seed
) -> nm
713 | MetaTypeDecl
(ar
,nm
) -> nm
714 | MetaInitDecl
(ar
,nm
) -> nm
715 | MetaInitListDecl
(ar
,nm
,nm1
) -> nm
716 | MetaListlenDecl
(nm
) -> nm
717 | MetaParamDecl
(ar
,nm
) -> nm
718 | MetaParamListDecl
(ar
,nm
,nm1
) -> nm
719 | MetaConstDecl
(ar
,nm
,ty
) -> nm
720 | MetaErrDecl
(ar
,nm
) -> nm
721 | MetaExpDecl
(ar
,nm
,ty
) -> nm
722 | MetaIdExpDecl
(ar
,nm
,ty
) -> nm
723 | MetaLocalIdExpDecl
(ar
,nm
,ty
) -> nm
724 | MetaExpListDecl
(ar
,nm
,nm1
) -> nm
725 | MetaDeclDecl
(ar
,nm
) -> nm
726 | MetaFieldDecl
(ar
,nm
) -> nm
727 | MetaFieldListDecl
(ar
,nm
,nm1
) -> nm
728 | MetaStmDecl
(ar
,nm
) -> nm
729 | MetaStmListDecl
(ar
,nm
) -> nm
730 | MetaFuncDecl
(ar
,nm
) -> nm
731 | MetaLocalFuncDecl
(ar
,nm
) -> nm
732 | MetaPosDecl
(ar
,nm
) -> nm
733 | MetaDeclarerDecl
(ar
,nm
) -> nm
734 | MetaIteratorDecl
(ar
,nm
) -> nm
736 (* --------------------------------------------------------------------- *)
739 FullTypeTag _
-> "FullTypeTag"
740 | BaseTypeTag _
-> "BaseTypeTag"
741 | StructUnionTag _
-> "StructUnionTag"
742 | SignTag _
-> "SignTag"
743 | IdentTag _
-> "IdentTag"
744 | ExpressionTag _
-> "ExpressionTag"
745 | ConstantTag _
-> "ConstantTag"
746 | UnaryOpTag _
-> "UnaryOpTag"
747 | AssignOpTag _
-> "AssignOpTag"
748 | FixOpTag _
-> "FixOpTag"
749 | BinaryOpTag _
-> "BinaryOpTag"
750 | ArithOpTag _
-> "ArithOpTag"
751 | LogicalOpTag _
-> "LogicalOpTag"
752 | DeclarationTag _
-> "DeclarationTag"
753 | InitTag _
-> "InitTag"
754 | StorageTag _
-> "StorageTag"
755 | IncFileTag _
-> "IncFileTag"
756 | Rule_elemTag _
-> "Rule_elemTag"
757 | StatementTag _
-> "StatementTag"
758 | CaseLineTag _
-> "CaseLineTag"
759 | ConstVolTag _
-> "ConstVolTag"
761 | Pragma _
-> "Pragma"
763 | ExprDotsTag _
-> "ExprDotsTag"
764 | ParamDotsTag _
-> "ParamDotsTag"
765 | StmtDotsTag _
-> "StmtDotsTag"
766 | DeclDotsTag _
-> "DeclDotsTag"
767 | TypeCTag _
-> "TypeCTag"
768 | ParamTag _
-> "ParamTag"
769 | SgrepStartTag _
-> "SgrepStartTag"
770 | SgrepEndTag _
-> "SgrepEndTag"
772 (* --------------------------------------------------------------------- *)
774 let no_info = { line
= 0; column
= -1; strbef
= []; straft
= [] }
780 minus_free_vars
= [];
786 true_if_test_exp
= false;
787 safe_for_multi_decls
= false;
790 let make_meta_rule_elem s d
(fvs
,fresh
,inh
) =
793 (MetaRuleElem
(((rule,s
),no_info,d
,[]),Type_cocci.Unitary
,false)))
794 with free_vars
= fvs
; fresh_vars
= fresh
; inherited
= inh
}
796 let make_meta_decl s d
(fvs
,fresh
,inh
) =
799 (MetaDecl
(((rule,s
),no_info,d
,[]),Type_cocci.Unitary
,false))) with
800 free_vars
= fvs
; fresh_vars
= fresh
; inherited
= inh
}
802 let make_mcode x
= (x
,no_info,CONTEXT
(NoPos
,NOTHING
),[])
804 (* --------------------------------------------------------------------- *)
806 let equal_pos x y
= x
= y
808 (* --------------------------------------------------------------------- *)