]> git.mdlowis.com Git - archive/parse-utils.git/commitdiff
Added default constructor to Exception and finished implementation of scope stack
authorMike D. Lowis <mike@mdlowis.com>
Tue, 13 Mar 2012 21:46:56 +0000 (17:46 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Tue, 13 Mar 2012 21:46:56 +0000 (17:46 -0400)
source/exception/exception.cpp
source/exception/exception.h
source/symbol/scopestack.cpp

index c0c47cb1b2e6f3a14e7120bd0665059f6ee6df77..f6adac72824fe1de926f22a0099fd65cb8c8aaad 100644 (file)
@@ -1,20 +1,29 @@
 #include <sstream>
 #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()
index 2c1b9b1f92cdc15d5fc08854f8d9b86798c8a8de..917b46dde173d314fa7178df023501c68e2780d1 100644 (file)
@@ -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() {};
index 1b7b469a025f5e981ad12bb8f07ef2c6e9ee76bc..10448ecda0aa603bf8e0fd0458ebe7aa82c2abd5 100644 (file)
@@ -1,9 +1,13 @@
 #include "scopestack.h"
+#include <iostream>
 
 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<sym_table_t>::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;
 }