aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/JavaEmitter.java
Commit message (Collapse)AuthorAgeFilesLines
* Bug 1481 - Hide [ArgumentIs]PascalString argument's lengthSven Gothel2023-12-021-37/+46
| | | | | | | | Native pascal strings shall be just treated as normal Java strings on the Java side. Hence drop the length parameter across generated API, i.e. - C Function bindings - Java Callbacks
* Bug 1450: Be more verbose w/ JavaEmitter comment lines for enums and ↵Sven Gothel2023-08-101-1/+1
| | | | defines, include native expression
* Minor cleanup (includes, spacing)Sven Gothel2023-08-051-1/+1
|
* Merge remote-tracking branch 'Mathieu_Fery/wip/test_case_callback_emission'Sven Gothel2023-08-041-31/+39
|\
| * wip(test_case): Example of test case for issue related of ↵Mathieu Féry2023-08-041-31/+39
| | | | | | | | | | | | 927bbc7160a812bb29c0e7120d4a3009bfb13bbf Almost done
* | Merge remote-tracking branch ↵Sven Gothel2023-08-041-2/+11
|\ \ | | | | | | | | | 'Mathieu_Fery/feature/prevent_callback_generation_if_setter_is_absent'
| * | feat(callbackGenerator): Prevent generation of CallBack interface if setter ↵Mathieu Féry2023-08-041-2/+11
| | | | | | | | | | | | related isn't present
* | | Merge remote-tracking branch ↵Sven Gothel2023-08-041-4/+15
|\ \ \ | | | | | | | | | | | | 'Mathieu_Fery/feat/array_accessor_with_getter_of_field_in_pascal_case'
| * | | feat(arrayAccessor): Allow to use ReturnedArrayLength with getter associated ↵Mathieu Féry2023-08-031-4/+15
| |/ / | | | | | | | | | with field with name in PascalCase or camelCase
* | / Revert "JavaCallback: Remove non-UserParam ↵Sven Gothel2023-08-041-2/+5
| |/ |/| | | | | | | | | JavaConfiguration.requiresJavaCallbackCode()" This reverts commit 927bbc7160a812bb29c0e7120d4a3009bfb13bbf.
* | JavaCallback: Remove non-UserParam JavaConfiguration.requiresJavaCallbackCode()Sven Gothel2023-08-041-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Method was encapsulated in commit d4e8ecc3b4f68b86d95ec951971a0fea20217988 and questioned whether it is required. The non-userParam callback case adds no additional code requirements. Both, callback with and without userParam shares same code path and the respective native static fields. Only that the non-userParam code path adds additional native static fields, but all code sections are produced in both cases. Passed all unit tests.
* | JavaEmitter.bindFunction(): Add JavaCallback userParam non-void case (i.e. ↵Sven Gothel2023-08-041-18/+28
| | | | | | | | | | | | | | | | | | 'String') Use case: String type as userParam, barely tested and not useful. However, let's pass through all cases in our code. Added LOG INFO for mapped types.
* | JavaEmitter: Encapsulate 'needsJavaCallbackCode' query in JavaConfiguration. ↵Sven Gothel2023-08-041-7/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | TBD: Is this even required? - needsIntermediateOperation -> needsJavaCallbackCode - Use JavaConfiguration.requiresJavaCallbackCode(..) TBD: Is this even required? As far as I see, the non-userParam callback case adds no additional code requirements. Both, callback with and without userParam shares same code path and the respective native static fields. Only that the non-userParam code path adds additional native static fields, but all code sections are produced in both cases.
* | Merge remote-tracking branch ↵Sven Gothel2023-08-021-4/+9
|\ \ | | | | | | | | | 'Mathieu_Fery/feature/java_callback_without_user_data' into pulled
| * | feat(callbackGenerator): Add basic management of callback without userDataMathieu Féry2023-07-311-4/+9
| |/
* / feat(generation): Add setter generation for not constant and not opaque ↵Mathieu Féry2023-07-311-0/+14
|/ | | | compound attribute
* GlueGen JavaCallback: Add optional custom 'Callback-UserParamClass` for ↵Sven Gothel2023-07-101-5/+17
| | | | non-compound `UserParam` types to have more clarity in resulting API
* GlueGen JavaCallback: Add capability to have UserParam as (part of) keySven Gothel2023-07-081-1/+1
| | | | | | | | | Resolves use case where UserParam reflects e.g. a context (AL_SOFT_events) and will be (part of) the key mapping. Implementation required an additional userParamID -> userParam mapping for default Object/ID usage. Added 2 test cases.
* GlueGen JavaCallback: Remove ambiguity: Config ↵Sven Gothel2023-07-061-20/+6
| | | | JavaCallbackDef/JavaCallbackKey: Always define both parameter indices; emitJavaStaticCallback(): Use cbFuncBinding and cbFuncKeyIndices from callback parameter to build key
* GlueGen: Add 'PascalString' string semantics (length + value-ptr), added ↵Sven Gothel2023-07-051-5/+14
| | | | | | | | | | | | | | | | | | | | | | | | | prelim code for JavaCallback use-case emitBodyMapCToJNIType() It is common in toolkit APIs that a string might not be passed as a 'nul' terminated (EOS) C string, but as a Pascal string with a given length argument. A C string is specied as ArgumentIsString alEventCallbackInject 3 while allowing multiple indices .. A Pascal string can be specified as ArgumentIsPascalString ALEVENTPROCSOFT 3 4 while allowing multiple indice-tuples for length and value .. The tuple consist of the length agrument-index first (usually an int) followed by the value argument-index (usually a 'char*'). +++ CMethodBindingEmitter.emitBodyMapCToJNIType(), where PascalString is implemented, is currently being used for - JNI return statement (no PascalString impact possible) - JavaCallback C type -> JNI type, PascalString impacting
* GlueGen JavaCallback/LibraryOnLoad: Always include the `libraryBasename` ↵Sven Gothel2023-07-051-2/+2
| | | | agnostic 'emitJNIEnvDecl()' (declaration) in JNI code; Detach the thread from the JVM if newly attach in callback!
* GlueGen JavaCallback: Revised: Static Java callback dispatcher, dropping ↵Sven Gothel2023-07-041-11/+25
| | | | | | | | | | | | | | | | | | | | | | | | | native heap, support Struct UserParam ... Implementation now generates a static Java callback dispatcher for each defined SetCallbackFunction, which gets invoked by the generated native static counterpart with all arguments required. The static callback utilizes its own synchronization for thread-safety and fetches the required data set stored at SetCallbackFunction to dispatch the call to the users' CallbackFunction. In case the callback has been removed already, the static callback simply bails out quietly. The native code does not create, release or manage heap memory and therefore is considered safe. +++ Further Struct Type UserParam are now supported including Heterogeneous UserParam mapping (read GlueGen_Mapping.*). +++ Cleaned up code by extracting all JavaCallback emitter code into JavaCallbackEmitter class in one place, leaving JavaMethodbindingEmitter and CMethodbindingEmitter mostly in their original stage (non-convoluted). In this regard, I had to refactor a few function, i.e. moving CMethodbindingEmitter.getJNIMangledArg(..) into JavaType.appendDescriptor(..) and JavaType.appendJNIDescriptor(..) while reusing the toJNIMethodDescriptor(..) conversion. Test4JavaCallback covers and passes all cases.
* GlueGen JavaCallback: Unify native 'T_JavaCallbackGlueData' typedef structcallback_jniuserparamproxySven Gothel2023-07-021-0/+3
|
* GlueGen Struct [18]: Drop redundant 'static get*ElemCount() { return 1 }` ↵Sven Gothel2023-07-021-2/+4
| | | | for: isPrimitive && !isPointer && staticElemCount && maxOneElement
* GlueGen JavaCallback: Only produce default 'Key' class if keys are used, ↵Sven Gothel2023-07-011-0/+5
| | | | | | | | | | | expose 'Key' to public and use it. Expose release*() and get*Keys() methods Further we use a dedicated lock Object used in the Java implementation. TODO: Native static callback dispatch code shall - (also) acquire the lock - handle case where the data has been released already to render this solution thread-safe and data-race free
* GlueGen JavaCallback: Resolve key mapping of callback and associated ↵Sven Gothel2023-06-301-22/+40
| | | | | | | | | | | | | | | | resources via 'JavaCallbackKey' config and custom `SetCallback-KeyClass` Updated unit test and doc accordingly. Unit tests handle OpenAL's AL_SOFT_callback_buffer and AL_SOFT_events. Tested global scope (no key, default) and 1 key (default) and 1 key (custom class). Added more query functions, which all only take the `SetCallbackFunction` key arguments as specified. Cleaned up JavaCallback* config class field naminig scheme. Added 'synchronized (..Map) { }' block in crucial `SetCallbackFunction`, rendering implementation thread safe.
* GlueGen JavaCallback: 1st Working Draft: Changed 'JavaCallbackDef' config, ↵Sven Gothel2023-06-291-55/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | added code generation incl. native to Java dispatch and resource management Tested via Test4JavaCallback.java (using test2.[hc]). Please read the GlueGen_Mapping.md as well as Test4JavaCallback.java . +++ Some implementation details: JavaConfiguration maps JavaCallbackDef to JavaCallback set-function and maintains a list. JavaCallbackDef itself holds all configured details. JavaConfiguration also maps JavaCallbackInfo to JavaCallback set-function. JavaCallbackInfo itself holds all compile time information, as produced by JavaEmitter.beginFunctions(..). This extends JavaCallbackDef and avoid repetetive computation for the callback-function-type and its MethodBinding, parameter indices for the callback interface and userParam, etc. CMethodBindingEmitter: Native callback to Java dispatch - The JavaCallback setter function creates a native 'UserParam' struct instance, which holds the callback-interface-jobject, its callback-jmethodID and the userParam-jobject for invocation of the actual JavaCallback interface method. - To produce the C-Type -> JNI-Type conversion, An internal CMethodBindingEmitter instance for the native-callback function binding is created inside the CMethodBindingEmitter of the callback setter method. It is being used to map the types to JNI within the generated native callback function, passed to the actual JavaCallback method. JavaMethodBindingEmitter: Native callback to Java dispatch - The JavaCallbacl setter passes the callback-interface-object, the userParam-object and the callback-method-signature (to have the native method retrieve the jmethodID). - It receives the native pointer of the native `UserParam` struct instance, which gets mapped to the userParam-object. (*TODO: Refine ownership + release*).
* GlueGen: Move [de]captializeString(..) JavaEmitter -> static in CodeGenUtilsSven Gothel2023-06-291-7/+7
|
* GlueGen LibraryOnLoad Config: Generate `JNI_OnLoad(..)` for dynamic and ↵Sven Gothel2023-06-291-1/+7
| | | | `JNI_OnLoad_<LibraryBasename>(..)` for static libraries and `JVMUtil_GetJNIEnv(..)` to resolve the `JNIEnv*` as used by JavaCallback
* GlueGen Struct [17]: Handle void pointers, i.e. `void*`, within a struct as ↵Sven Gothel2023-06-291-10/+5
| | | | | | `Opaque` configured pointer-types .. includes cross-ref'ed doc and unit test
* GlueGen JavaCallback: Move JavaCallback into JavaConfiguration, accessible ↵Sven Gothel2023-06-261-52/+31
| | | | across *Emitter (needed for CMethodEmitter as well); Add JavaCallback.methodSignature to be passed to native function later on to find the callback jmethodID
* GlueGen JavaCallback: Expose getJNIMethodDescriptor() for JNI mangled method ↵Sven Gothel2023-06-261-7/+11
| | | | names, used in CMethodBindingEmitter; Use JavaCallback's function-pointer-type capital-name as simple-class-name and its FQN for JNI resolution.
* GlueGen JavaCallback: Use new JavaType nature 'named-class', denoting the ↵Sven Gothel2023-06-261-1/+1
| | | | | | | | | | | | generated callback interface mapping the callback function. This passes the jobject for the callback function/interface and the userParam (from 'void*') down to the native implementation. TODO: Add specific native implementation for JavaCallback, wrapping the jobject's into a native struct as user-param and a universal C-function as the native callback to dispatch the call to the java method with known arguments.
* GlueGen JavaCallback: Add preliminary implementation (WIP): Produces proper ↵Sven Gothel2023-06-251-5/+134
| | | | | | interfaces, TODO implementation Note: JavaCallbackDef is commented out on test2.cfg example, since implementation is missing.
* JavaEmitter.generateArrayGetterSetterCode(): Place elemCountExpr null check ↵Sven Gothel2023-06-251-8/+7
| | | | where it could occur -> non-opaque, non-primitive array case
* GlueGen: Add JavaEmitter(JavaConfiguration) ctorSven Gothel2023-06-251-0/+5
|
* GlueGen: Rename GlueEmitter.getConfig{uration->}() and drop ↵Sven Gothel2023-06-251-10/+3
| | | | JavaEmitter.getConfig(), cleaning up API usage
* GlueGen Struct [16]: Add support for pointer-pointer and function-pointer valuesSven Gothel2023-06-231-173/+195
| | | | See documentation and unit test test2.h, Test2FuncPtr.java and Test3PtrStorage.java
* GlueGen: Type: Have get{Base,Target}Type() stop at isFunctionPointer(), ↵Sven Gothel2023-06-231-20/+8
| | | | | | | | | | 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.
* JavaEmitter.typeToJavaTypeImpl(): Add targetType in GlueGenException and ↵Sven Gothel2023-06-211-13/+15
| | | | remove '"' in message
* GlueGen Struct [15b]: FunctionPointer: Drop is<FuncName>Null() -> use ↵Sven Gothel2023-06-201-7/+2
| | | | get<FuncName>()
* GlueGen Struct [15]: Add FunctionPointer getter and setter support w/ ↵Sven Gothel2023-06-201-39/+84
| | | | documentation
* GlueGen Type: Use virt getTargetType() for ArrayType dropping ↵Sven Gothel2023-06-191-8/+8
| | | | getElementType(); Rename getBase{Elem ->}Type() to align with getTargetType()
* CustomJNICode: Fix/complete commit d7bc10d7ff0e3a30d74c4e4c439230f3983bcfb4: ↵Sven Gothel2023-06-181-0/+4
| | | | Add emitCustomJNICode(..) for JavaEmitter.endFunctions() not just structs and fix the JNI-c stub code
* Merge remote-tracking branch 'Mathieu_Fery/feature/add_customJNICode_directive'Sven Gothel2023-06-181-1/+19
|\
| * feat(jni): Add directive for dedicated JNI Code with CustomJNICodeMathieu Féry2023-06-161-1/+19
| |
* | GlueGen Struct [12]: Throw InternalError(..) for produced code-path where ↵Sven Gothel2023-06-181-0/+15
| | | | | | | | Ownership.Native _and_ native memory potentially gets replaced
* | GlueGen Struct [11]: Formalize Ownership (enum) and elaborate generated Java ↵Sven Gothel2023-06-181-120/+208
| | | | | | | | API-Doc
* | GlueGen Struct [10]: Don't skip primitive w/ platform dependent sized type ↵Sven Gothel2023-06-181-14/+7
| | | | | | | | | | | | | | | | | | | | in struct (like 'int') .. We already support platform dependent sizes like pointer etc, no reason to drop e.g. 'int'. Note: 'int' is also always 32bit of size within our current set of supported platforms, e.g. MachineDataInfo. Further fix and clarify primCElemFixedSize and primElemSizeExpr, only to be true and set if isPrimitive.
* | GlueGen Struct [9]: Fix regression which added a pointer referencing type ↵Sven Gothel2023-06-181-0/+8
| | | | | | | | 'void', i.e. exclude if !baseCElemType.hasSize() // like 'void*' -> 'void'