001: /*
002: * Copyright 1994-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.tools.tree;
027:
028: import sun.tools.java.*;
029: import sun.tools.asm.Assembler;
030: import sun.tools.asm.Label;
031: import java.io.PrintStream;
032: import java.util.Hashtable;
033:
034: /**
035: * WARNING: The contents of this source file are not part of any
036: * supported API. Code that depends on them does so at its own risk:
037: * they are subject to change or removal without notice.
038: */
039: public class BreakStatement extends Statement {
040: Identifier lbl;
041:
042: /**
043: * Constructor
044: */
045: public BreakStatement(long where, Identifier lbl) {
046: super (BREAK, where);
047: this .lbl = lbl;
048: }
049:
050: /**
051: * Check statement
052: */
053: Vset check(Environment env, Context ctx, Vset vset, Hashtable exp) {
054: reach(env, vset);
055: checkLabel(env, ctx);
056: CheckContext destctx = (CheckContext) new CheckContext(ctx,
057: this ).getBreakContext(lbl);
058: if (destctx != null) {
059: if (destctx.frameNumber != ctx.frameNumber) {
060: env.error(where, "branch.to.uplevel", lbl);
061: }
062: destctx.vsBreak = destctx.vsBreak.join(vset);
063: } else {
064: if (lbl != null) {
065: env.error(where, "label.not.found", lbl);
066: } else {
067: env.error(where, "invalid.break");
068: }
069: }
070: CheckContext exitctx = ctx.getTryExitContext();
071: if (exitctx != null) {
072: exitctx.vsTryExit = exitctx.vsTryExit.join(vset);
073: }
074: return DEAD_END;
075: }
076:
077: /**
078: * The cost of inlining this statement
079: */
080: public int costInline(int thresh, Environment env, Context ctx) {
081: return 1;
082: }
083:
084: /**
085: * Code
086: */
087: public void code(Environment env, Context ctx, Assembler asm) {
088: CodeContext newctx = new CodeContext(ctx, this );
089: CodeContext destctx = (CodeContext) newctx.getBreakContext(lbl);
090: codeFinally(env, ctx, asm, destctx, null);
091: asm.add(where, opc_goto, destctx.breakLabel);
092: asm.add(newctx.breakLabel);
093: }
094:
095: /**
096: * Print
097: */
098: public void print(PrintStream out, int indent) {
099: super .print(out, indent);
100: out.print("break");
101: if (lbl != null) {
102: out.print(" " + lbl);
103: }
104: out.print(";");
105: }
106: }
|