From 9ee44e1a289ecbac024662dd5a2ffc42e8add023 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 25 Jun 2014 10:16:01 +0200 Subject: Bug 1025 - GlueGen: Add accessor for compound fields of type array, pointer and string (code generation) Enhance compound access as delivered by Bug 1022, to also generate accessors (getter and setter) for array, pointer and string types. Allow configuration of array length either via their internal size (c-header) or config 'ReturnedArrayLength'. 'ReturnedArrayLength' allows specifying a java expression. Canonical field names of compounds are _now_ specified as follows for configuration entries: COMPOUND.FIELD e.g. StructA.fieldB Also allow configuration of pointer fields to be treated as referenced arrays via 'ReturnedArrayLength'. Further, allow specifying 'pointer fields' as String values via 'ReturnsString' configuration. ++++ Implementation details: - handle above described accessor features - enhance JavaDoc for generated accessors - generate native JNI compound and string accessor on demand - encapsule accessor code generation in their own methods - enhance exception messages - enhance type verbosity in debug mode - verbose debug output via GlueGen.debug() Tests: - Features covered by test1.[ch] and Test1p1JavaEmitter and Test1p2ProcAddressEmitter - Validated compilation and unit tests for modules: - joal - jogl (minor config changes req.) - jocl (minor config changes req.) --- .../gluegen/test/junit/generation/BaseClass.java | 467 ++++++++++++++++++++- .../test/junit/generation/Test1p1JavaEmitter.java | 16 + .../generation/Test1p2ProcAddressEmitter.java | 17 +- .../gluegen/test/junit/generation/test1-common.cfg | 42 +- .../jogamp/gluegen/test/junit/generation/test1.c | 110 +++++ .../jogamp/gluegen/test/junit/generation/test1.h | 78 +++- 6 files changed, 720 insertions(+), 10 deletions(-) (limited to 'src/junit/com/jogamp/gluegen') diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java index 3bfb5c4..fd64ba9 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseClass.java @@ -36,6 +36,7 @@ import com.jogamp.junit.util.JunitTracer; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.nio.LongBuffer; import java.util.Arrays; @@ -978,13 +979,28 @@ public class BaseClass extends JunitTracer { Assert.assertEquals(2, surface.getClipSize()); + TK_Dimension[] allclips = surface.getClips(0, new TK_Dimension[surface.getClipSize()]); + for(int i=0; i4*4 */ + { + Assert.assertEquals(4*4, model.getMat4x4ArrayLength()); + final FloatBuffer mat4x4 = model.getMat4x4(); + Assert.assertEquals(4*4, mat4x4.limit()); + for(int i=0; i<4; i++) { + final float[] vec4 = model.getMat4x4(i*4, new float[4]); + for(int j=0; j<4; j++) { + Assert.assertEquals(i*4+j, mat4x4.get(i*4+j), EPSILON); + Assert.assertEquals(i*4+j, vec4[j], EPSILON); + } + } + } + + // field: structArrayFixedLen + // field: CType['TK_Dimension *', size [fixed false, lnx64 48], [array*1]], with array length of 3 + { + final int size = model.getStructArrayFixedLenArrayLength(); + final TK_Dimension[] all = model.getStructArrayFixedLen(0, new TK_Dimension[size]); + for(int i=0; i4*4 */ + { + model.setMat4x4(0*4, new float[] { 11, 12, 13, 14 } ); + model.setMat4x4(1*4, new float[] { 21, 22, 23, 24 } ); + model.setMat4x4(2*4, new float[] { 31, 32, 33, 34 } ); + model.setMat4x4(3*4, new float[] { 41, 42, 43, 44 } ); + + Assert.assertEquals(4*4, model.getMat4x4ArrayLength()); + final FloatBuffer mat4x4 = model.getMat4x4(); + Assert.assertEquals(4*4, mat4x4.limit()); + for(int i=0; i<4; i++) { + final float[] vec4 = model.getMat4x4(i*4, new float[4]); + for(int j=0; j<4; j++) { + Assert.assertEquals((i+1)*10+(j+1), mat4x4.get(i*4+j), EPSILON); + Assert.assertEquals((i+1)*10+(j+1), vec4[j], EPSILON); + } + } + } + + // field: structArrayFixedLen + // field: CType['TK_Dimension *', size [fixed false, lnx64 48], [array*1]], with array length of 3 + { + final int size = model.getStructArrayFixedLenArrayLength(); + { + for(int i=0; iclips); free(surface->clips); // free(surface->engine); free(surface); @@ -578,3 +579,112 @@ MYAPI void MYAPIENTRY addByte(const char summands[2], char result[1]) { result[0] = summands[0] + summands[1]; } +MYAPI TK_ModelMutable * MYAPIENTRY createModelMutable() { + int i, j; + TK_ModelMutable * s = calloc(1, sizeof(TK_ModelMutable)); + + s->intxxArrayFixedLen[0]=1; + s->intxxArrayFixedLen[1]=2; + s->intxxArrayFixedLen[2]=3; + + s->intxxPointerCustomLen = calloc(3, sizeof(int)); + s->intxxPointerCustomLen[0] = 11; + s->intxxPointerCustomLen[1] = 12; + s->intxxPointerCustomLen[2] = 13; + s->intxxPointerCustomLenVal=3; + + s->int32ArrayFixedLen[0] = 21; + s->int32ArrayFixedLen[1] = 22; + s->int32ArrayFixedLen[2] = 23; + + s->int32ArrayOneElem[0] = 30; + + s->int32PointerCustomLen = calloc(3, sizeof(int)); + s->int32PointerCustomLen[0] = 31; + s->int32PointerCustomLen[1] = 32; + s->int32PointerCustomLen[2] = 33; + s->int32PointerCustomLenVal=3; + + s->int32PointerOneElem = calloc(1, sizeof(int)); + s->int32PointerOneElem[0] = 41; + + for(i=0; i<4; i++) { + for(j=0; j<4; j++) { + s->mat4x4[i][j] = i*4 + j; + } + } + + s->structArrayFixedLen[0].x = 51; + s->structArrayFixedLen[0].y = 52; + s->structArrayFixedLen[0].width = 53; + s->structArrayFixedLen[0].height = 54; + s->structArrayFixedLen[1].x = 61; + s->structArrayFixedLen[1].y = 62; + s->structArrayFixedLen[1].width = 63; + s->structArrayFixedLen[1].height = 64; + s->structArrayFixedLen[2].x = 71; + s->structArrayFixedLen[2].y = 72; + s->structArrayFixedLen[2].width = 73; + s->structArrayFixedLen[2].height = 74; + + s->structArrayOneElem[0].x = 81; + s->structArrayOneElem[0].y = 82; + s->structArrayOneElem[0].width = 83; + s->structArrayOneElem[0].height = 84; + + s->structPointerCustomLen = (TK_Dimension *) calloc(3, sizeof(TK_Dimension)); + s->structPointerCustomLen[0].x = 91; + s->structPointerCustomLen[0].y = 92; + s->structPointerCustomLen[0].width = 93; + s->structPointerCustomLen[0].height = 94; + s->structPointerCustomLen[1].x = 101; + s->structPointerCustomLen[1].y = 102; + s->structPointerCustomLen[1].width = 103; + s->structPointerCustomLen[1].height = 104; + s->structPointerCustomLen[2].x = 111; + s->structPointerCustomLen[2].y = 112; + s->structPointerCustomLen[2].width = 113; + s->structPointerCustomLen[2].height = 114; + s->structPointerCustomLenVal = 3; + + s->structPointerOneElem = (TK_Dimension *) calloc(1, sizeof(TK_Dimension)); + s->structPointerOneElem[0].x = 121; + s->structPointerOneElem[0].y = 122; + s->structPointerOneElem[0].width = 123; + s->structPointerOneElem[0].height = 124; + + s->ctx = (void *) 0x123456789abcdef0UL; + + strncpy(s->modelNameArrayFixedLen, "Hello Array", sizeof(s->modelNameArrayFixedLen)); + + s->modelNamePointerCString = calloc(13+1, sizeof(char)); + strncpy(s->modelNamePointerCString, "Hello CString", 13+1); + + s->modelNamePointerCustomLen = calloc(13+1, sizeof(char)); + strncpy(s->modelNamePointerCustomLen, "Hello Pointer", 13+1); + s->modelNamePointerCustomLenVal = 13+1; + + return s; +} + +MYAPI void MYAPIENTRY destroyModelMutable(TK_ModelMutable * s) { + assert(NULL!=s); + assert(NULL!=s->intxxPointerCustomLen); + assert(NULL!=s->int32PointerCustomLen); + assert(NULL!=s->int32PointerOneElem); + assert(NULL!=s->structPointerCustomLen); + free(s->intxxPointerCustomLen); + free(s->int32PointerCustomLen); + free(s->int32PointerOneElem); + free(s->structPointerCustomLen); + free(s->modelNamePointerCString); + free(s->modelNamePointerCustomLen); + free(s); +} + +MYAPI TK_ModelConst * MYAPIENTRY createModelConst() { + return (TK_ModelConst *)createModelMutable(); +} +MYAPI void MYAPIENTRY destroyModelConst(TK_ModelConst * s) { + destroyModelMutable((TK_ModelMutable *)s); +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h index 7343172..ebb41d3 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h @@ -183,15 +183,23 @@ typedef struct { TK_Context ctx; } TK_ContextWrapper; +struct _jobject; +typedef struct _jobject *jobject; +struct JNINativeInterface_; +typedef const struct JNINativeInterface_ *JNIEnv; + + typedef struct tk_Surface { TK_Context ctx; TK_ContextWrapper ctxWrapper; - // const TK_Engine * engine; TK_Engine engine; TK_Dimension bounds; int32_t clipSize; TK_Dimension * clips; TK_Dimension * (MYAPIENTRY *getClip) (struct tk_Surface * ds, int idx); + + jobject (MYAPIENTRY *GetComponent)(JNIEnv* env, void* platformInfo); + } TK_Surface; typedef struct { @@ -274,3 +282,71 @@ MYAPI void MYAPIENTRY intToRgba(int irgba, char rgbaSink[4]); MYAPI void MYAPIENTRY addInt(const int summands[2], int result[1]); MYAPI void MYAPIENTRY addByte(const char summands[2], char result[1]); +typedef struct { + const int intxxArrayFixedLen[3]; + + const int * intxxPointerCustomLen; + const int intxxPointerCustomLenVal; + + const int32_t int32ArrayFixedLen[3]; + const int32_t int32ArrayOneElem[1]; + + const int32_t * int32PointerCustomLen; + const int32_t int32PointerCustomLenVal; + + const int32_t * int32PointerOneElem; + + const float mat4x4[4][4]; + + const TK_Dimension structArrayFixedLen[3]; + const TK_Dimension structArrayOneElem[1]; + + const TK_Dimension * structPointerCustomLen; + const int32_t structPointerCustomLenVal; + const TK_Dimension * structPointerOneElem; + + const TK_Context ctx; + + const char modelNameArrayFixedLen[12]; /* 'Hello Array' len=11+1 */ + const char * modelNamePointerCString; /* 'Hello CString' len=13+1 */ + const char * modelNamePointerCustomLen; /* 'Hello Pointer' len=13+1 */ + const int modelNamePointerCustomLenVal; /* 13+1 */ + +} TK_ModelConst; + +typedef struct { + int intxxArrayFixedLen[3]; + + int * intxxPointerCustomLen; + int intxxPointerCustomLenVal; + + int32_t int32ArrayFixedLen[3]; + int32_t int32ArrayOneElem[1]; + + int32_t * int32PointerCustomLen; + int32_t int32PointerCustomLenVal; + + int32_t * int32PointerOneElem; + + float mat4x4[4][4]; + + TK_Dimension structArrayFixedLen[3]; + TK_Dimension structArrayOneElem[1]; + + TK_Dimension * structPointerCustomLen; + int32_t structPointerCustomLenVal; + TK_Dimension * structPointerOneElem; + + TK_Context ctx; + + char modelNameArrayFixedLen[12]; /* 'Hello Array' len=11+1 */ + const char * modelNamePointerCString; /* 'Hello CString' len=13+1 */ + char * modelNamePointerCustomLen; /* 'Hello Pointer' len=13+1 */ + int modelNamePointerCustomLenVal; /* 13+1 */ + +} TK_ModelMutable; + +MYAPI TK_ModelConst * MYAPIENTRY createModelConst(); +MYAPI void MYAPIENTRY destroyModelConst(TK_ModelConst * s); +MYAPI TK_ModelMutable * MYAPIENTRY createModelMutable(); +MYAPI void MYAPIENTRY destroyModelMutable(TK_ModelMutable * s); -- cgit v1.2.3