Change bargull-20110407-ugQ by bargull@Bargull02 on 2011-04-07 15:43:28
in /home/anba/src/svn/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: Generate utility visitor classes automatically
New Features: LPP-9876 (Generate utility visitor classes automatically)
Technical Reviewer: ptw
QA Reviewer: (pending)
Overview:
Simple visitor classes should be generated automatically rather than by
hand. For example the two visitors sc.EmptyParserVisitor and
sc.NewInstanceVisitor have a dead simple structure, so both are a
perfect choices for auto-generated classes.
I didn't want to introduce any dependencies to more mature template
engines (e.g. Xpand), because there is currently no integration with
JavaCC and the generated classes actually don't need any of these mature
features or whatsoever.
Details:
ToolsParser.jjt - simple grammar and generator
grammar part:
- mini grammar to parse the Visitor interface files from JavaCC
- supports a subset of Java interface declarations
generator part:
- OutputVisitor traverses the generated AST and produces the new visitor
class
- Template is an abstract class for the various template classes
- Currently supported templates
-- NullTemplate -> returns `null` for every visit() method
-- IdentityTemplate -> returns the input node in visit()
-- CommonTemplate -> calls a common visitor method named "$visit()" in
visit()
-- GenericTemplate -> helper interface because JavaCC doesn't yet
support generics for the Visitor interface
(http://java.net/jira/browse/JAVACC-235)
-- AdapterGenericTemplate -> adapter class from Visitor to the
"generified" Visitor (GenericTemplate)
-- NullGenericTemplate, CommonGenericTemplate -> same as the
NullTemplate resp. CommonTemplate but as generified classes
build.xml
- added new targets to build the new visitor tools
- updated the "compile" target to call "all-tools" to trigger the
creation of the visitor classes
Tests:
compile lps.jar
inspect generated visitor classes
Files:
M WEB-INF/lps/server/build.xml
A WEB-INF/lps/server/sc/src/org/openlaszlo/tools
A WEB-INF/lps/server/sc/src/org/openlaszlo/tools/ToolsParser.jjt
Changeset:
http://svn.openlaszlo.org/openlaszlo/patches/bargull-20110407-ugQ.tar