Project

General

Profile

root / trunk / compiler / ooasCompiler / src / org / momut / ooas / ast / statements / Assignment.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.statements;
29

    
30
import java.util.LinkedList;
31

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

    
38
///////////////////////////////////////////////
39
///  Assignment
40
///
41
public final class Assignment extends Statement implements IScope
42
{
43
        private final LinkedList<Expression> m_places;
44
        private final LinkedList<Expression> m_values;
45
        private Expression m_nondetExpression;
46
        private IScope m_parentScope;
47
        private final SymbolTable m_symbols; // needed for nondeterminsitic assignment (we most likely will have new variables)
48

    
49
        public LinkedList<Expression> places() { return m_places; }
50
        public LinkedList<Expression> values() { return m_values; }
51
        public Expression nondetExpression() { return m_nondetExpression; }
52
        public SymbolTable symbols() { return m_symbols; }
53

    
54
        public Assignment(Expression place, Expression value, Expression nondetExpression, int aline, int apos)
55
        {
56
                super (StatementKind.Assignment, aline, apos);
57
                m_places = new LinkedList<Expression>();
58
                m_values = new LinkedList<Expression>();
59
                if (place != null)
60
                        m_places.addFirst(place);
61
                if (value != null)
62
                        m_values.addFirst(value);
63
                m_nondetExpression = nondetExpression;
64
                m_symbols = new SymbolTable();
65
        }
66

    
67
        public Assignment(Assignment toCopy)
68
        {
69
                super (toCopy);
70
                m_places = new LinkedList<Expression>(toCopy.m_places);
71
                m_values = new LinkedList<Expression>(toCopy.m_values);
72
                m_nondetExpression = toCopy.m_nondetExpression;
73
                m_symbols = new SymbolTable(toCopy.symbols());
74
        }
75

    
76
        @Override
77
        public /*override*/ Statement Clone()
78
        {
79
                return new Assignment(this);
80
        }
81

    
82
        public void AddPlace(Expression aPlace)
83
        {
84
                m_places.addLast(aPlace);
85
        }
86

    
87
        public void AddValue(Expression aValue)
88
        {
89
                m_values.addLast(aValue);
90
        }
91

    
92
        public void SetNondetExpression(Expression anExpr)
93
        {
94
                m_nondetExpression = anExpr;
95
        }
96

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

    
103
        @Override
104
        public Identifier ResolveIdentifier(String aName)
105
        {
106
                if (m_symbols.Defined(aName))
107
                        return m_symbols.Get(aName);
108
                else
109
                        return null;
110
        }
111

    
112
        @Override
113
        public IScope GetParentScope()
114
        {
115
                return m_parentScope;
116
        }
117

    
118
        @Override
119
        public void SetParentScope(IScope parentScope)
120
        {
121
                m_parentScope = parentScope;
122
        }
123

    
124
        @Override
125
        public void AddIdentifier(Identifier anIdentifier, Object tag)
126
        {
127
                m_symbols.AddIdentifier(anIdentifier);
128
        }
129
}