Project

General

Profile

root / trunk / compiler / cppAst / ast / expressions / ObjectConstructor.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/IAstVisitor.hpp>
30
#include <ast/types/ActionSystemType.hpp>
31
#include <deque>
32
#include <cstdint>
33
#include <string>
34

    
35
namespace Ast {
36

    
37
class ObjectConstructor final
38
        : public TypeConstructionExpression
39
{
40
protected:
41
        /*std::int32_t*/ ActionSystemInstanceList::size_type m_currentInstance;
42
        ActionSystemInstanceList m_instances;
43
        std::string m_fixedObjectName;
44

    
45
        ObjectConstructor():
46
                TypeConstructionExpression(ExpressionKind::ObjectConstr),
47
                m_currentInstance (0),
48
                m_instances(),
49
                m_fixedObjectName ("")
50
        {};
51
        ObjectConstructor(const ObjectConstructor &toCopy):
52
                TypeConstructionExpression(toCopy),
53
                m_currentInstance(toCopy.m_currentInstance),
54
                m_instances(toCopy.m_instances),
55
                m_fixedObjectName (toCopy.m_fixedObjectName)
56
        {};
57

    
58
        static ObjectConstructor* create(ExpressionKind){return new ObjectConstructor();}
59
        static ObjectConstructor* createCopy(const ObjectConstructor& toCopy){return new ObjectConstructor(toCopy);}
60
public:
61
        friend class Ast;
62
        friend class Expression;
63

    
64
        void init(std::int32_t line, std::int32_t pos,
65
                        Type* typeRef,IdentifierList* callTargetsIdentifierListRef, SymbolTable* symbTabRef,
66
                        ActionSystemInstanceList* instanceList, std::uint32_t currentInstance, const char* name)
67
        {
68
                TypeConstructionExpression::init(line,pos,typeRef,callTargetsIdentifierListRef, symbTabRef);
69
                m_instances = std::move(*instanceList);
70
                m_currentInstance = currentInstance;
71
                m_fixedObjectName = name == nullptr ? "" : name;
72
        }
73

    
74

    
75
        std::uint32_t currentInstance() const {return (std::uint32_t) m_currentInstance;};
76
        ActionSystemInstanceList& instances() {return m_instances;};
77
        std::string givenObjectName() {return m_fixedObjectName;};
78
        void resetCurrentInstance() {m_currentInstance = 0;};
79

    
80
        void accept(IAstVisitor& visitor) override {visitor.visit(this);};
81
        void addInstance(ActionSystemInstance* anInstance) {m_instances.push_back(anInstance);};
82
        ActionSystemInstance* GetNextInstance() {
83
                ActionSystemInstance* result = m_instances[m_currentInstance];
84
                m_currentInstance++;
85
                return result;
86
        };
87
};
88
}