Revision 9
Added by Willibald K. over 8 years ago
OoaPrologExpression.java | ||
---|---|---|
40 | 40 |
import org.momut.ooas.ast.expressions.ListConstructor; |
41 | 41 |
import org.momut.ooas.ast.expressions.MapConstructor; |
42 | 42 |
import org.momut.ooas.ast.expressions.ObjectConstructor; |
43 |
import org.momut.ooas.ast.expressions.QValConstructor; |
|
44 | 43 |
import org.momut.ooas.ast.expressions.SetConstructor; |
45 | 44 |
import org.momut.ooas.ast.expressions.TernaryOperator; |
46 | 45 |
import org.momut.ooas.ast.expressions.TupleConstructor; |
... | ... | |
52 | 51 |
import org.momut.ooas.ast.identifiers.EnumIdentifier; |
53 | 52 |
import org.momut.ooas.ast.identifiers.Identifier; |
54 | 53 |
import org.momut.ooas.ast.identifiers.IdentifierKind; |
55 |
import org.momut.ooas.ast.identifiers.LandmarkIdentifier; |
|
56 | 54 |
import org.momut.ooas.ast.types.EnumType; |
57 | 55 |
import org.momut.ooas.ast.types.FunctionType; |
58 | 56 |
import org.momut.ooas.ast.types.TypeKind; |
59 |
import org.momut.ooas.ast.types.UlyssesType;
|
|
57 |
import org.momut.ooas.ast.types.Type; |
|
60 | 58 |
import org.momut.ooas.ast.types.ValuedEnumType; |
61 | 59 |
import org.momut.ooas.codegen.OoasCodeEmitter; |
62 | 60 |
import org.momut.ooas.utils.exceptions.ArgumentException; |
... | ... | |
106 | 104 |
|
107 | 105 |
// call of method that returns a value.. |
108 | 106 |
@Override |
109 |
public /*override*/ void visit(CallExpression callExpression)
|
|
107 |
public void visit(CallExpression callExpression) |
|
110 | 108 |
{ |
111 | 109 |
// we handle only function calls within expressions here (must have non-void return!) |
112 | 110 |
final FunctionType funtype = (FunctionType)callExpression.child().type(); |
... | ... | |
141 | 139 |
|
142 | 140 |
|
143 | 141 |
// we need to map all other things to Prolog constructs |
144 |
private String OperatorString(Expression expression, UlyssesType resultingType)
|
|
142 |
private String OperatorString(Expression expression, Type resultingType) |
|
145 | 143 |
{ |
146 | 144 |
switch (expression.kind()) |
147 | 145 |
{ |
... | ... | |
232 | 230 |
|
233 | 231 |
@SuppressWarnings("unchecked") |
234 | 232 |
@Override |
235 |
public /*override*/ <T> void visit(ValueExpression<T> valueExpression)
|
|
233 |
public <T> void visit(ValueExpression<T> valueExpression) |
|
236 | 234 |
{ |
237 | 235 |
assert(m_tmpVars.size() == 0); |
238 | 236 |
final String tmpVar = NewTempVariable(); |
... | ... | |
255 | 253 |
} |
256 | 254 |
|
257 | 255 |
@Override |
258 |
public /*override*/ void visit(IdentifierExpression identifierExpression)
|
|
256 |
public void visit(IdentifierExpression identifierExpression) |
|
259 | 257 |
{ |
260 |
if (identifierExpression.identifier().kind() == IdentifierKind.LandmarkIdentifier)
|
|
258 |
if (identifierExpression.identifier().kind() == IdentifierKind.EnumIdentifier)
|
|
261 | 259 |
{ |
262 |
final LandmarkIdentifier lmid = (LandmarkIdentifier)identifierExpression.identifier(); |
|
263 |
final OoaPrologIdentifier pid = createIdentifierVisitor(); |
|
264 |
lmid.Accept(pid); |
|
265 |
//m_emitter.Append(pid.ToString()); |
|
266 |
m_tmpVars.add(pid.toString()); |
|
267 |
return; |
|
268 |
} |
|
269 |
else if (identifierExpression.identifier().kind() == IdentifierKind.EnumIdentifier) |
|
270 |
{ |
|
271 | 260 |
final EnumIdentifier enumid = (EnumIdentifier)identifierExpression.identifier(); |
272 | 261 |
final EnumType enumType = (EnumType)enumid.type(); |
273 | 262 |
//m_emitter.Append(enumType.listOfEnumSymbols.IndexOf(enumid)); |
... | ... | |
281 | 270 |
m_emitter.AppendLine(String.format("%s = %s,", NewTempVariable(), GetIdentifierString(identifierExpression.identifier()))); |
282 | 271 |
} |
283 | 272 |
/*else if (identifierExpression.identifier.kind == IdentifierKind.AttributeIdentifier) |
284 |
{
|
|
285 |
m_emitter.AppendLine(String.format("getVal(%s,%s,_),", GetIdentifierString(identifierExpression.identifier), NewTempVariable(), ));
|
|
286 |
}*/
|
|
273 |
{
|
|
274 |
m_emitter.AppendLine(String.format("getVal(%s,%s,_),", GetIdentifierString(identifierExpression.identifier), NewTempVariable(), ));
|
|
275 |
}*/
|
|
287 | 276 |
else |
288 | 277 |
{ |
289 | 278 |
m_tmpVars.add(GetIdentifierString(identifierExpression.identifier())); |
... | ... | |
291 | 280 |
} |
292 | 281 |
|
293 | 282 |
@Override |
294 |
public /*override*/ void visit(TypeExpression typeExpression)
|
|
283 |
public void visit(TypeExpression typeExpression) |
|
295 | 284 |
{ |
296 | 285 |
if (typeExpression.type().kind() != TypeKind.QrType && |
297 | 286 |
typeExpression.type().kind() != TypeKind.EnumeratedType) |
... | ... | |
302 | 291 |
|
303 | 292 |
|
304 | 293 |
@Override |
305 |
public /*override*/ void visit(ObjectConstructor objectConstructor)
|
|
294 |
public void visit(ObjectConstructor objectConstructor) |
|
306 | 295 |
{ |
307 | 296 |
if (objectConstructor.instances().size() > 1) |
308 | 297 |
throw new NotImplementedException(); |
... | ... | |
313 | 302 |
} |
314 | 303 |
|
315 | 304 |
@Override |
316 |
public /*override*/ void visit(ListConstructor listConstructor)
|
|
305 |
public void visit(ListConstructor listConstructor) |
|
317 | 306 |
{ |
318 | 307 |
if (listConstructor.hasComprehension()) |
319 | 308 |
{ |
... | ... | |
363 | 352 |
} |
364 | 353 |
|
365 | 354 |
@Override |
366 |
public /*override*/ void visit(SetConstructor setConstructor)
|
|
355 |
public void visit(SetConstructor setConstructor) |
|
367 | 356 |
{ |
368 | 357 |
m_emitter.AppendLine("% make set"); |
369 | 358 |
// our resulting set. |
... | ... | |
385 | 374 |
} |
386 | 375 |
|
387 | 376 |
@Override |
388 |
public /*override*/ void visit(MapConstructor mapConstructor)
|
|
377 |
public void visit(MapConstructor mapConstructor) |
|
389 | 378 |
{ |
390 | 379 |
throw new NotImplementedException(); |
391 | 380 |
} |
392 | 381 |
|
393 | 382 |
@Override |
394 |
public /*override*/ void visit(TupleConstructor tupleConstructor)
|
|
383 |
public void visit(TupleConstructor tupleConstructor) |
|
395 | 384 |
{ |
396 | 385 |
if (tupleConstructor.isMatcher()) |
397 | 386 |
{ |
... | ... | |
421 | 410 |
} |
422 | 411 |
|
423 | 412 |
@Override |
424 |
public /*override*/ void visit(QValConstructor qValConstructor)
|
|
413 |
public void visit(AccessExpression accessExpression)
|
|
425 | 414 |
{ |
426 |
final OoaPrologIdentifier pident = createIdentifierVisitor(); |
|
427 |
qValConstructor.type().identifier().Accept(pident); |
|
428 |
final StringBuilder qVal = new StringBuilder(); |
|
429 |
if (qValConstructor.value() != null || qValConstructor.value().length != 0) |
|
430 |
{ |
|
431 |
final OoaPrologExpression landmark1 = createExpressionVisitor(); |
|
432 |
qValConstructor.value()[0].Accept(landmark1); |
|
433 |
qVal.append(landmark1.toString()); |
|
434 |
|
|
435 |
if (qValConstructor.value().length > 1) |
|
436 |
{ |
|
437 |
final OoaPrologExpression landmark2 = createExpressionVisitor(); |
|
438 |
qValConstructor.value()[1].Accept(landmark2); |
|
439 |
qVal.append(".."); |
|
440 |
qVal.append(landmark2.toString()); |
|
441 |
} |
|
442 |
} |
|
443 |
else |
|
444 |
qVal.append("_"); |
|
445 |
|
|
446 |
String deriv = "_"; |
|
447 |
switch (qValConstructor.valueDeriv()) |
|
448 |
{ |
|
449 |
case Dec: |
|
450 |
deriv = "dec"; |
|
451 |
break; |
|
452 |
case Inc: |
|
453 |
deriv = "inc"; |
|
454 |
break; |
|
455 |
case Steady: |
|
456 |
deriv = "std"; |
|
457 |
break; |
|
458 |
default: |
|
459 |
throw new NotImplementedException(); |
|
460 |
} |
|
461 |
final String tmpVar = NewTempVariable(); |
|
462 |
m_emitter.AppendLine(String.format("%s = (%s:%s/%s),", tmpVar, pident.toString(), qVal.toString(), deriv)); |
|
463 |
} |
|
464 |
|
|
465 |
@Override |
|
466 |
public /*override*/ void visit(AccessExpression accessExpression) |
|
467 |
{ |
|
468 | 415 |
if (accessExpression.left().type().kind() != TypeKind.QrType && |
469 | 416 |
accessExpression.left().type().kind() != TypeKind.EnumeratedType && |
470 | 417 |
!(accessExpression.right().kind() == ExpressionKind.Identifier && |
... | ... | |
485 | 432 |
} |
486 | 433 |
|
487 | 434 |
@Override |
488 |
public /*override*/ void visit(BinaryOperator binaryOperator)
|
|
435 |
public void visit(BinaryOperator binaryOperator) |
|
489 | 436 |
{ |
490 | 437 |
final OoasCodeEmitter origEmitter = m_emitter; |
491 | 438 |
|
... | ... | |
610 | 557 |
} |
611 | 558 |
|
612 | 559 |
@Override |
613 |
public /*override*/ void visit(TernaryOperator ternaryOperator)
|
|
560 |
public void visit(TernaryOperator ternaryOperator) |
|
614 | 561 |
{ |
615 | 562 |
if (ternaryOperator.kind() == ExpressionKind.conditional) |
616 | 563 |
{ |
... | ... | |
666 | 613 |
} |
667 | 614 |
|
668 | 615 |
@Override |
669 |
public /*override*/ void visit(TupleMapAccessExpression tupleMapAccessExpression)
|
|
616 |
public void visit(TupleMapAccessExpression tupleMapAccessExpression) |
|
670 | 617 |
{ |
671 | 618 |
assert(m_tmpVars.size() == 0); |
672 | 619 |
VisitSub(tupleMapAccessExpression.child(), tupleMapAccessExpression); |
... | ... | |
734 | 681 |
|
735 | 682 |
|
736 | 683 |
@Override |
737 |
public /*override*/ void visit(ForallQuantifier quantifier)
|
|
684 |
public void visit(ForallQuantifier quantifier) |
|
738 | 685 |
{ |
739 | 686 |
final OoaPrologExpression pExpr = createExpressionVisitor(); |
740 | 687 |
quantifier.child().Accept(pExpr); |
... | ... | |
764 | 711 |
|
765 | 712 |
|
766 | 713 |
@Override |
767 |
public /*override*/ void visit(ExistsQuantifier quantifier)
|
|
714 |
public void visit(ExistsQuantifier quantifier) |
|
768 | 715 |
{ |
769 | 716 |
final OoaPrologExpression pExpr = createExpressionVisitor(); |
770 | 717 |
quantifier.child().Accept(pExpr); |
... | ... | |
791 | 738 |
NewTempVariable(), Generator.toString(), nullGuard.toString(), pExpr.toString(), pExpr.tmpVariables().get(0))); |
792 | 739 |
} |
793 | 740 |
@Override |
794 |
public /*override*/ void visit(UnaryOperator unaryOperator)
|
|
741 |
public void visit(UnaryOperator unaryOperator) |
|
795 | 742 |
{ |
796 | 743 |
assert(m_tmpVars.size() == 0); |
797 | 744 |
VisitSub(unaryOperator.child(), unaryOperator); |
... | ... | |
849 | 796 |
} |
850 | 797 |
|
851 | 798 |
@Override |
852 |
public /*override*/ String toString()
|
|
799 |
public String toString() |
|
853 | 800 |
{ |
854 | 801 |
return m_emitter.toString(); |
855 | 802 |
} |
Also available in: Unified diff
remove support for Qualitative Action Systems, rename UlyssesType to Type