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

move stream selection to global data

parent 79fe90c3
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define _CLI_RESULT_PRINT_STATEMENT_H_ #define _CLI_RESULT_PRINT_STATEMENT_H_
   
#include <ast/Statement.h> #include <ast/Statement.h>
#include <global/GlobalData.h>
   
namespace cli { namespace cli {
   
...@@ -10,8 +11,8 @@ public: ...@@ -10,8 +11,8 @@ public:
ResultPrintStatement ( ) { ResultPrintStatement ( ) {
} }
   
virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & 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 ( ), environment.getOutput ( ) ); std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getValuePrinterAbstraction ( prev->getReturnType ( ), common::Streams::out );
   
if ( res->numberOfParams ( ) == 0 ) if ( res->numberOfParams ( ) == 0 )
return res; return res;
......
...@@ -11,13 +11,11 @@ class Environment { ...@@ -11,13 +11,11 @@ class Environment {
ext::map < std::string, std::shared_ptr < abstraction::OperationAbstraction > > m_variables; ext::map < std::string, std::shared_ptr < abstraction::OperationAbstraction > > m_variables;
   
std::unique_ptr < Environment > m_upper; std::unique_ptr < Environment > m_upper;
std::reference_wrapper < std::ostream > m_output;
public: 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 { std::string getBinding ( const std::string & name ) const {
...@@ -60,14 +58,6 @@ public: ...@@ -60,14 +58,6 @@ public:
return m_variables.erase ( name ); return m_variables.erase ( name );
} }
   
void setOutput ( std::ostream & output ) {
m_output = output;
}
std::ostream & getOutput ( ) const {
return m_output;
}
}; };
   
} /* namespace cli */ } /* namespace cli */
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "GlobalData.h" #include "GlobalData.h"
#include <cstdlib> #include <cstdlib>
   
#include <iostream>
namespace common { namespace common {
   
bool GlobalData::verbose = false; bool GlobalData::verbose = false;
...@@ -20,4 +22,10 @@ int GlobalData::argc = 0; ...@@ -20,4 +22,10 @@ int GlobalData::argc = 0;
   
char * * GlobalData::argv = NULL; 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 */ } /* common */
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
#ifndef _GLOBAL_DATAH_ #ifndef _GLOBAL_DATAH_
#define _GLOBAL_DATAH_ #define _GLOBAL_DATAH_
   
#include <functional>
#include <istream>
#include <ostream>
namespace common { namespace common {
   
class GlobalData { class GlobalData {
...@@ -20,6 +24,15 @@ public: ...@@ -20,6 +24,15 @@ public:
static char * * argv; 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 */ } /* common */
   
#endif /* _GLOBAL_DATAH_ */ #endif /* _GLOBAL_DATAH_ */
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