# HG changeset patch # User Paul Boddie # Date 1351899347 -3600 # Node ID 1788ce04ced0b4448f5e0313e38acea37dab530b # Parent 327b862e58b67812681ee6746c9468adcda2613a Moved target discovery using single attributes to the appropriate report methods in order to be able to display the resulting information differently when such measures are required. diff -r 327b862e58b6 -r 1788ce04ced0 micropython/report.py --- a/micropython/report.py Fri Nov 02 01:16:08 2012 +0100 +++ b/micropython/report.py Sat Nov 03 00:35:47 2012 +0100 @@ -91,6 +91,11 @@ color: white; } + .any-target { + background-color: #d60; + color: white; + } + .attr, .accessor, .name, @@ -1039,6 +1044,14 @@ def visitAssAttr(self, node): possible_types = self.possible_accessor_types(node, defining_users=0) + + # Record whether types were already deduced. If not, get types using + # only this attribute. + + deduced = possible_types + if not possible_types: + possible_types = self._get_possible_types(node.attrname) + attributes = self._get_attributes(possible_types, node.attrname) wraps_getattr = self._has_descendant(node.expr, compiler.ast.Getattr) @@ -1051,7 +1064,7 @@ self._accessor_end(possible_types) self.stream.write(".") self._attribute_start(node.attrname, self._attributes_to_attribute_names(attributes, node.attrname)) - self._span(node.attrname, "attrname" + (not possible_types and " no-targets" or "")) + self._span(node.attrname, "attrname" + (not possible_types and " no-targets" or not deduced and " any-target" or "")) self._attribute_end(attributes) if not wraps_getattr: self._span_end() @@ -1137,6 +1150,14 @@ def visitGetattr(self, node): possible_types = self.possible_accessor_types(node, defining_users=0) + + # Record whether types were already deduced. If not, get types using + # only this attribute. + + deduced = possible_types + if not possible_types: + possible_types = self._get_possible_types(node.attrname) + attributes = self._get_attributes(possible_types, node.attrname) wraps_getattr = self._has_descendant(node.expr, compiler.ast.Getattr) @@ -1153,7 +1174,7 @@ self.stream.write(".") self._attribute_start(node.attrname, self._attributes_to_attribute_names(attributes, node.attrname)) - self._span(node.attrname, "attrname" + (not possible_types and " no-targets" or "")) + self._span(node.attrname, "attrname" + (not possible_types and " no-targets" or not deduced and " any-target" or "")) self._attribute_end(attributes) if not wraps_getattr: @@ -1431,8 +1452,6 @@ def possible_accessor_types(self, node, defining_users=1): possible_types = [tn for (tn, st) in ASTVisitor.possible_accessor_types(self, node, defining_users)] if not possible_types: - possible_types = self._get_possible_types(node.attrname) - if not possible_types: self.program.unknown_target_nodes.append((self.units[-1], node)) return possible_types