Commit db144000 authored by root's avatar root

Removed reused references in tree. Tweaked style.

parent 2d146971
...@@ -661,66 +661,80 @@ class IterationTransform(Visitor.EnvTransform): ...@@ -661,66 +661,80 @@ class IterationTransform(Visitor.EnvTransform):
bound1, bound2 = bound2, bound1 bound1, bound2 = bound2, bound1
abs_step = abs(step_value) abs_step = abs(step_value)
if abs_step != 1: if abs_step != 1:
if not (isinstance(bound1.constant_result, (int, long)) and if (isinstance(bound1.constant_result, (int, long)) and
isinstance(bound2.constant_result, (int, long))): isinstance(bound2.constant_result, (int, long))):
if step_value < 0:
begin_value = bound2.constant_result
end_value = bound1.constant_result
bound1_value = begin_value - abs_step * ((begin_value - end_value - 1) // abs_step) - 1
else:
begin_value = bound1.constant_result
end_value = bound2.constant_result
bound1_value = end_value + abs_step * ((begin_value - end_value - 1) // abs_step) + 1
bound1 = ExprNodes.IntNode(
bound1.pos, value=str(bound1_value), constant_result=bound1_value,
type=PyrexTypes.spanning_type(bound1.type, bound2.type))
else:
spanning_type = PyrexTypes.spanning_type(bound1.type, bound2.type) spanning_type = PyrexTypes.spanning_type(bound1.type, bound2.type)
spanning_step_type = PyrexTypes.spanning_type(spanning_type, step.type) spanning_step_type = PyrexTypes.spanning_type(spanning_type, step.type)
if step_value < 0: if step_value < 0:
begin_value = bound2 begin_value = copy.copy(bound2)
end_value = bound1 end_value = copy.copy(bound1)
final_op = '-' final_op = '-'
final_node = ExprNodes.SubNode final_node = ExprNodes.SubNode
else: else:
begin_value = bound1 begin_value = copy.copy(bound1)
end_value = bound2 end_value = copy.copy(bound2)
final_op = '+' final_op = '+'
final_node = ExprNodes.AddNode final_node = ExprNodes.AddNode
beg_sub_end = ExprNodes.SubNode(bound1.pos,
bound1 = final_node(
bound1.pos,
operand1=final_node(
bound1.pos,
operand1=copy.copy(bound2),
operator=final_op,
operand2=ExprNodes.MulNode(
bound1.pos,
operand1=ExprNodes.IntNode(
bound1.pos,
value=str(abs_step),
constant_value=abs_step,
type=spanning_step_type),
operator='*',
operand2=ExprNodes.DivNode(
bound1.pos,
operand1=ExprNodes.SubNode(
bound1.pos,
operand1=ExprNodes.SubNode(
bound1.pos,
operand1=begin_value, operand1=begin_value,
operator='-', operator='-',
operand2=end_value, operand2=end_value,
type=spanning_type) type=spanning_type),
one_node = ExprNodes.IntNode(bound1.pos, value='1', constant_result=1)
beg_sub_end_sub_1 = ExprNodes.SubNode(bound1.pos,
operand1=beg_sub_end,
operator='-', operator='-',
operand2=one_node, operand2=ExprNodes.IntNode(
type=spanning_step_type) bound1.pos,
abs_step_node = ExprNodes.IntNode(bound1.pos, value=str(abs_step), constant_value=abs_step) value='1',
div_val_node = ExprNodes.DivNode(bound1.pos, constant_result=1),
operand1=beg_sub_end_sub_1, type=spanning_step_type),
operator='//', operator='//',
operand2=abs_step_node, operand2=ExprNodes.IntNode(
type=spanning_step_type) bound1.pos,
delta_node = ExprNodes.MulNode(bound1.pos, value=str(abs_step),
operand1=abs_step_node, constant_value=abs_step,
operator='*', type=spanning_step_type),
operand2=div_val_node, type=spanning_step_type),
type=spanning_step_type) type=spanning_step_type),
beg_func_delta = final_node(bound1.pos, type=spanning_step_type),
operand1=bound2,
operator=final_op,
operand2=delta_node,
type=spanning_step_type)
bound1 = final_node(bound1.pos,
operand1=beg_func_delta,
operator=final_op, operator=final_op,
operand2=one_node, operand2=ExprNodes.IntNode(
bound1.pos,
value='1',
constant_result=1),
type=spanning_type) type=spanning_type)
else:
if step_value < 0:
begin_value = bound2.constant_result
end_value = bound1.constant_result
bound1_value = begin_value - abs_step * ((begin_value - end_value - 1) // abs_step) - 1
else:
begin_value = bound1.constant_result
end_value = bound2.constant_result
bound1_value = end_value + abs_step * ((begin_value - end_value - 1) // abs_step) + 1
bound1 = ExprNodes.IntNode(
bound1.pos, value=str(bound1_value), constant_result=bound1_value,
type=PyrexTypes.spanning_type(bound1.type, bound2.type))
if step_value < 0: if step_value < 0:
step_value = -step_value step_value = -step_value
......
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