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) { | |
kustermann
2017/02/01 13:00:54
You could also verify that name._children is minim
asgerf
2017/02/02 12:30:27
Follow-up on the previous comment:
It is hard to
| |
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 ${name.definition} '; | |
kustermann
2017/02/01 13:00:54
maybe run dartfmt
asgerf
2017/02/02 12:30:27
Done.
| |
142 } | |
143 } | |
144 | |
136 visitField(Field node) { | 145 visitField(Field node) { |
146 checkCanonicalName(node.canonicalName, node); | |
137 currentMember = node; | 147 currentMember = node; |
138 var oldParent = enterParent(node); | 148 var oldParent = enterParent(node); |
139 classTypeParametersAreInScope = !node.isStatic; | 149 classTypeParametersAreInScope = !node.isStatic; |
140 node.initializer?.accept(this); | 150 node.initializer?.accept(this); |
141 classTypeParametersAreInScope = false; | 151 classTypeParametersAreInScope = false; |
142 visitList(node.annotations, this); | 152 visitList(node.annotations, this); |
143 exitParent(oldParent); | 153 exitParent(oldParent); |
144 currentMember = null; | 154 currentMember = null; |
145 } | 155 } |
146 | 156 |
147 visitProcedure(Procedure node) { | 157 visitProcedure(Procedure node) { |
158 checkCanonicalName(node.canonicalName, node); | |
148 currentMember = node; | 159 currentMember = node; |
149 var oldParent = enterParent(node); | 160 var oldParent = enterParent(node); |
150 classTypeParametersAreInScope = !node.isStatic; | 161 classTypeParametersAreInScope = !node.isStatic; |
151 node.function.accept(this); | 162 node.function.accept(this); |
152 classTypeParametersAreInScope = false; | 163 classTypeParametersAreInScope = false; |
153 visitList(node.annotations, this); | 164 visitList(node.annotations, this); |
154 exitParent(oldParent); | 165 exitParent(oldParent); |
155 currentMember = null; | 166 currentMember = null; |
156 } | 167 } |
157 | 168 |
158 visitConstructor(Constructor node) { | 169 visitConstructor(Constructor node) { |
170 checkCanonicalName(node.canonicalName, node); | |
159 currentMember = node; | 171 currentMember = node; |
160 classTypeParametersAreInScope = true; | 172 classTypeParametersAreInScope = true; |
161 // The constructor member needs special treatment due to parameters being | 173 // The constructor member needs special treatment due to parameters being |
162 // in scope in the initializer list. | 174 // in scope in the initializer list. |
163 var oldParent = enterParent(node); | 175 var oldParent = enterParent(node); |
164 int stackHeight = enterLocalScope(); | 176 int stackHeight = enterLocalScope(); |
165 visitChildren(node.function); | 177 visitChildren(node.function); |
166 visitList(node.initializers, this); | 178 visitList(node.initializers, this); |
167 exitLocalScope(stackHeight); | 179 exitLocalScope(stackHeight); |
168 classTypeParametersAreInScope = false; | 180 classTypeParametersAreInScope = false; |
169 visitList(node.annotations, this); | 181 visitList(node.annotations, this); |
170 exitParent(oldParent); | 182 exitParent(oldParent); |
171 classTypeParametersAreInScope = false; | 183 classTypeParametersAreInScope = false; |
172 currentMember = null; | 184 currentMember = null; |
173 } | 185 } |
174 | 186 |
175 visitClass(Class node) { | 187 visitClass(Class node) { |
188 checkCanonicalName(node.canonicalName, node); | |
176 currentClass = node; | 189 currentClass = node; |
177 declareTypeParameters(node.typeParameters); | 190 declareTypeParameters(node.typeParameters); |
178 var oldParent = enterParent(node); | 191 var oldParent = enterParent(node); |
179 classTypeParametersAreInScope = false; | 192 classTypeParametersAreInScope = false; |
180 visitList(node.annotations, this); | 193 visitList(node.annotations, this); |
181 classTypeParametersAreInScope = true; | 194 classTypeParametersAreInScope = true; |
182 visitList(node.typeParameters, this); | 195 visitList(node.typeParameters, this); |
183 visitList(node.fields, this); | 196 visitList(node.fields, this); |
184 visitList(node.constructors, this); | 197 visitList(node.constructors, this); |
185 visitList(node.procedures, this); | 198 visitList(node.procedures, this); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 throw 'Parent pointer on ${node.runtimeType} ' | 455 throw 'Parent pointer on ${node.runtimeType} ' |
443 'is ${node.parent.runtimeType} ' | 456 'is ${node.parent.runtimeType} ' |
444 'but should be ${parent.runtimeType}'; | 457 'but should be ${parent.runtimeType}'; |
445 } | 458 } |
446 var oldParent = parent; | 459 var oldParent = parent; |
447 parent = node; | 460 parent = node; |
448 node.visitChildren(this); | 461 node.visitChildren(this); |
449 parent = oldParent; | 462 parent = oldParent; |
450 } | 463 } |
451 } | 464 } |
OLD | NEW |