Info struct for compiling a binary operator. This struct is used with method TryCompilation(CIBinaryOp&) to provide information to derived compiler plug-ins, as well as to receive information back.
Information about whether the arguments are constants is separately given for lhs and rhs with fields LhsIsConst and RhsIsConst.
If both flags evaluate to true
, operator callback functions that do not use context information from the scope (or otherwise rely on external or random data), should calculate the - then constant - result at compile-time and return a constant value instead of the callback method.
If exactly one of the argument is constant, then some operators might detect further possibilities of optimization. Such optimization is operator-specific but goes along the lines of the following samples:
term + 0 -> term term - 0 -> term term * 0 -> 0 term * 1 -> term term / 1 -> term term && false -> false term && true -> term term || true -> true term || false -> term
These cases have in common that the result of the operator is either a constant or equals the non-constant argument.
In both cases inherited field Callback
is to be left nullptr
. If the result is constant, inherited field TypeOrValue is to be set to the constant value. In the second case that the non-constant argument equals the result, this can be indicated by setting field NonConstArgIsResult to true
. In this case, the compiler will choose the non-constant argument and drop the other.
Definition at line 333 of file compilerplugin.hpp.
#include <compilerplugin.hpp>
Public Field Index: | |
bool | LhsIsConst |
Input: Denotes if the lhs-argument is a constant value. | |
bool | NonConstArgIsResult |
Output: Used with optimization, see this struct's documentation for more information. | |
String & | Operator |
Input/Output: The binary operator symbol. | |
bool | RhsIsConst |
Input: Denotes if the rhs-argument is a constant value. | |
Public Field Index: inherited from CompilerPlugin::CompilationInfo | |
ArgIterator | ArgsBegin |
ArgIterator | ArgsEnd |
CallbackDecl | Callback = nullptr |
Output: The native C++ callback function to be set by one of the plug-ins. | |
MonoAllocator & | CompileTimeAllocator |
Scope & | CompileTimeScope |
const nchar * | DbgCallbackName = nullptr |
Box | TypeOrValue = nullptr |
Public Method Index: | |
CIBinaryOp (Scope &scope, MonoAllocator &compileTimeAllocator, String &op, bool lhsIsConst, bool rhsIsConst) | |
Public Method Index: inherited from CompilerPlugin::CompilationInfo | |
CompilationInfo (Scope &scope, MonoAllocator &allocator) | |
bool LhsIsConst |
Input: Denotes if the lhs-argument is a constant value.
Definition at line 338 of file compilerplugin.hpp.
bool NonConstArgIsResult |
Output: Used with optimization, see this struct's documentation for more information.
Definition at line 344 of file compilerplugin.hpp.
String& Operator |
Input/Output: The binary operator symbol.
Definition at line 335 of file compilerplugin.hpp.
bool RhsIsConst |
Input: Denotes if the rhs-argument is a constant value.
Definition at line 341 of file compilerplugin.hpp.
|
inline |
Constructor.
scope | Passed to parent. |
compileTimeAllocator | Passed to parent. |
op | Stored in Operator. |
lhsIsConst | Stored in LhsIsConst. |
rhsIsConst | Stored in RhsIsConst. |
Definition at line 353 of file compilerplugin.hpp.