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

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

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixes after rebase. 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // TODO(ahe): This class is simply wrong. This backend should use 7 // TODO(ahe): This class is simply wrong. This backend should use
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, 8 // elements when it can, not AST nodes. Perhaps a [Map<Element,
9 // TreeElements>] is what is needed. 9 // TreeElements>] is what is needed.
10 class ElementAst { 10 class ElementAst {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 DartResolutionCallbacks resolutionCallbacks; 45 DartResolutionCallbacks resolutionCallbacks;
46 46
47 final Set<ClassElement> usedTypeLiterals = new Set<ClassElement>(); 47 final Set<ClassElement> usedTypeLiterals = new Set<ClassElement>();
48 48
49 /// The set of visible platform classes that are implemented by instantiated 49 /// The set of visible platform classes that are implemented by instantiated
50 /// user classes. 50 /// user classes.
51 final Set<ClassElement> _userImplementedPlatformClasses = 51 final Set<ClassElement> _userImplementedPlatformClasses =
52 new Set<ClassElement>(); 52 new Set<ClassElement>();
53 53
54 bool enableCodegenWithErrorsIfSupported(Spannable node) { 54 bool enableCodegenWithErrorsIfSupported(Spannable node) {
55 compiler.reportHintMessage( 55 reporter.reportHintMessage(
56 node, 56 node,
57 MessageKind.GENERIC, 57 MessageKind.GENERIC,
58 {'text': "Generation of code with compile time errors is not " 58 {'text': "Generation of code with compile time errors is not "
59 "supported for dart2dart."}); 59 "supported for dart2dart."});
60 return false; 60 return false;
61 } 61 }
62 62
63 /** 63 /**
64 * Tells whether it is safe to remove type declarations from variables, 64 * Tells whether it is safe to remove type declarations from variables,
65 * functions parameters. It becomes not safe if: 65 * functions parameters. It becomes not safe if:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 101 }
102 } 102 }
103 return true; 103 return true;
104 } 104 }
105 105
106 DartBackend(Compiler compiler, List<String> strips, {bool multiFile}) 106 DartBackend(Compiler compiler, List<String> strips, {bool multiFile})
107 : tasks = <CompilerTask>[], 107 : tasks = <CompilerTask>[],
108 stripAsserts = strips.indexOf('asserts') != -1, 108 stripAsserts = strips.indexOf('asserts') != -1,
109 constantCompilerTask = new DartConstantTask(compiler), 109 constantCompilerTask = new DartConstantTask(compiler),
110 outputter = new DartOutputter( 110 outputter = new DartOutputter(
111 compiler, compiler.outputProvider, 111 compiler.reporter, compiler.outputProvider,
112 forceStripTypes: strips.indexOf('types') != -1, 112 forceStripTypes: strips.indexOf('types') != -1,
113 multiFile: multiFile, 113 multiFile: multiFile,
114 enableMinification: compiler.enableMinification), 114 enableMinification: compiler.enableMinification),
115 super(compiler) { 115 super(compiler) {
116 resolutionCallbacks = new DartResolutionCallbacks(this); 116 resolutionCallbacks = new DartResolutionCallbacks(this);
117 } 117 }
118 118
119
120 DiagnosticReporter get reporter => compiler.reporter;
121
119 Resolution get resolution => compiler.resolution; 122 Resolution get resolution => compiler.resolution;
120 123
121 bool classNeedsRti(ClassElement cls) => false; 124 bool classNeedsRti(ClassElement cls) => false;
122 bool methodNeedsRti(FunctionElement function) => false; 125 bool methodNeedsRti(FunctionElement function) => false;
123 126
124 void enqueueHelpers(ResolutionEnqueuer world, Registry registry) { 127 void enqueueHelpers(ResolutionEnqueuer world, Registry registry) {
125 // Right now resolver doesn't always resolve interfaces needed 128 // Right now resolver doesn't always resolve interfaces needed
126 // for literals, so force them. TODO(antonm): fix in the resolver. 129 // for literals, so force them. TODO(antonm): fix in the resolver.
127 final LITERAL_TYPE_NAMES = const [ 130 final LITERAL_TYPE_NAMES = const [
128 'Map', 'List', 'num', 'int', 'double', 'bool' 131 'Map', 'List', 'num', 'int', 'double', 'bool'
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return new ElementAst(element.resolvedAst.node, 165 return new ElementAst(element.resolvedAst.node,
163 element.resolvedAst.elements); 166 element.resolvedAst.elements);
164 } 167 }
165 168
166 // TODO(johnniwinther): Remove the need for this method. 169 // TODO(johnniwinther): Remove the need for this method.
167 void postProcessElementAst( 170 void postProcessElementAst(
168 AstElement element, ElementAst elementAst, 171 AstElement element, ElementAst elementAst,
169 newTypedefElementCallback, 172 newTypedefElementCallback,
170 newClassElementCallback) { 173 newClassElementCallback) {
171 ReferencedElementCollector collector = 174 ReferencedElementCollector collector =
172 new ReferencedElementCollector(compiler, 175 new ReferencedElementCollector(reporter,
173 element, 176 element,
174 elementAst, 177 elementAst,
175 newTypedefElementCallback, 178 newTypedefElementCallback,
176 newClassElementCallback); 179 newClassElementCallback);
177 collector.collect(); 180 collector.collect();
178 } 181 }
179 182
180 int totalSize = outputter.assembleProgram( 183 int totalSize = outputter.assembleProgram(
181 libraries: compiler.libraryLoader.libraries, 184 libraries: compiler.libraryLoader.libraries,
182 instantiatedClasses: compiler.resolverWorld.directlyInstantiatedClasses, 185 instantiatedClasses: compiler.resolverWorld.directlyInstantiatedClasses,
(...skipping 26 matching lines...) Expand all
209 for (LibraryElement lib in userLibraries) { 212 for (LibraryElement lib in userLibraries) {
210 for (CompilationUnitElement compilationUnit in lib.compilationUnits) { 213 for (CompilationUnitElement compilationUnit in lib.compilationUnits) {
211 nonPlatformSize += compilationUnit.script.file.length; 214 nonPlatformSize += compilationUnit.script.file.length;
212 } 215 }
213 } 216 }
214 int percentage = totalOutputSize * 100 ~/ nonPlatformSize; 217 int percentage = totalOutputSize * 100 ~/ nonPlatformSize;
215 log('Total used non-platform files size: ${nonPlatformSize} bytes, ' 218 log('Total used non-platform files size: ${nonPlatformSize} bytes, '
216 'Output total size: $totalOutputSize bytes (${percentage}%)'); 219 'Output total size: $totalOutputSize bytes (${percentage}%)');
217 } 220 }
218 221
219 log(String message) => compiler.log('[DartBackend] $message'); 222 log(String message) => reporter.log('[DartBackend] $message');
220 223
221 @override 224 @override
222 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { 225 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) {
223 // All platform classes must be resolved to ensure that their member names 226 // All platform classes must be resolved to ensure that their member names
224 // are preserved. 227 // are preserved.
225 loadedLibraries.forEachLibrary((LibraryElement library) { 228 loadedLibraries.forEachLibrary((LibraryElement library) {
226 if (library.isPlatformLibrary) { 229 if (library.isPlatformLibrary) {
227 library.forEachLocalMember((Element element) { 230 library.forEachLocalMember((Element element) {
228 if (element.isClass) { 231 if (element.isClass) {
229 ClassElement classElement = element; 232 ClassElement classElement = element;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 328 }
326 } 329 }
327 } 330 }
328 super.registerInstantiatedType( 331 super.registerInstantiatedType(
329 type, enqueuer, registry, mirrorUsage: mirrorUsage); 332 type, enqueuer, registry, mirrorUsage: mirrorUsage);
330 } 333 }
331 334
332 @override 335 @override
333 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) { 336 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry) {
334 // TODO(sigurdm): Implement deferred loading for dart2dart. 337 // TODO(sigurdm): Implement deferred loading for dart2dart.
335 compiler.reportWarningMessage( 338 reporter.reportWarningMessage(
336 node, MessageKind.DEFERRED_LIBRARY_DART_2_DART); 339 node, MessageKind.DEFERRED_LIBRARY_DART_2_DART);
337 return false; 340 return false;
338 } 341 }
339 } 342 }
340 343
341 class DartResolutionCallbacks extends ResolutionCallbacks { 344 class DartResolutionCallbacks extends ResolutionCallbacks {
342 final DartBackend backend; 345 final DartBackend backend;
343 346
344 DartResolutionCallbacks(this.backend); 347 DartResolutionCallbacks(this.backend);
345 348
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 383 }
381 384
382 385
383 /** 386 /**
384 * Some elements are not recorded by resolver now, 387 * Some elements are not recorded by resolver now,
385 * for example, typedefs or classes which are only 388 * for example, typedefs or classes which are only
386 * used in signatures, as/is operators or in super clauses 389 * used in signatures, as/is operators or in super clauses
387 * (just to name a few). Retraverse AST to pick those up. 390 * (just to name a few). Retraverse AST to pick those up.
388 */ 391 */
389 class ReferencedElementCollector extends Visitor { 392 class ReferencedElementCollector extends Visitor {
390 final Compiler compiler; 393 final DiagnosticReporter reporter;
391 final Element element; 394 final Element element;
392 final ElementAst elementAst; 395 final ElementAst elementAst;
393 final newTypedefElementCallback; 396 final newTypedefElementCallback;
394 final newClassElementCallback; 397 final newClassElementCallback;
395 398
396 ReferencedElementCollector(this.compiler, 399 ReferencedElementCollector(this.reporter,
397 this.element, 400 this.element,
398 this.elementAst, 401 this.elementAst,
399 this.newTypedefElementCallback, 402 this.newTypedefElementCallback,
400 this.newClassElementCallback); 403 this.newClassElementCallback);
401 404
402 visitNode(Node node) { 405 visitNode(Node node) {
403 node.visitChildren(this); 406 node.visitChildren(this);
404 } 407 }
405 408
406 visitTypeAnnotation(TypeAnnotation typeAnnotation) { 409 visitTypeAnnotation(TypeAnnotation typeAnnotation) {
407 TreeElements treeElements = elementAst.treeElements; 410 TreeElements treeElements = elementAst.treeElements;
408 final DartType type = treeElements.getType(typeAnnotation); 411 final DartType type = treeElements.getType(typeAnnotation);
409 assert(invariant(typeAnnotation, type != null, 412 assert(invariant(typeAnnotation, type != null,
410 message: "Missing type for type annotation: $treeElements.")); 413 message: "Missing type for type annotation: $treeElements."));
411 if (type.isTypedef) newTypedefElementCallback(type.element); 414 if (type.isTypedef) newTypedefElementCallback(type.element);
412 if (type.isInterfaceType) newClassElementCallback(type.element); 415 if (type.isInterfaceType) newClassElementCallback(type.element);
413 typeAnnotation.visitChildren(this); 416 typeAnnotation.visitChildren(this);
414 } 417 }
415 418
416 void collect() { 419 void collect() {
417 compiler.withCurrentElement(element, () { 420 reporter.withCurrentElement(element, () {
418 elementAst.ast.accept(this); 421 elementAst.ast.accept(this);
419 }); 422 });
420 } 423 }
421 } 424 }
422 425
423 Comparator compareBy(f) => (x, y) => f(x).compareTo(f(y)); 426 Comparator compareBy(f) => (x, y) => f(x).compareTo(f(y));
424 427
425 List sorted(Iterable l, comparison) { 428 List sorted(Iterable l, comparison) {
426 final result = new List.from(l); 429 final result = new List.from(l);
427 result.sort(comparison); 430 result.sort(comparison);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 527 }
525 528
526 // TODO(johnniwinther): Remove this when values are computed from the 529 // TODO(johnniwinther): Remove this when values are computed from the
527 // expressions. 530 // expressions.
528 @override 531 @override
529 void copyConstantValues(DartConstantTask task) { 532 void copyConstantValues(DartConstantTask task) {
530 constantCompiler.constantValueMap.addAll( 533 constantCompiler.constantValueMap.addAll(
531 task.constantCompiler.constantValueMap); 534 task.constantCompiler.constantValueMap);
532 } 535 }
533 } 536 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/dart_backend/outputter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698