language/duchain
identifier.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef IDENTIFIER_H
00021 #define IDENTIFIER_H
00022
00023 #include <QtCore/QList>
00024 #include <QtCore/QStack>
00025 #include <QtCore/QStringList>
00026 #include <util/kdevvarlengtharray.h>
00027
00028 #include <ksharedptr.h>
00029 #include <kdebug.h>
00030
00031 #include "../languageexport.h"
00032 #include "referencecounting.h"
00033
00034
00035
00036
00037 namespace KDevelop
00038 {
00039
00040 class IndexedTypeIdentifier;
00041 class Identifier;
00042 class QualifiedIdentifier;
00043 template<bool>
00044 class QualifiedIdentifierPrivate;
00045 template<bool>
00046 class IdentifierPrivate;
00047 class IndexedString;
00048
00054 struct KDEVPLATFORMLANGUAGE_EXPORT IndexedIdentifier : public ReferenceCountManager {
00055 IndexedIdentifier();
00056 IndexedIdentifier(const Identifier& id);
00057 IndexedIdentifier(const IndexedIdentifier& rhs);
00058 IndexedIdentifier& operator=(const Identifier& id);
00059 IndexedIdentifier& operator=(const IndexedIdentifier& rhs);
00060 ~IndexedIdentifier();
00061 bool operator==(const IndexedIdentifier& rhs) const;
00062 bool operator!=(const IndexedIdentifier& rhs) const;
00063 bool operator==(const Identifier& id) const;
00064
00065
00066 bool isEmpty() const;
00067
00068 Identifier identifier() const;
00069 operator Identifier() const;
00070
00071 uint getIndex() const {
00072 return index;
00073 }
00074
00075 private:
00076 unsigned int index;
00077 };
00078
00084 class KDEVPLATFORMLANGUAGE_EXPORT IndexedQualifiedIdentifier : public ReferenceCountManager {
00085 public:
00086
00087 IndexedQualifiedIdentifier();
00088 IndexedQualifiedIdentifier(const QualifiedIdentifier& id);
00089 IndexedQualifiedIdentifier(const IndexedQualifiedIdentifier& rhs);
00090 IndexedQualifiedIdentifier& operator=(const QualifiedIdentifier& id);
00091 IndexedQualifiedIdentifier& operator=(const IndexedQualifiedIdentifier& id);
00092 ~IndexedQualifiedIdentifier();
00093 bool operator==(const IndexedQualifiedIdentifier& rhs) const;
00094 bool operator==(const QualifiedIdentifier& id) const;
00095
00096 bool operator<(const IndexedQualifiedIdentifier& rhs) const {
00097 return index < rhs.index;
00098 }
00099
00100 bool isValid() const;
00101
00102 QualifiedIdentifier identifier() const;
00103 operator QualifiedIdentifier() const;
00104
00105 uint getIndex() const {
00106 return index;
00107 }
00108
00109 private:
00110 uint index;
00111 };
00112
00114 class KDEVPLATFORMLANGUAGE_EXPORT Identifier
00115 {
00116 friend class QualifiedIdentifier;
00117
00118 public:
00124 explicit Identifier(const QString& str, uint start = 0, uint* takenRange = 0);
00126 explicit Identifier(const IndexedString& str);
00127 Identifier(const Identifier& rhs);
00128 Identifier(uint index);
00129 Identifier();
00130 ~Identifier();
00131
00132 static Identifier unique(int token);
00133
00134 bool isUnique() const;
00135 int uniqueToken() const;
00139 void setUnique(int token);
00140
00141 const IndexedString identifier() const;
00142 void setIdentifier(const QString& identifier);
00143
00144 void setIdentifier(const IndexedString& identifier);
00145
00146
00147
00148 uint hash() const;
00149
00153 bool nameEquals(const Identifier& rhs) const;
00154
00155
00156 IndexedTypeIdentifier templateIdentifier(int num) const;
00157 uint templateIdentifiersCount() const;
00158 void appendTemplateIdentifier(const IndexedTypeIdentifier& identifier);
00159 void clearTemplateIdentifiers();
00160 void setTemplateIdentifiers(const QList<IndexedTypeIdentifier>& templateIdentifiers);
00161
00162 QString toString() const;
00163
00164 bool operator==(const Identifier& rhs) const;
00165 bool operator!=(const Identifier& rhs) const;
00166 Identifier& operator=(const Identifier& rhs);
00167
00168 bool isEmpty() const;
00169
00172 uint index() const;
00173
00177 inline friend kdbgstream& operator<< (kdbgstream& s, const Identifier& identifier) {
00178 s << identifier.toString();
00179 return s;
00180 }
00181
00182 private:
00183 void makeConstant() const;
00184 void prepareWrite();
00185
00186
00187 mutable uint m_index;
00188 union {
00189 mutable IdentifierPrivate<true>* dd;
00190 mutable const IdentifierPrivate<false>* cd;
00191 };
00192 };
00193
00199 class KDEVPLATFORMLANGUAGE_EXPORT QualifiedIdentifier
00200 {
00201 public:
00202 explicit QualifiedIdentifier(const QString& id, bool isExpression = false);
00203 explicit QualifiedIdentifier(const Identifier& id);
00204 QualifiedIdentifier(const QualifiedIdentifier& id);
00205 QualifiedIdentifier(uint index);
00206 QualifiedIdentifier();
00207 virtual ~QualifiedIdentifier();
00208
00209 void push(const Identifier& id);
00210 void push(const QualifiedIdentifier& id);
00211
00212 void pop();
00213 void clear();
00214 bool isEmpty() const;
00215 int count() const;
00216 Identifier first() const;
00217 Identifier last() const;
00218 Identifier top() const;
00219 const Identifier at(int i) const;
00224 QualifiedIdentifier mid(int pos, int len = -1) const;
00225
00231 inline QualifiedIdentifier left(int len) const { return mid(0, len > 0 ? len : count() + len); }
00232
00234 bool explicitlyGlobal() const;
00235 void setExplicitlyGlobal(bool eg);
00236 bool isQualified() const;
00237
00239 bool isExpression() const;
00245 void setIsExpression(bool);
00246
00247 QString toString(bool ignoreExplicitlyGlobal = false) const;
00248 QStringList toStringList() const;
00249
00250
00251
00252 QualifiedIdentifier operator+(const QualifiedIdentifier& rhs) const;
00253 QualifiedIdentifier& operator+=(const QualifiedIdentifier& rhs);
00254
00255
00256 QualifiedIdentifier operator+(const Identifier& rhs) const;
00257 QualifiedIdentifier& operator+=(const Identifier& rhs);
00258
00259
00260 QualifiedIdentifier merge(const QualifiedIdentifier& base) const;
00261
00266
00267
00271 bool operator==(const QualifiedIdentifier& rhs) const;
00272 bool operator!=(const QualifiedIdentifier& rhs) const;
00273 QualifiedIdentifier& operator=(const QualifiedIdentifier& rhs);
00274
00275 bool beginsWith(const QualifiedIdentifier& other) const;
00276
00277 uint index() const;
00278
00282 bool inRepository() const;
00283
00287 inline friend kdbgstream& operator<< (kdbgstream& s, const QualifiedIdentifier& identifier) {
00288 s << identifier.toString();
00289 return s;
00290 }
00291
00292 typedef uint HashType;
00293
00295 HashType hash() const;
00296
00298 static void findByHash(HashType hash, KDevVarLengthArray<QualifiedIdentifier>& target);
00299
00300 protected:
00301 bool sameIdentifiers(const QualifiedIdentifier& rhs) const;
00302
00303 void makeConstant() const;
00304 void prepareWrite();
00305
00306 mutable uint m_index;
00307 union {
00308 mutable QualifiedIdentifierPrivate<true>* dd;
00309 mutable const QualifiedIdentifierPrivate<false>* cd;
00310 };
00311 };
00312
00320 class KDEVPLATFORMLANGUAGE_EXPORT IndexedTypeIdentifier
00321 {
00322 public:
00324 explicit IndexedTypeIdentifier(IndexedQualifiedIdentifier identifier = IndexedQualifiedIdentifier());
00325 explicit IndexedTypeIdentifier(const QString& identifer, bool isExpression = false);
00326
00327 bool isReference() const;
00328 void setIsReference(bool);
00329
00330 bool isConstant() const;
00331 void setIsConstant(bool);
00332
00333 IndexedQualifiedIdentifier identifier() const ;
00334
00335 void setIdentifier(IndexedQualifiedIdentifier id);
00336
00338 int pointerDepth() const;
00342 void setPointerDepth(int);
00343
00345 bool isConstPointer(int depthNumber) const;
00346 void setIsConstPointer(int depthNumber, bool constant);
00347
00348 QString toString(bool ignoreExplicitlyGlobal = false) const;
00349
00350 uint hash() const;
00351
00355 bool operator==(const IndexedTypeIdentifier& rhs) const;
00356 bool operator!=(const IndexedTypeIdentifier& rhs) const;
00357 private:
00358 IndexedQualifiedIdentifier m_identifier;
00359 bool m_isConstant : 1;
00360 bool m_isReference : 1;
00361 uint m_pointerDepth : 5;
00362 uint m_pointerConstMask : 25;
00363 };
00364
00365 KDEVPLATFORMLANGUAGE_EXPORT uint qHash(const IndexedTypeIdentifier& id);
00366 KDEVPLATFORMLANGUAGE_EXPORT uint qHash(const QualifiedIdentifier& id);
00367 KDEVPLATFORMLANGUAGE_EXPORT uint qHash(const Identifier& id);
00368
00369 }
00370
00371 #endif // IDENTIFIER_H
00372
00373