Project

General

Profile

Revision 10

Added by Willibald K. over 8 years ago

restrict list casts to something useful - i.e. inner type sizes must not change; this is in preparation for faster dynamic list support in momut; deep casts now need to be done manually by the user via fold operations or can be added again to the ooas compiler as a more expensive, special cast operator; also more cleaning of Qualitative Action System stuff

View differences:

trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/types/Type.java
118 118
				(m_kind == TypeKind.EnumeratedType && o instanceof ValuedEnumType);
119 119
	}
120 120

  
121
	public boolean IsQualitative()
122
	{
123
		return (m_kind == TypeKind.QrType);
124
	}
125

  
126 121
	/**
127 122
	 * returns the number of unique values of the type (2 for bool, etc..)
128 123
	 */
......
276 271
				case ListType:
277 272
					final ListType listt1 = (ListType)type1;
278 273
					final ListType listt2 = (ListType)type2;
279
					int maxelems = listt1.maxNumberOfElements() > listt2.maxNumberOfElements() ?
280
						listt1.maxNumberOfElements() : listt2.maxNumberOfElements();
281 274
					// empty lists lack type, so take the other one
282 275
					if ((listt1.innerType().kind() == TypeKind.Null) && (listt2.innerType().kind() != TypeKind.Null))
283 276
						return listt2;
......
287 280
						return listt1;
288 281
					else
289 282
					{
290
						final Type subtype = Type.CoverType(listt1.innerType(), listt2.innerType());
291
						if (subtype != null)
283
						/**
284
						 * A cover type of a list must not change the size of the inner type. Mostly what is
285
						 * allowed to change is the list length.
286
						 */
287
						Type subtype = listt1.innerType();
288
						final boolean castAllowed = TypeEqual(listt1.innerType(), listt2.innerType())
289
						          || (    (listt1.innerType().kind() == TypeKind.OoActionSystemType)
290
						               && (subtype = Type.CoverType(listt1.innerType(), listt2.innerType())) != null);
291
						if (castAllowed){
292
							final int maxelems = listt1.maxNumberOfElements() > listt2.maxNumberOfElements()
293
							                ? listt1.maxNumberOfElements()
294
							                : listt2.maxNumberOfElements();
292 295
							return new ListType(subtype, maxelems, null);
293
						else
296
						} else
294 297
							return null;
298

  
299
//						// The code blow allowed for bit-size changes of the inner type and is considered too
300
//						// liberal. If a deep cast is necessary, the user might want to do a fold operation
301
//						// instead..
302
//						final Type subtype = Type.CoverType(listt1.innerType(), listt2.innerType());
303
//						if (subtype != null)
304
//							return new ListType(subtype, maxelems, null);
305
//						else
306
//							return null;
295 307
					}
296 308
				case MapType:
297 309
					final MapType mapt1 = (MapType)type1;
......
310 322
					{
311 323
						final Type sub1 = Type.CoverType(mapt1.fromType(), mapt2.fromType());
312 324
						final Type sub2 = Type.CoverType(mapt2.toType(), mapt2.toType());
313
						maxelems = mapt1.maxNumberOfElements() > mapt2.maxNumberOfElements() ?
325
						final int maxelems = mapt1.maxNumberOfElements() > mapt2.maxNumberOfElements() ?
314 326
							mapt1.maxNumberOfElements() : mapt2.maxNumberOfElements();
315 327
						if (sub1 != null && sub2 != null)
316 328
							return new MapType(sub1, sub2, maxelems, null);
317 329
						else
318 330
							return null;
319 331
					}
320
				case QrType:
321
					return null; /*if refs are equal, we do not reach this statement! see above..*/
322 332
				case TupleType:
323 333
					final TupleType tuplet1 = (TupleType)type1;
324 334
					final TupleType tuplet2 = (TupleType)type2;
......
413 423
				return (mapt1.maxNumberOfElements() < mapt2.maxNumberOfElements()) ||
414 424
					Type.FirstTypeLessRange(mapt1.fromType(), mapt2.fromType()) ||
415 425
					Type.FirstTypeLessRange(mapt1.toType(), mapt2.toType());
416
			case QrType:
417
				return false;
418 426
			case TupleType:
419 427
				final TupleType tuplet1 = (TupleType)type1;
420 428
				final TupleType tuplet2 = (TupleType)type2;
trunk/compiler/ooasCompiler/src/org/momut/ooas/ast/types/TypeKind.java
35 35
	EnumeratedType(3),
