Class Parser
- All Implemented Interfaces:
Constants
,ParserActions
,RuntimeConstants
- Direct Known Subclasses:
BatchParser
This class implements an operator precedence parser. Errors are reported to the Environment object, if the error can't be resolved immediately, a SyntaxError exception is thrown.
Error recovery is implemented by catching SyntaxError exceptions and discarding input tokens until an input token is reached that is possibly a legal continuation.
The parse tree that is constructed represents the input exactly (no rewrites to simpler forms). This is important if the resulting tree is to be used for code formatting in a programming environment. Currently only documentation comments are retained.
The parsing algorithm does NOT use any type information. Changes in the type system do not affect the structure of the parse tree. This restriction does introduce an ambiguity an expression of the form: (e1) e2 is assumed to be a cast if e2 does not start with an operator. That means that (a) - b is interpreted as subtract b from a and not cast negative b to type a. However, if a is a simple type (byte, int, ...) then it is assumed to be a cast.
WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
(package private) ParserActions
Usuallythis.actions == (ParserActions)this
.private IdentifierToken[]
protected int
private Node[]
private Type[]
private ClassDefinition
private int
protected Scanner
Usuallythis.scanner == (Scanner)this
.Fields inherited from class org.glassfish.rmic.tools.java.Scanner
ch, charValue, docComment, doubleValue, env, EOF, floatValue, idValue, in, intValue, LINEINC, longValue, OFFSETINC, pos, prevPos, radix, scanComments, stringValue, token
Fields inherited from interface org.glassfish.rmic.tools.java.Constants
ABSTRACT, ACCM_CLASS, ACCM_FIELD, ACCM_INNERCLASS, ACCM_MEMBER, ACCM_METHOD, ADD, AND, ARRAY, ARRAYACCESS, ASGADD, ASGBITAND, ASGBITOR, ASGBITXOR, ASGDIV, ASGLSHIFT, ASGMUL, ASGREM, ASGRSHIFT, ASGSUB, ASGURSHIFT, ASSIGN, ATT_ALL, ATT_ALLCLASSES, ATT_CODE, BITAND, BITNOT, BITOR, BITXOR, BOOLEAN, BOOLEANVAL, BREAK, BYTE, BYTEVAL, CASE, CAST, CATCH, CHAR, CHARVAL, CLASS, COLON, COMMA, COMMENT, COND, CONST, CONTINUE, CONVERT, CS_BINARY, CS_CHECKED, CS_COMPILED, CS_NOTFOUND, CS_PARSED, CS_SOURCE, CS_UNDECIDED, CS_UNDEFINED, CT_BLOCK, CT_BRANCH_FALSE, CT_BRANCH_TRUE, CT_CASE, CT_FIKT_METHOD, CT_FIKT_RET, CT_FIRST_KIND, CT_LAST_KIND, CT_METHOD, CT_SWITH_WO_DEF, DEC, DECLARATION, DEFAULT, DIV, DO, DOUBLE, DOUBLEVAL, ELSE, EQ, ERROR, EXPR, EXPRESSION, EXTENDS, F_COVDATA, F_COVERAGE, F_DEBUG_LINES, F_DEBUG_SOURCE, F_DEBUG_VARS, F_DEPENDENCIES, F_DEPRECATION, F_DUMP, F_ERRORSREPORTED, F_OPT, F_OPT_INTERCLASS, F_PRINT_DEPENDENCIES, F_STRICTDEFAULT, F_VERBOSE, F_VERSION12, F_WARNINGS, FALSE, FIELD, FINAL, FINALLY, FLOAT, FLOATVAL, FOR, GE, GOTO, GT, idAppend, idClass, idClassInit, idClone, idCode, idConstantValue, idCoverageTable, idDeprecated, idDocumentation, IDENT, idExceptions, idFinallyReturnValue, idGetClass, idInit, idInnerClasses, idJavaIoSerializable, idJavaLang, idJavaLangClass, idJavaLangCloneable, idJavaLangError, idJavaLangException, idJavaLangObject, idJavaLangRuntimeException, idJavaLangString, idJavaLangStringBuffer, idJavaLangThrowable, idLength, idLineNumberTable, idLocalVariableTable, idNew, idNull, idSourceFile, idStar, idSuper, idSynthetic, idThis, idToString, idTYPE, idValueOf, IF, IMPLEMENTS, IMPORT, INC, INLINEMETHOD, INLINENEWINSTANCE, INLINERETURN, INSTANCEOF, INT, INTERFACE, INTVAL, LBRACE, LE, LENGTH, LONG, LONGVAL, LPAREN, LSHIFT, LSQBRACKET, LT, M_ABSTRACT, M_ANONYMOUS, M_DEPRECATED, M_FINAL, M_INLINEABLE, M_INTERFACE, M_LOCAL, M_NATIVE, M_PRIVATE, M_PROTECTED, M_PUBLIC, M_STATIC, M_STRICTFP, M_SYNCHRONIZED, M_SYNTHETIC, M_TRANSIENT, M_VOLATILE, MAXFILESIZE, MAXLINENUMBER, METHOD, MM_CLASS, MM_FIELD, MM_MEMBER, MM_METHOD, MUL, NATIVE, NE, NEG, NEW, NEWARRAY, NEWFROMNAME, NEWINSTANCE, NOT, NULL, opNames, opPrecedence, OR, PACKAGE, paraDeprecated, POS, POSTDEC, POSTINC, PREDEC, prefixAccess, prefixArray, prefixClass, prefixLoc, prefixThis, prefixVal, PREINC, PRIVATE, PROTECTED, PUBLIC, QUESTIONMARK, RBRACE, REM, RETURN, RPAREN, RSHIFT, RSQBRACKET, SEMICOLON, SHORT, SHORTVAL, SIG_INNERCLASS, SIGC_INNERCLASS, STAT, STATIC, STRICTFP, STRINGVAL, SUB, SUPER, SWITCH, SYNCHRONIZED, TC_ARRAY, TC_BOOLEAN, TC_BYTE, TC_CHAR, TC_CLASS, TC_DOUBLE, TC_ERROR, TC_FLOAT, TC_INT, TC_LONG, TC_METHOD, TC_NULL, TC_SHORT, TC_VOID, THIS, THROW, THROWS, TM_ARRAY, TM_BOOLEAN, TM_BYTE, TM_CHAR, TM_CLASS, TM_DOUBLE, TM_ERROR, TM_FLOAT, TM_INT, TM_INT32, TM_INTEGER, TM_LONG, TM_METHOD, TM_NULL, TM_NUM32, TM_NUM64, TM_NUMBER, TM_REAL, TM_REFERENCE, TM_SHORT, TM_VOID, tracing, TRANSIENT, TRUE, TRY, TYPE, URSHIFT, VARDECLARATION, VOID, VOLATILE, WHEREOFFSETBITS, WHILE
Fields inherited from interface org.glassfish.rmic.tools.java.RuntimeConstants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_CLASS, CONSTANT_DOUBLE, CONSTANT_FIELD, CONSTANT_FLOAT, CONSTANT_INTEGER, CONSTANT_INTERFACEMETHOD, CONSTANT_INVOKEDYNAMIC, CONSTANT_LONG, CONSTANT_METHOD, CONSTANT_METHODHANDLE, CONSTANT_METHODTYPE, CONSTANT_NAMEANDTYPE, CONSTANT_STRING, CONSTANT_UNICODE, CONSTANT_UTF8, JAVA_DEFAULT_MINOR_VERSION, JAVA_DEFAULT_VERSION, JAVA_MAGIC, JAVA_MAX_SUPPORTED_MINOR_VERSION, JAVA_MAX_SUPPORTED_VERSION, JAVA_MIN_SUPPORTED_VERSION, opc_aaload, opc_aastore, opc_aconst_null, opc_aload, opc_aload_0, opc_aload_1, opc_aload_2, opc_aload_3, opc_anewarray, opc_areturn, opc_arraylength, opc_astore, opc_astore_0, opc_astore_1, opc_astore_2, opc_astore_3, opc_athrow, opc_baload, opc_bastore, opc_bipush, opc_breakpoint, opc_caload, opc_castore, opc_checkcast, opc_d2f, opc_d2i, opc_d2l, opc_dadd, opc_daload, opc_dastore, opc_dcmpg, opc_dcmpl, opc_dconst_0, opc_dconst_1, opc_ddiv, opc_dead, opc_dload, opc_dload_0, opc_dload_1, opc_dload_2, opc_dload_3, opc_dmul, opc_dneg, opc_drem, opc_dreturn, opc_dstore, opc_dstore_0, opc_dstore_1, opc_dstore_2, opc_dstore_3, opc_dsub, opc_dup, opc_dup_x1, opc_dup_x2, opc_dup2, opc_dup2_x1, opc_dup2_x2, opc_f2d, opc_f2i, opc_f2l, opc_fadd, opc_faload, opc_fastore, opc_fcmpg, opc_fcmpl, opc_fconst_0, opc_fconst_1, opc_fconst_2, opc_fdiv, opc_fload, opc_fload_0, opc_fload_1, opc_fload_2, opc_fload_3, opc_fmul, opc_fneg, opc_frem, opc_freturn, opc_fstore, opc_fstore_0, opc_fstore_1, opc_fstore_2, opc_fstore_3, opc_fsub, opc_getfield, opc_getstatic, opc_goto, opc_goto_w, opc_i2b, opc_i2c, opc_i2d, opc_i2f, opc_i2l, opc_i2s, opc_iadd, opc_iaload, opc_iand, opc_iastore, opc_iconst_0, opc_iconst_1, opc_iconst_2, opc_iconst_3, opc_iconst_4, opc_iconst_5, opc_iconst_m1, opc_idiv, opc_if_acmpeq, opc_if_acmpne, opc_if_icmpeq, opc_if_icmpge, opc_if_icmpgt, opc_if_icmple, opc_if_icmplt, opc_if_icmpne, opc_ifeq, opc_ifge, opc_ifgt, opc_ifle, opc_iflt, opc_ifne, opc_ifnonnull, opc_ifnull, opc_iinc, opc_iload, opc_iload_0, opc_iload_1, opc_iload_2, opc_iload_3, opc_imul, opc_ineg, opc_instanceof, opc_invokedynamic, opc_invokeinterface, opc_invokespecial, opc_invokestatic, opc_invokevirtual, opc_ior, opc_irem, opc_ireturn, opc_ishl, opc_ishr, opc_istore, opc_istore_0, opc_istore_1, opc_istore_2, opc_istore_3, opc_isub, opc_iushr, opc_ixor, opc_jsr, opc_jsr_w, opc_l2d, opc_l2f, opc_l2i, opc_label, opc_ladd, opc_laload, opc_land, opc_lastore, opc_lcmp, opc_lconst_0, opc_lconst_1, opc_ldc, opc_ldc_w, opc_ldc2_w, opc_ldiv, opc_lload, opc_lload_0, opc_lload_1, opc_lload_2, opc_lload_3, opc_lmul, opc_lneg, opc_lookupswitch, opc_lor, opc_lrem, opc_lreturn, opc_lshl, opc_lshr, opc_lstore, opc_lstore_0, opc_lstore_1, opc_lstore_2, opc_lstore_3, opc_lsub, opc_lushr, opc_lxor, opc_monitorenter, opc_monitorexit, opc_multianewarray, opc_new, opc_newarray, opc_nop, opc_pop, opc_pop2, opc_putfield, opc_putstatic, opc_ret, opc_return, opc_saload, opc_sastore, opc_sipush, opc_swap, opc_tableswitch, opc_try, opc_wide, opcLengths, opcNames, SIG_ARRAY, SIG_BOOLEAN, SIG_BYTE, SIG_CHAR, SIG_CLASS, SIG_DOUBLE, SIG_ENDCLASS, SIG_ENDMETHOD, SIG_FLOAT, SIG_INT, SIG_LONG, SIG_METHOD, SIG_PACKAGE, SIG_SHORT, SIG_VOID, SIGC_ARRAY, SIGC_BOOLEAN, SIGC_BYTE, SIGC_CHAR, SIGC_CLASS, SIGC_DOUBLE, SIGC_ENDCLASS, SIGC_ENDMETHOD, SIGC_FLOAT, SIGC_INT, SIGC_LONG, SIGC_METHOD, SIGC_PACKAGE, SIGC_SHORT, SIGC_VOID, T_BOOLEAN, T_BYTE, T_CHAR, T_CLASS, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Parser
(Environment env, InputStream in) Create a parserprotected
Create a parser, given a scanner.Parser
(Scanner scanner, ParserActions actions) Create a parser, given a scanner and the semantic callback. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addArgument
(int mod, Type t, IdentifierToken nm) protected final void
addArgument
(Node n) protected void
beginClass
(long off, String doc, int mod, Identifier nm, Identifier sup, Identifier[] impl) Deprecated.Use the version with the IdentifierToken arguments.beginClass
(long off, String doc, int mod, IdentifierToken nm, IdentifierToken sup, IdentifierToken[] impl) Deprecated.protected void
defineField
(long where, String doc, int mod, Type t, Identifier nm, Identifier[] args, Identifier[] exp, Node val) Deprecated.Use the version with the IdentifierToken arguments.void
defineField
(long where, ClassDefinition c, String doc, int mod, Type t, IdentifierToken nm, IdentifierToken[] args, IdentifierToken[] exp, Node val) Deprecated.void
endClass
(long off, ClassDefinition c) Deprecated.protected void
endClass
(long off, Identifier nm) Deprecated.Use the version with the IdentifierToken arguments.protected void
expect
(int t) Expect a token, return its value, scan the next token or throw an exception.protected final Expression[]
exprArgs
(int index) protected ClassDefinition
Report the current class under construction.protected void
importClass
(long off, Identifier nm) Deprecated.Use the version with the IdentifierToken arguments.void
importClass
(long off, IdentifierToken nm) Deprecated.protected void
importPackage
(long off, Identifier nm) Deprecated.Use the version with the IdentifierToken arguments.void
importPackage
(long off, IdentifierToken nm) Deprecated.void
match
(int open, int close) Scan to a matching '}', ']' or ')'.protected void
packageDeclaration
(long off, Identifier nm) Deprecated.void
packageDeclaration
(long off, IdentifierToken nm) Deprecated.protected Type
Parse the tail of a type expression, which might be array brackets.protected Expression
Given a left-hand term, parse an operator and right-hand term.protected Statement
protected void
Parse a top-level class or interface declaration.protected ClassDefinition
parseClassBody
(IdentifierToken nm, int mod, int ctx, String doc, Vector<IdentifierToken> ext, Vector<IdentifierToken> impl, long p) Parse the body of a class or interface declaration, starting at the left brace.protected Statement
parseDeclaration
(long p, int mod, Expression type) Parse declaration, called after the type expression has been parsed and the current token is IDENT.protected Expression
Parse an expression.protected void
Parse a field.void
Parse an Java file.protected Identifier
parseIdentifier
(boolean star) Deprecated.protected void
parseInheritance
(Vector<IdentifierToken> ext, Vector<IdentifierToken> impl) protected Statement
parseLocalClass
(int mod) Parse a block-local class or interface declaration.protected Expression
Parse a method invocation.protected int
parseModifiers
(int mask) Parse a possibly-empty sequence of modifier keywords.protected IdentifierToken
parseName
(boolean star) Parse an identifier.protected ClassDefinition
parseNamedClass
(int mod, int ctx, String doc) Parse a named class or interface declaration, starting at "class" or "interface".protected Expression
parseNewInstanceExpression
(long p, Expression outerArg, Expression type) Parse a new instance expression.protected Statement
Parse a statement.protected Expression
Parse a primary expression.protected Type
Parse a type expression, this results in a Type.protected Expression
Parse a type expression.protected void
recoverField
(ClassDefinition newClass) Recover after a syntax error in a field.protected void
Recover after a syntax error in the file.protected boolean
Recover after a syntax error in a statement.long
scan()
Scan the next token.protected final Statement[]
statArgs
(int index) protected void
Check if an expression is a legal toplevel expression.Methods inherited from class org.glassfish.rmic.tools.java.Scanner
getEndPos, getIdToken, useInputStream, xscan
-
Field Details
-
actions
ParserActions actionsUsuallythis.actions == (ParserActions)this
. However, a delegate scanner can produce tokens for this parser, in which case(Scanner)this
is unused, except forthis.token
andthis.pos
instance variables which are filled from the real scanner bythis.scan()
and the constructor. -
args
-
argIndex
protected int argIndex -
aCount
private int aCount -
aTypes
-
aNames
-
curClass
-
FPstate
private int FPstate -
scanner
Usuallythis.scanner == (Scanner)this
. However, a delegate scanner can produce tokens for this parser, in which case(Scanner)this
is unused, except forthis.token
andthis.pos
instance variables which are filled from the real scanner bythis.scan()
and the constructor.
-
-
Constructor Details
-
Parser
Create a parser- Throws:
IOException
-
Parser
Create a parser, given a scanner.- Throws:
IOException
-
Parser
Create a parser, given a scanner and the semantic callback.- Throws:
IOException
-
-
Method Details
-
packageDeclaration
Deprecated.package declaration- Specified by:
packageDeclaration
in interfaceParserActions
-
packageDeclaration
Deprecated. -
importClass
Deprecated.import class- Specified by:
importClass
in interfaceParserActions
-
importClass
Deprecated.Use the version with the IdentifierToken arguments. -
importPackage
Deprecated.import package- Specified by:
importPackage
in interfaceParserActions
-
importPackage
Deprecated.Use the version with the IdentifierToken arguments. -
beginClass
@Deprecated public ClassDefinition beginClass(long off, String doc, int mod, IdentifierToken nm, IdentifierToken sup, IdentifierToken[] impl) Deprecated.Define class- Specified by:
beginClass
in interfaceParserActions
- Returns:
- a cookie for the class This cookie is used by the parser when calling defineField and endClass, and is not examined otherwise.
-
beginClass
@Deprecated protected void beginClass(long off, String doc, int mod, Identifier nm, Identifier sup, Identifier[] impl) Deprecated.Use the version with the IdentifierToken arguments. -
getCurrentClass
Report the current class under construction. By default, it's a no-op which returns null. It may only be called before the corresponding endClass(). -
endClass
Deprecated.End class- Specified by:
endClass
in interfaceParserActions
- Parameters:
c
- a cookie returned by the corresponding beginClass call
-
endClass
Deprecated.Use the version with the IdentifierToken arguments. -
defineField
@Deprecated public void defineField(long where, ClassDefinition c, String doc, int mod, Type t, IdentifierToken nm, IdentifierToken[] args, IdentifierToken[] exp, Node val) Deprecated.Define a field- Specified by:
defineField
in interfaceParserActions
- Parameters:
c
- a cookie returned by the corresponding beginClass call
-
defineField
@Deprecated protected void defineField(long where, String doc, int mod, Type t, Identifier nm, Identifier[] args, Identifier[] exp, Node val) Deprecated.Use the version with the IdentifierToken arguments. -
addArgument
-
exprArgs
-
statArgs
-
expect
Expect a token, return its value, scan the next token or throw an exception.- Throws:
SyntaxError
IOException
-
parseTypeExpression
Parse a type expression. Does not parse the []'s.- Throws:
SyntaxError
IOException
-
parseMethodExpression
protected Expression parseMethodExpression(Expression e, Identifier id) throws SyntaxError, IOException Parse a method invocation. Should be called when the current then is the '(' of the argument list.- Throws:
SyntaxError
IOException
-
parseNewInstanceExpression
protected Expression parseNewInstanceExpression(long p, Expression outerArg, Expression type) throws SyntaxError, IOException Parse a new instance expression. Should be called when the current token is the '(' of the argument list.- Throws:
SyntaxError
IOException
-
parseTerm
Parse a primary expression.- Throws:
SyntaxError
IOException
-
parseExpression
Parse an expression.- Throws:
SyntaxError
IOException
-
parseBinaryExpression
Given a left-hand term, parse an operator and right-hand term.- Throws:
SyntaxError
IOException
-
recoverStatement
Recover after a syntax error in a statement. This involves discarding tokens until EOF or a possible continuation is encountered.- Throws:
SyntaxError
IOException
-
parseDeclaration
protected Statement parseDeclaration(long p, int mod, Expression type) throws SyntaxError, IOException Parse declaration, called after the type expression has been parsed and the current token is IDENT.- Throws:
SyntaxError
IOException
-
topLevelExpression
Check if an expression is a legal toplevel expression. Only method, inc, dec, and new expression are allowed. -
parseStatement
Parse a statement.- Throws:
SyntaxError
IOException
-
parseBlockStatement
- Throws:
SyntaxError
IOException
-
parseName
Parse an identifier. ie: a.b.c returns "a.b.c" If star is true then "a.b.*" is allowed. The return value encodes both the identifier and its location.- Throws:
SyntaxError
IOException
-
parseIdentifier
Deprecated.- Throws:
SyntaxError
IOException
- See Also:
-
parseType
Parse a type expression, this results in a Type. The parse includes trailing array brackets.- Throws:
SyntaxError
IOException
-
parseArrayBrackets
Parse the tail of a type expression, which might be array brackets. Return the given type, as possibly modified by the suffix.- Throws:
SyntaxError
IOException
-
addArgument
-
parseModifiers
Parse a possibly-empty sequence of modifier keywords. Return the resulting bitmask. Diagnose repeated modifiers, but make no other checks. Only modifiers mentioned in the given bitmask are scanned; an unmatched modifier must be handled by the caller.- Throws:
IOException
-
parseField
Parse a field.- Throws:
SyntaxError
IOException
-
recoverField
Recover after a syntax error in a field. This involves discarding tokens until an EOF or a possible legal continuation is encountered.- Throws:
SyntaxError
IOException
-
parseClass
Parse a top-level class or interface declaration.- Throws:
SyntaxError
IOException
-
parseLocalClass
Parse a block-local class or interface declaration.- Throws:
SyntaxError
IOException
-
parseNamedClass
protected ClassDefinition parseNamedClass(int mod, int ctx, String doc) throws SyntaxError, IOException Parse a named class or interface declaration, starting at "class" or "interface".- Throws:
SyntaxError
IOException
-
parseInheritance
protected void parseInheritance(Vector<IdentifierToken> ext, Vector<IdentifierToken> impl) throws SyntaxError, IOException - Throws:
SyntaxError
IOException
-
parseClassBody
protected ClassDefinition parseClassBody(IdentifierToken nm, int mod, int ctx, String doc, Vector<IdentifierToken> ext, Vector<IdentifierToken> impl, long p) throws SyntaxError, IOException Parse the body of a class or interface declaration, starting at the left brace.- Throws:
SyntaxError
IOException
-
recoverFile
Recover after a syntax error in the file. This involves discarding tokens until an EOF or a possible legal continuation is encountered.- Throws:
IOException
-
parseFile
public void parseFile()Parse an Java file. -
scan
Description copied from class:Scanner
Scan the next token.- Overrides:
scan
in classScanner
- Returns:
- the position of the previous token.
- Throws:
IOException
-
match
Description copied from class:Scanner
Scan to a matching '}', ']' or ')'. The current token must be a '{', '[' or '(';- Overrides:
match
in classScanner
- Throws:
IOException
-