Commit f9483650 authored by Vitja Makarov's avatar Vitja Makarov

CF fix for defnodes and classes

parent 5ba30c45
...@@ -583,6 +583,10 @@ class CreateControlFlowGraph(CythonTransform): ...@@ -583,6 +583,10 @@ class CreateControlFlowGraph(CythonTransform):
return node return node
def visit_FuncDefNode(self, node): def visit_FuncDefNode(self, node):
for arg in node.args:
if arg.default:
self.visitchildren(arg)
self.visitchildren(node, attrs=('decorators',))
self.env_stack.append(self.env) self.env_stack.append(self.env)
self.env = node.local_scope self.env = node.local_scope
self.stack.append(self.flow) self.stack.append(self.flow)
...@@ -597,6 +601,8 @@ class CreateControlFlowGraph(CythonTransform): ...@@ -597,6 +601,8 @@ class CreateControlFlowGraph(CythonTransform):
# Function body block # Function body block
self.flow.nextblock() self.flow.nextblock()
for arg in node.args:
self.visit(arg)
if node.star_arg: if node.star_arg:
self.flow.mark_argument(node.star_arg, self.flow.mark_argument(node.star_arg,
TypedExprNode(Builtin.tuple_type, TypedExprNode(Builtin.tuple_type,
...@@ -607,7 +613,7 @@ class CreateControlFlowGraph(CythonTransform): ...@@ -607,7 +613,7 @@ class CreateControlFlowGraph(CythonTransform):
TypedExprNode(Builtin.dict_type, TypedExprNode(Builtin.dict_type,
may_be_none=False), may_be_none=False),
node.starstar_arg.entry) node.starstar_arg.entry)
self.visitchildren(node) self.visit(node.body)
# Workaround for generators # Workaround for generators
if node.is_generator: if node.is_generator:
self.visit(node.gbody.body) self.visit(node.gbody.body)
...@@ -1105,15 +1111,14 @@ class CreateControlFlowGraph(CythonTransform): ...@@ -1105,15 +1111,14 @@ class CreateControlFlowGraph(CythonTransform):
return node return node
def visit_PyClassDefNode(self, node): def visit_PyClassDefNode(self, node):
self.flow.mark_assignment(node.target, self.visitchildren(node, attrs=('dict', 'metaclass',
object_expr_not_none, self.env.lookup(node.name)) 'mkw', 'bases', 'class_result'))
# TODO: add negative attribute list to "visitchildren"? self.flow.mark_assignment(node.target, object_expr_not_none,
self.visitchildren(node, attrs=['dict', 'metaclass', self.env.lookup(node.name))
'mkw', 'bases', 'classobj'])
self.env_stack.append(self.env) self.env_stack.append(self.env)
self.env = node.scope self.env = node.scope
self.flow.nextblock() self.flow.nextblock()
self.visitchildren(node, attrs=['body']) self.visitchildren(node, attrs=('body',))
self.flow.nextblock() self.flow.nextblock()
self.env = self.env_stack.pop() self.env = self.env_stack.pop()
return node return node
......
...@@ -74,6 +74,44 @@ def raise_stat(): ...@@ -74,6 +74,44 @@ def raise_stat():
exc = ValueError exc = ValueError
msg = 'dummy' msg = 'dummy'
def defnode_decorator():
@decorator
def foo():
pass
def decorator():
pass
def defnode_default():
def foo(arg=default()):
pass
def default():
pass
def class_bases():
class foo(bar):
pass
class bar(object):
pass
def class_decorators():
@decorator
class foo(object):
pass
def decorator(cls):
return cls
def class_py3k_metaclass():
class foo(metaclass=Meta):
pass
class Meta(object):
pass
def class_py3k_args():
class foo(*args, **kwargs):
pass
args = []
kwargs = {}
_ERRORS = """ _ERRORS = """
6:11: local variable 'a' referenced before assignment 6:11: local variable 'a' referenced before assignment
12:12: local variable 'a' might be referenced before assignment 12:12: local variable 'a' might be referenced before assignment
...@@ -85,4 +123,11 @@ _ERRORS = """ ...@@ -85,4 +123,11 @@ _ERRORS = """
66:13: local variable 'foo' referenced before assignment 66:13: local variable 'foo' referenced before assignment
71:17: local variable 'exc' referenced before assignment 71:17: local variable 'exc' referenced before assignment
71:22: local variable 'msg' referenced before assignment 71:22: local variable 'msg' referenced before assignment
78:4: local variable 'decorator' referenced before assignment
85:23: local variable 'default' referenced before assignment
91:17: local variable 'bar' referenced before assignment
97:4: local variable 'decorator' referenced before assignment
104:28: local variable 'Meta' referenced before assignment
110:19: local variable 'args' referenced before assignment
110:29: local variable 'kwargs' referenced before assignment
""" """
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