Info struct for compiling automatic type casts. Such automatic cast is tried to be inserted into the expression program by the compiler if:
T
and F
were given with conditional operator Q ? T : F
.For which the scenarios a cast is needed can be determined with field Operator and also by checking the number of given arguments.
Built-in compiler plug-in AutoCast ignores unary operations. For binary operations, it just always tries to match both types to the 'major' one. It does this, as it is more probable, that for two same types an operator is available.
In contrast to this, a custom plug-in may choose to cast both values to a joint one or to any combination of types that it provides an operator for!
Compile-time optimization is supported with auto-casts the same as with other compilation mechanics. Information about whether the arguments are constants is separately given for the first and second argument with fields IsConst and RhsIsConst.
Hence, if a plug-in leaves the parent field Callback and/or field CallbackRhs nulled, but stores a constant casted result value in TypeOrValue and/or TypeOrValueRhs, then this is detected by the compiler and instead of inserting a cast function call, the original constant value is replaced with the returned constant value(s).
If a cast function is compiled (returned with this struct), and the resulting program should be duly "decompilable", then along with the callback information, a compilable expression function name has to be returned in field ReverseCastFunctionName, respectively ReverseCastFunctionNameRhs. For further information on this topic see 11.5.6 Optimized Expression Strings
Definition at line 459 of file compilerplugin.hpp.
#include <compilerplugin.hpp>
Public Field Index: | |
CallbackDecl | CallbackRhs |
const nchar * | DbgCallbackNameRhs |
bool | IsConst |
String & | Operator |
String | ReverseCastFunctionName |
String | ReverseCastFunctionNameRhs |
bool | RhsIsConst |
Box | TypeOrValueRhs |
Public Field Index: inherited from CompilerPlugin::CompilationInfo | |
ArgIterator | ArgsBegin |
ArgIterator | ArgsEnd |
CallbackDecl | Callback = nullptr |
MonoAllocator & | CompileTimeAllocator |
Scope & | CompileTimeScope |
const nchar * | DbgCallbackName = nullptr |
Box | TypeOrValue = nullptr |
Public Method Index: | |
CIAutoCast (Scope &scope, MonoAllocator &compileTimeAllocator, String &op, bool isConst, bool rhsIsConst) | |
Public Method Index: inherited from CompilerPlugin::CompilationInfo | |
CompilationInfo (Scope &scope, MonoAllocator &allocator) | |
CallbackDecl CallbackRhs |
Output: Native C++ callback function to cast the first type with.
Definition at line 482 of file compilerplugin.hpp.
const nchar* DbgCallbackNameRhs |
Output: The C++ name of the callback function. This field is available only in debug compilations of the library. Hence, setting it must be performed with preprocessor conditionals.
Definition at line 515 of file compilerplugin.hpp.
bool IsConst |
Input: denotes if the unary argument, respectively the lhs argument of a binary operator, is a constant value.
Definition at line 471 of file compilerplugin.hpp.
String& Operator |
The operator that the cast is required for. If this is '?:' then the request is made for conditional operator Q ? T : F
. In this case, the requirement is to cast both given arguments to the same type - otherwise, the conditional operator does not compile!
Definition at line 467 of file compilerplugin.hpp.
String ReverseCastFunctionName |
This is the name of the left-hand side cast function, respectively that of the unary argument's cast function, that is used when an expression with auto-cast functions is decompiled to generate compilable, optimized expression strings.
Definition at line 500 of file compilerplugin.hpp.
String ReverseCastFunctionNameRhs |
This is the name of the right-hand side cast function that is inserted when an expression with an auto-cast functions is decompiled to generate compilable, optimized expression strings.
Definition at line 507 of file compilerplugin.hpp.
bool RhsIsConst |
Input: denotes if rhs argument is constant value.
Definition at line 474 of file compilerplugin.hpp.
Box TypeOrValueRhs |
Output: Specifies the return type of CallbackRhs, respectively, as the name indicates, the result value in case of constant a result.
In case of constant compile-time values, it might be necessary to allocate compile-time memory for the values. For this, field CompileTimeScope is to be used.
Definition at line 493 of file compilerplugin.hpp.
|
inline |
Constructor.
scope | Passed to parent. |
compileTimeAllocator | Passed to parent. |
op | Stored in Operator. |
isConst | Stored in IsConst. |
rhsIsConst | Stored in RhsIsConst. |
Definition at line 526 of file compilerplugin.hpp.