The super class all compilers should extend from. The behavior of how the Haxe AST is transpiled is configured by implementing the abstract methods.
Constructor
Variables
dynamicTypeStack:Array<ModuleType> = []
Used internally with addModuleTypeForCompilation for the manualDCE option.
A stack of ModuleTypes yet to be processed.
dynamicTypesHandled:Array<String> = []
Used internally with addModuleTypeForCompilation for the manualDCE option.
A list of ModuleType unique identifiers that have been queued once.
Methods
addModuleTypeForCompilation(mt:ModuleType):Void
This function is to be used in conjunction with the manualDCE option.
With manualDCE enabled, types encountered while compiling should
be passed to this function to be added to the compilation queue.
Any repeats will NOT be re-queued, you are safe (as expected) to spam this function as much as you want.
You should essentially call this for: - The type of every variable compiled. - The type of every expression compiled. - All argument and return types for every function compiled.
Use addTypeForCompilation to pass a haxe.macro.Type instead.
addReservedVarName(name:String):Void
Manually adds a reserved variable name that cannot be used in the output.
addTypeForCompilation(type:Type):Bool
See addModuleTypeForCompilation.
Works the same as addModuleTypeForCompilation but takes a
haxe.macro.Type instead of haxe.macro.ModuleType.
Returns false if the haxe.macro.Type couldn't be converted
to haxe.macro.ModuleType.
appendToExtraFile(path:OutputPath, content:String, priority:Int = 0):Void
Set the content or append it if it already exists.
priority dictates where the content is appended relative to
other calls to these functions.
compileAbstract(classType:AbstractType):Void
A function intended to be overriden by your compiler class.
Compiles the provided abstract. Defined in GenericCompiler.
It ignores all abstracts by default since Haxe converts them to function calls.
compileClass(classType:ClassType, varFields:Array<ClassVarData>, funcFields:Array<ClassFuncData>):Void
A function required to be overriden by your compiler class.
Compiles the provided class. Defined in GenericCompiler.
Override this to configure the behavior.
compileEnum(enumType:EnumType, options:Array<EnumOptionData>):Void
A function required to be overriden by your compiler class.
Compiles the provided enum. Defined in GenericCompiler.
Override this to configure the behavior.
compileMetadata(metaAccess:Null<MetaAccess>, target:MetadataTarget):Null<String>
Compiles the Haxe metadata to the target's equivalent.
This function will always return null unless allowMetaMetadata
is true or metadataTemplates contains at least one entry.
compileTypedef(classType:DefType):Void
A function intended to be overriden by your compiler class.
Compiles the provided typedef. Defined in GenericCompiler.
It ignores all typedefs by default since Haxe redirects all types automatically.
compileVarName(name:String, ?expr:TypedExpr, ?field:ClassField):String
Compiles the provided variable name. Ensures it does not match any of the reserved variable names.
filterTypes(moduleTypes:Array<ModuleType>):Array<ModuleType>
A function intended to be overriden by your compiler class.
This is called once at the start of compilation.
moduleTypes is an array of ALL types supplied by the Haxe
compiler. Removing (or adding?) entries from this will
change what modules are sent to your compiler.
moduleTypes is a unique copy made specifically for this
function, so it is safe to modify directly and return it.
To enable the exact behavior supplied by the deprecated
smartDCE option, the following code can be used:
public override function filterTypes(moduleTypes: Array<ModuleType>): Array<ModuleType> {
final tracker = new reflaxe.input.ModuleUsageTracker(moduleTypes, this);
return tracker.filteredTypes(this.options.customStdMeta);
}generateFilesManually():Void
A function intended to be overriden by your compiler class.
This is called once at the end of compilation if
options.fileOutputType is set to Manual.
This is where you can generate your output files manually instead of relying on Reflaxe's default output system.
Files should be saved using output.saveFile(path, content)
generateInjectionExpression(content:String, ?position:Position):TypedExpr
Generates an "injection" expression if possible.
// For example:
generateInjectionExpression("const booty <= (1,2)");
// Returns a dynamically-typed `TypedExpr` for the expression:
untyped __LANG__("const booty <= (1,2)");generateOutputIterator():Iterator<DataAndFileInfo<StringOrBytes>>
Used to configure how output is generated automatically.
getExtraFileContent(path:OutputPath, priority:Int = 0):String
Returns the contents of the file if it exists.
priority dictates where the content is appended relative to
other calls to these functions.
Returns an empty string if nothing exists.
getMainExpr():Null<TypedExpr>
Returns the "main" typed expression for the program.
For example, if -main MyClass is set in the project, the expression
will be: MyClass.main().
Please note if using Haxe v4.2.5 or below, the main class must be
defined using -D mainClass. For example: -D mainClass=MyClass.
getMainModule():Null<ModuleType>
Extracts the ModuleType of the main class based on getMainExpr function.
onExpressionUnsuccessful(pos:Position):CompiledExpressionType
Given a haxe.macro.Position, generates an error at the position
stating: "Could not generate expression".
replaceInExtraFile(path:OutputPath, content:String, priority:Int = 0):Void
Set the content or append it if it already exists.
priority dictates where the content is appended relative to
other calls to these functions.
setExtraFile(path:OutputPath, content:String = ""):Void
Set all the content for an arbitrary file added to the output folder.
setExtraFileIfEmpty(path:OutputPath, content:String = ""):Void
Set all the content for a file if it doesn't exist yet.
setOutputFileDir(dir:Null<String>):Void
Use while compiling a module type (typically through one of the
BaseCompiler override methods like compileClassImpl) to set
the name of the file that will contain the output being generated.
Subdirectories can be used with the forward slash.
Setting to an empty String or null will result
in the file being generated in the top directory
(the output directory).
setOutputFileName(name:Null<String>):Void
Use while compiling a module type (typically through one of the
BaseCompiler override methods like compileClassImpl) to set
the name of the file that will contain the output being generated.
Setting to an empty String or null will result in the default
file name being used.
setupModule(mt:Null<ModuleType>):Void
Called before compileClass, compileEnum, etc. to set up fields to be referenced.
shouldGenerateClass(cls:ClassType):Bool
A function intended to be overriden by your compiler class.
This is called at the start of compilation for each class.
If false is returned, the class will not be sent to your
compiler later.
shouldGenerateClassField(cls:ClassField):Bool
A function intended to be overriden by your compiler class.
This is called at the start of compilation for each class field.
If false is returned, a ClassFuncData or ClassVarData will
not be generated for the field. The field will still be accessible
from the ClassType however.
shouldGenerateEnum(enumType:EnumType):Bool
A function intended to be overriden by your compiler class.
This is called at the start of compilation for each enum.
If false is returned, the enum will not be sent to your
compiler later.