Commit d5f88aac authored by Stefan Behnel's avatar Stefan Behnel

cleanup, keep for-range optimisation more local

parent 1f7b40c4
...@@ -3870,13 +3870,6 @@ class ForFromStatNode(LoopNode, StatNode): ...@@ -3870,13 +3870,6 @@ class ForFromStatNode(LoopNode, StatNode):
self.bound2.release_temp(env) self.bound2.release_temp(env)
if self.step is not None: if self.step is not None:
self.step.release_temp(env) self.step.release_temp(env)
def reanalyse_c_loop(self, env):
# only make sure all subnodes have an integer type
self.bound1 = self.bound1.coerce_to_integer(env)
self.bound2 = self.bound2.coerce_to_integer(env)
if self.step is not None:
self.step = self.step.coerce_to_integer(env)
def generate_execution_code(self, code): def generate_execution_code(self, code):
old_loop_labels = code.new_loop_labels() old_loop_labels = code.new_loop_labels()
......
...@@ -115,33 +115,31 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -115,33 +115,31 @@ class IterationTransform(Visitor.VisitorTransform):
else: else:
step = args[2] step = args[2]
step_pos = step.pos step_pos = step.pos
if step.constant_result is ExprNodes.not_a_constant: if not isinstance(step.constant_result, (int, long)):
# cannot determine step direction # cannot determine step direction
return node return node
try: step_value = step.constant_result
# FIXME: check how Python handles rounding here, e.g. from float if step_value == 0:
step_value = int(step.constant_result) # will lead to an error elsewhere
except:
return node return node
if not isinstance(step, ExprNodes.IntNode): if not isinstance(step, ExprNodes.IntNode):
step = ExprNodes.IntNode(step_pos, value=step_value) step = ExprNodes.IntNode(step_pos, value=step_value)
if step_value > 0: if step_value < 0:
relation1 = '<='
relation2 = '<'
elif step_value < 0:
step.value = -step_value step.value = -step_value
relation1 = '>=' relation1 = '>='
relation2 = '>' relation2 = '>'
else: else:
return node relation1 = '<='
relation2 = '<'
if len(args) == 1: if len(args) == 1:
bound1 = ExprNodes.IntNode(range_function.pos, value=0) bound1 = ExprNodes.IntNode(range_function.pos, value=0)
bound2 = args[0] bound2 = args[0].coerce_to_integer(self.current_scope)
else: else:
bound1 = args[0] bound1 = args[0].coerce_to_integer(self.current_scope)
bound2 = args[1] bound2 = args[1].coerce_to_integer(self.current_scope)
step = step.coerce_to_integer(self.current_scope)
for_node = Nodes.ForFromStatNode( for_node = Nodes.ForFromStatNode(
node.pos, node.pos,
...@@ -151,8 +149,6 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -151,8 +149,6 @@ class IterationTransform(Visitor.VisitorTransform):
step=step, body=node.body, step=step, body=node.body,
else_clause=node.else_clause, else_clause=node.else_clause,
loopvar_name = node.target.entry.cname) loopvar_name = node.target.entry.cname)
for_node.reanalyse_c_loop(self.current_scope)
# for_node.analyse_expressions(self.current_scope)
return for_node return for_node
def _transform_dict_iteration(self, node, dict_obj, keys, values): def _transform_dict_iteration(self, node, dict_obj, keys, values):
......
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