/** * * 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 #include #include namespace Ast { class Block: public Statement, public IScope { protected: SymbolTable* m_symbols; StatementList m_statements; Expression* m_filter; IScope* m_parentScope; Block(StatementKind kind): Statement(kind), m_symbols (nullptr), m_statements (), m_filter (nullptr), m_parentScope (nullptr) {} Block(const Block& toCopy): Statement(toCopy), m_symbols (toCopy.m_symbols), m_statements (toCopy.m_statements), m_filter (toCopy.m_filter), m_parentScope (toCopy.m_parentScope) {} public: void init(std::int32_t line, std::int32_t col, SymbolTable* symTabRef, StatementList* stmtListRef, IScope* scopeRef) { init(line,col,symTabRef,stmtListRef,scopeRef,nullptr); } void init(std::int32_t line, std::int32_t col, SymbolTable* symTabRef, StatementList* stmtListRef, IScope* scopeRef, Expression* filter) { Statement::init(line,col); m_symbols = symTabRef; m_statements = std::move(*stmtListRef); m_parentScope = scopeRef; m_filter = filter; } SymbolTable* symbols() const {return m_symbols;}; Expression* filter() const {return m_filter;}; StatementList& statements() {return m_statements;}; void addStatement(Statement* toAdd){ IScope* childScope = toAdd->asScope(); if (childScope != nullptr) childScope->setParentScope((IScope*)this); m_statements.push_back(toAdd); }; void setFilter(Expression* sexpr) {m_filter = sexpr;}; bool isSimpleBlock() {return m_symbols->size() == 0 && m_filter == nullptr;}; Identifier* resolveIdentifier(const std::string& aName) const override { return m_symbols->get(aName); }; IScope* getParentScope() const {return m_parentScope;}; std::string getScopeName() const override {return "";} void setParentScope(IScope* parentScope) {m_parentScope = parentScope;}; void addIdentifier(Identifier* anIdentifier, void* /*tag*/) {m_symbols->addIdentifier(anIdentifier);}; IScope* asScope() final {return (IScope*)this;} }; }