X-Git-Url: http://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/91eba41f0f6608eba3499d37eeaf609f7060fffe..5636bb2c2537506718da74f85a2b81a5ff3df16f:/tools/bridge.ml diff --git a/tools/bridge.ml b/tools/bridge.ml index c3dcdfb..bd967eb 100644 --- a/tools/bridge.ml +++ b/tools/bridge.ml @@ -1,3 +1,47 @@ +(* + * 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 . + * + * The authors reserve the right to distribute this or future versions of + * Coccinelle under other licenses. + *) + + +(* + * 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 . + * + * The authors reserve the right to distribute this or future versions of + * Coccinelle under other licenses. + *) + + let drop_spaces s = String.concat "" (Str.split (Str.regexp "[ ]+") s) @@ -26,7 +70,7 @@ let parse_line fp l n = | _ -> failwith "no data" in Some (cocci,loop (drop_spaces first) others) | _ -> failwith (Printf.sprintf "bad line: %s" l) - + let collect_lines fp i = let lines = ref [] in let ln = ref 0 in @@ -56,6 +100,7 @@ let process_fp fl = !lines (* --------------------------------------------------------------------- *) +(* same info, different categories *) let discard_ambiguous lines = let rec loop = function @@ -97,7 +142,7 @@ let collect_ors fp lines = | line::xs -> let (c,k,v) = split_or line in let ((c1,k1,v1),rest) = loop xs in - if c = c1 && k = k1 + if c = c1 && k = k1 && not (k = []) then if List.mem v v1 then ((c1,k1,v1),rest) @@ -192,9 +237,9 @@ let process_line env (cocci,tags) = (mktag !n) first_tag_val; n := !n + 1) files - + (* --------------------------------------------------------------------- *) - + let rec mkenv = function [] -> [] | [_] -> failwith "required arguments: file (category x cocci file)*" @@ -206,10 +251,13 @@ let rec mkenv = function let rec upto = function 0 -> [] | n -> (mktag (n-1)) :: (upto (n-1)) - + let _ = + let (no_ors,args) = + List.partition (function "-no_ors" -> true | _ -> false) + (Array.to_list Sys.argv) in let (file,fp,env) = - match List.tl(Array.to_list Sys.argv) with + match List.tl args with file::env -> let rec loop prev = function [] -> @@ -233,7 +281,7 @@ let _ = let fp = List.fold_left (@) [] (List.map process_fp fp) in let i = open_in file in let lines = collect_lines fp i in - let lines = collect_ors fp lines in + let lines = if no_ors = [] then collect_ors fp lines else lines in close_in i; let lines = discard_ambiguous lines in List.iter (process_line env) lines;