History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/tools/tree/ThrowStatement.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/tools/tree/ThrowStatement.java+124−0
@@ -0,0 +1,124 @@
1/*
2 * Copyright (c) 1994, 2003, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package sun.tools.tree;
27
28import sun.tools.java.*;
29import sun.tools.asm.Assembler;
30import java.io.PrintStream;
31import java.util.Hashtable;
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 */
38public
39class ThrowStatement extends Statement {
40 Expression expr;
41
42 /**
43 * Constructor
44 */
45 public ThrowStatement(long where, Expression expr) {
46 super(THROW, where);
47 this.expr = expr;
48 }
49
50 /**
51 * Check statement
52 */
53 Vset check(Environment env, Context ctx, Vset vset, Hashtable exp) {
54 checkLabel(env, ctx);
55 try {
56 vset = reach(env, vset);
57 expr.checkValue(env, ctx, vset, exp);
58 if (expr.type.isType(TC_CLASS)) {
59 ClassDeclaration c = env.getClassDeclaration(expr.type);
60 if (exp.get(c) == null) {
61 exp.put(c, this);
62 }
63 ClassDefinition def = c.getClassDefinition(env);
64 ClassDeclaration throwable =
65 env.getClassDeclaration(idJavaLangThrowable);
66 if (!def.subClassOf(env, throwable)) {
67 env.error(where, "throw.not.throwable", def);
68 }
69 expr = convert(env, ctx, Type.tObject, expr);
70 } else if (!expr.type.isType(TC_ERROR)) {
71 env.error(expr.where, "throw.not.throwable", expr.type);
72 }
73 } catch (ClassNotFound e) {
74 env.error(where, "class.not.found", e.name, opNames[op]);
75 }
76 CheckContext exitctx = ctx.getTryExitContext();
77 if (exitctx != null) {
78 exitctx.vsTryExit = exitctx.vsTryExit.join(vset);
79 }
80 return DEAD_END;
81 }
82
83 /**
84 * Inline
85 */
86 public Statement inline(Environment env, Context ctx) {
87 expr = expr.inlineValue(env, ctx);
88 return this;
89 }
90
91 /**
92 * Create a copy of the statement for method inlining
93 */
94 public Statement copyInline(Context ctx, boolean valNeeded) {
95 ThrowStatement s = (ThrowStatement)clone();
96 s.expr = expr.copyInline(ctx);
97 return s;
98 }
99
100 /**
101 * The cost of inlining this statement
102 */
103 public int costInline(int thresh, Environment env, Context ctx) {
104 return 1 + expr.costInline(thresh, env, ctx);
105 }
106
107 /**
108 * Code
109 */
110 public void code(Environment env, Context ctx, Assembler asm) {
111 expr.codeValue(env, ctx, asm);
112 asm.add(where, opc_athrow);
113 }
114
115 /**
116 * Print
117 */
118 public void print(PrintStream out, int indent) {
119 super.print(out, indent);
120 out.print("throw ");
121 expr.print(out);
122 out.print(":");
123 }
124}