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 <ast/IScope.hpp>
|
29 |
|
|
#include <ast/identifiers/TypeIdentifier.hpp>
|
30 |
|
|
#include <ast/SymbolTable.hpp>
|
31 |
|
|
#include <string>
|
32 |
|
|
|
33 |
|
|
namespace Ast {
|
34 |
|
|
|
35 |
|
|
class Scope :
|
36 |
|
|
public TypeIdentifier,
|
37 |
|
|
public IScope
|
38 |
|
|
{
|
39 |
|
|
protected:
|
40 |
|
|
SymbolTable* m_symbolTable;
|
41 |
|
|
|
42 |
|
|
Scope(IdentifierKind id): TypeIdentifier(id), m_symbolTable (nullptr) {};
|
43 |
|
|
Scope(const Scope& toCopy): TypeIdentifier(toCopy), m_symbolTable (toCopy.m_symbolTable) {};
|
44 |
|
|
|
45 |
|
|
public:
|
46 |
|
|
|
47 |
|
|
void init (std::int32_t line, std::int32_t col, const char* text,
|
48 |
|
|
IScope* scopeRef, Type* typeRef, const char* prefix,
|
49 |
|
|
SymbolTable* symbolTableRef)
|
50 |
|
|
{
|
51 |
|
|
TypeIdentifier::init(line,col,text,scopeRef,typeRef, prefix);
|
52 |
|
|
m_symbolTable = symbolTableRef;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
SymbolTable* symbolTable() const {return m_symbolTable;}
|
56 |
|
|
IScope* getParentScope() const override {return m_definingScope;};
|
57 |
|
|
Identifier* resolveIdentifier(const std::string& aName) const override { return m_symbolTable->get(aName); };
|
58 |
|
|
std::string getScopeName() const override {return toString();}
|
59 |
|
|
|
60 |
|
|
void setParentScope(IScope* parentScope) override { m_definingScope = parentScope; };
|
61 |
|
|
void addIdentifier(Identifier* anIdentifier, void* ) override { m_symbolTable->addIdentifier(anIdentifier);};
|
62 |
|
|
};
|
63 |
|
|
} |