make/jdk/src/classes/build/tools/jdwpgen/Node.java
author lana
Mon, 19 Mar 2018 21:52:50 +0000
changeset 49266 778e4516409c
parent 47216 71c04702a3d5
child 57916 97257da4ac8d
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package build.tools.jdwpgen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
abstract class Node {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    String kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    List<Node> components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    int lineno;
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    37
    List<String> commentList = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    static final int maxStructIndent = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static int structIndent = 0; // horrible hack
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    abstract void document(PrintWriter writer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    void set(String kind, List<Node> components, int lineno) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        this.kind = kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        this.components = components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        this.lineno = lineno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    void parentAndExtractComments() {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    53
        for (Iterator<Node> it = components.iterator(); it.hasNext();) {
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    54
            Node node = it.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            if (node instanceof CommentNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                commentList.add(((CommentNode)node).text());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                node.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                node.parentAndExtractComments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    void prune() {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    66
        for (Node node : components) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            node.prune();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    void constrain(Context ctx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        context = ctx;
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
    73
        for (Node node : components) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            constrainComponent(ctx, node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    void constrainComponent(Context ctx, Node node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        node.constrain(ctx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            writer.print("    ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    void documentIndex(PrintWriter writer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    void docRowStart(PrintWriter writer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        writer.println("<tr>");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (structIndent > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            writer.println("<td colspan=" + structIndent + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    String comment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        StringBuffer comment = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        for (String st : commentList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            comment.append(st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return comment.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    void genJavaComment(PrintWriter writer, int depth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (commentList.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            indent(writer, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            writer.println("/**");
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   110
            for (String comment : commentList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                indent(writer, depth);
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   112
                writer.println(" * " + comment);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            indent(writer, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            writer.println(" */");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    String javaType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return "-- WRONG ---";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    void genJava(PrintWriter writer, int depth) {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   124
        for (Node node : components) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            node.genJava(writer, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    void genCInclude(PrintWriter writer) {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   130
        for (Node node : components) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            node.genCInclude(writer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    String debugValue(String label) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    void genJavaDebugWrite(PrintWriter writer, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                           String writeLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        genJavaDebugWrite(writer, depth, writeLabel, debugValue(writeLabel));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    void genJavaDebugWrite(PrintWriter writer, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                           String writeLabel, String displayValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (!Main.genDebug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        indent(writer, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        writer.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
          "if ((ps.vm.traceFlags & VirtualMachineImpl.TRACE_SENDS) != 0) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        indent(writer, depth+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        writer.print("ps.vm.printTrace(\"Sending: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        indent(writer, depth);  // this is inside the quotes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        writer.print(writeLabel + "(" + javaType() + "): \" + ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        writer.println(displayValue + ");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        indent(writer, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        writer.println("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public void genJavaRead(PrintWriter writer, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                            String readLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        error("Internal - Should not call Node.genJavaRead()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    void genJavaDebugRead(PrintWriter writer, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                          String readLabel, String displayValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (!Main.genDebug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        indent(writer, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        writer.println(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
          "if (vm.traceReceives) {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        indent(writer, depth+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        writer.print("vm.printReceiveTrace(" + depth + ", \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        writer.print(readLabel + "(" + javaType() + "): \" + ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        writer.println(displayValue + ");");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        indent(writer, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        writer.println("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    void genJavaPreDef(PrintWriter writer, int depth) {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   183
        for (Node node : components) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            node.genJavaPreDef(writer, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    void error(String errmsg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        System.err.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        System.err.println(Main.specSource + ":" + lineno + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                           kind + " - " + errmsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}