From fc9e26d6438fbbac1c30497486cb447ea613b00c Mon Sep 17 00:00:00 2001 From: jimtahu Date: Sun, 28 Apr 2013 15:48:34 -0500 Subject: [PATCH] Added some cleanup code --- AssingmentStatement.cpp | 3 ++- BinOpValue.cpp | 3 ++- PrintStatement.cpp | 2 +- Program.cpp | 4 +++- ScalarVariable.cpp | 10 ++++++++++ ScalarVariable.h | 1 + Util.cpp | 3 +++ 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/AssingmentStatement.cpp b/AssingmentStatement.cpp index a8fa520..b43e0af 100644 --- a/AssingmentStatement.cpp +++ b/AssingmentStatement.cpp @@ -22,7 +22,8 @@ void AssingmentStatement::Execute(){ } AssingmentStatement::~AssingmentStatement() { - // TODO Auto-generated destructor stub + delete this->id; + delete this->value; } } /* namespace ParseTree */ diff --git a/BinOpValue.cpp b/BinOpValue.cpp index f48f63f..8b87f82 100644 --- a/BinOpValue.cpp +++ b/BinOpValue.cpp @@ -49,7 +49,8 @@ string BinOpValue::getValue(){ } BinOpValue::~BinOpValue() { - // TODO Auto-generated destructor stub + delete this->a; + delete this->b; } } /* namespace ParseTree */ diff --git a/PrintStatement.cpp b/PrintStatement.cpp index 1a190f9..e42f4ef 100644 --- a/PrintStatement.cpp +++ b/PrintStatement.cpp @@ -23,7 +23,7 @@ void PrintStatement::Execute(){ } PrintStatement::~PrintStatement() { - // TODO Auto-generated destructor stub + delete this->value; } } /* namespace ParseTree */ diff --git a/Program.cpp b/Program.cpp index 876a831..7db67db 100644 --- a/Program.cpp +++ b/Program.cpp @@ -25,7 +25,9 @@ void Program::run(){ } Program::~Program() { - + for(std::vector::iterator i=code.begin(); i!=code.end(); i++){ + delete *i; + } } } /* namespace ParseTree */ diff --git a/ScalarVariable.cpp b/ScalarVariable.cpp index ae18476..29e508e 100644 --- a/ScalarVariable.cpp +++ b/ScalarVariable.cpp @@ -38,6 +38,16 @@ string getScalar(string name){ else return "EMPTY"; }//end getValue +/** + * Cleans out the Scalar table. + */ +void cleanScalars(){ + for(map::iterator i=scalarTable.begin(); + i!=scalarTable.end();i++){ + delete i->second; + }//end for table +}//end cleanScalars + ScalarVariable::ScalarVariable(string name):Variable(name){ this->Value=""; } diff --git a/ScalarVariable.h b/ScalarVariable.h index adb2bda..d6e2e3a 100644 --- a/ScalarVariable.h +++ b/ScalarVariable.h @@ -14,6 +14,7 @@ namespace runtime { std::string setScalar(std::string name, std::string value); std::string getScalar(std::string name); +void cleanScalars(); class ScalarVariable: public Variable { std::string Value; diff --git a/Util.cpp b/Util.cpp index e653dde..5f71ab6 100644 --- a/Util.cpp +++ b/Util.cpp @@ -3,6 +3,7 @@ #include #include "ParseTree.h" +#include "ScalarVariable.h" using namespace std; @@ -43,8 +44,10 @@ int main(int argc, char *argv[]) { theProg->run(); }catch(ParseTree::ExitCondition *ex){ cout<<"Program terminated"<