|
/**
|
|
*
|
|
* OOAS Compiler - C++ AST
|
|
*
|
|
* Copyright 2015, AIT Austrian Institute of Technology.
|
|
* All rights reserved.
|
|
*
|
|
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
|
*
|
|
* If you modify the file please update the list of contributors below to in-
|
|
* clude your name. Please also stick to the coding convention of using TABs
|
|
* to do the basic (block-level) indentation and spaces for anything after
|
|
* that. (Enable the display of special chars and it should be pretty obvious
|
|
* what this means.) Also, remove all trailing whitespace.
|
|
*
|
|
* Contributors:
|
|
* Willibald Krenn (AIT)
|
|
* Stephan Zimmerer (AIT)
|
|
* Christoph Czurda (AIT)
|
|
*
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <ast/statements/Statement.hpp>
|
|
#include <ast/IScope.hpp>
|
|
#include <ast/expressions/Expression.hpp>
|
|
#include <ast/statements/Block.hpp>
|
|
|
|
namespace Ast {
|
|
|
|
class GuardedCommand final
|
|
: public Statement
|
|
, public IScope
|
|
{
|
|
protected:
|
|
Expression* m_guard;
|
|
Statement* m_body;
|
|
IScope* m_parentScope;
|
|
|
|
GuardedCommand():
|
|
Statement(StatementKind::GuardedCommand),
|
|
m_guard (nullptr),
|
|
m_body (nullptr),
|
|
m_parentScope(nullptr)
|
|
{}
|
|
|
|
GuardedCommand(const GuardedCommand &toCopy):
|
|
Statement(toCopy),
|
|
m_guard (toCopy.m_guard),
|
|
m_body (toCopy.m_body),
|
|
m_parentScope(toCopy.m_parentScope)
|
|
{}
|
|
|
|
static GuardedCommand* create() {return new GuardedCommand();}
|
|
static GuardedCommand* createCopy(const GuardedCommand& toCopy) {return new GuardedCommand(toCopy);}
|
|
public:
|
|
friend class Ast;
|
|
friend class Statement;
|
|
|
|
void init(std::int32_t line, std::int32_t pos, IScope* scopeRef, Expression* guardExprRef,
|
|
Statement* bodyRef)
|
|
{
|
|
Statement::init(line,pos);
|
|
m_guard = guardExprRef;
|
|
m_body = bodyRef;
|
|
m_parentScope = scopeRef;
|
|
}
|
|
Expression* guard() {return m_guard;};
|
|
Statement* body() {return m_body;};
|
|
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
|
|
|
void setGuard(Expression* newGuard) {m_guard = newGuard;};
|
|
void setBody(Statement* newBody) {m_body = newBody;};
|
|
|
|
Identifier* resolveIdentifier(const std::string& ) const override { return nullptr; };
|
|
IScope* getParentScope() const override {return m_parentScope;};
|
|
std::string getScopeName() const override {return "";}
|
|
void setParentScope(IScope* parentScope) override {m_parentScope = parentScope;};
|
|
void addIdentifier(Identifier*, void* ) override {throw new Base::NotImplementedException(); /*cannot add to guarded command!*/};
|
|
|
|
IScope* asScope() final {return (IScope*) this;}
|
|
};
|
|
}
|