Version 1.0.0-rc17 has been released. Some changes are:
[bpt/coccinelle.git] / parsing_cocci / iso_pattern.ml
index 8866940..6814e0b 100644 (file)
  *)
 
 
-# 0 "./iso_pattern.ml"
-(*
- * 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 "./iso_pattern.ml"
 (* Potential problem: offset of mcode is not updated when an iso is
 instantiated, implying that a term may end up with many mcodes with the
@@ -89,7 +62,7 @@ let strip_info =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing
+    donothing donothing donothing
 
 let anything_equal = function
     (Ast0.DotsExprTag(d1),Ast0.DotsExprTag(d2)) ->
@@ -464,7 +437,7 @@ let match_maker checks_needed context_required whencode_allowed =
     V0.flat_combiner bind option_default
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
       donothing donothing donothing donothing donothing donothing
-      ident expression typeC init param decl stmt donothing
+      ident expression typeC init param decl stmt donothing donothing
       donothing in
 
   let add_pure_list_binding name pure is_pure builder1 builder2 lst =
@@ -1135,12 +1108,20 @@ let match_maker checks_needed context_required whencode_allowed =
                 [check_mcode d1 d; check_mcode w1 w; check_mcode lp1 lp;
                   check_mcode rp1 rp; match_statement bodya bodyb;
                   match_expr expa expb]
-         | (Ast0.For(f1,lp1,e1a,sc1a,e2a,sc2a,e3a,rp1,bodya,_),
-            Ast0.For(f,lp,e1b,sc1b,e2b,sc2b,e3b,rp,bodyb,_)) ->
+         | (Ast0.For(f1,lp1,firsta,e2a,sc2a,e3a,rp1,bodya,_),
+            Ast0.For(f,lp,firstb,e2b,sc2b,e3b,rp,bodyb,_)) ->
+              let first =
+                match (Ast0.unwrap firsta,Ast0.unwrap firstb) with
+                  (Ast0.ForExp(e1a,sc1a),Ast0.ForExp(e1b,sc1b)) ->
+                    conjunct_bindings
+                      (check_mcode sc2a sc2b)
+                      (match_option match_expr e1a e1b)
+                | (Ast0.ForDecl (_,decla),Ast0.ForDecl (_,declb)) ->
+                    match_decl decla declb
+                | _ -> return false in
               conjunct_many_bindings
-                [check_mcode f1 f; check_mcode lp1 lp; check_mcode sc1a sc1b;
+                [check_mcode f1 f; check_mcode lp1 lp; first;
                   check_mcode sc2a sc2b; check_mcode rp1 rp;
-                  match_option match_expr e1a e1b;
                   match_option match_expr e2a e2b;
                   match_option match_expr e3a e3b;
                   match_statement bodya bodyb]
@@ -1443,7 +1424,7 @@ let make_minus =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     dots dots dots dots dots dots
     donothing expression donothing initialiser donothing declaration
-    statement donothing donothing
+    statement donothing donothing donothing
 
 (* --------------------------------------------------------------------- *)
 (* rebuild mcode cells in an instantiated alt *)
@@ -1501,18 +1482,18 @@ let rebuild_mcode start_line =
           (match Ast0.unwrap s with
             Ast0.Decl((info,mc),decl) ->
               Ast0.Decl((info,copy_mcodekind mc),decl)
-          | Ast0.IfThen(iff,lp,tst,rp,branch,(info,mc)) ->
-              Ast0.IfThen(iff,lp,tst,rp,branch,(info,copy_mcodekind mc))
-          | Ast0.IfThenElse(iff,lp,tst,rp,branch1,els,branch2,(info,mc)) ->
+          | Ast0.IfThen(iff,lp,tst,rp,branch,(info,mc,adj)) ->
+              Ast0.IfThen(iff,lp,tst,rp,branch,(info,copy_mcodekind mc,adj))
+          | Ast0.IfThenElse(iff,lp,tst,rp,branch1,els,branch2,(info,mc,adj))->
               Ast0.IfThenElse(iff,lp,tst,rp,branch1,els,branch2,
-                (info,copy_mcodekind mc))
-          | Ast0.While(whl,lp,exp,rp,body,(info,mc)) ->
-              Ast0.While(whl,lp,exp,rp,body,(info,copy_mcodekind mc))
-          | Ast0.For(fr,lp,e1,sem1,e2,sem2,e3,rp,body,(info,mc)) ->
-              Ast0.For(fr,lp,e1,sem1,e2,sem2,e3,rp,body,
-                       (info,copy_mcodekind mc))
-          | Ast0.Iterator(nm,lp,args,rp,body,(info,mc)) ->
-              Ast0.Iterator(nm,lp,args,rp,body,(info,copy_mcodekind mc))
+                (info,copy_mcodekind mc,adj))
+          | Ast0.While(whl,lp,exp,rp,body,(info,mc,adj)) ->
+              Ast0.While(whl,lp,exp,rp,body,(info,copy_mcodekind mc,adj))
+          | Ast0.For(fr,lp,first,e2,sem2,e3,rp,body,(info,mc,adj)) ->
+              Ast0.For(fr,lp,first,e2,sem2,e3,rp,body,
+                       (info,copy_mcodekind mc,adj))
+          | Ast0.Iterator(nm,lp,args,rp,body,(info,mc,adj)) ->
+              Ast0.Iterator(nm,lp,args,rp,body,(info,copy_mcodekind mc,adj))
           | Ast0.FunDecl
               ((info,mc),fninfo,name,lp,params,rp,lbrace,body,rbrace) ->
                 Ast0.FunDecl
@@ -1531,7 +1512,7 @@ let rebuild_mcode start_line =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing
-    donothing statement donothing donothing
+    donothing statement donothing donothing donothing
 
 (* --------------------------------------------------------------------- *)
 (* The problem of whencode.  If an isomorphism contains dots in multiple
@@ -1976,6 +1957,7 @@ let instantiate bindings mv_bindings =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     (dots elist) donothing (dots plist) (dots slist) donothing donothing
     identfn exprfn tyfn initfn paramfn declfn stmtfn donothing donothing
+    donothing
 
 (* --------------------------------------------------------------------- *)
 
@@ -2107,17 +2089,17 @@ let extra_copy_stmt_plus model e =
        | Ast0.Decl((info,bef1),_) ->
            merge_plus bef bef1
        | _ ->  merge_plus bef (Ast0.get_mcodekind e))
-    | Ast0.IfThen(_,_,_,_,_,(info,aft))
-    | Ast0.IfThenElse(_,_,_,_,_,_,_,(info,aft))
-    | Ast0.While(_,_,_,_,_,(info,aft))
-    | Ast0.For(_,_,_,_,_,_,_,_,_,(info,aft))
-    | Ast0.Iterator(_,_,_,_,_,(info,aft)) ->
+    | Ast0.IfThen(_,_,_,_,_,(_,aft,_))
+    | Ast0.IfThenElse(_,_,_,_,_,_,_,(_,aft,_))
+    | Ast0.While(_,_,_,_,_,(_,aft,_))
+    | Ast0.For(_,_,_,_,_,_,_,_,(_,aft,_))
+    | Ast0.Iterator(_,_,_,_,_,(_,aft,_)) ->
        (match Ast0.unwrap e with
-         Ast0.IfThen(_,_,_,_,_,(info,aft1))
-       | Ast0.IfThenElse(_,_,_,_,_,_,_,(info,aft1))
-       | Ast0.While(_,_,_,_,_,(info,aft1))
-       | Ast0.For(_,_,_,_,_,_,_,_,_,(info,aft1))
-       | Ast0.Iterator(_,_,_,_,_,(info,aft1)) ->
+         Ast0.IfThen(_,_,_,_,_,(_,aft1,_))
+       | Ast0.IfThenElse(_,_,_,_,_,_,_,(_,aft1,_))
+       | Ast0.While(_,_,_,_,_,(_,aft1,_))
+       | Ast0.For(_,_,_,_,_,_,_,_,(_,aft1,_))
+       | Ast0.Iterator(_,_,_,_,_,(_,aft1,_)) ->
            merge_plus aft aft1
        | _ -> merge_plus aft (Ast0.get_mcodekind e))
     | _ -> ()));
@@ -2180,6 +2162,8 @@ let get_name = function
       (nm,function nm -> Ast.MetaLocalFuncDecl(ar,nm))
   | Ast.MetaPosDecl(ar,nm) ->
       (nm,function nm -> Ast.MetaPosDecl(ar,nm))
+  | Ast.MetaAnalysisDecl(ar,nm) ->
+      (nm,function nm -> Ast.MetaAnalysisDecl(ar,nm))
   | Ast.MetaDeclarerDecl(ar,nm) ->
       (nm,function nm -> Ast.MetaDeclarerDecl(ar,nm))
   | Ast.MetaIteratorDecl(ar,nm) ->
@@ -2617,7 +2601,7 @@ let rewrap =
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
     donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
-    donothing donothing
+    donothing donothing donothing
 
 let rewrap_anything = function
     Ast0.DotsExprTag(d) ->
@@ -2643,6 +2627,7 @@ let rewrap_anything = function
   | Ast0.ParamTag(d) -> Ast0.ParamTag(rewrap.VT0.rebuilder_rec_parameter d)
   | Ast0.DeclTag(d) -> Ast0.DeclTag(rewrap.VT0.rebuilder_rec_declaration d)
   | Ast0.StmtTag(d) -> Ast0.StmtTag(rewrap.VT0.rebuilder_rec_statement d)
+  | Ast0.ForInfoTag(d) -> Ast0.ForInfoTag(rewrap.VT0.rebuilder_rec_forinfo d)
   | Ast0.CaseLineTag(d) ->
       Ast0.CaseLineTag(rewrap.VT0.rebuilder_rec_case_line d)
   | Ast0.TopTag(d) -> Ast0.TopTag(rewrap.VT0.rebuilder_rec_top_level d)