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

Side by Side Diff: pkg/compiler/lib/src/dart_backend/outputter.dart

Issue 832363002: Remove Compiler.assembledCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 part of dart_backend; 5 part of dart_backend;
6 6
7 typedef bool IsSafeToRemoveTypeDeclarations( 7 typedef bool IsSafeToRemoveTypeDeclarations(
8 Map<ClassElement, Iterable<Element>> classMembers); 8 Map<ClassElement, Iterable<Element>> classMembers);
9 typedef void ElementCallback<E>(E element); 9 typedef void ElementCallback<E>(E element);
10 typedef void ElementPostProcessFunction( 10 typedef void ElementPostProcessFunction(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 /// referenced in the program. 48 /// referenced in the program.
49 /// 49 ///
50 /// [instantiatedClasses] is the set of classes that are potentially 50 /// [instantiatedClasses] is the set of classes that are potentially
51 /// instantiated in the program. 51 /// instantiated in the program.
52 /// 52 ///
53 /// [resolvedElements] is the set of methods, constructors, and fields that 53 /// [resolvedElements] is the set of methods, constructors, and fields that
54 /// are potentially accessed/called in the program. 54 /// are potentially accessed/called in the program.
55 /// 55 ///
56 /// The [sortElements] function is used to sort [instantiatedClasses] and 56 /// The [sortElements] function is used to sort [instantiatedClasses] and
57 /// [resolvedElements] in the generated output. 57 /// [resolvedElements] in the generated output.
58 String assembleProgram({ 58 ///
59 /// Returns the total size of the generated code.
60 int assembleProgram({
59 MirrorRenamer mirrorRenamer: const MirrorRenamer(), 61 MirrorRenamer mirrorRenamer: const MirrorRenamer(),
60 Iterable<LibraryElement> libraries, 62 Iterable<LibraryElement> libraries,
61 Iterable<Element> instantiatedClasses, 63 Iterable<Element> instantiatedClasses,
62 Iterable<Element> resolvedElements, 64 Iterable<Element> resolvedElements,
63 Iterable<ClassElement> usedTypeLiterals: const <ClassElement>[], 65 Iterable<ClassElement> usedTypeLiterals: const <ClassElement>[],
64 FunctionElement mainFunction, 66 FunctionElement mainFunction,
65 Uri outputUri, 67 Uri outputUri,
66 ElementPostProcessFunction postProcessElementAst, 68 ElementPostProcessFunction postProcessElementAst,
67 ComputeElementAstFunction computeElementAst, 69 ComputeElementAstFunction computeElementAst,
68 ElementFilter shouldOutput, 70 ElementFilter shouldOutput,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 elementInfo); 115 elementInfo);
114 116
115 renamer = createRenamer( 117 renamer = createRenamer(
116 collector, 118 collector,
117 libraryInfo, 119 libraryInfo,
118 elementInfo, 120 elementInfo,
119 enableMinification: enableMinification, 121 enableMinification: enableMinification,
120 forceStripTypes: forceStripTypes, 122 forceStripTypes: forceStripTypes,
121 isSafeToRemoveTypeDeclarations: isSafeToRemoveTypeDeclarations); 123 isSafeToRemoveTypeDeclarations: isSafeToRemoveTypeDeclarations);
122 124
123 String assembledCode;
124 if (outputAst) { 125 if (outputAst) {
125 assembledCode = astOutput(listener, elementInfo); 126 String code = astOutput(listener, elementInfo);
127 outputProvider("", "dart")
128 ..add(code)
129 ..close();
130 return code.length;
126 } else { 131 } else {
127 output = new MainOutputGenerator(); 132 output = new MainOutputGenerator();
128 assembledCode = output.generateCode( 133 return output.generateCode(
129 libraryInfo, 134 libraryInfo,
130 elementInfo, 135 elementInfo,
131 collector, 136 collector,
132 renamer, 137 renamer,
133 mainFunction, 138 mainFunction,
134 outputUri, 139 outputUri,
135 outputProvider, 140 outputProvider,
136 mirrorRenamer, 141 mirrorRenamer,
137 multiFile: multiFile, 142 multiFile: multiFile,
138 forceStripTypes: forceStripTypes, 143 forceStripTypes: forceStripTypes,
139 enableMinification: enableMinification); 144 enableMinification: enableMinification);
140 } 145 }
141 return assembledCode;
142 } 146 }
143 147
144 static PlaceholderCollector collectPlaceholders( 148 static PlaceholderCollector collectPlaceholders(
145 DiagnosticListener listener, 149 DiagnosticListener listener,
146 MirrorRenamer mirrorRenamer, 150 MirrorRenamer mirrorRenamer,
147 FunctionElement mainFunction, 151 FunctionElement mainFunction,
148 LibraryInfo libraryInfo, 152 LibraryInfo libraryInfo,
149 ElementInfo elementInfo) { 153 ElementInfo elementInfo) {
150 // Create all necessary placeholders. 154 // Create all necessary placeholders.
151 PlaceholderCollector collector = new PlaceholderCollector( 155 PlaceholderCollector collector = new PlaceholderCollector(
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 428 }
425 } 429 }
426 430
427 /// Main output generator for [DartOutputter] that emits dart code through a 431 /// Main output generator for [DartOutputter] that emits dart code through a
428 /// [CompilerOutputProvider]. 432 /// [CompilerOutputProvider].
429 class MainOutputGenerator { 433 class MainOutputGenerator {
430 final Map<ClassNode, List<Node>> memberNodes = 434 final Map<ClassNode, List<Node>> memberNodes =
431 new Map<ClassNode, List<Node>>(); 435 new Map<ClassNode, List<Node>>();
432 final List<Node> topLevelNodes = <Node>[]; 436 final List<Node> topLevelNodes = <Node>[];
433 437
434 String generateCode( 438 /// Generates the code and returns the total size.
439 int generateCode(
435 LibraryInfo libraryInfo, 440 LibraryInfo libraryInfo,
436 ElementInfo elementInfo, 441 ElementInfo elementInfo,
437 PlaceholderCollector collector, 442 PlaceholderCollector collector,
438 PlaceholderRenamer placeholderRenamer, 443 PlaceholderRenamer placeholderRenamer,
439 FunctionElement mainFunction, 444 FunctionElement mainFunction,
440 Uri outputUri, 445 Uri outputUri,
441 CompilerOutputProvider outputProvider, 446 CompilerOutputProvider outputProvider,
442 MirrorRenamer mirrorRenamer, 447 MirrorRenamer mirrorRenamer,
443 {bool multiFile: false, 448 {bool multiFile: false,
444 bool forceStripTypes: false, 449 bool forceStripTypes: false,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if (node is ClassNode) { 537 if (node is ClassNode) {
533 // TODO(smok): Filter out default constructors here. 538 // TODO(smok): Filter out default constructors here.
534 unparser.unparseClassWithBody(node, memberNodes[node]); 539 unparser.unparseClassWithBody(node, memberNodes[node]);
535 } else { 540 } else {
536 unparser.unparse(node); 541 unparser.unparse(node);
537 } 542 }
538 unparser.newline(); 543 unparser.newline();
539 } 544 }
540 545
541 int totalSize = 0; 546 int totalSize = 0;
542 String assembledCode;
543 if (multiFile) { 547 if (multiFile) {
544 for(LibraryElement outputLibrary in libraryInfo.userLibraries) { 548 for(LibraryElement outputLibrary in libraryInfo.userLibraries) {
545 // TODO(sigurdm): Make the unparser output directly into the buffer 549 // TODO(sigurdm): Make the unparser output directly into the buffer
546 // instead of caching in `.result`. 550 // instead of caching in `.result`.
547 String code = unparsers[outputLibrary].result; 551 String code = unparsers[outputLibrary].result;
548 totalSize += code.length; 552 totalSize += code.length;
549 outputProvider(outputPaths[outputLibrary], "dart") 553 outputProvider(outputPaths[outputLibrary], "dart")
550 ..add(code) 554 ..add(code)
551 ..close(); 555 ..close();
552 } 556 }
553 // TODO(sigurdm): We should get rid of compiler.assembledCode.
554 assembledCode = unparsers[mainFunction.library].result;
555 } else { 557 } else {
556 assembledCode = mainUnparser.result; 558 String code = mainUnparser.result;
557 outputProvider("", "dart") 559 outputProvider("", "dart")
558 ..add(assembledCode) 560 ..add(code)
559 ..close(); 561 ..close();
560 562
561 totalSize = assembledCode.length; 563 totalSize = code.length;
562 } 564 }
563 565
564 return assembledCode; 566 return totalSize;
565 } 567 }
566 } 568 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698