Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qhashfunctions.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
3// Copyright (C) 2024 Intel Corporation.
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5// Qt-Security score:significant reason:default
6
7#ifndef QHASHFUNCTIONS_H
8#define QHASHFUNCTIONS_H
9
10#include <QtCore/qstring.h>
11#include <QtCore/qstringfwd.h>
12#ifndef QT_BOOTSTRAPPED
13#include <QtCore/qbitarray.h>
14#endif
15
16#include <numeric> // for std::accumulate
17#include <functional> // for std::hash
18#include <optional>
19
20#if 0
21#pragma qt_class(QHashFunctions)
22#endif
23
24#if defined(Q_CC_MSVC)
25#pragma warning( push )
26#pragma warning( disable : 4311 ) // disable pointer truncation warning
27#pragma warning( disable : 4127 ) // conditional expression is constant
28#endif
29
30QT_BEGIN_NAMESPACE
31
32#if QT_DEPRECATED_SINCE(6,6)
33QT_DEPRECATED_VERSION_X_6_6("Use QHashSeed instead")
34Q_CORE_EXPORT int qGlobalQHashSeed();
35QT_DEPRECATED_VERSION_X_6_6("Use QHashSeed instead")
36Q_CORE_EXPORT void qSetGlobalQHashSeed(int newSeed);
37#endif
38
39struct QHashSeed
40{
41 constexpr QHashSeed(size_t d = 0) : data(d) {}
42 constexpr operator size_t() const noexcept { return data; }
43
44 static Q_CORE_EXPORT QHashSeed globalSeed() noexcept;
45 static Q_CORE_EXPORT void setDeterministicGlobalSeed();
46 static Q_CORE_EXPORT void resetRandomGlobalSeed();
47private:
48 size_t data;
49};
50
51// Whether, ∀ t of type T && ∀ seed, qHash(Key(t), seed) == qHash(t, seed)
52template <typename Key, typename T> struct QHashHeterogeneousSearch : std::false_type {};
53
54// Specializations
55template <> struct QHashHeterogeneousSearch<QString, QStringView> : std::true_type {};
56template <> struct QHashHeterogeneousSearch<QStringView, QString> : std::true_type {};
57template <> struct QHashHeterogeneousSearch<QByteArray, QByteArrayView> : std::true_type {};
58template <> struct QHashHeterogeneousSearch<QByteArrayView, QByteArray> : std::true_type {};
59#ifndef Q_PROCESSOR_ARM
60template <> struct QHashHeterogeneousSearch<QString, QLatin1StringView> : std::true_type {};
61template <> struct QHashHeterogeneousSearch<QStringView, QLatin1StringView> : std::true_type {};
62template <> struct QHashHeterogeneousSearch<QLatin1StringView, QString> : std::true_type {};
63template <> struct QHashHeterogeneousSearch<QLatin1StringView, QStringView> : std::true_type {};
64#endif
65
66namespace QHashPrivate {
67
68Q_DECL_CONST_FUNCTION constexpr size_t hash(size_t key, size_t seed) noexcept
69{
70 key ^= seed;
71 if constexpr (sizeof(size_t) == 4) {
72 key ^= key >> 16;
73 key *= UINT32_C(0x45d9f3b);
74 key ^= key >> 16;
75 key *= UINT32_C(0x45d9f3b);
76 key ^= key >> 16;
77 return key;
78 } else {
80 key64 ^= key64 >> 32;
81 key64 *= UINT64_C(0xd6e8feb86659fd93);
82 key64 ^= key64 >> 32;
83 key64 *= UINT64_C(0xd6e8feb86659fd93);
84 key64 ^= key64 >> 32;
85 return size_t(key64);
86 }
87}
88
89template <typename T1, typename T2> inline constexpr bool noexceptPairHash();
90}
91
92Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHashBits(const void *p, size_t size, size_t seed = 0) noexcept;
93
94// implementation below qHashMulti
95template <typename T1, typename T2> inline size_t qHash(const std::pair<T1, T2> &key, size_t seed = 0)
96 noexcept(QHashPrivate::noexceptPairHash<T1, T2>());
97
98constexpr size_t qHash(std::nullopt_t, size_t seed = 0) noexcept;
99template <typename T> constexpr size_t qHash(const std::optional<T> &key, size_t seed = 0)
100 noexcept(QHashPrivate::noexceptPairHash<T, T>());
101
102// C++ builtin types
103#define QT_MK_QHASH_COMPAT(X)
104 template <typename T, std::enable_if_t<std::is_same_v<T, X>, bool> = true>
105 constexpr size_t qHash(T key, size_t seed = 0) noexcept
106 /* QHashPrivate::hash() xors before mixing, while 1-to-2-arg adapter xors after */
107 { return QHashPrivate::hash(size_t(key), 0 QT7_ONLY(+ seed)) QT6_ONLY(^ seed); }
108 /* end */
109QT_MK_QHASH_COMPAT(bool) // QTBUG-126674
110Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(char key, size_t seed = 0) noexcept
111{ return QHashPrivate::hash(size_t(key), seed); }
112Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(uchar key, size_t seed = 0) noexcept
113{ return QHashPrivate::hash(size_t(key), seed); }
114Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(signed char key, size_t seed = 0) noexcept
115{ return QHashPrivate::hash(size_t(key), seed); }
116Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(ushort key, size_t seed = 0) noexcept
117{ return QHashPrivate::hash(size_t(key), seed); }
118Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(short key, size_t seed = 0) noexcept
119{ return QHashPrivate::hash(size_t(key), seed); }
120Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(uint key, size_t seed = 0) noexcept
121{ return QHashPrivate::hash(size_t(key), seed); }
122Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(int key, size_t seed = 0) noexcept
123{ return QHashPrivate::hash(size_t(key), seed); }
124Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(ulong key, size_t seed = 0) noexcept
125{ return QHashPrivate::hash(size_t(key), seed); }
126Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(long key, size_t seed = 0) noexcept
127{ return QHashPrivate::hash(size_t(key), seed); }
128#undef QT_MK_QHASH_COMPAT
129Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(quint64 key, size_t seed = 0) noexcept
130{
131 if constexpr (sizeof(quint64) > sizeof(size_t))
132 key ^= (key >> 32);
133 return QHashPrivate::hash(size_t(key), seed);
134}
135Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(qint64 key, size_t seed = 0) noexcept
136{
137 if constexpr (sizeof(qint64) > sizeof(size_t)) {
138 // Avoid QTBUG-116080: we XOR the top half with its own sign bit:
139 // - if the qint64 is in range of qint32, then signmask ^ high == 0
140 // (for Qt 7 only)
141 // - if the qint64 is in range of quint32, then signmask == 0 and we
142 // do the same as the quint64 overload above
143 quint32 high = quint32(quint64(key) >> 32);
144 quint32 low = quint32(quint64(key));
145 quint32 signmask = qint32(high) >> 31; // all zeroes or all ones
146 signmask = QT_VERSION_MAJOR > 6 ? signmask : 0;
147 low ^= signmask ^ high;
148 return qHash(low, seed);
149 }
150 return qHash(quint64(key), seed);
151}
152#ifdef QT_SUPPORTS_INT128
153constexpr size_t qHash(quint128 key, size_t seed = 0) noexcept
154{
155 return qHash(quint64(key + (key >> 64)), seed);
156}
157constexpr size_t qHash(qint128 key, size_t seed = 0) noexcept
158{
159 // Avoid QTBUG-116080: same as above, but with double the sizes and without
160 // the need for compatibility
161 quint64 high = quint64(quint128(key) >> 64);
162 quint64 low = quint64(quint128(key));
163 quint64 signmask = qint64(high) >> 63; // all zeroes or all ones
164 low += signmask ^ high;
165 return qHash(low, seed);
166}
167#endif // QT_SUPPORTS_INT128
168Q_DECL_CONST_FUNCTION inline size_t qHash(float key, size_t seed = 0) noexcept
169{
170 // ensure -0 gets mapped to 0
171 key += 0.0f;
172 uint k;
173 memcpy(&k, &key, sizeof(float));
174 return QHashPrivate::hash(k, seed);
175}
176Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(double key, size_t seed = 0) noexcept;
177Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(long double key, size_t seed = 0) noexcept;
178Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(wchar_t key, size_t seed = 0) noexcept
179{ return QHashPrivate::hash(size_t(key), seed); }
180Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(char16_t key, size_t seed = 0) noexcept
181{ return QHashPrivate::hash(size_t(key), seed); }
182Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(char32_t key, size_t seed = 0) noexcept
183{ return QHashPrivate::hash(size_t(key), seed); }
184#ifdef __cpp_char8_t
185Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(char8_t key, size_t seed = 0) noexcept
186{ return QHashPrivate::hash(size_t(key), seed); }
187#endif
188template <class T> inline size_t qHash(const T *key, size_t seed = 0) noexcept
189{
190 return qHash(reinterpret_cast<quintptr>(key), seed);
191}
192#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
193
194// this used to be matched by the 1-to-2-arg adapter, which mixed the seed in differently
195// in Qt 7, when the adapter is gone, this will use the const T* overload above instead
196template <class T> inline size_t qHash(T *key, size_t seed = 0) noexcept
197{
198 return qHash(reinterpret_cast<quintptr>(key)) ^ seed;
199}
200#endif // Qt 6
201Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(std::nullptr_t, size_t seed = 0) noexcept
202{
203 return seed;
204}
205template <class Enum, std::enable_if_t<std::is_enum_v<Enum>, bool> = true>
206Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(Enum e, size_t seed = 0) noexcept
207{ return QHashPrivate::hash(qToUnderlying(e), seed); }
208
209// (some) Qt types
210Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(const QChar key, size_t seed = 0) noexcept { return qHash(key.unicode(), seed); }
211
212#if QT_CORE_REMOVED_SINCE(6, 4)
213Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray &key, size_t seed = 0) noexcept;
214Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArrayView &key, size_t seed = 0) noexcept;
215#else
216Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QByteArrayView key, size_t seed = 0) noexcept;
217inline Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray &key, size_t seed = 0
218 QT6_DECL_NEW_OVERLOAD_TAIL) noexcept
219{ return qHash(qToByteArrayViewIgnoringNull(key), seed); }
220#endif
221
222Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QStringView key, size_t seed = 0) noexcept;
223inline Q_DECL_PURE_FUNCTION size_t qHash(const QString &key, size_t seed = 0) noexcept
224{ return qHash(QStringView{key}, seed); }
225#ifndef QT_BOOTSTRAPPED
226Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QBitArray &key, size_t seed = 0) noexcept;
227#endif
228Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QLatin1StringView key, size_t seed = 0) noexcept;
229Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(QKeyCombination key, size_t seed = 0) noexcept
230{ return qHash(key.toCombined(), seed); }
231Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0) noexcept;
232
233template <typename Enum>
234Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(QFlags<Enum> flags, size_t seed = 0) noexcept
235{ return qHash(flags.toInt(), seed); }
236
237// ### Qt 7: remove this "catch-all" overload logic, and require users
238// to provide the two-argument version of qHash.
239#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
240// Beware of moving this code from here. It needs to see all the
241// declarations of qHash overloads for C++ fundamental types *before*
242// its own declaration.
243namespace QHashPrivate {
244template <typename T, typename = void>
245constexpr inline bool HasQHashSingleArgOverload = false;
246
247template <typename T>
248constexpr inline bool HasQHashSingleArgOverload<T, std::enable_if_t<
249 std::is_convertible_v<decltype(qHash(std::declval<const T &>())), size_t>
250>> = true;
251}
252
253// Add Args... to make this overload consistently a worse match than
254// original 2-arg qHash overloads (QTBUG-126659)
255template <typename T, typename...Args,
256 std::enable_if_t<QHashPrivate::HasQHashSingleArgOverload<T>
257 && sizeof...(Args) == 0 && !std::is_enum_v<T>, bool> = true>
258constexpr size_t qHash(const T &t, size_t seed, Args&&...) noexcept(noexcept(qHash(t)))
259#ifdef QT_NO_SINGLE_ARGUMENT_QHASH_OVERLOAD
260 = delete;
261#else
262{ return qHash(t) ^ seed; }
263#endif // QT_NO_SINGLE_ARGUMENT_QHASH_OVERLOAD
264#endif // < Qt 7
265
266namespace QHashPrivate {
267
268// helper for qHash() calls that used to go via the above 1-to-2-arg adapter
269template <typename T>
270constexpr size_t ex1to2arg(const T &key, size_t seed)
271{
272 return QT7_ONLY(qHash(key, seed)) QT6_ONLY(qHash(key, 0U) ^ seed);
273}
274
275namespace detail {
276// approximates std::equality_comparable_with
277template <typename T, typename U, typename = void>
278struct is_equality_comparable_with : std::false_type {};
279
280template <typename T, typename U>
281struct is_equality_comparable_with<T, U,
282 std::void_t<
283 decltype(bool(std::declval<T>() == std::declval<U>())),
284 decltype(bool(std::declval<U>() == std::declval<T>())),
285 decltype(bool(std::declval<T>() != std::declval<U>())),
286 decltype(bool(std::declval<U>() != std::declval<T>()))
287 >>
288 : std::true_type {};
289}
290
291template <typename Key, typename T> struct HeterogeneouslySearchableWithHelper
292 : std::conjunction<
293 // if Key and T are not the same (member already exists)
294 std::negation<std::is_same<Key, T>>,
295 // but are comparable amongst each other
296 detail::is_equality_comparable_with<Key, T>,
297 // and supports heteregenous hashing
298 QHashHeterogeneousSearch<Key, T>
299 > {};
300
301template <typename Key, typename T>
305>;
306
307template <typename Key, typename K>
310 bool>;
311
312}
313
314template<typename T>
315bool qHashEquals(const T &a, const T &b)
316{
317 return a == b;
318}
319
320template <typename T1, typename T2, QHashPrivate::if_heterogeneously_searchable_with<T1, T2> = true>
321bool qHashEquals(const T1 &a, const T2 &b)
322{
323 return a == b;
324}
325
326namespace QtPrivate {
327template <typename Mixer> struct QHashCombinerWithSeed : private Mixer
328{
329 using result_type = typename Mixer::result_type;
330 size_t seed;
331 constexpr QHashCombinerWithSeed(result_type s) noexcept : seed(s) {}
332
333 template <typename T>
334 constexpr result_type operator()(result_type result, const T &t) const
335 noexcept(noexcept(qHash(t, seed)))
336 {
337 return Mixer::operator()(result, qHash(t, seed));
338 }
339};
340
341#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED)
342// Earlier Qt 6.x versions of qHashMulti() failed to pass the seed as the seed
343// argument of qHash(), so this class exists for compatibility with user and
344// inline code that relies on the old behavior. For Qt 7, we'll replace with
345// the above version, except for the bootstrapped tools (which have no seed).
346template <typename Mixer> struct QHashCombiner : private Mixer
347{
348 using result_type = typename Mixer::result_type;
349
350 static constexpr size_t seed = 0;
351 constexpr QHashCombiner(result_type) noexcept {}
352 Q_DECL_DEPRECATED_X("pass the seed argument") constexpr QHashCombiner() noexcept {}
353
354 template <typename T>
355 constexpr result_type operator()(result_type result, const T &t) const
356 noexcept(noexcept(qHash(t, seed)))
357 {
358 return Mixer::operator()(result, qHash(t, seed));
359 }
360};
361#else
362template <typename Mixer> using QHashCombiner = QHashCombinerWithSeed<Mixer>;
363#endif
364
365struct QHashCombineMixer
366{
367 typedef size_t result_type;
368 constexpr result_type operator()(result_type result, result_type hash) const noexcept
369 {
370 // combiner taken from N3876 / boost::hash_combine
371 return result ^ (hash + 0x9e3779b9 + (result << 6) + (result >> 2));
372 }
373};
375using QHashCombineWithSeed = QHashCombinerWithSeed<QHashCombineMixer>;
376
377struct QHashCombineCommutativeMixer : std::plus<size_t>
378{
379 // QHashCombine is a good hash combiner, but is not commutative,
380 // ie. it depends on the order of the input elements. That is
381 // usually what we want: {0,1,3} should hash differently than
382 // {1,3,0}. Except when it isn't (e.g. for QSet and
383 // QHash). Therefore, provide a commutative combiner, too.
384 typedef size_t result_type;
385};
387using QHashCombineCommutativeWithSeed = QHashCombinerWithSeed<QHashCombineCommutativeMixer>;
388
389template <typename... T>
390using QHashMultiReturnType = decltype(
391 std::declval< std::enable_if_t<(sizeof...(T) > 0)> >(),
392 (qHash(std::declval<const T &>(), size_t(0)), ...),
393 size_t{}
394);
395
396template <typename T, typename Enable = void>
397struct QNothrowHashable : std::false_type {};
398
399template <typename T>
400struct QNothrowHashable<T, std::enable_if_t<noexcept(qHash(std::declval<const T &>(), size_t(0)))>>
401 : std::true_type {};
402
403template <typename T>
404constexpr inline bool QNothrowHashable_v = QNothrowHashable<T>::value;
405
406} // namespace QtPrivate
407
408template <typename... T>
409constexpr
410#ifdef Q_QDOC
411size_t
412#else
413QtPrivate::QHashMultiReturnType<T...>
414#endif
415qHashMulti(size_t seed, const T &... args)
416 noexcept(std::conjunction_v<QtPrivate::QNothrowHashable<T>...>)
417{
418 QtPrivate::QHashCombine hash(seed);
419 return ((seed = hash(seed, args)), ...), seed;
420}
421
422template <typename... T>
423constexpr
424#ifdef Q_QDOC
425size_t
426#else
427QtPrivate::QHashMultiReturnType<T...>
428#endif
429qHashMultiCommutative(size_t seed, const T &... args)
430 noexcept(std::conjunction_v<QtPrivate::QNothrowHashable<T>...>)
431{
432 QtPrivate::QHashCombineCommutative hash(seed);
433 return ((seed = hash(seed, args)), ...), seed;
434}
435
436template <typename InputIterator>
437inline size_t qHashRange(InputIterator first, InputIterator last, size_t seed = 0)
438 noexcept(noexcept(qHash(*first, 0))) // assume iterator operations don't throw
439{
440 return std::accumulate(first, last, seed, QtPrivate::QHashCombine(seed));
441}
442
443template <typename InputIterator>
444inline size_t qHashRangeCommutative(InputIterator first, InputIterator last, size_t seed = 0)
445 noexcept(noexcept(qHash(*first, 0))) // assume iterator operations don't throw
446{
447 return std::accumulate(first, last, seed, QtPrivate::QHashCombineCommutative(seed));
448}
449
450namespace QHashPrivate {
451template <typename T1, typename T2> inline constexpr bool noexceptPairHash()
452{
453 return QtPrivate::QNothrowHashable_v<T1> && QtPrivate::QNothrowHashable_v<T2>;
454}
455} // QHashPrivate
456
457constexpr size_t qHash(std::nullopt_t, size_t seed) noexcept
458{
459 // Hash nullopt to something that's unlikely to occur elsewehre, and cheap
460 // to move-immediate.
461 // Choice: smallest prime within RISC-V addi 12-bit signed range
462 // (not optimal for Thumb/RISC-V compressed, but ±32 is really too small):
463 constexpr int NoValueHash = -2039;
464 return qHash(NoValueHash, seed);
465}
466
467template <typename T> constexpr size_t qHash(const std::optional<T> &key, size_t seed)
468 noexcept(QHashPrivate::noexceptPairHash<T, T>())
469{
470 return key ? qHash(*key, seed) : qHash(std::nullopt, seed);
471}
472
473template <typename T1, typename T2> inline size_t qHash(const std::pair<T1, T2> &key, size_t seed)
474 noexcept(QHashPrivate::noexceptPairHash<T1, T2>())
475{
476 return qHashMulti(seed, key.first, key.second);
477}
478
479#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, Arguments)
480 QT_BEGIN_INCLUDE_NAMESPACE
481 namespace std {
482 template <>
483 struct hash< QT_PREPEND_NAMESPACE(Class) > {
484 using argument_type = QT_PREPEND_NAMESPACE(Class);
485 using result_type = size_t;
486 size_t operator()(Arguments s) const
487 noexcept(QT_PREPEND_NAMESPACE(
488 QtPrivate::QNothrowHashable_v)<argument_type>)
489 {
490 /* this seeds qHash with the result of */
491 /* std::hash applied to an int, to reap */
492 /* any protection against predictable hash */
493 /* values the std implementation may provide */
494 using QT_PREPEND_NAMESPACE(qHash);
495 return qHash(s, qHash(std::hash<int>{}(0)));
496 }
497 };
498 }
499 QT_END_INCLUDE_NAMESPACE
500 /*end*/
501
502#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(Class)
503 QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, const argument_type &)
504#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_VALUE(Class)
505 QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, argument_type)
506
512#ifndef QT_BOOTSTRAPPED
514#endif
515
517
518#if defined(Q_CC_MSVC)
519#pragma warning( pop )
520#endif
521
522#endif // QHASHFUNCTIONS_H
Definition moc.h:234
void parse()
Definition moc.cpp:775
bool requireCompleteTypes
Definition moc.h:246
ModuleUnitKind moduleUnitKind
Definition moc.h:258
void generate(FILE *out, FILE *jsonOutput)
Definition moc.cpp:1343
bool noInclude
Definition moc.h:244
QByteArray resolveIncludeNext(const QByteArray &filename, qsizetype startIndex, qsizetype *foundIndex=nullptr)
void setDebugIncludes(bool value)
void parseDefineArguments(Macro *m)
void skipUntilEndif()
Symbols preprocessed(const QByteArray &filename, QFile *device)
void substituteUntilNewline(Symbols &substituted)
QList< QByteArray > frameworks
QHash< QByteArray, IncludeResolution > nonlocalIncludePathResolutionCache
static bool preprocessOnly
QByteArray resolveInclude(const QByteArray &filename, const QByteArray &relativeTo, qsizetype *foundIndex=nullptr)
static Symbols macroExpandIdentifier(Preprocessor *that, SymbolStack &symbols, int lineNum, QByteArray *macroName)
static Symbols tokenize(const QByteArray &input, int lineNum=1, TokenizeMode mode=TokenizeCpp)
static void macroExpand(Symbols *into, Preprocessor *that, const Symbols &toExpand, qsizetype &index, int lineNum, bool one, const QSet< QByteArray > &excludeSymbols=QSet< QByteArray >())
@ PreparePreprocessorStatement
@ TokenizePreprocessorStatement
The QCommandLineOption class defines a possible command-line option. \inmodule QtCore.
The QCommandLineParser class provides a means for handling the command line options.
Definition qlist.h:82
\inmodule QtSql
QByteArray unquotedLexem()
Definition symbols.h:105
const Symbol & symbol() const
Definition symbols.h:102
Token token()
Definition symbols.h:103
bool dontReplaceSymbol(const QByteArray &name) const
Definition symbols.h:125
bool hasNext()
Definition symbols.h:89
QByteArray lexem() const
Definition symbols.h:104
Token next()
Definition symbols.h:94
const SafeSymbols & constTop() const
Definition symbols.h:88
bool test(Token)
Definition symbols.h:111
ModuleUnitKind
Definition moc.h:225
std::conditional_t< std::is_same_v< HashKey, q20::remove_cvref_t< KeyArgument > >, KeyArgument, HashKey > HeterogenousConstructProxy
Definition qhash.h:834
Combined button and popup list for selecting options.
QHash< MacroName, Macro > Macros
SubArray MacroName
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(Class)
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH(Class, Arguments)
#define QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_VALUE(Class)
#define QT_MK_QHASH_COMPAT(X)
#define qPrintable(string)
Definition qstring.h:1718
#define QStringLiteral(str)
Definition qstring.h:1865
static QByteArray combinePath(const QString &infile, const QString &outfile)
Definition main.cpp:40
static bool hasNext(const Symbols &symbols, int i)
Definition main.cpp:78
static const Symbol & next(const Symbols &symbols, int &i)
Definition main.cpp:81
int runMoc(int argc, char **argv)
Definition main.cpp:170
static auto openFileForWriting(const QString &name)
Definition main.cpp:62
void error(const char *msg="Invalid argument")
Definition main.cpp:56
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments, bool &hasOptionFiles)
Definition main.cpp:138
QByteArray composePreprocessorOutput(const Symbols &symbols)
Definition main.cpp:85
int main(int argc, char *argv[])
[ctor_close]
qsizetype foundIndex
Simple structure used by the Doc and DocParser classes.
Symbols symbols
bool isVariadic
bool isFunction
Symbols arguments
qsizetype index
Definition symbols.h:81
Symbols symbols
Definition symbols.h:78
QByteArray expandedMacro
Definition symbols.h:79
QByteArray array
Definition symbols.h:26
SubArray(const char *s)
Definition symbols.h:21
qsizetype len
Definition symbols.h:28
bool operator==(const SubArray &other) const
Definition symbols.h:29
qsizetype from
Definition symbols.h:27
SubArray()=default
SubArray(const QByteArray &a)
Definition symbols.h:20
SubArray(const QByteArray &a, qsizetype from, qsizetype len)
Definition symbols.h:22
qsizetype from
Definition symbols.h:70
QByteArrayView unquotedLexemView() const
Definition symbols.h:62
Symbol(int lineNum, Token token)
Definition symbols.h:48
operator SubArray() const
Definition symbols.h:64
QByteArrayView lexemView() const
Definition symbols.h:61
Token token
Definition symbols.h:58
void mergeStringLiteral(const Symbol &next)
bool operator==(const Symbol &o) const
Definition symbols.h:65
int lineNum
Definition symbols.h:57
Symbol()=default
Symbol(int lineNum, Token token, const QByteArray &lexem, qsizetype from, qsizetype len)
Definition symbols.h:53
QByteArray lexem() const
Definition symbols.h:59
QByteArray lex
Definition symbols.h:69
QByteArray unquotedLexem() const
Definition symbols.h:60
qsizetype len
Definition symbols.h:71
Symbol(int lineNum, Token token, const QByteArray &lexem)
Definition symbols.h:49
size_t qHash(const SubArray &key, size_t seed=0)
Definition symbols.h:39
Q_DECLARE_TYPEINFO(Symbol, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(SafeSymbols, Q_RELOCATABLE_TYPE)
QList< Symbol > Symbols
Definition symbols.h:75
#define FOR_ALL_TOKENS(F)
Definition token.h:11
Token PP_Token
Definition token.h:254