-(*
- * 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.
- *)
-
-
module Ast = Ast_cocci
module V = Visitor_ast
+let setify l = (* keep first *)
+ let rec loop seen = function
+ [] -> []
+ | x::xs ->
+ if List.mem x seen then loop seen xs else x::(loop (x::seen) xs) in
+ loop [] l
+
let disjmult2 e1 e2 k =
List.concat
(List.map (function e1 -> List.map (function e2 -> k e1 e2) e2) e1)
let generic_orify_rule_elem f re exp rebuild =
match f exp with
[exp] -> re
- | orexps -> Ast.rewrap re (Ast.DisjRuleElem (List.map rebuild orexps))
+ | orexps ->
+ Ast.rewrap re (Ast.DisjRuleElem (setify(List.map rebuild orexps)))
let orify_rule_elem re exp rebuild =
generic_orify_rule_elem disjexp re exp rebuild
(function exp -> Ast.rewrap re (Ast.Case(case,exp,colon)))
| Ast.DisjRuleElem(l) ->
(* only case lines *)
- Ast.rewrap re(Ast.DisjRuleElem(List.map (disj_rule_elem r k) l))
+ Ast.rewrap re(Ast.DisjRuleElem(setify(List.map (disj_rule_elem r k) l)))
let disj_all =
let mcode x = x in