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

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

Issue 2977013002: Report messages instead of just printing. (Closed)
Patch Set: Update expectations. 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'
8 show TypeSchemaVisitor, UnknownType;
9
10 import 'package:kernel/ast.dart' 7 import 'package:kernel/ast.dart'
11 show 8 show
12 InvalidExpression, 9 InvalidExpression,
13 InvalidStatement, 10 InvalidStatement,
14 InvalidInitializer, 11 InvalidInitializer,
15 Class, 12 Class,
16 ExpressionStatement, 13 ExpressionStatement,
17 Field, 14 Field,
18 Library, 15 Library,
19 Procedure, 16 Procedure,
20 Program, 17 Program,
21 TreeNode; 18 TreeNode;
22 19
23 import 'package:kernel/verifier.dart' show VerificationError, VerifyingVisitor; 20 import 'package:kernel/verifier.dart' show VerifyingVisitor;
24 21
25 import '../deprecated_problems.dart' show deprecated_printUnexpected; 22 import '../compiler_context.dart' show CompilerContext;
26 23
27 import '../fasta_codes.dart'; 24 import '../fasta_codes.dart'
25 show LocatedMessage, templateInternalVerificationError;
26
27 import '../severity.dart' show Severity;
28
29 import '../type_inference/type_schema.dart' show TypeSchemaVisitor, UnknownType;
28 30
29 import 'redirecting_factory_body.dart' show RedirectingFactoryBody; 31 import 'redirecting_factory_body.dart' show RedirectingFactoryBody;
30 32
31 List<LocatedMessage> verifyProgram(Program program, {bool isOutline: false}) { 33 List<LocatedMessage> verifyProgram(Program program, {bool isOutline: false}) {
32 FastaVerifyingVisitor verifier = new FastaVerifyingVisitor(isOutline); 34 FastaVerifyingVisitor verifier = new FastaVerifyingVisitor(isOutline);
33 program.accept(verifier); 35 program.accept(verifier);
34 return verifier.errors.map(convertError).toList(); 36 return verifier.errors;
35 } 37 }
36 38
37 class FastaVerifyingVisitor extends VerifyingVisitor 39 class FastaVerifyingVisitor extends VerifyingVisitor
38 implements TypeSchemaVisitor { 40 implements TypeSchemaVisitor {
39 final List<VerificationError> errors = <VerificationError>[]; 41 final List<LocatedMessage> errors = <LocatedMessage>[];
40 42
41 String fileUri; 43 String fileUri;
42 44
43 FastaVerifyingVisitor(bool isOutline) { 45 FastaVerifyingVisitor(bool isOutline) {
44 this.isOutline = isOutline; 46 this.isOutline = isOutline;
45 } 47 }
46 48
47 @override 49 @override
48 problem(TreeNode node, String details, {TreeNode context}) { 50 problem(TreeNode node, String details, {TreeNode context}) {
49 context ??= this.context; 51 node ??= (context ?? this.context);
50 VerificationError error = new VerificationError(context, node, details); 52 int offset = node?.fileOffset ?? -1;
51 deprecated_printUnexpected( 53 LocatedMessage message = templateInternalVerificationError
52 Uri.parse(fileUri), node?.fileOffset ?? -1, "$error"); 54 .withArguments(details)
53 errors.add(error); 55 .withLocation(Uri.parse(fileUri), offset);
56 CompilerContext.current.report(message, Severity.error);
57 errors.add(message);
54 } 58 }
55 59
56 @override 60 @override
57 visitExpressionStatement(ExpressionStatement node) { 61 visitExpressionStatement(ExpressionStatement node) {
58 // Bypass verification of the [StaticGet] in [RedirectingFactoryBody] as 62 // Bypass verification of the [StaticGet] in [RedirectingFactoryBody] as
59 // this is a static get without a getter. 63 // this is a static get without a getter.
60 if (node is! RedirectingFactoryBody) { 64 if (node is! RedirectingFactoryBody) {
61 super.visitExpressionStatement(node); 65 super.visitExpressionStatement(node);
62 } 66 }
63 } 67 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 visitInvalidInitializer(InvalidInitializer node) { 104 visitInvalidInitializer(InvalidInitializer node) {
101 problem(node, "Invalid initializer."); 105 problem(node, "Invalid initializer.");
102 } 106 }
103 107
104 @override 108 @override
105 visitUnknownType(UnknownType node) { 109 visitUnknownType(UnknownType node) {
106 // Note: we can't pass [node] to [problem] because it's not a [TreeNode]. 110 // Note: we can't pass [node] to [problem] because it's not a [TreeNode].
107 problem(null, "Unexpected appearance of the unknown type."); 111 problem(null, "Unexpected appearance of the unknown type.");
108 } 112 }
109 } 113 }
110
111 LocatedMessage convertError(VerificationError error) {
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 templateInternalVerificationError
117 .withArguments(error.details)
118 .withLocation(uri, offset);
119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698