Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-12-20 20:45:51 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-12-30 11:06:38 +0100
commita067880f70c09f84bfeb24b4944c9e013c0fb93f (patch)
tree1d92d37ae4a95df6afd61d811a948956eb4553d4
parentc78ddb92a8b8f3b55fd3abfac94c88fe16d9618f (diff)
Separate out wrapper constructors
Task-number: PYSIDE-2966 Change-Id: Ia9aba41dddb0c1a25e86701641113269d99fdc5f Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp10
-rw-r--r--sources/shiboken6/generator/shiboken/headergenerator.cpp31
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp22
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.h4
4 files changed, 51 insertions, 16 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 0bae97122..d2fc202b4 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -691,14 +691,16 @@ void CppGenerator::generateClass(TextStream &s,
s << outdent << "}\n\n";
}
- int maxOverrides = 0;
+ const auto &wrapperConstructors = ShibokenGenerator::getWrapperConstructors(metaClass);
+
if (useOverrideCaching(classContext.metaClass()))
writeCacheResetNative(s, classContext);
+ for (const auto &func : wrapperConstructors)
+ writeConstructorNative(s, classContext, func);
+ int maxOverrides = 0;
for (const auto &func : metaClass->functions()) {
const auto generation = functionGeneration(func);
- if (generation.testFlag(FunctionGenerationFlag::WrapperConstructor))
- writeConstructorNative(s, classContext, func);
- else if (generation.testFlag(FunctionGenerationFlag::VirtualMethod))
+ if (generation.testFlag(FunctionGenerationFlag::VirtualMethod))
writeVirtualMethodNative(s, func, maxOverrides++);
}
diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp
index bf5ad29d0..287ab3f4a 100644
--- a/sources/shiboken6/generator/shiboken/headergenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp
@@ -96,7 +96,7 @@ QString HeaderGenerator::fileNameForContext(const GeneratorContext &context) con
void HeaderGenerator::writeCopyCtor(TextStream &s,
const AbstractMetaClassCPtr &metaClass)
{
- s << wrapperName(metaClass) << "(const " << metaClass->qualifiedCppName()
+ s << '\n' << wrapperName(metaClass) << "(const " << metaClass->qualifiedCppName()
<< "& self) : " << metaClass->qualifiedCppName() << "(self)\n{\n}\n\n";
}
@@ -239,13 +239,27 @@ void HeaderGenerator::writeWrapperClassDeclaration(TextStream &s,
s << '\n';
}
+ const auto &wrapperConstructors = ShibokenGenerator::getWrapperConstructors(metaClass);
+ for (const auto &func : wrapperConstructors)
+ writeFunction(s, func, &inheritedOverloads, functionGeneration(func));
+
+ // Special inline copy CT (Wrapper from metaClass)
+ const auto &copyConstructors = metaClass->queryFunctions(FunctionQueryOption::CopyConstructor);
+ if (!copyConstructors.isEmpty()) {
+ auto generation = functionGeneration(copyConstructors.constFirst());
+ if (generation.testFlag(FunctionGenerationFlag::WrapperSpecialCopyConstructor))
+ writeCopyCtor(s, metaClass); // FIXME: Remove in writeFunction()?
+ }
+
int maxOverrides = 0;
for (const auto &func : metaClass->functions()) {
const auto generation = functionGeneration(func);
- writeFunction(s, func, &inheritedOverloads, generation);
- // PYSIDE-803: Build a boolean cache for unused overrides.
- if (generation.testFlag(FunctionGenerationFlag::VirtualMethod))
- maxOverrides++;
+ if (!func->isConstructor()) {
+ writeFunction(s, func, &inheritedOverloads, generation);
+ // PYSIDE-803: Build a boolean cache for unused overrides.
+ if (generation.testFlag(FunctionGenerationFlag::VirtualMethod))
+ maxOverrides++;
+ }
}
//destructor
@@ -352,13 +366,6 @@ void HeaderGenerator::writeFunction(TextStream &s, const AbstractMetaFunctionCPt
InheritedOverloadSet *inheritedOverloads,
FunctionGeneration generation) const
{
-
- // do not write copy ctors here.
- if (generation.testFlag(FunctionGenerationFlag::WrapperSpecialCopyConstructor)) {
- writeCopyCtor(s, func->ownerClass());
- return;
- }
-
if (generation.testFlag(FunctionGenerationFlag::ProtectedWrapper))
writeMemberFunctionWrapper(s, func, u"_protected"_s);
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index 3c80752b2..83b6f39e6 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -106,6 +106,7 @@ struct GeneratorClassInfoCacheEntry
{
ShibokenGenerator::FunctionGroups functionGroups;
AbstractMetaFunctionCList constructors;
+ AbstractMetaFunctionCList wrapperConstructors;
QList<AbstractMetaFunctionCList> numberProtocolOperators;
BoolCastFunctionOptional boolCastFunctionO;
ShibokenGenerator::AttroCheck attroCheck;
@@ -2053,6 +2054,18 @@ ShibokenGenerator::FunctionGroups ShibokenGenerator::getGlobalFunctionGroups() c
return results;
}
+AbstractMetaFunctionCList
+ ShibokenGenerator::wrapperConstructorsImpl(const AbstractMetaClassCPtr &scope)
+{
+ auto pred = [](const AbstractMetaFunctionCPtr &f) {
+ return ShibokenGenerator::functionGeneration(f).testFlag(FunctionGenerationFlag::WrapperConstructor);
+ };
+ AbstractMetaFunctionCList result;
+ std::copy_if(scope->functions().cbegin(), scope->functions().cend(),
+ std::back_inserter(result), pred);
+ return result;
+}
+
const GeneratorClassInfoCacheEntry &
ShibokenGenerator::getGeneratorClassInfo(const AbstractMetaClassCPtr &scope)
{
@@ -2062,6 +2075,9 @@ const GeneratorClassInfoCacheEntry &
it = cache->insert(scope, {});
auto &entry = it.value();
entry.functionGroups = getFunctionGroupsImpl(scope, &entry.constructors);
+ const bool useWrapper = shouldGenerateCppWrapper(scope);
+ if (useWrapper)
+ entry.wrapperConstructors = wrapperConstructorsImpl(scope);
entry.attroCheck = checkAttroFunctionNeedsImpl(scope, entry.functionGroups);
entry.numberProtocolOperators = getNumberProtocolOperators(scope);
entry.boolCastFunctionO = getBoolCast(scope);
@@ -2083,6 +2099,12 @@ AbstractMetaFunctionCList
return getGeneratorClassInfo(scope).constructors;
}
+AbstractMetaFunctionCList ShibokenGenerator::getWrapperConstructors(const AbstractMetaClassCPtr &scope)
+{
+ Q_ASSERT(scope);
+ return getGeneratorClassInfo(scope).wrapperConstructors;
+}
+
QList<AbstractMetaFunctionCList>
ShibokenGenerator::numberProtocolOperators(const AbstractMetaClassCPtr &scope)
{
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h
index e3782e0be..b486785e1 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.h
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h
@@ -112,6 +112,9 @@ protected:
/// Returns the constructors for which bindings should be generated.
/// \param scope Where to search for functions
static AbstractMetaFunctionCList getConstructors(const AbstractMetaClassCPtr &scope);
+ /// Returns the constructors which should be added to wrapper class.
+ /// \param scope Where to search for functions
+ static AbstractMetaFunctionCList getWrapperConstructors(const AbstractMetaClassCPtr &scope);
static QList<AbstractMetaFunctionCList>
numberProtocolOperators(const AbstractMetaClassCPtr &scope);
@@ -375,6 +378,7 @@ private:
getGeneratorClassInfo(const AbstractMetaClassCPtr &scope);
static FunctionGroups getFunctionGroupsImpl(const AbstractMetaClassCPtr &scope,
AbstractMetaFunctionCList *constructors);
+ static AbstractMetaFunctionCList wrapperConstructorsImpl(const AbstractMetaClassCPtr &scope);
static QList<AbstractMetaFunctionCList>
getNumberProtocolOperators(const AbstractMetaClassCPtr &metaClass);
static BoolCastFunctionOptional getBoolCast(const AbstractMetaClassCPtr &metaClass);