Project

General

Profile

Revision 9

Added by Willibald K. over 8 years ago

remove support for Qualitative Action Systems, rename UlyssesType to Type

View differences:

ooaCustomParser.java
50 50
import org.momut.ooas.ast.expressions.ListConstructor;
51 51
import org.momut.ooas.ast.expressions.MapConstructor;
52 52
import org.momut.ooas.ast.expressions.ObjectConstructor;
53
import org.momut.ooas.ast.expressions.QValConstructor;
54 53
import org.momut.ooas.ast.expressions.Quantifier;
55 54
import org.momut.ooas.ast.expressions.SetConstructor;
56 55
import org.momut.ooas.ast.expressions.TernaryOperator;
......
59 58
import org.momut.ooas.ast.expressions.UnaryOperator;
60 59
import org.momut.ooas.ast.expressions.UnresolvedIdentifierExpression;
61 60
import org.momut.ooas.ast.expressions.ValueExpression;
62
import org.momut.ooas.ast.expressions.QValConstructor.QValDeriv;
63 61
import org.momut.ooas.ast.identifiers.AttributeIdentifier;
64 62
import org.momut.ooas.ast.identifiers.ConstantIdentifier;
65 63
import org.momut.ooas.ast.identifiers.EnumIdentifier;
......
68 66
import org.momut.ooas.ast.identifiers.Identifier;
69 67
import org.momut.ooas.ast.identifiers.IdentifierKind;
70 68
import org.momut.ooas.ast.identifiers.IdentifierList;
71
import org.momut.ooas.ast.identifiers.LandmarkIdentifier;
72 69
import org.momut.ooas.ast.identifiers.LocalVariableIdentifier;
73 70
import org.momut.ooas.ast.identifiers.MainModule;
74 71
import org.momut.ooas.ast.identifiers.MethodIdentifier;
......
85 82
import org.momut.ooas.ast.statements.KillStatement;
86 83
import org.momut.ooas.ast.statements.NondetBlock;
87 84
import org.momut.ooas.ast.statements.PrioBlock;
88
import org.momut.ooas.ast.statements.QualitativeConstraintStatement;
89 85
import org.momut.ooas.ast.statements.SeqBlock;
90 86
import org.momut.ooas.ast.statements.SkipStatement;
91 87
import org.momut.ooas.ast.statements.Statement;
92
import org.momut.ooas.ast.statements.QualitativeConstraintStatement.QualitativeConstraintOperation;
93
import org.momut.ooas.ast.types.AnyType;
94 88
import org.momut.ooas.ast.types.BoolType;
95 89
import org.momut.ooas.ast.types.CharType;
96 90
import org.momut.ooas.ast.types.EnumType;
......
101 95
import org.momut.ooas.ast.types.MapType;
102 96
import org.momut.ooas.ast.types.OoActionSystemType;
103 97
import org.momut.ooas.ast.types.OpaqueType;
104
import org.momut.ooas.ast.types.QrType;
105 98
import org.momut.ooas.ast.types.TupleType;
106 99
import org.momut.ooas.ast.types.TypeKind;
107
import org.momut.ooas.ast.types.UlyssesType;
100
import org.momut.ooas.ast.types.Type;
108 101
import org.momut.ooas.ast.types.ValuedEnumType;
109 102
import org.momut.ooas.ast.types.FunctionType.FunctionTypeEnum;
110 103
import org.momut.ooas.utils.exceptions.ArgumentException;
......
248 241
				new ParserError(pState.filename, aToken, aMessage));
249 242
	}
250 243

  
251
	/* add warning message to state */
252
	private void doWarning(Token id1, String p)
253
	{
254
		pState.AddWarningMessage(new ParserWarning(pState.filename, id1, p));
255
	}
244
//	/* add warning message to state */
245
//	private void doWarning(Token id1, String p)
246
//	{
247
//		pState.AddWarningMessage(new ParserWarning(pState.filename, id1, p));
248
//	}
256 249

  
257 250
	private void doError(String aMessage)
