Say hello to Q_NAMESPACE

Q_NAMESPACE is useful to add Q_ENUM_NS/Q_ENUMS, Q_FLAG_NS/Q_FLAGS and
Q_CLASSINFO to a namespace.

[ChangeLog] Added Q_NAMESPACE which can be used to add Q_ENUM_NS/
Q_ENUMS, Q_FLAG_NS/Q_FLAGS and Q_CLASSINFO to a namespace

Task-number: QTBUG-54981
Change-Id: Ic61b972794063e77134681fb347d6c4acddcdb44
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
BogDan Vatra 2016-08-19 15:44:42 +03:00
parent a1c782062c
commit 691dc71a01
9 changed files with 487 additions and 223 deletions

View File

@ -68,6 +68,7 @@ Cpp.ignoretokens += \
Q_LOCATION_EXPORT \
Q_POSITIONING_EXPORT \
Q_MULTIMEDIA_EXPORT \
Q_NAMESPACE \
Q_NETWORK_EXPORT \
Q_NEVER_INLINE \
Q_NORETURN \

View File

@ -4248,7 +4248,7 @@ QDebug operator<<(QDebug dbg, const QObject *o)
This macro registers an enum type with the meta-object system.
It must be placed after the enum declaration in a class that has the Q_OBJECT or the
Q_GADGET macro.
Q_GADGET macro. For namespaces use \l Q_ENUM_NS instead.
For example:
@ -4275,7 +4275,7 @@ QDebug operator<<(QDebug dbg, const QObject *o)
This macro registers a single \l{QFlags}{flags type} with the
meta-object system. It is typically used in a class definition to declare
that values of a given enum can be used as flags and combined using the
bitwise OR operator.
bitwise OR operator. For namespaces use \l Q_FLAG_NS instead.
The macro must be placed after the enum declaration.
@ -4294,6 +4294,48 @@ QDebug operator<<(QDebug dbg, const QObject *o)
\sa {Qt's Property System}
*/
/*!
\macro Q_ENUM_NS(...)
\since 5.8
This macro registers an enum type with the meta-object system.
It must be placed after the enum declaration in a namespace that
has the Q_NAMESPACE macro. It is the same as \l Q_ENUM but in a
namespace.
Enumerations that are declared with Q_ENUM_NS have their QMetaEnum
registered in the enclosing QMetaObject. You can also use
QMetaEnum::fromType() to get the QMetaEnum.
Registered enumerations are automatically registered also to the Qt meta
type system, making them known to QMetaType without the need to use
Q_DECLARE_METATYPE(). This will enable useful features; for example, if
used in a QVariant, you can convert them to strings. Likewise, passing them
to QDebug will print out their names.
\sa {Qt's Property System}
*/
/*!
\macro Q_FLAG_NS(...)
\since 5.8
This macro registers a single \l{QFlags}{flags type} with the
meta-object system. It is used in a namespace that has the
Q_NAMESPACE macro, to declare that values of a given enum can be
used as flags and combined using the bitwise OR operator.
It is the same as \l Q_FLAG but in a namespace.
The macro must be placed after the enum declaration.
\note The Q_FLAG_NS macro takes care of registering individual flag
values with the meta-object system, so it is unnecessary to use
Q_ENUM_NS() in addition to this macro.
\sa {Qt's Property System}
*/
/*!
\macro Q_OBJECT
@ -4334,6 +4376,21 @@ QDebug operator<<(QDebug dbg, const QObject *o)
enums declared with Q_ENUMS.
*/
/*!
\macro Q_NAMESPACE
\since 5.8
The Q_NAMESPACE macro can be used to add QMetaObject capabilities
to a namespace.
Q_NAMESPACEs can have Q_CLASSINFO, Q_ENUM_NS, Q_FLAG_NS, but they
cannot have Q_ENUM, Q_FLAG, Q_PROPERTY, Q_INVOKABLE, signals nor slots.
Q_NAMESPACE makes an external variable, \c{staticMetaObject}, available.
\c{staticMetaObject} is of type QMetaObject and provides access to the
enums declared with Q_ENUM_NS/Q_FLAG_NS.
*/
/*!
\macro Q_SIGNALS
\relates QObject

View File

@ -124,6 +124,11 @@ class QString;
friend Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
#define Q_ENUM(x) Q_ENUMS(x) Q_ENUM_IMPL(x)
#define Q_FLAG(x) Q_FLAGS(x) Q_ENUM_IMPL(x)
#define Q_ENUM_NS_IMPL(ENUM) \
inline Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
#define Q_ENUM_NS(x) Q_ENUMS(x) Q_ENUM_NS_IMPL(x)
#define Q_FLAG_NS(x) Q_FLAGS(x) Q_ENUM_NS_IMPL(x)
#define Q_SCRIPTABLE QT_ANNOTATE_FUNCTION(qt_scriptable)
#define Q_INVOKABLE QT_ANNOTATE_FUNCTION(qt_invokable)
#define Q_SIGNAL QT_ANNOTATE_FUNCTION(qt_signal)
@ -227,6 +232,12 @@ private: \
QT_WARNING_POP \
QT_ANNOTATE_CLASS(qt_qgadget, "") \
/*end*/
#define Q_NAMESPACE \
extern const QMetaObject staticMetaObject; \
QT_ANNOTATE_CLASS(qt_qnamespace, "") \
/*end*/
#endif // QT_NO_META_MACROS
#else // Q_MOC_RUN

View File

@ -30,12 +30,12 @@
// DO NOT EDIT.
static const short keyword_trans[][128] = {
{0,0,0,0,0,0,0,0,0,546,543,0,0,0,0,0,
{0,0,0,0,0,0,0,0,0,561,558,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
546,252,544,547,8,38,239,545,25,26,236,234,30,235,27,237,
561,252,559,562,8,38,239,560,25,26,236,234,30,235,27,237,
22,22,22,22,22,22,22,22,22,22,34,41,23,39,24,43,
0,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,21,8,8,8,8,8,8,8,8,8,31,549,32,238,8,
8,21,8,8,8,8,8,8,8,8,8,31,564,32,238,8,
0,1,2,3,4,5,6,7,8,9,8,8,10,11,12,13,
14,8,15,16,17,18,19,20,8,8,8,36,245,37,248,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -116,7 +116,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,290,222,0,0,475,0,0,0,
0,0,0,0,0,0,0,0,290,222,0,0,490,0,0,0,
0,0,0,0,55,0,0,330,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -155,7 +155,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,499,0,0,0,0,0,0,0,0,0,0,357,
0,0,0,0,514,0,0,0,0,0,0,0,0,0,0,357,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -177,7 +177,7 @@ static const short keyword_trans[][128] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,42,0,0,0,28,0,
552,552,552,552,552,552,552,552,552,552,0,0,0,0,0,0,
567,567,567,567,567,567,567,567,567,567,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -336,7 +336,7 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,551,0,0,0,0,550,
0,0,0,0,0,0,0,0,0,0,566,0,0,0,0,565,
0,0,0,0,0,0,0,0,0,0,0,0,0,258,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@ -372,45 +372,29 @@ static const short keyword_trans[][128] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
542,0,0,510,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
@ -805,189 +821,204 @@ static const struct
{CHARACTER, 0, 84, 363, CHARACTER},
{Q_OBJECT_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 65, 365, CHARACTER},
{CHARACTER, 0, 68, 366, CHARACTER},
{CHARACTER, 0, 71, 367, CHARACTER},
{CHARACTER, 0, 69, 368, CHARACTER},
{CHARACTER, 0, 84, 369, CHARACTER},
{CHARACTER, 0, 77, 366, CHARACTER},
{CHARACTER, 0, 69, 367, CHARACTER},
{CHARACTER, 0, 83, 368, CHARACTER},
{CHARACTER, 0, 80, 369, CHARACTER},
{CHARACTER, 0, 65, 370, CHARACTER},
{CHARACTER, 0, 67, 371, CHARACTER},
{CHARACTER, 0, 69, 372, CHARACTER},
{Q_NAMESPACE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 65, 374, CHARACTER},
{CHARACTER, 0, 68, 375, CHARACTER},
{CHARACTER, 0, 71, 376, CHARACTER},
{CHARACTER, 0, 69, 377, CHARACTER},
{CHARACTER, 0, 84, 378, CHARACTER},
{Q_GADGET_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 44, 0, 0, CHARACTER},
{CHARACTER, 45, 0, 0, CHARACTER},
{CHARACTER, 0, 80, 373, CHARACTER},
{CHARACTER, 0, 69, 374, CHARACTER},
{CHARACTER, 0, 82, 375, CHARACTER},
{CHARACTER, 0, 84, 376, CHARACTER},
{CHARACTER, 0, 89, 377, CHARACTER},
{CHARACTER, 0, 80, 382, CHARACTER},
{CHARACTER, 0, 69, 383, CHARACTER},
{CHARACTER, 0, 82, 384, CHARACTER},
{CHARACTER, 0, 84, 385, CHARACTER},
{CHARACTER, 0, 89, 386, CHARACTER},
{Q_PROPERTY_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 85, 379, CHARACTER},
{CHARACTER, 0, 71, 380, CHARACTER},
{CHARACTER, 0, 73, 381, CHARACTER},
{CHARACTER, 0, 78, 382, CHARACTER},
{CHARACTER, 0, 95, 383, CHARACTER},
{CHARACTER, 0, 77, 384, CHARACTER},
{CHARACTER, 0, 69, 385, CHARACTER},
{CHARACTER, 0, 84, 386, CHARACTER},
{CHARACTER, 0, 65, 387, CHARACTER},
{CHARACTER, 0, 68, 388, CHARACTER},
{CHARACTER, 0, 65, 389, CHARACTER},
{CHARACTER, 0, 84, 390, CHARACTER},
{CHARACTER, 0, 65, 391, CHARACTER},
{CHARACTER, 0, 85, 388, CHARACTER},
{CHARACTER, 0, 71, 389, CHARACTER},
{CHARACTER, 0, 73, 390, CHARACTER},
{CHARACTER, 0, 78, 391, CHARACTER},
{CHARACTER, 0, 95, 392, CHARACTER},
{CHARACTER, 0, 77, 393, CHARACTER},
{CHARACTER, 0, 69, 394, CHARACTER},
{CHARACTER, 0, 84, 395, CHARACTER},
{CHARACTER, 0, 65, 396, CHARACTER},
{CHARACTER, 0, 68, 397, CHARACTER},
{CHARACTER, 0, 65, 398, CHARACTER},
{CHARACTER, 0, 84, 399, CHARACTER},
{CHARACTER, 0, 65, 400, CHARACTER},
{Q_PLUGIN_METADATA_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 393, CHARACTER},
{CHARACTER, 0, 85, 394, CHARACTER},
{CHARACTER, 0, 77, 395, CHARACTER},
{Q_ENUM_TOKEN, 0, 83, 396, CHARACTER},
{CHARACTER, 0, 78, 402, CHARACTER},
{CHARACTER, 0, 85, 403, CHARACTER},
{CHARACTER, 0, 77, 404, CHARACTER},
{Q_ENUM_TOKEN, 46, 0, 0, CHARACTER},
{Q_ENUMS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 76, 398, CHARACTER},
{CHARACTER, 0, 65, 399, CHARACTER},
{CHARACTER, 0, 71, 400, CHARACTER},
{Q_FLAG_TOKEN, 0, 83, 401, CHARACTER},
{CHARACTER, 0, 78, 407, CHARACTER},
{CHARACTER, 0, 83, 408, CHARACTER},
{Q_ENUM_NS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 76, 410, CHARACTER},
{CHARACTER, 0, 65, 411, CHARACTER},
{CHARACTER, 0, 71, 412, CHARACTER},
{Q_FLAG_TOKEN, 47, 0, 0, CHARACTER},
{Q_FLAGS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 403, CHARACTER},
{CHARACTER, 0, 67, 404, CHARACTER},
{CHARACTER, 0, 76, 405, CHARACTER},
{CHARACTER, 0, 65, 406, CHARACTER},
{CHARACTER, 0, 82, 407, CHARACTER},
{CHARACTER, 0, 69, 408, CHARACTER},
{CHARACTER, 0, 95, 409, CHARACTER},
{CHARACTER, 46, 0, 0, CHARACTER},
{CHARACTER, 0, 76, 411, CHARACTER},
{CHARACTER, 0, 65, 412, CHARACTER},
{CHARACTER, 0, 71, 413, CHARACTER},
{CHARACTER, 0, 83, 414, CHARACTER},
{Q_DECLARE_FLAGS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 416, CHARACTER},
{CHARACTER, 0, 84, 417, CHARACTER},
{CHARACTER, 0, 78, 415, CHARACTER},
{CHARACTER, 0, 83, 416, CHARACTER},
{Q_FLAG_NS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 418, CHARACTER},
{CHARACTER, 0, 82, 419, CHARACTER},
{CHARACTER, 0, 70, 420, CHARACTER},
{CHARACTER, 0, 67, 419, CHARACTER},
{CHARACTER, 0, 76, 420, CHARACTER},
{CHARACTER, 0, 65, 421, CHARACTER},
{CHARACTER, 0, 67, 422, CHARACTER},
{CHARACTER, 0, 82, 422, CHARACTER},
{CHARACTER, 0, 69, 423, CHARACTER},
{Q_DECLARE_INTERFACE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 425, CHARACTER},
{CHARACTER, 0, 84, 426, CHARACTER},
{CHARACTER, 0, 65, 427, CHARACTER},
{CHARACTER, 0, 84, 428, CHARACTER},
{CHARACTER, 0, 89, 429, CHARACTER},
{CHARACTER, 0, 80, 430, CHARACTER},
{CHARACTER, 0, 69, 431, CHARACTER},
{Q_DECLARE_METATYPE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 88, 433, CHARACTER},
{CHARACTER, 0, 84, 434, CHARACTER},
{CHARACTER, 0, 69, 435, CHARACTER},
{CHARACTER, 0, 78, 436, CHARACTER},
{CHARACTER, 0, 83, 437, CHARACTER},
{CHARACTER, 0, 73, 438, CHARACTER},
{CHARACTER, 0, 79, 439, CHARACTER},
{CHARACTER, 0, 78, 440, CHARACTER},
{CHARACTER, 0, 95, 441, CHARACTER},
{CHARACTER, 0, 73, 442, CHARACTER},
{CHARACTER, 0, 78, 443, CHARACTER},
{CHARACTER, 0, 84, 444, CHARACTER},
{CHARACTER, 0, 69, 445, CHARACTER},
{CHARACTER, 0, 82, 446, CHARACTER},
{CHARACTER, 0, 70, 447, CHARACTER},
{CHARACTER, 0, 65, 448, CHARACTER},
{CHARACTER, 0, 67, 449, CHARACTER},
{CHARACTER, 0, 69, 423, CHARACTER},
{CHARACTER, 47, 0, 0, CHARACTER},
{CHARACTER, 0, 84, 452, CHARACTER},
{CHARACTER, 0, 83, 401, CHARACTER},
{CHARACTER, 0, 76, 454, CHARACTER},
{CHARACTER, 0, 65, 455, CHARACTER},
{CHARACTER, 0, 83, 456, CHARACTER},
{CHARACTER, 0, 83, 457, CHARACTER},
{CHARACTER, 0, 73, 458, CHARACTER},
{CHARACTER, 0, 78, 459, CHARACTER},
{CHARACTER, 0, 70, 460, CHARACTER},
{CHARACTER, 0, 79, 461, CHARACTER},
{Q_CLASSINFO_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 463, CHARACTER},
{CHARACTER, 0, 95, 424, CHARACTER},
{CHARACTER, 48, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 465, CHARACTER},
{CHARACTER, 0, 82, 466, CHARACTER},
{CHARACTER, 0, 70, 467, CHARACTER},
{CHARACTER, 0, 65, 468, CHARACTER},
{CHARACTER, 0, 67, 469, CHARACTER},
{CHARACTER, 0, 69, 470, CHARACTER},
{CHARACTER, 0, 83, 471, CHARACTER},
{Q_INTERFACES_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 108, 473, CHARACTER},
{CHARACTER, 0, 115, 474, CHARACTER},
{SIGNALS, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 111, 476, CHARACTER},
{CHARACTER, 0, 116, 477, CHARACTER},
{CHARACTER, 0, 115, 478, CHARACTER},
{SLOTS, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 71, 480, CHARACTER},
{CHARACTER, 0, 78, 481, CHARACTER},
{CHARACTER, 0, 65, 482, CHARACTER},
{CHARACTER, 0, 76, 483, CHARACTER},
{Q_SIGNAL_TOKEN, 0, 83, 484, CHARACTER},
{Q_SIGNALS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 79, 486, CHARACTER},
{CHARACTER, 0, 84, 487, CHARACTER},
{Q_SLOT_TOKEN, 0, 83, 488, CHARACTER},
{Q_SLOTS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 86, 490, CHARACTER},
{CHARACTER, 0, 65, 491, CHARACTER},
{CHARACTER, 0, 84, 492, CHARACTER},
{CHARACTER, 0, 69, 493, CHARACTER},
{CHARACTER, 0, 95, 494, CHARACTER},
{CHARACTER, 0, 76, 426, CHARACTER},
{CHARACTER, 0, 65, 427, CHARACTER},
{CHARACTER, 0, 71, 428, CHARACTER},
{CHARACTER, 0, 83, 429, CHARACTER},
{Q_DECLARE_FLAGS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 431, CHARACTER},
{CHARACTER, 0, 84, 432, CHARACTER},
{CHARACTER, 0, 69, 433, CHARACTER},
{CHARACTER, 0, 82, 434, CHARACTER},
{CHARACTER, 0, 70, 435, CHARACTER},
{CHARACTER, 0, 65, 436, CHARACTER},
{CHARACTER, 0, 67, 437, CHARACTER},
{CHARACTER, 0, 69, 438, CHARACTER},
{Q_DECLARE_INTERFACE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 440, CHARACTER},
{CHARACTER, 0, 84, 441, CHARACTER},
{CHARACTER, 0, 65, 442, CHARACTER},
{CHARACTER, 0, 84, 443, CHARACTER},
{CHARACTER, 0, 89, 444, CHARACTER},
{CHARACTER, 0, 80, 445, CHARACTER},
{CHARACTER, 0, 69, 446, CHARACTER},
{Q_DECLARE_METATYPE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 88, 448, CHARACTER},
{CHARACTER, 0, 84, 449, CHARACTER},
{CHARACTER, 0, 69, 450, CHARACTER},
{CHARACTER, 0, 78, 451, CHARACTER},
{CHARACTER, 0, 83, 452, CHARACTER},
{CHARACTER, 0, 73, 453, CHARACTER},
{CHARACTER, 0, 79, 454, CHARACTER},
{CHARACTER, 0, 78, 455, CHARACTER},
{CHARACTER, 0, 95, 456, CHARACTER},
{CHARACTER, 0, 73, 457, CHARACTER},
{CHARACTER, 0, 78, 458, CHARACTER},
{CHARACTER, 0, 84, 459, CHARACTER},
{CHARACTER, 0, 69, 460, CHARACTER},
{CHARACTER, 0, 82, 461, CHARACTER},
{CHARACTER, 0, 70, 462, CHARACTER},
{CHARACTER, 0, 65, 463, CHARACTER},
{CHARACTER, 0, 67, 464, CHARACTER},
{CHARACTER, 0, 69, 438, CHARACTER},
{CHARACTER, 49, 0, 0, CHARACTER},
{CHARACTER, 0, 76, 496, CHARACTER},
{CHARACTER, 0, 79, 497, CHARACTER},
{CHARACTER, 0, 84, 498, CHARACTER},
{Q_PRIVATE_SLOT_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 95, 500, CHARACTER},
{CHARACTER, 0, 77, 501, CHARACTER},
{CHARACTER, 0, 79, 502, CHARACTER},
{CHARACTER, 0, 67, 503, CHARACTER},
{CHARACTER, 0, 95, 504, CHARACTER},
{CHARACTER, 0, 67, 505, CHARACTER},
{CHARACTER, 0, 79, 506, CHARACTER},
{CHARACTER, 0, 77, 507, CHARACTER},
{CHARACTER, 0, 80, 508, CHARACTER},
{CHARACTER, 0, 65, 509, CHARACTER},
{CHARACTER, 0, 84, 510, CHARACTER},
{Q_MOC_COMPAT_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 84, 467, CHARACTER},
{CHARACTER, 0, 83, 413, CHARACTER},
{CHARACTER, 0, 76, 469, CHARACTER},
{CHARACTER, 0, 65, 470, CHARACTER},
{CHARACTER, 0, 83, 471, CHARACTER},
{CHARACTER, 0, 83, 472, CHARACTER},
{CHARACTER, 0, 73, 473, CHARACTER},
{CHARACTER, 0, 78, 474, CHARACTER},
{CHARACTER, 0, 70, 475, CHARACTER},
{CHARACTER, 0, 79, 476, CHARACTER},
{Q_CLASSINFO_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 78, 478, CHARACTER},
{CHARACTER, 50, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 480, CHARACTER},
{CHARACTER, 0, 82, 481, CHARACTER},
{CHARACTER, 0, 70, 482, CHARACTER},
{CHARACTER, 0, 65, 483, CHARACTER},
{CHARACTER, 0, 67, 484, CHARACTER},
{CHARACTER, 0, 69, 485, CHARACTER},
{CHARACTER, 0, 83, 486, CHARACTER},
{Q_INTERFACES_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 108, 488, CHARACTER},
{CHARACTER, 0, 115, 489, CHARACTER},
{SIGNALS, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 111, 491, CHARACTER},
{CHARACTER, 0, 116, 492, CHARACTER},
{CHARACTER, 0, 115, 493, CHARACTER},
{SLOTS, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 71, 495, CHARACTER},
{CHARACTER, 0, 78, 496, CHARACTER},
{CHARACTER, 0, 65, 497, CHARACTER},
{CHARACTER, 0, 76, 498, CHARACTER},
{Q_SIGNAL_TOKEN, 0, 83, 499, CHARACTER},
{Q_SIGNALS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 79, 501, CHARACTER},
{CHARACTER, 0, 84, 502, CHARACTER},
{Q_SLOT_TOKEN, 0, 83, 503, CHARACTER},
{Q_SLOTS_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 86, 505, CHARACTER},
{CHARACTER, 0, 65, 506, CHARACTER},
{CHARACTER, 0, 84, 507, CHARACTER},
{CHARACTER, 0, 69, 508, CHARACTER},
{CHARACTER, 0, 95, 509, CHARACTER},
{CHARACTER, 51, 0, 0, CHARACTER},
{CHARACTER, 0, 76, 511, CHARACTER},
{CHARACTER, 0, 79, 512, CHARACTER},
{CHARACTER, 0, 75, 513, CHARACTER},
{CHARACTER, 0, 65, 514, CHARACTER},
{CHARACTER, 0, 66, 515, CHARACTER},
{CHARACTER, 0, 76, 516, CHARACTER},
{CHARACTER, 0, 69, 517, CHARACTER},
{CHARACTER, 0, 84, 513, CHARACTER},
{Q_PRIVATE_SLOT_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 95, 515, CHARACTER},
{CHARACTER, 0, 77, 516, CHARACTER},
{CHARACTER, 0, 79, 517, CHARACTER},
{CHARACTER, 0, 67, 518, CHARACTER},
{CHARACTER, 0, 95, 519, CHARACTER},
{CHARACTER, 0, 67, 520, CHARACTER},
{CHARACTER, 0, 79, 521, CHARACTER},
{CHARACTER, 0, 77, 522, CHARACTER},
{CHARACTER, 0, 80, 523, CHARACTER},
{CHARACTER, 0, 65, 524, CHARACTER},
{CHARACTER, 0, 84, 525, CHARACTER},
{Q_MOC_COMPAT_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 79, 527, CHARACTER},
{CHARACTER, 0, 75, 528, CHARACTER},
{CHARACTER, 0, 65, 529, CHARACTER},
{CHARACTER, 0, 66, 530, CHARACTER},
{CHARACTER, 0, 76, 531, CHARACTER},
{CHARACTER, 0, 69, 532, CHARACTER},
{Q_INVOKABLE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 82, 519, CHARACTER},
{CHARACTER, 0, 73, 520, CHARACTER},
{CHARACTER, 0, 80, 521, CHARACTER},
{CHARACTER, 0, 84, 522, CHARACTER},
{CHARACTER, 0, 65, 523, CHARACTER},
{CHARACTER, 0, 66, 524, CHARACTER},
{CHARACTER, 0, 76, 525, CHARACTER},
{CHARACTER, 0, 69, 526, CHARACTER},
{CHARACTER, 0, 82, 534, CHARACTER},
{CHARACTER, 0, 73, 535, CHARACTER},
{CHARACTER, 0, 80, 536, CHARACTER},
{CHARACTER, 0, 84, 537, CHARACTER},
{CHARACTER, 0, 65, 538, CHARACTER},
{CHARACTER, 0, 66, 539, CHARACTER},
{CHARACTER, 0, 76, 540, CHARACTER},
{CHARACTER, 0, 69, 541, CHARACTER},
{Q_SCRIPTABLE_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 82, 528, CHARACTER},
{CHARACTER, 0, 79, 529, CHARACTER},
{CHARACTER, 0, 80, 530, CHARACTER},
{CHARACTER, 0, 69, 531, CHARACTER},
{CHARACTER, 0, 82, 532, CHARACTER},
{CHARACTER, 0, 84, 533, CHARACTER},
{CHARACTER, 0, 89, 534, CHARACTER},
{CHARACTER, 0, 82, 543, CHARACTER},
{CHARACTER, 0, 79, 544, CHARACTER},
{CHARACTER, 0, 80, 545, CHARACTER},
{CHARACTER, 0, 69, 546, CHARACTER},
{CHARACTER, 0, 82, 547, CHARACTER},
{CHARACTER, 0, 84, 548, CHARACTER},
{CHARACTER, 0, 89, 549, CHARACTER},
{Q_PRIVATE_PROPERTY_TOKEN, 0, 0, 0, CHARACTER},
{CHARACTER, 0, 69, 536, CHARACTER},
{CHARACTER, 0, 86, 537, CHARACTER},
{CHARACTER, 0, 73, 538, CHARACTER},
{CHARACTER, 0, 83, 539, CHARACTER},
{CHARACTER, 0, 73, 540, CHARACTER},
{CHARACTER, 0, 79, 541, CHARACTER},
{CHARACTER, 0, 78, 542, CHARACTER},
{CHARACTER, 0, 69, 551, CHARACTER},
{CHARACTER, 0, 86, 552, CHARACTER},
{CHARACTER, 0, 73, 553, CHARACTER},
{CHARACTER, 0, 83, 554, CHARACTER},
{CHARACTER, 0, 73, 555, CHARACTER},
{CHARACTER, 0, 79, 556, CHARACTER},
{CHARACTER, 0, 78, 557, CHARACTER},
{Q_REVISION_TOKEN, 0, 0, 0, CHARACTER},
{NEWLINE, 0, 0, 0, NOTOKEN},
{QUOTE, 0, 0, 0, NOTOKEN},
{SINGLEQUOTE, 0, 0, 0, NOTOKEN},
{WHITESPACE, 0, 0, 0, NOTOKEN},
{HASH, 0, 35, 548, HASH},
{HASH, 0, 35, 563, HASH},
{PP_HASHHASH, 0, 0, 0, NOTOKEN},
{BACKSLASH, 0, 0, 0, NOTOKEN},
{CPP_COMMENT, 0, 0, 0, NOTOKEN},

View File

@ -554,14 +554,51 @@ void Moc::parse()
until(SEMIC);
} else if (!test(SEMIC)) {
NamespaceDef def;
def.name = lexem();
def.classname = lexem();
next(LBRACE);
def.begin = index - 1;
until(RBRACE);
def.end = index;
index = def.begin + 1;
while (inNamespace(&def) && hasNext()) {
switch (next()) {
case Q_NAMESPACE_TOKEN:
def.hasQNamespace = true;
break;
case Q_ENUMS_TOKEN:
case Q_ENUM_NS_TOKEN:
parseEnumOrFlag(&def, false);
break;
case Q_FLAGS_TOKEN:
case Q_FLAG_NS_TOKEN:
parseEnumOrFlag(&def, true);
break;
case Q_DECLARE_FLAGS_TOKEN:
parseFlag(&def);
break;
case Q_CLASSINFO_TOKEN:
parseClassInfo(&def);
break;
case ENUM: {
EnumDef enumDef;
if (parseEnum(&enumDef))
def.enumList += enumDef;
} break;
case CLASS:
case STRUCT: {
ClassDef classdef;
if (!parseClassHead(&classdef))
continue;
while (inClass(&classdef) && hasNext())
next(); // consume all Q_XXXX macros from this class
} break;
default: break;
}
}
namespaceList += def;
index = rewind;
if (!def.hasQNamespace && (!def.classInfoList.isEmpty() || !def.enumDeclarations.isEmpty()))
error("Namespace declaration lacks Q_NAMESPACE macro.");
}
}
break;
@ -618,7 +655,7 @@ void Moc::parse()
for (int i = namespaceList.size() - 1; i >= 0; --i)
if (inNamespace(&namespaceList.at(i)))
def.qualified.prepend(namespaceList.at(i).name + "::");
def.qualified.prepend(namespaceList.at(i).classname + "::");
QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
classHash.insert(def.classname, def.qualified);
@ -634,7 +671,7 @@ void Moc::parse()
FunctionDef::Access access = FunctionDef::Private;
for (int i = namespaceList.size() - 1; i >= 0; --i)
if (inNamespace(&namespaceList.at(i)))
def.qualified.prepend(namespaceList.at(i).name + "::");
def.qualified.prepend(namespaceList.at(i).classname + "::");
while (inClass(&def) && hasNext()) {
switch ((t = next())) {
case PRIVATE:
@ -802,6 +839,19 @@ void Moc::parse()
classHash.insert(def.qualified, def.qualified);
}
}
for (const auto &n : qAsConst(namespaceList)) {
if (!n.hasQNamespace)
continue;
ClassDef def;
static_cast<BaseDef &>(def) = static_cast<BaseDef>(n);
if (!def.qualified.isEmpty())
def.qualified += "::";
def.qualified += def.classname;
def.hasQGadget = true;
classList += def;
knownGadgets.insert(def.classname, def.qualified);
knownGadgets.insert(def.qualified, def.qualified);
}
}
static bool any_type_contains(const QVector<PropertyDef> &properties, const QByteArray &pattern)
@ -1248,7 +1298,7 @@ void Moc::parsePrivateProperty(ClassDef *def)
def->propertyList += propDef;
}
void Moc::parseEnumOrFlag(ClassDef *def, bool isFlag)
void Moc::parseEnumOrFlag(BaseDef *def, bool isFlag)
{
next(LPAREN);
QByteArray identifier;
@ -1263,7 +1313,7 @@ void Moc::parseEnumOrFlag(ClassDef *def, bool isFlag)
next(RPAREN);
}
void Moc::parseFlag(ClassDef *def)
void Moc::parseFlag(BaseDef *def)
{
next(LPAREN);
QByteArray flagName, enumName;
@ -1287,7 +1337,7 @@ void Moc::parseFlag(ClassDef *def)
next(RPAREN);
}
void Moc::parseClassInfo(ClassDef *def)
void Moc::parseClassInfo(BaseDef *def)
{
next(LPAREN);
ClassInfoDef infoDef;

View File

@ -144,12 +144,18 @@ struct ClassInfoDef
};
Q_DECLARE_TYPEINFO(ClassInfoDef, Q_MOVABLE_TYPE);
struct ClassDef {
ClassDef():
hasQObject(false), hasQGadget(false), notifyableProperties(0)
, revisionedMethods(0), revisionedProperties(0), begin(0), end(0){}
struct BaseDef {
QByteArray classname;
QByteArray qualified;
QVector<ClassInfoDef> classInfoList;
QMap<QByteArray, bool> enumDeclarations;
QVector<EnumDef> enumList;
QMap<QByteArray, QByteArray> flagAliases;
int begin = 0;
int end = 0;
};
struct ClassDef : BaseDef {
QVector<QPair<QByteArray, FunctionDef::Access> > superclassList;
struct Interface
@ -162,8 +168,8 @@ struct ClassDef {
};
QVector<QVector<Interface> >interfaceList;
bool hasQObject;
bool hasQGadget;
bool hasQObject = false;
bool hasQGadget = false;
struct PluginData {
QByteArray iid;
@ -173,25 +179,17 @@ struct ClassDef {
QVector<FunctionDef> constructorList;
QVector<FunctionDef> signalList, slotList, methodList, publicList;
int notifyableProperties;
int notifyableProperties = 0;
QVector<PropertyDef> propertyList;
QVector<ClassInfoDef> classInfoList;
QMap<QByteArray, bool> enumDeclarations;
QVector<EnumDef> enumList;
QMap<QByteArray, QByteArray> flagAliases;
int revisionedMethods;
int revisionedProperties;
int revisionedMethods = 0;
int revisionedProperties = 0;
int begin;
int end;
};
Q_DECLARE_TYPEINFO(ClassDef, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(ClassDef::Interface, Q_MOVABLE_TYPE);
struct NamespaceDef {
QByteArray name;
int begin;
int end;
struct NamespaceDef : BaseDef {
bool hasQNamespace = false;
};
Q_DECLARE_TYPEINFO(NamespaceDef, Q_MOVABLE_TYPE);
@ -240,9 +238,9 @@ public:
void parseProperty(ClassDef *def);
void parsePluginData(ClassDef *def);
void createPropertyDef(PropertyDef &def);
void parseEnumOrFlag(ClassDef *def, bool isFlag);
void parseFlag(ClassDef *def);
void parseClassInfo(ClassDef *def);
void parseEnumOrFlag(BaseDef *def, bool isFlag);
void parseFlag(BaseDef *def);
void parseClassInfo(BaseDef *def);
void parseInterfaces(ClassDef *def);
void parseDeclareInterface();
void parseDeclareMetatype();

View File

@ -154,12 +154,15 @@ QT_BEGIN_NAMESPACE
F(RETURN) \
F(Q_OBJECT_TOKEN) \
F(Q_GADGET_TOKEN) \
F(Q_NAMESPACE_TOKEN) \
F(Q_PROPERTY_TOKEN) \
F(Q_PLUGIN_METADATA_TOKEN) \
F(Q_ENUMS_TOKEN) \
F(Q_ENUM_TOKEN) \
F(Q_ENUM_NS_TOKEN) \
F(Q_FLAGS_TOKEN) \
F(Q_FLAG_TOKEN) \
F(Q_FLAG_NS_TOKEN) \
F(Q_DECLARE_FLAGS_TOKEN) \
F(Q_DECLARE_INTERFACE_TOKEN) \
F(Q_DECLARE_METATYPE_TOKEN) \

View File

@ -213,13 +213,16 @@ static const Keyword keywords[] = {
{ "goto", "GOTO" },
{ "return", "RETURN" },
{ "Q_OBJECT", "Q_OBJECT_TOKEN" },
{ "Q_NAMESPACE", "Q_NAMESPACE_TOKEN" },
{ "Q_GADGET", "Q_GADGET_TOKEN" },
{ "Q_PROPERTY", "Q_PROPERTY_TOKEN" },
{ "Q_PLUGIN_METADATA", "Q_PLUGIN_METADATA_TOKEN" },
{ "Q_ENUMS", "Q_ENUMS_TOKEN" },
{ "Q_ENUM", "Q_ENUM_TOKEN" },
{ "Q_ENUM_NS", "Q_ENUM_NS_TOKEN" },
{ "Q_FLAGS", "Q_FLAGS_TOKEN" },
{ "Q_FLAG", "Q_FLAG_TOKEN" },
{ "Q_FLAG_NS", "Q_FLAG_NS_TOKEN" },
{ "Q_DECLARE_FLAGS", "Q_DECLARE_FLAGS_TOKEN" },
{ "Q_DECLARE_INTERFACE", "Q_DECLARE_INTERFACE_TOKEN" },
{ "Q_DECLARE_METATYPE", "Q_DECLARE_METATYPE_TOKEN" },

View File

@ -78,6 +78,73 @@ const char *string_hash_hash = STRING_HASH_HASH("baz");
Q_DECLARE_METATYPE(const QMetaObject*);
namespace TestNonQNamespace {
struct TestGadget {
Q_GADGET
Q_CLASSINFO("key", "value")
public:
enum class TestGEnum1 {
Key1 = 11,
Key2
};
Q_ENUM(TestGEnum1)
enum class TestGEnum2 {
Key1 = 17,
Key2
};
Q_ENUM(TestGEnum2)
};
}
namespace TestQNamespace {
Q_NAMESPACE
enum class TestEnum1 {
Key1 = 11,
Key2
};
Q_ENUM_NS(TestEnum1)
enum class TestEnum2 {
Key1 = 17,
Key2
};
Q_ENUM_NS(TestEnum2)
// try to dizzy moc by adding a struct in between
struct TestGadget {
Q_GADGET
public:
enum class TestGEnum1 {
Key1 = 13,
Key2
};
enum class TestGEnum2 {
Key1 = 23,
Key2
};
Q_ENUM(TestGEnum1)
Q_ENUM(TestGEnum2)
};
enum class TestFlag1 {
None = 0,
Flag1 = 1,
Flag2 = 2,
Any = Flag1 | Flag2
};
Q_FLAG_NS(TestFlag1)
enum class TestFlag2 {
None = 0,
Flag1 = 4,
Flag2 = 8,
Any = Flag1 | Flag2
};
Q_FLAG_NS(TestFlag2)
}
QT_USE_NAMESPACE
@ -627,6 +694,7 @@ private slots:
void gadgetHierarchy();
void optionsFileError_data();
void optionsFileError();
void testQNamespace();
signals:
void sigWithUnsignedArg(unsigned foo);
@ -2007,6 +2075,13 @@ void tst_Moc::warnings_data()
<< QString()
<< QString("standard input:5: Error: Class declaration lacks Q_OBJECT macro.");
QTest::newRow("Namespace declaration lacks Q_NAMESPACE macro.")
<< QByteArray("namespace X {\nQ_CLASSINFO(\"key\",\"value\")\nenum class MyEnum {Key1 = 1}\nQ_ENUMS(MyEnum)\n}\n")
<< QStringList()
<< 1
<< QString()
<< QString("standard input:1: Error: Namespace declaration lacks Q_NAMESPACE macro.");
QTest::newRow("Invalid macro definition")
<< QByteArray("#define Foo(a, b, c) a b c #a #b #c a##b##c #d\n Foo(45, 42, 39);")
<< QStringList()
@ -3637,6 +3712,41 @@ void tst_Moc::optionsFileError()
#endif
}
static void checkEnum(const QMetaEnum &enumerator, const QByteArray &name, const QVector<QPair<QByteArray, int >> &keys)
{
QCOMPARE(name, QByteArray{enumerator.name()});
QCOMPARE(keys.size(), enumerator.keyCount());
for (int i = 0; i < enumerator.keyCount(); ++i) {
QCOMPARE(keys[i].first, QByteArray{enumerator.key(i)});
QCOMPARE(keys[i].second, enumerator.value(i));
}
}
void tst_Moc::testQNamespace()
{
QCOMPARE(TestQNamespace::staticMetaObject.enumeratorCount(), 4);
checkEnum(TestQNamespace::staticMetaObject.enumerator(0), "TestEnum1",
{{"Key1", 11}, {"Key2", 12}});
checkEnum(TestQNamespace::staticMetaObject.enumerator(1), "TestEnum2",
{{"Key1", 17}, {"Key2", 18}});
checkEnum(TestQNamespace::staticMetaObject.enumerator(2), "TestFlag1",
{{"None", 0}, {"Flag1", 1}, {"Flag2", 2}, {"Any", 1 | 2}});
checkEnum(TestQNamespace::staticMetaObject.enumerator(3), "TestFlag2",
{{"None", 0}, {"Flag1", 4}, {"Flag2", 8}, {"Any", 4 | 8}});
QCOMPARE(TestQNamespace::TestGadget::staticMetaObject.enumeratorCount(), 2);
checkEnum(TestQNamespace::TestGadget::staticMetaObject.enumerator(0), "TestGEnum1",
{{"Key1", 13}, {"Key2", 14}});
checkEnum(TestQNamespace::TestGadget::staticMetaObject.enumerator(1), "TestGEnum2",
{{"Key1", 23}, {"Key2", 24}});
QMetaEnum meta = QMetaEnum::fromType<TestQNamespace::TestEnum1>();
QVERIFY(meta.isValid());
QCOMPARE(meta.name(), "TestEnum1");
QCOMPARE(meta.enclosingMetaObject(), &TestQNamespace::staticMetaObject);
QCOMPARE(meta.keyCount(), 2);
}
QTEST_MAIN(tst_Moc)
// the generated code must compile with QT_NO_KEYWORDS