Version 1.0.0-rc17 has been released. Some changes are:
[bpt/coccinelle.git] / parsing_cocci / ast0_cocci.mli
index bd78144..0b51ee7 100644 (file)
@@ -1,3 +1,30 @@
+(*
+ * Copyright 2012, INRIA
+ * Julia Lawall, Gilles Muller
+ * Copyright 2010-2011, INRIA, University of Copenhagen
+ * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
+ * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
+ * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
+ * This file is part of Coccinelle.
+ *
+ * Coccinelle is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, according to version 2 of the License.
+ *
+ * Coccinelle is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Coccinelle.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The authors reserve the right to distribute this or future versions of
+ * Coccinelle under other licenses.
+ *)
+
+
+# 0 "./ast0_cocci.mli"
 (* --------------------------------------------------------------------- *)
 (* Modified code *)
 
@@ -9,8 +36,8 @@ type token_info =
 val default_token_info : token_info
 
 type mcodekind =
-    MINUS       of (Ast_cocci.anything list list * token_info) ref
-  | PLUS
+    MINUS       of (Ast_cocci.anything Ast_cocci.replacement * token_info) ref
+  | PLUS        of Ast_cocci.count
   | CONTEXT     of (Ast_cocci.anything Ast_cocci.befaft *
                      token_info * token_info) ref
   | MIXED       of (Ast_cocci.anything Ast_cocci.befaft *
@@ -24,10 +51,18 @@ type info = { pos_info : position_info;
              attachable_start : bool; attachable_end : bool;
              mcode_start : mcodekind list; mcode_end : mcodekind list;
              (* the following are only for + code *)
-             strings_before : (string * position_info) list;
-             strings_after : (string * position_info) list }
+             strings_before : (Ast_cocci.added_string * position_info) list;
+             strings_after : (Ast_cocci.added_string * position_info) list;
+             isSymbolIdent : bool; (* is the token a symbol identifier or not *) }
+
+type adjacency = int
+
+type fake_mcode = info * mcodekind * adjacency
+
+type 'a mcode =
+    'a * arity * info * mcodekind * anything list ref (* pos, - only *) *
+      adjacency (* adjacency_index *)
 
-type 'a mcode = 'a * arity * info * mcodekind * meta_pos ref (* pos, - only *)
 and 'a wrap =
     { node : 'a;
       info : info;
@@ -65,10 +100,14 @@ and 'a dots = 'a base_dots wrap
 (* Identifier *)
 
 and base_ident =
-    Id of string mcode
-  | MetaId        of Ast_cocci.meta_name mcode * ident list * pure
-  | MetaFunc      of Ast_cocci.meta_name mcode * ident list * pure
-  | MetaLocalFunc of Ast_cocci.meta_name mcode * ident list * pure
+    Id            of string mcode
+  | MetaId        of Ast_cocci.meta_name mcode * Ast_cocci.idconstraint *
+       Ast_cocci.seed * pure
+  | MetaFunc      of Ast_cocci.meta_name mcode * Ast_cocci.idconstraint * pure
+  | MetaLocalFunc of Ast_cocci.meta_name mcode * Ast_cocci.idconstraint * pure
+  | AsIdent       of ident * ident (* as ident, always metavar *)
+  | DisjId        of string mcode * ident list *
+                     string mcode list (* the |s *) * string mcode
   | OptIdent      of ident
   | UniqueIdent   of ident
 
@@ -84,6 +123,7 @@ and base_expression =
                       expression dots * string mcode (* ) *)
   | Assignment     of expression * Ast_cocci.assignOp mcode * expression *
                      bool (* true if it can match an initialization *)
+  | Sequence       of expression * string mcode (* , *) * expression
   | CondExpr       of expression * string mcode (* ? *) * expression option *
                      string mcode (* : *) * expression
   | Postfix        of expression * Ast_cocci.fixOp mcode
@@ -103,11 +143,14 @@ and base_expression =
   | SizeOfType     of string mcode (* sizeof *) * string mcode (* ( *) *
                       typeC * string mcode (* ) *)
   | TypeExp        of typeC
