J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1994-2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package sun.tools.tree; |
| 27 | |
| 28 | import sun.tools.java.*; |
| 29 | import sun.tools.asm.Assembler; |
| 30 | import sun.tools.asm.Label; |
| 31 | import java.io.PrintStream; |
| 32 | |
| 33 | /** |
| 34 | * WARNING: The contents of this source file are not part of any |
| 35 | * supported API. Code that depends on them does so at its own risk: |
| 36 | * they are subject to change or removal without notice. |
| 37 | */ |
| 38 | public |
| 39 | class InlineReturnStatement extends Statement { |
| 40 | Expression expr; |
| 41 | |
| 42 | /** |
| 43 | * Constructor |
| 44 | */ |
| 45 | public InlineReturnStatement(long where, Expression expr) { |
| 46 | super(INLINERETURN, where); |
| 47 | this.expr = expr; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get the destination context of a break |
| 52 | */ |
| 53 | Context getDestination(Context ctx) { |
| 54 | for (; ctx != null ; ctx = ctx.prev) { |
| 55 | if ((ctx.node != null) && ((ctx.node.op == INLINEMETHOD) || (ctx.node.op == INLINENEWINSTANCE))) { |
| 56 | return ctx; |
| 57 | } |
| 58 | } |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Inline |
| 64 | */ |
| 65 | public Statement inline(Environment env, Context ctx) { |
| 66 | if (expr != null) { |
| 67 | expr = expr.inlineValue(env, ctx); |
| 68 | } |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Create a copy of the statement for method inlining |
| 74 | */ |
| 75 | public Statement copyInline(Context ctx, boolean valNeeded) { |
| 76 | InlineReturnStatement s = (InlineReturnStatement)clone(); |
| 77 | if (expr != null) { |
| 78 | s.expr = expr.copyInline(ctx); |
| 79 | } |
| 80 | return s; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * The cost of inlining this statement |
| 85 | */ |
| 86 | public int costInline(int thresh, Environment env, Context ctx) { |
| 87 | return 1 + ((expr != null) ? expr.costInline(thresh, env, ctx) : 0); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Code |
| 92 | */ |
| 93 | public void code(Environment env, Context ctx, Assembler asm) { |
| 94 | if (expr != null) { |
| 95 | expr.codeValue(env, ctx, asm); |
| 96 | } |
| 97 | CodeContext destctx = (CodeContext)getDestination(ctx); |
| 98 | asm.add(where, opc_goto, destctx.breakLabel); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Print |
| 103 | */ |
| 104 | public void print(PrintStream out, int indent) { |
| 105 | super.print(out, indent); |
| 106 | out.print("inline-return"); |
| 107 | if (expr != null) { |
| 108 | out.print(" "); |
| 109 | expr.print(out); |
| 110 | } |
| 111 | out.print(";"); |
| 112 | } |
| 113 | } |