author | jcbeyler |
Thu, 30 Aug 2018 09:47:12 -0700 | |
changeset 51594 | dc79850e0254 |
parent 47216 | 71c04702a3d5 |
child 57916 | 97257da4ac8d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21805
diff
changeset
|
2 |
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package build.tools.jdwpgen; |
|
27 |
||
28 |
||
29 |
import java.util.*; |
|
30 |
import java.io.*; |
|
31 |
||
32 |
abstract class Node { |
|
33 |
||
34 |
String kind; |
|
35 |
List<Node> components; |
|
36 |
int lineno; |
|
10110 | 37 |
List<String> commentList = new ArrayList<>(); |
2 | 38 |
Node parent = null; |
3635
dfc746e20834
6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents:
2
diff
changeset
|
39 |
Context context = null; |
2 | 40 |
|
41 |
static final int maxStructIndent = 5; |
|
42 |
static int structIndent = 0; // horrible hack |
|
43 |
||
44 |
abstract void document(PrintWriter writer); |
|
45 |
||
46 |
void set(String kind, List<Node> components, int lineno) { |
|
47 |
this.kind = kind; |
|
48 |
this.components = components; |
|
49 |
this.lineno = lineno; |
|
50 |
} |
|
51 |
||
52 |
void parentAndExtractComments() { |
|
10110 | 53 |
for (Iterator<Node> it = components.iterator(); it.hasNext();) { |
54 |
Node node = it.next(); |
|
2 | 55 |
if (node instanceof CommentNode) { |
56 |
it.remove(); |
|
57 |
commentList.add(((CommentNode)node).text()); |
|
58 |
} else { |
|
59 |
node.parent = this; |
|
60 |
node.parentAndExtractComments(); |
|
61 |
} |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
void prune() { |
|
10110 | 66 |
for (Node node : components) { |
2 | 67 |
node.prune(); |
68 |
} |
|
69 |
} |
|
70 |
||
71 |
void constrain(Context ctx) { |
|
72 |
context = ctx; |
|
10110 | 73 |
for (Node node : components) { |
2 | 74 |
constrainComponent(ctx, node); |
75 |
} |
|
76 |
} |
|
77 |
||
78 |
void constrainComponent(Context ctx, Node node) { |
|
79 |
node.constrain(ctx); |
|
80 |
} |
|
81 |
||
82 |
void indent(PrintWriter writer, int depth) { |
|
3635
dfc746e20834
6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents:
2
diff
changeset
|
83 |
for (int i = 0; i < depth; i++) { |
2 | 84 |
writer.print(" "); |
85 |
} |
|
86 |
} |
|
87 |
||
88 |
void documentIndex(PrintWriter writer) { |
|
89 |
} |
|
90 |
||
91 |
void docRowStart(PrintWriter writer) { |
|
92 |
writer.println("<tr>"); |
|
93 |
if (structIndent > 0) { |
|
94 |
writer.println("<td colspan=" + structIndent + ">"); |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
String comment() { |
|
99 |
StringBuffer comment = new StringBuffer(); |
|
100 |
for (String st : commentList) { |
|
101 |
comment.append(st); |
|
102 |
} |
|
103 |
return comment.toString(); |
|
104 |
} |
|
105 |
||
106 |
void genJavaComment(PrintWriter writer, int depth) { |
|
107 |
if (commentList.size() > 0) { |
|
108 |
indent(writer, depth); |
|
109 |
writer.println("/**"); |
|
10110 | 110 |
for (String comment : commentList) { |
2 | 111 |
indent(writer, depth); |
10110 | 112 |
writer.println(" * " + comment); |
2 | 113 |
} |
114 |
indent(writer, depth); |
|
115 |
writer.println(" */"); |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
String javaType() { |
|
120 |
return "-- WRONG ---"; |
|
121 |
} |
|
122 |
||
123 |
void genJava(PrintWriter writer, int depth) { |
|
10110 | 124 |
for (Node node : components) { |
2 | 125 |
node.genJava(writer, depth); |
126 |
} |
|
127 |
} |
|
128 |
||
129 |
void genCInclude(PrintWriter writer) { |
|
10110 | 130 |
for (Node node : components) { |
2 | 131 |
node.genCInclude(writer); |
132 |
} |
|
133 |
} |
|
134 |
||
135 |
String debugValue(String label) { |
|
136 |
return label; |
|
137 |
} |
|
138 |
||
139 |
void genJavaDebugWrite(PrintWriter writer, int depth, |
|
140 |
String writeLabel) { |
|
141 |
genJavaDebugWrite(writer, depth, writeLabel, debugValue(writeLabel)); |
|
142 |
} |
|
143 |
||
144 |
void genJavaDebugWrite(PrintWriter writer, int depth, |
|
145 |
String writeLabel, String displayValue) { |
|
146 |
if (!Main.genDebug) { |
|
147 |
return; |
|
148 |
} |
|
149 |
indent(writer, depth); |
|
150 |
writer.println( |
|
151 |
"if ((ps.vm.traceFlags & VirtualMachineImpl.TRACE_SENDS) != 0) {"); |
|
152 |
indent(writer, depth+1); |
|
153 |
writer.print("ps.vm.printTrace(\"Sending: "); |
|
154 |
indent(writer, depth); // this is inside the quotes |
|
155 |
writer.print(writeLabel + "(" + javaType() + "): \" + "); |
|
156 |
writer.println(displayValue + ");"); |
|
157 |
indent(writer, depth); |
|
158 |
writer.println("}"); |
|
159 |
} |
|
160 |
||
161 |
public void genJavaRead(PrintWriter writer, int depth, |
|
162 |
String readLabel) { |
|
163 |
error("Internal - Should not call Node.genJavaRead()"); |
|
164 |
} |
|
165 |
||
166 |
void genJavaDebugRead(PrintWriter writer, int depth, |
|
167 |
String readLabel, String displayValue) { |
|
168 |
if (!Main.genDebug) { |
|
169 |
return; |
|
170 |
} |
|
171 |
indent(writer, depth); |
|
172 |
writer.println( |
|
173 |
"if (vm.traceReceives) {"); |
|
174 |
indent(writer, depth+1); |
|
175 |
writer.print("vm.printReceiveTrace(" + depth + ", \""); |
|
176 |
writer.print(readLabel + "(" + javaType() + "): \" + "); |
|
177 |
writer.println(displayValue + ");"); |
|
178 |
indent(writer, depth); |
|
179 |
writer.println("}"); |
|
180 |
} |
|
181 |
||
182 |
void genJavaPreDef(PrintWriter writer, int depth) { |
|
10110 | 183 |
for (Node node : components) { |
2 | 184 |
node.genJavaPreDef(writer, depth); |
185 |
} |
|
186 |
} |
|
187 |
||
188 |
void error(String errmsg) { |
|
189 |
System.err.println(); |
|
190 |
System.err.println(Main.specSource + ":" + lineno + ": " + |
|
191 |
kind + " - " + errmsg); |
|
192 |
System.err.println(); |
|
3635
dfc746e20834
6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents:
2
diff
changeset
|
193 |
throw new RuntimeException("Error: " + errmsg); |
2 | 194 |
} |
195 |
} |