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 |
| 8 Compiler; |
8 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
9 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
10 import '../constant_system_dart.dart'; | 11 import '../constant_system_dart.dart'; |
| 12 import '../core_types.dart' show |
| 13 CoreTypes; |
11 import '../dart_types.dart'; | 14 import '../dart_types.dart'; |
12 import '../elements/elements.dart' show ClassElement; | 15 import '../elements/elements.dart' show |
13 import '../tree/tree.dart' show DartString, LiteralDartString; | 16 ClassElement; |
| 17 import '../tree/tree.dart' show |
| 18 DartString, |
| 19 LiteralDartString; |
14 import 'js_backend.dart'; | 20 import 'js_backend.dart'; |
15 | 21 |
16 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); | 22 const JAVA_SCRIPT_CONSTANT_SYSTEM = const JavaScriptConstantSystem(); |
17 | 23 |
18 class JavaScriptBitNotOperation extends BitNotOperation { | 24 class JavaScriptBitNotOperation extends BitNotOperation { |
19 const JavaScriptBitNotOperation(); | 25 const JavaScriptBitNotOperation(); |
20 | 26 |
21 ConstantValue fold(ConstantValue constant) { | 27 ConstantValue fold(ConstantValue constant) { |
22 if (JAVA_SCRIPT_CONSTANT_SYSTEM.isInt(constant)) { | 28 if (JAVA_SCRIPT_CONSTANT_SYSTEM.isInt(constant)) { |
23 // In JavaScript we don't check for -0 and treat it as if it was zero. | 29 // In JavaScript we don't check for -0 and treat it as if it was zero. |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 return true; | 290 return true; |
285 } | 291 } |
286 return types.isSubtype(s, t); | 292 return types.isSubtype(s, t); |
287 } | 293 } |
288 | 294 |
289 MapConstantValue createMap(Compiler compiler, | 295 MapConstantValue createMap(Compiler compiler, |
290 InterfaceType sourceType, | 296 InterfaceType sourceType, |
291 List<ConstantValue> keys, | 297 List<ConstantValue> keys, |
292 List<ConstantValue> values) { | 298 List<ConstantValue> values) { |
293 JavaScriptBackend backend = compiler.backend; | 299 JavaScriptBackend backend = compiler.backend; |
| 300 CoreTypes coreTypes = compiler.coreTypes; |
294 | 301 |
295 bool onlyStringKeys = true; | 302 bool onlyStringKeys = true; |
296 ConstantValue protoValue = null; | 303 ConstantValue protoValue = null; |
297 for (int i = 0; i < keys.length ; i++) { | 304 for (int i = 0; i < keys.length ; i++) { |
298 var key = keys[i]; | 305 var key = keys[i]; |
299 if (key.isString) { | 306 if (key.isString) { |
300 if (key.primitiveValue == JavaScriptMapConstant.PROTO_PROPERTY) { | 307 if (key.primitiveValue == JavaScriptMapConstant.PROTO_PROPERTY) { |
301 protoValue = values[i]; | 308 protoValue = values[i]; |
302 } | 309 } |
303 } else { | 310 } else { |
304 onlyStringKeys = false; | 311 onlyStringKeys = false; |
305 // Don't handle __proto__ values specially in the general map case. | 312 // Don't handle __proto__ values specially in the general map case. |
306 protoValue = null; | 313 protoValue = null; |
307 break; | 314 break; |
308 } | 315 } |
309 } | 316 } |
310 | 317 |
311 bool hasProtoKey = (protoValue != null); | 318 bool hasProtoKey = (protoValue != null); |
312 DartType keysType; | 319 DartType keysType; |
313 if (sourceType.treatAsRaw) { | 320 if (sourceType.treatAsRaw) { |
314 keysType = compiler.listClass.rawType; | 321 keysType = coreTypes.listType(); |
315 } else { | 322 } else { |
316 List<DartType> arguments = <DartType>[sourceType.typeArguments.first]; | 323 keysType = coreTypes.listType(sourceType.typeArguments.first); |
317 keysType = new InterfaceType(compiler.listClass, arguments); | |
318 } | 324 } |
319 ListConstantValue keysList = new ListConstantValue(keysType, keys); | 325 ListConstantValue keysList = new ListConstantValue(keysType, keys); |
320 String className = onlyStringKeys | 326 String className = onlyStringKeys |
321 ? (hasProtoKey ? JavaScriptMapConstant.DART_PROTO_CLASS | 327 ? (hasProtoKey ? JavaScriptMapConstant.DART_PROTO_CLASS |
322 : JavaScriptMapConstant.DART_STRING_CLASS) | 328 : JavaScriptMapConstant.DART_STRING_CLASS) |
323 : JavaScriptMapConstant.DART_GENERAL_CLASS; | 329 : JavaScriptMapConstant.DART_GENERAL_CLASS; |
324 ClassElement classElement = backend.jsHelperLibrary.find(className); | 330 ClassElement classElement = backend.jsHelperLibrary.find(className); |
325 classElement.ensureResolved(compiler.resolution); | 331 classElement.ensureResolved(compiler.resolution); |
326 List<DartType> typeArgument = sourceType.typeArguments; | 332 List<DartType> typeArgument = sourceType.typeArguments; |
327 InterfaceType type; | 333 InterfaceType type; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 result.add(keyList); | 380 result.add(keyList); |
375 } else { | 381 } else { |
376 // Add the keys individually to avoid generating an unused list constant | 382 // Add the keys individually to avoid generating an unused list constant |
377 // for the keys. | 383 // for the keys. |
378 result.addAll(keys); | 384 result.addAll(keys); |
379 } | 385 } |
380 result.addAll(values); | 386 result.addAll(values); |
381 return result; | 387 return result; |
382 } | 388 } |
383 } | 389 } |
OLD | NEW |