1 |
7
|
krennw
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
2
|
krennw
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
#pragma once
|
27 |
|
|
|
28 |
|
|
#include <cstdint>
|
29 |
|
|
#include <unordered_map>
|
30 |
|
|
#include <unordered_set>
|
31 |
|
|
#include <list>
|
32 |
|
|
#include <string>
|
33 |
|
|
#include <ast/identifiers/Identifier.hpp>
|
34 |
|
|
#include <base/Exceptions.hpp>
|
35 |
|
|
|
36 |
|
|
namespace Ast {
|
37 |
|
|
|
38 |
|
|
class SymbolTable: public Base::TiresiasObject {
|
39 |
|
|
protected:
|
40 |
|
|
std::unordered_map<std::string, Identifier*> m_symbols;
|
41 |
|
|
std::unordered_set<const Identifier*> m_identifiers;
|
42 |
|
|
|
43 |
|
|
SymbolTable():
|
44 |
|
|
TiresiasObject(),
|
45 |
|
|
m_symbols(),
|
46 |
|
|
m_identifiers()
|
47 |
|
|
{};
|
48 |
|
|
SymbolTable(const SymbolTable &toCopy):
|
49 |
|
|
TiresiasObject(),
|
50 |
|
|
m_symbols(toCopy.m_symbols),
|
51 |
|
|
m_identifiers (toCopy.m_identifiers)
|
52 |
|
|
{};
|
53 |
|
|
public:
|
54 |
|
|
friend class Ast;
|
55 |
|
|
|
56 |
|
|
std::unordered_map<std::string, Identifier*>::iterator begin() {return m_symbols.begin();}
|
57 |
|
|
std::unordered_map<std::string, Identifier*>::iterator end() {return m_symbols.end();}
|
58 |
|
|
std::unordered_set<const Identifier*> identifiers() {return m_identifiers;}
|
59 |
|
|
|
60 |
|
|
std::uint64_t size() {return m_symbols.size();}
|
61 |
|
|
bool defined(const Identifier* aValue) { return m_identifiers.count(aValue) > 0; }
|
62 |
|
|
bool defined(std::string& aKey) { return m_symbols.find(aKey) != m_symbols.end(); }
|
63 |
|
|
Identifier* get(const std::string& aKey) {
|
64 |
|
|
std::unordered_map<std::string, Identifier*>::iterator iter = m_symbols.find(aKey);
|
65 |
|
|
if (iter == m_symbols.end())
|
66 |
|
|
return nullptr;
|
67 |
|
|
return iter->second;
|
68 |
|
|
}
|
69 |
|
|
Identifier* get(const char* aKey);
|
70 |
|
|
bool addIdentifier(Identifier* anIdent);
|
71 |
|
|
void setSymbolList(std::list<Identifier*>& newList);
|
72 |
|
|
};
|
73 |
|
|
|
74 |
|
|
}
|