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