Project

General

Profile

root / trunk / compiler / ooasCompiler / src / org / momut / ooas / ast / expressions / SetConstructor.java @ 7

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
  *
25
  */
26

    
27

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

    
30
import java.util.ArrayList;
31

    
32
import org.momut.ooas.ast.IAstVisitor;
33
import org.momut.ooas.ast.IScope;
34
import org.momut.ooas.ast.identifiers.Identifier;
35
import org.momut.ooas.parser.SymbolTable;
36

    
37
///////////////////////////////////////////////
38
///  Constructor: Set
39
///
40
public final class SetConstructor extends TypeConstructionExpression implements IScope
41
{
42
        private ArrayList<Expression> m_items;
43
        private final SymbolTable m_comprehensionVars;
44
        private IScope m_parentScope;
45
        private Expression m_comprehension;
46
        private boolean m_hasComprehension = false;
47

    
48
        public ArrayList<Expression> items() { return m_items; }
49
        public Expression comprehension() { return m_comprehension; }
50
        public boolean hasComprehension() { return m_hasComprehension; }
51
        public SymbolTable comprehensionVariables() { return m_comprehensionVars; }
52

    
53
        public SetConstructor(int line, int pos)
54
        {
55
                super (ExpressionKind.SetConstr, line, pos);
56
                m_items = new ArrayList<Expression>();
57
                m_comprehensionVars = new SymbolTable();
58
        }
59

    
60
        public SetConstructor(SetConstructor toCopy)
61
        {
62
                super (toCopy);
63
                m_items = new ArrayList<Expression>(toCopy.m_items);
64
                m_comprehensionVars = new SymbolTable(toCopy.m_comprehensionVars);
65
                m_parentScope = toCopy.m_parentScope;
66
                m_comprehension = toCopy.m_comprehension;
67
                m_hasComprehension = toCopy.m_hasComprehension;
68
        }
69

    
70
        @Override
71
        public /*override*/ Expression Clone()
72
        {
73
                return new SetConstructor(this);
74
        }
75

    
76
        public void AddItem(Expression anItem)
77
        {
78
                m_items.add(anItem);
79
        }
80

    
81
        public void SetComprehension(Expression anExpr)
82
        {
83
                m_comprehension = anExpr;
84
        }
85

    
86
        public void SetHasComprehension(boolean flag)
87
        {
88
                m_hasComprehension = flag;
89
        }
90

    
91
        @Override
92
        public Identifier ResolveIdentifier(String aName)
93
        {
94
                if (m_comprehensionVars.Defined(aName))
95
                        return m_comprehensionVars.Get(aName);
96
                else
97
                        return null;
98
        }
99

    
100
        @Override
101
        public IScope GetParentScope()
102
        {
103
                return m_parentScope;
104
        }
105

    
106
        @Override
107
        public void SetParentScope(IScope parentScope)
108
        {
109
                m_parentScope = parentScope;
110
        }
111

    
112
        @Override
113
        public void AddIdentifier(Identifier anIdentifier, Object tag)
114
        {
115
                m_comprehensionVars.AddIdentifier(anIdentifier);
116
        }
117

    
118
        public /*override*/ void Accept(IAstVisitor visitor)
119
        {
120
                visitor.visit(this);
121
        }
122

    
123
        public void SetItems(ArrayList<Expression> newItems)
124
        {
125
                m_items = newItems;
126
        }
127

    
128
}