File indexing completed on 2024-05-12 04:38:05

0001 /*
0002     SPDX-FileCopyrightText: 2008 David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef KDEVPLATFORM_DEFINITIONUSE_H
0008 #define KDEVPLATFORM_DEFINITIONUSE_H
0009 
0010 #include <limits>
0011 
0012 #include "../editor/rangeinrevision.h"
0013 
0014 #include <language/languageexport.h>
0015 
0016 namespace KDevelop {
0017 class TopDUContext;
0018 class Declaration;
0019 /**
0020  * Represents a position in a document where a specific declaration is used.
0021  *
0022  * Since we want to build uses for all files, and every single function may contain
0023  * tens to hundreds of uses, uses must be extremely light-weight.
0024  *
0025  * For that reason they are built in a way that a use can completely be stored in a simple vector,
0026  * and they only contain indices that represent the actual declaration used. Since the same
0027  * Declarations are used over and over again, the actual declarations are stored and indexed centrally
0028  * in the enclosing top-context. Additionally, because a use may refer to a not globally addressable item,
0029  * each top-context contains a local map that maps declaration-indices to local declarations.
0030  *
0031  * Since only a small fraction of all files is loaded as document at any time, only few documents actually
0032  * need smart-ranges. For that reason we do not store them here, but instead only map them to the uses
0033  * when there actually IS smart-ranges for them.
0034  */
0035 class KDEVPLATFORMLANGUAGE_EXPORT Use
0036 {
0037 public:
0038 
0039     explicit Use(const RangeInRevision& range = RangeInRevision::invalid(),
0040                  int declarationIndex = std::numeric_limits<int>::max())
0041         : m_range(range)
0042         , m_declarationIndex(declarationIndex)
0043     {
0044     }
0045 
0046     Declaration* usedDeclaration(TopDUContext* topContext) const;
0047 
0048     RangeInRevision m_range;
0049     int m_declarationIndex;
0050 };
0051 }
0052 
0053 Q_DECLARE_TYPEINFO(KDevelop::Use, Q_MOVABLE_TYPE);
0054 
0055 #endif // KDEVPLATFORM_DEFINITIONUSE_H