Package com.jogamp.gluegen
Class CMethodBindingEmitter
- java.lang.Object
-
- com.jogamp.gluegen.FunctionEmitter
-
- com.jogamp.gluegen.CMethodBindingEmitter
-
- Direct Known Subclasses:
ProcAddressCMethodBindingEmitter
public class CMethodBindingEmitter extends FunctionEmitter
Emits the C-side component of the Java<->C JNI binding to itsCodeUnit
, seeFunctionEmitter
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CMethodBindingEmitter.DefaultCommentEmitter
Class that emits a generic comment for CMethodBindingEmitters; the comment includes the C signature of the native method that is being bound by the emitter java method.-
Nested classes/interfaces inherited from class com.jogamp.gluegen.FunctionEmitter
FunctionEmitter.EmissionModifier
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
arrayIdx
protected static String
arrayRes
protected static String
arrayResLength
protected static CommentEmitter
defaultCommentEmitter
protected boolean
forImplementingMethodCall
protected boolean
forIndirectBufferAndArrayImplementation
protected Logging.LoggerIf
LOG
protected MachineDataInfo
machDesc
protected static String
STRING_CHARS_PREFIX
-
Fields inherited from class com.jogamp.gluegen.FunctionEmitter
binding, cfg, STATIC, unit
-
-
Constructor Summary
Constructors Constructor Description CMethodBindingEmitter(MethodBinding binding, CodeUnit unit, String javaPackageName, String javaClassName, boolean isOverloadedBinding, boolean isJavaMethodStatic, boolean forImplementingMethodCall, boolean forIndirectBufferAndArrayImplementation, MachineDataInfo machDesc, JavaConfiguration configuration)
Constructs an emitter for the specified binding, and sets a default comment emitter that will emit the signature of the C function that is being bound.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
appendArguments(StringBuilder buf)
Returns the number of arguments emitted.static StringBuilder
appendJNIMangledArgs(MethodBinding binding, boolean forIndirectBufferAndArrayImplementation, StringBuilder buf)
Return the mangled JNI argument names of given binding.protected StringBuilder
appendName(StringBuilder buf)
protected StringBuilder
appendReturnType(StringBuilder buf)
protected String[]
argumentNameArray()
protected String
byteOffsetArgName(int i)
protected String
byteOffsetArrayArgName(int i)
protected static String
cThisArgumentName()
protected void
emitAdditionalCode()
protected void
emitBody()
protected void
emitBodyCallCFunction()
boolean
emitBodyMapCToJNIType(int argIdx, boolean addLocalVar)
Emit code, converting a C type into a java JNI-type.protected int
emitBodyPassCArguments()
Returns the number of arguments passed so calling code knows whether to print a commaprotected void
emitBodyUserVariableAssignments()
Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the .cfg file.protected void
emitBodyUserVariableDeclarations()
Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in the .cfg file.protected void
emitBodyVariableDeclarations()
protected void
emitBodyVariablePostCallCleanup()
Code to clean up any variables that were declared in emitBodyVariableDeclarations(), AFTER calling the actual C function.protected void
emitBodyVariablePreCallSetup()
Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the actual C function.boolean
forIndirectBufferAndArrayImplementation()
Is this CMethodBindingEmitter implementing the case of an indirect buffer or array being passed down to C code?FunctionSymbol
getCSymbol()
String
getImplName()
protected String
getImplSuffix()
String
getInterfaceName()
boolean
getIsJavaMethodStatic()
Is the Java side of the Java<->C JNI binding for this emitter's MethodBinding a static method?.boolean
getIsOverloadedBinding()
Is the Java<->C JNI binding for this emitter's MethodBinding one of several overloaded methods with the same name?String
getJavaClassName()
Get the name of the package in which the corresponding Java method resides.String
getJavaPackageName()
Get the name of the class in which the corresponding Java method resides.MachineDataInfo
getMachineDataInfo()
Used for certain internal type size computationsString
getNativeName()
MessageFormat
getReturnValueCapacityExpression()
Get the expression for the capacity of the returned java.nio.Buffer.MessageFormat
getReturnValueLengthExpression()
Get the expression for the length of the returned arrayList<String>
getTemporaryCVariableAssignments()
Returns the List of Strings containing assignments for temporary C variables which are made after the underlying function call.List<String>
getTemporaryCVariableDeclarations()
Returns the List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.protected String
isNIOArgName(int i)
protected String
isNIOArgName(String s)
protected boolean
isUTF8Type(Type type)
Checks a type to see whether it is for a UTF-8 pointer type (i.e., "const char *", "const char **").protected boolean
javaArgTypeNeedsDataCopy(JavaType javaArgType)
protected String
jniMangle(MethodBinding binding)
protected String
pointerConversionArgumentName(String argName)
protected void
setIsCStructFunctionPointer(boolean v)
If method originates from a struct, seeMethodBinding.hasContainingType()
, it can either purposed to call a native static function (default) or a struct's function pointer.void
setReturnValueCapacityExpression(MessageFormat expression)
If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper), sets the expression for the capacity of the returned Buffer.void
setReturnValueLengthExpression(MessageFormat expression)
If this function returns an array, sets the expression for the length of the returned array.void
setTemporaryCVariableAssignments(List<String> arg)
Sets up a List of Strings containing assignments for temporary C variables which are made after the underlying function call.void
setTemporaryCVariableDeclarations(List<String> arg)
Sets up a List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.-
Methods inherited from class com.jogamp.gluegen.FunctionEmitter
addModifier, addModifiers, appendModifiers, appendSignature, clearModifiers, emit, emitArguments, emitDocComment, emitModifiers, emitName, emitReturnType, emitSignature, getBaseIndentString, getBinding, getCommentEmitter, getCommentEndString, getCommentStartString, getModifiers, getUnit, hasModifier, isInterface, removeModifier, setCommentEmitter, toString
-
-
-
-
Field Detail
-
defaultCommentEmitter
protected static final CommentEmitter defaultCommentEmitter
-
arrayResLength
protected static final String arrayResLength
- See Also:
- Constant Field Values
-
arrayRes
protected static final String arrayRes
- See Also:
- Constant Field Values
-
arrayIdx
protected static final String arrayIdx
- See Also:
- Constant Field Values
-
LOG
protected final Logging.LoggerIf LOG
-
forImplementingMethodCall
protected boolean forImplementingMethodCall
-
forIndirectBufferAndArrayImplementation
protected boolean forIndirectBufferAndArrayImplementation
-
STRING_CHARS_PREFIX
protected static final String STRING_CHARS_PREFIX
- See Also:
- Constant Field Values
-
machDesc
protected MachineDataInfo machDesc
-
-
Constructor Detail
-
CMethodBindingEmitter
public CMethodBindingEmitter(MethodBinding binding, CodeUnit unit, String javaPackageName, String javaClassName, boolean isOverloadedBinding, boolean isJavaMethodStatic, boolean forImplementingMethodCall, boolean forIndirectBufferAndArrayImplementation, MachineDataInfo machDesc, JavaConfiguration configuration)
Constructs an emitter for the specified binding, and sets a default comment emitter that will emit the signature of the C function that is being bound.
-
-
Method Detail
-
getInterfaceName
public String getInterfaceName()
- Specified by:
getInterfaceName
in classFunctionEmitter
-
getImplName
public String getImplName()
- Specified by:
getImplName
in classFunctionEmitter
-
getNativeName
public String getNativeName()
- Specified by:
getNativeName
in classFunctionEmitter
-
getCSymbol
public FunctionSymbol getCSymbol()
- Specified by:
getCSymbol
in classFunctionEmitter
-
getReturnValueCapacityExpression
public final MessageFormat getReturnValueCapacityExpression()
Get the expression for the capacity of the returned java.nio.Buffer.
-
setReturnValueCapacityExpression
public final void setReturnValueCapacityExpression(MessageFormat expression)
If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper), sets the expression for the capacity of the returned Buffer.- Parameters:
expression
- a MessageFormat which, when applied to an array of type String[] that contains each of the arguments names of the Java-side binding, returns an expression that will (when compiled by a C compiler) evaluate to an integer-valued expression. The value of this expression is the capacity of the java.nio.Buffer returned from this method.- Throws:
IllegalArgumentException
- if thebinding.getJavaReturnType().isNIOBuffer() == false and binding.getJavaReturnType().isCompoundTypeWrapper() == false
-
getReturnValueLengthExpression
public final MessageFormat getReturnValueLengthExpression()
Get the expression for the length of the returned array
-
setReturnValueLengthExpression
public final void setReturnValueLengthExpression(MessageFormat expression)
If this function returns an array, sets the expression for the length of the returned array.- Parameters:
expression
- a MessageFormat which, when applied to an array of type String[] that contains each of the arguments names of the Java-side binding, returns an expression that will (when compiled by a C compiler) evaluate to an integer-valued expression. The value of this expression is the length of the array returned from this method.- Throws:
IllegalArgumentException
- if thebinding.getJavaReturnType().isNIOBuffer() == false
-
getTemporaryCVariableDeclarations
public final List<String> getTemporaryCVariableDeclarations()
Returns the List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.
-
setTemporaryCVariableDeclarations
public final void setTemporaryCVariableDeclarations(List<String> arg)
Sets up a List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call. A null argument indicates that no manual declarations are to be made.
-
getTemporaryCVariableAssignments
public final List<String> getTemporaryCVariableAssignments()
Returns the List of Strings containing assignments for temporary C variables which are made after the underlying function call. A null argument indicates that no manual assignments are to be made.
-
setTemporaryCVariableAssignments
public final void setTemporaryCVariableAssignments(List<String> arg)
Sets up a List of Strings containing assignments for temporary C variables which are made after the underlying function call. A null argument indicates that no manual assignments are to be made.
-
getJavaPackageName
public String getJavaPackageName()
Get the name of the class in which the corresponding Java method resides.
-
getJavaClassName
public String getJavaClassName()
Get the name of the package in which the corresponding Java method resides.
-
getIsOverloadedBinding
public final boolean getIsOverloadedBinding()
Is the Java<->C JNI binding for this emitter's MethodBinding one of several overloaded methods with the same name?
-
getIsJavaMethodStatic
public final boolean getIsJavaMethodStatic()
Is the Java side of the Java<->C JNI binding for this emitter's MethodBinding a static method?.
-
forIndirectBufferAndArrayImplementation
public final boolean forIndirectBufferAndArrayImplementation()
Is this CMethodBindingEmitter implementing the case of an indirect buffer or array being passed down to C code?
-
getMachineDataInfo
public final MachineDataInfo getMachineDataInfo()
Used for certain internal type size computations
-
appendReturnType
protected StringBuilder appendReturnType(StringBuilder buf)
- Specified by:
appendReturnType
in classFunctionEmitter
-
appendName
protected StringBuilder appendName(StringBuilder buf)
- Specified by:
appendName
in classFunctionEmitter
-
getImplSuffix
protected String getImplSuffix()
-
appendArguments
protected int appendArguments(StringBuilder buf)
Description copied from class:FunctionEmitter
Returns the number of arguments emitted.- Specified by:
appendArguments
in classFunctionEmitter
-
emitAdditionalCode
protected void emitAdditionalCode()
- Overrides:
emitAdditionalCode
in classFunctionEmitter
-
emitBody
protected void emitBody()
- Specified by:
emitBody
in classFunctionEmitter
-
emitBodyVariableDeclarations
protected void emitBodyVariableDeclarations()
-
emitBodyUserVariableDeclarations
protected void emitBodyUserVariableDeclarations()
Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in the .cfg file.
-
isUTF8Type
protected boolean isUTF8Type(Type type)
Checks a type to see whether it is for a UTF-8 pointer type (i.e., "const char *", "const char **"). False implies that this type is for a Unicode pointer type ("jchar *", "jchar **").
-
emitBodyVariablePreCallSetup
protected void emitBodyVariablePreCallSetup()
Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the actual C function.
-
emitBodyVariablePostCallCleanup
protected void emitBodyVariablePostCallCleanup()
Code to clean up any variables that were declared in emitBodyVariableDeclarations(), AFTER calling the actual C function.
-
emitBodyPassCArguments
protected int emitBodyPassCArguments()
Returns the number of arguments passed so calling code knows whether to print a comma
-
setIsCStructFunctionPointer
protected void setIsCStructFunctionPointer(boolean v)
If method originates from a struct, seeMethodBinding.hasContainingType()
, it can either purposed to call a native static function (default) or a struct's function pointer.
-
emitBodyCallCFunction
protected void emitBodyCallCFunction()
-
emitBodyUserVariableAssignments
protected void emitBodyUserVariableAssignments()
Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the .cfg file.
-
emitBodyMapCToJNIType
public boolean emitBodyMapCToJNIType(int argIdx, boolean addLocalVar)
Emit code, converting a C type into a java JNI-type.The resulting JNI value is assigned to a local JNI variable named cArgName+"_jni" with `cArgName = binding.getArgumentName(argIdx)` or `cArgName = "_res"`.
- Parameters:
argIdx
- -1 is return value, [0..n] is argument indexaddLocalVar
- if true, emit instantiating the local JNI variable.- Returns:
- true if a non-void result has been produced, otherwise false
-
cThisArgumentName
protected static String cThisArgumentName()
-
jniMangle
protected String jniMangle(MethodBinding binding)
-
appendJNIMangledArgs
public static StringBuilder appendJNIMangledArgs(MethodBinding binding, boolean forIndirectBufferAndArrayImplementation, StringBuilder buf)
Return the mangled JNI argument names of given binding.- Parameters:
binding
-forIndirectBufferAndArrayImplementation
- If true, this CMethodBindingEmitter implements the case of an indirect buffer or array being passed down to C code, otherwise false.buf
-- Returns:
-
byteOffsetArgName
protected String byteOffsetArgName(int i)
-
isNIOArgName
protected String isNIOArgName(int i)
-
byteOffsetArrayArgName
protected String byteOffsetArrayArgName(int i)
-
argumentNameArray
protected String[] argumentNameArray()
-
javaArgTypeNeedsDataCopy
protected boolean javaArgTypeNeedsDataCopy(JavaType javaArgType)
-
-