| 673 | } |
| 674 | |
| 675 | QMap<IndexedString, QVector<RangeInRevision>> Declaration::uses() const |
| 676 | { |
| 677 | ENSURE_CAN_READ |
| 678 | QMap<IndexedString, QMap<RangeInRevision, bool>> tempUses; |
| 679 | |
| 680 | //First, search for uses within the own context |
| 681 | { |
| 682 | QMap<RangeInRevision, bool>& ranges(tempUses[topContext()->url()]); |
| 683 | const auto useRanges = allUses(topContext(), const_cast<Declaration*>(this)); |
| 684 | for (const RangeInRevision range : useRanges) { |
| 685 | ranges[range] = true; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | DeclarationId _id = id(); |
| 690 | KDevVarLengthArray<IndexedTopDUContext> useContexts = DUChain::uses()->uses(_id); |
| 691 | if (!_id.isDirect()) { // also check uses based on direct IDs |
| 692 | KDevVarLengthArray<IndexedTopDUContext> directUseContexts = DUChain::uses()->uses(id(true)); |
| 693 | useContexts.append(directUseContexts.data(), directUseContexts.size()); |
| 694 | } |
| 695 | |
| 696 | for (const IndexedTopDUContext indexedContext : std::as_const(useContexts)) { |
| 697 | TopDUContext* context = indexedContext.data(); |
| 698 | if (context) { |
| 699 | QMap<RangeInRevision, bool>& ranges(tempUses[context->url()]); |
| 700 | const auto useRanges = allUses(context, const_cast<Declaration*>(this)); |
| 701 | for (const RangeInRevision range : useRanges) { |
| 702 | ranges[range] = true; |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | QMap<IndexedString, QVector<RangeInRevision>> ret; |
| 708 | |
| 709 | for (QMap<IndexedString, QMap<RangeInRevision, bool>>::const_iterator it = tempUses.constBegin(); |
| 710 | it != tempUses.constEnd(); ++it) { |
| 711 | if (!(*it).isEmpty()) { |
| 712 | auto& list = ret[it.key()]; |
| 713 | list.reserve((*it).size()); |
| 714 | for (QMap<RangeInRevision, bool>::const_iterator it2 = (*it).constBegin(); it2 != (*it).constEnd(); ++it2) |
| 715 | list << it2.key(); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | return ret; |
| 720 | } |
| 721 | |
| 722 | bool hasDeclarationUse(DUContext* context, int declIdx) |
| 723 | { |