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