Project

General

Profile

root / trunk / compiler / cppAst / ast / expressions / SetConstructor.hpp @ 7

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/expressions/TypeConstructionExpression.hpp>
29
#include <ast/IScope.hpp>
30
#include <ast/expressions/Expression.hpp>
31
#include <ast/IAstVisitor.hpp>
32
#include <ast/SymbolTable.hpp>
33
#include <base/Exceptions.hpp>
34
#include <ast/identifiers/Identifier.hpp>
35
#include <deque>
36

    
37
namespace Ast {
38

    
39
class SetConstructor final
40
        : public TypeConstructionExpression
41
        , public IScope
42
{
43
protected:
44
        ExpressionList m_items;
45
        SymbolTable* m_comprehensionVars;
46
        IScope* m_parentScope;
47
        Expression* m_comprehension;
48
        bool m_hasComprehension;
49

    
50
        SetConstructor():
51
                TypeConstructionExpression(ExpressionKind::SetConstr),
52
                m_items (),
53
                m_comprehensionVars (nullptr),
54
                m_parentScope (nullptr),
55
                m_comprehension (nullptr),
56
                m_hasComprehension (false)
57
        {};
58
        SetConstructor(const SetConstructor &toCopy):
59
                TypeConstructionExpression(toCopy),
60
                m_items (toCopy.m_items),
61
                m_comprehensionVars (toCopy.m_comprehensionVars),
62
                m_parentScope (toCopy.m_parentScope),
63
                m_comprehension (toCopy.m_comprehension),
64
                m_hasComprehension (toCopy.m_hasComprehension)
65
        {};
66

    
67
        static SetConstructor* create(ExpressionKind) {return new SetConstructor();}
68
        static SetConstructor* createCopy(const SetConstructor& toCopy) {return new SetConstructor(toCopy);}
69
public:
70
        friend class Ast;
71
        friend class Expression;
72

    
73
        void init(std::int32_t line, std::int32_t pos,
74
                        Type* typeRef,IdentifierList* callTargetsIdentifierListRef, SymbolTable* symbTabRef,
75
                        ExpressionList* exprList, SymbolTable *symTab, IScope* parentScope,
76
                        Expression* comprehension, bool hasComprehension)
77
        {
78
                TypeConstructionExpression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
79
                m_items = std::move(*exprList);
80
                m_parentScope = parentScope;
81
                m_comprehensionVars = symTab;
82
                m_comprehension = comprehension;
83
                m_hasComprehension = hasComprehension;
84
        }
85

    
86

    
87

    
88
        ExpressionList& items() {return m_items;}
89
        Expression* comprehension() {return m_comprehension;}
90
        bool hasComprehension() const {return m_hasComprehension;};
91
        SymbolTable* comprehensionVariables() {return m_comprehensionVars;};
92

    
93
        void addItem(Expression* anItem) {m_items.push_back(anItem);};
94
        void setComprehension(Expression* anExpr) {m_comprehension = anExpr;};
95
        void setHasComprehension(bool flag) {m_hasComprehension = flag;};
96
        Identifier* resolveIdentifier(const string& aName) const override {return m_comprehensionVars->get(aName);};
97
        IScope* getParentScope() const override {return m_parentScope;};
98
        std::string getScopeName() const override {return "";}
99
        void setParentScope(IScope* parentScope) override {m_parentScope = parentScope;};
100
        void addIdentifier(Identifier* anIdentifier, void* ) override {m_comprehensionVars->addIdentifier(anIdentifier);};
101
        void accept(IAstVisitor& visitor) override {visitor.visit(this);};
102
        //void setItems(ExpressionList& newItems) {m_items = newItems;};
103

    
104
        IScope* asScope() final {return (IScope*) this;}
105
};
106

    
107
}