Commit 8d4c8f4d authored by Vitja Makarov's avatar Vitja Makarov

Code cleanup

parent 480798a6
import cython
cython.declare(PyrexTypes=object, Naming=object, ExprNodes=object, Nodes=object,
Options=object, UtilNodes=object, ModuleNode=object,
......@@ -145,7 +144,8 @@ class ControlFlow(object):
if entry.type.is_array or entry.type.is_struct_or_union:
return False
return (entry.is_local or entry.is_pyclass_attr or entry.is_arg or
entry.from_closure or entry.in_closure or entry.error_on_uninitialized)
entry.from_closure or entry.in_closure or
entry.error_on_uninitialized)
def mark_position(self, node):
"""Mark position, will be used to draw graph nodes."""
......@@ -501,18 +501,21 @@ def check_definitions(flow, compiler_directives):
# Unused result
for assmt in assignments:
if not assmt.refs and not assmt.entry.is_pyclass_attr \
and not assmt.entry.in_closure:
if (not assmt.refs and not assmt.entry.is_pyclass_attr
and not assmt.entry.in_closure):
if assmt.entry.cf_references and warn_unused_result:
if assmt.is_arg:
messages.warning(assmt.pos, "Unused argument value '%s'" % assmt.entry.name)
messages.warning(assmt.pos, "Unused argument value '%s'" %
assmt.entry.name)
else:
messages.warning(assmt.pos, "Unused result in '%s'" % assmt.entry.name)
messages.warning(assmt.pos, "Unused result in '%s'" %
assmt.entry.name)
assmt.lhs.cf_used = False
# Unused entries
for entry in flow.entries:
if not entry.cf_references and not entry.is_pyclass_attr and not entry.in_closure:
if (not entry.cf_references and not entry.is_pyclass_attr
and not entry.in_closure):
# TODO: starred args entries are not marked with is_arg flag
for assmt in entry.cf_assignments:
if assmt.is_arg:
......@@ -522,10 +525,12 @@ def check_definitions(flow, compiler_directives):
is_arg = False
if is_arg:
if warn_unused_arg:
messages.warning(entry.pos, "Unused argument '%s'" % entry.name)
messages.warning(entry.pos, "Unused argument '%s'" %
entry.name)
else:
if warn_unused:
messages.warning(entry.pos, "Unused entry '%s'" % entry.name)
messages.warning(entry.pos, "Unused entry '%s'" %
entry.name)
entry.cf_used = False
messages.report()
......@@ -709,7 +714,9 @@ class CreateControlFlowGraph(CythonTransform):
if arg.is_name:
entry = arg.entry or self.env.lookup(arg.name)
if entry.in_closure or entry.from_closure:
error(arg.pos, "can not delete variable '%s' referenced in nested scope" % entry.name)
error(arg.pos,
"can not delete variable '%s' "
"referenced in nested scope" % entry.name)
# Mark reference
self.visit(arg)
self.flow.mark_deletion(arg, entry)
......@@ -1094,7 +1101,8 @@ class CreateControlFlowGraph(CythonTransform):
self.flow.mark_assignment(node.target,
object_expr, self.env.lookup(node.name))
# TODO: add negative attribute list to "visitchildren"?
self.visitchildren(node, attrs=['dict', 'metaclass', 'mkw', 'bases', 'classobj'])
self.visitchildren(node, attrs=['dict', 'metaclass',
'mkw', 'bases', 'classobj'])
self.env_stack.append(self.env)
self.env = node.scope
self.flow.nextblock()
......
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