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 ContinueStatement extends Statement {
040: Identifier lbl;
041:
042: /**
043: * Constructor
044: */
045: public ContinueStatement(long where, Identifier lbl) {
046: super (CONTINUE, where);
047: this .lbl = lbl;
048: }
049:
050: /**
051: * Check statement
052: */
053:
054: Vset check(Environment env, Context ctx, Vset vset, Hashtable exp) {
055: checkLabel(env, ctx);
056: reach(env, vset);
057: // A new context is established here because the 'continue' statement
058: // itself may be labelled, however erroneously. A 'CheckContext' must
059: // be used here, as 'getContinueContext' is expected to return one.
060: CheckContext destctx = (CheckContext) new CheckContext(ctx,
061: this ).getContinueContext(lbl);
062: if (destctx != null) {
063: switch (destctx.node.op) {
064: case FOR:
065: case DO:
066: case WHILE:
067: if (destctx.frameNumber != ctx.frameNumber) {
068: env.error(where, "branch.to.uplevel", lbl);
069: }
070: destctx.vsContinue = destctx.vsContinue.join(vset);
071: break;
072: default:
073: env.error(where, "invalid.continue");
074: }
075: } else {
076: if (lbl != null) {
077: env.error(where, "label.not.found", lbl);
078: } else {
079: env.error(where, "invalid.continue");
080: }
081: }
082: CheckContext exitctx = ctx.getTryExitContext();
083: if (exitctx != null) {
084: exitctx.vsTryExit = exitctx.vsTryExit.join(vset);
085: }
086: return DEAD_END;
087: }
088:
089: /**
090: * The cost of inlining this statement
091: */
092: public int costInline(int thresh, Environment env, Context ctx) {
093: return 1;
094: }
095:
096: /**
097: * Code
098: */
099: public void code(Environment env, Context ctx, Assembler asm) {
100: CodeContext destctx = (CodeContext) ctx.getContinueContext(lbl);
101: codeFinally(env, ctx, asm, destctx, null);
102: asm.add(where, opc_goto, destctx.contLabel);
103: }
104:
105: /**
106: * Print
107: */
108: public void print(PrintStream out, int indent) {
109: super .print(out, indent);
110: out.print("continue");
111: if (lbl != null) {
112: out.print(" " + lbl);
113: }
114: out.print(";");
115: }
116: }
|