langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java
author mcimadamore
Mon, 21 Jan 2013 20:14:39 +0000
changeset 15375 d2529dc91d77
parent 15367 31b57f2b8d0b
child 15377 515846bb6637
permissions -rw-r--r--
8006566: Remove transient lambda-related guards from JavacParser Summary: Remove transitional internal flag for allowing intersection types in cast Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.parser;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
    30
import com.sun.source.tree.MemberReferenceTree.ReferenceMode;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
    31
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
    32
import com.sun.tools.javac.code.*;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
    33
import com.sun.tools.javac.parser.Tokens.*;
10948
063463f6535f 7104201: Refactor DocCommentScanner
mcimadamore
parents: 10815
diff changeset
    34
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.tree.*;
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
    36
import com.sun.tools.javac.tree.JCTree.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.util.*;
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
    38
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
    39
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
    42
import static com.sun.tools.javac.parser.Tokens.TokenKind.*;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
    43
import static com.sun.tools.javac.parser.Tokens.TokenKind.ASSERT;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
    44
import static com.sun.tools.javac.parser.Tokens.TokenKind.CASE;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
    45
import static com.sun.tools.javac.parser.Tokens.TokenKind.CATCH;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
    46
import static com.sun.tools.javac.parser.Tokens.TokenKind.EQ;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
    47
import static com.sun.tools.javac.parser.Tokens.TokenKind.GT;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
    48
import static com.sun.tools.javac.parser.Tokens.TokenKind.IMPORT;
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
    49
import static com.sun.tools.javac.parser.Tokens.TokenKind.LT;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
    50
import static com.sun.tools.javac.tree.JCTree.Tag.*;
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
    51
import static com.sun.tools.javac.util.ListBuffer.lb;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
/** The parser maps a token sequence into an abstract syntax
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *  tree. It operates by recursive descent, with code derived
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  systematically from an LL(1) grammar. For efficiency reasons, an
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  operator precedence scheme is used for parsing binary operation
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  expressions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    59
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    60
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 */
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
    64
public class JavacParser implements Parser {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    /** The number of precedence levels of infix operators.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    private static final int infixPrecedenceLevels = 10;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    /** The scanner used for lexical analysis.
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     */
10200
56cc93e7b6ef 7068902: (javac) allow enabling or disabling of String folding
ksrini
parents: 10199
diff changeset
    72
    protected Lexer S;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /** The factory to be used for abstract syntax tree construction.
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    protected TreeMaker F;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    /** The log to be used for error diagnostics.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    private Log log;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    /** The Source language setting. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    private Source source;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /** The name table. */
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1258
diff changeset
    86
    private Names names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
    88
    /** End position mappings container */
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
    89
    private final AbstractEndPosTable endPosTable;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
    90
14450
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    91
    interface ErrorRecoveryAction {
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    92
        JCTree doRecover(JavacParser parser);
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    93
    }
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    94
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    95
    enum BasicErrorRecoveryAction implements ErrorRecoveryAction {
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    96
        BLOCK_STMT {public JCTree doRecover(JavacParser parser) { return parser.parseStatementAsBlock(); }},
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    97
        CATCH_CLAUSE {public JCTree doRecover(JavacParser parser) { return parser.catchClause(); }}
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    98
    }
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
    99
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** Construct a parser from a given scanner, tree factory and log.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     */
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   102
    protected JavacParser(ParserFactory fac,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
                     Lexer S,
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   104
                     boolean keepDocComments,
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   105
                     boolean keepLineMap,
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   106
                     boolean keepEndPositions) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        this.S = S;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   108
        nextToken(); // prime the pump
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        this.F = fac.F;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        this.log = fac.log;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        this.names = fac.names;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        this.source = fac.source;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        this.allowGenerics = source.allowGenerics();
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        this.allowVarargs = source.allowVarargs();
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        this.allowAsserts = source.allowAsserts();
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        this.allowEnums = source.allowEnums();
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        this.allowForeach = source.allowForeach();
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        this.allowStaticImport = source.allowStaticImport();
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        this.allowAnnotations = source.allowAnnotations();
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
   120
        this.allowTWR = source.allowTryWithResources();
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   121
        this.allowDiamond = source.allowDiamond();
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
   122
        this.allowMulticatch = source.allowMulticatch();
10200
56cc93e7b6ef 7068902: (javac) allow enabling or disabling of String folding
ksrini
parents: 10199
diff changeset
   123
        this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true);
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   124
        this.allowLambda = source.allowLambda();
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   125
        this.allowMethodReferences = source.allowMethodReferences();
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14541
diff changeset
   126
        this.allowDefaultMethods = source.allowDefaultMethods();
15375
d2529dc91d77 8006566: Remove transient lambda-related guards from JavacParser
mcimadamore
parents: 15367
diff changeset
   127
        this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        this.keepDocComments = keepDocComments;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
   129
        docComments = newDocCommentTable(keepDocComments, fac);
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   130
        this.keepLineMap = keepLineMap;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        this.errorTree = F.Erroneous();
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   132
        endPosTable = newEndPosTable(keepEndPositions);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   135
    protected AbstractEndPosTable newEndPosTable(boolean keepEndPositions) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   136
        return  keepEndPositions
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   137
                ? new SimpleEndPosTable()
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   138
                : new EmptyEndPosTable();
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   139
    }
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
   140
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
   141
    protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
   142
        return keepDocComments ? new LazyDocCommentTable(fac) : null;
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
   143
    }
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
   144
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    /** Switch: Should generics be recognized?
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    boolean allowGenerics;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   149
    /** Switch: Should diamond operator be recognized?
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   150
     */
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   151
    boolean allowDiamond;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   152
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
   153
    /** Switch: Should multicatch clause be accepted?
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
   154
     */
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
   155
    boolean allowMulticatch;
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
   156
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    /** Switch: Should varargs be recognized?
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    boolean allowVarargs;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
    /** Switch: should we recognize assert statements, or just give a warning?
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    boolean allowAsserts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    /** Switch: should we recognize enums, or just give a warning?
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    boolean allowEnums;
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    /** Switch: should we recognize foreach?
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    boolean allowForeach;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    /** Switch: should we recognize foreach?
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    boolean allowStaticImport;
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    /** Switch: should we recognize annotations?
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    boolean allowAnnotations;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 8047
diff changeset
   181
    /** Switch: should we recognize try-with-resources?
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
   182
     */
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
   183
    boolean allowTWR;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
   184
10200
56cc93e7b6ef 7068902: (javac) allow enabling or disabling of String folding
ksrini
parents: 10199
diff changeset
   185
    /** Switch: should we fold strings?
56cc93e7b6ef 7068902: (javac) allow enabling or disabling of String folding
ksrini
parents: 10199
diff changeset
   186
     */
56cc93e7b6ef 7068902: (javac) allow enabling or disabling of String folding
ksrini
parents: 10199
diff changeset
   187
    boolean allowStringFolding;
56cc93e7b6ef 7068902: (javac) allow enabling or disabling of String folding
ksrini
parents: 10199
diff changeset
   188
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   189
    /** Switch: should we recognize lambda expressions?
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   190
     */
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   191
    boolean allowLambda;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   192
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
   193
    /** Switch: should we allow method/constructor references?
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
   194
     */
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
   195
    boolean allowMethodReferences;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
   196
