Revision 10
Added by Willibald K. over 8 years ago
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; |
Also available in: Unified diff
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