diff options
author | Sven Gothel <[email protected]> | 2023-06-29 03:03:30 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-06-29 03:03:30 +0200 |
commit | a83dad9963b394ac3e7bb193c6da7d9a5004a40e (patch) | |
tree | a1ec8caad1d0c46ddb49a5e654493df6f8b1a50e /src/java/com/jogamp/gluegen/MethodBinding.java | |
parent | 809a7f84fcada7fbde8b7d0c226b78492fbfc616 (diff) |
GlueGen FunctionType: Factor out getParameterList(..) from toString(..) and drop 'void' and use typedef-name; MethodBinding: Add getCParameterList(..) and getJavaParameterList(..) for general usage similar to FunctionType.getParameterList()
Diffstat (limited to 'src/java/com/jogamp/gluegen/MethodBinding.java')
-rw-r--r-- | src/java/com/jogamp/gluegen/MethodBinding.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/java/com/jogamp/gluegen/MethodBinding.java b/src/java/com/jogamp/gluegen/MethodBinding.java index 21df415..44ed2e3 100644 --- a/src/java/com/jogamp/gluegen/MethodBinding.java +++ b/src/java/com/jogamp/gluegen/MethodBinding.java @@ -41,6 +41,7 @@ package com.jogamp.gluegen; import com.jogamp.gluegen.cgram.types.FunctionSymbol; +import com.jogamp.gluegen.cgram.types.FunctionType; import com.jogamp.gluegen.cgram.types.Type; import java.util.ArrayList; @@ -154,6 +155,67 @@ public class MethodBinding { return sym.getArgumentType(i); } + /** + * Returns the function parameter list, i.e. a comma separated list of argument type and name. + * @param buf StringBuilder instance + * @param callingConvention optional calling-convention + * @return given StringBuilder instance + */ + public StringBuilder getCParameterList(final StringBuilder buf, final String callingConvention) { + final int n = getNumArguments(); + final boolean[] needsComma = { false }; + for (int i = 0; i < n; i++) { + final Type t = getCArgumentType(i); + if( t.isVoid() ) { + // nop + } else if( t.isTypedef() ) { + CodeGenUtils.addParameterToList(buf, t.getName(), needsComma); + final String argumentName = getArgumentName(i); + if (argumentName != null) { + buf.append(" "); + buf.append(argumentName); + } + } else if ( t.isFunctionPointer() ) { + final FunctionType ft = t.getTargetFunction(); + CodeGenUtils.addParameterToList(buf, ft.toString(getArgumentName(i), callingConvention, false, true), needsComma); + } else if (t.isArray()) { + CodeGenUtils.addParameterToList(buf, t.asArray().toString(getArgumentName(i)), needsComma); + } else { + CodeGenUtils.addParameterToList(buf, t.getCName(true), needsComma); + final String argumentName = getArgumentName(i); + if (argumentName != null) { + buf.append(" "); + buf.append(argumentName); + } + } + } + return buf; + } + + /** + * Returns the function parameter list, i.e. a comma separated list of argument type and name. + * @param buf StringBuilder instance + * @return given StringBuilder instance + */ + public StringBuilder getJavaParameterList(final StringBuilder buf) { + final int n = getNumArguments(); + final boolean[] needsComma = { false }; + for (int i = 0; i < n; i++) { + final JavaType t = getJavaArgumentType(i); + if( t.isVoid() ) { + // nop + } else { + CodeGenUtils.addParameterToList(buf, t.getName(), needsComma); + final String argumentName = getArgumentName(i); + if (argumentName != null) { + buf.append(" "); + buf.append(argumentName); + } + } + } + return buf; + } + public final boolean isReturnCompoundByValue() { final Type cReturnType = getCReturnType(); if (cReturnType.isVoid()) { |