# HG changeset patch # User Paul Boddie # Date 1340917082 -7200 # Node ID 875b09b3d3559964eecd81066a1eb0290a64f9f2 # Parent 499e42c00d574af271adf17212bfd7a61a86ad4a Removed usage gathering for module globals by introducing Module-specific methods. Added _attr annotations for attribute accessors, using them in reports via the possible_accessor_types ASTVisitor method. Fixed imports in the common module. diff -r 499e42c00d57 -r 875b09b3d355 docs/annotations.txt --- a/docs/annotations.txt Wed Jun 27 01:32:38 2012 +0200 +++ b/docs/annotations.txt Thu Jun 28 22:58:02 2012 +0200 @@ -3,6 +3,12 @@ These annotations should be defined in the revised compiler.ast classes. +Evaluation Results +------------------ + +_attr notes the result associated with an attribute access + operation during inspection + Attribute Users --------------- diff -r 499e42c00d57 -r 875b09b3d355 micropython/common.py --- a/micropython/common.py Wed Jun 27 01:32:38 2012 +0200 +++ b/micropython/common.py Thu Jun 28 22:58:02 2012 +0200 @@ -19,7 +19,8 @@ this program. If not, see . """ -from micropython.basicdata import Instance +from micropython.data import Attr, Instance +from micropython.errors import * import sys # Visitors and activities related to node annotations. @@ -69,7 +70,14 @@ target_names = set() - if hasattr(node, "_attrusers"): + if hasattr(node, "_attr") and not isinstance(node._attr, Instance): + attr = node._attr + if isinstance(attr, Attr): + target_names.add((attr.parent.full_name(), attr.is_static_attribute())) + else: + target_names.add((attr.full_name(), attr.is_static_attribute())) + + elif hasattr(node, "_attrusers"): # Visit each attribute user. diff -r 499e42c00d57 -r 875b09b3d355 micropython/data.py --- a/micropython/data.py Wed Jun 27 01:32:38 2012 +0200 +++ b/micropython/data.py Thu Jun 28 22:58:02 2012 +0200 @@ -685,6 +685,16 @@ if not hasattr(node, "_attrdefs"): node._attrdefs = [] + def _define_attribute_accessor(self, name, attrname, node, value): + + # NOTE: Revisiting of nodes may occur for loops. + + if not hasattr(node, "_attrusers"): + node._attrusers = set() + + node._attrusers.update(self.use_attribute(name, attrname, value)) + node._username = name + # Branch management methods. def _new_branchpoint(self, loop_node=None): @@ -2043,6 +2053,26 @@ return dict(self) + # Attribute usage methods that do not apply to module globals. + + def _define_attribute_user(self, node): + pass + + def _use_attribute(self, name, attrname, value=None): + + """ + Record usage for 'name' of 'attrname' (and optional assignment 'value') + by recording general name usage. + """ + + self.importer.use_name(attrname, self.full_name(), value) + + def _init_attribute_user(self, node): + pass + + def _define_attribute_accessor(self, name, attrname, node, value): + pass + # Pre-made instances. type_class = TypeClass("type") # details to be filled in later diff -r 499e42c00d57 -r 875b09b3d355 micropython/inspect.py --- a/micropython/inspect.py Wed Jun 27 01:32:38 2012 +0200 +++ b/micropython/inspect.py Thu Jun 28 22:58:02 2012 +0200 @@ -457,6 +457,16 @@ return self.get_namespace()._use_specific_attribute(objname, attrname, from_name) + def define_attribute_accessor(self, name, attrname, node, value=None): + + """ + Note applicable attribute users providing the given 'name' when + accessing the given 'attrname' on the specified 'node', with the + optional 'value' indicating an assignment. + """ + + self.get_namespace()._define_attribute_accessor(name, attrname, node, value) + # Visitor methods. def default(self, node, *args): @@ -588,14 +598,7 @@ # independently of the namespace). if expr.parent is self.get_namespace() and not self.get_namespace() is self: - - # NOTE: Revisiting of nodes may occur for loops. - - if not hasattr(node, "_attrusers"): - node._attrusers = set() - - node._attrusers.update(self.use_attribute(expr.name, attrname, value)) - node._username = expr.name + self.define_attribute_accessor(expr.name, attrname, node, value) else: self.use_name(attrname, node.expr, value) @@ -715,7 +718,7 @@ if expr.name == "self": self.store_instance_attr(attrname) - self.use_attribute(expr.name, attrname, value) # NOTE: Impose constraints on the type given the hierarchy. + self.use_attribute(expr.name, attrname, value) self._visitAttrUser(expr, attrname, node, self.expr) elif isinstance(value, Module): @@ -1039,7 +1042,8 @@ def visitGetattr(self, node): expr = self.dispatch(node.expr) attrname = node.attrname - return self._visitAttr(expr, attrname, node) + node._attr = self._visitAttr(expr, attrname, node) + return node._attr def visitGlobal(self, node): if self.namespaces: