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