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

use registry to get all followup abstractions

parent ec46db21
No related branches found
No related tags found
No related merge requests found
Pipeline #
Showing
with 39 additions and 99 deletions
......@@ -2,7 +2,7 @@
#define _CLI_BINDED_VALUE_PARAM_H_
 
#include <ast/Param.h>
#include <abstraction/ImmediateValueAbstraction.hpp>
#include <abstraction/Registry.h>
 
namespace cli {
 
......@@ -14,7 +14,7 @@ public:
}
 
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override {
return std::make_shared < abstraction::ImmediateValueAbstraction < std::string > > ( environment.getBinding ( m_bind ) );
return abstraction::Registry::getImmediateAbstraction ( ext::to_string < std::string > ( ), environment.getBinding ( m_bind ) );
}
};
 
......
......@@ -18,12 +18,12 @@ public:
 
bool normalize;
 
std::shared_ptr < abstraction::OperationAbstraction > res = translatedParam->getCastFromResult ( m_type, normalize );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( m_type, translatedParam->getReturnType ( ), normalize );
res->attachInput ( translatedParam, 0 );
res->eval ( );
 
if ( normalize ) {
std::shared_ptr < abstraction::OperationAbstraction > normalized = res->getNormalizeResult ( );
std::shared_ptr < abstraction::OperationAbstraction > normalized = abstraction::Registry::getNormalizeAbstraction ( res->getReturnType ( ) );
normalized->attachInput ( res, 0 );
normalized->eval ( );
 
......
......@@ -16,14 +16,14 @@ public:
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override {
std::shared_ptr < abstraction::OperationAbstraction > translatedStatement = m_statement->translateAndEval ( prev, environment );
 
bool normalize = false;
bool normalize;
 
std::shared_ptr < abstraction::OperationAbstraction > res = translatedStatement->getCastFromResult ( m_type, normalize );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( m_type, translatedStatement->getReturnType ( ), normalize );
res->attachInput ( translatedStatement, 0 );
res->eval ( );
 
if ( normalize ) {
std::shared_ptr < abstraction::OperationAbstraction > normalized = res->getNormalizeResult ( );
std::shared_ptr < abstraction::OperationAbstraction > normalized = abstraction::Registry::getNormalizeAbstraction ( res->getReturnType ( ) );
normalized->attachInput ( res, 0 );
normalized->eval ( );
 
......
......@@ -13,7 +13,7 @@ public:
}
 
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override {
std::shared_ptr < abstraction::OperationAbstraction > res = prev->getXmlFileWriterFromResult ( environment.getBinding ( m_bind ) );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getXmlFileWriterAbstraction ( prev->getReturnType ( ), environment.getBinding ( m_bind ) );
res->attachInput ( prev, 0 );
res->eval ( );
return res;
......
......@@ -13,7 +13,7 @@ public:
}
 
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override {
std::shared_ptr < abstraction::OperationAbstraction > res = prev->getXmlFileWriterFromResult ( m_name );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getXmlFileWriterAbstraction ( prev->getReturnType ( ), m_name );
res->attachInput ( prev, 0 );
res->eval ( );
return res;
......
......@@ -11,7 +11,7 @@ public:
}
 
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override {
std::shared_ptr < abstraction::OperationAbstraction > res = prev->getValuePrinterFromResult ( );
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getValuePrinterAbstraction ( prev->getReturnType ( ) );
res->attachInput ( prev, 0 );
res->eval ( );
return res;
......
......@@ -17,8 +17,8 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate
}
 
ext::vector < ext::type_index > paramTypes;
for ( const std::shared_ptr < abstraction::OperationAbstraction > & param : params ) {
paramTypes.push_back ( param->type ( ) );
for ( const std::shared_ptr < abstraction::OperationAbstraction > & param : params ) {
paramTypes.push_back ( param->getReturnTypeIndex ( ) );
}
 
bool downcast = false;
......@@ -29,7 +29,7 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate
unsigned i = 0;
for ( const std::shared_ptr < abstraction::OperationAbstraction > & param : params ) {
if ( ! algo->attachInput ( param, i ) )
throw exception::CommonException ( "Can't connect param at " + ext::to_string ( i ) + " of algorithm " + m_name + " with result of type " + ext::to_string ( param->type ( ) ) + "." );
throw exception::CommonException ( "Can't connect param at " + ext::to_string ( i ) + " of algorithm " + m_name + " with result of type " + param->getReturnType ( ) + "." );
i++;
}
 
......@@ -37,7 +37,7 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate
throw exception::CommonException ( "Eval of algorithm " + m_name + " failed." );
 
if ( downcast ) {
std::shared_ptr < abstraction::OperationAbstraction > downcaster = algo->getDowncastResult ( );
std::shared_ptr < abstraction::OperationAbstraction > downcaster = abstraction::Registry::getDowncastAbstraction ( algo->getRuntimeReturnType ( ), algo->getReturnType ( ) );
downcaster->attachInput ( algo, 0 );
downcaster->eval ( );
 
......@@ -45,7 +45,7 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate
}
 
if ( normalize ) {
std::shared_ptr < abstraction::OperationAbstraction > normalized = algo->getNormalizeResult ( );
std::shared_ptr < abstraction::OperationAbstraction > normalized = abstraction::Registry::getNormalizeAbstraction ( algo->getReturnType ( ) );
normalized->attachInput ( algo, 0 );
normalized->eval ( );
 
......
......@@ -111,21 +111,13 @@ public:
return sizeof ... ( ParamTypes );
}
 
virtual std::shared_ptr < OperationAbstraction > getImmediateValueFromParam ( unsigned index, const std::string & value ) const override {
virtual ext::type_index getParamTypeIndex ( unsigned index ) const override {
auto callback = [ & ] ( auto & param ) {
std::string paramType = ext::to_string < typename std::decay < decltype ( param ) >::type::element_type::return_type > ( );
return Registry::getImmediateAbstraction ( std::move ( paramType ), value );
return ext::type_index ( typeid ( typename std::decay < decltype ( param ) >::type::element_type::return_type ) );
};
return ext::call_on_nth < std::shared_ptr < OperationAbstraction > > ( inputs, index, callback );
return ext::call_on_nth < ext::type_index > ( inputs, index, callback );
}
 
virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned index, ext::deque < sax::Token > tokens ) const override {
auto callback = [ & ] ( auto & param ) {
std::string paramType = ext::to_string < typename std::decay < decltype ( param ) >::type::element_type::return_type > ( );
return Registry::getXmlParserAbstraction ( std::move ( paramType ), std::move ( tokens ) );
};
return ext::call_on_nth < std::shared_ptr < OperationAbstraction > > ( inputs, index, callback );
}
};
 
template < class ReturnType, class ... ParamTypes >
......
......@@ -46,13 +46,10 @@ public:
return 0;
}
 
virtual std::shared_ptr < OperationAbstraction > getImmediateValueFromParam ( unsigned, const std::string & ) const override {
virtual ext::type_index getParamTypeIndex ( unsigned ) const override {
throw exception::CommonException ( "Nullary algorithm does not have any parameter." );
}
 
virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned, ext::deque < sax::Token > ) const override {
throw exception::CommonException ( "Nullary algorithm does not have any parameter." );
}
};
 
} /* namespace abstraction */
......
......@@ -30,19 +30,24 @@ public:
virtual bool inputsAttached ( ) const = 0;
virtual bool run ( ) = 0;
virtual bool eval ( ) = 0;
virtual ext::type_index type ( ) const = 0;
virtual ext::type_index runtime_type ( ) const = 0;
virtual unsigned numberOfParams ( ) const = 0;
virtual bool cached ( ) const = 0;
 
virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned index, ext::deque < sax::Token > tokens ) const = 0;
virtual std::shared_ptr < OperationAbstraction > getImmediateValueFromParam ( unsigned index, const std::string & data ) const = 0;
virtual ext::type_index getParamTypeIndex ( unsigned index ) const = 0;
virtual ext::type_index getReturnTypeIndex ( ) const = 0;
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const = 0;
 
virtual std::shared_ptr < OperationAbstraction > getXmlFileWriterFromResult ( const std::string & filename ) const = 0;
virtual std::shared_ptr < OperationAbstraction > getValuePrinterFromResult ( ) const = 0;
virtual std::shared_ptr < OperationAbstraction > getCastFromResult ( const std::string & type, bool & normalize ) const = 0;
virtual std::shared_ptr < OperationAbstraction > getNormalizeResult ( ) const = 0;
virtual std::shared_ptr < OperationAbstraction > getDowncastResult ( ) const = 0;
std::string getParamType ( unsigned index ) const {
return ext::to_string ( getParamTypeIndex ( index ) );
}
std::string getReturnType ( ) const {
return ext::to_string ( getReturnTypeIndex ( ) );
}
std::string getRuntimeReturnType ( ) const {
return ext::to_string ( getRuntimeReturnTypeIndex ( ) );
}
 
};
 
