1.1 --- a/micropython/inspect.py Sun Jun 13 02:24:35 2010 +0200
1.2 +++ b/micropython/inspect.py Mon Jun 14 01:46:42 2010 +0200
1.3 @@ -93,13 +93,12 @@
1.4 """
1.5
1.6 ASTVisitor.__init__(self)
1.7 - Module.__init__(self, name)
1.8 + Module.__init__(self, name, importer)
1.9 self.visitor = self
1.10
1.11 # Import machinery links.
1.12
1.13 - self.importer = importer
1.14 - self.optimisations = importer.optimisations
1.15 + self.optimisations = self.importer.optimisations
1.16 self.builtins = self.importer.modules.get("__builtins__")
1.17 self.loaded = 0
1.18
1.19 @@ -114,7 +113,6 @@
1.20 self.in_function = 0 # Note function presence, affecting definitions.
1.21 self.in_loop = 0 # Note loop "membership", affecting assignments.
1.22 self.namespaces = []
1.23 - self.module = None
1.24 self.functions = []
1.25
1.26 def parse(self, filename):
1.27 @@ -128,7 +126,7 @@
1.28
1.29 "Process the given 'module'."
1.30
1.31 - self.astnode = self.module = module
1.32 + self.astnode = module
1.33
1.34 # Add __name__ to the namespace by adding an explicit assignment to the
1.35 # module.
1.36 @@ -387,20 +385,6 @@
1.37
1.38 return self.get_namespace()._use_attribute(name, attrname)
1.39
1.40 - def use_specific_attribute(self, objname, attrname):
1.41 -
1.42 - """
1.43 - Note attribute usage specifically on 'objname' - an object which is
1.44 - known at inspection time - or in the current unit if 'objname' is None,
1.45 - nominating a specific attribute 'attrname'.
1.46 -
1.47 - This bypasses attribute user mechanisms.
1.48 - """
1.49 -
1.50 - from_name = self.get_namespace().full_name()
1.51 - objname = objname or from_name
1.52 - self.importer.use_specific_name(objname, attrname, from_name)
1.53 -
1.54 # Visitor methods.
1.55
1.56 def default(self, node, *args):
1.57 @@ -933,60 +917,7 @@
1.58 visitMul = _visitBinary
1.59
1.60 def visitName(self, node):
1.61 - name = node.name
1.62 -
1.63 - # Constants.
1.64 -
1.65 - if self.importer.predefined_constants.has_key(name):
1.66 - attr = self.importer.get_predefined_constant(name)
1.67 - node._scope = "constant"
1.68 -
1.69 - # Locals.
1.70 -
1.71 - elif self.namespaces and self.namespaces[-1].has_key(name):
1.72 - attr = self.namespaces[-1][name]
1.73 -
1.74 - # Note usage of the local (potentially a class attribute).
1.75 -
1.76 - self.use_specific_attribute(None, name)
1.77 - node._scope = "local"
1.78 -
1.79 - # Globals.
1.80 -
1.81 - elif self.has_key(name):
1.82 - attr = self[name]
1.83 -
1.84 - # Note usage of the module attribute.
1.85 -
1.86 - self.use_specific_attribute(self.full_name(), name)
1.87 - node._scope = "global"
1.88 -
1.89 - # Note global usage in any local namespace.
1.90 -
1.91 - if self.namespaces:
1.92 - self.namespaces[-1].note_scope(name, "global")
1.93 -
1.94 - # Builtins.
1.95 -
1.96 - elif self.builtins is not None and self.builtins.has_key(name):
1.97 - attr = self.builtins[name]
1.98 - self.use_specific_attribute(self.builtins.full_name(), name)
1.99 - node._scope = "builtins"
1.100 -
1.101 - # Note builtins usage in any local namespace.
1.102 -
1.103 - if self.namespaces:
1.104 - self.namespaces[-1].note_scope(name, "builtins")
1.105 - else:
1.106 - self.note_scope(name, "builtins")
1.107 -
1.108 - # Unknown.
1.109 -
1.110 - else:
1.111 - attr = None
1.112 - self.use_name(name)
1.113 -
1.114 - return attr
1.115 + return self.get_namespace().get_using_node(node.name, node)
1.116
1.117 visitNot = OP
1.118