# HG changeset patch # User Paul Boddie # Date 1281139575 -7200 # Node ID 34ebed37aecc2779b7c0a06c0f2523f9cc242d9d # Parent 67d7ed58ac5003cebb68bf267afac2ff423d9dd5 Added some support for HTML reports of program modules, separating the program finalisation out into a separate method of the Program class, in order to avoid obtaining an actual program image, yet removing unneeded parts of a program. Moved code to test for the usage of program sections into the common module, since this is also useful when generating reports. Added AST node annotation documentation. diff -r 67d7ed58ac50 -r 34ebed37aecc docs/annotations.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/annotations.txt Sat Aug 07 02:06:15 2010 +0200 @@ -0,0 +1,9 @@ +AST Node Annotations +==================== + +_attrnames defines a dictionary mapping local names to sets of attribute + names found to be used with those names +_attrusers defines a dictionary mapping local names to sets of nodes + defining those names +_def refers to a micropython Class or Function instance +_scope set as "constant", "local", "global" or "builtins" diff -r 67d7ed58ac50 -r 34ebed37aecc micropython/__init__.py --- a/micropython/__init__.py Sun Jul 11 02:05:41 2010 +0200 +++ b/micropython/__init__.py Sat Aug 07 02:06:15 2010 +0200 @@ -84,6 +84,23 @@ # Access to finalised program information. + def finalise(self): + + "Finalise the program." + + # Need the tables to finalise. + + objtable = self.get_object_table() + self.get_parameter_table() + + self.importer.vacuum(objtable) + self.importer.finalise() + + # Now remove unneeded things from the tables. + + self.get_object_table(reset=1) + self.get_parameter_table(reset=1) + def get_image(self, with_builtins=0): """ @@ -94,17 +111,9 @@ if self.code is not None: return self.code - objtable = self.get_object_table() - paramtable = self.get_parameter_table() - # Optimise and regenerate the object table. - self.importer.vacuum(objtable) - self.importer.finalise() - - objtable = self.get_object_table(reset=1) - paramtable = self.get_parameter_table(reset=1) - + self.finalise() self.code = [] # Append constants to the image. diff -r 67d7ed58ac50 -r 34ebed37aecc micropython/ast.py --- a/micropython/ast.py Sun Jul 11 02:05:41 2010 +0200 +++ b/micropython/ast.py Sat Aug 07 02:06:15 2010 +0200 @@ -564,7 +564,7 @@ self.discard_temp(temp2) def visitClass(self, node): - if not node.unit.parent.has_key(node.unit.name): + if not used_by_unit(node): return # Store the name. @@ -587,7 +587,7 @@ def visitFrom(self, node): pass def visitFunction(self, node): - if not node.unit.parent.has_key(node.unit.name): + if not used_by_unit(node): return # Only store the name when visiting this node from outside. diff -r 67d7ed58ac50 -r 34ebed37aecc micropython/common.py --- a/micropython/common.py Sun Jul 11 02:05:41 2010 +0200 +++ b/micropython/common.py Sat Aug 07 02:06:15 2010 +0200 @@ -47,6 +47,15 @@ exc.unit_name = self.full_name() raise +def used_by_unit(node): + + """ + Return whether the definition made by a 'node' is actually employed by the + program unit within which it is found. + """ + + return node.unit.parent.has_key(node.unit.name) + # Errors. class ProcessingError(Exception): diff -r 67d7ed58ac50 -r 34ebed37aecc micropython/report.py --- a/micropython/report.py Sun Jul 11 02:05:41 2010 +0200 +++ b/micropython/report.py Sat Aug 07 02:06:15 2010 +0200 @@ -19,8 +19,9 @@ this program. If not, see . """ +from micropython.common import * from micropython.data import * -from compiler.visitor import ASTVisitor +from os.path import exists, extsep, join import sys import os import textwrap @@ -33,7 +34,7 @@ - Module + Module: %(full_name)s