......
......@@ -69,21 +69,13 @@ public:
return 1;
}
 
virtual std::shared_ptr < OperationAbstraction > getImmediateValueFromParam ( unsigned index, const std::string & value ) const override {
virtual ext::type_index getParamTypeIndex ( unsigned index ) const override {
if ( index != 0 )
throw std::out_of_range ( "Invalid input index" );
 
std::string paramType = ext::to_string < ParamType > ( );
return Registry::getImmediateAbstraction ( std::move ( paramType ), value );
return ext::type_index ( typeid ( ParamType ) );
}
 
virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned index, ext::deque < sax::Token > tokens ) const override {
if ( index != 0 )
throw exception::CommonException ( "Out of range index: " + ext::to_string ( index ) + " max: " + ext::to_string ( numberOfParams ( ) ) + "." );
std::string paramType = ext::to_string < ParamType > ( );
return Registry::getXmlParserAbstraction ( std::move ( paramType ), std::move ( tokens ) );
}
};
 
} /* namespace abstraction */
......
......@@ -44,37 +44,11 @@ public:
return * m_data;
}
 
virtual std::shared_ptr < OperationAbstraction > getXmlFileWriterFromResult ( const std::string & filename ) const override {
std::string param = ext::to_string < ReturnType > ( );
return Registry::getXmlFileWriterAbstraction ( param, filename );
}
virtual std::shared_ptr < OperationAbstraction > getValuePrinterFromResult ( ) const override {
std::string param = ext::to_string < ReturnType > ( );
return Registry::getValuePrinterAbstraction ( param );
}
virtual std::shared_ptr < OperationAbstraction > getCastFromResult ( const std::string & target, bool & normalize ) const override {
std::string param = ext::to_string < ReturnType > ( );
return Registry::getCastAbstraction ( target, param, normalize );
}
virtual std::shared_ptr < OperationAbstraction > getNormalizeResult ( ) const override {
std::string param = ext::to_string < ReturnType > ( );
return Registry::getNormalizeAbstraction ( param );
}
virtual std::shared_ptr < OperationAbstraction > getDowncastResult ( ) const override {
std::string base = ext::to_string < ReturnType > ( );
std::string concrete = ext::to_string ( runtime_type ( ) );
return Registry::getDowncastAbstraction ( concrete, base );
}
virtual ext::type_index type ( ) const override {
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( ReturnType ) );
}
 
virtual ext::type_index runtime_type ( ) const override {
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( isReady ( ) )
return ext::type_index ( typeid ( getData ( ) ) );
else
......
......@@ -25,31 +25,11 @@ public:
callback ( input->getData ( ) );
}
 
virtual std::shared_ptr < OperationAbstraction > getXmlFileWriterFromResult ( const std::string & ) const override {
throw exception::CommonException ( "Void algorithm does not have a result." );
}
virtual std::shared_ptr < OperationAbstraction > getValuePrinterFromResult ( ) const override {
throw exception::CommonException ( "Void algorithm does not have a result." );
}
virtual std::shared_ptr < OperationAbstraction > getCastFromResult ( const std::string &, bool & ) const override {
throw exception::CommonException ( "Void algorithm does not have a result." );
}
virtual std::shared_ptr < OperationAbstraction > getNormalizeResult ( ) const override {
throw exception::CommonException ( "Void algorithm does not have a result." );
}
virtual std::shared_ptr < OperationAbstraction > getDowncastResult ( ) const override {
throw exception::CommonException ( "Void algorithm does not have a result." );
}
virtual ext::type_index type ( ) const override {
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( void ) );
}
 
virtual ext::type_index runtime_type ( ) const override {
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( void ) );
}
 
......
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