diff options
Diffstat (limited to 'sources/shiboken2/ApiExtractor/typesystem.cpp')
-rw-r--r-- | sources/shiboken2/ApiExtractor/typesystem.cpp | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index 4a8d3063d..69dccbb86 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -58,6 +58,12 @@ 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"); } +static inline QString trueAttributeValue() { return QStringLiteral("true"); } +static inline QString falseAttributeValue() { return QStringLiteral("false"); } static QVector<CustomConversion *> customConversionsForReview; @@ -534,21 +540,22 @@ bool Handler::importFileElement(const QXmlStreamAttributes &atts) return true; } -bool Handler::convertBoolean(const QString &_value, const QString &attributeName, bool defaultValue) +static bool convertBoolean(const QString &value, const QString &attributeName, bool defaultValue) { - QString value = _value.toLower(); - if (value == QLatin1String("true") || value == QLatin1String("yes")) + if (value.compare(trueAttributeValue(), Qt::CaseInsensitive) == 0 + || value.compare(yesAttributeValue(), Qt::CaseInsensitive) == 0) { return true; - else if (value == QLatin1String("false") || value == QLatin1String("no")) + } + if (value.compare(falseAttributeValue(), Qt::CaseInsensitive) == 0 + || value.compare(noAttributeValue(), Qt::CaseInsensitive) == 0) { return false; - else { - QString warn = QStringLiteral("Boolean value '%1' not supported in attribute '%2'. Use 'yes' or 'no'. Defaulting to '%3'.") + } + const QString warn = QStringLiteral("Boolean value '%1' not supported in attribute '%2'. Use 'yes' or 'no'. Defaulting to '%3'.") .arg(value, attributeName, - defaultValue ? QLatin1String("yes") : QLatin1String("no")); + defaultValue ? yesAttributeValue() : noAttributeValue()); - qCWarning(lcShiboken).noquote().nospace() << warn; - return defaultValue; - } + qCWarning(lcShiboken).noquote().nospace() << warn; + return defaultValue; } static bool convertRemovalAttribute(const QString& removalAttribute, Modification& mod, QString& errorMsg) @@ -733,8 +740,8 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts case StackElement::PrimitiveTypeEntry: attributes.insert(QLatin1String("target-lang-name"), QString()); attributes.insert(QLatin1String("target-lang-api-name"), QString()); - attributes.insert(QLatin1String("preferred-conversion"), QLatin1String("yes")); - attributes.insert(QLatin1String("preferred-target-lang-type"), QLatin1String("yes")); + attributes.insert(QLatin1String("preferred-conversion"), yesAttributeValue()); + attributes.insert(QLatin1String("preferred-target-lang-type"), yesAttributeValue()); attributes.insert(QLatin1String("default-constructor"), QString()); break; case StackElement::ContainerTypeEntry: @@ -750,23 +757,24 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts attributes.insert(QLatin1String("flags-revision"), QString()); attributes.insert(QLatin1String("upper-bound"), QString()); attributes.insert(QLatin1String("lower-bound"), QString()); - attributes.insert(QLatin1String("force-integer"), QLatin1String("no")); - attributes.insert(QLatin1String("extensible"), QLatin1String("no")); - attributes.insert(QLatin1String("identified-by-value"), QString()); + attributes.insert(QLatin1String("force-integer"), noAttributeValue()); + attributes.insert(QLatin1String("extensible"), noAttributeValue()); + attributes.insert(enumIdentifiedByValueAttribute(), QString()); + attributes.insert(classAttribute(), falseAttributeValue()); break; case StackElement::ValueTypeEntry: attributes.insert(QLatin1String("default-constructor"), QString()); Q_FALLTHROUGH(); case StackElement::ObjectTypeEntry: - attributes.insert(QLatin1String("force-abstract"), QLatin1String("no")); - attributes.insert(QLatin1String("deprecated"), QLatin1String("no")); + attributes.insert(QLatin1String("force-abstract"), noAttributeValue()); + attributes.insert(QLatin1String("deprecated"), noAttributeValue()); attributes.insert(QLatin1String("hash-function"), QString()); - attributes.insert(QLatin1String("stream"), QLatin1String("no")); + attributes.insert(QLatin1String("stream"), noAttributeValue()); Q_FALLTHROUGH(); case StackElement::InterfaceTypeEntry: attributes[QLatin1String("default-superclass")] = m_defaultSuperclass; attributes.insert(QLatin1String("polymorphic-id-expression"), QString()); - attributes.insert(QLatin1String("delete-in-main-thread"), QLatin1String("no")); + attributes.insert(QLatin1String("delete-in-main-thread"), noAttributeValue()); attributes.insert(QLatin1String("held-type"), QString()); attributes.insert(QLatin1String("copyable"), QString()); Q_FALLTHROUGH(); @@ -775,10 +783,10 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts attributes[QLatin1String("package")] = m_defaultPackage; attributes.insert(QLatin1String("expense-cost"), QLatin1String("1")); attributes.insert(QLatin1String("expense-limit"), QLatin1String("none")); - attributes.insert(QLatin1String("polymorphic-base"), QLatin1String("no")); - attributes.insert(QLatin1String("generate"), QLatin1String("yes")); + attributes.insert(QLatin1String("polymorphic-base"), noAttributeValue()); + attributes.insert(QLatin1String("generate"), yesAttributeValue()); attributes.insert(QLatin1String("target-type"), QString()); - attributes.insert(QLatin1String("generic-class"), QLatin1String("no")); + attributes.insert(QLatin1String("generic-class"), noAttributeValue()); break; case StackElement::FunctionTypeEntry: attributes.insert(QLatin1String("signature"), QString()); @@ -846,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; } @@ -933,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); @@ -988,7 +1001,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts if (!element->entry) element->entry = new ObjectTypeEntry(name, since); - element->entry->setStream(attributes[QLatin1String("stream")] == QLatin1String("yes")); + element->entry->setStream(attributes[QLatin1String("stream")] == yesAttributeValue()); ComplexTypeEntry *ctype = static_cast<ComplexTypeEntry *>(element->entry); ctype->setTargetLangPackage(attributes[QLatin1String("package")]); @@ -1174,7 +1187,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts break; case StackElement::LoadTypesystem: attributes.insert(nameAttribute(), QString()); - attributes.insert(QLatin1String("generate"), QLatin1String("yes")); + attributes.insert(QLatin1String("generate"), yesAttributeValue()); break; case StackElement::NoNullPointers: attributes.insert(QLatin1String("default-value"), QString()); @@ -1193,28 +1206,28 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts attributes.insert(QLatin1String("signature"), QString()); attributes.insert(QLatin1String("return-type"), QLatin1String("void")); attributes.insert(QLatin1String("access"), QLatin1String("public")); - attributes.insert(QLatin1String("static"), QLatin1String("no")); + attributes.insert(QLatin1String("static"), noAttributeValue()); break; case StackElement::ModifyFunction: attributes.insert(QLatin1String("signature"), QString()); attributes.insert(QLatin1String("access"), QString()); attributes.insert(QLatin1String("remove"), QString()); attributes.insert(QLatin1String("rename"), QString()); - attributes.insert(QLatin1String("deprecated"), QLatin1String("no")); + attributes.insert(QLatin1String("deprecated"), noAttributeValue()); attributes.insert(QLatin1String("associated-to"), QString()); - attributes.insert(QLatin1String("virtual-slot"), QLatin1String("no")); - attributes.insert(QLatin1String("thread"), QLatin1String("no")); - attributes.insert(QLatin1String("allow-thread"), QLatin1String("no")); + attributes.insert(QLatin1String("virtual-slot"), noAttributeValue()); + attributes.insert(QLatin1String("thread"), noAttributeValue()); + attributes.insert(QLatin1String("allow-thread"), noAttributeValue()); break; case StackElement::ModifyArgument: attributes.insert(QLatin1String("index"), QString()); attributes.insert(QLatin1String("replace-value"), QString()); - attributes.insert(QLatin1String("invalidate-after-use"), QLatin1String("no")); + attributes.insert(QLatin1String("invalidate-after-use"), noAttributeValue()); break; case StackElement::ModifyField: attributes.insert(nameAttribute(), QString()); - attributes.insert(QLatin1String("write"), QLatin1String("true")); - attributes.insert(QLatin1String("read"), QLatin1String("true")); + attributes.insert(QLatin1String("write"), trueAttributeValue()); + attributes.insert(QLatin1String("read"), trueAttributeValue()); attributes.insert(QLatin1String("remove"), QString()); break; case StackElement::Access: @@ -1245,7 +1258,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts attributes.insert(QLatin1String("file"), QString()); break; case StackElement::TargetToNative: - attributes.insert(QLatin1String("replace"), QLatin1String("yes")); + attributes.insert(QLatin1String("replace"), yesAttributeValue()); break; case StackElement::AddConversion: attributes.insert(QLatin1String("type"), QString()); @@ -1429,7 +1442,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts m_error = QLatin1String("Target to Native conversions can only be specified for custom conversion rules."); return false; } - bool replace = attributes[QLatin1String("replace")] == QLatin1String("yes"); + bool replace = attributes[QLatin1String("replace")] == yesAttributeValue(); static_cast<TypeEntry*>(m_current->entry)->customConversion()->setReplaceOriginalTargetToNativeConversions(replace); } break; @@ -1679,8 +1692,8 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts QString read = attributes[QLatin1String("read")]; QString write = attributes[QLatin1String("write")]; - if (read == QLatin1String("true")) fm.modifiers |= FieldModification::Readable; - if (write == QLatin1String("true")) fm.modifiers |= FieldModification::Writable; + if (read == trueAttributeValue()) fm.modifiers |= FieldModification::Readable; + if (write == trueAttributeValue()) fm.modifiers |= FieldModification::Writable; m_contextStack.top()->fieldMods << fm; } @@ -1706,7 +1719,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts } AddedFunction func(signature, attributes[QLatin1String("return-type")], since); - func.setStatic(attributes[QLatin1String("static")] == QLatin1String("yes")); + func.setStatic(attributes[QLatin1String("static")] == yesAttributeValue()); if (!signature.contains(QLatin1Char('('))) signature += QLatin1String("()"); m_currentSignature = signature; @@ -2273,19 +2286,6 @@ QString FlagsTypeEntry::targetLangPackage() const return m_enum->targetLangPackage(); } -void EnumTypeEntry::addEnumValueRedirection(const QString &rejected, const QString &usedValue) -{ - m_enumRedirections << EnumValueRedirection(rejected, usedValue); -} - -QString EnumTypeEntry::enumValueRedirection(const QString &value) const -{ - for (int i = 0; i < m_enumRedirections.size(); ++i) - if (m_enumRedirections.at(i).rejected == value) - return m_enumRedirections.at(i).used; - return QString(); -} - QString FlagsTypeEntry::qualifiedTargetLangName() const { return targetLangPackage() + QLatin1Char('.') + m_enum->targetLangQualifier() |