diff options
author | Kenneth Russel <[email protected]> | 2003-07-03 00:09:30 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2003-07-03 00:09:30 +0000 |
commit | 93d272a0525ec57aa3cd584f15cde6cf2a637e0c (patch) | |
tree | 3d6c9f2a305539d26c7449566bbb0d72bf74b12c /src/net/java/games/gluegen/JavaEmitter.java | |
parent | 37d90a0da397a1958fb101051170a60f871fb8cc (diff) |
Added pbuffer support to JOGL on X11; HWShadowmapsSimple and
ProceduralTexturePhysics demos are now working on Linux with the
appropriate hardware. Moved core GLX routines out of the public GLX
interface; this allowed XVisualInfo (and the new GLXFBConfig) to be
removed from the public API. Added support to GlueGen for returning
arrays of pointers as arrays of StructAccessors in Java and for
choosing the typedef name for a pointer-to-struct if the struct itself
does not have a typedef name. Added support to GLEmitter to emit
ProcAddressTables under arbitrary names and to support arbitrary
mechanisms for fetching those tables. Made GLU (on all platforms) and
GLX (on X11) be dynamically linked. Refactored ProcAddressTable
filling to be mostly shared code. Tested changes on Linux, Mac OS X
and Windows.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@17 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/gluegen/JavaEmitter.java')
-rw-r--r-- | src/net/java/games/gluegen/JavaEmitter.java | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/src/net/java/games/gluegen/JavaEmitter.java b/src/net/java/games/gluegen/JavaEmitter.java index 228b5aff2..26e2a4f23 100644 --- a/src/net/java/games/gluegen/JavaEmitter.java +++ b/src/net/java/games/gluegen/JavaEmitter.java @@ -451,18 +451,26 @@ public class JavaEmitter implements GlueEmitter { this.canonMap = canonMap; } - public void emitStruct(CompoundType structType) throws Exception { - if (structType.getName() == null) { + public void emitStruct(CompoundType structType, String alternateName) throws Exception { + String name = structType.getName(); + if (name == null && alternateName != null) { + name = alternateName; + } + + if (name == null) { System.err.println("WARNING: skipping emission of unnamed struct \"" + structType + "\""); return; } - if (cfg.shouldIgnore(structType.getName())) { + if (cfg.shouldIgnore(name)) { return; } Type containingCType = canonicalize(new PointerType(machDesc.pointerSizeInBytes(), structType, 0)); JavaType containingType = typeToJavaType(containingCType, false); + if (!containingType.isCompoundTypeWrapper()) { + return; + } String containingTypeName = containingType.getName(); boolean needsNativeCode = false; @@ -473,7 +481,7 @@ public class JavaEmitter implements GlueEmitter { } } - String structClassPkg = cfg.packageForStruct(structType.getName()); + String structClassPkg = cfg.packageForStruct(name); PrintWriter writer = null; PrintWriter cWriter = null; try @@ -534,7 +542,7 @@ public class JavaEmitter implements GlueEmitter { for (int i = 0; i < structType.getNumFields(); i++) { Field field = structType.getField(i); Type fieldType = field.getType(); - if (!cfg.shouldIgnore(structType.getName() + " " + field.getName())) { + if (!cfg.shouldIgnore(name + " " + field.getName())) { if (fieldType.isFunctionPointer()) { try { // Emit method call and associated native code @@ -566,7 +574,7 @@ public class JavaEmitter implements GlueEmitter { cWriter); cEmitter.emit(); } catch (Exception e) { - System.err.println("While processing field " + field + " of type " + structType.getName() + ":"); + System.err.println("While processing field " + field + " of type " + name + ":"); throw(e); } } else if (fieldType.isCompound()) { @@ -575,7 +583,7 @@ public class JavaEmitter implements GlueEmitter { // a name?) if (fieldType.getName() == null) { throw new RuntimeException("Anonymous structs as fields not supported yet (field \"" + - field + "\" in type \"" + structType.getName() + "\")"); + field + "\" in type \"" + name + "\")"); } writer.println(); @@ -586,7 +594,7 @@ public class JavaEmitter implements GlueEmitter { // FIXME: add setter by autogenerating "copyTo" for all compound type wrappers } else if (fieldType.isArray()) { - System.err.println("WARNING: Array fields (field \"" + field + "\" of type \"" + structType.getName() + + System.err.println("WARNING: Array fields (field \"" + field + "\" of type \"" + name + "\") not implemented yet"); } else { JavaType javaType = null; @@ -594,7 +602,7 @@ public class JavaEmitter implements GlueEmitter { javaType = typeToJavaType(fieldType, false); } catch (Exception e) { System.err.println("Error occurred while creating accessor for field \"" + - field.getName() + "\" in type \"" + structType.getName() + "\""); + field.getName() + "\" in type \"" + name + "\""); e.printStackTrace(); throw(e); } @@ -629,10 +637,6 @@ public class JavaEmitter implements GlueEmitter { writer.println(" }"); } else { // FIXME - String name = structType.getName(); - if (name == null) { - name = structType.toString(); - } System.err.println("WARNING: Complicated fields (field \"" + field + "\" of type \"" + name + "\") not implemented yet"); // throw new RuntimeException("Complicated fields (field \"" + field + "\" of type \"" + t + @@ -663,6 +667,7 @@ public class JavaEmitter implements GlueEmitter { String bindingJavaClassName, PrintWriter output) { MessageFormat returnValueCapacityFormat = null; + MessageFormat returnValueLengthFormat = null; JavaType javaReturnType = binding.getJavaReturnType(); if (javaReturnType.isNIOBuffer()) { // See whether capacity has been specified @@ -670,6 +675,12 @@ public class JavaEmitter implements GlueEmitter { if (capacity != null) { returnValueCapacityFormat = new MessageFormat(capacity); } + } else if (javaReturnType.isArray()) { + // See whether length has been specified + String len = cfg.returnValueLength(binding.getName()); + if (len != null) { + returnValueLengthFormat = new MessageFormat(len); + } } CMethodBindingEmitter cEmitter; if (doingImplRoutine) { @@ -686,6 +697,9 @@ public class JavaEmitter implements GlueEmitter { if (returnValueCapacityFormat != null) { cEmitter.setReturnValueCapacityExpression(returnValueCapacityFormat); } + if (returnValueLengthFormat != null) { + cEmitter.setReturnValueLengthExpression(returnValueLengthFormat); + } cEmitter.setTemporaryCVariableDeclarations(cfg.temporaryCVariableDeclarations(binding.getName())); cEmitter.setTemporaryCVariableAssignments(cfg.temporaryCVariableAssignments(binding.getName())); return cEmitter; @@ -758,12 +772,21 @@ public class JavaEmitter implements GlueEmitter { throw new RuntimeException("Arrays of compound types not handled yet"); } // Special cases for known JNI types (in particular for converting jawt.h) - if (cType.getName() != null && - cType.getName().equals("jobject")) { + if (t.getName() != null && + t.getName().equals("jobject")) { return javaType(java.lang.Object.class); } - return JavaType.createForCStruct(cfg.renameJavaType(targetType.getName())); + String name = targetType.getName(); + if (name == null) { + // Try containing pointer type for any typedefs + name = t.getName(); + if (name == null) { + throw new RuntimeException("Couldn't find a proper type name for pointer type " + t); + } + } + + return JavaType.createForCStruct(cfg.renameJavaType(name)); } else { throw new RuntimeException("Don't know how to convert pointer/array type \"" + t + "\""); @@ -775,15 +798,16 @@ public class JavaEmitter implements GlueEmitter { // Get the target type of the target type (targetType was computer earlier // as to be a pointer to the target type, so now we need to get its // target type) + Type bottomType; if (targetType.isPointer()) { // t is<type>**, targetType is <type>*, we need to get <type> - targetType = targetType.asPointer().getTargetType(); + bottomType = targetType.asPointer().getTargetType(); } else { // t is<type>[][], targetType is <type>[], we need to get <type> - targetType = targetType.asArray().getElementType(); + bottomType = targetType.asArray().getElementType(); } - if (targetType.isInt()) { - switch (targetType.getSize()) + if (bottomType.isInt()) { + switch (bottomType.getSize()) { case 1: return javaType(ArrayTypes.byteArrayArrayClass); // FIXME: handle 2,4,8-byte int types here @@ -793,10 +817,13 @@ public class JavaEmitter implements GlueEmitter { "Java type; Currently, the only supported depth=2 " + "pointer/array integer types are \"char**\" and \"char[][]\""); } + } else if (targetType.isPointer() && (targetType.pointerDepth() == 1)) { + // Array of pointers; convert as array of StructAccessors + return JavaType.createForCArray(targetType); } else { throw new RuntimeException( "Could not convert C type \"" + t + "\" " + - "to appropriate Java type; need to add support for " + + "to appropriate Java type; need to add more support for " + "depth=2 pointer/array types with non-integral target " + "types [debug info: targetType=\"" + targetType + "\"]"); } |