From: Mike D. Lowis Date: Tue, 13 Mar 2012 21:46:56 +0000 (-0400) Subject: Added default constructor to Exception and finished implementation of scope stack X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=26f3bec2f9621a02d529bfefe6dc7020d645499d;p=archive%2Fparse-utils.git Added default constructor to Exception and finished implementation of scope stack --- diff --git a/source/exception/exception.cpp b/source/exception/exception.cpp index c0c47cb..f6adac7 100644 --- a/source/exception/exception.cpp +++ b/source/exception/exception.cpp @@ -1,20 +1,29 @@ #include #include "exception.h" -Exception::Exception(const Token& tok) throw() : std::exception(), ex_line(tok.line()), ex_column(tok.column()) +Exception::Exception() throw() : std::exception() { } -Exception::Exception(int line, int column) throw() : std::exception(), ex_line(line), ex_column(column) +Exception::Exception(const Token& tok) throw() : std::exception(), ex_line(tok.line()), ex_column(tok.column()) { + std::ostringstream oss; + oss << "(ln " << ex_line << ", col " << ex_column << "): "; + oss << ((Exception*)this)->message() << std::endl; + ex_msg = oss.str(); } -const char* Exception::what() const throw() +Exception::Exception(int line, int column) throw() : std::exception(), ex_line(line), ex_column(column) { std::ostringstream oss; oss << "(ln " << ex_line << ", col " << ex_column << "): "; oss << ((Exception*)this)->message() << std::endl; - return oss.str().c_str(); + ex_msg = oss.str(); +} + +const char* Exception::what() const throw() +{ + return ex_msg.c_str(); } void Exception::message(const std::string& msg) throw() diff --git a/source/exception/exception.h b/source/exception/exception.h index 2c1b9b1..917b46d 100644 --- a/source/exception/exception.h +++ b/source/exception/exception.h @@ -12,6 +12,7 @@ class Exception : public std::exception int ex_column; std::string ex_msg; public: + Exception() throw(); Exception(const Token& tok) throw(); Exception(int line, int column) throw(); virtual ~Exception() throw() {}; diff --git a/source/symbol/scopestack.cpp b/source/symbol/scopestack.cpp index 1b7b469..10448ec 100644 --- a/source/symbol/scopestack.cpp +++ b/source/symbol/scopestack.cpp @@ -1,9 +1,13 @@ #include "scopestack.h" +#include using namespace std; ScopeStack::ScopeStack() { + // Initialize the stack + sym_table_t table; + scope_stack.push_front( table ); } ScopeStack::~ScopeStack() @@ -12,7 +16,8 @@ ScopeStack::~ScopeStack() void ScopeStack::startScope() { - scope_stack.push_front( sym_table_t() ); + sym_table_t table; + scope_stack.push_front( table ); } void ScopeStack::stopScope() @@ -49,11 +54,28 @@ const Symbol* ScopeStack::lookup(const std::string& name) bool ScopeStack::isLocal(const std::string& name) const { - return false; + bool ret = false; + sym_table_t::const_iterator p_val = scope_stack.front().find(name); + if( p_val != scope_stack.front().end()) + { + ret = true; + } + return ret; } bool ScopeStack::isGlobal(const std::string& name) const { - return false; + bool ret = false; + list::const_iterator it; + for(it = ++(scope_stack.begin()); it != scope_stack.end(); it++) + { + sym_table_t::const_iterator p_val = (*it).find(name); + if( p_val != (*it).end()) + { + ret = true; + break; + } + } + return ret; }