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
|
|
29
|
|
30
|
|
31
|
|
32
|
#include "Ast.hpp"
|
33
|
|
34
|
#include <ast/identifiers/TypeIdentifier.hpp>
|
35
|
#include <ast/identifiers/EnumIdentifier.hpp>
|
36
|
#include <ast/identifiers/AttributeIdentifier.hpp>
|
37
|
#include <ast/identifiers/LocalVariableIdentifier.hpp>
|
38
|
#include <ast/identifiers/ParameterIdentifier.hpp>
|
39
|
#include <ast/identifiers/ExpressionVariableIdentifier.hpp>
|
40
|
#include <ast/identifiers/MethodIdentifier.hpp>
|
41
|
#include <ast/identifiers/NamedActionIdentifier.hpp>
|
42
|
#include <ast/identifiers/Module.hpp>
|
43
|
#include <ast/identifiers/ConstantIdentifier.hpp>
|
44
|
#include <ast/types/IntType.hpp>
|
45
|
#include <ast/types/BoolType.hpp>
|
46
|
#include <ast/types/EnumType.hpp>
|
47
|
#include <ast/types/ValuedEnumType.hpp>
|
48
|
#include <ast/types/ListType.hpp>
|
49
|
#include <ast/types/TupleType.hpp>
|
50
|
#include <ast/types/NullType.hpp>
|
51
|
#include <ast/types/FunctionType.hpp>
|
52
|
#include <ast/types/ActionSystemType.hpp>
|
53
|
#include <ast/statements/GuardedCommand.hpp>
|
54
|
#include <ast/statements/Call.hpp>
|
55
|
#include <ast/statements/Assignment.hpp>
|
56
|
#include <ast/statements/SeqBlock.hpp>
|
57
|
#include <ast/statements/NondetBlock.hpp>
|
58
|
#include <ast/statements/PrioBlock.hpp>
|
59
|
#include <ast/statements/Skip.hpp>
|
60
|
#include <ast/statements/Abort.hpp>
|
61
|
#include <ast/expressions/TernaryOperator.hpp>
|
62
|
#include <ast/expressions/BinaryOperator.hpp>
|
63
|
#include <ast/expressions/UnaryOperator.hpp>
|
64
|
#include <ast/expressions/ExistsQuantifier.hpp>
|
65
|
#include <ast/expressions/ForallQuantifier.hpp>
|
66
|
#include <ast/expressions/ListConstructor.hpp>
|
67
|
#include <ast/expressions/SetConstructor.hpp>
|
68
|
#include <ast/expressions/TupleConstructor.hpp>
|
69
|
#include <ast/expressions/ObjectConstructor.hpp>
|
70
|
#include <ast/expressions/IdentifierExpression.hpp>
|
71
|
#include <ast/expressions/ValueExpression.hpp>
|
72
|
#include <ast/expressions/TypeExpression.hpp>
|
73
|
#include <ast/expressions/TupleMapAccessExpression.hpp>
|
74
|
#include <ast/expressions/CallExpression.hpp>
|
75
|
#include <ast/expressions/AccessExpression.hpp>
|
76
|
#include <ast/identifiers/IdentifierBlock.hpp>
|
77
|
#include <ast/identifiers/MainModule.hpp>
|
78
|
#include <ast/types/PointerType.hpp>
|
79
|
#include "DeepCloneVisitor.hpp"
|
80
|
#include <CallContext.hpp>
|
81
|
#include <base/CdtFixes.hpp>
|
82
|
#include <cassert>
|
83
|
|
84
|
|
85
|
namespace Ast {
|
86
|
|
87
|
Base::TiresiasObject* Ast::takeOwnership(Base::TiresiasObject* obj) {
|
88
|
m_allocatedAstObjects.push_back(obj);
|
89
|
return obj;
|
90
|
}
|
91
|
|
92
|
|
93
|
|
94
|
SymbolTable* Ast::createSymbolTable() {
|
95
|
return (SymbolTable*) takeOwnership(new SymbolTable());
|
96
|
}
|
97
|
SymbolTable* Ast::createSymbolTable(const SymbolTable& toCopy) {
|
98
|
return (SymbolTable*) takeOwnership(new SymbolTable(toCopy));
|
99
|
}
|
100
|
|
101
|
|
102
|
|
103
|
Identifier* Ast::createIdentifier(IdentifierKind t) {
|
104
|
Identifier* result = (Identifier*) takeOwnership(Identifier::createVirtual(t));
|
105
|
assert(result == nullptr || result->kind() == t);
|
106
|
return result;
|
107
|
}
|
108
|
Identifier* Ast::createIdentifier(const Identifier& toCopy) {
|
109
|
Identifier* result = (Identifier*) takeOwnership(Identifier::createVirtual(toCopy));
|
110
|
assert(result == nullptr || result->kind() == toCopy.kind());
|
111
|
return result;
|
112
|
}
|
113
|
|
114
|
|
115
|
ActionSystemInstance* Ast::createActionSystemInstance(){
|
116
|
return (ActionSystemInstance*) takeOwnership(new ActionSystemInstance());
|
117
|
}
|
118
|
ActionSystemInstance* Ast::createActionSystemInstance(const ActionSystemInstance& toCopy) {
|
119
|
return (ActionSystemInstance*) takeOwnership(new ActionSystemInstance(toCopy));
|
120
|
}
|
121
|
|
122
|
|
123
|
IdentifierList* Ast::createIdentifierList() {
|
124
|
return (IdentifierList*) takeOwnership(new IdentifierList());
|
125
|
};
|
126
|
IdentifierList* Ast::createIdentifierList(const IdentifierList& toCopy) {
|
127
|
return (IdentifierList*) takeOwnership(new IdentifierList(toCopy));
|
128
|
}
|
129
|
|
130
|
|
131
|
ParameterList* Ast::createParameterList() {
|
132
|
return (ParameterList*) takeOwnership(new ParameterList());
|
133
|
}
|
134
|
ParameterList* Ast::createParameterList(const ParameterList& toCopy) {
|
135
|
return (ParameterList*) takeOwnership(new ParameterList(toCopy));
|
136
|
}
|
137
|
|
138
|
|
139
|
ActionSystemInstanceList* Ast::createActionSystemInstanceList() {
|
140
|
return (ActionSystemInstanceList*) takeOwnership(new ActionSystemInstanceList());
|
141
|
}
|
142
|
ActionSystemInstanceList* Ast::createActionSystemInstanceList(const ActionSystemInstanceList& toCopy) {
|
143
|
return (ActionSystemInstanceList*) takeOwnership(new ActionSystemInstanceList(toCopy));
|
144
|
}
|
145
|
|
146
|
|
147
|
|
148
|
Type* Ast::createType(TypeKind t) {
|
149
|
Type* result = (Type*)takeOwnership(Type::createVirtual(t));
|
150
|
assert(result == nullptr || result->kind() == t);
|
151
|
return result;
|
152
|
}
|
153
|
Type* Ast::createType(const Type& toCopy) {
|
154
|
Type* result = (Type*)takeOwnership(Type::createVirtual(toCopy));
|
155
|
assert(result == nullptr || result->kind() == toCopy.kind());
|
156
|
return result;
|
157
|
}
|
158
|
|
159
|
|
160
|
TypeList* Ast::createTypeList() {
|
161
|
return (TypeList*) takeOwnership(new TypeList());
|
162
|
}
|
163
|
TypeList* Ast::createTypeList(const TypeList& toCopy) {
|
164
|
return (TypeList*) takeOwnership(new TypeList(toCopy));
|
165
|
}
|
166
|
|
167
|
|
168
|
|
169
|
Statement* Ast::createStatement(StatementKind t) {
|
170
|
Statement* result = (Statement*) takeOwnership(Statement::createVirtual(t));
|
171
|
assert(result == nullptr || result->kind() == t);
|
172
|
return result;
|
173
|
}
|
174
|
Statement* Ast::createStatement(const Statement& toCopy) {
|
175
|
Statement* result = (Statement*) takeOwnership(Statement::createVirtual(toCopy));
|
176
|
assert(result == nullptr || result->kind() == toCopy.kind());
|
177
|
return result;
|
178
|
}
|
179
|
|
180
|
Statement* Ast::deepCopyStatement(Statement* toCopy) {
|
181
|
Statement* result = createStatement(*toCopy);
|
182
|
DeepCloneVisitor cloner (m_context, this);
|
183
|
result->accept(cloner);
|
184
|
return result;
|
185
|
}
|
186
|
|
187
|
|
188
|
StatementList* Ast::createStatementList() {
|
189
|
return (StatementList*) takeOwnership( new StatementList());
|
190
|
};
|
191
|
StatementList* Ast::createStatementList(const StatementList& toCopy) {
|
192
|
return (StatementList*) takeOwnership( new StatementList(toCopy));
|
193
|
}
|
194
|
|
195
|
|
196
|
|
197
|
|
198
|
Expression* Ast::createExpression(ExpressionKind t) {
|
199
|
Expression* result = (Expression*) takeOwnership(Expression::createVirtual(t));
|
200
|
assert(result == nullptr || result->kind() == t);
|
201
|
return result;
|
202
|
}
|
203
|
Expression* Ast::createExpression(const Expression& toCopy) {
|
204
|
Expression* result = (Expression*) takeOwnership(Expression::createVirtual(toCopy));
|
205
|
assert(result == nullptr || result->kind() == toCopy.kind());
|
206
|
return result;
|
207
|
}
|
208
|
|
209
|
Expression* Ast::deepCopyExpression(Expression* toCopy) {
|
210
|
Expression* result = createExpression(*toCopy);
|
211
|
DeepCloneVisitor cloner (m_context, this);
|
212
|
result->accept(cloner);
|
213
|
return result;
|
214
|
}
|
215
|
|
216
|
|
217
|
ExpressionList* Ast::createExpressionList(){
|
218
|
return (ExpressionList*) takeOwnership(new ExpressionList());
|
219
|
};
|
220
|
ExpressionList* Ast::createExpressionList(const ExpressionList& toCopy) {
|
221
|
return (ExpressionList*) takeOwnership(new ExpressionList(toCopy));
|
222
|
}
|
223
|
|
224
|
Ast::Ast(CallContext* context):
|
225
|
m_context (context),
|
226
|
m_allocatedAstObjects()
|
227
|
{}
|
228
|
|
229
|
Ast::~Ast() {
|
230
|
for (auto& o: m_allocatedAstObjects)
|
231
|
delete o;
|
232
|
}
|
233
|
|
234
|
}
|