root / trunk / compiler / cppAst / ast / SymbolTable.hpp @ 2
1 |
/**
|
---|---|
2 |
*
|
3 |
* OOAS Compiler - C++ AST
|
4 |
*
|
5 |
* Copyright 2015, AIT Austrian Institute of Technology.
|
6 |
* All rights reserved.
|
7 |
*
|
8 |
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
9 |
*
|
10 |
* If you modify the file please update the list of contributors below to in-
|
11 |
* clude your name. Please also stick to the coding convention of using TABs
|
12 |
* to do the basic (block-level) indentation and spaces for anything after
|
13 |
* that. (Enable the display of special chars and it should be pretty obvious
|
14 |
* what this means.) Also, remove all trailing whitespace.
|
15 |
*
|
16 |
* Contributors:
|
17 |
* Willibald Krenn (AIT)
|
18 |
* Stephan Zimmerer (AIT)
|
19 |
* Christoph Czurda (AIT)
|
20 |
*
|
21 |
*/
|
22 |
|
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 |
} |
75 |
|