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 java.io.PrintStream;
031: import java.util.Hashtable;
032:
033: /**
034: * WARNING: The contents of this source file are not part of any
035: * supported API. Code that depends on them does so at its own risk:
036: * they are subject to change or removal without notice.
037: */
038: public class ThrowStatement extends Statement {
039: Expression expr;
040:
041: /**
042: * Constructor
043: */
044: public ThrowStatement(long where, Expression expr) {
045: super (THROW, where);
046: this .expr = expr;
047: }
048:
049: /**
050: * Check statement
051: */
052: Vset check(Environment env, Context ctx, Vset vset, Hashtable exp) {
053: checkLabel(env, ctx);
054: try {
055: vset = reach(env, vset);
056: expr.checkValue(env, ctx, vset, exp);
057: if (expr.type.isType(TC_CLASS)) {
058: ClassDeclaration c = env.getClassDeclaration(expr.type);
059: if (exp.get(c) == null) {
060: exp.put(c, this );
061: }
062: ClassDefinition def = c.getClassDefinition(env);
063: ClassDeclaration throwable = env
064: .getClassDeclaration(idJavaLangThrowable);
065: if (!def.subClassOf(env, throwable)) {
066: env.error(where, "throw.not.throwable", def);
067: }
068: expr = convert(env, ctx, Type.tObject, expr);
069: } else if (!expr.type.isType(TC_ERROR)) {
070: env.error(expr.where, "throw.not.throwable", expr.type);
071: }
072: } catch (ClassNotFound e) {
073: env.error(where, "class.not.found", e.name, opNames[op]);
074: }
075: CheckContext exitctx = ctx.getTryExitContext();
076: if (exitctx != null) {
077: exitctx.vsTryExit = exitctx.vsTryExit.join(vset);
078: }
079: return DEAD_END;
080: }
081:
082: /**
083: * Inline
084: */
085: public Statement inline(Environment env, Context ctx) {
086: expr = expr.inlineValue(env, ctx);
087: return this ;
088: }
089:
090: /**
091: * Create a copy of the statement for method inlining
092: */
093: public Statement copyInline(Context ctx, boolean valNeeded) {
094: ThrowStatement s = (ThrowStatement) clone();
095: s.expr = expr.copyInline(ctx);
096: return s;
097: }
098:
099: /**
100: * The cost of inlining this statement
101: */
102: public int costInline(int thresh, Environment env, Context ctx) {
103: return 1 + expr.costInline(thresh, env, ctx);
104: }
105:
106: /**
107: * Code
108: */
109: public void code(Environment env, Context ctx, Assembler asm) {
110: expr.codeValue(env, ctx, asm);
111: asm.add(where, opc_athrow);
112: }
113:
114: /**
115: * Print
116: */
117: public void print(PrintStream out, int indent) {
118: super .print(out, indent);
119: out.print("throw ");
120: expr.print(out);
121: out.print(":");
122: }
123: }
|