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

rename ParamQualifiers to TypeQualifiers

parent 28cdbdf1
......@@ -50,8 +50,8 @@ public:
return ext::type_index ( typeid ( ParamType ) );
}
abstraction::ParamQualifiers::ParamQualifierSet getParamTypeQualifiers ( size_t ) const override {
return abstraction::ParamQualifiers::paramQualifiers < ParamType > ( );
abstraction::TypeQualifiers::TypeQualifierSet getParamTypeQualifiers ( size_t ) const override {
return abstraction::TypeQualifiers::typeQualifiers < ParamType > ( );
}
};
......
......@@ -86,7 +86,7 @@ public:
return abstraction::paramType < ParamTypes ... > ( index );
}
abstraction::ParamQualifiers::ParamQualifierSet getParamTypeQualifiers ( size_t index ) const override {
abstraction::TypeQualifiers::TypeQualifierSet getParamTypeQualifiers ( size_t index ) const override {
return abstraction::paramTypeQualifiers < ParamTypes ... > ( index );
}
......
......@@ -13,7 +13,7 @@
#include <alib/typeindex>
#include <alib/set>
#include <common/ParamQualifiers.hpp>
#include <common/TypeQualifiers.hpp>
namespace abstraction {
......@@ -43,11 +43,11 @@ public:
std::string getParamType ( size_t index ) const;
virtual abstraction::ParamQualifiers::ParamQualifierSet getParamTypeQualifiers ( size_t index ) const = 0;
virtual abstraction::TypeQualifiers::TypeQualifierSet getParamTypeQualifiers ( size_t index ) const = 0;
std::string getReturnType ( ) const;
virtual abstraction::ParamQualifiers::ParamQualifierSet getReturnTypeQualifiers ( ) const = 0;
virtual abstraction::TypeQualifiers::TypeQualifierSet getReturnTypeQualifiers ( ) const = 0;
virtual std::shared_ptr < abstraction::OperationAbstraction > getProxyAbstraction ( );
};
......
......@@ -15,7 +15,7 @@ namespace abstraction {
PackingAbstractionImpl::LazyValue::LazyValue ( const std::shared_ptr < abstraction::OperationAbstraction > & ref ) : m_lifeReference ( std::move ( ref ) ) {
}
std::shared_ptr < abstraction::Value > PackingAbstractionImpl::LazyValue::clone ( abstraction::ParamQualifiers::ParamQualifierSet, bool ) {
std::shared_ptr < abstraction::Value > PackingAbstractionImpl::LazyValue::clone ( abstraction::TypeQualifiers::TypeQualifierSet, bool ) {
throw std::domain_error ( "Feature not available on lazy value" );
}
......@@ -23,7 +23,7 @@ ext::type_index PackingAbstractionImpl::LazyValue::getTypeIndex ( ) const {
return this->getLifeReference( )->getReturnTypeIndex ( );
}
abstraction::ParamQualifiers::ParamQualifierSet PackingAbstractionImpl::LazyValue::getTypeQualifiers ( ) const {
abstraction::TypeQualifiers::TypeQualifierSet PackingAbstractionImpl::LazyValue::getTypeQualifiers ( ) const {
return this->getLifeReference ( )->getReturnTypeQualifiers ( );
}
......
......@@ -25,11 +25,11 @@ protected:
public:
LazyValue ( const std::shared_ptr < abstraction::OperationAbstraction > & ref );
std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) override;
std::shared_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) override;
ext::type_index getTypeIndex ( ) const override;
abstraction::ParamQualifiers::ParamQualifierSet getTypeQualifiers ( ) const override;
abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override;
std::shared_ptr < abstraction::Value > getProxyAbstraction ( ) override;
......@@ -118,7 +118,7 @@ public:
return getAbstractions ( ) [ m_connections.at ( index ) [ 0 ].targetId ]->getLifeReference ( )->getParamTypeIndex ( m_connections.at ( index ) [ 0 ].paramPosition );
}
abstraction::ParamQualifiers::ParamQualifierSet getParamTypeQualifiers ( size_t index ) const override {
abstraction::TypeQualifiers::TypeQualifierSet getParamTypeQualifiers ( size_t index ) const override {
return getAbstractions ( ) [ m_connections.at ( index ) [ 0 ].targetId ]->getLifeReference ( )->getParamTypeQualifiers ( m_connections.at ( index ) [ 0 ].paramPosition );
}
......@@ -126,7 +126,7 @@ public:
return getAbstractions ( ) [ m_resultId ]->getLifeReference ( )->getReturnTypeIndex ( );
}
abstraction::ParamQualifiers::ParamQualifierSet getReturnTypeQualifiers ( ) const override {
abstraction::TypeQualifiers::TypeQualifierSet getReturnTypeQualifiers ( ) const override {
return getAbstractions ( ) [ m_resultId ]->getLifeReference ( )->getReturnTypeQualifiers ( );
}
......
......@@ -14,12 +14,12 @@
namespace abstraction {
class RawAbstraction : virtual public OperationAbstraction {
ext::vector < ext::tuple < std::string, abstraction::ParamQualifiers::ParamQualifierSet > > m_paramSpecs;
ext::vector < ext::tuple < std::string, abstraction::TypeQualifiers::TypeQualifierSet > > m_paramSpecs;
std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > m_callback;
ext::vector < std::shared_ptr < abstraction::Value > > m_params;
public:
RawAbstraction ( ext::vector < ext::tuple < std::string, abstraction::ParamQualifiers::ParamQualifierSet > > paramSpecs, std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > callback ) : m_paramSpecs ( paramSpecs ), m_callback ( std::move ( callback ) ), m_params ( m_paramSpecs.size ( ) ) {
RawAbstraction ( ext::vector < ext::tuple < std::string, abstraction::TypeQualifiers::TypeQualifierSet > > paramSpecs, std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > callback ) : m_paramSpecs ( paramSpecs ), m_callback ( std::move ( callback ) ), m_params ( m_paramSpecs.size ( ) ) {
}
private:
......@@ -59,7 +59,7 @@ public:
return m_params [ index ]->getTypeIndex ( );
}
abstraction::ParamQualifiers::ParamQualifierSet getParamTypeQualifiers ( size_t index ) const override {
abstraction::TypeQualifiers::TypeQualifierSet getParamTypeQualifiers ( size_t index ) const override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
......@@ -73,7 +73,7 @@ public:
return true;
}
abstraction::ParamQualifiers::ParamQualifierSet getReturnTypeQualifiers ( ) const override {
abstraction::TypeQualifiers::TypeQualifierSet getReturnTypeQualifiers ( ) const override {
throw std::domain_error ( "Return type not available.");
}
......
......@@ -19,7 +19,7 @@ std::string Value::getType ( ) const {
}
std::shared_ptr < abstraction::Value > Void::clone ( abstraction::ParamQualifiers::ParamQualifierSet, bool ) {
std::shared_ptr < abstraction::Value > Void::clone ( abstraction::TypeQualifiers::TypeQualifierSet, bool ) {
throw std::domain_error ( "Void variables are not allowed" );
}
......@@ -27,8 +27,8 @@ ext::type_index Void::getTypeIndex ( ) const {
return ext::type_index ( typeid ( void ) );
}
abstraction::ParamQualifiers::ParamQualifierSet Void::getTypeQualifiers ( ) const {
return abstraction::ParamQualifiers::paramQualifiers < void > ( );
abstraction::TypeQualifiers::TypeQualifierSet Void::getTypeQualifiers ( ) const {
return abstraction::TypeQualifiers::typeQualifiers < void > ( );
}
} /* namespace abstraction */
......@@ -12,7 +12,7 @@
#include <alib/set>
#include <alib/typeindex>
#include <common/ParamQualifiers.hpp>
#include <common/TypeQualifiers.hpp>
namespace abstraction {
......@@ -24,7 +24,7 @@ class Value : public std::enable_shared_from_this < Value > {
public:
virtual ~Value ( ) noexcept = default;
virtual std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) = 0;
virtual std::shared_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) = 0;
virtual std::shared_ptr < abstraction::Value > getProxyAbstraction ( );
......@@ -32,7 +32,7 @@ public:
std::string getType ( ) const;
virtual abstraction::ParamQualifiers::ParamQualifierSet getTypeQualifiers ( ) const = 0;
virtual abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const = 0;
void increaseTemporaryReference ( ) {
m_temporaryReferences += 1;
......@@ -52,11 +52,11 @@ public:
class Void : public Value {
public:
std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) override;
std::shared_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) override;
ext::type_index getTypeIndex ( ) const override;
abstraction::ParamQualifiers::ParamQualifierSet getTypeQualifiers ( ) const override;
abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override;
};
......
......@@ -121,30 +121,30 @@ public:
this->setData ( std::forward < Type > ( value ) );
}
std::shared_ptr < abstraction::Value > clone ( ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) override {
/* if ( ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF || paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF ) && this->isTemporary ( ) && ! this->isRef ( ) && this->getTemporaryReferences ( ) == 0 )
std::shared_ptr < abstraction::Value > clone ( TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) override {
/* if ( ( typeQualifiers && TypeQualifiers::TypeQualifierSet::LREF || typeQualifiers && TypeQualifiers::TypeQualifierSet::RREF ) && this->isTemporary ( ) && ! this->isRef ( ) && this->getTemporaryReferences ( ) == 0 )
throw std::domain_error ( "Taking reference to a temporary" );*/
if ( ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST ) && ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF ) )
if ( TypeQualifiers::isConst ( typeQualifiers ) && TypeQualifiers::isLvalueRef ( typeQualifiers ) )
return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > & > > ( retrieveValue < const std::decay_t < Type > & > ( this->shared_from_this ( ) ), isTemporary );
else if ( ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST ) && ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF ) )
else if ( TypeQualifiers::isConst ( typeQualifiers ) && TypeQualifiers::isRvalueRef ( typeQualifiers ) )
return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > && > > ( retrieveValue < const std::decay_t < Type > && > ( this->shared_from_this ( ) ), isTemporary );
else if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF )
else if ( TypeQualifiers::isLvalueRef ( typeQualifiers ) )
return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > & > > ( retrieveValue < std::decay_t < Type > & > ( this->shared_from_this ( ) ), isTemporary );
else if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF )
else if ( TypeQualifiers::isRvalueRef ( typeQualifiers ) )
return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > && > > ( retrieveValue < std::decay_t < Type > && > ( this->shared_from_this ( ) ), isTemporary );
else if constexpr ( std::is_abstract_v < std::decay_t < Type > > )
throw std::domain_error ( "Cannot declare value of abstract class." );
else if constexpr ( ! std::is_assignable_v < std::decay_t < Type > &, std::decay_t < Type > > )
throw std::domain_error ( "Cannot assign value." );
else if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST )
else if ( TypeQualifiers::isConst ( typeQualifiers ) )
return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > > > ( retrieveValue < const std::decay_t < Type > > ( this->shared_from_this ( ) ), isTemporary );
else
return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->shared_from_this ( ) ), isTemporary );
}
abstraction::ParamQualifiers::ParamQualifierSet getTypeQualifiers ( ) const override {
return abstraction::ParamQualifiers::paramQualifiers < Type > ( );
abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override {
return abstraction::TypeQualifiers::typeQualifiers < Type > ( );
}
ext::type_index getTypeIndex ( ) const override {
......
......@@ -23,7 +23,7 @@ protected:
public:
bool isConst ( ) const {
return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::CONST;
return TypeQualifiers::isConst ( getTypeQualifiers ( ) );
}
bool isRef ( ) const {
......@@ -33,13 +33,13 @@ public:
bool isRvalueRef ( ) const {
if ( m_isCastedToTemporaryRvalue )
return true;
return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::RREF;
return TypeQualifiers::isRvalueRef ( getTypeQualifiers ( ) );
}
bool isLvalueRef ( ) const {
if ( m_isCastedToTemporaryRvalue )
return false;
return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::LREF;
return TypeQualifiers::isLvalueRef ( getTypeQualifiers ( ) );
}
bool isTemporary ( ) const {
......
......@@ -13,8 +13,8 @@ ext::type_index ValueOperationAbstraction < void >::getReturnTypeIndex ( ) const
return ext::type_index ( typeid ( void ) );
}
abstraction::ParamQualifiers::ParamQualifierSet ValueOperationAbstraction < void >::getReturnTypeQualifiers ( ) const {
return abstraction::ParamQualifiers::paramQualifiers < void > ( );
abstraction::TypeQualifiers::TypeQualifierSet ValueOperationAbstraction < void >::getReturnTypeQualifiers ( ) const {
return abstraction::TypeQualifiers::typeQualifiers < void > ( );
}
} /* namespace abstraction */
......@@ -11,7 +11,7 @@
#include <alib/array>
#include <alib/memory>
#include <common/ParamQualifiers.hpp>
#include <common/TypeQualifiers.hpp>
#include <abstraction/ValueHolder.hpp>
#include <common/AbstractionHelpers.hpp>
......@@ -26,8 +26,8 @@ public:
return std::make_shared < abstraction::ValueHolder < ReturnType > > ( abstraction::apply < ParamTypes ... > ( callback, inputs ), std::is_lvalue_reference_v < ReturnType > ? false : true );
}
abstraction::ParamQualifiers::ParamQualifierSet getReturnTypeQualifiers ( ) const override {
return abstraction::ParamQualifiers::paramQualifiers < ReturnType > ( );
abstraction::TypeQualifiers::TypeQualifierSet getReturnTypeQualifiers ( ) const override {
return abstraction::TypeQualifiers::typeQualifiers < ReturnType > ( );
}
ext::type_index getReturnTypeIndex ( ) const override {
......@@ -47,7 +47,7 @@ public:
ext::type_index getReturnTypeIndex ( ) const override;
abstraction::ParamQualifiers::ParamQualifierSet getReturnTypeQualifiers ( ) const override;
abstraction::TypeQualifiers::TypeQualifierSet getReturnTypeQualifiers ( ) const override;
};
} /* namespace abstraction */
......
......@@ -98,7 +98,7 @@ public:
throw std::domain_error ( "ReturnTypeIndex not avaiable before evaluation." );
}
abstraction::ParamQualifiers::ParamQualifierSet getReturnTypeQualifiers ( ) const override {
abstraction::TypeQualifiers::TypeQualifierSet getReturnTypeQualifiers ( ) const override {
if ( this->m_abstraction )
return this->m_abstraction->getReturnTypeQualifiers ( );
else
......@@ -138,7 +138,7 @@ public:
return abstraction::paramType < ParamTypes ... > ( index );
}
abstraction::ParamQualifiers::ParamQualifierSet getParamTypeQualifiers ( size_t index ) const override {
abstraction::TypeQualifiers::TypeQualifierSet getParamTypeQualifiers ( size_t index ) const override {
return abstraction::paramTypeQualifiers < ParamTypes ... > ( index );
}
......
......@@ -38,11 +38,11 @@ static ext::type_index paramType ( unsigned index ) {
}
template < class ... Params >
abstraction::ParamQualifiers::ParamQualifierSet paramTypeQualifiers ( unsigned index ) {
abstraction::ParamQualifiers::ParamQualifierSet res = abstraction::ParamQualifiers::ParamQualifierSet::NONE;
abstraction::TypeQualifiers::TypeQualifierSet paramTypeQualifiers ( unsigned index ) {
abstraction::TypeQualifiers::TypeQualifierSet res = abstraction::TypeQualifiers::TypeQualifierSet::NONE;
auto lambda = [ & ] ( auto I ) {
res = abstraction::ParamQualifiers::paramQualifiers < std::tuple_element_t < decltype ( I )::value, std::tuple < Params ... > > > ( );
res = abstraction::TypeQualifiers::typeQualifiers < std::tuple_element_t < decltype ( I )::value, std::tuple < Params ... > > > ( );
};
ext::constexpr_switch < sizeof ... ( Params ) > ( index, lambda );
......
......@@ -15,7 +15,7 @@ namespace abstraction {
std::shared_ptr < abstraction::Value > EvalHelper::evalAlgorithm ( abstraction::TemporariesHolder & environment, const std::string & name, const ext::vector < std::string > & templateParams, const ext::vector < std::shared_ptr < abstraction::Value > > & params, abstraction::AlgorithmCategories::AlgorithmCategory category ) {
ext::vector < std::string > paramTypes;
ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > paramTypeQualifiers;
ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > paramTypeQualifiers;
for ( const std::shared_ptr < abstraction::Value > & param : params ) {
paramTypes.push_back ( param->getType ( ) );
paramTypeQualifiers.push_back ( param->getTypeQualifiers ( ) );
......@@ -30,7 +30,7 @@ std::shared_ptr < abstraction::Value > EvalHelper::evalAlgorithm ( abstraction::
std::shared_ptr < abstraction::Value > EvalHelper::evalOperator ( abstraction::TemporariesHolder & environment, abstraction::Operators::BinaryOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, abstraction::AlgorithmCategories::AlgorithmCategory category ) {
ext::vector < std::string > paramTypes;
ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > paramTypeQualifiers;
ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > paramTypeQualifiers;
for ( const std::shared_ptr < abstraction::Value > & param : params ) {
paramTypes.push_back ( param->getType ( ) );
paramTypeQualifiers.push_back ( param->getTypeQualifiers ( ) );
......@@ -45,7 +45,7 @@ std::shared_ptr < abstraction::Value > EvalHelper::evalOperator ( abstraction::T
std::shared_ptr < abstraction::Value > EvalHelper::evalOperator ( abstraction::TemporariesHolder & environment, abstraction::Operators::PrefixOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, abstraction::AlgorithmCategories::AlgorithmCategory category ) {
ext::vector < std::string > paramTypes;
ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > paramTypeQualifiers;
ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > paramTypeQualifiers;
for ( const std::shared_ptr < abstraction::Value > & param : params ) {
paramTypes.push_back ( param->getType ( ) );
paramTypeQualifiers.push_back ( param->getTypeQualifiers ( ) );
......@@ -60,7 +60,7 @@ std::shared_ptr < abstraction::Value > EvalHelper::evalOperator ( abstraction::T
std::shared_ptr < abstraction::Value > EvalHelper::evalOperator ( abstraction::TemporariesHolder & environment, abstraction::Operators::PostfixOperators type, const ext::vector < std::shared_ptr < abstraction::Value > > & params, abstraction::AlgorithmCategories::AlgorithmCategory category ) {
ext::vector < std::string > paramTypes;
ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > paramTypeQualifiers;
ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > paramTypeQualifiers;
for ( const std::shared_ptr < abstraction::Value > & param : params ) {
paramTypes.push_back ( param->getType ( ) );
paramTypeQualifiers.push_back ( param->getTypeQualifiers ( ) );
......
......@@ -7,7 +7,7 @@
namespace abstraction {
template < class Entry >
std::shared_ptr < abstraction::OperationAbstraction > getOverload ( const ext::list < std::unique_ptr < Entry > > & overloads, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::ParamQualifiers::ParamQualifierSet > &, AlgorithmCategories::AlgorithmCategory category ) {
std::shared_ptr < abstraction::OperationAbstraction > getOverload ( const ext::list < std::unique_ptr < Entry > > & overloads, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > &, AlgorithmCategories::AlgorithmCategory category ) {
enum class MatchType {
EXACT,
CAST,
......
#ifndef _PARAM_QUALIFIERS_HPP_
#define _PARAM_QUALIFIERS_HPP_
#include <alib/set>
#include <alib/type_traits>
namespace abstraction {
class ParamQualifiers {
public:
enum class ParamQualifierSet {
NONE = 0x0,
CONST = 0x1,
LREF = 0x2,
RREF = 0x4,
};
friend constexpr ParamQualifierSet operator | ( ParamQualifierSet first, ParamQualifierSet second ) {
return static_cast < ParamQualifierSet > ( static_cast < unsigned > ( first ) | static_cast < unsigned > ( second ) );
}
friend constexpr ParamQualifierSet operator & ( ParamQualifierSet first, ParamQualifierSet second ) {
return static_cast < ParamQualifierSet > ( static_cast < unsigned > ( first ) & static_cast < unsigned > ( second ) );
}
friend constexpr bool operator && ( ParamQualifierSet first, ParamQualifierSet second ) {
return ( static_cast < unsigned > ( first ) & static_cast < unsigned > ( second ) ) == static_cast < unsigned > ( second );
}
template < class Param >
static constexpr ParamQualifierSet paramQualifiers ( ) {
ParamQualifierSet res = ParamQualifierSet::NONE;
if ( std::is_lvalue_reference < Param >::value )
res = res | ParamQualifierSet::LREF;
if ( std::is_rvalue_reference < Param >::value )
res = res | ParamQualifierSet::RREF;
if ( std::is_const < typename std::remove_reference < Param >::type >::value )
res = res | ParamQualifierSet::CONST;
return res;
}
friend std::ostream & operator << ( std::ostream & os, ParamQualifierSet paramQualifierSet );
};
} /* namespace abstraction */
#endif // _PARAM_QUALIFIERS_HPP_
#include "ParamQualifiers.hpp"
#include "TypeQualifiers.hpp"
namespace abstraction {
std::ostream & operator << ( std::ostream & os, ParamQualifiers::ParamQualifierSet paramQualifierSet ) {
std::ostream & operator << ( std::ostream & os, TypeQualifiers::TypeQualifierSet arg ) {
os << "[ ";
bool first = true;
if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST )
if ( TypeQualifiers::isConst ( arg ) )
os << ( first ? "" : ", " ) << "Constant", first = false;
if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF )
if ( TypeQualifiers::isLvalueRef ( arg ) )
os << ( first ? "" : ", " ) << "LValue reference", first = false;
if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF )
if ( TypeQualifiers::isRvalueRef ( arg ) )
os << ( first ? "" : ", " ) << "RValue reference", first = false;
os << " ]";
return os;
......
#ifndef _TYPE_QUALIFIERS_HPP_
#define _TYPE_QUALIFIERS_HPP_
#include <alib/set>
#include <alib/type_traits>
namespace abstraction {
class TypeQualifiers {
public:
enum class TypeQualifierSet {
NONE = 0x0,
CONST = 0x1,
LREF = 0x2,
RREF = 0x4,
};
friend constexpr TypeQualifierSet operator | ( TypeQualifierSet first, TypeQualifierSet second ) {
return static_cast < TypeQualifierSet > ( static_cast < unsigned > ( first ) | static_cast < unsigned > ( second ) );
}
friend constexpr TypeQualifierSet operator & ( TypeQualifierSet first, TypeQualifierSet second ) {
return static_cast < TypeQualifierSet > ( static_cast < unsigned > ( first ) & static_cast < unsigned > ( second ) );
}
friend constexpr bool operator && ( TypeQualifierSet first, TypeQualifierSet second ) {
return ( static_cast < unsigned > ( first ) & static_cast < unsigned > ( second ) ) == static_cast < unsigned > ( second );
}
static constexpr bool isConst ( TypeQualifierSet arg ) {
return arg && TypeQualifiers::TypeQualifierSet::CONST;
}
static constexpr bool isRef ( TypeQualifierSet arg ) {
return isRvalueRef ( arg ) || isLvalueRef ( arg );
}
static constexpr bool isRvalueRef ( TypeQualifierSet arg ) {
return arg && TypeQualifiers::TypeQualifierSet::RREF;
}
static constexpr bool isLvalueRef ( TypeQualifierSet arg ) {
return arg && TypeQualifiers::TypeQualifierSet::LREF;
}
template < class Type >
static constexpr TypeQualifierSet typeQualifiers ( ) {
TypeQualifierSet res = TypeQualifierSet::NONE;
if ( std::is_lvalue_reference < Type >::value )
res = res | TypeQualifierSet::LREF;
if ( std::is_rvalue_reference < Type >::value )
res = res | TypeQualifierSet::RREF;
if ( std::is_const < typename std::remove_reference < Type >::type >::value )
res = res | TypeQualifierSet::CONST;
return res;
}
friend std::ostream & operator << ( std::ostream & os, TypeQualifierSet typeQualifierSet );
};
} /* namespace abstraction */
#endif // _TYPE_QUALIFIERS_HPP_
......@@ -100,11 +100,11 @@ ext::list < std::unique_ptr < AlgorithmRegistry::Entry > > & AlgorithmRegistry::
return group->second;
}
std::shared_ptr < abstraction::OperationAbstraction > AlgorithmRegistry::getAbstraction ( 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 category ) {
std::shared_ptr < abstraction::OperationAbstraction > AlgorithmRegistry::getAbstraction ( const std::string & name, const ext::vector < std::string > & templateParams, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > & typeQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
auto & group = findAbstractionGroup ( name, templateParams );
try {
return getOverload ( group, paramTypes, paramQualifiers, category );
return getOverload ( group, paramTypes, typeQualifiers, category );
} catch ( ... ) {
if ( templateParams.empty ( ) )
std::throw_with_nested ( std::invalid_argument ( "Entry overload " + name + " " + ext::to_string ( paramTypes ) + " not available" ) );
......
......@@ -22,7 +22,7 @@
#include "AlgorithmRegistryInfo.hpp"
#include "BaseRegistryEntry.hpp"
#include <common/ParamQualifiers.hpp>
#include <common/TypeQualifiers.hpp>
#include <common/AlgorithmCategories.hpp>
namespace abstraction {
......@@ -89,7 +89,7 @@ private:
std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > m_rawCallback;
public:
RawImpl ( ext::pair < std::string, abstraction::ParamQualifiers::ParamQualifierSet > result, ext::vector < ext::tuple < std::string, abstraction::ParamQualifiers::ParamQualifierSet, std::string > > paramSpecs, std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > rawCallback ) : Entry ( AlgorithmFullInfo::rawEntryInfo ( std::move ( result ), std::move ( paramSpecs ) ) ), m_rawCallback ( std::move ( rawCallback ) ) {
RawImpl ( ext::pair < std::string, abstraction::TypeQualifiers::TypeQualifierSet > result, ext::vector < ext::tuple < std::string, abstraction::TypeQualifiers::TypeQualifierSet, std::string > > paramSpecs, std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > rawCallback ) : Entry ( AlgorithmFullInfo::rawEntryInfo ( std::move ( result ), std::move ( paramSpecs ) ) ), m_rawCallback ( std::move ( rawCallback ) ) {
}
std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override;
......@@ -161,7 +161,7 @@ public:
}
template < class Algo >
static void unregisterRaw ( ext::vector < ext::tuple < std::string, abstraction::ParamQualifiers::ParamQualifierSet > > parameterSpecs ) {
static void unregisterRaw ( ext::vector < ext::tuple < std::string, abstraction::TypeQualifiers::TypeQualifierSet > > parameterSpecs ) {
std::string algorithm = ext::to_string < Algo > ( );
ext::vector < std::string > templateParams = ext::get_template_info ( algorithm );
algorithm = ext::erase_template_info ( algorithm );
......@@ -204,19 +204,19 @@ public:
}
template < class Algo >
static void registerRaw ( std::shared_ptr < abstraction::Value > ( * callback ) ( std::vector < std::shared_ptr < abstraction::Value > > ), ext::pair < std::string, abstraction::ParamQualifiers::ParamQualifierSet > result, ext::vector < ext::tuple < std::string, abstraction::ParamQualifiers::ParamQualifierSet, std::string > > paramSpecs ) {
static void registerRaw ( std::shared_ptr < abstraction::Value > ( * callback ) ( std::vector < std::shared_ptr < abstraction::Value > > ), ext::pair < std::string, abstraction::TypeQualifiers::TypeQualifierSet > result, ext::vector < ext::tuple < std::string, abstraction::TypeQualifiers::TypeQualifierSet, std::string > > paramSpecs ) {
std::string algorithm = ext::to_string < Algo > ( );
registerRaw ( algorithm, callback, std::move ( result ), std::move ( paramSpecs ) );
}
static void registerRaw ( std::string algorithm, std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > callback, ext::pair < std::string, abstraction::ParamQualifiers::ParamQualifierSet > result, ext::vector < ext::tuple < std::string, abstraction::ParamQualifiers::ParamQualifierSet, std::string > > paramSpecs ) {
static void registerRaw ( std::string algorithm, std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > callback, ext::pair < std::string, abstraction::TypeQualifiers::TypeQualifierSet > result, ext::vector < ext::tuple < std::string, abstraction::TypeQualifiers::TypeQualifierSet, std::string > > paramSpecs ) {
ext::vector < std::string > templateParams = ext::get_template_info ( algorithm );
algorithm = ext::erase_template_info ( algorithm );
registerInternal ( std::move ( algorithm ), std::move ( templateParams ), std::make_unique < RawImpl > ( std::move ( result ), std::move ( paramSpecs ), callback ) );
}
static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( 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 category );
static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & name, const ext::vector < std::string > & templateParams, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > & typeQualifiers, AlgorithmCategories::AlgorithmCategory category );
static ext::set < ext::pair < std::string, ext::vector < std::string > > > listGroup ( const std::string & group );
......
......@@ -10,7 +10,7 @@
namespace abstraction {
ext::pair < std::string, abstraction::ParamQualifiers::ParamQualifierSet > AlgorithmFullInfo::getNormalizedResult ( ) const {
ext::pair < std::string, abstraction::TypeQualifiers::TypeQualifierSet > AlgorithmFullInfo::getNormalizedResult ( ) const {
if ( ! abstraction::Registry::hasNormalize ( m_result.first ) )
return m_result;
......
......@@ -55,10 +55,10 @@ void OperatorRegistry::unregisterBinaryInternal ( Operators::BinaryOperators typ
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 ) {
std::shared_ptr < abstraction::OperationAbstraction > OperatorRegistry::getBinaryAbstraction ( Operators::BinaryOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > & typeQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
auto & group = getBinaryEntries ( ) [ type ];
return getOverload ( group, paramTypes, paramQualifiers, category );
return getOverload ( group, paramTypes, typeQualifiers, category );
}
ext::list < ext::pair < Operators::BinaryOperators, AlgorithmFullInfo > > OperatorRegistry::listBinaryOverloads ( ) {
......@@ -110,10 +110,10 @@ void OperatorRegistry::unregisterPrefixInternal ( Operators::PrefixOperators typ
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 ) {
std::shared_ptr < abstraction::OperationAbstraction > OperatorRegistry::getPrefixAbstraction ( Operators::PrefixOperators type, const ext::vector < std::string > & paramTypes, const ext::vector < abstraction::TypeQualifiers::TypeQualifierSet > & typeQualifiers, AlgorithmCategories::AlgorithmCategory category ) {
auto & group = getPrefixEntries ( ) [ type ];
return getOverload ( group, paramTypes, paramQualifiers, category );
return getOverload ( group, paramTypes, typeQualifiers, category );
}
ext::list < ext::pair < Operators::PrefixOperators, AlgorithmFullInfo > > OperatorRegistry::listPrefixOverloads ( ) {
......@@ -165,10 +165,10 @@ void OperatorRegistry::unregisterPostfixInternal ( Operators::PostfixOperators t
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 )