-  | MetaErr        of Ast_cocci.meta_name mcode * expression list * pure
-  | MetaExpr       of Ast_cocci.meta_name mcode * expression list *
+  | Constructor    of string mcode (* ( *) * typeC * string mcode (* ) *) *
+                     initialiser
+  | MetaErr        of Ast_cocci.meta_name mcode * constraints * pure
+  | MetaExpr       of Ast_cocci.meta_name mcode * constraints *
                      Type_cocci.typeC list option * Ast_cocci.form * pure
   | MetaExprList   of Ast_cocci.meta_name mcode (* only in arglists *) *
                      listlen * pure
+  | AsExpr         of expression * expression (* as expr, always metavar *)
   | EComma         of string mcode (* only in arglists *)
   | DisjExpr       of string mcode * expression list * string mcode list *
                      string mcode
@@ -121,7 +164,16 @@ and base_expression =
 
 and expression = base_expression wrap
 
-and listlen = Ast_cocci.meta_name mcode option
+and constraints =
+    NoConstraint
+  | NotIdCstrt     of Ast_cocci.reconstraint
+  | NotExpCstrt    of expression list
+  | SubExpCstrt    of Ast_cocci.meta_name list
+
+and listlen =
+    MetaListLen of Ast_cocci.meta_name mcode
+  | CstListLen of int
+  | AnyListLen
 
 (* --------------------------------------------------------------------- *)
 (* Types *)
@@ -139,12 +191,15 @@ and base_typeC =
                        string mcode (* ) *)
   | Array           of typeC * string mcode (* [ *) *
                       expression option * string mcode (* ] *)
-  | EnumName        of string mcode (*enum*) * ident (* name *)
+  | EnumName        of string mcode (*enum*) * ident option (* name *)
+  | EnumDef  of typeC (* either StructUnionName or metavar *) *
+       string mcode (* { *) * expression dots * string mcode (* } *)
   | StructUnionName of Ast_cocci.structUnion mcode * ident option (* name *)
   | StructUnionDef  of typeC (* either StructUnionName or metavar *) *
        string mcode (* { *) * declaration dots * string mcode (* } *)
   | TypeName        of string mcode
   | MetaType        of Ast_cocci.meta_name mcode * pure
+  | AsType          of typeC * typeC (* as type, always metavar *)
   | DisjType        of string mcode * typeC list * (* only after iso *)
                        string mcode list (* the |s *)  * string mcode
   | OptType         of typeC
@@ -158,13 +213,20 @@ and typeC = base_typeC wrap
    split out into multiple declarations of a single variable each. *)
 
 and base_declaration =
-    Init       of Ast_cocci.storage mcode option * typeC * ident *
+    MetaDecl   of Ast_cocci.meta_name mcode * pure (* variables *)
+  | MetaField  of Ast_cocci.meta_name mcode * pure (* structure fields *)
+  | MetaFieldList of Ast_cocci.meta_name mcode * listlen * pure
+  | AsDecl        of declaration * declaration
+  | Init       of Ast_cocci.storage mcode option * typeC * ident *
        string mcode (*=*) * initialiser * string mcode (*;*)
   | UnInit     of Ast_cocci.storage mcode option * typeC * ident *
        string mcode (* ; *)
   | TyDecl of typeC * string mcode (* ; *)
   | MacroDecl of ident (* name *) * string mcode (* ( *) *
         expression dots * string mcode (* ) *) * string mcode (* ; *)
+  | MacroDeclInit of ident (* name *) * string mcode (* ( *) *
+        expression dots * string mcode (* ) *) * string mcode (*=*) *
+        initialiser * string mcode (* ; *)
   | Typedef of string mcode (* typedef *) * typeC * typeC * string mcode (*;*)
   | DisjDecl   of string mcode * declaration list * string mcode list *
                  string mcode
@@ -179,8 +241,11 @@ and declaration = base_declaration wrap
 
 and base_initialiser =
     MetaInit of Ast_cocci.meta_name mcode * pure
+  | MetaInitList of Ast_cocci.meta_name mcode * listlen * pure
+  | AsInit of initialiser * initialiser (* as init, always metavar *)
   | InitExpr of expression
-  | InitList of string mcode (*{*) * initialiser_list * string mcode (*}*)
+  | InitList of string mcode (*{*) * initialiser_list * string mcode (*}*) *
+       bool (* true if ordered, false if unordered *)
   | InitGccExt of
       designator list (* name *) * string mcode (*=*) *
        initialiser (* gccext: *)
