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