diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-11-25 16:11:08 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-12-03 12:53:21 +0100 |
| commit | b311fabb7e3d29c25fee1c3924d938ca12c1578a (patch) | |
| tree | c7fb2684437d4cbf6334d1224904e822dbffe5a0 | |
| parent | 7647b5052968f6fa2de04e8f744c697844d5b275 (diff) | |
shiboken6: Rename traverseOperatorFunction() to traverseFreeOperatorFunction()
Make it clear that the function is meant to be called for the global
namespaces or other namespaces, not for classes. Add assert and comment.
Task-number: PYSIDE-3245
Change-Id: I0e5e07c7822286ff148c5b76ff292d45d799165d
Reviewed-by: Ece Cinucen <ece.cinucen@qt.io>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
| -rw-r--r-- | sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp | 19 | ||||
| -rw-r--r-- | sources/shiboken6_generator/ApiExtractor/abstractmetabuilder_p.h | 4 |
2 files changed, 13 insertions, 10 deletions
diff --git a/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp index 17fde1751..8cc90a30c 100644 --- a/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder.cpp @@ -276,11 +276,12 @@ void AbstractMetaBuilderPrivate::registerToStringCapability(const FunctionModelI } } -void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelItem &item, - const AbstractMetaClassPtr ¤tClass) +// Traverse free operator functions (global/namespace) +void AbstractMetaBuilderPrivate::traverseFreeOperatorFunction(const FunctionModelItem &item, + const AbstractMetaClassPtr ¤tClass) { - if (item->accessPolicy() != Access::Public) - return; + Q_ASSERT(!currentClass || currentClass->isNamespace()); + Q_ASSERT(item->accessPolicy() == Access::Public); const ArgumentList &itemArguments = item->arguments(); bool firstArgumentIsSelf = true; @@ -322,6 +323,7 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte return; auto flags = metaFunction->flags(); + // Add free comparison operators to their classes, stripping the first argument. // Strip away first argument, since that is the containing object AbstractMetaArgumentList arguments = metaFunction->arguments(); if (firstArgumentIsSelf || unaryOperator) { @@ -676,11 +678,11 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom, case CodeModel::ArithmeticOperator: case CodeModel::BitwiseOperator: case CodeModel::LogicalOperator: - traverseOperatorFunction(func, nullptr); + traverseFreeOperatorFunction(func, {}); break; case CodeModel::ShiftOperator: - if (!traverseStreamOperator(func, nullptr)) - traverseOperatorFunction(func, nullptr); + if (!traverseStreamOperator(func, {})) + traverseFreeOperatorFunction(func, {}); default: break; } @@ -1464,13 +1466,14 @@ AbstractMetaFunctionList const bool isNamespace = currentClass->isNamespace(); for (const FunctionModelItem &function : scopeFunctionList) { if (isNamespace && function->isOperator()) { - traverseOperatorFunction(function, currentClass); + traverseFreeOperatorFunction(function, currentClass); } else if (function->isSpaceshipOperator() && !function->isDeleted()) { if (currentClass) AbstractMetaClass::addSynthesizedComparisonOperators(currentClass); } else if (auto metaFunction = traverseFunction(function, currentClass)) { result.append(metaFunction); } else if (!function->isDeleted() && function->functionType() == CodeModel::Constructor) { + // traverseFunction() failed: mark rejected constructors auto arguments = function->arguments(); *constructorAttributes |= AbstractMetaClass::HasRejectedConstructor; if (arguments.isEmpty() || arguments.constFirst()->defaultValue()) diff --git a/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder_p.h index 0a09d578b..5dc934934 100644 --- a/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken6_generator/ApiExtractor/abstractmetabuilder_p.h @@ -111,8 +111,8 @@ public: void traverseFields(const ScopeModelItem &item, const AbstractMetaClassPtr &parent); bool traverseStreamOperator(const FunctionModelItem &functionItem, const AbstractMetaClassPtr ¤tClass); - void traverseOperatorFunction(const FunctionModelItem &item, - const AbstractMetaClassPtr ¤tClass); + void traverseFreeOperatorFunction(const FunctionModelItem &item, + const AbstractMetaClassPtr ¤tClass); AbstractMetaFunctionPtr traverseAddedFunctionHelper(const AddedFunctionPtr &addedFunc, const AbstractMetaClassPtr &metaClass, |
