annotate src/share/tools/MakeDeps/MacroDefinitions.java @ 592:82e4d969e7cb

6806046: Hotspot build error when compiled from Visual Studio Summary: Define HOTSPOT_LIB_ARCH in the preprocessor flags of the generated projects Reviewed-by: kamg, xlu
author ikrylov
date Thu, 19 Feb 2009 04:54:22 -0500
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
26 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 public class MacroDefinitions {
a61af66fc99e Initial load
duke
parents:
diff changeset
29 private Vector macros;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public MacroDefinitions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 macros = new Vector();
a61af66fc99e Initial load
duke
parents:
diff changeset
33 }
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private String lookup(String name) throws NoSuchElementException {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 for (Iterator iter = macros.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 Macro macro = (Macro) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
38 if (macro.name.equals(name)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 return macro.contents;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 }
a61af66fc99e Initial load
duke
parents:
diff changeset
41 }
a61af66fc99e Initial load
duke
parents:
diff changeset
42 throw new NoSuchElementException(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 public void addMacro(String name, String contents) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 Macro macro = new Macro();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 macro.name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 macro.contents = contents;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 macros.add(macro);
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private boolean lineIsEmpty(String s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 for (int i = 0; i < s.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if (!Character.isWhitespace(s.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 public void readFrom(String fileName, boolean missingOk)
a61af66fc99e Initial load
duke
parents:
diff changeset
62 throws FileNotFoundException, FileFormatException, IOException {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 BufferedReader reader = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 reader = new BufferedReader(new FileReader(fileName));
a61af66fc99e Initial load
duke
parents:
diff changeset
66 } catch (FileNotFoundException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (missingOk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 throw(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 String line;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 line = reader.readLine();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (line != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // This had to be rewritten (compare to Database.java)
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // because the Solaris platform file has been
a61af66fc99e Initial load
duke
parents:
diff changeset
79 // repurposed and now contains "macros" with spaces in
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // them.
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if ((!line.startsWith("//")) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
83 (!lineIsEmpty(line))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 int nameBegin = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 int nameEnd = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 boolean gotEquals = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 int contentsBegin = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 int contentsEnd = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 // Scan forward for beginning of name
a61af66fc99e Initial load
duke
parents:
diff changeset
92 while (i < line.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 if (!Character.isWhitespace(line.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 nameBegin = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Scan forward for end of name
a61af66fc99e Initial load
duke
parents:
diff changeset
101 while (i < line.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (Character.isWhitespace(line.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 nameEnd = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Scan forward for equals sign
a61af66fc99e Initial load
duke
parents:
diff changeset
110 while (i < line.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (line.charAt(i) == '=') {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 gotEquals = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Scan forward for start of contents
a61af66fc99e Initial load
duke
parents:
diff changeset
119 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 while (i < line.length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 if (!Character.isWhitespace(line.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 contentsBegin = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // Scan *backward* for end of contents
a61af66fc99e Initial load
duke
parents:
diff changeset
129 i = line.length() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 while (i >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (!Character.isWhitespace(line.charAt(i))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 contentsEnd = i+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // Now do consistency check
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (!((nameBegin < nameEnd) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
139 (nameEnd < contentsBegin) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
140 (contentsBegin < contentsEnd) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
141 (gotEquals == true))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 throw new FileFormatException(
a61af66fc99e Initial load
duke
parents:
diff changeset
143 "Expected \"macroname = value\", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
144 "but found: " + line
a61af66fc99e Initial load
duke
parents:
diff changeset
145 );
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 String name = line.substring(nameBegin, nameEnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 String contents = line.substring(contentsBegin,
a61af66fc99e Initial load
duke
parents:
diff changeset
150 contentsEnd);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 addMacro(name, contents);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 } while (line != null);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 reader.close();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158 /** Throws IllegalArgumentException if passed token is illegally
a61af66fc99e Initial load
duke
parents:
diff changeset
159 formatted */
a61af66fc99e Initial load
duke
parents:
diff changeset
160 public String expand(String token)
a61af66fc99e Initial load
duke
parents:
diff changeset
161 throws IllegalArgumentException {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // the token may contain one or more <macroName>'s
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 String out = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // emacs lingo
a61af66fc99e Initial load
duke
parents:
diff changeset
167 int mark = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 int point = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 int len = token.length();
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (len == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
173 return out;
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // Scan "point" forward until hitting either the end of
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // the string or the beginning of a macro
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (token.charAt(point) == '<') {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // Append (point - mark) to out
a61af66fc99e Initial load
duke
parents:
diff changeset
180 if ((point - mark) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 out += token.substring(mark, point);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 mark = point + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // Scan forward from point for right bracket
a61af66fc99e Initial load
duke
parents:
diff changeset
185 point++;
a61af66fc99e Initial load
duke
parents:
diff changeset
186 while ((point < len) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
187 (token.charAt(point) != '>')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 point++;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (point == len) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 throw new IllegalArgumentException(
a61af66fc99e Initial load
duke
parents:
diff changeset
192 "Could not find right angle-bracket in token " + token
a61af66fc99e Initial load
duke
parents:
diff changeset
193 );
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 String name = token.substring(mark, point);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 if (name == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 throw new IllegalArgumentException(
a61af66fc99e Initial load
duke
parents:
diff changeset
198 "Empty macro in token " + token
a61af66fc99e Initial load
duke
parents:
diff changeset
199 );
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 String contents = lookup(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 out += contents;
a61af66fc99e Initial load
duke
parents:
diff changeset
204 point++;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 mark = point;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 } catch (NoSuchElementException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 throw new IllegalArgumentException(
a61af66fc99e Initial load
duke
parents:
diff changeset
208 "Unknown macro " + name + " in token " + token
a61af66fc99e Initial load
duke
parents:
diff changeset
209 );
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 point++;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 } while (point != len);
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 if (mark != point) {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 out += token.substring(mark, point);
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 return out;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 public MacroDefinitions copy() {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 MacroDefinitions ret = new MacroDefinitions();
a61af66fc99e Initial load
duke
parents:
diff changeset
225 for (Iterator iter = macros.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
226 iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 Macro orig = (Macro) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
228 Macro macro = new Macro();
a61af66fc99e Initial load
duke
parents:
diff changeset
229 macro.name = orig.name;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 macro.contents = orig.contents;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 ret.macros.add(macro);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 public void setAllMacroBodiesTo(String s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 for (Iterator iter = macros.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
238 iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 Macro macro = (Macro) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
240 macro.contents = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 /** This returns an Iterator of Macros. You should not mutate the
a61af66fc99e Initial load
duke
parents:
diff changeset
245 returned Macro objects or use the Iterator to remove
a61af66fc99e Initial load
duke
parents:
diff changeset
246 macros. */
a61af66fc99e Initial load
duke
parents:
diff changeset
247 public Iterator getMacros() {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 return macros.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
249 }
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 private void error(String text) throws FileFormatException {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 throw new FileFormatException(
a61af66fc99e Initial load
duke
parents:
diff changeset
253 "Expected \"macroname = value\", but found: " + text
a61af66fc99e Initial load
duke
parents:
diff changeset
254 );
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }