Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/jdwpgen/Node.java
32287 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package build.tools.jdwpgen;262728import java.util.*;29import java.io.*;3031abstract class Node {3233String kind;34List<Node> components;35int lineno;36List<String> commentList = new ArrayList<>();37Node parent = null;38Context context = null;3940static final int maxStructIndent = 5;41static int structIndent = 0; // horrible hack4243abstract void document(PrintWriter writer);4445void set(String kind, List<Node> components, int lineno) {46this.kind = kind;47this.components = components;48this.lineno = lineno;49}5051void parentAndExtractComments() {52for (Iterator<Node> it = components.iterator(); it.hasNext();) {53Node node = it.next();54if (node instanceof CommentNode) {55it.remove();56commentList.add(((CommentNode)node).text());57} else {58node.parent = this;59node.parentAndExtractComments();60}61}62}6364void prune() {65for (Node node : components) {66node.prune();67}68}6970void constrain(Context ctx) {71context = ctx;72for (Node node : components) {73constrainComponent(ctx, node);74}75}7677void constrainComponent(Context ctx, Node node) {78node.constrain(ctx);79}8081void indent(PrintWriter writer, int depth) {82for (int i = 0; i < depth; i++) {83writer.print(" ");84}85}8687void documentIndex(PrintWriter writer) {88}8990void docRowStart(PrintWriter writer) {91writer.println("<tr>");92if (structIndent > 0) {93writer.println("<td colspan=" + structIndent + ">");94}95}9697String comment() {98StringBuffer comment = new StringBuffer();99for (String st : commentList) {100comment.append(st);101}102return comment.toString();103}104105void genJavaComment(PrintWriter writer, int depth) {106if (commentList.size() > 0) {107indent(writer, depth);108writer.println("/**");109for (String comment : commentList) {110indent(writer, depth);111writer.println(" * " + comment);112}113indent(writer, depth);114writer.println(" */");115}116}117118String javaType() {119return "-- WRONG ---";120}121122void genJava(PrintWriter writer, int depth) {123for (Node node : components) {124node.genJava(writer, depth);125}126}127128void genCInclude(PrintWriter writer) {129for (Node node : components) {130node.genCInclude(writer);131}132}133134String debugValue(String label) {135return label;136}137138void genJavaDebugWrite(PrintWriter writer, int depth,139String writeLabel) {140genJavaDebugWrite(writer, depth, writeLabel, debugValue(writeLabel));141}142143void genJavaDebugWrite(PrintWriter writer, int depth,144String writeLabel, String displayValue) {145if (!Main.genDebug) {146return;147}148indent(writer, depth);149writer.println(150"if ((ps.vm.traceFlags & VirtualMachineImpl.TRACE_SENDS) != 0) {");151indent(writer, depth+1);152writer.print("ps.vm.printTrace(\"Sending: ");153indent(writer, depth); // this is inside the quotes154writer.print(writeLabel + "(" + javaType() + "): \" + ");155writer.println(displayValue + ");");156indent(writer, depth);157writer.println("}");158}159160public void genJavaRead(PrintWriter writer, int depth,161String readLabel) {162error("Internal - Should not call Node.genJavaRead()");163}164165void genJavaDebugRead(PrintWriter writer, int depth,166String readLabel, String displayValue) {167if (!Main.genDebug) {168return;169}170indent(writer, depth);171writer.println(172"if (vm.traceReceives) {");173indent(writer, depth+1);174writer.print("vm.printReceiveTrace(" + depth + ", \"");175writer.print(readLabel + "(" + javaType() + "): \" + ");176writer.println(displayValue + ");");177indent(writer, depth);178writer.println("}");179}180181void genJavaPreDef(PrintWriter writer, int depth) {182for (Node node : components) {183node.genJavaPreDef(writer, depth);184}185}186187void error(String errmsg) {188System.err.println();189System.err.println(Main.specSource + ":" + lineno + ": " +190kind + " - " + errmsg);191System.err.println();192throw new RuntimeException("Error: " + errmsg);193}194}195196197