| 8 | |
| 9 | |
| 10 | class PatternMatchingVisitor: |
| 11 | def __init__(self, pattern: ASTPattern): |
| 12 | self.p = pattern |
| 13 | self.q = deque() |
| 14 | self.call_graph = CallGraph() |
| 15 | self.hits = [] |
| 16 | self.normalized_path = "pytest_src" |
| 17 | self.path = self.normalized_path |
| 18 | |
| 19 | def traverse(self, initial_node): |
| 20 | self.q.clear() |
| 21 | self.q.append(Context(node=initial_node, parent=None, visitor=self)) |
| 22 | |
| 23 | while len(self.q): |
| 24 | ctx = self.q.popleft() |
| 25 | if self.p.match(ctx.node): |
| 26 | self.p.apply(ctx) |
| 27 | return ctx.node |
| 28 | |
| 29 | if isinstance(ctx.node, ASTNode): |
| 30 | ctx.node._visit_node(ctx) |
| 31 | |
| 32 | return False |
| 33 | |
| 34 | def push(self, ctx): |
| 35 | self.q.append(ctx) |
| 36 | |
| 37 | |
| 38 | CASES = ( |
no outgoing calls