Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: lib/compiler/implementation/ssa/types.dart

Issue 10700104: Fix more type intersection stuff. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/compiler/dart2js/type_combination_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 abstract class HType { 5 abstract class HType {
6 const HType(); 6 const HType();
7 7
8 /** 8 /**
9 * Returns an [HType] that represents [type] and all types that have 9 * Returns an [HType] that represents [type] and all types that have
10 * [type] as supertype. 10 * [type] as supertype.
(...skipping 22 matching lines...) Expand all
33 || Elements.isListSupertype(element, compiler)) { 33 || Elements.isListSupertype(element, compiler)) {
34 return new HBoundedPotentialPrimitiveArray(type, canBeNull); 34 return new HBoundedPotentialPrimitiveArray(type, canBeNull);
35 } else if (Elements.isStringSupertype(element, compiler)) { 35 } else if (Elements.isStringSupertype(element, compiler)) {
36 return new HBoundedPotentialPrimitiveString(type, canBeNull); 36 return new HBoundedPotentialPrimitiveString(type, canBeNull);
37 } else { 37 } else {
38 return canBeNull ? new HBoundedType.withNull(type) 38 return canBeNull ? new HBoundedType.withNull(type)
39 : new HBoundedType.nonNull(type); 39 : new HBoundedType.nonNull(type);
40 } 40 }
41 } 41 }
42 42
43 static final HType CONFLICTING = const HAnalysisType("conflicting"); 43 static final HType CONFLICTING = const HConflictingType();
44 static final HType UNKNOWN = const HAnalysisType("unknown"); 44 static final HType UNKNOWN = const HAnalysisType("unknown");
45 static final HType BOOLEAN = const HBooleanType(); 45 static final HType BOOLEAN = const HBooleanType();
46 static final HType NUMBER = const HNumberType(); 46 static final HType NUMBER = const HNumberType();
47 static final HType INTEGER = const HIntegerType(); 47 static final HType INTEGER = const HIntegerType();
48 static final HType DOUBLE = const HDoubleType(); 48 static final HType DOUBLE = const HDoubleType();
49 static final HType INDEXABLE_PRIMITIVE = const HIndexablePrimitiveType(); 49 static final HType INDEXABLE_PRIMITIVE = const HIndexablePrimitiveType();
50 static final HType STRING = const HStringType(); 50 static final HType STRING = const HStringType();
51 static final HType READABLE_ARRAY = const HReadableArrayType(); 51 static final HType READABLE_ARRAY = const HReadableArrayType();
52 static final HType MUTABLE_ARRAY = const HMutableArrayType(); 52 static final HType MUTABLE_ARRAY = const HMutableArrayType();
53 static final HType EXTENDABLE_ARRAY = const HExtendableArrayType(); 53 static final HType EXTENDABLE_ARRAY = const HExtendableArrayType();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 HType combine(HType other) { 132 HType combine(HType other) {
133 if (isUnknown()) return other; 133 if (isUnknown()) return other;
134 if (other.isUnknown()) return this; 134 if (other.isUnknown()) return this;
135 return HType.CONFLICTING; 135 return HType.CONFLICTING;
136 } 136 }
137 137
138 HType union(HType other) => combine(other); 138 HType union(HType other) => combine(other);
139 HType intersection(HType other) => combine(other); 139 HType intersection(HType other) => combine(other);
140 } 140 }
141 141
142 class HConflictingType extends HAnalysisType {
143 const HConflictingType() : super("conflicting");
144 bool canBePrimitive() => false;
145 bool canBeNull() => false;
146 }
147
142 abstract class HPrimitiveType extends HType { 148 abstract class HPrimitiveType extends HType {
143 const HPrimitiveType(); 149 const HPrimitiveType();
144 bool isPrimitive() => true; 150 bool isPrimitive() => true;
145 bool canBePrimitive() => true; 151 bool canBePrimitive() => true;
146 } 152 }
147 153
148 class HNullType extends HPrimitiveType { 154 class HNullType extends HPrimitiveType {
149 const HNullType(); 155 const HNullType();
150 bool canBeNull() => true; 156 bool canBeNull() => true;
151 bool isNull() => true; 157 bool isNull() => true;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; 309 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL;
304 if (other.isNull()) return HType.INTEGER_OR_NULL; 310 if (other.isNull()) return HType.INTEGER_OR_NULL;
305 return HType.CONFLICTING; 311 return HType.CONFLICTING;
306 } 312 }
307 313
308 HType intersection(HType other) { 314 HType intersection(HType other) {
309 if (other.isUnknown()) return HType.INTEGER_OR_NULL; 315 if (other.isUnknown()) return HType.INTEGER_OR_NULL;
310 if (other.isIntegerOrNull()) return HType.INTEGER_OR_NULL; 316 if (other.isIntegerOrNull()) return HType.INTEGER_OR_NULL;
311 if (other.isInteger()) return HType.INTEGER; 317 if (other.isInteger()) return HType.INTEGER;
312 if (other.isDouble()) return HType.CONFLICTING; 318 if (other.isDouble()) return HType.CONFLICTING;
313 if (other.isDoubleOrNull()) return HType.CONFLICTING; 319 if (other.isDoubleOrNull()) return HType.NULL;
314 if (other.isNumber()) return HType.INTEGER; 320 if (other.isNumber()) return HType.INTEGER;
315 if (other.isNumberOrNull()) return HType.INTEGER_OR_NULL; 321 if (other.isNumberOrNull()) return HType.INTEGER_OR_NULL;
316 if (other.canBeNull()) return HType.NULL; 322 if (other.canBeNull()) return HType.NULL;
317 return HType.CONFLICTING; 323 return HType.CONFLICTING;
318 } 324 }
319 } 325 }
320 326
321 class HIntegerType extends HNumberType { 327 class HIntegerType extends HNumberType {
322 const HIntegerType(); 328 const HIntegerType();
323 bool isInteger() => true; 329 bool isInteger() => true;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (other.isDoubleOrNull()) return HType.DOUBLE_OR_NULL; 369 if (other.isDoubleOrNull()) return HType.DOUBLE_OR_NULL;
364 if (other.isDouble()) return HType.DOUBLE_OR_NULL; 370 if (other.isDouble()) return HType.DOUBLE_OR_NULL;
365 if (other.isNumber()) return HType.NUMBER_OR_NULL; 371 if (other.isNumber()) return HType.NUMBER_OR_NULL;
366 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL; 372 if (other.isNumberOrNull()) return HType.NUMBER_OR_NULL;
367 if (other.isNull()) return HType.DOUBLE_OR_NULL; 373 if (other.isNull()) return HType.DOUBLE_OR_NULL;
368 return HType.CONFLICTING; 374 return HType.CONFLICTING;
369 } 375 }
370 376
371 HType intersection(HType other) { 377 HType intersection(HType other) {
372 if (other.isUnknown()) return HType.DOUBLE_OR_NULL; 378 if (other.isUnknown()) return HType.DOUBLE_OR_NULL;
373 if (other.isIntegerOrNull()) return HType.CONFLICTING; 379 if (other.isIntegerOrNull()) return HType.NULL;
374 if (other.isInteger()) return HType.CONFLICTING; 380 if (other.isInteger()) return HType.CONFLICTING;
375 if (other.isDouble()) return HType.DOUBLE; 381 if (other.isDouble()) return HType.DOUBLE;
376 if (other.isDoubleOrNull()) return HType.DOUBLE_OR_NULL; 382 if (other.isDoubleOrNull()) return HType.DOUBLE_OR_NULL;
377 if (other.isNumber()) return HType.DOUBLE; 383 if (other.isNumber()) return HType.DOUBLE;
378 if (other.isNumberOrNull()) return HType.DOUBLE_OR_NULL; 384 if (other.isNumberOrNull()) return HType.DOUBLE_OR_NULL;
379 if (other.canBeNull()) return HType.NULL; 385 if (other.canBeNull()) return HType.NULL;
380 return HType.CONFLICTING; 386 return HType.CONFLICTING;
381 } 387 }
382 } 388 }
383 389
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 HType intersection(HType other) { 739 HType intersection(HType other) {
734 if (other.isString()) return HType.STRING; 740 if (other.isString()) return HType.STRING;
735 if (other.isStringOrNull()) { 741 if (other.isStringOrNull()) {
736 return canBeNull() ? HType.STRING_OR_NULL : HType.STRING; 742 return canBeNull() ? HType.STRING_OR_NULL : HType.STRING;
737 } 743 }
738 if (other.isReadableArray()) return HType.CONFLICTING; 744 if (other.isReadableArray()) return HType.CONFLICTING;
739 if (other.isIndexablePrimitive()) return HType.STRING; 745 if (other.isIndexablePrimitive()) return HType.STRING;
740 return super.intersection(other); 746 return super.intersection(other);
741 } 747 }
742 } 748 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/type_combination_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698