summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-03-18 10:03:13 +0100
committerEmile Anclin <emile.anclin@logilab.fr>2010-03-18 10:03:13 +0100
commit3db03d809b40839fc146996f5e7b7f0f024cf38f (patch)
tree2da1530b79b0cc20dec16912dd23920c79c0b21e
parent24c39e3880d6a1a11d3fb0a1416d6aa038997a2d (diff)
downloadastroid-git-3db03d809b40839fc146996f5e7b7f0f024cf38f.tar.gz
remove two useless function calls on tree rebuilding.
* rename 'walk' to 'build' * the tree starts always with a Module node, so we can call directly 'visit_module' in the 'build' method, * hence remove '_visit_module'. --HG-- branch : rebuild
-rw-r--r--_nodes_ast.py2
-rw-r--r--_nodes_compiler.py2
-rw-r--r--builder.py2
-rw-r--r--rebuilder.py36
-rw-r--r--scoped_nodes.py4
5 files changed, 21 insertions, 25 deletions
diff --git a/_nodes_ast.py b/_nodes_ast.py
index f6b4fb9e..9c06cf19 100644
--- a/_nodes_ast.py
+++ b/_nodes_ast.py
@@ -490,7 +490,7 @@ class TreeRebuilder(RebuildVisitor):
newnode.set_line_info(newnode.last_child())
return newnode
- def _visit_module(self, node, parent):
+ def visit_module(self, node, parent):
"""visit a Module node by returning a fresh instance of it"""
newnode = new.Module()
_lineno_parent(node, newnode, parent)
diff --git a/_nodes_compiler.py b/_nodes_compiler.py
index 573c548b..a6b54897 100644
--- a/_nodes_compiler.py
+++ b/_nodes_compiler.py
@@ -545,7 +545,7 @@ class TreeRebuilder(RebuildVisitor):
newnode.generators = [self.visit(child, newnode) for child in node.quals]
return newnode
- def _visit_module(self, node, parent):
+ def visit_module(self, node, parent):
"""visit a Module node by returning a fresh instance of it"""
newnode = new.Module()
self._set_infos(node, newnode, parent)
diff --git a/builder.py b/builder.py
index 6df3657f..8a820133 100644
--- a/builder.py
+++ b/builder.py
@@ -142,7 +142,7 @@ class ASTNGBuilder:
else:
package = path and path.find('__init__.py') > -1 or False
node.name = modname # we need the name during the rebuilding prcess
- newnode = self.rebuilder.walk(node)
+ newnode = self.rebuilder.build(node)
newnode.pure_python = True
newnode.package = package
newnode.file = newnode.path = node_file
diff --git a/rebuilder.py b/rebuilder.py
index 2cab2470..4084d25b 100644
--- a/rebuilder.py
+++ b/rebuilder.py
@@ -22,12 +22,12 @@ order to get a single ASTNG representation
from logilab.astng import ASTNGBuildingException, InferenceError
from logilab.astng import nodes
-from logilab.astng.utils import ASTVisitor, REDIRECT, _check_children
+from logilab.astng.utils import REDIRECT
from logilab.astng.bases import YES, Instance
-class RebuildVisitor(ASTVisitor):
+class RebuildVisitor(object):
"""Visitor to transform an AST to an ASTNG
"""
def __init__(self, manager):
@@ -45,15 +45,22 @@ class RebuildVisitor(ASTVisitor):
visit_method = getattr(self, visit_name)
return visit_method(node, parent)
- def walk(self, node):
- """start the walk down the tree and do some work after it"""
- newnode = self.visit(node, None)
+ def build(self, node):
+ """rebuild the tree starting with an Module node;
+ return an astng.Module node
+ """
+ self._metaclass = ['']
+ self._global_names = []
+ module = self.visit_module(node, None)
+ # init module cache here else we may get some infinite recursion
+ # errors while infering delayed assignments
+ if self._manager is not None:
+ self._manager._cache[module.name] = module
# handle delayed assattr nodes
delay_assattr = self.delayed_assattr
- for node in self._delayed_assattr:
- delay_assattr(node)
- _check_children(newnode)
- return newnode
+ for delayed in self._delayed_assattr:
+ delay_assattr(delayed)
+ return module
def _save_argument_name(self, node):
"""save argument names in locals"""
@@ -180,17 +187,6 @@ class RebuildVisitor(ASTVisitor):
name = asname or name
newnode.parent.set_local(name.split('.')[0], newnode)
- def visit_module(self, node, parent):
- """visit an Module node to become astng"""
- self._metaclass = ['']
- self._global_names = []
- module = self._visit_module(node, parent)
- # init module cache here else we may get some infinite recursion
- # errors while infering delayed assignments
- if self._manager is not None:
- self._manager._cache[module.name] = module
- return module
-
def visit_pass(self, node, parent):
"""visit a Pass node by returning a fresh instance of it"""
newnode = nodes.Pass()
diff --git a/scoped_nodes.py b/scoped_nodes.py
index 794680b9..6d2852fa 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -35,8 +35,8 @@ from logilab.astng import MANAGER, NotFoundError, NoDefault, \
from logilab.astng.node_classes import (Const, DelName, DelAttr,
Dict, From, List, Name, Pass, Raise, Return, Tuple, Yield,
are_exclusive, LookupMixIn, const_factory as cf, unpack_infer)
-from logilab.astng.bases import (NodeNG, BaseClass, YES, InferenceContext, Instance,
- Generator, UnboundMethod, BoundMethod, _infer_stmts, copy_context)
+from logilab.astng.bases import (NodeNG, BaseClass, InferenceContext, Instance,
+ YES, Generator, UnboundMethod, BoundMethod, _infer_stmts, copy_context)
from logilab.astng.mixins import (StmtMixIn, FilterStmtsMixin)
from logilab.astng.nodes_as_string import as_string