diff --git a/alib2abstraction/src/abstraction/PackingAbstraction.cpp b/alib2abstraction/src/abstraction/PackingAbstraction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd38605bb3f1ae285f994dd639f02e5328ca5fcc --- /dev/null +++ b/alib2abstraction/src/abstraction/PackingAbstraction.cpp @@ -0,0 +1,11 @@ +/* + * PackingAbstraction.hpp + * + * Created on: 20. 8. 2017 + * Author: Jan Travnicek + */ + +#include "PackingAbstraction.hpp" + +template class abstraction::PackingAbstraction < 2 >; +template class abstraction::PackingAbstraction < 3 >; diff --git a/alib2abstraction/src/abstraction/PackingAbstraction.hpp b/alib2abstraction/src/abstraction/PackingAbstraction.hpp index 98e50e80cb99fae02e513db5ca49d6335485a7c7..77227cadba2dafe70f8dfd449a8449baacedba01 100644 --- a/alib2abstraction/src/abstraction/PackingAbstraction.hpp +++ b/alib2abstraction/src/abstraction/PackingAbstraction.hpp @@ -12,43 +12,10 @@ #include <alib/array> #include <abstraction/OperationAbstraction.hpp> +#include <abstraction/Value.hpp> namespace abstraction { -class LazyValue : public Value { - std::shared_ptr < Value > cache; - -public: - LazyValue ( std::shared_ptr < abstraction::OperationAbstraction > ref ) : Value ( ref ) { - } - - virtual bool evaluated ( ) const { - throw std::domain_error ( "" ); - } - - virtual std::shared_ptr < abstraction::Value > cloneAsVariable ( bool /*isConst*/, bool /*isRvalueRef*/, bool /*isLvalueRef*/, bool /*move*/ ) { - throw std::domain_error ( "" ); - } - - virtual std::shared_ptr < abstraction::Value > cloneAsValue ( bool /*isConst*/, bool /*isRvalueRef*/, bool /*isLvalueRef*/, bool /*move*/ ) { - throw std::domain_error ( "" ); - } - - virtual ext::type_index getTypeIndex ( ) const { - return this->getLifeReference( )->getReturnTypeIndex ( ); - } - - virtual ext::set < abstraction::ParamQualifiers::ParamQualifier > getTypeQualifiers ( ) const { - return this->getLifeReference ( )->getReturnTypeQualifiers ( ); - } - - virtual std::shared_ptr < abstraction::Value > getProxyAbstraction ( ) { - if ( cache == nullptr ) - cache = this->getLifeReference ( )->eval ( ); - return cache; - } -}; - template < size_t NumberOfParams > class PackingAbstraction : public OperationAbstraction { struct ConnectionTarget { @@ -148,4 +115,7 @@ public: } /* namespace abstraction */ +extern template class abstraction::PackingAbstraction < 2 >; +extern template class abstraction::PackingAbstraction < 3 >; + #endif /* _PACKING_ABSTRACTION_HPP_ */ diff --git a/alib2abstraction/src/abstraction/Value.cpp b/alib2abstraction/src/abstraction/Value.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a8a5e496d07dd7d9743aa404ca4f18b5521d8615 --- /dev/null +++ b/alib2abstraction/src/abstraction/Value.cpp @@ -0,0 +1,71 @@ +/* + * ValueHolderInterface.hpp + * + * Created on: 11. 7. 2017 + * Author: Jan Travnicek + */ + +#include <abstraction/Value.hpp> +#include <abstraction/OperationAbstraction.hpp> + +namespace abstraction { + +Value::Value ( std::shared_ptr < abstraction::OperationAbstraction > ref ) : m_lifeReference ( ref ) { +} + +std::shared_ptr < abstraction::Value > Value::getProxyAbstraction ( ) { + return shared_from_this ( ); +} + +std::string Value::getType ( ) const { + return ext::to_string ( getTypeIndex ( ) ); +} + +const std::shared_ptr < abstraction::OperationAbstraction > Value::getLifeReference ( ) const { + return m_lifeReference; +} + + +std::shared_ptr < abstraction::Value > Void::cloneAsVariable ( bool, bool, bool, bool ) { + throw std::domain_error ( "Void variables are not allowed" ); +} + +std::shared_ptr < abstraction::Value > Void::cloneAsValue ( bool, bool, bool, bool ) { + return getProxyAbstraction ( ); +} + +ext::type_index Void::getTypeIndex ( ) const { + return ext::type_index ( typeid ( void ) ); +} + +ext::set < abstraction::ParamQualifiers::ParamQualifier > Void::getTypeQualifiers ( ) const { + return abstraction::ParamQualifiers::paramQualifiers < void > ( ); +} + + +LazyValue::LazyValue ( std::shared_ptr < abstraction::OperationAbstraction > ref ) : Value ( ref ) { +} + +std::shared_ptr < abstraction::Value > LazyValue::cloneAsVariable ( bool, bool, bool, bool ) { + throw std::domain_error ( "Feature not available on lazy value" ); +} + +std::shared_ptr < abstraction::Value > LazyValue::cloneAsValue ( bool, bool, bool, bool ) { + throw std::domain_error ( "Feature not available on lazy value" ); +} + +ext::type_index LazyValue::getTypeIndex ( ) const { + return this->getLifeReference( )->getReturnTypeIndex ( ); +} + +ext::set < abstraction::ParamQualifiers::ParamQualifier > LazyValue::getTypeQualifiers ( ) const { + return this->getLifeReference ( )->getReturnTypeQualifiers ( ); +} + +std::shared_ptr < abstraction::Value > LazyValue::getProxyAbstraction ( ) { + if ( cache == nullptr ) + cache = this->getLifeReference ( )->eval ( ); + return cache; +} + +} /* namespace abstraction */ diff --git a/alib2abstraction/src/abstraction/Value.hpp b/alib2abstraction/src/abstraction/Value.hpp index 0f83b705093ab486f4b10a05afb1df5c5ac0dc2f..5679f36acf78920d1fd8dc62307b73760fbfd75e 100644 --- a/alib2abstraction/src/abstraction/Value.hpp +++ b/alib2abstraction/src/abstraction/Value.hpp @@ -22,53 +22,53 @@ class Value : public std::enable_shared_from_this < Value > { std::shared_ptr < abstraction::OperationAbstraction > m_lifeReference; public: - Value ( std::shared_ptr < abstraction::OperationAbstraction > ref ) : m_lifeReference ( ref ) { - } + Value ( std::shared_ptr < abstraction::OperationAbstraction > ref ); + + virtual ~Value ( ) noexcept = default; - virtual bool evaluated ( ) const = 0; virtual std::shared_ptr < abstraction::Value > cloneAsVariable ( bool isConst, bool isRvalueRef, bool isLvalueRef, bool move = false ) = 0; virtual std::shared_ptr < abstraction::Value > cloneAsValue ( bool isConst, bool isRvalueRef, bool isLvalueRef, bool move = false ) = 0; - virtual std::shared_ptr < abstraction::Value > getProxyAbstraction ( ) { - return shared_from_this ( ); - } + virtual std::shared_ptr < abstraction::Value > getProxyAbstraction ( ); virtual ext::type_index getTypeIndex ( ) const = 0; - std::string getType ( ) const { - return ext::to_string ( getTypeIndex ( ) ); - } + std::string getType ( ) const; virtual ext::set < abstraction::ParamQualifiers::ParamQualifier > getTypeQualifiers ( ) const = 0; - const std::shared_ptr < abstraction::OperationAbstraction > getLifeReference ( ) const { - return m_lifeReference; - } + const std::shared_ptr < abstraction::OperationAbstraction > getLifeReference ( ) const; }; class Void : public Value { public: using Value::Value; - bool evaluated ( ) const { - return false; - } - std::shared_ptr < abstraction::Value > cloneAsVariable ( bool /*isConst*/, bool /*isRvalueRef*/, bool /*isLvalueRef*/, bool /*move*/ ) override { - throw std::domain_error ( "Void variables are not allowed" ); - } + std::shared_ptr < abstraction::Value > cloneAsVariable ( bool isConst, bool isRvalueRef, bool isLvalueRef, bool move ) override; + + std::shared_ptr < abstraction::Value > cloneAsValue ( bool isConst, bool isRvalueRef, bool isLvalueRef, bool move ) override; + + ext::type_index getTypeIndex ( ) const; + + ext::set < abstraction::ParamQualifiers::ParamQualifier > getTypeQualifiers ( ) const; + +}; + +class LazyValue : public Value { + std::shared_ptr < Value > cache; + +public: + LazyValue ( std::shared_ptr < abstraction::OperationAbstraction > ref ); + + std::shared_ptr < abstraction::Value > cloneAsVariable ( bool, bool, bool, bool ) override; - std::shared_ptr < abstraction::Value > cloneAsValue ( bool /*isConst*/, bool /*isRvalueRef*/, bool /*isLvalueRef*/, bool /*move*/ ) override { - return getProxyAbstraction ( ); - } + std::shared_ptr < abstraction::Value > cloneAsValue ( bool, bool, bool, bool ) override; - ext::type_index getTypeIndex ( ) const { - return ext::type_index ( typeid ( void ) ); - } + ext::type_index getTypeIndex ( ) const override; - ext::set < abstraction::ParamQualifiers::ParamQualifier > getTypeQualifiers ( ) const { - return abstraction::ParamQualifiers::paramQualifiers < void > ( ); - } + ext::set < abstraction::ParamQualifiers::ParamQualifier > getTypeQualifiers ( ) const override; + std::shared_ptr < abstraction::Value > getProxyAbstraction ( ) override; }; } /* namespace abstraction */ diff --git a/alib2abstraction/src/abstraction/ValueHolder.hpp b/alib2abstraction/src/abstraction/ValueHolder.hpp index a2ed918feed523d457bf051bccd52ead0d292f16..66321889b9a145fd3c613efadc2aa13c143680fd 100644 --- a/alib2abstraction/src/abstraction/ValueHolder.hpp +++ b/alib2abstraction/src/abstraction/ValueHolder.hpp @@ -29,10 +29,6 @@ public: void setData ( Type && data ) { m_data = std::move ( data ); } - - bool evaluated ( ) const override { - return ( bool ) m_data; - } }; template < class Type > @@ -49,10 +45,6 @@ public: Type && getValue ( ) const override { return std::move ( m_data.value ( ) ); } - - bool evaluated ( ) const override { - return ( bool ) m_data; - } }; template < class Type > @@ -69,10 +61,6 @@ public: Type && getValue ( ) const override { return std::move ( m_data->get ( ) ); } - - bool evaluated ( ) const override { - return ( bool ) m_data; - } }; template < class Type > @@ -89,10 +77,6 @@ public: Type && getValue ( ) const override { return std::move ( m_data->get ( ) ); } - - bool evaluated ( ) const override { - return ( bool ) m_data; - } }; template < class Type > @@ -109,10 +93,6 @@ public: Type && getValue ( ) const override { return std::move ( m_data->get ( ) ); } - - bool evaluated ( ) const override { - return ( bool ) m_data; - } }; template < class Type > @@ -129,24 +109,17 @@ public: Type && getValue ( ) const override { return std::move ( m_data->get ( ) ); } - - bool evaluated ( ) const override { - return ( bool ) m_data; - } }; template < class Type > class ValueHolder : public ValueHolderImpl < Type > { -public: - ValueHolder ( std::shared_ptr < abstraction::OperationAbstraction > ref ) : ValueHolderImpl < Type > ( ref, std::is_const_v < std::remove_reference_t < Type > >, std::is_rvalue_reference_v < Type >, std::is_lvalue_reference_v < Type >, true ) { - } + using ValueHolderImpl < Type >::ValueHolderImpl; +public: ValueHolder ( std::shared_ptr < abstraction::OperationAbstraction > ref, Type && value ) : ValueHolderImpl < Type > ( ref, std::is_const_v < std::remove_reference_t < Type > >, std::is_rvalue_reference_v < Type >, std::is_lvalue_reference_v < Type >, true ) { this->setData ( std::forward < Type > ( value ) ); } - using ValueHolderImpl < Type >::ValueHolderImpl; - std::shared_ptr < abstraction::Value > cloneAsVariable ( bool isConst, bool isRvalueRef, bool isLvalueRef, bool move ) override { std::shared_ptr < abstraction::ValueHolder < Type > > res = std::make_shared < abstraction::ValueHolder < Type > > ( this->getLifeReference ( ), isConst, isRvalueRef, isLvalueRef, false ); res->setData ( retrieveValue < Type > ( this->getProxyAbstraction ( ), move ) ); diff --git a/alib2abstraction/src/abstraction/ValueOperationAbstraction.hpp b/alib2abstraction/src/abstraction/ValueOperationAbstraction.hpp index 591de0baba03fc2566fe3ddecaae2009f3471314..f2b671e3e074339d43b8412401d2ba26eb248659 100644 --- a/alib2abstraction/src/abstraction/ValueOperationAbstraction.hpp +++ b/alib2abstraction/src/abstraction/ValueOperationAbstraction.hpp @@ -23,9 +23,7 @@ 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 ) { - std::shared_ptr < abstraction::ValueHolder < ReturnType > > value = std::make_shared < abstraction::ValueHolder < ReturnType > > ( this->getProxyAbstraction ( ) ); - value->setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) ); - return value; + return std::make_shared < abstraction::ValueHolder < ReturnType > > ( this->getProxyAbstraction ( ), abstraction::apply < ParamTypes ... > ( callback, inputs ) ); } ext::set < abstraction::ParamQualifiers::ParamQualifier > getReturnTypeQualifiers ( ) const override { diff --git a/alib2abstraction/src/abstraction/WrapperAbstraction.cpp b/alib2abstraction/src/abstraction/WrapperAbstraction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe3d0850dfd6b0fa8df5c98aa32d49329ba8b9cf --- /dev/null +++ b/alib2abstraction/src/abstraction/WrapperAbstraction.cpp @@ -0,0 +1,12 @@ +/* + * WrapperAbstraction.hpp + * + * Created on: 20. 8. 2017 + * Author: Jan Travnicek + */ + +#include "WrapperAbstraction.hpp" + +template class abstraction::WrapperAbstractionImpl < 1 >; +template class abstraction::WrapperAbstractionImpl < 2 >; +template class abstraction::WrapperAbstractionImpl < 3 >; diff --git a/alib2abstraction/src/abstraction/WrapperAbstraction.hpp b/alib2abstraction/src/abstraction/WrapperAbstraction.hpp index 4062fe42b3495c46ba0233153fdc922dc1fe3a78..21f60e7c0319a656d62a656e14b0bd4dfa2f1dd5 100644 --- a/alib2abstraction/src/abstraction/WrapperAbstraction.hpp +++ b/alib2abstraction/src/abstraction/WrapperAbstraction.hpp @@ -8,12 +8,12 @@ #ifndef _WRAPPER_ABSTRACTION_HPP_ #define _WRAPPER_ABSTRACTION_HPP_ -#include <optional> #include <memory> #include <alib/array> #include <abstraction/OperationAbstraction.hpp> +#include <common/AbstractionHelpers.hpp> namespace abstraction { @@ -130,6 +130,14 @@ public: }; +} /* namespace abstraction */ + +extern template class abstraction::WrapperAbstractionImpl < 1 >; +extern template class abstraction::WrapperAbstractionImpl < 2 >; +extern template class abstraction::WrapperAbstractionImpl < 3 >; + +namespace abstraction { + template < class ... ParamTypes > class WrapperAbstraction : public WrapperAbstractionImpl < sizeof ... ( ParamTypes ) > { std::function < std::shared_ptr < abstraction::OperationAbstraction > ( ParamTypes ... ) > m_WrapperFinder; diff --git a/alib2cli/src/ast/statements/ValueStatement.h b/alib2cli/src/ast/statements/ValueStatement.h index e37ffb9c616460eab2708d6e0f5d5fe99d62bca1..216212350440526569df649455cacf8b76a09087 100644 --- a/alib2cli/src/ast/statements/ValueStatement.h +++ b/alib2cli/src/ast/statements/ValueStatement.h @@ -14,9 +14,7 @@ public: } std::shared_ptr < abstraction::Value > translateAndEval ( const std::shared_ptr < abstraction::Value > &, Environment & environment ) const override { - auto result = std::make_shared < abstraction::ValueHolder < std::string > > ( nullptr ); - result->setData ( m_arg->eval ( environment ) ); - return result; + return std::make_shared < abstraction::ValueHolder < std::string > > ( nullptr, m_arg->eval ( environment ) ); } }; diff --git a/alib2cli/src/environment/Environment.h b/alib2cli/src/environment/Environment.h index d21bbf81e86f90f31232bb0eac9631e44b3494b3..2d681ed3efc9edb56960cc0c47176419b6804a55 100644 --- a/alib2cli/src/environment/Environment.h +++ b/alib2cli/src/environment/Environment.h @@ -97,8 +97,7 @@ public: template < class T > void setVariable ( std::string name, T value ) { - auto variable = std::make_shared < abstraction::ValueHolder < T > > ( nullptr ); - variable->setData ( std::move ( value ) ); + auto variable = std::make_shared < abstraction::ValueHolder < T > > ( nullptr, std::move ( value ) ); setVariableInt ( std::move ( name ), variable ); }