Commit 11e478b1 authored by Tom Niget's avatar Tom Niget

Fix support for If and while

parent 84321467
......@@ -95,11 +95,28 @@ class ScoperBlockVisitor(ScoperVisitor):
def visit_If(self, node: ast.If):
scope = self.scope.child(ScopeKind.FUNCTION_INNER)
scope.function = self.scope.function
node.inner_scope = scope
visitor = ScoperBlockVisitor(scope, self.root_decls)
self.expr().visit(node.test)
then_scope = scope.child(ScopeKind.FUNCTION_INNER)
then_visitor = ScoperBlockVisitor(then_scope, self.root_decls)
for b in node.body:
visitor.visit(b)
then_visitor.visit(b)
if node.orelse:
else_scope = scope.child(ScopeKind.FUNCTION_INNER)
else_visitor = ScoperBlockVisitor(else_scope, self.root_decls)
for b in node.orelse:
else_visitor.visit(b)
def visit_While(self, node: ast.While):
scope = self.scope.child(ScopeKind.FUNCTION_INNER)
node.inner_scope = scope
self.expr().visit(node.test)
body_scope = scope.child(ScopeKind.FUNCTION_INNER)
body_visitor = ScoperBlockVisitor(body_scope, self.root_decls)
for b in node.body:
body_visitor.visit(b)
if node.orelse:
raise NotImplementedError(node.orelse)
def visit_Expr(self, node: ast.Expr):
self.expr().visit(node.value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment