40package com.jogamp.gluegen.procaddress;
43import java.text.MessageFormat;
44import java.util.ArrayList;
45import java.util.HashSet;
49import java.util.logging.Level;
51import com.jogamp.gluegen.CMethodBindingEmitter;
52import com.jogamp.gluegen.CodeGenUtils;
53import com.jogamp.gluegen.FunctionEmitter;
54import com.jogamp.gluegen.JavaCodeUnit;
55import com.jogamp.gluegen.JavaConfiguration;
56import com.jogamp.gluegen.JavaEmitter;
57import com.jogamp.gluegen.JavaMethodBindingEmitter;
58import com.jogamp.gluegen.cgram.types.FunctionSymbol;
59import com.jogamp.gluegen.cgram.types.Type;
60import com.jogamp.gluegen.cgram.types.TypeDictionary;
61import com.jogamp.gluegen.runtime.FunctionAddressResolver;
62import com.jogamp.gluegen.runtime.ProcAddressTable;
82 final Map<Type, Type> canonMap,
final List<FunctionSymbol> cFunctions)
throws Exception {
83 this.typedefDictionary = typedefDictionary;
88 super.beginFunctions(typedefDictionary, structDictionary, canonMap, cFunctions);
101 super.beginStructs(typedefDictionary, structDictionary, canonMap);
105 return getConfig().runtimeExceptionType();
109 return getConfig().unsupportedExceptionType();
119 return generateMethodBindingEmittersImpl(sym);
130 private List<? extends FunctionEmitter> generateMethodBindingEmittersImpl(
final FunctionSymbol sym)
throws Exception {
131 final List<? extends FunctionEmitter> defaultEmitters = super.generateMethodBindingEmitters(sym);
136 if (defaultEmitters.isEmpty()) {
137 LOG.
log(Level.INFO, sym.getASTLocusTag(),
"genModProcAddrEmitter: SKIP, empty binding set: {0}", sym);
138 return defaultEmitters;
146 LOG.
log(Level.INFO, sym.getASTLocusTag(),
"genModProcAddrEmitter: SKIP, not needed: callThrough {0}, isUnimplemented {1}: {2}",
148 return defaultEmitters;
151 final ArrayList<FunctionEmitter> modifiedEmitters =
new ArrayList<FunctionEmitter>(defaultEmitters.size());
159 for (
final FunctionEmitter emitter : defaultEmitters) {
160 if (emitter instanceof JavaMethodBindingEmitter) {
162 }
else if (emitter instanceof CMethodBindingEmitter) {
165 throw new RuntimeException(
"Unexpected emitter type: " + emitter.getClass().getName());
169 return modifiedEmitters;
208 final boolean needsJavaWrapper = baseJavaEmitter.
signatureOnly() &&
209 baseJavaEmitter.isNativeMethod() &&
210 !baseJavaEmitter.isPrivateNativeMethod() &&
218 baseJavaEmitter.isPrivateNativeMethod(),
220 if( needsJavaWrapper ) {
226 emitters.add(emitter);
229 if( needsJavaWrapper ) {
237 emitters.add(emitter);
250 LOG.
log(Level.INFO, cSymbol.
getASTLocusTag(),
"genModProcAddrEmitter: callThrough {0}, hasTypedef {1}, localCallConv {2}: {3}",
274 if (
cfg.forceProcAddressGen(sym)) {
278 if (
cfg.skipProcAddressGen(sym)) {
286 LOG.
log(Level.INFO, sym.
getASTLocusTag(),
"callThroughProcAddress: {0} [m {1}]: {2}", res, mode, sym);
291 final boolean res = typedefDictionary.
containsKey(funcPointerTypedefName);
303 if (implPackageName ==
null) {
306 final String tableClassFQN = implPackageName +
"." +
tableClassName;
311 final String javaFileName = jImplRoot + File.separator +
tableClassName +
".java";
318 for (
final String imporT :
getConfig().imports()) {
326 tableJavaUnit.
emitln(
" * This table is a cache of pointers to the dynamically-linkable C library.");
329 for (
int i = 0; accessModifiers !=
null && i < accessModifiers.length; ++i) {
Emits the C-side component of the Java<->C JNI binding to its CodeUnit, see FunctionEmitter.
final MessageFormat getReturnValueCapacityExpression()
Get the expression for the capacity of the returned java.nio.Buffer.
final void setReturnValueCapacityExpression(final MessageFormat expression)
If this function returns a void* encapsulated in a java.nio.Buffer (or compound type wrapper),...
static String packageAsPath(final String packageName)
Given a java package name (e.g., "java.lang"), return the package as a directory path (i....
void emit(final String s)
boolean removeModifier(final EmissionModifier m)
boolean hasModifier(final EmissionModifier m)
void addModifier(final EmissionModifier m)
final MethodBinding getBinding()
Java code unit (a generated Java source file), covering multiple FunctionEmitter allowing to unify ou...
Parses and provides access to the contents of .cfg files for the JavaEmitter.
boolean isUnimplemented(final AliasedSymbol symbol)
Returns true if this function should be given a body which throws a run-time exception with an "unimp...
String getJavaOutputDir()
Returns the value that was specified by the configuration directive "JavaOutputDir",...
JavaCodeUnit openJavaUnit(final String filename, final String packageName, final String simpleClassName)
String getImplPackageName()
Returns the value that was specified by the configuration directive "ImplPackage",...
JavaConfiguration getConfig()
String[] getClassAccessModifiers(final String classFQName)
Emits the Java-side component (interface and.or implementation) of the Java<->C JNI binding to its Co...
static final EmissionModifier PRIVATE
void setEmitBody(final boolean emitBody)
Accessor for subclasses.
boolean signatureOnly()
Indicates whether this emitter will print only a signature, or whether it will emit Java code for the...
void setPrivateNativeMethod(final boolean v)
Accessor for subclasses.
static final EmissionModifier PUBLIC
static final EmissionModifier NATIVE
static final EmissionModifier PROTECTED
FunctionSymbol getCSymbol()
Returns the FunctionSymbol.
String getOrigName()
Return the original-name as set at creation.
Describes a function symbol, which includes the name and type.
ASTLocusTag getASTLocusTag()
Returns this instance's ASTLocusTag, if available, otherwise returns null.
Utility class for recording names of typedefs and structs.
boolean containsKey(final String key)
String getLocalProcAddressCallingConvention(final FunctionSymbol symbol)
String convertToFunctionPointerName(final String funcName)
A subclass of JavaEmitter that modifies the normal emission of C and Java code to allow dynamic looku...
List<? extends FunctionEmitter > generateMethodBindingEmitters(final FunctionSymbol sym)
Generate all appropriate Java bindings for the specified C function symbols.
String getFunctionPointerTypedefName(final FunctionSymbol sym)
Returns the name of the typedef for a pointer to the function represented by the argument as defined ...
void beginStructs(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, final Map< Type, Type > canonMap)
void beginFunctions(final TypeDictionary typedefDictionary, final TypeDictionary structDictionary, final Map< Type, Type > canonMap, final List< FunctionSymbol > cFunctions)
boolean hasFunctionPointerTypedef(final FunctionSymbol sym)
ProcAddressConfiguration getProcAddressConfig()
void generateModifiedEmitters(final CMethodBindingEmitter baseCEmitter, final List< FunctionEmitter > emitters)
void beginProcAddressTable()
void emitProcAddressTableEntryForString(final String str)
static final String PROCADDRESS_VAR_PREFIX
Must be synchronized w/ ProcAddressTable.PROCADDRESS_VAR_PREFIX !!!
static final String WRAP_PREFIX
boolean callThroughProcAddress(final FunctionSymbol sym)
JavaConfiguration createConfig()
Create the object that will read and store configuration information for this JavaEmitter.
String unsupportedExceptionType()
void endProcAddressTable()
void fixSecurityModifiers(final JavaMethodBindingEmitter javaEmitter)
If 'native', enforce 'private native' modifiers.
Set< String > emittedTableEntries
boolean needsModifiedEmitters(final FunctionSymbol sym)
String runtimeExceptionType()
JavaCodeUnit tableJavaUnit
void generateModifiedEmitters(final JavaMethodBindingEmitter baseJavaEmitter, final List< FunctionEmitter > emitters)
A specialization of JavaMethodBindingEmitter with knowledge of how to call through a function pointer...
Superclass for all generated ProcAddressTables.
void log(final Level level, final String msg)
See Logger#log(Level, String).