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/IScope.hpp>
|
30 |
|
|
#include <ast/expressions/Expression.hpp>
|
31 |
|
|
#include <ast/statements/Block.hpp>
|
32 |
|
|
|
33 |
|
|
namespace Ast {
|
34 |
|
|
|
35 |
|
|
class GuardedCommand final
|
36 |
|
|
: public Statement
|
37 |
|
|
, public IScope
|
38 |
|
|
{
|
39 |
|
|
protected:
|
40 |
|
|
Expression* m_guard;
|
41 |
|
|
Statement* m_body;
|
42 |
|
|
IScope* m_parentScope;
|
43 |
|
|
|
44 |
|
|
GuardedCommand():
|
45 |
|
|
Statement(StatementKind::GuardedCommand),
|
46 |
|
|
m_guard (nullptr),
|
47 |
|
|
m_body (nullptr),
|
48 |
|
|
m_parentScope(nullptr)
|
49 |
|
|
{}
|
50 |
|
|
|
51 |
|
|
GuardedCommand(const GuardedCommand &toCopy):
|
52 |
|
|
Statement(toCopy),
|
53 |
|
|
m_guard (toCopy.m_guard),
|
54 |
|
|
m_body (toCopy.m_body),
|
55 |
|
|
m_parentScope(toCopy.m_parentScope)
|
56 |
|
|
{}
|
57 |
|
|
|
58 |
|
|
static GuardedCommand* create() {return new GuardedCommand();}
|
59 |
|
|
static GuardedCommand* createCopy(const GuardedCommand& toCopy) {return new GuardedCommand(toCopy);}
|
60 |
|
|
public:
|
61 |
|
|
friend class Ast;
|
62 |
|
|
friend class Statement;
|
63 |
|
|
|
64 |
|
|
void init(std::int32_t line, std::int32_t pos, IScope* scopeRef, Expression* guardExprRef,
|
65 |
|
|
Statement* bodyRef)
|
66 |
|
|
{
|
67 |
|
|
Statement::init(line,pos);
|
68 |
|
|
m_guard = guardExprRef;
|
69 |
|
|
m_body = bodyRef;
|
70 |
|
|
m_parentScope = scopeRef;
|
71 |
|
|
}
|
72 |
|
|
Expression* guard() {return m_guard;};
|
73 |
|
|
Statement* body() {return m_body;};
|
74 |
|
|
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
75 |
|
|
|
76 |
|
|
void setGuard(Expression* newGuard) {m_guard = newGuard;};
|
77 |
|
|
void setBody(Statement* newBody) {m_body = newBody;};
|
78 |
|
|
|
79 |
|
|
Identifier* resolveIdentifier(const std::string& ) const override { return nullptr; };
|
80 |
|
|
IScope* getParentScope() const override {return m_parentScope;};
|
81 |
|
|
std::string getScopeName() const override {return "";}
|
82 |
|
|
void setParentScope(IScope* parentScope) override {m_parentScope = parentScope;};
|
83 |
|
|
void addIdentifier(Identifier*, void* ) override {throw new Base::NotImplementedException(); };
|
84 |
|
|
|
85 |
|
|
IScope* asScope() final {return (IScope*) this;}
|
86 |
|
|
};
|
87 |
|
|
} |