netscape-revival
sun-java/classsrc/netscape/tools/jmc/ImplStubGen.java
// Copyright (c) 1995 Netscape Communications Corporation. All rights reserved.
package netscape.tools.jmc;
import netscape.tools.jmc.*;
import netscape.tools.jric.*;
import netscape.tools.ClassFileParser.*;
import java.io.*;
import java.util.Vector;
public abstract
class ImplStubGen extends JMCGenerator {
public ImplStubGen(netscape.tools.jmc.Main global, ClassDef clazz) {
super(global, clazz);
}
protected String getFileName() {
return "M" + getImplName() + ".c";
}
protected String getHeaderString() {
return clazz.name + " module C-language stub file\n * Generated by jmc";
}
protected void generateJumpTable(Vector interfaces, String prefix) throws IOException {
int i;
printBlockComment("Jump Table");
out.println("const " + clazzCName + "Interface "
+ getImplName() + "_interface = {");
out.println("\t(void*\t(*)(" + clazzCName + "* self, jint op, jint a))\n\t\t"
+ prefix + "_GetInterface,");
out.println("\t(void\t(*)(" + clazzCName + "* self, jint op))\n\t\t"
+ prefix + "_AddRef,");
out.println("\t(void\t(*)(" + clazzCName + "* self, jint op))\n\t\t"
+ prefix + "_Release,");
out.print("\t(const char**\t(*)(" + clazzCName + "* self, jint op))\n\t\t"
+ prefix + "_Description");
for (i = interfaces.size() - 1; i >= 0; i--) {
ClassDef intf = (ClassDef)interfaces.elementAt(i);
for (int j = 0; j < intf.methods.length; j++) {
MethodDef method = intf.methods[j];
out.print(",\n\t");
printMethodType(prefix, method, j);
}
}
out.println("\n};\n");
}
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\
void printMethodType(String prefix, MethodDef method, int methodIndex)
throws IOException {
if (method.isVararg()) {
printMethodType(prefix, method, methodIndex, VARARGS_ELIPSIS);
out.print(",\n\t");
printMethodType(prefix, method, methodIndex, VARARGS_VA_LIST);
out.print(",\n\t");
printMethodType(prefix, method, methodIndex, VARARGS_ARRAY);
}
else
printMethodType(prefix, method, methodIndex, VARARGS_NONE);
}
protected abstract void printMethodType(String prefix, MethodDef method,
int methodIndex, byte varargsType)
throws IOException;
}