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

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

Issue 2979623002: Use messages for (some) public API errors (Closed)
Patch Set: wrap - verification error still pending 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:front_end/file_system.dart'; 9 import 'package:front_end/file_system.dart';
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 final DillTarget dillTarget; 91 final DillTarget dillTarget;
92 92
93 /// Shared with [CompilerContext]. 93 /// Shared with [CompilerContext].
94 final Map<String, Source> uriToSource; 94 final Map<String, Source> uriToSource;
95 95
96 SourceLoader<Library> loader; 96 SourceLoader<Library> loader;
97 97
98 Program program; 98 Program program;
99 99
100 final List<String> errors = <String>[]; 100 final List<LocatedMessage> errors = <LocatedMessage>[];
Siggi Cherem (dart-lang) 2017/07/12 00:35:15 note: this is now possible because I made deprecat
ahe 2017/07/12 13:14:43 I'd like to hold back on this change. I'm pretty c
Siggi Cherem (dart-lang) 2017/07/12 21:54:59 OK, I reverted this.
101 101
102 final TypeBuilder dynamicType = 102 final TypeBuilder dynamicType =
103 new KernelNamedTypeBuilder("dynamic", null, -1, null); 103 new KernelNamedTypeBuilder("dynamic", null, -1, null);
104 104
105 bool get strongMode => backendTarget.strongMode; 105 bool get strongMode => backendTarget.strongMode;
106 106
107 bool get disableTypeInference => backendTarget.disableTypeInference; 107 bool get disableTypeInference => backendTarget.disableTypeInference;
108 108
109 KernelTarget( 109 KernelTarget(
110 this.fileSystem, DillTarget dillTarget, TranslateUri uriTranslator, 110 this.fileSystem, DillTarget dillTarget, TranslateUri uriTranslator,
111 [Map<String, Source> uriToSource]) 111 [Map<String, Source> uriToSource])
112 : dillTarget = dillTarget, 112 : dillTarget = dillTarget,
113 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, 113 uriToSource = uriToSource ?? CompilerContext.current.uriToSource,
114 super(dillTarget.ticker, uriTranslator, dillTarget.backendTarget) { 114 super(dillTarget.ticker, uriTranslator, dillTarget.backendTarget) {
115 resetCrashReporting(); 115 resetCrashReporting();
116 loader = createLoader(); 116 loader = createLoader();
117 } 117 }
118 118
119 void deprecated_addError(file, int charOffset, String message) { 119 void deprecated_addError(file, int charOffset, String message) {
120 Uri uri = file is String ? Uri.parse(file) : file; 120 Uri uri = file is String ? Uri.parse(file) : file;
121 deprecated_InputError error = 121 deprecated_InputError error =
122 new deprecated_InputError(uri, charOffset, message); 122 new deprecated_InputError(uri, charOffset, message);
123 String formatterMessage = error.deprecated_format(); 123 errors.add(error);
124 print(formatterMessage); 124 print(error.deprecated_format());
ahe 2017/07/12 13:14:43 I'm pretty close to removing this and all the othe
Siggi Cherem (dart-lang) 2017/07/12 21:54:59 fantastic!, reverted to prevent conflicts.
125 errors.add(formatterMessage);
126 } 125 }
127 126
128 SourceLoader<Library> createLoader() => 127 SourceLoader<Library> createLoader() =>
129 new SourceLoader<Library>(fileSystem, this); 128 new SourceLoader<Library>(fileSystem, this);
130 129
131 void addSourceInformation( 130 void addSourceInformation(
132 Uri uri, List<int> lineStarts, List<int> sourceCode) { 131 Uri uri, List<int> lineStarts, List<int> sourceCode) {
133 String fileUri = relativizeUri(uri); 132 String fileUri = relativizeUri(uri);
134 uriToSource[fileUri] = new Source(lineStarts, sourceCode); 133 uriToSource[fileUri] = new Source(lineStarts, sourceCode);
135 } 134 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 cls.mixedInType = null; 212 cls.mixedInType = null;
214 builder.supertype = new KernelNamedTypeBuilder("Object", null, 213 builder.supertype = new KernelNamedTypeBuilder("Object", null,
215 builder.charOffset, builder.fileUri ?? Uri.parse(cls.fileUri)) 214 builder.charOffset, builder.fileUri ?? Uri.parse(cls.fileUri))
216 ..builder = objectClassBuilder; 215 ..builder = objectClassBuilder;
217 builder.interfaces = null; 216 builder.interfaces = null;
218 builder.mixedInType = null; 217 builder.mixedInType = null;
219 } 218 }
220 219
221 void handleInputError(deprecated_InputError error, {bool isFullProgram}) { 220 void handleInputError(deprecated_InputError error, {bool isFullProgram}) {
222 if (error != null) { 221 if (error != null) {
223 String message = error.deprecated_format(); 222 errors.add(error);
224 print(message); 223 print(error.deprecated_format());
225 errors.add(message);
226 } 224 }
227 program = erroneousProgram(isFullProgram); 225 program = erroneousProgram(isFullProgram);
228 } 226 }
229 227
230 @override 228 @override
231 Future<Program> buildOutlines({CanonicalName nameRoot}) async { 229 Future<Program> buildOutlines({CanonicalName nameRoot}) async {
232 if (loader.first == null) return null; 230 if (loader.first == null) return null;
233 try { 231 try {
234 loader.createTypeInferenceEngine(); 232 loader.createTypeInferenceEngine();
235 await loader.buildOutlines(); 233 await loader.buildOutlines();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 /// replace [program]. 302 /// replace [program].
305 void handleRecoverableErrors(List<LocatedMessage> recoverableErrors) { 303 void handleRecoverableErrors(List<LocatedMessage> recoverableErrors) {
306 if (recoverableErrors.isEmpty) return; 304 if (recoverableErrors.isEmpty) return;
307 KernelLibraryBuilder mainLibrary = loader.first; 305 KernelLibraryBuilder mainLibrary = loader.first;
308 if (mainLibrary == null) { 306 if (mainLibrary == null) {
309 program = erroneousProgram(true); 307 program = erroneousProgram(true);
310 return; 308 return;
311 } 309 }
312 List<Expression> expressions = <Expression>[]; 310 List<Expression> expressions = <Expression>[];
313 for (LocatedMessage error in recoverableErrors) { 311 for (LocatedMessage error in recoverableErrors) {
312 errors.add(error);
314 String message = deprecated_formatUnexpected( 313 String message = deprecated_formatUnexpected(
315 error.uri, error.charOffset, error.message); 314 error.uri, error.charOffset, error.message);
316 errors.add(message);
317 expressions.add(new StringLiteral(message)); 315 expressions.add(new StringLiteral(message));
318 } 316 }
319 mainLibrary.library.addMember(new Field(new Name("#errors"), 317 mainLibrary.library.addMember(new Field(new Name("#errors"),
320 initializer: new ListLiteral(expressions, isConst: true), 318 initializer: new ListLiteral(expressions, isConst: true),
321 isConst: true)); 319 isConst: true));
322 } 320 }
323 321
324 Program erroneousProgram(bool isFullProgram) { 322 Program erroneousProgram(bool isFullProgram) {
325 Uri uri = loader.first?.uri ?? Uri.parse("error:error"); 323 Uri uri = loader.first?.uri ?? Uri.parse("error:error");
326 Uri fileUri = loader.first?.fileUri ?? uri; 324 Uri fileUri = loader.first?.fileUri ?? uri;
327 KernelLibraryBuilder library = 325 KernelLibraryBuilder library =
328 new KernelLibraryBuilder(uri, fileUri, loader, false); 326 new KernelLibraryBuilder(uri, fileUri, loader, false);
329 loader.first = library; 327 loader.first = library;
330 if (isFullProgram) { 328 if (isFullProgram) {
331 // If this is an outline, we shouldn't add an executable main 329 // If this is an outline, we shouldn't add an executable main
332 // method. Similarly considerations apply to separate compilation. It 330 // method. Similarly considerations apply to separate compilation. It
333 // could also make sense to add a way to mark .dill files as having 331 // could also make sense to add a way to mark .dill files as having
334 // compile-time errors. 332 // compile-time errors.
335 KernelProcedureBuilder mainBuilder = new KernelProcedureBuilder(null, 0, 333 KernelProcedureBuilder mainBuilder = new KernelProcedureBuilder(null, 0,
336 null, "main", null, null, ProcedureKind.Method, library, -1, -1, -1); 334 null, "main", null, null, ProcedureKind.Method, library, -1, -1, -1);
337 library.addBuilder(mainBuilder.name, mainBuilder, -1); 335 library.addBuilder(mainBuilder.name, mainBuilder, -1);
338 mainBuilder.body = new ExpressionStatement( 336 mainBuilder.body = new ExpressionStatement(new Throw(
339 new Throw(new StringLiteral("${errors.join('\n')}"))); 337 new StringLiteral("${errors.map((e) => e.message).join('\n')}")));
Siggi Cherem (dart-lang) 2017/07/12 00:35:15 this changes the generated code a bit, one of our
ahe 2017/07/12 13:14:43 What's currently stored in the .expect files helps
Siggi Cherem (dart-lang) 2017/07/12 21:54:59 reverted this for now as well
340 } 338 }
341 library.build(loader.coreLibrary); 339 library.build(loader.coreLibrary);
342 return link(<Library>[library.library]); 340 return link(<Library>[library.library]);
343 } 341 }
344 342
345 /// Creates a program by combining [libraries] with the libraries of 343 /// Creates a program by combining [libraries] with the libraries of
346 /// `dillTarget.loader.program`. 344 /// `dillTarget.loader.program`.
347 Program link(List<Library> libraries, {CanonicalName nameRoot}) { 345 Program link(List<Library> libraries, {CanonicalName nameRoot}) {
348 Map<String, Source> uriToSource = 346 Map<String, Source> uriToSource =
349 new Map<String, Source>.from(this.uriToSource); 347 new Map<String, Source>.from(this.uriToSource);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 void runBuildTransformations() { 630 void runBuildTransformations() {
633 backendTarget.performModularTransformationsOnLibraries( 631 backendTarget.performModularTransformationsOnLibraries(
634 loader.coreTypes, loader.hierarchy, loader.libraries, 632 loader.coreTypes, loader.hierarchy, loader.libraries,
635 logger: (String msg) => ticker.logMs(msg)); 633 logger: (String msg) => ticker.logMs(msg));
636 backendTarget.performGlobalTransformations(loader.coreTypes, program, 634 backendTarget.performGlobalTransformations(loader.coreTypes, program,
637 logger: (String msg) => ticker.logMs(msg)); 635 logger: (String msg) => ticker.logMs(msg));
638 } 636 }
639 637
640 void verify() { 638 void verify() {
641 var verifyErrors = verifyProgram(program); 639 var verifyErrors = verifyProgram(program);
642 errors.addAll(verifyErrors.map((error) => '$error')); 640 errors.addAll(verifyErrors);
643 ticker.logMs("Verified program"); 641 ticker.logMs("Verified program");
644 } 642 }
645 643
646 /// Return `true` if the given [library] was built by this [KernelTarget] 644 /// Return `true` if the given [library] was built by this [KernelTarget]
647 /// from sources, and not loaded from a [DillTarget]. 645 /// from sources, and not loaded from a [DillTarget].
648 bool isSourceLibrary(Library library) { 646 bool isSourceLibrary(Library library) {
649 return loader.libraries.contains(library); 647 return loader.libraries.contains(library);
650 } 648 }
651 } 649 }
652 650
653 /// Looks for a constructor call that matches `super()` from a constructor in 651 /// Looks for a constructor call that matches `super()` from a constructor in
654 /// [cls]. Such a constructor may have optional arguments, but no required 652 /// [cls]. Such a constructor may have optional arguments, but no required
655 /// arguments. 653 /// arguments.
656 Constructor defaultSuperConstructor(Class cls) { 654 Constructor defaultSuperConstructor(Class cls) {
657 Class superclass = cls.superclass; 655 Class superclass = cls.superclass;
658 while (superclass != null && superclass.isMixinApplication) { 656 while (superclass != null && superclass.isMixinApplication) {
659 superclass = superclass.superclass; 657 superclass = superclass.superclass;
660 } 658 }
661 for (Constructor constructor in superclass.constructors) { 659 for (Constructor constructor in superclass.constructors) {
662 if (constructor.name.name.isEmpty) { 660 if (constructor.name.name.isEmpty) {
663 return constructor.function.requiredParameterCount == 0 661 return constructor.function.requiredParameterCount == 0
664 ? constructor 662 ? constructor
665 : null; 663 : null;
666 } 664 }
667 } 665 }
668 return null; 666 return null;
669 } 667 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698