(*
-* Copyright 2005-2009, 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.
+ *)
open Common
(function ast -> function (ua,(fua,(fuas,pos))) ->
List.combine
(if !Flag_cocci.popl
- then failwith "no popl here" (* Popl.popl ast *)
+ then Popl.popl ast
else Asttoctl2.asttoctl ast (ua,fua,fuas) pos)
(Asttomember.asttomember ast ua))
ast (List.combine ua (List.combine fua (List.combine fuas pos)))
let show_or_not_diff2 cfile outfile show_only_minus =
if !Flag_cocci.show_diff then begin
- match Common.fst(Compare_c.compare_default cfile outfile) with
+ match Common.fst(Compare_c.compare_to_original cfile outfile) with
Compare_c.Correct -> () (* diff only in spacing, etc *)
| _ ->
(* may need --strip-trailing-cr under windows *)
(interpret_dependencies local global s1) or
(interpret_dependencies local global s2)
| Ast_cocci.NoDep -> true
+ | Ast_cocci.FailDep -> false
let rec print_dependencies str local global dep =
if !Flag_cocci.show_dependencies
let seen = ref [] in
let rec loop = function
Ast_cocci.Dep s | Ast_cocci.AntiDep s ->
- if not (List.mem s !seen)
- then
- begin
- if List.mem s local
- then pr2 (s^" satisfied")
- else pr2 (s^" not satisfied");
- seen := s :: !seen
- end
+ if not (List.mem s !seen)
+ then
+ begin
+ if List.mem s local
+ then pr2 (s^" satisfied")
+ else pr2 (s^" not satisfied");
+ seen := s :: !seen
+ end
| Ast_cocci.EverDep s | Ast_cocci.NeverDep s ->
- if not (List.mem s !seen)
- then
- begin
- if List.mem s global
- then pr2 (s^" satisfied")
- else pr2 (s^" not satisfied");
- seen := s :: !seen
- end
+ if not (List.mem s !seen)
+ then
+ begin
+ if List.mem s global
+ then pr2 (s^" satisfied")
+ else pr2 (s^" not satisfied");
+ seen := s :: !seen
+ end
| Ast_cocci.AndDep(s1,s2) ->
loop s1;
loop s2
| Ast_cocci.OrDep(s1,s2) ->
loop s1;
loop s2
- | Ast_cocci.NoDep -> () in
+ | Ast_cocci.NoDep -> ()
+ | Ast_cocci.FailDep -> pr2 "False not satisfied" in
loop dep
end
-
-
-
+
(* --------------------------------------------------------------------- *)
(* #include relative position in the file *)
(* --------------------------------------------------------------------- *)
(* --------------------------------------------------------------------- *)
let prepare_cocci ctls free_var_lists negated_pos_lists
- (ua,fua,fuas) positions_list metavars astcocci =
+ (ua,fua,fuas) positions_list metavars astcocci =
let gathered = Common.index_list_1
(zip (zip (zip (zip (zip (zip (zip (zip ctls metavars) astcocci)
let (fullstr, tokens) = parseinfo in
let flow =
- ast_to_flow_with_error_messages c +> Common.map_option (fun flow ->
+ ast_to_flow_with_error_messages c +>
+ Common.map_option (fun flow ->
let flow = Ast_to_flow.annotate_loop_nodes flow in
(* remove the fake nodes for julia *)
);
ccs +> List.map (fun c_or_h ->
{ c_or_h with
- asts = rebuild_info_program c_or_h.asts c_or_h.full_fname isexp }
+ asts =
+ rebuild_info_program c_or_h.asts c_or_h.full_fname isexp }
)
let apply_python_rule r cache newes e rules_that_have_matched
rules_that_have_ever_matched =
- Common.profile_code "python" (fun () ->
+ Common.profile_code "python" (fun () ->
show_or_not_scr_rule_name r.scr_ruleid;
if not(interpret_dependencies rules_that_have_matched
!rules_that_have_ever_matched r.scr_dependencies)
e in
let new_cache =
if List.mem relevant_bindings cache
- then cache
+ then
+ begin
+ print_dependencies
+ "dependencies for script satisfied, but cached:"
+ rules_that_have_matched
+ !rules_that_have_ever_matched
+ r.scr_dependencies;
+ show_or_not_binding "in" e;
+ cache
+ end
else
begin
print_dependencies "dependencies for script satisfied:"
rules_that_have_matched
- !rules_that_have_ever_matched r.scr_dependencies;
+ !rules_that_have_ever_matched
+ r.scr_dependencies;
show_or_not_binding "in" e;
Pycocci.build_classes (List.map (function (x,y) -> x) e);
Pycocci.construct_variables mv e;
(function (cache,newes) ->
function ((e,rules_that_have_matched),relevant_bindings) ->
if not(interpret_dependencies rules_that_have_matched
- !rules_that_have_ever_matched r.dependencies)
+ !rules_that_have_ever_matched
+ r.dependencies)
then
begin
print_dependencies
print_dependencies
("dependencies for rule "^r.rulename^" satisfied:")
rules_that_have_matched
- !rules_that_have_ever_matched r.dependencies;
+ !rules_that_have_ever_matched
+ r.dependencies;
show_or_not_binding "in" e;
show_or_not_binding "relevant in" relevant_bindings;
if !Flag_ctl.partial_match
then
printf
- "Empty list of bindings, I will restart from old env";
+ "Empty list of bindings, I will restart from old env\n";
[(old_bindings_to_keep,rules_that_have_matched)]
end
else
(fun () -> process_a_ctl_a_env_a_toplevel2 a b c f)
-let rec bigloop2 rs (ccs: file_info list) =
- let es = ref [(Ast_c.emptyMetavarsBinding,[])] in
+let rec bigloop2 rs (ccs: file_info list) =
+ let init_es = [(Ast_c.emptyMetavarsBinding,[])] in
+ let es = ref init_es in
let ccs = ref ccs in
let rules_that_have_ever_matched = ref [] in
)
([],[]) !es in
- es := newes;
+ es := (if newes = [] then init_es else newes);
| CocciRuleCocciInfo r ->
- apply_cocci_rule r rules_that_have_ever_matched es ccs);
+ apply_cocci_rule r rules_that_have_ever_matched
+ es ccs);
if !Flag.sgrep_mode2
then begin
"python" ->
(* include_match makes no sense in an initial or final rule, although
er have no way to prevent it *)
- let _ = apply_python_rule r [] [] [] [] (ref []) in ()
+ let _ = apply_python_rule r [] [] [] [] (ref []) in
+ ()
| _ ->
Printf.printf "Unknown language for initial/final script: %s\n"
r.language
r.language::languages
| _ -> languages)
[] cocci_infos in
+
(cocci_infos,toks)
let pre_engine a =
if !Flag_cocci.worth_trying_opt && not (worth_trying cfiles toks)
then
begin
- pr2 ("not worth trying:" ^ Common.join " " cfiles);
+ pr2 ("No matches found for " ^ (Common.join " " (Common.union_all toks))
+ ^ "\nSkipping:" ^ (Common.join " " cfiles));
cfiles +> List.map (fun s -> s, None)
end
else