ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
No Matches
CompilerPlugin::CIAutoCast Struct Reference


Info struct for compiling automatic type casts. Such automatic cast is tried to be inserted into the expression program by the compiler if:

  • An unary operator for a type can not be found.
  • A binary operator for a combination of types can not be found.
  • Two different types for 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>

Inheritance diagram for CompilerPlugin::CIAutoCast:
Collaboration diagram for CompilerPlugin::CIAutoCast:

Public Field Index:

CallbackDecl CallbackRhs
const ncharDbgCallbackNameRhs
bool IsConst
String ReverseCastFunctionName
String ReverseCastFunctionNameRhs
bool RhsIsConst
Box TypeOrValueRhs
- Public Field Index: inherited from CompilerPlugin::CompilationInfo
ArgIterator ArgsBegin
ArgIterator ArgsEnd
CallbackDecl Callback = nullptr
const ncharDbgCallbackName = 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)

Field Details:

◆ CallbackRhs

CallbackDecl CallbackRhs

Output: Native C++ callback function to cast the first type with.

The optional callback function for casting the left-hand side type is returned with inherited field Callback .

Definition at line 482 of file compilerplugin.hpp.

◆ DbgCallbackNameRhs

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.

◆ IsConst

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.

◆ Operator

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.

◆ ReverseCastFunctionName

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.

◆ ReverseCastFunctionNameRhs

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.

◆ RhsIsConst

bool RhsIsConst

Input: denotes if rhs argument is constant value.

Definition at line 474 of file compilerplugin.hpp.

◆ TypeOrValueRhs

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.

The optional return type and value casting the left-hand side argument is returned with inherited field TypeOrValue .

Definition at line 493 of file compilerplugin.hpp.

Constructor(s) / Destructor Details::

◆ CIAutoCast()

CIAutoCast ( Scope & scope,
MonoAllocator & compileTimeAllocator,
String & op,
bool isConst,
bool rhsIsConst )


scopePassed to parent.
compileTimeAllocatorPassed to parent.
opStored in Operator.
isConstStored in IsConst.
rhsIsConstStored in RhsIsConst.

Definition at line 526 of file compilerplugin.hpp.

The documentation for this struct was generated from the following file: