public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Break up jnixx.java.
@ 2008-05-02 17:27 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-05-02 17:27 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  af25ece64f0052558eafb2673a73c972b434ca2a (commit)
      from  f93291d2e47b362bbf2247ac41e5867d64a778f4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit af25ece64f0052558eafb2673a73c972b434ca2a
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri May 2 13:25:47 2008 -0400

    Break up jnixx.java.
    
    frysk-common/ChangeLog
    2008-05-02  Andrew Cagney  <cagney@redhat.com>
    
    	* Makefile.rules (JNIXX): Update; frysk.jnixx.jnixx refactored,
    	main in frysk.jnixx.Main.
    
    frysk-sys/frysk/jnixx/ChangeLog
    2008-05-02  Andrew Cagney  <cagney@redhat.com>
    
    	* jnixx.java: Refactor into ...
    	* Main.java: ... this; new.
    	* WalkClass.java: ... this; new.
    	* PrintDeclarations.java: ... this; new.
    	* PrintDefinitions.java: ... this; new.
    	* Printer.java: ... this; new.
    	* PrintNamespaces.java: ... this; new.

-----------------------------------------------------------------------

Summary of changes:
 frysk-common/ChangeLog                       |    3 +
 frysk-common/Makefile.rules                  |    2 +-
 frysk-sys/frysk/jnixx/ChangeLog              |    8 +
 frysk-sys/frysk/jnixx/ClassWalker.java       |   57 ++
 frysk-sys/frysk/jnixx/Main.java              |   96 ++++
 frysk-sys/frysk/jnixx/PrintDeclarations.java |  116 ++++
 frysk-sys/frysk/jnixx/PrintDefinitions.java  |  276 ++++++++++
 frysk-sys/frysk/jnixx/PrintNamespaces.java   |  114 ++++
 frysk-sys/frysk/jnixx/Printer.java           |  440 +++++++++++++++
 frysk-sys/frysk/jnixx/WalkClass.java         |   63 +++
 frysk-sys/frysk/jnixx/jnixx.java             |  744 --------------------------
 11 files changed, 1174 insertions(+), 745 deletions(-)
 create mode 100644 frysk-sys/frysk/jnixx/ClassWalker.java
 create mode 100644 frysk-sys/frysk/jnixx/Main.java
 create mode 100644 frysk-sys/frysk/jnixx/PrintDeclarations.java
 create mode 100644 frysk-sys/frysk/jnixx/PrintDefinitions.java
 create mode 100644 frysk-sys/frysk/jnixx/PrintNamespaces.java
 create mode 100644 frysk-sys/frysk/jnixx/Printer.java
 create mode 100644 frysk-sys/frysk/jnixx/WalkClass.java
 delete mode 100644 frysk-sys/frysk/jnixx/jnixx.java

First 500 lines of diff:
diff --git a/frysk-common/ChangeLog b/frysk-common/ChangeLog
index 84ebce5..ba5bcd8 100644
--- a/frysk-common/ChangeLog
+++ b/frysk-common/ChangeLog
@@ -1,5 +1,8 @@
 2008-05-02  Andrew Cagney  <cagney@redhat.com>
 
+	* Makefile.rules (JNIXX): Update; frysk.jnixx.jnixx refactored,
+	main in frysk.jnixx.Main.
+
 	* Makefile.rules (JNIXX): Update; frysk.jni renamed to
 	frysk.jnixx.
 
diff --git a/frysk-common/Makefile.rules b/frysk-common/Makefile.rules
index 224c4ad..5382b2a 100644
--- a/frysk-common/Makefile.rules
+++ b/frysk-common/Makefile.rules
@@ -402,7 +402,7 @@ JNIXX = \
 	echo "$$class $$suffix => $@" ; \
 	rm -f $@.tmp ; \
 	CLASSPATH=$(GEN_DIRNAME).jar:$(CLASSPATH) \
-	    $(JAVA) frysk.jnixx.jnixx $$class $$suffix \
+	    $(JAVA) frysk.jnixx.Main $$class $$suffix \
 		> $@.tmp ; \
 	mv $@.tmp $@
 %-jni.hxx: %.java
diff --git a/frysk-sys/frysk/jnixx/ChangeLog b/frysk-sys/frysk/jnixx/ChangeLog
index cc35afb..dc7e4d6 100644
--- a/frysk-sys/frysk/jnixx/ChangeLog
+++ b/frysk-sys/frysk/jnixx/ChangeLog
@@ -1,5 +1,13 @@
 2008-05-02  Andrew Cagney  <cagney@redhat.com>
 
+	* jnixx.java: Refactor into ...
+	* Main.java: ... this; new.
+	* WalkClass.java: ... this; new.
+	* PrintDeclarations.java: ... this; new.
+	* PrintDefinitions.java: ... this; new.
+	* Printer.java: ... this; new.
+	* PrintNamespaces.java: ... this; new.
+
 	* Rename directory to frysk/jnixx/
 
 	* jnixx.java: Generate constructors and field accessors.
