| 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 library dart2js.constant_system.js; | 5 library dart2js.constant_system.js; |
| 6 | 6 |
| 7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
| 10 import '../constant_system_dart.dart'; | 10 import '../constant_system_dart.dart'; |
| 11 import '../core_types.dart' show CoreTypes; | 11 import '../core_types.dart' show CoreTypes; |
| 12 import '../dart_types.dart'; | 12 import '../dart_types.dart'; |
| 13 import '../elements/elements.dart' show ClassElement; | 13 import '../elements/elements.dart' show ClassElement, FieldElement; |
| 14 import '../tree/tree.dart' show DartString, LiteralDartString; | 14 import '../tree/tree.dart' show DartString, LiteralDartString; |
| 15 import 'js_backend.dart'; | 15 import 'js_backend.dart'; |
| 16 | 16 |
| 17 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); | 17 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); |
| 18 | 18 |
| 19 class JavaScriptBitNotOperation extends BitNotOperation { | 19 class JavaScriptBitNotOperation extends BitNotOperation { |
| 20 const JavaScriptBitNotOperation(); | 20 const JavaScriptBitNotOperation(); |
| 21 | 21 |
| 22 ConstantValue fold(ConstantValue constant) { | 22 ConstantValue fold(ConstantValue constant) { |
| 23 if (JAVA_SCRIPT_CONSTANT_SYSTEM.isInt(constant)) { | 23 if (JAVA_SCRIPT_CONSTANT_SYSTEM.isInt(constant)) { |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 List<DartType> typeArgument = sourceType.typeArguments; | 338 List<DartType> typeArgument = sourceType.typeArguments; |
| 339 InterfaceType type; | 339 InterfaceType type; |
| 340 if (sourceType.treatAsRaw) { | 340 if (sourceType.treatAsRaw) { |
| 341 type = classElement.rawType; | 341 type = classElement.rawType; |
| 342 } else { | 342 } else { |
| 343 type = new InterfaceType(classElement, typeArgument); | 343 type = new InterfaceType(classElement, typeArgument); |
| 344 } | 344 } |
| 345 return new JavaScriptMapConstant( | 345 return new JavaScriptMapConstant( |
| 346 type, keysList, values, protoValue, onlyStringKeys); | 346 type, keysList, values, protoValue, onlyStringKeys); |
| 347 } | 347 } |
| 348 |
| 349 @override |
| 350 ConstantValue createSymbol(Compiler compiler, String text) { |
| 351 // TODO(johnniwinther): Create a backend agnostic value. |
| 352 InterfaceType type = compiler.coreTypes.symbolType; |
| 353 ConstantValue argument = createString(new DartString.literal(text)); |
| 354 Map<FieldElement, ConstantValue> fields = <FieldElement, ConstantValue>{}; |
| 355 JavaScriptBackend backend = compiler.backend; |
| 356 backend.helpers.symbolImplementationClass.forEachInstanceField( |
| 357 (ClassElement enclosingClass, FieldElement field) { |
| 358 fields[field] = argument; |
| 359 }); |
| 360 assert(fields.length == 1); |
| 361 return new ConstructedConstantValue(type, fields); |
| 362 } |
| 348 } | 363 } |
| 349 | 364 |
| 350 class JavaScriptMapConstant extends MapConstantValue { | 365 class JavaScriptMapConstant extends MapConstantValue { |
| 351 /** | 366 /** |
| 352 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript | 367 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript |
| 353 * object. It would change the prototype chain. | 368 * object. It would change the prototype chain. |
| 354 */ | 369 */ |
| 355 static const LiteralDartString PROTO_PROPERTY = | 370 static const LiteralDartString PROTO_PROPERTY = |
| 356 const LiteralDartString("__proto__"); | 371 const LiteralDartString("__proto__"); |
| 357 | 372 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 382 result.add(keyList); | 397 result.add(keyList); |
| 383 } else { | 398 } else { |
| 384 // Add the keys individually to avoid generating an unused list constant | 399 // Add the keys individually to avoid generating an unused list constant |
| 385 // for the keys. | 400 // for the keys. |
| 386 result.addAll(keys); | 401 result.addAll(keys); |
| 387 } | 402 } |
| 388 result.addAll(values); | 403 result.addAll(values); |
| 389 return result; | 404 return result; |
| 390 } | 405 } |
| 391 } | 406 } |
| OLD | NEW |