258 251
	{
......
302 295

  
303 296

  
304 297
	/* create a named type; we're on top-level here */
305
	 void createNamedType(Token aName, UlyssesType aType)
298
	 void createNamedType(Token aName, Type aType)
306 299
	{
307 300
		// precond..
308 301
		assert(aName != null);
......
454 447
	}
455 448

  
456 449
	/* add var symbol to the current action system */
457
	void createAttribute(Token varname, boolean isStatic, boolean isObs, boolean isCtr, UlyssesType aType, Expression anExpr)
450
	void createAttribute(Token varname, boolean isStatic, boolean isObs, boolean isCtr, Type aType, Expression anExpr)
458 451
	{
459 452
		if (!TosIsActionSystem())
460 453
			return;
......
494 487

  
495 488
	/* create an int type */
496 489
	@SuppressWarnings("unchecked")
497
	UlyssesType createIntType(Token rangeLow, Token rangeHigh)
490
	Type createIntType(Token rangeLow, Token rangeHigh)
498 491
	{
499 492
		int low = 0;
500 493
		int high = 0;
......
548 541

  
549 542
	/* create a float type */
550 543
	 @SuppressWarnings("unchecked")
551
	UlyssesType createFloatType(Token rangeLow, Token rangeHigh)
544
	Type createFloatType(Token rangeLow, Token rangeHigh)
552 545
	{
553 546
		float low = 0;
554 547
		float high = 0;
......
606 599
	}
607 600

  
608 601
	/* create a list of an enumerated type */
609
	 UlyssesType createListEnumType(Token alistelem)
602
	 Type createListEnumType(Token alistelem)
610 603
	{
611 604
		final EnumType hiddenEnumType = new EnumType(null);
612 605

  
......
616 609
	}
617 610

  
618 611
	/* add a new enum symbol to a list with an anonymous enumerated type */
619
	 void addToListEnumType(UlyssesType aTypeSymbol, Token otherlistelem)
612
	 void addToListEnumType(Type aTypeSymbol, Token otherlistelem)
620 613
	{
621 614
		final EnumType enumtype = (EnumType)((ListType)aTypeSymbol).innerType();
622 615
		addToEnumType(enumtype, otherlistelem, null);
623 616
	}
624 617

  
625 618
	/* create a new enumerated type */
626
	 UlyssesType createEnumType(Token aRangeValue, Token anIntegerValue)
619
	 Type createEnumType(Token aRangeValue, Token anIntegerValue)
627 620
	{
628 621
		EnumType result;
629 622

  
......
637 630
	}
638 631

  
639 632
	/* add a new enum symbol to the enumerated type */
640
	 void addToEnumType(UlyssesType aTypeSymbol, Token otherRangeValue, Token anIntegerValue)
633
	 void addToEnumType(Type aTypeSymbol, Token otherRangeValue, Token anIntegerValue)
641 634
	{
642 635
		final EnumType anEnum = (EnumType)aTypeSymbol;
643 636
		if (anEnum.symbolTable().Defined(otherRangeValue.getText()))
......
685 678
	}
686 679

  
687 680
	/* get a named type */
688
	 UlyssesType getNamedType(Token aType)
681
	 Type getNamedType(Token aType)
689 682
	{
690
		UlyssesType result = null;
683
		Type result = null;
691 684
		final Identifier sym = pState.Lookup(aType);
692 685
		if (sym == null)
693 686
		{
......
705 698

  
706 699
	/* create a list type */
707 700
	 @SuppressWarnings("unchecked")
708
	UlyssesType createListType(Token numOfElements, UlyssesType innertype)
701
	Type createListType(Token numOfElements, Type innertype)
709 702
	{
710 703
		if (innertype == null)
711 704
			doError(numOfElements, "List type lacks proper element type (null)");
......
740 733

  
741 734
	/* create a map type */
742 735
	 @SuppressWarnings("unchecked")
743
	UlyssesType createMapType(Token numOfElements, UlyssesType mapfromtype, UlyssesType maptotype)
736
	Type createMapType(Token numOfElements, Type mapfromtype, Type maptotype)
744 737
	{
745 738
		if (mapfromtype == null)
746 739
			doError(numOfElements, "Map: From-type not set (null)");
......
772 765
	}
773 766

  
774 767
	/* create a tuple type */
775
	 UlyssesType createTupleType(UlyssesType aType)
768
	 Type createTupleType(Type aType)
776 769
	{
777 770
		final TupleType result = new TupleType(null);
778 771
		addToTupleType(result, aType);
......
780 773
	}
781 774

  
782 775
	/* add inner type to tuple */
783
	 void addToTupleType(UlyssesType aTypeSymbol, UlyssesType anotherType)
776
	 void addToTupleType(Type aTypeSymbol, Type anotherType)
784 777
	{
785 778
		final TupleType tuple = (TupleType)aTypeSymbol;
786 779
		if (anotherType != null)
......
789 782
			doError("Unknown inner type in tuple");
790 783
	}
791 784

  
792
	/* create a QR type */
793
	UlyssesType createQrType(Token alandmark)
794
	{
795
		final QrType result = new QrType(null);
796
		addToQrType(result, alandmark);
797
		return result;
798
	}
799

  
800
	/* add another landmark to QR type */
801
	protected void addToQrType(UlyssesType aTypeSymbol, Token otherlandmark)
802
	{
803
		final Identifier sym = pState.Lookup(otherlandmark);
804
		if (sym != null)
805
		{
806
			doError(otherlandmark, String.format("Redifinition of %s", otherlandmark.getText()));
807
			return;
808
		}
809

  
810
		final LandmarkIdentifier lndmrk = new LandmarkIdentifier(otherlandmark, (QrType)aTypeSymbol, GetScope());
811
		((QrType)aTypeSymbol).AddLandmark(lndmrk);
812
	}
813

  
814 785
	/* gets called after a simple type has been constructed. used to define an internal name*/
815
	 void fixupSimpleType(UlyssesType aTypeSymbol)
786
	 void fixupSimpleType(Type aTypeSymbol)
816 787
	{
817 788
		if (aTypeSymbol != null)
818 789
			aTypeSymbol.SetupAnonymousName();
819 790
	}
820 791

  
821 792
	/* gets called after a simple or complex type has been constructed. used to define an internal name */
822
	 void fixupComplexType(UlyssesType aTypeSymbol)
793
	 void fixupComplexType(Type aTypeSymbol)
823 794
	{
824 795
		if (aTypeSymbol != null)
825 796
			aTypeSymbol.SetupAnonymousName();
......
836 807
			return null;
837 808
		}
838 809

  
839
		final FunctionType funtype = new FunctionType(FunctionTypeEnum.Method, new LinkedList<UlyssesType>(), null);
810
		final FunctionType funtype = new FunctionType(FunctionTypeEnum.Method, new LinkedList<Type>(), null);
840 811
		final MethodIdentifier msym = new MethodIdentifier(mname, funtype, GetScope());
841 812
		// funtype.SetTypeIdentifier(msym); -- the type of this function doesn't have a name!
842 813

  
......
855 826

  
856 827

  
857 828
	/* add a return type to a method */
858
	 void setMethodReturnType(FunctionIdentifier newMethod, UlyssesType rt)
829
	 void setMethodReturnType(FunctionIdentifier newMethod, Type rt)
859 830
	{
860 831
		if (newMethod == null)
861 832
			return;
......
879 850
	}
880 851

  
881 852
	/* add a parameter to a method */
882
	 void addMethodParameter(FunctionIdentifier newMethod, Token paramName, UlyssesType atype)
853
	 void addMethodParameter(FunctionIdentifier newMethod, Token paramName, Type atype)
883 854
	{
884 855
		if (newMethod == null)
885 856
			return;
......
932 903
			return null;
933 904
		}
934 905

  
935
		final FunctionType atype = new FunctionType(actionType, new LinkedList<UlyssesType>(), null);
906
		final FunctionType atype = new FunctionType(actionType, new LinkedList<Type>(), null);
936 907
		final NamedActionIdentifier action = new NamedActionIdentifier(actionname, atype, GetScope());
937 908
		// atype.SetTypeIdentifier(action); -- the type of this action doesn't have a name!
938 909

  
......
1275 1246
	}
1276 1247

  
1277 1248
	/* add block var */
1278
	 void addBlockVariable(Block seqList, Token varname, UlyssesType aType)
1249
	 void addBlockVariable(Block seqList, Token varname, Type aType)
1279 1250
	{
1280 1251
		if (aType == null)
1281 1252
		{
......
1291 1262
		}
1292 1263
	}
1293 1264

  
1294

  
1295
	 QualitativeConstraintStatement createTwoVarConstraintStatement(Token id1, Token id2, QualitativeConstraintOperation op)
1296
	{
1297
		Identifier var1 = pState.Lookup(id1);
1298
		if (var1 == null)
1299
		{
1300
			var1 = new ExpressionVariableIdentifier(id1.getText(), id1.getLine(), id1.getCharPositionInLine());
1301
			var1.SetType(new AnyType((ExpressionVariableIdentifier)var1));
1302

  
1303
			GetScope().AddIdentifier(var1, null);
1304

  
1305
			doWarning(id1, String.format("Free variable in qualitative constraint: '%s'.", id1.getText()));
1306
		}
1307

  
1308
		Identifier var2 = pState.Lookup(id2);
1309
		if (var2 == null)
1310
		{
1311
			var2 = new ExpressionVariableIdentifier(id2.getText(), id2.getLine(), id2.getCharPositionInLine());
1312
			var2.SetType(new AnyType((ExpressionVariableIdentifier)var2));
1313

  
1314
			GetScope().AddIdentifier(var2, null);
1315

  
1316
			doWarning(id1, String.format("Free variable in qualitative constraint: '%s'.", id2.getText()));
1317
		}
1318

  
1319
		final QualitativeConstraintStatement result = new QualitativeConstraintStatement(var1, var2, op, id1.getLine(), id1.getCharPositionInLine());
1320
		return result;
1321
	}
1322

  
1323

  
1324
	 QualitativeConstraintStatement createQualEqualConstraintStatement(Token id1, Token id2)
1325
	{
1326
		return createTwoVarConstraintStatement(id1, id2, QualitativeConstraintOperation.Equal);
1327
	}
1328

  
1329
	 QualitativeConstraintStatement createQualArithConstraintStatement(Token id1, Token id2, Token id3, Token op)
1330
	{
1331
		Identifier var1 = pState.Lookup(id1);
1332
		if (var1 == null)
1333
		{
1334
			var1 = new ExpressionVariableIdentifier(id1.getText(), id1.getLine(), id1.getCharPositionInLine());
1335
			var1.SetType(new AnyType((ExpressionVariableIdentifier)var1));
1336

  
1337
			GetScope().AddIdentifier(var1, null);
1338

  
1339
			doWarning(id1, String.format("Free variable in qualitative constraint: '%s'.", id1.getText()));
1340
		}
1341

  
1342
		Identifier var2 = pState.Lookup(id2);
1343
		if (var2 == null)
1344
		{
1345
			var2 = new ExpressionVariableIdentifier(id2.getText(), id2.getLine(), id2.getCharPositionInLine());
1346
			var2.SetType(new AnyType((ExpressionVariableIdentifier)var2));
1347

  
1348
			GetScope().AddIdentifier(var2, null);
1349

  
1350
			doWarning(id1, String.format("Free variable in qualitative constraint: '%s'.", id2.getText()));
1351
		}
1352

  
1353
		Identifier var3 = pState.Lookup(id3);
1354
		if (var3 == null)
1355
		{
1356
			var3 = new ExpressionVariableIdentifier(id3.getText(), id3.getLine(), id3.getCharPositionInLine());
1357
			var3.SetType(new AnyType((ExpressionVariableIdentifier)var3));
1358

  
1359
			GetScope().AddIdentifier(var3, null);
1360

  
1361
			doWarning(id1, String.format("Free variable in qualitative constraint: '%s'.", id3.getText()));
1362
		}
1363
		QualitativeConstraintOperation operation;
1364
		switch (op.getType())
1365
		{
1366
		case ooaParser.T_SUM:
1367
			operation = QualitativeConstraintOperation.Sum;
1368
			break;
1369
		case ooaParser.T_DIFF:
1370
			operation = QualitativeConstraintOperation.Diff;
1371
			break;
1372
		case ooaParser.T_PROD:
1373
			operation = QualitativeConstraintOperation.Prod;
1374
			break;
1375
		default:
1376
			doError(op, String.format("'%s' unknown operation", op.getText()));
1377
			return null;
1378
		}
1379

  
1380
		final QualitativeConstraintStatement result = new QualitativeConstraintStatement(var1, var2, var3, operation, id1.getLine(), id1.getCharPositionInLine());
1381
		return result;
1382
	}
1383

  
1384
	 QualitativeConstraintStatement createQualDerivConstraintStatement(Token id1, Token derivid)
1385
	{
1386
		return createTwoVarConstraintStatement(id1, derivid, QualitativeConstraintOperation.Deriv);
1387
	}
1388

  
1389

  
1390

  
1391 1265
	/* creates a general binary operator without any children */
1392 1266
	 BinaryOperator createBinaryOperator(ExpressionKind akind)
1393 1267
	{
......
1424 1298
	}
1425 1299

  
1426 1300
	/* add a bound variable to the quantifier */
1427
	 void addBoundVarToQuantifierExpression(Quantifier result, Token id, UlyssesType id_type)
1301
	 void addBoundVarToQuantifierExpression(Quantifier result, Token id, Type id_type)
1428 1302
	{
1429 1303
		/*note: this might be a bit harsh, but for now it's easier to demand uniquely named vars,
1430 1304
                without any hiding. Could be fixed in searching only the first resolve level for
......
1554 1428
	}
1555 1429

  
1556 1430
	/* add list comprehension variable */
1557
	 void addListComprVar(ListConstructor result, Token id, UlyssesType t1)
1431
	 void addListComprVar(ListConstructor result, Token id, Type t1)
1558 1432
	{
1559 1433
		final Identifier sym = pState.Lookup(id);
1560 1434
		if (sym != null)
......
1636 1510
	}
1637 1511

  
1638 1512
	/* add local set compr. variable */
1639
	 void addSetComprVar(SetConstructor _set, Token id1, UlyssesType t1)
1513
	 void addSetComprVar(SetConstructor _set, Token id1, Type t1)
1640 1514
	{
1641 1515
		final Identifier sym = pState.Lookup(id1);
1642 1516
		if (sym != null)
......
1739 1613
		return new ObjectConstructor(atype, aname.getText(), anid.getLine(), anid.getCharPositionInLine());
1740 1614
	}
1741 1615

  
1742

  
1743
	 void setQualitativeDerivDec(QValConstructor result)
1744
	{
1745
		result.SetDerivation(QValDeriv.Dec);
1746
	}
1747

  
1748
	 void setQualitativeDerivInc(QValConstructor result)
1749
	{
1750
		result.SetDerivation(QValDeriv.Inc);
1751
	}
1752

  
1753
	 void setQualitativeDerivSteady(QValConstructor result)
1754
	{
1755
		result.SetDerivation(QValDeriv.Steady);
1756
	}
1757

  
1758
	 void setQualitativeDerivDontCare(QValConstructor result)
1759
	{
1760
		result.SetDerivation(QValDeriv.DonTCare);
1761
	}
1762

  
1763
	 void setQualitativeValueRangeInfinity(QValConstructor result, boolean p)
1764
	{
1765
		throw new NotImplementedException();
1766
	}
1767

  
1768
	 void setQualitativeValueRange(QValConstructor result, Expression expr2)
1769
	{
1770
		result.AddRange(expr2);
1771
	}
1772

  
1773
	 void setQualitativeValueInfinity(QValConstructor result, boolean minus)
1774
	{
1775
		throw new NotImplementedException();
1776
	}
1777

  
1778
	 void setQualitativeValueLandmark(QValConstructor result, Expression expr)
1779
	{
1780
		result.SetValue(expr);
1781
	}
1782

  
1783
	 void setQualitativeValueDontCare(QValConstructor result)
1784
	{
1785
		throw new NotImplementedException();
1786
	}
1787

  
1788
	 QValConstructor createQualitativeValue(Token aval)
1789
	{
1790
		return new QValConstructor(aval.getLine(), aval.getCharPositionInLine());
1791
	}
1792

  
1793 1616
	/* add a local variable to a named action */
1794
	 void addLocalVariableToNamedAction(FunctionIdentifier newMethod, Token id1, UlyssesType t1)
1617
	 void addLocalVariableToNamedAction(FunctionIdentifier newMethod, Token id1, Type t1)
1795 1618
	{
1796 1619
		if (t1 == null)
1797 1620
		{

Also available in: Unified diff