Changeset View
Changeset View
Standalone View
Standalone View
language/duchain/declarationid.h
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 54 | public: | |||
---|---|---|---|---|---|
69 | * directly reference the Declaration | 69 | * directly reference the Declaration | ||
70 | * | 70 | * | ||
71 | * \param decl Declaration to reference. | 71 | * \param decl Declaration to reference. | ||
72 | * \param specialization Specialization index (see class documentation). | 72 | * \param specialization Specialization index (see class documentation). | ||
73 | */ | 73 | */ | ||
74 | explicit DeclarationId(const IndexedDeclaration& decl, | 74 | explicit DeclarationId(const IndexedDeclaration& decl, | ||
75 | const IndexedInstantiationInformation& specialization = IndexedInstantiationInformation()); | 75 | const IndexedInstantiationInformation& specialization = IndexedInstantiationInformation()); | ||
76 | 76 | | |||
77 | | ||||
78 | DeclarationId(const DeclarationId& rhs); | ||||
79 | | ||||
80 | ~DeclarationId(); | ||||
81 | | ||||
82 | DeclarationId& operator=(const DeclarationId& rhs); | ||||
83 | | ||||
77 | /** | 84 | /** | ||
78 | * Equality operator. | 85 | * Equality operator. | ||
79 | * | 86 | * | ||
80 | * \param rhs declaration identifier to compare. | 87 | * \param rhs declaration identifier to compare. | ||
81 | * \returns true if equal, otherwise false. | 88 | * \returns true if equal, otherwise false. | ||
82 | */ | 89 | */ | ||
83 | bool operator==(const DeclarationId& rhs) const { | 90 | bool operator==(const DeclarationId& rhs) const { | ||
84 | if(m_direct != rhs.m_direct) | 91 | if(m_isDirect != rhs.m_isDirect) | ||
85 | return false; | 92 | return false; | ||
86 | 93 | | |||
87 | if(!m_direct) | 94 | if(!m_isDirect) | ||
88 | return indirect.m_identifier == rhs.indirect.m_identifier && indirect.m_additionalIdentity == rhs.indirect.m_additionalIdentity && m_specialization == rhs.m_specialization; | 95 | return m_indirectData.identifier == rhs.m_indirectData.identifier && m_indirectData.additionalIdentity == rhs.m_indirectData.additionalIdentity && m_specialization == rhs.m_specialization; | ||
mwolff: break the long line | |||||
89 | else | 96 | else | ||
90 | return direct == rhs.direct && m_specialization == rhs.m_specialization; | 97 | return m_directData == rhs.m_directData && m_specialization == rhs.m_specialization; | ||
91 | } | 98 | } | ||
92 | 99 | | |||
93 | /** | 100 | /** | ||
94 | * Not equal operator. | 101 | * Not equal operator. | ||
95 | * | 102 | * | ||
96 | * \param rhs declaration identifier to compare. | 103 | * \param rhs declaration identifier to compare. | ||
97 | * \returns true if not equal, otherwise false. | 104 | * \returns true if not equal, otherwise false. | ||
98 | */ | 105 | */ | ||
99 | bool operator!=(const DeclarationId& rhs) const { | 106 | bool operator!=(const DeclarationId& rhs) const { | ||
100 | return !operator==(rhs); | 107 | return !operator==(rhs); | ||
101 | } | 108 | } | ||
102 | 109 | | |||
103 | /** | 110 | /** | ||
104 | * Determine whether this declaration identifier references a valid declaration. | 111 | * Determine whether this declaration identifier references a valid declaration. | ||
105 | */ | 112 | */ | ||
106 | bool isValid() const { | 113 | bool isValid() const { | ||
107 | return (m_direct && direct.isValid()) || indirect.m_identifier.isValid(); | 114 | return (m_isDirect && m_directData.isValid()) || m_indirectData.identifier.isValid(); | ||
108 | } | 115 | } | ||
109 | 116 | | |||
110 | /** | 117 | /** | ||
111 | * Hash function for this declaration identifier. | 118 | * Hash function for this declaration identifier. | ||
112 | * | 119 | * | ||
113 | * \warning This may return different hashes for the same declaration, | 120 | * \warning This may return different hashes for the same declaration, | ||
114 | * depending on whether the id is direct or indirect, | 121 | * depending on whether the id is direct or indirect, | ||
115 | * and thus you cannot compare hashes for declaration equality (use operator==() instead) | 122 | * and thus you cannot compare hashes for declaration equality (use operator==() instead) | ||
116 | */ | 123 | */ | ||
117 | uint hash() const { | 124 | uint hash() const { | ||
118 | if(m_direct) | 125 | if(m_isDirect) | ||
119 | return KDevHash() << direct.hash() << m_specialization.index(); | 126 | return KDevHash() << m_directData.hash() << m_specialization.index(); | ||
120 | else | 127 | else | ||
121 | return KDevHash() << indirect.m_identifier.getIndex() << indirect.m_additionalIdentity << m_specialization.index(); | 128 | return KDevHash() << m_indirectData.identifier.getIndex() << m_indirectData.additionalIdentity << m_specialization.index(); | ||
122 | } | 129 | } | ||
123 | 130 | | |||
124 | /** | 131 | /** | ||
125 | * Retrieve the declaration, from the perspective of \a context. | 132 | * Retrieve the declaration, from the perspective of \a context. | ||
126 | * In order to be retrievable, the declaration must be in the symbol table. | 133 | * In order to be retrievable, the declaration must be in the symbol table. | ||
127 | * | 134 | * | ||
128 | * \param context Context in which to search for the Declaration. | 135 | * \param context Context in which to search for the Declaration. | ||
129 | * \param instantiateIfRequired Whether the declaration should be instantiated if required | 136 | * \param instantiateIfRequired Whether the declaration should be instantiated if required | ||
Show All 33 Lines | |||||
163 | * Return the qualified identifier for this declaration. | 170 | * Return the qualified identifier for this declaration. | ||
164 | * | 171 | * | ||
165 | * \warning This is relatively expensive, and not 100% correct in all cases(actually a top-context would be needed to resolve this correctly), | 172 | * \warning This is relatively expensive, and not 100% correct in all cases(actually a top-context would be needed to resolve this correctly), | ||
166 | * so avoid using this, except for debugging purposes. | 173 | * so avoid using this, except for debugging purposes. | ||
167 | */ | 174 | */ | ||
168 | QualifiedIdentifier qualifiedIdentifier() const; | 175 | QualifiedIdentifier qualifiedIdentifier() const; | ||
169 | 176 | | |||
170 | private: | 177 | private: | ||
178 | /// An indirect reference to the declaration, which uses the symbol-table for lookup. Should be preferred for all | ||||
179 | /// declarations that are in the symbol-table | ||||
171 | struct Indirect { | 180 | struct Indirect { | ||
172 | IndexedQualifiedIdentifier m_identifier; | 181 | IndexedQualifiedIdentifier identifier; | ||
173 | // Hash from signature, or similar. | 182 | /// Hash from signature, or similar. Used to disambiguate multiple declarations of the same name. | ||
174 | // Used to disambiguate multiple declarations of the same name. | 183 | uint additionalIdentity; | ||
175 | uint m_additionalIdentity; | 184 | | ||
185 | Indirect& operator=(const Indirect& rhs) = default; | ||||
186 | }; | ||||
187 | | ||||
188 | union { | ||||
189 | Indirect m_indirectData; | ||||
190 | IndexedDeclaration m_directData; | ||||
176 | } ; | 191 | }; | ||
192 | bool m_isDirect; | ||||
177 | 193 | | |||
178 | //union { | | |||
179 | //An indirect reference to the declaration, which uses the symbol-table for lookup. Should be preferred for all | | |||
180 | //declarations that are in the symbol-table | | |||
181 | Indirect indirect; | | |||
182 | IndexedDeclaration direct; | | |||
183 | //}; | | |||
184 | bool m_direct; | | |||
185 | // Can be used in a language-specific way to pick other versions of the declaration. | 194 | // Can be used in a language-specific way to pick other versions of the declaration. | ||
186 | // When the declaration is found, pickSpecialization is called on the found declaration | 195 | // When the declaration is found, pickSpecialization is called on the found declaration | ||
187 | // with this value, and the returned value is the actually found declaration. | 196 | // with this value, and the returned value is the actually found declaration. | ||
188 | IndexedInstantiationInformation m_specialization; | 197 | IndexedInstantiationInformation m_specialization; | ||
189 | }; | 198 | }; | ||
190 | 199 | | |||
191 | inline uint qHash(const KDevelop::DeclarationId& id) { | 200 | inline uint qHash(const KDevelop::DeclarationId& id) { | ||
192 | return id.hash(); | 201 | return id.hash(); | ||
193 | } | 202 | } | ||
194 | 203 | | |||
195 | } | 204 | } | ||
196 | 205 | | |||
197 | Q_DECLARE_TYPEINFO(KDevelop::DeclarationId, Q_MOVABLE_TYPE); | 206 | Q_DECLARE_TYPEINFO(KDevelop::DeclarationId, Q_MOVABLE_TYPE); | ||
198 | 207 | | |||
199 | #endif | 208 | #endif |
break the long line