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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_target.dart

Issue 2977013002: Report messages instead of just printing. (Closed)
Patch Set: Created 3 years, 5 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library fasta.kernel_target; 5 library fasta.kernel_target;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'package:kernel/ast.dart' 9 import 'package:kernel/ast.dart'
10 show 10 show
(...skipping 27 matching lines...) Expand all
38 VariableGet, 38 VariableGet,
39 VoidType; 39 VoidType;
40 40
41 import 'package:kernel/type_algebra.dart' show substitute; 41 import 'package:kernel/type_algebra.dart' show substitute;
42 42
43 import '../../../file_system.dart' show FileSystem; 43 import '../../../file_system.dart' show FileSystem;
44 44
45 import '../compiler_context.dart' show CompilerContext; 45 import '../compiler_context.dart' show CompilerContext;
46 46
47 import '../deprecated_problems.dart' 47 import '../deprecated_problems.dart'
48 show 48 show deprecated_InputError, reportCrash, resetCrashReporting;
49 deprecated_formatUnexpected,
50 deprecated_InputError,
51 reportCrash,
52 resetCrashReporting;
53 49
54 import '../dill/dill_target.dart' show DillTarget; 50 import '../dill/dill_target.dart' show DillTarget;
55 51
56 import '../messages.dart' 52 import '../messages.dart'
57 show 53 show
58 LocatedMessage, 54 LocatedMessage,
59 messageConstConstructorNonFinalField, 55 messageConstConstructorNonFinalField,
60 messageConstConstructorNonFinalFieldCause, 56 messageConstConstructorNonFinalFieldCause,
61 templateSuperclassHasNoDefaultConstructor; 57 templateSuperclassHasNoDefaultConstructor;
62 58
63 import '../problems.dart' show unhandled; 59 import '../problems.dart' show unhandled;
64 60
61 import '../severity.dart' show Severity;
62
65 import '../source/source_class_builder.dart' show SourceClassBuilder; 63 import '../source/source_class_builder.dart' show SourceClassBuilder;
66 64
67 import '../source/source_loader.dart' show SourceLoader; 65 import '../source/source_loader.dart' show SourceLoader;
68 66
69 import '../target_implementation.dart' show TargetImplementation; 67 import '../target_implementation.dart' show TargetImplementation;
70 68
71 import '../uri_translator.dart' show UriTranslator; 69 import '../uri_translator.dart' show UriTranslator;
72 70
73 import '../util/relativize.dart' show relativizeUri; 71 import '../util/relativize.dart' show relativizeUri;
74 72
(...skipping 21 matching lines...) Expand all
96 94
97 final DillTarget dillTarget; 95 final DillTarget dillTarget;
98 96
99 /// Shared with [CompilerContext]. 97 /// Shared with [CompilerContext].
100 final Map<String, Source> uriToSource; 98 final Map<String, Source> uriToSource;
101 99
102 SourceLoader<Library> loader; 100 SourceLoader<Library> loader;
103 101
104 Program program; 102 Program program;
105 103
106 final List<String> errors = <String>[]; 104 final List<LocatedMessage> errors = <LocatedMessage>[];
107 105
108 final TypeBuilder dynamicType = 106 final TypeBuilder dynamicType =
109 new KernelNamedTypeBuilder("dynamic", null, -1, null); 107 new KernelNamedTypeBuilder("dynamic", null, -1, null);
110 108
111 bool get strongMode => backendTarget.strongMode; 109 bool get strongMode => backendTarget.strongMode;
112 110
113 bool get disableTypeInference => backendTarget.disableTypeInference; 111 bool get disableTypeInference => backendTarget.disableTypeInference;
114 112
115 KernelTarget( 113 KernelTarget(
116 this.fileSystem, DillTarget dillTarget, UriTranslator uriTranslator, 114 this.fileSystem, DillTarget dillTarget, UriTranslator uriTranslator,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 cls.mixedInType = null; 209 cls.mixedInType = null;
212 builder.supertype = new KernelNamedTypeBuilder("Object", null, 210 builder.supertype = new KernelNamedTypeBuilder("Object", null,
213 builder.charOffset, builder.fileUri ?? Uri.parse(cls.fileUri)) 211 builder.charOffset, builder.fileUri ?? Uri.parse(cls.fileUri))
214 ..builder = objectClassBuilder; 212 ..builder = objectClassBuilder;
215 builder.interfaces = null; 213 builder.interfaces = null;
216 builder.mixedInType = null; 214 builder.mixedInType = null;
217 } 215 }
218 216
219 void handleInputError(deprecated_InputError error, {bool isFullProgram}) { 217 void handleInputError(deprecated_InputError error, {bool isFullProgram}) {
220 if (error != null) { 218 if (error != null) {
221 String message = error.deprecated_format(); 219 LocatedMessage message = deprecated_InputError.toMessage(error);
222 print(message); 220 context.report(message, Severity.error);
223 errors.add(message); 221 errors.add(message);
224 } 222 }
225 program = erroneousProgram(isFullProgram); 223 program = erroneousProgram(isFullProgram);
226 } 224 }
227 225
228 @override 226 @override
229 Future<Program> buildOutlines({CanonicalName nameRoot}) async { 227 Future<Program> buildOutlines({CanonicalName nameRoot}) async {
230 if (loader.first == null) return null; 228 if (loader.first == null) return null;
231 try { 229 try {
232 loader.createTypeInferenceEngine(); 230 loader.createTypeInferenceEngine();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 /// replace [program]. 300 /// replace [program].
303 void handleRecoverableErrors(List<LocatedMessage> recoverableErrors) { 301 void handleRecoverableErrors(List<LocatedMessage> recoverableErrors) {
304 if (recoverableErrors.isEmpty) return; 302 if (recoverableErrors.isEmpty) return;
305 KernelLibraryBuilder mainLibrary = loader.first; 303 KernelLibraryBuilder mainLibrary = loader.first;
306 if (mainLibrary == null) { 304 if (mainLibrary == null) {
307 program = erroneousProgram(true); 305 program = erroneousProgram(true);
308 return; 306 return;
309 } 307 }
310 List<Expression> expressions = <Expression>[]; 308 List<Expression> expressions = <Expression>[];
311 for (LocatedMessage error in recoverableErrors) { 309 for (LocatedMessage error in recoverableErrors) {
312 String message = deprecated_formatUnexpected( 310 errors.add(error);
313 error.uri, error.charOffset, error.message); 311 expressions.add(new StringLiteral(context.format(error, Severity.error)));
314 errors.add(message);
315 expressions.add(new StringLiteral(message));
316 } 312 }
317 mainLibrary.library.addMember(new Field(new Name("#errors"), 313 mainLibrary.library.addMember(new Field(new Name("#errors"),
318 initializer: new ListLiteral(expressions, isConst: true), 314 initializer: new ListLiteral(expressions, isConst: true),
319 isConst: true)); 315 isConst: true));
320 } 316 }
321 317
322 Program erroneousProgram(bool isFullProgram) { 318 Program erroneousProgram(bool isFullProgram) {
323 Uri uri = loader.first?.uri ?? Uri.parse("error:error"); 319 Uri uri = loader.first?.uri ?? Uri.parse("error:error");
324 Uri fileUri = loader.first?.fileUri ?? uri; 320 Uri fileUri = loader.first?.fileUri ?? uri;
325 KernelLibraryBuilder library = 321 KernelLibraryBuilder library =
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 /// first time. 622 /// first time.
627 void runBuildTransformations() { 623 void runBuildTransformations() {
628 backendTarget.performModularTransformationsOnLibraries( 624 backendTarget.performModularTransformationsOnLibraries(
629 loader.coreTypes, loader.hierarchy, loader.libraries, 625 loader.coreTypes, loader.hierarchy, loader.libraries,
630 logger: (String msg) => ticker.logMs(msg)); 626 logger: (String msg) => ticker.logMs(msg));
631 backendTarget.performGlobalTransformations(loader.coreTypes, program, 627 backendTarget.performGlobalTransformations(loader.coreTypes, program,
632 logger: (String msg) => ticker.logMs(msg)); 628 logger: (String msg) => ticker.logMs(msg));
633 } 629 }
634 630
635 void verify() { 631 void verify() {
636 var verifyErrors = verifyProgram(program); 632 errors.addAll(verifyProgram(program));
637 errors.addAll(verifyErrors.map((error) => error.message));
638 ticker.logMs("Verified program"); 633 ticker.logMs("Verified program");
639 } 634 }
640 635
641 /// Return `true` if the given [library] was built by this [KernelTarget] 636 /// Return `true` if the given [library] was built by this [KernelTarget]
642 /// from sources, and not loaded from a [DillTarget]. 637 /// from sources, and not loaded from a [DillTarget].
643 bool isSourceLibrary(Library library) { 638 bool isSourceLibrary(Library library) {
644 return loader.libraries.contains(library); 639 return loader.libraries.contains(library);
645 } 640 }
646 } 641 }
647 642
648 /// Looks for a constructor call that matches `super()` from a constructor in 643 /// Looks for a constructor call that matches `super()` from a constructor in
649 /// [cls]. Such a constructor may have optional arguments, but no required 644 /// [cls]. Such a constructor may have optional arguments, but no required
650 /// arguments. 645 /// arguments.
651 Constructor defaultSuperConstructor(Class cls) { 646 Constructor defaultSuperConstructor(Class cls) {
652 Class superclass = cls.superclass; 647 Class superclass = cls.superclass;
653 while (superclass != null && superclass.isMixinApplication) { 648 while (superclass != null && superclass.isMixinApplication) {
654 superclass = superclass.superclass; 649 superclass = superclass.superclass;
655 } 650 }
656 for (Constructor constructor in superclass.constructors) { 651 for (Constructor constructor in superclass.constructors) {
657 if (constructor.name.name.isEmpty) { 652 if (constructor.name.name.isEmpty) {
658 return constructor.function.requiredParameterCount == 0 653 return constructor.function.requiredParameterCount == 0
659 ? constructor 654 ? constructor
660 : null; 655 : null;
661 } 656 }
662 } 657 }
663 return null; 658 return null;
664 } 659 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698