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

data: extern value holder

parent cc74b2a9
No related branches found
No related tags found
1 merge request!221New normalization
Showing
with 57 additions and 25 deletions
......@@ -56,39 +56,52 @@ template < class Type >
class ValueHolder : public std::conditional_t < std::is_reference_v < Type >, ReferenceImpl < std::decay_t < Type > >, ValueImpl < std::decay_t < Type > > > {
bool m_isTemporary;
 
abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override {
return abstraction::TypeQualifiers::typeQualifiers < Type > ( );
}
abstraction::TypeQualifiers::TypeQualifierSet getTypeQualifiers ( ) const override;
 
core::type_details getActualType ( ) const override {
return core::type_details::get ( this->getValue ( ) );
}
core::type_details getActualType ( ) const override;
 
core::type_details getDeclaredType ( ) const override {
return core::type_details::get < std::decay_t < Type > > ( );
}
core::type_details getDeclaredType ( ) const override;
 
bool isTemporary ( ) const override {
return m_isTemporary;
}
 
std::unique_ptr < abstraction::Value > asValue ( bool move, bool temporary ) override {
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
return std::make_unique < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->shared_from_this ( ), move ), temporary );
}
std::unique_ptr < abstraction::Value > asValue ( bool move, bool temporary ) override;
public:
ValueHolder ( Type && value, bool temporary ) : m_isTemporary ( temporary ) {
if ( TypeQualifiers::isLvalueRef ( abstraction::TypeQualifiers::typeQualifiers < Type > ( ) ) && this->isTemporary ( ) )
throw std::domain_error ( "Lvalue references cannot be temporaries." );
this->setValue ( std::forward < Type > ( value ) );
}
ValueHolder ( Type && value, bool temporary );
};
 
} /* namespace abstraction */
template < class Type >
abstraction::TypeQualifiers::TypeQualifierSet ValueHolder < Type >::getTypeQualifiers ( ) const {
return abstraction::TypeQualifiers::typeQualifiers < Type > ( );
}
 
template < class Type >
core::type_details ValueHolder < Type >::getActualType ( ) const {
return core::type_details::get ( this->getValue ( ) );
}
template < class Type >
core::type_details ValueHolder < Type >::getDeclaredType ( ) const {
return core::type_details::get < std::decay_t < Type > > ( );
}
template < class Type >
std::unique_ptr < abstraction::Value > ValueHolder < Type >::asValue ( bool move, bool temporary ) {
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
return std::make_unique < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->shared_from_this ( ), move ), temporary );
}
template < class Type >
ValueHolder < Type >::ValueHolder ( Type && value, bool temporary ) : m_isTemporary ( temporary ) {
if ( TypeQualifiers::isLvalueRef ( abstraction::TypeQualifiers::typeQualifiers < Type > ( ) ) && this->isTemporary ( ) )
throw std::domain_error ( "Lvalue references cannot be temporaries." );
this->setValue ( std::forward < Type > ( value ) );
}
} /* namespace abstraction */
......@@ -5,6 +5,7 @@
#include <registration/ComponentRegistration.hpp>
 
template class automaton::CompactDFA < >;
template class abstraction::ValueHolder < automaton::CompactDFA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::CompactDFA < > & >;
template class registration::NormalizationRegisterImpl < automaton::CompactDFA < > >;
 
......
......@@ -778,5 +778,6 @@ struct type_details_retriever < automaton::CompactDFA < SymbolType, StateType >
} /* namespace core */
 
extern template class automaton::CompactDFA < >;
extern template class abstraction::ValueHolder < automaton::CompactDFA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::CompactDFA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::CompactDFA < > >;
......@@ -5,6 +5,7 @@
#include <registration/ComponentRegistration.hpp>
 
template class automaton::CompactNFA < >;
template class abstraction::ValueHolder < automaton::CompactNFA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::CompactNFA < > & >;
template class registration::NormalizationRegisterImpl < automaton::CompactNFA < > >;
 
......
......@@ -849,5 +849,6 @@ struct type_details_retriever < automaton::CompactNFA < SymbolType, StateType >
} /* namespace core */
 
extern template class automaton::CompactNFA < >;
extern template class abstraction::ValueHolder < automaton::CompactNFA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::CompactNFA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::CompactNFA < > >;
......@@ -3,6 +3,7 @@
#include <registration/ValuePrinterRegistration.hpp>
 
template class automaton::DFA < >;
template class abstraction::ValueHolder < automaton::DFA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::DFA < > & >;
template class registration::NormalizationRegisterImpl < automaton::DFA < > >;
 
......
......@@ -771,5 +771,6 @@ struct type_details_retriever < automaton::DFA < SymbolType, StateType > > {
} /* namespace core */
 
extern template class automaton::DFA < >;
extern template class abstraction::ValueHolder < automaton::DFA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::DFA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::DFA < > >;
......@@ -4,6 +4,7 @@
#include <registration/CastRegistration.hpp>
 
template class automaton::EpsilonNFA < >;
template class abstraction::ValueHolder < automaton::EpsilonNFA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::EpsilonNFA < > & >;
template class registration::NormalizationRegisterImpl < automaton::EpsilonNFA < > >;
 
......
......@@ -1062,5 +1062,6 @@ struct type_details_retriever < automaton::EpsilonNFA < SymbolType, StateType >
} /* namespace core */
 
extern template class automaton::EpsilonNFA < >;
extern template class abstraction::ValueHolder < automaton::EpsilonNFA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::EpsilonNFA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::EpsilonNFA < > >;
......@@ -4,6 +4,7 @@
#include <registration/CastRegistration.hpp>
 
template class automaton::ExtendedNFA < >;
template class abstraction::ValueHolder < automaton::ExtendedNFA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::ExtendedNFA < > & >;
template class registration::NormalizationRegisterImpl < automaton::ExtendedNFA < > >;
 
......
......@@ -875,5 +875,6 @@ struct type_details_retriever < automaton::ExtendedNFA < SymbolType, StateType >
} /* namespace core */
 
extern template class automaton::ExtendedNFA < >;
extern template class abstraction::ValueHolder < automaton::ExtendedNFA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::ExtendedNFA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::ExtendedNFA < > >;
......@@ -4,6 +4,7 @@
#include <registration/CastRegistration.hpp>
 
template class automaton::MultiInitialStateEpsilonNFA < >;
template class abstraction::ValueHolder < automaton::MultiInitialStateEpsilonNFA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::MultiInitialStateEpsilonNFA < > & >;
template class registration::NormalizationRegisterImpl < automaton::MultiInitialStateEpsilonNFA < > >;
 
......
......@@ -1107,5 +1107,6 @@ struct type_details_retriever < automaton::MultiInitialStateEpsilonNFA < SymbolT
} /* namespace core */
 
extern template class automaton::MultiInitialStateEpsilonNFA < >;
extern template class abstraction::ValueHolder < automaton::MultiInitialStateEpsilonNFA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::MultiInitialStateEpsilonNFA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::MultiInitialStateEpsilonNFA < > >;
......@@ -4,6 +4,7 @@
#include <registration/CastRegistration.hpp>
 
template class automaton::MultiInitialStateNFA < >;
template class abstraction::ValueHolder < automaton::MultiInitialStateNFA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::MultiInitialStateNFA < > & >;
template class registration::NormalizationRegisterImpl < automaton::MultiInitialStateNFA < > >;
 
......
......@@ -836,5 +836,6 @@ struct type_details_retriever < automaton::MultiInitialStateNFA < SymbolType, St
} /* namespace core */
 
extern template class automaton::MultiInitialStateNFA < >;
extern template class abstraction::ValueHolder < automaton::MultiInitialStateNFA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::MultiInitialStateNFA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::MultiInitialStateNFA < > >;
......@@ -4,6 +4,7 @@
#include <registration/CastRegistration.hpp>
 
template class automaton::NFA < >;
template class abstraction::ValueHolder < automaton::NFA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::NFA < > & >;
template class registration::NormalizationRegisterImpl < automaton::NFA < > >;
 
......
......@@ -794,5 +794,6 @@ struct type_details_retriever < automaton::NFA < SymbolType, StateType > > {
} /* namespace core */
 
extern template class automaton::NFA < >;
extern template class abstraction::ValueHolder < automaton::NFA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::NFA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::NFA < > >;
......@@ -3,6 +3,7 @@
#include <registration/ValuePrinterRegistration.hpp>
 
template class automaton::DPDA < >;
template class abstraction::ValueHolder < automaton::DPDA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::DPDA < > & >;
template class registration::NormalizationRegisterImpl < automaton::DPDA < > >;
 
......
......@@ -1083,5 +1083,6 @@ struct type_details_retriever < automaton::DPDA < InputSymbolType, PushdownStore
} /* namespace core */
 
extern template class automaton::DPDA < >;
extern template class abstraction::ValueHolder < automaton::DPDA < > >;
extern template class registration::DenormalizationRegisterImpl < const automaton::DPDA < > & >;
extern template class registration::NormalizationRegisterImpl < automaton::DPDA < > >;
......@@ -3,6 +3,7 @@
#include <registration/ValuePrinterRegistration.hpp>
 
template class automaton::InputDrivenDPDA < >;
template class abstraction::ValueHolder < automaton::InputDrivenDPDA < > >;
template class registration::DenormalizationRegisterImpl < const automaton::InputDrivenDPDA < > & >;
template class registration::NormalizationRegisterImpl < automaton::InputDrivenDPDA < > >;
 
......
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