java.lang.Object
antlr.TreeParser
de.grogra.xl.compiler.CompilerBase
- All Implemented Interfaces:
CompilerTokenTypes
,Members.Resolution
- Direct Known Subclasses:
Compiler
public abstract class CompilerBase
extends antlr.TreeParser
implements CompilerTokenTypes, Members.Resolution
This helper class is the superclass of
Compiler
.
Its members would normally be declared in Compiler
. However,
since the latter class is generated by ANTLR from a grammar file, it is
more convenient to extract these members to a helper class which is defined
by this conventional Java source file.- Author:
- Ole Kniemeyer
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Constant forrun
indicating the third, final run.Stores the current CompilationUnitScope, if one was set.static final int
static final int
static final I18NBundle
Resource bundle for messages.static final int
Constant forrun
indicating the second run.static final long
static final long
static final long
static final long
static final long
static final long
static final long
static final long
static final long
static final long
static final long
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final long
static final int
Constant forrun
indicating the first run.static final long
Fields inherited from class antlr.TreeParser
_retTree, astFactory, ASTNULL, inputState, returnAST, tokenNames, traceDepth
Fields inherited from interface de.grogra.xl.compiler.CompilerTokenTypes
ABSTRACT_, ADD, ADD_ASSIGN, AND, AND_ASSIGN, ANNOTATION, ANY, APPLICATION_CONDITION, ARGLIST, ARRAY_DECLARATOR, ARRAY_INIT, ARRAY_ITERATOR, ARROW, ASSERT, ASSIGN, BOOLEAN_, BOOLEAN_LITERAL, BREAK, BYTE_, CAND, CASE, CATCH, CHAR_, CHAR_LITERAL, CLASS, CLASS_LITERAL, CMP, COM, COMPILATION_UNIT, COMPOUND_PATTERN, CONST_, CONSTRUCTOR, CONTEXT, CONTINUE, COR, DEC, DECLARING_TYPE, DEFAULT, DEFERRED_ADD, DEFERRED_AND, DEFERRED_ASSIGN, DEFERRED_DIV, DEFERRED_MUL, DEFERRED_OR, DEFERRED_POW, DEFERRED_RATE_ASSIGN, DEFERRED_REM, DEFERRED_SHL, DEFERRED_SHR, DEFERRED_SUB, DEFERRED_USHR, DEFERRED_XOR, DIMLIST, DIV, DIV_ASSIGN, DO, DOT, DOUBLE_, DOUBLE_ARROW_RULE, DOUBLE_LITERAL, ELIST, EMPTY, ENHANCED_FOR, EOF, EQUALS, EXEC_RULE, EXPR, EXTENDS, FINAL_, FINALLY, FLOAT_, FLOAT_LITERAL, FOLDING, FOR, GE, GT, GUARD, IDENT, IF, IMPLEMENTS, IMPORT_ON_DEMAND, IN, INC, INDEX_OP, INSTANCE_INIT, INSTANCEOF, INSTANTIATOR, INT_, INT_LITERAL, INTERFACE, INVALID_EXPR, INVOKE_OP, ITERATING_, LABEL, LABELED_STATEMENT, LATE_MATCH, LCLIQUE, LE, LEFT_ARROW, LEFT_RIGHT_ARROW, LINE, LONG_, LONG_ARROW, LONG_LEFT_ARROW, LONG_LEFT_RIGHT_ARROW, LONG_LITERAL, LT, MARKER, METHOD, METHOD_CALL, METHOD_PATTERN, MINIMAL, MODIFIERS, MODULE, MUL, MUL_ASSIGN, NAME_PATTERN, NATIVE_, NEG, NEW, NODE, NODES, NORMAL, NOT, NOT_EQUALS, NULL_LITERAL, NULL_TREE_LOOKAHEAD, OPTIONAL_MATCH, OR, OR_ASSIGN, PACKAGE, PARAMETER_DEF, PARAMETERIZED_PATTERN, PARAMETERS, PATTERN_WITH_BLOCK, PLUS_ARROW, PLUS_LEFT_ARROW, PLUS_LEFT_RIGHT_ARROW, PLUS_LINE, POS, POST_DEC, POST_INC, POW, POW_ASSIGN, PRIVATE_, PRODUCE, PROTECTED_, PUBLIC_, QUALIFIED_NEW, QUALIFIED_SUPER, QUERY, QUERY_EXPR, QUESTION, QUOTE, RANGE, RANGE_EXACTLY, RANGE_MIN, RCLIQUE, REM, REM_ASSIGN, RETURN, ROOT, RULE, RULE_BLOCK, SCALE, SEMI, SEPARATE, SHELL_BLOCK, SHL, SHL_ASSIGN, SHORT_, SHR, SHR_ASSIGN, SINGLE_ELEMENT, SINGLE_MATCH, SINGLE_OPTIONAL_MATCH, SINGLE_STATIC_IMPORT, SINGLE_TYPE_IMPORT, SLASH_ARROW, SLASH_LEFT_ARROW, SLASH_LEFT_RIGHT_ARROW, SLASH_LINE, SLIST, STATIC_, STATIC_IMPORT_ON_DEMAND, STATIC_INIT, STATIC_MEMBER_CLASSES, STRICT_, STRING_LITERAL, SUB, SUB_ASSIGN, SUPER, SWITCH, SWITCH_GROUP, SYNCHRONIZED_, THIS, THROW, THROWS, TRANSIENT_, TRAVERSAL, TREE, TRY, TYPE_PATTERN, TYPECAST, TYPECHECK, UNARY_PREFIX, USHR, USHR_ASSIGN, VARARGS_, VARIABLE_DEF, VOID_, VOLATILE_, WHILE, WITH, WRAPPED_TYPE_PATTERN, X_LEFT_RIGHT_ARROW, XOR, XOR_ASSIGN, YIELD
-
Method Summary
Modifier and TypeMethodDescriptionboolean
allowsAmbiguousMembers
(Member first) Defines if ambiguous members are allowed.assignmentConversion
(Expression expr, Type type, Scope scope, antlr.collections.AST pos) castingConversion
(Expression expr, Type type, Scope scope, antlr.collections.AST pos) castingConversion
(Expression expr, Type type, Scope scope, antlr.collections.AST pos, String msg, boolean test) static void
checkOperatorFunction
(antlr.collections.AST params, antlr.collections.AST mods, antlr.collections.AST id, int symbol, RecognitionExceptionList exceptionList) compile
(CompilationUnit[] units, CClass shell, BytecodeWriter writer, FileSystem fs, Object dir, boolean keepExpressions) protected abstract CompilationUnitScope
compile
(ClassPath classPath, antlr.collections.AST tree, String source, Scope defaultImports, Annotation[] annotations, CClass shell) compileFieldExpression
(Field field, Expression expr, Scope scope, antlr.collections.AST pos) compileInstance
(Member m, Scope declaring, Scope s, antlr.collections.AST pos) static void
copyInfo
(Expression src, Expression dest) <T> T
createModel
(Class<T> type, Type<?> model, antlr.collections.AST pos) void
<T extends Annotation>
Annotation<T>getAnnotation
(Member member, Class<T> cls, boolean inherited) Type[]
Returns the argument types which are used inMembers.Resolution.isApplicable(Member, Members.Applicability, Scope)
to determine the applicability.static antlr.collections.AST
getAST
(Expression e) static BlockScope
Return the current value of theCompilationUnitScope
.Returns the package of the current compilation unit.int
getRun()
Returns the current run of the compiler.Return the current value of theTypeScope
.getWrapperTypeFor
(Type type, CompiletimeModel model, antlr.collections.AST pos) implicitConversion
(Expression expr, Type type, boolean allowD2F, Scope scope, antlr.collections.AST pos, String msg, boolean test) Perform autoconversion of the expression to target type.void
intersect
(IntersectionType intersection, Type newType, antlr.collections.AST pos) boolean
isApplicable
(Member m, Members.Applicability appl, Scope scope) Checks whether a memberm
is applicable.boolean
isLessThan
(Member m1, Members.Applicability a1, Member m2, Members.Applicability a2, Scope scope) Checks whether an applicable memberm1
is less specific than another applicable memberm2
.methodInvocationConversion
(Expression expr, Type type, Scope scope, antlr.collections.AST pos) static final String
modifiersToString
(long mods) returnConversion
(Expression expr, Type type, Scope scope, antlr.collections.AST pos) static Expression
setAST
(Expression e, antlr.collections.AST ast) static void
void
setLegalSupertype
(Type lst) void
setVerbose
(PrintWriter out) standardImplicitConversion
(Expression expr, Type type, boolean allowD2F, Scope scope, antlr.collections.AST pos, String msg, boolean test) Perform autoconversion of the expression to target type.boolean
supportsVersion
(int ver) Returns true if the specified version number designates a version of the JVM that is compatible with the target version currently set.typeForType
(Type type) verifyNotDeclared
(antlr.collections.AST name, BlockScope s) verifyNotDeclared
(String name, BlockScope s, antlr.collections.AST pos) wideningConversion
(Expression expr, Type type, Scope scope, antlr.collections.AST pos) Methods inherited from class antlr.TreeParser
getAST, getASTFactory, getTokenName, getTokenNames, match, match, matchNot, panic, reportError, reportError, reportWarning, setASTFactory, setASTNodeClass, setASTNodeType, traceIn, traceIndent, traceOut
-
Field Details
-
I18N
Resource bundle for messages. -
TYPE_AND_FIELD_DECLARATION
public static final int TYPE_AND_FIELD_DECLARATIONConstant forrun
indicating the first run. In this run, type and field declarations are processed.- See Also:
-
METHOD_DECLARATION
public static final int METHOD_DECLARATIONConstant forrun
indicating the second run. In this run, method and constructor declarations are processed.- See Also:
-
COMPILATION
public static final int COMPILATIONConstant forrun
indicating the third, final run. In this run, the actual expressions and statements are compiled.- See Also:
-
currentCompilationUnitScope
Stores the current CompilationUnitScope, if one was set. This field is set during parsing, so see Compiler.tree.g. -
options
-
EXPR_FINAL
public static final int EXPR_FINAL- See Also:
-
EXPR_THIS
public static final int EXPR_THIS- See Also:
-
MOD_ITERATING
public static final long MOD_ITERATING- See Also:
-
MOD_PARAMETER
public static final long MOD_PARAMETER- See Also:
-
MOD_ROUTINE
public static final long MOD_ROUTINE- See Also:
-
MOD_CONSTRUCTOR
public static final long MOD_CONSTRUCTOR- See Also:
-
MOD_THIS_PARAMETER
public static final long MOD_THIS_PARAMETER- See Also:
-
MOD_INITIALIZER
public static final long MOD_INITIALIZER- See Also:
-
MOD_CONST
public static final long MOD_CONST- See Also:
-
MOD_INSTANTIATOR
public static final long MOD_INSTANTIATOR- See Also:
-
MOD_MODULE
public static final long MOD_MODULE- See Also:
-
MOD_IMPLICIT_ARGUMENT
public static final long MOD_IMPLICIT_ARGUMENT- See Also:
-
MOD_STATIC_MEMBER_CLASSES
public static final long MOD_STATIC_MEMBER_CLASSES- See Also:
-
ROUTINE_MODIFIERS
public static final long ROUTINE_MODIFIERS- See Also:
-
problems
-
WARN_ON_IMPLICIT_MODIFIER
public static final long WARN_ON_IMPLICIT_MODIFIER- See Also:
-
PRODUCER_GET_ROOT
- See Also:
-
PRODUCER_BEGIN
- See Also:
-
PRODUCER_END
- See Also:
-
PRODUCER_PUSH
- See Also:
-
PRODUCER_POP
- See Also:
-
PRODUCER_SEPARATE
- See Also:
-
PRODUCER_CLIQUE_BEGIN
- See Also:
-
PRODUCER_CLIQUE_END
- See Also:
-
OPERATOR_NAME_NEG
- See Also:
-
OPERATOR_NAME_POS
- See Also:
-
OPERATOR_NAME_NOT
- See Also:
-
OPERATOR_NAME_COM
- See Also:
-
OPERATOR_NAME_INC
- See Also:
-
OPERATOR_NAME_DEC
- See Also:
-
OPERATOR_NAME_POST_INC
- See Also:
-
OPERATOR_NAME_POST_DEC
- See Also:
-
OPERATOR_NAME_ADD
- See Also:
-
OPERATOR_NAME_SUB
- See Also:
-
OPERATOR_NAME_MUL
- See Also:
-
OPERATOR_NAME_DIV
- See Also:
-
OPERATOR_NAME_REM
- See Also:
-
OPERATOR_NAME_POW
- See Also:
-
OPERATOR_NAME_COR
- See Also:
-
OPERATOR_NAME_CAND
- See Also:
-
OPERATOR_NAME_ADD_ASSIGN
- See Also:
-
OPERATOR_NAME_SUB_ASSIGN
- See Also:
-
OPERATOR_NAME_MUL_ASSIGN
- See Also:
-
OPERATOR_NAME_DIV_ASSIGN
- See Also:
-
OPERATOR_NAME_REM_ASSIGN
- See Also:
-
OPERATOR_NAME_POW_ASSIGN
- See Also:
-
OPERATOR_NAME_SHL
- See Also:
-
OPERATOR_NAME_SHR
- See Also:
-
OPERATOR_NAME_USHR
- See Also:
-
OPERATOR_NAME_SHL_ASSIGN
- See Also:
-
OPERATOR_NAME_SHR_ASSIGN
- See Also:
-
OPERATOR_NAME_USHR_ASSIGN
- See Also:
-
OPERATOR_NAME_XOR
- See Also:
-
OPERATOR_NAME_OR
- See Also:
-
OPERATOR_NAME_AND
- See Also:
-
OPERATOR_NAME_XOR_ASSIGN
- See Also:
-
OPERATOR_NAME_OR_ASSIGN
- See Also:
-
OPERATOR_NAME_AND_ASSIGN
- See Also:
-
OPERATOR_NAME_EQUALS
- See Also:
-
OPERATOR_NAME_NOT_EQUALS
- See Also:
-
OPERATOR_NAME_LT
- See Also:
-
OPERATOR_NAME_LE
- See Also:
-
OPERATOR_NAME_GT
- See Also:
-
OPERATOR_NAME_GE
- See Also:
-
OPERATOR_NAME_CMP
- See Also:
-
OPERATOR_NAME_RANGE
- See Also:
-
OPERATOR_NAME_IN
- See Also:
-
OPERATOR_NAME_GUARD
- See Also:
-
OPERATOR_NAME_ARROW
- See Also:
-
OPERATOR_NAME_LEFT_ARROW
- See Also:
-
OPERATOR_NAME_LONG_ARROW
- See Also:
-
OPERATOR_NAME_LONG_LEFT_ARROW
- See Also:
-
OPERATOR_NAME_LONG_LEFT_RIGHT_ARROW
- See Also:
-
OPERATOR_NAME_PLUS_LEFT_ARROW
- See Also:
-
OPERATOR_NAME_PLUS_ARROW
- See Also:
-
OPERATOR_NAME_PLUS_LEFT_RIGHT_ARROW
- See Also:
-
OPERATOR_NAME_PLUS_LINE
- See Also:
-
OPERATOR_NAME_SLASH_LEFT_ARROW
- See Also:
-
OPERATOR_NAME_SLASH_ARROW
- See Also:
-
OPERATOR_NAME_SLASH_LEFT_RIGHT_ARROW
- See Also:
-
OPERATOR_NAME_SLASH_LINE
- See Also:
-
OPERATOR_NAME_LEFT_RIGHT_ARROW
- See Also:
-
OPERATOR_NAME_X_LEFT_RIGHT_ARROW
- See Also:
-
OPERATOR_NAME_LINE
- See Also:
-
OPERATOR_NAME_INDEX
- See Also:
-
OPERATOR_NAME_INVOKE
- See Also:
-
OPERATOR_NAME_QUOTE
- See Also:
-
OPERATOR_NAME_SPACE
- See Also:
-
OPERATOR_NAME_DEFERRED_ASSIGN
- See Also:
-
OPERATOR_NAME_DEFERRED_RATE_ASSIGN
- See Also:
-
OPERATOR_NAME_DEFERRED_POW
- See Also:
-
OPERATOR_NAME_DEFERRED_MUL
- See Also:
-
OPERATOR_NAME_DEFERRED_DIV
- See Also:
-
OPERATOR_NAME_DEFERRED_REM
- See Also:
-
OPERATOR_NAME_DEFERRED_ADD
- See Also:
-
OPERATOR_NAME_DEFERRED_SUB
- See Also:
-
OPERATOR_NAME_DEFERRED_SHL
- See Also:
-
OPERATOR_NAME_DEFERRED_SHR
- See Also:
-
OPERATOR_NAME_DEFERRED_USHR
- See Also:
-
OPERATOR_NAME_DEFERRED_AND
- See Also:
-
OPERATOR_NAME_DEFERRED_XOR
- See Also:
-
OPERATOR_NAME_DEFERRED_OR
- See Also:
-
-
Method Details
-
getRun
public int getRun()Returns the current run of the compiler. The compiler works in three runs. The return value indicates the current run.- Returns:
- current run
- See Also:
-
compile
public Object compile(ClassPath classPath, Scope defaultImports, Parser parser, CClass shell) throws IOException, RecognitionException - Throws:
IOException
RecognitionException
-
compile
protected abstract CompilationUnitScope compile(ClassPath classPath, antlr.collections.AST tree, String source, Scope defaultImports, Annotation[] annotations, CClass shell) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
compile
public CompilationUnitScope[] compile(CompilationUnit[] units, CClass shell, BytecodeWriter writer, FileSystem fs, Object dir, boolean keepExpressions) throws IOException - Throws:
IOException
-
supportsVersion
public boolean supportsVersion(int ver) Returns true if the specified version number designates a version of the JVM that is compatible with the target version currently set. Valid values for the version number are the constants in org.objectweb.asm.Opcodes.V* For instance a call supportsVersion(Opcodes.V1_4) with Opcodes.V1_4 currently set as target would return true. The same call with Opcodes.V1_3 set as target would return false.- Parameters:
ver
-- Returns:
-
getPackage
Returns the package of the current compilation unit.- Returns:
- current package
-
getCompilationUnitScope
Return the current value of theCompilationUnitScope
.- Returns:
- current
CompilationUnitScope
-
getTypeScope
Return the current value of theTypeScope
.- Returns:
- current
TypeScope
-
modifiersToString
-
copyInfo
-
setBlockScope
-
getBlockScope
-
setAST
-
getAST
-
setLegalSupertype
-
setVerbose
-
verifyNotDeclared
-
verifyNotDeclared
-
intersect
-
getWrapperTypeFor
-
castingConversion
public Expression castingConversion(Expression expr, Type type, Scope scope, antlr.collections.AST pos) -
wideningConversion
public Expression wideningConversion(Expression expr, Type type, Scope scope, antlr.collections.AST pos) -
methodInvocationConversion
public Expression methodInvocationConversion(Expression expr, Type type, Scope scope, antlr.collections.AST pos) -
assignmentConversion
public Expression assignmentConversion(Expression expr, Type type, Scope scope, antlr.collections.AST pos) -
returnConversion
public Expression returnConversion(Expression expr, Type type, Scope scope, antlr.collections.AST pos) -
typeForType
-
getAnnotation
public <T extends Annotation> Annotation<T> getAnnotation(Member member, Class<T> cls, boolean inherited) -
implicitConversion
public Expression implicitConversion(Expression expr, Type type, boolean allowD2F, Scope scope, antlr.collections.AST pos, String msg, boolean test) Perform autoconversion of the expression to target type. Autoconversion includes widening conversions, boxing and unboxing, and allows to transform an object of type A into an object of type B by means of conversion functions. Every function declared as 'static B valueOf(A)', 'static B toB(A)', 'B A.toB()' and constructors of the form 'B(A)' are considered as conversion functions. If more than one conversion from type A to type B using those conversion functions is possible, the conversion is ambiguous and results in an error.- Parameters:
expr
- source expressiontype
- target typeboxOnly
- only check for autoboxing/unboxing, no further autoconversionsscope
- current scopepos
- location to use for error reportsmsg
- message key to use for error reports- Returns:
- auto-converted expression, or
null
if no such conversion is possible andmsg
isnull
-
castingConversion
public Expression castingConversion(Expression expr, Type type, Scope scope, antlr.collections.AST pos, String msg, boolean test) -
standardImplicitConversion
public Expression standardImplicitConversion(Expression expr, Type type, boolean allowD2F, Scope scope, antlr.collections.AST pos, String msg, boolean test) Perform autoconversion of the expression to target type. Autoconversion includes widening conversions, boxing and unboxing, and allows to transform an object of type A into an object of type B by means of conversion functions. Every function declared as 'static B valueOf(A)', 'static B toB(A)', 'B A.toB()' and constructors of the form 'B(A)' are considered as conversion functions. If more than one conversion from type A to type B using those conversion functions is possible, the conversion is ambiguous and results in an error.- Parameters:
expr
- source expressiontype
- target typeboxOnly
- only check for autoboxing/unboxing, no further autoconversionsscope
- current scopepos
- location to use for error reportsmsg
- message key to use for error reports- Returns:
- auto-converted expression, or
null
if no such conversion is possible andmsg
isnull
-
createModel
-
allowsAmbiguousMembers
Description copied from interface:Members.Resolution
Defines if ambiguous members are allowed. If so, ambiguities between members do not cause an exception be thrown inMembers#find(Resolution)
; the first member is returned.- Specified by:
allowsAmbiguousMembers
in interfaceMembers.Resolution
- Parameters:
first
- the first member of a set of ambiguous members- Returns:
true
iff ambiguous members are allowed andfirst
shall be returned as the result of resolution
-
isApplicable
Description copied from interface:Members.Resolution
Checks whether a memberm
is applicable. The quality of applicability is stored inapplOut
by this method.- Specified by:
isApplicable
in interfaceMembers.Resolution
- Parameters:
m
- a memberappl
- the quality of applicability is stored here by this methodscope
- scope in which the member is accessed- Returns:
true
iffm
is applicable
-
getArgumentTypes
Description copied from interface:Members.Resolution
Returns the argument types which are used inMembers.Resolution.isApplicable(Member, Members.Applicability, Scope)
to determine the applicability. This method is only invoked to generate an error message in case no applicable member was found.- Specified by:
getArgumentTypes
in interfaceMembers.Resolution
- Returns:
- argument types
-
isLessThan
public boolean isLessThan(Member m1, Members.Applicability a1, Member m2, Members.Applicability a2, Scope scope) Description copied from interface:Members.Resolution
Checks whether an applicable memberm1
is less specific than another applicable memberm2
. The applicablities are the same instances which have been passed before toMembers.Resolution.isApplicable(Member, Members.Applicability, Scope)
.- Specified by:
isLessThan
in interfaceMembers.Resolution
- Parameters:
m1
- a membera1
-m1
's applicability as determined byMembers.Resolution.isApplicable(Member, Members.Applicability, Scope)
m2
- another membera2
-m2
's applicability as determined byMembers.Resolution.isApplicable(Member, Members.Applicability, Scope)
scope
- scope in which the member is accessed- Returns:
true
iffm1
is less specific thanm2
-
compileFieldExpression
public Expression compileFieldExpression(Field field, Expression expr, Scope scope, antlr.collections.AST pos) -
compileInstance
-
finish
-
checkOperatorFunction
public static void checkOperatorFunction(antlr.collections.AST params, antlr.collections.AST mods, antlr.collections.AST id, int symbol, RecognitionExceptionList exceptionList)
-