aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-06-29 03:03:30 +0200
committerSven Gothel <[email protected]>2023-06-29 03:03:30 +0200
commita83dad9963b394ac3e7bb193c6da7d9a5004a40e (patch)
treea1ec8caad1d0c46ddb49a5e654493df6f8b1a50e /src/java/com/jogamp
parent809a7f84fcada7fbde8b7d0c226b78492fbfc616 (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')
-rw-r--r--src/java/com/jogamp/gluegen/CodeGenUtils.java10
-rw-r--r--src/java/com/jogamp/gluegen/MethodBinding.java62
-rw-r--r--src/java/com/jogamp/gluegen/cgram/types/FunctionType.java63
3 files changed, 113 insertions, 22 deletions
diff --git a/src/java/com/jogamp/gluegen/CodeGenUtils.java b/src/java/com/jogamp/gluegen/CodeGenUtils.java
index 5442a24..aa7a4e2 100644
--- a/src/java/com/jogamp/gluegen/CodeGenUtils.java
+++ b/src/java/com/jogamp/gluegen/CodeGenUtils.java
@@ -57,6 +57,16 @@ public class CodeGenUtils {
return Character.toLowerCase(string.charAt(0)) + string.substring(1);
}
+ /** Appends `param` to `buf` while prepending a comman separator if `needsComma[0]` is true. Sets `needsComma[0]=true` afterwards. */
+ public static StringBuilder addParameterToList(final StringBuilder buf, final String param, final boolean[] needsComma) {
+ if( needsComma[0] ) {
+ buf.append(", ");
+ }
+ buf.append(param);
+ needsComma[0] = true;
+ return buf;
+ }
+
/**
* Given a java package name (e.g., "java.lang"), return the package as a
* directory path (i.e., "java/lang").
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()) {
diff --git a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
index 086361e..aab106f 100644
--- a/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
+++ b/src/java/com/jogamp/gluegen/cgram/types/FunctionType.java
@@ -42,6 +42,7 @@ package com.jogamp.gluegen.cgram.types;
import java.util.*;
import com.jogamp.gluegen.ASTLocusTag;
+import com.jogamp.gluegen.CodeGenUtils;
/** Describes a function type, used to model both function
declarations and (via PointerType) function pointers. */
@@ -136,6 +137,43 @@ public class FunctionType extends Type implements Cloneable {
}
/**
+ * 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 getParameterList(final StringBuilder buf, final String callingConvention) {
+ final int n = getNumArguments();
+ final boolean[] needsComma = { false };
+ for (int i = 0; i < n; i++) {
+ final Type t = getArgumentType(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;
+ }
+
+ /**
* Add an argument's name and type. Use null for unknown argument names.
*/
public void addArgument(final Type argumentType, final String argumentName) {
@@ -165,8 +203,8 @@ public class FunctionType extends Type implements Cloneable {
return toString(functionName, null, emitNativeTag, isPointer);
}
- String toString(final String functionName, final String callingConvention,
- final boolean emitNativeTag, final boolean isPointer) {
+ public String toString(final String functionName, final String callingConvention,
+ final boolean emitNativeTag, final boolean isPointer) {
final StringBuilder res = new StringBuilder();
res.append(getReturnType().getCName(true));
res.append(" ");
@@ -191,26 +229,7 @@ public class FunctionType extends Type implements Cloneable {
res.append(")");
}
res.append("(");
- final int n = getNumArguments();
- for (int i = 0; i < n; i++) {
- final Type t = getArgumentType(i);
- if (t.isFunctionPointer()) {
- final FunctionType ft = t.getTargetFunction();
- res.append(ft.toString(getArgumentName(i), callingConvention, false, true));
- } else if (t.isArray()) {
- res.append(t.asArray().toString(getArgumentName(i)));
- } else {
- res.append(t.getCName(true));
- final String argumentName = getArgumentName(i);
- if (argumentName != null) {
- res.append(" ");
- res.append(argumentName);
- }
- }
- if (i < n - 1) {
- res.append(", ");
- }
- }
+ getParameterList(res, callingConvention);
res.append(")");
return res.toString();
}