Skip to content
Snippets Groups Projects
Commit 6abd7141 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

abstraction: reduce some use of shared_ptrs

parent fe1b5fe7
No related branches found
No related tags found
1 merge request!223Merge jt
...@@ -8,7 +8,7 @@ namespace abstraction { ...@@ -8,7 +8,7 @@ namespace abstraction {
PackingAbstractionImpl::LazyValue::LazyValue ( std::unique_ptr < abstraction::OperationAbstraction > ref ) : m_lifeReference ( std::move ( ref ) ) { PackingAbstractionImpl::LazyValue::LazyValue ( std::unique_ptr < abstraction::OperationAbstraction > ref ) : m_lifeReference ( std::move ( ref ) ) {
} }
   
std::shared_ptr < abstraction::Value > PackingAbstractionImpl::LazyValue::asValue ( bool, bool ) { std::unique_ptr < abstraction::Value > PackingAbstractionImpl::LazyValue::asValue ( bool, bool ) {
throw std::domain_error ( "Feature not available on lazy value" ); throw std::domain_error ( "Feature not available on lazy value" );
} }
   
......
...@@ -17,7 +17,7 @@ protected: ...@@ -17,7 +17,7 @@ protected:
public: public:
explicit LazyValue ( std::unique_ptr < abstraction::OperationAbstraction > ref ); explicit LazyValue ( std::unique_ptr < abstraction::OperationAbstraction > ref );
   
std::shared_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override; std::unique_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override;
   
ext::type_index getTypeIndex ( ) const override; ext::type_index getTypeIndex ( ) const override;
   
......
...@@ -11,20 +11,20 @@ std::string Value::getType ( ) const { ...@@ -11,20 +11,20 @@ std::string Value::getType ( ) const {
return ext::to_string ( getTypeIndex ( ) ); return ext::to_string ( getTypeIndex ( ) );
} }
   
std::shared_ptr < abstraction::Value > Value::clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) { std::unique_ptr < abstraction::Value > Value::clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ) {
if ( TypeQualifiers::isRef ( typeQualifiers ) ) { if ( TypeQualifiers::isRef ( typeQualifiers ) ) {
if ( TypeQualifiers::isConst ( this->getTypeQualifiers ( ) ) && ! TypeQualifiers::isConst ( typeQualifiers ) ) if ( TypeQualifiers::isConst ( this->getTypeQualifiers ( ) ) && ! TypeQualifiers::isConst ( typeQualifiers ) )
throw std::domain_error ( "Cannot bind const value to non-const reference." ); throw std::domain_error ( "Cannot bind const value to non-const reference." );
if ( ! this->isTemporary ( ) && isTemporary ) if ( ! this->isTemporary ( ) && isTemporary )
throw std::domain_error ( "Cannot bind without move." ); throw std::domain_error ( "Cannot bind without move." );
return std::make_shared < abstraction::ValueReference > ( this->getProxyAbstraction ( ), typeQualifiers, isTemporary ); return std::make_unique < abstraction::ValueReference > ( this->getProxyAbstraction ( ), typeQualifiers, isTemporary );
} else { } else {
return this->asValue ( this->isTemporary ( ), isTemporary ); return this->asValue ( this->isTemporary ( ), isTemporary );
} }
} }
   
   
std::shared_ptr < abstraction::Value > ValueReference::asValue ( bool move, bool isTemporary ) { std::unique_ptr < abstraction::Value > ValueReference::asValue ( bool move, bool isTemporary ) {
return getProxyAbstraction ( )->asValue ( move, isTemporary ); return getProxyAbstraction ( )->asValue ( move, isTemporary );
} }
   
...@@ -56,7 +56,7 @@ bool ValueReference::isTemporary ( ) const { ...@@ -56,7 +56,7 @@ bool ValueReference::isTemporary ( ) const {
} }
   
   
std::shared_ptr < abstraction::Value > Void::asValue ( bool, bool ) { std::unique_ptr < abstraction::Value > Void::asValue ( bool, bool ) {
throw std::domain_error ( "Void variables are not allowed" ); throw std::domain_error ( "Void variables are not allowed" );
} }
   
......
...@@ -13,12 +13,12 @@ class ValueReference; ...@@ -13,12 +13,12 @@ class ValueReference;
   
class Value : public std::enable_shared_from_this < Value > { class Value : public std::enable_shared_from_this < Value > {
protected: protected:
virtual std::shared_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) = 0; virtual std::unique_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) = 0;
   
public: public:
virtual ~Value ( ) noexcept = default; virtual ~Value ( ) noexcept = default;
   
std::shared_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ); std::unique_ptr < abstraction::Value > clone ( abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary );
   
virtual std::shared_ptr < abstraction::Value > getProxyAbstraction ( ); virtual std::shared_ptr < abstraction::Value > getProxyAbstraction ( );
   
...@@ -39,7 +39,7 @@ class ValueReference : public Value { ...@@ -39,7 +39,7 @@ class ValueReference : public Value {
abstraction::TypeQualifiers::TypeQualifierSet m_typeQualifiers; abstraction::TypeQualifiers::TypeQualifierSet m_typeQualifiers;
bool m_isTemporary; bool m_isTemporary;
   
std::shared_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override; std::unique_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override;
   
public: public:
ValueReference ( const std::shared_ptr < abstraction::Value > & value, abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary ); ValueReference ( const std::shared_ptr < abstraction::Value > & value, abstraction::TypeQualifiers::TypeQualifierSet typeQualifiers, bool isTemporary );
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
   
class Void : public Value { class Void : public Value {
public: public:
std::shared_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override; std::unique_ptr < abstraction::Value > asValue ( bool move, bool isTemporary ) override;
   
ext::type_index getTypeIndex ( ) const override; ext::type_index getTypeIndex ( ) const override;
   
......
...@@ -57,16 +57,13 @@ class ValueHolder : public std::conditional_t < std::is_reference_v < Type >, Re ...@@ -57,16 +57,13 @@ class ValueHolder : public std::conditional_t < std::is_reference_v < Type >, Re
return m_isTemporary; return m_isTemporary;
} }
   
std::shared_ptr < abstraction::Value > asValue ( bool move, bool temporary ) override { std::unique_ptr < abstraction::Value > asValue ( bool move, bool temporary ) override {
( void ) move;
( void ) temporary;
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." ); 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 > > ) else if constexpr ( ! std::is_assignable_v < std::decay_t < Type > &, std::decay_t < Type > > )
throw std::domain_error ( "Cannot assign value." ); throw std::domain_error ( "Cannot assign value." );
else else
return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->shared_from_this ( ), move ), temporary ); return std::make_unique < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->shared_from_this ( ), move ), temporary );
} }
   
public: public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment