Coccinelle release 1.0.0-rc14
[bpt/coccinelle.git] / parsing_cocci / visitor_ast.ml
index d530bba..d223e0d 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 "./visitor_ast.ml"
 module Ast0 = Ast0_cocci
 module Ast = Ast_cocci
 
@@ -83,6 +110,7 @@ let combiner bind option_default
       | Ast.MetaId(name,_,_,_) -> meta_mcode name
       | Ast.MetaFunc(name,_,_,_) -> meta_mcode name
       | Ast.MetaLocalFunc(name,_,_,_) -> meta_mcode name
+      |        Ast.AsIdent(id,asid) -> bind (ident id) (ident asid)
       | Ast.DisjId(id_list) -> multibind (List.map ident id_list)
       | Ast.OptIdent(id) -> ident id
       | Ast.UniqueIdent(id) -> ident id in
@@ -98,6 +126,8 @@ let combiner bind option_default
                      string_mcode rp]
       | Ast.Assignment(left,op,right,simple) ->
          multibind [expression left; assign_mcode op; expression right]
+      | Ast.Sequence(left,op,right) ->
+         multibind [expression left; string_mcode op; expression right]
       | Ast.CondExpr(exp1,why,exp2,colon,exp3) ->
          multibind [expression exp1; string_mcode why;
                      get_option expression exp2; string_mcode colon;
@@ -128,9 +158,13 @@ let combiner bind option_default
          multibind
            [string_mcode szf; string_mcode lp; fullType ty; string_mcode rp]
       | Ast.TypeExp(ty) -> fullType ty
+      | Ast.Constructor(lp,ty,rp,init) ->
+         multibind
+           [string_mcode lp; fullType ty; string_mcode rp; initialiser init]
       | Ast.MetaErr(name,_,_,_)
       | Ast.MetaExpr(name,_,_,_,_,_)
       | Ast.MetaExprList(name,_,_,_) -> meta_mcode name
+      |        Ast.AsExpr(exp,asexp) -> bind (expression exp) (expression asexp)
       | Ast.EComma(cm) -> string_mcode cm
       | Ast.DisjExpr(exp_list) -> multibind (List.map expression exp_list)
       | Ast.NestExpr(starter,expr_dots,ender,whencode,multi) ->
@@ -148,7 +182,8 @@ let combiner bind option_default
   and fullType ft =
     let k ft =
       match Ast.unwrap ft with
-       Ast.Type(cv,ty) -> bind (get_option cv_mcode cv) (typeC ty)
+       Ast.Type(_,cv,ty) -> bind (get_option cv_mcode cv) (typeC ty)
+      |        Ast.AsType(ty,asty) -> bind (fullType ty) (fullType asty)
       | Ast.DisjType(types) -> multibind (List.map fullType types)
       | Ast.OptType(ty) -> fullType ty
       | Ast.UniqueType(ty) -> fullType ty in
@@ -202,7 +237,7 @@ let combiner bind option_default
 
   and named_type ty id =
     match Ast.unwrap ty with
-      Ast.Type(None,ty1) ->
+      Ast.Type(_,None,ty1) ->
        (match Ast.unwrap ty1 with
          Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
            function_pointer (ty,lp1,star,rp1,lp2,params,rp2) [ident id]
@@ -218,6 +253,8 @@ let combiner bind option_default
        Ast.MetaDecl(name,_,_) | Ast.MetaField(name,_,_)
       |        Ast.MetaFieldList(name,_,_,_) ->
          meta_mcode name
+      |        Ast.AsDecl(decl,asdecl) ->
+         bind (declaration decl) (declaration asdecl)
       |        Ast.Init(stg,ty,id,eq,ini,sem) ->
          bind (get_option storage_mcode stg)
            (bind (named_type ty id)
@@ -230,6 +267,11 @@ let combiner bind option_default
          multibind
            [ident name; string_mcode lp; expression_dots args;
              string_mcode rp; string_mcode sem]
+      | Ast.MacroDeclInit(name,lp,args,rp,eq,ini,sem) ->
+         multibind
+           [ident name; string_mcode lp; expression_dots args;
+             string_mcode rp; string_mcode eq; initialiser ini;
+             string_mcode sem]
       | Ast.TyDecl(ty,sem) -> bind (fullType ty) (string_mcode sem)
       | Ast.Typedef(stg,ty,id,sem) ->
          bind (string_mcode stg)
@@ -245,6 +287,9 @@ let combiner bind option_default
     let k i =
       match Ast.unwrap i with
        Ast.MetaInit(name,_,_) -> meta_mcode name
+      |        Ast.MetaInitList(name,_,_,_) -> meta_mcode name
+      |        Ast.AsInit(init,asinit) ->
+         bind (initialiser init) (initialiser asinit)
       |        Ast.InitExpr(exp) -> expression exp
       | Ast.ArInitList(lb,initlist,rb) ->
          multibind
@@ -304,7 +349,7 @@ let combiner bind option_default
       | Ast.SeqStart(brace) -> string_mcode brace
       | Ast.SeqEnd(brace) -> string_mcode brace
       | Ast.ExprStatement(exp,sem) ->
-         bind (expression exp) (string_mcode sem)
+         bind (get_option expression exp) (string_mcode sem)
       | Ast.IfHeader(iff,lp,exp,rp) ->
          multibind [string_mcode iff; string_mcode lp; expression exp;
                      string_mcode rp]
@@ -427,6 +472,8 @@ let combiner bind option_default
                      statement_dots body; rule_elem rbrace]
       | Ast.Define(header,body) ->
          bind (rule_elem header) (statement_dots body)
+      |        Ast.AsStmt(stm,asstm) ->
+         bind (statement stm) (statement asstm)
       | Ast.Dots(d,whn,_,_) | Ast.Circles(d,whn,_,_) | Ast.Stars(d,whn,_,_) ->
          bind (string_mcode d)
            (multibind (List.map (whencode statement_dots statement) whn))
@@ -460,7 +507,7 @@ let combiner bind option_default
       match Ast.unwrap t with
        Ast.FILEINFO(old_file,new_file) ->
          bind (string_mcode old_file) (string_mcode new_file)
-      | Ast.DECL(stmt) -> statement stmt
+      | Ast.NONDECL(stmt) -> statement stmt
       | Ast.CODE(stmt_dots) -> statement_dots stmt_dots
       | Ast.ERRORWORDS(exps) -> multibind (List.map expression exps) in
     topfn all_functions k t
@@ -589,6 +636,7 @@ let rebuilder
            Ast.MetaFunc(meta_mcode name,constraints,keep,inherited)
        | Ast.MetaLocalFunc(name,constraints,keep,inherited) ->
            Ast.MetaLocalFunc(meta_mcode name,constraints,keep,inherited)
+       | Ast.AsIdent(id,asid) -> Ast.AsIdent(ident id,ident asid)
        | Ast.DisjId(id_list) -> Ast.DisjId(List.map ident id_list)
        | Ast.OptIdent(id) -> Ast.OptIdent(ident id)
        | Ast.UniqueIdent(id) -> Ast.UniqueIdent(ident id)) in
@@ -606,6 +654,8 @@ let rebuilder
        | Ast.Assignment(left,op,right,simple) ->
            Ast.Assignment(expression left, assign_mcode op, expression right,
                           simple)
+       | Ast.Sequence(left,op,right) ->
+           Ast.Sequence(expression left, string_mcode op, expression right)
        | Ast.CondExpr(exp1,why,exp2,colon,exp3) ->
            Ast.CondExpr(expression exp1, string_mcode why,
                         get_option expression exp2, string_mcode colon,
@@ -635,12 +685,16 @@ let rebuilder
            Ast.SizeOfType(string_mcode szf,string_mcode lp, fullType ty,
                            string_mcode rp)
        | Ast.TypeExp(ty) -> Ast.TypeExp(fullType ty)
+       | Ast.Constructor(lp,ty,rp,init) ->
+           Ast.Constructor(string_mcode lp, fullType ty, string_mcode rp,
+                    initialiser init)
        | Ast.MetaErr(name,constraints,keep,inherited) ->
            Ast.MetaErr(meta_mcode name,constraints,keep,inherited)
        | Ast.MetaExpr(name,constraints,keep,ty,form,inherited) ->
            Ast.MetaExpr(meta_mcode name,constraints,keep,ty,form,inherited)
        | Ast.MetaExprList(name,lenname_inh,keep,inherited) ->
            Ast.MetaExprList(meta_mcode name,lenname_inh,keep,inherited)
+       | Ast.AsExpr(exp,asexp) -> Ast.AsExpr(expression exp,expression asexp)
        | Ast.EComma(cm) -> Ast.EComma(string_mcode cm)
        | Ast.DisjExpr(exp_list) -> Ast.DisjExpr(List.map expression exp_list)
        | Ast.NestExpr(starter,expr_dots,ender,whencode,multi) ->
@@ -661,7 +715,9 @@ let rebuilder
     let k ft =
       Ast.rewrap ft
        (match Ast.unwrap ft with
-         Ast.Type(cv,ty) -> Ast.Type (get_option cv_mcode cv, typeC ty)
+         Ast.Type(allminus,cv,ty) ->
+           Ast.Type (allminus,get_option cv_mcode cv, typeC ty)
+       | Ast.AsType(ty,asty) -> Ast.AsType(fullType ty,fullType asty)
        | Ast.DisjType(types) -> Ast.DisjType(List.map fullType types)
        | Ast.OptType(ty) -> Ast.OptType(fullType ty)
        | Ast.UniqueType(ty) -> Ast.UniqueType(fullType ty)) in
@@ -714,6 +770,8 @@ let rebuilder
            Ast.MetaField(meta_mcode name,keep,inherited)
        | Ast.MetaFieldList(name,lenname_inh,keep,inherited) ->
            Ast.MetaFieldList(meta_mcode name,lenname_inh,keep,inherited)
+       | Ast.AsDecl(decl,asdecl) ->
+           Ast.AsDecl(declaration decl,declaration asdecl)
        | Ast.Init(stg,ty,id,eq,ini,sem) ->
            Ast.Init(get_option storage_mcode stg, fullType ty, ident id,
                     string_mcode eq, initialiser ini, string_mcode sem)
@@ -723,6 +781,11 @@ let rebuilder
        | Ast.MacroDecl(name,lp,args,rp,sem) ->
            Ast.MacroDecl(ident name, string_mcode lp, expression_dots args,
                          string_mcode rp,string_mcode sem)
+       | Ast.MacroDeclInit(name,lp,args,rp,eq,ini,sem) ->
+           Ast.MacroDeclInit
+             (ident name, string_mcode lp, expression_dots args,
+              string_mcode rp,string_mcode eq,initialiser ini,
+              string_mcode sem)
        | Ast.TyDecl(ty,sem) -> Ast.TyDecl(fullType ty, string_mcode sem)
        | Ast.Typedef(stg,ty,id,sem) ->
            Ast.Typedef(string_mcode stg, fullType ty, typeC id,
@@ -740,6 +803,10 @@ let rebuilder
        (match Ast.unwrap i with
          Ast.MetaInit(name,keep,inherited) ->
            Ast.MetaInit(meta_mcode name,keep,inherited)
+       | Ast.MetaInitList(name,lenname_inh,keep,inherited) ->
+           Ast.MetaInitList(meta_mcode name,lenname_inh,keep,inherited)
+       | Ast.AsInit(ini,asini) ->
+           Ast.AsInit(initialiser ini,initialiser asini)
        | Ast.InitExpr(exp) -> Ast.InitExpr(expression exp)
        | Ast.ArInitList(lb,initlist,rb) ->
            Ast.ArInitList(string_mcode lb, initialiser_dots initlist,
@@ -800,7 +867,7 @@ let rebuilder
        | Ast.SeqStart(brace) -> Ast.SeqStart(string_mcode brace)
        | Ast.SeqEnd(brace) -> Ast.SeqEnd(string_mcode brace)
        | Ast.ExprStatement(exp,sem) ->
-           Ast.ExprStatement (expression exp, string_mcode sem)
+           Ast.ExprStatement (get_option expression exp, string_mcode sem)
        | Ast.IfHeader(iff,lp,exp,rp) ->
            Ast.IfHeader(string_mcode iff, string_mcode lp, expression exp,
              string_mcode rp)
@@ -937,6 +1004,7 @@ let rebuilder
                        statement_dots body, rule_elem rbrace)
        | Ast.Define(header,body) ->
            Ast.Define(rule_elem header,statement_dots body)
+       | Ast.AsStmt(stm,asstm) -> Ast.AsStmt(statement stm,statement asstm)
        | Ast.Dots(d,whn,bef,aft) ->
            Ast.Dots(string_mcode d,
                     List.map (whencode statement_dots statement) whn,bef,aft)
@@ -983,7 +1051,7 @@ let rebuilder
        (match Ast.unwrap t with
          Ast.FILEINFO(old_file,new_file) ->
            Ast.FILEINFO (string_mcode old_file, string_mcode new_file)
-       | Ast.DECL(stmt) -> Ast.DECL(statement stmt)
+       | Ast.NONDECL(stmt) -> Ast.NONDECL(statement stmt)
        | Ast.CODE(stmt_dots) -> Ast.CODE(statement_dots stmt_dots)
        | Ast.ERRORWORDS(exps) -> Ast.ERRORWORDS (List.map expression exps)) in
     topfn all_functions k t