1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20
|
|
21
|
|
22
|
|
23
|
|
24
|
|
25
|
|
26
|
|
27
|
|
28
|
package org.momut.ooas.ast.types;
|
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.ast.identifiers.TypeIdentifier;
|
36
|
import org.momut.ooas.ast.statements.Block;
|
37
|
import org.momut.ooas.parser.SymbolTable;
|
38
|
import org.momut.ooas.utils.exceptions.ArgumentException;
|
39
|
import org.momut.ooas.utils.exceptions.InternalCompilerException;
|
40
|
|
41
|
public class OoActionSystemType extends Type implements IScope
|
42
|
{
|
43
|
private final boolean m_autoCons;
|
44
|
private OoActionSystemType m_baseType;
|
45
|
private Block m_doOdBlock;
|
46
|
private IScope m_parentScope;
|
47
|
private final SymbolTable m_symbols;
|
48
|
private final ArrayList<OoActionSystemInstance> m_objects;
|
49
|
private final ArrayList<OoActionSystemInstance> m_derivedObjects;
|
50
|
private boolean m_isInSystemDescription;
|
51
|
|
52
|
public Block doOdBlock() { return m_doOdBlock; }
|
53
|
public boolean autoConstruction() { return m_autoCons; }
|
54
|
public OoActionSystemType baseType() { return m_baseType; }
|
55
|
public SymbolTable symbols() { return m_symbols; }
|
56
|
public ArrayList<OoActionSystemInstance> objects() { return m_objects; }
|
57
|
public ArrayList<OoActionSystemInstance> derivedObjects() { return m_derivedObjects; }
|
58
|
public boolean isInSystemDescription() { return m_isInSystemDescription; }
|
59
|
|
60
|
public OoActionSystemType(
|
61
|
boolean autoCons,
|
62
|
OoActionSystemType refinedSystem,
|
63
|
TypeIdentifier typeName)
|
64
|
{
|
65
|
super(TypeKind.OoActionSystemType, typeName);
|
66
|
m_symbols = new SymbolTable();
|
67
|
m_autoCons = autoCons;
|
68
|
m_baseType = refinedSystem;
|
69
|
m_objects = new ArrayList<OoActionSystemInstance>();
|
70
|
m_derivedObjects = new ArrayList<OoActionSystemInstance>();
|
71
|
m_isInSystemDescription = false;
|
72
|
}
|
73
|
|
74
|
public final void SetDoOdBlock(Block anArg)
|
75
|
{
|
76
|
m_doOdBlock = anArg;
|
77
|
if (anArg.GetParentScope() == null)
|
78
|
anArg.SetParentScope(this);
|
79
|
else if (anArg.GetParentScope() != this)
|
80
|
throw new InternalCompilerException("Internal Error: Do-Od block has different parent set.");
|
81
|
}
|
82
|
|
83
|
|
84
|
@Override
|
85
|
public IScope GetParentScope()
|
86
|
{
|
87
|
return m_parentScope;
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
public void SetParentScope(IScope parentScope)
|
92
|
{
|
93
|
m_parentScope = parentScope;
|
94
|
}
|
95
|
|
96
|
public Identifier ResolveLocal(String aName)
|
97
|
{
|
98
|
if (m_symbols.Defined(aName))
|
99
|
return m_symbols.Get(aName);
|
100
|
else
|
101
|
return null;
|
102
|
}
|
103
|
|
104
|
@Override
|
105
|
public Identifier ResolveIdentifier(String aName)
|
106
|
{
|
107
|
Identifier result = ResolveLocal(aName);
|
108
|
if ((result == null) && (m_baseType != null))
|
109
|
result = m_baseType.ResolveIdentifier(aName);
|
110
|
return result;
|
111
|
}
|
112
|
|
113
|
@Override
|
114
|
public void AddIdentifier(Identifier anIdentifier, Object tag)
|
115
|
{
|
116
|
m_symbols.AddIdentifier(anIdentifier);
|
117
|
}
|
118
|
|
119
|
@Override
|
120
|
public void Accept(IAstVisitor visitor)
|
121
|
{
|
122
|
visitor.visit(this);
|
123
|
}
|
124
|
|
125
|
public void SetBaseType(OoActionSystemType newType)
|
126
|
{
|
127
|
if (newType == null)
|
128
|
throw new ArgumentException();
|
129
|
m_baseType = newType;
|
130
|
}
|
131
|
|
132
|
public SymbolTable getAllSymbols()
|
133
|
{
|
134
|
OoActionSystemType system;
|
135
|
final ArrayList<OoActionSystemType> inheritance = new ArrayList<OoActionSystemType>();
|
136
|
system = this;
|
137
|
while (system != null)
|
138
|
{
|
139
|
inheritance.add(0, system);
|
140
|
system = system.baseType();
|
141
|
}
|
142
|
final SymbolTable result = new SymbolTable();
|
143
|
for (final OoActionSystemType ooas: inheritance)
|
144
|
result.AddSymbolTable(ooas.symbols());
|
145
|
result.Replace("self", this.symbols().Get("self"));
|
146
|
return result;
|
147
|
}
|
148
|
|
149
|
@Override
|
150
|
public String AnonymousName()
|
151
|
{
|
152
|
return String.format("class_%s", Math.abs((long) this.hashCode()));
|
153
|
}
|
154
|
|
155
|
public final void SetIsInSystemDescription(boolean p)
|
156
|
{
|
157
|
m_isInSystemDescription = p;
|
158
|
}
|
159
|
|
160
|
@Override
|
161
|
public int valueCount() {
|
162
|
return m_objects.size() + m_derivedObjects.size() + 1;
|
163
|
}
|
164
|
|
165
|
}
|