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.
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
49 (* --------------------------------------------------------------------- *)
52 type added_string
= Noindent
of string | Indent
of string
54 type info
= { line
: int; column
: int;
55 strbef
: (added_string
* int (* line *) * int (* col *)) list
;
56 straft
: (added_string
* int (* line *) * int (* col *)) list
}
58 type meta_name
= string * string
59 (* need to be careful about rewrapping, to avoid duplicating pos info
60 currently, the pos info is always None until asttoctl2. *)
64 free_vars
: meta_name list
; (*free vars*)
65 minus_free_vars
: meta_name list
; (*minus free vars*)
66 fresh_vars
: (meta_name
* seed
) list
; (*fresh vars*)
67 inherited
: meta_name list
; (*inherited vars*)
68 saved_witness
: meta_name list
; (*witness vars*)
69 bef_aft
: dots_bef_aft
;
70 (* the following is for or expressions *)
71 pos_info
: meta_name mcode
option; (* pos info, try not to duplicate *)
72 true_if_test_exp
: bool;(* true if "test_exp from iso", only for exprs *)
73 (* isos relevant to the term; ultimately only used for rule_elems *)
74 iso_info
: (string*anything
) list
}
77 BEFORE
of 'a list list
* count
78 | AFTER
of 'a list list
* count
79 | BEFOREAFTER
of 'a list list
* 'a list list
* count
82 and 'a mcode
= 'a
* info
* mcodekind
* meta_pos
(* pos variable *)
83 (* pos is an offset indicating where in the C code the mcodekind
85 (* int list is the match instances, which are only meaningful in annotated
87 (* int is the adjacency index, which is incremented on context dots *)
88 (* iteration is only allowed on context code, the intuition vaguely being
89 that there is no way to replace something more than once. Actually,
90 allowing iterated additions on minus code would cause problems with some
91 heuristics for adding braces, because one couldn't identify simple
92 replacements with certainty. Anyway, iteration doesn't seem to be needed
93 on - code for the moment. Although it may be confusing that there can be
94 iterated addition of code before context code where the context code is
95 immediately followed by removed code. *)
97 MINUS
of pos
* int list
* int * anything list list
98 | CONTEXT
of pos
* anything befaft
100 and count
= ONE
(* + *) | MANY
(* ++ *)
102 Real
of int (* charpos *) | Virt
of int * int (* charpos + offset *)
103 and pos
= NoPos
| DontCarePos
| FixPos
of (fixpos
* fixpos
)
107 | AddingBetweenDots
of statement
* int (*index of let var*)
108 | DroppingBetweenDots
of statement
* int (*index of let var*)
110 and inherited
= Type_cocci.inherited
111 and keep_binding
= Type_cocci.keep_binding
112 and multi
= bool (*true if a nest is one or more, false if it is zero or more*)
115 meta_name list
(*free vars*) * (meta_name
* seed
) list
(*fresh*) *
116 meta_name list
(*inherited vars*) * mcodekind
118 (* --------------------------------------------------------------------- *)
121 and arity
= UNIQUE
| OPT
| MULTI
| NONE
124 MetaIdDecl
of arity
* meta_name
(* name *)
125 | MetaFreshIdDecl
of meta_name
(* name *) * seed
(* seed *)
126 | MetaTypeDecl
of arity
* meta_name
(* name *)
127 | MetaInitDecl
of arity
* meta_name
(* name *)
128 | MetaListlenDecl
of meta_name
(* name *)
129 | MetaParamDecl
of arity
* meta_name
(* name *)
130 | MetaParamListDecl
of arity
* meta_name
(*name*) * list_len
(*len*)
132 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
133 | MetaErrDecl
of arity
* meta_name
(* name *)
135 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
137 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
138 | MetaLocalIdExpDecl
of
139 arity
* meta_name
(* name *) * Type_cocci.typeC list
option
140 | MetaExpListDecl
of arity
* meta_name
(*name*) * list_len
(*len*)
141 | MetaDeclDecl
of arity
* meta_name
(* name *)
142 | MetaFieldDecl
of arity
* meta_name
(* name *)
143 | MetaStmDecl
of arity
* meta_name
(* name *)
144 | MetaStmListDecl
of arity
* meta_name
(* name *)
145 | MetaFuncDecl
of arity
* meta_name
(* name *)
146 | MetaLocalFuncDecl
of arity
* meta_name
(* name *)
147 | MetaPosDecl
of arity
* meta_name
(* name *)
148 | MetaDeclarerDecl
of arity
* meta_name
(* name *)
149 | MetaIteratorDecl
of arity
* meta_name
(* name *)
151 and list_len
= AnyLen
| MetaLen
of meta_name
| CstLen
of int
153 and seed
= NoVal
| StringSeed
of string | ListSeed
of seed_elem list
154 and seed_elem
= SeedString
of string | SeedId
of meta_name
156 (* --------------------------------------------------------------------- *)
157 (* --------------------------------------------------------------------- *)
165 and 'a dots
= 'a base_dots wrap
167 (* --------------------------------------------------------------------- *)
172 | MetaId
of meta_name mcode
* idconstraint
* keep_binding
* inherited
173 | MetaFunc
of meta_name mcode
* idconstraint
* keep_binding
* inherited
174 | MetaLocalFunc
of meta_name mcode
* idconstraint
* keep_binding
* inherited
177 | UniqueIdent
of ident
179 and ident
= base_ident wrap
181 (* --------------------------------------------------------------------- *)
184 and base_expression
=
186 | Constant
of constant mcode
187 | FunCall
of expression
* string mcode
(* ( *) *
188 expression dots
* string mcode
(* ) *)
189 | Assignment
of expression
* assignOp mcode
* expression
*
190 bool (* true if it can match an initialization *)
191 | CondExpr
of expression
* string mcode
(* ? *) * expression
option *
192 string mcode
(* : *) * expression
193 | Postfix
of expression
* fixOp mcode
194 | Infix
of expression
* fixOp mcode
195 | Unary
of expression
* unaryOp mcode
196 | Binary
of expression
* binaryOp mcode
* expression
197 | Nested
of expression
* binaryOp mcode
* expression
198 | ArrayAccess
of expression
* string mcode
(* [ *) * expression
*
200 | RecordAccess
of expression
* string mcode
(* . *) * ident
201 | RecordPtAccess
of expression
* string mcode
(* -> *) * ident
202 | Cast
of string mcode
(* ( *) * fullType
* string mcode
(* ) *) *
204 | SizeOfExpr
of string mcode
(* sizeof *) * expression
205 | SizeOfType
of string mcode
(* sizeof *) * string mcode
(* ( *) *
206 fullType
* string mcode
(* ) *)
207 | TypeExp
of fullType
(*type name used as an expression, only in
210 | Paren
of string mcode
(* ( *) * expression
*
213 | MetaErr
of meta_name mcode
* constraints
* keep_binding
*
215 | MetaExpr
of meta_name mcode
* constraints
* keep_binding
*
216 Type_cocci.typeC list
option * form
* inherited
217 | MetaExprList
of meta_name mcode
* listlen
* keep_binding
*
218 inherited
(* only in arg lists *)
220 | EComma
of string mcode
(* only in arg lists *)
222 | DisjExpr
of expression list
223 | NestExpr
of string mcode
(* <.../<+... *) *
225 string mcode
(* ...>/...+> *) *
226 expression
option * multi
228 (* can appear in arg lists, and also inside Nest, as in:
229 if(< ... X ... Y ...>)
230 In the following, the expression option is the WHEN *)
231 | Edots
of string mcode
(* ... *) * expression
option
232 | Ecircles
of string mcode
(* ooo *) * expression
option
233 | Estars
of string mcode
(* *** *) * expression
option
235 | OptExp
of expression
236 | UniqueExp
of expression
240 | NotIdCstrt
of reconstraint
241 | NotExpCstrt
of expression list
242 | SubExpCstrt
of meta_name list
244 (* Constraints on Meta-* Identifiers, Functions *)
247 | IdNegIdSet
of string list
* meta_name list
248 | IdRegExpConstraint
of reconstraint
251 | IdRegExp
of string * Str.regexp
252 | IdNotRegExp
of string * Str.regexp
254 (* ANY = int E; ID = idexpression int X; CONST = constant int X; *)
255 and form
= ANY
| ID
| LocalID
| CONST
(* form for MetaExp *)
257 and expression
= base_expression wrap
260 MetaListLen
of meta_name mcode
* keep_binding
* inherited
264 and unaryOp
= GetRef
| DeRef
| UnPlus
| UnMinus
| Tilde
| Not
265 and assignOp
= SimpleAssign
| OpAssign
of arithOp
266 and fixOp
= Dec
| Inc
268 and binaryOp
= Arith
of arithOp
| Logical
of logicalOp
270 Plus
| Minus
| Mul
| Div
| Mod
| DecLeft
| DecRight
| And
| Or
| Xor
271 and logicalOp
= Inf
| Sup
| InfEq
| SupEq
| Eq
| NotEq
| AndLog
| OrLog
279 (* --------------------------------------------------------------------- *)
283 Type
of const_vol mcode
option * typeC
284 | DisjType
of fullType list
(* only after iso *)
285 | OptType
of fullType
286 | UniqueType
of fullType
289 BaseType
of baseType
* string mcode list
(* Yoann style *)
290 | SignedT
of sign mcode
* typeC
option
291 | Pointer
of fullType
* string mcode
(* * *)
292 | FunctionPointer
of fullType
*
293 string mcode
(* ( *)*string mcode
(* * *)*string mcode
(* ) *)*
294 string mcode
(* ( *)*parameter_list
*string mcode
(* ) *)
296 (* used for the automatic managment of prototypes *)
297 | FunctionType
of bool (* true if all minus for dropping return type *) *
299 string mcode
(* ( *) * parameter_list
*
302 | Array
of fullType
* string mcode
(* [ *) *
303 expression
option * string mcode
(* ] *)
304 | EnumName
of string mcode
(*enum*) * ident
option (* name *)
305 | EnumDef
of fullType
(* either EnumName or metavar *) *
306 string mcode
(* { *) * expression dots
* string mcode
(* } *)
307 | StructUnionName
of structUnion mcode
* ident
option (* name *)
308 | StructUnionDef
of fullType
(* either StructUnionName or metavar *) *
309 string mcode
(* { *) * declaration dots
* string mcode
(* } *)
310 | TypeName
of string mcode
(* pad: should be 'of ident' ? *)
312 | MetaType
of meta_name mcode
* keep_binding
* inherited
314 and fullType
= base_fullType wrap
315 and typeC
= base_typeC wrap
317 and baseType
= VoidType
| CharType
| ShortType
| IntType
| DoubleType
318 | FloatType
| LongType
| LongLongType
| SizeType
| SSizeType
| PtrDiffType
320 and structUnion
= Struct
| Union
322 and sign
= Signed
| Unsigned
324 and const_vol
= Const
| Volatile
326 (* --------------------------------------------------------------------- *)
327 (* Variable declaration *)
328 (* Even if the Cocci program specifies a list of declarations, they are
329 split out into multiple declarations of a single variable each. *)
331 and base_declaration
=
332 Init
of storage mcode
option * fullType
* ident
* string mcode
(*=*) *
333 initialiser
* string mcode
(*;*)
334 | UnInit
of storage mcode
option * fullType
* ident
* string mcode
(* ; *)
335 | TyDecl
of fullType
* string mcode
(* ; *)
336 | MacroDecl
of ident
(* name *) * string mcode
(* ( *) *
337 expression dots
* string mcode
(* ) *) * string mcode
(* ; *)
338 | Typedef
of string mcode
(*typedef*) * fullType
*
339 typeC
(* either TypeName or metavar *) * string mcode
(*;*)
340 | DisjDecl
of declaration list
341 (* Ddots is for a structure declaration *)
342 | Ddots
of string mcode
(* ... *) * declaration
option (* whencode *)
344 | MetaDecl
of meta_name mcode
* keep_binding
* inherited
345 | MetaField
of meta_name mcode
* keep_binding
* inherited
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 | InitExpr
of expression
358 | ArInitList
of string mcode
(*{*) * initialiser dots
* string mcode
(*}*)
359 | StrInitList
of bool (* true if all are - *) *
360 string mcode
(*{*) * initialiser list
* string mcode
(*}*) *
361 initialiser list
(* whencode: elements that shouldn't appear in init *)
363 designator list
(* name *) * string mcode
(*=*) *
364 initialiser
(* gccext: *)
365 | InitGccName
of ident
(* name *) * string mcode
(*:*) *
367 | IComma
of string mcode
(* , *)
368 | Idots
of string mcode
(* ... *) * initialiser
option (* whencode *)
370 | OptIni
of initialiser
371 | UniqueIni
of initialiser
374 DesignatorField
of string mcode
(* . *) * ident
375 | DesignatorIndex
of string mcode
(* [ *) * expression
* string mcode
(* ] *)
377 string mcode
(* [ *) * expression
* string mcode
(* ... *) *
378 expression
* string mcode
(* ] *)
380 and initialiser
= base_initialiser wrap
382 (* --------------------------------------------------------------------- *)
385 and base_parameterTypeDef
=
386 VoidParam
of fullType
387 | Param
of fullType
* ident
option
389 | MetaParam
of meta_name mcode
* keep_binding
* inherited
390 | MetaParamList
of meta_name mcode
* listlen
* keep_binding
* inherited
392 | PComma
of string mcode
394 | Pdots
of string mcode
(* ... *)
395 | Pcircles
of string mcode
(* ooo *)
397 | OptParam
of parameterTypeDef
398 | UniqueParam
of parameterTypeDef
400 and parameterTypeDef
= base_parameterTypeDef wrap
402 and parameter_list
= parameterTypeDef dots
404 (* --------------------------------------------------------------------- *)
405 (* #define Parameters *)
407 and base_define_param
=
409 | DPComma
of string mcode
410 | DPdots
of string mcode
(* ... *)
411 | DPcircles
of string mcode
(* ooo *)
412 | OptDParam
of define_param
413 | UniqueDParam
of define_param
415 and define_param
= base_define_param wrap
417 and base_define_parameters
=
418 NoParams
(* not parameter list, not an empty one *)
419 | DParams
of string mcode
(*( *) * define_param dots
* string mcode
(* )*)
421 and define_parameters
= base_define_parameters wrap
423 (* --------------------------------------------------------------------- *)
426 (* PER = keep bindings separate, ALL = collect them *)
427 and meta_collect
= PER
| ALL
430 MetaPos
of meta_name mcode
* meta_name list
*
431 meta_collect
* keep_binding
* inherited
434 (* --------------------------------------------------------------------- *)
435 (* Function declaration *)
437 and storage
= Static
| Auto
| Register
| Extern
439 (* --------------------------------------------------------------------- *)
443 FunHeader
of mcodekind
(* before the function header *) *
444 bool (* true if all minus, for dropping static, etc *) *
445 fninfo list
* ident
(* name *) *
446 string mcode
(* ( *) * parameter_list
*
448 | Decl
of mcodekind
(* before the decl *) *
449 bool (* true if all minus *) * declaration
451 | SeqStart
of string mcode
(* { *)
452 | SeqEnd
of string mcode
(* } *)
454 | ExprStatement
of expression
* string mcode
(*;*)
455 | IfHeader
of string mcode
(* if *) * string mcode
(* ( *) *
456 expression
* string mcode
(* ) *)
457 | Else
of string mcode
(* else *)
458 | WhileHeader
of string mcode
(* while *) * string mcode
(* ( *) *
459 expression
* string mcode
(* ) *)
460 | DoHeader
of string mcode
(* do *)
461 | WhileTail
of string mcode
(* while *) * string mcode
(* ( *) *
462 expression
* string mcode
(* ) *) *
464 | ForHeader
of string mcode
(* for *) * string mcode
(* ( *) *
465 expression
option * string mcode
(*;*) *
466 expression
option * string mcode
(*;*) *
467 expression
option * string mcode
(* ) *)
468 | IteratorHeader
of ident
(* name *) * string mcode
(* ( *) *
469 expression dots
* string mcode
(* ) *)
470 | SwitchHeader
of string mcode
(* switch *) * string mcode
(* ( *) *
471 expression
* string mcode
(* ) *)
472 | Break
of string mcode
(* break *) * string mcode
(* ; *)
473 | Continue
of string mcode
(* continue *) * string mcode
(* ; *)
474 | Label
of ident
* string mcode
(* : *)
475 | Goto
of string mcode
(* goto *) * ident
* string mcode
(* ; *)
476 | Return
of string mcode
(* return *) * string mcode
(* ; *)
477 | ReturnExpr
of string mcode
(* return *) * expression
*
480 | MetaRuleElem
of meta_name mcode
* keep_binding
* inherited
481 | MetaStmt
of meta_name mcode
* keep_binding
* metaStmtInfo
*
483 | MetaStmtList
of meta_name mcode
* keep_binding
* inherited
485 | Exp
of expression
(* matches a subterm *)
486 | TopExp
of expression
(* for macros body, exp at top level,
488 | Ty
of fullType
(* only at SP top level, matches a subterm *)
489 | TopInit
of initialiser
(* only at top level *)
490 | Include
of string mcode
(*#include*) * inc_file mcode
(*file *)
491 | DefineHeader
of string mcode
(* #define *) * ident
(* name *) *
492 define_parameters
(*params*)
493 | Case
of string mcode
(* case *) * expression
* string mcode
(*:*)
494 | Default
of string mcode
(* default *) * string mcode
(*:*)
495 | DisjRuleElem
of rule_elem list
498 FStorage
of storage mcode
500 | FInline
of string mcode
501 | FAttr
of string mcode
504 NotSequencible
| SequencibleAfterDots
of dots_whencode list
| Sequencible
506 and rule_elem
= base_rule_elem wrap
509 Seq
of rule_elem
(* { *) *
510 statement dots
* rule_elem
(* } *)
511 | IfThen
of rule_elem
(* header *) * statement
* end_info
(* endif *)
512 | IfThenElse
of rule_elem
(* header *) * statement
*
513 rule_elem
(* else *) * statement
* end_info
(* endif *)
514 | While
of rule_elem
(* header *) * statement
* end_info
(*endwhile*)
515 | Do
of rule_elem
(* do *) * statement
* rule_elem
(* tail *)
516 | For
of rule_elem
(* header *) * statement
* end_info
(*endfor*)
517 | Iterator
of rule_elem
(* header *) * statement
* end_info
(*enditer*)
518 | Switch
of rule_elem
(* header *) * rule_elem
(* { *) *
519 statement
(*decl*) dots
* case_line list
* rule_elem
(*}*)
520 | Atomic
of rule_elem
521 | Disj
of statement dots list
522 | Nest
of string mcode
(* <.../<+... *) * statement dots
*
523 string mcode
(* ...>/...+> *) *
524 (statement dots
,statement
) whencode list
* multi
*
525 dots_whencode list
* dots_whencode list
526 | FunDecl
of rule_elem
(* header *) * rule_elem
(* { *) *
527 statement dots
* rule_elem
(* } *)
528 | Define
of rule_elem
(* header *) * statement dots
529 | Dots
of string mcode
(* ... *) *
530 (statement dots
,statement
) whencode list
*
531 dots_whencode list
* dots_whencode list
532 | Circles
of string mcode
(* ooo *) *
533 (statement dots
,statement
) whencode list
*
534 dots_whencode list
* dots_whencode list
535 | Stars
of string mcode
(* *** *) *
536 (statement dots
,statement
) whencode list
*
537 dots_whencode list
* dots_whencode list
538 | OptStm
of statement
539 | UniqueStm
of statement
541 and ('a
,'b
) whencode
=
544 | WhenModifier
of when_modifier
545 | WhenNotTrue
of rule_elem
(* useful for fvs *)
546 | WhenNotFalse
of rule_elem
549 (* The following removes the shortest path constraint. It can be used
550 with other when modifiers *)
552 (* The following removes the special consideration of error paths. It
553 can be used with other when modifiers *)
558 (* only used with asttoctl *)
560 WParen
of rule_elem
* meta_name
(*pren_var*)
562 | Other_dots
of statement dots
564 and statement
= base_statement wrap
567 CaseLine
of rule_elem
(* case/default header *) * statement dots
568 | OptCase
of case_line
570 and case_line
= base_case_line wrap
573 Local
of inc_elem list
574 | NonLocal
of inc_elem list
582 | CODE
of statement dots
583 | FILEINFO
of string mcode
(* old file *) * string mcode
(* new file *)
584 | ERRORWORDS
of expression list
586 and top_level
= base_top_level wrap
589 CocciRulename
of string option * dependency
*
590 string list
* string list
* exists
* bool
591 | GeneratedRulename
of string option * dependency
*
592 string list
* string list
* exists
* bool
593 | ScriptRulename
of string option (* name *) * string (* language *) *
595 | InitialScriptRulename
of string option (* name *) * string (* language *) *
597 | FinalScriptRulename
of string option (* name *) * string (* language *) *
600 and ruletype
= Normal
| Generated
603 CocciRule
of string (* name *) *
604 (dependency
* string list
(* dropped isos *) * exists
) * top_level list
605 * bool list
* ruletype
606 | ScriptRule
of string (* name *) *
607 (* metaname for python (untyped), metavar for ocaml (typed) *)
608 string * dependency
*
609 (script_meta_name
* meta_name
* metavar
) list
(*inherited vars*) *
610 meta_name list
(*script vars*) * string
611 | InitialScriptRule
of string (* name *) *
612 string (*language*) * dependency
* string (*code*)
613 | FinalScriptRule
of string (* name *) *
614 string (*language*) * dependency
* string (*code*)
616 and script_meta_name
= string option (*string*) * string option (*ast*)
619 Dep
of string (* rule applies for the current binding *)
620 | AntiDep
of string (* rule doesn't apply for the current binding *)
621 | EverDep
of string (* rule applies for some binding *)
622 | NeverDep
of string (* rule never applies for any binding *)
623 | AndDep
of dependency
* dependency
624 | OrDep
of dependency
* dependency
627 and rule_with_metavars
= metavar list
* rule
630 FullTypeTag
of fullType
631 | BaseTypeTag
of baseType
632 | StructUnionTag
of structUnion
635 | ExpressionTag
of expression
636 | ConstantTag
of constant
637 | UnaryOpTag
of unaryOp
638 | AssignOpTag
of assignOp
640 | BinaryOpTag
of binaryOp
641 | ArithOpTag
of arithOp
642 | LogicalOpTag
of logicalOp
643 | DeclarationTag
of declaration
644 | InitTag
of initialiser
645 | StorageTag
of storage
646 | IncFileTag
of inc_file
647 | Rule_elemTag
of rule_elem
648 | StatementTag
of statement
649 | CaseLineTag
of case_line
650 | ConstVolTag
of const_vol
651 | Token
of string * info
option
652 | Pragma
of added_string list
654 | ExprDotsTag
of expression dots
655 | ParamDotsTag
of parameterTypeDef dots
656 | StmtDotsTag
of statement dots
657 | DeclDotsTag
of declaration dots
659 | ParamTag
of parameterTypeDef
660 | SgrepStartTag
of string
661 | SgrepEndTag
of string
663 (* --------------------------------------------------------------------- *)
665 and exists
= Exists
| Forall
| Undetermined
666 (* | ReverseForall - idea: look back on all flow paths; not implemented *)
668 (* --------------------------------------------------------------------- *)
670 let mkToken x
= Token
(x
,None
)
672 (* --------------------------------------------------------------------- *)
674 let lub_count i1 i2
=
679 (* --------------------------------------------------------------------- *)
681 let rewrap model x
= {model
with node
= x
}
682 let rewrap_mcode (_
,a
,b
,c
) x
= (x
,a
,b
,c
)
683 let unwrap x
= x
.node
684 let unwrap_mcode (x
,_
,_
,_
) = x
685 let get_mcodekind (_
,_
,x
,_
) = x
686 let get_line x
= x
.node_line
687 let get_mcode_line (_
,l
,_
,_
) = l
.line
688 let get_mcode_col (_
,l
,_
,_
) = l
.column
689 let get_fvs x
= x
.free_vars
690 let set_fvs fvs x
= {x
with free_vars
= fvs
}
691 let get_mfvs x
= x
.minus_free_vars
692 let set_mfvs mfvs x
= {x
with minus_free_vars
= mfvs
}
693 let get_fresh x
= x
.fresh_vars
694 let get_inherited x
= x
.inherited
695 let get_saved x
= x
.saved_witness
696 let get_dots_bef_aft x
= x
.bef_aft
697 let set_dots_bef_aft d x
= {x
with bef_aft
= d
}
698 let get_pos x
= x
.pos_info
699 let set_pos x pos
= {x
with pos_info
= pos
}
700 let get_test_exp x
= x
.true_if_test_exp
701 let set_test_exp x
= {x
with true_if_test_exp
= true}
702 let get_isos x
= x
.iso_info
703 let set_isos x isos
= {x
with iso_info
= isos
}
704 let get_pos_var (_
,_
,_
,p
) = p
705 let set_pos_var vr
(a
,b
,c
,_
) = (a
,b
,c
,vr
)
706 let drop_pos (a
,b
,c
,_
) = (a
,b
,c
,NoMetaPos
)
708 let get_wcfvs (whencode
: ('a wrap
, 'b wrap
) whencode list
) =
712 WhenNot
(a
) -> get_fvs a
713 | WhenAlways
(a
) -> get_fvs a
714 | WhenModifier
(_
) -> []
715 | WhenNotTrue
(e
) -> get_fvs e
716 | WhenNotFalse
(e
) -> get_fvs e
)
719 (* --------------------------------------------------------------------- *)
721 let get_meta_name = function
722 MetaIdDecl
(ar
,nm
) -> nm
723 | MetaFreshIdDecl
(nm
,seed
) -> nm
724 | MetaTypeDecl
(ar
,nm
) -> nm
725 | MetaInitDecl
(ar
,nm
) -> nm
726 | MetaListlenDecl
(nm
) -> nm
727 | MetaParamDecl
(ar
,nm
) -> nm
728 | MetaParamListDecl
(ar
,nm
,nm1
) -> nm
729 | MetaConstDecl
(ar
,nm
,ty
) -> nm
730 | MetaErrDecl
(ar
,nm
) -> nm
731 | MetaExpDecl
(ar
,nm
,ty
) -> nm
732 | MetaIdExpDecl
(ar
,nm
,ty
) -> nm
733 | MetaLocalIdExpDecl
(ar
,nm
,ty
) -> nm
734 | MetaExpListDecl
(ar
,nm
,nm1
) -> nm
735 | MetaDeclDecl
(ar
,nm
) -> nm
736 | MetaFieldDecl
(ar
,nm
) -> nm
737 | MetaStmDecl
(ar
,nm
) -> nm
738 | MetaStmListDecl
(ar
,nm
) -> nm
739 | MetaFuncDecl
(ar
,nm
) -> nm
740 | MetaLocalFuncDecl
(ar
,nm
) -> nm
741 | MetaPosDecl
(ar
,nm
) -> nm
742 | MetaDeclarerDecl
(ar
,nm
) -> nm
743 | MetaIteratorDecl
(ar
,nm
) -> nm
745 (* --------------------------------------------------------------------- *)
748 FullTypeTag _
-> "FullTypeTag"
749 | BaseTypeTag _
-> "BaseTypeTag"
750 | StructUnionTag _
-> "StructUnionTag"
751 | SignTag _
-> "SignTag"
752 | IdentTag _
-> "IdentTag"
753 | ExpressionTag _
-> "ExpressionTag"
754 | ConstantTag _
-> "ConstantTag"
755 | UnaryOpTag _
-> "UnaryOpTag"
756 | AssignOpTag _
-> "AssignOpTag"
757 | FixOpTag _
-> "FixOpTag"
758 | BinaryOpTag _
-> "BinaryOpTag"
759 | ArithOpTag _
-> "ArithOpTag"
760 | LogicalOpTag _
-> "LogicalOpTag"
761 | DeclarationTag _
-> "DeclarationTag"
762 | InitTag _
-> "InitTag"
763 | StorageTag _
-> "StorageTag"
764 | IncFileTag _
-> "IncFileTag"
765 | Rule_elemTag _
-> "Rule_elemTag"
766 | StatementTag _
-> "StatementTag"
767 | CaseLineTag _
-> "CaseLineTag"
768 | ConstVolTag _
-> "ConstVolTag"
770 | Pragma _
-> "Pragma"
772 | ExprDotsTag _
-> "ExprDotsTag"
773 | ParamDotsTag _
-> "ParamDotsTag"
774 | StmtDotsTag _
-> "StmtDotsTag"
775 | DeclDotsTag _
-> "DeclDotsTag"
776 | TypeCTag _
-> "TypeCTag"
777 | ParamTag _
-> "ParamTag"
778 | SgrepStartTag _
-> "SgrepStartTag"
779 | SgrepEndTag _
-> "SgrepEndTag"
781 (* --------------------------------------------------------------------- *)
783 let no_info = { line
= 0; column
= -1; strbef
= []; straft
= [] }
789 minus_free_vars
= [];
795 true_if_test_exp
= false;
798 let make_meta_rule_elem s d
(fvs
,fresh
,inh
) =
801 (MetaRuleElem
(((rule,s
),no_info,d
,NoMetaPos
),Type_cocci.Unitary
,false)))
802 with free_vars
= fvs
; fresh_vars
= fresh
; inherited
= inh
}
804 let make_meta_decl s d
(fvs
,fresh
,inh
) =
807 (MetaDecl
(((rule,s
),no_info,d
,NoMetaPos
),Type_cocci.Unitary
,false))) with
808 free_vars
= fvs
; fresh_vars
= fresh
; inherited
= inh
}
810 let make_mcode x
= (x
,no_info,CONTEXT
(NoPos
,NOTHING
),NoMetaPos
)
812 (* --------------------------------------------------------------------- *)
814 let equal_pos x y
= x
= y
816 (* --------------------------------------------------------------------- *)