root / trunk / compiler / cppAst / ast / statements / GuardedCommand.hpp @ 9
1 |
/**
|
---|---|
2 |
*
|
3 |
* OOAS Compiler - C++ AST
|
4 |
*
|
5 |
* Copyright 2015, AIT Austrian Institute of Technology.
|
6 |
* All rights reserved.
|
7 |
*
|
8 |
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
9 |
*
|
10 |
* If you modify the file please update the list of contributors below to in-
|
11 |
* clude your name. Please also stick to the coding convention of using TABs
|
12 |
* to do the basic (block-level) indentation and spaces for anything after
|
13 |
* that. (Enable the display of special chars and it should be pretty obvious
|
14 |
* what this means.) Also, remove all trailing whitespace.
|
15 |
*
|
16 |
* Contributors:
|
17 |
* Willibald Krenn (AIT)
|
18 |
* Stephan Zimmerer (AIT)
|
19 |
* Christoph Czurda (AIT)
|
20 |
*
|
21 |
*/
|
22 |
|
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(); /*cannot add to guarded command!*/}; |
84 |
|
85 |
IScope* asScope() final {return (IScope*) this;} |
86 |
}; |
87 |
} |