Commit a49fd9c0 authored by Ing. Jan Trávníček's avatar Ing. Jan Trávníček

operator registering facility and int operators

parent f30dded7
......@@ -27,6 +27,51 @@ std::shared_ptr < abstraction::Value > EvalHelper::evalAlgorithm ( const std::st
}
}
std::shared_ptr < abstraction::Value > EvalHelper::evalOperator ( Operators::BinaryOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, const std::vector < bool > & moves, AlgorithmCategories::AlgorithmCategory category ) {
ext::vector < std::string > paramTypes;
ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > paramTypeQualifiers;
for ( const std::shared_ptr < abstraction::Value > & param : params ) {
paramTypes.push_back ( param->getType ( ) );
paramTypeQualifiers.push_back ( param->getTypeQualifiers ( ) );
}
try {
return evalAbstraction ( Registry::getBinaryOperatorAbstraction ( type, paramTypes, paramTypeQualifiers, category ), params, moves );
} catch ( ... ) {
std::throw_with_nested ( std::runtime_error ( "Evaluation of binary operator " + Operators::toString ( type ) + " failed." ) );
}
}
std::shared_ptr < abstraction::Value > EvalHelper::evalOperator ( Operators::PrefixOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, const std::vector < bool > & moves, AlgorithmCategories::AlgorithmCategory category ) {
ext::vector < std::string > paramTypes;
ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > paramTypeQualifiers;
for ( const std::shared_ptr < abstraction::Value > & param : params ) {
paramTypes.push_back ( param->getType ( ) );
paramTypeQualifiers.push_back ( param->getTypeQualifiers ( ) );
}
try {
return evalAbstraction ( Registry::getPrefixOperatorAbstraction ( type, paramTypes, paramTypeQualifiers, category ), params, moves );
} catch ( ... ) {
std::throw_with_nested ( std::runtime_error ( "Evaluation of prefix operator " + Operators::toString ( type ) + " failed." ) );
}
}
std::shared_ptr < abstraction::Value > EvalHelper::evalOperator ( Operators::PostfixOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, const std::vector < bool > & moves, AlgorithmCategories::AlgorithmCategory category ) {
ext::vector < std::string > paramTypes;
ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > paramTypeQualifiers;
for ( const std::shared_ptr < abstraction::Value > & param : params ) {
paramTypes.push_back ( param->getType ( ) );
paramTypeQualifiers.push_back ( param->getTypeQualifiers ( ) );
}
try {
return evalAbstraction ( Registry::getPostfixOperatorAbstraction ( type, paramTypes, paramTypeQualifiers, category ), params, moves );
} catch ( ... ) {
std::throw_with_nested ( std::runtime_error ( "Evaluation of postfix operator " + Operators::toString ( type ) + " failed." ) );
}
}
std::shared_ptr < abstraction::Value > EvalHelper::evalAbstraction ( std::shared_ptr < abstraction::OperationAbstraction > abstraction, const ext::vector < std::shared_ptr < abstraction::Value > > & params, const std::vector < bool > & moves ) {
unsigned i = 0;
ext::vector < std::shared_ptr < abstraction::Value > > casted_params;
......
......@@ -12,6 +12,7 @@
#include <alib/memory>
#include <alib/vector>
#include <common/AlgorithmCategories.hpp>
#include <common/Operators.hpp>
#include <abstraction/Value.hpp>
namespace abstraction {
......@@ -21,6 +22,12 @@ class EvalHelper {
public:
static std::shared_ptr < abstraction::Value > evalAlgorithm ( const std::string & name, const ext::vector < std::string > & templateParams, const ext::vector < std::shared_ptr < abstraction::Value > > & params, const std::vector < bool > & moves, AlgorithmCategories::AlgorithmCategory category );
static std::shared_ptr < abstraction::Value > evalOperator ( Operators::BinaryOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, const std::vector < bool > & moves, AlgorithmCategories::AlgorithmCategory category );
static std::shared_ptr < abstraction::Value > evalOperator ( Operators::PrefixOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, const std::vector < bool > & moves, AlgorithmCategories::AlgorithmCategory category );
static std::shared_ptr < abstraction::Value > evalOperator ( Operators::PostfixOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, const std::vector < bool > & moves, AlgorithmCategories::AlgorithmCategory category );
};
} /* namespace abstraction */
......
#include <common/Operators.hpp>
namespace abstraction {
std::ostream & operator << ( std::ostream & os, Operators::BinaryOperators oper ) {
return os << Operators::toString ( oper );
}
std::ostream & operator << ( std::ostream & os, Operators::PrefixOperators oper ) {
return os << Operators::toString ( oper );
}
std::ostream & operator << ( std::ostream & os, Operators::PostfixOperators oper ) {
return os << Operators::toString ( oper );
}
} /* namespace abstraction */
#ifndef _OPERATORS_HPP_
#define _OPERATORS_HPP_
#include <alib/string>
namespace abstraction {
class Operators {
public:
enum class BinaryOperators {
LOGICAL_AND,
LOGICAL_OR,
BINARY_XOR,
BINARY_AND,
BINARY_OR,
ADD,
SUB,
MUL,
MOD,
DIV,
EQUALS,
NOT_EQUALS,
LESS,
LESS_OR_EQUAL,
MORE,
MORE_OR_EQUAL,
ASSIGN
};
enum class PrefixOperators {
PLUS,
MINUS,
LOGICAL_NOT,
BINARY_NEG,
INCREMENT,
DECREMENT
};
enum class PostfixOperators {
INCREMENT,
DECREMENT
};
static std::string toString ( BinaryOperators type ) {
switch ( type ) {
case BinaryOperators::BINARY_AND :
return "binary_and";
case BinaryOperators::BINARY_OR :
return "binary_or";
case BinaryOperators::BINARY_XOR :
return "binary_xor";
case BinaryOperators::LOGICAL_AND :
return "logical_and";
case BinaryOperators::LOGICAL_OR :
return "logical_or";
case BinaryOperators::ADD :
return "add";
case BinaryOperators::SUB :
return "sub";
case BinaryOperators::MUL :
return "mul";
case BinaryOperators::MOD :
return "mod";
case BinaryOperators::DIV :
return "div";
case BinaryOperators::EQUALS :
return "equals";
case BinaryOperators::NOT_EQUALS :
return "not_equals";
case BinaryOperators::LESS :
return "less";
case BinaryOperators::LESS_OR_EQUAL :
return "less_or_equal";
case BinaryOperators::MORE :
return "more";
case BinaryOperators::MORE_OR_EQUAL :
return "more_or_equal";
case BinaryOperators::ASSIGN :
return "assign";
}
throw std::invalid_argument ( "Undefined option" );
}
static std::string toString ( PrefixOperators type ) {
switch ( type ) {
case PrefixOperators::PLUS :
return "plus";
case PrefixOperators::MINUS :
return "minus";
case PrefixOperators::LOGICAL_NOT :
return "logical_not";
case PrefixOperators::BINARY_NEG :
return "binary_neg";
case PrefixOperators::INCREMENT :
return "increment";
case PrefixOperators::DECREMENT :
return "decrement";
}
throw std::invalid_argument ( "Undefined option" );
}
static std::string toString ( PostfixOperators type ) {
switch ( type ) {
case PostfixOperators::INCREMENT :
return "increment";
case PostfixOperators::DECREMENT :
return "decrement";
}
throw std::invalid_argument ( "Undefined option" );
}
};
std::ostream & operator << ( std::ostream & os, Operators::BinaryOperators oper );
std::ostream & operator << ( std::ostream & os, Operators::PrefixOperators oper );
std::ostream & operator << ( std::ostream & os, Operators::PostfixOperators oper );
} /* namespace abstraction */
#endif // _OPERATORS_HPP_
#ifndef _OPERATOR_REGISTRATION_HPP_
#define _OPERATOR_REGISTRATION_HPP_
#include <alib/registration>
#include <registry/OperatorRegistry.hpp>
namespace registration {
template < abstraction::Operators::BinaryOperators Type, class FirstParamType, class SecondParamType >
class BinaryOperatorRegister : public ext::Register < void > {
public:
template < class ReturnType >
BinaryOperatorRegister ( ReturnType ( * callback ) ( FirstParamType, SecondParamType ) ) : ext::Register < void > ( [ = ] ( ) {
abstraction::OperatorRegistry::registerBinary < ReturnType, FirstParamType, SecondParamType > ( Type, callback );
}, [ ] ( ) {
abstraction::OperatorRegistry::unregisterBinary < FirstParamType, SecondParamType > ( Type );
} ) {
}
BinaryOperatorRegister ( ) : ext::Register < void > ( [ ] ( ) {
abstraction::OperatorRegistry::registerBinary < Type, FirstParamType, SecondParamType > ( );
}, [ ] ( ) {
abstraction::OperatorRegistry::unregisterBinary < FirstParamType, SecondParamType > ( Type );
} ) {
}
};
template < abstraction::Operators::PrefixOperators Type, class ParamType >
class PrefixOperatorRegister : public ext::Register < void > {
public:
template < class ReturnType >
PrefixOperatorRegister ( ReturnType ( * callback ) ( ParamType ) ) : ext::Register < void > ( [ = ] ( ) {
abstraction::OperatorRegistry::registerPrefix < ReturnType, ParamType > ( Type, callback );
}, [ ] ( ) {
abstraction::OperatorRegistry::unregisterBinary < ParamType > ( Type );
} ) {
}
PrefixOperatorRegister ( ) : ext::Register < void > ( [ ] ( ) {
abstraction::OperatorRegistry::registerPrefix < Type, ParamType > ( );
}, [ ] ( ) {
abstraction::OperatorRegistry::unregisterPrefix < ParamType > ( Type );
} ) {
}
};
template < abstraction::Operators::PostfixOperators Type, class ParamType >
class PostfixOperatorRegister : public ext::Register < void > {
public:
template < class ReturnType >
PostfixOperatorRegister ( ReturnType ( * callback ) ( ParamType ) ) : ext::Register < void > ( [ = ] ( ) {
abstraction::OperatorRegistry::registerPostfix < ReturnType, ParamType > ( Type, callback );
}, [ ] ( ) {
abstraction::OperatorRegistry::unregisterBinary < ParamType > ( Type );
} ) {
}
PostfixOperatorRegister ( ) : ext::Register < void > ( [ ] ( ) {
abstraction::OperatorRegistry::registerPostfix < Type, ParamType > ( );
}, [ ] ( ) {
abstraction::OperatorRegistry::unregisterPostfix < ParamType > ( Type );
} ) {
}
};
} /* namespace registration */
#endif // _OPERATOR_REGISTRATION_HPP_
......@@ -9,7 +9,6 @@
#define _ALGORITHM_REGISTRY_INFO_HPP_
#include <alib/vector>
#include <alib/set>
#include <alib/pair>
#include <alib/typeinfo>
#include <alib/tuple>
......@@ -74,6 +73,15 @@ public:
return AlgorithmBaseInfo ( category, std::move ( params ) );
}
template < class ... ParamTypes >
static AlgorithmBaseInfo operatorEntryInfo ( ) {
AlgorithmCategories::AlgorithmCategory category = AlgorithmCategories::AlgorithmCategory::DEFAULT;
ext::vector < ext::tuple < std::string, abstraction::ParamQualifiers::ParamQualifierSet > > params = convertTypes < ParamTypes ... > ( );
return AlgorithmBaseInfo ( category, std::move ( params ) );
}
};
class AlgorithmFullInfo : public AlgorithmBaseInfo {
......@@ -124,6 +132,23 @@ public:
return AlgorithmFullInfo ( AlgorithmBaseInfo::wrapperEntryInfo < ParamTypes ... > ( ), std::move ( parameterNames ), std::move ( result ) );
}
template < class ReturnType, class ... ParamTypes >
static AlgorithmFullInfo operatorEntryInfo ( ) {
ext::pair < std::string, abstraction::ParamQualifiers::ParamQualifierSet > result = convertType < ReturnType > ( );
ext::vector < std::string > parameterNames;
if constexpr ( sizeof ... ( ParamTypes ) == 1 ) {
parameterNames.push_back ( "arg" );
} else if constexpr ( sizeof ... ( ParamTypes ) == 2 ) {
parameterNames.push_back ( "lhs" );
parameterNames.push_back ( "rhs" );
} else {
static_assert ( "Invalid number of params or operator" );
}
return AlgorithmFullInfo ( AlgorithmBaseInfo::operatorEntryInfo < ParamTypes ... > ( ), std::move ( parameterNames ), std::move ( result ) );
}
};
} /* namespace abstraction */
......
/*
* OperatorRegistry.cpp
*
* Created on: 19. 8. 2017
* Author: Jan Travnicek
*/
#include <registry/OperatorRegistry.hpp>
#include <registry/CastRegistry.hpp>
#include <alib/foreach>
#include <alib/algorithm>
#include <exception>
#include <common/OverloadResolution.hpp>
namespace abstraction {
ext::map < Operators::BinaryOperators, ext::list < std::unique_ptr < OperatorRegistry::BinaryEntry > > > & OperatorRegistry::getBinaryEntries ( ) {
static ext::map < Operators::BinaryOperators, ext::list < std::unique_ptr < BinaryEntry > > > algorithmGroups;
return algorithmGroups;
}
bool OperatorRegistry::isRegisteredBinary ( Operators::BinaryOperators type, const AlgorithmBaseInfo & entryInfo ) {
auto & group = getBinaryEntries ( ) [ type ];
for ( const std::unique_ptr < BinaryEntry > & entry : group )
if ( entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( ) )
return true;
return false;
}
void OperatorRegistry::registerBinaryInternal ( Operators::BinaryOperators type, std::unique_ptr < BinaryEntry > value ) {
if ( isRegisteredBinary ( type, value->getEntryInfo ( ) ) )
throw std::invalid_argument ( "Callback for operator " + Operators::toString ( type ) + " with params " + ext::to_string ( value->getEntryInfo ( ).getParams ( ) ) + " already registered." );
auto & group = getBinaryEntries ( ) [ type ];
group.insert ( group.end ( ), std::move ( value ) );
}
void OperatorRegistry::unregisterBinaryInternal ( Operators::BinaryOperators type, const AlgorithmBaseInfo & entryInfo ) {
auto & group = getBinaryEntries ( ) [ type ];
auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const std::unique_ptr < BinaryEntry > & entry ) {
return entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( );
} );
if ( iter == group.end ( ) )
throw std::invalid_argument ( "Entry for operator " + Operators::toString ( type ) + " with parameters " + ext::to_string ( entryInfo.getParams ( ) ) + " not registered." );
group.erase ( iter );
if ( group.empty ( ) )
getBinaryEntries ( ).erase ( type );
}
std::shared_ptr < abstraction::OperationAbstraction > OperatorRegistry::getBinaryAbstraction ( Operators::BinaryOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
auto & group = getBinaryEntries ( ) [ type ];
return getOverload ( group, paramTypes, paramQualifiers, category );
}
ext::list < ext::pair < Operators::BinaryOperators, AlgorithmFullInfo > > OperatorRegistry::listBinaryOverloads ( ) {
auto & group = getBinaryEntries ( );
ext::list < ext::pair < Operators::BinaryOperators, AlgorithmFullInfo > > res;
for ( const std::pair < const Operators::BinaryOperators, ext::list < std::unique_ptr < BinaryEntry > > > & overloads : group )
for ( const std::unique_ptr < BinaryEntry > & entry : overloads.second )
res.push_back ( ext::make_pair ( overloads.first, entry->getEntryInfo ( ) ) );
return res;
}
ext::map < Operators::PrefixOperators, ext::list < std::unique_ptr < OperatorRegistry::PrefixEntry > > > & OperatorRegistry::getPrefixEntries ( ) {
static ext::map < Operators::PrefixOperators, ext::list < std::unique_ptr < PrefixEntry > > > algorithmGroups;
return algorithmGroups;
}
bool OperatorRegistry::isRegisteredPrefix ( Operators::PrefixOperators type, const AlgorithmBaseInfo & entryInfo ) {
auto & group = getPrefixEntries ( ) [ type ];
for ( const std::unique_ptr < PrefixEntry > & entry : group )
if ( entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( ) )
return true;
return false;
}
void OperatorRegistry::registerPrefixInternal ( Operators::PrefixOperators type, std::unique_ptr < PrefixEntry > value ) {
if ( isRegisteredPrefix ( type, value->getEntryInfo ( ) ) )
throw std::invalid_argument ( "Callback for operator " + Operators::toString ( type ) + " with params " + ext::to_string ( value->getEntryInfo ( ).getParams ( ) ) + " already registered." );
auto & group = getPrefixEntries ( ) [ type ];
group.insert ( group.end ( ), std::move ( value ) );
}
void OperatorRegistry::unregisterPrefixInternal ( Operators::PrefixOperators type, const AlgorithmBaseInfo & entryInfo ) {
auto & group = getPrefixEntries ( ) [ type ];
auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const std::unique_ptr < PrefixEntry > & entry ) {
return entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( );
} );
if ( iter == group.end ( ) )
throw std::invalid_argument ( "Entry for operator " + Operators::toString ( type ) + " with parameters " + ext::to_string ( entryInfo.getParams ( ) ) + " not registered." );
group.erase ( iter );
if ( group.empty ( ) )
getPrefixEntries ( ).erase ( type );
}
std::shared_ptr < abstraction::OperationAbstraction > OperatorRegistry::getPrefixAbstraction ( Operators::PrefixOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
auto & group = getPrefixEntries ( ) [ type ];
return getOverload ( group, paramTypes, paramQualifiers, category );
}
ext::list < ext::pair < Operators::PrefixOperators, AlgorithmFullInfo > > OperatorRegistry::listPrefixOverloads ( ) {
auto & group = getPrefixEntries ( );
ext::list < ext::pair < Operators::PrefixOperators, AlgorithmFullInfo > > res;
for ( const std::pair < const Operators::PrefixOperators, ext::list < std::unique_ptr < PrefixEntry > > > & overloads : group )
for ( const std::unique_ptr < PrefixEntry > & entry : overloads.second )
res.push_back ( ext::make_pair ( overloads.first, entry->getEntryInfo ( ) ) );
return res;
}
ext::map < Operators::PostfixOperators, ext::list < std::unique_ptr < OperatorRegistry::PostfixEntry > > > & OperatorRegistry::getPostfixEntries ( ) {
static ext::map < Operators::PostfixOperators, ext::list < std::unique_ptr < PostfixEntry > > > algorithmGroups;
return algorithmGroups;
}
bool OperatorRegistry::isRegisteredPostfix ( Operators::PostfixOperators type, const AlgorithmBaseInfo & entryInfo ) {
auto & group = getPostfixEntries ( ) [ type ];
for ( const std::unique_ptr < PostfixEntry > & entry : group )
if ( entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( ) )
return true;
return false;
}
void OperatorRegistry::registerPostfixInternal ( Operators::PostfixOperators type, std::unique_ptr < PostfixEntry > value ) {
if ( isRegisteredPostfix ( type, value->getEntryInfo ( ) ) )
throw std::invalid_argument ( "Callback for operator " + Operators::toString ( type ) + " with params " + ext::to_string ( value->getEntryInfo ( ).getParams ( ) ) + " already registered." );
auto & group = getPostfixEntries ( ) [ type ];
group.insert ( group.end ( ), std::move ( value ) );
}
void OperatorRegistry::unregisterPostfixInternal ( Operators::PostfixOperators type, const AlgorithmBaseInfo & entryInfo ) {
auto & group = getPostfixEntries ( ) [ type ];
auto iter = find_if ( group.begin ( ), group.end ( ), [ & ] ( const std::unique_ptr < PostfixEntry > & entry ) {
return entry->getEntryInfo ( ).getCategory ( ) == entryInfo.getCategory ( ) && entry->getEntryInfo ( ).getParams ( ) == entryInfo.getParams ( );
} );
if ( iter == group.end ( ) )
throw std::invalid_argument ( "Entry for operator " + Operators::toString ( type ) + " with parameters " + ext::to_string ( entryInfo.getParams ( ) ) + " not registered." );
group.erase ( iter );
if ( group.empty ( ) )
getPostfixEntries ( ).erase ( type );
}
std::shared_ptr < abstraction::OperationAbstraction > OperatorRegistry::getPostfixAbstraction ( Operators::PostfixOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
auto & group = getPostfixEntries ( ) [ type ];
return getOverload ( group, paramTypes, paramQualifiers, category );
}
ext::list < ext::pair < Operators::PostfixOperators, AlgorithmFullInfo > > OperatorRegistry::listPostfixOverloads ( ) {
auto & group = getPostfixEntries ( );
ext::list < ext::pair < Operators::PostfixOperators, AlgorithmFullInfo > > res;
for ( const std::pair < const Operators::PostfixOperators, ext::list < std::unique_ptr < PostfixEntry > > > & overloads : group )
for ( const std::unique_ptr < PostfixEntry > & entry : overloads.second )
res.push_back ( ext::make_pair ( overloads.first, entry->getEntryInfo ( ) ) );
return res;
}
} /* namespace abstraction */
This diff is collapsed.
......@@ -12,6 +12,7 @@
#include <registry/CastRegistry.hpp>
#include <registry/NormalizeRegistry.hpp>
#include <registry/ContainerRegistry.hpp>
#include <registry/OperatorRegistry.hpp>
namespace abstraction {
......@@ -39,6 +40,18 @@ ext::list < ext::tuple < AlgorithmFullInfo, std::string > > Registry::listOverlo
return AlgorithmRegistry::listOverloads ( algorithm, templateParams );
}
ext::list < ext::pair < Operators::BinaryOperators, AlgorithmFullInfo > > Registry::listBinaryOperators ( ) {
return OperatorRegistry::listBinaryOverloads ( );
}
ext::list < ext::pair < Operators::PrefixOperators, AlgorithmFullInfo > > Registry::listPrefixOperators ( ) {
return OperatorRegistry::listPrefixOverloads ( );
}
ext::list < ext::pair < Operators::PostfixOperators, AlgorithmFullInfo > > Registry::listPostfixOperators ( ) {
return OperatorRegistry::listPostfixOverloads ( );
}
std::shared_ptr < abstraction::OperationAbstraction > Registry::getContainerAbstraction ( const std::string & container, const std::string & type ) {
return ContainerRegistry::getAbstraction ( container, type );
}
......@@ -47,6 +60,18 @@ std::shared_ptr < abstraction::OperationAbstraction > Registry::getAlgorithmAbst
return AlgorithmRegistry::getAbstraction ( name, templateParams, paramTypes, paramQualifiers, category );
}
std::shared_ptr < abstraction::OperationAbstraction > Registry::getBinaryOperatorAbstraction ( Operators::BinaryOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
return OperatorRegistry::getBinaryAbstraction ( type, paramTypes, paramQualifiers, category );
}
std::shared_ptr < abstraction::OperationAbstraction > Registry::getPrefixOperatorAbstraction ( Operators::PrefixOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
return OperatorRegistry::getPrefixAbstraction ( type, paramTypes, paramQualifiers, category );
}
std::shared_ptr < abstraction::OperationAbstraction > Registry::getPostfixOperatorAbstraction ( Operators::PostfixOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
return OperatorRegistry::getPostfixAbstraction ( type, paramTypes, paramQualifiers, category );
}
std::shared_ptr < abstraction::OperationAbstraction > Registry::getCastAbstraction ( const std::string & target, const std::string & param ) {
return CastRegistry::getAbstraction ( target, param );
}
......
......@@ -11,6 +11,7 @@
#include <abstraction/OperationAbstraction.hpp>
#include <common/ParamQualifiers.hpp>
#include <common/AlgorithmCategories.hpp>
#include <common/Operators.hpp>
#include "AlgorithmRegistryInfo.hpp"
#include <alib/pair>
......@@ -30,8 +31,15 @@ public:
static ext::list < ext::tuple < AlgorithmFullInfo, std::string > > listOverloads ( const std::string & algorithm, const ext::vector < std::string > & templateParams );
static ext::list < ext::pair < Operators::BinaryOperators, AlgorithmFullInfo > > listBinaryOperators ( );
static ext::list < ext::pair < Operators::PrefixOperators, AlgorithmFullInfo > > listPrefixOperators ( );
static ext::list < ext::pair < Operators::PostfixOperators, AlgorithmFullInfo > > listPostfixOperators ( );
static std::shared_ptr < abstraction::OperationAbstraction > getContainerAbstraction ( const std::string & container, const std::string & type );
static std::shared_ptr < abstraction::OperationAbstraction > getAlgorithmAbstraction ( const std::string & name, const ext::vector < std::string > & templateParams, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory );
static std::shared_ptr < abstraction::OperationAbstraction > getBinaryOperatorAbstraction ( Operators::BinaryOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory );
static std::shared_ptr < abstraction::OperationAbstraction > getPrefixOperatorAbstraction ( Operators::PrefixOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory );
static std::shared_ptr < abstraction::OperationAbstraction > getPostfixOperatorAbstraction ( Operators::PostfixOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > & paramQualifiers, AlgorithmCategories::AlgorithmCategory );
static std::shared_ptr < abstraction::OperationAbstraction > getCastAbstraction ( const std::string & target, const std::string & param );
static bool isCastNoOp ( const std::string & target, const std::string & param );
static std::shared_ptr < abstraction::OperationAbstraction > getNormalizeAbstraction ( const std::string & param );
......
#ifndef _CLI_OPERATOR_INTROSPECTION_COMMAND_H_
#define _CLI_OPERATOR_INTROSPECTION_COMMAND_H_
#include <ast/Command.h>
#include <environment/Environment.h>
namespace cli {
class OperatorsIntrospectionCommand : public Command {
static void typePrint ( const ext::pair < std::string, abstraction::ParamQualifiers::ParamQualifierSet > & result, std::ostream & os ) {
if ( std::get < 1 > ( result ) && abstraction::ParamQualifiers::ParamQualifierSet::CONST )
os << "const ";
os << std::get < 0 > ( result );
if ( std::get < 1 > ( result ) && abstraction::ParamQualifiers::ParamQualifierSet::LREF )
os << " &";
if ( std::get < 1 > ( result ) && abstraction::ParamQualifiers::ParamQualifierSet::RREF )
os << " &&";
}
public:
OperatorsIntrospectionCommand ( ) {
}
template < class Operators >
static void printOperators ( const ext::list < ext::pair < Operators, abstraction::AlgorithmFullInfo > > & overloads ) {
for ( const ext::pair < Operators, abstraction::AlgorithmFullInfo > & overload : overloads ) {
typePrint ( std::get < 1 > ( overload ).getNormalizedResult ( ), common::Streams::out );
common::Streams::out << " operator ";
common::Streams::out << abstraction::Operators::toString ( std::get < 0 > ( overload ) );
common::Streams::out << " (";
for ( size_t i = 0; i < std::get < 1 > ( overload ).getParams ( ).size ( ); ++ i ) {
if ( i != 0 )
common::Streams::out << ",";
common::Streams::out << " ";
typePrint ( std::get < 1 > ( overload ).getParams ( ) [ i ], common::Streams::out );
common::Streams::out << " " << std::get < 1 > ( overload ).getParamNames ( ) [ i ];
}
common::Streams::out << " )" << std::endl;
}
}
CommandResult run ( Environment & /* environment */ ) const override {
printOperators ( abstraction::Registry::listBinaryOperators ( ) );
printOperators ( abstraction::Registry::listPrefixOperators ( ) );
printOperators ( abstraction::Registry::listPostfixOperators ( ) );
return CommandResult::OK;
}
};
} /* namespace cli */
#endif /* _CLI_OPERATOR_INTROSPECTION_COMMAND_H_ */
......@@ -20,6 +20,7 @@
#include <ast/command/EOTCommand.h>
#include <ast/command/HelpCommand.h>
#include <ast/command/AlgorithmsIntrospectionCommand.h>
#include <ast/command/OperatorsIntrospectionCommand.h>