OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.js_emitter.full_emitter; | 5 library dart2js.js_emitter.full_emitter; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 import 'dart:collection' show HashMap; | 8 import 'dart:collection' show HashMap; |
9 | 9 |
10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
11 import 'package:js_runtime/shared/embedded_names.dart' show | 11 import 'package:js_runtime/shared/embedded_names.dart' show |
12 JsBuiltin, | 12 JsBuiltin, |
13 JsGetName; | 13 JsGetName; |
14 | 14 |
15 import '../headers.dart'; | 15 import '../headers.dart'; |
16 import '../js_emitter.dart' hide Emitter; | 16 import '../js_emitter.dart' hide Emitter; |
17 import '../js_emitter.dart' as js_emitter show Emitter; | 17 import '../js_emitter.dart' as js_emitter show Emitter; |
18 import '../model.dart'; | 18 import '../model.dart'; |
19 import '../program_builder/program_builder.dart'; | 19 import '../program_builder/program_builder.dart'; |
20 | 20 |
21 import '../../common.dart'; | 21 import '../../common.dart'; |
22 import '../../common/names.dart' show | 22 import '../../common/names.dart' show |
23 Names; | 23 Names; |
24 import '../../compiler.dart' show | 24 import '../../compiler.dart' show |
25 Compiler; | 25 Compiler; |
26 import '../../constants/values.dart'; | 26 import '../../constants/values.dart'; |
| 27 import '../../core_types.dart' show |
| 28 CoreClasses; |
27 import '../../dart_types.dart' show | 29 import '../../dart_types.dart' show |
28 DartType; | 30 DartType; |
29 import '../../deferred_load.dart' show OutputUnit; | 31 import '../../deferred_load.dart' show OutputUnit; |
30 import '../../elements/elements.dart' show | 32 import '../../elements/elements.dart' show |
31 ClassElement, | 33 ClassElement, |
32 ConstructorBodyElement, | 34 ConstructorBodyElement, |
33 Element, | 35 Element, |
34 Elements, | 36 Elements, |
35 ElementKind, | 37 ElementKind, |
36 FieldElement, | 38 FieldElement, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 126 |
125 /// True if [ContainerBuilder.addMemberMethodFromInfo] used "structured info", | 127 /// True if [ContainerBuilder.addMemberMethodFromInfo] used "structured info", |
126 /// that is, some function was needed for reflection, had stubs, or had a | 128 /// that is, some function was needed for reflection, had stubs, or had a |
127 /// super alias. | 129 /// super alias. |
128 bool needsStructuredMemberInfo = false; | 130 bool needsStructuredMemberInfo = false; |
129 | 131 |
130 final Namer namer; | 132 final Namer namer; |
131 ConstantEmitter constantEmitter; | 133 ConstantEmitter constantEmitter; |
132 NativeEmitter get nativeEmitter => task.nativeEmitter; | 134 NativeEmitter get nativeEmitter => task.nativeEmitter; |
133 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry; | 135 TypeTestRegistry get typeTestRegistry => task.typeTestRegistry; |
| 136 CoreClasses get coreClasses => compiler.coreClasses; |
134 | 137 |
135 // The full code that is written to each hunk part-file. | 138 // The full code that is written to each hunk part-file. |
136 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); | 139 Map<OutputUnit, CodeOutput> outputBuffers = new Map<OutputUnit, CodeOutput>(); |
137 | 140 |
138 String classesCollector; | 141 String classesCollector; |
139 final Map<jsAst.Name, String> mangledFieldNames = | 142 final Map<jsAst.Name, String> mangledFieldNames = |
140 new HashMap<jsAst.Name, String>(); | 143 new HashMap<jsAst.Name, String>(); |
141 final Map<jsAst.Name, String> mangledGlobalFieldNames = | 144 final Map<jsAst.Name, String> mangledGlobalFieldNames = |
142 new HashMap<jsAst.Name, String>(); | 145 new HashMap<jsAst.Name, String>(); |
143 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>(); | 146 final Set<jsAst.Name> recordedMangledNames = new Set<jsAst.Name>(); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 @override | 366 @override |
364 jsAst.PropertyAccess typeAccess(Element element) { | 367 jsAst.PropertyAccess typeAccess(Element element) { |
365 return globalPropertyAccess(element); | 368 return globalPropertyAccess(element); |
366 } | 369 } |
367 | 370 |
368 @override | 371 @override |
369 jsAst.Template templateForBuiltin(JsBuiltin builtin) { | 372 jsAst.Template templateForBuiltin(JsBuiltin builtin) { |
370 switch (builtin) { | 373 switch (builtin) { |
371 case JsBuiltin.dartObjectConstructor: | 374 case JsBuiltin.dartObjectConstructor: |
372 return jsAst.js.expressionTemplateYielding( | 375 return jsAst.js.expressionTemplateYielding( |
373 typeAccess(compiler.objectClass)); | 376 typeAccess(coreClasses.objectClass)); |
374 | 377 |
375 case JsBuiltin.isCheckPropertyToJsConstructorName: | 378 case JsBuiltin.isCheckPropertyToJsConstructorName: |
376 int isPrefixLength = namer.operatorIsPrefix.length; | 379 int isPrefixLength = namer.operatorIsPrefix.length; |
377 return jsAst.js.expressionTemplateFor('#.substring($isPrefixLength)'); | 380 return jsAst.js.expressionTemplateFor('#.substring($isPrefixLength)'); |
378 | 381 |
379 case JsBuiltin.isFunctionType: | 382 case JsBuiltin.isFunctionType: |
380 return backend.rtiEncoder.templateForIsFunctionType; | 383 return backend.rtiEncoder.templateForIsFunctionType; |
381 | 384 |
382 case JsBuiltin.rawRtiToJsConstructorName: | 385 case JsBuiltin.rawRtiToJsConstructorName: |
383 return jsAst.js.expressionTemplateFor("#.$typeNameProperty"); | 386 return jsAst.js.expressionTemplateFor("#.$typeNameProperty"); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 leafTagsAccess); | 441 leafTagsAccess); |
439 } | 442 } |
440 | 443 |
441 jsAst.ObjectInitializer generateInterceptedNamesSet() { | 444 jsAst.ObjectInitializer generateInterceptedNamesSet() { |
442 return interceptorEmitter.generateInterceptedNamesSet(); | 445 return interceptorEmitter.generateInterceptedNamesSet(); |
443 } | 446 } |
444 | 447 |
445 /// In minified mode we want to keep the name for the most common core types. | 448 /// In minified mode we want to keep the name for the most common core types. |
446 bool _isNativeTypeNeedingReflectionName(Element element) { | 449 bool _isNativeTypeNeedingReflectionName(Element element) { |
447 if (!element.isClass) return false; | 450 if (!element.isClass) return false; |
448 return (element == compiler.intClass || | 451 return (element == coreClasses.intClass || |
449 element == compiler.doubleClass || | 452 element == coreClasses.doubleClass || |
450 element == compiler.numClass || | 453 element == coreClasses.numClass || |
451 element == compiler.stringClass || | 454 element == coreClasses.stringClass || |
452 element == compiler.boolClass || | 455 element == coreClasses.boolClass || |
453 element == compiler.nullClass || | 456 element == coreClasses.nullClass || |
454 element == compiler.listClass); | 457 element == coreClasses.listClass); |
455 } | 458 } |
456 | 459 |
457 /// Returns the "reflection name" of an [Element] or [Selector]. | 460 /// Returns the "reflection name" of an [Element] or [Selector]. |
458 /// The reflection name of a getter 'foo' is 'foo'. | 461 /// The reflection name of a getter 'foo' is 'foo'. |
459 /// The reflection name of a setter 'foo' is 'foo='. | 462 /// The reflection name of a setter 'foo' is 'foo='. |
460 /// The reflection name of a method 'foo' is 'foo:N:M:O', where N is the | 463 /// The reflection name of a method 'foo' is 'foo:N:M:O', where N is the |
461 /// number of required arguments, M is the number of optional arguments, and | 464 /// number of required arguments, M is the number of optional arguments, and |
462 /// O is the named arguments. | 465 /// O is the named arguments. |
463 /// The reflection name of a constructor is similar to a regular method but | 466 /// The reflection name of a constructor is similar to a regular method but |
464 /// starts with 'new '. | 467 /// starts with 'new '. |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); | 1183 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); |
1181 ClassBuilder builder = new ClassBuilder.forStatics(typedef, namer); | 1184 ClassBuilder builder = new ClassBuilder.forStatics(typedef, namer); |
1182 builder.addPropertyByName(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, | 1185 builder.addPropertyByName(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, |
1183 typeIndex); | 1186 typeIndex); |
1184 builder.addPropertyByName(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, | 1187 builder.addPropertyByName(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, |
1185 js.boolean(true)); | 1188 js.boolean(true)); |
1186 | 1189 |
1187 // We can be pretty sure that the objectClass is initialized, since | 1190 // We can be pretty sure that the objectClass is initialized, since |
1188 // typedefs are only emitted with reflection, which requires lots of | 1191 // typedefs are only emitted with reflection, which requires lots of |
1189 // classes. | 1192 // classes. |
1190 assert(compiler.objectClass != null); | 1193 assert(coreClasses.objectClass != null); |
1191 builder.superName = namer.className(compiler.objectClass); | 1194 builder.superName = namer.className(coreClasses.objectClass); |
1192 jsAst.Node declaration = builder.toObjectInitializer(); | 1195 jsAst.Node declaration = builder.toObjectInitializer(); |
1193 jsAst.Name mangledName = namer.globalPropertyName(typedef); | 1196 jsAst.Name mangledName = namer.globalPropertyName(typedef); |
1194 String reflectionName = getReflectionName(typedef, mangledName); | 1197 String reflectionName = getReflectionName(typedef, mangledName); |
1195 getElementDescriptor(library, mainFragment) | 1198 getElementDescriptor(library, mainFragment) |
1196 ..addProperty(mangledName, declaration) | 1199 ..addProperty(mangledName, declaration) |
1197 ..addPropertyByName("+$reflectionName", js.string('')); | 1200 ..addPropertyByName("+$reflectionName", js.string('')); |
1198 // Also emit a trivial constructor for CSP mode. | 1201 // Also emit a trivial constructor for CSP mode. |
1199 jsAst.Name constructorName = mangledName; | 1202 jsAst.Name constructorName = mangledName; |
1200 jsAst.Expression constructorAst = js('function() {}'); | 1203 jsAst.Expression constructorAst = js('function() {}'); |
1201 List<jsAst.Name> fieldNames = []; | 1204 List<jsAst.Name> fieldNames = []; |
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2122 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2125 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
2123 if (element.isInstanceMember) { | 2126 if (element.isInstanceMember) { |
2124 cachedClassBuilders.remove(element.enclosingClass); | 2127 cachedClassBuilders.remove(element.enclosingClass); |
2125 | 2128 |
2126 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2129 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
2127 | 2130 |
2128 } | 2131 } |
2129 } | 2132 } |
2130 } | 2133 } |
2131 } | 2134 } |
OLD | NEW |