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/DeclarationStatement.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/tools/tree/DeclarationStatement.java+151−0
@@ -0,0 +1,151 @@
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 java.io.PrintStream;
30import sun.tools.asm.Assembler;
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 DeclarationStatement extends Statement {
40 int mod;
41 Expression type;
42 Statement args[];
43
44 /**
45 * Constructor
46 */
47 public DeclarationStatement(long where, int mod, Expression type, Statement args[]) {
48 super(DECLARATION, where);
49 this.mod = mod;
50 this.type = type;
51 this.args = args;
52 }
53
54 /**
55 * Check statement
56 * Report an error unless the call is checkBlockStatement.
57 */
58 Vset check(Environment env, Context ctx, Vset vset, Hashtable exp) {
59 env.error(where, "invalid.decl");
60 return checkBlockStatement(env, ctx, vset, exp);
61 }
62 Vset checkBlockStatement(Environment env, Context ctx, Vset vset, Hashtable exp) {
63 if (labels != null) {
64 env.error(where, "declaration.with.label", labels[0]);
65 }
66 vset = reach(env, vset);
67 Type t = type.toType(env, ctx);
68
69 for (int i = 0 ; i < args.length ; i++) {
70 vset = args[i].checkDeclaration(env, ctx, vset, mod, t, exp);
71 }
72
73 return vset;
74 }
75
76 /**
77 * Inline
78 */
79 public Statement inline(Environment env, Context ctx) {
80 int n = 0;
81 for (int i = 0 ; i < args.length ; i++) {
82 if ((args[i] = args[i].inline(env, ctx)) != null) {
83 n++;
84 }
85 }
86 return (n == 0) ? null : this;
87 }
88
89 /**
90 * Create a copy of the statement for method inlining
91 */
92 public Statement copyInline(Context ctx, boolean valNeeded) {
93 DeclarationStatement s = (DeclarationStatement)clone();
94 if (type != null) {
95 s.type = type.copyInline(ctx);
96 }
97 s.args = new Statement[args.length];
98 for (int i = 0; i < args.length; i++){
99 if (args[i] != null){
100 s.args[i] = args[i].copyInline(ctx, valNeeded);
101 }
102 }
103 return s;
104 }
105
106 /**
107 * The cost of inlining this statement
108 */
109 public int costInline(int thresh, Environment env, Context ctx) {
110 int cost = 1;
111 for (int i = 0; i < args.length; i++){
112 if (args[i] != null){
113 cost += args[i].costInline(thresh, env, ctx);
114 }
115 }
116 return cost;
117 }
118
119
120 /**
121 * Code
122 */
123 public void code(Environment env, Context ctx, Assembler asm) {
124 for (int i = 0 ; i < args.length ; i++) {
125 if (args[i] != null) {
126 args[i].code(env, ctx, asm);
127 }
128 }
129 }
130
131 /**
132 * Print
133 */
134 public void print(PrintStream out, int indent) {
135 out.print("declare ");
136 super.print(out, indent);
137 type.print(out);
138 out.print(" ");
139 for (int i = 0 ; i < args.length ; i++) {
140 if (i > 0) {
141 out.print(", ");
142 }
143 if (args[i] != null) {
144 args[i].print(out);
145 } else {
146 out.print("<empty>");
147 }
148 }
149 out.print(";");
150 }
151}