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

drop move qualifier from Parser

parent b781a16b
......@@ -9,24 +9,23 @@
namespace abstraction {
void AnyaryOperationAbstractionImpl::attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) {
void AnyaryOperationAbstractionImpl::attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) {
if ( m_params.size ( ) < index + 1 )
m_params.resize ( index + 1 );
m_params [ index ] = std::make_pair ( input, move );
m_params [ index ] = input;
}
void AnyaryOperationAbstractionImpl::detachInput ( size_t index ) {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ].first = nullptr;
m_params [ index ].second = false;
m_params [ index ] = nullptr;
}
bool AnyaryOperationAbstractionImpl::inputsAttached ( ) const {
auto attached_lambda = [ ] ( const std::pair < std::shared_ptr < abstraction::Value >, bool > & param ) {
return ( bool ) param.first;
auto attached_lambda = [ ] ( const std::shared_ptr < abstraction::Value > & param ) {
return ( bool ) param;
};
return std::all_of ( m_params.begin ( ), m_params.end ( ), attached_lambda );
......
......@@ -16,17 +16,17 @@
namespace abstraction {
class AnyaryOperationAbstractionImpl : virtual public OperationAbstraction {
ext::vector < std::pair < std::shared_ptr < abstraction::Value >, bool > > m_params;
ext::vector < std::shared_ptr < abstraction::Value > > m_params;
protected:
ext::vector < std::pair < std::shared_ptr < abstraction::Value >, bool > > & getParams ( ) {
ext::vector < std::shared_ptr < abstraction::Value > > & getParams ( ) {
return m_params;
}
virtual std::shared_ptr < abstraction::Value > run ( ) = 0;
private:
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) override;
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) override;
void detachInput ( size_t index ) override;
......
......@@ -17,9 +17,9 @@ template < class ReturnType, class ParamType >
class CastAbstraction : virtual public NaryOperationAbstraction < const ParamType & >, virtual public ValueOperationAbstraction < ReturnType > {
public:
std::shared_ptr < abstraction::Value > run ( ) override {
std::pair < std::shared_ptr < abstraction::Value >, bool > & param = std::get < 0 > ( this->getParams ( ) );
std::shared_ptr < abstraction::Value > & param = std::get < 0 > ( this->getParams ( ) );
return std::make_shared < abstraction::ValueHolder < ReturnType > > ( ReturnType ( retrieveValue < const ParamType & > ( param.first, param.second ) ), true );
return std::make_shared < abstraction::ValueHolder < ReturnType > > ( ReturnType ( retrieveValue < const ParamType & > ( param ) ), true );
}
};
......
......@@ -25,16 +25,16 @@ public:
}
std::shared_ptr < abstraction::Value > run ( ) override {
ext::array < std::pair < std::shared_ptr < abstraction::Value >, bool >, sizeof ... ( ParamTypes ) + 1 > params = this->getParams ( );
ext::array < std::shared_ptr < abstraction::Value >, sizeof ... ( ParamTypes ) + 1 > params = this->getParams ( );
std::shared_ptr < OperationAbstraction > reference = std::make_shared < ReferenceAbstraction < typename std::remove_reference < ObjectType >::type > > ( );
reference->attachInput ( std::get < 0 > ( this->getParams ( ) ).first, 0, std::get < 0 > ( this->getParams ( ) ).second );
reference->attachInput ( std::get < 0 > ( this->getParams ( ) ), 0 );
std::shared_ptr < abstraction::Value > ref = reference->eval ( );
if ( ! ref )
throw std::invalid_argument ( "Eval of object of call to member falsed." );
std::get < 0 > ( params ) = std::make_pair ( ref, false );
std::get < 0 > ( params ) = ref;
return this->template run_helper < typename std::remove_reference < ObjectType >::type *, ParamTypes ... > ( m_callback, params );
}
......
......@@ -18,43 +18,40 @@ namespace abstraction {
template < size_t NumberOfParams >
class NaryOperationAbstractionImpl : virtual public OperationAbstraction {
ext::array < std::pair < std::shared_ptr < abstraction::Value >, bool >, NumberOfParams > m_params;
ext::array < std::shared_ptr < abstraction::Value >, NumberOfParams > m_params;
protected:
ext::array < std::pair < std::shared_ptr < abstraction::Value >, bool >, NumberOfParams > & getParams ( ) {
ext::array < std::shared_ptr < abstraction::Value >, NumberOfParams > & getParams ( ) {
return m_params;
}
virtual std::shared_ptr < abstraction::Value > run ( ) = 0;
private:
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) override {
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ].first = input;
m_params [ index ].second = move;
m_params [ index ] = input;
}
void detachInput ( size_t index ) override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ].first = nullptr;
m_params [ index ].second = false;
m_params [ index ] = nullptr;
}
public:
NaryOperationAbstractionImpl ( ) {
for ( size_t i = 0; i < NumberOfParams; ++ i ) {
m_params [ i ].first = nullptr;
m_params [ i ].second = false;
m_params [ i ] = nullptr;
}
}
bool inputsAttached ( ) const override {
for ( const std::pair < std::shared_ptr < abstraction::Value >, bool > & param : m_params )
if ( ! param.first )
for ( const std::shared_ptr < abstraction::Value > & param : m_params )
if ( ! param )
return false;
return true;
......
......@@ -19,8 +19,8 @@ template < class ReturnType, class ParamType >
class NormalizeAbstraction : virtual public NaryOperationAbstraction < ParamType && >, virtual public ValueOperationAbstraction < ReturnType > {
public:
std::shared_ptr < abstraction::Value > run ( ) override {
std::pair < std::shared_ptr < abstraction::Value >, bool > & rawParam = std::get < 0 > ( this->getParams ( ) );
ParamType && param = retrieveValue < ParamType && > ( rawParam.first, rawParam.second );
std::shared_ptr < abstraction::Value > & rawParam = std::get < 0 > ( this->getParams ( ) );
ParamType && param = retrieveValue < ParamType && > ( rawParam );
return std::make_shared < abstraction::ValueHolder < ReturnType > > ( factory::NormalizeFactory::normalize ( std::move ( param ) ), true );
}
......
......@@ -21,7 +21,7 @@ class Value;
class OperationAbstraction : public std::enable_shared_from_this < OperationAbstraction > {
public:
virtual void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) = 0;
virtual void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) = 0;
virtual void detachInput ( size_t index ) = 0;
virtual ~OperationAbstraction ( ) noexcept = default;
......
......@@ -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, bool ) {
std::shared_ptr < abstraction::Value > PackingAbstractionImpl::LazyValue::clone ( abstraction::ParamQualifiers::ParamQualifierSet, bool ) {
throw std::domain_error ( "Feature not available on lazy value" );
}
......
......@@ -25,7 +25,7 @@ protected:
public:
LazyValue ( const std::shared_ptr < abstraction::OperationAbstraction > & ref );
std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary, bool move ) override;
std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) override;
ext::type_index getTypeIndex ( ) const override;
......@@ -50,8 +50,8 @@ public:
m_abstractions.push_back ( std::make_shared < LazyValue > ( std::move ( abstraction ) ) );
}
void setInnerConnection ( size_t sourceId, size_t targetId, size_t paramPosition, bool move ) {
m_abstractions [ targetId ]->getLifeReference ( )->attachInput ( m_abstractions [ sourceId ], paramPosition, move );
void setInnerConnection ( size_t sourceId, size_t targetId, size_t paramPosition ) {
m_abstractions [ targetId ]->getLifeReference ( )->attachInput ( m_abstractions [ sourceId ], paramPosition );
}
void clearInnerConnection ( size_t targetId, size_t paramPosition ) {
......@@ -87,10 +87,10 @@ public:
}
private:
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) override {
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) override {
try {
for ( const ConnectionTarget & target : m_connections [ index ] )
getAbstractions ( ) [ target.targetId ]->getLifeReference ( )->attachInput ( input, target.paramPosition, move );
getAbstractions ( ) [ target.targetId ]->getLifeReference ( )->attachInput ( input, target.paramPosition );
} catch ( ... ) {
this->detachInput ( index );
throw;
......
......@@ -9,24 +9,23 @@
namespace abstraction {
void RawAbstraction::attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) {
void RawAbstraction::attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ] = std::make_pair ( input, move );
m_params [ index ] = input;
}
void RawAbstraction::detachInput ( size_t index ) {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ].first = nullptr;
m_params [ index ].second = false;
m_params [ index ] = nullptr;
}
bool RawAbstraction::inputsAttached ( ) const {
auto attached_lambda = [ ] ( const std::pair < std::shared_ptr < abstraction::Value >, bool > & param ) {
return ( bool ) param.first;
auto attached_lambda = [ ] ( const std::shared_ptr < abstraction::Value > & param ) {
return ( bool ) param;
};
return std::all_of ( m_params.begin ( ), m_params.end ( ), attached_lambda );
......
......@@ -16,7 +16,7 @@ namespace abstraction {
class RawAbstraction : virtual public OperationAbstraction {
ext::vector < ext::tuple < std::string, abstraction::ParamQualifiers::ParamQualifierSet > > m_paramSpecs;
std::function < std::shared_ptr < abstraction::Value > ( std::vector < std::shared_ptr < abstraction::Value > > ) > m_callback;
ext::vector < ext::pair < std::shared_ptr < abstraction::Value >, bool > > m_params;
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 ( ) ) {
......@@ -26,13 +26,13 @@ private:
std::shared_ptr < abstraction::Value > run ( ) {
std::vector < std::shared_ptr < abstraction::Value > > params;
for ( const ext::pair < std::shared_ptr < abstraction::Value >, bool > & param : m_params )
params.push_back ( param.first );
for ( const std::shared_ptr < abstraction::Value > & param : m_params )
params.push_back ( param );
return m_callback ( params );
}
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) override;
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) override;
void detachInput ( size_t index ) override;
......@@ -53,20 +53,20 @@ public:
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
if ( m_params [ index ].first == nullptr )
if ( m_params [ index ] == nullptr )
throw std::domain_error ( "Parameter index " + ext::to_string ( index ) + " not yet set.");
return m_params [ index ].first->getTypeIndex ( );
return m_params [ index ]->getTypeIndex ( );
}
abstraction::ParamQualifiers::ParamQualifierSet getParamTypeQualifiers ( size_t index ) const override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
if ( m_params [ index ].first == nullptr )
if ( m_params [ index ] == nullptr )
throw std::domain_error ( "Parameter index " + ext::to_string ( index ) + " not yet set.");
return m_params [ index ].first->getTypeQualifiers ( );
return m_params [ index ]->getTypeQualifiers ( );
}
bool isReturnTypeUniversal ( ) const override {
......
......@@ -19,9 +19,9 @@ template < class Type >
class ReferenceAbstraction : virtual public NaryOperationAbstraction < Type & >, virtual public ValueOperationAbstraction < Type * > {
public:
std::shared_ptr < abstraction::Value > run ( ) override {
std::pair < std::shared_ptr < abstraction::Value >, bool > & param = std::get < 0 > ( this->getParams ( ) );
std::shared_ptr < abstraction::Value > & param = std::get < 0 > ( this->getParams ( ) );
return std::make_shared < abstraction::ValueHolder < Type * > > ( & retrieveValue < Type & > ( param.first, param.second ), true );
return std::make_shared < abstraction::ValueHolder < Type * > > ( & retrieveValue < Type & > ( param ), true );
}
};
......
......@@ -20,8 +20,8 @@ class SetAbstraction : virtual public AnyaryOperationAbstraction < ParamType >,
public:
std::shared_ptr < abstraction::Value > run ( ) override {
ext::set < ParamType > theSet;
for ( const std::pair < std::shared_ptr < abstraction::Value >, bool > & param : this->getParams ( ) ) {
theSet.insert ( abstraction::retrieveValue < ParamType > ( param.first, param.second ) );
for ( const std::shared_ptr < abstraction::Value > & param : this->getParams ( ) ) {
theSet.insert ( abstraction::retrieveValue < ParamType > ( param ) );
}
return std::make_shared < abstraction::ValueHolder < ext::set < ParamType > > > ( std::move ( theSet ), true );
......
......@@ -19,7 +19,7 @@ std::string Value::getType ( ) const {
}
std::shared_ptr < abstraction::Value > Void::clone ( abstraction::ParamQualifiers::ParamQualifierSet, bool, bool ) {
std::shared_ptr < abstraction::Value > Void::clone ( abstraction::ParamQualifiers::ParamQualifierSet, bool ) {
throw std::domain_error ( "Void variables are not allowed" );
}
......
......@@ -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, bool move = false ) = 0;
virtual std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) = 0;
virtual std::shared_ptr < abstraction::Value > getProxyAbstraction ( );
......@@ -52,7 +52,7 @@ public:
class Void : public Value {
public:
std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary, bool move ) override;
std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) override;
ext::type_index getTypeIndex ( ) const override;
......
......@@ -121,26 +121,26 @@ public:
this->setData ( std::forward < Type > ( value ) );
}
std::shared_ptr < abstraction::Value > clone ( ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary, bool move ) override {
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 )
throw std::domain_error ( "Taking reference to a temporary" );*/
if ( ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST ) && ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF ) )
return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > & > > ( retrieveValue < const std::decay_t < Type > & > ( this->shared_from_this ( ), move ), isTemporary );
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 ) )
return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > && > > ( retrieveValue < const std::decay_t < Type > && > ( this->shared_from_this ( ), move ), isTemporary );
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 )
return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > & > > ( retrieveValue < std::decay_t < Type > & > ( this->shared_from_this ( ), move ), isTemporary );
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 )
return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > && > > ( retrieveValue < std::decay_t < Type > && > ( this->shared_from_this ( ), move ), isTemporary );
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 )
return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > > > ( retrieveValue < const std::decay_t < Type > > ( this->shared_from_this ( ), move ), isTemporary );
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 ( ), move ), isTemporary );
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 {
......
......@@ -22,8 +22,7 @@ public:
};
template < class ParamType >
ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param, bool move ) {
(void) move;
ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param ) {
using Type = std::decay_t < ParamType >;
std::shared_ptr < ValueHolderInterface < Type > > interface = std::dynamic_pointer_cast < ValueHolderInterface < Type > > ( param->getProxyAbstraction ( ) );
......@@ -36,7 +35,7 @@ ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param,
}*/
if constexpr ( std::is_rvalue_reference_v < ParamType > ) {
if ( move || interface->isTemporary ( ) )
if ( interface->isTemporary ( ) )
return std::move ( interface->getValue ( ) );
else
throw std::domain_error ( "Cannot bind without move" );
......@@ -49,26 +48,26 @@ ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param,
Type && res = interface->getValue ( );
return res;
} else if constexpr ( std::is_copy_constructible_v < Type > && std::is_move_constructible_v < Type > ) {
if ( ! interface->isConst ( ) && ( move || interface->isTemporary ( ) ) )
if ( ! interface->isConst ( ) && interface->isTemporary ( ) )
return std::move ( interface->getValue ( ) );
else {
const Type & res = interface->getValue ( );
return res;
}
} else if constexpr ( std::is_copy_constructible_v < Type > && ! std::is_move_constructible_v < Type > ) {
if ( ! interface->isConst ( ) && ( move || interface->isTemporary ( ) ) )
if ( ! interface->isConst ( ) && interface->isTemporary ( ) )
throw std::domain_error ( "Value not move constructible" );
else {
Type && res = interface->getValue ( );
return res;
}
} else if constexpr ( ! std::is_copy_constructible_v < Type > && std::is_move_constructible_v < Type > ) {
if ( ! interface->isConst ( ) && ( move || interface->isTemporary ( ) ) )
if ( ! interface->isConst ( ) && interface->isTemporary ( ) )
return std::move ( interface->getValue ( ) );
else
throw std::domain_error ( "Value not copy constructible" );
} else { // ! std::is_copy_constructible_v < Type > && ! std::is_move_constructible_v < Type >
if ( ! interface->isConst ( ) && move )
if ( ! interface->isConst ( ) )
throw std::domain_error ( "Value not move constructible" );
else
throw std::domain_error ( "Value not copy constructible" );
......
......@@ -15,6 +15,8 @@ namespace abstraction {
class ValueInterface : public Value {
bool m_isTemporary;
bool m_isCastedToTemporaryRvalue = false;
protected:
ValueInterface ( bool isTemporary ) : m_isTemporary ( isTemporary ) {
}
......@@ -29,16 +31,25 @@ public:
}
bool isRvalueRef ( ) const {
if ( m_isCastedToTemporaryRvalue )
return true;
return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::RREF;
}
bool isLvalueRef ( ) const {
return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::LREF;
if ( m_isCastedToTemporaryRvalue )
return false;
return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::LREF;
}
bool isTemporary ( ) const {
return m_isTemporary;
return m_isTemporary || m_isCastedToTemporaryRvalue;
}
void castToTemporaryRvalue ( ) { //FIXME I do not like this method
m_isCastedToTemporaryRvalue = true;
}
};
} /* namespace abstraction */
......
......@@ -22,7 +22,7 @@ template < class ReturnType >
class ValueOperationAbstraction : virtual public OperationAbstraction {
public:
template < typename ... ParamTypes, typename Callable >
inline std::shared_ptr < abstraction::Value > run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < abstraction::Value >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
inline std::shared_ptr < abstraction::Value > run_helper ( Callable callback, const ext::array < std::shared_ptr < abstraction::Value >, sizeof ... ( ParamTypes ) > & inputs ) {
return std::make_shared < abstraction::ValueHolder < ReturnType > > ( abstraction::apply < ParamTypes ... > ( callback, inputs ), std::is_lvalue_reference_v < ReturnType > ? false : true );
}
......@@ -40,7 +40,7 @@ template < >
class ValueOperationAbstraction < void > : virtual public OperationAbstraction {
public:
template < typename ... ParamTypes, typename Callable >
inline std::shared_ptr < abstraction::Value > run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < abstraction::Value >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
inline std::shared_ptr < abstraction::Value > run_helper ( Callable callback, const ext::array < std::shared_ptr < abstraction::Value >, sizeof ... ( ParamTypes ) > & inputs ) {
abstraction::apply < ParamTypes ... > ( callback, inputs );
return std::make_shared < abstraction::Void > ( );
}
......
......@@ -22,10 +22,10 @@ public:
}
std::shared_ptr < abstraction::Value > run ( ) override {
std::pair < std::shared_ptr < abstraction::Value >, bool > & firstParam = std::get < 0 > ( this->getParams ( ) );
std::pair < std::shared_ptr < abstraction::Value >, bool > & secondParam = std::get < 1 > ( this->getParams ( ) );
std::shared_ptr < abstraction::Value > & firstParam = std::get < 0 > ( this->getParams ( ) );
std::shared_ptr < abstraction::Value > & secondParam = std::get < 1 > ( this->getParams ( ) );
retrieveValue < std::ostream & > ( secondParam.first, secondParam.second ) << retrieveValue < const ParamType & > ( firstParam.first, firstParam.second ) << std::endl;
retrieveValue < std::ostream & > ( secondParam ) << retrieveValue < const ParamType & > ( firstParam ) << std::endl;
return std::make_shared < abstraction::Void > ( );
}
};
......
......@@ -23,10 +23,10 @@ class UnspecifiedType {
template < size_t NumberOfParams >
class WrapperAbstractionImpl : public OperationAbstraction {
std::shared_ptr < OperationAbstraction > m_abstraction;
ext::array < std::pair < std::shared_ptr < abstraction::Value >, bool >, NumberOfParams > m_params;
ext::array < std::shared_ptr < abstraction::Value >, NumberOfParams > m_params;
protected:
ext::array < std::pair < std::shared_ptr < abstraction::Value >, bool >, NumberOfParams > & getParams ( ) {
ext::array < std::shared_ptr < abstraction::Value >, NumberOfParams > & getParams ( ) {
return m_params;
}
......@@ -42,38 +42,35 @@ protected:
void attachInputsToAbstraction ( ) {
for ( size_t index = 0; index < NumberOfParams; ++ index )
this->m_abstraction->attachInput ( m_params [ index ].first, index, m_params [ index ].second );
this->m_abstraction->attachInput ( m_params [ index ], index );
}
public:
WrapperAbstractionImpl ( ) {
for ( size_t i = 0; i < NumberOfParams; ++ i ) {
m_params [ i ].first = nullptr;
m_params [ i ].second = false;
m_params [ i ] = nullptr;
}
}
private:
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) override {
void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index ) override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ].first = input;
m_params [ index ].second = move;
m_params [ index ] = input;
}
void detachInput ( size_t index ) override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ].first = nullptr;
m_params [ index ].second = false;
m_params [ index ] = nullptr;
}
public:
bool inputsAttached ( ) const override {
for ( const std::pair < std::shared_ptr < abstraction::Value >, bool > & param : m_params )
if ( ! param.first )
for ( const std::shared_ptr < abstraction::Value > & param : m_params )
if ( ! param )
return false;
return true;
......
......@@ -14,7 +14,7 @@ namespace detail {
template < class ... ParamTypes, class F, class Tuple, std::size_t... I >
constexpr decltype ( auto ) apply_impl ( F && f, Tuple && t, std::index_sequence < I ... > ) {
return std::invoke ( std::forward < F > ( f ), abstraction::retrieveValue < ParamTypes > ( std::get < I > ( std::forward < Tuple > ( t ) ).first->getProxyAbstraction ( ), std::get < I > ( std::forward < Tuple > ( t ) ).second ) ... );
return std::invoke ( std::forward < F > ( f ), abstraction::retrieveValue < ParamTypes > ( std::get < I > ( std::forward < Tuple > ( t ) )->getProxyAbstraction ( ) ) ... );
}
} // namespace detail
......
......@@ -5,13 +5,13 @@
namespace abstraction {
std::shared_ptr < abstraction::Value > CastHelper::eval ( abstraction::TemporariesHolder &, const std::shared_ptr < abstraction::Value > & param, const std::string & type, bool move ) {
std::shared_ptr < abstraction::Value > CastHelper::eval ( abstraction::TemporariesHolder &, const std::shared_ptr < abstraction::Value > & param, const std::string & type ) {
if ( abstraction::Registry::isCastNoOp ( type, param->getType ( ) ) ) {
return param;
}
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( type, param->getType ( ) );
res->attachInput ( param, 0, move );
res->attachInput ( param, 0 );
std::shared_ptr < abstraction::Value > result = res->eval ( );
if ( ! result )
......@@ -19,7 +19,7 @@ std::shared_ptr < abstraction::Value > CastHelper::eval ( abstraction::Temporari
if ( abstraction::Registry::hasNormalize ( result->getType ( ) ) ) {
std::shared_ptr < abstraction::OperationAbstraction > normalize = abstraction::Registry::getNormalizeAbstraction ( result->getType ( ) );
normalize->attachInput ( result, 0, true );
normalize->attachInput ( result, 0 );
result = normalize->eval ( );
if ( ! result )
throw std::invalid_argument ( "Eval of normalize of cast to " + type + " failed." );
......
......@@ -10,7 +10,7 @@ namespace abstraction {
class CastHelper {
public:
static std::shared_ptr < abstraction::Value > eval ( abstraction::TemporariesHolder & environment, const std::shared_ptr < abstraction::Value > & param, const std::string & type, bool move );
static std::shared_ptr < abstraction::Value > eval ( abstraction::TemporariesHolder & environment, const std::shared_ptr < abstraction::Value > & param, const std::string & type );
};
......
......@@ -13,7 +13,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, const std::vector < bool > & moves, abstraction::AlgorithmCategories::AlgorithmCategory category ) {
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 ) {