Get a Variable by name from this block recursively. Args: name(str): the Variable's name. Returns: Variable: the Variable with the giving name. Or None if not found.
(self, name)
| 4526 | return v |
| 4527 | |
| 4528 | def _find_var_recursive(self, name): |
| 4529 | """ |
| 4530 | Get a Variable by name from this block recursively. |
| 4531 | |
| 4532 | Args: |
| 4533 | name(str): the Variable's name. |
| 4534 | |
| 4535 | Returns: |
| 4536 | Variable: the Variable with the giving name. Or None if not found. |
| 4537 | """ |
| 4538 | frontier = [] |
| 4539 | visited = set() |
| 4540 | |
| 4541 | frontier.append(self) |
| 4542 | |
| 4543 | prog = self.program |
| 4544 | |
| 4545 | while len(frontier) != 0: # BFS |
| 4546 | cur = frontier[0] |
| 4547 | frontier = frontier[1:] |
| 4548 | |
| 4549 | if id(cur) in visited: |
| 4550 | continue |
| 4551 | |
| 4552 | if cur.has_var(name): |
| 4553 | return cur.var(name) |
| 4554 | |
| 4555 | if cur.parent_idx != -1: |
| 4556 | frontier.append(prog.block(cur.parent_idx)) |
| 4557 | |
| 4558 | if cur.forward_block_idx != -1: |
| 4559 | frontier.append(prog.block(cur.forward_block_idx)) |
| 4560 | |
| 4561 | visited.add(id(cur)) |
| 4562 | return None |
| 4563 | |
| 4564 | def _var_recursive(self, name): |
| 4565 | """ |