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.codegen.ast;
|
29
|
|
30
|
import java.util.HashSet;
|
31
|
import java.util.IdentityHashMap;
|
32
|
|
33
|
import org.momut.ooas.ast.IAst;
|
34
|
import org.momut.ooas.ast.IAstVisitor;
|
35
|
import org.momut.ooas.ast.IScope;
|
36
|
import org.momut.ooas.ast.expressions.AccessExpression;
|
37
|
import org.momut.ooas.ast.expressions.BinaryOperator;
|
38
|
import org.momut.ooas.ast.expressions.CallExpression;
|
39
|
import org.momut.ooas.ast.expressions.ExistsQuantifier;
|
40
|
import org.momut.ooas.ast.expressions.Expression;
|
41
|
import org.momut.ooas.ast.expressions.ForallQuantifier;
|
42
|
import org.momut.ooas.ast.expressions.IdentifierExpression;
|
43
|
import org.momut.ooas.ast.expressions.LeafExpression;
|
44
|
import org.momut.ooas.ast.expressions.ListConstructor;
|
45
|
import org.momut.ooas.ast.expressions.MapConstructor;
|
46
|
import org.momut.ooas.ast.expressions.ObjectConstructor;
|
47
|
import org.momut.ooas.ast.expressions.QValConstructor;
|
48
|
import org.momut.ooas.ast.expressions.Quantifier;
|
49
|
import org.momut.ooas.ast.expressions.SetConstructor;
|
50
|
import org.momut.ooas.ast.expressions.TernaryOperator;
|
51
|
import org.momut.ooas.ast.expressions.TupleConstructor;
|
52
|
import org.momut.ooas.ast.expressions.TupleMapAccessExpression;
|
53
|
import org.momut.ooas.ast.expressions.TypeExpression;
|
54
|
import org.momut.ooas.ast.expressions.UnaryOperator;
|
55
|
import org.momut.ooas.ast.expressions.UnresolvedIdentifierExpression;
|
56
|
import org.momut.ooas.ast.expressions.ValueExpression;
|
57
|
import org.momut.ooas.ast.identifiers.AttributeIdentifier;
|
58
|
import org.momut.ooas.ast.identifiers.ConstantIdentifier;
|
59
|
import org.momut.ooas.ast.identifiers.EnumIdentifier;
|
60
|
import org.momut.ooas.ast.identifiers.ExpressionVariableIdentifier;
|
61
|
import org.momut.ooas.ast.identifiers.FunctionIdentifier;
|
62
|
import org.momut.ooas.ast.identifiers.Identifier;
|
63
|
import org.momut.ooas.ast.identifiers.IdentifierKind;
|
64
|
import org.momut.ooas.ast.identifiers.IdentifierList;
|
65
|
import org.momut.ooas.ast.identifiers.LandmarkIdentifier;
|
66
|
import org.momut.ooas.ast.identifiers.LocalVariableIdentifier;
|
67
|
import org.momut.ooas.ast.identifiers.MainModule;
|
68
|
import org.momut.ooas.ast.identifiers.MethodIdentifier;
|
69
|
import org.momut.ooas.ast.identifiers.Module;
|
70
|
import org.momut.ooas.ast.identifiers.NamedActionIdentifier;
|
71
|
import org.momut.ooas.ast.identifiers.NondetIdentifierList;
|
72
|
import org.momut.ooas.ast.identifiers.ParameterIdentifier;
|
73
|
import org.momut.ooas.ast.identifiers.PrioIdentifierList;
|
74
|
import org.momut.ooas.ast.identifiers.SelfTypeIdentifier;
|
75
|
import org.momut.ooas.ast.identifiers.SeqIdentifierList;
|
76
|
import org.momut.ooas.ast.identifiers.TypeIdentifier;
|
77
|
import org.momut.ooas.ast.identifiers.UnspecIdentifierList;
|
78
|
import org.momut.ooas.ast.statements.AbortStatement;
|
79
|
import org.momut.ooas.ast.statements.Assignment;
|
80
|
import org.momut.ooas.ast.statements.BreakStatement;
|
81
|
import org.momut.ooas.ast.statements.Call;
|
82
|
import org.momut.ooas.ast.statements.GuardedCommand;
|
83
|
import org.momut.ooas.ast.statements.KillStatement;
|
84
|
import org.momut.ooas.ast.statements.NondetBlock;
|
85
|
import org.momut.ooas.ast.statements.PrioBlock;
|
86
|
import org.momut.ooas.ast.statements.QualitativeConstraintStatement;
|
87
|
import org.momut.ooas.ast.statements.SeqBlock;
|
88
|
import org.momut.ooas.ast.statements.SkipStatement;
|
89
|
import org.momut.ooas.ast.statements.Statement;
|
90
|
import org.momut.ooas.ast.types.AnyType;
|
91
|
import org.momut.ooas.ast.types.BoolType;
|
92
|
import org.momut.ooas.ast.types.CharType;
|
93
|
import org.momut.ooas.ast.types.EnumType;
|
94
|
import org.momut.ooas.ast.types.FloatType;
|
95
|
import org.momut.ooas.ast.types.FunctionType;
|
96
|
import org.momut.ooas.ast.types.IntType;
|
97
|
import org.momut.ooas.ast.types.ListType;
|
98
|
import org.momut.ooas.ast.types.MapType;
|
99
|
import org.momut.ooas.ast.types.NullType;
|
100
|
import org.momut.ooas.ast.types.OoActionSystemInstance;
|
101
|
import org.momut.ooas.ast.types.OoActionSystemType;
|
102
|
import org.momut.ooas.ast.types.OpaqueType;
|
103
|
import org.momut.ooas.ast.types.QrType;
|
104
|
import org.momut.ooas.ast.types.TupleType;
|
105
|
import org.momut.ooas.ast.types.TypeKind;
|
106
|
import org.momut.ooas.ast.types.UlyssesType;
|
107
|
import org.momut.ooas.ast.types.ValuedEnumType;
|
108
|
import org.momut.ooas.parser.ParserState;
|
109
|
import org.momut.ooas.utils.exceptions.NotImplementedException;
|
110
|
import org.momut.ooas.utils.exceptions.OoasCompilerRuntimeException;
|
111
|
|
112
|
public class OoaAstEmitter<T> implements IAstVisitor {
|
113
|
|
114
|
|
115
|
final IAstDuplicator<T> m_copier;
|
116
|
final ParserState m_state;
|
117
|
protected HashSet<Object> m_visited = new HashSet<Object>();
|
118
|
final IdentityHashMap<Identifier,T> m_convertedIdentifiers;
|
119
|
final IdentityHashMap<UlyssesType,T> m_convertedTypes;
|
120
|
final IdentityHashMap<Expression,T> m_convertedExpressions;
|
121
|
final IdentityHashMap<Statement,T> m_convertedStatements;
|
122
|
final IdentityHashMap<IScope,T> m_convertedScopes;
|
123
|
final IdentityHashMap<OoActionSystemInstance, T> m_convertedInstances;
|
124
|
|
125
|
public OoaAstEmitter(ParserState aState, IAstDuplicator<T> copier) {
|
126
|
m_copier = copier;
|
127
|
m_state = aState;
|
128
|
m_convertedIdentifiers = new IdentityHashMap<>();
|
129
|
m_convertedTypes = new IdentityHashMap<>();
|
130
|
m_convertedExpressions = new IdentityHashMap<>();
|
131
|
m_convertedStatements = new IdentityHashMap<>();
|
132
|
m_convertedScopes = new IdentityHashMap<>();
|
133
|
m_convertedInstances = new IdentityHashMap<>();
|
134
|
}
|
135
|
|
136
|
@Override
|
137
|
public String returnVisitorName() {
|
138
|
return this.getClass().getName();
|
139
|
}
|
140
|
|
141
|
@Override
|
142
|
public void done() {
|
143
|
}
|
144
|
|
145
|
protected final void VisitSub(IAst subElement, IAst parent)
|
146
|
{
|
147
|
if (subElement == null || m_visited.contains(subElement))
|
148
|
return;
|
149
|
m_visited.add(subElement);
|
150
|
subElement.Accept(this);
|
151
|
}
|
152
|
|
153
|
|
154
|
|
155
|
|
156
|
|
157
|
|
158
|
|
159
|
private final T createIdentifier(Identifier id) {
|
160
|
IdentifierKind kind = id.kind();
|
161
|
if (id instanceof MainModule)
|
162
|
kind = IdentifierKind.MainModule;
|
163
|
final int subOrd = (id instanceof IdentifierList)
|
164
|
? ((IdentifierList)id).listType().integerValue
|
165
|
: 0;
|
166
|
final T result = m_copier.createIdentifier(kind, subOrd);
|
167
|
if (m_convertedIdentifiers.put(id, result) != null)
|
168
|
throw new OoasCompilerRuntimeException("Identifier %s already has been copied.", id.toString());
|
169
|
if (id instanceof IScope) {
|
170
|
if (m_convertedScopes.put((IScope)id, m_copier.castToIScope(result)) != null)
|
171
|
throw new OoasCompilerRuntimeException("Scope %s already has been copied.", id.toString());
|
172
|
}
|
173
|
return result;
|
174
|
}
|
175
|
|
176
|
private final T createType(UlyssesType type) {
|
177
|
TypeKind kind = type.kind();
|
178
|
if (type instanceof ValuedEnumType)
|
179
|
kind = TypeKind.ValuedEnumeratedType;
|
180
|
final T result = m_copier.createType(kind);
|
181
|
if (m_convertedTypes.put(type, result) != null)
|
182
|
throw new OoasCompilerRuntimeException("Type %s already has been copied.", type.toString());
|
183
|
if (type instanceof IScope) {
|
184
|
if (m_convertedScopes.put((IScope)type, m_copier.castToIScope(result)) != null)
|
185
|
throw new OoasCompilerRuntimeException("Scope %s already has been copied.", type.toString());
|
186
|
}
|
187
|
return result;
|
188
|
}
|
189
|
|
190
|
private final T createExpression(Expression expression) {
|
191
|
final int subOrd = (expression instanceof LeafExpression)
|
192
|
? ((LeafExpression)expression).valueType().integerValue
|
193
|
: 0;
|
194
|
final T result = m_copier.createExpression(expression.kind(), subOrd);
|
195
|
if (m_convertedExpressions.put(expression, result) != null)
|
196
|
throw new OoasCompilerRuntimeException("Expression %s already has been copied.", expression.toString());
|
197
|
if (expression instanceof IScope) {
|
198
|
if (m_convertedScopes.put((IScope)expression, m_copier.castToIScope(result)) != null)
|
199
|
throw new OoasCompilerRuntimeException("Scope %s already has been copied.", expression.toString());
|
200
|
}
|
201
|
return result;
|
202
|
}
|
203
|
|
204
|
private final T createStatement(Statement statement) {
|
205
|
final T result = m_copier.createStatement(statement.kind());
|
206
|
if (m_convertedStatements.put(statement, result) != null)
|
207
|
throw new OoasCompilerRuntimeException("Statement %s already has been copied.", statement.toString());
|
208
|
if (statement instanceof IScope) {
|
209
|
if (m_convertedScopes.put((IScope)statement, m_copier.castToIScope(result)) != null)
|
210
|
throw new OoasCompilerRuntimeException("Scope %s already has been copied.", statement.toString());
|
211
|
}
|
212
|
return result;
|
213
|
}
|
214
|
|
215
|
@Override
|
216
|
public void visit(EnumIdentifier enumIdentifier)
|
217
|
{
|
218
|
final T id = createIdentifier(enumIdentifier);
|
219
|
|
220
|
|
221
|
VisitSub(enumIdentifier.definingScope(), enumIdentifier);
|
222
|
VisitSub(enumIdentifier.type(), enumIdentifier);
|
223
|
|
224
|
|
225
|
m_copier.initEnumIdentifier(
|
226
|
id,
|
227
|
enumIdentifier.line(),
|
228
|
enumIdentifier.column(),
|
229
|
enumIdentifier.tokenText(),
|
230
|
m_convertedScopes.get(enumIdentifier.definingScope()),
|
231
|
m_convertedTypes.get(enumIdentifier.type()),
|
232
|
enumIdentifier.HaveValue(),
|
233
|
enumIdentifier.Value());
|
234
|
}
|
235
|
|
236
|
|
237
|
@Override
|
238
|
public void visit(ConstantIdentifier constantIdentifier)
|
239
|
{
|
240
|
final T constId = createIdentifier(constantIdentifier);
|
241
|
|
242
|
|
243
|
VisitSub(constantIdentifier.definingScope(), constantIdentifier);
|
244
|
VisitSub(constantIdentifier.type(), constantIdentifier);
|
245
|
VisitSub(constantIdentifier.Value(), constantIdentifier);
|
246
|
|
247
|
|
248
|
m_copier.initConstantIdentifier(
|
249
|
constId,
|
250
|
constantIdentifier.line(),
|
251
|
constantIdentifier.column(),
|
252
|
constantIdentifier.tokenText(),
|
253
|
m_convertedScopes.get(constantIdentifier.definingScope()),
|
254
|
m_convertedTypes.get(constantIdentifier.type()),
|
255
|
m_convertedExpressions.get(constantIdentifier.Value()));
|
256
|
}
|
257
|
|
258
|
@Override
|
259
|
public void visit(AttributeIdentifier attributeIdentifier)
|
260
|
{
|
261
|
final T id = createIdentifier(attributeIdentifier);
|
262
|
|
263
|
|
264
|
VisitSub(attributeIdentifier.definingScope(), attributeIdentifier);
|
265
|
VisitSub(attributeIdentifier.type(), attributeIdentifier);
|
266
|
VisitSub(attributeIdentifier.initializer(), attributeIdentifier);
|
267
|
|
268
|
|
269
|
m_copier.initAttributeIdentifier(
|
270
|
id,
|
271
|
attributeIdentifier.line(),
|
272
|
attributeIdentifier.column(),
|
273
|
attributeIdentifier.tokenText(),
|
274
|
m_convertedScopes.get(attributeIdentifier.definingScope()),
|
275
|
m_convertedTypes.get(attributeIdentifier.type()),
|
276
|
m_convertedExpressions.get(attributeIdentifier.initializer()),
|
277
|
attributeIdentifier.isStatic(),
|
278
|
attributeIdentifier.isControllable(),
|
279
|
attributeIdentifier.isObservable());
|
280
|
}
|
281
|
|
282
|
@Override
|
283
|
public void visit(ExpressionVariableIdentifier expressionVariableIdentifier)
|
284
|
{
|
285
|
final T id = createIdentifier(expressionVariableIdentifier);
|
286
|
|
287
|
|
288
|
VisitSub(expressionVariableIdentifier.definingScope(), expressionVariableIdentifier);
|
289
|
VisitSub(expressionVariableIdentifier.type(), expressionVariableIdentifier);
|
290
|
|
291
|
|
292
|
m_copier.initExprVarIdentifier(
|
293
|
id,
|
294
|
expressionVariableIdentifier.line(),
|
295
|
expressionVariableIdentifier.column(),
|
296
|
expressionVariableIdentifier.tokenText(),
|
297
|
m_convertedScopes.get(expressionVariableIdentifier.definingScope()),
|
298
|
m_convertedTypes.get(expressionVariableIdentifier.type()),
|
299
|
expressionVariableIdentifier.initialized());
|
300
|
}
|
301
|
|
302
|
@Override
|
303
|
public void visit(ParameterIdentifier parameterIdentifier)
|
304
|
{
|
305
|
final T id = createIdentifier(parameterIdentifier);
|
306
|
|
307
|
|
308
|
VisitSub(parameterIdentifier.definingScope(), parameterIdentifier);
|
309
|
VisitSub(parameterIdentifier.type(), parameterIdentifier);
|
310
|
|
311
|
|
312
|
m_copier.initParamIdentifier(
|
313
|
id,
|
314
|
parameterIdentifier.line(),
|
315
|
parameterIdentifier.column(),
|
316
|
parameterIdentifier.tokenText(),
|
317
|
m_convertedScopes.get(parameterIdentifier.definingScope()),
|
318
|
m_convertedTypes.get(parameterIdentifier.type()));
|
319
|
}
|
320
|
|
321
|
@Override
|
322
|
public void visit(LocalVariableIdentifier localVariableIdentifier)
|
323
|
{
|
324
|
final T id = createIdentifier(localVariableIdentifier);
|
325
|
|
326
|
|
327
|
VisitSub(localVariableIdentifier.definingScope(), localVariableIdentifier);
|
328
|
VisitSub(localVariableIdentifier.type(), localVariableIdentifier);
|
329
|
|
330
|
|
331
|
m_copier.initLocalVarIdentifier(
|
332
|
id,
|
333
|
localVariableIdentifier.line(),
|
334
|
localVariableIdentifier.column(),
|
335
|
localVariableIdentifier.tokenText(),
|
336
|
m_convertedScopes.get(localVariableIdentifier.definingScope()),
|
337
|
m_convertedTypes.get(localVariableIdentifier.type()));
|
338
|
}
|
339
|
|
340
|
@Override
|
341
|
public void visit(TypeIdentifier typeIdentifier)
|
342
|
{
|
343
|
final T id = createIdentifier(typeIdentifier);
|
344
|
|
345
|
|
346
|
VisitSub(typeIdentifier.definingScope(), typeIdentifier);
|
347
|
VisitSub(typeIdentifier.type(), typeIdentifier);
|
348
|
|
349
|
|
350
|
m_copier.initTypeIdentifier(
|
351
|
id,
|
352
|
typeIdentifier.line(),
|
353
|
typeIdentifier.column(),
|
354
|
typeIdentifier.tokenText(),
|
355
|
m_convertedScopes.get(typeIdentifier.definingScope()),
|
356
|
m_convertedTypes.get(typeIdentifier.type()),
|
357
|
typeIdentifier.prefix);
|
358
|
}
|
359
|
|
360
|
@Override
|
361
|
public void visit(SelfTypeIdentifier aself)
|
362
|
{
|
363
|
final T id = createIdentifier(aself);
|
364
|
|
365
|
|
366
|
VisitSub(aself.definingScope(), aself);
|
367
|
VisitSub(aself.type(), aself);
|
368
|
|
369
|
|
370
|
m_copier.initSelfIdentifier(
|
371
|
id,
|
372
|
aself.line(),
|
373
|
aself.column(),
|
374
|
aself.tokenText(),
|
375
|
m_convertedScopes.get(aself.definingScope()),
|
376
|
m_convertedTypes.get(aself.type()),
|
377
|
aself.prefix);
|
378
|
}
|
379
|
|
380
|
@Override
|
381
|
public void visit(MethodIdentifier methodIdentifier)
|
382
|
{
|
383
|
final T id = createIdentifier(methodIdentifier);
|
384
|
|
385
|
|
386
|
VisitSub(methodIdentifier.definingScope(), methodIdentifier);
|
387
|
VisitSub(methodIdentifier.type(), methodIdentifier);
|
388
|
for (final Identifier sym: methodIdentifier.symbolTable().symbolList())
|
389
|
VisitSub(sym, methodIdentifier);
|
390
|
for (final ParameterIdentifier par: methodIdentifier.parameter())
|
391
|
VisitSub(par, methodIdentifier);
|
392
|
VisitSub(methodIdentifier.body(), methodIdentifier);
|
393
|
|
394
|
|
395
|
final T symbolTable = m_copier.createSymbolTable();
|
396
|
for (final Identifier sym: methodIdentifier.symbolTable().symbolList())
|
397
|
m_copier.addIdentifierToSymbolTable(symbolTable, m_convertedIdentifiers.get(sym));
|
398
|
final T parameterList = m_copier.createParameterList();
|
399
|
for (final ParameterIdentifier par: methodIdentifier.parameter())
|
400
|
m_copier.addParameterIdentifierToList(parameterList, m_convertedIdentifiers.get(par));
|
401
|
|
402
|
m_copier.initMethodIdentifier(
|
403
|
id,
|
404
|
methodIdentifier.line(),
|
405
|
methodIdentifier.column(),
|
406
|
methodIdentifier.tokenText(),
|
407
|
m_convertedScopes.get(methodIdentifier.definingScope()),
|
408
|
m_convertedTypes.get(methodIdentifier.type()),
|
409
|
methodIdentifier.prefix,
|
410
|
parameterList,
|
411
|
symbolTable,
|
412
|
m_convertedStatements.get(methodIdentifier.body()));
|
413
|
}
|
414
|
|
415
|
@Override
|
416
|
public void visit(NamedActionIdentifier namedActionIdentifier)
|
417
|
{
|
418
|
final T id = createIdentifier(namedActionIdentifier);
|
419
|
|
420
|
|
421
|
VisitSub(namedActionIdentifier.definingScope(), namedActionIdentifier);
|
422
|
VisitSub(namedActionIdentifier.type(), namedActionIdentifier);
|
423
|
for (final Identifier sym : namedActionIdentifier.symbolTable().symbolList())
|
424
|
VisitSub(sym, namedActionIdentifier);
|
425
|
for (final ParameterIdentifier par: namedActionIdentifier.parameter())
|
426
|
VisitSub(par, namedActionIdentifier);
|
427
|
VisitSub(namedActionIdentifier.body(), namedActionIdentifier);
|
428
|
|
429
|
|
430
|
final T symbolTable = m_copier.createSymbolTable();
|
431
|
for (final Identifier sym: namedActionIdentifier.symbolTable().symbolList())
|
432
|
m_copier.addIdentifierToSymbolTable(symbolTable, m_convertedIdentifiers.get(sym));
|
433
|
final T parameterList = m_copier.createParameterList();
|
434
|
for (final ParameterIdentifier par: namedActionIdentifier.parameter())
|
435
|
m_copier.addParameterIdentifierToList(parameterList, m_convertedIdentifiers.get(par));
|
436
|
|
437
|
m_copier.initMethodIdentifier(
|
438
|
id,
|
439
|
namedActionIdentifier.line(),
|
440
|
namedActionIdentifier.column(),
|
441
|
namedActionIdentifier.tokenText(),
|
442
|
m_convertedScopes.get(namedActionIdentifier.definingScope()),
|
443
|
m_convertedTypes.get(namedActionIdentifier.type()),
|
444
|
namedActionIdentifier.prefix,
|
445
|
parameterList,
|
446
|
symbolTable,
|
447
|
m_convertedStatements.get(namedActionIdentifier.body()));
|
448
|
}
|
449
|
|
450
|
@Override
|
451
|
public void visit(Module module)
|
452
|
{
|
453
|
final T id = createIdentifier(module);
|
454
|
|
455
|
VisitSub(module.definingScope(), module);
|
456
|
VisitSub(module.type(), module);
|
457
|
for (final Identifier sym: module.symbolTable().symbolList())
|
458
|
VisitSub(sym, module);
|
459
|
|
460
|
final T symTab = m_copier.createSymbolTable();
|
461
|
for (final Identifier sym: module.symbolTable().symbolList())
|
462
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(sym));
|
463
|
|
464
|
m_copier.initModule(
|
465
|
id,
|
466
|
module.line(),
|
467
|
module.column(),
|
468
|
module.tokenText(),
|
469
|
m_convertedScopes.get(module.definingScope()),
|
470
|
m_convertedTypes.get(module.type()),
|
471
|
module.prefix,
|
472
|
symTab);
|
473
|
}
|
474
|
|
475
|
|
476
|
|
477
|
|
478
|
|
479
|
|
480
|
|
481
|
@Override
|
482
|
public void visit(MainModule mainModule)
|
483
|
{
|
484
|
m_visited.add(mainModule);
|
485
|
|
486
|
final T id = createIdentifier(mainModule);
|
487
|
|
488
|
VisitSub(mainModule.definingScope(), mainModule);
|
489
|
VisitSub(mainModule.type(), mainModule);
|
490
|
for (final Identifier sym: mainModule.symbolTable().symbolList())
|
491
|
VisitSub(sym, mainModule);
|
492
|
VisitSub(mainModule.systemDescription(), mainModule);
|
493
|
|
494
|
final T symTab = m_copier.createSymbolTable();
|
495
|
for (final Identifier sym: mainModule.symbolTable().symbolList())
|
496
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(sym));
|
497
|
|
498
|
m_copier.initMainModule(
|
499
|
id,
|
500
|
mainModule.line(),
|
501
|
mainModule.column(),
|
502
|
mainModule.tokenText(),
|
503
|
m_convertedScopes.get(mainModule.definingScope()),
|
504
|
m_convertedTypes.get(mainModule.type()),
|
505
|
mainModule.prefix,
|
506
|
symTab,
|
507
|
m_convertedIdentifiers.get(mainModule.systemDescription()));
|
508
|
|
509
|
m_copier.setMainModule(mainModule, id);
|
510
|
}
|
511
|
|
512
|
|
513
|
@Override
|
514
|
public void visit(NondetIdentifierList nondetIdentifierList)
|
515
|
{
|
516
|
final T idList = createIdentifier(nondetIdentifierList);
|
517
|
|
518
|
|
519
|
|
520
|
for (final Identifier id: nondetIdentifierList.identifiers())
|
521
|
VisitSub(id, nondetIdentifierList);
|
522
|
|
523
|
for (final Identifier id: nondetIdentifierList.identifiers())
|
524
|
m_copier.addIdentifierToBlock(idList, m_convertedIdentifiers.get(id));
|
525
|
}
|
526
|
|
527
|
@Override
|
528
|
public void visit(SeqIdentifierList seqIdentifierList)
|
529
|
{
|
530
|
final T idList = createIdentifier(seqIdentifierList);
|
531
|
|
532
|
|
533
|
|
534
|
for (final Identifier id: seqIdentifierList.identifiers())
|
535
|
VisitSub(id, seqIdentifierList);
|
536
|
|
537
|
for (final Identifier id: seqIdentifierList.identifiers())
|
538
|
m_copier.addIdentifierToBlock(idList, m_convertedIdentifiers.get(id));
|
539
|
}
|
540
|
|
541
|
@Override
|
542
|
public void visit(PrioIdentifierList prioIdentifierList)
|
543
|
{
|
544
|
final T idList = createIdentifier(prioIdentifierList);
|
545
|
|
546
|
|
547
|
|
548
|
for (final Identifier id: prioIdentifierList.identifiers())
|
549
|
VisitSub(id, prioIdentifierList);
|
550
|
|
551
|
for (final Identifier id: prioIdentifierList.identifiers())
|
552
|
m_copier.addIdentifierToBlock(idList, m_convertedIdentifiers.get(id));
|
553
|
}
|
554
|
|
555
|
@Override
|
556
|
public void visit(UnspecIdentifierList unspecIdentifierList)
|
557
|
{
|
558
|
final T idList = createIdentifier(unspecIdentifierList);
|
559
|
|
560
|
|
561
|
|
562
|
for (final Identifier id: unspecIdentifierList.identifiers())
|
563
|
VisitSub(id, unspecIdentifierList);
|
564
|
|
565
|
for (final Identifier id: unspecIdentifierList.identifiers())
|
566
|
m_copier.addIdentifierToBlock(idList, m_convertedIdentifiers.get(id));
|
567
|
}
|
568
|
|
569
|
|
570
|
|
571
|
|
572
|
@Override
|
573
|
public void visit(IntType intType)
|
574
|
{
|
575
|
final T type = createType(intType);
|
576
|
|
577
|
final Identifier id = intType.identifier();
|
578
|
VisitSub(id, intType);
|
579
|
|
580
|
m_copier.initIntType(
|
581
|
type,
|
582
|
m_convertedIdentifiers.get(id),
|
583
|
intType.isAnonymousType(),
|
584
|
intType.rangeLow(),
|
585
|
intType.rangeHigh());
|
586
|
}
|
587
|
|
588
|
@Override
|
589
|
public void visit(BoolType boolType)
|
590
|
{
|
591
|
final T type = createType(boolType);
|
592
|
|
593
|
final Identifier id = boolType.identifier();
|
594
|
VisitSub(id, boolType);
|
595
|
|
596
|
m_copier.initBoolType(
|
597
|
type,
|
598
|
m_convertedIdentifiers.get(id),
|
599
|
boolType.isAnonymousType());
|
600
|
}
|
601
|
|
602
|
@Override
|
603
|
public void visit(EnumType enumType)
|
604
|
{
|
605
|
final T type = createType(enumType);
|
606
|
|
607
|
final Identifier id = enumType.identifier();
|
608
|
VisitSub(id, enumType);
|
609
|
for (final Identifier sym: enumType.listOfEnumSymbols())
|
610
|
VisitSub(sym, enumType);
|
611
|
|
612
|
|
613
|
final T symTab = m_copier.createSymbolTable();
|
614
|
for (final Identifier sym: enumType.listOfEnumSymbols())
|
615
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(sym));
|
616
|
|
617
|
|
618
|
if (enumType instanceof ValuedEnumType) {
|
619
|
final ValuedEnumType t = (ValuedEnumType) enumType;
|
620
|
VisitSub(t.getIntType(), t);
|
621
|
m_copier.initValuedEnumType(
|
622
|
type,
|
623
|
m_convertedIdentifiers.get(id),
|
624
|
enumType.isAnonymousType(),
|
625
|
symTab,
|
626
|
m_convertedTypes.get(t.getIntType()));
|
627
|
} else
|
628
|
m_copier.initEnumType(
|
629
|
type,
|
630
|
m_convertedIdentifiers.get(id),
|
631
|
enumType.isAnonymousType(),
|
632
|
symTab);
|
633
|
}
|
634
|
|
635
|
@Override
|
636
|
public void visit(ListType listType)
|
637
|
{
|
638
|
final T type = createType(listType);
|
639
|
|
640
|
final Identifier id = listType.identifier();
|
641
|
VisitSub(id, listType);
|
642
|
VisitSub(listType.innerType(), listType);
|
643
|
|
644
|
m_copier.initListType(
|
645
|
type,
|
646
|
m_convertedIdentifiers.get(id),
|
647
|
listType.isAnonymousType(),
|
648
|
m_convertedTypes.get(listType.innerType()),
|
649
|
listType.maxNumberOfElements());
|
650
|
}
|
651
|
|
652
|
|
653
|
@Override
|
654
|
public void visit(TupleType tupleType)
|
655
|
{
|
656
|
final T type = createType(tupleType);
|
657
|
|
658
|
final Identifier id = tupleType.identifier();
|
659
|
VisitSub(id, tupleType);
|
660
|
for (final UlyssesType t: tupleType.innerTypes())
|
661
|
VisitSub(t, tupleType);
|
662
|
|
663
|
final T list = m_copier.createTypeList();
|
664
|
for (final UlyssesType t: tupleType.innerTypes())
|
665
|
m_copier.addTypeToList(list, m_convertedTypes.get(t));
|
666
|
|
667
|
m_copier.initTupleType(
|
668
|
type,
|
669
|
m_convertedIdentifiers.get(id),
|
670
|
tupleType.isAnonymousType(),
|
671
|
list);
|
672
|
}
|
673
|
|
674
|
@Override
|
675
|
public void visit(FunctionType functionType)
|
676
|
{
|
677
|
final T type = createType(functionType);
|
678
|
|
679
|
final Identifier id = functionType.identifier();
|
680
|
VisitSub(id, functionType);
|
681
|
for (final UlyssesType a: functionType.parameter())
|
682
|
VisitSub(a, functionType);
|
683
|
VisitSub(functionType.returnType(), functionType);
|
684
|
|
685
|
|
686
|
final T list = m_copier.createTypeList();
|
687
|
for (final UlyssesType t: functionType.parameter())
|
688
|
m_copier.addTypeToList(list, m_convertedTypes.get(t));
|
689
|
|
690
|
m_copier.initFunctionType(
|
691
|
type,
|
692
|
m_convertedIdentifiers.get(id),
|
693
|
functionType.isAnonymousType(),
|
694
|
list,
|
695
|
m_convertedTypes.get(functionType.returnType()),
|
696
|
functionType.functionType().integerValue,
|
697
|
functionType.isPureFunction());
|
698
|
|
699
|
}
|
700
|
|
701
|
private void convertActionSystemInstance(OoActionSystemInstance i, IAst ooActionSystemType) {
|
702
|
if (i == null || m_convertedInstances.containsKey(i))
|
703
|
return;
|
704
|
final T instance = m_copier.createActionSystemInstance();
|
705
|
m_convertedInstances.put(i, instance);
|
706
|
|
707
|
VisitSub(i.Type, ooActionSystemType);
|
708
|
convertActionSystemInstance(i.ParentObject, ooActionSystemType);
|
709
|
|
710
|
m_copier.initActionSystemInstance(
|
711
|
instance,
|
712
|
m_convertedTypes.get(i.Type),
|
713
|
i.Name,
|
714
|
i.numberOfCreatedObjects,
|
715
|
m_convertedInstances.get(i.ParentObject));
|
716
|
}
|
717
|
|
718
|
@Override
|
719
|
public void visit(OoActionSystemType ooActionSystemType)
|
720
|
{
|
721
|
final T type = createType(ooActionSystemType);
|
722
|
|
723
|
final Identifier id = ooActionSystemType.identifier();
|
724
|
VisitSub(id, ooActionSystemType);
|
725
|
for (final Identifier s: ooActionSystemType.symbols().symbolList())
|
726
|
VisitSub(s, ooActionSystemType);
|
727
|
VisitSub(ooActionSystemType.doOdBlock(), ooActionSystemType);
|
728
|
VisitSub(ooActionSystemType.baseType(), ooActionSystemType);
|
729
|
for (final OoActionSystemInstance i: ooActionSystemType.objects())
|
730
|
convertActionSystemInstance(i, ooActionSystemType);
|
731
|
for (final OoActionSystemInstance i: ooActionSystemType.derivedObjects())
|
732
|
convertActionSystemInstance(i, ooActionSystemType);
|
733
|
|
734
|
final T symTab = m_copier.createSymbolTable();
|
735
|
for (final Identifier s: ooActionSystemType.symbols().symbolList())
|
736
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(s));
|
737
|
|
738
|
final T objectsList = m_copier.createActionSystemInstanceList();
|
739
|
for (final OoActionSystemInstance i: ooActionSystemType.objects())
|
740
|
m_copier.addActionSystemInstanceToList(objectsList, m_convertedInstances.get(i));
|
741
|
final T derivedObjectsList = m_copier.createActionSystemInstanceList();
|
742
|
for (final OoActionSystemInstance i: ooActionSystemType.derivedObjects())
|
743
|
m_copier.addActionSystemInstanceToList(objectsList, m_convertedInstances.get(i));
|
744
|
|
745
|
|
746
|
m_copier.initActionSystemType(
|
747
|
type,
|
748
|
m_convertedIdentifiers.get(id),
|
749
|
ooActionSystemType.isAnonymousType(),
|
750
|
m_convertedTypes.get(ooActionSystemType.baseType()),
|
751
|
m_convertedScopes.get(ooActionSystemType.GetParentScope()),
|
752
|
m_convertedStatements.get(ooActionSystemType.doOdBlock()),
|
753
|
symTab,
|
754
|
objectsList,
|
755
|
derivedObjectsList,
|
756
|
ooActionSystemType.autoConstruction(),
|
757
|
ooActionSystemType.isInSystemDescription());
|
758
|
}
|
759
|
|
760
|
@Override
|
761
|
public void visit(NullType nullType)
|
762
|
{
|
763
|
final T type = createType(nullType);
|
764
|
|
765
|
final Identifier id = nullType.identifier();
|
766
|
VisitSub(id, nullType);
|
767
|
|
768
|
m_copier.initNullType(
|
769
|
type,
|
770
|
m_convertedIdentifiers.get(id),
|
771
|
nullType.isAnonymousType());
|
772
|
}
|
773
|
|
774
|
|
775
|
|
776
|
@Override
|
777
|
public void visit(SkipStatement skipStatement)
|
778
|
{
|
779
|
m_copier.initSkipStatement(
|
780
|
createStatement(skipStatement),
|
781
|
skipStatement.line(),
|
782
|
skipStatement.pos());
|
783
|
}
|
784
|
|
785
|
|
786
|
@Override
|
787
|
public void visit(BreakStatement breakStatement)
|
788
|
{
|
789
|
m_copier.initBreakStatement(
|
790
|
createStatement(breakStatement),
|
791
|
breakStatement.line(),
|
792
|
breakStatement.pos());
|
793
|
}
|
794
|
|
795
|
@Override
|
796
|
public void visit(AbortStatement abortStatement)
|
797
|
{
|
798
|
m_copier.initAbortStatement(
|
799
|
createStatement(abortStatement),
|
800
|
abortStatement.line(),
|
801
|
abortStatement.pos());
|
802
|
}
|
803
|
|
804
|
@Override
|
805
|
public void visit(NondetBlock nondetBlock)
|
806
|
{
|
807
|
final T stmt = createStatement(nondetBlock);
|
808
|
|
809
|
|
810
|
VisitSub(nondetBlock.GetParentScope(), nondetBlock);
|
811
|
for (final Identifier id: nondetBlock.symbols().symbolList())
|
812
|
VisitSub(id, nondetBlock);
|
813
|
for (final Statement stmnt: nondetBlock.statements())
|
814
|
VisitSub(stmnt, nondetBlock);
|
815
|
|
816
|
|
817
|
final T symTab = m_copier.createSymbolTable();
|
818
|
for (final Identifier id: nondetBlock.symbols().symbolList())
|
819
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(id));
|
820
|
|
821
|
final T stmtList = m_copier.createStatementList();
|
822
|
for (final Statement stmnt: nondetBlock.statements())
|
823
|
m_copier.addStatementToList(stmtList, m_convertedStatements.get(stmnt));
|
824
|
|
825
|
m_copier.initNondetBlock(
|
826
|
stmt,
|
827
|
nondetBlock.line(),
|
828
|
nondetBlock.pos(),
|
829
|
symTab,
|
830
|
stmtList,
|
831
|
m_convertedScopes.get(nondetBlock.GetParentScope()));
|
832
|
}
|
833
|
|
834
|
@Override
|
835
|
public void visit(SeqBlock seqBlock)
|
836
|
{
|
837
|
final T stmt = createStatement(seqBlock);
|
838
|
|
839
|
|
840
|
VisitSub(seqBlock.GetParentScope(), seqBlock);
|
841
|
for (final Identifier id: seqBlock.symbols().symbolList())
|
842
|
VisitSub(id, seqBlock);
|
843
|
if (seqBlock.filter() != null)
|
844
|
VisitSub(seqBlock.filter(), seqBlock);
|
845
|
for (final Statement stmnt: seqBlock.statements())
|
846
|
VisitSub(stmnt, seqBlock);
|
847
|
|
848
|
|
849
|
final T symTab = m_copier.createSymbolTable();
|
850
|
for (final Identifier id: seqBlock.symbols().symbolList())
|
851
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(id));
|
852
|
|
853
|
final T stmtList = m_copier.createStatementList();
|
854
|
for (final Statement stmnt: seqBlock.statements())
|
855
|
m_copier.addStatementToList(stmtList, m_convertedStatements.get(stmnt));
|
856
|
|
857
|
m_copier.initSeqBlock(
|
858
|
stmt,
|
859
|
seqBlock.line(),
|
860
|
seqBlock.pos(),
|
861
|
symTab,
|
862
|
stmtList,
|
863
|
m_convertedScopes.get(seqBlock.GetParentScope()),
|
864
|
m_convertedExpressions.get(seqBlock.filter()));
|
865
|
}
|
866
|
|
867
|
@Override
|
868
|
public void visit(PrioBlock prioBlock)
|
869
|
{
|
870
|
final T stmt = createStatement(prioBlock);
|
871
|
|
872
|
|
873
|
VisitSub(prioBlock.GetParentScope(), prioBlock);
|
874
|
for (final Identifier id: prioBlock.symbols().symbolList())
|
875
|
VisitSub(id, prioBlock);
|
876
|
for (final Statement stmnt: prioBlock.statements())
|
877
|
VisitSub(stmnt, prioBlock);
|
878
|
|
879
|
|
880
|
final T symTab = m_copier.createSymbolTable();
|
881
|
for (final Identifier id: prioBlock.symbols().symbolList())
|
882
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(id));
|
883
|
|
884
|
final T stmtList = m_copier.createStatementList();
|
885
|
for (final Statement stmnt: prioBlock.statements())
|
886
|
m_copier.addStatementToList(stmtList, m_convertedStatements.get(stmnt));
|
887
|
|
888
|
m_copier.initPrioBlock(
|
889
|
stmt,
|
890
|
prioBlock.line(),
|
891
|
prioBlock.pos(),
|
892
|
symTab,
|
893
|
stmtList,
|
894
|
m_convertedScopes.get(prioBlock.GetParentScope()));
|
895
|
}
|
896
|
|
897
|
@Override
|
898
|
public void visit(GuardedCommand guardedCommand)
|
899
|
{
|
900
|
final T stmt = createStatement(guardedCommand);
|
901
|
|
902
|
|
903
|
VisitSub(guardedCommand.GetParentScope(), guardedCommand);
|
904
|
VisitSub(guardedCommand.guard(), guardedCommand);
|
905
|
VisitSub(guardedCommand.body(), guardedCommand);
|
906
|
|
907
|
m_copier.initGuardedCommand(
|
908
|
stmt,
|
909
|
guardedCommand.line(),
|
910
|
guardedCommand.pos(),
|
911
|
m_convertedScopes.get(guardedCommand.GetParentScope()),
|
912
|
m_convertedExpressions.get(guardedCommand.guard()),
|
913
|
m_convertedStatements.get(guardedCommand.body()));
|
914
|
}
|
915
|
|
916
|
@Override
|
917
|
public void visit(Assignment assignment)
|
918
|
{
|
919
|
final T stmt = createStatement(assignment);
|
920
|
|
921
|
|
922
|
VisitSub(assignment.GetParentScope(), assignment);
|
923
|
for (final Identifier id: assignment.symbols().symbolList())
|
924
|
VisitSub(id, assignment);
|
925
|
for (final Expression vexp: assignment.places())
|
926
|
VisitSub(vexp, assignment);
|
927
|
for (final Expression expr: assignment.values())
|
928
|
VisitSub(expr, assignment);
|
929
|
VisitSub(assignment.nondetExpression(), assignment);
|
930
|
|
931
|
|
932
|
final T symTab = m_copier.createSymbolTable();
|
933
|
for (final Identifier id: assignment.symbols().symbolList())
|
934
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(id));
|
935
|
final T places = m_copier.createExpressionList();
|
936
|
for (final Expression vexp: assignment.places())
|
937
|
m_copier.addExpressionToList(places,m_convertedExpressions.get(vexp));
|
938
|
final T values = m_copier.createExpressionList();
|
939
|
for (final Expression expr: assignment.values())
|
940
|
m_copier.addExpressionToList(values,m_convertedExpressions.get(expr));
|
941
|
|
942
|
m_copier.initAssignment(
|
943
|
stmt,
|
944
|
assignment.line(),
|
945
|
assignment.pos(),
|
946
|
m_convertedScopes.get(assignment.GetParentScope()),
|
947
|
m_convertedExpressions.get(assignment.nondetExpression()),
|
948
|
places,
|
949
|
values,
|
950
|
symTab);
|
951
|
}
|
952
|
|
953
|
@Override
|
954
|
public void visit(Call call)
|
955
|
{
|
956
|
final T stmt = createStatement(call);
|
957
|
|
958
|
|
959
|
VisitSub(call.callExpression(), call);
|
960
|
|
961
|
m_copier.initCall(
|
962
|
stmt,
|
963
|
call.line(),
|
964
|
call.pos(),
|
965
|
m_convertedExpressions.get(call.callExpression()));
|
966
|
}
|
967
|
|
968
|
|
969
|
|
970
|
|
971
|
|
972
|
private final class ExprData {
|
973
|
public final T typeRef;
|
974
|
public final T callTargetsIdentifierListRef;
|
975
|
public final T symbTabRef;
|
976
|
public final int line;
|
977
|
public final int pos;
|
978
|
|
979
|
public ExprData(T type, T callTgts, T symbTabRef, int line, int pos) {
|
980
|
typeRef = type;
|
981
|
callTargetsIdentifierListRef = callTgts;
|
982
|
this.symbTabRef = symbTabRef;
|
983
|
this.line = line;
|
984
|
this.pos = pos;
|
985
|
}
|
986
|
}
|
987
|
|
988
|
private ExprData visitBasicExpression(Expression e) {
|
989
|
final T list = m_copier.createIdentifierList();
|
990
|
final T symTab = m_copier.createSymbolTable();
|
991
|
|
992
|
VisitSub(e.type(), e);
|
993
|
for (final FunctionIdentifier i: e.callTargets())
|
994
|
VisitSub(i, e);
|
995
|
if (e.freeVariables() != null) {
|
996
|
for (final Identifier id: e.freeVariables().symbolList())
|
997
|
VisitSub(id, e);
|
998
|
for (final Identifier id: e.freeVariables().symbolList())
|
999
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(id));
|
1000
|
}
|
1001
|
|
1002
|
for (final FunctionIdentifier i: e.callTargets())
|
1003
|
m_copier.addIdentifierToList(list, m_convertedIdentifiers.get(i));
|
1004
|
|
1005
|
return new ExprData(m_convertedTypes.get(e.type()), list, symTab,
|
1006
|
e.line(), e.pos());
|
1007
|
}
|
1008
|
|
1009
|
@Override
|
1010
|
public void visit(TypeExpression typeExpression)
|
1011
|
{
|
1012
|
final T expr = createExpression(typeExpression);
|
1013
|
final ExprData d = visitBasicExpression(typeExpression);
|
1014
|
m_copier.initTypeExpression(
|
1015
|
expr,
|
1016
|
d.line,
|
1017
|
d.pos,
|
1018
|
d.typeRef,
|
1019
|
d.callTargetsIdentifierListRef,
|
1020
|
d.symbTabRef);
|
1021
|
}
|
1022
|
|
1023
|
@Override
|
1024
|
public void visit(IdentifierExpression identifierExpression)
|
1025
|
{
|
1026
|
final T expr = createExpression(identifierExpression);
|
1027
|
|
1028
|
final ExprData d = visitBasicExpression(identifierExpression);
|
1029
|
VisitSub(identifierExpression.identifier(), identifierExpression);
|
1030
|
|
1031
|
m_copier.initIdentifierExpression(
|
1032
|
expr,
|
1033
|
d.line,
|
1034
|
d.pos,
|
1035
|
d.typeRef,
|
1036
|
d.callTargetsIdentifierListRef,
|
1037
|
d.symbTabRef,
|
1038
|
m_convertedIdentifiers.get(identifierExpression.identifier()),
|
1039
|
identifierExpression.isSelf());
|
1040
|
}
|
1041
|
|
1042
|
@Override
|
1043
|
public void visit(UnaryOperator unaryOperator)
|
1044
|
{
|
1045
|
final T expr = createExpression(unaryOperator);
|
1046
|
|
1047
|
final ExprData d = visitBasicExpression(unaryOperator);
|
1048
|
VisitSub(unaryOperator.child(), unaryOperator);
|
1049
|
|
1050
|
m_copier.initUnaryExpression(
|
1051
|
expr,
|
1052
|
d.line,
|
1053
|
d.pos,
|
1054
|
d.typeRef,
|
1055
|
d.callTargetsIdentifierListRef,
|
1056
|
d.symbTabRef,
|
1057
|
m_convertedExpressions.get(unaryOperator.child()));
|
1058
|
}
|
1059
|
|
1060
|
@Override
|
1061
|
public void visit(BinaryOperator binaryOperator)
|
1062
|
{
|
1063
|
final T expr = createExpression(binaryOperator);
|
1064
|
|
1065
|
final ExprData d = visitBasicExpression(binaryOperator);
|
1066
|
VisitSub(binaryOperator.left(), binaryOperator);
|
1067
|
VisitSub(binaryOperator.right(), binaryOperator);
|
1068
|
|
1069
|
m_copier.initBinaryExpression(
|
1070
|
expr,
|
1071
|
d.line,
|
1072
|
d.pos,
|
1073
|
d.typeRef,
|
1074
|
d.callTargetsIdentifierListRef,
|
1075
|
d.symbTabRef,
|
1076
|
m_convertedExpressions.get(binaryOperator.left()),
|
1077
|
m_convertedExpressions.get(binaryOperator.right()));
|
1078
|
}
|
1079
|
|
1080
|
@Override
|
1081
|
public void visit(TernaryOperator ternaryOperator)
|
1082
|
{
|
1083
|
final T expr = createExpression(ternaryOperator);
|
1084
|
|
1085
|
final ExprData d = visitBasicExpression(ternaryOperator);
|
1086
|
VisitSub(ternaryOperator.left(), ternaryOperator);
|
1087
|
VisitSub(ternaryOperator.mid(), ternaryOperator);
|
1088
|
VisitSub(ternaryOperator.right(), ternaryOperator);
|
1089
|
VisitSub(ternaryOperator.definingScope(), ternaryOperator);
|
1090
|
|
1091
|
m_copier.initTernaryExpression(
|
1092
|
expr,
|
1093
|
d.line,
|
1094
|
d.pos,
|
1095
|
d.typeRef,
|
1096
|
d.callTargetsIdentifierListRef,
|
1097
|
d.symbTabRef,
|
1098
|
m_convertedExpressions.get(ternaryOperator.left()),
|
1099
|
m_convertedExpressions.get(ternaryOperator.mid()),
|
1100
|
m_convertedExpressions.get(ternaryOperator.right()),
|
1101
|
m_convertedScopes.get(ternaryOperator.definingScope()));
|
1102
|
}
|
1103
|
|
1104
|
|
1105
|
|
1106
|
@Override
|
1107
|
public <U>void visit(ValueExpression<U> valueExpression)
|
1108
|
{
|
1109
|
final T expr = createExpression(valueExpression);
|
1110
|
|
1111
|
final ExprData d = visitBasicExpression(valueExpression);
|
1112
|
switch (valueExpression.valueType()) {
|
1113
|
case integer:
|
1114
|
@SuppressWarnings("unchecked")
|
1115
|
final int value = ((ValueExpression<Integer>) valueExpression).value();
|
1116
|
m_copier.initIntValueExpression(
|
1117
|
expr,
|
1118
|
d.line,
|
1119
|
d.pos,
|
1120
|
d.typeRef,
|
1121
|
d.callTargetsIdentifierListRef,
|
1122
|
d.symbTabRef,
|
1123
|
value);
|
1124
|
break;
|
1125
|
case bool:
|
1126
|
@SuppressWarnings("unchecked")
|
1127
|
final boolean bvalue = ((ValueExpression<Boolean>) valueExpression).value();
|
1128
|
m_copier.initBoolValueExpression(
|
1129
|
expr,
|
1130
|
d.line,
|
1131
|
d.pos,
|
1132
|
d.typeRef,
|
1133
|
d.callTargetsIdentifierListRef,
|
1134
|
d.symbTabRef,
|
1135
|
bvalue);
|
1136
|
break;
|
1137
|
case reference:
|
1138
|
@SuppressWarnings("unchecked")
|
1139
|
final Object ovalue = ((ValueExpression<Object>) valueExpression).value();
|
1140
|
if (ovalue != null)
|
1141
|
throw new NotImplementedException();
|
1142
|
m_copier.initNullValueExpression(
|
1143
|
expr,
|
1144
|
d.line,
|
1145
|
d.pos,
|
1146
|
d.typeRef,
|
1147
|
d.callTargetsIdentifierListRef,
|
1148
|
d.symbTabRef);
|
1149
|
break;
|
1150
|
|
1151
|
case qval:
|
1152
|
case real:
|
1153
|
case chr:
|
1154
|
throw new NotImplementedException();
|
1155
|
|
1156
|
case identifier:
|
1157
|
case complex:
|
1158
|
case type:
|
1159
|
case unset:
|
1160
|
default:
|
1161
|
throw new IllegalArgumentException();
|
1162
|
}
|
1163
|
}
|
1164
|
|
1165
|
|
1166
|
@Override
|
1167
|
public void visit(ListConstructor listConstructor)
|
1168
|
{
|
1169
|
final T expr = createExpression(listConstructor);
|
1170
|
|
1171
|
final ExprData d = visitBasicExpression(listConstructor);
|
1172
|
for (final Identifier lvar: listConstructor.comprehensionVariables().symbolList())
|
1173
|
VisitSub(lvar, listConstructor);
|
1174
|
for (final Expression elems: listConstructor.elements())
|
1175
|
VisitSub(elems, listConstructor);
|
1176
|
VisitSub(listConstructor.comprehension(), listConstructor);
|
1177
|
VisitSub(listConstructor.GetParentScope(), listConstructor);
|
1178
|
|
1179
|
final T symTab = m_copier.createSymbolTable();
|
1180
|
for (final Identifier lvar: listConstructor.comprehensionVariables().symbolList())
|
1181
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(lvar));
|
1182
|
final T exprList = m_copier.createExpressionList();
|
1183
|
for (final Expression elems: listConstructor.elements())
|
1184
|
m_copier.addExpressionToList(exprList, m_convertedExpressions.get(elems));
|
1185
|
|
1186
|
m_copier.initListConstructor(
|
1187
|
expr,
|
1188
|
d.line,
|
1189
|
d.pos,
|
1190
|
d.typeRef,
|
1191
|
d.callTargetsIdentifierListRef,
|
1192
|
d.symbTabRef,
|
1193
|
exprList,
|
1194
|
symTab,
|
1195
|
m_convertedScopes.get(listConstructor.GetParentScope()),
|
1196
|
m_convertedExpressions.get(listConstructor.comprehension()),
|
1197
|
listConstructor.hasComprehension());
|
1198
|
}
|
1199
|
|
1200
|
@Override
|
1201
|
public void visit(SetConstructor setConstructor)
|
1202
|
{
|
1203
|
final T expr = createExpression(setConstructor);
|
1204
|
|
1205
|
final ExprData d = visitBasicExpression(setConstructor);
|
1206
|
for (final Identifier svar: setConstructor.comprehensionVariables().symbolList())
|
1207
|
VisitSub(svar, setConstructor);
|
1208
|
for (final Expression elems: setConstructor.items())
|
1209
|
VisitSub(elems, setConstructor);
|
1210
|
VisitSub(setConstructor.comprehension(), setConstructor);
|
1211
|
VisitSub(setConstructor.GetParentScope(), setConstructor);
|
1212
|
|
1213
|
|
1214
|
final T symTab = m_copier.createSymbolTable();
|
1215
|
for (final Identifier lvar: setConstructor.comprehensionVariables().symbolList())
|
1216
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(lvar));
|
1217
|
final T exprList = m_copier.createExpressionList();
|
1218
|
for (final Expression elems: setConstructor.items())
|
1219
|
m_copier.addExpressionToList(exprList, m_convertedExpressions.get(elems));
|
1220
|
|
1221
|
m_copier.initSetConstructor(
|
1222
|
expr,
|
1223
|
d.line,
|
1224
|
d.pos,
|
1225
|
d.typeRef,
|
1226
|
d.callTargetsIdentifierListRef,
|
1227
|
d.symbTabRef,
|
1228
|
exprList,
|
1229
|
symTab,
|
1230
|
m_convertedScopes.get(setConstructor.GetParentScope()),
|
1231
|
m_convertedExpressions.get(setConstructor.comprehension()),
|
1232
|
setConstructor.hasComprehension());
|
1233
|
}
|
1234
|
|
1235
|
@Override
|
1236
|
public void visit(TupleConstructor tupleConstructor)
|
1237
|
{
|
1238
|
final T expr = createExpression(tupleConstructor);
|
1239
|
|
1240
|
final ExprData d = visitBasicExpression(tupleConstructor);
|
1241
|
for (final Expression elem: tupleConstructor.values())
|
1242
|
VisitSub(elem, tupleConstructor);
|
1243
|
VisitSub(tupleConstructor.tupleType(), tupleConstructor);
|
1244
|
|
1245
|
|
1246
|
final T exprList = m_copier.createExpressionList();
|
1247
|
for (final Expression elems: tupleConstructor.values())
|
1248
|
m_copier.addExpressionToList(exprList, m_convertedExpressions.get(elems));
|
1249
|
|
1250
|
m_copier.initTupleConstructor(
|
1251
|
expr,
|
1252
|
d.line,
|
1253
|
d.pos,
|
1254
|
d.typeRef,
|
1255
|
d.callTargetsIdentifierListRef,
|
1256
|
d.symbTabRef,
|
1257
|
exprList,
|
1258
|
m_convertedIdentifiers.get(tupleConstructor.tupleType()),
|
1259
|
tupleConstructor.isMatcher());
|
1260
|
}
|
1261
|
|
1262
|
@Override
|
1263
|
public void visit(AccessExpression accessExpression)
|
1264
|
{
|
1265
|
final T expr = createExpression(accessExpression);
|
1266
|
|
1267
|
final ExprData d = visitBasicExpression(accessExpression);
|
1268
|
VisitSub(accessExpression.left(), accessExpression);
|
1269
|
VisitSub(accessExpression.right(), accessExpression);
|
1270
|
|
1271
|
m_copier.initAccessExpression(
|
1272
|
expr,
|
1273
|
d.line,
|
1274
|
d.pos,
|
1275
|
d.typeRef,
|
1276
|
d.callTargetsIdentifierListRef,
|
1277
|
d.symbTabRef,
|
1278
|
m_convertedExpressions.get(accessExpression.left()),
|
1279
|
m_convertedExpressions.get(accessExpression.right()));
|
1280
|
}
|
1281
|
|
1282
|
@Override
|
1283
|
public void visit(TupleMapAccessExpression tupleMapAccessExpression)
|
1284
|
{
|
1285
|
final T expr = createExpression(tupleMapAccessExpression);
|
1286
|
|
1287
|
final ExprData d = visitBasicExpression(tupleMapAccessExpression);
|
1288
|
VisitSub(tupleMapAccessExpression.argument(), tupleMapAccessExpression);
|
1289
|
VisitSub(tupleMapAccessExpression.child(), tupleMapAccessExpression);
|
1290
|
|
1291
|
m_copier.initTupleMapAccessExpression(
|
1292
|
expr,
|
1293
|
d.line,
|
1294
|
d.pos,
|
1295
|
d.typeRef,
|
1296
|
d.callTargetsIdentifierListRef,
|
1297
|
d.symbTabRef,
|
1298
|
m_convertedExpressions.get(tupleMapAccessExpression.child()),
|
1299
|
m_convertedExpressions.get(tupleMapAccessExpression.argument()));
|
1300
|
}
|
1301
|
|
1302
|
@Override
|
1303
|
public void visit(CallExpression callExpression)
|
1304
|
{
|
1305
|
final T expr = createExpression(callExpression);
|
1306
|
|
1307
|
final ExprData d = visitBasicExpression(callExpression);
|
1308
|
VisitSub(callExpression.child(), callExpression);
|
1309
|
VisitSub(callExpression.scope(), callExpression);
|
1310
|
|
1311
|
final T exprList = m_copier.createExpressionList();
|
1312
|
if (callExpression.arguments() != null) {
|
1313
|
for (final Expression arg: callExpression.arguments())
|
1314
|
VisitSub(arg, callExpression);
|
1315
|
for (final Expression elems: callExpression.arguments())
|
1316
|
m_copier.addExpressionToList(exprList, m_convertedExpressions.get(elems));
|
1317
|
}
|
1318
|
|
1319
|
m_copier.initCallExpression(
|
1320
|
expr,
|
1321
|
d.line,
|
1322
|
d.pos,
|
1323
|
d.typeRef,
|
1324
|
d.callTargetsIdentifierListRef,
|
1325
|
d.symbTabRef,
|
1326
|
m_convertedExpressions.get(callExpression.child()),
|
1327
|
exprList,
|
1328
|
m_convertedScopes.get(callExpression.scope()));
|
1329
|
}
|
1330
|
|
1331
|
private void visitQuantifierExpression(Quantifier quantifier)
|
1332
|
{
|
1333
|
final T expr = createExpression(quantifier);
|
1334
|
|
1335
|
final ExprData d = visitBasicExpression(quantifier);
|
1336
|
for (final Identifier lvar: quantifier.symbols().symbolList())
|
1337
|
VisitSub(lvar, quantifier);
|
1338
|
VisitSub(quantifier.child(), quantifier);
|
1339
|
VisitSub(quantifier.GetParentScope(), quantifier);
|
1340
|
|
1341
|
final T symTab = m_copier.createSymbolTable();
|
1342
|
for (final Identifier lvar: quantifier.symbols().symbolList())
|
1343
|
m_copier.addIdentifierToSymbolTable(symTab, m_convertedIdentifiers.get(lvar));
|
1344
|
|
1345
|
m_copier.initQuantifierExpression(
|
1346
|
expr,
|
1347
|
d.line,
|
1348
|
d.pos,
|
1349
|
d.typeRef,
|
1350
|
d.callTargetsIdentifierListRef,
|
1351
|
d.symbTabRef,
|
1352
|
m_convertedExpressions.get(quantifier.child()),
|
1353
|
symTab,
|
1354
|
m_convertedScopes.get(quantifier.GetParentScope()));
|
1355
|
}
|
1356
|
|
1357
|
@Override
|
1358
|
public void visit(ForallQuantifier quantifier)
|
1359
|
{
|
1360
|
visitQuantifierExpression(quantifier);
|
1361
|
}
|
1362
|
|
1363
|
@Override
|
1364
|
public void visit(ExistsQuantifier quantifier)
|
1365
|
{
|
1366
|
visitQuantifierExpression(quantifier);
|
1367
|
}
|
1368
|
|
1369
|
@Override
|
1370
|
public void visit(ObjectConstructor objectConstructor)
|
1371
|
{
|
1372
|
final T expr = createExpression(objectConstructor);
|
1373
|
|
1374
|
final ExprData d = visitBasicExpression(objectConstructor);
|
1375
|
for (final OoActionSystemInstance i: objectConstructor.instances())
|
1376
|
convertActionSystemInstance(i, objectConstructor);
|
1377
|
|
1378
|
final T instanceList = m_copier.createActionSystemInstanceList();
|
1379
|
for (final OoActionSystemInstance i: objectConstructor.instances())
|
1380
|
m_copier.addActionSystemInstanceToList(instanceList, m_convertedInstances.get(i));
|
1381
|
|
1382
|
m_copier.initObjectConstructor(
|
1383
|
expr,
|
1384
|
d.line,
|
1385
|
d.pos,
|
1386
|
d.typeRef,
|
1387
|
d.callTargetsIdentifierListRef,
|
1388
|
d.symbTabRef,
|
1389
|
instanceList,
|
1390
|
objectConstructor.currentInstance(),
|
1391
|
objectConstructor.givenObjectName());
|
1392
|
}
|
1393
|
|
1394
|
|
1395
|
|
1396
|
|
1397
|
|
1398
|
|
1399
|
@Override
|
1400
|
public void visit(KillStatement killStatement)
|
1401
|
{
|
1402
|
|
1403
|
throw new NotImplementedException();
|
1404
|
}
|
1405
|
@Override
|
1406
|
public void visit(OpaqueType opaqueType)
|
1407
|
{
|
1408
|
|
1409
|
throw new NotImplementedException();
|
1410
|
}
|
1411
|
|
1412
|
@Override
|
1413
|
public void visit(AnyType anyType)
|
1414
|
{
|
1415
|
|
1416
|
throw new NotImplementedException();
|
1417
|
}
|
1418
|
|
1419
|
@Override
|
1420
|
public void visit(UnresolvedIdentifierExpression unresolvedIdentifierExpression)
|
1421
|
{
|
1422
|
|
1423
|
throw new NotImplementedException();
|
1424
|
}
|
1425
|
@Override
|
1426
|
public void visit(MapConstructor mapConstructor)
|
1427
|
{
|
1428
|
|
1429
|
throw new NotImplementedException();
|
1430
|
}
|
1431
|
|
1432
|
@Override
|
1433
|
public void visit(CharType charType)
|
1434
|
{
|
1435
|
|
1436
|
throw new NotImplementedException();
|
1437
|
}
|
1438
|
|
1439
|
@Override
|
1440
|
public void visit(FloatType floatType)
|
1441
|
{
|
1442
|
|
1443
|
throw new NotImplementedException();
|
1444
|
}
|
1445
|
|
1446
|
@Override
|
1447
|
public void visit(MapType mapType)
|
1448
|
{
|
1449
|
|
1450
|
throw new NotImplementedException();
|
1451
|
}
|
1452
|
|
1453
|
@Override
|
1454
|
public void visit(QrType qrType)
|
1455
|
{
|
1456
|
|
1457
|
throw new NotImplementedException();
|
1458
|
}
|
1459
|
|
1460
|
@Override
|
1461
|
public void visit(QValConstructor qValConstructor)
|
1462
|
{
|
1463
|
|
1464
|
throw new NotImplementedException();
|
1465
|
}
|
1466
|
|
1467
|
@Override
|
1468
|
public void visit(QualitativeConstraintStatement qalitativeConstraintStatement)
|
1469
|
{
|
1470
|
|
1471
|
throw new NotImplementedException();
|
1472
|
}
|
1473
|
|
1474
|
@Override
|
1475
|
public void visit(LandmarkIdentifier landmarkIdentifier)
|
1476
|
{
|
1477
|
|
1478
|
throw new NotImplementedException();
|
1479
|
}
|
1480
|
}
|