Skip to content

Commit

Permalink
Moved stuffs into runtime namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtahu committed Apr 28, 2013
1 parent dae27f8 commit 2512dac
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 45 deletions.
4 changes: 3 additions & 1 deletion AssingmentStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions ListVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include "ListVariable.h"

namespace runtime {

using namespace std;

ListVarable::ListVarable(string name):Variable(name) {
this->head=NULL;
}
Expand All @@ -26,3 +30,5 @@ ListVarable::~ListVarable() {
item=this->head;
}//end while list items
}

}//end namespace runtime
10 changes: 6 additions & 4 deletions ListVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@

#include "Variable.h"

namespace runtime {

class ListItem {
public:
string value;
std::string value;
ListItem *next;
public:
};

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_ */
32 changes: 32 additions & 0 deletions ScalarVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,39 @@
* Author: jimtahu
*/

#include <map>
#include "ScalarVariable.h"

namespace runtime{

using namespace std;

map<string, ScalarVariable*> 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="";
}
Expand All @@ -27,3 +58,4 @@ ScalarVariable::~ScalarVariable() {
// TODO Auto-generated destructor stub
}

}//end namespace runtime
14 changes: 10 additions & 4 deletions ScalarVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
31 changes: 3 additions & 28 deletions Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,12 @@
* Author: jimtahu
*/

#include <map>

#include "Variable.h"
#include "ScalarVariable.h"

using namespace std;
namespace runtime{

map<string, ScalarVariable*> 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;
Expand All @@ -54,3 +28,4 @@ Variable::~Variable(){
// TODO Auto-generated destructor stub
}

}//end namespace runtime
12 changes: 5 additions & 7 deletions Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@

#include <string>

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_ */

0 comments on commit 2512dac

Please sign in to comment.