Release coccinelle-0.2.2-rc1
[bpt/coccinelle.git] / parsing_cocci / get_constants2.ml
index 82cc072..2a8f55a 100644 (file)
@@ -1,3 +1,25 @@
+(*
+ * Copyright 2005-2010, 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.
+ *)
+
+
 module Ast = Ast_cocci
 module V = Visitor_ast
 module TC = Type_cocci
@@ -169,9 +191,11 @@ let do_get_constants constants keywords env neg_pos =
   let option_default = True in
   let bind = build_and in
   let inherited ((nm1,_) as x) =
+    (* ignore virtuals *)
+    if nm1 = "virtual" then option_default
     (* perhaps inherited, but value not required, so no constraints *)
-    if List.mem x neg_pos then option_default
-    else try List.assoc nm1 env with Not_found -> False in
+    else if List.mem x neg_pos then option_default
+    else (try List.assoc nm1 env with Not_found -> False) in
   let minherited name = inherited (Ast.unwrap_mcode name) in
   let mcode _ x =
     match Ast.get_pos_var x with
@@ -195,7 +219,8 @@ let do_get_constants constants keywords env neg_pos =
   let rec type_collect res = function
       TC.ConstVol(_,ty) | TC.Pointer(ty) | TC.FunctionPointer(ty)
     | TC.Array(ty) -> type_collect res ty
-    | TC.MetaType(tyname,_,_) -> inherited tyname
+    | TC.MetaType(tyname,_,_) ->
+       inherited tyname
     | TC.TypeName(s) -> constants s
     | TC.EnumName(false,s) -> constants s
     | TC.StructUnionName(_,false,s) -> constants s
@@ -437,7 +462,8 @@ let rule_fn tls in_plus env neg_pos =
     (function (rest_info,in_plus) ->
       function (cur,neg_pos) ->
        let minuses =
-         (do_get_constants keep drop env neg_pos).V.combiner_top_level cur in
+         let getter = do_get_constants keep drop env neg_pos in
+         getter.V.combiner_top_level cur in
        let all_minuses =
          if !Flag.sgrep_mode2
          then [] (* nothing removed for sgrep *)
@@ -457,9 +483,8 @@ let rule_fn tls in_plus env neg_pos =
           minirules anymore anyway. *)
        match new_minuses with
          True ->
-           let retry =
-             (do_get_constants drop keep env neg_pos).V.combiner_top_level
-               cur in
+           let getter = do_get_constants drop keep env neg_pos in
+           let retry = getter.V.combiner_top_level cur in
            (match retry with
              True when not was_bot -> (rest_info, new_plusses)
            | x -> (build_or x rest_info, new_plusses))
@@ -479,17 +504,24 @@ let get_constants rules neg_pos_vars =
                    List.fold_left
                      (function prev ->
                        function (_,(rule,_)) ->
-                         Ast.AndDep (Ast.Dep rule,prev))
+                         if rule = "virtual"
+                         then prev
+                         else Ast.AndDep (Ast.Dep rule,prev))
                      deps mv in
                  (match dependencies env extra_deps with
                    False -> (rest_info, in_plus, env, locals)
                  | dependencies ->
                      (build_or dependencies rest_info, in_plus, env, locals))
-              | (Ast.InitialScriptRule (_,_),_)
-             | (Ast.FinalScriptRule (_,_),_) -> (rest_info,in_plus,env,locals)
+              | (Ast.InitialScriptRule (_,deps,_),_)
+             | (Ast.FinalScriptRule (_,deps,_),_) ->
+                 (match dependencies env deps with
+                   False -> (rest_info, in_plus, env, locals)
+                 | dependencies ->
+                     (build_or dependencies rest_info, in_plus, env, locals))
               | (Ast.CocciRule (nm,(dep,_,_),cur,_,_),neg_pos_vars) ->
                  let (cur_info,cur_plus) =
-                   rule_fn cur in_plus ((nm,True)::env) neg_pos_vars in
+                   rule_fn cur in_plus ((nm,True)::env)
+                     neg_pos_vars in
                  if List.for_all all_context.V.combiner_top_level cur
                  then (rest_info,cur_plus,(nm,cur_info)::env,nm::locals)
                  else