1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20
|
|
21
|
|
22
|
|
23
|
|
24
|
|
25
|
|
26
|
#pragma once
|
27
|
|
28
|
#include <ast/expressions/TypeConstructionExpression.hpp>
|
29
|
#include <ast/IScope.hpp>
|
30
|
#include <deque>
|
31
|
#include <ast/SymbolTable.hpp>
|
32
|
#include <base/Exceptions.hpp>
|
33
|
#include <string>
|
34
|
#include <ast/IAstVisitor.hpp>
|
35
|
|
36
|
namespace Ast {
|
37
|
|
38
|
class ListConstructor final
|
39
|
: public TypeConstructionExpression
|
40
|
, public IScope
|
41
|
{
|
42
|
protected:
|
43
|
ExpressionList m_elements;
|
44
|
IScope* m_parentScope;
|
45
|
SymbolTable* m_comprehensionVars;
|
46
|
Expression* m_comprehension;
|
47
|
bool m_hasComprehension;
|
48
|
|
49
|
ListConstructor():
|
50
|
TypeConstructionExpression(ExpressionKind::ListConstr),
|
51
|
m_elements(),
|
52
|
m_parentScope(nullptr),
|
53
|
m_comprehensionVars(nullptr),
|
54
|
m_comprehension(nullptr),
|
55
|
m_hasComprehension(false)
|
56
|
{};
|
57
|
ListConstructor(const ListConstructor &toCopy):
|
58
|
TypeConstructionExpression(toCopy),
|
59
|
m_elements(toCopy.m_elements),
|
60
|
m_parentScope(toCopy.m_parentScope),
|
61
|
m_comprehensionVars(toCopy.m_comprehensionVars),
|
62
|
m_comprehension(toCopy.m_comprehension),
|
63
|
m_hasComprehension(toCopy.m_hasComprehension)
|
64
|
{};
|
65
|
|
66
|
static ListConstructor* create(ExpressionKind){return new ListConstructor();}
|
67
|
static ListConstructor* createCopy(const ListConstructor& toCopy){return new ListConstructor(toCopy);}
|
68
|
public:
|
69
|
friend class Ast;
|
70
|
friend class Expression;
|
71
|
|
72
|
void init(std::int32_t line, std::int32_t pos,
|
73
|
Type* typeRef,IdentifierList* callTargetsIdentifierListRef, SymbolTable* symbTabRef,
|
74
|
ExpressionList* exprList, SymbolTable *symTab, IScope* parentScope,
|
75
|
Expression* comprehension, bool hasComprehension)
|
76
|
{
|
77
|
TypeConstructionExpression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
|
78
|
m_elements = std::move(*exprList);
|
79
|
m_parentScope = parentScope;
|
80
|
m_comprehensionVars = symTab;
|
81
|
m_comprehension = comprehension;
|
82
|
m_hasComprehension = hasComprehension;
|
83
|
}
|
84
|
|
85
|
|
86
|
ExpressionList& elements() {return m_elements;};
|
87
|
Expression* comprehension() {return m_comprehension;};
|
88
|
bool hasComprehension() {return m_hasComprehension;};
|
89
|
SymbolTable* comprehensionVariables() {return m_comprehensionVars;};
|
90
|
|
91
|
void addElement(Expression* anElement) {m_elements.push_back(anElement);};
|
92
|
void setComprehension(Expression* comprehension) {m_comprehension = comprehension;};
|
93
|
void setHasComprehension(bool flag) {m_hasComprehension = flag;};
|
94
|
|
95
|
Identifier* resolveIdentifier(const std::string& aName) const override { return m_comprehensionVars->get(aName); };
|
96
|
IScope* getParentScope() const override {return m_parentScope;};
|
97
|
std::string getScopeName() const override {return "";}
|
98
|
void setParentScope(IScope* parentScope) override {m_parentScope = parentScope;};
|
99
|
void addIdentifier(Identifier* anIdentifier, void* ) override {m_comprehensionVars->addIdentifier(anIdentifier);};
|
100
|
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
101
|
|
102
|
|
103
|
IScope* asScope() final {return (IScope*) this;}
|
104
|
};
|
105
|
}
|