From 9e61409658358834c2ba26c69c3efcbb5755c128 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 23 Jun 2023 06:31:56 +0200 Subject: GlueGen: Type: Have get{Base,Target}Type() stop at isFunctionPointer(), enhance API doc; Add getArrayBaseOrPointerTargetType() and getTargetFunction() Added getArrayBaseOrPointerTargetType() returns getBaseType() for arrays or getTargetType() for pointer, i.e. stops traversing if an elementType is a pointer and returns the elementType as target-type. This resolves 'int* intPtrArray[10]', but also simplifies all cases of 'int** intPtrPtr' and 'int intPtr[10]' etc. Since get{Base,Target}Type() returns the functionPointer, getTargetFunction() allows to retrieve the actual target function type. --- src/java/com/jogamp/gluegen/JavaEmitter.java | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) (limited to 'src/java/com/jogamp/gluegen/JavaEmitter.java') diff --git a/src/java/com/jogamp/gluegen/JavaEmitter.java b/src/java/com/jogamp/gluegen/JavaEmitter.java index 0bf5725..110bf50 100644 --- a/src/java/com/jogamp/gluegen/JavaEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaEmitter.java @@ -983,7 +983,7 @@ public class JavaEmitter implements GlueEmitter { } generateOffsetAndSizeArrays(javaUnit, " ", fieldName, fieldType, field, null); } else if (fieldType.isArray()) { - final Type baseElementType = field.getType().asArray().getBaseType(); + final Type baseElementType = fieldType.getBaseType(); if( GlueGen.debug() ) { System.err.printf("SE.os.%02d: %s / %s, %s (%s)%n", (i+1), field, cfgFieldName1, fieldType.getDebugString(), "array"); System.err.printf("SE.os.%02d: baseType %s%n", (i+1), baseElementType.getDebugString()); @@ -1249,11 +1249,11 @@ public class JavaEmitter implements GlueEmitter { isArray = false; referencedType = null; relationship = "being"; - } else if( fieldType.pointerDepth() > 0 ) { + } else if( fieldType.isPointer() ) { isArray = true; referencedType = fieldType.getBaseType(); relationship = "referencing"; - } else if( fieldType.arrayDimension() > 0 ) { + } else if( fieldType.isArray() ) { isArray = true; referencedType = null; relationship = "being"; @@ -2390,14 +2390,8 @@ public class JavaEmitter implements GlueEmitter { if (info != null) { boolean isPointerPointer = false; if (cType.pointerDepth() > 0 || cType.arrayDimension() > 0) { - Type targetType; // target type - if (cType.isPointer()) { - // t is *, we need to get - targetType = cType.asPointer().getTargetType(); - } else { - // t is [], we need to get - targetType = cType.asArray().getBaseType(); - } + // t is `*`, `[]` or `[][]`, we need to get + final Type targetType = cType.getArrayBaseOrPointerTargetType(); if (cType.pointerDepth() == 2 || cType.arrayDimension() == 2) { // 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 @@ -2435,14 +2429,8 @@ public class JavaEmitter implements GlueEmitter { } else if (cType.isVoid()) { return javaType(Void.TYPE); } else if (cType.pointerDepth() > 0 || cType.arrayDimension() > 0) { - Type targetType; // target type - if (cType.isPointer()) { - // t is *, we need to get - targetType = cType.asPointer().getTargetType(); - } else { - // t is [], we need to get - targetType = cType.asArray().getBaseType(); - } + // [][] + final Type targetType = cType.getArrayBaseOrPointerTargetType(); // Handle Types of form pointer-to-type or array-of-type, like // char* or int[]; these are expanded out into Java primitive @@ -2521,7 +2509,7 @@ public class JavaEmitter implements GlueEmitter { return JavaType.forNIOPointerBufferClass(); } else if(targetType.isArray()) { // t is[][], targetType is [], we need to get - bottomType = targetType.asArray().getBaseType(); + bottomType = targetType.getBaseType(); if( GlueGen.debug() ) { LOG.log(INFO, cType.getASTLocusTag(), "typeToJavaType(ptr-ptr.array): {0}, targetType: {1}, bottomType: {2}", cType.getDebugString(), targetType.getDebugString(), bottomType.getDebugString()); -- cgit v1.2.3