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

do not print statements resulting in void

parent 1427b6c9
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,10 @@ public: ...@@ -12,6 +12,10 @@ public:
   
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override { virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override {
std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getValuePrinterAbstraction ( prev->getReturnType ( ) ); std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getValuePrinterAbstraction ( prev->getReturnType ( ) );
if ( res->numberOfParams ( ) == 0 )
return res;
if ( ! res->attachInput ( prev, 0, false ) ) if ( ! res->attachInput ( prev, 0, false ) )
throw exception::CommonException ( "Can't connect param at 0 of result print statement with result of type " + prev->getReturnType ( ) + "." ); throw exception::CommonException ( "Can't connect param at 0 of result print statement with result of type " + prev->getReturnType ( ) + "." );
if ( ! res->eval ( ) ) if ( ! res->eval ( ) )
......
...@@ -23,6 +23,9 @@ protected: ...@@ -23,6 +23,9 @@ protected:
   
private: private:
virtual bool attachInput ( const std::shared_ptr < OperationAbstraction > & input, unsigned index, bool move ) override { virtual bool attachInput ( const std::shared_ptr < OperationAbstraction > & input, unsigned index, bool move ) override {
if ( index >= m_moves.size ( ) )
throw exception::CommonException ( "Parameter index out of bounds.");
m_moves [ index ] = move; m_moves [ index ] = move;
   
auto attachCallback = [ & ] ( auto & param ) { auto attachCallback = [ & ] ( auto & param ) {
...@@ -37,16 +40,21 @@ private: ...@@ -37,16 +40,21 @@ private:
return false; return false;
} }
}; };
return ext::call_on_nth < bool > ( m_params, index, attachCallback ); return ext::call_on_nth < bool > ( m_params, index, attachCallback );
} }
   
virtual bool detachInput ( unsigned index ) override { virtual bool detachInput ( unsigned index ) override {
if ( index >= m_moves.size ( ) )
throw exception::CommonException ( "Parameter index out of bounds.");
m_moves [ index ] = false; m_moves [ index ] = false;
   
auto detachCallback = [ & ] ( auto & param ) { auto detachCallback = [ & ] ( auto & param ) {
param = nullptr; param = nullptr;
return true; return true;
}; };
return ext::call_on_nth < bool > ( m_params, index, detachCallback ); return ext::call_on_nth < bool > ( m_params, index, detachCallback );
} }
   
......
...@@ -43,6 +43,7 @@ public: ...@@ -43,6 +43,7 @@ public:
abstraction::ValuePrinterRegistry::registerValuePrinter < int > ( ); abstraction::ValuePrinterRegistry::registerValuePrinter < int > ( );
abstraction::ValuePrinterRegistry::registerValuePrinter < double > ( ); abstraction::ValuePrinterRegistry::registerValuePrinter < double > ( );
abstraction::ValuePrinterRegistry::registerValuePrinter < std::string > ( ); abstraction::ValuePrinterRegistry::registerValuePrinter < std::string > ( );
abstraction::ValuePrinterRegistry::registerValuePrinter < void > ( );
   
abstraction::ImmediateRegistry::registerImmediate < int > ( ); abstraction::ImmediateRegistry::registerImmediate < int > ( );
abstraction::ImmediateRegistry::registerImmediate < std::string > ( ); abstraction::ImmediateRegistry::registerImmediate < std::string > ( );
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define _VALUE_PRINTER_ABSTRACTION_HPP_ #define _VALUE_PRINTER_ABSTRACTION_HPP_
   
#include <abstraction/UnaryOperationAbstraction.hpp> #include <abstraction/UnaryOperationAbstraction.hpp>
#include <abstraction/NullaryOperationAbstraction.hpp>
#include <tuple> #include <tuple>
   
namespace abstraction { namespace abstraction {
...@@ -25,6 +26,14 @@ public: ...@@ -25,6 +26,14 @@ public:
} }
}; };
   
template < >
class ValuePrinterAbstraction < void > : public NullaryOperationAbstraction < void > {
public:
virtual bool run ( ) override {
return true;
}
};
} /* namespace abstraction */ } /* namespace abstraction */
   
#endif /* _VALUE_PRINTER_ABSTRACTION_HPP_ */ #endif /* _VALUE_PRINTER_ABSTRACTION_HPP_ */
/*
* ValuePrinterRegistry.cpp
*
* Created on: 21. 7. 2017
* Author: Jan Travnicek
*/
#include <abstraction/ValuePrinterRegistry.hpp>
namespace abstraction {
template < >
std::shared_ptr < abstraction::OperationAbstraction > ValuePrinterRegistry::EntryImpl < void >::getAbstraction ( ) const {
return std::make_shared < abstraction::ValuePrinterAbstraction < void > > ( );
}
} /* namespace abstraction */
...@@ -69,6 +69,9 @@ std::shared_ptr < abstraction::OperationAbstraction > ValuePrinterRegistry::Entr ...@@ -69,6 +69,9 @@ std::shared_ptr < abstraction::OperationAbstraction > ValuePrinterRegistry::Entr
return std::make_shared < abstraction::ValuePrinterAbstraction < const Param & > > ( ); return std::make_shared < abstraction::ValuePrinterAbstraction < const Param & > > ( );
} }
   
template < >
std::shared_ptr < abstraction::OperationAbstraction > ValuePrinterRegistry::EntryImpl < void >::getAbstraction ( ) const;
} /* namespace abstraction */ } /* namespace abstraction */
   
#endif /* _VALUE_PRINTER_REGISTRY_HPP_ */ #endif /* _VALUE_PRINTER_REGISTRY_HPP_ */
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