8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
19 module ALib.Expressions.Impl;
20 import ALib.Characters.Functions;
40 const char* dbgCallbackName,
49 std::make_tuple( callback, resultType, cti
ALIB_DBG(, dbgCallbackName) ) );
52 "Binary operator '{}' already defined for types <{}> (aka {})\n"
53 " and <{}> (aka {}).",
59 std::make_tuple( callback, resultType, cti
ALIB_DBG(, dbgCallbackName) ) );
67 #define OP std::get<0>( *(table + i) )
68 #define LHS_TYPE std::get<1>( *(table + i) ).TypeID()
69 #define RHS_TYPE std::get<2>( *(table + i) ).TypeID()
70 #define CBFUNC std::get<3>( *(table + i) )
71 #define RESULTTYPE std::get<ALIB_REL_DBG(4,5)>( *(table + i) )
72 #define CTINVOKE std::get<ALIB_REL_DBG(5,6)>( *(table + i) )
74 for(
size_t i= 0 ; i < length ; ++i ) {
79 std::make_tuple( CBFUNC, RESULTTYPE, CTINVOKE
80 ALIB_DBG(, std::get<4>( *(table + i) )) ) );
83 "Binary operator '{}' already defined for types <{}> (aka {})\n"
84 " and <{}> (aka {}).",
85 OP,
Cmplr.TypeName(std::get<1>( *(table+i))), &LHS_TYPE,
86 Cmplr.TypeName(std::get<2>( *(table+i))), &RHS_TYPE )
90 std::make_tuple( CBFUNC, RESULTTYPE, CTINVOKE
91 ALIB_DBG(, std::get<4>( *(table + i) )) ) );
96 "This is rather an internal error of HashTable: The number of buckets "
97 "of hash map 'Operators' increased, although it was reserved above." )
114 "Binary operator alias '{}' already defined for types <{}> (aka {})\n"
115 "and <{}> (aka {}).",
127 #define ALIAS std::get<0>( *(table + i) )
128 #define LHS_TYPE std::get<1>( *(table + i) ).TypeID()
129 #define RHS_TYPE std::get<2>( *(table + i) ).TypeID()
130 #define OP std::get<3>( *(table + i) )
132 for(
size_t i= 0 ; i < length ; ++i ) {
138 "Binary operator alias '{}' already defined for types <{}> (aka {})\n"
139 "and <{}> (aka {}).",
140 ALIAS,
Cmplr.TypeName( std::get<1>( *(table + i) ) ), &LHS_TYPE,
141 Cmplr.TypeName( std::get<2>( *(table + i) ) ), &RHS_TYPE )
166 ciUnaryOp.
Operator= aliasIt.Mapped();
171 auto opIt=
Operators.Find( key, hashCode );
175 auto& op= opIt.Mapped();
178 if( ciUnaryOp.
ArgIsConst && std::get<2>(op) ) {
185 "Type mismatch in definition of unary operator \"{}\" ({}) in plugin \"{}\".\n"
186 " Type specified: <{}> (aka {})\n"
187 " Type returned by callback: <{}> (aka {})",
190 &std::get<1>(op).TypeID(),
195 ciUnaryOp.
Callback = std::get<0>(op);
208 #define OP std::get<0>( *(table + i) )
209 #define SIDE std::get<1>( *(table + i) )
210 #define CONSTVAL std::get<2>( *(table + i) )
211 #define CONSTTYPE std::get<2>( *(table + i) ).TypeID()
212 #define OTHERBOX std::get<3>( *(table + i) )
213 #define OTHERTYPE std::get<3>( *(table + i) ).TypeID()
214 #define RESULT std::get<4>( *(table + i) )
216 for(
size_t i= 0 ; i < length ; ++i ) {
222 "Optimization already defined for operator \"{}\" with {!Lower}-hand "
223 "constant value \"{}\" of type <{}> (aka {}) and with "
224 "{!L}-hand type <{}> (aka {}).",
225 OP, SIDE, CONSTVAL,
Cmplr.TypeName(CONSTVAL), &CONSTTYPE,
256 ciBinaryOp.
Operator= aliasIt.Mapped();
259 #define CBFUNC std::get<0>(op)
260 #define RESULTTYPE std::get<1>(op)
261 #define CT_INVOKABLE std::get<2>(op)
263 # define DBG_CB_NAME std::get<3>(op)
267 auto opIt =
Operators.Find( key, hashCode );
271 auto& op= opIt.Mapped();
282 "Type mismatch in definition of binary operator \"{}\" ({}) of plugin \"{}\".\n"
283 " Type specified: <{}> (aka {})\n"
284 " Type returned by callback: <{}> (aka {})",
287 &RESULTTYPE .TypeID(),
309 if( entryIt.Mapped().IsType<
void>() )
340 if( ciFunction.
QtyArgs() == 0 ) {
342 if ( entry.Descriptor.Match( name ) ) {
356 ciFunction.
Name.
Reset( entry.Descriptor );
363 if( entry.Descriptor.Match( name ) ) {
365 size_t qtyGiven = ciFunction.
QtyArgs();
366 size_t qtyRequired = entry.SignatureLength;
367 bool isVariadic =
false;
368 if( entry.SignatureLength > 0 && ( entry.Signature[entry.SignatureLength - 1] ==
nullptr
369 || entry.Signature[entry.SignatureLength - 1]->IsType<
void>() ) )
375 size_t qtyShared = (std::min)( qtyGiven, qtyRequired );
376 bool sharedAreSameType =
true;
377 for(
size_t i= 0; i != qtyShared ; ++i )
378 sharedAreSameType&= ciFunction.
Arg(i).
IsSameType( *entry.Signature[i] );
381 if( !sharedAreSameType
382 || ( isVariadic ? qtyGiven < qtyRequired
383 : qtyGiven != qtyRequired ) )
387 Cmplr.WriteFunctionSignature( entry.Signature,
388 entry.SignatureLength,
398 && entry.Signature !=
nullptr
404 && entry.Signature ==
nullptr
410 ciFunction.
Name.
Reset( entry.Descriptor );
412 if( !entry.Callback ) {
425 "Type mismatch in definition of function \"{}\" ({}) in plugin \"{}\".\n"
426 " Type specified: <{}> (aka {})\n"
427 " Type returned by callback: <{}> (aka {})",
430 &entry.ResultType->TypeID(),
437 ciFunction.
Callback = entry.Callback;
457 for(
auto& entry : table ) {
459 if( !entry.Type.IsSameType( valueToCast ) )
463 bool operatorIsIn=
true;
464 if( entry.OperatorsAccepted !=
nullptr
465 && entry.OperatorsAccepted->size() > 0 )
468 for(
auto& op : *entry.OperatorsAccepted )
476 && entry.OperatorsDeclined !=
nullptr
477 && entry.OperatorsDeclined->size() > 0 )
479 for(
auto& op : *entry.OperatorsDeclined )
505 if( entry !=
nullptr ) {
533 entry= findAutoCastEntry(
AutoCasts, ciAutoCast, 1 );
534 if( entry !=
nullptr ) {
bool IsSameType(const Box &other) const
const std::type_info & TypeID() const
const Placeholder & Data() const
#define ALIB_CALLER_NULLED
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_IGNORE_UNUSED_MACRO
#define ALIB_ASSERT_ERROR(cond, domain,...)
Box(*)(Scope &scope, ArgIterator argsBegin, ArgIterator argsEnd) CallbackDecl
const alib::boxing::Box & Type
@ AllowEmptyParenthesesForIdentifierFunctions
@ AliasEqualsOperatorWithAssignOperator
@ AllowOmittingParenthesesOfParameterlessFunctions
@ MissingFunctionParentheses
@ IdentifierWithFunctionParentheses
StdVectorMA< Box >::iterator ArgIterator
@ Right
Denotes the right side of something.
@ Left
Denotes the left side of something.
@ Relative
Referring to a relative value.
LocalString< 256 > String256
Type alias name for TLocalString<character,256>.
lang::integer integer
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
exceptions::Exception Exception
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
bool RhsIsConst
Input: denotes if rhs argument is constant value.
String ReverseCastFunctionNameRhs
String ReverseCastFunctionName
const nchar * DbgCallbackNameRhs
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.
bool RhsIsConst
Input: Denotes if the rhs-argument is a constant value.
String & Operator
Input/Output: The binary operator symbol.
AString & Name
Input: The identifier name to search.
void AddFunctionsWithNonMatchingArguments(const String &signature)
String & Operator
Input/Output: The unary operator.
const nchar * DbgCallbackName
CallbackDecl Callback
Output: The native C++ callback function to be set by one of the plug-ins.
Compiler & Cmplr
The compiler that this plug-in is attached to.
StdVectorMA< Box > * Stack
static ALIB_DLL Box Integer
Sample type-box for integer types. (Precisely for type integer.)
An entry of the field AutoCasts. Defines auto-casts for custom types.
const char * DbgCallbackName
String ReverseCastFunctionName
Key type for operator hash maps Operators and OperatorAliases.
Hash functor for operator hash map.
Key type for operator hash maps Operators and OperatorAliases.
void AddOperatorAlias(const String &alias, Type lhsType, Type rhsType, const String &op)
HashMap< MonoAllocator, OperatorKey, std::tuple< CallbackDecl, Box, CTInvokable ALIB_DBG(, const char *) >, OperatorKey::Hash, OperatorKey::EqualTo > Operators
virtual ALIB_DLL bool TryCompilation(CIFunction &ciFunction) override
void AddOperatorAliases(OperatorAliasTableEntry(&table)[TCapacity])
const std::tuple< String, lang::Side, Type, const Box &, const Box & > BinaryOpOptimizationsTableEntry
std::vector< ConstantIdentifierEntry > ConstantIdentifiers
List of identifiers that return constant values to be compiled by this plug-in.
void AddBinaryOpOptimizations(BinaryOpOptimizationsTableEntry(&table)[TCapacity])
HashMap< MonoAllocator, BinOpOptKey, Box, BinOpOptKey::Hash, BinOpOptKey::EqualTo > BinaryOperatorOptimizations
std::vector< AutoCastEntry > AutoCasts
List of auto-casts to be compiled by this plug-in.
void AddOperators(OperatorTableEntry(&table)[TCapacity])
std::vector< FunctionEntry > Functions
List of functions to be compiled by this plug-in.
void AddOperator(const String &op, Type lhsType, Type rhsType, CallbackDecl callback, const char *dbgCallbackName, Type resultType, CTInvokable cti)
HashMap< MonoAllocator, OperatorKey, String, OperatorKey::Hash, OperatorKey::EqualTo > OperatorAliases
const std::tuple< String, Type, Type, String > OperatorAliasTableEntry
const std::tuple< String, Type, Type, CallbackDecl, Type, CTInvokable > OperatorTableEntry
detail::UnionIntegrals Integrals
Collection of integrals of different sizes, placed next to each other.
integer Array[2]
Array of 64-bit signed integrals of length two on 64-bit platform, one on a 32-bit platform.