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

Side by Side Diff: pkg/front_end/lib/src/fasta/builder/library_builder.dart

Issue 2938573002: Improve recovery from compile-time errors. (Closed)
Patch Set: Created 3 years, 6 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.library_builder; 5 library fasta.library_builder;
6 6
7 import '../combinator.dart' show Combinator; 7 import '../combinator.dart' show Combinator;
8 8
9 import '../errors.dart' show InputError, internalError, printUnexpected; 9 import '../errors.dart' show internalError;
10 10
11 import '../export.dart' show Export; 11 import '../export.dart' show Export;
12 12
13 import '../loader.dart' show Loader; 13 import '../loader.dart' show Loader;
14 14
15 import '../messages.dart' show nit, warning; 15 import '../messages.dart' show nit, warning;
16 16
17 import '../util/relativize.dart' show relativizeUri; 17 import '../util/relativize.dart' show relativizeUri;
18 18
19 import 'builder.dart' 19 import 'builder.dart'
(...skipping 11 matching lines...) Expand all
31 final Scope scope; 31 final Scope scope;
32 32
33 final Scope exports; 33 final Scope exports;
34 34
35 final ScopeBuilder scopeBuilder; 35 final ScopeBuilder scopeBuilder;
36 36
37 final ScopeBuilder exportScopeBuilder; 37 final ScopeBuilder exportScopeBuilder;
38 38
39 final List<Export> exporters = <Export>[]; 39 final List<Export> exporters = <Export>[];
40 40
41 final List<InputError> compileTimeErrors = <InputError>[];
42
43 final Uri fileUri; 41 final Uri fileUri;
44 42
45 final String relativeFileUri; 43 final String relativeFileUri;
46 44
47 LibraryBuilder partOfLibrary; 45 LibraryBuilder partOfLibrary;
48 46
47 /// True if a compile-time error has been reported in this library.
48 bool hasCompileTimeErrors = false;
49
49 LibraryBuilder(Uri fileUri, this.scope, this.exports) 50 LibraryBuilder(Uri fileUri, this.scope, this.exports)
50 : fileUri = fileUri, 51 : fileUri = fileUri,
51 relativeFileUri = relativizeUri(fileUri), 52 relativeFileUri = relativizeUri(fileUri),
52 scopeBuilder = new ScopeBuilder(scope), 53 scopeBuilder = new ScopeBuilder(scope),
53 exportScopeBuilder = new ScopeBuilder(exports), 54 exportScopeBuilder = new ScopeBuilder(exports),
54 super(null, -1, fileUri); 55 super(null, -1, fileUri);
55 56
56 Loader get loader; 57 Loader get loader;
57 58
58 Uri get uri; 59 Uri get uri;
59 60
60 Builder addBuilder(String name, Builder builder, int charOffset); 61 Builder addBuilder(String name, Builder builder, int charOffset);
61 62
62 void addExporter( 63 void addExporter(
63 LibraryBuilder exporter, List<Combinator> combinators, int charOffset) { 64 LibraryBuilder exporter, List<Combinator> combinators, int charOffset) {
64 exporters.add(new Export(exporter, this, combinators, charOffset)); 65 exporters.add(new Export(exporter, this, combinators, charOffset));
65 } 66 }
66 67
68 /// See `Loader.addCompileTimeError` for an explanation of the arguments
69 /// passed to this method.
70 ///
71 /// If [fileUri] is null, it defaults to `this.fileUri`.
67 void addCompileTimeError(int charOffset, Object message, 72 void addCompileTimeError(int charOffset, Object message,
68 {Uri fileUri, bool silent: false}) { 73 {Uri fileUri, bool silent: false, bool wasHandled: false}) {
69 fileUri ??= this.fileUri; 74 hasCompileTimeErrors = true;
70 if (!silent) { 75 loader.addCompileTimeError(fileUri ?? this.fileUri, charOffset, message,
71 printUnexpected(fileUri, charOffset, message); 76 silent: silent, wasHandled: wasHandled);
72 }
73 compileTimeErrors.add(new InputError(fileUri, charOffset, message));
74 } 77 }
75 78
76 void addWarning(int charOffset, Object message, 79 void addWarning(int charOffset, Object message,
77 {Uri fileUri, bool silent: false}) { 80 {Uri fileUri, bool silent: false}) {
78 fileUri ??= this.fileUri; 81 fileUri ??= this.fileUri;
79 if (!silent) { 82 if (!silent) {
80 warning(fileUri, charOffset, message); 83 warning(fileUri, charOffset, message);
81 } 84 }
82 } 85 }
83 86
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 /// Don't use for scope lookup. Only use when an element is known to exist 176 /// Don't use for scope lookup. Only use when an element is known to exist
174 /// (and not a setter). 177 /// (and not a setter).
175 Builder operator [](String name) { 178 Builder operator [](String name) {
176 return scope.local[name] ?? internalError("Not found: '$name'."); 179 return scope.local[name] ?? internalError("Not found: '$name'.");
177 } 180 }
178 181
179 Builder lookup(String name, int charOffset, Uri fileUri) { 182 Builder lookup(String name, int charOffset, Uri fileUri) {
180 return scope.lookup(name, charOffset, fileUri); 183 return scope.lookup(name, charOffset, fileUri);
181 } 184 }
182 } 185 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698