diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-09-11 09:45:24 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-09-12 04:49:50 +0000 |
commit | 9f7532987dfcebb195fc46a9349975e00ab4ea62 (patch) | |
tree | 38bdcf08eb9ece938b7017d704ecc85839536381 /sources/shiboken2/ApiExtractor | |
parent | 253553022f1ea1692795a28efe3a62b39b4f6bb9 (diff) |
shiboken: Store null enum values
If an enum has a null value, store that on the EnumTypeEntry for
use in Generator::minimalConstructor() as a default value.
Fully qualify scoped enum value type entries for this purpose.
The value can then be used for default values instead of an ugly
static_cast<EnumType>(0).
Task-number: PYSIDE-62
Change-Id: I42cb2ca63fb1da6c795df630ab30bded66aac901
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor')
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp | 14 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/parser/enumvalue.h | 1 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/typesystem.h | 6 |
3 files changed, 19 insertions, 2 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index 251d674a9..c8ff41d91 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -960,6 +960,15 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & metaEnum->setOriginalAttributes(metaEnum->attributes()); // Register all enum values on Type database + QString prefix; + if (enclosing) { + prefix += enclosing->typeEntry()->qualifiedCppName(); + prefix += colonColon(); + } + if (enumItem->enumKind() == EnumClass) { + prefix += enumItem->name(); + prefix += colonColon(); + } const EnumeratorList &enumerators = enumItem->enumerators(); for (const EnumeratorModelItem &e : enumerators) { QString name; @@ -967,11 +976,12 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & name += enclosing->name(); name += colonColon(); } - name += e->name(); EnumValueTypeEntry *enumValue = - new EnumValueTypeEntry(name, e->stringValue(), + new EnumValueTypeEntry(prefix + e->name(), e->stringValue(), enumTypeEntry, enumTypeEntry->version()); TypeDatabase::instance()->addType(enumValue); + if (e->value().isNullValue()) + enumTypeEntry->setNullValue(enumValue); } return metaEnum; diff --git a/sources/shiboken2/ApiExtractor/parser/enumvalue.h b/sources/shiboken2/ApiExtractor/parser/enumvalue.h index 4905e89ba..ea30c39bb 100644 --- a/sources/shiboken2/ApiExtractor/parser/enumvalue.h +++ b/sources/shiboken2/ApiExtractor/parser/enumvalue.h @@ -49,6 +49,7 @@ public: Type type() { return m_type; } qint64 value() const { return m_value; } quint64 unsignedValue() const { return m_unsignedValue; } + bool isNullValue() const { return m_type == Signed ? m_value == 0 : m_unsignedValue == 0u; } void setValue(qint64 v); void setUnsignedValue(quint64 v); diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h index 26f94e3ee..d892cb3a5 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.h +++ b/sources/shiboken2/ApiExtractor/typesystem.h @@ -1067,6 +1067,8 @@ private: PrimitiveTypeEntry* m_referencedTypeEntry = nullptr; }; +class EnumValueTypeEntry; + class EnumTypeEntry : public TypeEntry { public: @@ -1088,6 +1090,9 @@ public: m_qualifier = q; } + const EnumValueTypeEntry *nullValue() const { return m_nullValue; } + void setNullValue(const EnumValueTypeEntry *n) { m_nullValue = n; } + void setFlags(FlagsTypeEntry *flags) { m_flags = flags; @@ -1121,6 +1126,7 @@ private: QString m_packageName; QString m_qualifier; QString m_targetLangName; + const EnumValueTypeEntry *m_nullValue = nullptr; QStringList m_rejectedEnums; |