| 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 '../constant_system_dart.dart'; | 7 import '../constant_system_dart.dart'; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
| 10 import '../common_elements.dart' show CommonElements; | 10 import '../common_elements.dart' show CommonElements; |
| 11 import '../elements/types.dart'; | 11 import '../elements/types.dart'; |
| 12 import '../elements/entities.dart'; | 12 import '../elements/entities.dart'; |
| 13 import '../tree/dartstring.dart' show DartString, LiteralDartString; | |
| 14 | 13 |
| 15 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); | 14 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); |
| 16 | 15 |
| 17 class JavaScriptBitNotOperation extends BitNotOperation { | 16 class JavaScriptBitNotOperation extends BitNotOperation { |
| 18 const JavaScriptBitNotOperation(); | 17 const JavaScriptBitNotOperation(); |
| 19 | 18 |
| 20 ConstantValue fold(ConstantValue constant) { | 19 ConstantValue fold(ConstantValue constant) { |
| 21 if (JAVA_SCRIPT_CONSTANT_SYSTEM.isInt(constant)) { | 20 if (JAVA_SCRIPT_CONSTANT_SYSTEM.isInt(constant)) { |
| 22 // In JavaScript we don't check for -0 and treat it as if it was zero. | 21 // In JavaScript we don't check for -0 and treat it as if it was zero. |
| 23 if (constant.isMinusZero) constant = DART_CONSTANT_SYSTEM.createInt(0); | 22 if (constant.isMinusZero) constant = DART_CONSTANT_SYSTEM.createInt(0); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 295 } |
| 297 | 296 |
| 298 @override | 297 @override |
| 299 NumConstantValue createInt(int i) { | 298 NumConstantValue createInt(int i) { |
| 300 return convertToJavaScriptConstant(new IntConstantValue(i)); | 299 return convertToJavaScriptConstant(new IntConstantValue(i)); |
| 301 } | 300 } |
| 302 | 301 |
| 303 NumConstantValue createInt32(int i) => new IntConstantValue(i & BITS32); | 302 NumConstantValue createInt32(int i) => new IntConstantValue(i & BITS32); |
| 304 NumConstantValue createDouble(double d) => | 303 NumConstantValue createDouble(double d) => |
| 305 convertToJavaScriptConstant(new DoubleConstantValue(d)); | 304 convertToJavaScriptConstant(new DoubleConstantValue(d)); |
| 306 StringConstantValue createString(DartString string) { | 305 StringConstantValue createString(String string) { |
| 307 return new StringConstantValue(string); | 306 return new StringConstantValue(string); |
| 308 } | 307 } |
| 309 | 308 |
| 310 BoolConstantValue createBool(bool value) => new BoolConstantValue(value); | 309 BoolConstantValue createBool(bool value) => new BoolConstantValue(value); |
| 311 NullConstantValue createNull() => new NullConstantValue(); | 310 NullConstantValue createNull() => new NullConstantValue(); |
| 312 | 311 |
| 313 @override | 312 @override |
| 314 ListConstantValue createList(InterfaceType type, List<ConstantValue> values) { | 313 ListConstantValue createList(InterfaceType type, List<ConstantValue> values) { |
| 315 return new ListConstantValue(type, values); | 314 return new ListConstantValue(type, values); |
| 316 } | 315 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 InterfaceType type = commonElements.getConstantMapTypeFor(sourceType, | 383 InterfaceType type = commonElements.getConstantMapTypeFor(sourceType, |
| 385 hasProtoKey: hasProtoKey, onlyStringKeys: onlyStringKeys); | 384 hasProtoKey: hasProtoKey, onlyStringKeys: onlyStringKeys); |
| 386 return new JavaScriptMapConstant( | 385 return new JavaScriptMapConstant( |
| 387 type, keysList, values, protoValue, onlyStringKeys); | 386 type, keysList, values, protoValue, onlyStringKeys); |
| 388 } | 387 } |
| 389 | 388 |
| 390 @override | 389 @override |
| 391 ConstantValue createSymbol(CommonElements commonElements, String text) { | 390 ConstantValue createSymbol(CommonElements commonElements, String text) { |
| 392 InterfaceType type = commonElements.symbolImplementationType; | 391 InterfaceType type = commonElements.symbolImplementationType; |
| 393 FieldEntity field = commonElements.symbolField; | 392 FieldEntity field = commonElements.symbolField; |
| 394 ConstantValue argument = createString(new DartString.literal(text)); | 393 ConstantValue argument = createString(text); |
| 395 // TODO(johnniwinther): Use type arguments when all uses no longer expect | 394 // TODO(johnniwinther): Use type arguments when all uses no longer expect |
| 396 // a [FieldElement]. | 395 // a [FieldElement]. |
| 397 Map<FieldEntity, ConstantValue> fields = /*<FieldElement, ConstantValue>*/ { | 396 Map<FieldEntity, ConstantValue> fields = /*<FieldElement, ConstantValue>*/ { |
| 398 field: argument | 397 field: argument |
| 399 }; | 398 }; |
| 400 return new ConstructedConstantValue(type, fields); | 399 return new ConstructedConstantValue(type, fields); |
| 401 } | 400 } |
| 402 } | 401 } |
| 403 | 402 |
| 404 class JavaScriptMapConstant extends MapConstantValue { | 403 class JavaScriptMapConstant extends MapConstantValue { |
| 405 /** | 404 /** |
| 406 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript | 405 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript |
| 407 * object. It would change the prototype chain. | 406 * object. It would change the prototype chain. |
| 408 */ | 407 */ |
| 409 static const LiteralDartString PROTO_PROPERTY = | 408 static const String PROTO_PROPERTY = "__proto__"; |
| 410 const LiteralDartString("__proto__"); | |
| 411 | 409 |
| 412 /** The dart class implementing constant map literals. */ | 410 /** The dart class implementing constant map literals. */ |
| 413 static const String DART_CLASS = "ConstantMap"; | 411 static const String DART_CLASS = "ConstantMap"; |
| 414 static const String DART_STRING_CLASS = "ConstantStringMap"; | 412 static const String DART_STRING_CLASS = "ConstantStringMap"; |
| 415 static const String DART_PROTO_CLASS = "ConstantProtoMap"; | 413 static const String DART_PROTO_CLASS = "ConstantProtoMap"; |
| 416 static const String DART_GENERAL_CLASS = "GeneralConstantMap"; | 414 static const String DART_GENERAL_CLASS = "GeneralConstantMap"; |
| 417 static const String LENGTH_NAME = "_length"; | 415 static const String LENGTH_NAME = "_length"; |
| 418 static const String JS_OBJECT_NAME = "_jsObject"; | 416 static const String JS_OBJECT_NAME = "_jsObject"; |
| 419 static const String KEYS_NAME = "_keys"; | 417 static const String KEYS_NAME = "_keys"; |
| 420 static const String PROTO_VALUE = "_protoValue"; | 418 static const String PROTO_VALUE = "_protoValue"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 436 result.add(keyList); | 434 result.add(keyList); |
| 437 } else { | 435 } else { |
| 438 // Add the keys individually to avoid generating an unused list constant | 436 // Add the keys individually to avoid generating an unused list constant |
| 439 // for the keys. | 437 // for the keys. |
| 440 result.addAll(keys); | 438 result.addAll(keys); |
| 441 } | 439 } |
| 442 result.addAll(values); | 440 result.addAll(values); |
| 443 return result; | 441 return result; |
| 444 } | 442 } |
| 445 } | 443 } |
| OLD | NEW |