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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 1654983002: Don't use 'info.type', always set 'element'. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 summary_resynthesizer; 5 library summary_resynthesizer;
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/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 break; 407 break;
408 case UnlinkedConstOperation.makeTypedMap: 408 case UnlinkedConstOperation.makeTypedMap:
409 TypeName keyType = _newTypeName(); 409 TypeName keyType = _newTypeName();
410 TypeName valueType = _newTypeName(); 410 TypeName valueType = _newTypeName();
411 _pushMap(AstFactory.typeArgumentList(<TypeName>[keyType, valueType])); 411 _pushMap(AstFactory.typeArgumentList(<TypeName>[keyType, valueType]));
412 break; 412 break;
413 case UnlinkedConstOperation.pushReference: 413 case UnlinkedConstOperation.pushReference:
414 EntityRef ref = uc.references[refPtr++]; 414 EntityRef ref = uc.references[refPtr++];
415 _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference]; 415 _ReferenceInfo info = resynthesizer.referenceInfos[ref.reference];
416 if (info.element != null) { 416 if (info.element != null) {
417 Identifier node = _buildElementAst(info.name, info.element); 417 SimpleIdentifier node = AstFactory.identifier3(info.name);
418 _push(node); 418 node.staticElement = info.element;
419 } else if (info.type != null) {
420 Identifier node = _buildElementAst(info.name, info.type.element);
421 _push(node); 419 _push(node);
422 } else { 420 } else {
423 throw new StateError('Unsupported reference ${ref.toMap()}'); 421 throw new StateError('Unsupported reference ${ref.toMap()}');
424 } 422 }
425 break; 423 break;
426 case UnlinkedConstOperation.invokeConstructor: 424 case UnlinkedConstOperation.invokeConstructor:
427 case UnlinkedConstOperation.length: 425 case UnlinkedConstOperation.length:
428 return AstFactory.nullLiteral(); 426 return AstFactory.nullLiteral();
429 // throw new StateError('Unsupported constant operation $operation'); 427 // throw new StateError('Unsupported constant operation $operation');
430 } 428 }
431 } 429 }
432 return stack.single; 430 return stack.single;
433 } 431 }
434 432
435 Identifier _buildElementAst(String name, Element element) {
436 SimpleIdentifier node = AstFactory.identifier3(name);
437 node.staticElement = element;
438 return node;
439 }
440
441 TypeName _buildTypeAst(DartType type) { 433 TypeName _buildTypeAst(DartType type) {
442 if (type is DynamicTypeImpl) { 434 if (type is DynamicTypeImpl) {
443 TypeName node = AstFactory.typeName4('dynamic'); 435 TypeName node = AstFactory.typeName4('dynamic');
444 node.type = type; 436 node.type = type;
445 (node.name as SimpleIdentifier).staticElement = type.element; 437 (node.name as SimpleIdentifier).staticElement = type.element;
446 return node; 438 return node;
447 } else if (type is InterfaceType) { 439 } else if (type is InterfaceType) {
448 List<TypeName> argumentNodes = 440 List<TypeName> argumentNodes =
449 type.typeArguments.map(_buildTypeAst).toList(); 441 type.typeArguments.map(_buildTypeAst).toList();
450 TypeName node = AstFactory.typeName4(type.name, argumentNodes); 442 TypeName node = AstFactory.typeName4(type.name, argumentNodes);
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 LinkedReference linkedReference = linkedUnit.references[i]; 1453 LinkedReference linkedReference = linkedUnit.references[i];
1462 String name; 1454 String name;
1463 int containingReference; 1455 int containingReference;
1464 if (i < numUnlinkedReferences) { 1456 if (i < numUnlinkedReferences) {
1465 name = unlinkedUnit.references[i].name; 1457 name = unlinkedUnit.references[i].name;
1466 containingReference = unlinkedUnit.references[i].prefixReference; 1458 containingReference = unlinkedUnit.references[i].prefixReference;
1467 } else { 1459 } else {
1468 name = linkedUnit.references[i].name; 1460 name = linkedUnit.references[i].name;
1469 containingReference = linkedUnit.references[i].containingReference; 1461 containingReference = linkedUnit.references[i].containingReference;
1470 } 1462 }
1471 ElementHandle element; 1463 Element element;
1472 DartType type; 1464 DartType type;
1473 if (linkedReference.kind == ReferenceKind.unresolved) { 1465 if (linkedReference.kind == ReferenceKind.unresolved) {
1474 type = summaryResynthesizer.typeProvider.undefinedType; 1466 type = summaryResynthesizer.typeProvider.undefinedType;
1467 element = type.element;
1475 } else if (name == 'dynamic') { 1468 } else if (name == 'dynamic') {
1476 type = summaryResynthesizer.typeProvider.dynamicType; 1469 type = summaryResynthesizer.typeProvider.dynamicType;
1470 element = type.element;
1477 } else if (name == 'void') { 1471 } else if (name == 'void') {
1478 type = VoidTypeImpl.instance; 1472 type = VoidTypeImpl.instance;
1473 element = type.element;
1479 } else { 1474 } else {
1480 List<String> locationComponents; 1475 List<String> locationComponents;
1481 if (containingReference != 0 && 1476 if (containingReference != 0 &&
1482 referenceInfos[containingReference].element is ClassElement) { 1477 referenceInfos[containingReference].element is ClassElement) {
1483 String identifier = _getElementIdentifier(name, linkedReference.kind); 1478 String identifier = _getElementIdentifier(name, linkedReference.kind);
1484 locationComponents = referenceInfos[containingReference] 1479 locationComponents = referenceInfos[containingReference]
1485 .element 1480 .element
1486 .location 1481 .location
1487 .components 1482 .components
1488 .toList(); 1483 .toList();
(...skipping 25 matching lines...) Expand all
1514 case ReferenceKind.method: 1509 case ReferenceKind.method:
1515 assert(location.components.length == 4); 1510 assert(location.components.length == 4);
1516 element = new MethodElementHandle(summaryResynthesizer, location); 1511 element = new MethodElementHandle(summaryResynthesizer, location);
1517 break; 1512 break;
1518 default: 1513 default:
1519 // This is an element that doesn't (yet) need to be referred to 1514 // This is an element that doesn't (yet) need to be referred to
1520 // directly, so don't bother populating an element for it. 1515 // directly, so don't bother populating an element for it.
1521 // TODO(paulberry): add support for more kinds, as needed. 1516 // TODO(paulberry): add support for more kinds, as needed.
1522 break; 1517 break;
1523 } 1518 }
1524 } 1519 }
scheglov 2016/02/01 20:19:25 Or we could use code like this here: element ??= t
Paul Berry 2016/02/01 20:33:29 IMHO, it's a little easier to follow as is, since
1525 referenceInfos[i] = new _ReferenceInfo( 1520 referenceInfos[i] = new _ReferenceInfo(
1526 name, element, type, linkedReference.numTypeParameters); 1521 name, element, type, linkedReference.numTypeParameters);
1527 } 1522 }
1528 } 1523 }
1529 1524
1530 /** 1525 /**
1531 * Populate a [CompilationUnitElement] by deserializing all the elements 1526 * Populate a [CompilationUnitElement] by deserializing all the elements
1532 * contained in it. 1527 * contained in it.
1533 */ 1528 */
1534 void populateUnit(CompilationUnitElementImpl unit, int unitNum) { 1529 void populateUnit(CompilationUnitElementImpl unit, int unitNum) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 return element; 1704 return element;
1710 }; 1705 };
1711 // TODO(paulberry): Is it a bug that we have to pass `false` for 1706 // TODO(paulberry): Is it a bug that we have to pass `false` for
1712 // isInstantiated? 1707 // isInstantiated?
1713 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); 1708 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false);
1714 } else { 1709 } else {
1715 return null; 1710 return null;
1716 } 1711 }
1717 } 1712 }
1718 } 1713 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698