Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/jdwpgen/SelectNode.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;2627import java.util.*;28import java.io.*;2930class SelectNode extends AbstractGroupNode implements TypeNode {3132AbstractSimpleTypeNode typeNode = null;3334void prune() {35super.prune();36Iterator<Node> it = components.iterator();3738if (it.hasNext()) {39Node typeNode = it.next();4041if (typeNode instanceof ByteTypeNode ||42typeNode instanceof IntTypeNode) {43this.typeNode = (AbstractSimpleTypeNode)typeNode;44it.remove();45} else {46error("Select must be based on 'int' or 'byte'");47}48} else {49error("empty");50}51}5253void constrain(Context ctx) {54super.constrain(ctx);55if (components.size() < 2) {56error("Select must have at least two options");57}58}5960void constrainComponent(Context ctx, Node node) {61node.constrain(ctx);62if (!(node instanceof AltNode)) {63error("Select must consist of selector followed by Alt items");64}65}6667void document(PrintWriter writer) {68typeNode.document(writer);69super.document(writer);70}7172String docType() {73// should never call this74error("Internal - called SelectNode.docType()");75return null;76}7778String commonBaseClass() {79return name() + "Common";80}8182private String commonVar() {83return " a" + commonBaseClass();84}8586void genJavaClassSpecifics(PrintWriter writer, int depth) {87indent(writer, depth);88writer.println("abstract static class " + commonBaseClass() + " {");89if (context.isWritingCommand()) {90indent(writer, depth+1);91writer.println("abstract void write(PacketStream ps);");92} else {93indent(writer, depth+1);94writer.println("abstract " + typeNode.javaParam() + "();");95}96indent(writer, depth);97writer.println("}");98typeNode.genJavaDeclaration(writer, depth);99indent(writer, depth);100writer.println(commonBaseClass() + commonVar() + ";");101super.genJavaClassSpecifics(writer, depth);102}103104void genJavaClassBodyComponents(PrintWriter writer, int depth) {105// don't naively include alt components106}107108void genJavaWritingClassBody(PrintWriter writer, int depth,109String className) {110writer.println();111indent(writer, depth);112writer.print(className + "(" + typeNode.javaParam() + ", ");113writer.print(commonBaseClass() + commonVar());114writer.println(") {");115indent(writer, depth+1);116writer.println("this." + typeNode.name() + " = " + typeNode.name() + ";");117indent(writer, depth+1);118writer.println("this." + commonVar() + " =" + commonVar() + ";");119indent(writer, depth);120writer.println("}");121}122123void genJavaWrites(PrintWriter writer, int depth) {124typeNode.genJavaWrite(writer, depth, typeNode.name());125indent(writer, depth);126writer.println(commonVar() + ".write(ps);");127}128129void genJavaReads(PrintWriter writer, int depth) {130typeNode.genJavaRead(writer, depth, typeNode.name());131indent(writer, depth);132writer.println("switch (" + typeNode.name() + ") {");133for (Node node : components) {134AltNode alt = (AltNode)node;135alt.genJavaReadsSelectCase(writer, depth+1, commonVar());136}137indent(writer, depth);138writer.println("}");139}140141public void genJavaDeclaration(PrintWriter writer, int depth) {142typeNode.genJavaDeclaration(writer, depth);143super.genJavaDeclaration(writer, depth);144}145146public String javaParam() {147return typeNode.javaParam() + ", " + name() + " a" + name();148}149}150151152