diff --git a/alib2cli/src/ast/statements/ResultPrintStatement.h b/alib2cli/src/ast/statements/ResultPrintStatement.h index 87f637b5a506ccdb78be827cc9862033dabe3ad6..1eb472a503caf1834a493d72c189976f01039303 100644 --- a/alib2cli/src/ast/statements/ResultPrintStatement.h +++ b/alib2cli/src/ast/statements/ResultPrintStatement.h @@ -2,6 +2,7 @@ #define _CLI_RESULT_PRINT_STATEMENT_H_ #include <ast/Statement.h> +#include <global/GlobalData.h> namespace cli { @@ -10,8 +11,8 @@ public: ResultPrintStatement ( ) { } - virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override { - std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getValuePrinterAbstraction ( prev->getReturnType ( ), environment.getOutput ( ) ); + 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 ( ), common::Streams::out ); if ( res->numberOfParams ( ) == 0 ) return res; diff --git a/alib2cli/src/environment/Environment.h b/alib2cli/src/environment/Environment.h index e72970fc9b9c51e193ef568b00f179d3647c6380..6edac91dd3008d7f9cabe871479b862f01250634 100644 --- a/alib2cli/src/environment/Environment.h +++ b/alib2cli/src/environment/Environment.h @@ -11,13 +11,11 @@ class Environment { ext::map < std::string, std::shared_ptr < abstraction::OperationAbstraction > > m_variables; std::unique_ptr < Environment > m_upper; - - std::reference_wrapper < std::ostream > m_output; public: - Environment ( ) : m_output ( std::cout ) { + Environment ( ) { } - Environment ( std::unique_ptr < Environment > upper ) : m_upper ( std::move ( upper ) ), m_output ( std::cout ) { + Environment ( std::unique_ptr < Environment > upper ) : m_upper ( std::move ( upper ) ) { } std::string getBinding ( const std::string & name ) const { @@ -60,14 +58,6 @@ public: return m_variables.erase ( name ); } - void setOutput ( std::ostream & output ) { - m_output = output; - } - - std::ostream & getOutput ( ) const { - return m_output; - } - }; } /* namespace cli */ diff --git a/alib2common/src/global/GlobalData.cpp b/alib2common/src/global/GlobalData.cpp index bde73e30ab90c2894d40993b9ea3536529cbdbce..977b577610f552646bacbab1306b64f5b9e591df 100644 --- a/alib2common/src/global/GlobalData.cpp +++ b/alib2common/src/global/GlobalData.cpp @@ -8,6 +8,8 @@ #include "GlobalData.h" #include <cstdlib> +#include <iostream> + namespace common { bool GlobalData::verbose = false; @@ -20,4 +22,10 @@ int GlobalData::argc = 0; char * * GlobalData::argv = NULL; +std::reference_wrapper < std::istream > Streams::in = std::cin; +std::reference_wrapper < std::ostream > Streams::out = std::cout; +std::reference_wrapper < std::ostream > Streams::err = std::cerr; +std::reference_wrapper < std::ostream > Streams::log = std::clog; +std::reference_wrapper < std::ostream > Streams::measure = ext::cmeasure; + } /* common */ diff --git a/alib2common/src/global/GlobalData.h b/alib2common/src/global/GlobalData.h index a0d51368ed8d0dc4711293e2ab5b639b11d65fc1..d08654d778bf591669ce42621629ea0b7959d341 100644 --- a/alib2common/src/global/GlobalData.h +++ b/alib2common/src/global/GlobalData.h @@ -8,6 +8,10 @@ #ifndef _GLOBAL_DATAH_ #define _GLOBAL_DATAH_ +#include <functional> +#include <istream> +#include <ostream> + namespace common { class GlobalData { @@ -20,6 +24,15 @@ public: static char * * argv; }; +class Streams { +public: + static std::reference_wrapper < std::istream > in; + static std::reference_wrapper < std::ostream > out; + static std::reference_wrapper < std::ostream > err; + static std::reference_wrapper < std::ostream > log; + static std::reference_wrapper < std::ostream > measure; +}; + } /* common */ #endif /* _GLOBAL_DATAH_ */