14267
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
   197
    /** Switch: should we allow default methods in interfaces?
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
   198
     */
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
   199
    boolean allowDefaultMethods;
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
   200
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   201
    /** Switch: should we allow intersection types in cast?
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   202
     */
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   203
    boolean allowIntersectionTypesInCast;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   204
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    /** Switch: should we keep docComments?
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    boolean keepDocComments;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   209
    /** Switch: should we keep line table?
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   210
     */
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   211
    boolean keepLineMap;
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   212
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    /** When terms are parsed, the mode determines which is expected:
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     *     mode = EXPR        : an expression
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     *     mode = TYPE        : a type
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     *     mode = NOPARAMS    : no parameters allowed for type
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     *     mode = TYPEARG     : type argument
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     */
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   219
    static final int EXPR = 0x1;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   220
    static final int TYPE = 0x2;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   221
    static final int NOPARAMS = 0x4;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   222
    static final int TYPEARG = 0x8;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   223
    static final int DIAMOND = 0x10;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    /** The current mode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    private int mode = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
    /** The mode of the term that was parsed last.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
    private int lastmode = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   233
    /* ---------- token management -------------- */
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   234
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   235
    protected Token token;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   236
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
   237
    public Token token() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
   238
        return token;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
   239
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
   240
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14450
diff changeset
   241
    public void nextToken() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   242
        S.nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   243
        token = S.token();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   244
    }
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   245
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   246
    protected boolean peekToken(Filter<TokenKind> tk) {
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   247
        return peekToken(0, tk);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   248
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   249
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   250
    protected boolean peekToken(int lookahead, Filter<TokenKind> tk) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   251
        return tk.accepts(S.token(lookahead + 1).kind);
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   252
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   253
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   254
    protected boolean peekToken(Filter<TokenKind> tk1, Filter<TokenKind> tk2) {
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   255
        return peekToken(0, tk1, tk2);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   256
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   257
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   258
    protected boolean peekToken(int lookahead, Filter<TokenKind> tk1, Filter<TokenKind> tk2) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   259
        return tk1.accepts(S.token(lookahead + 1).kind) &&
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   260
                tk2.accepts(S.token(lookahead + 2).kind);
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   261
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   262
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   263
    protected boolean peekToken(Filter<TokenKind> tk1, Filter<TokenKind> tk2, Filter<TokenKind> tk3) {
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   264
        return peekToken(0, tk1, tk2, tk3);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   265
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   266
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   267
    protected boolean peekToken(int lookahead, Filter<TokenKind> tk1, Filter<TokenKind> tk2, Filter<TokenKind> tk3) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   268
        return tk1.accepts(S.token(lookahead + 1).kind) &&
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   269
                tk2.accepts(S.token(lookahead + 2).kind) &&
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   270
                tk3.accepts(S.token(lookahead + 3).kind);
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   271
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   272
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   273
    @SuppressWarnings("unchecked")
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   274
    protected boolean peekToken(Filter<TokenKind>... kinds) {
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   275
        return peekToken(0, kinds);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   276
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   277
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   278
    @SuppressWarnings("unchecked")
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   279
    protected boolean peekToken(int lookahead, Filter<TokenKind>... kinds) {
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   280
        for (; lookahead < kinds.length ; lookahead++) {
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   281
            if (!kinds[lookahead].accepts(S.token(lookahead + 1).kind)) {
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   282
                return false;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   283
            }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   284
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   285
        return true;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   286
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   287
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   288
    /* ---------- error recovery -------------- */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    private JCErroneous errorTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    /** Skip forward until a suitable stop token is found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    private void skip(boolean stopAtImport, boolean stopAtMemberDecl, boolean stopAtIdentifier, boolean stopAtStatement) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
         while (true) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   296
             switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
                case SEMI:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   298
                    nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
                case PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
                case FINAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
                case ABSTRACT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                case MONKEYS_AT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                case EOF:
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
                case CLASS:
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
                case INTERFACE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                case ENUM:
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                    return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                case IMPORT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                    if (stopAtImport)
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
                case LBRACE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
                case RBRACE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
                case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
                case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
                case STATIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
                case TRANSIENT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
                case NATIVE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
                case VOLATILE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
                case SYNCHRONIZED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
                case STRICTFP:
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
                case LT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
                case BYTE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
                case SHORT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                case CHAR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                case INT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                case LONG:
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                case FLOAT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                case DOUBLE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                case BOOLEAN:
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                case VOID:
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                    if (stopAtMemberDecl)
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
                    break;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   336
                case UNDERSCORE:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                case IDENTIFIER:
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                   if (stopAtIdentifier)
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                case CASE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                case DEFAULT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                case IF:
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                case FOR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                case WHILE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                case DO:
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
                case TRY:
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
                case SWITCH:
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
                case RETURN:
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
                case THROW:
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                case BREAK:
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                case CONTINUE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                case ELSE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
                case FINALLY:
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                case CATCH:
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
                    if (stopAtStatement)
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   360
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   364
    private JCErroneous syntaxError(int pos, String key, TokenKind... args) {
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   365
        return syntaxError(pos, List.<JCTree>nil(), key, args);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   368
    private JCErroneous syntaxError(int pos, List<JCTree> errs, String key, TokenKind... args) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        setErrorEndPos(pos);
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   370
        JCErroneous err = F.at(pos).Erroneous(errs);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   371
        reportSyntaxError(err, key, (Object[])args);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   372
        if (errs != null) {
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   373
            JCTree last = errs.last();
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   374
            if (last != null)
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   375
                storeEnd(last, pos);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   376
        }
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   377
        return toP(err);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    private int errorPos = Position.NOPOS;
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   381
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
    /**
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   383
     * Report a syntax using the given the position parameter and arguments,
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   384
     * unless one was already reported at the same position.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     */
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   386
    private void reportSyntaxError(int pos, String key, Object... args) {
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   387
        JCDiagnostic.DiagnosticPosition diag = new JCDiagnostic.SimpleDiagnosticPosition(pos);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   388
        reportSyntaxError(diag, key, args);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   389
    }
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   390
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   391
    /**
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   392
     * Report a syntax error using the given DiagnosticPosition object and
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   393
     * arguments, unless one was already reported at the same position.
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   394
     */
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   395
    private void reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, String key, Object... args) {
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   396
        int pos = diagPos.getPreferredPosition();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        if (pos > S.errPos() || pos == Position.NOPOS) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   398
            if (token.kind == EOF) {
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   399
                error(diagPos, "premature.eof");
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   400
            } else {
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   401
                error(diagPos, key, args);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   402
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
        S.errPos(pos);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   405
        if (token.pos == errorPos)
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   406
            nextToken(); // guarantee progress
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   407
        errorPos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    /** Generate a syntax error at current position unless one was already
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
     *  reported at the same position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
    private JCErroneous syntaxError(String key) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   415
        return syntaxError(token.pos, key);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    /** Generate a syntax error at current position unless one was
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
     *  already reported at the same position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
     */
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   421
    private JCErroneous syntaxError(String key, TokenKind arg) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   422
        return syntaxError(token.pos, key, arg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
    /** If next input token matches given token, skip it, otherwise report
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
     *  an error.
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
     */
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   428
    public void accept(TokenKind tk) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   429
        if (token.kind == tk) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   430
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   432
            setErrorEndPos(token.pos);
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   433
            reportSyntaxError(S.prevToken().endPos, "expected", tk);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
    /** Report an illegal start of expression/type error at given position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    JCExpression illegal(int pos) {
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   440
        setErrorEndPos(pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        if ((mode & EXPR) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            return syntaxError(pos, "illegal.start.of.expr");
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            return syntaxError(pos, "illegal.start.of.type");
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
    /** Report an illegal start of expression/type error at current position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    JCExpression illegal() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   451
        return illegal(token.pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    /** Diagnose a modifier flag from the set, if any. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
    void checkNoMods(long mods) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        if (mods != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
            long lowestMod = mods & -mods;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   458
            error(token.pos, "mod.not.allowed.here",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   459
                      Flags.asFlagSet(lowestMod));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
/* ---------- doc comments --------- */
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
   465
    /** A table to store all documentation comments
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
     *  indexed by the tree nodes they refer to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
     *  defined only if option flag keepDocComment is set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
   469
    private final DocCommentTable docComments;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
    /** Make an entry into docComments hashtable,
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
     *  provided flag keepDocComments is set and given doc comment is non-null.
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
     *  @param tree   The tree to be used as index in the hashtable
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
     *  @param dc     The doc comment to associate with the tree, or null.
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
   476
    void attach(JCTree tree, Comment dc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        if (keepDocComments && dc != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
//          System.out.println("doc comment = ");System.out.println(dc);//DEBUG
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
   479
            docComments.putComment(tree, dc);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
/* -------- source positions ------- */
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
    private void setErrorEndPos(int errPos) {
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   486
        endPosTable.setErrorEndPos(errPos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   489
    private void storeEnd(JCTree tree, int endpos) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   490
        endPosTable.storeEnd(tree, endpos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   493
    private <T extends JCTree> T to(T t) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   494
        return endPosTable.to(t);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   495
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   497
    private <T extends JCTree> T toP(T t) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   498
        return endPosTable.toP(t);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   499
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    /** Get the start position for a tree node.  The start position is
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
     * defined to be the position of the first character of the first
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
     * token of the node's source text.
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
     * @param tree  The tree node
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
    public int getStartPos(JCTree tree) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        return TreeInfo.getStartPos(tree);
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
     * Get the end position for a tree node.  The end position is
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
     * defined to be the position of the last character of the last
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
     * token of the node's source text.  Returns Position.NOPOS if end
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
     * positions are not generated or the position is otherwise not
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
     * found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
     * @param tree  The tree node
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
    public int getEndPos(JCTree tree) {
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
   519
        return endPosTable.getEndPos(tree);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
/* ---------- parsing -------------- */
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
     * Ident = IDENTIFIER
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
    Name ident() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   530
        if (token.kind == IDENTIFIER) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   531
            Name name = token.name();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   532
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            return name;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   534
        } else if (token.kind == ASSERT) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            if (allowAsserts) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   536
                error(token.pos, "assert.as.identifier");
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   537
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
                return names.error;
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   540
                warning(token.pos, "assert.as.identifier");
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   541
                Name name = token.name();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   542
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   545
        } else if (token.kind == ENUM) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
            if (allowEnums) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   547
                error(token.pos, "enum.as.identifier");
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   548
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
                return names.error;
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
            } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   551
                warning(token.pos, "enum.as.identifier");
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   552
                Name name = token.name();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   553
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
            }
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   556
        } else if (token.kind == UNDERSCORE) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   557
            warning(token.pos, "underscore.as.identifier");
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   558
            Name name = token.name();
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   559
            nextToken();
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   560
            return name;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
            accept(IDENTIFIER);
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
            return names.error;
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        }
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
   565
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
     * Qualident = Ident { DOT Ident }
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    public JCExpression qualident() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   571
        JCExpression t = toP(F.at(token.pos).Ident(ident()));
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   572
        while (token.kind == DOT) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   573
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   574
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
            t = toP(F.at(pos).Select(t, ident()));
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   580
    JCExpression literal(Name prefix) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   581
        return literal(prefix, token.pos);
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   582
    }
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   583
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
     * Literal =
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
     *     INTLITERAL
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
     *   | LONGLITERAL
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
     *   | FLOATLITERAL
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
     *   | DOUBLELITERAL
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
     *   | CHARLITERAL
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
     *   | STRINGLITERAL
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
     *   | TRUE
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
     *   | FALSE
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
     *   | NULL
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
     */
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   596
    JCExpression literal(Name prefix, int pos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
        JCExpression t = errorTree;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   598
        switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        case INTLITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
                t = F.at(pos).Literal(
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   602
                    TypeTag.INT,
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   603
                    Convert.string2int(strval(prefix), token.radix()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
            } catch (NumberFormatException ex) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   605
                error(token.pos, "int.number.too.large", strval(prefix));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
        case LONGLITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                t = F.at(pos).Literal(
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   611
                    TypeTag.LONG,
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   612
                    new Long(Convert.string2long(strval(prefix), token.radix())));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
            } catch (NumberFormatException ex) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   614
                error(token.pos, "int.number.too.large", strval(prefix));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
        case FLOATLITERAL: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   618
            String proper = token.radix() == 16 ?
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   619
                    ("0x"+ token.stringVal()) :
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   620
                    token.stringVal();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
            Float n;
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
                n = Float.valueOf(proper);
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
            } catch (NumberFormatException ex) {
7636
030f141aa32b 6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents: 7211
diff changeset
   625
                // error already reported in scanner
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
                n = Float.NaN;
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
            if (n.floatValue() == 0.0f && !isZero(proper))
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   629
                error(token.pos, "fp.number.too.small");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
            else if (n.floatValue() == Float.POSITIVE_INFINITY)
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   631
                error(token.pos, "fp.number.too.large");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
            else
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   633
                t = F.at(pos).Literal(TypeTag.FLOAT, n);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
        case DOUBLELITERAL: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   637
            String proper = token.radix() == 16 ?
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   638
                    ("0x"+ token.stringVal()) :
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   639
                    token.stringVal();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
            Double n;
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
                n = Double.valueOf(proper);
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
            } catch (NumberFormatException ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
                // error already reported in scanner
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
                n = Double.NaN;
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
            if (n.doubleValue() == 0.0d && !isZero(proper))
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   648
                error(token.pos, "fp.number.too.small");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
            else if (n.doubleValue() == Double.POSITIVE_INFINITY)
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   650
                error(token.pos, "fp.number.too.large");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
            else
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   652
                t = F.at(pos).Literal(TypeTag.DOUBLE, n);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
        case CHARLITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
            t = F.at(pos).Literal(
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   657
                TypeTag.CHAR,
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   658
                token.stringVal().charAt(0) + 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
        case STRINGLITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
            t = F.at(pos).Literal(
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   662
                TypeTag.CLASS,
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   663
                token.stringVal());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
        case TRUE: case FALSE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
            t = F.at(pos).Literal(
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   667
                TypeTag.BOOLEAN,
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   668
                (token.kind == TRUE ? 1 : 0));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        case NULL:
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
            t = F.at(pos).Literal(
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   672
                TypeTag.BOT,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
                null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
        default:
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7636
diff changeset
   676
            Assert.error();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
        if (t == errorTree)
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
            t = F.at(pos).Erroneous();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   680
        storeEnd(t, token.endPos);
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   681
        nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        boolean isZero(String s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
            char[] cs = s.toCharArray();
3894
e470a29ed0a2 6882235: invalid exponent causes silent javac crash
jjg
parents: 3765
diff changeset
   687
            int base = ((cs.length > 1 && Character.toLowerCase(cs[1]) == 'x') ? 16 : 10);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
            int i = ((base==16) ? 2 : 0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
            while (i < cs.length && (cs[i] == '0' || cs[i] == '.')) i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
            return !(i < cs.length && (Character.digit(cs[i], base) > 0));
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
        String strval(Name prefix) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   694
            String s = token.stringVal();
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1258
diff changeset
   695
            return prefix.isEmpty() ? s : prefix + s;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
    /** terms can be either expressions or types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
     */
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   700
    public JCExpression parseExpression() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        return term(EXPR);
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
   704
    public JCExpression parseType() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        return term(TYPE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
    JCExpression term(int newmode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
        int prevmode = mode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
        mode = newmode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
        JCExpression t = term();
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
        lastmode = mode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
        mode = prevmode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
    /**
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
   718
     *  {@literal
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
     *  Expression = Expression1 [ExpressionRest]
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
     *  ExpressionRest = [AssignmentOperator Expression1]
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
     *  AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" |
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
     *                       "&=" | "|=" | "^=" |
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
     *                       "%=" | "<<=" | ">>=" | ">>>="
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
     *  Type = Type1
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
     *  TypeNoParams = TypeNoParams1
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
     *  StatementExpression = Expression
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
     *  ConstantExpression = Expression
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
   728
     *  }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
    JCExpression term() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
        JCExpression t = term1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        if ((mode & EXPR) != 0 &&
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   733
            token.kind == EQ || PLUSEQ.compareTo(token.kind) <= 0 && token.kind.compareTo(GTGTGTEQ) <= 0)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
            return termRest(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
    JCExpression termRest(JCExpression t) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   740
        switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
        case EQ: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   742
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   743
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
            mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
            JCExpression t1 = term();
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
            return toP(F.at(pos).Assign(t, t1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
        case PLUSEQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
        case SUBEQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
        case STAREQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
        case SLASHEQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
        case PERCENTEQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
        case AMPEQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
        case BAREQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
        case CARETEQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
        case LTLTEQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
        case GTGTEQ:
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
        case GTGTGTEQ:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   759
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   760
            TokenKind tk = token.kind;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   761
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
            mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
            JCExpression t1 = term();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   764
            return F.at(pos).Assignop(optag(tk), t, t1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
    /** Expression1   = Expression2 [Expression1Rest]
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
     *  Type1         = Type2
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
     *  TypeNoParams1 = TypeNoParams2
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
    JCExpression term1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
        JCExpression t = term2();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   776
        if ((mode & EXPR) != 0 && token.kind == QUES) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
            mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
            return term1Rest(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
    /** Expression1Rest = ["?" Expression ":" Expression1]
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
    JCExpression term1Rest(JCExpression t) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   787
        if (token.kind == QUES) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   788
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   789
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
            JCExpression t1 = term();
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
            accept(COLON);
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
            JCExpression t2 = term1();
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            return F.at(pos).Conditional(t, t1, t2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
    /** Expression2   = Expression3 [Expression2Rest]
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
     *  Type2         = Type3
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
     *  TypeNoParams2 = TypeNoParams3
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
    JCExpression term2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
        JCExpression t = term3();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   805
        if ((mode & EXPR) != 0 && prec(token.kind) >= TreeInfo.orPrec) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
            mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
            return term2Rest(t, TreeInfo.orPrec);
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
    /*  Expression2Rest = {infixop Expression3}
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
     *                  | Expression3 instanceof Type
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
     *  infixop         = "||"
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
     *                  | "&&"
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
     *                  | "|"
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
     *                  | "^"
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
     *                  | "&"
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
     *                  | "==" | "!="
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
     *                  | "<" | ">" | "<=" | ">="
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
     *                  | "<<" | ">>" | ">>>"
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
     *                  | "+" | "-"
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
     *                  | "*" | "/" | "%"
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
    JCExpression term2Rest(JCExpression t, int minprec) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
        JCExpression[] odStack = newOdStack();
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
        Token[] opStack = newOpStack();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   829
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
        // optimization, was odStack = new Tree[...]; opStack = new Tree[...];
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
        int top = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
        odStack[0] = t;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   833
        int startPos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   834
        Token topOp = Tokens.DUMMY;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   835
        while (prec(token.kind) >= minprec) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
            opStack[top] = topOp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
            top++;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   838
            topOp = token;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   839
            nextToken();
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
   840
            odStack[top] = (topOp.kind == INSTANCEOF) ? parseType() : term3();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   841
            while (top > 0 && prec(topOp.kind) >= prec(token.kind)) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   842
                odStack[top-1] = makeOp(topOp.pos, topOp.kind, odStack[top-1],
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
                                        odStack[top]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
                top--;
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
                topOp = opStack[top];
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
        }
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7636
diff changeset
   848
        Assert.check(top == 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
        t = odStack[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
   851
        if (t.hasTag(JCTree.Tag.PLUS)) {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14062
diff changeset
   852
            StringBuilder buf = foldStrings(t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
            if (buf != null) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   854
                t = toP(F.at(startPos).Literal(TypeTag.CLASS, buf.toString()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   858
        odStackSupply.add(odStack);
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   859
        opStackSupply.add(opStack);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
        /** Construct a binary or type test node.
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
        private JCExpression makeOp(int pos,
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   866
                                    TokenKind topOp,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
                                    JCExpression od1,
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
                                    JCExpression od2)
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
        {
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
            if (topOp == INSTANCEOF) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
                return F.at(pos).TypeTest(od1, od2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
                return F.at(pos).Binary(optag(topOp), od1, od2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
        /** If tree is a concatenation of string literals, replace it
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
         *  by a single literal representing the concatenated string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
         */
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14062
diff changeset
   879
        protected StringBuilder foldStrings(JCTree tree) {
10200
56cc93e7b6ef 7068902: (javac) allow enabling or disabling of String folding
ksrini
parents: 10199
diff changeset
   880
            if (!allowStringFolding)
56cc93e7b6ef 7068902: (javac) allow enabling or disabling of String folding
ksrini
parents: 10199
diff changeset
   881
                return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
            List<String> buf = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
            while (true) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
   884
                if (tree.hasTag(LITERAL)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
                    JCLiteral lit = (JCLiteral) tree;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   886
                    if (lit.typetag == TypeTag.CLASS) {
14263
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14062
diff changeset
   887
                        StringBuilder sbuf =
473b1eaede64 8000310: Clean up use of StringBuffer in langtools
jjg
parents: 14062
diff changeset
   888
                            new StringBuilder((String)lit.value);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
                        while (buf.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
                            sbuf.append(buf.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
                            buf = buf.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
                        return sbuf;
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
                    }
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
   895
                } else if (tree.hasTag(JCTree.Tag.PLUS)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
                    JCBinary op = (JCBinary)tree;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
   897
                    if (op.rhs.hasTag(LITERAL)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
                        JCLiteral lit = (JCLiteral) op.rhs;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
   899
                        if (lit.typetag == TypeTag.CLASS) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
                            buf = buf.prepend((String) lit.value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
                            tree = op.lhs;
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
                            continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
        /** optimization: To save allocating a new operand/operator stack
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
         *  for every binary operation, we use supplys.
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
         */
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   913
        ArrayList<JCExpression[]> odStackSupply = new ArrayList<JCExpression[]>();
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   914
        ArrayList<Token[]> opStackSupply = new ArrayList<Token[]>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
        private JCExpression[] newOdStack() {
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   917
            if (odStackSupply.isEmpty())
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   918
                return new JCExpression[infixPrecedenceLevels + 1];
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   919
            return odStackSupply.remove(odStackSupply.size() - 1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
        private Token[] newOpStack() {
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   923
            if (opStackSupply.isEmpty())
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   924
                return new Token[infixPrecedenceLevels + 1];
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
   925
            return opStackSupply.remove(opStackSupply.size() - 1);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
   928
    /**
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
   929
     *  Expression3    = PrefixOp Expression3
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
     *                 | "(" Expr | TypeNoParams ")" Expression3
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
     *                 | Primary {Selector} {PostfixOp}
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
   932
     *
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
   933
     *  {@literal
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
     *  Primary        = "(" Expression ")"
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
     *                 | Literal
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
     *                 | [TypeArguments] THIS [Arguments]
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
     *                 | [TypeArguments] SUPER SuperSuffix
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
     *                 | NEW [TypeArguments] Creator
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   939
     *                 | "(" Arguments ")" "->" ( Expression | Block )
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
   940
     *                 | Ident "->" ( Expression | Block )
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
   941
     *                 | Ident { "." Ident }
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
   942
     *                 | Expression3 MemberReferenceSuffix
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
   943
     *                   [ "[" ( "]" BracketsOpt "." CLASS | Expression "]" )
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
     *                   | Arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
     *                   | "." ( CLASS | THIS | [TypeArguments] SUPER Arguments | NEW [TypeArguments] InnerCreator )
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
     *                   ]
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
     *                 | BasicType BracketsOpt "." CLASS
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
   948
     *  }
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
   949
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
     *  PrefixOp       = "++" | "--" | "!" | "~" | "+" | "-"
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
     *  PostfixOp      = "++" | "--"
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
     *  Type3          = Ident { "." Ident } [TypeArguments] {TypeSelector} BracketsOpt
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
     *                 | BasicType
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
     *  TypeNoParams3  = Ident { "." Ident } BracketsOpt
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
     *  Selector       = "." [TypeArguments] Ident [Arguments]
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
     *                 | "." THIS
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
     *                 | "." [TypeArguments] SUPER SuperSuffix
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
     *                 | "." NEW [TypeArguments] InnerCreator
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
     *                 | "[" Expression "]"
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
     *  TypeSelector   = "." Ident [TypeArguments]
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
     *  SuperSuffix    = Arguments | "." Ident [Arguments]
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
    protected JCExpression term3() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   964
        int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
        JCExpression t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
        List<JCExpression> typeArgs = typeArgumentsOpt(EXPR);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   967
        switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
        case QUES:
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
            if ((mode & TYPE) != 0 && (mode & (TYPEARG|NOPARAMS)) == TYPEARG) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
                mode = TYPE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
                return typeArgument();
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
            } else
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
                return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
        case PLUSPLUS: case SUBSUB: case BANG: case TILDE: case PLUS: case SUB:
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
            if (typeArgs == null && (mode & EXPR) != 0) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   976
                TokenKind tk = token.kind;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   977
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
                mode = EXPR;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   979
                if (tk == SUB &&
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   980
                    (token.kind == INTLITERAL || token.kind == LONGLITERAL) &&
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   981
                    token.radix() == 10) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
                    mode = EXPR;
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
   983
                    t = literal(names.hyphen, pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
                } else {
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
   985
                    t = term3();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
   986
                    return F.at(pos).Unary(unoptag(tk), t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
            } else return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
        case LPAREN:
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
            if (typeArgs == null && (mode & EXPR) != 0) {
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   992
                ParensResult pres = analyzeParens();
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   993
                switch (pres) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   994
                    case CAST:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   995
                       accept(LPAREN);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   996
                       mode = TYPE;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   997
                       int pos1 = pos;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   998
                       List<JCExpression> targets = List.of(t = term3());
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
   999
                       while (token.kind == AMP) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1000
                           checkIntersectionTypesInCast();
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1001
                           accept(AMP);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1002
                           targets = targets.prepend(term3());
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1003
                       }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1004
                       if (targets.length() > 1) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1005
                           t = toP(F.at(pos1).TypeIntersection(targets.reverse()));
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1006
                       }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1007
                       accept(RPAREN);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1008
                       mode = EXPR;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1009
                       JCExpression t1 = term3();
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1010
                       return F.at(pos).TypeCast(t, t1);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1011
                    case IMPLICIT_LAMBDA:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1012
                    case EXPLICIT_LAMBDA:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1013
                        t = lambdaExpressionOrStatement(true, pres == ParensResult.EXPLICIT_LAMBDA, pos);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1014
                        break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1015
                    default: //PARENS
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1016
                        accept(LPAREN);
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1017
                        mode = EXPR;
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1018
                        t = termRest(term1Rest(term2Rest(term3(), TreeInfo.orPrec)));
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1019
                        accept(RPAREN);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1020
                        t = toP(F.at(pos).Parens(t));
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1021
                        break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
                }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1023
            } else {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1024
                return illegal();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1025
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
        case THIS:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
            if ((mode & EXPR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
                mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
                t = to(F.at(pos).Ident(names._this));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1031
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
                if (typeArgs == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
                    t = argumentsOpt(null, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
                    t = arguments(typeArgs, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
                typeArgs = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
            } else return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
        case SUPER:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
            if ((mode & EXPR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
                mode = EXPR;
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  1042
                t = to(F.at(pos).Ident(names._super));
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  1043
                t = superSuffix(typeArgs, t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
                typeArgs = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
            } else return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
        case INTLITERAL: case LONGLITERAL: case FLOATLITERAL: case DOUBLELITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
        case CHARLITERAL: case STRINGLITERAL:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
        case TRUE: case FALSE: case NULL:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
            if (typeArgs == null && (mode & EXPR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
                mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
                t = literal(names.empty);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
            } else return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
        case NEW:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
            if (typeArgs != null) return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
            if ((mode & EXPR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
                mode = EXPR;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1059
                nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1060
                if (token.kind == LT) typeArgs = typeArguments(false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
                t = creator(pos, typeArgs);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
                typeArgs = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
            } else return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
            break;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1065
        case UNDERSCORE: case IDENTIFIER: case ASSERT: case ENUM:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
            if (typeArgs != null) return illegal();
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1067
            if ((mode & EXPR) != 0 && peekToken(ARROW)) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1068
                t = lambdaExpressionOrStatement(false, false, pos);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1069
            } else {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1070
                t = toP(F.at(token.pos).Ident(ident()));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1071
                loop: while (true) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1072
                    pos = token.pos;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1073
                    switch (token.kind) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1074
                    case LBRACKET:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1075
                        nextToken();
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1076
                        if (token.kind == RBRACKET) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1077
                            nextToken();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1078
                            t = bracketsOpt(t);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1079
                            t = toP(F.at(pos).TypeArray(t));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1080
                            t = bracketsSuffix(t);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1081
                        } else {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1082
                            if ((mode & EXPR) != 0) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1083
                                mode = EXPR;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1084
                                JCExpression t1 = term();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1085
                                t = to(F.at(pos).Indexed(t, t1));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1086
                            }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1087
                            accept(RBRACKET);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1088
                        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1089
                        break loop;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1090
                    case LPAREN:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
                        if ((mode & EXPR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
                            mode = EXPR;
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1093
                            t = arguments(typeArgs, t);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1094
                            typeArgs = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
                        }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1096
                        break loop;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1097
                    case DOT:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1098
                        nextToken();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1099
                        int oldmode = mode;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1100
                        mode &= ~NOPARAMS;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1101
                        typeArgs = typeArgumentsOpt(EXPR);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1102
                        mode = oldmode;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1103
                        if ((mode & EXPR) != 0) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1104
                            switch (token.kind) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1105
                            case CLASS:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1106
                                if (typeArgs != null) return illegal();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1107
                                mode = EXPR;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1108
                                t = to(F.at(pos).Select(t, names._class));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1109
                                nextToken();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1110
                                break loop;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1111
                            case THIS:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1112
                                if (typeArgs != null) return illegal();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1113
                                mode = EXPR;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1114
                                t = to(F.at(pos).Select(t, names._this));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1115
                                nextToken();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1116
                                break loop;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1117
                            case SUPER:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1118
                                mode = EXPR;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1119
                                t = to(F.at(pos).Select(t, names._super));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1120
                                t = superSuffix(typeArgs, t);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1121
                                typeArgs = null;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1122
                                break loop;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1123
                            case NEW:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1124
                                if (typeArgs != null) return illegal();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1125
                                mode = EXPR;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1126
                                int pos1 = token.pos;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1127
                                nextToken();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1128
                                if (token.kind == LT) typeArgs = typeArguments(false);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1129
                                t = innerCreator(pos1, typeArgs, t);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1130
                                typeArgs = null;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1131
                                break loop;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1132
                            }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1133
                        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1134
                        // typeArgs saved for next loop iteration.
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1135
                        t = toP(F.at(pos).Select(t, ident()));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1136
                        break;
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1137
                    case LT:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1138
                        if ((mode & TYPE) == 0 && isUnboundMemberRef()) {
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1139
                            //this is an unbound method reference whose qualifier
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1140
                            //is a generic type i.e. A<S>::m
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1141
                            int pos1 = token.pos;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1142
                            accept(LT);
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1143
                            ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1144
                            args.append(typeArgument());
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1145
                            while (token.kind == COMMA) {
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1146
                                nextToken();
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1147
                                args.append(typeArgument());
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1148
                            }
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1149
                            accept(GT);
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1150
                            t = toP(F.at(pos1).TypeApply(t, args.toList()));
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1151
                            checkGenerics();
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1152
                            while (token.kind == DOT) {
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1153
                                nextToken();
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1154
                                mode = TYPE;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1155
                                t = toP(F.at(token.pos).Select(t, ident()));
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1156
                                t = typeArgumentsOpt(t);
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1157
                            }
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1158
                            t = bracketsOpt(t);
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1159
                            if (token.kind != COLCOL) {
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1160
                                //method reference expected here
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1161
                                t = illegal();
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1162
                            }
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1163
                            mode = EXPR;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1164
                            return term3Rest(t, typeArgs);
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1165
                        }
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1166
                        break loop;
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1167
                    default:
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1168
                        break loop;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
            if (typeArgs != null) illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
            t = typeArgumentsOpt(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
        case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
        case DOUBLE: case BOOLEAN:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
            if (typeArgs != null) illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
            t = bracketsSuffix(bracketsOpt(basicType()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
        case VOID:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
            if (typeArgs != null) illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
            if ((mode & EXPR) != 0) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1183
                nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1184
                if (token.kind == DOT) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1185
                    JCPrimitiveTypeTree ti = toP(F.at(pos).TypeIdent(TypeTag.VOID));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
                    t = bracketsSuffix(ti);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
                    return illegal(pos);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
            } else {
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 2212
diff changeset
  1191
                // Support the corner case of myMethodHandle.<void>invoke() by passing
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 2212
diff changeset
  1192
                // a void type (like other primitive types) to the next phase.
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 2212
diff changeset
  1193
                // The error will be reported in Attr.attribTypes or Attr.visitApply.
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  1194
                JCPrimitiveTypeTree ti = to(F.at(pos).TypeIdent(TypeTag.VOID));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1195
                nextToken();
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 2212
diff changeset
  1196
                return ti;
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 2212
diff changeset
  1197
                //return illegal();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
            return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
        }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1203
        return term3Rest(t, typeArgs);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1204
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1205
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1206
    JCExpression term3Rest(JCExpression t, List<JCExpression> typeArgs) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
        if (typeArgs != null) illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
        while (true) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1209
            int pos1 = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1210
            if (token.kind == LBRACKET) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1211
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
                if ((mode & TYPE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
                    int oldmode = mode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
                    mode = TYPE;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1215
                    if (token.kind == RBRACKET) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1216
                        nextToken();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1217
                        t = bracketsOpt(t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
                        t = toP(F.at(pos1).TypeArray(t));
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1219
                        if (token.kind == COLCOL) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1220
                            mode = EXPR;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1221
                            continue;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1222
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
                        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
                    mode = oldmode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
                if ((mode & EXPR) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
                    mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
                    JCExpression t1 = term();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
                    t = to(F.at(pos1).Indexed(t, t1));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
                accept(RBRACKET);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1233
            } else if (token.kind == DOT) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1234
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
                typeArgs = typeArgumentsOpt(EXPR);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1236
                if (token.kind == SUPER && (mode & EXPR) != 0) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
                    mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
                    t = to(F.at(pos1).Select(t, names._super));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1239
                    nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
                    t = arguments(typeArgs, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
                    typeArgs = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1242
                } else if (token.kind == NEW && (mode & EXPR) != 0) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
                    if (typeArgs != null) return illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
                    mode = EXPR;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1245
                    int pos2 = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1246
                    nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1247
                    if (token.kind == LT) typeArgs = typeArguments(false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
                    t = innerCreator(pos2, typeArgs, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
                    typeArgs = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
                    t = toP(F.at(pos1).Select(t, ident()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
                    t = argumentsOpt(typeArgs, typeArgumentsOpt(t));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
                    typeArgs = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
                }
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1255
            } else if ((mode & EXPR) != 0 && token.kind == COLCOL) {
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1256
                mode = EXPR;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1257
                if (typeArgs != null) return illegal();
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1258
                accept(COLCOL);
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1259
                t = memberReferenceSuffix(pos1, t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
        }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1264
        while ((token.kind == PLUSPLUS || token.kind == SUBSUB) && (mode & EXPR) != 0) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
            mode = EXPR;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1266
            t = to(F.at(token.pos).Unary(
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  1267
                  token.kind == PLUSPLUS ? POSTINC : POSTDEC, t));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1268
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
        return toP(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1273
    /**
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1274
     * If we see an identifier followed by a '&lt;' it could be an unbound
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1275
     * method reference or a binary expression. To disambiguate, look for a
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1276
     * matching '&gt;' and see if the subsequent terminal is either '.' or '#'.
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1277
     */
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1278
    @SuppressWarnings("fallthrough")
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1279
    boolean isUnboundMemberRef() {
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1280
        int pos = 0, depth = 0;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1281
        for (Token t = S.token(pos) ; ; t = S.token(++pos)) {
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1282
            switch (t.kind) {
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1283
                case IDENTIFIER: case UNDERSCORE: case QUES: case EXTENDS: case SUPER:
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1284
                case DOT: case RBRACKET: case LBRACKET: case COMMA:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1285
                case BYTE: case SHORT: case INT: case LONG: case FLOAT:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1286
                case DOUBLE: case BOOLEAN: case CHAR:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1287
                    break;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1288
                case LT:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1289
                    depth++; break;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1290
                case GTGTGT:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1291
                    depth--;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1292
                case GTGT:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1293
                    depth--;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1294
                case GT:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1295
                    depth--;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1296
                    if (depth == 0) {
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1297
                        TokenKind nextKind = S.token(pos + 1).kind;
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1298
                        return
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1299
                            nextKind == TokenKind.DOT ||
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1300
                            nextKind == TokenKind.LBRACKET ||
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1301
                            nextKind == TokenKind.COLCOL;
11322
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1302
                    }
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1303
                    break;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1304
                default:
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1305
                    return false;
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1306
            }
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1307
        }
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1308
    }
6ee85f80967a 7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents: 11149
diff changeset
  1309
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1310
    /**
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1311
     * If we see an identifier followed by a '&lt;' it could be an unbound
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1312
     * method reference or a binary expression. To disambiguate, look for a
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1313
     * matching '&gt;' and see if the subsequent terminal is either '.' or '#'.
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1314
     */
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1315
    @SuppressWarnings("fallthrough")
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1316
    ParensResult analyzeParens() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1317
        int depth = 0;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1318
        boolean type = false;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1319
        for (int lookahead = 0 ; ; lookahead++) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1320
            TokenKind tk = S.token(lookahead).kind;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1321
            switch (tk) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1322
                case EXTENDS: case SUPER: case COMMA:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1323
                    type = true;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1324
                case QUES: case DOT: case AMP:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1325
                    //skip
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1326
                    break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1327
                case BYTE: case SHORT: case INT: case LONG: case FLOAT:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1328
                case DOUBLE: case BOOLEAN: case CHAR:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1329
                    if (peekToken(lookahead, RPAREN)) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1330
                        //Type, ')' -> cast
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1331
                        return ParensResult.CAST;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1332
                    } else if (peekToken(lookahead, LAX_IDENTIFIER)) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1333
                        //Type, Identifier/'_'/'assert'/'enum' -> explicit lambda
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1334
                        return ParensResult.EXPLICIT_LAMBDA;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1335
                    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1336
                    break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1337
                case LPAREN:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1338
                    if (lookahead != 0) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1339
                        // '(' in a non-starting position -> parens
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1340
                        return ParensResult.PARENS;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1341
                    } else if (peekToken(lookahead, RPAREN)) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1342
                        // '(', ')' -> explicit lambda
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1343
                        return ParensResult.EXPLICIT_LAMBDA;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1344
                    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1345
                    break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1346
                case RPAREN:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1347
                    // if we have seen something that looks like a type,
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1348
                    // then it's a cast expression
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1349
                    if (type) return ParensResult.CAST;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1350
                    // otherwise, disambiguate cast vs. parenthesized expression
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1351
                    // based on subsequent token.
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1352
                    switch (S.token(lookahead + 1).kind) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1353
                        /*case PLUSPLUS: case SUBSUB: */
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1354
                        case BANG: case TILDE:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1355
                        case LPAREN: case THIS: case SUPER:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1356
                        case INTLITERAL: case LONGLITERAL: case FLOATLITERAL:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1357
                        case DOUBLELITERAL: case CHARLITERAL: case STRINGLITERAL:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1358
                        case TRUE: case FALSE: case NULL:
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1359
                        case NEW: case IDENTIFIER: case ASSERT: case ENUM: case UNDERSCORE:
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1360
                        case BYTE: case SHORT: case CHAR: case INT:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1361
                        case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1362
                            return ParensResult.CAST;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1363
                        default:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1364
                            return ParensResult.PARENS;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1365
                    }
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1366
                case UNDERSCORE:
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1367
                case ASSERT:
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1368
                case ENUM:
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1369
                case IDENTIFIER:
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1370
                    if (peekToken(lookahead, LAX_IDENTIFIER)) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1371
                        // Identifier, Identifier/'_'/'assert'/'enum' -> explicit lambda
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1372
                        return ParensResult.EXPLICIT_LAMBDA;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1373
                    } else if (peekToken(lookahead, RPAREN, ARROW)) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1374
                        // Identifier, ')' '->' -> implicit lambda
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1375
                        return ParensResult.IMPLICIT_LAMBDA;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1376
                    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1377
                    break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1378
                case FINAL:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1379
                case ELLIPSIS:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1380
                case MONKEYS_AT:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1381
                    //those can only appear in explicit lambdas
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1382
                    return ParensResult.EXPLICIT_LAMBDA;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1383
                case LBRACKET:
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1384
                    if (peekToken(lookahead, RBRACKET, LAX_IDENTIFIER)) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1385
                        // '[', ']', Identifier/'_'/'assert'/'enum' -> explicit lambda
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1386
                        return ParensResult.EXPLICIT_LAMBDA;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1387
                    } else if (peekToken(lookahead, RBRACKET, RPAREN) ||
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1388
                            peekToken(lookahead, RBRACKET, AMP)) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1389
                        // '[', ']', ')' -> cast
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1390
                        // '[', ']', '&' -> cast (intersection type)
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1391
                        return ParensResult.CAST;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1392
                    } else if (peekToken(lookahead, RBRACKET)) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1393
                        //consume the ']' and skip
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1394
                        type = true;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1395
                        lookahead++;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1396
                        break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1397
                    } else {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1398
                        return ParensResult.PARENS;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1399
                    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1400
                case LT:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1401
                    depth++; break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1402
                case GTGTGT:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1403
                    depth--;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1404
                case GTGT:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1405
                    depth--;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1406
                case GT:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1407
                    depth--;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1408
                    if (depth == 0) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1409
                        if (peekToken(lookahead, RPAREN) ||
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1410
                                peekToken(lookahead, AMP)) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1411
                            // '>', ')' -> cast
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1412
                            // '>', '&' -> cast
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1413
                            return ParensResult.CAST;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1414
                        } else if (peekToken(lookahead, LAX_IDENTIFIER, COMMA) ||
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1415
                                peekToken(lookahead, LAX_IDENTIFIER, RPAREN, ARROW) ||
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1416
                                peekToken(lookahead, ELLIPSIS)) {
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1417
                            // '>', Identifier/'_'/'assert'/'enum', ',' -> explicit lambda
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1418
                            // '>', Identifier/'_'/'assert'/'enum', ')', '->' -> explicit lambda
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1419
                            // '>', '...' -> explicit lambda
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1420
                            return ParensResult.EXPLICIT_LAMBDA;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1421
                        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1422
                        //it looks a type, but could still be (i) a cast to generic type,
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1423
                        //(ii) an unbound method reference or (iii) an explicit lambda
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1424
                        type = true;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1425
                        break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1426
                    } else if (depth < 0) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1427
                        //unbalanced '<', '>' - not a generic type
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1428
                        return ParensResult.PARENS;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1429
                    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1430
                    break;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1431
                default:
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1432
                    //this includes EOF
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1433
                    return ParensResult.PARENS;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1434
            }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1435
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1436
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1437
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1438
    /** Accepts all identifier-like tokens */
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1439
    Filter<TokenKind> LAX_IDENTIFIER = new Filter<TokenKind>() {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1440
        public boolean accepts(TokenKind t) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1441
            return t == IDENTIFIER || t == UNDERSCORE || t == ASSERT || t == ENUM;
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1442
        }
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1443
    };
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1444
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1445
    enum ParensResult {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1446
        CAST,
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1447
        EXPLICIT_LAMBDA,
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1448
        IMPLICIT_LAMBDA,
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1449
        PARENS;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1450
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  1451
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1452
    JCExpression lambdaExpressionOrStatement(boolean hasParens, boolean explicitParams, int pos) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1453
        List<JCVariableDecl> params = explicitParams ?
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1454
                formalParameters(true) :
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1455
                implicitParameters(hasParens);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1456
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1457
        return lambdaExpressionOrStatementRest(params, pos);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1458
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1459
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1460
    JCExpression lambdaExpressionOrStatementRest(List<JCVariableDecl> args, int pos) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1461
        checkLambda();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1462
        accept(ARROW);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1463
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1464
        return token.kind == LBRACE ?
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1465
            lambdaStatement(args, pos, pos) :
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1466
            lambdaExpression(args, pos);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1467
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1468
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1469
    JCExpression lambdaStatement(List<JCVariableDecl> args, int pos, int pos2) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1470
        JCBlock block = block(pos2, 0);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1471
        return toP(F.at(pos).Lambda(args, block));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1472
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1473
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1474
    JCExpression lambdaExpression(List<JCVariableDecl> args, int pos) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1475
        JCTree expr = parseExpression();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1476
        return toP(F.at(pos).Lambda(args, expr));
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1477
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  1478
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1479
    /** SuperSuffix = Arguments | "." [TypeArguments] Ident [Arguments]
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1481
    JCExpression superSuffix(List<JCExpression> typeArgs, JCExpression t) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1482
        nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1483
        if (token.kind == LPAREN || typeArgs != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
            t = arguments(typeArgs, t);
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1485
        } else if (token.kind == COLCOL) {
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1486
            if (typeArgs != null) return illegal();
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1487
            t = memberReferenceSuffix(t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1488
        } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1489
            int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1490
            accept(DOT);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1491
            typeArgs = (token.kind == LT) ? typeArguments(false) : null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1492
            t = toP(F.at(pos).Select(t, ident()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1493
            t = argumentsOpt(typeArgs, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1494
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1495
        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1496
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1497
06bc494ca11e Initial load
duke
parents:
diff changeset
  1498
    /** BasicType = BYTE | SHORT | CHAR | INT | LONG | FLOAT | DOUBLE | BOOLEAN
06bc494ca11e Initial load
duke
parents:
diff changeset
  1499
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1500
    JCPrimitiveTypeTree basicType() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1501
        JCPrimitiveTypeTree t = to(F.at(token.pos).TypeIdent(typetag(token.kind)));
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1502
        nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1505
06bc494ca11e Initial load
duke
parents:
diff changeset
  1506
    /** ArgumentsOpt = [ Arguments ]
06bc494ca11e Initial load
duke
parents:
diff changeset
  1507
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
    JCExpression argumentsOpt(List<JCExpression> typeArgs, JCExpression t) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1509
        if ((mode & EXPR) != 0 && token.kind == LPAREN || typeArgs != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
            mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
            return arguments(typeArgs, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1515
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
06bc494ca11e Initial load
duke
parents:
diff changeset
  1517
    /** Arguments = "(" [Expression { COMMA Expression }] ")"
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1519
    List<JCExpression> arguments() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1520
        ListBuffer<JCExpression> args = lb();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1521
        if (token.kind == LPAREN) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1522
            nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1523
            if (token.kind != RPAREN) {
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  1524
                args.append(parseExpression());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1525
                while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1526
                    nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  1527
                    args.append(parseExpression());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1530
            accept(RPAREN);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
        } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1532
            syntaxError(token.pos, "expected", LPAREN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1533
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1534
        return args.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1535
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1536
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
    JCMethodInvocation arguments(List<JCExpression> typeArgs, JCExpression t) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1538
        int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
        List<JCExpression> args = arguments();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
        return toP(F.at(pos).Apply(typeArgs, t, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1541
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1542
06bc494ca11e Initial load
duke
parents:
diff changeset
  1543
    /**  TypeArgumentsOpt = [ TypeArguments ]
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
    JCExpression typeArgumentsOpt(JCExpression t) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1546
        if (token.kind == LT &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
            (mode & TYPE) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1548
            (mode & NOPARAMS) == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
            mode = TYPE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
            checkGenerics();
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1551
            return typeArguments(t, false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1552
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1553
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1554
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1555
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1556
    List<JCExpression> typeArgumentsOpt() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1557
        return typeArgumentsOpt(TYPE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1558
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1559
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
    List<JCExpression> typeArgumentsOpt(int useMode) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1561
        if (token.kind == LT) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1562
            checkGenerics();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1563
            if ((mode & useMode) == 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1564
                (mode & NOPARAMS) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1565
                illegal();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1566
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1567
            mode = useMode;
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1568
            return typeArguments(false);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1569
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1570
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1571
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1572
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  1573
    /**
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  1574
     *  {@literal
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  1575
     *  TypeArguments  = "<" TypeArgument {"," TypeArgument} ">"
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  1576
     *  }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1577
     */
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1578
    List<JCExpression> typeArguments(boolean diamondAllowed) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1579
        if (token.kind == LT) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1580
            nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1581
            if (token.kind == GT && diamondAllowed) {
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  1582
                checkDiamond();
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1583
                mode |= DIAMOND;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1584
                nextToken();
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  1585
                return List.nil();
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1586
            } else {
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1587
                ListBuffer<JCExpression> args = ListBuffer.lb();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  1588
                args.append(((mode & EXPR) == 0) ? typeArgument() : parseType());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1589
                while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1590
                    nextToken();
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1591
                    args.append(((mode & EXPR) == 0) ? typeArgument() : parseType());
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1592
                }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1593
                switch (token.kind) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1594
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1595
                case GTGTGTEQ: case GTGTEQ: case GTEQ:
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1596
                case GTGTGT: case GTGT:
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1597
                    token = S.split();
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1598
                    break;
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1599
                case GT:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1600
                    nextToken();
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1601
                    break;
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1602
                default:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1603
                    args.append(syntaxError(token.pos, "expected", GT));
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1604
                    break;
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1605
                }
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1606
                return args.toList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1607
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1608
        } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1609
            return List.<JCExpression>of(syntaxError(token.pos, "expected", LT));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1610
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1611
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  1613
    /**
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  1614
     *  {@literal
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  1615
     *  TypeArgument = Type
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1616
     *               | "?"
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1617
     *               | "?" EXTENDS Type {"&" Type}
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1618
     *               | "?" SUPER Type
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  1619
     *  }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1620
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1621
    JCExpression typeArgument() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1622
        if (token.kind != QUES) return parseType();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1623
        int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1624
        nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1625
        if (token.kind == EXTENDS) {
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  1626
            TypeBoundKind t = to(F.at(pos).TypeBoundKind(BoundKind.EXTENDS));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1627
            nextToken();
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  1628
            JCExpression bound = parseType();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1629
            return F.at(pos).Wildcard(t, bound);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1630
        } else if (token.kind == SUPER) {
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  1631
            TypeBoundKind t = to(F.at(pos).TypeBoundKind(BoundKind.SUPER));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1632
            nextToken();
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  1633
            JCExpression bound = parseType();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1634
            return F.at(pos).Wildcard(t, bound);
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1635
        } else if (LAX_IDENTIFIER.accepts(token.kind)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1636
            //error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  1637
            TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1638
            JCExpression wc = toP(F.at(pos).Wildcard(t, null));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1639
            JCIdent id = toP(F.at(token.pos).Ident(ident()));
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1640
            JCErroneous err = F.at(pos).Erroneous(List.<JCTree>of(wc, id));
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1641
            reportSyntaxError(err, "expected3", GT, EXTENDS, SUPER);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1642
            return err;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
        } else {
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  1644
            TypeBoundKind t = toP(F.at(pos).TypeBoundKind(BoundKind.UNBOUND));
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1645
            return toP(F.at(pos).Wildcard(t, null));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1646
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1647
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1648
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1649
    JCTypeApply typeArguments(JCExpression t, boolean diamondAllowed) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1650
        int pos = token.pos;
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1651
        List<JCExpression> args = typeArguments(diamondAllowed);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1652
        return toP(F.at(pos).TypeApply(t, args));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1653
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1654
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1655
    /** BracketsOpt = {"[" "]"}
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1656
     */
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1657
    private JCExpression bracketsOpt(JCExpression t) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1658
        if (token.kind == LBRACKET) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1659
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1660
            nextToken();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1661
            t = bracketsOptCont(t, pos);
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1662
            F.at(pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1664
        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1665
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1666
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1667
    private JCArrayTypeTree bracketsOptCont(JCExpression t, int pos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1668
        accept(RBRACKET);
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1669
        t = bracketsOpt(t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1670
        return toP(F.at(pos).TypeArray(t));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
06bc494ca11e Initial load
duke
parents:
diff changeset
  1673
    /** BracketsSuffixExpr = "." CLASS
06bc494ca11e Initial load
duke
parents:
diff changeset
  1674
     *  BracketsSuffixType =
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
    JCExpression bracketsSuffix(JCExpression t) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1677
        if ((mode & EXPR) != 0 && token.kind == DOT) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1678
            mode = EXPR;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1679
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1680
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
            accept(CLASS);
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  1682
            if (token.pos == endPosTable.errorEndPos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
                // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  1684
                Name name = null;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  1685
                if (LAX_IDENTIFIER.accepts(token.kind)) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1686
                    name = token.name();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1687
                    nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1688
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1689
                    name = names.error;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1690
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1691
                t = F.at(pos).Erroneous(List.<JCTree>of(toP(F.at(pos).Select(t, name))));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1692
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1693
                t = toP(F.at(pos).Select(t, names._class));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1694
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
        } else if ((mode & TYPE) != 0) {
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1696
            if (token.kind != COLCOL) {
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1697
                mode = TYPE;
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1698
            }
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1699
        } else if (token.kind != COLCOL) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1700
            syntaxError(token.pos, "dot.class.expected");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
        return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1705
    /**
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1706
     * MemberReferenceSuffix = "::" [TypeArguments] Ident
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1707
     *                       | "::" [TypeArguments] "new"
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1708
     */
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1709
    JCExpression memberReferenceSuffix(JCExpression t) {
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1710
        int pos1 = token.pos;
14062
b7439971a094 7177386: Add attribution support for method references
mcimadamore
parents: 14058
diff changeset
  1711
        accept(COLCOL);
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1712
        return memberReferenceSuffix(pos1, t);
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1713
    }
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1714
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1715
    JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1716
        checkMethodReferences();
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1717
        mode = EXPR;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1718
        List<JCExpression> typeArgs = null;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1719
        if (token.kind == LT) {
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1720
            typeArgs = typeArguments(false);
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1721
        }
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1722
        Name refName = null;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1723
        ReferenceMode refMode = null;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1724
        if (token.kind == NEW) {
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1725
            refMode = ReferenceMode.NEW;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1726
            refName = names.init;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1727
            nextToken();
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1728
        } else {
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1729
            refMode = ReferenceMode.INVOKE;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1730
            refName = ident();
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1731
        }
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1732
        return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1733
    }
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  1734
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1735
    /** Creator = Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest )
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1736
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1737
    JCExpression creator(int newpos, List<JCExpression> typeArgs) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1738
        switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1739
        case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1740
        case DOUBLE: case BOOLEAN:
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1741
            if (typeArgs == null)
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1742
                return arrayCreatorRest(newpos, basicType());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
        JCExpression t = qualident();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1747
        int oldmode = mode;
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1748
        mode = TYPE;
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1749
        boolean diamondFound = false;
10199
48bd09ecc88a 7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents: 9300
diff changeset
  1750
        int lastTypeargsPos = -1;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1751
        if (token.kind == LT) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1752
            checkGenerics();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1753
            lastTypeargsPos = token.pos;
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1754
            t = typeArguments(t, true);
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1755
            diamondFound = (mode & DIAMOND) != 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1756
        }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1757
        while (token.kind == DOT) {
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1758
            if (diamondFound) {
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1759
                //cannot select after a diamond
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1760
                illegal();
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1761
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1762
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1763
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
            t = toP(F.at(pos).Select(t, ident()));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1765
            if (token.kind == LT) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1766
                lastTypeargsPos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1767
                checkGenerics();
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1768
                t = typeArguments(t, true);
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1769
                diamondFound = (mode & DIAMOND) != 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1770
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1771
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1772
        mode = oldmode;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1773
        if (token.kind == LBRACKET) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1774
            JCExpression e = arrayCreatorRest(newpos, t);
10199
48bd09ecc88a 7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents: 9300
diff changeset
  1775
            if (diamondFound) {
48bd09ecc88a 7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents: 9300
diff changeset
  1776
                reportSyntaxError(lastTypeargsPos, "cannot.create.array.with.diamond");
48bd09ecc88a 7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents: 9300
diff changeset
  1777
                return toP(F.at(newpos).Erroneous(List.of(e)));
48bd09ecc88a 7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents: 9300
diff changeset
  1778
            }
48bd09ecc88a 7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents: 9300
diff changeset
  1779
            else if (typeArgs != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
                int pos = newpos;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1781
                if (!typeArgs.isEmpty() && typeArgs.head.pos != Position.NOPOS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
                    // note: this should always happen but we should
06bc494ca11e Initial load
duke
parents:
diff changeset
  1783
                    // not rely on this as the parser is continuously
06bc494ca11e Initial load
duke
parents:
diff changeset
  1784
                    // modified to improve error recovery.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1785
                    pos = typeArgs.head.pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
                }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1787
                setErrorEndPos(S.prevToken().endPos);
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1788
                JCErroneous err = F.at(pos).Erroneous(typeArgs.prepend(e));
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1789
                reportSyntaxError(err, "cannot.create.array.with.type.arguments");
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1790
                return toP(err);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1792
            return e;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1793
        } else if (token.kind == LPAREN) {
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1794
            return classCreatorRest(newpos, null, typeArgs, t);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1795
        } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1796
            setErrorEndPos(token.pos);
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1797
            reportSyntaxError(token.pos, "expected2", LPAREN, LBRACKET);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1798
            t = toP(F.at(newpos).NewClass(null, typeArgs, t, List.<JCExpression>nil(), null));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1799
            return toP(F.at(newpos).Erroneous(List.<JCTree>of(t)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1800
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1801
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1802
06bc494ca11e Initial load
duke
parents:
diff changeset
  1803
    /** InnerCreator = Ident [TypeArguments] ClassCreatorRest
06bc494ca11e Initial load
duke
parents:
diff changeset
  1804
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1805
    JCExpression innerCreator(int newpos, List<JCExpression> typeArgs, JCExpression encl) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1806
        JCExpression t = toP(F.at(token.pos).Ident(ident()));
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1807
        if (token.kind == LT) {
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  1808
            int oldmode = mode;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1809
            checkGenerics();
9073
a29adf86aa0c 7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents: 8625
diff changeset
  1810
            t = typeArguments(t, true);
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  1811
            mode = oldmode;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1812
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1813
        return classCreatorRest(newpos, encl, typeArgs, t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1814
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1815
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1816
    /** ArrayCreatorRest = "[" ( "]" BracketsOpt ArrayInitializer
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1817
     *                         | Expression "]" {"[" Expression "]"} BracketsOpt )
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1818
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1819
    JCExpression arrayCreatorRest(int newpos, JCExpression elemtype) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1820
        accept(LBRACKET);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1821
        if (token.kind == RBRACKET) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1822
            accept(RBRACKET);
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1823
            elemtype = bracketsOpt(elemtype);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1824
            if (token.kind == LBRACE) {
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1825
                return arrayInitializer(newpos, elemtype);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
            } else {
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  1827
                JCExpression t = toP(F.at(newpos).NewArray(elemtype, List.<JCExpression>nil(), null));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1828
                return syntaxError(token.pos, List.<JCTree>of(t), "array.dimension.missing");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1829
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1830
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1831
            ListBuffer<JCExpression> dims = new ListBuffer<JCExpression>();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  1832
            dims.append(parseExpression());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1833
            accept(RBRACKET);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1834
            while (token.kind == LBRACKET) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1835
                int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1836
                nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1837
                if (token.kind == RBRACKET) {
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1838
                    elemtype = bracketsOptCont(elemtype, pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1839
                } else {
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1840
                    dims.append(parseExpression());
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1841
                    accept(RBRACKET);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1842
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1843
            }
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  1844
            return toP(F.at(newpos).NewArray(elemtype, dims.toList(), null));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1845
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1846
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1847
06bc494ca11e Initial load
duke
parents:
diff changeset
  1848
    /** ClassCreatorRest = Arguments [ClassBody]
06bc494ca11e Initial load
duke
parents:
diff changeset
  1849
     */
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2723
diff changeset
  1850
    JCNewClass classCreatorRest(int newpos,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1851
                                  JCExpression encl,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1852
                                  List<JCExpression> typeArgs,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1853
                                  JCExpression t)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1854
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
        List<JCExpression> args = arguments();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1856
        JCClassDecl body = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1857
        if (token.kind == LBRACE) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1858
            int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1859
            List<JCTree> defs = classOrInterfaceBody(names.empty, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1860
            JCModifiers mods = F.at(Position.NOPOS).Modifiers(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1861
            body = toP(F.at(pos).AnonymousClassDef(mods, defs));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1862
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1863
        return toP(F.at(newpos).NewClass(encl, typeArgs, t, args, body));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1864
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1865
06bc494ca11e Initial load
duke
parents:
diff changeset
  1866
    /** ArrayInitializer = "{" [VariableInitializer {"," VariableInitializer}] [","] "}"
06bc494ca11e Initial load
duke
parents:
diff changeset
  1867
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1868
    JCExpression arrayInitializer(int newpos, JCExpression t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1869
        accept(LBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1870
        ListBuffer<JCExpression> elems = new ListBuffer<JCExpression>();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1871
        if (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1872
            nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1873
        } else if (token.kind != RBRACE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1874
            elems.append(variableInitializer());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1875
            while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1876
                nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1877
                if (token.kind == RBRACE) break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1878
                elems.append(variableInitializer());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1879
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1880
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1881
        accept(RBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1882
        return toP(F.at(newpos).NewArray(t, List.<JCExpression>nil(), elems.toList()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1883
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1884
06bc494ca11e Initial load
duke
parents:
diff changeset
  1885
    /** VariableInitializer = ArrayInitializer | Expression
06bc494ca11e Initial load
duke
parents:
diff changeset
  1886
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1887
    public JCExpression variableInitializer() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1888
        return token.kind == LBRACE ? arrayInitializer(token.pos, null) : parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1889
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1890
06bc494ca11e Initial load
duke
parents:
diff changeset
  1891
    /** ParExpression = "(" Expression ")"
06bc494ca11e Initial load
duke
parents:
diff changeset
  1892
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1893
    JCExpression parExpression() {
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  1894
        int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1895
        accept(LPAREN);
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  1896
        JCExpression t = parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1897
        accept(RPAREN);
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  1898
        return toP(F.at(pos).Parens(t));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1899
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1900
06bc494ca11e Initial load
duke
parents:
diff changeset
  1901
    /** Block = "{" BlockStatements "}"
06bc494ca11e Initial load
duke
parents:
diff changeset
  1902
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1903
    JCBlock block(int pos, long flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1904
        accept(LBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1905
        List<JCStatement> stats = blockStatements();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1906
        JCBlock t = F.at(pos).Block(flags, stats);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1907
        while (token.kind == CASE || token.kind == DEFAULT) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1908
            syntaxError("orphaned", token.kind);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1909
            switchBlockStatementGroups();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1910
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1911
        // the Block node has a field "endpos" for first char of last token, which is
06bc494ca11e Initial load
duke
parents:
diff changeset
  1912
        // usually but not necessarily the last char of the last token.
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1913
        t.endpos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1914
        accept(RBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1915
        return toP(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1916
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1917
06bc494ca11e Initial load
duke
parents:
diff changeset
  1918
    public JCBlock block() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  1919
        return block(token.pos, 0);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1920
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1921
06bc494ca11e Initial load
duke
parents:
diff changeset
  1922
    /** BlockStatements = { BlockStatement }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1923
     *  BlockStatement  = LocalVariableDeclarationStatement
06bc494ca11e Initial load
duke
parents:
diff changeset
  1924
     *                  | ClassOrInterfaceOrEnumDeclaration
06bc494ca11e Initial load
duke
parents:
diff changeset
  1925
     *                  | [Ident ":"] Statement
06bc494ca11e Initial load
duke
parents:
diff changeset
  1926
     *  LocalVariableDeclarationStatement
06bc494ca11e Initial load
duke
parents:
diff changeset
  1927
     *                  = { FINAL | '@' Annotation } Type VariableDeclarators ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  1928
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1929
    @SuppressWarnings("fallthrough")
06bc494ca11e Initial load
duke
parents:
diff changeset
  1930
    List<JCStatement> blockStatements() {
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1931
        //todo: skip to anchor on error(?)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1932
        ListBuffer<JCStatement> stats = new ListBuffer<JCStatement>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1933
        while (true) {
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1934
            List<JCStatement> stat = blockStatement();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1935
            if (stat.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1936
                return stats.toList();
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1937
            } else {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1938
                if (token.pos <= endPosTable.errorEndPos) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1939
                    skip(false, true, true, true);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1940
                }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1941
                stats.addAll(stat);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1942
            }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1943
        }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1944
    }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1945
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1946
    /*
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1947
     * This method parses a statement treating it as a block, relaxing the
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1948
     * JLS restrictions, allows us to parse more faulty code, doing so
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1949
     * enables us to provide better and accurate diagnostics to the user.
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1950
     */
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1951
    JCStatement parseStatementAsBlock() {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1952
        int pos = token.pos;
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1953
        List<JCStatement> stats = blockStatement();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1954
        if (stats.isEmpty()) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1955
            JCErroneous e = F.at(pos).Erroneous();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1956
            error(e, "illegal.start.of.stmt");
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1957
            return F.at(pos).Exec(e);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1958
        } else {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1959
            JCStatement first = stats.head;
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1960
            String error = null;
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1961
            switch (first.getTag()) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1962
            case CLASSDEF:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1963
                error = "class.not.allowed";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1964
                break;
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1965
            case VARDEF:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1966
                error = "variable.not.allowed";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1967
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1968
            }
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1969
            if (error != null) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1970
                error(first, error);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1971
                List<JCBlock> blist = List.of(F.at(first.pos).Block(0, stats));
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1972
                return toP(F.at(pos).Exec(F.at(first.pos).Erroneous(blist)));
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1973
            }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1974
            return first;
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1975
        }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1976
    }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1977
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1978
    @SuppressWarnings("fallthrough")
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1979
    List<JCStatement> blockStatement() {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1980
        //todo: skip to anchor on error(?)
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1981
        int pos = token.pos;
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1982
        switch (token.kind) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1983
        case RBRACE: case CASE: case DEFAULT: case EOF:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1984
            return List.nil();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1985
        case LBRACE: case IF: case FOR: case WHILE: case DO: case TRY:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1986
        case SWITCH: case SYNCHRONIZED: case RETURN: case THROW: case BREAK:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1987
        case CONTINUE: case SEMI: case ELSE: case FINALLY: case CATCH:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1988
            return List.of(parseStatement());
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1989
        case MONKEYS_AT:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1990
        case FINAL: {
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  1991
            Comment dc = token.comment(CommentStyle.JAVADOC);
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1992
            JCModifiers mods = modifiersOpt();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1993
            if (token.kind == INTERFACE ||
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1994
                token.kind == CLASS ||
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1995
                allowEnums && token.kind == ENUM) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1996
                return List.of(classOrInterfaceOrEnumDeclaration(mods, dc));
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1997
            } else {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1998
                JCExpression t = parseType();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  1999
                ListBuffer<JCStatement> stats =
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2000
                        variableDeclarators(mods, t, new ListBuffer<JCStatement>());
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2001
                // A "LocalVariableDeclarationStatement" subsumes the terminating semicolon
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
  2002
                storeEnd(stats.last(), token.endPos);
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2003
                accept(SEMI);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2004
                return stats.toList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2005
            }
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2006
        }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2007
        case ABSTRACT: case STRICTFP: {
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2008
            Comment dc = token.comment(CommentStyle.JAVADOC);
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2009
            JCModifiers mods = modifiersOpt();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2010
            return List.of(classOrInterfaceOrEnumDeclaration(mods, dc));
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2011
        }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2012
        case INTERFACE:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2013
        case CLASS:
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2014
            Comment dc = token.comment(CommentStyle.JAVADOC);
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2015
            return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2016
        case ENUM:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2017
        case ASSERT:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2018
            if (allowEnums && token.kind == ENUM) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2019
                error(token.pos, "local.enum");
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2020
                dc = token.comment(CommentStyle.JAVADOC);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2021
                return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc));
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2022
            } else if (allowAsserts && token.kind == ASSERT) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2023
                return List.of(parseStatement());
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2024
            }
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2025
            /* fall through to default */
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2026
        default:
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2027
            Token prevToken = token;
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2028
            JCExpression t = term(EXPR | TYPE);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2029
            if (token.kind == COLON && t.hasTag(IDENT)) {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2030
                nextToken();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2031
                JCStatement stat = parseStatement();
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2032
                return List.<JCStatement>of(F.at(pos).Labelled(prevToken.name(), stat));
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2033
            } else if ((lastmode & TYPE) != 0 && LAX_IDENTIFIER.accepts(token.kind)) {
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2034
                pos = token.pos;
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2035
                JCModifiers mods = F.at(Position.NOPOS).Modifiers(0);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2036
                F.at(pos);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2037
                ListBuffer<JCStatement> stats =
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2038
                        variableDeclarators(mods, t, new ListBuffer<JCStatement>());
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2039
                // A "LocalVariableDeclarationStatement" subsumes the terminating semicolon
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
  2040
                storeEnd(stats.last(), token.endPos);
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2041
                accept(SEMI);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2042
                return stats.toList();
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2043
            } else {
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2044
                // This Exec is an "ExpressionStatement"; it subsumes the terminating semicolon
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2045
                JCExpressionStatement expr = to(F.at(pos).Exec(checkExprStat(t)));
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2046
                accept(SEMI);
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2047
                return List.<JCStatement>of(expr);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2048
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2049
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2050
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2051
06bc494ca11e Initial load
duke
parents:
diff changeset
  2052
    /** Statement =
06bc494ca11e Initial load
duke
parents:
diff changeset
  2053
     *       Block
06bc494ca11e Initial load
duke
parents:
diff changeset
  2054
     *     | IF ParExpression Statement [ELSE Statement]
06bc494ca11e Initial load
duke
parents:
diff changeset
  2055
     *     | FOR "(" ForInitOpt ";" [Expression] ";" ForUpdateOpt ")" Statement
06bc494ca11e Initial load
duke
parents:
diff changeset
  2056
     *     | FOR "(" FormalParameter : Expression ")" Statement
06bc494ca11e Initial load
duke
parents:
diff changeset
  2057
     *     | WHILE ParExpression Statement
06bc494ca11e Initial load
duke
parents:
diff changeset
  2058
     *     | DO Statement WHILE ParExpression ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2059
     *     | TRY Block ( Catches | [Catches] FinallyPart )
8234
5050975e2df0 7014734: Project Coin: Allow optional trailing semicolon to terminate resources list in try-with-resources
darcy
parents: 8224
diff changeset
  2060
     *     | TRY "(" ResourceSpecification ";"opt ")" Block [Catches] [FinallyPart]
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2061
     *     | SWITCH ParExpression "{" SwitchBlockStatementGroups "}"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2062
     *     | SYNCHRONIZED ParExpression Block
06bc494ca11e Initial load
duke
parents:
diff changeset
  2063
     *     | RETURN [Expression] ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2064
     *     | THROW Expression ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2065
     *     | BREAK [Ident] ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2066
     *     | CONTINUE [Ident] ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2067
     *     | ASSERT Expression [ ":" Expression ] ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2068
     *     | ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2069
     *     | ExpressionStatement
06bc494ca11e Initial load
duke
parents:
diff changeset
  2070
     *     | Ident ":" Statement
06bc494ca11e Initial load
duke
parents:
diff changeset
  2071
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2072
    @SuppressWarnings("fallthrough")
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2073
    public JCStatement parseStatement() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2074
        int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2075
        switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2076
        case LBRACE:
06bc494ca11e Initial load
duke
parents:
diff changeset
  2077
            return block();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2078
        case IF: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2079
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2080
            JCExpression cond = parExpression();
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2081
            JCStatement thenpart = parseStatementAsBlock();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2082
            JCStatement elsepart = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2083
            if (token.kind == ELSE) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2084
                nextToken();
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2085
                elsepart = parseStatementAsBlock();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2086
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2087
            return F.at(pos).If(cond, thenpart, elsepart);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2088
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2089
        case FOR: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2090
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2091
            accept(LPAREN);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2092
            List<JCStatement> inits = token.kind == SEMI ? List.<JCStatement>nil() : forInit();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2093
            if (inits.length() == 1 &&
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  2094
                inits.head.hasTag(VARDEF) &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2095
                ((JCVariableDecl) inits.head).init == null &&
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2096
                token.kind == COLON) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2097
                checkForeach();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2098
                JCVariableDecl var = (JCVariableDecl)inits.head;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2099
                accept(COLON);
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2100
                JCExpression expr = parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2101
                accept(RPAREN);
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2102
                JCStatement body = parseStatementAsBlock();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2103
                return F.at(pos).ForeachLoop(var, expr, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2104
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2105
                accept(SEMI);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2106
                JCExpression cond = token.kind == SEMI ? null : parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2107
                accept(SEMI);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2108
                List<JCExpressionStatement> steps = token.kind == RPAREN ? List.<JCExpressionStatement>nil() : forUpdate();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2109
                accept(RPAREN);
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2110
                JCStatement body = parseStatementAsBlock();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2111
                return F.at(pos).ForLoop(inits, cond, steps, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2112
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2113
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2114
        case WHILE: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2115
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2116
            JCExpression cond = parExpression();
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2117
            JCStatement body = parseStatementAsBlock();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2118
            return F.at(pos).WhileLoop(cond, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2119
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2120
        case DO: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2121
            nextToken();
12466
08863ee323df 7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents: 12337
diff changeset
  2122
            JCStatement body = parseStatementAsBlock();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2123
            accept(WHILE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2124
            JCExpression cond = parExpression();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2125
            JCDoWhileLoop t = to(F.at(pos).DoLoop(body, cond));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2126
            accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2127
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2128
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2129
        case TRY: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2130
            nextToken();
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2131
            List<JCTree> resources = List.<JCTree>nil();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2132
            if (token.kind == LPAREN) {
7211
163fe60f63de 6970016: Clean up ARM/try-with-resources implementation
mcimadamore
parents: 7076
diff changeset
  2133
                checkTryWithResources();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2134
                nextToken();
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2135
                resources = resources();
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2136
                accept(RPAREN);
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2137
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2138
            JCBlock body = block();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2139
            ListBuffer<JCCatch> catchers = new ListBuffer<JCCatch>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2140
            JCBlock finalizer = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2141
            if (token.kind == CATCH || token.kind == FINALLY) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2142
                while (token.kind == CATCH) catchers.append(catchClause());
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2143
                if (token.kind == FINALLY) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2144
                    nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2145
                    finalizer = block();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2146
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2147
            } else {
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2148
                if (allowTWR) {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2149
                    if (resources.isEmpty())
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  2150
                        error(pos, "try.without.catch.finally.or.resource.decls");
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2151
                } else
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  2152
                    error(pos, "try.without.catch.or.finally");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2153
            }
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2154
            return F.at(pos).Try(resources, body, catchers.toList(), finalizer);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2155
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2156
        case SWITCH: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2157
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2158
            JCExpression selector = parExpression();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2159
            accept(LBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2160
            List<JCCase> cases = switchBlockStatementGroups();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2161
            JCSwitch t = to(F.at(pos).Switch(selector, cases));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2162
            accept(RBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2163
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2164
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2165
        case SYNCHRONIZED: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2166
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2167
            JCExpression lock = parExpression();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2168
            JCBlock body = block();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2169
            return F.at(pos).Synchronized(lock, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2170
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2171
        case RETURN: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2172
            nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2173
            JCExpression result = token.kind == SEMI ? null : parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2174
            JCReturn t = to(F.at(pos).Return(result));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2175
            accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2176
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2177
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2178
        case THROW: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2179
            nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2180
            JCExpression exc = parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2181
            JCThrow t = to(F.at(pos).Throw(exc));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2182
            accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2183
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2184
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2185
        case BREAK: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2186
            nextToken();
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2187
            Name label = LAX_IDENTIFIER.accepts(token.kind) ? ident() : null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2188
            JCBreak t = to(F.at(pos).Break(label));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2189
            accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2190
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2191
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2192
        case CONTINUE: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2193
            nextToken();
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2194
            Name label = LAX_IDENTIFIER.accepts(token.kind) ? ident() : null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2195
            JCContinue t =  to(F.at(pos).Continue(label));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2196
            accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2197
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2198
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2199
        case SEMI:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2200
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2201
            return toP(F.at(pos).Skip());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2202
        case ELSE:
14450
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2203
            int elsePos = token.pos;
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2204
            nextToken();
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2205
            return doRecover(elsePos, BasicErrorRecoveryAction.BLOCK_STMT, "else.without.if");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2206
        case FINALLY:
14450
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2207
            int finallyPos = token.pos;
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2208
            nextToken();
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2209
            return doRecover(finallyPos, BasicErrorRecoveryAction.BLOCK_STMT, "finally.without.try");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2210
        case CATCH:
14450
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2211
            return doRecover(token.pos, BasicErrorRecoveryAction.CATCH_CLAUSE, "catch.without.try");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2212
        case ASSERT: {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2213
            if (allowAsserts && token.kind == ASSERT) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2214
                nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2215
                JCExpression assertion = parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2216
                JCExpression message = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2217
                if (token.kind == COLON) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2218
                    nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2219
                    message = parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2220
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2221
                JCAssert t = to(F.at(pos).Assert(assertion, message));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2222
                accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2223
                return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2224
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2225
            /* else fall through to default case */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2226
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2227
        case ENUM:
06bc494ca11e Initial load
duke
parents:
diff changeset
  2228
        default:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2229
            Token prevToken = token;
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2230
            JCExpression expr = parseExpression();
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  2231
            if (token.kind == COLON && expr.hasTag(IDENT)) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2232
                nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2233
                JCStatement stat = parseStatement();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2234
                return F.at(pos).Labelled(prevToken.name(), stat);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2235
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2236
                // This Exec is an "ExpressionStatement"; it subsumes the terminating semicolon
06bc494ca11e Initial load
duke
parents:
diff changeset
  2237
                JCExpressionStatement stat = to(F.at(pos).Exec(checkExprStat(expr)));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2238
                accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2239
                return stat;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2240
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2241
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2242
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2243
14450
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2244
    private JCStatement doRecover(int startPos, ErrorRecoveryAction action, String key) {
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2245
        int errPos = S.errPos();
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2246
        JCTree stm = action.doRecover(this);
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2247
        S.errPos(errPos);
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2248
        return toP(F.Exec(syntaxError(startPos, List.<JCTree>of(stm), key)));
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2249
    }
7a62c5b13d6e 8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents: 14359
diff changeset
  2250
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2251
    /** CatchClause     = CATCH "(" FormalParameter ")" Block
06bc494ca11e Initial load
duke
parents:
diff changeset
  2252
     */
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  2253
    protected JCCatch catchClause() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2254
        int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2255
        accept(CATCH);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2256
        accept(LPAREN);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2257
        JCModifiers mods = optFinal(Flags.PARAMETER);
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2258
        List<JCExpression> catchTypes = catchTypes();
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2259
        JCExpression paramType = catchTypes.size() > 1 ?
9300
c2de4dd9853b 7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents: 9073
diff changeset
  2260
                toP(F.at(catchTypes.head.getStartPosition()).TypeUnion(catchTypes)) :
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2261
                catchTypes.head;
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2262
        JCVariableDecl formal = variableDeclaratorId(mods, paramType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2263
        accept(RPAREN);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2264
        JCBlock body = block();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2265
        return F.at(pos).Catch(formal, body);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2266
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2267
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2268
    List<JCExpression> catchTypes() {
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2269
        ListBuffer<JCExpression> catchTypes = ListBuffer.lb();
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2270
        catchTypes.add(parseType());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2271
        while (token.kind == BAR) {
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2272
            checkMulticatch();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2273
            nextToken();
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2274
            catchTypes.add(qualident());
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2275
        }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2276
        return catchTypes.toList();
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2277
    }
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  2278
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2279
    /** SwitchBlockStatementGroups = { SwitchBlockStatementGroup }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2280
     *  SwitchBlockStatementGroup = SwitchLabel BlockStatements
06bc494ca11e Initial load
duke
parents:
diff changeset
  2281
     *  SwitchLabel = CASE ConstantExpression ":" | DEFAULT ":"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2282
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2283
    List<JCCase> switchBlockStatementGroups() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2284
        ListBuffer<JCCase> cases = new ListBuffer<JCCase>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2285
        while (true) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2286
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2287
            switch (token.kind) {
14056
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2288
            case CASE:
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2289
            case DEFAULT:
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2290
                cases.append(switchBlockStatementGroup());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2291
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2292
            case RBRACE: case EOF:
06bc494ca11e Initial load
duke
parents:
diff changeset
  2293
                return cases.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2294
            default:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2295
                nextToken(); // to ensure progress
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2296
                syntaxError(pos, "expected3",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  2297
                    CASE, DEFAULT, RBRACE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2298
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2299
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2300
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2301
14056
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2302
    protected JCCase switchBlockStatementGroup() {
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2303
        int pos = token.pos;
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2304
        List<JCStatement> stats;
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2305
        JCCase c;
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2306
        switch (token.kind) {
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2307
        case CASE:
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2308
            nextToken();
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2309
            JCExpression pat = parseExpression();
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2310
            accept(COLON);
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2311
            stats = blockStatements();
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2312
            c = F.at(pos).Case(pat, stats);
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2313
            if (stats.isEmpty())
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2314
                storeEnd(c, S.prevToken().endPos);
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2315
            return c;
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2316
        case DEFAULT:
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2317
            nextToken();
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2318
            accept(COLON);
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2319
            stats = blockStatements();
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2320
            c = F.at(pos).Case(null, stats);
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2321
            if (stats.isEmpty())
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2322
                storeEnd(c, S.prevToken().endPos);
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2323
            return c;
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2324
        }
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2325
        throw new AssertionError("should not reach here");
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2326
    }
0ea78d6e0b7b 7198582: (java) Minor refactor of JavacParser
ksrini
parents: 13844
diff changeset
  2327
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2328
    /** MoreStatementExpressions = { COMMA StatementExpression }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2329
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2330
    <T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2331
                                                                    JCExpression first,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2332
                                                                    T stats) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2333
        // This Exec is a "StatementExpression"; it subsumes no terminating token
06bc494ca11e Initial load
duke
parents:
diff changeset
  2334
        stats.append(toP(F.at(pos).Exec(checkExprStat(first))));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2335
        while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2336
            nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2337
            pos = token.pos;
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2338
            JCExpression t = parseExpression();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2339
            // This Exec is a "StatementExpression"; it subsumes no terminating token
06bc494ca11e Initial load
duke
parents:
diff changeset
  2340
            stats.append(toP(F.at(pos).Exec(checkExprStat(t))));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2341
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2342
        return stats;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2343
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2344
06bc494ca11e Initial load
duke
parents:
diff changeset
  2345
    /** ForInit = StatementExpression MoreStatementExpressions
06bc494ca11e Initial load
duke
parents:
diff changeset
  2346
     *           |  { FINAL | '@' Annotation } Type VariableDeclarators
06bc494ca11e Initial load
duke
parents:
diff changeset
  2347
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2348
    List<JCStatement> forInit() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2349
        ListBuffer<JCStatement> stats = lb();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2350
        int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2351
        if (token.kind == FINAL || token.kind == MONKEYS_AT) {
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2352
            return variableDeclarators(optFinal(0), parseType(), stats).toList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2353
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2354
            JCExpression t = term(EXPR | TYPE);
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2355
            if ((lastmode & TYPE) != 0 && LAX_IDENTIFIER.accepts(token.kind)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2356
                return variableDeclarators(modifiersOpt(), t, stats).toList();
12715
139b8354de6a 7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents: 12466
diff changeset
  2357
            } else if ((lastmode & TYPE) != 0 && token.kind == COLON) {
139b8354de6a 7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents: 12466
diff changeset
  2358
                error(pos, "bad.initializer", "for-loop");
139b8354de6a 7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents: 12466
diff changeset
  2359
                return List.of((JCStatement)F.at(pos).VarDef(null, null, t, null));
139b8354de6a 7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents: 12466
diff changeset
  2360
            } else {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2361
                return moreStatementExpressions(pos, t, stats).toList();
12715
139b8354de6a 7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents: 12466
diff changeset
  2362
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2363
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2364
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2365
06bc494ca11e Initial load
duke
parents:
diff changeset
  2366
    /** ForUpdate = StatementExpression MoreStatementExpressions
06bc494ca11e Initial load
duke
parents:
diff changeset
  2367
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2368
    List<JCExpressionStatement> forUpdate() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2369
        return moreStatementExpressions(token.pos,
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2370
                                        parseExpression(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2371
                                        new ListBuffer<JCExpressionStatement>()).toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2372
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2373
06bc494ca11e Initial load
duke
parents:
diff changeset
  2374
    /** AnnotationsOpt = { '@' Annotation }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2375
     */
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  2376
    List<JCAnnotation> annotationsOpt() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2377
        if (token.kind != MONKEYS_AT) return List.nil(); // optimization
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2378
        ListBuffer<JCAnnotation> buf = new ListBuffer<JCAnnotation>();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2379
        while (token.kind == MONKEYS_AT) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2380
            int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2381
            nextToken();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  2382
            buf.append(annotation(pos));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2383
        }
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  2384
        return buf.toList();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2385
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2386
06bc494ca11e Initial load
duke
parents:
diff changeset
  2387
    /** ModifiersOpt = { Modifier }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2388
     *  Modifier = PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL
06bc494ca11e Initial load
duke
parents:
diff changeset
  2389
     *           | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE | "@"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2390
     *           | "@" Annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
  2391
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2392
    JCModifiers modifiersOpt() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2393
        return modifiersOpt(null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2394
    }
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  2395
    protected JCModifiers modifiersOpt(JCModifiers partial) {
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2396
        long flags;
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2397
        ListBuffer<JCAnnotation> annotations = new ListBuffer<JCAnnotation>();
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2398
        int pos;
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2399
        if (partial == null) {
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2400
            flags = 0;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2401
            pos = token.pos;
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2402
        } else {
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2403
            flags = partial.flags;
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2404
            annotations.appendList(partial.annotations);
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2405
            pos = partial.pos;
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2406
        }
10948
063463f6535f 7104201: Refactor DocCommentScanner
mcimadamore
parents: 10815
diff changeset
  2407
        if (token.deprecatedFlag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2408
            flags |= Flags.DEPRECATED;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2409
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2410
        int lastPos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2411
    loop:
06bc494ca11e Initial load
duke
parents:
diff changeset
  2412
        while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2413
            long flag;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2414
            switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2415
            case PRIVATE     : flag = Flags.PRIVATE; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2416
            case PROTECTED   : flag = Flags.PROTECTED; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2417
            case PUBLIC      : flag = Flags.PUBLIC; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2418
            case STATIC      : flag = Flags.STATIC; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2419
            case TRANSIENT   : flag = Flags.TRANSIENT; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2420
            case FINAL       : flag = Flags.FINAL; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2421
            case ABSTRACT    : flag = Flags.ABSTRACT; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2422
            case NATIVE      : flag = Flags.NATIVE; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2423
            case VOLATILE    : flag = Flags.VOLATILE; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2424
            case SYNCHRONIZED: flag = Flags.SYNCHRONIZED; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2425
            case STRICTFP    : flag = Flags.STRICTFP; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2426
            case MONKEYS_AT  : flag = Flags.ANNOTATION; break;
14267
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
  2427
            case DEFAULT     : checkDefaultMethods(); flag = Flags.DEFAULT; break;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2428
            case ERROR       : flag = 0; nextToken(); break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2429
            default: break loop;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2430
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2431
            if ((flags & flag) != 0) error(token.pos, "repeated.modifier");
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2432
            lastPos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2433
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2434
            if (flag == Flags.ANNOTATION) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2435
                checkAnnotations();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2436
                if (token.kind != INTERFACE) {
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  2437
                    JCAnnotation ann = annotation(lastPos);
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2438
                    // if first modifier is an annotation, set pos to annotation's.
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2439
                    if (flags == 0 && annotations.isEmpty())
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2440
                        pos = ann.pos;
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2441
                    annotations.append(ann);
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2442
                    lastPos = ann.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2443
                    flag = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2444
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2445
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2446
            flags |= flag;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2447
        }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2448
        switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2449
        case ENUM: flags |= Flags.ENUM; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2450
        case INTERFACE: flags |= Flags.INTERFACE; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2451
        default: break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2452
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2453
06bc494ca11e Initial load
duke
parents:
diff changeset
  2454
        /* A modifiers tree with no modifier tokens or annotations
06bc494ca11e Initial load
duke
parents:
diff changeset
  2455
         * has no text position. */
6152
111b884a19a7 6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents: 6148
diff changeset
  2456
        if ((flags & (Flags.ModifierFlags | Flags.ANNOTATION)) == 0 && annotations.isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2457
            pos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2458
06bc494ca11e Initial load
duke
parents:
diff changeset
  2459
        JCModifiers mods = F.at(pos).Modifiers(flags, annotations.toList());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2460
        if (pos != Position.NOPOS)
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2461
            storeEnd(mods, S.prevToken().endPos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2462
        return mods;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2463
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2464
06bc494ca11e Initial load
duke
parents:
diff changeset
  2465
    /** Annotation              = "@" Qualident [ "(" AnnotationFieldValues ")" ]
06bc494ca11e Initial load
duke
parents:
diff changeset
  2466
     * @param pos position of "@" token
06bc494ca11e Initial load
duke
parents:
diff changeset
  2467
     */
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  2468
    JCAnnotation annotation(int pos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2469
        // accept(AT); // AT consumed by caller
06bc494ca11e Initial load
duke
parents:
diff changeset
  2470
        checkAnnotations();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2471
        JCTree ident = qualident();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2472
        List<JCExpression> fieldValues = annotationFieldValuesOpt();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  2473
        JCAnnotation ann = F.at(pos).Annotation(ident, fieldValues);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2474
        storeEnd(ann, S.prevToken().endPos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2475
        return ann;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2476
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2477
06bc494ca11e Initial load
duke
parents:
diff changeset
  2478
    List<JCExpression> annotationFieldValuesOpt() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2479
        return (token.kind == LPAREN) ? annotationFieldValues() : List.<JCExpression>nil();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2480
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2481
06bc494ca11e Initial load
duke
parents:
diff changeset
  2482
    /** AnnotationFieldValues   = "(" [ AnnotationFieldValue { "," AnnotationFieldValue } ] ")" */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2483
    List<JCExpression> annotationFieldValues() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2484
        accept(LPAREN);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2485
        ListBuffer<JCExpression> buf = new ListBuffer<JCExpression>();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2486
        if (token.kind != RPAREN) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2487
            buf.append(annotationFieldValue());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2488
            while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2489
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2490
                buf.append(annotationFieldValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2491
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2492
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2493
        accept(RPAREN);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2494
        return buf.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2495
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2496
06bc494ca11e Initial load
duke
parents:
diff changeset
  2497
    /** AnnotationFieldValue    = AnnotationValue
06bc494ca11e Initial load
duke
parents:
diff changeset
  2498
     *                          | Identifier "=" AnnotationValue
06bc494ca11e Initial load
duke
parents:
diff changeset
  2499
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2500
    JCExpression annotationFieldValue() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2501
        if (token.kind == IDENTIFIER) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2502
            mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2503
            JCExpression t1 = term1();
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  2504
            if (t1.hasTag(IDENT) && token.kind == EQ) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2505
                int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2506
                accept(EQ);
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2507
                JCExpression v = annotationValue();
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2508
                return toP(F.at(pos).Assign(t1, v));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2509
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2510
                return t1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2511
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2512
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2513
        return annotationValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2514
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2515
06bc494ca11e Initial load
duke
parents:
diff changeset
  2516
    /* AnnotationValue          = ConditionalExpression
06bc494ca11e Initial load
duke
parents:
diff changeset
  2517
     *                          | Annotation
3997
35250de1d4ea 6337964: should ignore last comma in annotation array
darcy
parents: 3894
diff changeset
  2518
     *                          | "{" [ AnnotationValue { "," AnnotationValue } ] [","] "}"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2519
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2520
    JCExpression annotationValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2521
        int pos;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2522
        switch (token.kind) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2523
        case MONKEYS_AT:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2524
            pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2525
            nextToken();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  2526
            return annotation(pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2527
        case LBRACE:
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2528
            pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2529
            accept(LBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2530
            ListBuffer<JCExpression> buf = new ListBuffer<JCExpression>();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2531
            if (token.kind != RBRACE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2532
                buf.append(annotationValue());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2533
                while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2534
                    nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2535
                    if (token.kind == RBRACE) break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2536
                    buf.append(annotationValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2537
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2538
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2539
            accept(RBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2540
            return toP(F.at(pos).NewArray(null, List.<JCExpression>nil(), buf.toList()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2541
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  2542
            mode = EXPR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2543
            return term1();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2544
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2545
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2546
06bc494ca11e Initial load
duke
parents:
diff changeset
  2547
    /** VariableDeclarators = VariableDeclarator { "," VariableDeclarator }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2548
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2549
    public <T extends ListBuffer<? super JCVariableDecl>> T variableDeclarators(JCModifiers mods,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2550
                                                                         JCExpression type,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2551
                                                                         T vdefs)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2552
    {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2553
        return variableDeclaratorsRest(token.pos, mods, type, ident(), false, null, vdefs);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2554
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2555
06bc494ca11e Initial load
duke
parents:
diff changeset
  2556
    /** VariableDeclaratorsRest = VariableDeclaratorRest { "," VariableDeclarator }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2557
     *  ConstantDeclaratorsRest = ConstantDeclaratorRest { "," ConstantDeclarator }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2558
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  2559
     *  @param reqInit  Is an initializer always required?
06bc494ca11e Initial load
duke
parents:
diff changeset
  2560
     *  @param dc       The documentation comment for the variable declarations, or null.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2561
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2562
    <T extends ListBuffer<? super JCVariableDecl>> T variableDeclaratorsRest(int pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2563
                                                                     JCModifiers mods,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2564
                                                                     JCExpression type,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2565
                                                                     Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2566
                                                                     boolean reqInit,
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2567
                                                                     Comment dc,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2568
                                                                     T vdefs)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2569
    {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2570
        vdefs.append(variableDeclaratorRest(pos, mods, type, name, reqInit, dc));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2571
        while (token.kind == COMMA) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2572
            // All but last of multiple declarators subsume a comma
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
  2573
            storeEnd((JCTree)vdefs.last(), token.endPos);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2574
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2575
            vdefs.append(variableDeclarator(mods, type, reqInit, dc));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2576
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2577
        return vdefs;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2578
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2579
06bc494ca11e Initial load
duke
parents:
diff changeset
  2580
    /** VariableDeclarator = Ident VariableDeclaratorRest
06bc494ca11e Initial load
duke
parents:
diff changeset
  2581
     *  ConstantDeclarator = Ident ConstantDeclaratorRest
06bc494ca11e Initial load
duke
parents:
diff changeset
  2582
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2583
    JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean reqInit, Comment dc) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2584
        return variableDeclaratorRest(token.pos, mods, type, ident(), reqInit, dc);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2585
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2586
06bc494ca11e Initial load
duke
parents:
diff changeset
  2587
    /** VariableDeclaratorRest = BracketsOpt ["=" VariableInitializer]
06bc494ca11e Initial load
duke
parents:
diff changeset
  2588
     *  ConstantDeclaratorRest = BracketsOpt "=" VariableInitializer
06bc494ca11e Initial load
duke
parents:
diff changeset
  2589
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  2590
     *  @param reqInit  Is an initializer always required?
06bc494ca11e Initial load
duke
parents:
diff changeset
  2591
     *  @param dc       The documentation comment for the variable declarations, or null.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2592
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2593
    JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name,
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2594
                                  boolean reqInit, Comment dc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2595
        type = bracketsOpt(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2596
        JCExpression init = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2597
        if (token.kind == EQ) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2598
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2599
            init = variableInitializer();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2600
        }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2601
        else if (reqInit) syntaxError(token.pos, "expected", EQ);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2602
        JCVariableDecl result =
06bc494ca11e Initial load
duke
parents:
diff changeset
  2603
            toP(F.at(pos).VarDef(mods, name, type, init));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2604
        attach(result, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2605
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2606
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2607
06bc494ca11e Initial load
duke
parents:
diff changeset
  2608
    /** VariableDeclaratorId = Ident BracketsOpt
06bc494ca11e Initial load
duke
parents:
diff changeset
  2609
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2610
    JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type) {
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2611
        return variableDeclaratorId(mods, type, false);
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2612
    }
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2613
    //where
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2614
    JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type, boolean lambdaParameter) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2615
        int pos = token.pos;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2616
        Name name;
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2617
        if (lambdaParameter && token.kind == UNDERSCORE) {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2618
            syntaxError(pos, "expected", IDENTIFIER);
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2619
            name = token.name();
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2620
        } else {
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2621
            name = ident();
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2622
        }
8047
c7f08cdb5c3c 6569633: Varargs: parser error when varargs element type is an array
mcimadamore
parents: 8033
diff changeset
  2623
        if ((mods.flags & Flags.VARARGS) != 0 &&
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2624
                token.kind == LBRACKET) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2625
            log.error(token.pos, "varargs.and.old.array.syntax");
8047
c7f08cdb5c3c 6569633: Varargs: parser error when varargs element type is an array
mcimadamore
parents: 8033
diff changeset
  2626
        }
c7f08cdb5c3c 6569633: Varargs: parser error when varargs element type is an array
mcimadamore
parents: 8033
diff changeset
  2627
        type = bracketsOpt(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2628
        return toP(F.at(pos).VarDef(mods, name, type, null));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2629
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2630
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2631
    /** Resources = Resource { ";" Resources }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2632
     */
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2633
    List<JCTree> resources() {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2634
        ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2635
        defs.append(resource());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2636
        while (token.kind == SEMI) {
8234
5050975e2df0 7014734: Project Coin: Allow optional trailing semicolon to terminate resources list in try-with-resources
darcy
parents: 8224
diff changeset
  2637
            // All but last of multiple declarators must subsume a semicolon
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
  2638
            storeEnd(defs.last(), token.endPos);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2639
            int semiColonPos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2640
            nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2641
            if (token.kind == RPAREN) { // Optional trailing semicolon
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 8047
diff changeset
  2642
                                       // after last resource
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 8047
diff changeset
  2643
                break;
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 8047
diff changeset
  2644
            }
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2645
            defs.append(resource());
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2646
        }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2647
        return defs.toList();
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2648
    }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2649
8224
8f18e1622660 7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents: 8047
diff changeset
  2650
    /** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2651
     */
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  2652
    protected JCTree resource() {
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  2653
        JCModifiers optFinal = optFinal(Flags.FINAL);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  2654
        JCExpression type = parseType();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2655
        int pos = token.pos;
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  2656
        Name ident = ident();
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  2657
        return variableDeclaratorRest(pos, optFinal, type, ident, true, null);
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2658
    }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  2659
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2660
    /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
06bc494ca11e Initial load
duke
parents:
diff changeset
  2661
     */
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2662
    public JCTree.JCCompilationUnit parseCompilationUnit() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2663
        Token firstToken = token;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2664
        JCExpression pid = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2665
        JCModifiers mods = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2666
        boolean consumedToplevelDoc = false;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2667
        boolean seenImport = false;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2668
        boolean seenPackage = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2669
        List<JCAnnotation> packageAnnotations = List.nil();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2670
        if (token.kind == MONKEYS_AT)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2671
            mods = modifiersOpt();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2672
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2673
        if (token.kind == PACKAGE) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2674
            seenPackage = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2675
            if (mods != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2676
                checkNoMods(mods.flags);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2677
                packageAnnotations = mods.annotations;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2678
                mods = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2679
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2680
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2681
            pid = qualident();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2682
            accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2683
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2684
        ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2685
        boolean checkForImports = true;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2686
        boolean firstTypeDecl = true;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2687
        while (token.kind != EOF) {
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  2688
            if (token.pos <= endPosTable.errorEndPos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2689
                // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  2690
                skip(checkForImports, false, false, false);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2691
                if (token.kind == EOF)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2692
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2693
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2694
            if (checkForImports && mods == null && token.kind == IMPORT) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2695
                seenImport = true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2696
                defs.append(importDeclaration());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2697
            } else {
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2698
                Comment docComment = token.comment(CommentStyle.JAVADOC);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2699
                if (firstTypeDecl && !seenImport && !seenPackage) {
10948
063463f6535f 7104201: Refactor DocCommentScanner
mcimadamore
parents: 10815
diff changeset
  2700
                    docComment = firstToken.comment(CommentStyle.JAVADOC);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2701
                    consumedToplevelDoc = true;
6716
71df48777dd1 6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents: 6585
diff changeset
  2702
                }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2703
                JCTree def = typeDeclaration(mods, docComment);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2704
                if (def instanceof JCExpressionStatement)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2705
                    def = ((JCExpressionStatement)def).expr;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2706
                defs.append(def);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2707
                if (def instanceof JCClassDecl)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2708
                    checkForImports = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2709
                mods = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2710
                firstTypeDecl = false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2711
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2712
        }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2713
        JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(packageAnnotations, pid, defs.toList());
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2714
        if (!consumedToplevelDoc)
10948
063463f6535f 7104201: Refactor DocCommentScanner
mcimadamore
parents: 10815
diff changeset
  2715
            attach(toplevel, firstToken.comment(CommentStyle.JAVADOC));
14803
88347e495d34 8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents: 14725
diff changeset
  2716
        if (defs.isEmpty())
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2717
            storeEnd(toplevel, S.prevToken().endPos);
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2718
        if (keepDocComments)
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2719
            toplevel.docComments = docComments;
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2720
        if (keepLineMap)
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2721
            toplevel.lineMap = S.getLineMap();
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  2722
        toplevel.endPositions = this.endPosTable;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2723
        return toplevel;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2724
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2725
06bc494ca11e Initial load
duke
parents:
diff changeset
  2726
    /** ImportDeclaration = IMPORT [ STATIC ] Ident { "." Ident } [ "." "*" ] ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2727
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2728
    JCTree importDeclaration() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2729
        int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2730
        nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2731
        boolean importStatic = false;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2732
        if (token.kind == STATIC) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2733
            checkStaticImports();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2734
            importStatic = true;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2735
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2736
        }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2737
        JCExpression pid = toP(F.at(token.pos).Ident(ident()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2738
        do {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2739
            int pos1 = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2740
            accept(DOT);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2741
            if (token.kind == STAR) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2742
                pid = to(F.at(pos1).Select(pid, names.asterisk));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2743
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2744
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2745
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2746
                pid = toP(F.at(pos1).Select(pid, ident()));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2747
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2748
        } while (token.kind == DOT);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2749
        accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2750
        return toP(F.at(pos).Import(pid, importStatic));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2751
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2752
06bc494ca11e Initial load
duke
parents:
diff changeset
  2753
    /** TypeDeclaration = ClassOrInterfaceOrEnumDeclaration
06bc494ca11e Initial load
duke
parents:
diff changeset
  2754
     *                  | ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2755
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2756
    JCTree typeDeclaration(JCModifiers mods, Comment docComment) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2757
        int pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2758
        if (mods == null && token.kind == SEMI) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2759
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2760
            return toP(F.at(pos).Skip());
06bc494ca11e Initial load
duke
parents:
diff changeset
  2761
        } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2762
            return classOrInterfaceOrEnumDeclaration(modifiersOpt(mods), docComment);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2763
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2764
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2765
06bc494ca11e Initial load
duke
parents:
diff changeset
  2766
    /** ClassOrInterfaceOrEnumDeclaration = ModifiersOpt
06bc494ca11e Initial load
duke
parents:
diff changeset
  2767
     *           (ClassDeclaration | InterfaceDeclaration | EnumDeclaration)
06bc494ca11e Initial load
duke
parents:
diff changeset
  2768
     *  @param mods     Any modifiers starting the class or interface declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
  2769
     *  @param dc       The documentation comment for the class, or null.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2770
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2771
    JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods, Comment dc) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2772
        if (token.kind == CLASS) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2773
            return classDeclaration(mods, dc);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2774
        } else if (token.kind == INTERFACE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2775
            return interfaceDeclaration(mods, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2776
        } else if (allowEnums) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2777
            if (token.kind == ENUM) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2778
                return enumDeclaration(mods, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2779
            } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2780
                int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2781
                List<JCTree> errs;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2782
                if (LAX_IDENTIFIER.accepts(token.kind)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2783
                    errs = List.<JCTree>of(mods, toP(F.at(pos).Ident(ident())));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2784
                    setErrorEndPos(token.pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2785
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2786
                    errs = List.<JCTree>of(mods);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2787
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2788
                return toP(F.Exec(syntaxError(pos, errs, "expected3",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  2789
                                              CLASS, INTERFACE, ENUM)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2790
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2791
        } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2792
            if (token.kind == ENUM) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2793
                error(token.pos, "enums.not.supported.in.source", source.name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2794
                allowEnums = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2795
                return enumDeclaration(mods, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2796
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2797
            int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2798
            List<JCTree> errs;
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  2799
            if (LAX_IDENTIFIER.accepts(token.kind)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2800
                errs = List.<JCTree>of(mods, toP(F.at(pos).Ident(ident())));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2801
                setErrorEndPos(token.pos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2802
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2803
                errs = List.<JCTree>of(mods);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2804
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2805
            return toP(F.Exec(syntaxError(pos, errs, "expected2",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  2806
                                          CLASS, INTERFACE)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2807
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2808
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2809
06bc494ca11e Initial load
duke
parents:
diff changeset
  2810
    /** ClassDeclaration = CLASS Ident TypeParametersOpt [EXTENDS Type]
06bc494ca11e Initial load
duke
parents:
diff changeset
  2811
     *                     [IMPLEMENTS TypeList] ClassBody
06bc494ca11e Initial load
duke
parents:
diff changeset
  2812
     *  @param mods    The modifiers starting the class declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
  2813
     *  @param dc       The documentation comment for the class, or null.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2814
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2815
    protected JCClassDecl classDeclaration(JCModifiers mods, Comment dc) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2816
        int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2817
        accept(CLASS);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2818
        Name name = ident();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2819
06bc494ca11e Initial load
duke
parents:
diff changeset
  2820
        List<JCTypeParameter> typarams = typeParametersOpt();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2821
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8234
diff changeset
  2822
        JCExpression extending = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2823
        if (token.kind == EXTENDS) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2824
            nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2825
            extending = parseType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2826
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2827
        List<JCExpression> implementing = List.nil();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2828
        if (token.kind == IMPLEMENTS) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2829
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2830
            implementing = typeList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2831
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2832
        List<JCTree> defs = classOrInterfaceBody(name, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2833
        JCClassDecl result = toP(F.at(pos).ClassDef(
06bc494ca11e Initial load
duke
parents:
diff changeset
  2834
            mods, name, typarams, extending, implementing, defs));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2835
        attach(result, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2836
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2837
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2838
06bc494ca11e Initial load
duke
parents:
diff changeset
  2839
    /** InterfaceDeclaration = INTERFACE Ident TypeParametersOpt
06bc494ca11e Initial load
duke
parents:
diff changeset
  2840
     *                         [EXTENDS TypeList] InterfaceBody
06bc494ca11e Initial load
duke
parents:
diff changeset
  2841
     *  @param mods    The modifiers starting the interface declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
  2842
     *  @param dc       The documentation comment for the interface, or null.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2843
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2844
    protected JCClassDecl interfaceDeclaration(JCModifiers mods, Comment dc) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2845
        int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2846
        accept(INTERFACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2847
        Name name = ident();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2848
06bc494ca11e Initial load
duke
parents:
diff changeset
  2849
        List<JCTypeParameter> typarams = typeParametersOpt();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2850
06bc494ca11e Initial load
duke
parents:
diff changeset
  2851
        List<JCExpression> extending = List.nil();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2852
        if (token.kind == EXTENDS) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2853
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2854
            extending = typeList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2855
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2856
        List<JCTree> defs = classOrInterfaceBody(name, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2857
        JCClassDecl result = toP(F.at(pos).ClassDef(
06bc494ca11e Initial load
duke
parents:
diff changeset
  2858
            mods, name, typarams, null, extending, defs));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2859
        attach(result, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2860
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2861
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2862
06bc494ca11e Initial load
duke
parents:
diff changeset
  2863
    /** EnumDeclaration = ENUM Ident [IMPLEMENTS TypeList] EnumBody
06bc494ca11e Initial load
duke
parents:
diff changeset
  2864
     *  @param mods    The modifiers starting the enum declaration
06bc494ca11e Initial load
duke
parents:
diff changeset
  2865
     *  @param dc       The documentation comment for the enum, or null.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2866
     */
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2867
    protected JCClassDecl enumDeclaration(JCModifiers mods, Comment dc) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2868
        int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2869
        accept(ENUM);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2870
        Name name = ident();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2871
06bc494ca11e Initial load
duke
parents:
diff changeset
  2872
        List<JCExpression> implementing = List.nil();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2873
        if (token.kind == IMPLEMENTS) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2874
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2875
            implementing = typeList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2876
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2877
06bc494ca11e Initial load
duke
parents:
diff changeset
  2878
        List<JCTree> defs = enumBody(name);
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2879
        mods.flags |= Flags.ENUM;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2880
        JCClassDecl result = toP(F.at(pos).
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  2881
            ClassDef(mods, name, List.<JCTypeParameter>nil(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2882
                null, implementing, defs));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2883
        attach(result, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2884
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2885
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2886
06bc494ca11e Initial load
duke
parents:
diff changeset
  2887
    /** EnumBody = "{" { EnumeratorDeclarationList } [","]
06bc494ca11e Initial load
duke
parents:
diff changeset
  2888
     *                  [ ";" {ClassBodyDeclaration} ] "}"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2889
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2890
    List<JCTree> enumBody(Name enumName) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2891
        accept(LBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2892
        ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2893
        if (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2894
            nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2895
        } else if (token.kind != RBRACE && token.kind != SEMI) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2896
            defs.append(enumeratorDeclaration(enumName));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2897
            while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2898
                nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2899
                if (token.kind == RBRACE || token.kind == SEMI) break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2900
                defs.append(enumeratorDeclaration(enumName));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2901
            }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2902
            if (token.kind != SEMI && token.kind != RBRACE) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2903
                defs.append(syntaxError(token.pos, "expected3",
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
  2904
                                COMMA, RBRACE, SEMI));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2905
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2906
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2907
        }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2908
        if (token.kind == SEMI) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2909
            nextToken();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2910
            while (token.kind != RBRACE && token.kind != EOF) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2911
                defs.appendList(classOrInterfaceBodyDeclaration(enumName,
06bc494ca11e Initial load
duke
parents:
diff changeset
  2912
                                                                false));
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  2913
                if (token.pos <= endPosTable.errorEndPos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2914
                    // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  2915
                   skip(false, true, true, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2916
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2917
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2918
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2919
        accept(RBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2920
        return defs.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2921
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2922
06bc494ca11e Initial load
duke
parents:
diff changeset
  2923
    /** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ]
06bc494ca11e Initial load
duke
parents:
diff changeset
  2924
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2925
    JCTree enumeratorDeclaration(Name enumName) {
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  2926
        Comment dc = token.comment(CommentStyle.JAVADOC);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2927
        int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM;
10948
063463f6535f 7104201: Refactor DocCommentScanner
mcimadamore
parents: 10815
diff changeset
  2928
        if (token.deprecatedFlag()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2929
            flags |= Flags.DEPRECATED;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2930
        }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2931
        int pos = token.pos;
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  2932
        List<JCAnnotation> annotations = annotationsOpt();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2933
        JCModifiers mods = F.at(annotations.isEmpty() ? Position.NOPOS : pos).Modifiers(flags, annotations);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2934
        List<JCExpression> typeArgs = typeArgumentsOpt();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2935
        int identPos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2936
        Name name = ident();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2937
        int createPos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2938
        List<JCExpression> args = (token.kind == LPAREN)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2939
            ? arguments() : List.<JCExpression>nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2940
        JCClassDecl body = null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2941
        if (token.kind == LBRACE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2942
            JCModifiers mods1 = F.at(Position.NOPOS).Modifiers(Flags.ENUM | Flags.STATIC);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2943
            List<JCTree> defs = classOrInterfaceBody(names.empty, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2944
            body = toP(F.at(identPos).AnonymousClassDef(mods1, defs));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2945
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2946
        if (args.isEmpty() && body == null)
4704
5206047418c2 6472751: SourcePositions.getStartPos returns incorrect value for enum constants
jjg
parents: 3997
diff changeset
  2947
            createPos = identPos;
5206047418c2 6472751: SourcePositions.getStartPos returns incorrect value for enum constants
jjg
parents: 3997
diff changeset
  2948
        JCIdent ident = F.at(identPos).Ident(enumName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2949
        JCNewClass create = F.at(createPos).NewClass(null, typeArgs, ident, args, body);
4704
5206047418c2 6472751: SourcePositions.getStartPos returns incorrect value for enum constants
jjg
parents: 3997
diff changeset
  2950
        if (createPos != identPos)
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2951
            storeEnd(create, S.prevToken().endPos);
4704
5206047418c2 6472751: SourcePositions.getStartPos returns incorrect value for enum constants
jjg
parents: 3997
diff changeset
  2952
        ident = F.at(identPos).Ident(enumName);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2953
        JCTree result = toP(F.at(pos).VarDef(mods, name, ident, create));
06bc494ca11e Initial load
duke
parents:
diff changeset
  2954
        attach(result, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2955
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2956
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2957
06bc494ca11e Initial load
duke
parents:
diff changeset
  2958
    /** TypeList = Type {"," Type}
06bc494ca11e Initial load
duke
parents:
diff changeset
  2959
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2960
    List<JCExpression> typeList() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2961
        ListBuffer<JCExpression> ts = new ListBuffer<JCExpression>();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2962
        ts.append(parseType());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2963
        while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2964
            nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  2965
            ts.append(parseType());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2966
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2967
        return ts.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2968
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2969
06bc494ca11e Initial load
duke
parents:
diff changeset
  2970
    /** ClassBody     = "{" {ClassBodyDeclaration} "}"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2971
     *  InterfaceBody = "{" {InterfaceBodyDeclaration} "}"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2972
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2973
    List<JCTree> classOrInterfaceBody(Name className, boolean isInterface) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2974
        accept(LBRACE);
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  2975
        if (token.pos <= endPosTable.errorEndPos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2976
            // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  2977
            skip(false, true, false, false);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2978
            if (token.kind == LBRACE)
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2979
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2980
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2981
        ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  2982
        while (token.kind != RBRACE && token.kind != EOF) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2983
            defs.appendList(classOrInterfaceBodyDeclaration(className, isInterface));
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  2984
            if (token.pos <= endPosTable.errorEndPos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2985
               // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  2986
               skip(false, true, true, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2987
           }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2988
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2989
        accept(RBRACE);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2990
        return defs.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  2991
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2992
06bc494ca11e Initial load
duke
parents:
diff changeset
  2993
    /** ClassBodyDeclaration =
06bc494ca11e Initial load
duke
parents:
diff changeset
  2994
     *      ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  2995
     *    | [STATIC] Block
06bc494ca11e Initial load
duke
parents:
diff changeset
  2996
     *    | ModifiersOpt
06bc494ca11e Initial load
duke
parents:
diff changeset
  2997
     *      ( Type Ident
06bc494ca11e Initial load
duke
parents:
diff changeset
  2998
     *        ( VariableDeclaratorsRest ";" | MethodDeclaratorRest )
06bc494ca11e Initial load
duke
parents:
diff changeset
  2999
     *      | VOID Ident MethodDeclaratorRest
06bc494ca11e Initial load
duke
parents:
diff changeset
  3000
     *      | TypeParameters (Type | VOID) Ident MethodDeclaratorRest
06bc494ca11e Initial load
duke
parents:
diff changeset
  3001
     *      | Ident ConstructorDeclaratorRest
06bc494ca11e Initial load
duke
parents:
diff changeset
  3002
     *      | TypeParameters Ident ConstructorDeclaratorRest
06bc494ca11e Initial load
duke
parents:
diff changeset
  3003
     *      | ClassOrInterfaceOrEnumDeclaration
06bc494ca11e Initial load
duke
parents:
diff changeset
  3004
     *      )
06bc494ca11e Initial load
duke
parents:
diff changeset
  3005
     *  InterfaceBodyDeclaration =
06bc494ca11e Initial load
duke
parents:
diff changeset
  3006
     *      ";"
06bc494ca11e Initial load
duke
parents:
diff changeset
  3007
     *    | ModifiersOpt Type Ident
06bc494ca11e Initial load
duke
parents:
diff changeset
  3008
     *      ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" )
06bc494ca11e Initial load
duke
parents:
diff changeset
  3009
     */
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3010
    protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3011
        if (token.kind == SEMI) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3012
            nextToken();
6585
189f53daed52 6921495: spurious semicolons in class def cause empty NOPOS blocks
jjg
parents: 6152
diff changeset
  3013
            return List.<JCTree>nil();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3014
        } else {
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  3015
            Comment dc = token.comment(CommentStyle.JAVADOC);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3016
            int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3017
            JCModifiers mods = modifiersOpt();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3018
            if (token.kind == CLASS ||
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3019
                token.kind == INTERFACE ||
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3020
                allowEnums && token.kind == ENUM) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3021
                return List.<JCTree>of(classOrInterfaceOrEnumDeclaration(mods, dc));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3022
            } else if (token.kind == LBRACE && !isInterface &&
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3023
                       (mods.flags & Flags.StandardFlags & ~Flags.STATIC) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  3024
                       mods.annotations.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3025
                return List.<JCTree>of(block(pos, mods.flags));
06bc494ca11e Initial load
duke
parents:
diff changeset
  3026
            } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3027
                pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3028
                List<JCTypeParameter> typarams = typeParametersOpt();
8033
13d9c18b8fa1 6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents: 8032
diff changeset
  3029
                // if there are type parameters but no modifiers, save the start
13d9c18b8fa1 6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents: 8032
diff changeset
  3030
                // position of the method in the modifiers.
13d9c18b8fa1 6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents: 8032
diff changeset
  3031
                if (typarams.nonEmpty() && mods.pos == Position.NOPOS) {
13d9c18b8fa1 6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents: 8032
diff changeset
  3032
                    mods.pos = pos;
13d9c18b8fa1 6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents: 8032
diff changeset
  3033
                    storeEnd(mods, pos);
13d9c18b8fa1 6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents: 8032
diff changeset
  3034
                }
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3035
                Token tk = token;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3036
                pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3037
                JCExpression type;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3038
                boolean isVoid = token.kind == VOID;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3039
                if (isVoid) {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3040
                    type = to(F.at(pos).TypeIdent(TypeTag.VOID));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3041
                    nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3042
                } else {
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3043
                    type = parseType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3044
                }
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3045
                if (token.kind == LPAREN && !isInterface && type.hasTag(IDENT)) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3046
                    if (isInterface || tk.name() != className)
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3047
                        error(pos, "invalid.meth.decl.ret.type.req");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3048
                    return List.of(methodDeclaratorRest(
06bc494ca11e Initial load
duke
parents:
diff changeset
  3049
                        pos, mods, null, names.init, typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3050
                        isInterface, true, dc));
06bc494ca11e Initial load
duke
parents:
diff changeset
  3051
                } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3052
                    pos = token.pos;
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3053
                    Name name = ident();
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3054
                    if (token.kind == LPAREN) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3055
                        return List.of(methodDeclaratorRest(
06bc494ca11e Initial load
duke
parents:
diff changeset
  3056
                            pos, mods, type, name, typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3057
                            isInterface, isVoid, dc));
06bc494ca11e Initial load
duke
parents:
diff changeset
  3058
                    } else if (!isVoid && typarams.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3059
                        List<JCTree> defs =
06bc494ca11e Initial load
duke
parents:
diff changeset
  3060
                            variableDeclaratorsRest(pos, mods, type, name, isInterface, dc,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3061
                                                    new ListBuffer<JCTree>()).toList();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3062
                        storeEnd(defs.last(), token.endPos);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3063
                        accept(SEMI);
06bc494ca11e Initial load
duke
parents:
diff changeset
  3064
                        return defs;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3065
                    } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3066
                        pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3067
                        List<JCTree> err = isVoid
06bc494ca11e Initial load
duke
parents:
diff changeset
  3068
                            ? List.<JCTree>of(toP(F.at(pos).MethodDef(mods, name, type, typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3069
                                List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null)))
06bc494ca11e Initial load
duke
parents:
diff changeset
  3070
                            : null;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3071
                        return List.<JCTree>of(syntaxError(token.pos, err, "expected", LPAREN));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3072
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3073
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3074
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3075
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3076
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3077
06bc494ca11e Initial load
duke
parents:
diff changeset
  3078
    /** MethodDeclaratorRest =
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3079
     *      FormalParameters BracketsOpt [Throws TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3080
     *  VoidMethodDeclaratorRest =
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3081
     *      FormalParameters [Throws TypeList] ( MethodBody | ";")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3082
     *  InterfaceMethodDeclaratorRest =
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3083
     *      FormalParameters BracketsOpt [THROWS TypeList] ";"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3084
     *  VoidInterfaceMethodDeclaratorRest =
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3085
     *      FormalParameters [THROWS TypeList] ";"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3086
     *  ConstructorDeclaratorRest =
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3087
     *      "(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3088
     */
11147
20770e90d993 7119032: (javac) increase visibility of JavacParser methods to improve subtyping
ksrini
parents: 11144
diff changeset
  3089
    protected JCTree methodDeclaratorRest(int pos,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3090
                              JCModifiers mods,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3091
                              JCExpression type,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3092
                              Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3093
                              List<JCTypeParameter> typarams,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3094
                              boolean isInterface, boolean isVoid,
13077
16fb753bb5dc 7174143: encapsulate doc comment table
jjg
parents: 12715
diff changeset
  3095
                              Comment dc) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3096
        List<JCVariableDecl> params = formalParameters();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3097
        if (!isVoid) type = bracketsOpt(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3098
        List<JCExpression> thrown = List.nil();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3099
        if (token.kind == THROWS) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3100
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3101
            thrown = qualidentList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3102
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3103
        JCBlock body = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3104
        JCExpression defaultValue;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3105
        if (token.kind == LBRACE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3106
            body = block();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3107
            defaultValue = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3108
        } else {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3109
            if (token.kind == DEFAULT) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3110
                accept(DEFAULT);
06bc494ca11e Initial load
duke
parents:
diff changeset
  3111
                defaultValue = annotationValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3112
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3113
                defaultValue = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3114
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3115
            accept(SEMI);
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3116
            if (token.pos <= endPosTable.errorEndPos) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3117
                // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
  3118
                skip(false, true, false, false);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3119
                if (token.kind == LBRACE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3120
                    body = block();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3121
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3122
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3123
        }
4870
a132763160d7 6919889: assorted position errors in compiler syntax trees
jjg
parents: 4704
diff changeset
  3124
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3125
        JCMethodDecl result =
06bc494ca11e Initial load
duke
parents:
diff changeset
  3126
            toP(F.at(pos).MethodDef(mods, name, type, typarams,
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3127
                                    params, thrown,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3128
                                    body, defaultValue));
06bc494ca11e Initial load
duke
parents:
diff changeset
  3129
        attach(result, dc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  3130
        return result;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3131
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3132
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3133
    /** QualidentList = Qualident {"," Qualident}
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3134
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  3135
    List<JCExpression> qualidentList() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3136
        ListBuffer<JCExpression> ts = new ListBuffer<JCExpression>();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3137
        ts.append(qualident());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3138
        while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3139
            nextToken();
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3140
            ts.append(qualident());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3141
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3142
        return ts.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3144
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  3145
    /**
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  3146
     *  {@literal
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  3147
     *  TypeParametersOpt = ["<" TypeParameter {"," TypeParameter} ">"]
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  3148
     *  }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3149
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  3150
    List<JCTypeParameter> typeParametersOpt() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3151
        if (token.kind == LT) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3152
            checkGenerics();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3153
            ListBuffer<JCTypeParameter> typarams = new ListBuffer<JCTypeParameter>();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3154
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3155
            typarams.append(typeParameter());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3156
            while (token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3157
                nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3158
                typarams.append(typeParameter());
06bc494ca11e Initial load
duke
parents:
diff changeset
  3159
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3160
            accept(GT);
06bc494ca11e Initial load
duke
parents:
diff changeset
  3161
            return typarams.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3162
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3163
            return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3164
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3166
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  3167
    /**
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  3168
     *  {@literal
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  3169
     *  TypeParameter = TypeVariable [TypeParameterBound]
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3170
     *  TypeParameterBound = EXTENDS Type {"&" Type}
06bc494ca11e Initial load
duke
parents:
diff changeset
  3171
     *  TypeVariable = Ident
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13439
diff changeset
  3172
     *  }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3173
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  3174
    JCTypeParameter typeParameter() {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3175
        int pos = token.pos;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3176
        Name name = ident();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3177
        ListBuffer<JCExpression> bounds = new ListBuffer<JCExpression>();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3178
        if (token.kind == EXTENDS) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3179
            nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  3180
            bounds.append(parseType());
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3181
            while (token.kind == AMP) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3182
                nextToken();
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  3183
                bounds.append(parseType());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3184
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3185
        }
7072
4863847e93a5 6987760: remove 308 support from JDK7
jjg
parents: 6716
diff changeset
  3186
        return toP(F.at(pos).TypeParameter(name, bounds.toList()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3187
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3188
06bc494ca11e Initial load
duke
parents:
diff changeset
  3189
    /** FormalParameters = "(" [ FormalParameterList ] ")"
06bc494ca11e Initial load
duke
parents:
diff changeset
  3190
     *  FormalParameterList = [ FormalParameterListNovarargs , ] LastFormalParameter
06bc494ca11e Initial load
duke
parents:
diff changeset
  3191
     *  FormalParameterListNovarargs = [ FormalParameterListNovarargs , ] FormalParameter
06bc494ca11e Initial load
duke
parents:
diff changeset
  3192
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  3193
    List<JCVariableDecl> formalParameters() {
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3194
        return formalParameters(false);
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3195
    }
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3196
    List<JCVariableDecl> formalParameters(boolean lambdaParameters) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3197
        ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3198
        JCVariableDecl lastParam = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3199
        accept(LPAREN);
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3200
        if (token.kind != RPAREN) {
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3201
            params.append(lastParam = formalParameter(lambdaParameters));
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3202
            while ((lastParam.mods.flags & Flags.VARARGS) == 0 && token.kind == COMMA) {
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3203
                nextToken();
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3204
                params.append(lastParam = formalParameter(lambdaParameters));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3205
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3206
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3207
        accept(RPAREN);
06bc494ca11e Initial load
duke
parents:
diff changeset
  3208
        return params.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3209
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3210
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3211
    List<JCVariableDecl> implicitParameters(boolean hasParens) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3212
        if (hasParens) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3213
            accept(LPAREN);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3214
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3215
        ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3216
        if (token.kind != RPAREN && token.kind != ARROW) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3217
            params.append(implicitParameter());
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3218
            while (token.kind == COMMA) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3219
                nextToken();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3220
                params.append(implicitParameter());
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3221
            }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3222
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3223
        if (hasParens) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3224
            accept(RPAREN);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3225
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3226
        return params.toList();
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3227
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3228
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3229
    JCModifiers optFinal(long flags) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3230
        JCModifiers mods = modifiersOpt();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3231
        checkNoMods(mods.flags & ~(Flags.FINAL | Flags.DEPRECATED));
06bc494ca11e Initial load
duke
parents:
diff changeset
  3232
        mods.flags |= flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3233
        return mods;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3234
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3235
06bc494ca11e Initial load
duke
parents:
diff changeset
  3236
    /** FormalParameter = { FINAL | '@' Annotation } Type VariableDeclaratorId
06bc494ca11e Initial load
duke
parents:
diff changeset
  3237
     *  LastFormalParameter = { FINAL | '@' Annotation } Type '...' Ident | FormalParameter
06bc494ca11e Initial load
duke
parents:
diff changeset
  3238
     */
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3239
    protected JCVariableDecl formalParameter() {
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3240
        return formalParameter(false);
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3241
    }
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3242
    protected JCVariableDecl formalParameter(boolean lambdaParameter) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3243
        JCModifiers mods = optFinal(Flags.PARAMETER);
1258
1cf37d8837d1 6724118: change JavaCompiler to not use Scanner directly
jjg
parents: 939
diff changeset
  3244
        JCExpression type = parseType();
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3245
        if (token.kind == ELLIPSIS) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3246
            checkVarargs();
06bc494ca11e Initial load
duke
parents:
diff changeset
  3247
            mods.flags |= Flags.VARARGS;
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3248
            type = to(F.at(token.pos).TypeArray(type));
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3249
            nextToken();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3250
        }
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3251
        return variableDeclaratorId(mods, type, lambdaParameter);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3252
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3253
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3254
    protected JCVariableDecl implicitParameter() {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3255
        JCModifiers mods = F.at(token.pos).Modifiers(Flags.PARAMETER);
15367
31b57f2b8d0b 8005852: Treatment of '_' as identifier
mcimadamore
parents: 14803
diff changeset
  3256
        return variableDeclaratorId(mods, null, true);
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3257
    }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3258
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3259
/* ---------- auxiliary methods -------------- */
06bc494ca11e Initial load
duke
parents:
diff changeset
  3260
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3261
    void error(int pos, String key, Object ... args) {
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3262
        log.error(DiagnosticFlag.SYNTAX, pos, key, args);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3263
    }
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3264
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3265
    void error(DiagnosticPosition pos, String key, Object ... args) {
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3266
        log.error(DiagnosticFlag.SYNTAX, pos, key, args);
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3267
    }
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3268
7076
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3269
    void warning(int pos, String key, Object ... args) {
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3270
        log.warning(pos, key, args);
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3271
    }
c96fa26247c8 6994946: option to specify only syntax errors as unrecoverable
jjg
parents: 7074
diff changeset
  3272
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3273
    /** Check that given tree is a legal expression statement.
06bc494ca11e Initial load
duke
parents:
diff changeset
  3274
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  3275
    protected JCExpression checkExprStat(JCExpression t) {
14722
aaa39655aa2e 8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents: 14547
diff changeset
  3276
        if (!TreeInfo.isExpressionStatement(t)) {
10455
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3277
            JCExpression ret = F.at(t.pos).Erroneous(List.<JCTree>of(t));
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3278
            error(ret, "not.stmt");
3d070be0fff8 7073631: (javac) javac parser improvements for error position reporting
ksrini
parents: 10200
diff changeset
  3279
            return ret;
14722
aaa39655aa2e 8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents: 14547
diff changeset
  3280
        } else {
aaa39655aa2e 8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents: 14547
diff changeset
  3281
            return t;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3282
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3283
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3284
06bc494ca11e Initial load
duke
parents:
diff changeset
  3285
    /** Return precedence of operator represented by token,
06bc494ca11e Initial load
duke
parents:
diff changeset
  3286
     *  -1 if token is not a binary operator. @see TreeInfo.opPrec
06bc494ca11e Initial load
duke
parents:
diff changeset
  3287
     */
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3288
    static int prec(TokenKind token) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3289
        JCTree.Tag oc = optag(token);
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3290
        return (oc != NO_TAG) ? TreeInfo.opPrec(oc) : -1;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3291
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3292
5013
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3293
    /**
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3294
     * Return the lesser of two positions, making allowance for either one
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3295
     * being unset.
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3296
     */
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3297
    static int earlier(int pos1, int pos2) {
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3298
        if (pos1 == Position.NOPOS)
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3299
            return pos2;
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3300
        if (pos2 == Position.NOPOS)
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3301
            return pos1;
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3302
        return (pos1 < pos2 ? pos1 : pos2);
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3303
    }
e942b2e52479 6931927: position issues with synthesized anonymous class
jjg
parents: 4870
diff changeset
  3304
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3305
    /** Return operation tag of binary operator represented by token,
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3306
     *  No_TAG if token is not a binary operator.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3307
     */
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3308
    static JCTree.Tag optag(TokenKind token) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3309
        switch (token) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3310
        case BARBAR:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3311
            return OR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3312
        case AMPAMP:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3313
            return AND;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3314
        case BAR:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3315
            return BITOR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3316
        case BAREQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3317
            return BITOR_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3318
        case CARET:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3319
            return BITXOR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3320
        case CARETEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3321
            return BITXOR_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3322
        case AMP:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3323
            return BITAND;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3324
        case AMPEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3325
            return BITAND_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3326
        case EQEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3327
            return JCTree.Tag.EQ;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3328
        case BANGEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3329
            return NE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3330
        case LT:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3331
            return JCTree.Tag.LT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3332
        case GT:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3333
            return JCTree.Tag.GT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3334
        case LTEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3335
            return LE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3336
        case GTEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3337
            return GE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3338
        case LTLT:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3339
            return SL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3340
        case LTLTEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3341
            return SL_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3342
        case GTGT:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3343
            return SR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3344
        case GTGTEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3345
            return SR_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3346
        case GTGTGT:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3347
            return USR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3348
        case GTGTGTEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3349
            return USR_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3350
        case PLUS:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3351
            return JCTree.Tag.PLUS;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3352
        case PLUSEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3353
            return PLUS_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3354
        case SUB:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3355
            return MINUS;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3356
        case SUBEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3357
            return MINUS_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3358
        case STAR:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3359
            return MUL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3360
        case STAREQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3361
            return MUL_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3362
        case SLASH:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3363
            return DIV;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3364
        case SLASHEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3365
            return DIV_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3366
        case PERCENT:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3367
            return MOD;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3368
        case PERCENTEQ:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3369
            return MOD_ASG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3370
        case INSTANCEOF:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3371
            return TYPETEST;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3372
        default:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3373
            return NO_TAG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3374
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3375
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3376
06bc494ca11e Initial load
duke
parents:
diff changeset
  3377
    /** Return operation tag of unary operator represented by token,
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3378
     *  No_TAG if token is not a binary operator.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3379
     */
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3380
    static JCTree.Tag unoptag(TokenKind token) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3381
        switch (token) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3382
        case PLUS:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3383
            return POS;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3384
        case SUB:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3385
            return NEG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3386
        case BANG:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3387
            return NOT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3388
        case TILDE:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3389
            return COMPL;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3390
        case PLUSPLUS:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3391
            return PREINC;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3392
        case SUBSUB:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3393
            return PREDEC;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3394
        default:
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10948
diff changeset
  3395
            return NO_TAG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3396
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3397
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3398
06bc494ca11e Initial load
duke
parents:
diff changeset
  3399
    /** Return type tag of basic type represented by token,
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3400
     *  NONE if token is not a basic type identifier.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3401
     */
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3402
    static TypeTag typetag(TokenKind token) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3403
        switch (token) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3404
        case BYTE:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3405
            return TypeTag.BYTE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3406
        case CHAR:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3407
            return TypeTag.CHAR;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3408
        case SHORT:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3409
            return TypeTag.SHORT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3410
        case INT:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3411
            return TypeTag.INT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3412
        case LONG:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3413
            return TypeTag.LONG;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3414
        case FLOAT:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3415
            return TypeTag.FLOAT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3416
        case DOUBLE:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3417
            return TypeTag.DOUBLE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3418
        case BOOLEAN:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3419
            return TypeTag.BOOLEAN;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3420
        default:
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14267
diff changeset
  3421
            return TypeTag.NONE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3422
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3423
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3424
06bc494ca11e Initial load
duke
parents:
diff changeset
  3425
    void checkGenerics() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3426
        if (!allowGenerics) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3427
            error(token.pos, "generics.not.supported.in.source", source.name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3428
            allowGenerics = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3429
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3430
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3431
    void checkVarargs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3432
        if (!allowVarargs) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3433
            error(token.pos, "varargs.not.supported.in.source", source.name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3434
            allowVarargs = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3435
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3436
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3437
    void checkForeach() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3438
        if (!allowForeach) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3439
            error(token.pos, "foreach.not.supported.in.source", source.name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3440
            allowForeach = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3441
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3442
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3443
    void checkStaticImports() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3444
        if (!allowStaticImport) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3445
            error(token.pos, "static.import.not.supported.in.source", source.name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3446
            allowStaticImport = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3447
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3448
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3449
    void checkAnnotations() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  3450
        if (!allowAnnotations) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3451
            error(token.pos, "annotations.not.supported.in.source", source.name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3452
            allowAnnotations = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  3453
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  3454
    }
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  3455
    void checkDiamond() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  3456
        if (!allowDiamond) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3457
            error(token.pos, "diamond.not.supported.in.source", source.name);
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  3458
            allowDiamond = true;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  3459
        }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
  3460
    }
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  3461
    void checkMulticatch() {
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  3462
        if (!allowMulticatch) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3463
            error(token.pos, "multicatch.not.supported.in.source", source.name);
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  3464
            allowMulticatch = true;
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  3465
        }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  3466
    }
7211
163fe60f63de 6970016: Clean up ARM/try-with-resources implementation
mcimadamore
parents: 7076
diff changeset
  3467
    void checkTryWithResources() {
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  3468
        if (!allowTWR) {
10815
a719aa5f1631 7096014: Javac tokens should retain state
mcimadamore
parents: 10455
diff changeset
  3469
            error(token.pos, "try.with.resources.not.supported.in.source", source.name);
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  3470
            allowTWR = true;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 6146
diff changeset
  3471
        }
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
  3472
    }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3473
    void checkLambda() {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3474
        if (!allowLambda) {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3475
            log.error(token.pos, "lambda.not.supported.in.source", source.name);
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3476
            allowLambda = true;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3477
        }
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 11055
diff changeset
  3478
    }
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  3479
    void checkMethodReferences() {
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  3480
        if (!allowMethodReferences) {
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  3481
            log.error(token.pos, "method.references.not.supported.in.source", source.name);
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  3482
            allowMethodReferences = true;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  3483
        }
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
  3484
    }
14267
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
  3485
    void checkDefaultMethods() {
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
  3486
        if (!allowDefaultMethods) {
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
  3487
            log.error(token.pos, "default.methods.not.supported.in.source", source.name);
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
  3488
            allowDefaultMethods = true;
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
  3489
        }
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14263
diff changeset
  3490
    }
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  3491
    void checkIntersectionTypesInCast() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  3492
        if (!allowIntersectionTypesInCast) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  3493
            log.error(token.pos, "intersection.types.in.cast.not.supported.in.source", source.name);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  3494
            allowIntersectionTypesInCast = true;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  3495
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14722
diff changeset
  3496
    }
11055
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3497
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3498
    /*
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3499
     * a functional source tree and end position mappings
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3500
     */
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3501
    protected class SimpleEndPosTable extends AbstractEndPosTable {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3502
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3503
        private final Map<JCTree, Integer> endPosMap;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3504
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3505
        SimpleEndPosTable() {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3506
            endPosMap = new HashMap<JCTree, Integer>();
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3507
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3508
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3509
        protected void storeEnd(JCTree tree, int endpos) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3510
            endPosMap.put(tree, errorEndPos > endpos ? errorEndPos : endpos);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3511
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3512
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3513
        protected <T extends JCTree> T to(T t) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3514
            storeEnd(t, token.endPos);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3515
            return t;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3516
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3517
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3518
        protected <T extends JCTree> T toP(T t) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3519
            storeEnd(t, S.prevToken().endPos);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3520
            return t;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3521
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3522
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3523
        public int getEndPos(JCTree tree) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3524
            Integer value = endPosMap.get(tree);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3525
            return (value == null) ? Position.NOPOS : value;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3526
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3527
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3528
        public int replaceTree(JCTree oldTree, JCTree newTree) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3529
            Integer pos = endPosMap.remove(oldTree);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3530
            if (pos != null) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3531
                endPosMap.put(newTree, pos);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3532
                return pos;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3533
            }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3534
            return Position.NOPOS;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3535
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3536
    }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3537
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3538
    /*
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3539
     * a default skeletal implementation without any mapping overhead.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3540
     */
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3541
    protected class EmptyEndPosTable extends AbstractEndPosTable {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3542
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3543
        protected void storeEnd(JCTree tree, int endpos) { /* empty */ }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3544
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3545
        protected <T extends JCTree> T to(T t) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3546
            return t;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3547
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3548
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3549
        protected <T extends JCTree> T toP(T t) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3550
            return t;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3551
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3552
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3553
        public int getEndPos(JCTree tree) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3554
            return Position.NOPOS;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3555
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3556
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3557
        public int replaceTree(JCTree oldTree, JCTree newTree) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3558
            return Position.NOPOS;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3559
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3560
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3561
    }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3562
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3563
    protected abstract class AbstractEndPosTable implements EndPosTable {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3564
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3565
        /**
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3566
         * Store the last error position.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3567
         */
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3568
        protected int errorEndPos;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3569
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3570
        /**
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3571
         * Store ending position for a tree, the value of which is the greater
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3572
         * of last error position and the given ending position.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3573
         * @param tree   The tree.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3574
         * @param endpos The ending position to associate with the tree.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3575
         */
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3576
        protected abstract void storeEnd(JCTree tree, int endpos);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3577
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3578
        /**
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3579
         * Store current token's ending position for a tree, the value of which
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3580
         * will be the greater of last error position and the ending position of
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3581
         * the current token.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3582
         * @param t The tree.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3583
         */
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3584
        protected abstract <T extends JCTree> T to(T t);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3585
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3586
        /**
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3587
         * Store current token's ending position for a tree, the value of which
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3588
         * will be the greater of last error position and the ending position of
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3589
         * the previous token.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3590
         * @param t The tree.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3591
         */
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3592
        protected abstract <T extends JCTree> T toP(T t);
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3593
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3594
        /**
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3595
         * Set the error position during the parsing phases, the value of which
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3596
         * will be set only if it is greater than the last stored error position.
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3597
         * @param errPos The error position
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3598
         */
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3599
        protected void setErrorEndPos(int errPos) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3600
            if (errPos > errorEndPos) {
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3601
                errorEndPos = errPos;
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3602
            }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3603
        }
ec1418effa77 7106166: (javac) re-factor EndPos parser
ksrini
parents: 10950
diff changeset
  3604
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  3605
}