parser: regenerate with lambda
[nit.git] / src / saf / reaching_defs.nit
index 9a5b953..70c853e 100644 (file)
@@ -26,6 +26,19 @@ class ReachingDefsAnalysis
        # New initial flows are empty (conservative analysis).
        redef fun new_initial_flow do return new FlowHashSet[VarDef]
 
+       # New initial flows for methods contains the parameters.
+       redef fun new_initial_method_flow(n) do
+               var flow = new_initial_flow
+               var n_signature = n.n_signature
+               if n_signature == null then return flow
+               for n_param in n_signature.n_params do
+                       var variable = n_param.variable
+                       if variable == null then continue
+                       flow.add(new VarDef(variable, n_param.location))
+               end
+               return flow
+       end
+
        # Perform set union (used for **some path** analysis).
        redef fun merge(s1, s2) do return s1.flow_union(s2)
 
@@ -83,6 +96,24 @@ redef class AVarReassignExpr
        end
 end
 
+redef class AForExpr
+       redef fun accept_reaching_defs(v) do
+               # add variables from `for` declaration
+               for n_group in n_groups do
+                       var variables = n_group.variables
+                       if variables == null then continue
+                       for variable in variables do v.gen(variable, n_group.location)
+               end
+               super
+               # remove variables from `for` declaration
+               for n_group in n_groups do
+                       var variables = n_group.variables
+                       if variables == null then continue
+                       for variable in variables do v.kill(variable)
+               end
+       end
+end
+
 # A Variable definition.
 #
 # Associates a variable to the location of its definition.