40package com.jogamp.gluegen.cgram.types;
44import com.jogamp.gluegen.ASTLocusTag;
50 private final Type returnType;
51 private ArrayList<Type> argumentTypes;
52 private ArrayList<String> argumentNames;
55 final int cvAttributes) {
56 this(name, size, returnType, cvAttributes,
null);
59 final int cvAttributes,
final ASTLocusTag astLocus) {
60 super(name, size, cvAttributes, astLocus);
61 this.returnType = returnType;
66 returnType = o.returnType;
67 if(
null != o.argumentTypes) {
68 argumentTypes =
new ArrayList<Type>(o.argumentTypes);
70 if(
null != o.argumentNames) {
71 argumentNames =
new ArrayList<String>(o.argumentNames);
76 Type newVariantImpl(
final boolean newCVVariant,
final int cvAttributes,
final ASTLocusTag astLocus) {
88 final int hash = returnType.
hashCode();
89 return ((hash << 5) - hash) +
TypeComparator.listsHashCode(argumentTypes);
95 return returnType.
equals(t.returnType) &&
103 return ((hash << 5) - hash) +
TypeComparator.listsHashCodeSemantics(argumentTypes);
110 TypeComparator.listsEqualSemantics(argumentTypes, t.argumentTypes);
124 return ((argumentTypes ==
null) ? 0 : argumentTypes.size());
130 return argumentNames.get(i);
135 return argumentTypes.get(i);
145 public StringBuilder
getParameterList(
final StringBuilder buf,
final boolean useTypedef,
final String callingConvention) {
156 public StringBuilder
getParameterList(
final StringBuilder buf,
final boolean useTypedef,
final String callingConvention,
final List<Integer> exclude) {
157 forEachParameter( (
final int idx,
final int consumedCount,
final Type cType,
final String name ) -> {
158 if( !cType.
isVoid() && (
null == exclude || !exclude.contains(idx) ) ) {
159 if( 0 < consumedCount ) {
162 if( useTypedef && cType.isTypedef() ) {
163 buf.append( cType.getName() );
169 final FunctionType ft = cType.getTargetFunction();
170 buf.append( ft.toString(name, callingConvention, false, true) );
172 buf.append( cType.asArray().toString(name) );
174 buf.append( cType.getCName(true) );
199 boolean accept(
int idx,
int consumedCount,
Type cType, String name);
202 final int n = getNumArguments();
203 int consumedCount = 0;
204 for (
int i = 0; i < n; i++) {
205 if( c.
accept(i, consumedCount, getArgumentType(i), getArgumentName(i)) ) {
209 return consumedCount;
216 if (argumentTypes ==
null) {
217 argumentTypes =
new ArrayList<Type>();
218 argumentNames =
new ArrayList<String>();
220 argumentTypes.add(argumentType);
221 argumentNames.add(argumentName);
226 argumentNames.set(i, name);
232 return toString(
null,
false);
235 public String
toString(
final String functionName,
final boolean emitNativeTag) {
236 return toString(functionName,
null, emitNativeTag,
false);
238 public String
toString(
final String functionName,
final boolean emitNativeTag,
final boolean isPointer) {
239 return toString(functionName,
null, emitNativeTag, isPointer);
242 public String
toString(
final String functionName,
final String callingConvention,
243 final boolean emitNativeTag,
final boolean isPointer) {
244 final StringBuilder res =
new StringBuilder();
245 res.append(getReturnType().getCName(
true));
249 if (callingConvention !=
null) {
250 res.append(callingConvention);
254 if (functionName !=
null) {
257 res.append(
"{@native ");
259 res.append(functionName);
268 getParameterList(res,
true, callingConvention);
270 return res.toString();
276 returnType.
visit(arg);
277 final int n = getNumArguments();
278 for (
int i = 0; i < n; i++) {
279 getArgumentType(i).visit(arg);
Describes a function type, used to model both function declarations and (via PointerType) function po...
String getArgumentName(final int i)
Returns the name of the ith argument.
FunctionType(final String name, final SizeThunk size, final Type returnType, final int cvAttributes)
Type getReturnType()
Returns the return type of this function.
String toString(final String functionName, final boolean emitNativeTag)
void setArgumentName(final int i, final String name)
StringBuilder getParameterList(final StringBuilder buf, final boolean useTypedef, final String callingConvention, final List< Integer > exclude)
Returns the function parameter list, i.e.
String toString()
Returns a string representation of this type.
Type getArgumentType(final int i)
Returns the type of the ith argument.
FunctionType asFunction()
Casts this to a FunctionType or returns null if not a FunctionType.
int forEachParameter(final ParameterConsumer c)
boolean equalSemanticsImpl(final Type arg)
FunctionType(final String name, final SizeThunk size, final Type returnType, final int cvAttributes, final ASTLocusTag astLocus)
void visit(final TypeVisitor arg)
Traverse this Type and all of its component types; for example, the return type and argument types of...
String toString(final String functionName, final boolean emitNativeTag, final boolean isPointer)
String toString(final String functionName, final String callingConvention, final boolean emitNativeTag, final boolean isPointer)
int hashCodeSemanticsImpl()
void addArgument(final Type argumentType, final String argumentName)
Add an argument's name and type.
StringBuilder getParameterList(final StringBuilder buf, final boolean useTypedef, final String callingConvention)
Returns the function parameter list, i.e.
boolean equalsImpl(final Type arg)
Provides a level of indirection between the definition of a type's size and the absolute value of thi...
final boolean isArray()
Indicates whether this is an ArrayType.
final int hashCodeSemantics()
Semantic hashcode for Types exclusive its given name.
Type(final String name, final SizeThunk size, final int cvAttributes, final ASTLocusTag astLocus)
final int hashCode()
Hashcode for Types.
final boolean isVoid()
Indicates whether this is a VoidType.
boolean isFunctionPointer()
Convenience routine indicating whether this Type is a pointer to a function.
final boolean equalSemantics(final SemanticEqualityOp arg)
Semantic equality test for Types exclusive its given name.
void visit(final TypeVisitor visitor)
Traverse this Type and all of its component types; for example, the return type and argument types of...
final boolean equals(final Object arg)
Equality test for Types inclusive its given name.
final Type newCVVariant(final int cvAttributes)
Return a variant of this type matching the given const/volatile attributes.
final int getCVAttributes()
forEachParameter(ParameterConsumer) Consumer
boolean accept(int idx, int consumedCount, Type cType, String name)
Accept the arguments of the traversed collection element and return true if consumed.
A visitor for Type's visitor model.