Some more updates to get rid of "instanceof" tests. Are you fine with these kind of changes (bargull-20110413-mTp and this new one)?

Change bargull-20110416-KGZ by bargull@Bargull02 on 2011-04-16 11:04:51
in /home/anba/src/svn/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Use new visitor classes to replace bulk if-instanceof tests when traversing the AST (next change)

New Features: LPP-9876 (Generate utility visitor classes automatically) (partial)

Technical Reviewer: ptw
QA Reviewer: (pending)

Overview:
instanceof tests are a sign of poor oo-design, double-dispatch should be preferred.


Details:
SimpleNode:
#childrenAccept(ParserVisitor, Object)
- actually this method is auto-generated by JavaCC, but since we're using our own modified version of SimpleNode it wasn't present until now
#jjtAccept(TypedParserVisitor), childrenAccept(TypedParserVisitor)
- accept() methods for the new visitor classes, internally calling the ParserVisitor based accept() methods

ToolsParser:
- extended to generated "Named Visitors", that means the visit() method will also include the class-name from the ast type, e.g. visitIfStatement() - this helps to port the existings sources to a visitor based approach, because in the sc-package the visit() methods include the class-name, too

ParseTreePrinter:
- replaced instanceof tests with standard visitor approach

SWF9ParseTreePrinter, JavascriptGenerator, JavascriptCompressor:
- update methods


Tests:
compile lps.jar

Files:
M WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptGenerator.java
M WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9ParseTreePrinter.java
M WEB-INF/lps/server/src/org/openlaszlo/sc/JavascriptCompressor.java
M WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
M WEB-INF/lps/server/sc/src/org/openlaszlo/tools/ToolsParser.jjt
M WEB-INF/lps/server/sc/src/org/openlaszlo/sc/parser/SimpleNode.java

Changeset: http://svn.openlaszlo.org/openlaszlo/patches/bargull-20110416-KGZ.tar

Reply via email to