1.1 --- a/micropython/inspect.py Sun Jun 27 20:55:48 2010 +0200
1.2 +++ b/micropython/inspect.py Sun Jun 27 21:26:13 2010 +0200
1.3 @@ -614,17 +614,34 @@
1.4
1.5 cls = Class(node.name, self.get_namespace(), self, node)
1.6
1.7 + # Make a back reference from the node for code generation.
1.8 +
1.9 + node.unit = cls
1.10 +
1.11 + # Process base classes in the context of the class's namespace.
1.12 + # This confines references to such classes to the class instead of
1.13 + # the namespace in which it is defined.
1.14 +
1.15 + self.namespaces.append(cls)
1.16 +
1.17 # Visit the base class expressions, attempting to find concrete
1.18 # definitions of classes.
1.19
1.20 for base in node.bases:
1.21 expr = self.dispatch(base)
1.22 +
1.23 + # Each base class must be constant and known at compile-time.
1.24 +
1.25 if isinstance(expr, Attr):
1.26 if expr.assignments != 1:
1.27 raise InspectError("Base class %r for %r is not constant." % (base, cls.full_name()))
1.28 else:
1.29 cls.add_base(expr.get_value())
1.30 - else: # if expr is None:
1.31 +
1.32 + # Where no expression value is available, the base class is
1.33 + # not identifiable.
1.34 +
1.35 + else:
1.36 raise InspectError("Base class %r for %r is not found: it may be hidden in some way." % (base, cls.full_name()))
1.37
1.38 # NOTE: Potentially dubious measure to permit __init__ availability.
1.39 @@ -634,22 +651,19 @@
1.40 expr = self.dispatch(compiler.ast.Name("object"))
1.41 cls.add_base(expr.get_value())
1.42
1.43 - # Make a back reference from the node for code generation.
1.44 + # Make an entry for the class in the parent namespace.
1.45
1.46 - node.unit = cls
1.47 -
1.48 - # Make an entry for the class.
1.49 -
1.50 + self.namespaces.pop()
1.51 self.store(node.name, cls)
1.52 self.add_object(cls)
1.53
1.54 - # Process the class body.
1.55 + # Process the class body in its own namespace.
1.56
1.57 self.namespaces.append(cls)
1.58 self.dispatch(node.code)
1.59 - cls.finalise_attribute_usage()
1.60 self.namespaces.pop()
1.61
1.62 + cls.finalise_attribute_usage()
1.63 return cls
1.64
1.65 def visitCompare(self, node):