Package com.jogamp.gluegen
Class JavaEmitter
java.lang.Object
com.jogamp.gluegen.JavaEmitter
- All Implemented Interfaces:
GlueEmitter
- Direct Known Subclasses:
CStructAnnotationProcessor.AnnotationProcessorJavaStructEmitter,ProcAddressEmitter
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumStyle of code emission.static enumAccess control for emitted Java methods. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intaddStrings2Buffer(StringBuilder buf, String sep, String first, Collection<String> col) voidvoidbeginEmission(GlueEmitterControls controls) Begin the emission of glue code.voidbeginFunctions(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type, Type> canonMap) voidBegins the process of computing field offsets and type sizes for the structs to be emitted.voidbeginStructs(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type, Type> canonMap) protected StringFor#cImplWriterprotected JavaConfigurationCreate the object that will read and store configuration information for this JavaEmitter.protected PrintWritercWriter()protected voidWrite out any footer information for the output files (closing brace of class definition, etc).protected voidWrite out any header information for the output files (class declaration and opening brace, import statements, etc).protected voidemitCHeader(PrintWriter cWriter, String packageName, String className) protected voidemitCInitCode(PrintWriter cWriter, String packageName, String className) protected voidemitCustomJavaCode(PrintWriter writer, String className) Emit all the strings specified in the "CustomJavaCode" parameters of the configuration file.voidemitDefine(ConstantDefinition def, String optionalComment) emitFunctions(List<FunctionSymbol> funcsToBind) Emit glue code for the list of FunctionSymbols.protected voidemitJavaInitCode(PrintWriter jWriter, String className) voidemitStruct(CompoundType structCType, Type structCTypedefPtr) Emit glue code for the given CompoundType.voidvoidFinish the emission of glue code.voidvoidFinishes the struct layout process.voidprotected List<MethodBinding>expandMethodBinding(MethodBinding binding) protected List<? extends FunctionEmitter>Generate all appropriate Java bindings for the specified C function symbols.protected voidgeneratePrivateEmitters(MethodBinding binding, List<FunctionEmitter> allEmitters) Generates the private emitters for this MethodBinding.protected voidgeneratePublicEmitters(MethodBinding binding, List<FunctionEmitter> allEmitters, boolean signatureOnly) Generates the public emitters for this MethodBinding which will produce either simply signatures (for the interface class, if any) or function definitions with or without a body (depending on whether or not the implementing function can go directly to native code because it doesn't need any processing of the outgoing arguments).String[]getClassAccessModifiers(String classFQName) protected JavaConfigurationGet the configuration information for this JavaEmitter.protected StringReturns the value that was specified by the configuration directive "ImplPackage", or the default if none was specified.protected StringReturns the value that was specified by the configuration directive "JavaOutputDir", or the default if none was specified.protected StringReturns the value that was specified by the configuration directive "Package", or the default if none was specified.protected static StringgetJNIMethodNamePrefix(String javaPackageName, String javaClassName) Returns the JNI method prefix consisting our of mangled package- and class-nameprotected StringForjavaWriterorjavaImplWriterprotected PrintWriterprotected PrintWriterprotected static StringMangle a class, package or function name for JNI usage, i.e.voidLays out one struct which will be emitted later.protected voidmangleBinding(MethodBinding binding) Allow specializations to modify the givenMethodBindingbeforeexpandingand emission.protected PrintWriterprotected voidprepCEmitter(String returnSizeLookupName, JavaType javaReturnType, CMethodBindingEmitter cEmitter) voidreadConfigurationFile(String filename) protected final booleanrequiresStaticInitialization(String clazzName) Returnstrueif implementation (java and native-code) requiresstaticClassInitCodeCCodeandstaticClassInitCallJavaCodeand haveinitializeImpl()being called at static class initialization.
-
Field Details
-
cfg
-
LOG
-
-
Constructor Details
-
JavaEmitter
public JavaEmitter()
-
-
Method Details
-
readConfigurationFile
- Specified by:
readConfigurationFilein interfaceGlueEmitter- Throws:
Exception
-
getConfiguration
- Specified by:
getConfigurationin interfaceGlueEmitter
-
beginEmission
Description copied from interface:GlueEmitterBegin the emission of glue code. This might include opening files, emitting class headers, etc.- Specified by:
beginEmissionin interfaceGlueEmitter- Throws:
IOException
-
endEmission
public void endEmission()Description copied from interface:GlueEmitterFinish the emission of glue code. This might include closing files, closing open class definitions, etc.- Specified by:
endEmissionin interfaceGlueEmitter
-
beginDefines
- Specified by:
beginDefinesin interfaceGlueEmitter- Throws:
Exception
-
jniMangle
Mangle a class, package or function name for JNI usage, i.e. replace all '.' w/ '_' -
getJNIMethodNamePrefix
Returns the JNI method prefix consisting our of mangled package- and class-name -
emitDefine
- Specified by:
emitDefinein interfaceGlueEmitteroptionalComment- If optionalComment is non-null, the emitter can emit that string as a comment providing extra information about the define.- Throws:
Exception
-
endDefines
- Specified by:
endDefinesin interfaceGlueEmitter- Throws:
Exception
-
beginFunctions
public void beginFunctions(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type, Type> canonMap) throws Exception- Specified by:
beginFunctionsin interfaceGlueEmitter- Throws:
Exception
-
emitFunctions
Description copied from interface:GlueEmitterEmit glue code for the list of FunctionSymbols.- Specified by:
emitFunctionsin interfaceGlueEmitter- Throws:
Exception
-
createConfig
Create the object that will read and store configuration information for this JavaEmitter. -
getConfig
Get the configuration information for this JavaEmitter. -
requiresStaticInitialization
Returnstrueif implementation (java and native-code) requiresstaticClassInitCodeCCodeandstaticClassInitCallJavaCodeand haveinitializeImpl()being called at static class initialization.This is currently true, if one of the following method returns
true -
generatePublicEmitters
protected void generatePublicEmitters(MethodBinding binding, List<FunctionEmitter> allEmitters, boolean signatureOnly) Generates the public emitters for this MethodBinding which will produce either simply signatures (for the interface class, if any) or function definitions with or without a body (depending on whether or not the implementing function can go directly to native code because it doesn't need any processing of the outgoing arguments). -
generatePrivateEmitters
Generates the private emitters for this MethodBinding. On the Java side these will simply produce signatures for native methods. On the C side these will create the emitters which will write the JNI code to interface to the functions. We need to be careful to make the signatures all match up and not produce too many emitters which would lead to compilation errors from creating duplicated methods / functions. -
prepCEmitter
protected void prepCEmitter(String returnSizeLookupName, JavaType javaReturnType, CMethodBindingEmitter cEmitter) -
generateMethodBindingEmitters
protected List<? extends FunctionEmitter> generateMethodBindingEmitters(FunctionSymbol sym) throws Exception Generate all appropriate Java bindings for the specified C function symbols.- Throws:
Exception
-
endFunctions
- Specified by:
endFunctionsin interfaceGlueEmitter- Throws:
Exception
-
beginStructLayout
Description copied from interface:GlueEmitterBegins the process of computing field offsets and type sizes for the structs to be emitted.- Specified by:
beginStructLayoutin interfaceGlueEmitter- Throws:
Exception
-
layoutStruct
Description copied from interface:GlueEmitterLays out one struct which will be emitted later.- Specified by:
layoutStructin interfaceGlueEmitter- Throws:
Exception
-
endStructLayout
Description copied from interface:GlueEmitterFinishes the struct layout process.- Specified by:
endStructLayoutin interfaceGlueEmitter- Throws:
Exception
-
beginStructs
public void beginStructs(TypeDictionary typedefDictionary, TypeDictionary structDictionary, Map<Type, Type> canonMap) throws Exception- Specified by:
beginStructsin interfaceGlueEmitter- Throws:
Exception
-
emitStruct
Description copied from interface:GlueEmitterEmit glue code for the given CompoundType. typedefType is provided when the CompoundType (e.g. "struct foo_t") has not been typedefed to anything but the type of "pointer to struct foo_t" has (e.g. "typedef struct foo_t {} *Foo"); in this case typedefType would be set to pointer type Foo.- Specified by:
emitStructin interfaceGlueEmitter- Throws:
Exception
-
endStructs
- Specified by:
endStructsin interfaceGlueEmitter- Throws:
Exception
-
addStrings2Buffer
public static int addStrings2Buffer(StringBuilder buf, String sep, String first, Collection<String> col) -
openFile
- Parameters:
filename- the class's full filename to open w/ write accesssimpleClassName- the simple class name, i.e. w/o package name- Returns:
- a
PrintWriterinstance to write the class source file ornullto suppress output! - Throws:
IOException
-
javaFileName
ForjavaWriterorjavaImplWriter -
javaWriter
-
javaImplWriter
-
cFileName
For#cImplWriter -
cWriter
-
getJavaOutputDir
Returns the value that was specified by the configuration directive "JavaOutputDir", or the default if none was specified. -
getJavaPackageName
Returns the value that was specified by the configuration directive "Package", or the default if none was specified. -
getImplPackageName
Returns the value that was specified by the configuration directive "ImplPackage", or the default if none was specified. -
emitCustomJavaCode
Emit all the strings specified in the "CustomJavaCode" parameters of the configuration file.- Throws:
Exception
-
getClassAccessModifiers
-
emitAllFileHeaders
Write out any header information for the output files (class declaration and opening brace, import statements, etc).- Throws:
IOException
-
emitCHeader
-
emitCInitCode
-
emitJavaInitCode
-
mangleBinding
Allow specializations to modify the givenMethodBindingbeforeexpandingand emission. -
expandMethodBinding
-