Chromium Code Reviews| OLD | NEW |
|---|---|
| 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:kernel/ast.dart' | 7 import 'package:kernel/ast.dart' |
| 8 show | 8 show |
| 9 InvalidExpression, | 9 InvalidExpression, |
| 10 InvalidStatement, | 10 InvalidStatement, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 class FastaVerifyingVisitor extends VerifyingVisitor | 39 class FastaVerifyingVisitor extends VerifyingVisitor |
| 40 implements TypeSchemaVisitor { | 40 implements TypeSchemaVisitor { |
| 41 final List<LocatedMessage> errors = <LocatedMessage>[]; | 41 final List<LocatedMessage> errors = <LocatedMessage>[]; |
| 42 | 42 |
| 43 String fileUri; | 43 String fileUri; |
| 44 | 44 |
| 45 FastaVerifyingVisitor(bool isOutline) { | 45 FastaVerifyingVisitor(bool isOutline) { |
| 46 this.isOutline = isOutline; | 46 this.isOutline = isOutline; |
| 47 } | 47 } |
| 48 | 48 |
| 49 String checkLocation(TreeNode node, String name) { | |
|
sjindel
2017/08/16 10:27:01
How are these changes related?
ahe
2017/08/16 11:59:15
Without the change on line 79, Uri.parse would thr
ahe
2017/08/16 12:01:47
It would throw a NSM error *before* I modified ker
| |
| 50 if (name == null || name.contains("#")) { | |
| 51 // TODO(ahe): Investigate if these checks can be enabled: | |
| 52 // if (node.fileUri != null && node is! Library) { | |
| 53 // problem(node, "A synthetic node shouldn't have a fileUri", | |
| 54 // context: node); | |
| 55 // } | |
| 56 // if (node.fileOffset != -1) { | |
| 57 // problem(node, "A synthetic node shouldn't have a fileOffset", | |
| 58 // context: node); | |
| 59 // } | |
| 60 return fileUri; | |
| 61 } else { | |
| 62 if (node.fileUri == null) { | |
| 63 problem(node, "'$name' has no fileUri", context: node); | |
| 64 return fileUri; | |
| 65 } | |
| 66 if (node.fileOffset == -1 && node is! Library) { | |
| 67 problem(node, "'$name' has no fileOffset", context: node); | |
| 68 } | |
| 69 return node.fileUri; | |
| 70 } | |
| 71 } | |
| 72 | |
| 49 @override | 73 @override |
| 50 problem(TreeNode node, String details, {TreeNode context}) { | 74 problem(TreeNode node, String details, {TreeNode context}) { |
| 51 node ??= (context ?? this.context); | 75 node ??= (context ?? this.context); |
| 52 int offset = node?.fileOffset ?? -1; | 76 int offset = node?.fileOffset ?? -1; |
| 53 LocatedMessage message = templateInternalVerificationError | 77 LocatedMessage message = templateInternalVerificationError |
| 54 .withArguments(details) | 78 .withArguments(details) |
| 55 .withLocation(Uri.parse(fileUri), offset); | 79 .withLocation(fileUri == null ? null : Uri.parse(fileUri), offset); |
| 56 CompilerContext.current.report(message, Severity.error); | 80 CompilerContext.current.report(message, Severity.error); |
| 57 errors.add(message); | 81 errors.add(message); |
| 58 } | 82 } |
| 59 | 83 |
| 60 @override | 84 @override |
| 61 visitExpressionStatement(ExpressionStatement node) { | 85 visitExpressionStatement(ExpressionStatement node) { |
| 62 // Bypass verification of the [StaticGet] in [RedirectingFactoryBody] as | 86 // Bypass verification of the [StaticGet] in [RedirectingFactoryBody] as |
| 63 // this is a static get without a getter. | 87 // this is a static get without a getter. |
| 64 if (node is! RedirectingFactoryBody) { | 88 if (node is! RedirectingFactoryBody) { |
| 65 super.visitExpressionStatement(node); | 89 super.visitExpressionStatement(node); |
| 66 } | 90 } |
| 67 } | 91 } |
| 68 | 92 |
| 69 @override | 93 @override |
| 70 visitLibrary(Library node) { | 94 visitLibrary(Library node) { |
| 71 fileUri = node.fileUri; | 95 fileUri = checkLocation(node, node.name); |
| 72 super.visitLibrary(node); | 96 super.visitLibrary(node); |
| 73 } | 97 } |
| 74 | 98 |
| 75 @override | 99 @override |
| 76 visitClass(Class node) { | 100 visitClass(Class node) { |
| 77 fileUri = node.fileUri; | 101 fileUri = checkLocation(node, node.name); |
| 78 super.visitClass(node); | 102 super.visitClass(node); |
| 79 } | 103 } |
| 80 | 104 |
| 81 @override | 105 @override |
| 82 visitField(Field node) { | 106 visitField(Field node) { |
| 83 fileUri = node.fileUri; | 107 fileUri = checkLocation(node, node.name.name); |
| 84 super.visitField(node); | 108 super.visitField(node); |
| 85 } | 109 } |
| 86 | 110 |
| 87 @override | 111 @override |
| 88 visitProcedure(Procedure node) { | 112 visitProcedure(Procedure node) { |
| 89 fileUri = node.fileUri; | 113 fileUri = checkLocation(node, node.name.name); |
| 90 super.visitProcedure(node); | 114 super.visitProcedure(node); |
| 91 } | 115 } |
| 92 | 116 |
| 93 @override | 117 @override |
| 94 visitInvalidExpression(InvalidExpression node) { | 118 visitInvalidExpression(InvalidExpression node) { |
| 95 problem(node, "Invalid expression."); | 119 problem(node, "Invalid expression."); |
| 96 } | 120 } |
| 97 | 121 |
| 98 @override | 122 @override |
| 99 visitInvalidStatement(InvalidStatement node) { | 123 visitInvalidStatement(InvalidStatement node) { |
| 100 problem(node, "Invalid statement."); | 124 problem(node, "Invalid statement."); |
| 101 } | 125 } |
| 102 | 126 |
| 103 @override | 127 @override |
| 104 visitInvalidInitializer(InvalidInitializer node) { | 128 visitInvalidInitializer(InvalidInitializer node) { |
| 105 problem(node, "Invalid initializer."); | 129 problem(node, "Invalid initializer."); |
| 106 } | 130 } |
| 107 | 131 |
| 108 @override | 132 @override |
| 109 visitUnknownType(UnknownType node) { | 133 visitUnknownType(UnknownType node) { |
| 110 // Note: we can't pass [node] to [problem] because it's not a [TreeNode]. | 134 // Note: we can't pass [node] to [problem] because it's not a [TreeNode]. |
| 111 problem(null, "Unexpected appearance of the unknown type."); | 135 problem(null, "Unexpected appearance of the unknown type."); |
| 112 } | 136 } |
| 113 } | 137 } |
| OLD | NEW |