aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-02 15:24:23 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-02 15:41:39 +0000
commit3b9850880416d331bd39ae7e07d1d08887b5e6f2 (patch)
treea13210755ff3356ccf7f512b87cb731fa9f47756
parent34611847c6ffa59cde54e43788806c18d063b49d (diff)
shiboken6: Refactor ShibokenGenerator::getFunctionOverloads()
It is only ever used for class methods, so, rename it to getMethodOverloads() and remove the global functions code path. Streamline its usage in ShibokenGenerator::writeCodeSnips(). Task-number: PYSIDE-1653 Change-Id: I8ff0db418484d5b887d8eb7ef2b566eb9cc6d540 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp22
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.h4
2 files changed, 15 insertions, 11 deletions
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index 16a1e0e4b..8ed8eba16 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -1837,14 +1837,17 @@ void ShibokenGenerator::writeCodeSnips(TextStream &s,
// name and if any of them is of the protected visibility. This is used to replace
// calls to %FUNCTION_NAME on user written custom code for calls to the protected
// dispatcher.
- bool hasProtectedOverload = false;
- if (func->isUserAdded()) {
- const auto &funcs = getFunctionOverloads(func->ownerClass(), func->name());
- for (const auto &f : funcs)
- hasProtectedOverload |= f->isProtected();
+ bool isProtected = func->isProtected();
+ auto owner = func->ownerClass();
+ if (!isProtected && func->isUserAdded() && owner != nullptr) {
+ const auto &funcs = getMethodOverloads(owner, func->name());
+ isProtected = std::any_of(funcs.cbegin(), funcs.cend(),
+ [](const AbstractMetaFunctionCPtr &f) {
+ return f->isProtected();
+ });
}
- if (func->isProtected() || hasProtectedOverload) {
+ if (isProtected) {
code.replace(QLatin1String("%TYPE::%FUNCTION_NAME"),
QStringLiteral("%1::%2_protected")
.arg(wrapperName(func->ownerClass()), func->originalName()));
@@ -2337,10 +2340,11 @@ AbstractMetaFunctionCList
return results;
}
-AbstractMetaFunctionCList ShibokenGenerator::getFunctionOverloads(const AbstractMetaClass *scope,
- const QString &functionName) const
+AbstractMetaFunctionCList ShibokenGenerator::getMethodOverloads(const AbstractMetaClass *scope,
+ const QString &functionName) const
{
- const auto &lst = scope ? scope->functions() : api().globalFunctions();
+ Q_ASSERT(scope);
+ const auto &lst = scope->functions();
AbstractMetaFunctionCList results;
QSet<QString> seenSignatures;
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h
index c4c93a600..04dae6ca5 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.h
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h
@@ -426,8 +426,8 @@ private:
* \param scope scope used to search for overloads.
* \param functionName the function name.
*/
- AbstractMetaFunctionCList getFunctionOverloads(const AbstractMetaClass *scope,
- const QString &functionName) const;
+ AbstractMetaFunctionCList getMethodOverloads(const AbstractMetaClass *scope,
+ const QString &functionName) const;
/**
* Write a function argument in the C++ in the text stream \p s.
* This function just call \code s << argumentString(); \endcode