java-gobject-introspection r142 - in trunk: src/org/gnome/gir/compiler src/org/gnome/gir/gobject stub-examples
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: java-gobject-introspection r142 - in trunk: src/org/gnome/gir/compiler src/org/gnome/gir/gobject stub-examples
- Date: Mon, 1 Dec 2008 03:20:32 +0000 (UTC)
Author: walters
Date: Mon Dec 1 03:20:31 2008
New Revision: 142
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=142&view=rev
Log:
Fix up enum mapping a bit to allow nonzero initial offsets
To be strictly correct we should go the full mapping, needs a bit
more tweaking for that.
Removed:
trunk/src/org/gnome/gir/gobject/IntegerEnum.java
Modified:
trunk/src/org/gnome/gir/compiler/CodeFactory.java
trunk/src/org/gnome/gir/gobject/EnumMapper.java
trunk/stub-examples/TestEnum.java
Modified: trunk/src/org/gnome/gir/compiler/CodeFactory.java
==============================================================================
--- trunk/src/org/gnome/gir/compiler/CodeFactory.java (original)
+++ trunk/src/org/gnome/gir/compiler/CodeFactory.java Mon Dec 1 03:20:31 2008
@@ -27,6 +27,7 @@
import static org.objectweb.asm.Opcodes.ICONST_0;
import static org.objectweb.asm.Opcodes.IFNULL;
import static org.objectweb.asm.Opcodes.ILOAD;
+import static org.objectweb.asm.Opcodes.IADD;
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
@@ -76,6 +77,7 @@
import org.gnome.gir.gobject.GenericGList;
import org.gnome.gir.gobject.GlibAPI;
import org.gnome.gir.gobject.GlibRuntime;
+import org.gnome.gir.gobject.NativeEnum;
import org.gnome.gir.gobject.NativeObject;
import org.gnome.gir.gobject.annotation.Return;
import org.gnome.gir.repository.ArgInfo;
@@ -116,6 +118,7 @@
import com.sun.jna.Callback;
import com.sun.jna.Function;
import com.sun.jna.NativeLibrary;
+import com.sun.jna.NativeMapped;
import com.sun.jna.Pointer;
import com.sun.jna.TypeMapper;
import com.sun.jna.ptr.PointerByReference;
@@ -224,7 +227,7 @@
ClassCompilation compilation = getCompilation(info);
compilation.writer.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER + ACC_ENUM, compilation.internalName,
"Ljava/lang/Enum<L" + compilation.internalName + ";>;", "java/lang/Enum",
- null);
+ new String[] { Type.getInternalName(NativeEnum.class) });
ValueInfo[] values = info.getValueInfo();
for (ValueInfo valueInfo : values) {
String name = NameMap.enumNameToUpper(info.getName(), valueInfo.getName());
@@ -260,8 +263,17 @@
mv.visitCode();
l0 = new Label();
mv.visitLabel(l0);
+ int offset = 0;
int i = 0;
for (ValueInfo valueInfo : values) {
+ /* This hack is for enums which start from a nonzero offset, say 1.
+ * Really, we should support arbitrary values for enums.
+ */
+ if (i == 0) {
+ offset = (int) valueInfo.getValue();
+ if (offset != 0)
+ logger.info("Nonzero enum offset " + offset + " for " + info);
+ }
String name = NameMap.enumNameToUpper(info.getName(), valueInfo.getName());
mv.visitTypeInsn(NEW, compilation.internalName);
mv.visitInsn(DUP);
@@ -349,26 +361,15 @@
mv.visitMaxs(0, 0);
mv.visitEnd();
- mv = compilation.writer.visitMethod(ACC_PUBLIC, "nativeType", "()Ljava/lang/Class;", "()Ljava/lang/Class<*>;", null);
- mv.visitCode();
- l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLdcInsn(Type.getType("Ljava/lang/Integer;"));
- mv.visitInsn(ARETURN);
- l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "Lorg/gnome/gir/compiler/TestEnum;", null, l0, l1, 0);
- mv.visitMaxs(0, 0);
- mv.visitEnd();
-
- mv = compilation.writer.visitMethod(ACC_PUBLIC, "toNative", "()Ljava/lang/Object;", null, null);
+ mv = compilation.writer.visitMethod(ACC_PUBLIC, "getNative", "()I", null, null);
mv.visitCode();
l0 = new Label();
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, compilation.internalName, "ordinal", "()I");
- mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
- mv.visitInsn(ARETURN);
+ mv.visitLdcInsn(offset);
+ mv.visitInsn(IADD);
+ mv.visitInsn(IRETURN);
l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "L" + compilation.internalName + ";", null, l0, l1, 0);
Modified: trunk/src/org/gnome/gir/gobject/EnumMapper.java
==============================================================================
--- trunk/src/org/gnome/gir/gobject/EnumMapper.java (original)
+++ trunk/src/org/gnome/gir/gobject/EnumMapper.java Mon Dec 1 03:20:31 2008
@@ -47,6 +47,8 @@
import java.util.EnumSet;
+import com.sun.jna.NativeMapped;
+
/**
* Maps to and from native int and an Enum value.
* @author wayne
@@ -58,7 +60,7 @@
}
public int intValue(Enum<?> value) {
- return value instanceof IntegerEnum ? ((IntegerEnum) value).intValue() : value.ordinal();
+ return value instanceof NativeEnum ? ((NativeEnum) value).getNative() : value.ordinal();
}
public <E extends Enum<E>> E valueOf(int value, Class<E> enumClass) {
//
@@ -66,17 +68,9 @@
// Storing the values in a Map might be faster, but by the time you deal
// with locking overhead, its hardly worth it for small enums.
//
- if (IntegerEnum.class.isAssignableFrom(enumClass)) {
- for (E e : EnumSet.allOf(enumClass)) {
- if (((IntegerEnum) e).intValue() == value) {
- return e;
- }
- }
- } else {
- for (E e : EnumSet.allOf(enumClass)) {
- if (e.ordinal() == value) {
- return e;
- }
+ for (E e : EnumSet.allOf(enumClass)) {
+ if (e.ordinal() == value) {
+ return e;
}
}
//
Modified: trunk/stub-examples/TestEnum.java
==============================================================================
--- trunk/stub-examples/TestEnum.java (original)
+++ trunk/stub-examples/TestEnum.java Mon Dec 1 03:20:31 2008
@@ -7,6 +7,8 @@
FOO,
BAR;
+ private static int offset = 1;
+
private TestEnum() {}
@Override
@@ -22,6 +24,6 @@
@Override
public Object toNative() {
- return Integer.valueOf(ordinal());
+ return Integer.valueOf(ordinal()+offset);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]