1.1 --- a/micropython/common.py Sat Jul 14 21:46:38 2012 +0200
1.2 +++ b/micropython/common.py Sat Jul 14 23:27:43 2012 +0200
1.3 @@ -19,8 +19,9 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from compiler.ast import Class, Function, Module, AssAttr, Getattr, Name
1.8 -from micropython.data import Attr
1.9 +from compiler.ast import AssAttr, Getattr, Name
1.10 +import compiler.ast
1.11 +from micropython.data import Attr, Class, Module
1.12 from micropython.errors import *
1.13
1.14 try:
1.15 @@ -55,7 +56,7 @@
1.16
1.17 # NOTE: Should perhaps specialise the subclasses appropriately.
1.18
1.19 - if isinstance(self, (Class, Function, Module)):
1.20 + if isinstance(self, (compiler.ast.Class, compiler.ast.Function, compiler.ast.Module)):
1.21 exc.unit_name = self.unit.full_name()
1.22 else:
1.23 exc.unit_name = self.full_name()
1.24 @@ -81,13 +82,35 @@
1.25
1.26 if isinstance(node, (AssAttr, Getattr, Name)):
1.27
1.28 + # Use any explicit attribute annotation.
1.29 +
1.30 if isinstance(node._attr, Attr):
1.31 attr = node._attr
1.32 target_names.add((attr.parent.full_name(), attr.is_static_attribute()))
1.33 + return target_names
1.34 +
1.35 + # Otherwise, try and use an expression annotation.
1.36 +
1.37 + if isinstance(node, (AssAttr, Getattr)):
1.38 + expr = node._expr
1.39 +
1.40 + if isinstance(expr, Attr) and expr.get_value():
1.41 + expr = expr.get_value()
1.42 +
1.43 + if isinstance(expr, Class):
1.44 + attr = expr.all_class_attributes().get(node.attrname)
1.45 + elif isinstance(expr, Module):
1.46 + attr = expr.get(node.attrname)
1.47 + else:
1.48 + attr = None
1.49 +
1.50 + if attr:
1.51 + target_names.add((attr.parent.full_name(), attr.is_static_attribute()))
1.52 + return target_names
1.53
1.54 # Otherwise, attempt to employ the attribute usage observations.
1.55
1.56 - elif node._attrusers:
1.57 + if node._attrusers:
1.58
1.59 # Visit each attribute user.
1.60
2.1 --- a/micropython/inspect.py Sat Jul 14 21:46:38 2012 +0200
2.2 +++ b/micropython/inspect.py Sat Jul 14 23:27:43 2012 +0200
2.3 @@ -840,19 +840,30 @@
2.4 self.use_attribute(expr.name, attrname, value)
2.5 self._visitAttrUser(expr, attrname, node, self.expr)
2.6
2.7 + # No definite attribute can be identified, since the instance
2.8 + # being accessed may be a subclass of the method's class.
2.9 +
2.10 + attr = make_instance()
2.11 +
2.12 elif isinstance(value, Module):
2.13 self.store_module_attr(attrname, value)
2.14 + attr = value.get(attrname)
2.15
2.16 elif isinstance(value, Class):
2.17 self.store_class_attr(attrname, value)
2.18 + attr = value.get(attrname)
2.19
2.20 # Note usage of the attribute where a local is involved.
2.21
2.22 else:
2.23 self._visitAttrUser(expr, attrname, node, self.expr)
2.24 + attr = make_instance()
2.25
2.26 else:
2.27 self.use_name(attrname, node)
2.28 + attr = make_instance()
2.29 +
2.30 + node._attr = attr
2.31
2.32 def visitAssList(self, node):
2.33
2.34 @@ -1155,9 +1166,8 @@
2.35 visitGenExprInner = NOP
2.36
2.37 def visitGetattr(self, node):
2.38 - expr = self.dispatch(node.expr)
2.39 - attrname = node.attrname
2.40 - node._attr = self._visitAttr(expr, attrname, node)
2.41 + node._expr = self.dispatch(node.expr)
2.42 + node._attr = self._visitAttr(node._expr, node.attrname, node)
2.43 return node._attr
2.44
2.45 def visitGlobal(self, node):