41package com.jogamp.gluegen.procaddress;
43import com.jogamp.gluegen.CMethodBindingEmitter;
44import com.jogamp.gluegen.JavaType;
45import com.jogamp.gluegen.MethodBinding;
46import com.jogamp.gluegen.cgram.types.FunctionSymbol;
47import com.jogamp.gluegen.cgram.types.PointerType;
48import com.jogamp.gluegen.cgram.types.Type;
52 private boolean callThroughProcAddress;
53 private boolean hasProcAddrTypedef;
55 private String localTypedefCallingConvention;
61 final boolean callThroughProcAddress,
62 final boolean hasProcAddrTypedef,
63 final String localTypedefCallingConvention,
69 public String getImplName() {
70 if (callThroughProcAddress) {
71 return ProcAddressEmitter.WRAP_PREFIX + super.getImplName();
73 return super.getImplName();
77 methodToWrap.getUnit(),
78 methodToWrap.getJavaPackageName(),
79 methodToWrap.getJavaClassName(),
80 methodToWrap.getIsOverloadedBinding(),
81 methodToWrap.getIsJavaMethodStatic(),
83 methodToWrap.forIndirectBufferAndArrayImplementation(),
84 methodToWrap.getMachineDataInfo(),
87 if (methodToWrap.getReturnValueCapacityExpression() !=
null) {
90 if (methodToWrap.getReturnValueLengthExpression() !=
null) {
98 this.callThroughProcAddress = callThroughProcAddress;
99 this.hasProcAddrTypedef = hasProcAddrTypedef;
100 this.localTypedefCallingConvention = localTypedefCallingConvention;
101 this.emitter = emitter;
106 int numEmitted = super.appendArguments(buf);
107 if (callThroughProcAddress) {
108 if (numEmitted > 0) {
111 buf.append(procAddressJavaTypeName);
112 buf.append(
" procAddress");
120 if (callThroughProcAddress) {
131 final String funcPointerTypedefLocalName =
"_local_" + funcPointerTypedefBaseName;
132 final String funcPointerTypedefName;
133 if (hasProcAddrTypedef) {
134 funcPointerTypedefName = funcPointerTypedefBaseName;
136 funcPointerTypedefName = funcPointerTypedefLocalName;
140 unit.emit(
" typedef ");
141 unit.emit(funcPtrType.
toString(funcPointerTypedefLocalName, localTypedefCallingConvention));
145 unit.emit(funcPointerTypedefName);
147 unit.emit(getNativeName());
151 super.emitBodyVariableDeclarations();
156 super.emitBodyVariablePreCallSetup();
158 if (callThroughProcAddress) {
162 final String funcPointerTypedefLocalName =
"_local_" + funcPointerTypedefBaseName;
163 final String funcPointerTypedefName;
164 if (hasProcAddrTypedef) {
165 funcPointerTypedefName = funcPointerTypedefBaseName;
167 funcPointerTypedefName = funcPointerTypedefLocalName;
170 final String ptrVarName =
"ptr_" + getNativeName();
172 if (hasProcAddrTypedef) {
173 unit.emitln(
" // implicit type validation of "+funcPointerTypedefLocalName+
" -> "+funcPointerTypedefName);
176 unit.emit(ptrVarName);
178 unit.emit(funcPointerTypedefLocalName);
179 unit.emitln(
") (intptr_t) procAddress;");
181 unit.emitln(
" assert(" + ptrVarName +
" != NULL);");
187 if (!callThroughProcAddress) {
188 super.emitBodyCallCFunction();
195 final Type cReturnType = binding.getCReturnType();
197 if (!cReturnType.
isVoid()) {
201 unit.emit(
"_res = (");
202 unit.emit(cReturnType.
getCName(
false));
209 throw new IllegalStateException(
"Cannot call through function pointer because binding has containing type: " + mBinding);
213 unit.emit(
"(* ptr_");
214 unit.emit(getNativeName());
217 emitBodyPassCArguments();
224 final StringBuilder buf =
new StringBuilder(super.jniMangle(binding));
225 if (callThroughProcAddress && 0 <= buf.indexOf(
"__") ) {
228 return buf.toString();
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...
static final CommentEmitter defaultCommentEmitter
final void setReturnValueCapacityExpression(final MessageFormat expression)
If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper),...
final void setReturnValueLengthExpression(final MessageFormat expression)
If this function returns an array, sets the expression for the length of the returned array.
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...
void setCommentEmitter(final CommentEmitter cEmitter)
Set the object that will emit the comment for this function.
final MethodBinding getBinding()
JavaConfiguration getConfig()
Describes a java-side representation of a type that is used to represent the same data on both the Ja...
static StringBuilder appendJNIDescriptor(final StringBuilder res, final Class<?> c, final boolean useTrueType)
Appends the native (JNI) method-name descriptor corresponding to the given Class<?...
static JavaType createForClass(final Class<?> clazz)
Creates a JavaType corresponding to the given Java type.
String jniTypeName()
Returns the String corresponding to the JNI type for this type, or NULL if it can't be represented (i...
Represents the binding of a C function to a Java method.
boolean hasContainingType()
Indicates whether this MethodBinding is for a function pointer contained in a struct,...
Describes a function symbol, which includes the name and type.
FunctionType getType()
Returns the type of this function.
String toString()
Returns a string representation of this type.
final String getCName()
Returns the name of this type.
final boolean isVoid()
Indicates whether this is a VoidType.
void emitBodyVariablePreCallSetup()
Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the...
ProcAddressCMethodBindingEmitter(final CMethodBindingEmitter methodToWrap, final boolean callThroughProcAddress, final boolean hasProcAddrTypedef, final String localTypedefCallingConvention, final ProcAddressEmitter emitter)
String jniMangle(final MethodBinding binding)
void emitBodyVariableDeclarations()
int appendArguments(final StringBuilder buf)
Returns the number of arguments emitted.
void emitBodyCallCFunction()
A subclass of JavaEmitter that modifies the normal emission of C and Java code to allow dynamic looku...
String getFunctionPointerTypedefName(final FunctionSymbol sym)
Returns the name of the typedef for a pointer to the function represented by the argument as defined ...