diff --git a/alib2abstraction/src/abstraction/PackingAbstraction.cpp b/alib2abstraction/src/abstraction/PackingAbstraction.cpp index 4d42bda8293bcb0f1d10325fa43c35784d2857c2..eb4e24e85c81cb4dea33507a75b045bea6d79719 100644 --- a/alib2abstraction/src/abstraction/PackingAbstraction.cpp +++ b/alib2abstraction/src/abstraction/PackingAbstraction.cpp @@ -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::TypeQualifiers::TypeQualifierSet, bool ) { +std::shared_ptr < abstraction::Value > PackingAbstractionImpl::LazyValue::asValue ( bool, bool ) { throw std::domain_error ( "Feature not available on lazy value" ); } @@ -37,4 +37,10 @@ const std::shared_ptr < abstraction::OperationAbstraction > & PackingAbstraction return m_lifeReference; } +bool PackingAbstractionImpl::LazyValue::isTemporary ( ) const { + if ( cache == nullptr ) + throw std::domain_error ( "Feature not available on unevaluated value" ); + return cache->isTemporary ( ); +} + } /* namespace abstraction */ diff --git a/alib2abstraction/src/abstraction/PackingAbstraction.hpp b/alib2abstraction/src/abstraction/PackingAbstraction.hpp index 657f629b43d34823f5d5645de7a4d402753f9f9c..81d790783cf67837980108d0bfe58774ecc88140 100644 --- a/alib2abstraction/src/abstraction/PackingAbstraction.hpp +++ b/alib2abstraction/src/abstraction/PackingAbstraction.hpp @@ -25,7 +25,7 @@ protected: public: LazyValue ( const std::shared_ptr < abstraction::OperationAbstraction > & ref ); - std::shared_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) override; + std::shared_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override; ext::type_index getTypeIndex ( ) const override; @@ -34,6 +34,8 @@ protected: std::shared_ptr < abstraction::Value > getProxyAbstraction ( ) override; const std::shared_ptr < abstraction::OperationAbstraction > & getLifeReference ( ) const; + + bool isTemporary ( ) const override; }; struct ConnectionTarget { diff --git a/alib2abstraction/src/abstraction/TemporariesHolder.cpp b/alib2abstraction/src/abstraction/TemporariesHolder.cpp index 5852e26918e4d76a6a95a85e0ce32ef45d68d2d7..2c9e25d20d64d051b303d31b6aee356b5a5010f3 100644 --- a/alib2abstraction/src/abstraction/TemporariesHolder.cpp +++ b/alib2abstraction/src/abstraction/TemporariesHolder.cpp @@ -3,14 +3,10 @@ namespace abstraction { void TemporariesHolder::holdTemporary ( std::shared_ptr < abstraction::Value > temporary ) { - temporary->increaseTemporaryReference ( ); m_temporaries.push_back ( std::move ( temporary ) ); } void TemporariesHolder::clearTemporaries ( ) { - for ( std::shared_ptr < abstraction::Value > & temporary : m_temporaries ) { - temporary->decreaseTemporaryReference ( ); - } m_temporaries.clear ( ); } diff --git a/alib2abstraction/src/abstraction/Value.cpp b/alib2abstraction/src/abstraction/Value.cpp index 882c13d24cf2ac85ac7f421867cadd200091e393..41c8d5e5805ed9906e0ecd82f5888cdb98d6f00c 100644 --- a/alib2abstraction/src/abstraction/Value.cpp +++ b/alib2abstraction/src/abstraction/Value.cpp @@ -18,8 +18,52 @@ std::string Value::getType ( ) const { return ext::to_string ( getTypeIndex ( ) ); } +std::shared_ptr < abstraction::Value > Value::clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) { + if ( TypeQualifiers::isRef ( typeQualifiers ) ) { + if ( TypeQualifiers::isConst ( this->getTypeQualifiers ( ) ) && ! TypeQualifiers::isConst ( typeQualifiers ) ) + throw std::domain_error ( "Cannot bind const value to non-const reference." ); + if ( ! this->isTemporary ( ) && isTemporary ) + throw std::domain_error ( "Cannot bind without move." ); + return std::make_shared < abstraction::ValueReference > ( this->getProxyAbstraction ( ), typeQualifiers, isTemporary ); + } else { + return this->asValue ( this->isTemporary ( ), isTemporary ); + } +} + -std::shared_ptr < abstraction::Value > Void::clone ( abstraction::TypeQualifiers::TypeQualifierSet, bool ) { +std::shared_ptr < abstraction::Value > ValueReference::asValue ( bool move, bool isTemporary ) { + return getProxyAbstraction ( )->asValue ( move, isTemporary ); +} + +ValueReference::ValueReference ( std::shared_ptr < abstraction::Value > value, abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) : m_value ( value ), m_typeQualifiers ( typeQualifiers ), m_isTemporary ( isTemporary ) { + if ( ! abstraction::TypeQualifiers::isRef ( typeQualifiers ) ) + throw std::domain_error ( "Reference qualifier required" ); + if ( TypeQualifiers::isLvalueRef ( this->getTypeQualifiers ( ) ) && this->isTemporary ( ) ) + throw std::domain_error ( "Lvalue references cannot be temporaries." ); +} + +std::shared_ptr < abstraction::Value > ValueReference::getProxyAbstraction ( ) { + if ( m_value.expired ( ) ) + throw std::domain_error ( "Use of expired reference" ); + return m_value.lock ( )->getProxyAbstraction ( ); +} + +abstraction::TypeQualifiers::TypeQualifierSet ValueReference::getTypeQualifiers ( ) const { + return m_typeQualifiers; +} + +ext::type_index ValueReference::getTypeIndex ( ) const { + if ( m_value.expired ( ) ) + throw std::domain_error ( "Use of expired reference" ); + return m_value.lock ( )->getTypeIndex ( ); +} + +bool ValueReference::isTemporary ( ) const { + return m_isTemporary; +} + + +std::shared_ptr < abstraction::Value > Void::asValue ( bool, bool ) { throw std::domain_error ( "Void variables are not allowed" ); } @@ -31,4 +75,8 @@ abstraction::TypeQualifiers::TypeQualifierSet Void::getTypeQualifiers ( ) const return abstraction::TypeQualifiers::typeQualifiers < void > ( ); } +bool Void::isTemporary ( ) const { + return false; +} + } /* namespace abstraction */ diff --git a/alib2abstraction/src/abstraction/Value.hpp b/alib2abstraction/src/abstraction/Value.hpp index 08671525f31bbd545a7237fe482b0e4d3aad7cb3..51751351e7b161ab8f7a2ca3c21e42e007d01782 100644 --- a/alib2abstraction/src/abstraction/Value.hpp +++ b/alib2abstraction/src/abstraction/Value.hpp @@ -17,14 +17,16 @@ namespace abstraction { class OperationAbstraction; +class ValueReference; class Value : public std::enable_shared_from_this < Value > { - size_t m_temporaryReferences = 0; +protected: + virtual std::shared_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) = 0; public: virtual ~Value ( ) noexcept = default; - virtual std::shared_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) = 0; + std::shared_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifierSet, bool isTemporary ); virtual std::shared_ptr < abstraction::Value > getProxyAbstraction ( ); @@ -34,30 +36,40 @@ public: virtual abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const = 0; - void increaseTemporaryReference ( ) { - m_temporaryReferences += 1; - } + virtual bool isTemporary ( ) const = 0; - void decreaseTemporaryReference ( ) { - if ( m_temporaryReferences == 0 ) - throw std::domain_error ( "Attempted to decrease temporary reference count bellow zero" ); + friend class ValueReference; +}; + +class ValueReference : public Value { + std::weak_ptr < abstraction::Value > m_value; + + abstraction::TypeQualifiers::TypeQualifierSet m_typeQualifiers; + bool m_isTemporary; + + std::shared_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override; + +public: + ValueReference ( std::shared_ptr < abstraction::Value > value, abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ); + + std::shared_ptr < abstraction::Value > getProxyAbstraction ( ) override; - m_temporaryReferences -= 1; - } + abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override; + + ext::type_index getTypeIndex ( ) const override; - size_t getTemporaryReferences ( ) const { - return m_temporaryReferences; - } + bool isTemporary ( ) const override; }; class Void : public Value { public: - std::shared_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) override; + std::shared_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override; ext::type_index getTypeIndex ( ) const override; abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override; + bool isTemporary ( ) const override; }; } /* namespace abstraction */ diff --git a/alib2abstraction/src/abstraction/ValueHolder.hpp b/alib2abstraction/src/abstraction/ValueHolder.hpp index aa267dc6842b7fc10b84f41db183cbf9f368bede..0e70fc07c80cc73e1538a18bb259da567a3ea618 100644 --- a/alib2abstraction/src/abstraction/ValueHolder.hpp +++ b/alib2abstraction/src/abstraction/ValueHolder.hpp @@ -16,141 +16,72 @@ namespace abstraction { template < class Type > -class ValueHolderImpl : public ValueHolderInterface < Type > { - mutable std::optional < Type > m_data; +class ValueImpl : public ValueHolderInterface < std::decay_t < Type > > { + std::optional < std::decay_t < Type > > m_data; public: using ValueHolderInterface < Type >::ValueHolderInterface; - void setData ( Type && data ) { - m_data = std::move ( data ); - } - - Type && getValue ( ) const override { - return std::move ( m_data.value ( ) ); - } -}; - -template < class Type > -class ValueHolderImpl < const Type > : public ValueHolderInterface < Type > { - mutable std::optional < Type > m_data; - -public: - using ValueHolderInterface < Type >::ValueHolderInterface; - - void setData ( const Type && data ) { + void setValue ( const Type & data ) override { m_data = std::move ( const_cast < Type && > ( data ) ); } - Type && getValue ( ) const override { + Type && getValue ( ) override { return std::move ( m_data.value ( ) ); } }; template < class Type > -class ValueHolderImpl < Type & > : public ValueHolderInterface < Type > { - mutable std::optional < std::reference_wrapper < Type > > m_data; +class ReferenceImpl : public ValueHolderInterface < Type > { + std::optional < std::reference_wrapper < Type > > m_data; public: using ValueHolderInterface < Type >::ValueHolderInterface; - void setData ( Type & data ) { - m_data = std::reference_wrapper < Type > ( data ); - } - - Type && getValue ( ) const override { - return std::move ( m_data->get ( ) ); - } -}; - -template < class Type > -class ValueHolderImpl < const Type & > : public ValueHolderInterface < Type > { - mutable std::optional < std::reference_wrapper < Type > > m_data; - -public: - using ValueHolderInterface < Type >::ValueHolderInterface; - - void setData ( const Type & data ) { + void setValue ( const Type & data ) override { m_data = std::reference_wrapper < Type > ( const_cast < Type & > ( data ) ); } - Type && getValue ( ) const override { + Type && getValue ( ) override { return std::move ( m_data->get ( ) ); } }; template < class Type > -class ValueHolderImpl < Type && > : public ValueHolderInterface < Type > { - mutable std::optional < std::reference_wrapper < Type > > m_data; - -public: - using ValueHolderInterface < Type >::ValueHolderInterface; - - void setData ( Type && data ) { - m_data = std::reference_wrapper < Type > ( data ); - } +class ValueHolder : public std::conditional_t < std::is_reference_v < Type >, ReferenceImpl < std::decay_t < Type > >, ValueImpl < std::decay_t < Type > > > { + bool m_isTemporary; - Type && getValue ( ) const override { - return std::move ( m_data->get ( ) ); + abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override { + return abstraction::TypeQualifiers::typeQualifiers < Type > ( ); } -}; - -template < class Type > -class ValueHolderImpl < const Type && > : public ValueHolderInterface < Type > { - mutable std::optional < std::reference_wrapper < Type > > m_data; - -public: - using ValueHolderInterface < Type >::ValueHolderInterface; - void setData ( const Type && data ) { - m_data = std::reference_wrapper < Type > ( const_cast < Type & > ( data ) ); + ext::type_index getTypeIndex ( ) const override { + return ext::type_index ( typeid ( std::decay_t < Type > ) ); } - Type && getValue ( ) const override { - return std::move ( m_data->get ( ) ); + bool isTemporary ( ) const override { + return m_isTemporary; } -}; -template < class Type > -class ValueHolder : public ValueHolderImpl < Type > { -public: - ValueHolder ( Type && value, bool temporary ) : ValueHolderImpl < Type > ( temporary ) { - if ( this->isLvalueRef ( ) && this->isTemporary ( ) ) - throw std::domain_error ( "Lvalue references cannot be temporaries." ); + std::shared_ptr < abstraction::Value > asValue ( bool move, bool temporary ) override { + ( void ) move; + ( void ) temporary; - this->setData ( std::forward < Type > ( value ) ); - } - - 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 ( 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 ( 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 ( 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 ( 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 > > ) + 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 ( 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 ); + return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->shared_from_this ( ), move ), temporary ); } - abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override { - return abstraction::TypeQualifiers::typeQualifiers < Type > ( ); - } +public: + ValueHolder ( Type && value, bool temporary ) : m_isTemporary ( temporary ) { + if ( TypeQualifiers::isLvalueRef ( this->getTypeQualifiers ( ) ) && this->isTemporary ( ) ) + throw std::domain_error ( "Lvalue references cannot be temporaries." ); - ext::type_index getTypeIndex ( ) const override { - return ext::type_index ( typeid ( std::decay_t < Type > ) ); + this->setValue ( std::forward < Type > ( value ) ); } - }; } /* namespace abstraction */ diff --git a/alib2abstraction/src/abstraction/ValueHolderInterface.hpp b/alib2abstraction/src/abstraction/ValueHolderInterface.hpp index 4d4fbade8510ad5f710c5ec8243be18b0e68f8ec..31a2d6ab60f1df9848d21cd81a672f710ccb281c 100644 --- a/alib2abstraction/src/abstraction/ValueHolderInterface.hpp +++ b/alib2abstraction/src/abstraction/ValueHolderInterface.hpp @@ -8,21 +8,23 @@ #ifndef _VALUE_HOLDER_INTERFACE_HPP_ #define _VALUE_HOLDER_INTERFACE_HPP_ -#include <abstraction/ValueInterface.hpp> +#include <abstraction/Value.hpp> namespace abstraction { template < class Type > -class ValueHolderInterface : public ValueInterface { +class ValueHolderInterface : public Value { public: - using ValueInterface::ValueInterface; + using Value::Value; - virtual Type && getValue ( ) const = 0; + virtual void setValue ( const Type & ) = 0; + + virtual Type && getValue ( ) = 0; }; template < class ParamType > -ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param ) { +ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param, bool move = false ) { using Type = std::decay_t < ParamType >; std::shared_ptr < ValueHolderInterface < Type > > interface = std::dynamic_pointer_cast < ValueHolderInterface < Type > > ( param->getProxyAbstraction ( ) ); @@ -35,7 +37,7 @@ ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param ) }*/ if constexpr ( std::is_rvalue_reference_v < ParamType > ) { - if ( interface->isTemporary ( ) ) + if ( param->isTemporary ( ) || move ) return std::move ( interface->getValue ( ) ); else throw std::domain_error ( "Cannot bind without move" ); @@ -43,31 +45,31 @@ ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param ) Type && res = interface->getValue ( ); return res; } else if constexpr ( std::is_lvalue_reference_v < ParamType > ) { - if ( interface->isTemporary ( ) && ! interface->isRef ( ) ) + if ( ( param->isTemporary ( ) || move ) && ! TypeQualifiers::isRef ( param->getTypeQualifiers ( ) ) ) throw std::domain_error ( "Cannot bind temporary to non-const reference" ); Type && res = interface->getValue ( ); return res; } else if constexpr ( std::is_copy_constructible_v < Type > && std::is_move_constructible_v < Type > ) { - if ( ! interface->isConst ( ) && interface->isTemporary ( ) ) + if ( ! TypeQualifiers::isConst ( param->getTypeQualifiers ( ) ) && ( param->isTemporary ( ) || move ) ) 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 ( ) && interface->isTemporary ( ) ) + if ( ! TypeQualifiers::isConst ( param->getTypeQualifiers ( ) ) && ( param->isTemporary ( ) || move ) ) 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 ( ) && interface->isTemporary ( ) ) + if ( ! TypeQualifiers::isConst ( param->getTypeQualifiers ( ) ) && ( param->isTemporary ( ) || move ) ) 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 ( ) ) + if ( ! TypeQualifiers::isConst ( param->getTypeQualifiers ( ) ) ) throw std::domain_error ( "Value not move constructible" ); else throw std::domain_error ( "Value not copy constructible" ); diff --git a/alib2abstraction/src/abstraction/ValueInterface.hpp b/alib2abstraction/src/abstraction/ValueInterface.hpp deleted file mode 100644 index 8aecd60b27417ece0fc13630b7edb4ed4b99a9ec..0000000000000000000000000000000000000000 --- a/alib2abstraction/src/abstraction/ValueInterface.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ValueHolderInterface.hpp - * - * Created on: 11. 7. 2017 - * Author: Jan Travnicek - */ - -#ifndef _VALUE_INTERFACE_HPP_ -#define _VALUE_INTERFACE_HPP_ - -#include <abstraction/Value.hpp> - -namespace abstraction { - -class ValueInterface : public Value { - bool m_isTemporary; - - bool m_isCastedToTemporaryRvalue = false; - -protected: - ValueInterface ( bool isTemporary ) : m_isTemporary ( isTemporary ) { - } - -public: - bool isConst ( ) const { - return TypeQualifiers::isConst ( getTypeQualifiers ( ) ); - } - - bool isRef ( ) const { - return isRvalueRef ( ) || isLvalueRef ( ); - } - - bool isRvalueRef ( ) const { - if ( m_isCastedToTemporaryRvalue ) - return true; - return TypeQualifiers::isRvalueRef ( getTypeQualifiers ( ) ); - } - - bool isLvalueRef ( ) const { - if ( m_isCastedToTemporaryRvalue ) - return false; - return TypeQualifiers::isLvalueRef ( getTypeQualifiers ( ) ); - } - - bool isTemporary ( ) const { - return m_isTemporary || m_isCastedToTemporaryRvalue; - } - - void castToTemporaryRvalue ( ) { //FIXME I do not like this method - m_isCastedToTemporaryRvalue = true; - } - -}; - -} /* namespace abstraction */ - -#endif /* _VALUE_INTERFACE_HPP_ */ diff --git a/alib2abstraction/src/common/AbstractionHelpers.hpp b/alib2abstraction/src/common/AbstractionHelpers.hpp index 557813a2ca129f4d638ff7ae5600078cddc49fcf..f8d43a634cc0acc9037f748b3865fbb409528910 100644 --- a/alib2abstraction/src/common/AbstractionHelpers.hpp +++ b/alib2abstraction/src/common/AbstractionHelpers.hpp @@ -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 ) )->getProxyAbstraction ( ) ) ... ); + return std::invoke ( std::forward < F > ( f ), abstraction::retrieveValue < ParamTypes > ( std::get < I > ( std::forward < Tuple > ( t ) ) ) ... ); } } // namespace detail diff --git a/alib2cli/src/builtin/Move.h b/alib2cli/src/builtin/Move.h index 6ca38c62b0724c4ce6e3de5bc39e165d5c5a26e5..b47bb6782e2678f8426ca55507d69d851e8145f0 100644 --- a/alib2cli/src/builtin/Move.h +++ b/alib2cli/src/builtin/Move.h @@ -8,7 +8,7 @@ #ifndef _MOVE_H_ #define _MOVE_H_ -#include <abstraction/ValueInterface.hpp> +#include <abstraction/Value.hpp> namespace cli { @@ -21,24 +21,18 @@ namespace builtin { class Move { public: static std::shared_ptr < abstraction::Value > move ( std::vector < std::shared_ptr < abstraction::Value > > params ) { - if ( std::static_pointer_cast < abstraction::ValueInterface > ( params [ 0 ] )->isTemporary ( ) ) { + if ( params [ 0 ]->isTemporary ( ) ) { abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers = abstraction::TypeQualifiers::TypeQualifierSet::RREF; if ( params [ 0 ]->getTypeQualifiers ( ) && abstraction::TypeQualifiers::TypeQualifierSet::CONST ) typeQualifiers = typeQualifiers | abstraction::TypeQualifiers::TypeQualifierSet::CONST; return params [ 0 ]->clone ( typeQualifiers, true ); } else { - abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers = abstraction::TypeQualifiers::TypeQualifierSet::LREF; + abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers = abstraction::TypeQualifiers::TypeQualifierSet::RREF; if ( params [ 0 ]->getTypeQualifiers ( ) && abstraction::TypeQualifiers::TypeQualifierSet::CONST ) typeQualifiers = typeQualifiers | abstraction::TypeQualifiers::TypeQualifierSet::CONST; - std::shared_ptr < abstraction::Value > cloned = params [ 0 ]->clone ( typeQualifiers, false ); - std::static_pointer_cast < abstraction::ValueInterface > ( cloned )->castToTemporaryRvalue ( ); - - abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers2 = abstraction::TypeQualifiers::TypeQualifierSet::RREF; - if ( params [ 0 ]->getTypeQualifiers ( ) && abstraction::TypeQualifiers::TypeQualifierSet::CONST ) - typeQualifiers2 = typeQualifiers2 | abstraction::TypeQualifiers::TypeQualifierSet::CONST; - return cloned->clone ( typeQualifiers2, true ); + return std::make_shared < abstraction::ValueReference > ( params [ 0 ], typeQualifiers, true ); } } };