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

Side by Side Diff: pkg/compiler/lib/src/constants/values.dart

Issue 2595493002: Merge CoreTypes and CoreClasses into CommonElements. (Closed)
Patch Set: Updated cf. comment Created 3 years, 12 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
« no previous file with comments | « pkg/compiler/lib/src/constants/expressions.dart ('k') | pkg/compiler/lib/src/core_types.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 library dart2js.constants.values; 5 library dart2js.constants.values;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../core_types.dart'; 8 import '../core_types.dart';
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../elements/elements.dart' 10 import '../elements/elements.dart'
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 bool get isDummy => false; 75 bool get isDummy => false;
76 76
77 bool get isNaN => false; 77 bool get isNaN => false;
78 bool get isMinusZero => false; 78 bool get isMinusZero => false;
79 bool get isZero => false; 79 bool get isZero => false;
80 bool get isOne => false; 80 bool get isOne => false;
81 bool get isPositiveInfinity => false; 81 bool get isPositiveInfinity => false;
82 bool get isNegativeInfinity => false; 82 bool get isNegativeInfinity => false;
83 83
84 // TODO(johnniwinther): Replace with a 'type' getter. 84 // TODO(johnniwinther): Replace with a 'type' getter.
85 DartType getType(CoreTypes types); 85 DartType getType(CommonElements types);
86 86
87 List<ConstantValue> getDependencies(); 87 List<ConstantValue> getDependencies();
88 88
89 accept(ConstantValueVisitor visitor, arg); 89 accept(ConstantValueVisitor visitor, arg);
90 90
91 /// The value of this constant in Dart syntax, if possible. 91 /// The value of this constant in Dart syntax, if possible.
92 /// 92 ///
93 /// For [ConstructedConstantValue]s there is no way to create a valid const 93 /// For [ConstructedConstantValue]s there is no way to create a valid const
94 /// expression from the value so the unparse of these is best effort. 94 /// expression from the value so the unparse of these is best effort.
95 /// 95 ///
(...skipping 28 matching lines...) Expand all
124 if (other is! FunctionConstantValue) return false; 124 if (other is! FunctionConstantValue) return false;
125 return identical(other.element, element); 125 return identical(other.element, element);
126 } 126 }
127 127
128 List<ConstantValue> getDependencies() => const <ConstantValue>[]; 128 List<ConstantValue> getDependencies() => const <ConstantValue>[];
129 129
130 DartString toDartString() { 130 DartString toDartString() {
131 return new DartString.literal(element.name); 131 return new DartString.literal(element.name);
132 } 132 }
133 133
134 DartType getType(CoreTypes types) => element.type; 134 DartType getType(CommonElements types) => element.type;
135 135
136 int get hashCode => (17 * element.hashCode) & 0x7fffffff; 136 int get hashCode => (17 * element.hashCode) & 0x7fffffff;
137 137
138 accept(ConstantValueVisitor visitor, arg) => visitor.visitFunction(this, arg); 138 accept(ConstantValueVisitor visitor, arg) => visitor.visitFunction(this, arg);
139 139
140 ConstantValueKind get kind => ConstantValueKind.FUNCTION; 140 ConstantValueKind get kind => ConstantValueKind.FUNCTION;
141 141
142 String toDartText() { 142 String toDartText() {
143 if (element.isStatic) { 143 if (element.isStatic) {
144 return '${element.enclosingClass.name}.${element.name}'; 144 return '${element.enclosingClass.name}.${element.name}';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 static const String JsNull = "null"; 182 static const String JsNull = "null";
183 183
184 const factory NullConstantValue() = NullConstantValue._internal; 184 const factory NullConstantValue() = NullConstantValue._internal;
185 185
186 const NullConstantValue._internal(); 186 const NullConstantValue._internal();
187 187
188 bool get isNull => true; 188 bool get isNull => true;
189 189
190 get primitiveValue => null; 190 get primitiveValue => null;
191 191
192 DartType getType(CoreTypes types) => types.nullType; 192 DartType getType(CommonElements types) => types.nullType;
193 193
194 // The magic constant has no meaning. It is just a random value. 194 // The magic constant has no meaning. It is just a random value.
195 int get hashCode => 785965825; 195 int get hashCode => 785965825;
196 196
197 DartString toDartString() => const LiteralDartString("null"); 197 DartString toDartString() => const LiteralDartString("null");
198 198
199 accept(ConstantValueVisitor visitor, arg) => visitor.visitNull(this, arg); 199 accept(ConstantValueVisitor visitor, arg) => visitor.visitNull(this, arg);
200 200
201 ConstantValueKind get kind => ConstantValueKind.NULL; 201 ConstantValueKind get kind => ConstantValueKind.NULL;
202 202
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 bool isUInt31() => primitiveValue >= 0 && primitiveValue < (1 << 31); 254 bool isUInt31() => primitiveValue >= 0 && primitiveValue < (1 << 31);
255 255
256 bool isUInt32() => primitiveValue >= 0 && primitiveValue < (1 << 32); 256 bool isUInt32() => primitiveValue >= 0 && primitiveValue < (1 << 32);
257 257
258 bool isPositive() => primitiveValue >= 0; 258 bool isPositive() => primitiveValue >= 0;
259 259
260 bool get isZero => primitiveValue == 0; 260 bool get isZero => primitiveValue == 0;
261 261
262 bool get isOne => primitiveValue == 1; 262 bool get isOne => primitiveValue == 1;
263 263
264 DartType getType(CoreTypes types) => types.intType; 264 DartType getType(CommonElements types) => types.intType;
265 265
266 // We have to override the equality operator so that ints and doubles are 266 // We have to override the equality operator so that ints and doubles are
267 // treated as separate constants. 267 // treated as separate constants.
268 // The is [:!IntConstant:] check at the beginning of the function makes sure 268 // The is [:!IntConstant:] check at the beginning of the function makes sure
269 // that we compare only equal to integer constants. 269 // that we compare only equal to integer constants.
270 bool operator ==(var other) { 270 bool operator ==(var other) {
271 if (other is! IntConstantValue) return false; 271 if (other is! IntConstantValue) return false;
272 IntConstantValue otherInt = other; 272 IntConstantValue otherInt = other;
273 return primitiveValue == otherInt.primitiveValue; 273 return primitiveValue == otherInt.primitiveValue;
274 } 274 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 bool get isMinusZero => primitiveValue == 0.0 && primitiveValue.isNegative; 315 bool get isMinusZero => primitiveValue == 0.0 && primitiveValue.isNegative;
316 316
317 bool get isZero => primitiveValue == 0.0; 317 bool get isZero => primitiveValue == 0.0;
318 318
319 bool get isOne => primitiveValue == 1.0; 319 bool get isOne => primitiveValue == 1.0;
320 320
321 bool get isPositiveInfinity => primitiveValue == double.INFINITY; 321 bool get isPositiveInfinity => primitiveValue == double.INFINITY;
322 322
323 bool get isNegativeInfinity => primitiveValue == -double.INFINITY; 323 bool get isNegativeInfinity => primitiveValue == -double.INFINITY;
324 324
325 DartType getType(CoreTypes types) => types.doubleType; 325 DartType getType(CommonElements types) => types.doubleType;
326 326
327 bool operator ==(var other) { 327 bool operator ==(var other) {
328 if (other is! DoubleConstantValue) return false; 328 if (other is! DoubleConstantValue) return false;
329 DoubleConstantValue otherDouble = other; 329 DoubleConstantValue otherDouble = other;
330 double otherValue = otherDouble.primitiveValue; 330 double otherValue = otherDouble.primitiveValue;
331 if (primitiveValue == 0.0 && otherValue == 0.0) { 331 if (primitiveValue == 0.0 && otherValue == 0.0) {
332 return primitiveValue.isNegative == otherValue.isNegative; 332 return primitiveValue.isNegative == otherValue.isNegative;
333 } else if (primitiveValue.isNaN) { 333 } else if (primitiveValue.isNaN) {
334 return otherValue.isNaN; 334 return otherValue.isNaN;
335 } else { 335 } else {
(...skipping 16 matching lines...) Expand all
352 352
353 abstract class BoolConstantValue extends PrimitiveConstantValue { 353 abstract class BoolConstantValue extends PrimitiveConstantValue {
354 factory BoolConstantValue(value) { 354 factory BoolConstantValue(value) {
355 return value ? new TrueConstantValue() : new FalseConstantValue(); 355 return value ? new TrueConstantValue() : new FalseConstantValue();
356 } 356 }
357 357
358 const BoolConstantValue._internal(); 358 const BoolConstantValue._internal();
359 359
360 bool get isBool => true; 360 bool get isBool => true;
361 361
362 DartType getType(CoreTypes types) => types.boolType; 362 DartType getType(CommonElements types) => types.boolType;
363 363
364 BoolConstantValue negate(); 364 BoolConstantValue negate();
365 365
366 accept(ConstantValueVisitor visitor, arg) => visitor.visitBool(this, arg); 366 accept(ConstantValueVisitor visitor, arg) => visitor.visitBool(this, arg);
367 367
368 ConstantValueKind get kind => ConstantValueKind.BOOL; 368 ConstantValueKind get kind => ConstantValueKind.BOOL;
369 369
370 String toStructuredText() => 'BoolConstant(${toDartText()})'; 370 String toStructuredText() => 'BoolConstant(${toDartText()})';
371 } 371 }
372 372
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // DartString. 420 // DartString.
421 StringConstantValue(DartString value) 421 StringConstantValue(DartString value)
422 : this.primitiveValue = value, 422 : this.primitiveValue = value,
423 this.hashCode = value.slowToString().hashCode; 423 this.hashCode = value.slowToString().hashCode;
424 424
425 StringConstantValue.fromString(String value) 425 StringConstantValue.fromString(String value)
426 : this(new DartString.literal(value)); 426 : this(new DartString.literal(value));
427 427
428 bool get isString => true; 428 bool get isString => true;
429 429
430 DartType getType(CoreTypes types) => types.stringType; 430 DartType getType(CommonElements types) => types.stringType;
431 431
432 bool operator ==(var other) { 432 bool operator ==(var other) {
433 if (identical(this, other)) return true; 433 if (identical(this, other)) return true;
434 if (other is! StringConstantValue) return false; 434 if (other is! StringConstantValue) return false;
435 StringConstantValue otherString = other; 435 StringConstantValue otherString = other;
436 return hashCode == otherString.hashCode && 436 return hashCode == otherString.hashCode &&
437 primitiveValue == otherString.primitiveValue; 437 primitiveValue == otherString.primitiveValue;
438 } 438 }
439 439
440 DartString toDartString() => primitiveValue; 440 DartString toDartString() => primitiveValue;
(...skipping 10 matching lines...) Expand all
451 String toStructuredText() => 'StringConstant(${toDartText()})'; 451 String toStructuredText() => 'StringConstant(${toDartText()})';
452 } 452 }
453 453
454 abstract class ObjectConstantValue extends ConstantValue { 454 abstract class ObjectConstantValue extends ConstantValue {
455 final InterfaceType type; 455 final InterfaceType type;
456 456
457 ObjectConstantValue(this.type); 457 ObjectConstantValue(this.type);
458 458
459 bool get isObject => true; 459 bool get isObject => true;
460 460
461 DartType getType(CoreTypes types) => type; 461 DartType getType(CommonElements types) => type;
462 462
463 void _unparseTypeArguments(StringBuffer sb) { 463 void _unparseTypeArguments(StringBuffer sb) {
464 if (!type.treatAsRaw) { 464 if (!type.treatAsRaw) {
465 sb.write('<'); 465 sb.write('<');
466 sb.write(type.typeArguments.join(', ')); 466 sb.write(type.typeArguments.join(', '));
467 sb.write('>'); 467 sb.write('>');
468 } 468 }
469 } 469 }
470 } 470 }
471 471
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 649 }
650 650
651 int get hashCode => dispatchedType.hashCode * 43; 651 int get hashCode => dispatchedType.hashCode * 43;
652 652
653 List<ConstantValue> getDependencies() => const <ConstantValue>[]; 653 List<ConstantValue> getDependencies() => const <ConstantValue>[];
654 654
655 accept(ConstantValueVisitor visitor, arg) { 655 accept(ConstantValueVisitor visitor, arg) {
656 return visitor.visitInterceptor(this, arg); 656 return visitor.visitInterceptor(this, arg);
657 } 657 }
658 658
659 DartType getType(CoreTypes types) => const DynamicType(); 659 DartType getType(CommonElements types) => const DynamicType();
660 660
661 ConstantValueKind get kind => ConstantValueKind.INTERCEPTOR; 661 ConstantValueKind get kind => ConstantValueKind.INTERCEPTOR;
662 662
663 String toDartText() { 663 String toDartText() {
664 return 'interceptor($dispatchedType)'; 664 return 'interceptor($dispatchedType)';
665 } 665 }
666 666
667 String toStructuredText() { 667 String toStructuredText() {
668 return 'InterceptorConstant(${dispatchedType.getStringAsDeclared("o")})'; 668 return 'InterceptorConstant(${dispatchedType.getStringAsDeclared("o")})';
669 } 669 }
(...skipping 12 matching lines...) Expand all
682 } 682 }
683 683
684 get hashCode => payload.hashCode * 17 + valueKind.hashCode; 684 get hashCode => payload.hashCode * 17 + valueKind.hashCode;
685 685
686 List<ConstantValue> getDependencies() => const <ConstantValue>[]; 686 List<ConstantValue> getDependencies() => const <ConstantValue>[];
687 687
688 accept(ConstantValueVisitor visitor, arg) { 688 accept(ConstantValueVisitor visitor, arg) {
689 return visitor.visitSynthetic(this, arg); 689 return visitor.visitSynthetic(this, arg);
690 } 690 }
691 691
692 DartType getType(CoreTypes types) => const DynamicType(); 692 DartType getType(CommonElements types) => const DynamicType();
693 693
694 ConstantValueKind get kind => ConstantValueKind.SYNTHETIC; 694 ConstantValueKind get kind => ConstantValueKind.SYNTHETIC;
695 695
696 String toDartText() => 'synthetic($valueKind, $payload)'; 696 String toDartText() => 'synthetic($valueKind, $payload)';
697 697
698 String toStructuredText() => 'SyntheticConstant($valueKind, $payload)'; 698 String toStructuredText() => 'SyntheticConstant($valueKind, $payload)';
699 } 699 }
700 700
701 class ConstructedConstantValue extends ObjectConstantValue { 701 class ConstructedConstantValue extends ObjectConstantValue {
702 // TODO(johnniwinther): Make [fields] private to avoid misuse of the map 702 // TODO(johnniwinther): Make [fields] private to avoid misuse of the map
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 referenced == other.referenced && 786 referenced == other.referenced &&
787 prefix == other.prefix; 787 prefix == other.prefix;
788 } 788 }
789 789
790 get hashCode => (referenced.hashCode * 17 + prefix.hashCode) & 0x3fffffff; 790 get hashCode => (referenced.hashCode * 17 + prefix.hashCode) & 0x3fffffff;
791 791
792 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; 792 List<ConstantValue> getDependencies() => <ConstantValue>[referenced];
793 793
794 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); 794 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg);
795 795
796 DartType getType(CoreTypes types) => referenced.getType(types); 796 DartType getType(CommonElements types) => referenced.getType(types);
797 797
798 ConstantValueKind get kind => ConstantValueKind.DEFERRED; 798 ConstantValueKind get kind => ConstantValueKind.DEFERRED;
799 799
800 String toDartText() => 'deferred(${referenced.toDartText()})'; 800 String toDartText() => 'deferred(${referenced.toDartText()})';
801 801
802 String toStructuredText() { 802 String toStructuredText() {
803 return 'DeferredConstant(${referenced.toStructuredText()})'; 803 return 'DeferredConstant(${referenced.toStructuredText()})';
804 } 804 }
805 } 805 }
806 806
807 /// A constant value resulting from a non constant or erroneous constant 807 /// A constant value resulting from a non constant or erroneous constant
808 /// expression. 808 /// expression.
809 // TODO(johnniwinther): Expand this to contain the error kind. 809 // TODO(johnniwinther): Expand this to contain the error kind.
810 class NonConstantValue extends ConstantValue { 810 class NonConstantValue extends ConstantValue {
811 bool get isConstant => false; 811 bool get isConstant => false;
812 812
813 @override 813 @override
814 accept(ConstantValueVisitor visitor, arg) { 814 accept(ConstantValueVisitor visitor, arg) {
815 return visitor.visitNonConstant(this, arg); 815 return visitor.visitNonConstant(this, arg);
816 } 816 }
817 817
818 @override 818 @override
819 List<ConstantValue> getDependencies() => const <ConstantValue>[]; 819 List<ConstantValue> getDependencies() => const <ConstantValue>[];
820 820
821 @override 821 @override
822 DartType getType(CoreTypes types) => const DynamicType(); 822 DartType getType(CommonElements types) => const DynamicType();
823 823
824 ConstantValueKind get kind => ConstantValueKind.NON_CONSTANT; 824 ConstantValueKind get kind => ConstantValueKind.NON_CONSTANT;
825 825
826 @override 826 @override
827 String toStructuredText() => 'NonConstant'; 827 String toStructuredText() => 'NonConstant';
828 828
829 @override 829 @override
830 String toDartText() => '>>non-constant<<'; 830 String toDartText() => '>>non-constant<<';
831 } 831 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/constants/expressions.dart ('k') | pkg/compiler/lib/src/core_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698