Commit d5f88aac authored by Stefan Behnel's avatar Stefan Behnel

cleanup, keep for-range optimisation more local

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