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:

OoaTypeCheckVisitor.java
47 47
import org.momut.ooas.ast.statements.Call;
48 48
import org.momut.ooas.ast.statements.GuardedCommand;
49 49
import org.momut.ooas.ast.statements.KillStatement;
50
import org.momut.ooas.ast.statements.QualitativeConstraintStatement;
51 50
import org.momut.ooas.ast.statements.Statement;
52 51
import org.momut.ooas.ast.types.FunctionType;
53 52
import org.momut.ooas.ast.types.TypeKind;
54
import org.momut.ooas.ast.types.UlyssesType;
53
import org.momut.ooas.ast.types.Type;
55 54
import org.momut.ooas.parser.ParserError;
56 55
import org.momut.ooas.parser.ParserState;
57 56
import org.momut.ooas.parser.ParserWarning;
......
186 185
									RemoveWarning(exprvar, String.format("Free variable in expression: '%s'.", exprvar.tokenText()));
187 186
									RemoveWarning(freeRhsVar, String.format("Free variable in expression: '%s'.", exprvar.tokenText()));
188 187
								}
189
								else if (UlyssesType.TypeEqual(freeRhsVar.type(), exprvar.type()))
188
								else if (Type.TypeEqual(freeRhsVar.type(), exprvar.type()))
190 189
								{
191 190
									assignment.AddIdentifier(exprvar, null);
192 191
									// remove free variable warnings
......
226 225
			if (avalue.kind() != ExpressionKind.Call)
227 226
				CheckMethodCallsArePure(avalue);
228 227

  
229
			final UlyssesType acover = UlyssesType.CoverType(aplace.type(), avalue.type());
228
			final Type acover = Type.CoverType(aplace.type(), avalue.type());
230 229
			if (acover == null)
231 230
				Error(assignment, String.format("Type mismatch in assignment: %s ( %s := %s )", aplace.toString(), aplace.type().toString(), avalue.type().toString()));
232
			else if (!UlyssesType.TypeEqualByKind(aplace.type(), acover)) /*ignore range things.. (see warning below)*/
231
			else if (!Type.TypeEqualByKind(aplace.type(), acover)) /*ignore range things.. (see warning below)*/
233 232
				Error(assignment, String.format("Type mismatch in assignment: %s ( %s := %s )", aplace.toString(), aplace.type().toString(), acover.toString()));
234 233
			else
235 234
			{
......
239 238
				if (uninitvars.size() > 0)
240 239
					Error(assignment, String.format("Undefined variable '%s'", uninitvars.get(0).tokenText()));
241 240

  
242
				if (!UlyssesType.TypeEqual(avalue.type(), acover))
241
				if (!Type.TypeEqual(avalue.type(), acover))
243 242
				{
244 243
					final UnaryOperator cast = new UnaryOperator(ExpressionKind.Cast, avalue, avalue.line(), avalue.pos());
245 244
					cast.SetType(acover);
......
250 249
						throw new OoasCompilerRuntimeException();
251 250
				}
252 251

  
253
				if (UlyssesType.FirstTypeLessRange(aplace.type(), acover))
252
				if (Type.FirstTypeLessRange(aplace.type(), acover))
254 253
				{
255 254
					if (constantvalue == null)
256 255
					{
......
310 309
	}
311 310

  
312 311

  
313
	private void TypeCheckQualConstraint(QualitativeConstraintStatement qualConstr)
314
	{
315
		if (qualConstr.variable0().type().kind() != TypeKind.QrType && qualConstr.variable0().type().kind() != TypeKind.Any)
316
			Error(qualConstr, String.format("Qualitative type expected: '%s'", qualConstr.variable0().tokenText()));
317
		if (qualConstr.variable1().type().kind() != TypeKind.QrType && qualConstr.variable1().type().kind() != TypeKind.Any)
318
			Error(qualConstr, String.format("Qualitative type expected: '%s'", qualConstr.variable0().tokenText()));
319
		if (qualConstr.variable2() != null && qualConstr.variable2().type().kind() != TypeKind.QrType
320
				&& qualConstr.variable2().type().kind() != TypeKind.Any)
321
			Error(qualConstr, String.format("Qualitative type expected: '%s'", qualConstr.variable0().tokenText()));
322
	}
323 312
	private void TypeCheck(Statement statement)
324 313
	{
325 314
		switch (statement.kind())
......
357 346
					&& callstatement.callExpression().kind() != ExpressionKind.foldLR)
358 347
				Error(callstatement, "Not a valid method call");
359 348
			break;
360
		case QualConstraint:
361
			final QualitativeConstraintStatement qualConstr = (QualitativeConstraintStatement)statement;
362
			TypeCheckQualConstraint(qualConstr);
363
			break;
364 349
		default:
365 350
			throw new NotImplementedException();
366 351
		}
......
373 358
		if (attributeIdentifier.initializer() == null)
374 359
			throw new ArgumentException();
375 360

  
376
		final UlyssesType atype = attributeIdentifier.initializer().type();
361
		final Type atype = attributeIdentifier.initializer().type();
377 362
		if (atype == null)
378 363
			Error(attributeIdentifier, "Initializer lacks type.");
379 364
		else
......
396 381
								attributeIdentifier.initializer().freeVariables().symbolList().get(0).tokenText()));
397 382
			else
398 383
			{
399
				final UlyssesType idtype = attributeIdentifier.type();
400
				final UlyssesType acover = UlyssesType.CoverType(idtype, atype);
384
				final Type idtype = attributeIdentifier.type();
385
				final Type acover = Type.CoverType(idtype, atype);
401 386

  
402 387
				if (acover == null)
403 388
					Error(attributeIdentifier, String.format("Type mismatch in attribute initializer: %s ( %s := %s )", attributeIdentifier.toString(), idtype.toString(), atype.toString()));
404
				else if (!UlyssesType.TypeEqualByKind(idtype, acover)) /*ignore range things.. (see warning below)*/
389
				else if (!Type.TypeEqualByKind(idtype, acover)) /*ignore range things.. (see warning below)*/
405 390
					Error(attributeIdentifier, String.format("Type mismatch in attribute initializer: %s ( %s := %s )", attributeIdentifier.toString(), idtype.toString(), acover.toString()));
406 391
				else
407 392
				{
408 393
					final Expression constantvalue = attributeIdentifier.initializer().kind() == ExpressionKind.Value ? attributeIdentifier.initializer() : null;
409 394

  
410
					if (!UlyssesType.TypeEqual(atype, acover))
395
					if (!Type.TypeEqual(atype, acover))
411 396
					{
412 397
						final UnaryOperator cast = new UnaryOperator(ExpressionKind.Cast, attributeIdentifier.initializer(),
413 398
								attributeIdentifier.initializer().line(), attributeIdentifier.initializer().pos());
......
415 400
						attributeIdentifier.SetInitializer(cast);
416 401
					}
417 402

  
418
					if (UlyssesType.FirstTypeLessRange(idtype, acover))
403
					if (Type.FirstTypeLessRange(idtype, acover))
419 404
					{
420 405
						if (constantvalue == null)
421 406
						{

Also available in: Unified diff