File indexing completed on 2024-05-12 04:38:03
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #ifndef KDEVPLATFORM_INSTANTIATIONINFORMATION_H 0008 #define KDEVPLATFORM_INSTANTIATIONINFORMATION_H 0009 0010 #include <language/languageexport.h> 0011 #include "types/abstracttype.h" 0012 #include "types/indexedtype.h" 0013 #include "appendedlist.h" 0014 0015 #include <serialization/referencecounting.h> 0016 0017 namespace KDevelop { 0018 class IndexedInstantiationInformation; 0019 class InstantiationInformation; 0020 class QualifiedIdentifier; 0021 0022 KDEVPLATFORMLANGUAGE_EXPORT DECLARE_LIST_MEMBER_HASH(InstantiationInformation, templateParameters, IndexedType) 0023 0024 /** 0025 * @note Move constructor and move assignment operator are deliberately not implemented for 0026 * IndexedInstantiationInformation. The move operations are tricky to implement correctly and more 0027 * efficiently in practice than the copy operations. swap() could be specialized for this class, 0028 * but it would never be called in practice. See a similar note for class IndexedString. 0029 */ 0030 class KDEVPLATFORMLANGUAGE_EXPORT IndexedInstantiationInformation 0031 : public ReferenceCountManager 0032 { 0033 public: 0034 IndexedInstantiationInformation() noexcept = default; 0035 explicit IndexedInstantiationInformation(uint index); 0036 IndexedInstantiationInformation(const IndexedInstantiationInformation& rhs) noexcept; 0037 IndexedInstantiationInformation& operator=(const IndexedInstantiationInformation& rhs) noexcept; 0038 ~IndexedInstantiationInformation(); 0039 0040 const InstantiationInformation& information() const; 0041 0042 uint hash() const 0043 { 0044 return m_index * 73; 0045 } 0046 0047 //Is always zero for the empty information 0048 uint index() const 0049 { 0050 return m_index; 0051 } 0052 0053 bool operator==(const IndexedInstantiationInformation& rhs) const 0054 { 0055 return m_index == rhs.m_index; 0056 } 0057 0058 //Returns true if one of the values represented by this information is non-default 0059 bool isValid() const; 0060 0061 private: 0062 uint m_index = 0; 0063 }; 0064 0065 class KDEVPLATFORMLANGUAGE_EXPORT InstantiationInformation 0066 { 0067 public: 0068 0069 InstantiationInformation(); 0070 ///@todo include some information for instantiation only with default parameters 0071 InstantiationInformation(const InstantiationInformation& rhs, bool dynamic = true); 0072 0073 ~InstantiationInformation(); 0074 0075 InstantiationInformation& operator=(const InstantiationInformation& rhs); 0076 0077 bool operator==(const InstantiationInformation& rhs) const; 0078 0079 uint hash() const; 0080 0081 bool isValid() const 0082 { 0083 return previousInstantiationInformation.index() || templateParametersSize(); 0084 } 0085 0086 bool persistent() const 0087 { 0088 return ( bool )m_refCount; 0089 } 0090 0091 /** 0092 * Applies this instantiation information to the given QualifiedIdentifier. 0093 * 0094 * The template parameters of the qualified identifier will be marked as expressions, 0095 * thus the qualified identifier is not "clean". 0096 * 0097 * Should only be used for displaying. 0098 * 0099 * This only adds template-parameters in places where none are known yet. 0100 */ 0101 QualifiedIdentifier applyToIdentifier(const QualifiedIdentifier& id) const; 0102 0103 /** 0104 * @param local If this is true, only the template-parameters of this scope are printed, 0105 * but not the parent ones 0106 */ 0107 QString toString(bool local = false) const; 0108 0109 /** 0110 * This must always be used to add new parameters. 0111 * 0112 * @warning Never use @c templateParametersList() directly. 0113 */ 0114 void addTemplateParameter(const AbstractType::Ptr& type); 0115 0116 /** 0117 * Instantiation-information for the surrounding context(see IndexedInstantiationInformation). 0118 */ 0119 IndexedInstantiationInformation previousInstantiationInformation; 0120 0121 START_APPENDED_LISTS(InstantiationInformation) 0122 0123 static uint classSize() 0124 { 0125 return sizeof(InstantiationInformation); 0126 } 0127 0128 short unsigned int itemSize() const 0129 { 0130 return dynamicSize(); 0131 } 0132 0133 /** 0134 * templateParameters contains the template-parameters used for the instantiation 0135 */ 0136 APPENDED_LIST_FIRST(InstantiationInformation, IndexedType, templateParameters); 0137 0138 END_APPENDED_LISTS(InstantiationInformation, templateParameters); 0139 0140 IndexedInstantiationInformation indexed() const; 0141 0142 private: 0143 friend class IndexedInstantiationInformation; 0144 friend struct ItemRepositoryReferenceCounting; 0145 uint m_refCount; 0146 }; 0147 0148 inline uint qHash(const IndexedInstantiationInformation& info) 0149 { 0150 return info.hash(); 0151 } 0152 inline uint qHash(const InstantiationInformation& info) 0153 { 0154 return info.hash(); 0155 } 0156 } 0157 0158 Q_DECLARE_TYPEINFO(KDevelop::IndexedInstantiationInformation, Q_MOVABLE_TYPE); 0159 Q_DECLARE_TYPEINFO(KDevelop::InstantiationInformation, Q_MOVABLE_TYPE); 0160 0161 #endif // KDEVPLATFORM_INSTANTIATIONINFORMATION_H