nitc/scope: attach AReturnExpr to an escape mark of the whole propdef
authorJean Privat <jean@pryen.org>
Fri, 8 Apr 2016 15:46:47 +0000 (11:46 -0400)
committerJean Privat <jean@pryen.org>
Fri, 8 Apr 2016 15:46:47 +0000 (11:46 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/semantize/scope.nit

index 5f9c748..a0205a5 100644 (file)
@@ -71,6 +71,9 @@ private class ScopeVisitor
        # The tool context used to display errors
        var toolcontext: ToolContext
 
+       # The analysed property
+       var propdef: APropdef
+
        var selfvariable = new Variable("self")
 
        init
@@ -248,10 +251,13 @@ redef class ANode
 end
 
 redef class APropdef
+       # The break escape mark associated with the return
+       var return_mark: nullable EscapeMark
+
        # Entry point of the scope analysis
        fun do_scope(toolcontext: ToolContext)
        do
-               var v = new ScopeVisitor(toolcontext)
+               var v = new ScopeVisitor(toolcontext, self)
                v.enter_visit(self)
                v.shift_scope
        end
@@ -326,6 +332,21 @@ redef class ABreakExpr
        end
 end
 
+redef class AReturnExpr
+       redef fun accept_scope_visitor(v)
+       do
+               super
+
+               var escapemark = v.propdef.return_mark
+               if escapemark == null then
+                       escapemark = new EscapeMark
+                       v.propdef.return_mark = escapemark
+               end
+
+               escapemark.escapes.add(self)
+               self.escapemark = escapemark
+       end
+end
 
 redef class ADoExpr
        # The break escape mark associated with the 'do' block