File indexing completed on 2024-05-12 04:38:04
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_SPECIALIZATIONSTORE_H 0008 #define KDEVPLATFORM_SPECIALIZATIONSTORE_H 0009 0010 #include <QHash> 0011 0012 #include <language/languageexport.h> 0013 0014 namespace KDevelop { 0015 class DeclarationId; 0016 class Declaration; 0017 class DUContext; 0018 class TopDUContext; 0019 class IndexedInstantiationInformation; 0020 0021 /** 0022 * This class allows dynamic management of "current" specializations for declarations. 0023 * 0024 * The specializations will be applied in editors, and wherever it makes sense. 0025 * For example, this is used in C++ to get code-completion and use-building within 0026 * instantiated template-classes/functions. 0027 */ 0028 class KDEVPLATFORMLANGUAGE_EXPORT SpecializationStore 0029 { 0030 public: 0031 static SpecializationStore& self(); 0032 0033 /** 0034 * Adds/updates the current specialization for the given declaration-id 0035 * */ 0036 void set(const DeclarationId& declaration, const IndexedInstantiationInformation& specialization); 0037 /** 0038 * Gets the registered specialization for the given declaration-id, or zero. 0039 */ 0040 IndexedInstantiationInformation get(const DeclarationId& declaration); 0041 /** 0042 * Clears the specialization registered for the given declaration-id 0043 */ 0044 void clear(const DeclarationId& declaration); 0045 /** 0046 * Clears all registered specializations 0047 */ 0048 void clear(); 0049 0050 /** 0051 * Applies the known specializations for the given declaration using the Declaration::specialize() function. 0052 * 0053 * If no specializations are known, the original declaration is returned. 0054 * 0055 * @param declaration The declaration to specialize 0056 * @param source The top-context from where to start searching 0057 * @param recursive Whether parent-contexts should be checked for known specializations, and those applied. 0058 * This is a bit more expensive then just doing a local check. 0059 */ 0060 KDevelop::Declaration* applySpecialization(KDevelop::Declaration* declaration, 0061 KDevelop::TopDUContext* source, bool recursive = true); 0062 /** 0063 * Applies the known specializations for the given context using the DUContext::specialize() function. 0064 * 0065 * If no specializations are known, returns the original context. 0066 * 0067 * @param context The context to specialize 0068 * @param source The top-context from where to start searching 0069 * @param recursive Whether parent-contexts should be checked for known specializations, and those applied. 0070 * This is a bit more expensive then just doing a local check. 0071 */ 0072 DUContext* applySpecialization(KDevelop::DUContext* context, 0073 KDevelop::TopDUContext* source, 0074 bool recursive = true); 0075 0076 private: 0077 Q_DISABLE_COPY_MOVE(SpecializationStore) 0078 SpecializationStore(); 0079 ~SpecializationStore(); 0080 QHash<DeclarationId, IndexedInstantiationInformation> m_specializations; 0081 }; 0082 } 0083 0084 #endif