language/duchain
declarationid.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef DECLARATION_ID_H
00020 #define DECLARATION_ID_H
00021
00022 #include "../editor/hashedstring.h"
00023 #include "../editor/simplecursor.h"
00024
00025 #include "identifier.h"
00026 #include "indexeditems.h"
00027 #include "instantiationinformation.h"
00028
00029
00030
00031 class QString;
00032
00033 namespace KDevelop {
00034
00035 class Declaration;
00036 class TopDUContext;
00037
00055 class KDEVPLATFORMLANGUAGE_EXPORT DeclarationId {
00056 public:
00065 explicit DeclarationId(const IndexedQualifiedIdentifier& id = IndexedQualifiedIdentifier(), uint additionalId = 0, IndexedInstantiationInformation specialization = IndexedInstantiationInformation());
00066
00074 explicit DeclarationId(const IndexedDeclaration& decl, IndexedInstantiationInformation specialization = IndexedInstantiationInformation());
00075
00082 bool operator==(const DeclarationId& rhs) const {
00083 if(m_direct != rhs.m_direct)
00084 return false;
00085
00086 if(!m_direct)
00087 return indirect.m_identifier == rhs.indirect.m_identifier && indirect.m_additionalIdentity == rhs.indirect.m_additionalIdentity && m_specialization == rhs.m_specialization;
00088 else
00089 return direct == rhs.direct && m_specialization == rhs.m_specialization;
00090 }
00091
00098 bool operator!=(const DeclarationId& rhs) const {
00099 return !operator==(rhs);
00100 }
00101
00105 bool isValid() const {
00106 return (m_direct && direct.isValid()) || indirect.m_identifier.isValid();
00107 }
00108
00115 uint hash() const {
00116 if(m_direct)
00117 return direct.hash() + m_specialization.index() * 101;
00118 else
00119 return indirect.m_identifier.getIndex() * 13 + indirect.m_additionalIdentity + m_specialization.index() * 101;
00120 }
00121
00129 Declaration* getDeclaration(const TopDUContext* context) const;
00130
00132 KDevVarLengthArray<Declaration*> getDeclarations(const TopDUContext* context) const;
00133
00139 void setSpecialization(IndexedInstantiationInformation specialization);
00140
00146 IndexedInstantiationInformation specialization() const;
00147
00154 bool isDirect() const;
00155
00162 QualifiedIdentifier qualifiedIdentifier() const;
00163
00164 private:
00165 struct Indirect {
00166 IndexedQualifiedIdentifier m_identifier;
00167 uint m_additionalIdentity;
00168 } ;
00169
00170
00171
00172
00173 Indirect indirect;
00174 IndexedDeclaration direct;
00175
00176 bool m_direct;
00177 IndexedInstantiationInformation m_specialization;
00178
00179
00180 };
00181
00182 inline uint qHash(const KDevelop::DeclarationId& id) {
00183 return id.hash();
00184 }
00185
00186 }
00187
00188 #endif