Chromium Code Reviews| Index: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart |
| diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart |
| index b5d2fbad17e1112c8df3e5dbae4c50273937414c..d0a733f3acbc02ec8dea60e7c5da52bb66622720 100644 |
| --- a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart |
| +++ b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart |
| @@ -84,8 +84,8 @@ class OldEmitter implements Emitter { |
| */ |
| // TODO(ahe): Generate statics with their class, and store only libraries in |
| // this map. |
| - final Map<Element, ClassBuilder> elementDescriptors = |
| - new Map<Element, ClassBuilder>(); |
| + final Map<Fragment, Map<Element, ClassBuilder>> elementDescriptors = |
| + new Map<Fragment, Map<Element, ClassBuilder>>(); |
| final bool generateSourceMap; |
| @@ -434,14 +434,15 @@ class OldEmitter implements Emitter { |
| cspPrecompiledConstructorNamesFor(outputUnit))]); |
| } |
| - void emitClass(Class cls, ClassBuilder enclosingBuilder) { |
| + void assembleClass(Class cls, ClassBuilder enclosingBuilder, |
| + Fragment fragment) { |
| ClassElement classElement = cls.element; |
| compiler.withCurrentElement(classElement, () { |
| if (compiler.hasIncrementalSupport) { |
| ClassBuilder cachedBuilder = |
| cachedClassBuilders.putIfAbsent(classElement, () { |
| ClassBuilder builder = new ClassBuilder(classElement, namer); |
| - classEmitter.emitClass(cls, builder); |
| + classEmitter.emitClass(cls, builder, fragment); |
| return builder; |
| }); |
| invariant(classElement, cachedBuilder.fields.isEmpty); |
| @@ -450,12 +451,13 @@ class OldEmitter implements Emitter { |
| invariant(classElement, cachedBuilder.fieldMetadata == null); |
| enclosingBuilder.properties.addAll(cachedBuilder.properties); |
| } else { |
| - classEmitter.emitClass(cls, enclosingBuilder); |
| + classEmitter.emitClass(cls, enclosingBuilder, fragment); |
| } |
| }); |
| } |
| - void emitStaticFunctions(Iterable<Method> staticFunctions) { |
| + void assembleStaticFunctions(Iterable<Method> staticFunctions, |
| + Fragment fragment) { |
|
karlklose
2015/04/17 11:26:10
Align parameter.
herhut
2015/04/17 11:37:30
Done.
|
| if (staticFunctions == null) return; |
| for (Method method in staticFunctions) { |
| @@ -465,7 +467,8 @@ class OldEmitter implements Emitter { |
| if (element == null) continue; |
| ClassBuilder builder = new ClassBuilder(element, namer); |
| containerBuilder.addMemberMethod(method, builder); |
| - getElementDescriptor(element).properties.addAll(builder.properties); |
| + getElementDescriptor(element, fragment).properties |
| + .addAll(builder.properties); |
| } |
| } |
| @@ -951,7 +954,8 @@ class OldEmitter implements Emitter { |
| output.add(N); |
| } |
| - void writeLibraryDescriptor(CodeOutput output, LibraryElement library) { |
| + void writeLibraryDescriptor(CodeOutput output, LibraryElement library, |
| + Fragment fragment) { |
| var uri = ""; |
| if (!compiler.enableMinification || backend.mustPreserveUris) { |
| uri = library.canonicalUri; |
| @@ -959,7 +963,7 @@ class OldEmitter implements Emitter { |
| uri = relativize(compiler.outputUri, library.canonicalUri, false); |
| } |
| } |
| - ClassBuilder descriptor = elementDescriptors[library]; |
| + ClassBuilder descriptor = elementDescriptors[fragment][library]; |
| if (descriptor == null) { |
| // Nothing of the library was emitted. |
| // TODO(floitsch): this should not happen. We currently have an example |
| @@ -998,7 +1002,7 @@ class OldEmitter implements Emitter { |
| ..add('],$n'); |
| } |
| - void emitPrecompiledConstructor(OutputUnit outputUnit, |
| + void assemblePrecompiledConstructor(OutputUnit outputUnit, |
| String constructorName, |
|
karlklose
2015/04/17 11:26:10
Align parameters.
herhut
2015/04/17 11:37:30
Done.
|
| jsAst.Expression constructorAst, |
| List<String> fields) { |
| @@ -1031,8 +1035,9 @@ class OldEmitter implements Emitter { |
| cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); |
| } |
| - void emitTypedefs() { |
| - OutputUnit mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; |
| + void assembleTypedefs(Program program) { |
| + Fragment mainFragment = program.mainFragment; |
| + OutputUnit mainOutputUnit = mainFragment.outputUnit; |
| // Emit all required typedef declarations into the main output unit. |
| // TODO(karlklose): unify required classes and typedefs to declarations |
| @@ -1056,14 +1061,14 @@ class OldEmitter implements Emitter { |
| jsAst.Node declaration = builder.toObjectInitializer(); |
| String mangledName = namer.globalPropertyName(typedef); |
| String reflectionName = getReflectionName(typedef, mangledName); |
| - getElementDescriptor(library) |
| + getElementDescriptor(library, mainFragment) |
| ..addProperty(mangledName, declaration) |
| ..addProperty("+$reflectionName", js.string('')); |
| // Also emit a trivial constructor for CSP mode. |
| String constructorName = mangledName; |
| jsAst.Expression constructorAst = js('function() {}'); |
| List<String> fieldNames = []; |
| - emitPrecompiledConstructor(mainOutputUnit, |
| + assemblePrecompiledConstructor(mainOutputUnit, |
|
karlklose
2015/04/17 11:26:10
Align arguments.
herhut
2015/04/17 11:37:30
Done.
|
| constructorName, |
| constructorAst, |
| fieldNames); |
| @@ -1131,19 +1136,29 @@ class OldEmitter implements Emitter { |
| } |
| } |
| - void emitLibrary(Library library) { |
| + void assembleLibrary(Library library, Fragment fragment) { |
| LibraryElement libraryElement = library.element; |
| - emitStaticFunctions(library.statics); |
| + assembleStaticFunctions(library.statics, fragment); |
| - ClassBuilder libraryBuilder = getElementDescriptor(libraryElement); |
| + ClassBuilder libraryBuilder = |
| + getElementDescriptor(libraryElement, fragment); |
| for (Class cls in library.classes) { |
| - emitClass(cls, libraryBuilder); |
| + assembleClass(cls, libraryBuilder, fragment); |
| } |
| classEmitter.emitFields(library, libraryBuilder, emitStatics: true); |
| } |
| + void assembleProgram(Program program) { |
| + for (Fragment fragment in program.fragments) { |
| + for (Library library in fragment.libraries) { |
| + assembleLibrary(library, fragment); |
| + } |
| + } |
| + assembleTypedefs(program); |
| + } |
| + |
| void emitMainOutputUnit(Program program, |
| Map<OutputUnit, String> deferredLoadHashes) { |
| MainFragment mainFragment = program.fragments.first; |
| @@ -1243,24 +1258,23 @@ class OldEmitter implements Emitter { |
| mainOutput.add('$isolateProperties$_=$_$isolatePropertiesName$N'); |
| emitFunctionThatReturnsNull(mainOutput); |
| - mainFragment.libraries.forEach(emitLibrary); |
| Iterable<LibraryElement> libraries = |
| task.outputLibraryLists[mainOutputUnit]; |
| if (libraries == null) libraries = []; |
| - emitTypedefs(); |
| emitMangledNames(mainOutput); |
| - checkEverythingEmitted(elementDescriptors.keys); |
| + Map<Element, ClassBuilder> descriptors = elementDescriptors[mainFragment]; |
| + checkEverythingEmitted(descriptors.keys); |
| CodeBuffer libraryBuffer = new CodeBuffer(); |
| for (LibraryElement library in Elements.sortedByPosition(libraries)) { |
| - writeLibraryDescriptor(libraryBuffer, library); |
| - elementDescriptors.remove(library); |
| + writeLibraryDescriptor(libraryBuffer, library, mainFragment); |
| + descriptors.remove(library); |
| } |
| - if (elementDescriptors.isNotEmpty) { |
| - List<Element> remainingLibraries = elementDescriptors.keys |
| + if (descriptors.isNotEmpty) { |
| + List<Element> remainingLibraries = descriptors.keys |
| .where((Element e) => e is LibraryElement) |
| .toList(); |
| @@ -1270,8 +1284,8 @@ class OldEmitter implements Emitter { |
| for (LibraryElement element in remainingLibraries) { |
| assert(element is LibraryElement || compiler.hasIncrementalSupport); |
| if (element is LibraryElement) { |
| - writeLibraryDescriptor(libraryBuffer, element); |
| - elementDescriptors.remove(element); |
| + writeLibraryDescriptor(libraryBuffer, element, mainFragment); |
| + descriptors.remove(element); |
| } |
| } |
| } |
| @@ -1537,10 +1551,9 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| for (Fragment fragment in program.deferredFragments) { |
| OutputUnit outputUnit = fragment.outputUnit; |
| + Map<Element, ClassBuilder> descriptors = elementDescriptors[fragment]; |
| - fragment.libraries.forEach(emitLibrary); |
| - |
| - if (elementDescriptors.isNotEmpty) { |
| + if (descriptors.isNotEmpty) { |
| Iterable<LibraryElement> libraries = |
| task.outputLibraryLists[outputUnit]; |
| if (libraries == null) libraries = []; |
| @@ -1549,8 +1562,8 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| CodeBuffer buffer = new CodeBuffer(); |
| outputBuffers[outputUnit] = buffer; |
| for (LibraryElement library in Elements.sortedByPosition(libraries)) { |
| - writeLibraryDescriptor(buffer, library); |
| - elementDescriptors.remove(library); |
| + writeLibraryDescriptor(buffer, library, fragment); |
| + descriptors.remove(library); |
| } |
| } |
| } |
| @@ -1562,6 +1575,8 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| Program program = programBuilder.buildProgram( |
| storeFunctionTypesInMetadata: true); |
| + assembleProgram(program); |
| + |
| // Shorten the code by using [namer.currentIsolate] as temporary. |
| isolateProperties = namer.currentIsolate; |
| @@ -1593,7 +1608,7 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| return ''; |
| } |
| - ClassBuilder getElementDescriptor(Element element) { |
| + ClassBuilder getElementDescriptor(Element element, Fragment fragment) { |
| Element owner = element.library; |
| if (!element.isLibrary && !element.isTopLevel && !element.isNative) { |
| // For static (not top level) elements, record their code in a buffer |
| @@ -1612,6 +1627,8 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| compiler.internalError(element, 'Owner is null.'); |
| } |
| return elementDescriptors.putIfAbsent( |
|
karlklose
2015/04/17 11:26:10
How about formatting this as:
return elementDesc
herhut
2015/04/17 11:37:30
How about this one?
|
| + fragment, |
| + () => new Map<Element, ClassBuilder>()).putIfAbsent( |
| owner, |
| () => new ClassBuilder(owner, namer)); |
| } |