com.google.clearsilver.jsilver.compiler
Class ExpressionTranslator

java.lang.Object
  extended by com.google.clearsilver.jsilver.syntax.analysis.AnalysisAdapter
      extended by com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter
          extended by com.google.clearsilver.jsilver.compiler.ExpressionTranslator
All Implemented Interfaces:
Analysis, Switch

public class ExpressionTranslator
extends DepthFirstAdapter

Translates a CS expression (from the AST) into an equivalent Java expression. In order to optimize the expressions nicely this class emits code using a series of wrapper functions for casting to/from various types. Rather than the old style of saying:

ValueX.asFoo()
we now write:
asFoo(ValueX)
This is actually very important because it means that as we optimize the expressions to return fundamental types, we just have different versions of the asFoo() methods that take the appropriate types. The user of the expression is responsible for casting it and the producer of the expression is now free to produce optimized expressions.


Constructor Summary
ExpressionTranslator()
           
 
Method Summary
 void caseAAddExpression(AAddExpression node)
           
 void caseAAndExpression(AAndExpression node)
           
 void caseADecimalExpression(ADecimalExpression node)
          Process AST node for a decimal integer (e.g.
 void caseADivideExpression(ADivideExpression node)
           
 void caseAEqExpression(AEqExpression node)
           
 void caseAExistsExpression(AExistsExpression node)
           
 void caseAFunctionExpression(AFunctionExpression node)
          Process AST node for a function (e.g.
 void caseAGteExpression(AGteExpression node)
           
 void caseAGtExpression(AGtExpression node)
           
 void caseAHexExpression(AHexExpression node)
          Process AST node for a hex integer (e.g.
 void caseALteExpression(ALteExpression node)
           
 void caseALtExpression(ALtExpression node)
           
 void caseAModuloExpression(AModuloExpression node)
           
 void caseAMultiplyExpression(AMultiplyExpression node)
           
 void caseANeExpression(ANeExpression node)
           
 void caseANegativeExpression(ANegativeExpression node)
           
 void caseANotExpression(ANotExpression node)
           
 void caseANumericAddExpression(ANumericAddExpression node)
           
 void caseANumericEqExpression(ANumericEqExpression node)
           
 void caseANumericExpression(ANumericExpression node)
           
 void caseANumericNeExpression(ANumericNeExpression node)
           
 void caseAOrExpression(AOrExpression node)
           
 void caseAStringExpression(AStringExpression node)
          Process AST node for a string (e.g.
 void caseASubtractExpression(ASubtractExpression node)
           
 void caseAVariableExpression(AVariableExpression node)
          Process AST node for a variable (e.g.
 JavaExpression declareAsVariable(String name, PExpression csExpression)
          Declares the (typed) expression as a variable with the given name.
 JavaExpression translateToBoolean(PExpression csExpression)
          Translate a template AST expression into a Java boolean expression.
 JavaExpression translateToData(PExpression csExpression)
          Translate a template AST expression into a Java Data expression.
 JavaExpression translateToNumber(PExpression csExpression)
          Translate a template AST expression into a Java integer expression.
 JavaExpression translateToString(PExpression csExpression)
          Translate a template AST expression into a Java String expression.
 JavaExpression translateToValue(PExpression csExpression)
          Translate a template AST expression into a Java Value expression.
 JavaExpression translateToVarName(PExpression csExpression)
          Translate a template AST expression into a Java Data expression.
 JavaExpression translateUntyped(PExpression csExpression)
          Translate a template AST expression into an untyped expression.
 
Methods inherited from class com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter
caseAAltCommand, caseAAutoescapeCommand, caseACallCommand, caseACommaExpression, caseACommentCommand, caseAContentTypeCommand, caseACsOpenPosition, caseADataCommand, caseADecNumberVariable, caseADefCommand, caseADescendVariable, caseAEachCommand, caseAEscapeCommand, caseAEvarCommand, caseAExpandVariable, caseAHardIncludeCommand, caseAHardLincludeCommand, caseAHexNumberVariable, caseAIfCommand, caseAIncludeCommand, caseAInlineCommand, caseALincludeCommand, caseALoopCommand, caseALoopIncCommand, caseALoopToCommand, caseALvarCommand, caseAMultipleCommand, caseANameCommand, caseANameVariable, caseANoopCommand, caseANoopExpression, caseASequenceExpression, caseASetCommand, caseAUvarCommand, caseAVarCommand, caseAWithCommand, caseStart, defaultIn, defaultOut, inAAddExpression, inAAltCommand, inAAndExpression, inAAutoescapeCommand, inACallCommand, inACommaExpression, inACommentCommand, inAContentTypeCommand, inACsOpenPosition, inADataCommand, inADecimalExpression, inADecNumberVariable, inADefCommand, inADescendVariable, inADivideExpression, inAEachCommand, inAEqExpression, inAEscapeCommand, inAEvarCommand, inAExistsExpression, inAExpandVariable, inAFunctionExpression, inAGteExpression, inAGtExpression, inAHardIncludeCommand, inAHardLincludeCommand, inAHexExpression, inAHexNumberVariable, inAIfCommand, inAIncludeCommand, inAInlineCommand, inALincludeCommand, inALoopCommand, inALoopIncCommand, inALoopToCommand, inALteExpression, inALtExpression, inALvarCommand, inAModuloExpression, inAMultipleCommand, inAMultiplyExpression, inANameCommand, inANameVariable, inANeExpression, inANegativeExpression, inANoopCommand, inANoopExpression, inANotExpression, inANumericAddExpression, inANumericEqExpression, inANumericExpression, inANumericNeExpression, inAOrExpression, inASequenceExpression, inASetCommand, inAStringExpression, inASubtractExpression, inAUvarCommand, inAVarCommand, inAVariableExpression, inAWithCommand, inStart, outAAddExpression, outAAltCommand, outAAndExpression, outAAutoescapeCommand, outACallCommand, outACommaExpression, outACommentCommand, outAContentTypeCommand, outACsOpenPosition, outADataCommand, outADecimalExpression, outADecNumberVariable, outADefCommand, outADescendVariable, outADivideExpression, outAEachCommand, outAEqExpression, outAEscapeCommand, outAEvarCommand, outAExistsExpression, outAExpandVariable, outAFunctionExpression, outAGteExpression, outAGtExpression, outAHardIncludeCommand, outAHardLincludeCommand, outAHexExpression, outAHexNumberVariable, outAIfCommand, outAIncludeCommand, outAInlineCommand, outALincludeCommand, outALoopCommand, outALoopIncCommand, outALoopToCommand, outALteExpression, outALtExpression, outALvarCommand, outAModuloExpression, outAMultipleCommand, outAMultiplyExpression, outANameCommand, outANameVariable, outANeExpression, outANegativeExpression, outANoopCommand, outANoopExpression, outANotExpression, outANumericAddExpression, outANumericEqExpression, outANumericExpression, outANumericNeExpression, outAOrExpression, outASequenceExpression, outASetCommand, outAStringExpression, outASubtractExpression, outAUvarCommand, outAVarCommand, outAVariableExpression, outAWithCommand, outStart
 
Methods inherited from class com.google.clearsilver.jsilver.syntax.analysis.AnalysisAdapter
caseEOF, caseTAlt, caseTAnd, caseTArgWhitespace, caseTAssignment, caseTAutoescape, caseTBang, caseTBracketClose, caseTBracketOpen, caseTCall, caseTComma, caseTCommandDelimiter, caseTComment, caseTCommentStart, caseTContentType, caseTCsClose, caseTCsOpen, caseTData, caseTDecNumber, caseTDef, caseTDollar, caseTDot, caseTEach, caseTElse, caseTElseIf, caseTEq, caseTEscape, caseTEvar, caseTGt, caseTGte, caseTHardDelimiter, caseTHash, caseTHexNumber, caseTIf, caseTInclude, caseTInline, caseTLinclude, caseTLoop, caseTLt, caseTLte, caseTLvar, caseTMinus, caseTName, caseTNe, caseTOr, caseTParenClose, caseTParenOpen, caseTPercent, caseTPlus, caseTQuestion, caseTSet, caseTSlash, caseTStar, caseTString, caseTUvar, caseTVar, caseTWith, caseTWord, defaultCase, getIn, getOut, setIn, setOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionTranslator

public ExpressionTranslator()
Method Detail

translateToString

public JavaExpression translateToString(PExpression csExpression)
Translate a template AST expression into a Java String expression.


translateToBoolean

public JavaExpression translateToBoolean(PExpression csExpression)
Translate a template AST expression into a Java boolean expression.


translateToNumber

public JavaExpression translateToNumber(PExpression csExpression)
Translate a template AST expression into a Java integer expression.


translateToData

public JavaExpression translateToData(PExpression csExpression)
Translate a template AST expression into a Java Data expression.


translateToVarName

public JavaExpression translateToVarName(PExpression csExpression)
Translate a template AST expression into a Java Data expression.


translateToValue

public JavaExpression translateToValue(PExpression csExpression)
Translate a template AST expression into a Java Value expression.


declareAsVariable

public JavaExpression declareAsVariable(String name,
                                        PExpression csExpression)
Declares the (typed) expression as a variable with the given name. (e.g. "int foo = 5" or "Data foo = Data.getChild("a.b")"


translateUntyped

public JavaExpression translateUntyped(PExpression csExpression)
Translate a template AST expression into an untyped expression.


caseAVariableExpression

public void caseAVariableExpression(AVariableExpression node)
Process AST node for a variable (e.g. a.b.c).

Specified by:
caseAVariableExpression in interface Analysis
Overrides:
caseAVariableExpression in class DepthFirstAdapter

caseAStringExpression

public void caseAStringExpression(AStringExpression node)
Process AST node for a string (e.g. "hello").

Specified by:
caseAStringExpression in interface Analysis
Overrides:
caseAStringExpression in class DepthFirstAdapter

caseADecimalExpression

public void caseADecimalExpression(ADecimalExpression node)
Process AST node for a decimal integer (e.g. 123).

Specified by:
caseADecimalExpression in interface Analysis
Overrides:
caseADecimalExpression in class DepthFirstAdapter

caseAHexExpression

public void caseAHexExpression(AHexExpression node)
Process AST node for a hex integer (e.g. 0x1AB).

Specified by:
caseAHexExpression in interface Analysis
Overrides:
caseAHexExpression in class DepthFirstAdapter

caseANumericExpression

public void caseANumericExpression(ANumericExpression node)
Specified by:
caseANumericExpression in interface Analysis
Overrides:
caseANumericExpression in class DepthFirstAdapter

caseANotExpression

public void caseANotExpression(ANotExpression node)
Specified by:
caseANotExpression in interface Analysis
Overrides:
caseANotExpression in class DepthFirstAdapter

caseAExistsExpression

public void caseAExistsExpression(AExistsExpression node)
Specified by:
caseAExistsExpression in interface Analysis
Overrides:
caseAExistsExpression in class DepthFirstAdapter

caseAEqExpression

public void caseAEqExpression(AEqExpression node)
Specified by:
caseAEqExpression in interface Analysis
Overrides:
caseAEqExpression in class DepthFirstAdapter

caseANumericEqExpression

public void caseANumericEqExpression(ANumericEqExpression node)
Specified by:
caseANumericEqExpression in interface Analysis
Overrides:
caseANumericEqExpression in class DepthFirstAdapter

caseANeExpression

public void caseANeExpression(ANeExpression node)
Specified by:
caseANeExpression in interface Analysis
Overrides:
caseANeExpression in class DepthFirstAdapter

caseANumericNeExpression

public void caseANumericNeExpression(ANumericNeExpression node)
Specified by:
caseANumericNeExpression in interface Analysis
Overrides:
caseANumericNeExpression in class DepthFirstAdapter

caseALtExpression

public void caseALtExpression(ALtExpression node)
Specified by:
caseALtExpression in interface Analysis
Overrides:
caseALtExpression in class DepthFirstAdapter

caseAGtExpression

public void caseAGtExpression(AGtExpression node)
Specified by:
caseAGtExpression in interface Analysis
Overrides:
caseAGtExpression in class DepthFirstAdapter

caseALteExpression

public void caseALteExpression(ALteExpression node)
Specified by:
caseALteExpression in interface Analysis
Overrides:
caseALteExpression in class DepthFirstAdapter

caseAGteExpression

public void caseAGteExpression(AGteExpression node)
Specified by:
caseAGteExpression in interface Analysis
Overrides:
caseAGteExpression in class DepthFirstAdapter

caseAAndExpression

public void caseAAndExpression(AAndExpression node)
Specified by:
caseAAndExpression in interface Analysis
Overrides:
caseAAndExpression in class DepthFirstAdapter

caseAOrExpression

public void caseAOrExpression(AOrExpression node)
Specified by:
caseAOrExpression in interface Analysis
Overrides:
caseAOrExpression in class DepthFirstAdapter

caseAAddExpression

public void caseAAddExpression(AAddExpression node)
Specified by:
caseAAddExpression in interface Analysis
Overrides:
caseAAddExpression in class DepthFirstAdapter

caseANumericAddExpression

public void caseANumericAddExpression(ANumericAddExpression node)
Specified by:
caseANumericAddExpression in interface Analysis
Overrides:
caseANumericAddExpression in class DepthFirstAdapter

caseASubtractExpression

public void caseASubtractExpression(ASubtractExpression node)
Specified by:
caseASubtractExpression in interface Analysis
Overrides:
caseASubtractExpression in class DepthFirstAdapter

caseAMultiplyExpression

public void caseAMultiplyExpression(AMultiplyExpression node)
Specified by:
caseAMultiplyExpression in interface Analysis
Overrides:
caseAMultiplyExpression in class DepthFirstAdapter

caseADivideExpression

public void caseADivideExpression(ADivideExpression node)
Specified by:
caseADivideExpression in interface Analysis
Overrides:
caseADivideExpression in class DepthFirstAdapter

caseAModuloExpression

public void caseAModuloExpression(AModuloExpression node)
Specified by:
caseAModuloExpression in interface Analysis
Overrides:
caseAModuloExpression in class DepthFirstAdapter

caseANegativeExpression

public void caseANegativeExpression(ANegativeExpression node)
Specified by:
caseANegativeExpression in interface Analysis
Overrides:
caseANegativeExpression in class DepthFirstAdapter

caseAFunctionExpression

public void caseAFunctionExpression(AFunctionExpression node)
Process AST node for a function (e.g. dosomething(...)).

Specified by:
caseAFunctionExpression in interface Analysis
Overrides:
caseAFunctionExpression in class DepthFirstAdapter


Copyright © 2010-2012 Google. All Rights Reserved.