(*
+ * 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.
let astfvident recursor k i =
bind (k i)
(match Ast.unwrap i with
- Ast.MetaId(name,_,_,_) | Ast.MetaFunc(name,_,_,_)
- | Ast.MetaLocalFunc(name,_,_,_) -> [metaid name]
+ Ast.MetaId(name,idconstraint,_,_) | Ast.MetaFunc(name,idconstraint,_,_)
+ | Ast.MetaLocalFunc(name,idconstraint,_,_) ->
+ let metas =
+ if include_constraints
+ then
+ match idconstraint with
+ Ast.IdNegIdSet (_,metas) -> metas
+ | _ -> []
+ else [] in
+ bind (List.rev metas) [metaid name]
| _ -> option_default) in
let rec type_collect res = function
TC.ConstVol(_,ty) | TC.Pointer(ty) | TC.FunctionPointer(ty)
| TC.Array(ty) -> type_collect res ty
- | TC.MetaType(tyname,_,_) -> bind [tyname] res
+ | TC.MetaType(tyname,_,_) ->
+ bind [tyname] res
| TC.SignedT(_,Some ty) -> type_collect res ty
| ty -> res in
let astfvexpr recursor k e =
bind (k e)
(match Ast.unwrap e with
- Ast.MetaExpr(name,_,_,Some type_list,_,_) ->
+ Ast.MetaExpr(name,constraints,_,Some type_list,_,_) ->
let types = List.fold_left type_collect option_default type_list in
- bind [metaid name] types
- | Ast.MetaErr(name,_,_,_) | Ast.MetaExpr(name,_,_,_,_,_) -> [metaid name]
+ let extra =
+ if include_constraints
+ then
+ match constraints with
+ Ast.SubExpCstrt l -> l
+ | _ -> []
+ else [] in
+ bind extra (bind [metaid name] types)
+ | Ast.MetaErr(name,constraints,_,_)
+ | Ast.MetaExpr(name,constraints,_,_,_,_) ->
+ let extra =
+ if include_constraints
+ then
+ match constraints with
+ Ast.SubExpCstrt l -> l
+ | _ -> []
+ else [] in
+ bind extra [metaid name]
| Ast.MetaExprList(name,None,_,_) -> [metaid name]
| Ast.MetaExprList(name,Some (lenname,_,_),_,_) ->
[metaid name;metaid lenname]
let astfvident recursor k i =
bind (k i)
(match Ast.unwrap i with
- Ast.MetaId(name,_,TC.Saved,_) | Ast.MetaFunc(name,_,TC.Saved,_)
- | Ast.MetaLocalFunc(name,_,TC.Saved,_) -> [metaid name]
+ Ast.MetaId(name,_,TC.Saved,_)
+ | Ast.MetaFunc(name,_,TC.Saved,_)
+ | Ast.MetaLocalFunc(name,_,TC.Saved,_) ->
+ [metaid name]
| _ -> option_default) in
let rec type_collect res = function
TC.ConstVol(_,ty) | TC.Pointer(ty) | TC.FunctionPointer(ty)
| TC.Array(ty) -> type_collect res ty
- | TC.MetaType(tyname,TC.Saved,_) -> bind [tyname] res
+ | TC.MetaType(tyname,TC.Saved,_) ->
+ bind [tyname] res
| TC.SignedT(_,Some ty) -> type_collect res ty
| ty -> res in
match Ast.unwrap e with
Ast.MetaId(name,constraints,_,_) ->
let (unitary,inherited) = classify name in
- Ast.rewrap e (Ast.MetaId(name,constraints,unitary,inherited))
+ Ast.rewrap e
+ (Ast.MetaId(name,constraints,unitary,inherited))
| Ast.MetaFunc(name,constraints,_,_) ->
let (unitary,inherited) = classify name in
Ast.rewrap e (Ast.MetaFunc(name,constraints,unitary,inherited))
[] -> []
| (metavars, rule)::rules ->
match rule with
- Ast.ScriptRule (_,_,_,_)
- | Ast.InitialScriptRule (_,_) | Ast.FinalScriptRule (_,_) ->
+ Ast.ScriptRule (_,_,_,_,_)
+ | Ast.InitialScriptRule (_,_,_,_) | Ast.FinalScriptRule (_,_,_,_) ->
(* bound stays as is because script rules have no names, so no
inheritance is possible *)
rule::(loop bound rules)
let collect_top_level_used_after metavar_rule_list =
+ let drop_virt = List.filter (function ("virtual",_) -> false | _ -> true) in
let (used_after,used_after_lists) =
List.fold_right
(function (metavar_list,r) ->
used_after in
let free_vars =
match r with
- Ast.ScriptRule (_,_,mv,_) ->
- List.map (function (_,(r,v)) -> (r,v)) mv
- | Ast.InitialScriptRule (_,_) | Ast.FinalScriptRule (_,_) -> []
+ Ast.ScriptRule (_,_,_,mv,_) ->
+ drop_virt(List.map (function (_,(r,v),_) -> (r,v)) mv)
+ | Ast.InitialScriptRule (_,_,_,_)
+ | Ast.FinalScriptRule (_,_,_,_) -> []
| Ast.CocciRule (_,_,rule,_,_) ->
- Common.union_set (nub (collect_all_rule_refs rule))
- (collect_in_plus metavar_list rule) in
+ drop_virt
+ (Common.union_set (nub (collect_all_rule_refs rule))
+ (collect_in_plus metavar_list rule)) in
let inherited =
List.filter (function x -> not (List.mem x locally_defined))
free_vars in
(function (metavars,r) ->
function used_after ->
match r with
- Ast.ScriptRule (_,_,_,_)
- | Ast.InitialScriptRule (_,_) | Ast.FinalScriptRule (_,_) ->
+ Ast.ScriptRule (_,_,_,_,_)
+ | Ast.InitialScriptRule (_,_,_,_) | Ast.FinalScriptRule (_,_,_,_) ->
([], [used_after], [], [])
| Ast.CocciRule (name, rule_info, minirules, _,_) ->
collect_local_used_after metavars minirules used_after