|
/**
|
|
*
|
|
* 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 <deque>
|
|
#include <ast/SymbolTable.hpp>
|
|
#include <ast/IAstVisitor.hpp>
|
|
#include <base/Exceptions.hpp>
|
|
|
|
namespace Ast {
|
|
|
|
class Assignment final
|
|
: public Statement
|
|
, public IScope
|
|
{
|
|
protected:
|
|
SymbolTable* m_symbols;
|
|
Expression* m_nondetExpression;
|
|
IScope* m_parentScope;
|
|
ExpressionList m_places;
|
|
ExpressionList m_values;
|
|
|
|
Assignment():
|
|
Statement(StatementKind::Assignment),
|
|
m_symbols (nullptr),
|
|
m_nondetExpression (nullptr),
|
|
m_parentScope (nullptr),
|
|
m_places (),
|
|
m_values ()
|
|
{};
|
|
Assignment(const Assignment& toCopy):
|
|
Statement(toCopy),
|
|
m_symbols (toCopy.m_symbols),
|
|
m_nondetExpression (toCopy.m_nondetExpression),
|
|
m_parentScope (toCopy.m_parentScope),
|
|
m_places (toCopy.m_places),
|
|
m_values (toCopy.m_values)
|
|
{};
|
|
|
|
static Assignment* create() {return new Assignment();}
|
|
static Assignment* createCopy(const Assignment& toCopy) {return new Assignment(toCopy);}
|
|
public:
|
|
friend class Ast;
|
|
friend class Statement;
|
|
|
|
void init(std::int32_t line, std::int32_t pos, IScope* scopeRef,
|
|
Expression* nonDetExprRef, ExpressionList* placeExprListRef,
|
|
ExpressionList* valueExprListRef, SymbolTable*symTabRef)
|
|
{
|
|
Statement::init(line,pos);
|
|
m_parentScope = scopeRef;
|
|
m_nondetExpression = nonDetExprRef;
|
|
m_places = std::move(*placeExprListRef);
|
|
m_values = std::move(*valueExprListRef);
|
|
m_symbols = symTabRef;
|
|
}
|
|
|
|
ExpressionList& places() {return m_places;};
|
|
ExpressionList& values() {return m_values;};
|
|
Expression* nondetExpression() {return m_nondetExpression;};
|
|
SymbolTable* symbols() {return m_symbols;};
|
|
|
|
void addPlace(Expression* aPlace) {m_places.push_back(aPlace);};
|
|
void addValue(Expression* aValue) {m_values.push_back(aValue);};
|
|
void setNondetExpression(Expression* anExpr) {m_nondetExpression = anExpr;};
|
|
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
|
Identifier* resolveIdentifier(const std::string& aName) const override { return m_symbols->get(aName); };
|
|
IScope* getParentScope() const override {return m_parentScope;};
|
|
std::string getScopeName() const override {return "";}
|
|
void setParentScope(IScope* parentScope) override {m_parentScope = parentScope;};
|
|
void addIdentifier(Identifier* anIdentifier, void* ) override {m_symbols->addIdentifier(anIdentifier);};
|
|
|
|
IScope* asScope() final {return (IScope*) this;}
|
|
};
|
|
}
|