FileDocCategorySizeDatePackage
CStubGenerator.javaAPI DocJ2ME CLDC 1.18059Wed Feb 05 15:56:02 GMT 2003runtime

CStubGenerator

public class CStubGenerator extends Object

Fields Summary
char
CDelim
String
exportPrefix
boolean
tracemode
String
outfileName
static final char
DIR_DELIM
static final char
INNER_DELIM
PrintStream
o
String
className
Constructors Summary
public CStubGenerator(boolean dotrace, PrintStream outfile)


          
    tracemode = dotrace;
    o = outfile;
    
Methods Summary
private voiddumpStubs(ClassInfo c)

    className = strsub( c.className, CDelim );
    if ( (c.methods == null) || (c.methods.length==0 ))
        return;
    prolog();
    MethodInfo t[] = c.methods;
    for ( int i = 0; i < t.length; i++ ){
        if ( (t[i].access&Const.ACC_NATIVE) != 0 )
        printStub( t[i] );
    }
    epilog();
    
private voidepilog()

    
voidfileProlog()

    o.println("/* DO NOT EDIT THIS FILE - it is machine generated */");
    o.println("#include <StubPreamble.h>");
    if ( tracemode ){
        o.println("#include <threads.h>\n");
        o.println("#ifndef ENTER_STUB");
        o.println("#define ENTER_STUB(n,fcn,fmt,s,p)\\");
        o.println("    printf(\"0x%08x: %s_%s(\" #fmt \"%s)\\n\", threadSelf(), n, fcn, s, p);");
        o.println("#endif");
        o.println("#ifndef EXIT_STUB");
        o.println("#define EXIT_STUB(n,f,fmt,r)\\");
        o.println("    printf(\"0x%08x: %s_%s returned \" #fmt \"\\n\", threadSelf(), n, f, r);");
        o.println("#define EXIT_VOID_STUB(n,f)\\");
        o.println("    printf(\"0x%08x: %s_%s returned\\n\", threadSelf(), n, f);");
        o.println("#endif");
    }
    
private booleanprintStub(MethodInfo m)

    if ( (m.access&Const.ACC_NATIVE) == 0 )
        return false; // we're here in error.
    String  mName    = strsub( m.name.string, CDelim );
    String  funcName = className+"_"+mName;
    String  stubName = "Java_"+funcName+"_stub";

    StubGenerator g = new StubGenerator( funcName, m.isStaticMember(), "void *", m.type.string, tracemode, mName );
    try {
        g.iterate_parameters();
        g.iterate_returntype();
    } catch ( DataFormatException e ){
        e.printStackTrace();
        return false;
    }

    o.println(exportPrefix+"stack_item *"+stubName+"(stack_item *_P_,struct execenv *_EE_) {");
    o.print( g.result );
    o.println("}");
    return true;
    
private voidprolog()

    o.println("/* Stubs for class "+className+" */");
    
static java.lang.Stringstrsub(java.lang.String src, char substitute)

    return src.replace( DIR_DELIM, substitute).replace(INNER_DELIM, substitute );
    
public synchronized voidwriteStubs(ClassInfo[] c, int nclasses, ClassnameFilterList nativeTypes)

    fileProlog();
    for ( int i = 0; i < nclasses; i++ ){
        String[] types = nativeTypes.getTypes( c[i].className );
        for ( int j = 0; j < types.length; ++j ) {
        String type = types[j];
        if ( type.substring(0, 3).equals("JDK") ){
            dumpStubs( c[i] );
            break;
        }
        }
    }