From: Mike D. Lowis Date: Sat, 10 Mar 2012 20:23:40 +0000 (-0500) Subject: Cleaned up namespaces and added setters for AST class. X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=f33de2888d7ca359828b2532036403498312e452;p=archive%2Fparse-utils.git Cleaned up namespaces and added setters for AST class. --- diff --git a/source/lexer/ilexer.cpp b/source/lexer/ilexer.cpp index b90320d..66288f7 100644 --- a/source/lexer/ilexer.cpp +++ b/source/lexer/ilexer.cpp @@ -4,7 +4,7 @@ using namespace std; -ILexer::ILexer(istream& in) : line(-1), column(-1), in_stream(in) +ILexer::ILexer(istream& in) : line(-1), column(-1), in_stream(in), current(in_stream.get()) { } diff --git a/source/parser/ast/ast.cpp b/source/parser/ast/ast.cpp index 273dd6e..4f3a993 100644 --- a/source/parser/ast/ast.cpp +++ b/source/parser/ast/ast.cpp @@ -3,6 +3,8 @@ #include #include +using namespace std; + AST::AST(ASTNodeType type) { node_type = type; @@ -69,6 +71,11 @@ ASTNodeType AST::type(void) const return node_type; } +void AST::type(ASTNodeType typ) +{ + node_type = typ; +} + list* AST::children(void) { return node_children; @@ -79,6 +86,11 @@ string AST::text(void) const return node_text; } +void AST::text(std::string& txt) +{ + node_text = txt; +} + void AST::addChild(AST* node) { node_children->push_back(node); diff --git a/source/parser/ast/ast.h b/source/parser/ast/ast.h index ce9a897..abce052 100644 --- a/source/parser/ast/ast.h +++ b/source/parser/ast/ast.h @@ -5,30 +5,30 @@ #include #include -using namespace std; - typedef unsigned int ASTNodeType; class AST { protected: ASTNodeType node_type; - string node_text; - list* node_children; + std::string node_text; + std::list* node_children; public: AST(ASTNodeType type); AST(ASTNodeType type, const char* text); - AST(ASTNodeType type, string text); + AST(ASTNodeType type, std::string text); AST(ASTNodeType type, int child_count, ...); virtual ~AST(); AST& operator = (AST& rhs); ASTNodeType type(void) const; - string text(void) const; - list* children(void); - void addChild(AST* node); - AST* clone(void) const; + void type(ASTNodeType typ); + std::string text(void) const; + void text(std::string& txt); + std::list* children(void); + void addChild(AST* node); + AST* clone(void) const; }; #endif diff --git a/source/parser/btparser/btparser.cpp b/source/parser/btparser/btparser.cpp index 0981361..a913848 100644 --- a/source/parser/btparser/btparser.cpp +++ b/source/parser/btparser/btparser.cpp @@ -1,6 +1,8 @@ #include "btparser.h" #include "exception.h" +using namespace std; + BTParser::BTParser() : current(0) { } diff --git a/source/parser/iparser.h b/source/parser/iparser.h index 747778d..9f01626 100644 --- a/source/parser/iparser.h +++ b/source/parser/iparser.h @@ -23,8 +23,6 @@ #include "ilexer.h" #include "ivisitor.h" -using namespace std; - class IParser { protected: AST* result; diff --git a/source/visitor/astprinter/astprinter.cpp b/source/visitor/astprinter/astprinter.cpp index 11e434e..c612f62 100644 --- a/source/visitor/astprinter/astprinter.cpp +++ b/source/visitor/astprinter/astprinter.cpp @@ -1,6 +1,7 @@ #include #include "astprinter.h" +using namespace std; void ASTPrinter::beforeVisit(AST* cur, int depth) {