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 library kernel.checks; | 4 library kernel.checks; |
5 | 5 |
6 import 'ast.dart'; | 6 import 'ast.dart'; |
7 import 'transformations/flags.dart'; | 7 import 'transformations/flags.dart'; |
8 | 8 |
9 void verifyProgram(Program program) { | 9 void verifyProgram(Program program) { |
10 VerifyingVisitor.check(program); | 10 VerifyingVisitor.check(program); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 126 } |
127 visitChildren(program); | 127 visitChildren(program); |
128 for (var library in program.libraries) { | 128 for (var library in program.libraries) { |
129 library.members.forEach(undeclareMember); | 129 library.members.forEach(undeclareMember); |
130 for (var class_ in library.classes) { | 130 for (var class_ in library.classes) { |
131 class_.members.forEach(undeclareMember); | 131 class_.members.forEach(undeclareMember); |
132 } | 132 } |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
| 136 void checkCanonicalName(CanonicalName name, LinkedNode definition) { |
| 137 if (name == null) { |
| 138 throw '$definition has no canonical name'; |
| 139 } |
| 140 if (name.definition != definition) { |
| 141 throw '$definition has name $name, but that is bound to ' |
| 142 '${name.definition}'; |
| 143 } |
| 144 } |
| 145 |
136 visitField(Field node) { | 146 visitField(Field node) { |
| 147 checkCanonicalName(node.canonicalName, node); |
137 currentMember = node; | 148 currentMember = node; |
138 var oldParent = enterParent(node); | 149 var oldParent = enterParent(node); |
139 classTypeParametersAreInScope = !node.isStatic; | 150 classTypeParametersAreInScope = !node.isStatic; |
140 node.initializer?.accept(this); | 151 node.initializer?.accept(this); |
141 classTypeParametersAreInScope = false; | 152 classTypeParametersAreInScope = false; |
142 visitList(node.annotations, this); | 153 visitList(node.annotations, this); |
143 exitParent(oldParent); | 154 exitParent(oldParent); |
144 currentMember = null; | 155 currentMember = null; |
145 } | 156 } |
146 | 157 |
147 visitProcedure(Procedure node) { | 158 visitProcedure(Procedure node) { |
| 159 checkCanonicalName(node.canonicalName, node); |
148 currentMember = node; | 160 currentMember = node; |
149 var oldParent = enterParent(node); | 161 var oldParent = enterParent(node); |
150 classTypeParametersAreInScope = !node.isStatic; | 162 classTypeParametersAreInScope = !node.isStatic; |
151 node.function.accept(this); | 163 node.function.accept(this); |
152 classTypeParametersAreInScope = false; | 164 classTypeParametersAreInScope = false; |
153 visitList(node.annotations, this); | 165 visitList(node.annotations, this); |
154 exitParent(oldParent); | 166 exitParent(oldParent); |
155 currentMember = null; | 167 currentMember = null; |
156 } | 168 } |
157 | 169 |
158 visitConstructor(Constructor node) { | 170 visitConstructor(Constructor node) { |
| 171 checkCanonicalName(node.canonicalName, node); |
159 currentMember = node; | 172 currentMember = node; |
160 classTypeParametersAreInScope = true; | 173 classTypeParametersAreInScope = true; |
161 // The constructor member needs special treatment due to parameters being | 174 // The constructor member needs special treatment due to parameters being |
162 // in scope in the initializer list. | 175 // in scope in the initializer list. |
163 var oldParent = enterParent(node); | 176 var oldParent = enterParent(node); |
164 int stackHeight = enterLocalScope(); | 177 int stackHeight = enterLocalScope(); |
165 visitChildren(node.function); | 178 visitChildren(node.function); |
166 visitList(node.initializers, this); | 179 visitList(node.initializers, this); |
167 exitLocalScope(stackHeight); | 180 exitLocalScope(stackHeight); |
168 classTypeParametersAreInScope = false; | 181 classTypeParametersAreInScope = false; |
169 visitList(node.annotations, this); | 182 visitList(node.annotations, this); |
170 exitParent(oldParent); | 183 exitParent(oldParent); |
171 classTypeParametersAreInScope = false; | 184 classTypeParametersAreInScope = false; |
172 currentMember = null; | 185 currentMember = null; |
173 } | 186 } |
174 | 187 |
175 visitClass(Class node) { | 188 visitClass(Class node) { |
| 189 checkCanonicalName(node.canonicalName, node); |
176 currentClass = node; | 190 currentClass = node; |
177 declareTypeParameters(node.typeParameters); | 191 declareTypeParameters(node.typeParameters); |
178 var oldParent = enterParent(node); | 192 var oldParent = enterParent(node); |
179 classTypeParametersAreInScope = false; | 193 classTypeParametersAreInScope = false; |
180 visitList(node.annotations, this); | 194 visitList(node.annotations, this); |
181 classTypeParametersAreInScope = true; | 195 classTypeParametersAreInScope = true; |
182 visitList(node.typeParameters, this); | 196 visitList(node.typeParameters, this); |
183 visitList(node.fields, this); | 197 visitList(node.fields, this); |
184 visitList(node.constructors, this); | 198 visitList(node.constructors, this); |
185 visitList(node.procedures, this); | 199 visitList(node.procedures, this); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 throw 'Parent pointer on ${node.runtimeType} ' | 456 throw 'Parent pointer on ${node.runtimeType} ' |
443 'is ${node.parent.runtimeType} ' | 457 'is ${node.parent.runtimeType} ' |
444 'but should be ${parent.runtimeType}'; | 458 'but should be ${parent.runtimeType}'; |
445 } | 459 } |
446 var oldParent = parent; | 460 var oldParent = parent; |
447 parent = node; | 461 parent = node; |
448 node.visitChildren(this); | 462 node.visitChildren(this); |
449 parent = oldParent; | 463 parent = oldParent; |
450 } | 464 } |
451 } | 465 } |
OLD | NEW |