1 |
2
|
krennw
|
|
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/statements/Statement.hpp>
|
29 |
|
|
#include <ast/IScope.hpp>
|
30 |
|
|
#include <deque>
|
31 |
|
|
#include <ast/SymbolTable.hpp>
|
32 |
|
|
#include <ast/IAstVisitor.hpp>
|
33 |
|
|
#include <base/Exceptions.hpp>
|
34 |
|
|
|
35 |
|
|
namespace Ast {
|
36 |
|
|
|
37 |
|
|
class Assignment final
|
38 |
|
|
: public Statement
|
39 |
|
|
, public IScope
|
40 |
|
|
{
|
41 |
|
|
protected:
|
42 |
|
|
SymbolTable* m_symbols;
|
43 |
|
|
Expression* m_nondetExpression;
|
44 |
|
|
IScope* m_parentScope;
|
45 |
|
|
ExpressionList m_places;
|
46 |
|
|
ExpressionList m_values;
|
47 |
|
|
|
48 |
|
|
Assignment():
|
49 |
|
|
Statement(StatementKind::Assignment),
|
50 |
|
|
m_symbols (nullptr),
|
51 |
|
|
m_nondetExpression (nullptr),
|
52 |
|
|
m_parentScope (nullptr),
|
53 |
|
|
m_places (),
|
54 |
|
|
m_values ()
|
55 |
|
|
{};
|
56 |
|
|
Assignment(const Assignment& toCopy):
|
57 |
|
|
Statement(toCopy),
|
58 |
|
|
m_symbols (toCopy.m_symbols),
|
59 |
|
|
m_nondetExpression (toCopy.m_nondetExpression),
|
60 |
|
|
m_parentScope (toCopy.m_parentScope),
|
61 |
|
|
m_places (toCopy.m_places),
|
62 |
|
|
m_values (toCopy.m_values)
|
63 |
|
|
{};
|
64 |
|
|
|
65 |
|
|
static Assignment* create() {return new Assignment();}
|
66 |
|
|
static Assignment* createCopy(const Assignment& toCopy) {return new Assignment(toCopy);}
|
67 |
|
|
public:
|
68 |
|
|
friend class Ast;
|
69 |
|
|
friend class Statement;
|
70 |
|
|
|
71 |
|
|
void init(std::int32_t line, std::int32_t pos, IScope* scopeRef,
|
72 |
|
|
Expression* nonDetExprRef, ExpressionList* placeExprListRef,
|
73 |
|
|
ExpressionList* valueExprListRef, SymbolTable*symTabRef)
|
74 |
|
|
{
|
75 |
|
|
Statement::init(line,pos);
|
76 |
|
|
m_parentScope = scopeRef;
|
77 |
|
|
m_nondetExpression = nonDetExprRef;
|
78 |
|
|
m_places = std::move(*placeExprListRef);
|
79 |
|
|
m_values = std::move(*valueExprListRef);
|
80 |
|
|
m_symbols = symTabRef;
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
ExpressionList& places() {return m_places;};
|
84 |
|
|
ExpressionList& values() {return m_values;};
|
85 |
|
|
Expression* nondetExpression() {return m_nondetExpression;};
|
86 |
|
|
SymbolTable* symbols() {return m_symbols;};
|
87 |
|
|
|
88 |
|
|
void addPlace(Expression* aPlace) {m_places.push_back(aPlace);};
|
89 |
|
|
void addValue(Expression* aValue) {m_values.push_back(aValue);};
|
90 |
|
|
void setNondetExpression(Expression* anExpr) {m_nondetExpression = anExpr;};
|
91 |
|
|
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
92 |
|
|
Identifier* resolveIdentifier(const std::string& aName) const override { return m_symbols->get(aName); };
|
93 |
|
|
IScope* getParentScope() const override {return m_parentScope;};
|
94 |
|
|
std::string getScopeName() const override {return "";}
|
95 |
|
|
void setParentScope(IScope* parentScope) override {m_parentScope = parentScope;};
|
96 |
|
|
void addIdentifier(Identifier* anIdentifier, void* ) override {m_symbols->addIdentifier(anIdentifier);};
|
97 |
|
|
|
98 |
|
|
IScope* asScope() final {return (IScope*) this;}
|
99 |
|
|
};
|
100 |
|
|
} |