From 1bd34c035233034bd4184e9f1b053d873e7046d5 Mon Sep 17 00:00:00 2001 From: ishmal Date: Fri, 4 Apr 2008 20:01:35 +0000 Subject: [PATCH] Add native method stubbing utility --- src/bind/DomStub.java | 299 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 src/bind/DomStub.java diff --git a/src/bind/DomStub.java b/src/bind/DomStub.java new file mode 100644 index 000000000..df82e5012 --- /dev/null +++ b/src/bind/DomStub.java @@ -0,0 +1,299 @@ + +import java.io.*; +import java.util.HashMap; +import java.util.ArrayList; +import java.util.Collections; + + +/** + * This is not an actual java binding class. Rather, it is + * a simple tool for generating C++ native method stubs from classfiles + */ +public class DomStub +{ + +class MethodEntry +{ +ArrayList parms; +String name; +String type; + +public void addParam(String type) +{ + parms.add(type); +} + +public MethodEntry(String methodName, String type) +{ + this.name = methodName; + this.type = type; + parms = new ArrayList(); +} +} + + +class ClassEntry +{ +ArrayList methods; +String name; + +public void addMethod(MethodEntry method) +{ + methods.add(method); +} + +public ClassEntry(String className) +{ + this.name = className; + methods = new ArrayList(); +} +} + + +HashMap classes; + + +BufferedWriter out; + +void err(String msg) +{ + System.out.println("DomStub err:" + msg); +} + +void trace(String msg) +{ + System.out.println("DomStub:" + msg); +} + +void po(String msg) +{ + try + { + out.write(msg); + } + catch (IOException e) + { + } +} + + +//######################################################################## +//# G E N E R A T E +//######################################################################## + +void dumpClasses() +{ + for (ClassEntry ce : classes.values()) + { + trace("########################"); + trace("Class " + ce.name); + for (MethodEntry me : ce.methods) + { + trace(" " + me.type + " " + me.name); + for (String parm : me.parms) + { + trace(" " + parm); + } + } + } +} + + +void generateMethod(MethodEntry me) +{ + po("/**\n"); + po(" * Method : " + me.name + "\n"); + po(" */\n"); + for (String parm : me.parms) + { + po(" " + parm + "\n"); + } + +} + +void generateClass(ClassEntry ce) +{ + po("//################################################################\n"); + po("//## " + ce.name + "\n"); + po("//################################################################\n"); + + for (MethodEntry me : ce.methods) + generateMethod(me); + +} + + +void generate() +{ + ArrayList classNames = new ArrayList(classes.keySet()); + Collections.sort(classNames); + for (String key : classNames) + { + ClassEntry ce = classes.get(key); + generateClass(ce); + } +} + +//######################################################################## +//# P A R S E +//######################################################################## +boolean parseEntry(String className, String methodName, String signature) +{ + //trace("Decl :" + methodDecl); + //trace("params:" + params); + //################################# + //# Parse class and method lines + //################################# + String s = className.substring(14); + className = s.replace('_', '/'); + methodName = methodName.substring(14); + signature = signature.substring(14); + //trace("className : " + className); + //trace("methodName : " + methodName); + + int pos = signature.indexOf('('); + if (pos<0) + { + err("no opening ( for signature"); + return false; + } + pos++; + int p2 = signature.indexOf(')', pos); + if (p2<0) + { + err("no closing ) for signature"); + return false; + } + String parms = signature.substring(pos, p2); + String type = signature.substring(p2+1); + //################################# + //# create method entry. add to new or existing class + //################################# + MethodEntry method = new MethodEntry(methodName, type); + + ClassEntry clazz = classes.get(className); + if (clazz == null) + { + clazz = new ClassEntry(className); + classes.put(className, clazz); + } + clazz.addMethod(method); + + //################################# + //# Parse signature line + //################################# + + pos = 0; + int len = parms.length(); + while (pos(); +} + + + +public static void main(String argv[]) +{ + DomStub st = new DomStub(); + boolean ret = st.processFile("out.h"); +} + + +} \ No newline at end of file -- 2.30.2