| 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 '../dart_types.dart'; | 11 import '../dart_types.dart'; |
| 12 import '../elements/elements.dart' show ClassElement; | 12 import '../elements/elements.dart' show ClassElement, FieldElement; |
| 13 import '../tree/tree.dart' show DartString, LiteralDartString; | 13 import '../tree/tree.dart' show DartString, LiteralDartString; |
| 14 import 'js_backend.dart'; | 14 import 'js_backend.dart'; |
| 15 | 15 |
| 16 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); | 16 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); |
| 17 | 17 |
| 18 class JavaScriptBitNotOperation extends BitNotOperation { | 18 class JavaScriptBitNotOperation extends BitNotOperation { |
| 19 const JavaScriptBitNotOperation(); | 19 const JavaScriptBitNotOperation(); |
| 20 | 20 |
| 21 ConstantValue fold(ConstantValue constant) { | 21 ConstantValue fold(ConstantValue constant) { |
| 22 if (JAVA_SCRIPT_CONSTANT_SYSTEM.isInt(constant)) { | 22 if (JAVA_SCRIPT_CONSTANT_SYSTEM.isInt(constant)) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 final greater = const GreaterOperation(); | 186 final greater = const GreaterOperation(); |
| 187 final identity = const JavaScriptIdentityOperation(); | 187 final identity = const JavaScriptIdentityOperation(); |
| 188 final lessEqual = const LessEqualOperation(); | 188 final lessEqual = const LessEqualOperation(); |
| 189 final less = const LessOperation(); | 189 final less = const LessOperation(); |
| 190 final modulo = | 190 final modulo = |
| 191 const JavaScriptBinaryArithmeticOperation(const ModuloOperation()); | 191 const JavaScriptBinaryArithmeticOperation(const ModuloOperation()); |
| 192 final multiply = | 192 final multiply = |
| 193 const JavaScriptBinaryArithmeticOperation(const MultiplyOperation()); | 193 const JavaScriptBinaryArithmeticOperation(const MultiplyOperation()); |
| 194 final negate = const JavaScriptNegateOperation(); | 194 final negate = const JavaScriptNegateOperation(); |
| 195 final not = const NotOperation(); | 195 final not = const NotOperation(); |
| 196 final notEqual = const NotEqualsOperation(); |
| 196 final shiftLeft = | 197 final shiftLeft = |
| 197 const JavaScriptBinaryBitOperation(const ShiftLeftOperation()); | 198 const JavaScriptBinaryBitOperation(const ShiftLeftOperation()); |
| 198 final shiftRight = const JavaScriptShiftRightOperation(); | 199 final shiftRight = const JavaScriptShiftRightOperation(); |
| 199 final subtract = | 200 final subtract = |
| 200 const JavaScriptBinaryArithmeticOperation(const SubtractOperation()); | 201 const JavaScriptBinaryArithmeticOperation(const SubtractOperation()); |
| 201 final truncatingDivide = const JavaScriptBinaryArithmeticOperation( | 202 final truncatingDivide = const JavaScriptBinaryArithmeticOperation( |
| 202 const TruncatingDivideOperation()); | 203 const TruncatingDivideOperation()); |
| 203 final codeUnitAt = const CodeUnitAtRuntimeOperation(); | 204 final codeUnitAt = const CodeUnitAtRuntimeOperation(); |
| 204 | 205 |
| 205 const JavaScriptConstantSystem(); | 206 const JavaScriptConstantSystem(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 return new ListConstantValue(type, values); | 261 return new ListConstantValue(type, values); |
| 261 } | 262 } |
| 262 | 263 |
| 263 @override | 264 @override |
| 264 ConstantValue createType(Compiler compiler, DartType type) { | 265 ConstantValue createType(Compiler compiler, DartType type) { |
| 265 return new TypeConstantValue( | 266 return new TypeConstantValue( |
| 266 type, | 267 type, |
| 267 compiler.backend.typeImplementation.computeType(compiler.resolution)); | 268 compiler.backend.typeImplementation.computeType(compiler.resolution)); |
| 268 } | 269 } |
| 269 | 270 |
| 271 @override |
| 272 ConstantValue createSymbol(Compiler compiler, String text) { |
| 273 InterfaceType type = compiler.symbolClass.rawType; |
| 274 ConstantValue argument = createString(new DartString.literal(text)); |
| 275 Map<FieldElement, ConstantValue> fields = <FieldElement, ConstantValue>{}; |
| 276 compiler.symbolImplementationClass.forEachInstanceField( |
| 277 (ClassElement enclosingClass, FieldElement field) { |
| 278 fields[field] = argument; |
| 279 }); |
| 280 assert(fields.length == 1); |
| 281 return new ConstructedConstantValue(type, fields); |
| 282 } |
| 283 |
| 270 // Integer checks don't verify that the number is not -0.0. | 284 // Integer checks don't verify that the number is not -0.0. |
| 271 bool isInt(ConstantValue constant) => constant.isInt || constant.isMinusZero; | 285 bool isInt(ConstantValue constant) => constant.isInt || constant.isMinusZero; |
| 272 bool isDouble(ConstantValue constant) | 286 bool isDouble(ConstantValue constant) |
| 273 => constant.isDouble && !constant.isMinusZero; | 287 => constant.isDouble && !constant.isMinusZero; |
| 274 bool isString(ConstantValue constant) => constant.isString; | 288 bool isString(ConstantValue constant) => constant.isString; |
| 275 bool isBool(ConstantValue constant) => constant.isBool; | 289 bool isBool(ConstantValue constant) => constant.isBool; |
| 276 bool isNull(ConstantValue constant) => constant.isNull; | 290 bool isNull(ConstantValue constant) => constant.isNull; |
| 277 | 291 |
| 278 bool isSubtype(DartTypes types, DartType s, DartType t) { | 292 bool isSubtype(DartTypes types, DartType s, DartType t) { |
| 279 // At runtime, an integer is both an integer and a double: the | 293 // At runtime, an integer is both an integer and a double: the |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 result.add(keyList); | 388 result.add(keyList); |
| 375 } else { | 389 } else { |
| 376 // Add the keys individually to avoid generating an unused list constant | 390 // Add the keys individually to avoid generating an unused list constant |
| 377 // for the keys. | 391 // for the keys. |
| 378 result.addAll(keys); | 392 result.addAll(keys); |
| 379 } | 393 } |
| 380 result.addAll(values); | 394 result.addAll(values); |
| 381 return result; | 395 return result; |
| 382 } | 396 } |
| 383 } | 397 } |
| OLD | NEW |