46
44
class IdentifierPrivate;
47
45
class IndexedString;
49
///A helper-class to store an identifier by index in a type-safe way.
50
///The difference to Identifier is that this class only stores the index of an identifier that is in the repository, without any dynamic
51
///abilities or access to the contained data.
52
///This class does "disk reference counting"
53
///@warning Do not use this after QCoreApplication::aboutToQuit() has been emitted, items that are not disk-referenced will be invalid at that point
54
struct KDEVPLATFORMLANGUAGE_EXPORT IndexedIdentifier : public ReferenceCountManager {
48
* A helper-class to store an identifier by index in a type-safe way.
50
* The difference to Identifier is that this class only stores the index of an identifier that is in the repository, without any dynamic
51
* abilities or access to the contained data.
53
* This class does "disk reference counting"
55
* @warning Do not use this after QCoreApplication::aboutToQuit() has been emitted, items that are not disk-referenced will be invalid at that point.
57
class KDEVPLATFORMLANGUAGE_EXPORT IndexedIdentifier : public ReferenceCountManager
55
60
IndexedIdentifier();
56
61
IndexedIdentifier(const Identifier& id);
57
62
IndexedIdentifier(const IndexedIdentifier& rhs);
63
IndexedIdentifier(IndexedIdentifier&& rhs) Q_DECL_NOEXCEPT;
58
64
IndexedIdentifier& operator=(const Identifier& id);
59
65
IndexedIdentifier& operator=(const IndexedIdentifier& rhs);
66
IndexedIdentifier& operator=(IndexedIdentifier&& rhs) Q_DECL_NOEXCEPT;
60
67
~IndexedIdentifier();
61
68
bool operator==(const IndexedIdentifier& rhs) const;
62
69
bool operator!=(const IndexedIdentifier& rhs) const;
63
70
bool operator==(const Identifier& id) const;
66
72
bool isEmpty() const;
68
74
Identifier identifier() const;
69
75
operator Identifier() const;
71
uint getIndex() const {
76
83
unsigned int index;
79
///A helper-class to store an identifier by index in a type-safe way.
80
///The difference to QualifiedIdentifier is that this class only stores the index of an identifier that is in the repository, without any dynamic
81
///abilities or access to the contained data.
82
///This class does "disk reference counting"
83
///@warning Do not use this after QCoreApplication::aboutToQuit() has been emitted, items that are not disk-referenced will be invalid at that point
84
class KDEVPLATFORMLANGUAGE_EXPORT IndexedQualifiedIdentifier : public ReferenceCountManager {
87
* A helper-class to store an identifier by index in a type-safe way.
89
* The difference to QualifiedIdentifier is that this class only stores the index of an identifier that is in the repository, without any dynamic
90
* abilities or access to the contained data.
92
* This class does "disk reference counting"
94
* @warning Do not use this after QCoreApplication::aboutToQuit() has been emitted, items that are not disk-referenced will be invalid at that point.
96
class KDEVPLATFORMLANGUAGE_EXPORT IndexedQualifiedIdentifier : public ReferenceCountManager
87
99
IndexedQualifiedIdentifier();
88
100
IndexedQualifiedIdentifier(const QualifiedIdentifier& id);
89
101
IndexedQualifiedIdentifier(const IndexedQualifiedIdentifier& rhs);
102
IndexedQualifiedIdentifier(IndexedQualifiedIdentifier&& rhs) Q_DECL_NOEXCEPT;
90
103
IndexedQualifiedIdentifier& operator=(const QualifiedIdentifier& id);
91
104
IndexedQualifiedIdentifier& operator=(const IndexedQualifiedIdentifier& id);
105
IndexedQualifiedIdentifier& operator=(IndexedQualifiedIdentifier&& rhs) Q_DECL_NOEXCEPT;
92
106
~IndexedQualifiedIdentifier();
93
107
bool operator==(const IndexedQualifiedIdentifier& rhs) const;
94
108
bool operator==(const QualifiedIdentifier& id) const;
96
bool operator<(const IndexedQualifiedIdentifier& rhs) const {
110
bool operator<(const IndexedQualifiedIdentifier& rhs) const
97
112
return index < rhs.index;
100
115
bool isValid() const;
116
bool isEmpty() const;
102
118
QualifiedIdentifier identifier() const;
103
119
operator QualifiedIdentifier() const;
105
uint getIndex() const {
121
uint getIndex() const
113
/// Represents a single unqualified identifier
131
* Represents a single unqualified identifier
114
133
class KDEVPLATFORMLANGUAGE_EXPORT Identifier
116
135
friend class QualifiedIdentifier;
120
* @param start The position in the given string where to start searching for the identifier(optional).
121
* @param takenRange If this is nonzero, it will be filled with the length of the range from the beginning of the given string, that was used to construct this identifier.(optional)
122
* @warning The identifier is parsed in a C++-similar way, and the result may not be what you expect. If you want to prevent that parsing, use the constructor that takes IndexedString.
139
* @param start The position in the given string where to start searching for the identifier. (optional)
140
* @param takenRange If this is nonzero, it will be filled with the length of the range from the beginning
141
* of the given string, that was used to construct this identifier. (optional)
143
* @warning The identifier is parsed in a C++-similar way, and the result may not be what you expect.
144
* If you want to prevent that parsing, use the constructor that takes IndexedString.
124
146
explicit Identifier(const QString& str, uint start = 0, uint* takenRange = 0);
125
///Preferred constructor, ise this if you already have an IndexedString available. This does not decompose the given string.
148
* Preferred constructor, use this if you already have an IndexedString available. This does not decompose the given string.
126
150
explicit Identifier(const IndexedString& str);
127
151
Identifier(const Identifier& rhs);
128
152
Identifier(uint index);
154
Identifier(Identifier&& rhs) Q_DECL_NOEXCEPT;
156
Identifier& operator=(const Identifier& rhs);
157
Identifier& operator=(Identifier&& rhs) Q_DECL_NOEXCEPT;
132
159
static Identifier unique(int token);
134
161
bool isUnique() const;
135
162
int uniqueToken() const;
136
/// If \a token is non-zero, turns this Identifier into the special per-document
137
/// Unique identifier, used for anonymous namespaces.
138
/// Pass a token which is specific to the document to allow correct equality comparison.
164
* If \a token is non-zero, turns this Identifier into the special per-document unique identifier.
166
* This is used e.g. for anonymous namespaces.
168
* Pass a token which is specific to the document to allow correct equality comparison.
139
170
void setUnique(int token);
141
172
const IndexedString identifier() const;
142
173
void setIdentifier(const QString& identifier);
143
//Should be preferred over the other version
175
* Should be preferred over the other version
144
177
void setIdentifier(const IndexedString& identifier);
146
// QString mangled() const;
148
179
uint hash() const;
151
182
* Comparison ignoring the template-identifiers
153
184
bool nameEquals(const Identifier& rhs) const;
187
* @warning This is expensive.
156
189
IndexedTypeIdentifier templateIdentifier(int num) const;
157
190
uint templateIdentifiersCount() const;
158
191
void appendTemplateIdentifier(const IndexedTypeIdentifier& identifier);
208
262
Identifier first() const;
209
263
Identifier last() const;
210
264
Identifier top() const;
211
const Identifier at(int i) const;
265
Identifier at(int i) const;
213
267
* @param pos Position where to start the copy.
214
268
* @param len If this is -1, the whole following part will be returned.
216
270
QualifiedIdentifier mid(int pos, int len = -1) const;
219
273
* Copy the leftmost \a len number of identifiers.
221
275
* @param len The number of identifiers to copy, or if negative, the number of identifiers to omit from the right
223
inline QualifiedIdentifier left(int len) const { return mid(0, len > 0 ? len : count() + len); }
277
inline QualifiedIdentifier left(int len) const
279
return mid(0, len > 0 ? len : count() + len);
225
282
///@todo Remove this flag
226
283
bool explicitlyGlobal() const;
227
284
void setExplicitlyGlobal(bool eg);
228
285
bool isQualified() const;
230
///A flag that can be set by setIsExpression
288
* A flag that can be set by setIsExpression
231
290
bool isExpression() const;
233
292
* Set the expression-flag, that can be retrieved by isExpression().
234
293
* This flag is not respected while creating the hash-value and while operator==() comparison.
235
294
* It is respected while isSame(..) comparison.
237
296
void setIsExpression(bool);
239
298
QString toString(bool ignoreExplicitlyGlobal = false) const;
240
299
QStringList toStringList() const;
242
// QString mangled() const;
244
301
QualifiedIdentifier operator+(const QualifiedIdentifier& rhs) const;
245
302
QualifiedIdentifier& operator+=(const QualifiedIdentifier& rhs);
247
//Nicer interfaces to merge
305
* Nicer interfaces to merge
248
307
QualifiedIdentifier operator+(const Identifier& rhs) const;
249
308
QualifiedIdentifier& operator+=(const Identifier& rhs);
251
//Returns a QualifiedIdentifier with this one appended to the other. It is explicitly global if either this or base is.
310
QualifiedIdentifier operator+(const IndexedIdentifier& rhs) const;
311
QualifiedIdentifier& operator+=(const IndexedIdentifier& rhs);
314
* @return a QualifiedIdentifier with this one appended to the other.
316
* It is explicitly global if either this or base is.
252
318
QualifiedIdentifier merge(const QualifiedIdentifier& base) const;
255
* Computes the hash-value that would be created with a qualified identifier with hash-value @param leftHash of size @param leftSize
256
* with @param appendIdentifier appended as an identifier
258
// static uint combineHash(uint leftHash, uint leftSize, Identifier appendIdentifier);
260
/**The comparison-operators do not respect explicitlyGlobal and isExpression, they only respect the real scope.
321
* The comparison-operators do not respect explicitlyGlobal and isExpression, they only respect the real scope.
261
322
* This is for convenient use in hash-tables etc.
263
324
bool operator==(const QualifiedIdentifier& rhs) const;
264
325
bool operator!=(const QualifiedIdentifier& rhs) const;
265
QualifiedIdentifier& operator=(const QualifiedIdentifier& rhs);
267
327
bool beginsWith(const QualifiedIdentifier& other) const;
269
329
uint index() const;
272
* Returns true if this qualified identifier is already in the persistent identifier repository
332
* @return true if this qualified identifier is already in the persistent identifier repository
274
334
bool inRepository() const;
276
typedef uint HashType;
278
///The hash does not respect explicitlyGlobal, only the real scope.
279
HashType hash() const;
281
///Finds all identifiers in the identifier-repository that have the given hash value
282
static void findByHash(HashType hash, KDevVarLengthArray<QualifiedIdentifier>& target);
337
* The hash does not respect explicitlyGlobal, only the real scope.
342
* Finds all identifiers in the identifier-repository that have the given hash value
344
static void findByHash(uint hash, KDevVarLengthArray<QualifiedIdentifier>& target);
285
347
bool sameIdentifiers(const QualifiedIdentifier& rhs) const;
321
384
void setIsVolatile(bool);
323
386
IndexedQualifiedIdentifier identifier() const ;
325
void setIdentifier(IndexedQualifiedIdentifier id);
327
///Returns the pointer depth. Example for C++: "char*" has pointer-depth 1, "char***" has pointer-depth 3
388
void setIdentifier(const IndexedQualifiedIdentifier& id);
391
* @return the pointer depth. Example for C++: "char*" has pointer-depth 1, "char***" has pointer-depth 3
328
393
int pointerDepth() const;
329
/**Sets the pointer-depth to the specified count
395
* Sets the pointer-depth to the specified count.
330
397
* When the pointer-depth is increased, the "isConstPointer" values for new depths will be initialized with false.
331
* For efficiency-reasons the maximum currently is 23. */
399
* For efficiency-reasons the maximum currently is 23.
332
401
void setPointerDepth(int);
334
///Whether the target of pointer 'depthNumber' is constant
404
* Whether the target of pointer 'depthNumber' is constant
335
406
bool isConstPointer(int depthNumber) const;
336
407
void setIsConstPointer(int depthNumber, bool constant);
338
409
QString toString(bool ignoreExplicitlyGlobal = false) const;
340
411
uint hash() const;
342
/**The comparison-operators do not respect explicitlyGlobal and isExpression, they only respect the real scope.
414
* The comparison-operators do not respect explicitlyGlobal and isExpression, they only respect the real scope.
343
415
* This is for convenient use in hash-tables etc.
345
417
bool operator==(const IndexedTypeIdentifier& rhs) const;
346
418
bool operator!=(const IndexedTypeIdentifier& rhs) const;
348
IndexedQualifiedIdentifier m_identifier;
349
// The overall number of bits shared by these bit-fields should not exceed 32,
350
// so that we don't waste space. IndexedTypeIdentifer should be as compact as possible.
351
bool m_isConstant : 1;
352
bool m_isReference : 1;
354
bool m_isVolatile : 1;
355
uint m_pointerDepth : 5;
356
uint m_pointerConstMask : 23;
421
IndexedQualifiedIdentifier m_identifier;
422
// The overall number of bits shared by these bit-fields should not exceed 32,
423
// so that we don't waste space. IndexedTypeIdentifer should be as compact as possible.
424
bool m_isConstant : 1;
425
bool m_isReference : 1;
427
bool m_isVolatile : 1;
428
uint m_pointerDepth : 5;
429
uint m_pointerConstMask : 23;
359
432
KDEVPLATFORMLANGUAGE_EXPORT uint qHash(const IndexedTypeIdentifier& id);
360
433
KDEVPLATFORMLANGUAGE_EXPORT uint qHash(const QualifiedIdentifier& id);
361
434
KDEVPLATFORMLANGUAGE_EXPORT uint qHash(const Identifier& id);
436
inline uint qHash(const IndexedIdentifier& id)
438
return id.getIndex();
441
inline uint qHash(const IndexedQualifiedIdentifier& id)
443
return id.getIndex();
365
448
Q_DECLARE_TYPEINFO(KDevelop::IndexedQualifiedIdentifier, Q_MOVABLE_TYPE);