|
/**
|
|
*
|
|
* 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/expressions/TypeConstructionExpression.hpp>
|
|
#include <ast/IScope.hpp>
|
|
#include <ast/expressions/Expression.hpp>
|
|
#include <ast/IAstVisitor.hpp>
|
|
#include <ast/SymbolTable.hpp>
|
|
#include <base/Exceptions.hpp>
|
|
#include <ast/identifiers/Identifier.hpp>
|
|
#include <deque>
|
|
|
|
namespace Ast {
|
|
|
|
class SetConstructor final
|
|
: public TypeConstructionExpression
|
|
, public IScope
|
|
{
|
|
protected:
|
|
ExpressionList m_items;
|
|
SymbolTable* m_comprehensionVars;
|
|
IScope* m_parentScope;
|
|
Expression* m_comprehension;
|
|
bool m_hasComprehension;
|
|
|
|
SetConstructor():
|
|
TypeConstructionExpression(ExpressionKind::SetConstr),
|
|
m_items (),
|
|
m_comprehensionVars (nullptr),
|
|
m_parentScope (nullptr),
|
|
m_comprehension (nullptr),
|
|
m_hasComprehension (false)
|
|
{};
|
|
SetConstructor(const SetConstructor &toCopy):
|
|
TypeConstructionExpression(toCopy),
|
|
m_items (toCopy.m_items),
|
|
m_comprehensionVars (toCopy.m_comprehensionVars),
|
|
m_parentScope (toCopy.m_parentScope),
|
|
m_comprehension (toCopy.m_comprehension),
|
|
m_hasComprehension (toCopy.m_hasComprehension)
|
|
{};
|
|
|
|
static SetConstructor* create(ExpressionKind) {return new SetConstructor();}
|
|
static SetConstructor* createCopy(const SetConstructor& toCopy) {return new SetConstructor(toCopy);}
|
|
public:
|
|
friend class Ast;
|
|
friend class Expression;
|
|
|
|
void init(std::int32_t line, std::int32_t pos,
|
|
Type* typeRef,IdentifierList* callTargetsIdentifierListRef, SymbolTable* symbTabRef,
|
|
ExpressionList* exprList, SymbolTable *symTab, IScope* parentScope,
|
|
Expression* comprehension, bool hasComprehension)
|
|
{
|
|
TypeConstructionExpression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
|
|
m_items = std::move(*exprList);
|
|
m_parentScope = parentScope;
|
|
m_comprehensionVars = symTab;
|
|
m_comprehension = comprehension;
|
|
m_hasComprehension = hasComprehension;
|
|
}
|
|
|
|
|
|
|
|
ExpressionList& items() {return m_items;}
|
|
Expression* comprehension() {return m_comprehension;}
|
|
bool hasComprehension() const {return m_hasComprehension;};
|
|
SymbolTable* comprehensionVariables() {return m_comprehensionVars;};
|
|
|
|
void addItem(Expression* anItem) {m_items.push_back(anItem);};
|
|
void setComprehension(Expression* anExpr) {m_comprehension = anExpr;};
|
|
void setHasComprehension(bool flag) {m_hasComprehension = flag;};
|
|
Identifier* resolveIdentifier(const string& aName) const override {return m_comprehensionVars->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_comprehensionVars->addIdentifier(anIdentifier);};
|
|
void accept(IAstVisitor& visitor) override {visitor.visit(this);};
|
|
//void setItems(ExpressionList& newItems) {m_items = newItems;};
|
|
|
|
IScope* asScope() final {return (IScope*) this;}
|
|
};
|
|
|
|
}
|