net.java.games.gluegen

Class CMethodBindingEmitter

Known Direct Subclasses:
CMethodBindingImplEmitter

public class CMethodBindingEmitter
extends FunctionEmitter

Emits the C-side component of the Java<->C JNI binding.

Nested Class Summary

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 net.java.games.gluegen.FunctionEmitter

FunctionEmitter.EmissionModifier

Field Summary

protected static String
arrayIdx
protected static String
arrayRes
protected static String
arrayResLength
protected static CommentEmitter
defaultCommentEmitter

Fields inherited from class net.java.games.gluegen.FunctionEmitter

STATIC

Constructor Summary

CMethodBindingEmitter(MethodBinding binding, boolean isOverloadedBinding, String javaPackageName, String javaClassName, boolean isJavaMethodStatic, PrintWriter output)
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

protected static String
cThisArgumentName()
protected int
emitArguments(PrintWriter writer)
protected void
emitBody(PrintWriter writer)
protected void
emitBodyCallCFunction(PrintWriter writer)
protected void
emitBodyReturnResult(PrintWriter writer)
protected void
emitBodyUserVariableAssignments(PrintWriter writer)
Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the .cfg file.
protected void
emitBodyUserVariableDeclarations(PrintWriter writer)
Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in the .cfg file.
protected void
emitBodyVariableDeclarations(PrintWriter writer)
protected void
emitBodyVariablePostCallCleanup(PrintWriter writer, boolean emittingPrimitiveArrayCritical)
Code to clean up any variables that were declared in emitBodyVariableDeclarations(), AFTER calling the actual C function.
protected void
emitBodyVariablePreCallSetup(PrintWriter writer, boolean emittingPrimitiveArrayCritical)
Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the actual C function.
protected void
emitName(PrintWriter writer)
protected void
emitReturnType(PrintWriter writer)
MethodBinding
getBinding()
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.
String
getName()
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 array
List
getTemporaryCVariableAssignments()
Returns the List of Strings containing assignments for temporary C variables which are made after the underlying function call.
List
getTemporaryCVariableDeclarations()
Returns the List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.
protected static boolean
isNIOBufferClass(Class c)
protected boolean
javaArgTypeNeedsDataCopy(JavaType javaArgType)
protected void
jniMangle(Class c, StringBuffer res)
protected String
jniMangle(String name)
protected String
jniMangle(MethodBinding binding)
protected String
pointerConversionArgumentName(int i)
void
setReturnValueCapacityExpression(MessageFormat expression)
If this function returns a void* encapsulated in a java.nio.Buffer, 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 arg)
Sets up a List of Strings containing assignments for temporary C variables which are made after the underlying function call.
void
setTemporaryCVariableDeclarations(List 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 net.java.games.gluegen.FunctionEmitter

addModifier, addModifiers, clearModifiers, emit, emit, emitArguments, emitBody, emitDocComment, emitModifiers, emitName, emitReturnType, emitSignature, getBaseIndentString, getCommentEmitter, getCommentEndString, getCommentStartString, getDefaultOutput, getModifiers, getName, hasModifier, removeModifier, setCommentEmitter, toString

Field Details

arrayIdx

protected static final String arrayIdx

arrayRes

protected static final String arrayRes

arrayResLength

protected static final String arrayResLength

defaultCommentEmitter

protected static final CommentEmitter defaultCommentEmitter

Constructor Details

CMethodBindingEmitter

public CMethodBindingEmitter(MethodBinding binding,
                             boolean isOverloadedBinding,
                             String javaPackageName,
                             String javaClassName,
                             boolean isJavaMethodStatic,
                             PrintWriter output)
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 Details

cThisArgumentName

protected static String cThisArgumentName()

emitArguments

protected int emitArguments(PrintWriter writer)
Overrides:
emitArguments in interface FunctionEmitter

emitBody

protected void emitBody(PrintWriter writer)
Overrides:
emitBody in interface FunctionEmitter

emitBodyCallCFunction

protected void emitBodyCallCFunction(PrintWriter writer)

emitBodyReturnResult

protected void emitBodyReturnResult(PrintWriter writer)

emitBodyUserVariableAssignments

protected void emitBodyUserVariableAssignments(PrintWriter writer)
Emits the user-defined C variable assignments from the TemporaryCVariableAssignments directive in the .cfg file.

emitBodyUserVariableDeclarations

protected void emitBodyUserVariableDeclarations(PrintWriter writer)
Emits the user-defined C variable declarations from the TemporaryCVariableDeclarations directive in the .cfg file.

emitBodyVariableDeclarations

protected void emitBodyVariableDeclarations(PrintWriter writer)

emitBodyVariablePostCallCleanup

protected void emitBodyVariablePostCallCleanup(PrintWriter writer,
                                               boolean emittingPrimitiveArrayCritical)
Code to clean up any variables that were declared in emitBodyVariableDeclarations(), AFTER calling the actual C function.

emitBodyVariablePreCallSetup

protected void emitBodyVariablePreCallSetup(PrintWriter writer,
                                            boolean emittingPrimitiveArrayCritical)
Code to init the variables that were declared in emitBodyVariableDeclarations(), PRIOR TO calling the actual C function.

emitName

protected void emitName(PrintWriter writer)
Overrides:
emitName in interface FunctionEmitter

emitReturnType

protected void emitReturnType(PrintWriter writer)
Overrides:
emitReturnType in interface FunctionEmitter

getBinding

public final MethodBinding getBinding()

getIsJavaMethodStatic

public final boolean getIsJavaMethodStatic()
Is the Java side of the Java<->C JNI binding for this emitter's MethodBinding a static method?.

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?

getJavaClassName

public String getJavaClassName()
Get the name of the package in which the corresponding Java method resides.

getJavaPackageName

public String getJavaPackageName()
Get the name of the class in which the corresponding Java method resides.

getName

public String getName()
Overrides:
getName in interface FunctionEmitter

getReturnValueCapacityExpression

public final MessageFormat getReturnValueCapacityExpression()
Get the expression for the capacity of the returned java.nio.Buffer.

getReturnValueLengthExpression

public final MessageFormat getReturnValueLengthExpression()
Get the expression for the length of the returned array

getTemporaryCVariableAssignments

public final List 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.

getTemporaryCVariableDeclarations

public final List getTemporaryCVariableDeclarations()
Returns the List of Strings containing declarations for temporary C variables to be assigned to after the underlying function call.

isNIOBufferClass

protected static boolean isNIOBufferClass(Class c)

javaArgTypeNeedsDataCopy

protected boolean javaArgTypeNeedsDataCopy(JavaType javaArgType)

jniMangle

protected void jniMangle(Class c,
                         StringBuffer res)

jniMangle

protected String jniMangle(String name)

jniMangle

protected String jniMangle(MethodBinding binding)

pointerConversionArgumentName

protected String pointerConversionArgumentName(int i)

setReturnValueCapacityExpression

public final void setReturnValueCapacityExpression(MessageFormat expression)
If this function returns a void* encapsulated in a java.nio.Buffer, 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.

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.

setTemporaryCVariableAssignments

public final void setTemporaryCVariableAssignments(List 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.

setTemporaryCVariableDeclarations

public final void setTemporaryCVariableDeclarations(List 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.