langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java
author jjg
Fri, 29 Aug 2008 11:10:12 -0700
changeset 1206 3a05355982a9
parent 10 06bc494ca11e
child 1264 076a3cde30d5
permissions -rw-r--r--
6597471: unused imports in javax.tools.JavaCompiler 6597531: unused imports and unused private const. in com.sun.tools.javac.Server.java Reviewed-by: mcimadamore Contributed-by: davide.angelocola@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
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.jvm;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.javac.code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.jvm.Code.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.tree.JCTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import static com.sun.tools.javac.jvm.ByteCodes.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
/** A helper class for code generation. Items are objects
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *  that stand for addressable entities in the bytecode. Each item
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  supports a fixed protocol for loading the item on the stack, storing
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *  into it, converting it into a jump condition, and several others.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  There are many individual forms of items, such as local, static,
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  indexed, or instance variables, values on the top of stack, the
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  special values this or super, etc. Individual items are represented as
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *  inner classes in class Items.
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 Items {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /** The current constant pool.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    Pool pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /** The current code buffer.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    Code code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /** The current symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /** Type utilities. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    Types types;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    /** Items that exist only once (flyweight pattern).
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    private final Item voidItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    private final Item thisItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    private final Item superItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    private final Item[] stackItem = new Item[TypeCodeCount];
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    public Items(Pool pool, Code code, Symtab syms, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
        this.code = code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        this.pool = pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        this.types = types;
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        voidItem = new Item(VOIDcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                public String toString() { return "void"; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            };
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
        thisItem = new SelfItem(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
        superItem = new SelfItem(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        for (int i = 0; i < VOIDcode; i++) stackItem[i] = new StackItem(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        stackItem[VOIDcode] = voidItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        this.syms = syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    /** Make a void item
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    Item makeVoidItem() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return voidItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /** Make an item representing `this'.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    Item makeThisItem() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        return thisItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** Make an item representing `super'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    Item makeSuperItem() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        return superItem;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /** Make an item representing a value on stack.
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     *  @param type    The value's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    Item makeStackItem(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        return stackItem[Code.typecode(type)];
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /** Make an item representing an indexed expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     *  @param type    The expression's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    Item makeIndexedItem(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        return new IndexedItem(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    /** Make an item representing a local variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     *  @param v    The represented variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    LocalItem makeLocalItem(VarSymbol v) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return new LocalItem(v.erasure(types), v.adr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    /** Make an item representing a local anonymous variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     *  @param type  The represented variable's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     *  @param reg   The represented variable's register.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    private LocalItem makeLocalItem(Type type, int reg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        return new LocalItem(type, reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /** Make an item representing a static variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     *  @param member   The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    Item makeStaticItem(Symbol member) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        return new StaticItem(member);
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /** Make an item representing an instance variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     *  @param member       The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     *  @param nonvirtual   Is the reference not virtual? (true for constructors
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     *                      and private members).
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    Item makeMemberItem(Symbol member, boolean nonvirtual) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        return new MemberItem(member, nonvirtual);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    /** Make an item representing a literal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     *  @param type     The literal's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     *  @param value    The literal's value.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    Item makeImmediateItem(Type type, Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        return new ImmediateItem(type, value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
    /** Make an item representing an assignment expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     *  @param lhs      The item representing the assignment's left hand side.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    Item makeAssignItem(Item lhs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        return new AssignItem(lhs);
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /** Make an item representing a conditional or unconditional jump.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     *  @param opcode      The jump's opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     *  @param trueJumps   A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     *                     if the condition evaluates to true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     *  @param falseJumps  A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     *                     if the condition evaluates to false.
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    CondItem makeCondItem(int opcode, Chain trueJumps, Chain falseJumps) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        return new CondItem(opcode, trueJumps, falseJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    /** Make an item representing a conditional or unconditional jump.
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     *  @param opcode      The jump's opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    CondItem makeCondItem(int opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        return makeCondItem(opcode, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    /** The base class of all items, which implements default behavior.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    abstract class Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        /** The type code of values represented by this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        int typecode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        Item(int typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
            this.typecode = typecode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        /** Generate code to load this item onto stack.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        /** Generate code to store top of stack into this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            throw new AssertionError("store unsupported: " + this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        /** Generate code to invoke method represented by this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
        Item invoke() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            throw new AssertionError(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        /** Generate code to use this item twice.
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        void duplicate() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        /** Generate code to avoid having to use this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        void drop() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        /** Generate code to stash a copy of top of stack - of typecode toscode -
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
         *  under this item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
            stackItem[toscode].duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        /** Generate code to turn item into a testable condition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        CondItem mkCond() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            return makeCondItem(ifne);
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        /** Generate code to coerce item to given type code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
         *  @param targetcode    The type code to coerce to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        Item coerce(int targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
            if (typecode == targetcode)
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                int typecode1 = Code.truncate(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                int targetcode1 = Code.truncate(targetcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                if (typecode1 != targetcode1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
                    int offset = targetcode1 > typecode1 ? targetcode1 - 1
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                        : targetcode1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                    code.emitop0(i2l + typecode1 * 3 + offset);
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                if (targetcode != targetcode1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
                    code.emitop0(int2byte + targetcode - BYTEcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                return stackItem[targetcode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        /** Generate code to coerce item to given type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
         *  @param targettype    The type to coerce to.
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
        Item coerce(Type targettype) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            return coerce(Code.typecode(targettype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        /** Return the width of this item on stack as a number of words.
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
            return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        public abstract String toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
    /** An item representing a value on stack.
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
    class StackItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        StackItem(int typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            super(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            code.emitop0(width() == 2 ? dup2 : dup);
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
            code.emitop0(width() == 2 ? pop2 : pop);
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            code.emitop0(
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
                (width() == 2 ? dup_x2 : dup_x1) + 3 * (Code.width(toscode) - 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            return Code.width(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            return "stack(" + typecodeNames[typecode] + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    /** An item representing an indexed expression.
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    class IndexedItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
        IndexedItem(Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
            super(Code.typecode(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
            code.emitop0(iaload + typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            code.emitop0(iastore + typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
            code.emitop0(dup2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            code.emitop0(pop2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
            code.emitop0(dup_x2 + 3 * (Code.width(toscode) - 1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            return 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
            return "indexed(" + ByteCodes.typecodeNames[typecode] + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
    /** An item representing `this' or `super'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
    class SelfItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        /** Flag which determines whether this item represents `this' or `super'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        boolean isSuper;
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        SelfItem(boolean isSuper) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            super(OBJECTcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            this.isSuper = isSuper;
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
            code.emitop0(aload_0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            return isSuper ? "super" : "this";
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    /** An item representing a local variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    class LocalItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        /** The variable's register.
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        int reg;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        /** The variable's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
        LocalItem(Type type, int reg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
            super(Code.typecode(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
            assert reg >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            this.type = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
            this.reg = reg;
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
            if (reg <= 3)
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
                code.emitop0(iload_0 + Code.truncate(typecode) * 4 + reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
                code.emitop1w(iload + Code.truncate(typecode), reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            if (reg <= 3)
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
                code.emitop0(istore_0 + Code.truncate(typecode) * 4 + reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
                code.emitop1w(istore + Code.truncate(typecode), reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
            code.setDefined(reg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
        void incr(int x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            if (typecode == INTcode && x >= -32768 && x <= 32767) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
                code.emitop1w(iinc, reg, x);
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
                load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
                if (x >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
                    makeImmediateItem(syms.intType, x).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
                    code.emitop0(iadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
                    makeImmediateItem(syms.intType, -x).load();
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
                    code.emitop0(isub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
                makeStackItem(syms.intType).coerce(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
                store();
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            return "localItem(type=" + type + "; reg=" + reg + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
    /** An item representing a static variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
    class StaticItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        /** The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
        Symbol member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        StaticItem(Symbol member) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
            super(Code.typecode(member.erasure(types)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
            this.member = member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
            code.emitop2(getstatic, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
            code.emitop2(putstatic, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
        Item invoke() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
            MethodType mtype = (MethodType)member.erasure(types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
            int rescode = Code.typecode(mtype.restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
            code.emitInvokestatic(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            return stackItem[rescode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
            return "static(" + member + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
    /** An item representing an instance variable or method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    class MemberItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        /** The represented symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        Symbol member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        /** Flag that determines whether or not access is virtual.
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
        boolean nonvirtual;
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
        MemberItem(Symbol member, boolean nonvirtual) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
            super(Code.typecode(member.erasure(types)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
            this.member = member;
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
            this.nonvirtual = nonvirtual;
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
            code.emitop2(getfield, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        void store() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
            code.emitop2(putfield, pool.put(member));
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        Item invoke() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            MethodType mtype = (MethodType)member.externalType(types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
            int rescode = Code.typecode(mtype.restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
            if ((member.owner.flags() & Flags.INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
                code.emitInvokeinterface(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
            } else if (nonvirtual) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
                code.emitInvokespecial(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
                code.emitInvokevirtual(pool.put(member), mtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
            return stackItem[rescode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
            stackItem[OBJECTcode].duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
            stackItem[OBJECTcode].drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
            stackItem[OBJECTcode].stash(toscode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            return 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
            return "member(" + member + (nonvirtual ? " nonvirtual)" : ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
    /** An item representing a literal.
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
    class ImmediateItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        /** The literal's value.
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
        Object value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        ImmediateItem(Type type, Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
            super(Code.typecode(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
            this.value = value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        private void ldc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            int idx = pool.put(value);
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            if (typecode == LONGcode || typecode == DOUBLEcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                code.emitop2(ldc2w, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
            } else if (idx <= 255) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
                code.emitop1(ldc1, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
                code.emitop2(ldc2, idx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
            switch (typecode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
            case INTcode: case BYTEcode: case SHORTcode: case CHARcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
                int ival = ((Number)value).intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
                if (-1 <= ival && ival <= 5)
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
                    code.emitop0(iconst_0 + ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
                else if (Byte.MIN_VALUE <= ival && ival <= Byte.MAX_VALUE)
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
                    code.emitop1(bipush, ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
                else if (Short.MIN_VALUE <= ival && ival <= Short.MAX_VALUE)
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                    code.emitop2(sipush, ival);
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
            case LONGcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
                long lval = ((Number)value).longValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
                if (lval == 0 || lval == 1)
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
                    code.emitop0(lconst_0 + (int)lval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
            case FLOATcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
                float fval = ((Number)value).floatValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
                if (isPosZero(fval) || fval == 1.0 || fval == 2.0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
                    code.emitop0(fconst_0 + (int)fval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
                else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
            case DOUBLEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
                double dval = ((Number)value).doubleValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
                if (isPosZero(dval) || dval == 1.0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
                    code.emitop0(dconst_0 + (int)dval);
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
                    ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
            case OBJECTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
                ldc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
                assert false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        //where
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
            /** Return true iff float number is positive 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
            private boolean isPosZero(float x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
                return x == 0.0f && 1.0f / x > 0.0f;
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
            /** Return true iff double number is positive 0.
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
            private boolean isPosZero(double x) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
                return x == 0.0d && 1.0d / x > 0.0d;
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        CondItem mkCond() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
            int ival = ((Number)value).intValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
            return makeCondItem(ival != 0 ? goto_ : dontgoto);
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
        Item coerce(int targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            if (typecode == targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
                switch (targetcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
                case INTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
                    if (Code.truncate(typecode) == INTcode)
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
                        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
                    else
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
                        return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
                            syms.intType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
                            ((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
                case LONGcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
                        syms.longType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
                        ((Number)value).longValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
                case FLOATcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
                        syms.floatType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
                        ((Number)value).floatValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
                case DOUBLEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
                        syms.doubleType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
                        ((Number)value).doubleValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
                case BYTEcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
                        syms.byteType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
                        (int)(byte)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
                case CHARcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
                        syms.charType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
                        (int)(char)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
                case SHORTcode:
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
                    return new ImmediateItem(
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
                        syms.shortType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
                        (int)(short)((Number)value).intValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
                    return super.coerce(targetcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
            return "immediate(" + value + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
    /** An item representing an assignment expressions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
    class AssignItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
        /** The item representing the assignment's left hand side.
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
        Item lhs;
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
        AssignItem(Item lhs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
            super(lhs.typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
            this.lhs = lhs;
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
            lhs.stash(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
            lhs.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
            load().duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
            lhs.store();
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
            assert false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
            return lhs.width() + Code.width(typecode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
            return "assign(lhs = " + lhs + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
    /** An item representing a conditional or unconditional jump.
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
    class CondItem extends Item {
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
        /** A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
         *  if the condition evaluates to true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
        Chain trueJumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        /** A chain encomassing all jumps that can be taken
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
         *  if the condition evaluates to false.
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
        Chain falseJumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
        /** The jump's opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        int opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
        /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
         *  An abstract syntax tree of this item. It is needed
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
         *  for branch entries in 'CharacterRangeTable' attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
        JCTree tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
        CondItem(int opcode, Chain truejumps, Chain falsejumps) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            super(BYTEcode);
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
            this.opcode = opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
            this.trueJumps = truejumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
            this.falseJumps = falsejumps;
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
        Item load() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
            Chain trueChain = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
            Chain falseChain = jumpFalse();
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
            if (!isFalse()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
                code.resolve(trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
                code.emitop0(iconst_1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
                trueChain = code.branch(goto_);
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
            if (falseChain != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
                code.resolve(falseChain);
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
                code.emitop0(iconst_0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
            code.resolve(trueChain);
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
            return stackItem[typecode];
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
        void duplicate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
            load().duplicate();
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
        void drop() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
            load().drop();
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
        void stash(int toscode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
            assert false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
        CondItem mkCond() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
        Chain jumpTrue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
            if (tree == null) return code.mergeChains(trueJumps, code.branch(opcode));
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
            // we should proceed further in -Xjcov mode only
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
            int startpc = code.curPc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
            Chain c = code.mergeChains(trueJumps, code.branch(opcode));
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
            code.crt.put(tree, CRTable.CRT_BRANCH_TRUE, startpc, code.curPc());
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
        Chain jumpFalse() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
            if (tree == null) return code.mergeChains(falseJumps, code.branch(code.negate(opcode)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
            // we should proceed further in -Xjcov mode only
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
            int startpc = code.curPc();
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
            Chain c = code.mergeChains(falseJumps, code.branch(code.negate(opcode)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
            code.crt.put(tree, CRTable.CRT_BRANCH_FALSE, startpc, code.curPc());
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
        CondItem negate() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
            CondItem c = new CondItem(code.negate(opcode), falseJumps, trueJumps);
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
            c.tree = tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
            return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
        int width() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
            // a CondItem doesn't have a size on the stack per se.
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
        boolean isTrue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
            return falseJumps == null && opcode == goto_;
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
        boolean isFalse() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
            return trueJumps == null && opcode == dontgoto;
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            return "cond(" + Code.mnem(opcode) + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
}