From 0777959464fecc66a651676ba7f1bfdaad5bcc58 Mon Sep 17 00:00:00 2001 From: Thunder422 Date: Fri, 2 Jan 2015 15:30:28 -0500 Subject: [PATCH] token: header file and include statement refactoring added token forward declarations to header files as needed (cannot remove include from table until token type is replaced) - required moving rpn item equality operator function to source file - moved token includes to source files as needed - cleaned up some other forward declarations --- basic/basic.h | 2 +- parser.cpp | 1 + parser.h | 3 ++- rpnlist.cpp | 9 +++++++++ rpnlist.h | 13 +++++-------- table.cpp | 1 + table.h | 4 ++++ token.h | 6 ++---- translator.h | 1 + 9 files changed, 26 insertions(+), 14 deletions(-) diff --git a/basic/basic.h b/basic/basic.h index cd290d1..7477bbe 100644 --- a/basic/basic.h +++ b/basic/basic.h @@ -30,11 +30,11 @@ #include #include "ibcp.h" -#include "token.h" #include "dictionary.h" class Translator; class Token; +using TokenPtr = std::shared_ptr; class ProgramModel; class Recreator; class RpnItem; diff --git a/parser.cpp b/parser.cpp index 49eb392..c2a7f6f 100644 --- a/parser.cpp +++ b/parser.cpp @@ -24,6 +24,7 @@ #include "parser.h" #include "table.h" +#include "token.h" #include "utility.h" diff --git a/parser.h b/parser.h index 6739fba..bedc517 100644 --- a/parser.h +++ b/parser.h @@ -27,9 +27,10 @@ #include -#include "token.h" +#include "ibcp.h" class Table; +class Token; class Parser diff --git a/rpnlist.cpp b/rpnlist.cpp index 198a336..1f15206 100644 --- a/rpnlist.cpp +++ b/rpnlist.cpp @@ -24,6 +24,15 @@ #include "rpnlist.h" #include "table.h" +#include "token.h" + + +// function to overload the comparison operator +bool RpnItem::operator==(const RpnItem &other) const +{ + return *m_token == *other.m_token + && m_attached.size() == other.m_attached.size(); +} // function to overload the comparison operator diff --git a/rpnlist.h b/rpnlist.h index 57b6d5c..9526a21 100644 --- a/rpnlist.h +++ b/rpnlist.h @@ -29,13 +29,12 @@ #include #include -#include "token.h" - class Table; +class Token; +using TokenPtr = std::shared_ptr; class RpnItem; using RpnItemPtr = std::shared_ptr; using RpnItemVector = std::vector; -using RpnItemList = std::list; // class for holding an item in the RPN output list @@ -61,11 +60,7 @@ class RpnItem return m_attached; } - bool operator==(const RpnItem &other) const - { - return *m_token == *other.m_token - && m_attached.size() == other.m_attached.size(); - } + bool operator==(const RpnItem &other) const; bool operator!=(const RpnItem &other) const { return !(*this == other); @@ -76,6 +71,8 @@ class RpnItem RpnItemVector m_attached; // array of attached item pointers }; +using RpnItemList = std::list; + // class for holding a list of RPN items class RpnList diff --git a/table.cpp b/table.cpp index 03f2361..1a815d9 100644 --- a/table.cpp +++ b/table.cpp @@ -28,6 +28,7 @@ #include #include "table.h" +#include "token.h" #include "utility.h" #include "basic/basic.h" diff --git a/table.h b/table.h index 77f07ca..317f751 100644 --- a/table.h +++ b/table.h @@ -30,9 +30,13 @@ #include #include "ibcp.h" +// TODO remove this include once token type is replaced with code type #include "token.h" #include "utility.h" +class Token; +using TokenPtr = std::shared_ptr; + // bit definitions for flags field enum TableFlag : unsigned diff --git a/token.h b/token.h index 3dc445d..0487f97 100644 --- a/token.h +++ b/token.h @@ -32,10 +32,6 @@ #include "ibcp.h" -class Token; -using TokenPtr = std::shared_ptr; - - class Token { public: @@ -263,6 +259,8 @@ class Token int m_index; // index within encoded program code line }; +using TokenPtr = std::shared_ptr; + // structure for holding information about an error exception struct TokenError diff --git a/translator.h b/translator.h index 9943ae8..2db901c 100644 --- a/translator.h +++ b/translator.h @@ -31,6 +31,7 @@ #include "rpnlist.h" class Table; +class TokenError; class Translator