16namespace alib {
namespace expressions {
namespace plugins {
26 const char* dbgCallbackName,
35 std::make_tuple( callback, resultType, cti
ALIB_DBG(, dbgCallbackName) ) );
38 "Binary operator {!Q'} already defined for types {!Q<>} (aka {})\n"
39 " and {!Q<>} (aka {}).",
45 std::make_tuple( callback, resultType, cti
ALIB_DBG(, dbgCallbackName) ) );
55 #define OP std::get<0>( *(table + i) )
56 #define LHS_TYPE std::get<1>( *(table + i) ).TypeID()
57 #define RHS_TYPE std::get<2>( *(table + i) ).TypeID()
58 #define CBFUNC std::get<3>( *(table + i) )
59 #define RESULTTYPE std::get<ALIB_REL_DBG(4,5)>( *(table + i) )
60 #define CTINVOKE std::get<ALIB_REL_DBG(5,6)>( *(table + i) )
62 for(
size_t i= 0 ; i < length ; ++i )
68 std::make_tuple( CBFUNC, RESULTTYPE, CTINVOKE
69 ALIB_DBG(, std::get<4>( *(table + i) )) ) );
72 "Binary operator {!Q'} already defined for types {!Q<>} (aka {})\n"
73 " and {!Q<>} (aka {}).",
79 std::make_tuple( CBFUNC, RESULTTYPE, CTINVOKE
80 ALIB_DBG(, std::get<4>( *(table + i) )) ) );
85 "This is rather an internal error of HashTable: The number of buckets "
86 "of hash map 'Operators' increased, although it was reserved above." )
105 "Binary operator alias {!Q'} already defined for types {!Q<>} (aka {})\n"
106 "and {!Q<>} (aka {}).",
120 #define ALIAS std::get<0>( *(table + i) )
121 #define LHS_TYPE std::get<1>( *(table + i) ).TypeID()
122 #define RHS_TYPE std::get<2>( *(table + i) ).TypeID()
123 #define OP std::get<3>( *(table + i) )
125 for(
size_t i= 0 ; i < length ; ++i )
132 "Binary operator alias {!Q'} already defined for types {!Q<>} (aka {})\n"
133 "and {!Q<>} (aka {}).",
134 ALIAS,
Cmplr.
TypeName( std::get<1>( *(table + i) ) ), LHS_TYPE,
162 ciUnaryOp.
Operator= aliasIt.Mapped();
167 auto opIt=
Operators.Find( key, hashCode );
171 auto& op= opIt.Mapped();
182 "Type mismatch in definition of unary operator {!Q} ({}) in plugin {!Q}.\n"
183 " Type specified: {!Q<>} (aka {})\n"
184 " Type returned by callback: {!Q<>} (aka {})",
187 std::get<1>(op).TypeID(),
192 ciUnaryOp.
Callback = std::get<0>(op);
207 #define OP std::get<0>( *(table + i) )
208 #define SIDE std::get<1>( *(table + i) )
209 #define CONSTVAL std::get<2>( *(table + i) )
210 #define CONSTTYPE std::get<2>( *(table + i) ).TypeID()
211 #define OTHERBOX std::get<3>( *(table + i) )
212 #define OTHERTYPE std::get<3>( *(table + i) ).TypeID()
213 #define RESULT std::get<4>( *(table + i) )
215 for(
size_t i= 0 ; i < length ; ++i )
222 "Optimization already defined for operator {!Q} with {!Lower}-hand "
223 "constant value {!Q} of type {!Q<>} (aka {}) and with "
224 "{!L}-hand type {!Q<>} (aka {}).",
260 ciBinaryOp.
Operator= aliasIt.Mapped();
263 #define CBFUNC std::get<0>(op)
264 #define RESULTTYPE std::get<1>(op)
265 #define CT_INVOKABLE std::get<2>(op)
267 # define DBG_CB_NAME std::get<3>(op)
271 auto opIt =
Operators.Find( key, hashCode );
275 auto& op= opIt.Mapped();
288 "Type mismatch in definition of binary operator {!Q} ({}) of plugin {!Q}.\n"
289 " Type specified: {!Q<>} (aka {})\n"
290 " Type returned by callback: {!Q<>} (aka {})",
293 RESULTTYPE .TypeID(),
318 if( entryIt.Mapped().IsType<
void>() )
351 if( ciFunction.
QtyArgs() == 0 )
355 if ( entry.Descriptor.Match( name ) )
370 ciFunction.
Name.
Reset( entry.Descriptor );
380 if( entry.Descriptor.Match( name ) )
384 size_t qtyGiven = ciFunction.
QtyArgs();
385 size_t qtyRequired = entry.SignatureLength;
386 bool isVariadic =
false;
387 if( entry.SignatureLength > 0 && ( entry.Signature[entry.SignatureLength - 1] ==
nullptr
388 || entry.Signature[entry.SignatureLength - 1]->IsType<
void>() ) )
394 size_t qtyShared = (std::min)( qtyGiven, qtyRequired );
395 bool sharedAreSameType =
true;
396 for(
size_t i= 0; i != qtyShared ; ++i )
397 sharedAreSameType&= ciFunction.
Arg(i).
IsSameType( *entry.Signature[i] );
401 if( !sharedAreSameType
402 || ( isVariadic ? qtyGiven < qtyRequired
403 : qtyGiven != qtyRequired ) )
408 entry.SignatureLength,
418 && entry.Signature !=
nullptr
424 && entry.Signature ==
nullptr
430 ciFunction.
Name.
Reset( entry.Descriptor );
432 if( !entry.Callback )
447 "Type mismatch in definition of function {!Q} ({}) in plugin {!Q}.\n"
448 " Type specified: {!Q<>} (aka {})\n"
449 " Type returned by callback: {!Q<>} (aka {})",
452 entry.ResultType->TypeID(),
459 ciFunction.
Callback = entry.Callback;
481 for(
auto& entry : table )
484 if( !entry.Type.IsSameType( valueToCast ) )
488 bool operatorIsIn=
true;
489 if( entry.OperatorsAccepted !=
nullptr
490 && entry.OperatorsAccepted->size() > 0 )
493 for(
auto& op : *entry.OperatorsAccepted )
503 && entry.OperatorsDeclined !=
nullptr
504 && entry.OperatorsDeclined->size() > 0 )
506 for(
auto& op : *entry.OperatorsDeclined )
537 if( entry !=
nullptr )
569 entry= findAutoCastEntry(
AutoCasts, ciAutoCast, 1 );
570 if( entry !=
nullptr )
bool IsSameType(const Box &other) const
const std::type_info & TypeID() const
const Placeholder & Data() const
ALIB_API NString TypeName(Type box)
Compilation CfgCompilation
Compilation flags.
ALIB_API void WriteFunctionSignature(Box **boxArray, size_t qty, AString &target)
#define ALIB_CALLER_NULLED
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_IGNORE_UNUSED_MACRO
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
StdVectorMono< Box >::iterator ArgIterator
@ AllowEmptyParenthesesForIdentifierFunctions
@ AliasEqualsOperatorWithAssignOperator
@ AllowOmittingParenthesesOfParameterlessFunctions
Box(*)(Scope &scope, ArgIterator argsBegin, ArgIterator argsEnd) CallbackDecl
@ MissingFunctionParentheses
@ IdentifierWithFunctionParentheses
@ Relative
Referring to a relative value.
@ Right
Denotes the right side of something.
@ Left
Denotes the left side of something.
lang::Exception Exception
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
String ReverseCastFunctionName
bool RhsIsConst
Input: denotes if rhs argument is constant value.
const nchar * DbgCallbackNameRhs
String ReverseCastFunctionNameRhs
String & Operator
Input/Output: The binary operator symbol.
bool LhsIsConst
Input: Denotes if the lhs-argument is a constant value.
bool RhsIsConst
Input: Denotes if the rhs-argument is a constant value.
bool NonConstArgIsResult
Output: Used with optimization, see this struct's documentation for more information.
void AddFunctionsWithNonMatchingArguments(const String &signature)
AString & Name
Input: The identifier name to search.
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.
StdVectorMono< Box > * Stack
static ALIB_API Box Integer
Sample type-box for integer types. (Precisely for type integer.)
An entry of the field AutoCasts. Defines auto-casts for custom types.
String ReverseCastFunctionName
const char * DbgCallbackName
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 AddOperatorAliases(OperatorAliasTableEntry(&table)[TCapacity])
virtual ALIB_API bool TryCompilation(CIFunction &ciFunction) override
std::vector< ConstantIdentifierEntry > ConstantIdentifiers
List of identifiers that return constant values to be compiled by this plug-in.
void AddOperators(OperatorTableEntry(&table)[TCapacity])
void AddBinaryOpOptimizations(BinaryOpOptimizationsTableEntry(&table)[TCapacity])
const std::tuple< String, Type, Type, CallbackDecl, Type, CTInvokable > OperatorTableEntry
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)
std::vector< AutoCastEntry > AutoCasts
List of auto-casts to be compiled by this plug-in.
HashMap< MonoAllocator, OperatorKey, std::tuple< CallbackDecl, Box, CTInvokable ALIB_DBG(, const char *) >, OperatorKey::Hash, OperatorKey::EqualTo > Operators
const std::tuple< String, lang::Side, Type, const Box &, const Box & > BinaryOpOptimizationsTableEntry
const std::tuple< String, Type, Type, String > OperatorAliasTableEntry
HashMap< MonoAllocator, OperatorKey, String, OperatorKey::Hash, OperatorKey::EqualTo > OperatorAliases
void AddOperatorAlias(const String &alias, Type lhsType, Type rhsType, const String &op)
HashMap< MonoAllocator, BinOpOptKey, Box, BinOpOptKey::Hash, BinOpOptKey::EqualTo > BinaryOperatorOptimizations
ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE constexpr integer GetInteger(int idx) const