moc: add support for C++11 enum struct
C++11 added the new enum class key as well as enum struct. While the former is likely the most known and used, the later can be used in the same contexts and with the same effects. Currently moc doesn't parse enum struct while it does for enum class. This patch fixes this. [ChangeLog][moc] moc now parses enum struct the same way as enum class therefore that keyword can be used with the Q_ENUM macro as well as Q_FLAG and Q_DECLARE_FLAGS. Change-Id: Iaac3814ad63a15ee4d91b281d451e786b510449c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
41c1866d3e
commit
a5eabac96d
@ -260,7 +260,7 @@ bool Moc::parseEnum(EnumDef *def)
|
||||
{
|
||||
bool isTypdefEnum = false; // typedef enum { ... } Foo;
|
||||
|
||||
if (test(CLASS))
|
||||
if (test(CLASS) || test(STRUCT))
|
||||
def->isEnumClass = true;
|
||||
|
||||
if (test(IDENTIFIER)) {
|
||||
|
@ -40,13 +40,22 @@ public:
|
||||
enum class TypedEnumClass : char { C0, C1, C2, C3 };
|
||||
enum NormalEnum { D2 = 2, D3, D0 =0 , D1 };
|
||||
enum class ClassFlag { F0 = 1, F1 = 2, F2 = 4, F3 = 8};
|
||||
|
||||
enum struct EnumStruct { G0, G1, G2, G3 };
|
||||
enum struct TypedEnumStruct : char { H0, H1, H2, H3 };
|
||||
enum struct StructFlag { I0 = 1, I1 = 2, I2 = 4, I3 = 8};
|
||||
|
||||
Q_DECLARE_FLAGS(ClassFlags, ClassFlag)
|
||||
Q_DECLARE_FLAGS(StructFlags, StructFlag)
|
||||
|
||||
Q_ENUM(EnumClass)
|
||||
Q_ENUM(TypedEnum)
|
||||
Q_ENUM(TypedEnumClass)
|
||||
Q_ENUM(NormalEnum)
|
||||
Q_ENUM(EnumStruct)
|
||||
Q_ENUM(TypedEnumStruct)
|
||||
Q_FLAG(ClassFlags)
|
||||
Q_FLAG(StructFlags)
|
||||
};
|
||||
|
||||
// Also test the Q_ENUMS macro
|
||||
|
@ -2266,6 +2266,9 @@ void tst_Moc::cxx11Enums_data()
|
||||
QTest::newRow("NormalEnum 2") << meta2 << QByteArray("NormalEnum") << QByteArray("NormalEnum") << 'D' << false;
|
||||
QTest::newRow("ClassFlags") << meta1 << QByteArray("ClassFlags") << QByteArray("ClassFlag") << 'F' << true;
|
||||
QTest::newRow("ClassFlags 2") << meta2 << QByteArray("ClassFlags") << QByteArray("ClassFlag") << 'F' << true;
|
||||
QTest::newRow("EnumStruct") << meta1 << QByteArray("EnumStruct") << QByteArray("EnumStruct") << 'G' << true;
|
||||
QTest::newRow("TypedEnumStruct") << meta1 << QByteArray("TypedEnumStruct") << QByteArray("TypedEnumStruct") << 'H' << true;
|
||||
QTest::newRow("StructFlags") << meta1 << QByteArray("StructFlags") << QByteArray("StructFlag") << 'I' << true;
|
||||
}
|
||||
|
||||
void tst_Moc::cxx11Enums()
|
||||
|
Loading…
x
Reference in New Issue
Block a user