Release coccinelle-0.2.0
[bpt/coccinelle.git] / parsing_cocci / get_constants.ml
index 3cd8f90..5ceea90 100644 (file)
@@ -1,23 +1,23 @@
 (*
 (*
-* Copyright 2005-2008, Ecole des Mines de Nantes, University of Copenhagen
-* Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
-* 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.
-*)
+ * 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.
+ *)
 
 
 (* get a list of all of the constants in the - slice of a SmPL file, to be
 
 
 (* get a list of all of the constants in the - slice of a SmPL file, to be
@@ -83,7 +83,7 @@ let get_minus_constants bind orbind =
        if !Flag.sgrep_mode2
        then
          match ty with
        if !Flag.sgrep_mode2
        then
          match ty with
-           (_,_,Ast.MINUS(_,_),_) -> [Ast.unwrap_mcode ty]
+           (_,_,Ast.MINUS(_,_,_,_),_) -> [Ast.unwrap_mcode ty]
          | _ -> []
        else [Ast.unwrap_mcode ty]
     | _ -> k e in
          | _ -> []
        else [Ast.unwrap_mcode ty]
     | _ -> k e in
@@ -118,7 +118,6 @@ let get_minus_constants bind orbind =
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
-    mcode
     donothing donothing donothing donothing
     ident expression fullType typeC donothing donothing declaration
     rule_elem statement donothing donothing donothing
     donothing donothing donothing donothing
     ident expression fullType typeC donothing donothing declaration
     rule_elem statement donothing donothing donothing
@@ -131,13 +130,12 @@ let get_all_minus_constants =
   let option_default = [] in
   let mcode r (x,_,mcodekind,_) =
     match mcodekind with
   let option_default = [] in
   let mcode r (x,_,mcodekind,_) =
     match mcodekind with
-      Ast.MINUS(_,_) -> [x]
+      Ast.MINUS(_,_,_,_) -> [x]
     | _ -> [] in
   let other r (x,_,mcodekind,_) = [] in
 
   V.combiner bind option_default
     other mcode other other other other other other other other other other
     | _ -> [] in
   let other r (x,_,mcodekind,_) = [] in
 
   V.combiner bind option_default
     other mcode other other other other other other other other other other
-    other
 
     donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
 
     donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
@@ -158,16 +156,15 @@ let get_plus_constants =
               bind (fn.V.combiner_anything cur) prev))
        [] l in
     match mcodekind with
               bind (fn.V.combiner_anything cur) prev))
        [] l in
     match mcodekind with
-      Ast.MINUS(_,anythings) -> recurse anythings
-    | Ast.CONTEXT(_,Ast.BEFORE(a)) -> recurse a
-    | Ast.CONTEXT(_,Ast.AFTER(a)) -> recurse a
-    | Ast.CONTEXT(_,Ast.BEFOREAFTER(a1,a2)) ->
+      Ast.MINUS(_,_,_,anythings) -> recurse anythings
+    | Ast.CONTEXT(_,Ast.BEFORE(a,_)) -> recurse a
+    | Ast.CONTEXT(_,Ast.AFTER(a,_)) -> recurse a
+    | Ast.CONTEXT(_,Ast.BEFOREAFTER(a1,a2,_)) ->
        Common.union_set (recurse a1) (recurse a2)
     | _ -> [] in
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
        Common.union_set (recurse a1) (recurse a2)
     | _ -> [] in
 
   V.combiner bind option_default
     mcode 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 donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing
@@ -255,7 +252,6 @@ let check_inherited nm =
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
-    mcode
     donothing donothing donothing donothing
     strictident strictexpr strictfullType stricttypeC donothing strictparam
     strictdecls strictrule_elem strictstatement donothing donothing donothing
     donothing donothing donothing donothing
     strictident strictexpr strictfullType stricttypeC donothing strictparam
     strictdecls strictrule_elem strictstatement donothing donothing donothing
@@ -270,6 +266,7 @@ let rec dependent = function
   | Ast.AndDep (d1,d2) -> dependent d1 or dependent d2
   | Ast.OrDep (d1,d2) -> dependent d1 && dependent d2
   | Ast.NoDep -> false
   | Ast.AndDep (d1,d2) -> dependent d1 or dependent d2
   | Ast.OrDep (d1,d2) -> dependent d1 && dependent d2
   | Ast.NoDep -> false
+  | Ast.FailDep -> true
 
 (* ------------------------------------------------------------------------ *)
 
 
 (* ------------------------------------------------------------------------ *)
 
@@ -305,8 +302,10 @@ let get_constants rules =
         (function (rest_info,in_plus) ->
           function r ->
             match r with
         (function (rest_info,in_plus) ->
           function r ->
             match r with
-              Ast.ScriptRule (_,mv,deps,_) -> (rest_info, in_plus)
-            | Ast.CocciRule (nm, (dep,_,_), cur, _) ->
+              Ast.ScriptRule (_,_,_,_)
+           | Ast.InitialScriptRule (_,_) | Ast.FinalScriptRule (_,_) ->
+               (rest_info, in_plus)
+            | Ast.CocciRule (nm, (dep,_,_), cur, _, _) ->
                 let (cur_info,cur_plus) = rule_fn cur in_plus in
                let cur_info =
                  (* no dependencies if dependent on another rule; then we
                 let (cur_info,cur_plus) = rule_fn cur in_plus in
                let cur_info =
                  (* no dependencies if dependent on another rule; then we