Commit d8fa1dba authored by Vitja Makarov's avatar Vitja Makarov

ControlFlowState object instead of set() for convinience

parent e82a3a33
......@@ -327,6 +327,32 @@ class NameReference(object):
return '%s(entry=%r)' % (self.__class__.__name__, self.entry)
class ControlFlowState(list):
# Keeps track of Node's entry assignments
#
# cf_is_null [boolean] It is uninitialized
# cf_maybe_null [boolean] May be uninitialized
# is_single [boolean] Has only one assignment at this point
cf_maybe_null = False
cf_is_null = False
is_single = False
def __init__(self, state):
if Uninitialized in state:
state.discard(Uninitialized)
self.cf_maybe_null = True
if not state:
self.cf_is_null = True
else:
if len(state) == 1:
self.is_single = True
super(ControlFlowState, self).__init__(state)
def one(self):
return self[0]
class GVContext(object):
"""Graphviz subgraph object."""
......@@ -530,11 +556,10 @@ def check_definitions(flow, compiler_directives):
messages.report()
# Remove Uninitialized from cf_state
for node in assmt_nodes:
node.cf_state.discard(Uninitialized)
node.cf_state = ControlFlowState(node.cf_state)
for node in references:
node.cf_state.discard(Uninitialized)
node.cf_state = ControlFlowState(node.cf_state)
class AssignmentCollector(TreeVisitor):
......
......@@ -1653,9 +1653,9 @@ class InlineDefNodeCalls(Visitor.CythonTransform):
function_name = node.function
if not function_name.is_name:
return node
if len(function_name.cf_state) != 1:
if not function_name.cf_state.is_single:
return node
function = list(function_name.cf_state)[0].rhs
function = function_name.cf_state.one().rhs
if not isinstance(function, ExprNodes.PyCFunctionNode):
return node
inlined = ExprNodes.InlinedDefNodeCallNode(
......
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