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 RepeatNode extends AbstractTypeNode {
032:
033: Node member;
034:
035: void constrain(Context ctx) {
036: super .constrain(ctx);
037: if (components.size() != 1) {
038: error("Repeat must have exactly one member, use Group for more");
039: }
040: member = (Node) (components.get(0));
041: if (!(member instanceof TypeNode)) {
042: error("Repeat member must be type specifier");
043: }
044: }
045:
046: void document(PrintWriter writer) {
047: docRowStart(writer);
048: writer.println("<td colspan="
049: + (maxStructIndent - structIndent) + ">");
050: writer.println("int<td><i>" + name + "</i><td>" + comment()
051: + " ");
052: docRowStart(writer);
053: writer.println("<td colspan="
054: + (maxStructIndent - structIndent + 2) + ">");
055: writer.println("Repeated <i>" + name + "</i> times:");
056: ++structIndent;
057: member.document(writer);
058: --structIndent;
059: }
060:
061: String docType() {
062: return "-BOGUS-"; // should never call this
063: }
064:
065: String javaType() {
066: return member.javaType() + "[]";
067: }
068:
069: public void genJavaWrite(PrintWriter writer, int depth,
070: String writeLabel) {
071: genJavaDebugWrite(writer, depth, writeLabel, "\"\"");
072: indent(writer, depth);
073: writer.println("ps.writeInt(" + writeLabel + ".length);");
074: indent(writer, depth);
075: writer.println("for (int i = 0; i < " + writeLabel
076: + ".length; i++) {;");
077: ((TypeNode) member).genJavaWrite(writer, depth + 1, writeLabel
078: + "[i]");
079: indent(writer, depth);
080: writer.println("}");
081: }
082:
083: String javaRead() {
084: error("Internal - Should not call RepeatNode.javaRead()");
085: return "";
086: }
087:
088: public void genJavaRead(PrintWriter writer, int depth,
089: String readLabel) {
090: genJavaDebugRead(writer, depth, readLabel, "\"\"");
091: String cntLbl = readLabel + "Count";
092: indent(writer, depth);
093: writer.println("int " + cntLbl + " = ps.readInt();");
094: indent(writer, depth);
095: writer.println(readLabel + " = new " + member.javaType() + "["
096: + cntLbl + "];");
097: indent(writer, depth);
098: writer.println("for (int i = 0; i < " + cntLbl + "; i++) {;");
099: member.genJavaRead(writer, depth + 1, readLabel + "[i]");
100: indent(writer, depth);
101: writer.println("}");
102: }
103: }
|