root/trunk/compiler/cppAst/ast/SymbolTable.hpp @ 2
2 | krennw | /**
|
|
*
|
|||
* OOAS Compiler - C++ AST
|
|||
*
|
|||
* Copyright 2015, AIT Austrian Institute of Technology.
|
|||
* All rights reserved.
|
|||
*
|
|||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
|||
*
|
|||
* If you modify the file please update the list of contributors below to in-
|
|||
* clude your name. Please also stick to the coding convention of using TABs
|
|||
* to do the basic (block-level) indentation and spaces for anything after
|
|||
* that. (Enable the display of special chars and it should be pretty obvious
|
|||
* what this means.) Also, remove all trailing whitespace.
|
|||
*
|
|||
* Contributors:
|
|||
* Willibald Krenn (AIT)
|
|||
* Stephan Zimmerer (AIT)
|
|||
* Christoph Czurda (AIT)
|
|||
*
|
|||
*/
|
|||
#pragma once
|
|||
#include <cstdint>
|
|||
#include <unordered_map>
|
|||
#include <unordered_set>
|
|||
#include <list>
|
|||
#include <string>
|
|||
#include <ast/identifiers/Identifier.hpp>
|
|||
#include <base/Exceptions.hpp>
|
|||
namespace Ast {
|
|||
class SymbolTable: public Base::TiresiasObject {
|
|||
protected:
|
|||
std::unordered_map<std::string, Identifier*> m_symbols;
|
|||
std::unordered_set<const Identifier*> m_identifiers;
|
|||
SymbolTable():
|
|||
TiresiasObject(),
|
|||
m_symbols(),
|
|||
m_identifiers()
|
|||
{};
|
|||
SymbolTable(const SymbolTable &toCopy):
|
|||
TiresiasObject(),
|
|||
m_symbols(toCopy.m_symbols),
|
|||
m_identifiers (toCopy.m_identifiers)
|
|||
{};
|
|||
public:
|
|||
friend class Ast;
|
|||
std::unordered_map<std::string, Identifier*>::iterator begin() {return m_symbols.begin();}
|
|||
std::unordered_map<std::string, Identifier*>::iterator end() {return m_symbols.end();}
|
|||
std::unordered_set<const Identifier*> identifiers() {return m_identifiers;}
|
|||
std::uint64_t size() {return m_symbols.size();}
|
|||
bool defined(const Identifier* aValue) { return m_identifiers.count(aValue) > 0; }
|
|||
bool defined(std::string& aKey) { return m_symbols.find(aKey) != m_symbols.end(); }
|
|||
Identifier* get(const std::string& aKey) {
|
|||
std::unordered_map<std::string, Identifier*>::iterator iter = m_symbols.find(aKey);
|
|||
if (iter == m_symbols.end())
|
|||
return nullptr;
|
|||
return iter->second;
|
|||
}
|
|||
Identifier* get(const char* aKey);
|
|||
bool addIdentifier(Identifier* anIdent);
|
|||
void setSymbolList(std::list<Identifier*>& newList);
|
|||
};
|
|||
}
|