diff --git a/frysk-sys/frysk/jnixx/ClassWalker.java b/frysk-sys/frysk/jnixx/ClassWalker.java
new file mode 100644
index 0000000..244b0bb
--- /dev/null
+++ b/frysk-sys/frysk/jnixx/ClassWalker.java
@@ -0,0 +1,57 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.jnixx;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
+
+interface ClassWalker {
+
+    /**
+     * Returns true to indicate the need to walk this classes
+     * internals.
+     */
+    boolean acceptClass(Class klass);
+    void acceptConstructor(Constructor constructor);
+    void acceptField(Field field);
+    void acceptMethod(Method method);
+
+}
diff --git a/frysk-sys/frysk/jnixx/Main.java b/frysk-sys/frysk/jnixx/Main.java
new file mode 100644
index 0000000..c030532
--- /dev/null
+++ b/frysk-sys/frysk/jnixx/Main.java
@@ -0,0 +1,96 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.jnixx;
+
+class Main {
+
+    private static void printHxxFile(Printer p, Class klass) {
+	String header = klass.getName().replaceAll("\\.", "_") + "_jni_hxx";
+	p.println("#ifndef " + header);
+	p.println("#define " + header);
+	p.println();
+	p.println("#include \"frysk/jnixx/xx.hxx\"");
+	WalkClass.visit(klass, new PrintNamespaces(p));
+	p.println();
+	Class parent = klass.getSuperclass();
+	if (parent != Object.class) {
+	    p.print("#include \"");
+	    p.printHeaderFileName(parent);
+	    p.print("\"");
+	    p.println();
+	}
+	p.print("struct ");
+	p.printQualifiedCxxName(klass);
+	if (parent == Object.class) {
+	    p.print(" : public __jobject");
+	} else if (parent != null) {
+	    p.print(" : public ");
+	    p.printQualifiedCxxName(parent);
+	}
+	p.println(" {");
+	WalkClass.visit(klass, new PrintDeclarations(p));
+	p.println();
+	p.println("};");
+	p.println();
+	p.println("#endif");
+    }
+
+    private static void printCxxFile(Printer p, Class klass) {
+	p.print("#include \"");
+	p.printHeaderFileName(klass);
+	p.println("\"");
+	WalkClass.visit(klass, new PrintDefinitions(p));
+    }
+
+    public static void main(String[] args) throws ClassNotFoundException {
+	if (args.length != 2) {
+	    throw new RuntimeException("Usage: jnixx <class-name>");
+	}
+
+	Class klass = Class.forName(args[0], false,
+				    Main.class.getClassLoader());
+	Printer p = new Printer();
+
+	if (args[1].equals("hxx"))
+	    printHxxFile(p, klass);
+	else
+	    printCxxFile(p, klass);
+    }
+}
diff --git a/frysk-sys/frysk/jnixx/PrintDeclarations.java b/frysk-sys/frysk/jnixx/PrintDeclarations.java
new file mode 100644
index 0000000..30f14d9
--- /dev/null
+++ b/frysk-sys/frysk/jnixx/PrintDeclarations.java
@@ -0,0 +1,116 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.jnixx;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
+class PrintDeclarations implements ClassWalker {
+
+    private final Printer p;
+    PrintDeclarations(Printer p) {
+	this.p = p;
+    }
+
+    public boolean acceptClass(Class klass) {
+	// Static get-class method - a class knows its own class.
+	p.println();
+	p.print("  public: static jclass Class(JNIEnv* env);");
+	return true;
+    }
+
+    public void acceptConstructor(Constructor constructor) {
+	p.println();
+	p.printModifiers(constructor);
+	p.print(" ");
+	p.printCxxType(constructor.getDeclaringClass());
+	p.print(" New(");
+	p.printFormalCxxParameters(constructor, false);
+	p.print(");");
+	p.println();
+    }
+
+    private void printCxxFieldAccessorDeclaration(Field field, boolean get) {
+	p.printModifiers(field);
+	if (get) {
+	    p.print(" ");
+	    p.printCxxType(field.getType());
+	    p.print(" Get");
+	} else {
+	    p.print(" void Set");
+	}
+	String name = field.getName();
+	p.print(Character.toUpperCase(name.charAt(0)));
+	p.print(name.substring(1));
+	p.print("(JNIEnv*");
+	if (!Modifier.isStatic(field.getModifiers())) {
+	    p.print(", ");
+	    p.printCxxType(field.getDeclaringClass());
+	}
+	if (!get) {
+	    p.print(", ");
+	    p.printCxxType(field.getType());
+	    p.print(" value");
+	}
+	p.println(");");
+    }
+
+    public void acceptField(Field field) {
+	printCxxFieldAccessorDeclaration(field, true);
+	if (!Modifier.isFinal(field.getModifiers())) {
+	    printCxxFieldAccessorDeclaration(field, false);
+	}
+    }
+
+    public void acceptMethod(Method method) {
+	p.println();
+	p.printModifiers(method);
+	p.print(" ");
+	p.printCxxType(method.getReturnType());
+	p.print(" ");
+	p.print(method.getName());
+	p.print("(");
+	p.printFormalCxxParameters(method, false);
+	p.print(");");
+	p.println();
+    }
+}
diff --git a/frysk-sys/frysk/jnixx/PrintDefinitions.java b/frysk-sys/frysk/jnixx/PrintDefinitions.java
new file mode 100644
index 0000000..42f6de6
--- /dev/null
+++ b/frysk-sys/frysk/jnixx/PrintDefinitions.java
@@ -0,0 +1,276 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.jnixx;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+
+class PrintDefinitions implements ClassWalker {
+
+    private final Printer p;
+    PrintDefinitions(Printer p) {
+	this.p = p;
+    }
+
+    public boolean acceptClass(Class klass) {
+	// The class, via reflection.
+	p.println();
+	p.println("static jclass _Class;");
+	p.println();
+	p.println("jclass");
+	p.printQualifiedCxxName(klass);
+	p.println("::Class(JNIEnv* env) {");
+	p.println("  if (_Class == NULL) {");
+	p.println("    _Class = findClass(env, \""
+		+ klass.getName().replace("\\.", "/") + "\");");
+	p.println("  }");
+	p.println("  return _Class;");
+	p.println("}");
+	return true;
+    }
+
+    public void acceptConstructor(Constructor constructor) {
+	p.println();
+	p.printCxxType(constructor.getDeclaringClass());
+	p.println();
+	p.printQualifiedCxxName(constructor);
+	p.print("(");
+	p.printFormalCxxParameters(constructor, true);
+	p.println(") {");
+	p.println("  static jmethodID id;");
+	p.println("  if (id == NULL)");
+	p.print("    id = getMethodID(env, Class(env), \"<init>\", \"(");
+	p.printJniSignature(constructor.getParameterTypes());
+	p.println(")V\");");
+	p.print("  ");
+	p.printCxxType(constructor.getDeclaringClass());
+	p.print(" object = (");
+	p.printCxxType(constructor.getDeclaringClass());
+	p.print(") env->NewObject(");
+	p.printActualJniParameters(constructor);
+	p.println(");");
+	p.println("  if (object == NULL)");
+	p.println("    throw jnixx_exception();");
+	p.println("  return object;");
+	p.println("}");
+    }
+
+    private void printCxxFieldAccessorDefinition(Field field, boolean get) {
+	p.println();
+	if (get) {
+	    p.printCxxType(field.getType());
+	    p.println();
+	} else { 
+	    p.println("void");
+	}
+	p.printQualifiedCxxName(field.getDeclaringClass());
+	p.print("::");
+	if (get) {
+	    p.print("Get");
+	} else {
+	    p.print("Set");
+	}
+	String name = field.getName();
+	p.print(Character.toUpperCase(name.charAt(0)));
+	p.print(name.substring(1));
+	p.print("(JNIEnv* env");
+	if (!Modifier.isStatic(field.getModifiers())) {
+	    p.print(", ");
+	    p.printCxxType(field.getDeclaringClass());
+	    p.print(" object");
+	}
+	if (!get) {
+	    p.print(", ");
+	    p.printCxxType(field.getType());
+	    p.print(" value");
+	}
+	p.println(") {");
+	p.println("  if (" + name + "ID == NULL) {");
+	p.print("    " + name + "ID = getFieldID(env, ");
+	if (Modifier.isStatic(field.getModifiers())) {
+	    p.print("Class(env)");
+	} else {
+	    p.print("object");
+	}
+	p.print(", \"" + name + "\"");
+	p.print(", \"");
+	p.printJniSignature(field.getType());
+	p.print("\"");
+	p.println(");");
+	p.println("  }");
+	if (get) {
+	    p.print("  return");
+	    if (!field.getType().isPrimitive()) {
+		p.print(" (");
+		p.printCxxType(field.getType());
+		p.print(")");
+	    }
+	    p.print(" env->Get");
+	} else {
+	    p.print("  env->Set");
+	}
+	if (Modifier.isStatic(field.getModifiers())) {
+	    p.print("Static");
+	}
+	p.printJniReturnTypeName(field.getType());
+	p.print("Field(");
+	if (Modifier.isStatic(field.getModifiers())) {
+	    p.print("_Class");
+	} else {
+	    p.print("object");
+	}
+	p.print(", " + name + "ID");
+	if (!get) {
+	    p.print(",");


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-05-02 17:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-02 17:27 [SCM] master: Break up jnixx.java cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).