# HG changeset patch # User Paul Boddie # Date 1351814306 -3600 # Node ID 5d7a60729f293534e9df98371e0182919733c456 # Parent e341cf363eae3be2a9b239a5dd35e123ac9b5850 Removed the static labelling on attribute parents since the static information actually applied to the attributes and not to the parents. Introduced provisional tracking of unknown attribute accesses. diff -r e341cf363eae -r 5d7a60729f29 micropython/report.py --- a/micropython/report.py Fri Nov 02 00:36:01 2012 +0100 +++ b/micropython/report.py Fri Nov 02 00:58:26 2012 +0100 @@ -453,10 +453,14 @@ if attributes: self._span_end() + def _get_possible_types(self, attrname): + objtable = self.program.get_object_table() + return objtable.any_possible_objects([attrname]) + def _get_attributes(self, possible_types, attrname): objtable = self.program.get_object_table() attributes = [] - for target_name, is_static in possible_types: + for target_name in possible_types: target = objtable.get_object(target_name) try: attr = objtable.access(target_name, attrname) @@ -618,6 +622,8 @@ self.visitor = self self.module = module self.program = program + self.program.unknown_target_nodes = [] + self.units = [] def to_stream(self, stream): @@ -631,9 +637,13 @@ self.stream.write(html_footer) def visitModule(self, node): + self.units.append(node.unit) + self._doc(node, "module") self.default(node) + self.units.pop() + # Statements. def visitAssert(self, node): @@ -673,6 +683,8 @@ # Use inspected details where possible. cls = node.unit + self.units.append(cls) + bases = cls.bases self.stream.write("
\n" % cls.full_name()) @@ -718,6 +730,8 @@ self.stream.write("
\n") self.stream.write("\n") + self.units.pop() + def visitContinue(self, node): self.stream.write("
\n") self._keyword("continue") @@ -772,6 +786,8 @@ return fn = node.unit + self.units.append(fn) + self.stream.write("
\n" % fn.full_name()) # Write the declaration line. @@ -792,6 +808,8 @@ self.stream.write("
\n") self.stream.write("
\n") + self.units.pop() + def visitGlobal(self, node): self.stream.write("
\n") self._keyword("global") @@ -1021,21 +1039,19 @@ def visitAssAttr(self, node): possible_types = self.possible_accessor_types(node, defining_users=0) - target_names = set(["%s%s" % (is_static and "static " or "", target_name) - for target_name, is_static in possible_types]) attributes = self._get_attributes(possible_types, node.attrname) wraps_getattr = isinstance(node.expr, compiler.ast.Getattr) if not wraps_getattr: self._span_start("assattr") - self._accessor_start(target_names) + self._accessor_start(possible_types) self.dispatch(node.expr) if not wraps_getattr: - self._accessor_end(target_names) + 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 target_names and " no-targets" or "")) + self._span(node.attrname, "attrname" + (not possible_types and " no-targets" or "")) self._attribute_end(attributes) if not wraps_getattr: self._span_end() @@ -1121,25 +1137,23 @@ def visitGetattr(self, node): possible_types = self.possible_accessor_types(node, defining_users=0) - target_names = set(["%s%s" % (is_static and "static " or "", target_name) - for target_name, is_static in possible_types]) attributes = self._get_attributes(possible_types, node.attrname) wraps_getattr = isinstance(node.expr, compiler.ast.Getattr) if not wraps_getattr: self._span_start("getattr") - self._accessor_start(target_names) + self._accessor_start(possible_types) self.dispatch(node.expr) if not wraps_getattr: - self._accessor_end(target_names) + 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 target_names and " no-targets" or "")) + self._span(node.attrname, "attrname" + (not possible_types and " no-targets" or "")) self._attribute_end(attributes) if not wraps_getattr: @@ -1202,6 +1216,7 @@ def visitLambda(self, node): fn = node.unit + self.units.append(fn) self._span_start("lambda") self._keyword("lambda") @@ -1212,6 +1227,8 @@ self._span_end() self._span_end() + self.units.pop() + def visitLeftShift(self, node): self._visitBinary(node, "<<") @@ -1409,6 +1426,16 @@ self.stream.write("=") self.dispatch(default) + # Statistics gathering methods. + + 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 + # Convenience functions. def summarise(module, program, filename):