(*
-* 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-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 <http://www.gnu.org/licenses/>.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * 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. *)
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 *)
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"
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
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
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) ->
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"
(* --------------------------------------------------------------------- *)