diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor')
14 files changed, 307 insertions, 10 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index a3c2d3731..41e42ac2a 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -451,13 +451,11 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) if (!funcEntry->hasSignature(metaFunc->minimalSignature())) continue; + metaFunc->setTypeEntry(funcEntry); applyFunctionModifications(metaFunc); setInclude(funcEntry, func->fileName()); - if (metaFunc->typeEntry()) - delete metaFunc->typeEntry(); - metaFunc->setTypeEntry(funcEntry); m_globalFunctions << metaFuncPtr; } @@ -1368,6 +1366,51 @@ void AbstractMetaBuilderPrivate::fillAddedFunctions(AbstractMetaClass *metaClass } } +QString AbstractMetaBuilder::getSnakeCaseName(const QString &name) +{ + const int size = name.size(); + if (size < 3) + return name; + QString result; + result.reserve(size + 4); + for (int i = 0; i < size; ++i) { + const QChar c = name.at(i); + if (c.isUpper()) { + if (i > 0) { + if (name.at(i - 1).isUpper()) + return name; // Give up at consecutive upper chars + result.append(u'_'); + } + result.append(c.toLower()); + } else { + result.append(c); + } + } + return result; +} + +// Names under which an item will be registered to Python depending on snakeCase +QStringList AbstractMetaBuilder::definitionNames(const QString &name, + TypeSystem::SnakeCase snakeCase) +{ + QStringList result; + switch (snakeCase) { + case TypeSystem::SnakeCase::Unspecified: + case TypeSystem::SnakeCase::Disabled: + result.append(name); + break; + case TypeSystem::SnakeCase::Enabled: + result.append(AbstractMetaBuilder::getSnakeCaseName(name)); + break; + case TypeSystem::SnakeCase::Both: + result.append(AbstractMetaBuilder::getSnakeCaseName(name)); + if (name != result.constFirst()) + result.append(name); + break; + } + return result; +} + void AbstractMetaBuilderPrivate::applyFunctionModifications(AbstractMetaFunction *func) { AbstractMetaFunction& funcRef = *func; diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h index cd9f36ca9..5b0414cd0 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h @@ -32,6 +32,7 @@ #include "abstractmetalang_typedefs.h" #include "header_paths.h" #include "dependency.h" +#include "typesystem_enums.h" #include "clangparser/compilersupport.h" @@ -106,6 +107,11 @@ public: translateType(const QString &t, AbstractMetaClass *currentClass = nullptr, TranslateTypeFlags flags = {}, QString *errorMessage = nullptr); + static QString getSnakeCaseName(const QString &name); + // Names under which an item will be registered to Python depending on snakeCase + static QStringList definitionNames(const QString &name, + TypeSystem::SnakeCase snakeCase); + #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &d) const; #endif diff --git a/sources/shiboken6/ApiExtractor/abstractmetafield.cpp b/sources/shiboken6/ApiExtractor/abstractmetafield.cpp index 3c294c3c7..23c21d2a5 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafield.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafield.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include "abstractmetafield.h" +#include "abstractmetabuilder.h" #include "abstractmetalang.h" #include "abstractmetatype.h" #include "documentation.h" @@ -111,6 +112,11 @@ QString AbstractMetaField::qualifiedCppName() const + originalName(); } +QStringList AbstractMetaField::definitionNames() const +{ + return AbstractMetaBuilder::definitionNames(d->m_name, snakeCase()); +} + QString AbstractMetaField::originalName() const { return d->m_originalName.isEmpty() ? d->m_name : d->m_originalName; @@ -166,6 +172,23 @@ bool AbstractMetaField::canGenerateSetter() const && (!d->m_type.isConstant() || d->m_type.isPointerToConst()); } +TypeSystem::SnakeCase AbstractMetaField::snakeCase() const +{ + // Renamed? + if (!d->m_originalName.isEmpty() && d->m_originalName != d->m_name) + return TypeSystem::SnakeCase::Disabled; + + for (const auto &mod : modifications()) { + if (mod.snakeCase() != TypeSystem::SnakeCase::Unspecified) + return mod.snakeCase(); + } + + auto typeEntry = enclosingClass()->typeEntry(); + const auto snakeCase = typeEntry->snakeCase(); + return snakeCase != TypeSystem::SnakeCase::Unspecified + ? snakeCase : typeEntry->typeSystemTypeEntry()->snakeCase(); +} + FieldModificationList AbstractMetaField::modifications() const { const FieldModificationList &mods = enclosingClass()->typeEntry()->fieldModifications(); diff --git a/sources/shiboken6/ApiExtractor/abstractmetafield.h b/sources/shiboken6/ApiExtractor/abstractmetafield.h index 7964d5b57..52e08e2af 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafield.h +++ b/sources/shiboken6/ApiExtractor/abstractmetafield.h @@ -66,6 +66,9 @@ public: QString qualifiedCppName() const; + // Names under which the field will be registered to Python. + QStringList definitionNames() const; + QString originalName() const; void setOriginalName(const QString& name); @@ -80,6 +83,8 @@ public: bool canGenerateGetter() const; bool canGenerateSetter() const; + TypeSystem::SnakeCase snakeCase() const; + static std::optional<AbstractMetaField> find(const AbstractMetaFieldList &haystack, const QString &needle); diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp index e2d0fb9dc..9594cfdb6 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include "abstractmetafunction.h" +#include "abstractmetabuilder.h" #include "abstractmetalang.h" #include "abstractmetalang_helpers.h" #include "abstractmetatype.h" @@ -144,6 +145,11 @@ void AbstractMetaFunction::setOriginalName(const QString &name) d->m_originalName = name; } +QStringList AbstractMetaFunction::definitionNames() const +{ + return AbstractMetaBuilder::definitionNames(d->m_name, snakeCase()); +} + const Documentation &AbstractMetaFunction::documentation() const { return d->m_doc; @@ -1132,6 +1138,46 @@ int AbstractMetaFunction::overloadNumber() const return d->overloadNumber(this); } +TypeSystem::SnakeCase AbstractMetaFunction::snakeCase() const +{ + if (isUserAdded()) + return TypeSystem::SnakeCase::Disabled; + // Renamed? + if (!d->m_originalName.isEmpty() && d->m_originalName != d->m_name) + return TypeSystem::SnakeCase::Disabled; + switch (d->m_functionType) { + case AbstractMetaFunction::NormalFunction: + case AbstractMetaFunction::SignalFunction: + case AbstractMetaFunction::EmptyFunction: + case AbstractMetaFunction::SlotFunction: + case AbstractMetaFunction::GlobalScopeFunction: + if (isOperatorOverload()) + return TypeSystem::SnakeCase::Disabled; + break; + default: + return TypeSystem::SnakeCase::Disabled; + } + + for (const auto &mod : modifications()) { + if (mod.snakeCase() != TypeSystem::SnakeCase::Unspecified) + return mod.snakeCase(); + } + + if (d->m_typeEntry) { // Global function + const auto snakeCase = d->m_typeEntry->snakeCase(); + return snakeCase != TypeSystem::SnakeCase::Unspecified + ? snakeCase : d->m_typeEntry->typeSystemTypeEntry()->snakeCase(); + } + + if (d->m_class) { + auto typeEntry = d->m_class->typeEntry(); + const auto snakeCase = typeEntry->snakeCase(); + return snakeCase != TypeSystem::SnakeCase::Unspecified + ? snakeCase : typeEntry->typeSystemTypeEntry()->snakeCase(); + } + return TypeSystem::SnakeCase::Disabled; +} + // Query functions for generators bool AbstractMetaFunction::injectedCodeUsesPySelf() const { diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.h b/sources/shiboken6/ApiExtractor/abstractmetafunction.h index 1a29fcefe..99174b47f 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.h +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.h @@ -95,6 +95,9 @@ public: QString name() const; void setName(const QString &name); + // Names under which the function will be registered to Python. + QStringList definitionNames() const; + QString originalName() const; void setOriginalName(const QString &name); @@ -283,6 +286,8 @@ public: int overloadNumber() const; + TypeSystem::SnakeCase snakeCase() const; + // Query functions for generators /// Verifies if any of the function's code injections of the "native" /// type needs the type system variable "%PYSELF". diff --git a/sources/shiboken6/ApiExtractor/modifications.cpp b/sources/shiboken6/ApiExtractor/modifications.cpp index eba1437dc..9e5071a33 100644 --- a/sources/shiboken6/ApiExtractor/modifications.cpp +++ b/sources/shiboken6/ApiExtractor/modifications.cpp @@ -173,6 +173,7 @@ public: bool m_readable = true; bool m_writable = true; bool m_removed = false; + TypeSystem::SnakeCase snakeCase = TypeSystem::SnakeCase::Unspecified; }; FieldModification::FieldModification() : d(new FieldModificationData) @@ -245,6 +246,17 @@ void FieldModification::setRemoved(bool r) d->m_removed = r; } +TypeSystem::SnakeCase FieldModification::snakeCase() const +{ + return d->snakeCase; +} + +void FieldModification::setSnakeCase(TypeSystem::SnakeCase s) +{ + if (d->snakeCase != s) + d->snakeCase = s; +} + // Helpers to split a parameter list of <add-function>, <declare-function> // (@ denoting names), like // "void foo(QList<X,Y> &@list@ = QList<X,Y>{1,2}, int @b@=5, ...)" @@ -716,6 +728,7 @@ public: bool m_thread = false; TypeSystem::AllowThread m_allowThread = TypeSystem::AllowThread::Unspecified; TypeSystem::ExceptionHandling m_exceptionHandling = TypeSystem::ExceptionHandling::Unspecified; + TypeSystem::SnakeCase snakeCase = TypeSystem::SnakeCase::Unspecified; }; FunctionModification::FunctionModification() : d(new FunctionModificationData) @@ -763,6 +776,17 @@ void FunctionModification::setArgument_mods(const QList<ArgumentModification> &a d->m_argument_mods = argument_mods; } +TypeSystem::SnakeCase FunctionModification::snakeCase() const +{ + return d->snakeCase; +} + +void FunctionModification::setSnakeCase(TypeSystem::SnakeCase s) +{ + if (d->snakeCase != s) + d->snakeCase = s; +} + const CodeSnipList &FunctionModification::snips() const { return d->m_snips; diff --git a/sources/shiboken6/ApiExtractor/modifications.h b/sources/shiboken6/ApiExtractor/modifications.h index 1d217d0cb..de47c15c2 100644 --- a/sources/shiboken6/ApiExtractor/modifications.h +++ b/sources/shiboken6/ApiExtractor/modifications.h @@ -382,6 +382,9 @@ public: QList<ArgumentModification> &argument_mods(); void setArgument_mods(const QList<ArgumentModification> &argument_mods); + TypeSystem::SnakeCase snakeCase() const; + void setSnakeCase(TypeSystem::SnakeCase s); + #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &d) const; #endif @@ -423,6 +426,9 @@ public: bool isRemoved() const; void setRemoved(bool r); + TypeSystem::SnakeCase snakeCase() const; + void setSnakeCase(TypeSystem::SnakeCase s); + private: QSharedDataPointer<FieldModificationData> d; }; diff --git a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp index 7c7bb6115..906b8a4b4 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp @@ -29,6 +29,7 @@ #include "testmodifyfunction.h" #include <QtTest/QTest> #include "testutil.h" +#include <abstractmetabuilder_p.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> #include <modifications.h> @@ -469,4 +470,25 @@ void TestModifyFunction::testScopedModifications() QCOMPARE(f->generateExceptionHandling(), expectedGenerateThrowing); } +void TestModifyFunction::testSnakeCaseRenaming_data() +{ + QTest::addColumn<QString>("name"); + QTest::addColumn<QString>("expected"); + QTest::newRow("s1") + << QStringLiteral("snakeCaseFunc") << QStringLiteral("snake_case_func"); + QTest::newRow("s2") + << QStringLiteral("SnakeCaseFunc") << QStringLiteral("snake_case_func"); + QTest::newRow("consecutive-uppercase") + << QStringLiteral("snakeCAseFunc") << QStringLiteral("snakeCAseFunc"); +} + +void TestModifyFunction::testSnakeCaseRenaming() +{ + QFETCH(QString, name); + QFETCH(QString, expected); + + const QString actual = AbstractMetaBuilder::getSnakeCaseName(name); + QCOMPARE(actual, expected); +} + QTEST_APPLESS_MAIN(TestModifyFunction) diff --git a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.h b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.h index 375111e03..a9a13a82b 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.h +++ b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.h @@ -44,6 +44,8 @@ class TestModifyFunction : public QObject void testGlobalFunctionModification(); void testScopedModifications_data(); void testScopedModifications(); + void testSnakeCaseRenaming_data(); + void testSnakeCaseRenaming(); }; #endif diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index 372d36cfb..b76582b9f 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -637,9 +637,18 @@ void TypeEntry::useAsTypedef(const TypeEntry *source) m_d->m_version = source->m_d->m_version; } +// ----------------- TypeSystemTypeEntry +class TypeSystemTypeEntryPrivate : public TypeEntryPrivate +{ +public: + using TypeEntryPrivate::TypeEntryPrivate; + + TypeSystem::SnakeCase m_snakeCase = TypeSystem::SnakeCase::Disabled; +}; + TypeSystemTypeEntry::TypeSystemTypeEntry(const QString &entryName, const QVersionNumber &vr, const TypeEntry *parent) : - TypeEntry(entryName, TypeSystemType, vr, parent) + TypeEntry(new TypeSystemTypeEntryPrivate(entryName, TypeSystemType, vr, parent)) { } @@ -650,7 +659,20 @@ TypeSystemTypeEntry::TypeSystemTypeEntry(TypeEntryPrivate *d) : TypeEntry *TypeSystemTypeEntry::clone() const { - return new TypeSystemTypeEntry(new TypeEntryPrivate(*d_func())); + S_D(const TypeSystemTypeEntry); + return new TypeSystemTypeEntry(new TypeSystemTypeEntryPrivate(*d)); +} + +TypeSystem::SnakeCase TypeSystemTypeEntry::snakeCase() const +{ + S_D(const TypeSystemTypeEntry); + return d->m_snakeCase; +} + +void TypeSystemTypeEntry::setSnakeCase(TypeSystem::SnakeCase sc) +{ + S_D(TypeSystemTypeEntry); + d->m_snakeCase = sc; } // ----------------- VoidTypeEntry @@ -1148,6 +1170,7 @@ public: // For class functions TypeSystem::ExceptionHandling m_exceptionHandling = TypeSystem::ExceptionHandling::Unspecified; TypeSystem::AllowThread m_allowThread = TypeSystem::AllowThread::Unspecified; + TypeSystem::SnakeCase m_snakeCase = TypeSystem::SnakeCase::Unspecified; }; ComplexTypeEntry::ComplexTypeEntry(const QString &entryName, TypeEntry::Type t, @@ -1407,6 +1430,18 @@ bool ComplexTypeEntry::hasDefaultConstructor() const return !d->m_defaultConstructor.isEmpty(); } +TypeSystem::SnakeCase ComplexTypeEntry::snakeCase() const +{ + S_D(const ComplexTypeEntry); + return d->m_snakeCase; +} + +void ComplexTypeEntry::setSnakeCase(TypeSystem::SnakeCase sc) +{ + S_D(ComplexTypeEntry); + d->m_snakeCase = sc; +} + TypeEntry *ComplexTypeEntry::clone() const { S_D(const ComplexTypeEntry); @@ -1954,6 +1989,7 @@ public: } QStringList m_signatures; + TypeSystem::SnakeCase m_snakeCase = TypeSystem::SnakeCase::Unspecified; }; FunctionTypeEntry::FunctionTypeEntry(const QString &entryName, const QString &signature, @@ -1981,6 +2017,18 @@ bool FunctionTypeEntry::hasSignature(const QString &signature) const return d->m_signatures.contains(signature); } +TypeSystem::SnakeCase FunctionTypeEntry::snakeCase() const +{ + S_D(const FunctionTypeEntry); + return d->m_snakeCase; +} + +void FunctionTypeEntry::setSnakeCase(TypeSystem::SnakeCase sc) +{ + S_D(FunctionTypeEntry); + d->m_snakeCase = sc; +} + TypeEntry *FunctionTypeEntry::clone() const { S_D(const FunctionTypeEntry); @@ -2074,7 +2122,8 @@ void ComplexTypeEntry::formatDebug(QDebug &debug) const if (d->m_typeFlags != 0) debug << ", typeFlags=" << d->m_typeFlags; debug << ", copyableFlag=" << d->m_copyableFlag - << ", except=" << int(d->m_exceptionHandling); + << ", except=" << int(d->m_exceptionHandling) + << ", snakeCase=" << int(d->m_snakeCase); FORMAT_NONEMPTY_STRING("defaultSuperclass", d->m_defaultSuperclass) FORMAT_NONEMPTY_STRING("polymorphicIdValue", d->m_polymorphicIdValue) FORMAT_NONEMPTY_STRING("targetType", d->m_targetType) @@ -2084,6 +2133,15 @@ void ComplexTypeEntry::formatDebug(QDebug &debug) const FORMAT_LIST_SIZE("fieldMods", d->m_fieldMods) } +void FunctionTypeEntry::formatDebug(QDebug &debug) const +{ + S_D(const FunctionTypeEntry); + + TypeEntry::formatDebug(debug); + debug << "signatures=" << d->m_signatures + << ", snakeCase=" << int(d->m_snakeCase); +} + void TypedefEntry::formatDebug(QDebug &debug) const { S_D(const TypedefEntry); diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h index a2b52bb0d..a823814f7 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.h +++ b/sources/shiboken6/ApiExtractor/typesystem.h @@ -296,6 +296,9 @@ public: TypeEntry *clone() const override; + TypeSystem::SnakeCase snakeCase() const; + void setSnakeCase(TypeSystem::SnakeCase sc); + protected: explicit TypeSystemTypeEntry(TypeEntryPrivate *d); }; @@ -573,6 +576,9 @@ public: void useAsTypedef(const ComplexTypeEntry *source); + TypeSystem::SnakeCase snakeCase() const; + void setSnakeCase(TypeSystem::SnakeCase sc); + #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &debug) const override; #endif @@ -741,8 +747,15 @@ public: bool hasSignature(const QString& signature) const; void addSignature(const QString& signature); + TypeSystem::SnakeCase snakeCase() const; + void setSnakeCase(TypeSystem::SnakeCase sc); + TypeEntry *clone() const override; +#ifndef QT_NO_DEBUG_STREAM + void formatDebug(QDebug &d) const override; +#endif + protected: explicit FunctionTypeEntry(FunctionTypeEntryPrivate *d); }; diff --git a/sources/shiboken6/ApiExtractor/typesystem_enums.h b/sources/shiboken6/ApiExtractor/typesystem_enums.h index 0d7f279c4..60832b64e 100644 --- a/sources/shiboken6/ApiExtractor/typesystem_enums.h +++ b/sources/shiboken6/ApiExtractor/typesystem_enums.h @@ -81,6 +81,13 @@ enum class ExceptionHandling { On }; +enum class SnakeCase { + Unspecified, + Disabled, + Enabled, + Both +}; + enum Visibility { // For namespaces Unspecified, Visible, diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp index 4c754f680..6762bef21 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp @@ -97,6 +97,7 @@ static inline QString replaceAttribute() { return QStringLiteral("replace"); } static inline QString toAttribute() { return QStringLiteral("to"); } static inline QString signatureAttribute() { return QStringLiteral("signature"); } static inline QString snippetAttribute() { return QStringLiteral("snippet"); } +static inline QString snakeCaseAttribute() { return QStringLiteral("snake-case"); } static inline QString staticAttribute() { return QStringLiteral("static"); } static inline QString threadAttribute() { return QStringLiteral("thread"); } static inline QString sourceAttribute() { return QStringLiteral("source"); } @@ -392,6 +393,18 @@ ENUM_LOOKUP_BEGIN(StackElement::ElementType, Qt::CaseInsensitive, }; ENUM_LOOKUP_BINARY_SEARCH() + +ENUM_LOOKUP_BEGIN(TypeSystem::SnakeCase, Qt::CaseSensitive, + snakeCaseFromAttribute, TypeSystem::SnakeCase::Unspecified) +{ + {u"no", TypeSystem::SnakeCase::Disabled}, + {u"false", TypeSystem::SnakeCase::Disabled}, + {u"yes", TypeSystem::SnakeCase::Enabled}, + {u"true", TypeSystem::SnakeCase::Enabled}, + {u"both", TypeSystem::SnakeCase::Both}, +}; +ENUM_LOOKUP_LINEAR_SEARCH() + ENUM_LOOKUP_BEGIN(TypeSystem::Visibility, Qt::CaseSensitive, visibilityFromAttribute, TypeSystem::Visibility::Unspecified) { @@ -1442,18 +1455,29 @@ FunctionTypeEntry * { if (!checkRootElement()) return nullptr; - const int signatureIndex = indexOfAttribute(*attributes, signatureAttribute()); - if (signatureIndex == -1) { + + QString signature; + TypeSystem::SnakeCase snakeCase = TypeSystem::SnakeCase::Disabled; + + for (int i = attributes->size() - 1; i >= 0; --i) { + const auto name = attributes->at(i).qualifiedName(); + if (name == signatureAttribute()) { + signature = TypeDatabase::normalizedSignature(attributes->takeAt(i).value().toString()); + } else if (name == snakeCaseAttribute()) { + snakeCase = snakeCaseFromAttribute(attributes->takeAt(i).value()); + } + } + + if (signature.isEmpty()) { m_error = msgMissingAttribute(signatureAttribute()); return nullptr; } - const QString signature = - TypeDatabase::normalizedSignature(attributes->takeAt(signatureIndex).value().toString()); TypeEntry *existingType = m_database->findType(name); if (!existingType) { auto *result = new FunctionTypeEntry(name, signature, since, currentParentTypeEntry()); + result->setSnakeCase(snakeCase); applyCommonAttributes(reader, result, attributes); return result; } @@ -1564,6 +1588,8 @@ void TypeSystemParser::applyComplexTypeAttributes(const QXmlStreamReader &reader ctype->setDeleteInMainThread(true); } else if (name == QLatin1String("target-type")) { ctype->setTargetType(attributes->takeAt(i).value().toString()); + } else if (name == snakeCaseAttribute()) { + ctype->setSnakeCase(snakeCaseFromAttribute(attributes->takeAt(i).value())); } } @@ -1700,6 +1726,8 @@ TypeSystemTypeEntry *TypeSystemParser::parseRootElement(const QXmlStreamReader & const QVersionNumber &since, QXmlStreamAttributes *attributes) { + TypeSystem::SnakeCase snakeCase = TypeSystem::SnakeCase::Unspecified; + for (int i = attributes->size() - 1; i >= 0; --i) { const auto name = attributes->at(i).qualifiedName(); if (name == packageAttribute()) { @@ -1724,6 +1752,8 @@ TypeSystemTypeEntry *TypeSystemParser::parseRootElement(const QXmlStreamReader & qCWarning(lcShiboken, "%s", qPrintable(msgInvalidAttributeValue(attribute))); } + } else if (name == snakeCaseAttribute()) { + snakeCase = snakeCaseFromAttribute(attributes->takeAt(i).value()); } } @@ -1735,6 +1765,7 @@ TypeSystemTypeEntry *TypeSystemParser::parseRootElement(const QXmlStreamReader & currentParentTypeEntry()); } moduleEntry->setCodeGeneration(m_generate); + moduleEntry->setSnakeCase(snakeCase); if ((m_generate == TypeEntry::GenerateForSubclass || m_generate == TypeEntry::GenerateNothing) && !m_defaultPackage.isEmpty()) @@ -2078,6 +2109,8 @@ bool TypeSystemParser::parseModifyField(const QXmlStreamReader &reader, fm.setWritable(convertBoolean(attributes->takeAt(i).value(), writeAttribute(), true)); } else if (name == renameAttribute()) { fm.setRenamedToName(attributes->takeAt(i).value().toString()); + } else if (name == snakeCaseAttribute()) { + fm.setSnakeCase(snakeCaseFromAttribute(attributes->takeAt(i).value())); } } if (fm.name().isEmpty()) { @@ -2232,6 +2265,7 @@ bool TypeSystemParser::parseModifyFunction(const QXmlStreamReader &reader, int overloadNumber = TypeSystem::OverloadNumberUnset; TypeSystem::ExceptionHandling exceptionHandling = TypeSystem::ExceptionHandling::Unspecified; TypeSystem::AllowThread allowThread = TypeSystem::AllowThread::Unspecified; + TypeSystem::SnakeCase snakeCase = TypeSystem::SnakeCase::Unspecified; for (int i = attributes->size() - 1; i >= 0; --i) { const auto name = attributes->at(i).qualifiedName(); if (name == QLatin1String("signature")) { @@ -2265,6 +2299,8 @@ bool TypeSystemParser::parseModifyFunction(const QXmlStreamReader &reader, } else if (name == overloadNumberAttribute()) { if (!parseOverloadNumber(attributes->takeAt(i), &overloadNumber, &m_error)) return false; + } else if (name == snakeCaseAttribute()) { + snakeCase = snakeCaseFromAttribute(attributes->takeAt(i).value()); } else if (name == virtualSlotAttribute()) { qCWarning(lcShiboken, "%s", qPrintable(msgUnimplementedAttributeWarning(reader, name))); @@ -2295,6 +2331,7 @@ bool TypeSystemParser::parseModifyFunction(const QXmlStreamReader &reader, mod.setOriginalSignature(originalSignature); mod.setExceptionHandling(exceptionHandling); mod.setOverloadNumber(overloadNumber); + mod.setSnakeCase(snakeCase); m_currentSignature = signature; if (!access.isEmpty()) { |