Revision 9
Added by Willibald K. over 8 years ago
OoaDeepCloneVisitor.java | ||
---|---|---|
28 | 28 |
package org.momut.ooas.visitors; |
29 | 29 |
|
30 | 30 |
import java.util.ArrayList; |
31 |
import java.util.Arrays; |
|
32 | 31 |
import java.util.HashMap; |
33 | 32 |
import java.util.List; |
34 | 33 |
import java.util.ListIterator; |
... | ... | |
44 | 43 |
import org.momut.ooas.ast.expressions.ListConstructor; |
45 | 44 |
import org.momut.ooas.ast.expressions.MapConstructor; |
46 | 45 |
import org.momut.ooas.ast.expressions.ObjectConstructor; |
47 |
import org.momut.ooas.ast.expressions.QValConstructor; |
|
48 | 46 |
import org.momut.ooas.ast.expressions.Quantifier; |
49 | 47 |
import org.momut.ooas.ast.expressions.SetConstructor; |
50 | 48 |
import org.momut.ooas.ast.expressions.TernaryOperator; |
... | ... | |
59 | 57 |
import org.momut.ooas.ast.identifiers.ExpressionVariableIdentifier; |
60 | 58 |
import org.momut.ooas.ast.identifiers.Identifier; |
61 | 59 |
import org.momut.ooas.ast.identifiers.IdentifierKind; |
62 |
import org.momut.ooas.ast.identifiers.LandmarkIdentifier; |
|
63 | 60 |
import org.momut.ooas.ast.identifiers.LocalVariableIdentifier; |
64 | 61 |
import org.momut.ooas.ast.identifiers.MainModule; |
65 | 62 |
import org.momut.ooas.ast.identifiers.MethodIdentifier; |
... | ... | |
79 | 76 |
import org.momut.ooas.ast.statements.KillStatement; |
80 | 77 |
import org.momut.ooas.ast.statements.NondetBlock; |
81 | 78 |
import org.momut.ooas.ast.statements.PrioBlock; |
82 |
import org.momut.ooas.ast.statements.QualitativeConstraintStatement; |
|
83 | 79 |
import org.momut.ooas.ast.statements.SeqBlock; |
84 | 80 |
import org.momut.ooas.ast.statements.SkipStatement; |
85 | 81 |
import org.momut.ooas.ast.statements.Statement; |
... | ... | |
95 | 91 |
import org.momut.ooas.ast.types.NullType; |
96 | 92 |
import org.momut.ooas.ast.types.OoActionSystemType; |
97 | 93 |
import org.momut.ooas.ast.types.OpaqueType; |
98 |
import org.momut.ooas.ast.types.QrType; |
|
99 | 94 |
import org.momut.ooas.ast.types.TupleType; |
100 | 95 |
import org.momut.ooas.parser.SymbolTable; |
101 | 96 |
import org.momut.ooas.utils.OoasCompilerHashMap; |
... | ... | |
113 | 108 |
|
114 | 109 |
/* we do not clone types */ |
115 | 110 |
@Override |
116 |
public /*override*/ void visit(AnyType anyType)
|
|
111 |
public void visit(AnyType anyType) |
|
117 | 112 |
{ throw new NotImplementedException(); } |
118 | 113 |
@Override |
119 |
public /*override*/ void visit(BoolType boolType)
|
|
114 |
public void visit(BoolType boolType) |
|
120 | 115 |
{ throw new NotImplementedException(); } |
121 | 116 |
@Override |
122 |
public /*override*/ void visit(CharType charType)
|
|
117 |
public void visit(CharType charType) |
|
123 | 118 |
{ throw new NotImplementedException(); } |
124 | 119 |
@Override |
125 |
public /*override*/ void visit(EnumType enumType)
|
|
120 |
public void visit(EnumType enumType) |
|
126 | 121 |
{ throw new NotImplementedException(); } |
127 | 122 |
@Override |
128 |
public /*override*/ void visit(FloatType floatType)
|
|
123 |
public void visit(FloatType floatType) |
|
129 | 124 |
{ throw new NotImplementedException(); } |
130 | 125 |
@Override |
131 |
public /*override*/ void visit(FunctionType functionType)
|
|
126 |
public void visit(FunctionType functionType) |
|
132 | 127 |
{ throw new NotImplementedException(); } |
133 | 128 |
@Override |
134 |
public /*override*/ void visit(IntType intType)
|
|
129 |
public void visit(IntType intType) |
|
135 | 130 |
{ throw new NotImplementedException(); } |
136 | 131 |
@Override |
137 |
public /*override*/ void visit(ListType listType)
|
|
132 |
public void visit(ListType listType) |
|
138 | 133 |
{ throw new NotImplementedException(); } |
139 | 134 |
@Override |
140 |
public /*override*/ void visit(MapType mapType)
|
|
135 |
public void visit(MapType mapType) |
|
141 | 136 |
{ throw new NotImplementedException(); } |
142 | 137 |
@Override |
143 |
public /*override*/ void visit(NullType nullType)
|
|
138 |
public void visit(NullType nullType) |
|
144 | 139 |
{ throw new NotImplementedException(); } |
145 | 140 |
@Override |
146 |
public /*override*/ void visit(OoActionSystemType ooActionSystemType)
|
|
141 |
public void visit(OoActionSystemType ooActionSystemType) |
|
147 | 142 |
{ throw new NotImplementedException(); } |
148 | 143 |
@Override |
149 |
public /*override*/ void visit(TupleType tupleType)
|
|
144 |
public void visit(TupleType tupleType) |
|
150 | 145 |
{ throw new NotImplementedException(); } |
151 | 146 |
@Override |
152 |
public /*override*/ void visit(EnumIdentifier enumIdentifier)
|
|
147 |
public void visit(EnumIdentifier enumIdentifier) |
|
153 | 148 |
{ throw new NotImplementedException(); } |
154 | 149 |
@Override |
155 |
public /*override*/ void visit(LandmarkIdentifier landmarkIdentifier)
|
|
150 |
public void visit(ExpressionVariableIdentifier expressionVariableIdentifier)
|
|
156 | 151 |
{ throw new NotImplementedException(); } |
157 |
@Override |
|
158 |
public /*override*/ void visit(ExpressionVariableIdentifier expressionVariableIdentifier) |
|
159 |
{ throw new NotImplementedException(); } |
|
160 | 152 |
|
161 | 153 |
|
162 | 154 |
@Override |
163 |
public /*override*/ void visit(LocalVariableIdentifier localVariableIdentifier)
|
|
155 |
public void visit(LocalVariableIdentifier localVariableIdentifier) |
|
164 | 156 |
{ |
165 | 157 |
throw new NotImplementedException(); |
166 | 158 |
} |
167 | 159 |
|
168 | 160 |
@Override |
169 |
public /*override*/ void visit(MainModule mainModule)
|
|
161 |
public void visit(MainModule mainModule) |
|
170 | 162 |
{ |
171 | 163 |
throw new NotImplementedException(); |
172 | 164 |
} |
173 | 165 |
|
174 | 166 |
|
175 | 167 |
@Override |
176 |
public /*override*/ void visit(MapConstructor mapConstructor)
|
|
168 |
public void visit(MapConstructor mapConstructor) |
|
177 | 169 |
{ |
178 | 170 |
throw new NotImplementedException(); |
179 | 171 |
} |
180 | 172 |
|
181 | 173 |
@Override |
182 |
public /*override*/ void visit(MethodIdentifier methodIdentifier)
|
|
174 |
public void visit(MethodIdentifier methodIdentifier) |
|
183 | 175 |
{ |
184 | 176 |
throw new NotImplementedException(); |
185 | 177 |
} |
186 | 178 |
|
187 | 179 |
@Override |
188 |
public /*override*/ void visit(NamedActionIdentifier namedActionIdentifier)
|
|
180 |
public void visit(NamedActionIdentifier namedActionIdentifier) |
|
189 | 181 |
{ |
190 | 182 |
final Statement newBlock = SClone(namedActionIdentifier.body()); |
191 | 183 |
namedActionIdentifier.SetBody(newBlock); |
... | ... | |
193 | 185 |
} |
194 | 186 |
|
195 | 187 |
@Override |
196 |
public /*override*/ void visit(Module module)
|
|
188 |
public void visit(Module module) |
|
197 | 189 |
{ |
198 | 190 |
throw new NotImplementedException(); |
199 | 191 |
} |
200 | 192 |
|
201 | 193 |
@Override |
202 |
public /*override*/ void visit(NondetIdentifierList nondetIdentifierList)
|
|
194 |
public void visit(NondetIdentifierList nondetIdentifierList) |
|
203 | 195 |
{ |
204 | 196 |
throw new NotImplementedException(); |
205 | 197 |
} |
206 | 198 |
|
207 | 199 |
|
208 | 200 |
@Override |
209 |
public /*override*/ void visit(OpaqueType opaqueType)
|
|
201 |
public void visit(OpaqueType opaqueType) |
|
210 | 202 |
{ |
211 | 203 |
throw new NotImplementedException(); // must not happen |
212 | 204 |
} |
213 | 205 |
|
214 | 206 |
@Override |
215 |
public /*override*/ void visit(ParameterIdentifier parameterIdentifier)
|
|
207 |
public void visit(ParameterIdentifier parameterIdentifier) |
|
216 | 208 |
{ |
217 | 209 |
throw new NotImplementedException(); |
218 | 210 |
} |
219 | 211 |
|
220 | 212 |
@Override |
221 |
public /*override*/ void visit(PrioIdentifierList prioIdentifierList)
|
|
213 |
public void visit(PrioIdentifierList prioIdentifierList) |
|
222 | 214 |
{ |
223 | 215 |
throw new NotImplementedException(); |
224 | 216 |
} |
225 | 217 |
|
226 | 218 |
@Override |
227 |
public /*override*/ void visit(QrType qrType)
|
|
219 |
public void visit(ObjectConstructor objectConstructor)
|
|
228 | 220 |
{ |
229 |
throw new NotImplementedException(); |
|
230 |
} |
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
@Override |
|
235 |
public /*override*/ void visit(ObjectConstructor objectConstructor) |
|
236 |
{ |
|
237 | 221 |
//base.visit(objectConstructor); |
238 | 222 |
} |
239 | 223 |
|
... | ... | |
325 | 309 |
|
326 | 310 |
/*no need to clone leafs (they are already cloned and a shallow copy is sufficient*/ |
327 | 311 |
@Override |
328 |
public /*override*/ void visit(AbortStatement abortStatement)
|
|
312 |
public void visit(AbortStatement abortStatement) |
|
329 | 313 |
{ } |
330 | 314 |
@Override |
331 |
public /*override*/ <T> void visit(ValueExpression<T> valueExpression)
|
|
315 |
public <T> void visit(ValueExpression<T> valueExpression) |
|
332 | 316 |
{ } |
333 | 317 |
|
334 | 318 |
|
... | ... | |
345 | 329 |
} |
346 | 330 |
} |
347 | 331 |
@Override |
348 |
public /*override*/ void visit(NondetBlock nondetBlock)
|
|
332 |
public void visit(NondetBlock nondetBlock) |
|
349 | 333 |
{ |
350 | 334 |
cloneBlock(nondetBlock); |
351 | 335 |
} |
352 | 336 |
@Override |
353 |
public /*override*/ void visit(SeqBlock seqBlock)
|
|
337 |
public void visit(SeqBlock seqBlock) |
|
354 | 338 |
{ |
355 | 339 |
seqBlock.SetFilter(EClone(seqBlock.filter())); |
356 | 340 |
cloneBlock(seqBlock); |
357 | 341 |
} |
358 | 342 |
@Override |
359 |
public /*override*/ void visit(PrioBlock prioBlock)
|
|
343 |
public void visit(PrioBlock prioBlock) |
|
360 | 344 |
{ |
361 | 345 |
cloneBlock(prioBlock); |
362 | 346 |
} |
363 | 347 |
|
364 | 348 |
@Override |
365 |
public /*override*/ void visit(AccessExpression accessExpression)
|
|
349 |
public void visit(AccessExpression accessExpression) |
|
366 | 350 |
{ |
367 | 351 |
visit((BinaryOperator)accessExpression); |
368 | 352 |
} |
369 | 353 |
@Override |
370 |
public /*override*/ void visit(BinaryOperator binaryOperator)
|
|
354 |
public void visit(BinaryOperator binaryOperator) |
|
371 | 355 |
{ |
372 | 356 |
final Expression left = EClone(binaryOperator.left()); |
373 | 357 |
final Expression right = EClone(binaryOperator.right()); |
... | ... | |
376 | 360 |
} |
377 | 361 |
|
378 | 362 |
@Override |
379 |
public /*override*/ void visit(Assignment assignment)
|
|
363 |
public void visit(Assignment assignment) |
|
380 | 364 |
{ |
381 | 365 |
SymTabClone(assignment.symbols()); |
382 | 366 |
cloneExpressionList(assignment.places().listIterator()); |
... | ... | |
386 | 370 |
} |
387 | 371 |
|
388 | 372 |
@Override |
389 |
public /*override*/ void visit(AttributeIdentifier attributeIdentifier)
|
|
373 |
public void visit(AttributeIdentifier attributeIdentifier) |
|
390 | 374 |
{ |
391 | 375 |
final Expression initializer = EClone(attributeIdentifier.initializer()); |
392 | 376 |
attributeIdentifier.SetInitializer(initializer); |
393 | 377 |
} |
394 | 378 |
@Override |
395 |
public /*override*/ void visit(Call call)
|
|
379 |
public void visit(Call call) |
|
396 | 380 |
{ |
397 | 381 |
final Expression cExpr = EClone(call.callExpression()); |
398 | 382 |
call.SetCallExpression(cExpr); |
399 | 383 |
} |
400 | 384 |
|
401 | 385 |
@Override |
402 |
public /*override*/ void visit(CallExpression callExpression)
|
|
386 |
public void visit(CallExpression callExpression) |
|
403 | 387 |
{ |
404 | 388 |
final ArrayList<Expression> newargs = new ArrayList<Expression>(); |
405 | 389 |
for (final Expression x: callExpression.arguments()) |
... | ... | |
420 | 404 |
quantifierState = oldQunatifierState; |
421 | 405 |
} |
422 | 406 |
@Override |
423 |
public /*override*/ void visit(ExistsQuantifier quantifier)
|
|
407 |
public void visit(ExistsQuantifier quantifier) |
|
424 | 408 |
{ |
425 | 409 |
CloneQuantifier(quantifier); |
426 | 410 |
} |
427 | 411 |
@Override |
428 |
public /*override*/ void visit(ForallQuantifier quantifier)
|
|
412 |
public void visit(ForallQuantifier quantifier) |
|
429 | 413 |
{ |
430 | 414 |
CloneQuantifier(quantifier); |
431 | 415 |
} |
... | ... | |
434 | 418 |
|
435 | 419 |
|
436 | 420 |
@Override |
437 |
public /*override*/ void visit(GuardedCommand guardedCommand)
|
|
421 |
public void visit(GuardedCommand guardedCommand) |
|
438 | 422 |
{ |
439 | 423 |
final Statement newblock = SClone(guardedCommand.body()); |
440 | 424 |
final Expression newguard = EClone(guardedCommand.guard()); |
... | ... | |
443 | 427 |
} |
444 | 428 |
|
445 | 429 |
@Override |
446 |
public /*override*/ void visit(IdentifierExpression identifierExpression)
|
|
430 |
public void visit(IdentifierExpression identifierExpression) |
|
447 | 431 |
{ |
448 | 432 |
|
449 | 433 |
if (identifierExpression.isSelf()) |
450 |
{ |
|
451 |
/*if (quantifierState) //FIXXME |
|
452 |
{ |
|
453 |
if (!selfreplacement.tokenText.StartsWith("attr")) |
|
454 |
{ |
|
455 |
String oldTokenText = selfreplacement.tokenText; |
|
456 |
selfreplacement.SetTokenText("attr____model_root_" + selfreplacement.tokenText); |
|
457 |
identifierExpression.SetIdentifier(selfreplacement); |
|
458 |
selfreplacement.SetTokenText(oldTokenText); |
|
459 |
} |
|
460 |
} |
|
461 |
else |
|
462 |
*/ |
|
463 | 434 |
identifierExpression.SetIdentifier(selfreplacement); |
464 |
|
|
465 |
|
|
466 |
} |
|
467 | 435 |
else if (mapping.containsKey(identifierExpression.identifier()) |
468 | 436 |
&& identifierExpression.identifier().kind() != IdentifierKind.MethodIdentifier) |
469 |
|
|
470 | 437 |
/* we do NOT replace method calls here, since they are prefixed by self if it's a |
471 | 438 |
* method in the current object or by some field/method access if it's another |
472 | 439 |
* object. |
473 | 440 |
*/ |
474 | 441 |
identifierExpression.SetIdentifier((Identifier)mapping.get(identifierExpression.identifier())); |
475 |
|
|
476 | 442 |
} |
477 | 443 |
|
478 | 444 |
@Override |
479 |
public /*override*/ void visit(KillStatement killStatement)
|
|
445 |
public void visit(KillStatement killStatement) |
|
480 | 446 |
{ |
481 | 447 |
if (mapping.containsKey(killStatement.someOne)) |
482 | 448 |
killStatement.SetIdentifier((Identifier)mapping.get(killStatement.someOne)); |
... | ... | |
484 | 450 |
|
485 | 451 |
|
486 | 452 |
@Override |
487 |
public /*override*/ void visit(ListConstructor listConstructor)
|
|
453 |
public void visit(ListConstructor listConstructor) |
|
488 | 454 |
{ |
489 | 455 |
SymTabClone(listConstructor.comprehensionVariables()); |
490 | 456 |
|
... | ... | |
497 | 463 |
} |
498 | 464 |
|
499 | 465 |
@Override |
500 |
public /*override*/ void visit(QualitativeConstraintStatement qalitativeConstraintStatement)
|
|
466 |
public void visit(SeqIdentifierList seqIdentifierList)
|
|
501 | 467 |
{ |
502 |
if (qalitativeConstraintStatement.variable0() != null && mapping.containsKey(qalitativeConstraintStatement.variable0())) |
|
503 |
qalitativeConstraintStatement.SetVariable0((Identifier)mapping.get(qalitativeConstraintStatement.variable0())); |
|
504 |
if (qalitativeConstraintStatement.variable1() != null && mapping.containsKey(qalitativeConstraintStatement.variable1())) |
|
505 |
qalitativeConstraintStatement.SetVariable1((Identifier)mapping.get(qalitativeConstraintStatement.variable1())); |
|
506 |
if (qalitativeConstraintStatement.variable2() != null && mapping.containsKey(qalitativeConstraintStatement.variable2())) |
|
507 |
qalitativeConstraintStatement.SetVariable2((Identifier)mapping.get(qalitativeConstraintStatement.variable2())); |
|
508 |
} |
|
509 |
|
|
510 |
|
|
511 |
@Override |
|
512 |
public /*override*/ void visit(QValConstructor qValConstructor) |
|
513 |
{ |
|
514 |
final List<Expression> values = Arrays.asList(qValConstructor.value()); |
|
515 |
for (int i = 0; i < values.size(); i++) |
|
516 |
qValConstructor.value()[i] = EClone(values.get(i)); |
|
517 |
} |
|
518 |
|
|
519 |
@Override |
|
520 |
public /*override*/ void visit(SeqIdentifierList seqIdentifierList) |
|
521 |
{ |
|
522 | 468 |
throw new NotImplementedException(); |
523 | 469 |
} |
524 | 470 |
|
525 | 471 |
|
526 | 472 |
@Override |
527 |
public /*override*/ void visit(SetConstructor setConstructor)
|
|
473 |
public void visit(SetConstructor setConstructor) |
|
528 | 474 |
{ |
529 | 475 |
SymTabClone(setConstructor.comprehensionVariables()); |
530 | 476 |
final ArrayList<Expression> newelems = new ArrayList<Expression>(); |
... | ... | |
537 | 483 |
|
538 | 484 |
|
539 | 485 |
@Override |
540 |
public /*override*/ void visit(SkipStatement skipStatement)
|
|
486 |
public void visit(SkipStatement skipStatement) |
|
541 | 487 |
{ } |
542 | 488 |
|
543 | 489 |
@Override |
544 |
public /*override*/ void visit(TernaryOperator ternaryOperator)
|
|
490 |
public void visit(TernaryOperator ternaryOperator) |
|
545 | 491 |
{ |
546 | 492 |
ternaryOperator.SetLeftChild(EClone(ternaryOperator.left())); |
547 | 493 |
ternaryOperator.SetMidChild(EClone(ternaryOperator.mid())); |
... | ... | |
549 | 495 |
} |
550 | 496 |
|
551 | 497 |
@Override |
552 |
public /*override*/ void visit(TupleConstructor tupleConstructor)
|
|
498 |
public void visit(TupleConstructor tupleConstructor) |
|
553 | 499 |
{ |
554 | 500 |
final ArrayList<Expression> values = new ArrayList<Expression>(); |
555 | 501 |
for (final Expression x: tupleConstructor.values()) |
... | ... | |
558 | 504 |
} |
559 | 505 |
|
560 | 506 |
@Override |
561 |
public /*override*/ void visit(TupleMapAccessExpression tupleMapAccessExpression)
|
|
507 |
public void visit(TupleMapAccessExpression tupleMapAccessExpression) |
|
562 | 508 |
{ |
563 | 509 |
tupleMapAccessExpression.SetArgument(EClone(tupleMapAccessExpression.argument())); |
564 | 510 |
visit((UnaryOperator)tupleMapAccessExpression); |
565 | 511 |
} |
566 | 512 |
|
567 | 513 |
@Override |
568 |
public /*override*/ void visit(TypeExpression typeExpression)
|
|
514 |
public void visit(TypeExpression typeExpression) |
|
569 | 515 |
{ /*we do not clone types*/ } |
570 | 516 |
|
571 | 517 |
|
572 | 518 |
@Override |
573 |
public /*override*/ void visit(TypeIdentifier typeIdentifier)
|
|
519 |
public void visit(TypeIdentifier typeIdentifier) |
|
574 | 520 |
{ |
575 | 521 |
throw new NotImplementedException(); |
576 | 522 |
} |
577 | 523 |
|
578 | 524 |
@Override |
579 |
public /*override*/ void visit(UnaryOperator unaryOperator)
|
|
525 |
public void visit(UnaryOperator unaryOperator) |
|
580 | 526 |
{ |
581 | 527 |
final Expression child = EClone(unaryOperator.child()); |
582 | 528 |
unaryOperator.SetChild(child); |
... | ... | |
584 | 530 |
|
585 | 531 |
|
586 | 532 |
@Override |
587 |
public /*override*/ void visit(UnresolvedIdentifierExpression unresolvedIdentifierExpression)
|
|
533 |
public void visit(UnresolvedIdentifierExpression unresolvedIdentifierExpression) |
|
588 | 534 |
{ |
589 | 535 |
throw new NotImplementedException(); // must not occur |
590 | 536 |
} |
591 | 537 |
|
592 | 538 |
@Override |
593 |
public /*override*/ void visit(UnspecIdentifierList unspecIdentifierList)
|
|
539 |
public void visit(UnspecIdentifierList unspecIdentifierList) |
|
594 | 540 |
{ |
595 | 541 |
throw new NotImplementedException(); |
596 | 542 |
} |
Also available in: Unified diff
remove support for Qualitative Action Systems, rename UlyssesType to Type