Commit eace932b authored by Robert Bradshaw's avatar Robert Bradshaw

Inplace analysis fix.

parent 37efecfe
...@@ -5359,6 +5359,9 @@ class BinopNode(ExprNode): ...@@ -5359,6 +5359,9 @@ class BinopNode(ExprNode):
def analyse_types(self, env): def analyse_types(self, env):
self.operand1.analyse_types(env) self.operand1.analyse_types(env)
self.operand2.analyse_types(env) self.operand2.analyse_types(env)
self.analyse_operation(env)
def analyse_operation(self, env):
if self.is_py_operation(): if self.is_py_operation():
self.coerce_operands_to_pyobjects(env) self.coerce_operands_to_pyobjects(env)
self.type = self.result_type(self.operand1.type, self.type = self.result_type(self.operand1.type,
...@@ -5653,12 +5656,12 @@ class DivNode(NumBinopNode): ...@@ -5653,12 +5656,12 @@ class DivNode(NumBinopNode):
except Exception, e: except Exception, e:
self.compile_time_value_error(e) self.compile_time_value_error(e)
def analyse_types(self, env): def analyse_operation(self, env):
if self.cdivision or env.directives['cdivision']: if self.cdivision or env.directives['cdivision']:
self.ctruedivision = False self.ctruedivision = False
else: else:
self.ctruedivision = self.truedivision self.ctruedivision = self.truedivision
NumBinopNode.analyse_types(self, env) NumBinopNode.analyse_operation(self, env)
if self.is_cpp_operation(): if self.is_cpp_operation():
self.cdivision = True self.cdivision = True
if not self.type.is_pyobject: if not self.type.is_pyobject:
......
...@@ -1184,6 +1184,7 @@ class ExpandInplaceOperators(EnvTransform): ...@@ -1184,6 +1184,7 @@ class ExpandInplaceOperators(EnvTransform):
# There is code to handle this case. # There is code to handle this case.
return node return node
env = self.current_env()
def side_effect_free_reference(node, setting=False): def side_effect_free_reference(node, setting=False):
if isinstance(node, NameNode): if isinstance(node, NameNode):
return node, [] return node, []
...@@ -1206,18 +1207,23 @@ class ExpandInplaceOperators(EnvTransform): ...@@ -1206,18 +1207,23 @@ class ExpandInplaceOperators(EnvTransform):
lhs, let_ref_nodes = side_effect_free_reference(lhs, setting=True) lhs, let_ref_nodes = side_effect_free_reference(lhs, setting=True)
except ValueError: except ValueError:
return node return node
lhs.analyse_types(env)
dup = lhs.__class__(**lhs.__dict__) dup = lhs.__class__(**lhs.__dict__)
binop = binop_node(node.pos, binop = binop_node(node.pos,
operator = node.operator, operator = node.operator,
operand1 = dup, operand1 = dup,
operand2 = rhs, operand2 = rhs,
inplace=True) inplace=True)
node = SingleAssignmentNode(node.pos, lhs=lhs, rhs=binop) binop.analyse_operation(env)
node = SingleAssignmentNode(
node.pos,
lhs = lhs,
rhs=binop.coerce_to(lhs.type, env))
# Use LetRefNode to avoid side effects. # Use LetRefNode to avoid side effects.
let_ref_nodes.reverse() let_ref_nodes.reverse()
for t in let_ref_nodes: for t in let_ref_nodes:
node = LetNode(t, node) node = LetNode(t, node)
node.analyse_expressions(self.current_env()) # Manually analyse types for new node.
return node return node
def visit_ExprNode(self, node): def visit_ExprNode(self, node):
......
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