41package com.jogamp.gluegen;
43import com.jogamp.gluegen.cgram.types.FunctionSymbol;
44import com.jogamp.gluegen.cgram.types.FunctionType;
45import com.jogamp.gluegen.cgram.types.Type;
47import java.util.ArrayList;
57 private final String delegationImplName;
58 private final JavaType containingType;
59 private final Type containingCType;
60 private String nativeName;
62 private List<JavaType> javaArgumentTypes;
63 private boolean computedSignatureProperties;
64 private boolean argumentsUseNIO;
65 private boolean signatureUsesNIO;
66 private boolean signatureCanUseIndirectNIO;
67 private boolean signatureUsesCompoundTypeWrappers;
68 private boolean signatureUsesArraysOfCompoundTypeWrappers;
69 private boolean signatureUsesCVoidPointers;
70 private boolean signatureUsesCPrimitivePointers;
71 private boolean signatureUsesCArrays;
72 private boolean signatureUsesJavaPrimitiveArrays;
73 private int thisPointerIndex = -1;
81 this.sym = bindingToCopy.sym;
82 this.delegationImplName = bindingToCopy.delegationImplName;
83 this.containingType = bindingToCopy.containingType;
84 this.containingCType = bindingToCopy.containingCType;
86 this.nativeName = bindingToCopy.nativeName;
87 this.javaReturnType = bindingToCopy.javaReturnType;
88 this.javaArgumentTypes = (
null != bindingToCopy.javaArgumentTypes ) ?
new ArrayList<JavaType>(bindingToCopy.javaArgumentTypes) :
null;
89 this.computedSignatureProperties = bindingToCopy.computedSignatureProperties;
90 this.argumentsUseNIO = bindingToCopy.argumentsUseNIO;
91 this.signatureUsesNIO = bindingToCopy.signatureUsesNIO;
92 this.signatureCanUseIndirectNIO = bindingToCopy.signatureCanUseIndirectNIO;
93 this.signatureUsesCompoundTypeWrappers = bindingToCopy.signatureUsesCompoundTypeWrappers;
94 this.signatureUsesArraysOfCompoundTypeWrappers = bindingToCopy.signatureUsesArraysOfCompoundTypeWrappers;
95 this.signatureUsesCVoidPointers = bindingToCopy.signatureUsesCVoidPointers;
96 this.signatureUsesCPrimitivePointers = bindingToCopy.signatureUsesCPrimitivePointers;
97 this.signatureUsesCArrays = bindingToCopy.signatureUsesCArrays;
98 this.signatureUsesJavaPrimitiveArrays = bindingToCopy.signatureUsesJavaPrimitiveArrays;
99 this.thisPointerIndex = bindingToCopy.thisPointerIndex;
110 final String delegationImplName,
112 final List<JavaType> javaArgumentTypes,
114 final Type containingCType) {
116 this.delegationImplName = delegationImplName;
117 this.containingType = containingType;
118 this.containingCType = containingCType;
120 this.nativeName =
null;
121 this.javaReturnType = javaReturnType;
122 this.javaArgumentTypes = javaArgumentTypes;
126 javaReturnType = type;
127 computedSignatureProperties =
false;
131 if (javaArgumentTypes ==
null) {
132 javaArgumentTypes =
new ArrayList<JavaType>();
134 javaArgumentTypes.add(type);
135 computedSignatureProperties =
false;
139 return javaReturnType;
147 return javaArgumentTypes.get(i);
165 public StringBuilder
getCParameterList(
final StringBuilder buf,
final boolean useTypedef,
final String callingConvention) {
176 public StringBuilder
getCParameterList(
final StringBuilder buf,
final boolean useTypedef,
final String callingConvention,
final List<Integer> exclude) {
178 if( !cType.
isVoid() && (
null == exclude || !exclude.contains(idx) ) ) {
179 if( 0 < consumedCount ) {
182 if( useTypedef && cType.isTypedef() ) {
183 buf.append( cType.getName() );
189 final FunctionType ft = cType.getTargetFunction();
190 buf.append( ft.toString(name, callingConvention, false, true) );
192 buf.append( cType.asArray().toString(name) );
194 buf.append( cType.getCName(true) );
214 return getJavaParameterList(buf,
null);
223 forEachParameter( (
final int idx,
final int consumedCount,
final Type cType,
final JavaType jType,
final String name ) -> {
224 if( !cType.
isVoid() && !jType.
isPascalLen() && (
null == exclude || !exclude.contains(idx) ) ) {
225 if( 0 < consumedCount ) {
228 buf.append(jType+
" "+name);
243 public StringBuilder
getJavaSelectParameter(
final StringBuilder buf,
final List<Integer> include,
final boolean addTailSeparator) {
244 forEachParameter( (
final int idx,
final int consumedCount,
final Type cType,
final JavaType jType,
final String name ) -> {
245 if( !cType.
isVoid() && include.contains(idx) ) {
246 if( 0 < consumedCount ) {
249 buf.append(jType+
" "+name);
255 if( addTailSeparator && buf.length() > 0 ) {
261 forEachParameter( (
final int idx,
final int consumedCount,
final Type cType,
final JavaType jType,
final String name ) -> {
262 if( !cType.
isVoid() && (
null == exclude || !exclude.contains(idx) ) ) {
263 if( 0 < consumedCount ) {
275 forEachParameter( (
final int idx,
final int consumedCount,
final Type cType,
final JavaType jType,
final String name ) -> {
276 if( !cType.
isVoid() && include.contains(idx) ) {
277 if( 0 < consumedCount ) {
286 if( addTailSeparator && buf.length() > 0 ) {
307 final int n = getNumArguments();
308 int consumedCount = 0;
309 for (
int i = 0; i < n; i++) {
310 if( c.
accept(i, consumedCount, getCArgumentType(i), getJavaArgumentType(i), getArgumentName(i)) ) {
314 return consumedCount;
318 final Type cReturnType = getCReturnType();
319 if (cReturnType.
isVoid()) {
322 if (javaReturnType.isPrimitive()) {
325 return !cReturnType.
isPointer() && javaReturnType.isCompoundTypeWrapper();
339 final String ret = sym.getArgumentName(i);
348 return sym.getName();
357 return delegationImplName;
362 return sym.getName();
371 return null != delegationImplName ? delegationImplName : sym.getName();
379 return null != nativeName ? nativeName : sym.getOrigName();
389 binding.javaArgumentTypes =
null;
390 if (argumentNumber < 0) {
395 for (
int i = 0; i < getNumArguments(); i++) {
396 JavaType type = getJavaArgumentType(i);
397 if (i == argumentNumber) {
411 computeSignatureProperties();
412 return argumentsUseNIO;
421 computeSignatureProperties();
422 return signatureUsesNIO;
430 computeSignatureProperties();
431 return signatureCanUseIndirectNIO;
440 computeSignatureProperties();
441 return signatureUsesCompoundTypeWrappers;
450 computeSignatureProperties();
451 return signatureUsesArraysOfCompoundTypeWrappers;
461 return (signatureUsesNIO() || signatureUsesCompoundTypeWrappers() || signatureUsesArraysOfCompoundTypeWrappers() );
469 computeSignatureProperties();
470 return signatureUsesCVoidPointers;
478 computeSignatureProperties();
479 return signatureUsesCPrimitivePointers;
487 computeSignatureProperties();
488 return signatureUsesCArrays;
496 computeSignatureProperties();
497 return signatureUsesJavaPrimitiveArrays;
505 if (computedSignatureProperties)
508 argumentsUseNIO =
false;
509 signatureUsesNIO =
false;
510 signatureCanUseIndirectNIO =
false;
511 signatureUsesCompoundTypeWrappers =
false;
512 signatureUsesArraysOfCompoundTypeWrappers =
false;
513 signatureUsesCVoidPointers =
false;
514 signatureUsesCPrimitivePointers =
false;
515 signatureUsesCArrays =
false;
516 signatureUsesJavaPrimitiveArrays =
false;
518 if ( javaReturnType.isCompoundTypeWrapper() ) {
521 signatureUsesCompoundTypeWrappers =
true;
524 if (javaReturnType.isNIOBuffer() ||
525 javaReturnType.isArrayOfCompoundTypeWrappers()) {
529 signatureUsesNIO =
true;
532 final Type cRetType = sym.getReturnType();
535 signatureUsesCArrays =
true;
537 signatureUsesCPrimitivePointers =
true;
543 signatureUsesCPrimitivePointers =
true;
545 signatureUsesCVoidPointers =
true;
549 for (
int i = 0; i < getNumArguments(); i++) {
550 final JavaType javaArgType = getJavaArgumentType(i);
551 final Type cArgType = getCArgumentType(i);
554 signatureUsesCompoundTypeWrappers =
true;
560 signatureUsesArraysOfCompoundTypeWrappers =
true;
566 signatureUsesNIO =
true;
567 argumentsUseNIO =
true;
571 signatureCanUseIndirectNIO =
true;
577 signatureUsesCArrays =
true;
579 signatureUsesCPrimitivePointers =
true;
588 signatureUsesCPrimitivePointers =
true;
590 signatureUsesCVoidPointers =
true;
597 signatureUsesJavaPrimitiveArrays =
true;
601 computedSignatureProperties =
true;
615 return (getContainingType() !=
null);
621 return containingType;
627 return containingCType;
636 for (
int i = 0; i < getNumArguments(); i++) {
637 final JavaType arg = getJavaArgumentType(i);
638 if (arg.
equals(containingType)) {
639 thisPointerIndex = i;
651 thisPointerIndex = -1;
657 return (thisPointerIndex == i);
660 public boolean equals(
final Object obj) {
670 if ( !getName().equals(other.
getName()) ||
671 !sym.getType().equals(other.sym.
getType()) ) {
return false; }
673 if (containingCType !=
null &&
678 if (javaArgumentTypes.size() != other.javaArgumentTypes.size()) {
682 for (
int i = 0; i < javaArgumentTypes.size(); ++i) {
683 final Object typeThis = javaArgumentTypes.get(i);
685 if (!(typeThis.equals(typeOther))) {
695 final StringBuilder buf =
new StringBuilder(200);
696 buf.append(getName());
697 buf.append(sym.getType().getName(
true));
698 buf.append(getJavaReturnType().getName());
699 if (containingCType !=
null) {
700 buf.append(containingCType.getName(
true));
703 for (
int i = 0; i < getNumArguments(); i++) {
704 final JavaType type = getJavaArgumentType(i);
708 assert(getNumArguments() == 1);
714 return buf.toString().hashCode();
720 final StringBuilder buf =
new StringBuilder(200);
721 buf.append(getJavaReturnType().getName());
723 buf.append(getName());
725 boolean needComma =
false;
726 for (
int i = 0; i < getNumArguments(); i++) {
727 final JavaType type = getJavaArgumentType(i);
731 assert(getNumArguments() == 1);
745 buf.append(getArgumentName(i));
749 return buf.toString();
757 final boolean eraseBufferAndArrayTypes) {
758 final StringBuilder buf =
new StringBuilder();
762 if (forImplementingMethodCall && hasContainingType()) {
764 buf.append(
"Ljava/nio/ByteBuffer;");
767 for (
int i = 0; i < getNumArguments(); i++) {
768 final JavaType type = getJavaArgumentType(i);
772 if (getNumArguments() != 1) {
773 throw new InternalError(
774 "\"void\" argument type found in " +
775 "multi-argument function \"" +
this +
"\"");
780 if (type.
isJNIEnv() || isArgumentThisPointer(i)) {
785 buf.append(erasedTypeDescriptor(type, eraseBufferAndArrayTypes,
false));
788 if (forImplementingMethodCall) {
806 buf.append(erasedTypeDescriptor(getJavaReturnType(), eraseBufferAndArrayTypes,
false));
808 return buf.toString();
812 if (eraseBufferAndArrayTypes) {
818 return "Ljava/lang/Object;";
822 return "Ljava/nio/ByteBuffer;";
824 return "Ljava/nio/ByteBuffer;";
Describes a java-side representation of a type that is used to represent the same data on both the Ja...
boolean isNIOBufferArray()
boolean equals(final Object arg)
String getName()
Returns the Java type name corresponding to this type.
boolean isCompoundTypeWrapper()
boolean isPrimitiveArray()
boolean isCPrimitivePointerType()
String getDescriptor()
Returns the descriptor (internal type signature) corresponding to this type.
boolean isArrayOfCompoundTypeWrappers()
Represents the binding of a C function to a Java method.
String erasedTypeDescriptor(final JavaType type, final boolean eraseBufferAndArrayTypes, final boolean skipBuffers)
MethodBinding(final MethodBinding bindingToCopy)
Constructs a new MethodBinding that is an exact clone of the argument, including the java return type...
boolean signatureUsesCVoidPointers()
Returns true if the return type or any of the outgoing arguments in the method's signature represent ...
Type getCArgumentType(final int i)
boolean signatureCanUseIndirectNIO()
Returns true if it is possible for any of the outgoing arguments to be indirect NIO buffers.
String getArgumentName(final int i)
Returns either the argument name specified by the underlying FunctionSymbol or a fabricated argument ...
void computeSignatureProperties()
Computes summary information about the method's C and Java signatures.
StringBuilder getJavaCallSelectArguments(final StringBuilder buf, final List< Integer > include, final boolean addTailSeparator)
int forEachParameter(final ParameterConsumer c)
boolean signatureUsesCompoundTypeWrappers()
Returns true if the return type or any of the outgoing arguments in the method's signature use "compo...
StringBuilder getJavaParameterList(final StringBuilder buf)
Returns the function parameter list, i.e.
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...
StringBuilder getCParameterList(final StringBuilder buf, final boolean useTypedef, final String callingConvention, final List< Integer > exclude)
Returns the function parameter list, i.e.
String getDescriptor(final boolean forImplementingMethodCall, final boolean eraseBufferAndArrayTypes)
Returns a String containing the descriptor (signature in internal format) of this MethodBinding as it...
StringBuilder getJavaSelectParameter(final StringBuilder buf, final List< Integer > include, final boolean addTailSeparator)
Returns the function parameter list, i.e.
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()
void findThisPointer()
Find the leftmost argument matching the type of the containing type (for function pointer MethodBindi...
String getInterfaceName()
Returns the FunctionSymbol's current aliased API name for the interface.
String getName()
Returns the FunctionSymbol's current aliased API name.
boolean signatureUsesCPrimitivePointers()
Returns true if the return type or any of the outgoing arguments in the method's signature represent ...
MethodBinding replaceJavaArgumentType(final int argumentNumber, final JavaType newArgType)
Creates a new MethodBinding replacing the specified Java argument type with a new argument type.
void addJavaArgumentType(final JavaType type)
boolean hasContainingType()
Indicates whether this MethodBinding is for a function pointer contained in a struct,...
StringBuilder getJavaParameterList(final StringBuilder buf, final List< Integer > exclude)
Returns the function parameter list, i.e.
boolean argumentsUseNIO()
Returns true if any of the outgoing arguments in the method's signature require conversion or checkin...
boolean signatureUsesArraysOfCompoundTypeWrappers()
Returns true if the return type or any of the outgoing arguments in the method's signature use arrays...
String toString()
Returns the signature of this binding.
void setJavaReturnType(final JavaType type)
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()
void setNativeName(final String s)
StringBuilder getJavaCallArgumentList(final StringBuilder buf, final List< Integer > exclude)
boolean signatureUsesNIO()
Returns true if the return type or any of the outgoing arguments in the method's signature require co...
String getNativeName()
Returns the FunctionSymbol's name for the native function which is the original C API name per defaul...
boolean signatureUsesJavaPrimitiveArrays()
Returns true if the return type or any of the outgoing arguments in the method's signature represent ...
boolean signatureUsesCArrays()
Returns true if the return type or any of the outgoing arguments in the method's signature represent ...
boolean equals(final Object obj)
MethodBinding(final FunctionSymbol sym, final String delegationImplName, final JavaType javaReturnType, final List< JavaType > javaArgumentTypes, final JavaType containingType, final Type containingCType)
Constructor for calling a C function or a function pointer contained in a struct.
StringBuilder getCParameterList(final StringBuilder buf, final boolean useTypedef, final String callingConvention)
Returns the function parameter list, i.e.
void clearThisPointer()
Clears any record of a this pointer for this MethodBinding.
String getDelegationImplName()
The implementation delegation name, or null for no delegation.
boolean needsNIOWrappingOrUnwrapping()
Returns true if the function needs NIO-related wrapping/unwrapping or conversion of various arguments...
final Type getTargetType()
Helper method to returns the target type of this type, in case another type is being referenced,...
Describes a function symbol, which includes the name and type.
FunctionType getType()
Returns the type of this function.
Type getArgumentType(final int i)
Returns the type of the ith argument.
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 boolean isArray()
Indicates whether this is an ArrayType.
final boolean isVoid()
Indicates whether this is a VoidType.
boolean isFunctionPointer()
Convenience routine indicating whether this Type is a pointer to a function.
PointerType asPointer()
Casts this to a PointerType or returns null if not a PointerType.
boolean isPrimitive()
Indicates whether this type is a primitive type.
ArrayType asArray()
Casts this to an ArrayType or returns null if not an ArrayType.
final boolean isPointer()
Indicates whether this is a PointerType.
forEachParameter(ParameterConsumer) Consumer
boolean accept(int idx, int consumedCount, Type cType, JavaType jType, String name)
Accept the arguments of the traversed collection element and return true if consumed.