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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/verifier.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.verifier; 5 library fasta.verifier;
6 6
7 import 'package:front_end/src/fasta/type_inference/type_schema.dart' 7 import 'package:front_end/src/fasta/type_inference/type_schema.dart'
8 show TypeSchemaVisitor, UnknownType; 8 show TypeSchemaVisitor, UnknownType;
9 9
10 import 'package:kernel/ast.dart' 10 import 'package:kernel/ast.dart'
11 show 11 show
12 InvalidExpression, 12 InvalidExpression,
13 InvalidStatement, 13 InvalidStatement,
14 InvalidInitializer, 14 InvalidInitializer,
15 Class, 15 Class,
16 ExpressionStatement, 16 ExpressionStatement,
17 Field, 17 Field,
18 Library, 18 Library,
19 Procedure, 19 Procedure,
20 Program, 20 Program,
21 TreeNode; 21 TreeNode;
22 22
23 import 'package:kernel/verifier.dart' show VerificationError, VerifyingVisitor; 23 import 'package:kernel/verifier.dart' show VerificationError, VerifyingVisitor;
24 24
25 import '../deprecated_problems.dart' show deprecated_printUnexpected; 25 import '../deprecated_problems.dart' show deprecated_printUnexpected;
26 26
27 import '../fasta_codes.dart';
28
27 import 'redirecting_factory_body.dart' show RedirectingFactoryBody; 29 import 'redirecting_factory_body.dart' show RedirectingFactoryBody;
28 30
29 List<VerificationError> verifyProgram(Program program, 31 List<LocatedMessage> verifyProgram(Program program, {bool isOutline: false}) {
30 {bool isOutline: false}) {
31 FastaVerifyingVisitor verifier = new FastaVerifyingVisitor(isOutline); 32 FastaVerifyingVisitor verifier = new FastaVerifyingVisitor(isOutline);
32 program.accept(verifier); 33 program.accept(verifier);
33 return verifier.errors; 34 return verifier.errors.map(convertError).toList();
34 } 35 }
35 36
36 class FastaVerifyingVisitor extends VerifyingVisitor 37 class FastaVerifyingVisitor extends VerifyingVisitor
37 implements TypeSchemaVisitor { 38 implements TypeSchemaVisitor {
38 final List<VerificationError> errors = <VerificationError>[]; 39 final List<VerificationError> errors = <VerificationError>[];
39 40
40 String fileUri; 41 String fileUri;
41 42
42 FastaVerifyingVisitor(bool isOutline) { 43 FastaVerifyingVisitor(bool isOutline) {
43 this.isOutline = isOutline; 44 this.isOutline = isOutline;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 visitInvalidInitializer(InvalidInitializer node) { 100 visitInvalidInitializer(InvalidInitializer node) {
100 problem(node, "Invalid initializer."); 101 problem(node, "Invalid initializer.");
101 } 102 }
102 103
103 @override 104 @override
104 visitUnknownType(UnknownType node) { 105 visitUnknownType(UnknownType node) {
105 // Note: we can't pass [node] to [problem] because it's not a [TreeNode]. 106 // Note: we can't pass [node] to [problem] because it's not a [TreeNode].
106 problem(null, "Unexpected appearance of the unknown type."); 107 problem(null, "Unexpected appearance of the unknown type.");
107 } 108 }
108 } 109 }
110
111 LocatedMessage convertError(VerificationError error) {
ahe 2017/07/12 13:14:43 This is probably a better solution than what I hav
112 var node = error.node ?? error.context;
113 int offset = node?.fileOffset ?? -1;
114 var file = node?.location?.file;
115 Uri uri = file == null ? null : Uri.parse(file);
116 return templateVerificationError
117 .withArguments(error.details)
118 .withLocation(uri, offset);
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698