X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/708f4980a90e2a254d7863f875888e9f5c6db0b3..5636bb2c2537506718da74f85a2b81a5ff3df16f:/parsing_cocci/arity.ml diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index c8da41d..dda5557 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -1,23 +1,45 @@ (* -* 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 . -* -* 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. + *) + + +(* + * 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. + *) (* Arities matter for the minus slice, but not for the plus slice. *) @@ -155,32 +177,32 @@ let make_id = let ident opt_allowed tgt i = match Ast0.unwrap i with - Ast0.Id(name) -> - let arity = - all_same opt_allowed tgt (mcode2line name) - [mcode2arity name] in - let name = mcode name in - make_id i tgt arity (Ast0.Id(name)) - | Ast0.MetaId(name,constraints,pure) -> - let arity = - all_same opt_allowed tgt (mcode2line name) - [mcode2arity name] in - let name = mcode name in - make_id i tgt arity (Ast0.MetaId(name,constraints,pure)) - | Ast0.MetaFunc(name,constraints,pure) -> - let arity = - all_same opt_allowed tgt (mcode2line name) - [mcode2arity name] in - let name = mcode name in - make_id i tgt arity (Ast0.MetaFunc(name,constraints,pure)) - | Ast0.MetaLocalFunc(name,constraints,pure) -> - let arity = - all_same opt_allowed tgt (mcode2line name) - [mcode2arity name] in - let name = mcode name in - make_id i tgt arity (Ast0.MetaLocalFunc(name,constraints,pure)) - | Ast0.OptIdent(_) | Ast0.UniqueIdent(_) -> - failwith "unexpected code" + Ast0.Id(name) -> + let arity = + all_same opt_allowed tgt (mcode2line name) + [mcode2arity name] in + let name = mcode name in + make_id i tgt arity (Ast0.Id(name)) + | Ast0.MetaId(name,constraints,pure) -> + let arity = + all_same opt_allowed tgt (mcode2line name) + [mcode2arity name] in + let name = mcode name in + make_id i tgt arity (Ast0.MetaId(name,constraints,pure)) + | Ast0.MetaFunc(name,constraints,pure) -> + let arity = + all_same opt_allowed tgt (mcode2line name) + [mcode2arity name] in + let name = mcode name in + make_id i tgt arity (Ast0.MetaFunc(name,constraints,pure)) + | Ast0.MetaLocalFunc(name,constraints,pure) -> + let arity = + all_same opt_allowed tgt (mcode2line name) + [mcode2arity name] in + let name = mcode name in + make_id i tgt arity (Ast0.MetaLocalFunc(name,constraints,pure)) + | Ast0.OptIdent(_) | Ast0.UniqueIdent(_) -> + failwith "unexpected code" (* --------------------------------------------------------------------- *) (* Expression *) @@ -341,6 +363,7 @@ let rec top_expression opt_allowed tgt expr = let dots = mcode dots in let whencode = get_option (expression Ast0.NONE) whencode in make_exp expr tgt arity (Ast0.Estars(dots,whencode)) + (* why does optexp exist???? *) | Ast0.OptExp(_) | Ast0.UniqueExp(_) -> failwith "unexpected code" @@ -755,7 +778,7 @@ and statement tgt stm = let rp = mcode rp in let body = statement arity body in make_rule_elem stm tgt arity (Ast0.Iterator(nm,lp,args,rp,body,aft)) - | Ast0.Switch(switch,lp,exp,rp,lb,cases,rb) -> + | Ast0.Switch(switch,lp,exp,rp,lb,decls,cases,rb) -> let arity = stm_same (mcode2line switch) (List.map mcode2arity [switch;lp;rp;lb;rb]) in @@ -764,10 +787,11 @@ and statement tgt stm = let exp = expression arity exp in let rp = mcode rp in let lb = mcode lb in + let decls = dots (statement arity) decls in let cases = dots (case_line arity) cases in let rb = mcode rb in make_rule_elem stm tgt arity - (Ast0.Switch(switch,lp,exp,rp,lb,cases,rb)) + (Ast0.Switch(switch,lp,exp,rp,lb,decls,cases,rb)) | Ast0.Break(br,sem) -> let arity = stm_same (mcode2line br) (List.map mcode2arity [br;sem]) in let br = mcode br in @@ -788,7 +812,7 @@ and statement tgt stm = let arity = stm_same (mcode2line goto) (List.map mcode2arity [goto;sem]) in let goto = mcode goto in - let l = ident false tgt l in + let l = ident false arity l in let sem = mcode sem in make_rule_elem stm tgt arity (Ast0.Goto(goto,l,sem)) | Ast0.Return(ret,sem) -> @@ -1045,6 +1069,14 @@ and case_line tgt c = let colon = mcode colon in let code = dots (statement arity) code in make_case_line c tgt arity (Ast0.Case(case,exp,colon,code)) + | Ast0.DisjCase(starter,case_lines,mids,ender) -> + let case_lines = List.map (case_line tgt) case_lines in + (match List.rev case_lines with + _::xs -> + if anyopt xs (function Ast0.OptCase(_) -> true | _ -> false) + then fail c "opt only allowed in the last disjunct" + | _ -> ()); + Ast0.rewrap c (Ast0.DisjCase(starter,case_lines,mids,ender)) | Ast0.OptCase(_) -> failwith "unexpected OptCase" (* --------------------------------------------------------------------- *)