From ae0de1b63ff70c11accdc77c5ee51579d2c366b5 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Wed, 2 Aug 2017 18:18:36 +0200
Subject: [PATCH] refactor names of statements

---
 alib2cli/src/ast/params/BindedValueParam.h    |  2 +-
 .../src/ast/statements/BindedValueStatement.h | 23 ++++++++++++
 ...tatement.h => ResultBindedFileStatement.h} | 10 +++---
 ...esultStatement.h => ResultFileStatement.h} | 10 +++---
 ...sultStatement.h => ResultPrintStatement.h} | 10 +++---
 ...tStatement.h => ResultVariableStatement.h} | 10 +++---
 ...sResultStatement.h => VariableStatement.h} | 10 +++---
 alib2cli/src/parser/Parser.cpp                | 35 ++++++++-----------
 alib2cli/src/parser/Parser.h                  |  2 --
 9 files changed, 64 insertions(+), 48 deletions(-)
 create mode 100644 alib2cli/src/ast/statements/BindedValueStatement.h
 rename alib2cli/src/ast/statements/{BindedFileResultStatement.h => ResultBindedFileStatement.h} (66%)
 rename alib2cli/src/ast/statements/{FileResultStatement.h => ResultFileStatement.h} (67%)
 rename alib2cli/src/ast/statements/{PrintResultStatement.h => ResultPrintStatement.h} (68%)
 rename alib2cli/src/ast/statements/{BindedVariableResultStatement.h => ResultVariableStatement.h} (56%)
 rename alib2cli/src/ast/statements/{PreviousResultStatement.h => VariableStatement.h} (58%)

diff --git a/alib2cli/src/ast/params/BindedValueParam.h b/alib2cli/src/ast/params/BindedValueParam.h
index f695465549..ffdaee238e 100644
--- a/alib2cli/src/ast/params/BindedValueParam.h
+++ b/alib2cli/src/ast/params/BindedValueParam.h
@@ -2,7 +2,7 @@
 #define _CLI_BINDED_VALUE_PARAM_H_
 
 #include <ast/Param.h>
