TS_CPP
An efficient & easy to use implementation of a Symbol table used in most compilers
Loading...
Searching...
No Matches
TSManager.cpp
1#include "TSManager.h"
2
3using namespace TS_CPP;
4
6{
7 lastTableID = 0;
8 lastEntryID = 0;
9 tsinfo("Created TSManager with lastTableID=%d, lastEntryID=%d",lastTableID,lastEntryID);
10}
11
13{
14 lastTableID = firstID-1;
15 lastEntryID = 0;
16 tsinfo("Created TSManager with lastTableID=%d, lastEntryID=%d",lastTableID,lastEntryID);
17}
18
20{
21 auto* table = new SymbolTable(++lastTableID, &lastEntryID);
22 symbolTableList.push_back(table);
23 tsinfo("Created new Table (0x%llx) with id=%d",(unsigned long long)table,table->getId());
24 return table;
25}
26
27SymbolTable* TSManager::createNewTable(const ::std::string& tableName)
28{
29 auto* table = new SymbolTable(++lastTableID, &lastEntryID, tableName);
30 symbolTableList.push_back(table);
31 tsinfo("Created new Table (0x%llx) with id=%d, name=%s",(unsigned long long)table,table->getId(),table->getTableName().c_str());
32 return table;
33}
34
36{
37 SymbolTable* table = nullptr;
38
39 auto iter = symbolTableList.begin();
40 while (table == nullptr && iter!=symbolTableList.end() && (*iter)->getId()<=id)
41 {
42 if((*iter)->getId() == id)
43 {
44 table = *iter;
45 }
46 iter++;
47 }
48#if TS_PRINT_MESSAGES_LEVEL == TS_LEVEL_DEBUG
49 if(table == nullptr)
50 {
51 tsinfo("Table with id=%d does not exist", id);
52 }
53 else
54 {
55 tsinfo("Table with id=%d found at 0%llx", id, (unsigned long long)table);
56 }
57#endif
58 return table;
59}
60
61SymbolTable *TSManager::searchTable(const ::std::string& tableName)
62{
63 SymbolTable* table = nullptr;
64
65 auto iter = symbolTableList.begin();
66 while (table == nullptr && iter!=symbolTableList.end())
67 {
68 if((*iter)->getTableName() == tableName)
69 {
70 table = *iter;
71 }
72 iter++;
73 }
74#if TS_PRINT_MESSAGES_LEVEL >= TS_LEVEL_INFO
75 if(table == nullptr)
76 {
77 tsinfo("Table with name=%s does not exist", tableName.c_str());
78 }
79 else
80 {
81 tsinfo("Table with name=%s found at 0%llx", tableName.c_str(), (unsigned long long)table);
82 }
83#endif
84 return table;
85}
86
88{
89 SymbolTable* table = getTable(id);
90 if(table == nullptr)
91 {
92 tserror("Table with id=%d does not exist", id);
93 return false;
94 }
95 symbolTableList.remove(table);
96 delete table;
97 tsinfo("Table with id=%d successfully deleted", id);
98 return true;
99}
100
102{
103 for(auto table : symbolTableList)
104 {
105 delete table;
106 }
107}
108
110{
111 Entry* entry = nullptr;
112 for(auto table : symbolTableList)
113 {
114 entry = table->getEntry(id);
115 if(entry!= nullptr)
116 {
117 if(tableId!= nullptr)
118 {
119 *tableId = table->getId();
120 }
121 break;
122 }
123 }
124 return entry;
125}
126
127::std::list<SymbolTable *> &TSManager::_getTablesStorage()
128{
129 return symbolTableList;
130}
Definition Entry.h:19
int getId() const
Definition Entry.cpp:21
SymbolTable * createNewTable()
Definition TSManager.cpp:19
bool deleteTable(int id)
Definition TSManager.cpp:87
std::list< SymbolTable * > & _getTablesStorage()
SymbolTable * searchTable(const std::string &tableName)
Definition TSManager.cpp:61
Entry * searchAllTablesForEntryWithId(int id, int *tableId=nullptr)
SymbolTable * getTable(int id)
Definition TSManager.cpp:35