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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/referenced_names.dart

Issue 2689343003: Fixes for referenced names computing. (Closed)
Patch Set: Created 3 years, 10 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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/visitor.dart'; 6 import 'package:analyzer/dart/ast/visitor.dart';
7 7
8 /** 8 /**
9 * Compute the set of external names referenced in the [unit]. 9 * Compute the set of external names referenced in the [unit].
10 */ 10 */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return scope; 49 return scope;
50 } 50 }
51 51
52 factory _LocalNameScope.forClassTypeAlias( 52 factory _LocalNameScope.forClassTypeAlias(
53 _LocalNameScope enclosing, ClassTypeAlias node) { 53 _LocalNameScope enclosing, ClassTypeAlias node) {
54 _LocalNameScope scope = new _LocalNameScope(enclosing); 54 _LocalNameScope scope = new _LocalNameScope(enclosing);
55 scope.addTypeParameters(node.typeParameters); 55 scope.addTypeParameters(node.typeParameters);
56 return scope; 56 return scope;
57 } 57 }
58 58
59 factory _LocalNameScope.forConstructor(
60 _LocalNameScope enclosing, ConstructorDeclaration node) {
61 _LocalNameScope scope = new _LocalNameScope(enclosing);
62 scope.addFormalParameters(node.parameters);
63 return scope;
64 }
65
59 factory _LocalNameScope.forFunction( 66 factory _LocalNameScope.forFunction(
60 _LocalNameScope enclosing, FunctionDeclaration node) { 67 _LocalNameScope enclosing, FunctionDeclaration node) {
61 _LocalNameScope scope = new _LocalNameScope(enclosing); 68 _LocalNameScope scope = new _LocalNameScope(enclosing);
62 scope.addTypeParameters(node.functionExpression.typeParameters); 69 scope.addTypeParameters(node.functionExpression.typeParameters);
63 scope.addFormalParameters(node.functionExpression.parameters); 70 scope.addFormalParameters(node.functionExpression.parameters);
64 return scope; 71 return scope;
65 } 72 }
66 73
67 factory _LocalNameScope.forFunctionTypeAlias( 74 factory _LocalNameScope.forFunctionTypeAlias(
68 _LocalNameScope enclosing, FunctionTypeAlias node) { 75 _LocalNameScope enclosing, FunctionTypeAlias node) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 175 }
169 } 176 }
170 177
171 @override 178 @override
172 visitCompilationUnit(CompilationUnit node) { 179 visitCompilationUnit(CompilationUnit node) {
173 localScope = new _LocalNameScope.forUnit(node); 180 localScope = new _LocalNameScope.forUnit(node);
174 super.visitCompilationUnit(node); 181 super.visitCompilationUnit(node);
175 } 182 }
176 183
177 @override 184 @override
185 visitConstructorDeclaration(ConstructorDeclaration node) {
186 _LocalNameScope outerScope = localScope;
187 try {
188 localScope = new _LocalNameScope.forConstructor(localScope, node);
189 super.visitConstructorDeclaration(node);
190 } finally {
191 localScope = outerScope;
192 }
193 }
194
195 @override
178 visitConstructorName(ConstructorName node) { 196 visitConstructorName(ConstructorName node) {
179 if (node.parent is! ConstructorDeclaration) { 197 if (node.parent is! ConstructorDeclaration) {
180 super.visitConstructorName(node); 198 super.visitConstructorName(node);
181 } 199 }
182 } 200 }
183 201
184 @override 202 @override
185 visitFunctionDeclaration(FunctionDeclaration node) { 203 visitFunctionDeclaration(FunctionDeclaration node) {
186 _LocalNameScope outerScope = localScope; 204 _LocalNameScope outerScope = localScope;
187 try { 205 try {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 if (node.inDeclarationContext()) { 246 if (node.inDeclarationContext()) {
229 return; 247 return;
230 } 248 }
231 // Ignore class names references from constructors. 249 // Ignore class names references from constructors.
232 AstNode parent = node.parent; 250 AstNode parent = node.parent;
233 if (parent is ConstructorDeclaration && parent.returnType == node) { 251 if (parent is ConstructorDeclaration && parent.returnType == node) {
234 return; 252 return;
235 } 253 }
236 // Prepare name. 254 // Prepare name.
237 String name = node.name; 255 String name = node.name;
238 // Ignore unqualified names shadowed by local elements. 256 // Ignore names shadowed by local elements.
239 if (!node.isQualified) { 257 if (node.isQualified || _isNameExpressionLabel(parent)) {
258 // Cannot be local.
259 } else {
240 if (localScope.contains(name)) { 260 if (localScope.contains(name)) {
241 return; 261 return;
242 } 262 }
243 if (importPrefixNames.contains(name)) { 263 if (importPrefixNames.contains(name)) {
244 return; 264 return;
245 } 265 }
246 } 266 }
247 // Do add the name. 267 // Do add the name.
248 names.add(name); 268 names.add(name);
249 } 269 }
270
271 static bool _isNameExpressionLabel(AstNode parent) {
272 if (parent is Label) {
273 AstNode parent2 = parent?.parent;
274 return parent2 is NamedExpression && parent2.name == parent;
275 }
276 return false;
277 }
250 } 278 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/driver.dart ('k') | pkg/analyzer/test/src/dart/analysis/referenced_names_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698