jdk/src/jdk.rmic/share/classes/sun/tools/tree/VarDeclarationStatement.java
author jcoomes
Wed, 10 Sep 2014 13:01:13 -0700
changeset 26842 5081db39f634
parent 25859 3317bb8137f4
permissions -rw-r--r--
8057824: methods to copy allocation context statistics Reviewed-by: mikael, jmasa, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.tree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.tools.java.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.tools.asm.Assembler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.tools.asm.LocalVariable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
class VarDeclarationStatement extends Statement {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    LocalMember field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    Expression expr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public VarDeclarationStatement(long where, Expression expr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        super(VARDECLARATION, where);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        this.expr = expr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public VarDeclarationStatement(long where, LocalMember field, Expression expr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        super(VARDECLARATION, where);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        this.field = field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this.expr = expr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Check statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
    60
    Vset checkDeclaration(Environment env, Context ctx, Vset vset, int mod, Type t, Hashtable<Object, Object> exp) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (labels != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            env.error(where, "declaration.with.label", labels[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (field != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            if (ctx.getLocalClass(field.getName()) != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                && field.isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                env.error(where, "local.class.redefined", field.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            ctx.declare(env, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            if (field.isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                ClassDefinition body = field.getInnerClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    vset = body.checkLocalClass(env, ctx, vset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                                null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                } catch (ClassNotFound ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    env.error(where, "class.not.found", ee.name, opNames[op]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                return vset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            vset.addVar(field.number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            return (expr != null) ? expr.checkValue(env, ctx, vset, exp) : vset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // Argument 'expr' is either an IdentifierExpression for a declaration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // the form 'type x' or an AssignmentExpression for a declaration of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // form 'type x = initvalue'.  Note that these expressions are treated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // specially in this context, and don't have much connection to their ordinary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // meaning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        Expression e = expr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (e.op == ASSIGN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            expr = ((AssignExpression)e).right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            e = ((AssignExpression)e).left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            expr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        boolean declError = t.isType(TC_ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        while (e.op == ARRAYACCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            ArrayAccessExpression array = (ArrayAccessExpression)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            if (array.index != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                env.error(array.index.where, "array.dim.in.type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                declError = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            e = array.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            t = Type.tArray(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (e.op == IDENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            Identifier id = ((IdentifierExpression)e).id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (ctx.getLocalField(id) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                env.error(where, "local.redefined", id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            field = new LocalMember(e.where, ctx.field.getClassDefinition(), mod, t, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            ctx.declare(env, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (expr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                vset = expr.checkInitializer(env, ctx, vset, t, exp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                expr = convert(env, ctx, t, expr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                field.setValue(expr); // for the sake of non-blank finals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                if (field.isConstant()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    // Keep in mind that isConstant() only means expressions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    // that are constant according to the JLS.  They might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    // not be either constants or evaluable (eg. 1/0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    field.addModifiers(M_INLINEABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                vset.addVar(field.number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            } else if (declError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                vset.addVar(field.number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                vset.addVarUnassigned(field.number);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return vset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        env.error(e.where, "invalid.decl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return vset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public Statement inline(Environment env, Context ctx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (field.isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            ClassDefinition body = field.getInnerClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            body.inlineLocalClass(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // Don't generate code for variable if unused and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // optimization is on, whether or not debugging is on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (env.opt() && !field.isUsed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return new ExpressionStatement(where, expr).inline(env, ctx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        ctx.declare(env, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (expr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            expr = expr.inlineValue(env, ctx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            field.setValue(expr); // for the sake of non-blank finals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (env.opt() && (field.writecount == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                if (expr.op == IDENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    // This code looks like it tests whether a final variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    // is being initialized by an identifier expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    // Then if the identifier is a local of the same method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    // it makes the final variable eligible to be inlined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    // BUT: why isn't the local also checked to make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    // it is itself final?  Unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    IdentifierExpression e = (IdentifierExpression)expr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    if (e.field.isLocal() && ((ctx = ctx.getInlineContext()) != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                        (((LocalMember)e.field).number < ctx.varNumber)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                        //System.out.println("FINAL IDENT = " + field + " in " + ctx.field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                        field.setValue(expr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        field.addModifiers(M_INLINEABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        // The two lines below used to elide the declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        // of inlineable variables, on the theory that there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                        // wouldn't be any references.  But this breaks the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        // translation of nested classes, which might refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        // the variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        //expr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        //return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                if (expr.isConstant() || (expr.op == THIS) || (expr.op == SUPER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    //System.out.println("FINAL = " + field + " in " + ctx.field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    field.setValue(expr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    field.addModifiers(M_INLINEABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    // The two lines below used to elide the declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    // of inlineable variables, on the theory that there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    // wouldn't be any references.  But this breaks the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    // translation of nested classes, which might refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    // the variable.  Fix for 4073244.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    //expr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    //return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Create a copy of the statement for method inlining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public Statement copyInline(Context ctx, boolean valNeeded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        VarDeclarationStatement s = (VarDeclarationStatement)clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (expr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            s.expr = expr.copyInline(ctx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * The cost of inlining this statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public int costInline(int thresh, Environment env, Context ctx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (field != null && field.isInnerClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            return thresh;      // don't copy classes...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return (expr != null) ? expr.costInline(thresh, env, ctx) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public void code(Environment env, Context ctx, Assembler asm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (expr != null && !expr.type.isType(TC_VOID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            // The two lines of code directly following this comment used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // to be in the opposite order.  They were switched so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            // lines like the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            //     int j = (j = 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            // will compile correctly.  (Constructions like the above are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            // legal.  JLS 14.3.2 says that the scope of a local variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            // includes its own initializer.)  It is important that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            // declare `field' before we code `expr', because otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            // situations can arise where `field' thinks it is assigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            // a local variable slot that is, in actuality, assigned to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            // an entirely different variable.  (Bug id 4076729)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            ctx.declare(env, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            expr.codeValue(env, ctx, asm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            asm.add(where, opc_istore + field.getType().getTypeCodeOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    new LocalVariable(field, field.number));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            ctx.declare(env, field);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (expr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                // an initial side effect, rather than an initial value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                expr.code(env, ctx, asm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public void print(PrintStream out, int indent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        out.print("local ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (field != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            out.print(field + "#" + field.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (expr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                out.print(" = ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                expr.print(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            expr.print(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            out.print(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
}