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

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

Issue 1788673004: Index unqualified unresolved used names. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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/token.dart'; 6 import 'package:analyzer/dart/ast/token.dart';
7 import 'package:analyzer/dart/ast/visitor.dart'; 7 import 'package:analyzer/dart/ast/visitor.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/member.dart'; 10 import 'package:analyzer/src/dart/element/member.dart';
(...skipping 25 matching lines...) Expand all
36 */ 36 */
37 final IndexSyntheticElementKind kind; 37 final IndexSyntheticElementKind kind;
38 38
39 /** 39 /**
40 * The unique id of the element. It is set after indexing of the whole 40 * The unique id of the element. It is set after indexing of the whole
41 * package is done and we are assembling the full package index. 41 * package is done and we are assembling the full package index.
42 */ 42 */
43 int id; 43 int id;
44 44
45 ElementInfo(this.unitId, this.offset, this.kind) { 45 ElementInfo(this.unitId, this.offset, this.kind) {
46 if (offset < 0) {
47 print(offset);
Brian Wilkerson 2016/03/11 22:50:06 Debugging code?
48 }
46 assert(offset >= 0); 49 assert(offset >= 0);
47 } 50 }
48 } 51 }
49 52
50 /** 53 /**
51 * Object that gathers information about the whole package index and then uses 54 * Object that gathers information about the whole package index and then uses
52 * it to assemble a new [PackageIndexBuilder]. Call [index] on each compilation 55 * it to assemble a new [PackageIndexBuilder]. Call [index] on each compilation
53 * unit to be indexed, then call [assemble] to retrieve the complete index for 56 * unit to be indexed, then call [assemble] to retrieve the complete index for
54 * the package. 57 * the package.
55 */ 58 */
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 300 }
298 } 301 }
299 302
300 void recordIsAncestorOf(Element descendant) { 303 void recordIsAncestorOf(Element descendant) {
301 _recordIsAncestorOf(descendant, descendant, false, <ClassElement>[]); 304 _recordIsAncestorOf(descendant, descendant, false, <ClassElement>[]);
302 } 305 }
303 306
304 /** 307 /**
305 * Record that the name [node] has a relation of the given [kind]. 308 * Record that the name [node] has a relation of the given [kind].
306 */ 309 */
307 void recordNameRelation(SimpleIdentifier node, IndexRelationKind kind) { 310 void recordNameRelation(
311 SimpleIdentifier node, IndexRelationKind kind, bool isQualified) {
308 if (node != null) { 312 if (node != null) {
309 assembler.addNameRelation(node.name, kind, node.offset); 313 assembler.addNameRelation(node.name, kind, node.offset, isQualified);
310 } 314 }
311 } 315 }
312 316
313 /** 317 /**
314 * Record reference to the given operator [Element]. 318 * Record reference to the given operator [Element].
315 */ 319 */
316 void recordOperatorReference(Token operator, Element element) { 320 void recordOperatorReference(Token operator, Element element) {
317 recordRelationToken(element, IndexRelationKind.IS_INVOKED_BY, operator); 321 recordRelationToken(element, IndexRelationKind.IS_INVOKED_BY, operator);
318 } 322 }
319 323
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 Token operator = node.leftBracket; 488 Token operator = node.leftBracket;
485 recordRelationToken(element, IndexRelationKind.IS_INVOKED_BY, operator); 489 recordRelationToken(element, IndexRelationKind.IS_INVOKED_BY, operator);
486 } 490 }
487 super.visitIndexExpression(node); 491 super.visitIndexExpression(node);
488 } 492 }
489 493
490 @override 494 @override
491 visitMethodInvocation(MethodInvocation node) { 495 visitMethodInvocation(MethodInvocation node) {
492 SimpleIdentifier name = node.methodName; 496 SimpleIdentifier name = node.methodName;
493 Element element = name.bestElement; 497 Element element = name.bestElement;
494 // qualified unresolved name invocation 498 // unresolved name invocation
495 bool isQualified = node.realTarget != null; 499 bool isQualified = node.realTarget != null;
496 if (isQualified && element == null) { 500 if (element == null) {
497 recordNameRelation(name, IndexRelationKind.IS_INVOKED_BY); 501 recordNameRelation(name, IndexRelationKind.IS_INVOKED_BY, isQualified);
498 } 502 }
499 // element invocation 503 // element invocation
500 IndexRelationKind kind = element is ClassElement 504 IndexRelationKind kind = element is ClassElement
501 ? IndexRelationKind.IS_REFERENCED_BY 505 ? IndexRelationKind.IS_REFERENCED_BY
502 : IndexRelationKind.IS_INVOKED_BY; 506 : IndexRelationKind.IS_INVOKED_BY;
503 recordRelation(element, kind, name, isQualified); 507 recordRelation(element, kind, name, isQualified);
504 node.target?.accept(this); 508 node.target?.accept(this);
505 node.argumentList?.accept(this); 509 node.argumentList?.accept(this);
506 } 510 }
507 511
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 545 }
542 546
543 @override 547 @override
544 visitSimpleIdentifier(SimpleIdentifier node) { 548 visitSimpleIdentifier(SimpleIdentifier node) {
545 Element element = node.bestElement; 549 Element element = node.bestElement;
546 // name in declaration 550 // name in declaration
547 if (node.inDeclarationContext()) { 551 if (node.inDeclarationContext()) {
548 recordDefinedElement(element); 552 recordDefinedElement(element);
549 return; 553 return;
550 } 554 }
551 // record qualified unresolved name reference 555 // record unresolved name reference
552 bool isQualified = _isQualified(node); 556 bool isQualified = _isQualified(node);
553 if (isQualified && element == null) { 557 if (element == null) {
554 bool inGetterContext = node.inGetterContext(); 558 bool inGetterContext = node.inGetterContext();
555 bool inSetterContext = node.inSetterContext(); 559 bool inSetterContext = node.inSetterContext();
556 IndexRelationKind kind; 560 IndexRelationKind kind;
557 if (inGetterContext && inSetterContext) { 561 if (inGetterContext && inSetterContext) {
558 kind = IndexRelationKind.IS_READ_WRITTEN_BY; 562 kind = IndexRelationKind.IS_READ_WRITTEN_BY;
559 } else if (inGetterContext) { 563 } else if (inGetterContext) {
560 kind = IndexRelationKind.IS_READ_BY; 564 kind = IndexRelationKind.IS_READ_BY;
561 } else { 565 } else {
562 kind = IndexRelationKind.IS_WRITTEN_BY; 566 kind = IndexRelationKind.IS_WRITTEN_BY;
563 } 567 }
564 recordNameRelation(node, kind); 568 recordNameRelation(node, kind, isQualified);
565 } 569 }
566 // this.field parameter 570 // this.field parameter
567 if (element is FieldFormalParameterElement) { 571 if (element is FieldFormalParameterElement) {
568 AstNode parent = node.parent; 572 AstNode parent = node.parent;
569 IndexRelationKind kind = 573 IndexRelationKind kind =
570 parent is FieldFormalParameter && parent.identifier == node 574 parent is FieldFormalParameter && parent.identifier == node
571 ? IndexRelationKind.IS_WRITTEN_BY 575 ? IndexRelationKind.IS_WRITTEN_BY
572 : IndexRelationKind.IS_REFERENCED_BY; 576 : IndexRelationKind.IS_REFERENCED_BY;
573 recordRelation(element.field, kind, node, true); 577 recordRelation(element.field, kind, node, true);
574 return; 578 return;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 * context of the compilation unit pointed to by the [_UnitIndexAssembler]. 689 * context of the compilation unit pointed to by the [_UnitIndexAssembler].
686 */ 690 */
687 class _NameRelationInfo { 691 class _NameRelationInfo {
688 /** 692 /**
689 * The information about the name returned from 693 * The information about the name returned from
690 * [PackageIndexAssembler._getStringInfo]. 694 * [PackageIndexAssembler._getStringInfo].
691 */ 695 */
692 final _StringInfo nameInfo; 696 final _StringInfo nameInfo;
693 final IndexRelationKind kind; 697 final IndexRelationKind kind;
694 final int offset; 698 final int offset;
699 final bool isQualified;
695 700
696 _NameRelationInfo(this.nameInfo, this.kind, this.offset); 701 _NameRelationInfo(this.nameInfo, this.kind, this.offset, this.isQualified);
697 } 702 }
698 703
699 /** 704 /**
700 * Information about a string referenced in the index. 705 * Information about a string referenced in the index.
701 */ 706 */
702 class _StringInfo { 707 class _StringInfo {
703 /** 708 /**
704 * The value of the string. 709 * The value of the string.
705 */ 710 */
706 final String value; 711 final String value;
(...skipping 30 matching lines...) Expand all
737 742
738 void addElementRelation(Element element, IndexRelationKind kind, int offset, 743 void addElementRelation(Element element, IndexRelationKind kind, int offset,
739 int length, bool isQualified) { 744 int length, bool isQualified) {
740 try { 745 try {
741 ElementInfo elementInfo = pkg._getElementInfo(element); 746 ElementInfo elementInfo = pkg._getElementInfo(element);
742 elementRelations.add(new _ElementRelationInfo( 747 elementRelations.add(new _ElementRelationInfo(
743 elementInfo, kind, offset, length, isQualified)); 748 elementInfo, kind, offset, length, isQualified));
744 } on StateError {} 749 } on StateError {}
745 } 750 }
746 751
747 void addNameRelation(String name, IndexRelationKind kind, int offset) { 752 void addNameRelation(
753 String name, IndexRelationKind kind, int offset, bool isQualified) {
748 _StringInfo nameId = pkg._getStringInfo(name); 754 _StringInfo nameId = pkg._getStringInfo(name);
749 nameRelations.add(new _NameRelationInfo(nameId, kind, offset)); 755 nameRelations.add(new _NameRelationInfo(nameId, kind, offset, isQualified));
750 } 756 }
751 757
752 /** 758 /**
753 * Assemble a new [UnitIndexBuilder] using the information gathered 759 * Assemble a new [UnitIndexBuilder] using the information gathered
754 * by [addElementRelation] and [defineName]. 760 * by [addElementRelation] and [defineName].
755 */ 761 */
756 UnitIndexBuilder assemble() { 762 UnitIndexBuilder assemble() {
757 definedNames.sort((a, b) { 763 definedNames.sort((a, b) {
758 return a.nameInfo.id - b.nameInfo.id; 764 return a.nameInfo.id - b.nameInfo.id;
759 }); 765 });
760 elementRelations.sort((a, b) { 766 elementRelations.sort((a, b) {
761 return a.elementInfo.id - b.elementInfo.id; 767 return a.elementInfo.id - b.elementInfo.id;
762 }); 768 });
763 nameRelations.sort((a, b) { 769 nameRelations.sort((a, b) {
764 return a.nameInfo.id - b.nameInfo.id; 770 return a.nameInfo.id - b.nameInfo.id;
765 }); 771 });
766 return new UnitIndexBuilder( 772 return new UnitIndexBuilder(
767 unit: unitId, 773 unit: unitId,
768 definedNames: definedNames.map((n) => n.nameInfo.id).toList(), 774 definedNames: definedNames.map((n) => n.nameInfo.id).toList(),
769 definedNameKinds: definedNames.map((n) => n.kind).toList(), 775 definedNameKinds: definedNames.map((n) => n.kind).toList(),
770 definedNameOffsets: definedNames.map((n) => n.offset).toList(), 776 definedNameOffsets: definedNames.map((n) => n.offset).toList(),
771 usedElements: elementRelations.map((r) => r.elementInfo.id).toList(), 777 usedElements: elementRelations.map((r) => r.elementInfo.id).toList(),
772 usedElementKinds: elementRelations.map((r) => r.kind).toList(), 778 usedElementKinds: elementRelations.map((r) => r.kind).toList(),
773 usedElementOffsets: elementRelations.map((r) => r.offset).toList(), 779 usedElementOffsets: elementRelations.map((r) => r.offset).toList(),
774 usedElementLengths: elementRelations.map((r) => r.length).toList(), 780 usedElementLengths: elementRelations.map((r) => r.length).toList(),
775 usedElementIsQualifiedFlags: 781 usedElementIsQualifiedFlags:
776 elementRelations.map((r) => r.isQualified).toList(), 782 elementRelations.map((r) => r.isQualified).toList(),
777 usedNames: nameRelations.map((r) => r.nameInfo.id).toList(), 783 usedNames: nameRelations.map((r) => r.nameInfo.id).toList(),
778 usedNameKinds: nameRelations.map((r) => r.kind).toList(), 784 usedNameKinds: nameRelations.map((r) => r.kind).toList(),
779 usedNameOffsets: nameRelations.map((r) => r.offset).toList()); 785 usedNameOffsets: nameRelations.map((r) => r.offset).toList(),
786 usedNameIsQualifiedFlags:
787 nameRelations.map((r) => r.isQualified).toList());
780 } 788 }
781 789
782 void defineName(String name, IndexNameKind kind, int offset) { 790 void defineName(String name, IndexNameKind kind, int offset) {
783 _StringInfo nameInfo = pkg._getStringInfo(name); 791 _StringInfo nameInfo = pkg._getStringInfo(name);
784 definedNames.add(new _DefinedNameInfo(nameInfo, kind, offset)); 792 definedNames.add(new _DefinedNameInfo(nameInfo, kind, offset));
785 } 793 }
786 } 794 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/test/src/summary/index_unit_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698