X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/7f00441914f5b9bd4f845a1c866da65e1946083e..9bc82bae75129fec4d981ebf245f2f7d7ca73a41:/parsing_cocci/disjdistr.ml diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml index 0d511d3..ca38d9d 100644 --- a/parsing_cocci/disjdistr.ml +++ b/parsing_cocci/disjdistr.ml @@ -1,13 +1,54 @@ +(* + * Copyright 2010, 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. + *) + + +(* + * Copyright 2010, 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. + *) + + 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) @@ -78,6 +119,10 @@ and disjtypeC bty = (function ty -> function size -> Ast.rewrap bty (Ast.Array(ty,lb,size,rb))) | Ast.EnumName(_,_) | Ast.StructUnionName(_,_) -> [bty] + | Ast.EnumDef(ty,lb,ids,rb) -> + disjmult2 (disjty ty) (disjdots disjexp ids) + (function ty -> function ids -> + Ast.rewrap bty (Ast.EnumDef(ty,lb,ids,rb))) | Ast.StructUnionDef(ty,lb,decls,rb) -> disjmult2 (disjty ty) (disjdots disjdecl decls) (function ty -> function decls -> @@ -156,7 +201,7 @@ and disjexp e = | Ast.MetaExprList(_,_,_,_) | Ast.EComma(_) -> [e] | Ast.DisjExpr(exp_list) -> List.concat (List.map disjexp exp_list) - | Ast.NestExpr(expr_dots,whencode,multi) -> + | Ast.NestExpr(starter,expr_dots,ender,whencode,multi) -> (* not sure what to do here, so ambiguities still possible *) [e] | Ast.Edots(dots,_) | Ast.Ecircles(dots,_) | Ast.Estars(dots,_) -> [e] @@ -188,10 +233,15 @@ and disjini i = | Ast.InitExpr(exp) -> let exp = disjexp exp in List.map (function exp -> Ast.rewrap i (Ast.InitExpr(exp))) exp - | Ast.InitList(lb,initlist,rb,whencode) -> + | Ast.ArInitList(lb,initlist,rb) -> + List.map + (function initlist -> + Ast.rewrap i (Ast.ArInitList(lb,initlist,rb))) + (disjdots disjini initlist) + | Ast.StrInitList(allminus,lb,initlist,rb,whencode) -> List.map (function initlist -> - Ast.rewrap i (Ast.InitList(lb,initlist,rb,whencode))) + Ast.rewrap i (Ast.StrInitList(allminus,lb,initlist,rb,whencode))) (disjmult disjini initlist) | Ast.InitGccExt(designators,eq,ini) -> let designators = disjmult designator designators in @@ -205,6 +255,7 @@ and disjini i = (function ini -> Ast.rewrap i (Ast.InitGccName(name,eq,ini))) ini | Ast.IComma(comma) -> [i] + | Ast.Idots(dots,_) -> [i] | Ast.OptIni(ini) -> let ini = disjini ini in List.map (function ini -> Ast.rewrap i (Ast.OptIni(ini))) ini @@ -224,7 +275,8 @@ and designator = function and disjdecl d = match Ast.unwrap d with - Ast.Init(stg,ty,id,eq,ini,sem) -> + Ast.MetaDecl(_,_,_) | Ast.MetaField(_,_,_) -> [d] + | Ast.Init(stg,ty,id,eq,ini,sem) -> disjmult2 (disjty ty) (disjini ini) (function ty -> function ini -> Ast.rewrap d (Ast.Init(stg,ty,id,eq,ini,sem))) @@ -242,7 +294,7 @@ and disjdecl d = let ty = disjty ty in (* disj not allowed in id *) List.map (function ty -> Ast.rewrap d (Ast.Typedef(stg,ty,id,sem))) ty | Ast.DisjDecl(decls) -> List.concat (List.map disjdecl decls) - | Ast.Ddots(_,_) | Ast.MetaDecl(_,_,_) -> [d] + | Ast.Ddots(_,_) -> [d] | Ast.OptDecl(decl) -> let decl = disjdecl decl in List.map (function decl -> Ast.rewrap d (Ast.OptDecl(decl))) decl @@ -253,8 +305,7 @@ and disjdecl d = let generic_orify_rule_elem f re exp rebuild = match f exp with [exp] -> re - | orexps -> - Ast.rewrap re (Ast.DisjRuleElem (setify(List.map rebuild orexps))) + | orexps -> Ast.rewrap re (Ast.DisjRuleElem (List.map rebuild orexps)) let orify_rule_elem re exp rebuild = generic_orify_rule_elem disjexp re exp rebuild @@ -326,14 +377,14 @@ let rec disj_rule_elem r k re = (function exp -> Ast.rewrap re (Ast.Case(case,exp,colon))) | Ast.DisjRuleElem(l) -> (* only case lines *) - Ast.rewrap re(Ast.DisjRuleElem(setify(List.map (disj_rule_elem r k) l))) + Ast.rewrap re(Ast.DisjRuleElem(List.map (disj_rule_elem r k) l)) let disj_all = let mcode x = x in let donothing r k e = k e in V.rebuilder mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing disj_rule_elem donothing donothing donothing donothing @@ -350,7 +401,7 @@ let collect_all_isos = mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing - donothing doanything + donothing donothing doanything let collect_iso_info = let mcode x = x in @@ -364,6 +415,7 @@ let collect_iso_info = V.rebuilder mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode donothing donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing rule_elem donothing donothing donothing donothing