diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-05-22 10:22:02 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-05-29 09:46:19 +0000 |
commit | b72e4d6bcfb1335ee6dcad9ab30e429b62b8e6e1 (patch) | |
tree | 4c329f649dd14fd89f51ab4382774b9bb199d883 /sources/shiboken2 | |
parent | 16e5f4710e16aec6c46e3f9736f0be3cef3a537d (diff) |
Remove AbstractMetaFunction::invalid()
Change AbstractMetaBuilderPrivate::traverseFunction() to consistently
return 0 if something does not fit. Previously, functions with
half-parsed arguments with the invalid flag set were returned. This
caused strange side effects since the flag was not checked in
all places.
The only relevant information is whether some constructors were
rejected. In that case, no default constructors or default copy
constructors should be generated. This is now determined
by checking the code model function item; the attribute
HasRejectConstructor is introduced for this.
This fixes:
- Make it possible to reject the QTextStreamManipulator
constructor taking a function pointer without having
a default constructor generated:
typedef void (QTextStream::*QTSMFI)(int);
QTextStreamManipulator(QTSMFI m, int a) Q_DECL_NOTHROW
- Implement QtCharts whose class QAbstractSeries has a rejected
constructor.
Change-Id: I6310574ba677dac20699f257340d2c2a55674353
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2')
5 files changed, 35 insertions, 32 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index 58618d923..afdc84e46 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -327,7 +327,7 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(FunctionModelItem item AbstractMetaClass* oldCurrentClass = m_currentClass; m_currentClass = baseoperandClass; AbstractMetaFunction *metaFunction = traverseFunction(item); - if (metaFunction && !metaFunction->isInvalid()) { + if (metaFunction) { // Strip away first argument, since that is the containing object AbstractMetaArgumentList arguments = metaFunction->arguments(); if (firstArgumentIsSelf || unaryOperator) { @@ -376,8 +376,7 @@ void AbstractMetaBuilderPrivate::traverseStreamOperator(FunctionModelItem item) m_currentClass = streamedClass; AbstractMetaFunction *streamFunction = traverseFunction(item); - if (streamFunction && !streamFunction->isInvalid()) { - QString name = item->name(); + if (streamFunction) { streamFunction->setFunctionType(AbstractMetaFunction::GlobalScopeFunction); // Strip first argument, since that is the containing object AbstractMetaArgumentList arguments = streamFunction->arguments(); @@ -572,7 +571,8 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) << QStringLiteral("class '%1' does not have an entry in the type system") .arg(cls->name()); } else { - bool couldAddDefaultCtors = !cls->isFinalInCpp() && !cls->isInterface() && !cls->isNamespace(); + const bool couldAddDefaultCtors = !cls->isFinalInCpp() && !cls->isInterface() && !cls->isNamespace() + && (cls->attributes() & AbstractMetaAttributes::HasRejectedConstructor) == 0; if (couldAddDefaultCtors) { if (!cls->hasConstructors()) cls->addDefaultConstructor(); @@ -1588,14 +1588,18 @@ static bool _fixFunctionModelItemTypes(FunctionModelItem& function, const Abstra return templateTypeFixed; } -AbstractMetaFunctionList AbstractMetaBuilderPrivate::classFunctionList(const ScopeModelItem &scopeItem) +AbstractMetaFunctionList AbstractMetaBuilderPrivate::classFunctionList(const ScopeModelItem &scopeItem, + bool *constructorRejected) { + *constructorRejected = false; AbstractMetaFunctionList result; const FunctionList &scopeFunctionList = scopeItem->functions(); result.reserve(scopeFunctionList.size()); for (const FunctionModelItem &function : scopeFunctionList) { if (AbstractMetaFunction *metaFunction = traverseFunction(function)) result.append(metaFunction); + else if (function->functionType() == CodeModel::Constructor) + *constructorRejected = true; } return result; } @@ -1624,11 +1628,13 @@ private: }; AbstractMetaFunctionList AbstractMetaBuilderPrivate::templateClassFunctionList(const ScopeModelItem &scopeItem, - AbstractMetaClass *metaClass) + AbstractMetaClass *metaClass, + bool *constructorRejected) { AbstractMetaFunctionList result; AbstractMetaFunctionList unchangedFunctions; + *constructorRejected = false; const FunctionList &scopeFunctionList = scopeItem->functions(); result.reserve(scopeFunctionList.size()); unchangedFunctions.reserve(scopeFunctionList.size()); @@ -1640,6 +1646,8 @@ AbstractMetaFunctionList AbstractMetaBuilderPrivate::templateClassFunctionList(c result.append(metaFunction); if (!templateTypeFixed) unchangedFunctions.append(metaFunction); + } else if (function->functionType() == CodeModel::Constructor) { + *constructorRejected = true; } } @@ -1658,10 +1666,13 @@ AbstractMetaFunctionList AbstractMetaBuilderPrivate::templateClassFunctionList(c void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, AbstractMetaClass *metaClass) { - + bool constructorRejected = false; const AbstractMetaFunctionList functions = metaClass->templateArguments().isEmpty() - ? classFunctionList(scopeItem) - : templateClassFunctionList(scopeItem, metaClass); + ? classFunctionList(scopeItem, &constructorRejected) + : templateClassFunctionList(scopeItem, metaClass, &constructorRejected); + + if (constructorRejected) + *metaClass += AbstractMetaAttributes::HasRejectedConstructor; for (AbstractMetaFunction *metaFunction : functions){ metaFunction->setOriginalAttributes(metaFunction->attributes()); @@ -1692,8 +1703,7 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, const bool isInvalidDestructor = metaFunction->isDestructor() && metaFunction->isPrivate(); const bool isInvalidConstructor = metaFunction->isConstructor() - && ((metaFunction->isPrivate() && metaFunction->functionType() == AbstractMetaFunction::ConstructorFunction) - || metaFunction->isInvalid()); + && (metaFunction->isPrivate() && metaFunction->functionType() == AbstractMetaFunction::ConstructorFunction); if ((isInvalidDestructor || isInvalidConstructor) && !metaClass->hasNonPrivateConstructor()) { *metaClass += AbstractMetaAttributes::Final; @@ -1708,7 +1718,6 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, metaClass->setForceShellClass(true); if (!metaFunction->isDestructor() - && !metaFunction->isInvalid() && !(metaFunction->isPrivate() && metaFunction->functionType() == AbstractMetaFunction::ConstructorFunction)) { setupFunctionDefaults(metaFunction, metaClass); @@ -2197,8 +2206,8 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel .arg(originalQualifiedSignatureWithReturn, functionItem->type().toString()); m_rejectedFunctions.insert(originalQualifiedSignatureWithReturn, AbstractMetaBuilder::UnmatchedReturnType); - metaFunction->setInvalid(true); - return metaFunction; + delete metaFunction; + return nullptr; } metaFunction->setType(type); @@ -2237,8 +2246,8 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel const QString rejectedFunctionSignature = originalQualifiedSignatureWithReturn + QLatin1String(": ") + reason; m_rejectedFunctions.insert(rejectedFunctionSignature, AbstractMetaBuilder::UnmatchedArgumentType); - metaFunction->setInvalid(true); - return metaFunction; + delete metaFunction; + return nullptr; } if (metaType == Q_NULLPTR) { @@ -2249,8 +2258,8 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(FunctionModel const QString rejectedFunctionSignature = originalQualifiedSignatureWithReturn + QLatin1String(": ") + reason; m_rejectedFunctions.insert(rejectedFunctionSignature, AbstractMetaBuilder::UnmatchedArgumentType); - metaFunction->setInvalid(true); - return metaFunction; + delete metaFunction; + return nullptr; } AbstractMetaArgument *metaArgument = q->createMetaArgument(); diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h index 96a6fdbfd..8c4e4b185 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h @@ -81,9 +81,11 @@ public: const QSet<QString> &enumsDeclarations); void traverseEnums(ScopeModelItem item, AbstractMetaClass *parent, const QStringList &enumsDeclarations); - AbstractMetaFunctionList classFunctionList(const ScopeModelItem &scopeItem); + AbstractMetaFunctionList classFunctionList(const ScopeModelItem &scopeItem, + bool *constructorRejected); AbstractMetaFunctionList templateClassFunctionList(const ScopeModelItem &scopeItem, - AbstractMetaClass *metaClass); + AbstractMetaClass *metaClass, + bool *constructorRejected); void traverseFunctions(ScopeModelItem item, AbstractMetaClass *parent); void applyFunctionModifications(AbstractMetaFunction* func); void traverseFields(ScopeModelItem item, AbstractMetaClass *parent); diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index 4fa009fd2..db0558a99 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -1212,8 +1212,6 @@ void AbstractMetaFunction::formatDebugVerbose(QDebug &d) const d << "), signature=\"" << minimalSignature() << '"'; if (m_constant) d << " [const]"; - if (m_invalid) - d << " [invalid]"; if (m_reverse) d << " [reverse]"; if (m_userAdded) diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index 4d6d5fb1f..a16f79c30 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -135,6 +135,8 @@ public: Invokable = 0x00040000, + HasRejectedConstructor = 0x00080000, + Final = FinalInTargetLang | FinalInCpp }; Q_DECLARE_FLAGS(Attributes, Attribute) @@ -842,7 +844,6 @@ public: m_declaringClass(0), m_propertySpec(0), m_constant(false), - m_invalid(false), m_reverse(false), m_userAdded(false), m_explicit(false), @@ -1029,14 +1030,6 @@ public: } int actualMinimumArgumentCount() const; - void setInvalid(bool on) - { - m_invalid = on; - } - bool isInvalid() const - { - return m_invalid; - } bool isDeprecated() const; bool isDestructor() const { @@ -1215,7 +1208,6 @@ private: QPropertySpec *m_propertySpec; AbstractMetaArgumentList m_arguments; uint m_constant : 1; - uint m_invalid : 1; uint m_reverse : 1; uint m_userAdded : 1; uint m_explicit : 1; diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 4768ddc88..fb9946be1 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -1004,6 +1004,8 @@ bool ShibokenGenerator::isValueTypeWithCopyConstructorOnly(const AbstractMetaCla { if (!metaClass || !metaClass->typeEntry()->isValue()) return false; + if ((metaClass->attributes() & AbstractMetaAttributes::HasRejectedConstructor) != 0) + return false; AbstractMetaFunctionList ctors = metaClass->queryFunctions(AbstractMetaClass::Constructors); if (ctors.count() != 1) return false; |