1.1 --- a/micropython/inspect.py Tue Mar 04 00:41:53 2008 +0100
1.2 +++ b/micropython/inspect.py Sun Mar 09 02:10:12 2008 +0100
1.3 @@ -151,10 +151,6 @@
1.4 attr.assignments = 1
1.5 attr.assignment_values.add(value)
1.6
1.7 - "A specialised set operation for parameters."
1.8 -
1.9 - set_parameter = set_module
1.10 -
1.11 def _set(self, name, value):
1.12
1.13 "The underlying set operation associating 'name' with 'value'."
1.14 @@ -220,7 +216,7 @@
1.15
1.16 class Attr:
1.17
1.18 - "An attribute entry."
1.19 + "An attribute entry having a parent as context."
1.20
1.21 def __init__(self, position, parent, name, value=None, assignments=None):
1.22 self.position = position
1.23 @@ -261,10 +257,11 @@
1.24
1.25 class Const:
1.26
1.27 - "A constant object."
1.28 + "A constant object with no parent defined as its context."
1.29
1.30 def __init__(self, value):
1.31 self.value = value
1.32 + self.parent = None
1.33
1.34 # Image generation details.
1.35
1.36 @@ -287,6 +284,12 @@
1.37 "An inspected class."
1.38
1.39 def __init__(self, name, parent, global_namespace=None, node=None):
1.40 +
1.41 + """
1.42 + Initialise the class with the given 'name', 'parent' object, optional
1.43 + 'global_namespace' and optional AST 'node'.
1.44 + """
1.45 +
1.46 NamespaceDict.__init__(self, global_namespace)
1.47 self.name = name
1.48 self.parent = parent
1.49 @@ -512,7 +515,7 @@
1.50
1.51 d = {}
1.52 for i, name in enumerate(self._get_position_list(positions)):
1.53 - d[name] = Attr(i, None, None, name)
1.54 + d[name] = Attr(i, Instance(), name, None)
1.55 return d
1.56
1.57 def _cmp_positions(self, a, b):
1.58 @@ -586,7 +589,7 @@
1.59 if isinstance(name, tuple):
1.60 self._add_parameters(name)
1.61 else:
1.62 - self.set_parameter(name, None)
1.63 + self.set(name, None)
1.64
1.65 def __repr__(self):
1.66 if self.location is not None:
1.67 @@ -633,6 +636,29 @@
1.68 del self.localnames[name]
1.69 return self.localnames
1.70
1.71 + def is_relocated(self, name):
1.72 +
1.73 + """
1.74 + Determine whether the given attribute 'name' is relocated for instances
1.75 + having this function as a method.
1.76 + """
1.77 +
1.78 + for cls in self.parent.descendants:
1.79 + if name in cls.relocated:
1.80 + return 1
1.81 + return 0
1.82 +
1.83 + def finalise_attributes(self):
1.84 +
1.85 + "Make sure all attributes are fully defined."
1.86 +
1.87 + for i, name in enumerate(self.argnames):
1.88 + self[name].position = i
1.89 +
1.90 + j = i
1.91 + for i, attr in enumerate(self.locals()):
1.92 + attr.position = i + j
1.93 +
1.94 class UnresolvedName(NamespaceDict):
1.95
1.96 "A module, class or function which was mentioned but could not be imported."
1.97 @@ -657,6 +683,13 @@
1.98 else:
1.99 return self.parent_name
1.100
1.101 +class Instance:
1.102 +
1.103 + "A placeholder indicating the involvement of an instance."
1.104 +
1.105 + def __repr__(self):
1.106 + return "Instance()"
1.107 +
1.108 class Module(NamespaceDict):
1.109
1.110 "An inspected module's core details."