aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/typesystem.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-02-28 10:30:27 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-02-28 14:01:37 +0000
commit44cb6c51e6c3b43376f284941454dc8c13b81c3f (patch)
tree7e9fda1ba3788a3b9ed051e853b08926d325df6f /sources/shiboken2/ApiExtractor/typesystem.cpp
parent7c83f2ebc1ac55c6e2556c8c852716502dcdba5a (diff)
Type system: Add attribute indicating C++ 11 enum classes
Introduce enumeration for the type to EnumTypeEntry which can be specified by the boolean "class" attribute. For the enum classes, the value names need to be qualified by the enum name to match the C++ API. For the C++ generator, add an overload to Shiboken::createScopedEnumItem() that takes a PyTypeObject and add the enum items to the enum so that the name is in the enum scope. Change-Id: Ia0e469d13b08c196b9ddd965b9cf3cc62a38630b Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/typesystem.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp
index 749ce2f71..69dccbb86 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystem.cpp
@@ -58,6 +58,7 @@ static inline QString enumNameAttribute() { return QStringLiteral("enum-name");
static inline QString argumentTypeAttribute() { return QStringLiteral("argument-type"); }
static inline QString returnTypeAttribute() { return QStringLiteral("return-type"); }
static inline QString xPathAttribute() { return QStringLiteral("xpath"); }
+static inline QString enumIdentifiedByValueAttribute() { return QStringLiteral("identified-by-value"); }
static inline QString noAttributeValue() { return QStringLiteral("no"); }
static inline QString yesAttributeValue() { return QStringLiteral("yes"); }
@@ -758,7 +759,8 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
attributes.insert(QLatin1String("lower-bound"), QString());
attributes.insert(QLatin1String("force-integer"), noAttributeValue());
attributes.insert(QLatin1String("extensible"), noAttributeValue());
- attributes.insert(QLatin1String("identified-by-value"), QString());
+ attributes.insert(enumIdentifiedByValueAttribute(), QString());
+ attributes.insert(classAttribute(), falseAttributeValue());
break;
case StackElement::ValueTypeEntry:
attributes.insert(QLatin1String("default-constructor"), QString());
@@ -852,9 +854,10 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
}
if (element->type == StackElement::EnumTypeEntry) {
+ const QString identifiedByValue = attributes.value(enumIdentifiedByValueAttribute());
if (name.isEmpty()) {
- name = attributes[QLatin1String("identified-by-value")];
- } else if (!attributes[QLatin1String("identified-by-value")].isEmpty()) {
+ name = identifiedByValue;
+ } else if (!identifiedByValue.isEmpty()) {
m_error = QLatin1String("can't specify both 'name' and 'identified-by-value' attributes");
return false;
}
@@ -939,7 +942,11 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts
m_currentEnum =
new EnumTypeEntry(QStringList(names.mid(0, names.size() - 1)).join(colonColon()),
names.constLast(), since);
- m_currentEnum->setAnonymous(!attributes[QLatin1String("identified-by-value")].isEmpty());
+ if (!attributes.value(enumIdentifiedByValueAttribute()).isEmpty()) {
+ m_currentEnum->setEnumKind(EnumTypeEntry::AnonymousEnum);
+ } else if (convertBoolean(attributes.value(classAttribute()), classAttribute(), false)) {
+ m_currentEnum->setEnumKind(EnumTypeEntry::EnumClass);
+ }
element->entry = m_currentEnum;
m_currentEnum->setCodeGeneration(m_generate);
m_currentEnum->setTargetLangPackage(m_defaultPackage);