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

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

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
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(
11 AstElement element, ElementAst elementAst, 11 AstElement element, ElementAst elementAst,
12 ElementCallback<TypedefElement> typedefCallback, 12 ElementCallback<TypedefElement> typedefCallback,
13 ElementCallback<ClassElement> classCallback); 13 ElementCallback<ClassElement> classCallback);
14 typedef ElementAst ComputeElementAstFunction(AstElement element); 14 typedef ElementAst ComputeElementAstFunction(AstElement element);
15 typedef bool ElementFilter(Element element); 15 typedef bool ElementFilter(Element element);
16 typedef List<Element> ElementSorter(Iterable<Element> elements); 16 typedef List<Element> ElementSorter(Iterable<Element> elements);
17 17
18 /// Output engine for dart2dart that is shared between the dart2js and the 18 /// Output engine for dart2dart that is shared between the dart2js and the
19 /// analyzer implementations of dart2dart. 19 /// analyzer implementations of dart2dart.
20 class DartOutputter { 20 class DartOutputter {
21 final DiagnosticListener listener; 21 final DiagnosticReporter listener;
sigurdm 2015/10/05 13:45:34 Rename variable? (several occurences in this file)
Johnni Winther 2015/10/06 08:04:32 Done.
22 final CompilerOutputProvider outputProvider; 22 final CompilerOutputProvider outputProvider;
23 final bool forceStripTypes; 23 final bool forceStripTypes;
24 24
25 // TODO(antonm): make available from command-line options. 25 // TODO(antonm): make available from command-line options.
26 final bool outputAst = false; 26 final bool outputAst = false;
27 final bool enableMinification; 27 final bool enableMinification;
28 28
29 /// If `true`, libraries are generated into separate files. 29 /// If `true`, libraries are generated into separate files.
30 final bool multiFile; 30 final bool multiFile;
31 31
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 outputUri, 140 outputUri,
141 outputProvider, 141 outputProvider,
142 mirrorRenamer, 142 mirrorRenamer,
143 multiFile: multiFile, 143 multiFile: multiFile,
144 forceStripTypes: forceStripTypes, 144 forceStripTypes: forceStripTypes,
145 enableMinification: enableMinification); 145 enableMinification: enableMinification);
146 } 146 }
147 } 147 }
148 148
149 static PlaceholderCollector collectPlaceholders( 149 static PlaceholderCollector collectPlaceholders(
150 DiagnosticListener listener, 150 DiagnosticReporter listener,
151 MirrorRenamer mirrorRenamer, 151 MirrorRenamer mirrorRenamer,
152 FunctionElement mainFunction, 152 FunctionElement mainFunction,
153 LibraryInfo libraryInfo, 153 LibraryInfo libraryInfo,
154 ElementInfo elementInfo) { 154 ElementInfo elementInfo) {
155 // Create all necessary placeholders. 155 // Create all necessary placeholders.
156 PlaceholderCollector collector = new PlaceholderCollector( 156 PlaceholderCollector collector = new PlaceholderCollector(
157 listener, 157 listener,
158 mirrorRenamer, 158 mirrorRenamer,
159 libraryInfo.fixedDynamicNames, 159 libraryInfo.fixedDynamicNames,
160 elementInfo.elementAsts, 160 elementInfo.elementAsts,
(...skipping 26 matching lines...) Expand all
187 libraryInfo.fixedDynamicNames, 187 libraryInfo.fixedDynamicNames,
188 libraryInfo.fixedStaticNames, 188 libraryInfo.fixedStaticNames,
189 libraryInfo.reexportingLibraries, 189 libraryInfo.reexportingLibraries,
190 cutDeclarationTypes: shouldCutDeclarationTypes, 190 cutDeclarationTypes: shouldCutDeclarationTypes,
191 enableMinification: enableMinification); 191 enableMinification: enableMinification);
192 192
193 placeholderRenamer.computeRenames(collector); 193 placeholderRenamer.computeRenames(collector);
194 return placeholderRenamer; 194 return placeholderRenamer;
195 } 195 }
196 196
197 static String astOutput(DiagnosticListener listener, 197 static String astOutput(DiagnosticReporter listener,
198 ElementInfo elementInfo) { 198 ElementInfo elementInfo) {
199 // TODO(antonm): Ideally XML should be a separate backend. 199 // TODO(antonm): Ideally XML should be a separate backend.
200 // TODO(antonm): obey renames and minification, at least as an option. 200 // TODO(antonm): obey renames and minification, at least as an option.
201 StringBuffer sb = new StringBuffer(); 201 StringBuffer sb = new StringBuffer();
202 outputElement(element) { 202 outputElement(element) {
203 sb.write(element.parseNode(listener).toDebugString()); 203 sb.write(element.parseNode(listener).toDebugString());
204 } 204 }
205 205
206 // Emit XML for AST instead of the program. 206 // Emit XML for AST instead of the program.
207 for (Element topLevel in elementInfo.topLevelElements) { 207 for (Element topLevel in elementInfo.topLevelElements) {
(...skipping 14 matching lines...) Expand all
222 final Set<String> fixedDynamicNames; 222 final Set<String> fixedDynamicNames;
223 final Map<Element, LibraryElement> reexportingLibraries; 223 final Map<Element, LibraryElement> reexportingLibraries;
224 final List<LibraryElement> userLibraries; 224 final List<LibraryElement> userLibraries;
225 225
226 LibraryInfo(this.fixedStaticNames, 226 LibraryInfo(this.fixedStaticNames,
227 this.fixedDynamicNames, 227 this.fixedDynamicNames,
228 this.reexportingLibraries, 228 this.reexportingLibraries,
229 this.userLibraries); 229 this.userLibraries);
230 230
231 static LibraryInfo processLibraries( 231 static LibraryInfo processLibraries(
232 DiagnosticListener listener, 232 DiagnosticReporter reporter,
233 Iterable<LibraryElement> libraries, 233 Iterable<LibraryElement> libraries,
234 Iterable<AstElement> resolvedElements) { 234 Iterable<AstElement> resolvedElements) {
235 Set<String> fixedStaticNames = new Set<String>(); 235 Set<String> fixedStaticNames = new Set<String>();
236 Set<String> fixedDynamicNames = new Set<String>(); 236 Set<String> fixedDynamicNames = new Set<String>();
237 Map<Element, LibraryElement> reexportingLibraries = 237 Map<Element, LibraryElement> reexportingLibraries =
238 <Element, LibraryElement>{}; 238 <Element, LibraryElement>{};
239 List<LibraryElement> userLibraries = <LibraryElement>[]; 239 List<LibraryElement> userLibraries = <LibraryElement>[];
240 // Conservatively traverse all platform libraries and collect member names. 240 // Conservatively traverse all platform libraries and collect member names.
241 // TODO(antonm): ideally we should only collect names of used members, 241 // TODO(antonm): ideally we should only collect names of used members,
242 // however as of today there are problems with names of some core library 242 // however as of today there are problems with names of some core library
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 fixedDynamicNames.add(parameter.name); 292 fixedDynamicNames.add(parameter.name);
293 } 293 }
294 } 294 }
295 ClassElement cls = element.enclosingClass; 295 ClassElement cls = element.enclosingClass;
296 if (cls != null && cls.isEnumClass) { 296 if (cls != null && cls.isEnumClass) {
297 fixedDynamicNames.add('index'); 297 fixedDynamicNames.add('index');
298 298
299 ClassElement existingEnumClass = 299 ClassElement existingEnumClass =
300 enumClassMap.putIfAbsent(cls.name, () => cls); 300 enumClassMap.putIfAbsent(cls.name, () => cls);
301 if (existingEnumClass != cls) { 301 if (existingEnumClass != cls) {
302 listener.reportError( 302 reporter.reportError(
303 listener.createMessage( 303 reporter.createMessage(
304 cls, 304 cls,
305 MessageKind.GENERIC, 305 MessageKind.GENERIC,
306 {'text': "Duplicate enum names are not supported " 306 {'text': "Duplicate enum names are not supported "
307 "in dart2dart."}), 307 "in dart2dart."}),
308 <DiagnosticMessage>[ 308 <DiagnosticMessage>[
309 listener.createMessage( 309 reporter.createMessage(
310 existingEnumClass, 310 existingEnumClass,
311 MessageKind.GENERIC, 311 MessageKind.GENERIC,
312 {'text': "This is the other declaration of '${cls.name}'."}), 312 {'text': "This is the other declaration of '${cls.name}'."}),
313 ]); 313 ]);
314 } 314 }
315 } 315 }
316 } 316 }
317 317
318 fixedStaticNames.addAll(enumClassMap.keys); 318 fixedStaticNames.addAll(enumClassMap.keys);
319 319
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 outputProvider("", "dart") 596 outputProvider("", "dart")
597 ..add(code) 597 ..add(code)
598 ..close(); 598 ..close();
599 599
600 totalSize = code.length; 600 totalSize = code.length;
601 } 601 }
602 602
603 return totalSize; 603 return totalSize;
604 } 604 }
605 } 605 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698