36 36
	ListType(4),
37 37
	MapType(5),
38
	QrType(6),
38
//	QrType(6),               // no longer supported
39 39
	TupleType(7),
40 40
	FunctionType(8),
41 41
	OoActionSystemType(9),
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/cadp/CadpType.java
237 237
				EmitDefinition((OoActionSystemType)aType, emitter);
238 238
				break;
239 239

  
240
			case QrType:
241
				throw new UnsupportedOperationException(); // does not make sense in CADP target.
242

  
243 240
			case FunctionType:
244 241
				emittedTypes.add(typename);
245 242
				EmitDefinition((FunctionType)aType, emitter);
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/java/JavaExpression.java
184 184
	@Override
185 185
	public void visit(TypeExpression typeExpression)
186 186
	{
187
		if (typeExpression.type().kind() != TypeKind.QrType &&
188
				typeExpression.type().kind() != TypeKind.EnumeratedType)
187
		if (typeExpression.type().kind() != TypeKind.EnumeratedType)
189 188
			m_emitter.Append(GetIdentifierString(typeExpression.type().identifier().tokenText()));
190 189
	}
191 190

  
......
316 315
	@Override
317 316
	public void visit(AccessExpression accessExpression)
318 317
	{
319
		if (accessExpression.left().type().kind() != TypeKind.QrType &&
320
				accessExpression.left().type().kind() != TypeKind.EnumeratedType)
318
		if (accessExpression.left().type().kind() != TypeKind.EnumeratedType)
321 319
		{
322 320
			// enums and qr types are directly (statically) converted to nums...
323 321
			VisitSub(accessExpression.left(), accessExpression);
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/prolog/OoaPrologExpression.java
186 186
		case minus:  // T_MINUS:
187 187
			return "-";
188 188
		case less:
189
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? "<" : "#<";
189
			return !isNumericBinary(expression) ? "<" : "#<";
190 190
		case lessequal:
191
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? "=<" : "#=<";
191
			return !isNumericBinary(expression) ? "=<" : "#=<";
192 192
		case greater:
193
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? ">" : "#>";
193
			return !isNumericBinary(expression) ? ">" : "#>";
194 194
		case greaterequal:
195
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? ">=" : "#>=";
195
			return !isNumericBinary(expression) ? ">=" : "#>=";
196 196
		case equal:
197
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? "==" : "#=";
197
			return !isNumericBinary(expression) ? "==" : "#=";
198 198
		case notequal:
199
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? "\\=" : "#\\=";
199
			return !isNumericBinary(expression) ? "\\=" : "#\\=";
200 200
		case and:    // T_AND:
201 201
			throw new NotImplementedException(); // implemented in binaryoperator
202 202
		case or:     // T_OR:
......
282 282
	@Override
283 283
	public void visit(TypeExpression typeExpression)
284 284
	{
285
		if (typeExpression.type().kind() != TypeKind.QrType &&
286
				typeExpression.type().kind() != TypeKind.EnumeratedType)
285
		if (typeExpression.type().kind() != TypeKind.EnumeratedType)
287 286
		{
288 287
			m_emitter.Append(GetIdentifierString(typeExpression.type().identifier()));
289 288
		}
......
412 411
	@Override
413 412
	public void visit(AccessExpression accessExpression)
414 413
	{
415
		if (accessExpression.left().type().kind() != TypeKind.QrType &&
416
				accessExpression.left().type().kind() != TypeKind.EnumeratedType &&
417
				!(accessExpression.right().kind() == ExpressionKind.Identifier &&
418
				((IdentifierExpression)accessExpression.right()).identifier().kind() == IdentifierKind.AttributeIdentifier))
414
		if (accessExpression.left().type().kind() != TypeKind.EnumeratedType &&
415
		    !(accessExpression.right().kind() == ExpressionKind.Identifier &&
416
		    ((IdentifierExpression)accessExpression.right()).identifier().kind() == IdentifierKind.AttributeIdentifier))
419 417
		{
420 418
			assert(m_tmpVars.size() == 0);
421 419
			// enums and qr types are directly (statically) converted to nums...
......
541 539
		default:
542 540
			m_emitter.Append(leftcode.toString());
543 541
			m_emitter.Append(rightcode.toString());
544
			if (binaryOperator.left().type().kind() == TypeKind.QrType)
545
				m_emitter.Append("qEval");
546 542
			//m_emitter.Append("(");
547 543
			if (binaryOperator.type().kind() == TypeKind.IntType)
548 544
				m_emitter.AppendLine(String.format(" %s #= (%s %s %s), ",
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/prolog/OoaPrologIdentifier.java
132 132
			m_emitter.Append(String.format("list_%s%s", typeIdentifier.prefix, typeIdentifier.tokenText()));
133 133
			break;
134 134

  
135
		case QrType:
136 135
		case MapType:
137 136
			throw new NotImplementedException();
138 137

  
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/prolog/OoaPrologVisitor.java
40 40
import org.momut.ooas.ast.identifiers.TypeIdentifier;
41 41
import org.momut.ooas.ast.statements.Block;
42 42
import org.momut.ooas.ast.types.FunctionType;
43
import org.momut.ooas.ast.types.TypeKind;
44 43
import org.momut.ooas.ast.types.FunctionType.FunctionTypeEnum;
45 44
import org.momut.ooas.codegen.OoasCodeEmitter;
46 45
import org.momut.ooas.parser.ParserState;
......
355 354
				x.Accept(pid);
356 355
				x.type().Accept(ptype);
357 356

  
358
				final String key = x.type().kind() != TypeKind.QrType ? ptype.toString() : "qvar";
357
				final String key = ptype.toString();
359 358
				if (varlist.containsKey(key))
360 359
				{
361 360
					varlist.get(key).append(String.format(", %s", pid.toString()));
trunk/compiler/ooasCompiler/src/org/momut/ooas/codegen/prologsymbolic/OoaPrologSymbolicExpression.java
126 126
		case minus:  // T_MINUS:
127 127
			return "-";
128 128
		case less:
129
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? "<" : "#<";
129
			return !isNumericBinary(expression) ? "<" : "#<";
130 130
		case lessequal:
131
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? "=<" : "#=<";
131
			return !isNumericBinary(expression) ? "=<" : "#=<";
132 132
		case greater:
133
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? ">" : "#>";
133
			return !isNumericBinary(expression) ? ">" : "#>";
134 134
		case greaterequal:
135
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? ">=" : "#>=";
135
			return !isNumericBinary(expression) ? ">=" : "#>=";
136 136
		case equal:
137
			return resultingType.kind() == TypeKind.QrType ? "==" : "#=";
137
			return "#=";
138 138
		case notequal:
139
			return resultingType.kind() == TypeKind.QrType || !isNumericBinary(expression) ? "\\=" : "#\\=";
139
			return !isNumericBinary(expression) ? "\\=" : "#\\=";
140 140
		case and:    // T_AND:
141 141
			throw new NotImplementedException(); // implemented in binaryoperator
142 142
		case or:     // T_OR:
......
360 360
		default:
361 361
			m_emitter.Append(leftcode.toString());
362 362
			m_emitter.Append(rightcode.toString());
363
			if (binaryOperator.left().type().kind() == TypeKind.QrType)
364
				m_emitter.Append("qEval");
365 363

  
366 364
			//do not use #= for assignments in the symbolic backend
367 365
			m_emitter.AppendLine(String.format(" %s = (%s %s %s), ",
trunk/compiler/ooasCompiler/src/org/momut/ooas/parser/ooaCustomParser.java
461 461
			doError(varname, String.format("%s lacks initializer!", varname.getText()));
462 462
		}
463 463
		if (isObs == true || isCtr == true)
464
			if (aType.kind() != TypeKind.QrType)
465
				doError(varname, "'obs' or 'ctr' on attributes only allowed for qualitative types");
464
			doError(varname, "'obs' or 'ctr' on attributes not allowed");
466 465

  
467 466

  
468 467
		final AttributeIdentifier var = new AttributeIdentifier(varname, aType, GetScope(), anExpr, isStatic, isObs, isCtr);
trunk/compiler/ooasCompiler/src/org/momut/ooas/visitors/OoaResolveExpressionsVisitor.java
1326 1326
		case greaterequal:
1327 1327
		case less:
1328 1328
		case lessequal:
1329
			if (!((rt.IsNumeric() && lt.IsNumeric()) || (rt.IsQualitative() && lt.IsQualitative())))
1330
				return Error(expression, "Operator expects LHS and RHS to be numeric or qualitative");
1329
			if (!((rt.IsNumeric() && lt.IsNumeric()) ))
1330
				return Error(expression, "Operator expects LHS and RHS to be numeric");
1331 1331
			cover = Type.CoverType(lt, rt);
1332 1332
			if (cover != null)
1333 1333
			{

Also available in: Unified diff