diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-11 20:20:28 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-05-15 12:49:00 +0200 |
commit | c16caeb5cb0fbce4a552080d75166caf15374767 (patch) | |
tree | db10eba35f51d34435f32f07b8d8272214a2dfaf /sources/shiboken2/generator/shiboken2/shibokengenerator.cpp | |
parent | cce4684bfd1372822e3fdcb78dda023033c2dad3 (diff) |
shiboken: Refactor ShibokenGenerator::wrapperName()
Assert that it is only used for wrapped classes and remove
fallback path returning the class name, which obfuscates
the code.
Change-Id: I9af1a6a9edc5e566296ec99a50a9f8cfbe055cd0
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator/shiboken2/shibokengenerator.cpp')
-rw-r--r-- | sources/shiboken2/generator/shiboken2/shibokengenerator.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 47cca8173..543e1c02c 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -349,15 +349,11 @@ void ShibokenGenerator::lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumLi QString ShibokenGenerator::wrapperName(const AbstractMetaClass *metaClass) const { - if (shouldGenerateCppWrapper(metaClass)) { - QString result = metaClass->name(); - if (metaClass->enclosingClass()) // is a inner class - result.replace(QLatin1String("::"), QLatin1String("_")); - - result += QLatin1String("Wrapper"); - return result; - } - return metaClass->qualifiedCppName(); + Q_ASSERT(shouldGenerateCppWrapper(metaClass)); + QString result = metaClass->name(); + if (metaClass->enclosingClass()) // is a inner class + result.replace(QLatin1String("::"), QLatin1String("_")); + return result + QLatin1String("Wrapper"); } QString ShibokenGenerator::wrapperName(const AbstractMetaType *metaType) const @@ -1674,7 +1670,9 @@ void ShibokenGenerator::processCodeSnip(QString &code, const AbstractMetaClass * // for the class context in which the variable is used. code.replace(QLatin1String("%PYTHONTYPEOBJECT"), cpythonTypeName(context) + QLatin1String("->type")); - code.replace(QLatin1String("%TYPE"), wrapperName(context)); + const QString className = shouldGenerateCppWrapper(context) + ? wrapperName(context) : context->qualifiedCppName(); + code.replace(QLatin1String("%TYPE"), className); code.replace(QLatin1String("%CPPTYPE"), context->name()); } @@ -2147,7 +2145,10 @@ bool ShibokenGenerator::injectedCodeCallsCppFunction(const AbstractMetaFunction QString wrappedCtorCall; if (func->isConstructor()) { funcCall.prepend(QLatin1String("new ")); - wrappedCtorCall = QStringLiteral("new %1(").arg(wrapperName(func->ownerClass())); + const auto owner = func->ownerClass(); + const QString className = shouldGenerateCppWrapper(owner) + ? wrapperName(owner) : owner->qualifiedCppName(); + wrappedCtorCall = QLatin1String("new ") + className + QLatin1Char('('); } CodeSnipList snips = func->injectedCodeSnips(TypeSystem::CodeSnipPositionAny, TypeSystem::TargetLangCode); for (const CodeSnip &snip : qAsConst(snips)) { |