diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-12-14 09:58:52 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-12-16 15:38:05 +0100 |
| commit | 565ce8c4f32822034ffe9ff25d4093c7401d2e6a (patch) | |
| tree | d8eb4c906d439ecfba39b8dcc0cdd27e3c1a3d7b | |
| parent | 3efe0b3e66450aa98fd8600bc0ac356bcbe5ad54 (diff) | |
shiboken6: Add internal flags to AbstractMetaFunction
Add some internal flags useful mainly for documentation indicating:
- whether AbstractMetaBuilder removed operator arguments,
which is useful for the documentation.
- the function was inherited from a (container) template
- the function was declared a hidden friend
Task-number: PYSIDE-1106
Change-Id: Id31b1448a084f45ab7b3191b28c952d0226816e7
Reviewed-by: Christian Tismer <tismer@stackless.com>
6 files changed, 54 insertions, 0 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index f70685bf7..e2d16865c 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -269,6 +269,7 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte if (baseoperandClass) { AbstractMetaFunction *metaFunction = traverseFunction(item, baseoperandClass); if (metaFunction) { + auto flags = metaFunction->flags(); // Strip away first argument, since that is the containing object AbstractMetaArgumentList arguments = metaFunction->arguments(); if (firstArgumentIsSelf || unaryOperator) { @@ -277,6 +278,9 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte if (!unaryOperator && first.type().indirections()) metaFunction->setPointerOperator(true); metaFunction->setArguments(arguments); + flags.setFlag(AbstractMetaFunction::Flag::OperatorLeadingClassArgumentRemoved); + if (first.type().passByValue()) + flags.setFlag(AbstractMetaFunction::Flag::OperatorClassArgumentByValue); } else { // If the operator method is not unary and the first operator is // not of the same type of its owning class we suppose that it @@ -289,7 +293,12 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte metaFunction->setArguments(arguments); metaFunction->setReverseOperator(true); + flags.setFlag(AbstractMetaFunction::Flag::OperatorTrailingClassArgumentRemoved); + if (last.type().passByValue()) + flags.setFlag(AbstractMetaFunction::Flag::OperatorClassArgumentByValue); } + + metaFunction->setFlags(flags); metaFunction->setAccess(Access::Public); setupFunctionDefaults(metaFunction, baseoperandClass); baseoperandClass->addFunction(AbstractMetaFunctionCPtr(metaFunction)); @@ -1923,6 +1932,8 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio } auto *metaFunction = new AbstractMetaFunction; + if (functionItem->isHiddenFriend()) + metaFunction->setFlags(AbstractMetaFunction::Flag::HiddenFriend); metaFunction->setSourceLocation(functionItem->sourceLocation()); if (deprecated) *metaFunction += AbstractMetaFunction::Deprecated; @@ -2880,6 +2891,7 @@ void AbstractMetaBuilderPrivate::inheritTemplateFunctions(AbstractMetaClass *sub std::unique_ptr<AbstractMetaFunction> f(function->copy()); f->setArguments(AbstractMetaArgumentList()); + f->setFlags(f->flags() | AbstractMetaFunction::Flag::InheritedFromTemplate); if (!function->isVoid()) { auto returnType = inheritTemplateType(templateTypes, function->type()); diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp index 4b4399429..4b450370f 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp @@ -99,6 +99,7 @@ public: AddedFunctionPtr m_addedFunction; SourceLocation m_sourceLocation; AbstractMetaFunction::Attributes m_attributes; + AbstractMetaFunction::Flags m_flags; uint m_constant : 1; uint m_reverse : 1; uint m_explicit : 1; @@ -270,6 +271,16 @@ void AbstractMetaFunction::operator-=(AbstractMetaFunction::Attribute attribute) d->m_attributes.setFlag(attribute, false); } +AbstractMetaFunction::Flags AbstractMetaFunction::flags() const +{ + return d->m_flags; +} + +void AbstractMetaFunction::setFlags(Flags f) +{ + d->m_flags = f; +} + /******************************************************************************* * Indicates that this function has a modification that removes it */ @@ -414,6 +425,7 @@ AbstractMetaFunction *AbstractMetaFunction::copy() const { auto *cpy = new AbstractMetaFunction; cpy->setAttributes(attributes()); + cpy->setFlags(flags()); cpy->setAccess(access()); cpy->setName(name()); cpy->setOriginalName(originalName()); diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.h b/sources/shiboken6/ApiExtractor/abstractmetafunction.h index b0e979dc9..410128bf6 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.h +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.h @@ -146,6 +146,19 @@ public: void operator+=(Attribute attribute); void operator-=(Attribute attribute); + enum class Flag { // Internal flags not relevant for comparing functions + // Binary operator whose leading/trailing argument was removed by metabuilder + OperatorLeadingClassArgumentRemoved = 0x1, + OperatorTrailingClassArgumentRemoved = 0x2, + OperatorClassArgumentByValue = 0x4, // The removed class argument was passed by value + InheritedFromTemplate = 0x8, // Inherited from a template in metabuilder + HiddenFriend = 0x10 + }; + Q_DECLARE_FLAGS(Flags, Flag) + + Flags flags() const; + void setFlags(Flags f); + bool isFinalInTargetLang() const; bool isAbstract() const; bool isClassMethod() const; @@ -491,6 +504,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaFunction::CompareResult) Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaFunction::Attributes); +Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaFunction::Flags); + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const AbstractMetaFunction *af); #endif diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp index 427ccc537..b29fee34d 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp @@ -1068,6 +1068,7 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor) } } d->m_currentFunction = d->createFunction(cursor, CodeModel::Normal, false); + d->m_currentFunction->setHiddenFriend(d->m_withinFriendDecl); d->m_scopeStack.at(scope)->addFunction(d->m_currentFunction); } break; diff --git a/sources/shiboken6/ApiExtractor/parser/codemodel.cpp b/sources/shiboken6/ApiExtractor/parser/codemodel.cpp index ac7445c13..4364f695c 100644 --- a/sources/shiboken6/ApiExtractor/parser/codemodel.cpp +++ b/sources/shiboken6/ApiExtractor/parser/codemodel.cpp @@ -1021,6 +1021,16 @@ void _FunctionModelItem::setExplicit(bool isExplicit) m_isExplicit = isExplicit; } +bool _FunctionModelItem::isHiddenFriend() const +{ + return m_isHiddenFriend; +} + +void _FunctionModelItem::setHiddenFriend(bool f) +{ + m_isHiddenFriend = f; +} + bool _FunctionModelItem::isAbstract() const { return m_isAbstract; diff --git a/sources/shiboken6/ApiExtractor/parser/codemodel.h b/sources/shiboken6/ApiExtractor/parser/codemodel.h index 38652aa7e..69e30287b 100644 --- a/sources/shiboken6/ApiExtractor/parser/codemodel.h +++ b/sources/shiboken6/ApiExtractor/parser/codemodel.h @@ -526,6 +526,9 @@ public: bool isExplicit() const; void setExplicit(bool isExplicit); + bool isHiddenFriend() const; + void setHiddenFriend(bool f); + bool isInvokable() const; // Qt void setInvokable(bool isInvokable); // Qt @@ -569,6 +572,7 @@ private: uint m_isAbstract: 1; uint m_isExplicit: 1; uint m_isVariadics: 1; + uint m_isHiddenFriend: 1; uint m_isInvokable : 1; // Qt }; uint m_flags; |
