165 if not self.__checkCodes: |
173 if not self.__checkCodes: |
166 # don't do anything, if no codes were selected |
174 # don't do anything, if no codes were selected |
167 return |
175 return |
168 |
176 |
169 # Add parent information |
177 # Add parent information |
170 for node in ast.walk(self.__tree): |
178 self.__addMeta(self.__tree) |
171 for child in ast.iter_child_nodes(node): |
|
172 child.parent = node # type: ignore |
|
173 |
179 |
174 visitor = SimplifyNodeVisitor(self.__error) |
180 visitor = SimplifyNodeVisitor(self.__error) |
175 visitor.visit(self.__tree) |
181 visitor.visit(self.__tree) |
|
182 |
|
183 def __addMeta(self, root, level=0): |
|
184 """ |
|
185 Private method to amend the nodes of the given AST tree with backward and |
|
186 forward references. |
|
187 |
|
188 @param root reference to the root node of the tree |
|
189 @type ast.AST |
|
190 @param level nesting level (defaults to 0) |
|
191 @type int (optional) |
|
192 """ |
|
193 previousSibling = None |
|
194 for node in ast.iter_child_nodes(root): |
|
195 if level == 0: |
|
196 node.parent = root |
|
197 node.previous_sibling = previousSibling |
|
198 node.next_sibling = None |
|
199 if previousSibling: |
|
200 node.previous_sibling.next_sibling = node |
|
201 previousSibling = node |
|
202 for child in ast.iter_child_nodes(node): |
|
203 child.parent = node |
|
204 self.__addMeta(node, level=level + 1) |