Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilenio Quarti2012-07-23 21:45:30 -0400
committerSilenio Quarti2012-07-23 21:45:30 -0400
commitbb2eef651b26b2b9f80c89bd046829ffd5c3c314 (patch)
treeb7a005066ce87237a03cc246e31261e0c8a4ca98
parenta7e61736e1095cbe786bcaff8388454622dd1bc9 (diff)
downloadeclipse.platform.swt-steve/jnpi.tar.gz
eclipse.platform.swt-steve/jnpi.tar.xz
eclipse.platform.swt-steve/jnpi.zip
several fixes to MacGenerator toolsteve/jnpi
-rw-r--r--bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java6
-rw-r--r--bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java110
2 files changed, 105 insertions, 11 deletions
diff --git a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java
index d1a1989a1b..ce30ffbb6d 100644
--- a/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java
+++ b/bundles/org.eclipse.swt.tools/JNI Generation/org/eclipse/swt/tools/internal/StructsGenerator.java
@@ -220,7 +220,7 @@ void generateCacheFunction(JNIClass clazz) {
output(clazzName);
outputln("Fc.cached) return;");
JNIClass superclazz = clazz.getSuperclass();
- if (!superclazz.getName().equals("java.lang.Object")) {
+ if (!superclazz.getName().equals("java.lang.Object") && !superclazz.getName().endsWith(".struct")) {
String superName = superclazz.getSimpleName();
output("\tcache");
output(superName);
@@ -276,7 +276,7 @@ void generateGetFields(JNIClass clazz) {
JNIClass superclazz = clazz.getSuperclass();
String clazzName = clazz.getSimpleName();
String superName = superclazz.getSimpleName();
- if (!superclazz.getName().equals("java.lang.Object")) {
+ if (!superclazz.getName().equals("java.lang.Object") && !superclazz.getName().endsWith(".struct")) {
/* Windows exception - cannot call get/set function of super class in this case */
if (!(clazzName.equals(superName + "A") || clazzName.equals(superName + "W"))) {
output("\tget");
@@ -430,7 +430,7 @@ void generateSetFields(JNIClass clazz) {
JNIClass superclazz = clazz.getSuperclass();
String clazzName = clazz.getSimpleName();
String superName = superclazz.getSimpleName();
- if (!superclazz.getName().equals("java.lang.Object")) {
+ if (!superclazz.getName().equals("java.lang.Object") && !superclazz.getName().endsWith(".struct")) {
/* Windows exception - cannot call get/set function of super class in this case */
if (!(clazzName.equals(superName + "A") || clazzName.equals(superName + "W"))) {
output("\tset");
diff --git a/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java b/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java
index cee9a76550..cd2001981f 100644
--- a/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java
+++ b/bundles/org.eclipse.swt.tools/Mac Generation/org/eclipse/swt/tools/internal/MacGenerator.java
@@ -28,6 +28,8 @@ public class MacGenerator {
public static boolean BUILD_C_SOURCE = true;
public static boolean GENERATE_ALLOC = true;
public static boolean GENERATE_STRUCTS = false;
+ public static boolean CAST_ID = false;
+ public static boolean INTERN_OBJECTS = false;
public static boolean USE_SYSTEM_BRIDGE_FILES = false;
public MacGenerator() {
@@ -348,19 +350,66 @@ void generateMethods(String className, ArrayList methods) {
outln();
if (returnNode != null && isObject(returnNode)) {
if (!isStatic && returnType.equals(className)) {
- out("\treturn result == this.id ? this : (result != 0 ? new ");
- out(returnType);
- out("(result) : null);");
+ boolean generated = false;
+ if (CAST_ID) {
+ if (className.equals("id")) {
+ generated = true;
+ out("\treturn result == this.id ? this : (result != 0 ? new_id(result) : null);");
+ } else {
+ if (INTERN_OBJECTS) {
+ generated = true;
+ out("\treturn result == this.id ? this : (" + returnType + ")(result != 0 ? new");
+ out("_id(result, " + returnType + ".class) : null);");
+ }
+ }
+ }
+ if (!generated) {
+ out("\treturn result == this.id ? this : (result != 0 ? new ");
+ out(returnType);
+ out("(result) : null);");
+ }
} else {
- out("\treturn result != 0 ? new ");
NamedNodeMap attributes = returnNode.getAttributes();
Node swt_alloc = attributes.getNamedItem("swt_alloc");
if (swt_alloc != null && swt_alloc.getNodeValue().equals("true")) {
- out(className);
+ boolean generated = false;
+ if (CAST_ID) {
+ if (className.equals("id")) {
+ generated = true;
+ out("\treturn result != 0 ? new_id(result) : null);");
+ } else {
+ if (INTERN_OBJECTS) {
+ generated = true;
+ out("\treturn result != 0 ? (" + className + ") new");
+ out("_id(result, " + className + ".class) : null);");
+ }
+ }
+ }
+ if (!generated) {
+ out("\treturn result != 0 ? new ");
+ out(className);
+ out("(result) : null;");
+ }
} else {
- out(returnType);
+ boolean generated = false;
+ if (CAST_ID) {
+ if (className.equals("id")) {
+ generated = true;
+ out("\treturn result != 0 ? new_id(result) : null);");
+ } else {
+ if (INTERN_OBJECTS) {
+ generated = true;
+ out("\treturn result != 0 ? (" + returnType + ") new");
+ out("_id(result, " + returnType + ".class) : null;");
+ }
+ }
+ }
+ if (!generated) {
+ out("\treturn result != 0 ? new ");
+ out(returnType);
+ out("(result) : null;");
+ }
}
- out("(result) : null;");
}
outln();
} else if (returnNode != null && isStruct(returnNode)) {
@@ -378,6 +427,46 @@ void generateExtraFields(String className) {
out("\t");
out("public static int sizeof = OS." + className + "_sizeof();");
outln();
+ outln();
+ /* copyFrom method */
+ out("\t");
+ out("public void copyFrom(int /*long*/ ptr) {");
+ outln();
+ out("\t\tOS.memmove(this, ptr, sizeof);");
+ outln();
+ out("\t}");
+ outln();
+ outln();
+ /* copyTo method */
+ out("\t");
+ out("public void copyTo(int /*long*/ ptr) {");
+ outln();
+ out("\t\tOS.memmove(ptr, this, sizeof);");
+ outln();
+ out("\t}");
+ outln();
+ outln();
+ /* malloc method */
+ out("\t");
+ out("public int /*long*/ malloc() {");
+ outln();
+ out("\t\tint /*long*/ ptr = OS.malloc(sizeof);");
+ outln();
+ out("\t\tOS.memmove(ptr, this, sizeof);");
+ outln();
+ out("\t\treturn ptr;");
+ outln();
+ out("\t}");
+ outln();
+ outln();
+ /* sizeof method */
+ out("\t");
+ out("public int sizeof() {");
+ outln();
+ out("\t\treturn sizeof;");
+ outln();
+ out("\t}");
+ outln();
if ("CGSize".equals(className)) {
outln();
out("\tpublic String toString () {");
@@ -668,8 +757,11 @@ void generateStructs() {
out(";");
outln();
outln();
+ out("/** @jniclass flags=m */");
+ outln();
out("public class ");
out(className);
+ out(" extends struct");
out(" {");
outln();
generateFields(className, methods);
@@ -1405,7 +1497,9 @@ String buildSend(Node method, boolean tags, boolean only64, boolean superCall) {
String getCType (Node node) {
NamedNodeMap attributes = node.getAttributes();
- return attributes.getNamedItem("declared_type").getNodeValue();
+ String type = attributes.getNamedItem("declared_type").getNodeValue();
+ if ("CGFloat".equals(type)) return "float";
+ return type;
}
Node findNSObjectMethod(Node method) {

Back to the top