1.1 --- a/micropython/inspect.py Mon Jun 01 21:10:47 2009 +0200
1.2 +++ b/micropython/inspect.py Mon Jun 01 23:06:55 2009 +0200
1.3 @@ -114,6 +114,7 @@
1.4 self.in_loop = 0 # Note loop "membership", affecting assignments.
1.5 self.namespaces = []
1.6 self.module = None
1.7 + self.functions = []
1.8
1.9 def parse(self, filename):
1.10
1.11 @@ -128,11 +129,16 @@
1.12
1.13 self.astnode = self.module = module
1.14 processed = self.dispatch(module)
1.15 +
1.16 + for node, namespaces in self.functions:
1.17 + self._visitFunctionBody(node, namespaces)
1.18 +
1.19 if self.has_key("__all__"):
1.20 all = self["__all__"]
1.21 if isinstance(all, compiler.ast.List):
1.22 for n in all.nodes:
1.23 self.store(n.value, self.importer.add_module(self.name + "." + n.value))
1.24 +
1.25 return processed
1.26
1.27 def vacuum(self):
1.28 @@ -346,22 +352,7 @@
1.29 self.expr = self.dispatch(n)
1.30 function.store_default(self.expr)
1.31
1.32 - # Enter the function.
1.33 -
1.34 - self.namespaces.append(function)
1.35 -
1.36 - # Current namespace is the function.
1.37 - # Previous namespace is the class.
1.38 -
1.39 - if len(self.namespaces) > 1 and isinstance(self.namespaces[-2], Class):
1.40 - if name == "__init__":
1.41 - self.in_init = 1
1.42 - self.in_method = 1
1.43 -
1.44 - self.dispatch(node.code)
1.45 - self.in_init = 0
1.46 - self.in_method = 0
1.47 - self.namespaces.pop()
1.48 + self.functions.append((node, self.namespaces + [function]))
1.49
1.50 if name is not None:
1.51 self.store(name, function)
1.52 @@ -383,6 +374,24 @@
1.53
1.54 return function
1.55
1.56 + def _visitFunctionBody(self, node, namespaces):
1.57 +
1.58 + "Enter the function."
1.59 +
1.60 + # Current namespace is the function.
1.61 + # Previous namespace is the class.
1.62 +
1.63 + if len(namespaces) > 1 and isinstance(namespaces[-2], Class):
1.64 + if namespaces[-1].name == "__init__":
1.65 + self.in_init = 1
1.66 + self.in_method = 1
1.67 +
1.68 + self.namespaces = namespaces
1.69 + self.dispatch(node.code)
1.70 +
1.71 + self.in_init = 0
1.72 + self.in_method = 0
1.73 +
1.74 # Specific handler methods.
1.75
1.76 visitAdd = _visitBinary