# HG changeset patch # User Paul Boddie # Date 1341774112 -7200 # Node ID cde9f22a20244582ff1b51d83427d30f44b6af92 # Parent f391131fd7c6504277eb0efddf08c0c4d547ebc7 Added value annotations to Name nodes, showing such values in reports if known. diff -r f391131fd7c6 -r cde9f22a2024 micropython/inspect.py --- a/micropython/inspect.py Sun Jul 08 19:21:56 2012 +0200 +++ b/micropython/inspect.py Sun Jul 08 21:01:52 2012 +0200 @@ -1316,7 +1316,9 @@ visitMul = _visitOperator def visitName(self, node): - return self.get_namespace().get_using_node(node.name, node) or make_instance() + attr = self.get_namespace().get_using_node(node.name, node) or make_instance() + node._attr = attr + return attr def visitNot(self, node): self.use_name("__bool__", node) diff -r f391131fd7c6 -r cde9f22a2024 micropython/report.py --- a/micropython/report.py Sun Jul 08 19:21:56 2012 +0200 +++ b/micropython/report.py Sun Jul 08 21:01:52 2012 +0200 @@ -129,7 +129,8 @@ } .attrnames a, - .opnames a { + .opnames a, + .scope a { color: white; } @@ -287,8 +288,14 @@ classes or "specific-ref", module_name, os.path.extsep, self._attr(full_name), self._text(name))) - def _scope(self, scope): - self.stream.write("
scope
%s
\n" % scope) + def _scope(self, scope, attr): + self.stream.write("
" + "scope
%s
" % scope) + values = self._values_to_attribute_names(attr) + if values: + self.stream.write("values
") + self._attribute_list(values) + self.stream.write("
\n") def _assname(self, name, node): self._span_start("assname") @@ -368,42 +375,61 @@ if target_names: self._span_end() + def _values_to_attribute_names(self, attr): + + "Get the output form of the values referenced by 'attr'." + + if isinstance(attr, Instance): + return [(str(attr), attr)] + + values = [] + for v in attr.get_values(): + if not isinstance(v, Instance): + values.append((v.full_name(), v)) + + values.sort() + return values + + def _attributes_to_attribute_names(self, attributes, attrname): + + "Get the output form of the 'attributes'." + + output = [] + for value, target, target_name in attributes: + if value and not isinstance(value, Instance): + fullname = value.full_name() + else: + fullname = target_name + "." + attrname + output.append((fullname, value)) + + output.sort() + return output + def _attribute_start(self, attrname, attributes): if attributes: - - # Get the output form of the attributes. - - output = [] - for value, target, target_name in attributes: - if value and not isinstance(value, Instance): - fullname = value.full_name() - else: - fullname = target_name + "." + attrname - output.append((fullname, value)) - - output.sort() - self._span_start("attr") self._popup_start("attributes-popup") self._names_list_start("attributes", "attrnames") - - # Mix links to attributes with labels indicating undetermined - # attributes. - - last = None - for fullname, value in output: - if fullname != last: - if last is not None: - self.stream.write("
") - if value is not None and not isinstance(value, Instance): - self._object_name_ref(value.module, value, fullname, classes="attribute-name") - else: - self.stream.write(fullname) - last = fullname - + self._attribute_list(attributes) self._names_list_end() self._popup_end() + def _attribute_list(self, attributes): + + # Mix links to attributes with labels indicating undetermined + # attributes. + + last = None + for fullname, value in attributes: + if fullname != last: + if last is not None: + self.stream.write("
") + if value is not None and not isinstance(value, Instance): + self._object_name_ref(value.module, value, fullname, classes="attribute-name") + else: + self.stream.write(fullname) + last = fullname + def _attribute_end(self, attributes): if attributes: self._span_end() @@ -1001,7 +1027,7 @@ if not wraps_getattr: self._accessor_end(target_names) self.stream.write(".") - self._attribute_start(node.attrname, attributes) + 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._attribute_end(attributes) if not wraps_getattr: @@ -1101,7 +1127,7 @@ if not wraps_getattr: self._accessor_end(target_names) self.stream.write(".") - self._attribute_start(node.attrname, attributes) + 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._attribute_end(attributes) if not wraps_getattr: @@ -1226,7 +1252,7 @@ self._name_start() self.stream.write(node.name) self._popup_start() - self._scope(scope) + self._scope(node._scope, node._attr) self._popup_end() self._name_end() else: