org.apache.jdo.impl.jdoql.jdoqlc
Class Semantic

java.lang.Object
  extended byantlr.TreeParser
      extended byorg.apache.jdo.impl.jdoql.jdoqlc.Semantic
All Implemented Interfaces:
SemanticTokenTypes

public class Semantic
extends antlr.TreeParser
implements SemanticTokenTypes

This class defines the semantic analysis of the JDOQL compiler. Input of this pass is the AST as produced by the parser, that consists of JDOQLAST nodes. The result is a typed JDOQLAST tree.

TBD:

Author:
Michael Bouschen

Field Summary
static java.lang.String[] _tokenNames
           
static antlr.collections.impl.BitSet _tokenSet_0
           
protected  JavaType candidateClass
          Candidate class.
protected  ErrorMsg errorMsg
          The error message support class.
protected static I18NHelper msg
          I18N support
protected  ParameterTable paramtab
          The query parameter table
protected  SymbolTable symtab
          Symbol table handling names of variables and parameters.
protected  TypeNames typeNames
          Table of type names handling imports.
protected  TypeSupport typeSupport
          The type support.
protected  VariableChecker varChecker
          The variable checker.
protected  VariableTable vartab
          The variable table.
 
Fields inherited from class antlr.TreeParser
_retTree, astFactory, ASTNULL, inputState, returnAST, tokenNames, traceDepth
 
Fields inherited from interface org.apache.jdo.impl.jdoql.jdoqlc.SemanticTokenTypes
AND, ARG_LIST, ASCENDING, ASSIGN, BAND, BAND_ASSIGN, BNOT, BOOLEAN, BOOLEAN_LITERAL, BOR, BOR_ASSIGN, BYTE, BYTE_LITERAL, CANDIDATE_CLASS, CAST, CHAR, CHAR_LITERAL, COLLECTION_EQUAL, COLLECTION_NOT_EQUAL, COMMA, CONCAT, CONSTANT, CONTAINS, DEC, DESCENDING, DIV, DIV_ASSIGN, DOT, DOUBLE, DOUBLE_LITERAL, ENDS_WITH, EOF, EQUAL, ESC, EXPONENT, FALSE, FIELD_ACCESS, FLOAT, FLOAT_LITERAL, FLOATINGPOINT_SUFFIX, GE, GT, HEX_DIGIT, IDENT, IMPORT, IMPORT_ON_DEMAND, INC, INT, INT_LITERAL, IS_EMPTY, LE, LNOT, LONG, LONG_LITERAL, LPAREN, LT, MINUS, MINUS_ASSIGN, NAVIGATION, NEWLINE, NOT_EQUAL, NULL, NULL_TREE_LOOKAHEAD, OBJECT_EQUAL, OBJECT_NOT_EQUAL, OR, PARAMETER_ACCESS, PARAMETER_DECL, PLUS, PLUS_ASSIGN, QUERY_TREE, RPAREN, SEMI, SHORT, SHORT_LITERAL, SL, SR, STAR, STAR_ASSIGN, STARTS_WITH, STATIC_FIELD_ACCESS, STRING_LITERAL, THIS, TRUE, TYPE, UNARY_MINUS, UNARY_PLUS, UNICODE_CHAR, UNICODE_ESCAPE, VARIABLE_ACCESS, VARIABLE_DECL, WS
 
Constructor Summary
Semantic()
           
 
Method Summary
protected  JDOQLAST addCharacterCast(JDOQLAST ast, JavaType common)
          The query runtime has a problem with binary or relational expressions having an operand of type char or Character.
protected  JDOQLAST analyseBinaryArithmeticExpr(JDOQLAST op, JDOQLAST leftAST, JDOQLAST rightAST)
          Analyses a binary arithmetic expression +, -, *, /.
protected  JavaType analyseBitwiseExpr(JDOQLAST op, JDOQLAST leftAST, JDOQLAST rightAST)
          Analyses a bitwise/logical operation (&, |, ^)
protected  JDOQLAST analyseCollectionCall(JDOQLAST dot, JDOQLAST collection, JDOQLAST method, JDOQLAST args)
          Analyses a call for an object that implements Collection.
protected  JDOQLAST analyseComplementExpr(JDOQLAST op, JDOQLAST argAST)
          Analyses a complement expression.
protected  JavaType analyseComplementExprType(JDOQLAST op, JDOQLAST argAST)
          Analyses a complement expression.
protected  JavaType analyseConditionalExpr(JDOQLAST op, JDOQLAST leftAST, JDOQLAST rightAST)
          Analyses a boolean conditional operation (&&, ||)
protected  JDOQLAST analyseDefinedIdentifier(JDOQLAST ident)
          This method analyses an identifier defined in the current scope which is a field, variable or parameter defined in the symbol table.
protected  JDOQLAST analyseDotExpr(JDOQLAST dot, JDOQLAST expr, JDOQLAST ident, JDOQLAST args)
          This method analyses a dot expression of the form expr.ident or expr.ident(params) where expr itself can again be a dot expression.
protected  JDOQLAST analyseFieldAccess(JDOQLAST objectExpr, JDOQLAST ident, JavaType classType, JavaField javaField)
           
protected  void analyseOrderingExpression(JDOQLAST expr)
          This method analyses the expression of a single ordering definition.
protected  JDOQLAST analyseRelationalExpr(JDOQLAST op, JDOQLAST leftAST, JDOQLAST rightAST)
          Analyses a relational operation.
protected  JDOQLAST analyseStaticFieldAccess(JDOQLAST typename, JDOQLAST ident, JavaType classType, JavaField javaField)
           
protected  JDOQLAST analyseStringCall(JDOQLAST dot, JDOQLAST string, JDOQLAST method, JDOQLAST args)
          Analyses a call for an object of type String.
protected  JDOQLAST analyseUnaryArithmeticExpr(JDOQLAST op, JDOQLAST argAST)
          Analyses a unary expression + and -
protected  JavaType analyseUnaryArithmeticExprType(JDOQLAST op, JDOQLAST argAST)
          Analyses a unary expression + and -
 void argList(antlr.collections.AST _t)
           
 void args(antlr.collections.AST _t)
           
 void binaryArithmeticExpr(antlr.collections.AST _t)
           
 void bitwiseExpr(antlr.collections.AST _t)
           
 void candidateClass(antlr.collections.AST _t)
           
protected  void checkConstraints(JDOQLAST ast, java.lang.String dependentVariable, VariableChecker tab)
           
protected  void checkConstraints(JDOQLAST ast, VariableChecker tab)
           
protected  void checkContainsArgs(JDOQLAST collection, JDOQLAST method, JDOQLAST args)
          Check the arguments of a contains call.
protected  void checkIsEmptyArgs(JDOQLAST args)
          Check the arguments of a isEmpty call.
protected  void checkStringCallArgs(JDOQLAST method, JDOQLAST args)
          Check the arguments of a startWith or endWith call.
 void complementExpr(antlr.collections.AST _t)
           
 void conditionalExpr(antlr.collections.AST _t)
           
 void contains(antlr.collections.AST _t)
           
 JDOQLAST createQueryTree(java.lang.Class candidateClass, JDOQLAST importsAST, JDOQLAST paramsAST, JDOQLAST varsAST, JDOQLAST orderingAST, JDOQLAST filterAST)
          Combines partial ASTs into one query AST.
 void declareImport(antlr.collections.AST _t)
           
 void declareParameter(antlr.collections.AST _t)
           
 void declareVariable(antlr.collections.AST _t)
           
 java.lang.String dotExpr(antlr.collections.AST _t)
           
 void endsWith(antlr.collections.AST _t)
           
 void expression(antlr.collections.AST _t)
           
 java.lang.String exprNoCheck(antlr.collections.AST _t, boolean insideDotExpr)
           
 void fieldAccess(antlr.collections.AST _t)
           
 void filter(antlr.collections.AST _t)
           
protected  JavaField getCollectionField(JDOQLAST expr)
           
protected  JavaType getCommonOperandType(JavaType left, JavaType right)
          Returns the common type info for the specified operand types.
 java.lang.String identifier(antlr.collections.AST _t, boolean insideDotExpr)
           
 void imports(antlr.collections.AST _t)
           
 void init(TypeSupport typeSupport, ParameterTable paramtab, VariableTable vartab, ErrorMsg errorMsg)
           
 void isEmpty(antlr.collections.AST _t)
           
 void literal(antlr.collections.AST _t)
           
private static long[] mk_tokenSet_0()
           
 void navigation(antlr.collections.AST _t)
           
 void ordering(antlr.collections.AST _t)
           
 void orderSpec(antlr.collections.AST _t)
           
 void parameterAccess(antlr.collections.AST _t)
           
 void parameters(antlr.collections.AST _t)
           
 java.lang.String primary(antlr.collections.AST _t, boolean insideDotExpr)
           
 void primitiveType(antlr.collections.AST _t)
           
 java.lang.String qualifiedName(antlr.collections.AST _t)
           
 void query(antlr.collections.AST _t)
           
 void relationalExpr(antlr.collections.AST _t)
           
 void reportError(antlr.RecognitionException ex)
           
 void reportError(java.lang.String s)
           
 void startsWith(antlr.collections.AST _t)
           
 void staticFieldAccess(antlr.collections.AST _t)
           
 void type(antlr.collections.AST _t)
           
 void unaryArithmeticExpr(antlr.collections.AST _t)
           
 void variableAccess(antlr.collections.AST _t)
           
 void variables(antlr.collections.AST _t)
           
 
Methods inherited from class antlr.TreeParser
getAST, getASTFactory, getTokenName, getTokenNames, match, match, matchNot, panic, reportWarning, setASTFactory, setASTNodeClass, setASTNodeType, traceIn, traceIndent, traceOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errorMsg

protected ErrorMsg errorMsg
The error message support class.


symtab

protected SymbolTable symtab
Symbol table handling names of variables and parameters.


typeNames

protected TypeNames typeNames
Table of type names handling imports.


typeSupport

protected TypeSupport typeSupport
The type support.


paramtab

protected ParameterTable paramtab
The query parameter table


vartab

protected VariableTable vartab
The variable table.


varChecker

protected VariableChecker varChecker
The variable checker.


candidateClass

protected JavaType candidateClass
Candidate class.


msg

protected static final I18NHelper msg
I18N support


_tokenNames

public static final java.lang.String[] _tokenNames

_tokenSet_0

public static final antlr.collections.impl.BitSet _tokenSet_0
Constructor Detail

Semantic

public Semantic()
Method Detail

init

public void init(TypeSupport typeSupport,
                 ParameterTable paramtab,
                 VariableTable vartab,
                 ErrorMsg errorMsg)

reportError

public void reportError(antlr.RecognitionException ex)

reportError

public void reportError(java.lang.String s)

createQueryTree

public JDOQLAST createQueryTree(java.lang.Class candidateClass,
                                JDOQLAST importsAST,
                                JDOQLAST paramsAST,
                                JDOQLAST varsAST,
                                JDOQLAST orderingAST,
                                JDOQLAST filterAST)
Combines partial ASTs into one query AST.


analyseOrderingExpression

protected void analyseOrderingExpression(JDOQLAST expr)
This method analyses the expression of a single ordering definition. It checks whether the expression - is of a orderable type

Parameters:
expr - the expression of an ordering definition

analyseDotExpr

protected JDOQLAST analyseDotExpr(JDOQLAST dot,
                                  JDOQLAST expr,
                                  JDOQLAST ident,
                                  JDOQLAST args)
This method analyses a dot expression of the form expr.ident or expr.ident(params) where expr itself can again be a dot expression. It checks whether the dot expression is - part of a qualified class name specification - field access, - a method call The method returns a temporary single AST node that is defined with a specific token type (field access, method call, etc.). This node also contains the type of the dot expression.

Parameters:
expr - the left hand side of the dot expression
ident - the right hand side of the dot expression
args - arguments (in the case of a call)
Returns:
AST node representing the specialized dot expr

analyseFieldAccess

protected JDOQLAST analyseFieldAccess(JDOQLAST objectExpr,
                                      JDOQLAST ident,
                                      JavaType classType,
                                      JavaField javaField)

analyseStaticFieldAccess

protected JDOQLAST analyseStaticFieldAccess(JDOQLAST typename,
                                            JDOQLAST ident,
                                            JavaType classType,
                                            JavaField javaField)

analyseDefinedIdentifier

protected JDOQLAST analyseDefinedIdentifier(JDOQLAST ident)
This method analyses an identifier defined in the current scope which is a field, variable or parameter defined in the symbol table.

Parameters:
ident - the identifier AST
Returns:
AST node representing a defined identifier

analyseCollectionCall

protected JDOQLAST analyseCollectionCall(JDOQLAST dot,
                                         JDOQLAST collection,
                                         JDOQLAST method,
                                         JDOQLAST args)
Analyses a call for an object that implements Collection. Currently, only contains and isEmpty are supported.


checkContainsArgs

protected void checkContainsArgs(JDOQLAST collection,
                                 JDOQLAST method,
                                 JDOQLAST args)
Check the arguments of a contains call.


getCollectionField

protected JavaField getCollectionField(JDOQLAST expr)

checkIsEmptyArgs

protected void checkIsEmptyArgs(JDOQLAST args)
Check the arguments of a isEmpty call.


analyseStringCall

protected JDOQLAST analyseStringCall(JDOQLAST dot,
                                     JDOQLAST string,
                                     JDOQLAST method,
                                     JDOQLAST args)
Analyses a call for an object of type String. Currently startsWith and endsWith are the only valid String methods in a query filter.


checkStringCallArgs

protected void checkStringCallArgs(JDOQLAST method,
                                   JDOQLAST args)
Check the arguments of a startWith or endWith call.


analyseBitwiseExpr

protected JavaType analyseBitwiseExpr(JDOQLAST op,
                                      JDOQLAST leftAST,
                                      JDOQLAST rightAST)
Analyses a bitwise/logical operation (&, |, ^)

Parameters:
op - the bitwise/logical operator
leftAST - left operand
rightAST - right operand
Returns:
the type info of the operator

analyseConditionalExpr

protected JavaType analyseConditionalExpr(JDOQLAST op,
                                          JDOQLAST leftAST,
                                          JDOQLAST rightAST)
Analyses a boolean conditional operation (&&, ||)

Parameters:
op - the conditional operator
leftAST - left operand
rightAST - right operand
Returns:
the type info of the operator

analyseRelationalExpr

protected JDOQLAST analyseRelationalExpr(JDOQLAST op,
                                         JDOQLAST leftAST,
                                         JDOQLAST rightAST)
Analyses a relational operation. A relational operation contains one of <, <=, >, >=, ==, or !=.

Parameters:
op - the relational operator
leftAST - left operand
rightAST - right operand
Returns:
the node representing the relational expr

analyseBinaryArithmeticExpr

protected JDOQLAST analyseBinaryArithmeticExpr(JDOQLAST op,
                                               JDOQLAST leftAST,
                                               JDOQLAST rightAST)
Analyses a binary arithmetic expression +, -, *, /.

Parameters:
op - the operator
leftAST - left operand
rightAST - right operand
Returns:
the node representing the binary arithmetic op

addCharacterCast

protected JDOQLAST addCharacterCast(JDOQLAST ast,
                                    JavaType common)
The query runtime has a problem with binary or relational expressions having an operand of type char or Character. The query runtime treats the value of the expression to be a value of the promoted type (see binary numeric promotion). The value will be of type Character which is not compatible to java.lang.Number. In the current query runtime only the CastExpression includes the conversion code from the Character to Number. This keeps the code for binary and relational expressions free from any special treatement of char or Character values. As a consequence the semantic analsis needs to insert a cast node whenever binary numeric promotion converts a char or Character into a numeric or Number type. Method addCharacterCast checks whether the specified ast is of type char or Character. If so it wraps it into a cast expression ast using the specified type. If not the ast is reured as it is.

Parameters:
ast - the ast to be checked
common - the type to be used inside the cast
Returns:
a cast node that wraps the specified ast node, if the ast is of type char or Character; the ast itself otherwise.

getCommonOperandType

protected JavaType getCommonOperandType(JavaType left,
                                        JavaType right)
Returns the common type info for the specified operand types. This includes binary numeric promotion as specified in Java.

Parameters:
left - type info of left operand
right - type info of right operand
Returns:
the common type info

analyseUnaryArithmeticExpr

protected JDOQLAST analyseUnaryArithmeticExpr(JDOQLAST op,
                                              JDOQLAST argAST)
Analyses a unary expression + and -

Parameters:
op - the operator
argAST - the opreand
Returns:
the node representing the unary expression

analyseUnaryArithmeticExprType

protected JavaType analyseUnaryArithmeticExprType(JDOQLAST op,
                                                  JDOQLAST argAST)
Analyses a unary expression + and -

Parameters:
op - the operator
argAST - the operand
Returns:
the type info of the operator

analyseComplementExpr

protected JDOQLAST analyseComplementExpr(JDOQLAST op,
                                         JDOQLAST argAST)
Analyses a complement expression. A complement expression contains one of ! and ~

Parameters:
op - the operator
argAST - the operand
Returns:
the node representing the complement expression

analyseComplementExprType

protected JavaType analyseComplementExprType(JDOQLAST op,
                                             JDOQLAST argAST)
Analyses a complement expression. A complement expression contains one of ! and ~

Parameters:
op - the operator
argAST - the operand
Returns:
the type info of the operator

checkConstraints

protected void checkConstraints(JDOQLAST ast,
                                VariableChecker tab)

checkConstraints

protected void checkConstraints(JDOQLAST ast,
                                java.lang.String dependentVariable,
                                VariableChecker tab)

query

public final void query(antlr.collections.AST _t)
                 throws antlr.RecognitionException
Throws:
antlr.RecognitionException

candidateClass

public final void candidateClass(antlr.collections.AST _t)
                          throws antlr.RecognitionException
Throws:
antlr.RecognitionException

imports

public final void imports(antlr.collections.AST _t)
                   throws antlr.RecognitionException
Throws:
antlr.RecognitionException

parameters

public final void parameters(antlr.collections.AST _t)
                      throws antlr.RecognitionException
Throws:
antlr.RecognitionException

variables

public final void variables(antlr.collections.AST _t)
                     throws antlr.RecognitionException
Throws:
antlr.RecognitionException

ordering

public final void ordering(antlr.collections.AST _t)
                    throws antlr.RecognitionException
Throws:
antlr.RecognitionException

filter

public final void filter(antlr.collections.AST _t)
                  throws antlr.RecognitionException
Throws:
antlr.RecognitionException

type

public final void type(antlr.collections.AST _t)
                throws antlr.RecognitionException
Throws:
antlr.RecognitionException

declareImport

public final void declareImport(antlr.collections.AST _t)
                         throws antlr.RecognitionException
Throws:
antlr.RecognitionException

qualifiedName

public final java.lang.String qualifiedName(antlr.collections.AST _t)
                                     throws antlr.RecognitionException
Throws:
antlr.RecognitionException

declareParameter

public final void declareParameter(antlr.collections.AST _t)
                            throws antlr.RecognitionException
Throws:
antlr.RecognitionException

declareVariable

public final void declareVariable(antlr.collections.AST _t)
                           throws antlr.RecognitionException
Throws:
antlr.RecognitionException

orderSpec

public final void orderSpec(antlr.collections.AST _t)
                     throws antlr.RecognitionException
Throws:
antlr.RecognitionException

expression

public final void expression(antlr.collections.AST _t)
                      throws antlr.RecognitionException
Throws:
antlr.RecognitionException

exprNoCheck

public final java.lang.String exprNoCheck(antlr.collections.AST _t,
                                          boolean insideDotExpr)
                                   throws antlr.RecognitionException
Throws:
antlr.RecognitionException

bitwiseExpr

public final void bitwiseExpr(antlr.collections.AST _t)
                       throws antlr.RecognitionException
Throws:
antlr.RecognitionException

conditionalExpr

public final void conditionalExpr(antlr.collections.AST _t)
                           throws antlr.RecognitionException
Throws:
antlr.RecognitionException

relationalExpr

public final void relationalExpr(antlr.collections.AST _t)
                          throws antlr.RecognitionException
Throws:
antlr.RecognitionException

binaryArithmeticExpr

public final void binaryArithmeticExpr(antlr.collections.AST _t)
                                throws antlr.RecognitionException
Throws:
antlr.RecognitionException

unaryArithmeticExpr

public final void unaryArithmeticExpr(antlr.collections.AST _t)
                               throws antlr.RecognitionException
Throws:
antlr.RecognitionException

complementExpr

public final void complementExpr(antlr.collections.AST _t)
                          throws antlr.RecognitionException
Throws:
antlr.RecognitionException

primary

public final java.lang.String primary(antlr.collections.AST _t,
                                      boolean insideDotExpr)
                               throws antlr.RecognitionException
Throws:
antlr.RecognitionException

literal

public final void literal(antlr.collections.AST _t)
                   throws antlr.RecognitionException
Throws:
antlr.RecognitionException

dotExpr

public final java.lang.String dotExpr(antlr.collections.AST _t)
                               throws antlr.RecognitionException
Throws:
antlr.RecognitionException

identifier

public final java.lang.String identifier(antlr.collections.AST _t,
                                         boolean insideDotExpr)
                                  throws antlr.RecognitionException
Throws:
antlr.RecognitionException

parameterAccess

public final void parameterAccess(antlr.collections.AST _t)
                           throws antlr.RecognitionException
Throws:
antlr.RecognitionException

variableAccess

public final void variableAccess(antlr.collections.AST _t)
                          throws antlr.RecognitionException
Throws:
antlr.RecognitionException

fieldAccess

public final void fieldAccess(antlr.collections.AST _t)
                       throws antlr.RecognitionException
Throws:
antlr.RecognitionException

navigation

public final void navigation(antlr.collections.AST _t)
                      throws antlr.RecognitionException
Throws:
antlr.RecognitionException

contains

public final void contains(antlr.collections.AST _t)
                    throws antlr.RecognitionException
Throws:
antlr.RecognitionException

isEmpty

public final void isEmpty(antlr.collections.AST _t)
                   throws antlr.RecognitionException
Throws:
antlr.RecognitionException

startsWith

public final void startsWith(antlr.collections.AST _t)
                      throws antlr.RecognitionException
Throws:
antlr.RecognitionException

endsWith

public final void endsWith(antlr.collections.AST _t)
                    throws antlr.RecognitionException
Throws:
antlr.RecognitionException

argList

public final void argList(antlr.collections.AST _t)
                   throws antlr.RecognitionException
Throws:
antlr.RecognitionException

args

public final void args(antlr.collections.AST _t)
                throws antlr.RecognitionException
Throws:
antlr.RecognitionException

staticFieldAccess

public final void staticFieldAccess(antlr.collections.AST _t)
                             throws antlr.RecognitionException
Throws:
antlr.RecognitionException

primitiveType

public final void primitiveType(antlr.collections.AST _t)
                         throws antlr.RecognitionException
Throws:
antlr.RecognitionException

mk_tokenSet_0

private static final long[] mk_tokenSet_0()