| OLD | NEW |
| 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 class Constant implements Hashable { | 5 class Constant implements Hashable { |
| 6 const Constant(); | 6 const Constant(); |
| 7 | 7 |
| 8 bool isNull() => false; | 8 bool isNull() => false; |
| 9 bool isBool() => false; | 9 bool isBool() => false; |
| 10 bool isTrue() => false; | 10 bool isTrue() => false; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 List<Constant> getDependencies() => const <Constant>[]; | 81 List<Constant> getDependencies() => const <Constant>[]; |
| 82 abstract DartString toDartString(); | 82 abstract DartString toDartString(); |
| 83 | 83 |
| 84 void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) { | 84 void _writeCanonicalizedJsCode(CodeBuffer buffer, ConstantHandler handler) { |
| 85 _writeJsCode(buffer, handler); | 85 _writeJsCode(buffer, handler); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 class NullConstant extends PrimitiveConstant { | 89 class NullConstant extends PrimitiveConstant { |
| 90 /** The value a Dart null is compiled to in JavaScript. */ | 90 /** The value a Dart null is compiled to in JavaScript. */ |
| 91 static final String JsNull = "null"; | 91 static const String JsNull = "null"; |
| 92 | 92 |
| 93 factory NullConstant() => const NullConstant._internal(); | 93 factory NullConstant() => const NullConstant._internal(); |
| 94 const NullConstant._internal(); | 94 const NullConstant._internal(); |
| 95 bool isNull() => true; | 95 bool isNull() => true; |
| 96 get value => null; | 96 get value => null; |
| 97 | 97 |
| 98 void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) { | 98 void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) { |
| 99 buffer.add(JsNull); | 99 buffer.add(JsNull); |
| 100 } | 100 } |
| 101 | 101 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 List<Constant> getDependencies() => entries; | 346 List<Constant> getDependencies() => entries; |
| 347 | 347 |
| 348 int get length => entries.length; | 348 int get length => entries.length; |
| 349 } | 349 } |
| 350 | 350 |
| 351 class MapConstant extends ObjectConstant { | 351 class MapConstant extends ObjectConstant { |
| 352 /** | 352 /** |
| 353 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript | 353 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript |
| 354 * object. It would change the prototype chain. | 354 * object. It would change the prototype chain. |
| 355 */ | 355 */ |
| 356 static final String PROTO_PROPERTY = "__proto__"; | 356 static const String PROTO_PROPERTY = "__proto__"; |
| 357 | 357 |
| 358 /** The dart class implementing constant map literals. */ | 358 /** The dart class implementing constant map literals. */ |
| 359 static final SourceString DART_CLASS = const SourceString("ConstantMap"); | 359 static const SourceString DART_CLASS = const SourceString("ConstantMap"); |
| 360 static final SourceString DART_PROTO_CLASS = | 360 static const SourceString DART_PROTO_CLASS = |
| 361 const SourceString("ConstantProtoMap"); | 361 const SourceString("ConstantProtoMap"); |
| 362 static final SourceString LENGTH_NAME = const SourceString("length"); | 362 static const SourceString LENGTH_NAME = const SourceString("length"); |
| 363 static final SourceString JS_OBJECT_NAME = const SourceString("_jsObject"); | 363 static const SourceString JS_OBJECT_NAME = const SourceString("_jsObject"); |
| 364 static final SourceString KEYS_NAME = const SourceString("_keys"); | 364 static const SourceString KEYS_NAME = const SourceString("_keys"); |
| 365 static final SourceString PROTO_VALUE = const SourceString("_protoValue"); | 365 static const SourceString PROTO_VALUE = const SourceString("_protoValue"); |
| 366 | 366 |
| 367 final ListConstant keys; | 367 final ListConstant keys; |
| 368 final List<Constant> values; | 368 final List<Constant> values; |
| 369 final Constant protoValue; | 369 final Constant protoValue; |
| 370 int _hashCode; | 370 int _hashCode; |
| 371 | 371 |
| 372 MapConstant(Type type, this.keys, this.values, this.protoValue) | 372 MapConstant(Type type, this.keys, this.values, this.protoValue) |
| 373 : super(type) { | 373 : super(type) { |
| 374 // TODO(floitsch): create a better hash. | 374 // TODO(floitsch): create a better hash. |
| 375 int hash = 0; | 375 int hash = 0; |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 */ | 625 */ |
| 626 List<VariableElement> getStaticNonFinalFieldsForEmission() { | 626 List<VariableElement> getStaticNonFinalFieldsForEmission() { |
| 627 return initialVariableValues.getKeys().filter((element) { | 627 return initialVariableValues.getKeys().filter((element) { |
| 628 return element.kind == ElementKind.FIELD | 628 return element.kind == ElementKind.FIELD |
| 629 && !element.isInstanceMember() | 629 && !element.isInstanceMember() |
| 630 && !element.modifiers.isFinal(); | 630 && !element.modifiers.isFinal(); |
| 631 }); | 631 }); |
| 632 } | 632 } |
| 633 | 633 |
| 634 /** | 634 /** |
| 635 * Returns a [List] of static final fields that need to be initialized. The | 635 * Returns a [List] of static const fields that need to be initialized. The |
| 636 * list must be evaluated in order since the fields might depend on each | 636 * list must be evaluated in order since the fields might depend on each |
| 637 * other. | 637 * other. |
| 638 */ | 638 */ |
| 639 List<VariableElement> getStaticFinalFieldsForEmission() { | 639 List<VariableElement> getStaticFinalFieldsForEmission() { |
| 640 return initialVariableValues.getKeys().filter((element) { | 640 return initialVariableValues.getKeys().filter((element) { |
| 641 return element.kind == ElementKind.FIELD | 641 return element.kind == ElementKind.FIELD |
| 642 && !element.isInstanceMember() | 642 && !element.isInstanceMember() |
| 643 && element.modifiers.isFinal(); | 643 && element.modifiers.isFinal(); |
| 644 }); | 644 }); |
| 645 } | 645 } |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 Constant fieldValue = fieldValues[field]; | 1210 Constant fieldValue = fieldValues[field]; |
| 1211 if (fieldValue === null) { | 1211 if (fieldValue === null) { |
| 1212 // Use the default value. | 1212 // Use the default value. |
| 1213 fieldValue = compiler.compileVariable(field); | 1213 fieldValue = compiler.compileVariable(field); |
| 1214 } | 1214 } |
| 1215 jsNewArguments.add(fieldValue); | 1215 jsNewArguments.add(fieldValue); |
| 1216 }); | 1216 }); |
| 1217 return jsNewArguments; | 1217 return jsNewArguments; |
| 1218 } | 1218 } |
| 1219 } | 1219 } |
| OLD | NEW |