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/statements/Statement.hpp>
|
29 |
|
|
#include <ast/SymbolTable.hpp>
|
30 |
|
|
#include <deque>
|
31 |
|
|
|
32 |
|
|
namespace Ast {
|
33 |
|
|
|
34 |
|
|
class Block:
|
35 |
|
|
public Statement,
|
36 |
|
|
public IScope
|
37 |
|
|
{
|
38 |
|
|
protected:
|
39 |
|
|
SymbolTable* m_symbols;
|
40 |
|
|
StatementList m_statements;
|
41 |
|
|
Expression* m_filter;
|
42 |
|
|
IScope* m_parentScope;
|
43 |
|
|
|
44 |
|
|
Block(StatementKind kind):
|
45 |
|
|
Statement(kind),
|
46 |
|
|
m_symbols (nullptr),
|
47 |
|
|
m_statements (),
|
48 |
|
|
m_filter (nullptr),
|
49 |
|
|
m_parentScope (nullptr)
|
50 |
|
|
{}
|
51 |
|
|
Block(const Block& toCopy):
|
52 |
|
|
Statement(toCopy),
|
53 |
|
|
m_symbols (toCopy.m_symbols),
|
54 |
|
|
m_statements (toCopy.m_statements),
|
55 |
|
|
m_filter (toCopy.m_filter),
|
56 |
|
|
m_parentScope (toCopy.m_parentScope)
|
57 |
|
|
{}
|
58 |
|
|
|
59 |
|
|
public:
|
60 |
|
|
void init(std::int32_t line, std::int32_t col, SymbolTable* symTabRef,
|
61 |
|
|
StatementList* stmtListRef, IScope* scopeRef)
|
62 |
|
|
{
|
63 |
|
|
init(line,col,symTabRef,stmtListRef,scopeRef,nullptr);
|
64 |
|
|
}
|
65 |
|
|
void init(std::int32_t line, std::int32_t col, SymbolTable* symTabRef,
|
66 |
|
|
StatementList* stmtListRef, IScope* scopeRef, Expression* filter)
|
67 |
|
|
{
|
68 |
|
|
Statement::init(line,col);
|
69 |
|
|
m_symbols = symTabRef;
|
70 |
|
|
m_statements = std::move(*stmtListRef);
|
71 |
|
|
m_parentScope = scopeRef;
|
72 |
|
|
m_filter = filter;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
SymbolTable* symbols() const {return m_symbols;};
|
77 |
|
|
Expression* filter() const {return m_filter;};
|
78 |
|
|
StatementList& statements() {return m_statements;};
|
79 |
|
|
|
80 |
|
|
void addStatement(Statement* toAdd){
|
81 |
|
|
IScope* childScope = toAdd->asScope();
|
82 |
|
|
if (childScope != nullptr)
|
83 |
|
|
childScope->setParentScope((IScope*)this);
|
84 |
|
|
m_statements.push_back(toAdd);
|
85 |
|
|
};
|
86 |
|
|
void setFilter(Expression* sexpr) {m_filter = sexpr;};
|
87 |
|
|
bool isSimpleBlock() {return m_symbols->size() == 0 && m_filter == nullptr;};
|
88 |
|
|
|
89 |
|
|
Identifier* resolveIdentifier(const std::string& aName) const override { return m_symbols->get(aName); };
|
90 |
|
|
IScope* getParentScope() const {return m_parentScope;};
|
91 |
|
|
std::string getScopeName() const override {return "";}
|
92 |
|
|
|
93 |
|
|
void setParentScope(IScope* parentScope) {m_parentScope = parentScope;};
|
94 |
|
|
void addIdentifier(Identifier* anIdentifier, void* ) {m_symbols->addIdentifier(anIdentifier);};
|
95 |
|
|
|
96 |
|
|
IScope* asScope() final {return (IScope*)this;}
|
97 |
|
|
};
|
98 |
|
|
|
99 |
|
|
} |