001: /*
002: * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.jdwpgen;
027:
028: import java.util.*;
029: import java.io.*;
030:
031: class OutNode extends AbstractTypeListNode {
032:
033: String cmdName;
034:
035: void set(String kind, List<Node> components, int lineno) {
036: super .set(kind, components, lineno);
037: components.add(0, new NameNode("Out"));
038: }
039:
040: void constrain(Context ctx) {
041: super .constrain(ctx.commandWritingSubcontext());
042: CommandNode cmd = (CommandNode) parent;
043: cmdName = cmd.name;
044: }
045:
046: void genProcessMethod(PrintWriter writer, int depth) {
047: writer.println();
048: indent(writer, depth);
049: writer.print("static " + cmdName
050: + " process(VirtualMachineImpl vm");
051: for (Iterator it = components.iterator(); it.hasNext();) {
052: TypeNode tn = (TypeNode) it.next();
053: writer.println(", ");
054: indent(writer, depth + 5);
055: writer.print(tn.javaParam());
056: }
057: writer.println(")");
058: indent(writer, depth + 6);
059: writer.println("throws JDWPException {");
060: indent(writer, depth + 1);
061: writer.print("PacketStream ps = enqueueCommand(vm");
062: for (Iterator it = components.iterator(); it.hasNext();) {
063: TypeNode tn = (TypeNode) it.next();
064: writer.print(", ");
065: writer.print(tn.name());
066: }
067: writer.println(");");
068: indent(writer, depth + 1);
069: writer.println("return waitForReply(vm, ps);");
070: indent(writer, depth);
071: writer.println("}");
072: }
073:
074: void genEnqueueMethod(PrintWriter writer, int depth) {
075: writer.println();
076: indent(writer, depth);
077: writer
078: .print("static PacketStream enqueueCommand(VirtualMachineImpl vm");
079: for (Iterator it = components.iterator(); it.hasNext();) {
080: TypeNode tn = (TypeNode) it.next();
081: writer.println(", ");
082: indent(writer, depth + 5);
083: writer.print(tn.javaParam());
084: }
085: writer.println(") {");
086: indent(writer, depth + 1);
087: writer
088: .println("PacketStream ps = new PacketStream(vm, COMMAND_SET, COMMAND);");
089: if (Main.genDebug) {
090: indent(writer, depth + 1);
091: writer
092: .println("if ((vm.traceFlags & vm.TRACE_SENDS) != 0) {");
093: indent(writer, depth + 2);
094: writer
095: .print("vm.printTrace(\"Sending Command(id=\" + ps.pkt.id + \") ");
096: writer.print(parent.context.whereJava);
097: writer
098: .println("\"+(ps.pkt.flags!=0?\", FLAGS=\" + ps.pkt.flags:\"\"));");
099: indent(writer, depth + 1);
100: writer.println("}");
101: }
102: genJavaWrites(writer, depth + 1);
103: indent(writer, depth + 1);
104: writer.println("ps.send();");
105: indent(writer, depth + 1);
106: writer.println("return ps;");
107: indent(writer, depth);
108: writer.println("}");
109: }
110:
111: void genWaitMethod(PrintWriter writer, int depth) {
112: writer.println();
113: indent(writer, depth);
114: writer.println("static " + cmdName
115: + " waitForReply(VirtualMachineImpl vm, "
116: + "PacketStream ps)");
117: indent(writer, depth + 6);
118: writer.println("throws JDWPException {");
119: indent(writer, depth + 1);
120: writer.println("ps.waitForReply();");
121: indent(writer, depth + 1);
122: writer.println("return new " + cmdName + "(vm, ps);");
123: indent(writer, depth);
124: writer.println("}");
125: }
126:
127: void genJava(PrintWriter writer, int depth) {
128: genJavaPreDef(writer, depth);
129: super.genJava(writer, depth);
130: genProcessMethod(writer, depth);
131: genEnqueueMethod(writer, depth);
132: genWaitMethod(writer, depth);
133: }
134: }
|