Project

General

Profile

root / trunk / compiler / ooasCompiler / src / org / momut / ooas / ast / expressions / ObjectConstructor.java @ 9

1
/**
2
  *
3
  *                      OOAS Compiler
4
  *
5
  *       Copyright 2015, AIT Austrian Institute of Technology.
6
  * This code is based on the C# Version of the OOAS Compiler, which is
7
  * copyright 2015 by the Institute of Software Technology, Graz University
8
  * of Technology with portions copyright by the AIT Austrian Institute of
9
  * Technology. All rights reserved.
10
  *
11
  * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
12
  *
13
  * If you modify the file please update the list of contributors below to in-
14
  * clude your name. Please also stick to the coding convention of using TABs
15
  * to do the basic (block-level) indentation and spaces for anything after
16
  * that. (Enable the display of special chars and it should be pretty obvious
17
  * what this means.) Also, remove all trailing whitespace.
18
  *
19
  * Contributors:
20
  *               Willibald Krenn (AIT)
21
  *               Stephan Zimmerer (AIT)
22
  *               Markus Demetz (AIT)
23
  *               Christoph Czurda (AIT)
24
  *               Stefan Tiran (AIT)
25
  *
26
  */
27

    
28

    
29
package org.momut.ooas.ast.expressions;
30

    
31
import java.util.ArrayList;
32

    
33
import org.momut.ooas.ast.IAstVisitor;
34
import org.momut.ooas.ast.types.OoActionSystemInstance;
35
import org.momut.ooas.ast.types.OpaqueType;
36
import org.momut.ooas.ast.types.Type;
37

    
38
public final class ObjectConstructor extends TypeConstructionExpression
39
{
40
        private final ArrayList<OoActionSystemInstance> m_instances;
41
        private int m_currentInstance;
42
        private String m_fixedObjectName;
43

    
44
        private final String cleanup(String name) {
45
                if (name.startsWith("\"")) {
46
                        name = name.substring(1, name.length()-1);
47
                }
48
                return name;
49
        }
50

    
51
        public int currentInstance() { return m_currentInstance; }
52
        public ArrayList<OoActionSystemInstance> instances() { return m_instances; }
53
        public String givenObjectName() { return m_fixedObjectName; }
54

    
55
        public void ResetCurrentInstance() { m_currentInstance = 0; }
56

    
57
        public ObjectConstructor(OpaqueType aType, int line, int pos)
58
        {
59
                super (ExpressionKind.ObjectConstr, line, pos);
60
                SetType(aType);
61
                m_instances = new ArrayList<OoActionSystemInstance>();
62
                m_currentInstance = 0;
63
        }
64

    
65
        public ObjectConstructor(OpaqueType aType, String aName, int line, int pos)
66
        {
67
                super (ExpressionKind.ObjectConstr, line, pos);
68
                SetType(aType);
69
                m_instances = new ArrayList<OoActionSystemInstance>();
70
                m_currentInstance = 0;
71
                m_fixedObjectName = cleanup(aName);
72
        }
73

    
74
        public ObjectConstructor(Type aType, String aName, int line, int pos)
75
        {
76
                super (ExpressionKind.ObjectConstr, line, pos);
77
                SetType(aType);
78
                m_instances = new ArrayList<OoActionSystemInstance>();
79
                m_currentInstance = 0;
80
                m_fixedObjectName = cleanup(aName);
81
        }
82

    
83
        public ObjectConstructor(ObjectConstructor toCopy)
84
        {
85
                super (toCopy);
86
                m_instances = new ArrayList<OoActionSystemInstance>( toCopy.m_instances);
87
                m_currentInstance = toCopy.m_currentInstance;
88
                m_fixedObjectName = toCopy.m_fixedObjectName;
89
        }
90

    
91
        @Override
92
        public Expression Clone()
93
        {
94
                return new ObjectConstructor(this);
95
        }
96

    
97
        @Override
98
        public void Accept(IAstVisitor visitor)
99
        {
100
                visitor.visit(this);
101
        }
102

    
103
        public void AddInstance(OoActionSystemInstance anInstance)
104
        {
105
                m_instances.add(anInstance);
106
        }
107

    
108
        public OoActionSystemInstance GetNextInstance()
109
        {
110
                final OoActionSystemInstance result = m_instances.get(m_currentInstance);
111
                m_currentInstance++;
112
                return result;
113
        }
114
}