From 2512dac68408875486ffe538da943c5711291b78 Mon Sep 17 00:00:00 2001 From: jimtahu Date: Sun, 28 Apr 2013 14:59:42 -0500 Subject: [PATCH] Moved stuffs into runtime namespace --- AssingmentStatement.cpp | 4 +++- Identifier.cpp | 3 ++- ListVariable.cpp | 6 ++++++ ListVariable.h | 10 ++++++---- ScalarVariable.cpp | 32 ++++++++++++++++++++++++++++++++ ScalarVariable.h | 14 ++++++++++---- Variable.cpp | 31 +++---------------------------- Variable.h | 12 +++++------- 8 files changed, 67 insertions(+), 45 deletions(-) diff --git a/AssingmentStatement.cpp b/AssingmentStatement.cpp index b596d4d..a8fa520 100644 --- a/AssingmentStatement.cpp +++ b/AssingmentStatement.cpp @@ -6,10 +6,12 @@ */ #include "AssingmentStatement.h" -#include "Variable.h" +#include "ScalarVariable.h" namespace ParseTree { +using namespace runtime; + AssingmentStatement::AssingmentStatement(Identifier *id, Value *value) { this->id=id; this->value=value; diff --git a/Identifier.cpp b/Identifier.cpp index c5aa3a5..f3b3910 100644 --- a/Identifier.cpp +++ b/Identifier.cpp @@ -6,11 +6,12 @@ */ #include "Identifier.h" -#include "Variable.h" +#include "ScalarVariable.h" namespace ParseTree { using namespace std; +using namespace runtime; Identifier::Identifier(string name) { this->Name = name; diff --git a/ListVariable.cpp b/ListVariable.cpp index 4e395cf..8897f8e 100644 --- a/ListVariable.cpp +++ b/ListVariable.cpp @@ -7,6 +7,10 @@ #include "ListVariable.h" +namespace runtime { + +using namespace std; + ListVarable::ListVarable(string name):Variable(name) { this->head=NULL; } @@ -26,3 +30,5 @@ ListVarable::~ListVarable() { item=this->head; }//end while list items } + +}//end namespace runtime diff --git a/ListVariable.h b/ListVariable.h index 631a72d..370eb5e 100644 --- a/ListVariable.h +++ b/ListVariable.h @@ -10,9 +10,11 @@ #include "Variable.h" +namespace runtime { + class ListItem { public: - string value; + std::string value; ListItem *next; public: }; @@ -20,9 +22,9 @@ class ListItem { class ListVarable: public Variable { ListItem *head; public: - ListVarable(string name); - void add(string value); + ListVarable(std::string name); + void add(std::string value); virtual ~ListVarable(); }; - +}//end namespace runtime #endif /* LIST_H_ */ diff --git a/ScalarVariable.cpp b/ScalarVariable.cpp index 0a65c92..ae18476 100644 --- a/ScalarVariable.cpp +++ b/ScalarVariable.cpp @@ -5,8 +5,39 @@ * Author: jimtahu */ +#include #include "ScalarVariable.h" +namespace runtime{ + +using namespace std; + +map scalarTable; + +/** +* Places a varable into the table. +* @param name The lable for the varable. +* @param value The value the varable now holds. +* @return value, for convienace. +*/ +string setScalar(string name, string value){ + if(scalarTable.count(name)==0)scalarTable[name]=new ScalarVariable(name); + scalarTable[name]->SetValue(value); + return value; +}//end setValue + +/** +* Fetches the value for a varable. +* @param name The lable of the varable to fetch. +* @return the value. +* Fetching a variable which has not been stored is undefined. +*/ +string getScalar(string name){ + if(scalarTable.count(name)) + return scalarTable[name]->GetValue(); + else return "EMPTY"; +}//end getValue + ScalarVariable::ScalarVariable(string name):Variable(name){ this->Value=""; } @@ -27,3 +58,4 @@ ScalarVariable::~ScalarVariable() { // TODO Auto-generated destructor stub } +}//end namespace runtime diff --git a/ScalarVariable.h b/ScalarVariable.h index 0f906fb..adb2bda 100644 --- a/ScalarVariable.h +++ b/ScalarVariable.h @@ -10,14 +10,20 @@ #include "Variable.h" +namespace runtime { + +std::string setScalar(std::string name, std::string value); +std::string getScalar(std::string name); + class ScalarVariable: public Variable { - string Value; + std::string Value; public: - ScalarVariable(string name); + ScalarVariable(std::string name); ScalarVariable(ScalarVariable &other); - string GetValue(); - void SetValue(string value); + std::string GetValue(); + void SetValue(std::string value); virtual ~ScalarVariable(); }; +}//end namespace runtime #endif /* SCALARVARIABLE_H_ */ diff --git a/Variable.cpp b/Variable.cpp index 2eda14a..712496a 100644 --- a/Variable.cpp +++ b/Variable.cpp @@ -5,38 +5,12 @@ * Author: jimtahu */ -#include #include "Variable.h" -#include "ScalarVariable.h" -using namespace std; +namespace runtime{ -map varTable; - -/** -* Places a varable into the table. -* @param name The lable for the varable. -* @param value The value the varable now holds. -* @return value, for convienace. -*/ -string setScalar(string name, string value){ - if(varTable.count(name)==0)varTable[name]=new ScalarVariable(name); - varTable[name]->SetValue(value); - return value; -}//end setValue - -/** -* Fetches the value for a varable. -* @param name The lable of the varable to fetch. -* @return the value. -* Fetching a variable which has not been stored is undefined. -*/ -string getScalar(string name){ - if(varTable.count(name)) - return varTable[name]->GetValue(); - else return "EMPTY"; -}//end getValue +using namespace std; Variable::Variable(string name){ this->Name=name; @@ -54,3 +28,4 @@ Variable::~Variable(){ // TODO Auto-generated destructor stub } +}//end namespace runtime diff --git a/Variable.h b/Variable.h index 66a31bf..db7ac0a 100644 --- a/Variable.h +++ b/Variable.h @@ -10,19 +10,17 @@ #include -using namespace std; - -string setScalar(string name, string value); -string getScalar(string name); +namespace runtime { class Variable { private: - string Name; + std::string Name; public: - Variable(string name); + Variable(std::string name); Variable(Variable &other); - virtual string GetName(); + virtual std::string GetName(); virtual ~Variable(); }; +}//end namespace runtime #endif /* VARIABLE_H_ */