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