ni_nitdoc: added fast copy past utility to signatures.
[nit.git] / src / scope.nit
index 8914b31..5197c19 100644 (file)
@@ -19,6 +19,19 @@ module scope
 
 import parser
 import toolcontext
+import phase
+
+import modelbuilder #FIXME useless
+
+redef class ToolContext
+       var scope_phase: Phase = new ScopePhase(self, null)
+end
+
+private class ScopePhase
+       super Phase
+       redef fun process_npropdef(npropdef) do npropdef.do_scope(toolcontext)
+end
+
 
 # A local variable (including parameters, automatic variables and self)
 class Variable
@@ -35,7 +48,7 @@ class ClosureVariable
 end
 
 # Mark where break and continue will branch.
-# marks are either associated with a label of with a for_loop structure
+# Marks are either associated with a label of with a for_loop structure
 class EscapeMark
        # The name of the label (unless the mark is an anonymous loop mark)
        var name: nullable String
@@ -63,6 +76,8 @@ private class ScopeVisitor
        # The tool context used to display errors
        var toolcontext: ToolContext
 
+       var selfvariable: Variable = new Variable("self")
+
        init(toolcontext: ToolContext)
        do
                self.toolcontext = toolcontext
@@ -251,6 +266,16 @@ redef class AVardeclExpr
        end
 end
 
+redef class ASelfExpr
+       # The variable associated with the self reciever
+       var variable: nullable Variable
+       redef fun accept_scope_visitor(v)
+       do
+               super
+               self.variable = v.selfvariable
+       end
+end
+
 redef class AContinueExpr
        # The escape mark associated with the continue
        var escapemark: nullable EscapeMark
@@ -419,6 +444,20 @@ redef class AClosureCallExpr
        var variable: nullable ClosureVariable
 end
 
+redef class ASendExpr
+       # The escape mark used with the closures if any
+       var escapemark: nullable EscapeMark
+
+       redef fun accept_scope_visitor(v)
+       do
+               if self.n_closure_defs.length > 0 then
+                       var escapemark = v.make_escape_mark(self.n_closure_defs.last.n_label, true)
+                       self.escapemark = escapemark
+               end
+               super
+       end
+end
+
 redef class AClosureDef
        # The automatic variables in order
        var variables: nullable Array[Variable]
@@ -439,8 +478,7 @@ redef class AClosureDef
                        variables.add(va)
                end
 
-               var escapemark = v.make_escape_mark(n_label, true)
-               self.escapemark = escapemark
+               self.escapemark = self.parent.as(ASendExpr).escapemark
                v.enter_visit_block(self.n_expr, escapemark)
 
                v.scopes.shift