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 java.io.PrintStream;
030: import sun.tools.asm.Assembler;
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 DeclarationStatement extends Statement {
039: int mod;
040: Expression type;
041: Statement args[];
042:
043: /**
044: * Constructor
045: */
046: public DeclarationStatement(long where, int mod, Expression type,
047: Statement args[]) {
048: super (DECLARATION, where);
049: this .mod = mod;
050: this .type = type;
051: this .args = args;
052: }
053:
054: /**
055: * Check statement
056: * Report an error unless the call is checkBlockStatement.
057: */
058: Vset check(Environment env, Context ctx, Vset vset, Hashtable exp) {
059: env.error(where, "invalid.decl");
060: return checkBlockStatement(env, ctx, vset, exp);
061: }
062:
063: Vset checkBlockStatement(Environment env, Context ctx, Vset vset,
064: Hashtable exp) {
065: if (labels != null) {
066: env.error(where, "declaration.with.label", labels[0]);
067: }
068: vset = reach(env, vset);
069: Type t = type.toType(env, ctx);
070:
071: for (int i = 0; i < args.length; i++) {
072: vset = args[i]
073: .checkDeclaration(env, ctx, vset, mod, t, exp);
074: }
075:
076: return vset;
077: }
078:
079: /**
080: * Inline
081: */
082: public Statement inline(Environment env, Context ctx) {
083: int n = 0;
084: for (int i = 0; i < args.length; i++) {
085: if ((args[i] = args[i].inline(env, ctx)) != null) {
086: n++;
087: }
088: }
089: return (n == 0) ? null : this ;
090: }
091:
092: /**
093: * Create a copy of the statement for method inlining
094: */
095: public Statement copyInline(Context ctx, boolean valNeeded) {
096: DeclarationStatement s = (DeclarationStatement) clone();
097: if (type != null) {
098: s.type = type.copyInline(ctx);
099: }
100: s.args = new Statement[args.length];
101: for (int i = 0; i < args.length; i++) {
102: if (args[i] != null) {
103: s.args[i] = args[i].copyInline(ctx, valNeeded);
104: }
105: }
106: return s;
107: }
108:
109: /**
110: * The cost of inlining this statement
111: */
112: public int costInline(int thresh, Environment env, Context ctx) {
113: int cost = 1;
114: for (int i = 0; i < args.length; i++) {
115: if (args[i] != null) {
116: cost += args[i].costInline(thresh, env, ctx);
117: }
118: }
119: return cost;
120: }
121:
122: /**
123: * Code
124: */
125: public void code(Environment env, Context ctx, Assembler asm) {
126: for (int i = 0; i < args.length; i++) {
127: if (args[i] != null) {
128: args[i].code(env, ctx, asm);
129: }
130: }
131: }
132:
133: /**
134: * Print
135: */
136: public void print(PrintStream out, int indent) {
137: out.print("declare ");
138: super .print(out, indent);
139: type.print(out);
140: out.print(" ");
141: for (int i = 0; i < args.length; i++) {
142: if (i > 0) {
143: out.print(", ");
144: }
145: if (args[i] != null) {
146: args[i].print(out);
147: } else {
148: out.print("<empty>");
149: }
150: }
151: out.print(";");
152: }
153: }
|