blob: 12744ff2761b2b2137f94ec1740eec48d67c5ea2 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
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
26package sun.tools.tree;
27
28import sun.tools.java.*;
29import sun.tools.asm.Assembler;
30import sun.tools.asm.Label;
31import java.io.PrintStream;
32import java.util.Hashtable;
33
34/**
35 * WARNING: The contents of this source file are not part of any
36 * supported API. Code that depends on them does so at its own risk:
37 * they are subject to change or removal without notice.
38 */
39public
40class ContinueStatement extends Statement {
41 Identifier lbl;
42
43 /**
44 * Constructor
45 */
46 public ContinueStatement(long where, Identifier lbl) {
47 super(CONTINUE, where);
48 this.lbl = lbl;
49 }
50
51 /**
52 * Check statement
53 */
54
55 Vset check(Environment env, Context ctx, Vset vset, Hashtable exp) {
56 checkLabel(env, ctx);
57 reach(env, vset);
58 // A new context is established here because the 'continue' statement
59 // itself may be labelled, however erroneously. A 'CheckContext' must
60 // be used here, as 'getContinueContext' is expected to return one.
61 CheckContext destctx = (CheckContext)new CheckContext(ctx, this).getContinueContext(lbl);
62 if (destctx != null) {
63 switch (destctx.node.op) {
64 case FOR:
65 case DO:
66 case WHILE:
67 if (destctx.frameNumber != ctx.frameNumber) {
68 env.error(where, "branch.to.uplevel", lbl);
69 }
70 destctx.vsContinue = destctx.vsContinue.join(vset);
71 break;
72 default:
73 env.error(where, "invalid.continue");
74 }
75 } else {
76 if (lbl != null) {
77 env.error(where, "label.not.found", lbl);
78 } else {
79 env.error(where, "invalid.continue");
80 }
81 }
82 CheckContext exitctx = ctx.getTryExitContext();
83 if (exitctx != null) {
84 exitctx.vsTryExit = exitctx.vsTryExit.join(vset);
85 }
86 return DEAD_END;
87 }
88
89 /**
90 * The cost of inlining this statement
91 */
92 public int costInline(int thresh, Environment env, Context ctx) {
93 return 1;
94 }
95
96 /**
97 * Code
98 */
99 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}