@@ -210,6 +275,7 @@ and base_parameterTypeDef =
   | Param         of typeC * ident option
   | MetaParam     of Ast_cocci.meta_name mcode * pure
   | MetaParamList of Ast_cocci.meta_name mcode * listlen * pure
+  | AsParam       of parameterTypeDef * expression (* expr, always metavar *)
   | PComma        of string mcode
   | Pdots         of string mcode (* ... *)
   | Pcircles      of string mcode (* ooo *)
@@ -246,31 +312,31 @@ and base_statement =
     Decl          of (info * mcodekind) (* before the decl *) * declaration
   | Seq           of string mcode (* { *) * statement dots *
                     string mcode (* } *)
-  | ExprStatement of expression * string mcode (*;*)
+  | ExprStatement of expression option * string mcode (*;*)
   | IfThen        of string mcode (* if *) * string mcode (* ( *) *
                     expression * string mcode (* ) *) *
-                    statement * (info * mcodekind)
+                    statement * fake_mcode (* after info *)
   | IfThenElse    of string mcode (* if *) * string mcode (* ( *) *
                     expression * string mcode (* ) *) *
                     statement * string mcode (* else *) * statement *
-                    (info * mcodekind)
+                    fake_mcode (* after info *)
   | While         of string mcode (* while *) * string mcode (* ( *) *
                     expression * string mcode (* ) *) *
-                    statement * (info * mcodekind) (* after info *)
+                    statement * fake_mcode (* after info *)
   | Do            of string mcode (* do *) * statement *
                      string mcode (* while *) * string mcode (* ( *) *
                     expression * string mcode (* ) *) *
                      string mcode (* ; *)
