File indexing completed on 2024-05-12 04:37:57
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_CODEMODEL_H 0008 #define KDEVPLATFORM_CODEMODEL_H 0009 0010 #include "identifier.h" 0011 0012 namespace KDevelop { 0013 class Declaration; 0014 class IndexedDeclaration; 0015 class DeclarationId; 0016 class TopDUContext; 0017 class QualifiedIdentifier; 0018 class IndexedString; 0019 0020 struct CodeModelItem 0021 { 0022 CodeModelItem() 0023 : kind(Unknown) 0024 { 0025 } 0026 enum Kind { 0027 Unknown = 0, 0028 Function = 1, 0029 Variable = 2, 0030 Class = 4, 0031 ForwardDeclaration = 8, 0032 Namespace = 16, 0033 ClassMember = 32 0034 }; 0035 IndexedQualifiedIdentifier id; 0036 uint referenceCount = 0; 0037 union { 0038 Kind kind; 0039 uint uKind; 0040 }; 0041 bool operator<(const CodeModelItem& rhs) const 0042 { 0043 return id < rhs.id; 0044 } 0045 }; 0046 0047 /** 0048 * Persistent store that efficiently holds a list of identifiers 0049 * and their kind for each declaration-string. 0050 */ 0051 class KDEVPLATFORMLANGUAGE_EXPORT CodeModel 0052 { 0053 Q_DISABLE_COPY_MOVE(CodeModel) 0054 CodeModel(); 0055 public: 0056 /** 0057 * There can only be one item for each identifier. 0058 * If an item with this identifier already exists, the kind is updated. 0059 */ 0060 void addItem(const IndexedString& file, const IndexedQualifiedIdentifier& id, CodeModelItem::Kind kind); 0061 0062 void removeItem(const IndexedString& file, const IndexedQualifiedIdentifier& id); 0063 0064 /** 0065 * Updates the kind for the given item. The item must already be in the code model. 0066 */ 0067 void updateItem(const IndexedString& file, const IndexedQualifiedIdentifier& id, CodeModelItem::Kind kind); 0068 0069 /** 0070 * Retrieves all the global identifiers for a file-name in an efficient way. 0071 * 0072 * @param count A reference that will be filled with the count of retrieved items 0073 * @param items A reference to a pointer, that will represent the array of items. 0074 * The array may contain items with an invalid identifier, those should be ignored. 0075 * The list is sorted by identifier-index(except for the invalid identifiers in between). 0076 */ 0077 void items(const IndexedString& file, uint& count, const CodeModelItem*& items) const; 0078 0079 static CodeModel& self(); 0080 }; 0081 } 0082 0083 Q_DECLARE_TYPEINFO(KDevelop::CodeModelItem, Q_MOVABLE_TYPE); 0084 0085 #endif