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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/builder.dart

Issue 2966313002: Remove ExecutableElement.localVariables altogether. (Closed)
Patch Set: 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.src.dart.element.builder; 5 library analyzer.src.dart.element.builder;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 element.metadata = _createElementAnnotations(node.metadata); 147 element.metadata = _createElementAnnotations(node.metadata);
148 setElementDocumentationComment(element, node); 148 setElementDocumentationComment(element, node);
149 if (node.externalKeyword != null) { 149 if (node.externalKeyword != null) {
150 element.external = true; 150 element.external = true;
151 } 151 }
152 if (node.factoryKeyword != null) { 152 if (node.factoryKeyword != null) {
153 element.factory = true; 153 element.factory = true;
154 } 154 }
155 element.functions = holder.functions; 155 element.functions = holder.functions;
156 element.labels = holder.labels; 156 element.labels = holder.labels;
157 element.localVariables = holder.localVariables; 157 element.encloseElements(holder.localVariables);
158 element.parameters = holder.parameters; 158 element.parameters = holder.parameters;
159 element.isConst = node.constKeyword != null; 159 element.isConst = node.constKeyword != null;
160 element.isCycleFree = element.isConst; 160 element.isCycleFree = element.isConst;
161 if (body.isAsynchronous) { 161 if (body.isAsynchronous) {
162 element.asynchronous = true; 162 element.asynchronous = true;
163 } 163 }
164 if (body.isGenerator) { 164 if (body.isGenerator) {
165 element.generator = true; 165 element.generator = true;
166 } 166 }
167 _currentHolder.addConstructor(element); 167 _currentHolder.addConstructor(element);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 FunctionElementImpl element = 241 FunctionElementImpl element =
242 new FunctionElementImpl.forNode(functionName); 242 new FunctionElementImpl.forNode(functionName);
243 _setCodeRange(element, node); 243 _setCodeRange(element, node);
244 element.metadata = _createElementAnnotations(node.metadata); 244 element.metadata = _createElementAnnotations(node.metadata);
245 setElementDocumentationComment(element, node); 245 setElementDocumentationComment(element, node);
246 if (node.externalKeyword != null || body is NativeFunctionBody) { 246 if (node.externalKeyword != null || body is NativeFunctionBody) {
247 element.external = true; 247 element.external = true;
248 } 248 }
249 element.functions = holder.functions; 249 element.functions = holder.functions;
250 element.labels = holder.labels; 250 element.labels = holder.labels;
251 element.localVariables = holder.localVariables; 251 element.encloseElements(holder.localVariables);
252 element.parameters = holder.parameters; 252 element.parameters = holder.parameters;
253 element.typeParameters = holder.typeParameters; 253 element.typeParameters = holder.typeParameters;
254 if (body.isAsynchronous) { 254 if (body.isAsynchronous) {
255 element.asynchronous = true; 255 element.asynchronous = true;
256 } 256 }
257 if (body.isGenerator) { 257 if (body.isGenerator) {
258 element.generator = true; 258 element.generator = true;
259 } 259 }
260 if (node.returnType == null) { 260 if (node.returnType == null) {
261 element.hasImplicitReturnType = true; 261 element.hasImplicitReturnType = true;
(...skipping 20 matching lines...) Expand all
282 PropertyAccessorElementImpl getter = 282 PropertyAccessorElementImpl getter =
283 new PropertyAccessorElementImpl.forNode(propertyNameNode); 283 new PropertyAccessorElementImpl.forNode(propertyNameNode);
284 _setCodeRange(getter, node); 284 _setCodeRange(getter, node);
285 getter.metadata = _createElementAnnotations(node.metadata); 285 getter.metadata = _createElementAnnotations(node.metadata);
286 setElementDocumentationComment(getter, node); 286 setElementDocumentationComment(getter, node);
287 if (node.externalKeyword != null || body is NativeFunctionBody) { 287 if (node.externalKeyword != null || body is NativeFunctionBody) {
288 getter.external = true; 288 getter.external = true;
289 } 289 }
290 getter.functions = holder.functions; 290 getter.functions = holder.functions;
291 getter.labels = holder.labels; 291 getter.labels = holder.labels;
292 getter.localVariables = holder.localVariables; 292 getter.encloseElements(holder.localVariables);
293 if (body.isAsynchronous) { 293 if (body.isAsynchronous) {
294 getter.asynchronous = true; 294 getter.asynchronous = true;
295 } 295 }
296 if (body.isGenerator) { 296 if (body.isGenerator) {
297 getter.generator = true; 297 getter.generator = true;
298 } 298 }
299 getter.variable = variable; 299 getter.variable = variable;
300 getter.getter = true; 300 getter.getter = true;
301 getter.isStatic = true; 301 getter.isStatic = true;
302 variable.getter = getter; 302 variable.getter = getter;
303 if (node.returnType == null) { 303 if (node.returnType == null) {
304 getter.hasImplicitReturnType = true; 304 getter.hasImplicitReturnType = true;
305 } 305 }
306 _currentHolder.addAccessor(getter); 306 _currentHolder.addAccessor(getter);
307 expression.element = getter; 307 expression.element = getter;
308 propertyNameNode.staticElement = getter; 308 propertyNameNode.staticElement = getter;
309 } else { 309 } else {
310 PropertyAccessorElementImpl setter = 310 PropertyAccessorElementImpl setter =
311 new PropertyAccessorElementImpl.forNode(propertyNameNode); 311 new PropertyAccessorElementImpl.forNode(propertyNameNode);
312 _setCodeRange(setter, node); 312 _setCodeRange(setter, node);
313 setter.metadata = _createElementAnnotations(node.metadata); 313 setter.metadata = _createElementAnnotations(node.metadata);
314 setElementDocumentationComment(setter, node); 314 setElementDocumentationComment(setter, node);
315 if (node.externalKeyword != null || body is NativeFunctionBody) { 315 if (node.externalKeyword != null || body is NativeFunctionBody) {
316 setter.external = true; 316 setter.external = true;
317 } 317 }
318 setter.functions = holder.functions; 318 setter.functions = holder.functions;
319 setter.labels = holder.labels; 319 setter.labels = holder.labels;
320 setter.localVariables = holder.localVariables; 320 setter.encloseElements(holder.localVariables);
321 setter.parameters = holder.parameters; 321 setter.parameters = holder.parameters;
322 if (body.isAsynchronous) { 322 if (body.isAsynchronous) {
323 setter.asynchronous = true; 323 setter.asynchronous = true;
324 } 324 }
325 if (body.isGenerator) { 325 if (body.isGenerator) {
326 setter.generator = true; 326 setter.generator = true;
327 } 327 }
328 setter.variable = variable; 328 setter.variable = variable;
329 setter.setter = true; 329 setter.setter = true;
330 setter.isStatic = true; 330 setter.isStatic = true;
(...skipping 20 matching lines...) Expand all
351 return super.visitFunctionExpression(node); 351 return super.visitFunctionExpression(node);
352 } 352 }
353 ElementHolder holder = new ElementHolder(); 353 ElementHolder holder = new ElementHolder();
354 _visitChildren(holder, node); 354 _visitChildren(holder, node);
355 FunctionBody body = node.body; 355 FunctionBody body = node.body;
356 FunctionElementImpl element = 356 FunctionElementImpl element =
357 new FunctionElementImpl.forOffset(node.beginToken.offset); 357 new FunctionElementImpl.forOffset(node.beginToken.offset);
358 _setCodeRange(element, node); 358 _setCodeRange(element, node);
359 element.functions = holder.functions; 359 element.functions = holder.functions;
360 element.labels = holder.labels; 360 element.labels = holder.labels;
361 element.localVariables = holder.localVariables; 361 element.encloseElements(holder.localVariables);
362 element.parameters = holder.parameters; 362 element.parameters = holder.parameters;
363 element.typeParameters = holder.typeParameters; 363 element.typeParameters = holder.typeParameters;
364 if (body.isAsynchronous) { 364 if (body.isAsynchronous) {
365 element.asynchronous = true; 365 element.asynchronous = true;
366 } 366 }
367 if (body.isGenerator) { 367 if (body.isGenerator) {
368 element.generator = true; 368 element.generator = true;
369 } 369 }
370 element.type = new FunctionTypeImpl(element); 370 element.type = new FunctionTypeImpl(element);
371 element.hasImplicitReturnType = true; 371 element.hasImplicitReturnType = true;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 new MethodElementImpl(nameOfMethod, methodName.offset); 453 new MethodElementImpl(nameOfMethod, methodName.offset);
454 _setCodeRange(element, node); 454 _setCodeRange(element, node);
455 element.metadata = _createElementAnnotations(node.metadata); 455 element.metadata = _createElementAnnotations(node.metadata);
456 setElementDocumentationComment(element, node); 456 setElementDocumentationComment(element, node);
457 element.abstract = node.isAbstract; 457 element.abstract = node.isAbstract;
458 if (node.externalKeyword != null || body is NativeFunctionBody) { 458 if (node.externalKeyword != null || body is NativeFunctionBody) {
459 element.external = true; 459 element.external = true;
460 } 460 }
461 element.functions = holder.functions; 461 element.functions = holder.functions;
462 element.labels = holder.labels; 462 element.labels = holder.labels;
463 element.localVariables = holder.localVariables; 463 element.encloseElements(holder.localVariables);
464 element.parameters = holder.parameters; 464 element.parameters = holder.parameters;
465 element.isStatic = isStatic; 465 element.isStatic = isStatic;
466 element.typeParameters = holder.typeParameters; 466 element.typeParameters = holder.typeParameters;
467 if (body.isAsynchronous) { 467 if (body.isAsynchronous) {
468 element.asynchronous = true; 468 element.asynchronous = true;
469 } 469 }
470 if (body.isGenerator) { 470 if (body.isGenerator) {
471 element.generator = true; 471 element.generator = true;
472 } 472 }
473 if (node.returnType == null) { 473 if (node.returnType == null) {
(...skipping 17 matching lines...) Expand all
491 PropertyAccessorElementImpl getter = 491 PropertyAccessorElementImpl getter =
492 new PropertyAccessorElementImpl.forNode(propertyNameNode); 492 new PropertyAccessorElementImpl.forNode(propertyNameNode);
493 _setCodeRange(getter, node); 493 _setCodeRange(getter, node);
494 getter.metadata = _createElementAnnotations(node.metadata); 494 getter.metadata = _createElementAnnotations(node.metadata);
495 setElementDocumentationComment(getter, node); 495 setElementDocumentationComment(getter, node);
496 if (node.externalKeyword != null || body is NativeFunctionBody) { 496 if (node.externalKeyword != null || body is NativeFunctionBody) {
497 getter.external = true; 497 getter.external = true;
498 } 498 }
499 getter.functions = holder.functions; 499 getter.functions = holder.functions;
500 getter.labels = holder.labels; 500 getter.labels = holder.labels;
501 getter.localVariables = holder.localVariables; 501 getter.encloseElements(holder.localVariables);
502 if (body.isAsynchronous) { 502 if (body.isAsynchronous) {
503 getter.asynchronous = true; 503 getter.asynchronous = true;
504 } 504 }
505 if (body.isGenerator) { 505 if (body.isGenerator) {
506 getter.generator = true; 506 getter.generator = true;
507 } 507 }
508 getter.variable = field; 508 getter.variable = field;
509 getter.abstract = node.isAbstract; 509 getter.abstract = node.isAbstract;
510 getter.getter = true; 510 getter.getter = true;
511 getter.isStatic = isStatic; 511 getter.isStatic = isStatic;
512 field.getter = getter; 512 field.getter = getter;
513 if (node.returnType == null) { 513 if (node.returnType == null) {
514 getter.hasImplicitReturnType = true; 514 getter.hasImplicitReturnType = true;
515 } 515 }
516 _currentHolder.addAccessor(getter); 516 _currentHolder.addAccessor(getter);
517 propertyNameNode.staticElement = getter; 517 propertyNameNode.staticElement = getter;
518 } else { 518 } else {
519 PropertyAccessorElementImpl setter = 519 PropertyAccessorElementImpl setter =
520 new PropertyAccessorElementImpl.forNode(propertyNameNode); 520 new PropertyAccessorElementImpl.forNode(propertyNameNode);
521 _setCodeRange(setter, node); 521 _setCodeRange(setter, node);
522 setter.metadata = _createElementAnnotations(node.metadata); 522 setter.metadata = _createElementAnnotations(node.metadata);
523 setElementDocumentationComment(setter, node); 523 setElementDocumentationComment(setter, node);
524 if (node.externalKeyword != null || body is NativeFunctionBody) { 524 if (node.externalKeyword != null || body is NativeFunctionBody) {
525 setter.external = true; 525 setter.external = true;
526 } 526 }
527 setter.functions = holder.functions; 527 setter.functions = holder.functions;
528 setter.labels = holder.labels; 528 setter.labels = holder.labels;
529 setter.localVariables = holder.localVariables; 529 setter.encloseElements(holder.localVariables);
530 setter.parameters = holder.parameters; 530 setter.parameters = holder.parameters;
531 if (body.isAsynchronous) { 531 if (body.isAsynchronous) {
532 setter.asynchronous = true; 532 setter.asynchronous = true;
533 } 533 }
534 if (body.isGenerator) { 534 if (body.isGenerator) {
535 setter.generator = true; 535 setter.generator = true;
536 } 536 }
537 setter.variable = field; 537 setter.variable = field;
538 setter.abstract = node.isAbstract; 538 setter.abstract = node.isAbstract;
539 setter.setter = true; 539 setter.setter = true;
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 FunctionElementImpl element = new FunctionElementImpl.forNode(node.name); 1167 FunctionElementImpl element = new FunctionElementImpl.forNode(node.name);
1168 _setCodeRange(element, node); 1168 _setCodeRange(element, node);
1169 setElementDocumentationComment(element, node); 1169 setElementDocumentationComment(element, node);
1170 element.metadata = _createElementAnnotations(node.metadata); 1170 element.metadata = _createElementAnnotations(node.metadata);
1171 FunctionBody body = expression.body; 1171 FunctionBody body = expression.body;
1172 if (node.externalKeyword != null || body is NativeFunctionBody) { 1172 if (node.externalKeyword != null || body is NativeFunctionBody) {
1173 element.external = true; 1173 element.external = true;
1174 } 1174 }
1175 element.functions = holder.functions; 1175 element.functions = holder.functions;
1176 element.labels = holder.labels; 1176 element.labels = holder.labels;
1177 element.localVariables = holder.localVariables; 1177 element.encloseElements(holder.localVariables);
1178 element.parameters = holder.parameters; 1178 element.parameters = holder.parameters;
1179 element.typeParameters = holder.typeParameters; 1179 element.typeParameters = holder.typeParameters;
1180 1180
1181 if (body.isAsynchronous) { 1181 if (body.isAsynchronous) {
1182 element.asynchronous = body.isAsynchronous; 1182 element.asynchronous = body.isAsynchronous;
1183 } 1183 }
1184 if (body.isGenerator) { 1184 if (body.isGenerator) {
1185 element.generator = true; 1185 element.generator = true;
1186 } 1186 }
1187 1187
(...skipping 23 matching lines...) Expand all
1211 return super.visitFunctionExpression(node); 1211 return super.visitFunctionExpression(node);
1212 } 1212 }
1213 1213
1214 ElementHolder holder = new ElementHolder(); 1214 ElementHolder holder = new ElementHolder();
1215 _visitChildren(holder, node); 1215 _visitChildren(holder, node);
1216 FunctionElementImpl element = 1216 FunctionElementImpl element =
1217 new FunctionElementImpl.forOffset(node.beginToken.offset); 1217 new FunctionElementImpl.forOffset(node.beginToken.offset);
1218 _setCodeRange(element, node); 1218 _setCodeRange(element, node);
1219 element.functions = holder.functions; 1219 element.functions = holder.functions;
1220 element.labels = holder.labels; 1220 element.labels = holder.labels;
1221 element.localVariables = holder.localVariables; 1221 element.encloseElements(holder.localVariables);
1222 element.parameters = holder.parameters; 1222 element.parameters = holder.parameters;
1223 element.typeParameters = holder.typeParameters; 1223 element.typeParameters = holder.typeParameters;
1224 1224
1225 FunctionBody body = node.body; 1225 FunctionBody body = node.body;
1226 if (body.isAsynchronous) { 1226 if (body.isAsynchronous) {
1227 element.asynchronous = true; 1227 element.asynchronous = true;
1228 } 1228 }
1229 if (body.isGenerator) { 1229 if (body.isGenerator) {
1230 element.generator = true; 1230 element.generator = true;
1231 } 1231 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 void buildParameterInitializer( 1334 void buildParameterInitializer(
1335 ParameterElementImpl parameter, Expression defaultValue) { 1335 ParameterElementImpl parameter, Expression defaultValue) {
1336 if (defaultValue != null) { 1336 if (defaultValue != null) {
1337 ElementHolder holder = new ElementHolder(); 1337 ElementHolder holder = new ElementHolder();
1338 _visit(holder, defaultValue); 1338 _visit(holder, defaultValue);
1339 FunctionElementImpl initializer = 1339 FunctionElementImpl initializer =
1340 new FunctionElementImpl.forOffset(defaultValue.beginToken.offset); 1340 new FunctionElementImpl.forOffset(defaultValue.beginToken.offset);
1341 initializer.hasImplicitReturnType = true; 1341 initializer.hasImplicitReturnType = true;
1342 initializer.functions = holder.functions; 1342 initializer.functions = holder.functions;
1343 initializer.labels = holder.labels; 1343 initializer.labels = holder.labels;
1344 initializer.localVariables = holder.localVariables; 1344 initializer.encloseElements(holder.localVariables);
1345 initializer.parameters = holder.parameters; 1345 initializer.parameters = holder.parameters;
1346 initializer.isSynthetic = true; 1346 initializer.isSynthetic = true;
1347 initializer.type = new FunctionTypeImpl(initializer); 1347 initializer.type = new FunctionTypeImpl(initializer);
1348 parameter.initializer = initializer; 1348 parameter.initializer = initializer;
1349 parameter.defaultValueCode = defaultValue.toSource(); 1349 parameter.defaultValueCode = defaultValue.toSource();
1350 holder.validate(); 1350 holder.validate();
1351 } 1351 }
1352 } 1352 }
1353 1353
1354 /** 1354 /**
1355 * If the [initializer] is not `null`, build the [FunctionElementImpl] that 1355 * If the [initializer] is not `null`, build the [FunctionElementImpl] that
1356 * corresponds it, and set it as the initializer for the [variable]. 1356 * corresponds it, and set it as the initializer for the [variable].
1357 */ 1357 */
1358 void buildVariableInitializer( 1358 void buildVariableInitializer(
1359 VariableElementImpl variable, Expression initializer) { 1359 VariableElementImpl variable, Expression initializer) {
1360 if (initializer != null) { 1360 if (initializer != null) {
1361 ElementHolder holder = new ElementHolder(); 1361 ElementHolder holder = new ElementHolder();
1362 _visit(holder, initializer); 1362 _visit(holder, initializer);
1363 FunctionElementImpl initializerElement = 1363 FunctionElementImpl initializerElement =
1364 new FunctionElementImpl.forOffset(initializer.beginToken.offset); 1364 new FunctionElementImpl.forOffset(initializer.beginToken.offset);
1365 initializerElement.hasImplicitReturnType = true; 1365 initializerElement.hasImplicitReturnType = true;
1366 initializerElement.functions = holder.functions; 1366 initializerElement.functions = holder.functions;
1367 initializerElement.labels = holder.labels; 1367 initializerElement.labels = holder.labels;
1368 initializerElement.localVariables = holder.localVariables; 1368 initializerElement.encloseElements(holder.localVariables);
1369 initializerElement.isSynthetic = true; 1369 initializerElement.isSynthetic = true;
1370 initializerElement.type = new FunctionTypeImpl(initializerElement); 1370 initializerElement.type = new FunctionTypeImpl(initializerElement);
1371 variable.initializer = initializerElement; 1371 variable.initializer = initializerElement;
1372 holder.validate(); 1372 holder.validate();
1373 } 1373 }
1374 } 1374 }
1375 1375
1376 @override 1376 @override
1377 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 1377 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
1378 NormalFormalParameter normalParameter = node.parameter; 1378 NormalFormalParameter normalParameter = node.parameter;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 return null; 1668 return null;
1669 } 1669 }
1670 1670
1671 /** 1671 /**
1672 * Return the lexical identifiers associated with the given [identifiers]. 1672 * Return the lexical identifiers associated with the given [identifiers].
1673 */ 1673 */
1674 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { 1674 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) {
1675 return identifiers.map((identifier) => identifier.name).toList(); 1675 return identifiers.map((identifier) => identifier.name).toList();
1676 } 1676 }
1677 } 1677 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | pkg/analyzer/lib/src/dart/element/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698