-#include <abstraction/Registry.h>
+#include <abstraction/ImmediateValueAbstraction.hpp>
 
 namespace cli {
 
diff --git a/alib2cli/src/ast/statements/BindedValueStatement.h b/alib2cli/src/ast/statements/BindedValueStatement.h
new file mode 100644
index 0000000000..a82a59c94d
--- /dev/null
+++ b/alib2cli/src/ast/statements/BindedValueStatement.h
@@ -0,0 +1,23 @@
+#ifndef _CLI_BINDED_VALUE_STATEMENT_H_
+#define _CLI_BINDED_VALUE_STATEMENT_H_
+
+#include <ast/Statement.h>
+#include <abstraction/ImmediateValueAbstraction.hpp>
+
+namespace cli {
+
+class BindedValueStatement : public Statement {
+	std::string m_bind;
+
+public:
+	BindedValueStatement ( std::string bind ) : m_bind ( std::move ( bind ) ) {
+	}
+
+	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 ) );
+	}
+};
+
+} /* namespace cli */
+
+#endif /* _CLI_BINDED_VALUE_STATEMENT_H_ */
diff --git a/alib2cli/src/ast/statements/BindedFileResultStatement.h b/alib2cli/src/ast/statements/ResultBindedFileStatement.h
similarity index 66%
rename from alib2cli/src/ast/statements/BindedFileResultStatement.h
rename to alib2cli/src/ast/statements/ResultBindedFileStatement.h
index 1b0acded53..b0386a9251 100644
--- a/alib2cli/src/ast/statements/BindedFileResultStatement.h
+++ b/alib2cli/src/ast/statements/ResultBindedFileStatement.h
@@ -1,15 +1,15 @@
-#ifndef _CLI_BINDED_FILE_RESULT_STATEMENT_H_
-#define _CLI_BINDED_FILE_RESULT_STATEMENT_H_
+#ifndef _CLI_RESULT_BINDED_FILE_STATEMENT_H_
+#define _CLI_RESULT_BINDED_FILE_STATEMENT_H_
 
 #include <ast/Statement.h>
 
 namespace cli {
 
-class BindedFileResultStatement : public Statement {
+class ResultBindedFileStatement : public Statement {
 	std::string m_bind;
 
 public:
-	BindedFileResultStatement ( std::string bind ) : m_bind ( bind ) {
+	ResultBindedFileStatement ( std::string bind ) : m_bind ( bind ) {
 	}
 
 	virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override {
@@ -23,4 +23,4 @@ public:
 
 } /* namespace cli */
 
-#endif /* _CLI_BINDED_FILE_RESULT_STATEMENT_H_ */
+#endif /* _CLI_RESULT_BINDED_FILE_STATEMENT_H_ */
diff --git a/alib2cli/src/ast/statements/FileResultStatement.h b/alib2cli/src/ast/statements/ResultFileStatement.h
similarity index 67%
rename from alib2cli/src/ast/statements/FileResultStatement.h
rename to alib2cli/src/ast/statements/ResultFileStatement.h
index 5fb85260b0..b28852e042 100644
--- a/alib2cli/src/ast/statements/FileResultStatement.h
+++ b/alib2cli/src/ast/statements/ResultFileStatement.h
@@ -1,15 +1,15 @@
-#ifndef _CLI_FILE_RESULT_STATEMENT_H_
-#define _CLI_FILE_RESULT_STATEMENT_H_
+#ifndef _CLI_RESULT_FILE_STATEMENT_H_
+#define _CLI_RESULT_FILE_STATEMENT_H_
 
 #include <ast/Statement.h>
 
 namespace cli {
 
-class FileResultStatement : public Statement {
+class ResultFileStatement : public Statement {
 	std::string m_name;
 
 public:
-	FileResultStatement ( std::string name ) : m_name ( name ) {
+	ResultFileStatement ( std::string name ) : m_name ( name ) {
 	}
 
 	virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override {
@@ -23,4 +23,4 @@ public:
 
 } /* namespace cli */
 
-#endif /* _CLI_FILE_RESULT_STATEMENT_H_ */
+#endif /* _CLI_RESULT_FILE_STATEMENT_H_ */
diff --git a/alib2cli/src/ast/statements/PrintResultStatement.h b/alib2cli/src/ast/statements/ResultPrintStatement.h
similarity index 68%
rename from alib2cli/src/ast/statements/PrintResultStatement.h
rename to alib2cli/src/ast/statements/ResultPrintStatement.h
index 20ea47223a..86b043633b 100644
--- a/alib2cli/src/ast/statements/PrintResultStatement.h
+++ b/alib2cli/src/ast/statements/ResultPrintStatement.h
@@ -1,13 +1,13 @@
-#ifndef _CLI_PRINT_RESULT_STATEMENT_H_
-#define _CLI_PRINT_RESULT_STATEMENT_H_
+#ifndef _CLI_RESULT_PRINT_STATEMENT_H_
+#define _CLI_RESULT_PRINT_STATEMENT_H_
 
 #include <ast/Statement.h>
 
 namespace cli {
 
-class PrintResultStatement : public Statement {
+class ResultPrintStatement : public Statement {
 public:
-	PrintResultStatement ( ) {
+	ResultPrintStatement ( ) {
 	}
 
 	virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override {
@@ -21,4 +21,4 @@ public:
 
 } /* namespace cli */
 
-#endif /* _CLI_PRINT_RESULT_STATEMENT_H_ */
+#endif /* _CLI_RESULT_PRINT_STATEMENT_H_ */
diff --git a/alib2cli/src/ast/statements/BindedVariableResultStatement.h b/alib2cli/src/ast/statements/ResultVariableStatement.h
similarity index 56%
rename from alib2cli/src/ast/statements/BindedVariableResultStatement.h
rename to alib2cli/src/ast/statements/ResultVariableStatement.h
index 66c4f9f287..755624bd34 100644
--- a/alib2cli/src/ast/statements/BindedVariableResultStatement.h
+++ b/alib2cli/src/ast/statements/ResultVariableStatement.h
@@ -1,15 +1,15 @@
-#ifndef _CLI_BINDED_VARIABLE_RESULT_STATEMENT_H_
-#define _CLI_BINDED_VARIABLE_RESULT_STATEMENT_H_
+#ifndef _CLI_RESULT_VARIABLE_STATEMENT_H_
+#define _CLI_RESULT_VARIABLE_STATEMENT_H_
 
 #include <ast/Statement.h>
 
 namespace cli {
 
-class BindedVariableResultStatement : public Statement {
+class ResultVariableStatement : public Statement {
 	std::string m_bind;
 
 public:
-	BindedVariableResultStatement ( std::string bind ) : m_bind ( bind ) {
+	ResultVariableStatement ( std::string bind ) : m_bind ( bind ) {
 	}
 
 	virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override {
@@ -21,4 +21,4 @@ public:
 
 } /* namespace cli */
 
-#endif /* _CLI_BINDED_VARIABLE_RESULT_STATEMENT_H_ */
+#endif /* _CLI_RESULT_VARIABLE_STATEMENT_H_ */
diff --git a/alib2cli/src/ast/statements/PreviousResultStatement.h b/alib2cli/src/ast/statements/VariableStatement.h
similarity index 58%
rename from alib2cli/src/ast/statements/PreviousResultStatement.h
rename to alib2cli/src/ast/statements/VariableStatement.h
index f120ad48fc..ab5afdac8f 100644
--- a/alib2cli/src/ast/statements/PreviousResultStatement.h
+++ b/alib2cli/src/ast/statements/VariableStatement.h
@@ -1,16 +1,16 @@
-#ifndef _CLI_PREVIOUS_RESULT_STATEMENT_H_
-#define _CLI_PREVIOUS_RESULT_STATEMENT_H_
+#ifndef _CLI_VARIABLE_STATEMENT_H_
+#define _CLI_VARIABLE_STATEMENT_H_
 
 #include <string>
 #include <ast/Statement.h>
 
 namespace cli {
 
-class PreviousResultStatement : public Statement {
+class VariableStatement : public Statement {
 	std::string m_name;
 
 public:
-	PreviousResultStatement ( std::string name ) : m_name ( std::move ( name ) ) {
+	VariableStatement ( std::string name ) : m_name ( std::move ( name ) ) {
 	}
 
 	virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override {
@@ -20,4 +20,4 @@ public:
 
 } /* namespace cli */
 
-#endif /* _CLI_PREVIOUS_RESULT_STATEMENT_H_ */
+#endif /* _CLI_VARIABLE_STATEMENT_H_ */
diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp
index 61b57dbf4e..2b0016d9ef 100644
--- a/alib2cli/src/parser/Parser.cpp
+++ b/alib2cli/src/parser/Parser.cpp
@@ -2,11 +2,12 @@
 
 #include <ast/statements/CastStatement.h>
 #include <ast/statements/SingleStatement.h>
-#include <ast/statements/FileResultStatement.h>
-#include <ast/statements/BindedFileResultStatement.h>
-#include <ast/statements/BindedVariableResultStatement.h>
-#include <ast/statements/PrintResultStatement.h>
-#include <ast/statements/PreviousResultStatement.h>
+#include <ast/statements/ResultFileStatement.h>
+#include <ast/statements/ResultBindedFileStatement.h>
+#include <ast/statements/ResultVariableStatement.h>
+#include <ast/statements/ResultPrintStatement.h>
+#include <ast/statements/VariableStatement.h>
+#include <ast/statements/BindedValueStatement.h>
 
 #include <ast/params/StatementParam.h>
 #include <ast/params/ImmediateFileParam.h>
@@ -77,22 +78,16 @@ std::unique_ptr < Param > Parser::param ( ) {
 	}
 }
 
-std::shared_ptr < Statement > Parser::first_statement ( ) {
+std::shared_ptr < Statement > Parser::single_statement ( ) {
 	if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) {
 		match ( cli::Lexer::TokenType::DOLAR_SIGN );
 		std::string name = matchIdentifier ( );
-		return std::make_shared < PreviousResultStatement > ( std::move ( name ) );
+		return std::make_shared < VariableStatement > ( std::move ( name ) );
 	} else if ( check ( cli::Lexer::TokenType::COLON_SIGN ) ) {
 		match ( cli::Lexer::TokenType::COLON_SIGN );
 		std::string name = matchIdentifier ( );
-		return std::make_shared < PreviousResultStatement > ( std::move ( name ) );
-	} else {
-		return single_statement ( );
-	}
-}
-
-std::shared_ptr < Statement > Parser::single_statement ( ) {
-	if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) {
+		return std::make_shared < BindedValueStatement > ( std::move ( name ) );
+	} else if ( check ( cli::Lexer::TokenType::LEFT_PAREN ) ) {
 		match ( cli::Lexer::TokenType::LEFT_PAREN );
 		std::string type = matchIdentifier ( );
 		match ( cli::Lexer::TokenType::RIGHT_PAREN );
@@ -112,7 +107,7 @@ std::shared_ptr < Statement > Parser::single_statement ( ) {
 }
 
 std::shared_ptr < StatementList > Parser::statement_list ( ) {
-	std::shared_ptr < Statement > statement = first_statement ( );
+	std::shared_ptr < Statement > statement = single_statement ( );
 	return std::make_shared < StatementList > ( statement, statement_list_cont ( ) );
 }
 
@@ -131,15 +126,15 @@ void Parser::out_redirect ( std::shared_ptr < StatementList > & list ) {
 		match ( cli::Lexer::TokenType::COLON_SIGN );
 		std::string name = getTokenValue ( );
 		match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
-		list->append ( std::make_unique < BindedFileResultStatement > ( std::move ( name ) ) );
+		list->append ( std::make_unique < ResultBindedFileStatement > ( std::move ( name ) ) );
 	} else if ( check ( cli::Lexer::TokenType::DOLAR_SIGN ) ) {
 		match ( cli::Lexer::TokenType::DOLAR_SIGN );
 		std::string name = getTokenValue ( );
 		match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
-		list->append ( std::make_unique < BindedVariableResultStatement > ( std::move ( name ) ) );
+		list->append ( std::make_unique < ResultVariableStatement > ( std::move ( name ) ) );
 	} else {
 		std::string filename = matchIdentifier ( );
-		list->append ( std::make_unique < FileResultStatement > ( std::move ( filename ) ) );
+		list->append ( std::make_unique < ResultFileStatement > ( std::move ( filename ) ) );
 	}
 }
 
@@ -148,7 +143,7 @@ void Parser::result ( std::shared_ptr < StatementList > & list ) {
 		match ( cli::Lexer::TokenType::OUT_REDIRECT );
 		out_redirect ( list );
 	} else if ( check ( cli::Lexer::TokenType::END ) ) {
-		list->append ( std::make_unique < PrintResultStatement > ( ) );
+		list->append ( std::make_unique < ResultPrintStatement > ( ) );
 	} else {
 		return;
 	}
diff --git a/alib2cli/src/parser/Parser.h b/alib2cli/src/parser/Parser.h
index d03ba802d5..15a7de2bc0 100644
--- a/alib2cli/src/parser/Parser.h
+++ b/alib2cli/src/parser/Parser.h
@@ -72,8 +72,6 @@ public:
 
 	std::unique_ptr < Param > param ( );
 
-	std::shared_ptr < Statement > first_statement ( );
-
 	std::shared_ptr < Statement > single_statement ( );
 
 	std::shared_ptr < StatementList > statement_list ( );
-- 
GitLab