Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Unified Diff: pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart

Issue 2908153003: It's alive! (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart
index 513e5285175551c5fc95253eeacf31618ac04c99..3a3a0db071f34e5a9bb39c5fa78c6741fd71c101 100644
--- a/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart
@@ -24,7 +24,6 @@ import '../../elements/elements.dart'
Element,
Elements,
FieldElement,
- FunctionElement,
FunctionSignature,
LibraryElement,
MethodElement,
@@ -168,8 +167,11 @@ class Emitter extends js_emitter.EmitterBase {
*/
// TODO(ahe): Generate statics with their class, and store only libraries in
// this map.
- final Map<Fragment, Map<Element, ClassBuilder>> elementDescriptors =
- new Map<Fragment, Map<Element, ClassBuilder>>();
+ final Map<Fragment, Map<LibraryEntity, ClassBuilder>> libraryDescriptors =
+ new Map<Fragment, Map<LibraryEntity, ClassBuilder>>();
+
+ final Map<Fragment, Map<ClassEntity, ClassBuilder>> classDescriptors =
+ new Map<Fragment, Map<ClassEntity, ClassBuilder>>();
final bool generateSourceMap;
@@ -476,7 +478,7 @@ class Emitter extends js_emitter.EmitterBase {
positionalParameterCount = callStructure.positionalArgumentCount;
namedArguments = namedParametersAsReflectionNames(callStructure);
} else {
- FunctionElement function = elementOrSelector;
+ MethodElement function = elementOrSelector;
if (function.isConstructor) {
isConstructor = true;
name = Elements.reconstructConstructorName(function);
@@ -564,7 +566,7 @@ class Emitter extends js_emitter.EmitterBase {
if (staticFunctions == null) return;
for (Method method in staticFunctions) {
- MethodElement element = method.element;
+ FunctionEntity element = method.element;
// We need to filter out null-elements for the interceptors.
// TODO(floitsch): use the precomputed interceptors here.
if (element == null) continue;
@@ -1010,7 +1012,7 @@ class Emitter extends js_emitter.EmitterBase {
}
jsAst.Expression generateLibraryDescriptor(
- LibraryElement library, Fragment fragment) {
+ LibraryEntity library, Fragment fragment) {
var uri = "";
if (!compiler.options.enableMinification ||
backend.mirrorsData.mustPreserveUris) {
@@ -1023,13 +1025,14 @@ class Emitter extends js_emitter.EmitterBase {
String libraryName = (!compiler.options.enableMinification ||
backend.mirrorsData.mustRetainLibraryNames)
- ? library.libraryName
+ // TODO(johnniwinther): Support library names for entities.
+ ? library is LibraryElement ? library.libraryName : library.name
: "";
jsAst.Fun metadata =
task.metadataCollector.buildLibraryMetadataFunction(library);
- ClassBuilder descriptor = elementDescriptors[fragment][library];
+ ClassBuilder descriptor = libraryDescriptors[fragment][library];
jsAst.ObjectInitializer initializer;
if (descriptor == null) {
@@ -1263,11 +1266,11 @@ class Emitter extends js_emitter.EmitterBase {
return new jsAst.Block(parts);
}
- void checkEverythingEmitted(Iterable<Element> elements) {
- List<Element> pendingStatics =
- Elements.sortedByPosition(elements.where((e) => !e.isLibrary));
+ void checkEverythingEmitted(Map<ClassEntity, ClassBuilder> classes) {
Siggi Cherem (dart-lang) 2017/05/30 22:10:20 nit: classes => pendingClassBuilders pendingS
Johnni Winther 2017/05/31 08:19:31 Done.
+ if (classes == null) return;
+ List<ClassEntity> pendingStatics = _sorter.sortClasses(classes.keys);
- pendingStatics.forEach((element) => reporter.reportInfo(
+ pendingStatics.forEach((ClassEntity element) => reporter.reportInfo(
element, MessageKind.GENERIC, {'text': 'Pending statics.'}));
if (pendingStatics != null && !pendingStatics.isEmpty) {
@@ -1277,7 +1280,7 @@ class Emitter extends js_emitter.EmitterBase {
}
void assembleLibrary(Library library, Fragment fragment) {
- LibraryElement libraryElement = library.element;
+ LibraryEntity libraryElement = library.element;
assembleStaticFunctions(library.statics, fragment);
@@ -1325,13 +1328,13 @@ class Emitter extends js_emitter.EmitterBase {
}
// Collect the AST for the descriptors.
- Map<Element, ClassBuilder> descriptors = elementDescriptors[mainFragment];
- if (descriptors == null) descriptors = const {};
+ Map<LibraryEntity, ClassBuilder> descriptors =
+ libraryDescriptors[mainFragment] ?? const {};
- checkEverythingEmitted(descriptors.keys);
+ checkEverythingEmitted(classDescriptors[mainFragment]);
Iterable<LibraryEntity> libraries = outputLibraryLists[mainOutputUnit];
- if (libraries == null) libraries = <LibraryElement>[];
+ if (libraries == null) libraries = <LibraryEntity>[];
List<jsAst.Expression> parts = <jsAst.Expression>[];
for (LibraryEntity library in _sorter.sortLibraries(libraries)) {
@@ -1340,18 +1343,14 @@ class Emitter extends js_emitter.EmitterBase {
}
if (descriptors.isNotEmpty) {
- List<Element> remainingLibraries =
- descriptors.keys.where((Element e) => e is LibraryElement).toList();
+ List<LibraryEntity> remainingLibraries = descriptors.keys.toList();
// The remaining descriptors are only accessible through reflection.
// The program builder does not collect libraries that only
// contain typedefs that are used for reflection.
- for (LibraryElement element in remainingLibraries) {
- assert(element is LibraryElement);
- if (element is LibraryElement) {
- parts.add(generateLibraryDescriptor(element, mainFragment));
- descriptors.remove(element);
- }
+ for (LibraryEntity element in remainingLibraries) {
+ parts.add(generateLibraryDescriptor(element, mainFragment));
+ descriptors.remove(element);
}
}
jsAst.ArrayInitializer descriptorsAst = new jsAst.ArrayInitializer(parts);
@@ -1548,11 +1547,12 @@ class Emitter extends js_emitter.EmitterBase {
for (Fragment fragment in program.deferredFragments) {
OutputUnit outputUnit = fragment.outputUnit;
- Map<Element, ClassBuilder> descriptors = elementDescriptors[fragment];
+ Map<LibraryEntity, ClassBuilder> descriptors =
+ libraryDescriptors[fragment];
if (descriptors != null && descriptors.isNotEmpty) {
Iterable<LibraryEntity> libraries = outputLibraryLists[outputUnit];
- if (libraries == null) libraries = [];
+ if (libraries == null) libraries = <LibraryEntity>[];
// TODO(johnniwinther): Avoid creating [CodeBuffer]s.
List<jsAst.Expression> parts = <jsAst.Expression>[];
@@ -1629,37 +1629,40 @@ class Emitter extends js_emitter.EmitterBase {
}
ClassBuilder getStaticMethodDescriptor(
- MethodElement element, Fragment fragment) {
- Element owner = element.library;
+ FunctionEntity element, Fragment fragment) {
if (!_nativeData.isNativeMember(element)) {
// For static (not top level) elements, record their code in a buffer
// specific to the class. For now, not supported for native classes and
// native elements.
- ClassElement cls = element.enclosingClass;
+ ClassEntity cls = element.enclosingClass;
if (compiler.codegenWorldBuilder.directlyInstantiatedClasses
.contains(cls) &&
!_nativeData.isNativeClass(cls) &&
- compiler.deferredLoadTask.outputUnitForElement(element) ==
- compiler.deferredLoadTask.outputUnitForElement(cls)) {
- owner = cls;
+ compiler.deferredLoadTask.outputUnitForMember(element) ==
+ compiler.deferredLoadTask.outputUnitForClass(cls)) {
+ return classDescriptors
+ .putIfAbsent(fragment, () => new Map<ClassEntity, ClassBuilder>())
+ .putIfAbsent(cls, () {
+ return new ClassBuilder.forClass(cls, namer);
+ });
}
}
- return _getElementDescriptor(element, owner, fragment);
+ return _getLibraryDescriptor(element, element.library, fragment);
}
- ClassBuilder getLibraryDescriptor(LibraryElement element, Fragment fragment) {
- return _getElementDescriptor(element, element, fragment);
+ ClassBuilder getLibraryDescriptor(LibraryEntity element, Fragment fragment) {
+ return _getLibraryDescriptor(element, element, fragment);
}
- ClassBuilder _getElementDescriptor(
- Element element, Element owner, Fragment fragment) {
+ ClassBuilder _getLibraryDescriptor(
+ Entity element, LibraryEntity owner, Fragment fragment) {
if (owner == null) {
reporter.internalError(element, 'Owner is null.');
}
- return elementDescriptors
- .putIfAbsent(fragment, () => new Map<Element, ClassBuilder>())
+ return libraryDescriptors
+ .putIfAbsent(fragment, () => new Map<LibraryEntity, ClassBuilder>())
.putIfAbsent(owner, () {
- return new ClassBuilder(owner, namer, owner.isClass);
+ return new ClassBuilder.forLibrary(owner, namer);
});
}

Powered by Google App Engine
This is Rietveld 408576698