X-Git-Url: http://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/feec80c30d140c69f5d894bd09b6071247d0fbaa..d6ce1786f27a05efa53cabeca92fc8e744a4b239:/parsing_cocci/get_constants2.ml diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index ed95fd3..de76530 100644 --- a/parsing_cocci/get_constants2.ml +++ b/parsing_cocci/get_constants2.ml @@ -24,6 +24,33 @@ *) +# 0 "./get_constants2.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 . + * + * The authors reserve the right to distribute this or future versions of + * Coccinelle under other licenses. + *) + + # 0 "./get_constants2.ml" module Ast = Ast_cocci module V = Visitor_ast @@ -57,6 +84,13 @@ wanted *) type combine = And of combine list | Or of combine list | Elem of string | False | True +let rec dep2c = function + And l -> Printf.sprintf "(%s)" (String.concat "&" (List.map dep2c l)) + | Or l -> Printf.sprintf "(%s)" (String.concat "|" (List.map dep2c l)) + | Elem x -> x + | False -> "false" + | True -> "true" + (* glimpse often fails on large queries. We can safely remove arguments of && as long as we don't remove all of them (note that there is no negation). This tries just removing one of them and then orders the results by @@ -263,10 +297,11 @@ let drop x = True let do_get_constants constants keywords env neg_pos = let donothing r k e = k e in let option_default = True in + let bad_default = False in let bind = build_and in let inherited ((nm1,_) as x) = - (* ignore virtuals *) - if nm1 = "virtual" then option_default + (* ignore virtuals, can never match *) + if nm1 = "virtual" then bad_default (* perhaps inherited, but value not required, so no constraints *) else if List.mem x neg_pos then option_default else (try List.assoc nm1 env with Not_found -> False) in @@ -288,7 +323,8 @@ let do_get_constants constants keywords env neg_pos = "NULL" -> keywords "NULL" | nm -> constants nm) | Ast.MetaId(name,_,_,_) | Ast.MetaFunc(name,_,_,_) - | Ast.MetaLocalFunc(name,_,_,_) -> bind (k i) (minherited name) + | Ast.MetaLocalFunc(name,_,_,_) -> + bind (k i) (minherited name) | Ast.DisjId(ids) -> disj_union_all (List.map r.V.combiner_ident ids) | _ -> k i in @@ -629,7 +665,8 @@ let run rules neg_pos_vars = else Ast.AndDep (Ast.Dep rule,prev)) deps mv in (match dependencies env extra_deps with - False -> (rest_info, in_plus, (nm,True)::env, nm::locals) + False -> + (rest_info, in_plus, (nm,True)::env, nm::locals) | dependencies -> (build_or dependencies rest_info, in_plus, env, locals)) | (Ast.InitialScriptRule (_,_,deps,_),_)