-  | For           of string mcode (* for *) * string mcode (* ( *) *
-                     expression option * string mcode (*;*) *
+  | For           of string mcode (* for *) * string mcode (* ( *) * forinfo *
                     expression option * string mcode (*;*) *
                      expression option * string mcode (* ) *) * statement *
-                    (info * mcodekind) (* after info *)
+                    fake_mcode (* after info *)
   | Iterator      of ident (* name *) * string mcode (* ( *) *
                     expression dots * string mcode (* ) *) *
-                    statement * (info * mcodekind) (* after info *)
+                    statement * fake_mcode (* after info *)
   | Switch        of string mcode (* switch *) * string mcode (* ( *) *
                     expression * string mcode (* ) *) * string mcode (* { *) *
+                    statement (*decl*) dots *
                     case_line dots * string mcode (* } *)
   | Break         of string mcode (* break *) * string mcode (* ; *)
   | Continue      of string mcode (* continue *) * string mcode (* ; *)
@@ -282,6 +348,7 @@ and base_statement =
   | MetaStmt      of Ast_cocci.meta_name mcode * pure
   | MetaStmtList  of Ast_cocci.meta_name mcode (*only in statement lists*) *
                     pure
+  | AsStmt        of statement * statement (* as statement, always metavar *)
   | Exp           of expression  (* only in dotted statement lists *)
   | TopExp        of expression (* for macros body *)
   | Ty            of typeC (* only at top level *)
@@ -302,11 +369,18 @@ and base_statement =
        string mcode (* { *) * statement dots *
        string mcode (* } *)
   | Include of string mcode (* #include *) * Ast_cocci.inc_file mcode(* file *)
+  | Undef of string mcode (* #define *) * ident (* name *)
   | Define of string mcode (* #define *) * ident (* name *) *
        define_parameters (*params*) * statement dots
   | OptStm   of statement
   | UniqueStm of statement
 
+and base_forinfo =
+    ForExp of expression option * string mcode (*;*)
+  | ForDecl of (info * mcodekind) (* before the decl *) * declaration
+
+and forinfo = base_forinfo wrap
+
 and fninfo =
     FStorage of Ast_cocci.storage mcode
   | FType of typeC
@@ -326,6 +400,8 @@ and base_case_line =
     Default of string mcode (* default *) * string mcode (*:*) * statement dots
   | Case of string mcode (* case *) * expression * string mcode (*:*) *
        statement dots
+  | DisjCase of string mcode * case_line list *
+       string mcode list (* the |s *) * string mcode
   | OptCase of case_line
 
 and case_line = base_case_line wrap
@@ -336,13 +412,13 @@ and case_line = base_case_line wrap
 and meta_pos =
     MetaPos of Ast_cocci.meta_name mcode * Ast_cocci.meta_name list *
        Ast_cocci.meta_collect
-  | NoMetaPos
 
 (* --------------------------------------------------------------------- *)
 (* Top-level code *)
 
 and base_top_level =
-    DECL of statement
+    NONDECL of statement (* cannot match all of a top-level declaration *)
+  | TOPCODE of statement dots
   | CODE of statement dots
   | FILEINFO of string mcode (* old file *) * string mcode (* new file *)
   | ERRORWORDS of expression list
@@ -357,9 +433,27 @@ and parsed_rule =
         (string list * string list * Ast_cocci.dependency * string *
            Ast_cocci.exists)) *
        (rule * Ast_cocci.metavar list) * Ast_cocci.ruletype
-  | ScriptRule of
-      string * Ast_cocci.dependency * (string * Ast_cocci.meta_name) list *
+  | ScriptRule of string (* name *) *
+      string * Ast_cocci.dependency *
+       (Ast_cocci.script_meta_name *
+          Ast_cocci.meta_name * Ast_cocci.metavar) list (*inherited vars*) *
+       Ast_cocci.meta_name list (*script vars*) *
        string
+  | InitialScriptRule of string (* name *) *
+      string (*language*) * Ast_cocci.dependency * string (*code*)
+  | FinalScriptRule of string (* name *) *
+      string (*language*) * Ast_cocci.dependency * string (*code*)
+
+(* --------------------------------------------------------------------- *)
+
+and dependency =
+    Dep of string (* rule applies for the current binding *)
+  | AntiDep of dependency (* rule doesn't apply for the current binding *)
+  | EverDep of string (* rule applies for some binding *)
+  | NeverDep of string (* rule never applies for any binding *)
+  | AndDep of dependency * dependency
+  | OrDep of dependency * dependency
+  | NoDep | FailDep
 
 (* --------------------------------------------------------------------- *)
 
@@ -379,12 +473,14 @@ and anything =
   | InitTag of initialiser
   | DeclTag of declaration
   | StmtTag of statement
+  | ForInfoTag of forinfo
   | CaseLineTag of case_line
   | TopTag of top_level
   | IsoWhenTag of Ast_cocci.when_modifier (*only for when code, in iso phase*)
   | IsoWhenTTag of expression(*only for when code, in iso phase*)
   | IsoWhenFTag of expression(*only for when code, in iso phase*)
-  | MetaPosTag of meta_pos (* only in iso phase *)
+  | MetaPosTag of meta_pos
+  | HiddenVarTag of anything list (* in iso_compile/pattern only *)
 
 val dotsExpr : expression dots -> anything
 val dotsInit : initialiser dots -> anything
@@ -399,6 +495,7 @@ val param : parameterTypeDef -> anything
 val ini : initialiser -> anything
 val decl : declaration -> anything
 val stmt : statement -> anything
+val forinfo : forinfo -> anything
 val case_line : case_line -> anything
 val top : top_level -> anything
 
@@ -419,9 +516,9 @@ val unwrap_mcode : 'a mcode -> 'a
 val rewrap : 'a wrap -> 'b -> 'b wrap
 val rewrap_mcode : 'a mcode -> 'b -> 'b mcode
 val copywrap : 'a wrap -> 'b -> 'b wrap
-val get_pos : 'a mcode -> meta_pos
-val get_pos_ref : 'a mcode -> meta_pos ref
-val set_pos : meta_pos -> 'a mcode -> 'a mcode
+val get_pos : 'a mcode -> anything list
+val get_pos_ref : 'a mcode -> anything list ref
+val set_pos : anything list -> 'a mcode -> 'a mcode
 val get_info : 'a wrap -> info
 val set_info : 'a wrap -> info -> 'a wrap
 val get_index : 'a wrap -> int
@@ -448,6 +545,9 @@ val fresh_index : unit -> int
 val set_mcode_data : 'a -> 'a mcode -> 'a mcode
 val make_mcode : 'a -> 'a mcode
 val make_mcode_info : 'a -> info -> 'a mcode
+val make_minus_mcode : 'a -> 'a mcode
+
+val meta_pos_name : anything -> Ast_cocci.meta_name mcode
 
 val ast0_type_to_type : typeC -> Type_cocci.typeC
 val reverse_type : Type_cocci.typeC -> base_typeC