41package com.jogamp.gluegen;
43import static java.util.logging.Level.INFO;
45import java.io.PrintWriter;
46import java.text.MessageFormat;
49import com.jogamp.common.os.MachineDataInfo;
50import com.jogamp.gluegen.JavaConfiguration.JavaCallbackInfo;
51import com.jogamp.gluegen.Logging.LoggerIf;
52import com.jogamp.gluegen.cgram.types.ArrayType;
53import com.jogamp.gluegen.cgram.types.FunctionSymbol;
54import com.jogamp.gluegen.cgram.types.PointerType;
55import com.jogamp.gluegen.cgram.types.Type;
63 protected static final String
arrayRes =
"_array_res";
64 protected static final String
arrayIdx =
"_array_idx";
69 private final String packageName;
72 private final String className;
78 private final boolean isOverloadedBinding;
84 private final boolean isJavaMethodStatic;
93 private List<String> temporaryCVariableDeclarations;
99 private List<String> temporaryCVariableAssignments;
106 private MessageFormat returnValueCapacityExpression =
null;
112 private MessageFormat returnValueLengthExpression =
null;
129 final String javaPackageName,
130 final String javaClassName,
131 final boolean isOverloadedBinding,
132 final boolean isJavaMethodStatic,
142 assert(javaClassName !=
null);
143 assert(javaPackageName !=
null);
145 this.packageName = javaPackageName;
146 this.className = javaClassName;
147 this.isOverloadedBinding = isOverloadedBinding;
148 this.isJavaMethodStatic = isJavaMethodStatic;
155 if(
null != javaCallback ) {
158 unit, javaPackageName, javaClassName, isOverloadedBinding,
163 jcbFuncCMethodEmitter =
null;
164 javaCallbackEmitter =
null;
191 return returnValueCapacityExpression;
212 returnValueCapacityExpression = expression;
216 throw new IllegalArgumentException(
217 "Cannot specify return value capacity for a method that does not " +
218 "return java.nio.Buffer or a compound type wrapper: \"" +
binding +
"\"");
226 return returnValueLengthExpression;
245 returnValueLengthExpression = expression;
249 throw new IllegalArgumentException(
250 "Cannot specify return value length for a method that does not " +
251 "return an array: \"" +
binding +
"\"");
260 return temporaryCVariableDeclarations;
269 temporaryCVariableDeclarations = arg;
279 return temporaryCVariableAssignments;
288 temporaryCVariableAssignments = arg;
328 buf.append(
"JNIEXPORT ");
330 buf.append(
" JNICALL");
335 protected StringBuilder
appendName(
final StringBuilder buf) {
336 buf.append(System.lineSeparator());
339 if (isOverloadedBinding) {
360 buf.append(
"JNIEnv *env, ");
363 buf.append(
"jclass");
365 buf.append(
"jobject");
367 buf.append(
" _unused");
371 buf.append(
", jclass _clazzBuffers");
381 if (javaArgType.
isVoid()) {
403 buf.append(
", jintArray " +
408 if(
null != javaCallbackEmitter ) {
417 if(
null != javaCallbackEmitter ) {
429 if(
null != javaCallbackEmitter ) {
451 boolean emittedDataCopyTemps =
false;
462 final boolean needsDataCopy =
463 emitPointerDeclaration(type,
465 convName, javaArgName);
466 if (needsDataCopy && !emittedDataCopyTemps) {
478 emittedDataCopyTemps =
true;
498 if (!cReturnType.
isVoid()) {
516 }
else if (javaReturnType.
isArray()) {
521 final Class<?> componentType = javaReturnType.
getJavaClass().getComponentType();
522 if (componentType.isArray()) {
523 throw new RuntimeException(
"Multi-dimensional arrays not supported yet");
526 final String javaTypeName = componentType.getName();
527 final String javaArrayTypeName =
"j" + javaTypeName +
"Array";
540 if (temporaryCVariableDeclarations !=
null) {
541 for (
final String val : temporaryCVariableDeclarations) {
554 while (!type.
isInt() && !type.
isVoid() && (i < 2)) {
561 throw new IllegalArgumentException(
"Type " + type +
" should have been a pointer or array type");
571 throw new IllegalArgumentException(
"Type " + type +
" should have been a one- or two-dimensional integer pointer or array type");
574 throw new IllegalArgumentException(
"Type " + type +
" should have been a one- or two-dimensional pointer to char or short");
609 emitPointerConversion(
binding, javaArgType,
613 }
else if (javaArgType.
isArray() ||
618 unit.
emitln(
" if ( NULL != " + javaArgName +
" ) {");
621 String cArgTypeName = cArgType.
getCName();
625 if (!needsDataCopy) {
631 cArgTypeName =
"jstring *";
635 unit.
emit(
" (*env)->GetDirectBufferAddress(env, " + javaArgName +
") : ");
636 unit.
emit(
" (*env)->GetPrimitiveArrayCritical(env, " + javaArgName +
", NULL) );");
653 "Cannot copy data for ptr-to-ptr arg type \"" + cArgType.
getDebugString() +
658 unit.
emitln(
" /* Copy contents of " + javaArgName +
" into " + convName +
"_copy */");
661 final String arrayLenName =
"_tmpArrayLen";
664 unit.
emit(
" = (*env)->GetArrayLength(env, ");
669 final Type cArgElementType, cArgElementType2;
684 cArgElementType2 =
null;
689 }
else if( cArgType.
isArray() ) {
691 cArgElementType2 =
null;
693 cArgElementType =
null;
694 cArgElementType2 =
null;
700 "\"; currently only pointer- and array-types are supported. (error "+error+
"): "+
binding,
709 "Could not allocate buffer for copying data in argument \\\""+javaArgName+
"\\\"");
718 (
" _offsetHandle = (int *) (*env)->GetPrimitiveArrayCritical(env, " +
724 unit.
emitln(
" for (_copyIndex = 0; _copyIndex < "+arrayLenName+
"; ++_copyIndex) {");
727 unit.
emitln(
" /* get each element of the array argument \"" + javaArgName +
"\" */");
728 unit.
emit(
" _tmpObj = (*env)->GetObjectArrayElement(env, ");
739 emitGetStringChars(
"(jstring) _tmpObj",
740 convName+
"_copy[_copyIndex]",
746 emitGetDirectBufferAddress(
"_tmpObj",
748 convName +
"_copy[_copyIndex]",
750 "_offsetHandle[_copyIndex]",
true);
755 emitGetDirectBufferAddress(
"_tmpObj",
757 "("+convName +
"_copy + _copyIndex)",
761 if(
null == cArgElementType2 ) {
771 emitMalloc(convName+
"_copy[_copyIndex]",
774 "(*env)->GetArrayLength(env, _tmpObj)",
775 "Could not allocate buffer during copying of data in argument \\\""+javaArgName+
"\\\"");
779 "\"; need to add support for copying ptr-to-ptr-to-primitiveType subarrays: "+
binding,
788 (
" (*env)->ReleasePrimitiveArrayCritical(env, " +
790 ", _offsetHandle, JNI_ABORT);");
798 }
else if (javaArgType.
isString()) {
802 emitGetStringChars(javaArgName,
834 if (!needsDataCopy) {
838 final String modeFlag = cArgType.
isBaseTypeConst() ?
"JNI_ABORT" :
"0" ;
839 unit.
emit(
" (*env)->ReleasePrimitiveArrayCritical(env, " + javaArgName +
", " + convName +
", "+modeFlag+
");");
841 unit.
emitln(
" if ( NULL != " + javaArgName +
" ) {");
856 unit.
emitln(
" _tmpArrayLen = (*env)->GetArrayLength(env, " + javaArgName +
");");
857 unit.
emitln(
" for (_copyIndex = 0; _copyIndex < _tmpArrayLen; ++_copyIndex) {");
858 unit.
emitln(
" _tmpObj = (*env)->GetObjectArrayElement(env, " + javaArgName +
", _copyIndex);");
859 emitReturnDirectBufferAddress(
"_tmpObj",
861 "("+convName +
"_copy + _copyIndex)",
867 "Cannot clean up copied data for ptr-to-ptr arg type \"" + cArgType.
getDebugString() +
868 "\": support for cleaning up most non-const ptr-to-ptr types not implemented.",
873 unit.
emitln(
" /* Clean up " + convName +
"_copy */");
880 final String arrayLenName =
"_tmpArrayLen";
883 unit.
emit(
" = (*env)->GetArrayLength(env, ");
889 if (cArgPtrType ==
null) {
892 "\"; currently only pointer types supported.",
897 unit.
emitln(
" for (_copyIndex = 0; _copyIndex < " + arrayLenName +
"; ++_copyIndex) {");
900 unit.
emitln(
" /* free each element of " +convName +
"_copy */");
901 unit.
emit(
" _tmpObj = (*env)->GetObjectArrayElement(env, ");
906 unit.
emit(
" (*env)->ReleaseStringUTFChars(env, ");
909 unit.
emit(convName+
"_copy[_copyIndex]");
914 "\"; need to add support for cleaning up copied ptr-to-ptr-to-primitiveType subarrays",
928 }
else if (javaArgType.
isString()) {
929 unit.
emitln(
" if ( NULL != " + javaArgName +
" ) {");
932 unit.
emit(
" (*env)->ReleaseStringUTFChars(env, ");
955 if (javaArgType.
isVoid()) {
973 final boolean needsArrayOffset = !needsDataCopy && (
985 if( needsArrayOffset ) {
991 if ( needsDataCopy ) {
994 if( needsArrayOffset ) {
1002 if( !javaArgType.
isString() &&
null != javaCallbackEmitter ) {
1011 private boolean isCStructFunctionPointer =
false;
1019 isCStructFunctionPointer = v;
1030 if (!cReturnType.
isVoid()) {
1051 if (temporaryCVariableAssignments !=
null) {
1052 for (
final String val : temporaryCVariableAssignments) {
1073 final boolean isReturnVal;
1076 final String cArgName;
1083 isReturnVal =
false;
1088 final String javaArgName = cArgName +
"_jni";
1113 final String returnSizeOf;
1114 if ( isReturnVal && returnValueCapacityExpression !=
null ) {
1117 returnSizeOf =
"sizeof(" + cType.
getCName() +
")";
1119 unit.
emitln(
"JVMUtil_NewDirectByteBufferCopy(env, _clazzBuffers, &"+cArgName+
", "+returnSizeOf+
");");
1130 unit.emit (
" "+javaArgName+
" = (*env)->NewDirectByteBuffer(env, (void *)"+cArgName+
", ");
1133 if ( isReturnVal && returnValueCapacityExpression !=
null) {
1138 if ( 1 == cType.
pointerDepth() &&
null != cTargetType ) {
1140 if( !cTargetType.
isAnon() &&
1144 if ( cTargetType.
getSize() == null ) {
1146 "Error emitting code for compound type "+
1147 "for function \"" +
binding +
"\": " +
1148 "Structs to be emitted should have been laid out by this point " +
1149 "(type " + cTargetType.
getCName() +
" / " +
1166 }
else if( cTargetType.
isVoid() ) {
1179 final String wmsg =
"Assumed return size of equivalent C return type";
1183 "No capacity specified for java.nio.Buffer return " +
1188 unit.
emitln(
" * mode: "+mode+
", arg #"+argIdx);
1197 final String lenArgName;
1198 if( pascalString ) {
1206 if(
null != lenArgName ) {
1207 unit.
emitln(
" if (NULL == "+cArgName+
" || 0 >= "+lenArgName+
" ) {");
1213 if(
null != lenArgName ) {
1214 unit.
emitln(
" char* "+cArgName+
"_cstr = calloc("+lenArgName+
"+1, sizeof(char)); // PascalString -> Add EOS");
1215 unit.
emitln(
" memcpy("+cArgName+
"_cstr, "+cArgName+
", "+lenArgName+
");");
1217 unit.emit (
" "+javaArgName+
" = ");
1218 if(
null != lenArgName ) {
1219 unit.
emitln(
"(*env)->NewStringUTF(env, (const char *)"+cArgName+
"_cstr);");
1222 unit.
emitln(
"(*env)->NewStringUTF(env, (const char *)"+cArgName+
");");
1231 unit.
emitln(
" if (NULL == "+cArgName+
") { "+javaArgName+
" = NULL; } else {");
1232 if ( !isReturnVal || returnValueLengthExpression ==
null ) {
1233 throw new GlueGenException(
"Error while generating C code: No length specified for array returned from function for arg #" +
1243 ", (*env)->NewDirectByteBuffer(env, (void *)"+cArgName+
"[" +
arrayIdx +
"], sizeof(" + pointerType.
getCName() +
")));");
1247 }
else if (javaType.
isArray()) {
1254 ": array return values for non-char types not implemented yet.",
1288 final StringBuilder buf =
new StringBuilder();
1291 if(
null == javaCallbackEmitter ) {
1294 if(
null != javaCallbackEmitter ) {
1298 return buf.toString();
1342 final int[] intArrayType =
new int[0];
1343 c = intArrayType.getClass();
1356 final java.nio.ByteBuffer[] tmp =
new java.nio.ByteBuffer[0];
1370 private void emitOutOfMemoryCheck(
final String varName,
final String errorMessage) {
1371 unit.
emitln(
" if ( NULL == " + varName +
" ) {");
1372 unit.
emitln(
" (*env)->ThrowNew(env, (*env)->FindClass(env, \"java/lang/OutOfMemoryError\"),");
1374 unit.
emit(
" in native dispatcher for \\\"");
1385 private void emitMalloc(
final String targetVarName,
1386 final String elementTypeString,
1387 final boolean elementTypeIsConst,
1388 final String numElementsExpression,
1389 final String mallocFailureErrorString) {
1393 if(elementTypeIsConst) {
1403 emitOutOfMemoryCheck( targetVarName, mallocFailureErrorString);
1406 private void emitCalloc(
final String targetVarName,
1407 final String elementTypeString,
1408 final String numElementsExpression,
1409 final String mallocFailureErrorString) {
1420 emitOutOfMemoryCheck( targetVarName, mallocFailureErrorString);
1423 private void emitGetStringChars(
final String sourceVarName,
1424 final String receivingVarName,
1425 final boolean isUTF8,
1426 final boolean addLengthVar,
1427 final boolean emitElseClause) {
1428 unit.
emitln(
" if ( NULL != " + sourceVarName +
" ) {");
1430 if( addLengthVar ) {
1431 unit.
emit(
" "+receivingVarName+
"_len = (size_t) ");
1434 if( addLengthVar ) {
1435 unit.
emit(
" (*env)->GetStringUTFLength(env, ");
1441 unit.
emit(
" = (*env)->GetStringUTFChars(env, ");
1446 emitOutOfMemoryCheck( receivingVarName,
"Failed to get UTF-8 chars for argument \\\""+sourceVarName+
"\\\"");
1455 if( addLengthVar ) {
1456 unit.
emit(
" (*env)->GetStringLength(env, ");
1459 emitCalloc(receivingVarName,
1461 receivingVarName+
"_len + 1",
1462 "Could not allocate temporary buffer for copying string argument \\\""+sourceVarName+
"\\\"");
1464 emitCalloc(receivingVarName,
1466 "(*env)->GetStringLength(env, " + sourceVarName +
") + 1",
1467 "Could not allocate temporary buffer for copying string argument \\\""+sourceVarName+
"\\\"");
1469 unit.
emitln(
" (*env)->GetStringRegion(env, " + sourceVarName +
", 0, (*env)->GetStringLength(env, " + sourceVarName +
"), " + receivingVarName +
");");
1471 if( addLengthVar ) {
1473 unit.
emitln(
" "+receivingVarName+
"_len = 0;");
1476 if (emitElseClause) {
1487 private void emitGetDirectBufferAddress(
final String sourceVarName,
1488 final String receivingVarTypeString,
1489 final String receivingVarName,
1490 final boolean receivingIsPtrPtr,
1491 final String byteOffsetVarName,
final boolean emitElseClause) {
1492 unit.
emitln(
" if ( NULL != " + sourceVarName +
" ) {");
1495 if( receivingIsPtrPtr ) {
1496 unit.
emit(receivingVarName+
" = ("+receivingVarTypeString+
") (((char*) (*env)->GetDirectBufferAddress(env, "+sourceVarName+
"))");
1497 unit.
emitln(
" + " + ((byteOffsetVarName !=
null) ? byteOffsetVarName :
"0") +
");");
1500 unit.
emitln(
"memcpy((void *)"+receivingVarName+
", (*env)->GetDirectBufferAddress(env, "+sourceVarName+
"), sizeof("+receivingVarTypeString+
"));");
1503 if (emitElseClause) {
1507 if( receivingIsPtrPtr ) {
1511 unit.
emitln(
"memset((void *)"+receivingVarName+
", 0, sizeof("+receivingVarTypeString+
"));");
1518 private void emitReturnDirectBufferAddress(
final String sourceVarName,
1519 final String receivingVarTypeString,
1520 final String receivingVarName,
1521 final boolean receivingIsPtrPtr,
1522 final String byteOffsetVarName) {
1525 if( receivingIsPtrPtr ) {
1526 unit.
emit(
"(((char*) (*env)->GetDirectBufferAddress(env, "+sourceVarName+
"))");
1527 unit.
emitln(
" + " + ((byteOffsetVarName !=
null) ? byteOffsetVarName :
"0") +
") = "+receivingVarName+
";");
1528 throw new RuntimeException(
"incomplete implementation");
1531 unit.
emitln(
"memcpy((*env)->GetDirectBufferAddress(env, "+sourceVarName+
"), "+receivingVarName+
", sizeof("+receivingVarTypeString+
"));");
1540 private boolean emitPointerDeclaration(
final JavaType javaType,
1542 final String cVariableName,
1543 final String javaArgumentName) {
1544 String ptrTypeString =
null;
1545 boolean needsDataCopy =
false;
1551 if (javaType.isNIOBuffer()) {
1553 ptrTypeString = cType.getCName();
1554 }
else if (javaType.isArray() || javaType.isArrayOfCompoundTypeWrappers()) {
1556 if (javaType.isPrimitiveArray() ||
1557 javaType.isNIOBufferArray() ||
1558 javaType.isArrayOfCompoundTypeWrappers()) {
1559 ptrTypeString = cType.getCName();
1560 }
else if (!javaType.isStringArray()) {
1561 final Class<?> elementType = javaType.getJavaClass().getComponentType();
1562 if (elementType.isArray()) {
1563 final Class<?> subElementType = elementType.getComponentType();
1564 if (subElementType.isPrimitive()) {
1566 ptrTypeString = cType.getCName();
1570 throw new GlueGenException(
"Unsupported pointer type: \"" + cType.getDebugString() +
"\"", cType.getASTLocusTag());
1575 throw new GlueGenException(
"Unsupported pointer type: \"" + cType.getDebugString() +
"\"", cType.getASTLocusTag());
1579 ptrTypeString = cType.getCName();
1583 if (!needsDataCopy) {
1586 if( !cType.isPointer() && javaType.isCompoundTypeWrapper() ) {
1597 if (javaType.isStringArray()) {
1598 String cElementTypeName =
"char *";
1599 final PointerType cPtrType = cType.asPointer();
1600 if (cPtrType !=
null) {
1601 cElementTypeName = cPtrType.getTargetType().asPointer().getCName();
1603 if (cType.isBaseTypeConst()) {
1608 if (cType.isBaseTypeConst()) {
1615 unit.
emit(
"_copy = NULL; /* copy of data in ");
1617 unit.
emitln(
", laid out according to C memory model */");
1620 return needsDataCopy;
1623 private void emitPointerConversion(
final MethodBinding
binding,
1624 final JavaType type,
1626 final String incomingArgumentName,
1627 final String cVariableName,
1628 String byteOffsetVarName) {
1630 if (type.isCompoundTypeWrapper()) {
1631 byteOffsetVarName =
null;
1634 final String cVariableType;
1635 if( !cType.isPointer() && type.isCompoundTypeWrapper() ) {
1636 cVariableType = cType.getCName()+
" *";
1638 cVariableType = cType.getCName();
1640 emitGetDirectBufferAddress(incomingArgumentName,
1644 byteOffsetVarName,
false);
1656 return s +
"_is_nio";
1672 return argumentNames;
1676 return "_" + argName +
"_ptr";
1691 writer.println(
" Java->C glue code:");
1692 writer.print(
" * Java package: ");
1696 writer.print(
" * Java method: ");
1709 javaArgType.
getJavaClass().getComponentType().isArray());
Machine data description for alignment and size onle, see com.jogamp.gluegen.
C code unit (a generated C source file), covering multiple FunctionEmitter allowing to unify output,...
static final String NewDirectByteBufferCopyUnitCode
Emits the C-side component of the Java<->C JNI binding to its CodeUnit, see FunctionEmitter.
final void setTemporaryCVariableDeclarations(final List< String > arg)
Sets up a List of Strings containing declarations for temporary C variables to be assigned to after t...
int appendArguments(final StringBuilder buf)
Returns the number of arguments emitted.
void emitBodyUserVariableDeclarations()
Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in t...
final MachineDataInfo getMachineDataInfo()
Used for certain internal type size computations.
CMethodBindingEmitter(final MethodBinding binding, final CodeUnit unit, final String javaPackageName, final String javaClassName, final boolean isOverloadedBinding, final boolean isJavaMethodStatic, final boolean forImplementingMethodCall, final boolean forIndirectBufferAndArrayImplementation, final MachineDataInfo machDesc, final JavaConfiguration configuration)
Constructs an emitter for the specified binding, and sets a default comment emitter that will emit th...
void emitBodyVariablePostCallCleanup()
Code to clean up any variables that were declared in emitBodyVariableDeclarations(),...
int emitBodyPassCArguments()
Returns the number of arguments passed so calling code knows whether to print a comma.
static String cThisArgumentName()
final MessageFormat getReturnValueLengthExpression()
Get the expression for the length of the returned array.
StringBuilder appendName(final StringBuilder buf)
String jniMangle(final MethodBinding binding)
static final CommentEmitter defaultCommentEmitter
String isNIOArgName(final int i)
void emitBodyVariableDeclarations()
void emitBodyCallCFunction()
boolean javaArgTypeNeedsDataCopy(final JavaType javaArgType)
String[] argumentNameArray()
final List< String > getTemporaryCVariableDeclarations()
Returns the List of Strings containing declarations for temporary C variables to be assigned to after...
FunctionSymbol getCSymbol()
void emitBodyUserVariableAssignments()
Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the...
final MessageFormat getReturnValueCapacityExpression()
Get the expression for the capacity of the returned java.nio.Buffer.
final void setReturnValueCapacityExpression(final MessageFormat expression)
If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper),...
boolean forIndirectBufferAndArrayImplementation
void emitAdditionalCode()
String byteOffsetArgName(final int i)
boolean isUTF8Type(Type type)
Checks a type to see whether it is for a UTF-8 pointer type (i.e., "const char *",...
final boolean forIndirectBufferAndArrayImplementation()
Is this CMethodBindingEmitter implementing the case of an indirect buffer or array being passed down ...
final boolean getIsOverloadedBinding()
Is the Java<->C JNI binding for this emitter's MethodBinding one of several overloaded methods with t...
static final String arrayIdx
void emitBodyVariablePreCallSetup()
Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the...
static final String arrayResLength
static StringBuilder appendJNIMangledArgs(final MethodBinding binding, final boolean forIndirectBufferAndArrayImplementation, final StringBuilder buf)
Return the mangled JNI argument names of given binding.
final void setReturnValueLengthExpression(final MessageFormat expression)
If this function returns an array, sets the expression for the length of the returned array.
String getJavaClassName()
Get the name of the package in which the corresponding Java method resides.
String isNIOArgName(final String s)
static final String arrayRes
static final String STRING_CHARS_PREFIX
final boolean getIsJavaMethodStatic()
Is the Java side of the Java<->C JNI binding for this emitter's MethodBinding a static method?...
String byteOffsetArrayArgName(final int i)
void setIsCStructFunctionPointer(final boolean v)
If method originates from a struct, see MethodBinding#hasContainingType(), it can either purposed to ...
String getJavaPackageName()
Get the name of the class in which the corresponding Java method resides.
final List< String > getTemporaryCVariableAssignments()
Returns the List of Strings containing assignments for temporary C variables which are made after the...
String getInterfaceName()
StringBuilder appendReturnType(final StringBuilder buf)
boolean emitBodyMapCToJNIType(final int argIdx, final boolean addLocalVar)
Emit code, converting a C type into a java JNI-type.
boolean forImplementingMethodCall
String pointerConversionArgumentName(final String argName)
final void setTemporaryCVariableAssignments(final List< String > arg)
Sets up a List of Strings containing assignments for temporary C variables which are made after the u...
General code unit (a generated C or Java source file), covering multiple FunctionEmitter allowing to ...
boolean addTailCode(final String c)
Add a tail code to this unit.
void emit(final String s)
Generic function emitter to produce C (JNI) or Java code stubs to its CodeUnit, invoking a native fun...
void setCommentEmitter(final CommentEmitter cEmitter)
Set the object that will emit the comment for this function.
final JavaConfiguration cfg
final MethodBinding binding
final MethodBinding getBinding()
A generic exception for Jogamp errors used throughout the binding as a substitute for RuntimeExceptio...
void emitCAdditionalCode(final CodeUnit unit, final CMethodBindingEmitter jcbFuncCMethodEmitter)
Emit addition C code, i.e.
void appendCAdditionalJNIDescriptor(final StringBuilder buf)
void emitCSetFuncPreCall(final CodeUnit unit)
void emitCOptArgumentSuffix(final CodeUnit unit, final int argIdx)
int appendCAdditionalParameter(final StringBuilder buf)
JavaCallback compile time information, produced by JavaEmitter#beginFunctions(TypeDictionary,...
Parses and provides access to the contents of .cfg files for the JavaEmitter.
TypeInfo typeInfo(Type type)
If this type should be considered opaque, returns the TypeInfo describing the replacement type.
static String getJNIMethodNamePrefix(final String javaPackageName, final String javaClassName)
Returns the JNI method prefix consisting our of mangled package- and class-name.
static String jniMangle(final String name)
Mangle a class, package or function name for JNI usage, i.e.
Emits the Java-side component (interface and.or implementation) of the Java<->C JNI binding to its Co...
String byteOffsetArgName(final int i)
static String javaThisArgumentName()
Describes a java-side representation of a type that is used to represent the same data on both the Ja...
boolean isNIOBufferArray()
static StringBuilder appendJNIDescriptor(final StringBuilder res, final Class<?> c, final boolean useTrueType)
Appends the native (JNI) method-name descriptor corresponding to the given Class<?...
boolean isNIOByteBufferArray()
String getName()
Returns the Java type name corresponding to this type.
String getJNIMethodDesciptor()
Returns the native (JNI) method-name descriptor corresponding to this type, i.e.
boolean isCompoundTypeWrapper()
boolean isPrimitiveArray()
final PascalStringElem pascalStrElem
String jniTypeName()
Returns the String corresponding to the JNI type for this type, or NULL if it can't be represented (i...
boolean isPascalStrElem()
boolean isArrayOfCompoundTypeWrappers()
Class<?> getJavaClass()
Returns the Java Class corresponding to this type.
static LoggerIf getLogger()
Returns the root package logger.
Represents the binding of a C function to a Java method.
Type getCArgumentType(final int i)
String getArgumentName(final int i)
Returns either the argument name specified by the underlying FunctionSymbol or a fabricated argument ...
Type getContainingCType()
Retrieves the containing C type of this MethodBinding if it is for a function pointer contained in a ...
String getImplName()
Returns the FunctionSymbol's name for the implementation, which is the current aliased API name per d...
JavaType getContainingType()
Retrieves the containing type of this MethodBinding if it is for a function pointer contained in a st...
JavaType getJavaArgumentType(final int i)
JavaType getJavaReturnType()
String getInterfaceName()
Returns the FunctionSymbol's current aliased API name for the interface.
String getName()
Returns the FunctionSymbol's current aliased API name.
boolean hasContainingType()
Indicates whether this MethodBinding is for a function pointer contained in a struct,...
boolean isArgumentThisPointer(final int i)
Indicates whether the ith argument to this MethodBinding is actually a "this" pointer.
FunctionSymbol getCSymbol()
Returns the FunctionSymbol.
final boolean isReturnCompoundByValue()
String getNativeName()
Returns the FunctionSymbol's name for the native function which is the original C API name per defaul...
Represents an array type.
final Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced,...
int getNumFields()
Returns the number of fields in this type.
Describes a function symbol, which includes the name and type.
ASTLocusTag getASTLocusTag()
Returns this instance's ASTLocusTag, if available, otherwise returns null.
Type getReturnType()
Returns the return type of this function.
final Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced,...
final String getCName()
Returns the name of this type.
final boolean isArray()
Indicates whether this is an ArrayType.
final boolean isInt()
Indicates whether this is an IntType.
final boolean isVoid()
Indicates whether this is a VoidType.
final boolean isBaseTypeConst()
Checks the base type of pointer-to-pointer, pointer, array or plain for const-ness.
final ASTLocusTag getASTLocusTag()
Returns this instance's ASTLocusTag, if available, otherwise returns null.
Type getArrayBaseOrPointerTargetType()
Return getBaseType() if isArray() or returns getTargetType() otherwise.
Type getBaseType()
Helper method to returns the bottom-most element type of this type, i.e.
PointerType asPointer()
Casts this to a PointerType or returns null if not a PointerType.
int pointerDepth()
Helper method for determining how many pointer indirections this type represents (i....
Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced,...
boolean isPrimitive()
Indicates whether this type is a primitive type.
final SizeThunk getSize()
SizeThunk which computes size of this type in bytes.
final String getDebugString()
ArrayType asArray()
Casts this to an ArrayType or returns null if not an ArrayType.
final boolean isPointer()
Indicates whether this is a PointerType.
CompoundType asCompound()
Casts this to a CompoundType or returns null if not a CompoundType.
final boolean isCompound()
Indicates whether this is a CompoundType.
void warning(final String msg)
See Logger#warning(String).