Package com.jogamp.gluegen
Class MethodBinding
- java.lang.Object
-
- com.jogamp.gluegen.MethodBinding
-
public class MethodBinding extends Object
Represents the binding of a C function to a Java method. Also used to represent calls through function pointers contained in structs.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
MethodBinding.ParameterConsumer
forEachParameter(ParameterConsumer)
Consumer
-
Constructor Summary
Constructors Constructor Description MethodBinding(FunctionSymbol sym, String delegationImplName, JavaType javaReturnType, List<JavaType> javaArgumentTypes, JavaType containingType, Type containingCType)
Constructor for calling a C function or a function pointer contained in a struct.MethodBinding(MethodBinding bindingToCopy)
Constructs a new MethodBinding that is an exact clone of the argument, including the java return type and java argument types.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addJavaArgumentType(JavaType type)
boolean
argumentsUseNIO()
Returns true if any of the outgoing arguments in the method's signature require conversion or checking due to the use of New I/O.void
clearThisPointer()
Clears any record of a this pointer for this MethodBinding.protected void
computeSignatureProperties()
Computes summary information about the method's C and Java signatures.boolean
equals(Object obj)
protected String
erasedTypeDescriptor(JavaType type, boolean eraseBufferAndArrayTypes, boolean skipBuffers)
void
findThisPointer()
Find the leftmost argument matching the type of the containing type (for function pointer MethodBindings) and record that as a "this" pointer, meaning that it does not need to be explicitly passed at the Java level.int
forEachParameter(MethodBinding.ParameterConsumer c)
String
getArgumentName(int i)
Returns either the argument name specified by the underlying FunctionSymbol or a fabricated argument name based on the position.Type
getCArgumentType(int i)
Type
getContainingCType()
Retrieves the containing C type of this MethodBinding if it is for a function pointer contained in a struct.JavaType
getContainingType()
Retrieves the containing type of this MethodBinding if it is for a function pointer contained in a struct.StringBuilder
getCParameterList(StringBuilder buf, boolean useTypedef, String callingConvention)
Returns the function parameter list, i.e.StringBuilder
getCParameterList(StringBuilder buf, boolean useTypedef, String callingConvention, List<Integer> exclude)
Returns the function parameter list, i.e.Type
getCReturnType()
FunctionSymbol
getCSymbol()
Returns theFunctionSymbol
.String
getDelegationImplName()
Theimplementation delegation
name, ornull
for no delegation.String
getDescriptor(boolean forImplementingMethodCall, boolean eraseBufferAndArrayTypes)
Returns a String containing the descriptor (signature in internal format) of this MethodBinding as it will be emitted.String
getImplName()
Returns theFunctionSymbol
's name for the implementation, which is the currentaliased
API name per default, or thedelegation
name.String
getInterfaceName()
Returns theFunctionSymbol
's currentaliased
API name for the interface.JavaType
getJavaArgumentType(int i)
StringBuilder
getJavaCallArgumentList(StringBuilder buf, List<Integer> exclude)
StringBuilder
getJavaCallSelectArguments(StringBuilder buf, List<Integer> include, boolean addTailSeparator)
StringBuilder
getJavaParameterList(StringBuilder buf)
Returns the function parameter list, i.e.StringBuilder
getJavaParameterList(StringBuilder buf, List<Integer> exclude)
Returns the function parameter list, i.e.JavaType
getJavaReturnType()
StringBuilder
getJavaSelectParameter(StringBuilder buf, List<Integer> include, boolean addTailSeparator)
Returns the function parameter list, i.e.String
getName()
Returns theFunctionSymbol
's currentaliased
API name.String
getNativeName()
Returns theFunctionSymbol
's name for the native function which is theoriginal
C API name per default, but may be overridden viasetNativeName(String)
.int
getNumArguments()
boolean
hasContainingType()
Indicates whether this MethodBinding is for a function pointer contained in a struct, or to access array- or pointer-data from a struct.int
hashCode()
boolean
isArgumentThisPointer(int i)
Indicates whether the ith argument to this MethodBinding is actually a "this" pointer.boolean
isReturnCompoundByValue()
boolean
needsNIOWrappingOrUnwrapping()
Returns true if the function needs NIO-related wrapping/unwrapping or conversion of various arguments.MethodBinding
replaceJavaArgumentType(int argumentNumber, JavaType newArgType)
Creates a new MethodBinding replacing the specified Java argument type with a new argument type.void
setJavaReturnType(JavaType type)
void
setNativeName(String s)
boolean
signatureCanUseIndirectNIO()
Returns true if it is possible for any of the outgoing arguments to be indirect NIO buffers.boolean
signatureUsesArraysOfCompoundTypeWrappers()
Returns true if the return type or any of the outgoing arguments in the method's signature use arrays of "compound type wrappers", or NIO-based wrappers for C data structures.boolean
signatureUsesCArrays()
Returns true if the return type or any of the outgoing arguments in the method's signature represent C arrays.boolean
signatureUsesCompoundTypeWrappers()
Returns true if the return type or any of the outgoing arguments in the method's signature use "compound type wrappers", or NIO-based wrappers for C data structures.boolean
signatureUsesCPrimitivePointers()
Returns true if the return type or any of the outgoing arguments in the method's signature represent C primitive pointers.boolean
signatureUsesCVoidPointers()
Returns true if the return type or any of the outgoing arguments in the method's signature represent C void* pointers.boolean
signatureUsesJavaPrimitiveArrays()
Returns true if the return type or any of the outgoing arguments in the method's signature represent Java primitive arrays.boolean
signatureUsesNIO()
Returns true if the return type or any of the outgoing arguments in the method's signature require conversion or checking due to the use of New I/O.String
toString()
Returns the signature of this binding.
-
-
-
Constructor Detail
-
MethodBinding
public MethodBinding(MethodBinding bindingToCopy)
Constructs a new MethodBinding that is an exact clone of the argument, including the java return type and java argument types. It's safe to modify this binding after construction.
-
MethodBinding
public MethodBinding(FunctionSymbol sym, String delegationImplName, JavaType javaReturnType, List<JavaType> javaArgumentTypes, JavaType containingType, Type containingCType)
Constructor for calling a C function or a function pointer contained in a struct.In case of the latter, a struct function pointer, the arguments
containingType
andcontainingCType
must not benull
!
-
-
Method Detail
-
setJavaReturnType
public void setJavaReturnType(JavaType type)
-
addJavaArgumentType
public void addJavaArgumentType(JavaType type)
-
getJavaReturnType
public JavaType getJavaReturnType()
-
getNumArguments
public int getNumArguments()
-
getJavaArgumentType
public JavaType getJavaArgumentType(int i)
-
getCReturnType
public Type getCReturnType()
-
getCArgumentType
public Type getCArgumentType(int i)
-
getCParameterList
public StringBuilder getCParameterList(StringBuilder buf, boolean useTypedef, String callingConvention)
Returns the function parameter list, i.e. a comma separated list of argument type and name.- Parameters:
buf
- StringBuilder instanceuseTypedef
- if true and type is typedef'ed, use its namecallingConvention
- optional calling-convention- Returns:
- given StringBuilder instance
-
getCParameterList
public StringBuilder getCParameterList(StringBuilder buf, boolean useTypedef, String callingConvention, List<Integer> exclude)
Returns the function parameter list, i.e. a comma separated list of argument type and name.- Parameters:
buf
- StringBuilder instanceuseTypedef
- if true and type is typedef'ed, use its namecallingConvention
- optional calling-conventionexclude
- optional list of excluded parameter indices- Returns:
- given StringBuilder instance
-
getJavaParameterList
public StringBuilder getJavaParameterList(StringBuilder buf)
Returns the function parameter list, i.e. a comma separated list of argument type and name.- Parameters:
buf
- StringBuilder instance- Returns:
- given StringBuilder instance
-
getJavaParameterList
public StringBuilder getJavaParameterList(StringBuilder buf, List<Integer> exclude)
Returns the function parameter list, i.e. a comma separated list of argument type and name.- Parameters:
buf
- StringBuilder instanceexclude
- optional list of excluded parameter indices- Returns:
- given StringBuilder instance
-
getJavaSelectParameter
public StringBuilder getJavaSelectParameter(StringBuilder buf, List<Integer> include, boolean addTailSeparator)
Returns the function parameter list, i.e. a comma separated list of argument type and name.- Parameters:
buf
- StringBuilder instanceinclude
- list of explicit included parameter indicesaddTailSeparator
- add a comma separator in the end if result is not empty- Returns:
- given StringBuilder instance
-
getJavaCallArgumentList
public StringBuilder getJavaCallArgumentList(StringBuilder buf, List<Integer> exclude)
-
getJavaCallSelectArguments
public StringBuilder getJavaCallSelectArguments(StringBuilder buf, List<Integer> include, boolean addTailSeparator)
-
forEachParameter
public int forEachParameter(MethodBinding.ParameterConsumer c)
-
isReturnCompoundByValue
public final boolean isReturnCompoundByValue()
-
getCSymbol
public FunctionSymbol getCSymbol()
Returns theFunctionSymbol
.
-
getArgumentName
public String getArgumentName(int i)
Returns either the argument name specified by the underlying FunctionSymbol or a fabricated argument name based on the position. Note that it is currently not guaranteed that there are no namespace clashes with these fabricated argument names.
-
getName
public String getName()
Returns theFunctionSymbol
's currentaliased
API name.
-
getDelegationImplName
public String getDelegationImplName()
Theimplementation delegation
name, ornull
for no delegation.- See Also:
getImplName()
-
getInterfaceName
public String getInterfaceName()
Returns theFunctionSymbol
's currentaliased
API name for the interface.
-
getImplName
public String getImplName()
Returns theFunctionSymbol
's name for the implementation, which is the currentaliased
API name per default, or thedelegation
name.- See Also:
getDelegationImplName()
-
getNativeName
public String getNativeName()
Returns theFunctionSymbol
's name for the native function which is theoriginal
C API name per default, but may be overridden viasetNativeName(String)
.
-
setNativeName
public void setNativeName(String s)
-
replaceJavaArgumentType
public MethodBinding replaceJavaArgumentType(int argumentNumber, JavaType newArgType)
Creates a new MethodBinding replacing the specified Java argument type with a new argument type. If argumentNumber is less than 0 then replaces the return type.
-
argumentsUseNIO
public boolean argumentsUseNIO()
Returns true if any of the outgoing arguments in the method's signature require conversion or checking due to the use of New I/O.
-
signatureUsesNIO
public boolean signatureUsesNIO()
Returns true if the return type or any of the outgoing arguments in the method's signature require conversion or checking due to the use of New I/O.
-
signatureCanUseIndirectNIO
public boolean signatureCanUseIndirectNIO()
Returns true if it is possible for any of the outgoing arguments to be indirect NIO buffers.
-
signatureUsesCompoundTypeWrappers
public boolean signatureUsesCompoundTypeWrappers()
Returns true if the return type or any of the outgoing arguments in the method's signature use "compound type wrappers", or NIO-based wrappers for C data structures.
-
signatureUsesArraysOfCompoundTypeWrappers
public boolean signatureUsesArraysOfCompoundTypeWrappers()
Returns true if the return type or any of the outgoing arguments in the method's signature use arrays of "compound type wrappers", or NIO-based wrappers for C data structures.
-
needsNIOWrappingOrUnwrapping
public boolean needsNIOWrappingOrUnwrapping()
Returns true if the function needs NIO-related wrapping/unwrapping or conversion of various arguments. Currently this returns the logical OR of signatureUsesNIO(), signatureUsesCompoundTypeWrappers() and signatureUsesArraysOfCompoundTypeWrappers().
-
signatureUsesCVoidPointers
public boolean signatureUsesCVoidPointers()
Returns true if the return type or any of the outgoing arguments in the method's signature represent C void* pointers.
-
signatureUsesCPrimitivePointers
public boolean signatureUsesCPrimitivePointers()
Returns true if the return type or any of the outgoing arguments in the method's signature represent C primitive pointers.
-
signatureUsesCArrays
public boolean signatureUsesCArrays()
Returns true if the return type or any of the outgoing arguments in the method's signature represent C arrays.
-
signatureUsesJavaPrimitiveArrays
public boolean signatureUsesJavaPrimitiveArrays()
Returns true if the return type or any of the outgoing arguments in the method's signature represent Java primitive arrays.
-
computeSignatureProperties
protected void computeSignatureProperties()
Computes summary information about the method's C and Java signatures.
-
hasContainingType
public boolean hasContainingType()
Indicates whether this MethodBinding is for a function pointer contained in a struct, or to access array- or pointer-data from a struct.The native calling convention, i.e. via a 'this' function pointer or by a static native function must be decided in the
JavaEmitter
handling structs and passed to theCMethodBindingEmitter.setIsCStructFunctionPointer(boolean)
.
-
getContainingType
public JavaType getContainingType()
Retrieves the containing type of this MethodBinding if it is for a function pointer contained in a struct.
-
getContainingCType
public Type getContainingCType()
Retrieves the containing C type of this MethodBinding if it is for a function pointer contained in a struct.
-
findThisPointer
public void findThisPointer()
Find the leftmost argument matching the type of the containing type (for function pointer MethodBindings) and record that as a "this" pointer, meaning that it does not need to be explicitly passed at the Java level.
-
clearThisPointer
public void clearThisPointer()
Clears any record of a this pointer for this MethodBinding.
-
isArgumentThisPointer
public boolean isArgumentThisPointer(int i)
Indicates whether the ith argument to this MethodBinding is actually a "this" pointer.
-
toString
public String toString()
Returns the signature of this binding.
-
getDescriptor
public String getDescriptor(boolean forImplementingMethodCall, boolean eraseBufferAndArrayTypes)
Returns a String containing the descriptor (signature in internal format) of this MethodBinding as it will be emitted. This is used to disambiguate between overloadings when manually specifying prologue and epilogue code, for example.
-
-