def do_Loop(self, node):
''' For and While loops are treated the same. The only difference is
the possibility of iterators in a For loop.
The loop body always returns to test unless there is a break or
return.
The else body is entered when the test is false but not when there
is a break or an exception.
The next block of the test could in theory be the else or after.
But when we access it for the breaks we want it to be the after. '''
# Put the test in its own block
test_block = self.current_block
test_block.tag = Block.LOOP_HEADER
self.push_frame_block(F_BLOCK_LOOP, test_block)
after_loop_block = self.new_block()
loop_body_block = self.new_block()
self.add_to_exits(test_block, loop_body_block)
test_block.next = after_loop_block
self.use_block(loop_body_block)
for z in node.body:
self.visit(z)
self.check_child_exits(self.current_block, test_block)
self.pop_frame_block(F_BLOCK_LOOP, test_block)
if node.orelse:
else_body = self.new_block()
self.add_to_exits(test_block, else_body)
self.use_block(else_body)
else_body.next = after_loop_block
for z in node.orelse:
self.visit(z)
self.check_child_exits(self.current_block, after_loop_block)
else:
self.add_to_exits(test_block, after_loop_block)
self.use_next_block(after_loop_block)
评论列表
文章目录