| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The [ConstantHandler] keeps track of compile-time constants, | 8 * The [ConstantHandler] keeps track of compile-time constants, |
| 9 * initializations of global and static fields, and default values of | 9 * initializations of global and static fields, and default values of |
| 10 * optional parameters. | 10 * optional parameters. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 compiledConstants.add(constant); | 58 compiledConstants.add(constant); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void registerInstantiatedType(DartType type, TreeElements elements) { | 61 void registerInstantiatedType(DartType type, TreeElements elements) { |
| 62 if (isMetadata) { | 62 if (isMetadata) { |
| 63 compiler.backend.registerMetadataInstantiatedType(type, elements); | 63 compiler.backend.registerMetadataInstantiatedType(type, elements); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 compiler.enqueuer.codegen.registerInstantiatedType(type, elements); | 66 compiler.enqueuer.codegen.registerInstantiatedType(type, elements); |
| 67 if (type is InterfaceType && | 67 if (type is InterfaceType && |
| 68 !type.isRaw && | 68 !type.treatAsRaw && |
| 69 compiler.backend.classNeedsRti(type.element)) { | 69 compiler.backend.classNeedsRti(type.element)) { |
| 70 registerSetRuntimeTypeInfoFunction(); | 70 registerSetRuntimeTypeInfoFunction(); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 void registerStaticUse(Element element) { | 74 void registerStaticUse(Element element) { |
| 75 if (isMetadata) { | 75 if (isMetadata) { |
| 76 compiler.backend.registerMetadataStaticUse(element); | 76 compiler.backend.registerMetadataStaticUse(element); |
| 77 return; | 77 return; |
| 78 } | 78 } |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 onlyStringKeys = false; | 415 onlyStringKeys = false; |
| 416 // Don't handle __proto__ values specially in the general map case. | 416 // Don't handle __proto__ values specially in the general map case. |
| 417 protoValue = null; | 417 protoValue = null; |
| 418 break; | 418 break; |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 | 421 |
| 422 bool hasProtoKey = (protoValue != null); | 422 bool hasProtoKey = (protoValue != null); |
| 423 List<Constant> values = map.values.toList(); | 423 List<Constant> values = map.values.toList(); |
| 424 InterfaceType sourceType = elements.getType(node); | 424 InterfaceType sourceType = elements.getType(node); |
| 425 Link<DartType> arguments = | 425 DartType keysType; |
| 426 new Link<DartType>.fromList([compiler.stringClass.rawType]); | 426 if (sourceType.treatAsRaw) { |
| 427 DartType keysType = new InterfaceType(compiler.listClass, arguments); | 427 keysType = compiler.listClass.rawType; |
| 428 } else { |
| 429 Link<DartType> arguments = |
| 430 new Link<DartType>.fromList([sourceType.typeArguments.head]); |
| 431 keysType = new InterfaceType(compiler.listClass, arguments); |
| 432 } |
| 428 ListConstant keysList = new ListConstant(keysType, keys); | 433 ListConstant keysList = new ListConstant(keysType, keys); |
| 429 if (onlyStringKeys) { | 434 if (onlyStringKeys) { |
| 430 handler.registerCompileTimeConstant(keysList, elements); | 435 handler.registerCompileTimeConstant(keysList, elements); |
| 431 } | 436 } |
| 432 SourceString className = onlyStringKeys | 437 SourceString className = onlyStringKeys |
| 433 ? (hasProtoKey ? MapConstant.DART_PROTO_CLASS | 438 ? (hasProtoKey ? MapConstant.DART_PROTO_CLASS |
| 434 : MapConstant.DART_STRING_CLASS) | 439 : MapConstant.DART_STRING_CLASS) |
| 435 : MapConstant.DART_GENERAL_CLASS; | 440 : MapConstant.DART_GENERAL_CLASS; |
| 436 ClassElement classElement = compiler.jsHelperLibrary.find(className); | 441 ClassElement classElement = compiler.jsHelperLibrary.find(className); |
| 437 classElement.ensureResolved(compiler); | 442 classElement.ensureResolved(compiler); |
| 438 Link<DartType> typeArgument = sourceType.typeArguments; | 443 Link<DartType> typeArgument = sourceType.typeArguments; |
| 439 InterfaceType type = new InterfaceType(classElement, typeArgument); | 444 InterfaceType type; |
| 440 handler.registerInstantiatedType(type, elements); | 445 if (sourceType.treatAsRaw) { |
| 446 type = classElement.rawType; |
| 447 } else { |
| 448 type = new InterfaceType(classElement, typeArgument); |
| 449 } |
| 441 Constant constant = | 450 Constant constant = |
| 442 new MapConstant(type, keysList, values, protoValue, onlyStringKeys); | 451 new MapConstant(type, keysList, values, protoValue, onlyStringKeys); |
| 443 handler.registerCompileTimeConstant(constant, elements); | 452 handler.registerCompileTimeConstant(constant, elements); |
| 444 return constant; | 453 return constant; |
| 445 } | 454 } |
| 446 | 455 |
| 447 Constant visitLiteralNull(LiteralNull node) { | 456 Constant visitLiteralNull(LiteralNull node) { |
| 448 return constantSystem.createNull(); | 457 return constantSystem.createNull(); |
| 449 } | 458 } |
| 450 | 459 |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 if (fieldValue == null) { | 977 if (fieldValue == null) { |
| 969 // Use the default value. | 978 // Use the default value. |
| 970 fieldValue = handler.compileConstant(field); | 979 fieldValue = handler.compileConstant(field); |
| 971 } | 980 } |
| 972 jsNewArguments.add(fieldValue); | 981 jsNewArguments.add(fieldValue); |
| 973 }, | 982 }, |
| 974 includeSuperAndInjectedMembers: true); | 983 includeSuperAndInjectedMembers: true); |
| 975 return jsNewArguments; | 984 return jsNewArguments; |
| 976 } | 985 } |
| 977 } | 986 } |
| OLD | NEW |