Index: pkg/compiler/lib/src/dart_backend/outputter.dart |
diff --git a/pkg/compiler/lib/src/dart_backend/outputter.dart b/pkg/compiler/lib/src/dart_backend/outputter.dart |
index 484bda298d61885beb97f75d175610b88ed8d115..ce9022afe009326af0e269327da520c675426c0f 100644 |
--- a/pkg/compiler/lib/src/dart_backend/outputter.dart |
+++ b/pkg/compiler/lib/src/dart_backend/outputter.dart |
@@ -8,7 +8,8 @@ typedef bool IsSafeToRemoveTypeDeclarations( |
Map<ClassElement, Iterable<Element>> classMembers); |
typedef void ElementCallback<E>(E element); |
typedef void ElementPostProcessFunction( |
- AstElement element, ElementAst elementAst, |
+ AstElement element, |
+ ElementAst elementAst, |
ElementCallback<TypedefElement> typedefCallback, |
ElementCallback<ClassElement> classCallback); |
typedef ElementAst ComputeElementAstFunction(AstElement element); |
@@ -38,9 +39,9 @@ class DartOutputter { |
// TODO(johnniwinther): Support recompilation. |
DartOutputter(this.reporter, this.outputProvider, |
- {bool this.forceStripTypes: false, |
- bool this.enableMinification: false, |
- bool this.multiFile: false}); |
+ {bool this.forceStripTypes: false, |
+ bool this.enableMinification: false, |
+ bool this.multiFile: false}); |
/// Generate Dart code for the program starting at [mainFunction]. |
/// |
@@ -57,8 +58,8 @@ class DartOutputter { |
/// [resolvedElements] in the generated output. |
/// |
/// Returns the total size of the generated code. |
- int assembleProgram({ |
- MirrorRenamer mirrorRenamer: const MirrorRenamer(), |
+ int assembleProgram( |
+ {MirrorRenamer mirrorRenamer: const MirrorRenamer(), |
Iterable<LibraryElement> libraries, |
Iterable<Element> instantiatedClasses, |
Iterable<Element> resolvedElements, |
@@ -70,7 +71,6 @@ class DartOutputter { |
ElementFilter shouldOutput, |
IsSafeToRemoveTypeDeclarations isSafeToRemoveTypeDeclarations, |
ElementSorter sortElements}) { |
- |
assert(invariant(NO_LOCATION_SPANNABLE, libraries != null, |
message: "'libraries' must be non-null.")); |
assert(invariant(NO_LOCATION_SPANNABLE, instantiatedClasses != null, |
@@ -83,8 +83,8 @@ class DartOutputter { |
message: "'computeElementAst' must be non-null.")); |
assert(invariant(NO_LOCATION_SPANNABLE, shouldOutput != null, |
message: "'shouldOutput' must be non-null.")); |
- assert(invariant(NO_LOCATION_SPANNABLE, |
- isSafeToRemoveTypeDeclarations != null, |
+ assert(invariant( |
+ NO_LOCATION_SPANNABLE, isSafeToRemoveTypeDeclarations != null, |
message: "'isSafeToRemoveTypeDeclarations' must be non-null.")); |
if (sortElements == null) { |
@@ -96,29 +96,20 @@ class DartOutputter { |
}; |
} |
- libraryInfo = LibraryInfo.processLibraries( |
- reporter, libraries, resolvedElements); |
+ libraryInfo = |
+ LibraryInfo.processLibraries(reporter, libraries, resolvedElements); |
elementInfo = ElementInfoProcessor.createElementInfo( |
- instantiatedClasses, |
- resolvedElements, |
- usedTypeLiterals, |
+ instantiatedClasses, resolvedElements, usedTypeLiterals, |
postProcessElementAst: postProcessElementAst, |
parseElementAst: computeElementAst, |
shouldOutput: shouldOutput, |
sortElements: sortElements); |
PlaceholderCollector collector = collectPlaceholders( |
- reporter, |
- mirrorRenamer, |
- mainFunction, |
- libraryInfo, |
- elementInfo); |
- |
- renamer = createRenamer( |
- collector, |
- libraryInfo, |
- elementInfo, |
+ reporter, mirrorRenamer, mainFunction, libraryInfo, elementInfo); |
+ |
+ renamer = createRenamer(collector, libraryInfo, elementInfo, |
enableMinification: enableMinification, |
forceStripTypes: forceStripTypes, |
isSafeToRemoveTypeDeclarations: isSafeToRemoveTypeDeclarations); |
@@ -126,20 +117,13 @@ class DartOutputter { |
if (outputAst) { |
String code = astOutput(reporter, elementInfo); |
outputProvider("", "dart") |
- ..add(code) |
- ..close(); |
+ ..add(code) |
+ ..close(); |
return code.length; |
} else { |
output = new MainOutputGenerator(); |
- return output.generateCode( |
- libraryInfo, |
- elementInfo, |
- collector, |
- renamer, |
- mainFunction, |
- outputUri, |
- outputProvider, |
- mirrorRenamer, |
+ return output.generateCode(libraryInfo, elementInfo, collector, renamer, |
+ mainFunction, outputUri, outputProvider, mirrorRenamer, |
multiFile: multiFile, |
forceStripTypes: forceStripTypes, |
enableMinification: enableMinification); |
@@ -171,17 +155,15 @@ class DartOutputter { |
return collector; |
} |
- static PlaceholderRenamer createRenamer( |
- PlaceholderCollector collector, |
- LibraryInfo libraryInfo, |
- ElementInfo elementInfo, |
+ static PlaceholderRenamer createRenamer(PlaceholderCollector collector, |
+ LibraryInfo libraryInfo, ElementInfo elementInfo, |
{bool enableMinification: false, |
- bool forceStripTypes: false, |
- isSafeToRemoveTypeDeclarations}) { |
+ bool forceStripTypes: false, |
+ isSafeToRemoveTypeDeclarations}) { |
// Create renames. |
- bool shouldCutDeclarationTypes = forceStripTypes |
- || (enableMinification |
- && isSafeToRemoveTypeDeclarations(elementInfo.classMembers)); |
+ bool shouldCutDeclarationTypes = forceStripTypes || |
+ (enableMinification && |
+ isSafeToRemoveTypeDeclarations(elementInfo.classMembers)); |
PlaceholderRenamer placeholderRenamer = new PlaceholderRenamer( |
libraryInfo.fixedDynamicNames, |
@@ -194,8 +176,8 @@ class DartOutputter { |
return placeholderRenamer; |
} |
- static String astOutput(DiagnosticReporter reporter, |
- ElementInfo elementInfo) { |
+ static String astOutput( |
+ DiagnosticReporter reporter, ElementInfo elementInfo) { |
// TODO(antonm): Ideally XML should be a separate backend. |
// TODO(antonm): obey renames and minification, at least as an option. |
StringBuffer sb = new StringBuffer(); |
@@ -223,10 +205,8 @@ class LibraryInfo { |
final Map<Element, LibraryElement> reexportingLibraries; |
final List<LibraryElement> userLibraries; |
- LibraryInfo(this.fixedStaticNames, |
- this.fixedDynamicNames, |
- this.reexportingLibraries, |
- this.userLibraries); |
+ LibraryInfo(this.fixedStaticNames, this.fixedDynamicNames, |
+ this.reexportingLibraries, this.userLibraries); |
static LibraryInfo processLibraries( |
DiagnosticReporter reporter, |
@@ -235,7 +215,7 @@ class LibraryInfo { |
Set<String> fixedStaticNames = new Set<String>(); |
Set<String> fixedDynamicNames = new Set<String>(); |
Map<Element, LibraryElement> reexportingLibraries = |
- <Element, LibraryElement>{}; |
+ <Element, LibraryElement>{}; |
List<LibraryElement> userLibraries = <LibraryElement>[]; |
// Conservatively traverse all platform libraries and collect member names. |
// TODO(antonm): ideally we should only collect names of used members, |
@@ -268,8 +248,7 @@ class LibraryInfo { |
}); |
library.forEachExport((Element export) { |
- if (!library.isInternalLibrary && |
- export.library.isInternalLibrary) { |
+ if (!library.isInternalLibrary && export.library.isInternalLibrary) { |
// If an element of an internal library is reexported by a platform |
// library, we have to import the reexporting library instead of the |
// internal library, because the internal library is an |
@@ -300,17 +279,15 @@ class LibraryInfo { |
enumClassMap.putIfAbsent(cls.name, () => cls); |
if (existingEnumClass != cls) { |
reporter.reportError( |
- reporter.createMessage( |
- cls, |
- MessageKind.GENERIC, |
- {'text': "Duplicate enum names are not supported " |
- "in dart2dart."}), |
- <DiagnosticMessage>[ |
- reporter.createMessage( |
- existingEnumClass, |
- MessageKind.GENERIC, |
- {'text': "This is the other declaration of '${cls.name}'."}), |
- ]); |
+ reporter.createMessage(cls, MessageKind.GENERIC, { |
+ 'text': "Duplicate enum names are not supported " |
+ "in dart2dart." |
+ }), |
+ <DiagnosticMessage>[ |
+ reporter.createMessage(existingEnumClass, MessageKind.GENERIC, { |
+ 'text': "This is the other declaration of '${cls.name}'." |
+ }), |
+ ]); |
} |
} |
} |
@@ -321,8 +298,7 @@ class LibraryInfo { |
// that are invoked as functions. Make sure to not rename that. |
fixedDynamicNames.add('call'); |
- return new LibraryInfo( |
- fixedStaticNames, fixedDynamicNames, |
+ return new LibraryInfo(fixedStaticNames, fixedDynamicNames, |
reexportingLibraries, userLibraries); |
} |
} |
@@ -333,10 +309,8 @@ class ElementInfo { |
final Map<ClassElement, Iterable<Element>> classMembers; |
final Iterable<ClassElement> emitNoMembersFor; |
- ElementInfo(this.elementAsts, |
- this.topLevelElements, |
- this.classMembers, |
- this.emitNoMembersFor); |
+ ElementInfo(this.elementAsts, this.topLevelElements, this.classMembers, |
+ this.emitNoMembersFor); |
} |
class ElementInfoProcessor implements ElementInfo { |
@@ -350,18 +324,16 @@ class ElementInfoProcessor implements ElementInfo { |
final ElementFilter shouldOutput; |
ElementInfoProcessor( |
- {this.postProcessElementAst, |
- this.parseElementAst, |
- this.shouldOutput}); |
+ {this.postProcessElementAst, this.parseElementAst, this.shouldOutput}); |
static ElementInfo createElementInfo( |
Iterable<ClassElement> instantiatedClasses, |
Iterable<AstElement> resolvedElements, |
Iterable<ClassElement> usedTypeLiterals, |
{ElementPostProcessFunction postProcessElementAst, |
- ComputeElementAstFunction parseElementAst, |
- ElementFilter shouldOutput, |
- ElementSorter sortElements}) { |
+ ComputeElementAstFunction parseElementAst, |
+ ElementFilter shouldOutput, |
+ ElementSorter sortElements}) { |
ElementInfoProcessor processor = new ElementInfoProcessor( |
postProcessElementAst: postProcessElementAst, |
parseElementAst: parseElementAst, |
@@ -371,10 +343,11 @@ class ElementInfoProcessor implements ElementInfo { |
sortElements: sortElements); |
} |
- ElementInfo process(Iterable<ClassElement> instantiatedClasses, |
- Iterable<AstElement> resolvedElements, |
- Iterable<ClassElement> usedTypeLiterals, |
- {ElementSorter sortElements}) { |
+ ElementInfo process( |
+ Iterable<ClassElement> instantiatedClasses, |
+ Iterable<AstElement> resolvedElements, |
+ Iterable<ClassElement> usedTypeLiterals, |
+ {ElementSorter sortElements}) { |
// Build all top level elements to emit and necessary class members. |
instantiatedClasses.where(shouldOutput).forEach(addClass); |
resolvedElements.where(shouldOutput).forEach(addMember); |
@@ -402,9 +375,8 @@ class ElementInfoProcessor implements ElementInfo { |
void processElement(Element element, ElementAst elementAst) { |
if (postProcessElementAst != null) { |
- postProcessElementAst(element, elementAst, |
- newTypedefElementCallback, |
- newClassElementCallback); |
+ postProcessElementAst(element, elementAst, newTypedefElementCallback, |
+ newClassElementCallback); |
} |
elementAsts[element] = elementAst; |
} |
@@ -459,7 +431,7 @@ class ElementInfoProcessor implements ElementInfo { |
/// [CompilerOutputProvider]. |
class MainOutputGenerator { |
final Map<ClassNode, List<Node>> memberNodes = |
- new Map<ClassNode, List<Node>>(); |
+ new Map<ClassNode, List<Node>>(); |
final List<Node> topLevelNodes = <Node>[]; |
/// Generates the code and returns the total size. |
@@ -473,8 +445,8 @@ class MainOutputGenerator { |
CompilerOutputProvider outputProvider, |
MirrorRenamer mirrorRenamer, |
{bool multiFile: false, |
- bool forceStripTypes: false, |
- bool enableMinification: false}) { |
+ bool forceStripTypes: false, |
+ bool enableMinification: false}) { |
for (Element element in elementInfo.topLevelElements) { |
topLevelNodes.add(elementInfo.elementAsts[element].ast); |
if (element.isClass) { |
@@ -490,8 +462,8 @@ class MainOutputGenerator { |
} |
} |
- mirrorRenamer.addRenames(placeholderRenamer.renames, |
- topLevelNodes, collector); |
+ mirrorRenamer.addRenames( |
+ placeholderRenamer.renames, topLevelNodes, collector); |
Map<LibraryElement, String> outputPaths = new Map<LibraryElement, String>(); |
Map<LibraryElement, EmitterUnparser> unparsers = |
@@ -501,8 +473,7 @@ class MainOutputGenerator { |
EmitterUnparser mainUnparser = multiFile |
? null |
: new EmitterUnparser(placeholderRenamer.renames, |
- stripTypes: forceStripTypes, |
- minify: enableMinification); |
+ stripTypes: forceStripTypes, minify: enableMinification); |
if (multiFile) { |
// TODO(sigurdm): Factor handling of library-paths out from emitting. |
@@ -528,7 +499,7 @@ class MainOutputGenerator { |
} |
/// Rewrites imports/exports to refer to the paths given in [outputPaths]. |
- for(LibraryElement outputLibrary in libraryInfo.userLibraries) { |
+ for (LibraryElement outputLibrary in libraryInfo.userLibraries) { |
EmitterUnparser unparser = new EmitterUnparser( |
placeholderRenamer.renames, |
stripTypes: forceStripTypes, |
@@ -553,8 +524,8 @@ class MainOutputGenerator { |
} |
} |
} else { |
- placeholderRenamer.platformImports.forEach( |
- (LibraryElement library, String prefix) { |
+ placeholderRenamer.platformImports |
+ .forEach((LibraryElement library, String prefix) { |
assert(library.isPlatformLibrary && !library.isInternalLibrary); |
mainUnparser.unparseImportTag(library.canonicalUri.toString()); |
if (prefix != null) { |
@@ -562,7 +533,7 @@ class MainOutputGenerator { |
// it to avoid shadowing. |
// TODO(johnniwinther): Avoid prefix-less import if not needed. |
mainUnparser.unparseImportTag(library.canonicalUri.toString(), |
- prefix: prefix); |
+ prefix: prefix); |
} |
}); |
} |
@@ -582,20 +553,20 @@ class MainOutputGenerator { |
int totalSize = 0; |
if (multiFile) { |
- for(LibraryElement outputLibrary in libraryInfo.userLibraries) { |
+ for (LibraryElement outputLibrary in libraryInfo.userLibraries) { |
// TODO(sigurdm): Make the unparser output directly into the buffer |
// instead of caching in `.result`. |
String code = unparsers[outputLibrary].result; |
totalSize += code.length; |
outputProvider(outputPaths[outputLibrary], "dart") |
- ..add(code) |
- ..close(); |
+ ..add(code) |
+ ..close(); |
} |
} else { |
String code = mainUnparser.result; |
outputProvider("", "dart") |
- ..add(code) |
- ..close(); |
+ ..add(code) |
+ ..close(); |
totalSize = code.length; |
} |