diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-26 08:34:20 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-26 08:34:20 +0200 |
commit | 45fa0715398f8d90573552eada0adf2e4eb5e763 (patch) | |
tree | 82ec6ef675f8fd77204667354f92b954e2df00b4 /sources/shiboken2 | |
parent | 54c3abd8774f479535d0b8741a3c30d1e7ee8548 (diff) | |
parent | 4ccfd8de6462ce2ed938587eb0518038640c310f (diff) |
Merge remote-tracking branch 'origin/5.12' into 5.13
Change-Id: I5bfa45782938d3bf43e16164f1ecd69f53bfcf8e
Diffstat (limited to 'sources/shiboken2')
106 files changed, 745 insertions, 767 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index d3a232546..bb9b94a5b 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -112,8 +112,7 @@ static QStringList parseTemplateType(const QString &name) { } AbstractMetaBuilderPrivate::AbstractMetaBuilderPrivate() : - m_logDirectory(QLatin1String(".") + QDir::separator()), - m_skipDeprecated(false) + m_logDirectory(QLatin1String(".") + QDir::separator()) { } @@ -442,7 +441,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) ReportHandler::startProgress("Generating enum model (" + QByteArray::number(enums.size()) + ")..."); for (const EnumModelItem &item : enums) { - AbstractMetaEnum *metaEnum = traverseEnum(item, 0, QSet<QString>()); + AbstractMetaEnum *metaEnum = traverseEnum(item, nullptr, QSet<QString>()); if (metaEnum) { if (metaEnum->typeEntry()->generateCode()) m_globalEnums << metaEnum; @@ -743,14 +742,14 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseNamespace(const FileModel if (TypeDatabase::instance()->isClassRejected(namespaceName)) { m_rejectedClasses.insert(namespaceName, AbstractMetaBuilder::GenerationDisabled); - return 0; + return nullptr; } auto type = TypeDatabase::instance()->findNamespaceType(namespaceName, namespaceItem->fileName()); if (!type) { qCWarning(lcShiboken).noquote().nospace() << QStringLiteral("namespace '%1' does not have a type entry").arg(namespaceName); - return 0; + return nullptr; } // Continue populating namespace? @@ -862,7 +861,7 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & if (typeEntry) typeEntry->setCodeGeneration(TypeEntry::GenerateNothing); m_rejectedEnums.insert(qualifiedName + rejectReason, AbstractMetaBuilder::GenerationDisabled); - return 0; + return nullptr; } const bool rejectionWarning = !enclosing @@ -884,7 +883,7 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & return nullptr; } - AbstractMetaEnum *metaEnum = new AbstractMetaEnum; + auto *metaEnum = new AbstractMetaEnum; metaEnum->setEnumKind(enumItem->enumKind()); metaEnum->setSigned(enumItem->isSigned()); if (enumsDeclarations.contains(qualifiedName) @@ -892,7 +891,7 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & metaEnum->setHasQEnumsDeclaration(true); } - EnumTypeEntry *enumTypeEntry = static_cast<EnumTypeEntry *>(typeEntry); + auto *enumTypeEntry = static_cast<EnumTypeEntry *>(typeEntry); metaEnum->setTypeEntry(enumTypeEntry); switch (enumItem->accessPolicy()) { case CodeModel::Public: @@ -915,7 +914,7 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & const EnumeratorList &enums = enumItem->enumerators(); for (const EnumeratorModelItem &value : enums) { - AbstractMetaEnumValue *metaEnumValue = new AbstractMetaEnumValue; + auto *metaEnumValue = new AbstractMetaEnumValue; metaEnumValue->setName(value->name()); // Deciding the enum value... @@ -964,7 +963,7 @@ AbstractMetaEnum *AbstractMetaBuilderPrivate::traverseEnum(const EnumModelItem & return metaEnum; } -AbstractMetaClass *AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelItem &dom, +AbstractMetaClass *AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelItem &, const TypeDefModelItem &typeDef, AbstractMetaClass *currentClass) { @@ -985,16 +984,16 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelIt if (ptype) { QString typeDefName = typeDef->type().qualifiedName()[0]; ptype->setReferencedTypeEntry(types->findPrimitiveType(typeDefName)); - return 0; + return nullptr; } // If we haven't specified anything for the typedef, then we don't care ComplexTypeEntry *type = types->findComplexType(fullClassName); if (!type) - return 0; + return nullptr; - AbstractMetaClass *metaClass = new AbstractMetaClass; + auto *metaClass = new AbstractMetaClass; metaClass->setTypeDef(true); metaClass->setTypeEntry(type); metaClass->setBaseClassNames(QStringList(typeDef->type().toString())); @@ -1015,7 +1014,7 @@ void AbstractMetaBuilderPrivate::traverseTypesystemTypedefs() const auto &entries = TypeDatabase::instance()->typedefEntries(); for (auto it = entries.begin(), end = entries.end(); it != end; ++it) { TypedefEntry *te = it.value(); - AbstractMetaClass *metaClass = new AbstractMetaClass; + auto *metaClass = new AbstractMetaClass; metaClass->setTypeDef(true); metaClass->setTypeEntry(te->target()); metaClass->setBaseClassNames(QStringList(te->sourceType())); @@ -1054,10 +1053,10 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem } if (reason != AbstractMetaBuilder::NoReason) { m_rejectedClasses.insert(fullClassName, reason); - return 0; + return nullptr; } - AbstractMetaClass *metaClass = new AbstractMetaClass; + auto *metaClass = new AbstractMetaClass; metaClass->setTypeEntry(type); if (classItem->isFinal()) @@ -1129,7 +1128,7 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem return metaClass; } -void AbstractMetaBuilderPrivate::traverseScopeMembers(ScopeModelItem item, +void AbstractMetaBuilderPrivate::traverseScopeMembers(const ScopeModelItem &item, AbstractMetaClass *metaClass) { // Classes/Namespace members @@ -1142,7 +1141,7 @@ void AbstractMetaBuilderPrivate::traverseScopeMembers(ScopeModelItem item, traverseClassMembers(ci); } -void AbstractMetaBuilderPrivate::traverseClassMembers(ClassModelItem item) +void AbstractMetaBuilderPrivate::traverseClassMembers(const ClassModelItem &item) { AbstractMetaClass *metaClass = m_itemToClass.value(item.data()); if (!metaClass) @@ -1152,7 +1151,7 @@ void AbstractMetaBuilderPrivate::traverseClassMembers(ClassModelItem item) traverseScopeMembers(item, metaClass); } -void AbstractMetaBuilderPrivate::traverseNamespaceMembers(NamespaceModelItem item) +void AbstractMetaBuilderPrivate::traverseNamespaceMembers(const NamespaceModelItem &item) { AbstractMetaClass *metaClass = m_itemToClass.value(item.data()); if (!metaClass) @@ -1186,20 +1185,20 @@ AbstractMetaField *AbstractMetaBuilderPrivate::traverseField(const VariableModel // Ignore friend decl. if (field->isFriend()) - return 0; + return nullptr; if (field->accessPolicy() == CodeModel::Private) - return 0; + return nullptr; QString rejectReason; if (TypeDatabase::instance()->isFieldRejected(className, fieldName, &rejectReason)) { m_rejectedFields.insert(qualifiedFieldSignatureWithType(className, field) + rejectReason, AbstractMetaBuilder::GenerationDisabled); - return 0; + return nullptr; } - AbstractMetaField *metaField = new AbstractMetaField; + auto *metaField = new AbstractMetaField; metaField->setName(fieldName); metaField->setEnclosingClass(cls); @@ -1214,12 +1213,12 @@ AbstractMetaField *AbstractMetaBuilderPrivate::traverseField(const VariableModel .arg(cls->name(), fieldName, type); } delete metaField; - return 0; + return nullptr; } metaField->setType(metaType); - AbstractMetaAttributes::Attributes attr = 0; + AbstractMetaAttributes::Attributes attr = nullptr; if (field->isStatic()) attr |= AbstractMetaAttributes::Static; @@ -1283,7 +1282,7 @@ void AbstractMetaBuilderPrivate::fixReturnTypeOfConversionOperator(AbstractMetaF if (!retType) return; - AbstractMetaType *metaType = new AbstractMetaType; + auto *metaType = new AbstractMetaType; metaType->setTypeEntry(retType); metaFunction->replaceType(metaType); } @@ -1317,7 +1316,7 @@ AbstractMetaFunctionList AbstractMetaBuilderPrivate::classFunctionList(const Sco AbstractMetaClass::Attributes *constructorAttributes, AbstractMetaClass *currentClass) { - *constructorAttributes = 0; + *constructorAttributes = nullptr; AbstractMetaFunctionList result; const FunctionList &scopeFunctionList = scopeItem->functions(); result.reserve(scopeFunctionList.size()); @@ -1370,10 +1369,11 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, if (metaClass->isNamespace()) *metaFunction += AbstractMetaAttributes::Static; - QPropertySpec *read = 0; + QPropertySpec *read = nullptr; if (!metaFunction->isSignal() && (read = metaClass->propertySpecForRead(metaFunction->name()))) { // Property reader must be in the form "<type> name()" - if (metaFunction->type() && (read->type() == metaFunction->type()->typeEntry()) && (metaFunction->arguments().size() == 0)) { + if (metaFunction->type() && (read->type() == metaFunction->type()->typeEntry()) + && metaFunction->arguments().isEmpty()) { *metaFunction += AbstractMetaAttributes::PropertyReader; metaFunction->setPropertySpec(read); } @@ -1435,7 +1435,7 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem, } if (!metaFunction->ownerClass()) { delete metaFunction; - metaFunction = 0; + metaFunction = nullptr; } } @@ -1605,13 +1605,13 @@ void AbstractMetaBuilderPrivate::traverseEnums(const ScopeModelItem &scopeItem, AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFunctionPtr &addedFunc) { - return traverseFunction(addedFunc, 0); + return traverseFunction(addedFunc, nullptr); } AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFunctionPtr &addedFunc, AbstractMetaClass *metaClass) { - AbstractMetaFunction *metaFunction = new AbstractMetaFunction(addedFunc); + auto *metaFunction = new AbstractMetaFunction(addedFunc); metaFunction->setType(translateType(addedFunc->returnType())); @@ -1620,7 +1620,7 @@ AbstractMetaFunction* AbstractMetaBuilderPrivate::traverseFunction(const AddedFu for (int i = 0; i < args.count(); ++i) { const AddedFunction::TypeInfo& typeInfo = args.at(i).typeInfo; - AbstractMetaArgument *metaArg = new AbstractMetaArgument; + auto *metaArg = new AbstractMetaArgument; AbstractMetaType *type = translateType(typeInfo); if (Q_UNLIKELY(!type)) { qCWarning(lcShiboken, @@ -1834,7 +1834,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio return nullptr; if (functionItem->isFriend()) - return 0; + return nullptr; const bool deprecated = functionItem->isDeprecated(); if (deprecated && m_skipDeprecated) { @@ -1843,7 +1843,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio return nullptr; } - AbstractMetaFunction *metaFunction = new AbstractMetaFunction; + auto *metaFunction = new AbstractMetaFunction; if (deprecated) *metaFunction += AbstractMetaAttributes::Deprecated; @@ -1958,7 +1958,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio } break; } - Q_ASSERT(metaType == 0); + Q_ASSERT(metaType == nullptr); const QString reason = msgUnmatchedParameterType(arg, i, errorMessage); qCWarning(lcShiboken, "%s", qPrintable(msgSkippingFunction(functionItem, originalQualifiedSignatureWithReturn, reason))); @@ -1969,7 +1969,7 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio return nullptr; } - AbstractMetaArgument *metaArgument = new AbstractMetaArgument; + auto *metaArgument = new AbstractMetaArgument; metaArgument->setType(metaType); metaArgument->setName(arg->name()); @@ -2074,7 +2074,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction: QString typeName = typeInfo.name; if (typeName == QLatin1String("void")) - return 0; + return nullptr; type = typeDb->findType(typeName); @@ -2116,7 +2116,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction: qFatal("%s", qPrintable(msg)); } - AbstractMetaType *metaType = new AbstractMetaType; + auto *metaType = new AbstractMetaType; metaType->setTypeEntry(type); metaType->setIndirections(typeInfo.indirections); if (typeInfo.isReference) @@ -2135,7 +2135,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const AddedFunction: static const TypeEntry* findTypeEntryUsingContext(const AbstractMetaClass* metaClass, const QString& qualifiedName) { - const TypeEntry* type = 0; + const TypeEntry* type = nullptr; QStringList context = metaClass->qualifiedCppName().split(colonColon()); while (!type && !context.isEmpty()) { type = TypeDatabase::instance()->findType(context.join(colonColon()) + colonColon() + qualifiedName); @@ -2230,7 +2230,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo } for (int i = typeInfo.arrayElements().size() - 1; i >= 0; --i) { - AbstractMetaType *arrayType = new AbstractMetaType; + auto *arrayType = new AbstractMetaType; arrayType->setArrayElementType(elementType); const QString &arrayElement = typeInfo.arrayElements().at(i); if (!arrayElement.isEmpty()) { @@ -2269,7 +2269,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo typeInfo.clearInstantiations(); } - const TypeEntry *type = 0; + const TypeEntry *type = nullptr; // 5. Try to find the type // 5.1 - Try first using the current scope @@ -2320,7 +2320,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo // These are only implicit and should not appear in code... Q_ASSERT(!type->isInterface()); - AbstractMetaType *metaType = new AbstractMetaType; + auto *metaType = new AbstractMetaType; metaType->setTypeEntry(type); metaType->setIndirectionsV(typeInfo.indirectionsV()); metaType->setReferenceType(typeInfo.referenceType()); @@ -2538,7 +2538,7 @@ AbstractMetaClass* AbstractMetaBuilderPrivate::findTemplateClass(const QString & if (info) *info = parsed; - AbstractMetaClass* templ = 0; + AbstractMetaClass *templ = nullptr; for (AbstractMetaClass *c : qAsConst(m_templates)) { if (c->typeEntry()->name() == qualifiedName) { templ = c; @@ -2556,7 +2556,7 @@ AbstractMetaClass* AbstractMetaBuilderPrivate::findTemplateClass(const QString & *baseContainerType = types->findContainerType(qualifiedName); } - return 0; + return nullptr; } AbstractMetaClassList AbstractMetaBuilderPrivate::getBaseClasses(const AbstractMetaClass *metaClass) const @@ -2564,7 +2564,7 @@ AbstractMetaClassList AbstractMetaBuilderPrivate::getBaseClasses(const AbstractM AbstractMetaClassList baseClasses; const QStringList &baseClassNames = metaClass->baseClassNames(); for (const QString& parent : baseClassNames) { - AbstractMetaClass* cls = 0; + AbstractMetaClass *cls = nullptr; if (parent.contains(QLatin1Char('<'))) cls = findTemplateClass(parent, metaClass); else @@ -2602,7 +2602,7 @@ AbstractMetaType * returned->setOriginalTemplateType(metaType); if (returned->typeEntry()->isTemplateArgument()) { - const TemplateArgumentEntry* tae = static_cast<const TemplateArgumentEntry*>(returned->typeEntry()); + const auto *tae = static_cast<const TemplateArgumentEntry*>(returned->typeEntry()); // If the template is intantiated with void we special case this as rejecting the functions that use this // parameter from the instantiation. @@ -2684,7 +2684,7 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass, } if (t) { - AbstractMetaType *temporaryType = new AbstractMetaType; + auto *temporaryType = new AbstractMetaType; temporaryType->setTypeEntry(t); temporaryType->setConstant(i.isConstant()); temporaryType->setReferenceType(i.referenceType()); @@ -2836,7 +2836,7 @@ void AbstractMetaBuilderPrivate::parseQ_Property(AbstractMetaClass *metaClass, continue; } - QPropertySpec* spec = new QPropertySpec(type->typeEntry()); + auto *spec = new QPropertySpec(type->typeEntry()); spec->setName(propertyTokens.at(1).toString()); spec->setIndex(i); @@ -2866,7 +2866,7 @@ static AbstractMetaFunction* findCopyCtor(AbstractMetaClass* cls) if (t == AbstractMetaFunction::CopyConstructorFunction || t == AbstractMetaFunction::AssignmentOperatorFunction) return f; } - return 0; + return nullptr; } void AbstractMetaBuilderPrivate::setupClonable(AbstractMetaClass *cls) @@ -3199,13 +3199,12 @@ template <class Container> static void debugFormatSequence(QDebug &d, const char *key, const Container& c, const char *separator = ", ") { - typedef typename Container::const_iterator ConstIt; if (c.isEmpty()) return; - const ConstIt begin = c.begin(); - const ConstIt end = c.end(); + const auto begin = c.begin(); + const auto end = c.end(); d << "\n " << key << '[' << c.size() << "]=("; - for (ConstIt it = begin; it != end; ++it) { + for (auto it = begin; it != end; ++it) { if (it != begin) d << separator; d << *it; diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h index 1fd5f3c34..fec2eddb9 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h @@ -43,6 +43,8 @@ class TypeDatabase; class AbstractMetaBuilderPrivate { public: + Q_DISABLE_COPY(AbstractMetaBuilderPrivate) + AbstractMetaBuilderPrivate(); ~AbstractMetaBuilderPrivate(); @@ -71,9 +73,9 @@ public: AbstractMetaClass *traverseClass(const FileModelItem &dom, const ClassModelItem &item, AbstractMetaClass *currentClass); - void traverseScopeMembers(ScopeModelItem item, AbstractMetaClass *metaClass); - void traverseClassMembers(ClassModelItem scopeItem); - void traverseNamespaceMembers(NamespaceModelItem scopeItem); + void traverseScopeMembers(const ScopeModelItem &item, AbstractMetaClass *metaClass); + void traverseClassMembers(const ClassModelItem &scopeItem); + void traverseNamespaceMembers(const NamespaceModelItem &scopeItem); bool setupInheritance(AbstractMetaClass *metaClass); AbstractMetaClass *traverseNamespace(const FileModelItem &dom, const NamespaceModelItem &item); @@ -173,7 +175,7 @@ public: AbstractMetaFunctionList m_globalFunctions; AbstractMetaEnumList m_globalEnums; - typedef QMap<QString, AbstractMetaBuilder::RejectReason> RejectMap; + using RejectMap = QMap<QString, AbstractMetaBuilder::RejectReason>; RejectMap m_rejectedClasses; RejectMap m_rejectedEnums; @@ -190,7 +192,7 @@ public: QFileInfo m_globalHeader; QStringList m_headerPaths; mutable QHash<QString, Include> m_resolveIncludeHash; - bool m_skipDeprecated; + bool m_skipDeprecated = false; }; #endif // ABSTRACTMETBUILDER_P_H diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index 7bcad504d..455140e59 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -188,7 +188,7 @@ QString AbstractMetaType::fullName() const AbstractMetaType *AbstractMetaType::copy() const { - AbstractMetaType *cpy = new AbstractMetaType; + auto *cpy = new AbstractMetaType; cpy->setTypeUsagePattern(typeUsagePattern()); cpy->setConstant(isConstant()); @@ -198,9 +198,9 @@ AbstractMetaType *AbstractMetaType::copy() const cpy->setInstantiations(instantiations()); cpy->setArrayElementCount(arrayElementCount()); cpy->setOriginalTypeDescription(originalTypeDescription()); - cpy->setOriginalTemplateType(originalTemplateType() ? originalTemplateType()->copy() : 0); + cpy->setOriginalTemplateType(originalTemplateType() ? originalTemplateType()->copy() : nullptr); - cpy->setArrayElementType(arrayElementType() ? arrayElementType()->copy() : 0); + cpy->setArrayElementType(arrayElementType() ? arrayElementType()->copy() : nullptr); cpy->setTypeEntry(typeEntry()); @@ -427,7 +427,7 @@ void AbstractMetaArgument::assignMetaArgument(const AbstractMetaArgument &other) AbstractMetaArgument *AbstractMetaArgument::copy() const { - AbstractMetaArgument *copy = new AbstractMetaArgument; + auto *copy = new AbstractMetaArgument; copy->assignMetaArgument(*this); return copy; } @@ -519,7 +519,7 @@ bool AbstractMetaFunction::operator<(const AbstractMetaFunction &other) const */ AbstractMetaFunction::CompareResult AbstractMetaFunction::compareTo(const AbstractMetaFunction *other) const { - CompareResult result = 0; + CompareResult result = nullptr; // Enclosing class... if (ownerClass() == other->ownerClass()) @@ -587,7 +587,7 @@ AbstractMetaFunction::CompareResult AbstractMetaFunction::compareTo(const Abstra AbstractMetaFunction *AbstractMetaFunction::copy() const { - AbstractMetaFunction *cpy = new AbstractMetaFunction; + auto *cpy = new AbstractMetaFunction; cpy->assignMetaAttributes(*this); cpy->setName(name()); cpy->setOriginalName(originalName()); @@ -1406,9 +1406,9 @@ AbstractMetaClass *AbstractMetaClass::extractInterface() Q_ASSERT(typeEntry()->designatedInterface()); if (!m_extractedInterface) { - AbstractMetaClass *iface = new AbstractMetaClass; + auto *iface = new AbstractMetaClass; iface->setAttributes(attributes()); - iface->setBaseClass(0); + iface->setBaseClass(nullptr); iface->setTypeEntry(typeEntry()->designatedInterface()); @@ -1709,30 +1709,32 @@ bool AbstractMetaClass::hasProtectedMembers() const QPropertySpec *AbstractMetaClass::propertySpecForRead(const QString &name) const { - for (int i = 0; i < m_propertySpecs.size(); ++i) - if (name == m_propertySpecs.at(i)->read()) - return m_propertySpecs.at(i); - return 0; + for (const auto &propertySpec : m_propertySpecs) { + if (name == propertySpec->read()) + return propertySpec; + } + return nullptr; } QPropertySpec *AbstractMetaClass::propertySpecForWrite(const QString &name) const { - for (int i = 0; i < m_propertySpecs.size(); ++i) - if (name == m_propertySpecs.at(i)->write()) - return m_propertySpecs.at(i); - return 0; + for (const auto &propertySpec : m_propertySpecs) { + if (name == propertySpec->write()) + return propertySpec; + } + return nullptr; } QPropertySpec *AbstractMetaClass::propertySpecForReset(const QString &name) const { - for (int i = 0; i < m_propertySpecs.size(); ++i) { - if (name == m_propertySpecs.at(i)->reset()) - return m_propertySpecs.at(i); + for (const auto &propertySpec : m_propertySpecs) { + if (name == propertySpec->reset()) + return propertySpec; } - return 0; + return nullptr; } -typedef QHash<const AbstractMetaClass *, AbstractMetaTypeList> AbstractMetaClassBaseTemplateInstantiationsMap; +using AbstractMetaClassBaseTemplateInstantiationsMap = QHash<const AbstractMetaClass *, AbstractMetaTypeList>; Q_GLOBAL_STATIC(AbstractMetaClassBaseTemplateInstantiationsMap, metaClassBaseTemplateInstantiations); bool AbstractMetaClass::hasTemplateBaseClassInstantiations() const @@ -1782,7 +1784,7 @@ AbstractMetaField::~AbstractMetaField() AbstractMetaField *AbstractMetaField::copy() const { - AbstractMetaField *returned = new AbstractMetaField; + auto *returned = new AbstractMetaField; returned->assignMetaVariable(*this); returned->assignMetaAttributes(*this); returned->setEnclosingClass(nullptr); @@ -1822,7 +1824,7 @@ static QString upCaseFirst(const QString &str) static AbstractMetaFunction *createXetter(const AbstractMetaField *g, const QString &name, AbstractMetaAttributes::Attributes type) { - AbstractMetaFunction *f = new AbstractMetaFunction; + auto *f = new AbstractMetaFunction; f->setName(name); f->setOriginalName(name); @@ -1880,7 +1882,7 @@ const AbstractMetaFunction *AbstractMetaField::setter() const QLatin1String("set") + upCaseFirst(name()), AbstractMetaAttributes::SetterFunction); AbstractMetaArgumentList arguments; - AbstractMetaArgument *argument = new AbstractMetaArgument; + auto *argument = new AbstractMetaArgument; argument->setType(type()->copy()); argument->setName(name()); arguments.append(argument); @@ -2000,7 +2002,7 @@ bool AbstractMetaClass::hasPrivateCopyConstructor() const void AbstractMetaClass::addDefaultConstructor() { - AbstractMetaFunction *f = new AbstractMetaFunction; + auto *f = new AbstractMetaFunction; f->setOriginalName(name()); f->setName(name()); f->setOwnerClass(this); @@ -2263,9 +2265,9 @@ static void addExtraIncludeForType(AbstractMetaClass *metaClass, const AbstractM return; Q_ASSERT(metaClass); - const TypeEntry *entry = (type ? type->typeEntry() : 0); + const TypeEntry *entry = (type ? type->typeEntry() : nullptr); if (entry && entry->isComplex()) { - const ComplexTypeEntry *centry = static_cast<const ComplexTypeEntry *>(entry); + const auto *centry = static_cast<const ComplexTypeEntry *>(entry); ComplexTypeEntry *class_entry = metaClass->typeEntry(); if (class_entry && centry->include().isValid()) class_entry->addExtraInclude(centry->include()); @@ -2324,9 +2326,7 @@ void AbstractMetaClass::fixFunctions() } QSet<AbstractMetaFunction *> funcsToAdd; - for (int sfi = 0; sfi < superFuncs.size(); ++sfi) { - AbstractMetaFunction *sf = superFuncs.at(sfi); - + for (auto sf : qAsConst(superFuncs)) { if (sf->isRemovedFromAllLanguages(sf->implementingClass())) continue; @@ -2589,7 +2589,7 @@ AbstractMetaEnum *AbstractMetaClass::findEnum(const AbstractMetaClassList &class qCWarning(lcShiboken).noquote().nospace() << QStringLiteral("AbstractMeta::findEnum(), unknown class '%1' in '%2'") .arg(className, entry->qualifiedCppName()); - return 0; + return nullptr; } return metaClass->findEnum(enumName); @@ -2601,8 +2601,8 @@ AbstractMetaEnumValue *AbstractMetaClass::findEnumValue(const AbstractMetaClassL const QVector<QStringRef> lst = name.splitRef(QLatin1String("::")); if (lst.size() > 1) { - const QStringRef prefixName = lst.at(0); - const QStringRef enumName = lst.at(1); + const QStringRef &prefixName = lst.at(0); + const QStringRef &enumName = lst.at(1); if (AbstractMetaClass *cl = findClass(classes, prefixName.toString())) return cl->findEnumValue(enumName.toString()); } @@ -2626,7 +2626,7 @@ AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &cla const QString &name) { if (name.isEmpty()) - return 0; + return nullptr; for (AbstractMetaClass *c : classes) { if (c->qualifiedCppName() == name) @@ -2643,7 +2643,7 @@ AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &cla return c; } - return 0; + return nullptr; } AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &classes, @@ -2653,7 +2653,7 @@ AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &cla if (c->typeEntry() == typeEntry) return c; } - return 0; + return nullptr; } #ifndef QT_NO_DEBUG_STREAM diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index e8ec21f48..afb4e5fbd 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -72,7 +72,7 @@ public: Target }; - Documentation() {} + Documentation() = default; Documentation(const QString& value, Format fmt = Documentation::Native) : m_data(value.trimmed()), m_format(fmt) {} @@ -105,9 +105,10 @@ private: class AbstractMetaAttributes { - Q_DISABLE_COPY(AbstractMetaAttributes) Q_GADGET public: + Q_DISABLE_COPY(AbstractMetaAttributes) + AbstractMetaAttributes(); virtual ~AbstractMetaAttributes(); @@ -292,7 +293,7 @@ class AbstractMetaType { Q_GADGET public: - typedef QVector<Indirection> Indirections; + using Indirections = QVector<Indirection>; enum TypeUsagePattern { InvalidPattern, @@ -587,13 +588,12 @@ public: } void setType(AbstractMetaType *type) { - Q_ASSERT(m_type == 0); + Q_ASSERT(m_type == nullptr); m_type = type; } void replaceType(AbstractMetaType *type) { - if (m_type) - delete m_type; + delete m_type; m_type = type; } @@ -896,14 +896,13 @@ public: } void setType(AbstractMetaType *type) { - Q_ASSERT(m_type == 0); + Q_ASSERT(m_type == nullptr); m_type = type; } void replaceType(AbstractMetaType *type) { - if (m_type) - delete m_type; + delete m_type; m_type = type; } @@ -1053,12 +1052,12 @@ public: * \return true if there is some modification to function signature */ bool hasSignatureModifications() const; - FunctionModificationList modifications(const AbstractMetaClass* implementor = 0) const; + FunctionModificationList modifications(const AbstractMetaClass* implementor = nullptr) const; /** * Return the argument name if there is a modification the renamed value will be returned */ - QString argumentName(int index, bool create = true, const AbstractMetaClass *cl = 0) const; + QString argumentName(int index, bool create = true, const AbstractMetaClass *cl = nullptr) const; void setPropertySpec(QPropertySpec *spec) { @@ -1132,7 +1131,7 @@ QDebug operator<<(QDebug d, const AbstractMetaFunction *af); class AbstractMetaEnumValue { public: - AbstractMetaEnumValue() {} + AbstractMetaEnumValue() = default; EnumValue value() const { @@ -1507,7 +1506,7 @@ public: m_innerClasses << cl; } - void setInnerClasses(AbstractMetaClassList innerClasses) + void setInnerClasses(const AbstractMetaClassList &innerClasses) { m_innerClasses = innerClasses; } diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang_typedefs.h b/sources/shiboken2/ApiExtractor/abstractmetalang_typedefs.h index 9ff11d44e..617ebcf4f 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang_typedefs.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang_typedefs.h @@ -39,13 +39,13 @@ class AbstractMetaEnumValue; class AbstractMetaFunction; class AbstractMetaType; -typedef QVector<AbstractMetaArgument *> AbstractMetaArgumentList; -typedef QVector<AbstractMetaClass *> AbstractMetaClassList; -typedef QVector<AbstractMetaEnum *> AbstractMetaEnumList; -typedef QVector<AbstractMetaEnumValue *> AbstractMetaEnumValueList; -typedef QVector<AbstractMetaField *> AbstractMetaFieldList; -typedef QVector<AbstractMetaFunction *> AbstractMetaFunctionList; -typedef QVector<AbstractMetaType *> AbstractMetaTypeList; -typedef QVector<const AbstractMetaType *> AbstractMetaTypeCList; +using AbstractMetaArgumentList = QVector<AbstractMetaArgument *>; +using AbstractMetaClassList = QVector<AbstractMetaClass *>; +using AbstractMetaEnumList = QVector<AbstractMetaEnum *>; +using AbstractMetaEnumValueList = QVector<AbstractMetaEnumValue *>; +using AbstractMetaFieldList = QVector<AbstractMetaField *>; +using AbstractMetaFunctionList = QVector<AbstractMetaFunction *>; +using AbstractMetaTypeList = QVector<AbstractMetaType *>; +using AbstractMetaTypeCList = QVector<const AbstractMetaType *>; #endif // ABSTRACTMETALANG_TYPEDEFS_H diff --git a/sources/shiboken2/ApiExtractor/apiextractor.cpp b/sources/shiboken2/ApiExtractor/apiextractor.cpp index fbe7664e9..78fa9e313 100644 --- a/sources/shiboken2/ApiExtractor/apiextractor.cpp +++ b/sources/shiboken2/ApiExtractor/apiextractor.cpp @@ -43,7 +43,7 @@ #include "typedatabase.h" #include "typesystem.h" -ApiExtractor::ApiExtractor() : m_builder(0) +ApiExtractor::ApiExtractor() { // Environment TYPESYSTEMPATH QString envTypesystemPaths = QFile::decodeName(qgetenv("TYPESYSTEMPATH")); @@ -116,7 +116,7 @@ void ApiExtractor::setSilent ( bool value ) bool ApiExtractor::setApiVersion(const QString& package, const QString &version) { - return TypeDatabase::instance()->setApiVersion(package, version); + return TypeDatabase::setApiVersion(package, version); } void ApiExtractor::setDropTypeEntries(QString dropEntries) @@ -168,7 +168,7 @@ ContainerTypeEntryList ApiExtractor::containerTypes() const static const AbstractMetaEnum* findEnumOnClasses(AbstractMetaClassList metaClasses, const EnumTypeEntry* typeEntry) { - const AbstractMetaEnum* result = 0; + const AbstractMetaEnum *result = nullptr; for (const AbstractMetaClass* metaClass : qAsConst(metaClasses)) { const AbstractMetaEnumList &enums = metaClass->enums(); for (const AbstractMetaEnum *metaEnum : enums) { @@ -247,7 +247,7 @@ LanguageLevel ApiExtractor::languageLevel() const return m_languageLevel; } -void ApiExtractor::setLanguageLevel(const LanguageLevel languageLevel) +void ApiExtractor::setLanguageLevel(LanguageLevel languageLevel) { m_languageLevel = languageLevel; } @@ -256,13 +256,11 @@ void ApiExtractor::setLanguageLevel(const LanguageLevel languageLevel) template <class Container> static void debugFormatSequence(QDebug &d, const char *key, const Container& c) { - typedef typename Container::const_iterator ConstIt; if (c.isEmpty()) return; - const ConstIt begin = c.begin(); - const ConstIt end = c.end(); + const auto begin = c.begin(); d << "\n " << key << '[' << c.size() << "]=("; - for (ConstIt it = begin; it != end; ++it) { + for (auto it = begin, end = c.end(); it != end; ++it) { if (it != begin) d << ", "; d << *it; diff --git a/sources/shiboken2/ApiExtractor/apiextractor.h b/sources/shiboken2/ApiExtractor/apiextractor.h index 3eb90e748..c8f50f2a5 100644 --- a/sources/shiboken2/ApiExtractor/apiextractor.h +++ b/sources/shiboken2/ApiExtractor/apiextractor.h @@ -58,6 +58,8 @@ QT_END_NAMESPACE class ApiExtractor { public: + Q_DISABLE_COPY(ApiExtractor) + ApiExtractor(); ~ApiExtractor(); @@ -78,7 +80,7 @@ public: bool setApiVersion(const QString& package, const QString& version); void setDropTypeEntries(QString dropEntries); LanguageLevel languageLevel() const; - void setLanguageLevel(const LanguageLevel languageLevel); + void setLanguageLevel(LanguageLevel languageLevel); AbstractMetaEnumList globalEnums() const; AbstractMetaFunctionList globalFunctions() const; @@ -97,17 +99,15 @@ private: QString m_typeSystemFileName; QString m_cppFileName; HeaderPaths m_includePaths; - AbstractMetaBuilder* m_builder; + AbstractMetaBuilder* m_builder = nullptr; QString m_logDirectory; LanguageLevel m_languageLevel = LanguageLevel::Default; bool m_skipDeprecated = false; - // disable copy - ApiExtractor(const ApiExtractor&); - ApiExtractor& operator=(const ApiExtractor&); #ifndef QT_NO_DEBUG_STREAM friend QDebug operator<<(QDebug d, const ApiExtractor &ae); #endif }; #endif // APIEXTRACTOR_H + diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp index 3ced0e06c..8d1b4debf 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp @@ -144,9 +144,9 @@ static bool isSigned(CXTypeKind kind) class BuilderPrivate { public: - typedef QHash<CXCursor, ClassModelItem> CursorClassHash; - typedef QHash<CXCursor, TypeDefModelItem> CursorTypedefHash; - typedef QHash<CXType, TypeInfo> TypeInfoHash; + using CursorClassHash = QHash<CXCursor, ClassModelItem>; + using CursorTypedefHash = QHash<CXCursor, TypeDefModelItem>; + using TypeInfoHash = QHash<CXType, TypeInfo>; explicit BuilderPrivate(BaseVisitor *bv) : m_baseVisitor(bv), m_model(new CodeModel) { @@ -645,11 +645,9 @@ static inline CXCursor definitionFromTypeRef(const CXCursor &typeRefCursor) template <class Item> // ArgumentModelItem, VariableModelItem void BuilderPrivate::qualifyTypeDef(const CXCursor &typeRefCursor, const QSharedPointer<Item> &item) const { - typedef typename CursorTypedefHash::const_iterator ConstIt; - TypeInfo type = item->type(); if (type.qualifiedName().size() == 1) { // item's type is unqualified. - const ConstIt it = m_cursorTypedefHash.constFind(definitionFromTypeRef(typeRefCursor)); + const auto it = m_cursorTypedefHash.constFind(definitionFromTypeRef(typeRefCursor)); if (it != m_cursorTypedefHash.constEnd() && !it.value()->scope().isEmpty()) { type.setQualifiedName(it.value()->scope() + type.qualifiedName()); item->setType(type); diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h index 2c4dd0e03..fa79acb2a 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h +++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.h @@ -39,6 +39,8 @@ class BuilderPrivate; class Builder : public BaseVisitor { public: + Q_DISABLE_COPY(Builder) + Builder(); ~Builder(); diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangparser.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangparser.cpp index e116f8b83..6303d09e5 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangparser.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangparser.cpp @@ -119,7 +119,7 @@ QString BaseVisitor::getCodeSnippetString(const CXCursor &cursor) static CXChildVisitResult visitorCallback(CXCursor cursor, CXCursor /* parent */, CXClientData clientData) { - BaseVisitor *bv = reinterpret_cast<BaseVisitor *>(clientData); + auto *bv = reinterpret_cast<BaseVisitor *>(clientData); const CXSourceLocation location = clang_getCursorLocation(cursor); if (!bv->visitLocation(location)) diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangparser.h b/sources/shiboken2/ApiExtractor/clangparser/clangparser.h index 36b9e0bd1..4248be853 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangparser.h +++ b/sources/shiboken2/ApiExtractor/clangparser/clangparser.h @@ -43,12 +43,12 @@ struct Diagnostic; class SourceFileCache { public: - typedef QPair<const char *, const char *> Snippet; + using Snippet = QPair<const char *, const char *>; Snippet getCodeSnippet(const CXCursor &cursor); private: - typedef QHash<QString, QByteArray> FileBufferCache; + using FileBufferCache = QHash<QString, QByteArray>; FileBufferCache m_fileBufferCache; }; @@ -56,8 +56,8 @@ private: class BaseVisitor { Q_DISABLE_COPY(BaseVisitor) public: - typedef QVector<Diagnostic> Diagnostics; - typedef SourceFileCache::Snippet CodeSnippet; + using Diagnostics = QVector<Diagnostic>; + using CodeSnippet = SourceFileCache::Snippet; enum StartTokenResult { Error, Skip, Recurse }; diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h index db2db6267..738b51bb4 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h +++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h @@ -73,7 +73,7 @@ struct SourceLocation SourceLocation getExpansionLocation(const CXSourceLocation &location); -typedef QPair<SourceLocation, SourceLocation> SourceRange; +using SourceRange =QPair<SourceLocation, SourceLocation>; SourceLocation getCursorLocation(const CXCursor &cursor); CXString getFileNameFromLocation(const CXSourceLocation &location); @@ -82,7 +82,7 @@ SourceRange getCursorRange(const CXCursor &cursor); struct Diagnostic { enum Source { Clang, Other }; - Diagnostic() : source(Clang) {} + Diagnostic() = default; // Clang static Diagnostic fromCXDiagnostic(CXDiagnostic cd); // Other @@ -91,8 +91,8 @@ struct Diagnostic { QString message; QStringList childMessages; SourceLocation location; - Source source; - CXDiagnosticSeverity severity; + Source source = Clang; + CXDiagnosticSeverity severity = CXDiagnostic_Warning; }; QVector<Diagnostic> getDiagnostics(CXTranslationUnit tu); @@ -100,7 +100,7 @@ CXDiagnosticSeverity maxSeverity(const QVector<Diagnostic> &ds); // Parse a template argument list "a<b<c,d>,e>" and invoke a handler // with each match (level and string). Return begin and end of the list. -typedef std::function<void(int /*level*/, const QStringRef &)> TemplateArgumentHandler; +using TemplateArgumentHandler = std::function<void (int, const QStringRef &)>; QPair<int, int> parseTemplateArgumentList(const QString &l, const TemplateArgumentHandler &handler, diff --git a/sources/shiboken2/ApiExtractor/dependency.h b/sources/shiboken2/ApiExtractor/dependency.h index d563e9094..7168ea3bc 100644 --- a/sources/shiboken2/ApiExtractor/dependency.h +++ b/sources/shiboken2/ApiExtractor/dependency.h @@ -42,6 +42,6 @@ struct Dependency { AbstractMetaClass *child; }; -typedef QVector<Dependency> Dependencies; +using Dependencies = QVector<Dependency>; #endif // DEPENDENCY_H diff --git a/sources/shiboken2/ApiExtractor/docparser.h b/sources/shiboken2/ApiExtractor/docparser.h index 53507b0f5..1dccae4d6 100644 --- a/sources/shiboken2/ApiExtractor/docparser.h +++ b/sources/shiboken2/ApiExtractor/docparser.h @@ -43,6 +43,8 @@ class XQuery; class DocParser { public: + Q_DISABLE_COPY(DocParser) + using XQueryPtr = QSharedPointer<XQuery>; DocParser(); diff --git a/sources/shiboken2/ApiExtractor/doxygenparser.h b/sources/shiboken2/ApiExtractor/doxygenparser.h index ed3a7bf0d..ada64ac18 100644 --- a/sources/shiboken2/ApiExtractor/doxygenparser.h +++ b/sources/shiboken2/ApiExtractor/doxygenparser.h @@ -34,7 +34,7 @@ class DoxygenParser : public DocParser { public: - DoxygenParser() {} + DoxygenParser() = default; void fillDocumentation(AbstractMetaClass *metaClass) override; Documentation retrieveModuleDocumentation() override; Documentation retrieveModuleDocumentation(const QString& name) override; diff --git a/sources/shiboken2/ApiExtractor/fileout.h b/sources/shiboken2/ApiExtractor/fileout.h index aace70131..b1011c4d6 100644 --- a/sources/shiboken2/ApiExtractor/fileout.h +++ b/sources/shiboken2/ApiExtractor/fileout.h @@ -41,6 +41,8 @@ private: QString name; public: + Q_DISABLE_COPY(FileOut) + enum State { Failure, Unchanged, Success }; explicit FileOut(QString name); diff --git a/sources/shiboken2/ApiExtractor/graph.cpp b/sources/shiboken2/ApiExtractor/graph.cpp index c2ac81e6c..95a80197e 100644 --- a/sources/shiboken2/ApiExtractor/graph.cpp +++ b/sources/shiboken2/ApiExtractor/graph.cpp @@ -38,8 +38,7 @@ struct Graph::GraphPrivate { enum Color { WHITE, GRAY, BLACK }; - typedef QVector<QSet<int> > Edges; - typedef QSet<int>::const_iterator EdgeIterator; + using Edges = QVector<QSet<int> >; Edges edges; @@ -50,11 +49,10 @@ struct Graph::GraphPrivate void dfsVisit(int node, Graph::Indexes &result, QVector<Color> &colors) const { colors[node] = GRAY; - EdgeIterator it = edges[node].begin(); - for (; it != edges[node].end(); ++it) { - if (colors[*it] == WHITE) - dfsVisit(*it, result, colors); - else if (colors[*it] == GRAY) // This is not a DAG! + for (const auto &c : edges.at(node)) { + if (colors[c] == WHITE) + dfsVisit(c, result, colors); + else if (colors[c] == GRAY) // This is not a DAG! return; } colors[node] = BLACK; diff --git a/sources/shiboken2/ApiExtractor/graph.h b/sources/shiboken2/ApiExtractor/graph.h index 043a182b5..5dc8e21ea 100644 --- a/sources/shiboken2/ApiExtractor/graph.h +++ b/sources/shiboken2/ApiExtractor/graph.h @@ -37,6 +37,8 @@ class Graph { public: + Q_DISABLE_COPY(Graph) + using Indexes = QVector<int>; /// Create a new graph with \p numNodes nodes. diff --git a/sources/shiboken2/ApiExtractor/header_paths.h b/sources/shiboken2/ApiExtractor/header_paths.h index 01d830921..0c25702ef 100644 --- a/sources/shiboken2/ApiExtractor/header_paths.h +++ b/sources/shiboken2/ApiExtractor/header_paths.h @@ -67,6 +67,6 @@ public: } }; -typedef QList<HeaderPath> HeaderPaths; +using HeaderPaths = QList<HeaderPath>; #endif // HEADER_PATHS_H diff --git a/sources/shiboken2/ApiExtractor/include.h b/sources/shiboken2/ApiExtractor/include.h index 4890eea2c..f7dfea5a7 100644 --- a/sources/shiboken2/ApiExtractor/include.h +++ b/sources/shiboken2/ApiExtractor/include.h @@ -46,7 +46,7 @@ public: InvalidInclude }; - Include() : m_type(IncludePath) {} + Include() = default; Include(IncludeType t, const QString &nam) : m_type(t), m_name(nam) {}; bool isValid() const @@ -78,7 +78,7 @@ public: friend uint qHash(const Include&); private: - IncludeType m_type; + IncludeType m_type = IncludePath; QString m_name; }; @@ -88,6 +88,6 @@ QTextStream& operator<<(QTextStream& out, const Include& include); QDebug operator<<(QDebug d, const Include &i); #endif -typedef QVector<Include> IncludeList; +using IncludeList = QVector<Include>; #endif diff --git a/sources/shiboken2/ApiExtractor/merge.xsl b/sources/shiboken2/ApiExtractor/merge.xsl index d0b7eafa5..c6cab5a42 100644 --- a/sources/shiboken2/ApiExtractor/merge.xsl +++ b/sources/shiboken2/ApiExtractor/merge.xsl @@ -2,11 +2,11 @@ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> - <xsl:param name="lang" /> - <xsl:param name="source" /> + <xsl:param name="lang" /> + <xsl:param name="source" /> <xsl:template match="processing-instruction()" /> - + <xsl:template match="/typesystem"> <xsl:copy> <xsl:for-each select="@*"> @@ -20,8 +20,8 @@ <xsl:value-of select="." /> </xsl:copy> </xsl:for-each> - - <xsl:variable name="other" select="document($source)/typesystem/*[not(self::object-type | self::value-type | self::interface-type | self::namespace-type)]" /> + + <xsl:variable name="other" select="document($source)/typesystem/*[not(self::object-type | self::value-type | self::interface-type | self::namespace-type)]" /> <xsl:if test="$other"> <xsl:choose> <xsl:when test="$lang != ''"> @@ -37,7 +37,7 @@ </xsl:if> <xsl:apply-templates select="node()" /> - + </xsl:copy> </xsl:template> @@ -53,14 +53,14 @@ </xsl:for-each> <xsl:apply-templates select="node()" /> - + <xsl:variable name="other" select="document($source)/typesystem/*[name() = $name][@name = current()/@name]" /> <xsl:if test="$other"> <xsl:choose> <xsl:when test="$lang != ''"> <xsl:element name="language"> <xsl:attribute name="name" ><xsl:value-of select="$lang" /></xsl:attribute> - <xsl:copy-of select="$other/node()" /> + <xsl:copy-of select="$other/node()" /> </xsl:element> </xsl:when> <xsl:otherwise> diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp index 7bb7e0a83..099ab8860 100644 --- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp +++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp @@ -53,9 +53,8 @@ private: template <class T> static QSharedPointer<T> findModelItem(const QVector<QSharedPointer<T> > &list, const QString &name) { - typedef typename QVector<QSharedPointer<T> >::const_iterator It; - const It it = std::find_if(list.begin(), list.end(), ModelItemNamePredicate<T>(name)); - return it != list.end() ? *it : QSharedPointer<T>(); + const auto it = std::find_if(list.cbegin(), list.cend(), ModelItemNamePredicate<T>(name)); + return it != list.cend() ? *it : QSharedPointer<T>(); } // --------------------------------------------------------------------------- @@ -64,16 +63,14 @@ CodeModel::CodeModel() : m_globalNamespace(new _NamespaceModelItem(this)) { } -CodeModel::~CodeModel() -{ -} +CodeModel::~CodeModel() = default; NamespaceModelItem CodeModel::globalNamespace() const { return m_globalNamespace; } -void CodeModel::addFile(FileModelItem item) +void CodeModel::addFile(const FileModelItem &item) { m_files.append(item); } @@ -161,7 +158,7 @@ bool TypeInfo::isVoid() const TypeInfo TypeInfo::resolveType(TypeInfo const &__type, const ScopeModelItem &__scope) { CodeModel *__model = __scope->model(); - Q_ASSERT(__model != 0); + Q_ASSERT(__model != nullptr); return TypeInfo::resolveType(__model->findItem(__type.qualifiedName(), __scope), __type, __scope); } @@ -724,7 +721,7 @@ static void formatModelItemList(QDebug &d, const char *prefix, const List &l, void _ClassModelItem::formatDebug(QDebug &d) const { - _CodeModelItem::formatDebug(d); + _ScopeModelItem::formatDebug(d); if (!m_baseClasses.isEmpty()) { if (m_final) d << " [final]"; @@ -742,7 +739,7 @@ void _ClassModelItem::formatDebug(QDebug &d) const #endif // !QT_NO_DEBUG_STREAM // --------------------------------------------------------------------------- -FunctionModelItem _ScopeModelItem::declaredFunction(FunctionModelItem item) +FunctionModelItem _ScopeModelItem::declaredFunction(const FunctionModelItem &item) { for (const FunctionModelItem &fun : qAsConst(m_functions)) { if (fun->name() == item->name() && fun->isSimilar(item)) @@ -759,27 +756,27 @@ void _ScopeModelItem::addEnumsDeclaration(const QString &enumsDeclaration) m_enumsDeclarations << enumsDeclaration; } -void _ScopeModelItem::addClass(ClassModelItem item) +void _ScopeModelItem::addClass(const ClassModelItem &item) { m_classes.append(item); } -void _ScopeModelItem::addFunction(FunctionModelItem item) +void _ScopeModelItem::addFunction(const FunctionModelItem &item) { m_functions.append(item); } -void _ScopeModelItem::addVariable(VariableModelItem item) +void _ScopeModelItem::addVariable(const VariableModelItem &item) { m_variables.append(item); } -void _ScopeModelItem::addTypeDef(TypeDefModelItem item) +void _ScopeModelItem::addTypeDef(const TypeDefModelItem &item) { m_typeDefs.append(item); } -void _ScopeModelItem::addEnum(EnumModelItem item) +void _ScopeModelItem::addEnum(const EnumModelItem &item) { m_enums.append(item); } @@ -800,12 +797,10 @@ static void formatScopeHash(QDebug &d, const char *prefix, const Hash &h, const char *separator = ", ", bool trailingNewLine = false) { - typedef typename Hash::ConstIterator HashIterator; if (!h.isEmpty()) { d << prefix << '[' << h.size() << "]("; - const HashIterator begin = h.begin(); - const HashIterator end = h.end(); - for (HashIterator it = begin; it != end; ++it) { // Omit the names as they are repeated + const auto begin = h.cbegin(); + for (auto it = begin, end = h.cend(); it != end; ++it) { // Omit the names as they are repeated if (it != begin) d << separator; d << it.value().data(); @@ -916,9 +911,7 @@ NamespaceModelItem _NamespaceModelItem::findNamespace(const QString &name) const return findModelItem(m_namespaces, name); } -_FileModelItem::~_FileModelItem() -{ -} +_FileModelItem::~_FileModelItem() = default; void _NamespaceModelItem::appendNamespace(const _NamespaceModelItem &other) { @@ -1188,9 +1181,7 @@ CodeModel::AccessPolicy _EnumModelItem::accessPolicy() const return m_accessPolicy; } -_EnumModelItem::~_EnumModelItem() -{ -} +_EnumModelItem::~_EnumModelItem() = default; void _EnumModelItem::setAccessPolicy(CodeModel::AccessPolicy accessPolicy) { @@ -1202,7 +1193,7 @@ EnumeratorList _EnumModelItem::enumerators() const return m_enumerators; } -void _EnumModelItem::addEnumerator(EnumeratorModelItem item) +void _EnumModelItem::addEnumerator(const EnumeratorModelItem &item) { m_enumerators.append(item); } diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h index 6f3c17613..777b2d103 100644 --- a/sources/shiboken2/ApiExtractor/parser/codemodel.h +++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h @@ -50,6 +50,8 @@ QT_FORWARD_DECLARE_CLASS(QDebug) class CodeModel { public: + Q_DISABLE_COPY(CodeModel) + enum AccessPolicy { Public, Protected, @@ -79,7 +81,7 @@ public: FileList files() const { return m_files; } NamespaceModelItem globalNamespace() const; - void addFile(FileModelItem item); + void addFile(const FileModelItem &item); FileModelItem findFile(const QString &name) const; CodeModelItem findItem(const QStringList &qualifiedName, const ScopeModelItem &scope) const; @@ -87,10 +89,6 @@ public: private: FileList m_files; NamespaceModelItem m_globalNamespace; - -private: - CodeModel(const CodeModel &other); - void operator = (const CodeModel &other); }; #ifndef QT_NO_DEBUG_STREAM @@ -101,7 +99,7 @@ class TypeInfo { friend class TypeParser; public: - typedef QVector<Indirection> Indirections; + using Indirections = QVector<Indirection>; TypeInfo() : flags(0), m_referenceType(NoReference) {} @@ -334,11 +332,11 @@ public: TypeDefList typeDefs() const { return m_typeDefs; } VariableList variables() const { return m_variables; } - void addClass(ClassModelItem item); - void addEnum(EnumModelItem item); - void addFunction(FunctionModelItem item); - void addTypeDef(TypeDefModelItem item); - void addVariable(VariableModelItem item); + void addClass(const ClassModelItem &item); + void addEnum(const EnumModelItem &item); + void addFunction(const FunctionModelItem &item); + void addTypeDef(const TypeDefModelItem &item); + void addVariable(const VariableModelItem &item); ClassModelItem findClass(const QString &name) const; EnumModelItem findEnum(const QString &name) const; @@ -349,7 +347,7 @@ public: void addEnumsDeclaration(const QString &enumsDeclaration); QStringList enumsDeclarations() const { return m_enumsDeclarations; } - FunctionModelItem declaredFunction(FunctionModelItem item); + FunctionModelItem declaredFunction(const FunctionModelItem &item); #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &d) const override; @@ -692,7 +690,7 @@ public: bool hasValues() const { return !m_enumerators.isEmpty(); } EnumeratorList enumerators() const; - void addEnumerator(EnumeratorModelItem item); + void addEnumerator(const EnumeratorModelItem &item); EnumKind enumKind() const { return m_enumKind; } void setEnumKind(EnumKind kind) { m_enumKind = kind; } diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel_fwd.h b/sources/shiboken2/ApiExtractor/parser/codemodel_fwd.h index f67c64221..54dbe78dc 100644 --- a/sources/shiboken2/ApiExtractor/parser/codemodel_fwd.h +++ b/sources/shiboken2/ApiExtractor/parser/codemodel_fwd.h @@ -51,32 +51,32 @@ class _VariableModelItem; class _MemberModelItem; class TypeInfo; -typedef QSharedPointer<_ArgumentModelItem> ArgumentModelItem; -typedef QSharedPointer<_ClassModelItem> ClassModelItem; -typedef QSharedPointer<_CodeModelItem> CodeModelItem; -typedef QSharedPointer<_EnumModelItem> EnumModelItem; -typedef QSharedPointer<_EnumeratorModelItem> EnumeratorModelItem; -typedef QSharedPointer<_FileModelItem> FileModelItem; -typedef QSharedPointer<_FunctionModelItem> FunctionModelItem; -typedef QSharedPointer<_NamespaceModelItem> NamespaceModelItem; -typedef QSharedPointer<_ScopeModelItem> ScopeModelItem; -typedef QSharedPointer<_TemplateParameterModelItem> TemplateParameterModelItem; -typedef QSharedPointer<_TypeDefModelItem> TypeDefModelItem; -typedef QSharedPointer<_VariableModelItem> VariableModelItem; -typedef QSharedPointer<_MemberModelItem> MemberModelItem; +using ArgumentModelItem = QSharedPointer<_ArgumentModelItem>; +using ClassModelItem = QSharedPointer<_ClassModelItem>; +using CodeModelItem = QSharedPointer<_CodeModelItem>; +using EnumModelItem = QSharedPointer<_EnumModelItem>; +using EnumeratorModelItem = QSharedPointer<_EnumeratorModelItem>; +using FileModelItem = QSharedPointer<_FileModelItem>; +using FunctionModelItem = QSharedPointer<_FunctionModelItem>; +using NamespaceModelItem = QSharedPointer<_NamespaceModelItem>; +using ScopeModelItem = QSharedPointer<_ScopeModelItem>; +using TemplateParameterModelItem = QSharedPointer<_TemplateParameterModelItem>; +using TypeDefModelItem = QSharedPointer<_TypeDefModelItem>; +using VariableModelItem = QSharedPointer<_VariableModelItem>; +using MemberModelItem = QSharedPointer<_MemberModelItem>; -typedef QVector<ArgumentModelItem> ArgumentList; -typedef QVector<ClassModelItem> ClassList; -typedef QVector<CodeModelItem> ItemList; -typedef QVector<EnumModelItem> EnumList; -typedef QVector<EnumeratorModelItem> EnumeratorList; -typedef QVector<FileModelItem> FileList; -typedef QVector<FunctionModelItem> FunctionList; -typedef QVector<NamespaceModelItem> NamespaceList; -typedef QVector<ScopeModelItem> ScopeList; -typedef QVector<TemplateParameterModelItem> TemplateParameterList; -typedef QVector<TypeDefModelItem> TypeDefList; -typedef QVector<VariableModelItem> VariableList; -typedef QVector<MemberModelItem> MemberList; +using ArgumentList = QVector<ArgumentModelItem>; +using ClassList = QVector<ClassModelItem>; +using ItemList = QVector<CodeModelItem>; +using EnumList = QVector<EnumModelItem>; +using EnumeratorList = QVector<EnumeratorModelItem>; +using FileList = QVector<FileModelItem>; +using FunctionList = QVector<FunctionModelItem>; +using NamespaceList = QVector<NamespaceModelItem>; +using ScopeList = QVector<ScopeModelItem>; +using TemplateParameterList = QVector<TemplateParameterModelItem>; +using TypeDefList = QVector<TypeDefModelItem>; +using VariableList = QVector<VariableModelItem>; +using MemberList = QVector<MemberModelItem>; #endif // CODEMODEL_FWD_H diff --git a/sources/shiboken2/ApiExtractor/qtdocparser.cpp b/sources/shiboken2/ApiExtractor/qtdocparser.cpp index c5ee1743d..2e50470e4 100644 --- a/sources/shiboken2/ApiExtractor/qtdocparser.cpp +++ b/sources/shiboken2/ApiExtractor/qtdocparser.cpp @@ -54,7 +54,7 @@ static void formatFunctionArgTypeQuery(QTextStream &str, const AbstractMetaArgum case AbstractMetaType::FlagsPattern: { // Modify qualified name "QFlags<Qt::AlignmentFlag>" with name "Alignment" // to "Qt::Alignment" as seen by qdoc. - const FlagsTypeEntry *flagsEntry = static_cast<const FlagsTypeEntry *>(metaType->typeEntry()); + const auto *flagsEntry = static_cast<const FlagsTypeEntry *>(metaType->typeEntry()); QString name = flagsEntry->qualifiedCppName(); if (name.endsWith(QLatin1Char('>')) && name.startsWith(QLatin1String("QFlags<"))) { const int lastColon = name.lastIndexOf(QLatin1Char(':')); @@ -212,7 +212,7 @@ void QtDocParser::fillDocumentation(AbstractMetaClass* metaClass) const AbstractMetaClass* context = metaClass->enclosingClass(); while(context) { - if (context->enclosingClass() == 0) + if (context->enclosingClass() == nullptr) break; context = context->enclosingClass(); } diff --git a/sources/shiboken2/ApiExtractor/qtdocparser.h b/sources/shiboken2/ApiExtractor/qtdocparser.h index c4333e820..b01139de6 100644 --- a/sources/shiboken2/ApiExtractor/qtdocparser.h +++ b/sources/shiboken2/ApiExtractor/qtdocparser.h @@ -34,7 +34,7 @@ class QtDocParser : public DocParser { public: - QtDocParser() {} + QtDocParser() = default; void fillDocumentation(AbstractMetaClass* metaClass) override; Documentation retrieveModuleDocumentation() override; Documentation retrieveModuleDocumentation(const QString& name) override; diff --git a/sources/shiboken2/ApiExtractor/tests/testabstractmetaclass.cpp b/sources/shiboken2/ApiExtractor/tests/testabstractmetaclass.cpp index 8a6b59285..98b493c67 100644 --- a/sources/shiboken2/ApiExtractor/tests/testabstractmetaclass.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testabstractmetaclass.cpp @@ -134,7 +134,7 @@ public: const AbstractMetaClass *f = AbstractMetaClass::findClass(classes, QLatin1String("F")); QVERIFY(f); - AbstractMetaClass* no_class = 0; + AbstractMetaClass* no_class = nullptr; QCOMPARE(a->baseClass(), no_class); QCOMPARE(b->baseClass(), a); diff --git a/sources/shiboken2/ApiExtractor/tests/testconversionoperator.cpp b/sources/shiboken2/ApiExtractor/tests/testconversionoperator.cpp index 67865d3aa..142c783a4 100644 --- a/sources/shiboken2/ApiExtractor/tests/testconversionoperator.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testconversionoperator.cpp @@ -64,7 +64,7 @@ void TestConversionOperator::testConversionOperator() QCOMPARE(classC->functions().count(), 3); QCOMPARE(classA->externalConversionOperators().count(), 2); - AbstractMetaFunction* convOp = 0; + AbstractMetaFunction *convOp = nullptr; for (AbstractMetaFunction *func : classB->functions()) { if (func->isConversionOperator()) { convOp = func; diff --git a/sources/shiboken2/ApiExtractor/tests/testconversionruletag.cpp b/sources/shiboken2/ApiExtractor/tests/testconversionruletag.cpp index 8c662d76b..aa2bec5d6 100644 --- a/sources/shiboken2/ApiExtractor/tests/testconversionruletag.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testconversionruletag.cpp @@ -119,7 +119,7 @@ void TestConversionRuleTag::testConversionRuleTagReplace() QVERIFY(toNative); QCOMPARE(toNative->sourceTypeName(), QLatin1String("TargetNone")); QVERIFY(toNative->isCustomType()); - QCOMPARE(toNative->sourceType(), (const TypeEntry*)0); + QCOMPARE(toNative->sourceType(), nullptr); QCOMPARE(toNative->sourceTypeCheck(), QLatin1String("%IN == Target_None")); QCOMPARE(toNative->conversion().simplified(), QLatin1String("DoThat(); DoSomething(); %OUT = A();")); @@ -138,7 +138,7 @@ void TestConversionRuleTag::testConversionRuleTagReplace() QVERIFY(toNative); QCOMPARE(toNative->sourceTypeName(), QLatin1String("String")); QVERIFY(toNative->isCustomType()); - QCOMPARE(toNative->sourceType(), (const TypeEntry*)0); + QCOMPARE(toNative->sourceType(), nullptr); QCOMPARE(toNative->sourceTypeCheck(), QLatin1String("String_Check(%IN)")); QCOMPARE(toNative->conversion().trimmed(), QLatin1String("%OUT = new A(String_AsString(%IN), String_GetSize(%IN));")); } @@ -183,7 +183,7 @@ if (!TargetDateTimeAPI) TargetDateTime_IMPORT;\n\ QVERIFY(toNative); QCOMPARE(toNative->sourceTypeName(), QLatin1String("TargetDate")); QVERIFY(toNative->isCustomType()); - QCOMPARE(toNative->sourceType(), (const TypeEntry*)0); + QCOMPARE(toNative->sourceType(), nullptr); QCOMPARE(toNative->sourceTypeCheck(), QLatin1String("TargetDate_Check(%IN)")); QCOMPARE(toNative->conversion().trimmed(), QLatin1String("if (!TargetDateTimeAPI) TargetDateTime_IMPORT;\n%OUT = new Date(TargetDate_Day(%IN), TargetDate_Month(%IN), TargetDate_Year(%IN));")); diff --git a/sources/shiboken2/ApiExtractor/tests/testimplicitconversions.cpp b/sources/shiboken2/ApiExtractor/tests/testimplicitconversions.cpp index 7b3616daa..26fb148d5 100644 --- a/sources/shiboken2/ApiExtractor/tests/testimplicitconversions.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testimplicitconversions.cpp @@ -151,7 +151,7 @@ void TestImplicitConversions::testWithExternalConversionOperator() AbstractMetaFunctionList externalConvOps = classA->externalConversionOperators(); QCOMPARE(externalConvOps.count(), 1); - const AbstractMetaFunction* convOp = 0; + const AbstractMetaFunction *convOp = nullptr; for (const AbstractMetaFunction *func : classB->functions()) { if (func->isConversionOperator()) convOp = func; diff --git a/sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp b/sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp index 2ea95595e..dc4801e18 100644 --- a/sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testreverseoperators.cpp @@ -51,7 +51,7 @@ void TestReverseOperators::testReverseSum() QVERIFY(classA); QCOMPARE(classA->functions().count(), 4); - const AbstractMetaFunction* reverseOp = 0; + const AbstractMetaFunction* reverseOp = nullptr; const AbstractMetaFunction* normalOp = 0; for (const AbstractMetaFunction *func : classA->functions()) { if (func->name() == QLatin1String("operator+")) { @@ -100,8 +100,8 @@ void TestReverseOperators::testReverseSumWithAmbiguity() QVERIFY(classB); QCOMPARE(classB->functions().count(), 4); - const AbstractMetaFunction* reverseOp = 0; - const AbstractMetaFunction* normalOp = 0; + const AbstractMetaFunction *reverseOp = nullptr; + const AbstractMetaFunction *normalOp = nullptr; for (const AbstractMetaFunction *func : classB->functions()) { if (func->name() == QLatin1String("operator+")) { if (func->isReverseOperator()) diff --git a/sources/shiboken2/ApiExtractor/tests/testutil.h b/sources/shiboken2/ApiExtractor/tests/testutil.h index c6ad19d7e..9a2faad5c 100644 --- a/sources/shiboken2/ApiExtractor/tests/testutil.h +++ b/sources/shiboken2/ApiExtractor/tests/testutil.h @@ -47,7 +47,7 @@ namespace TestUtil TypeDatabase* td = TypeDatabase::instance(true); if (apiVersion.isEmpty()) TypeDatabase::clearApiVersions(); - else if (!td->setApiVersion(QLatin1String("*"), apiVersion)) + else if (!TypeDatabase::setApiVersion(QLatin1String("*"), apiVersion)) return nullptr; td->setDropTypeEntries(dropTypeEntries); QBuffer buffer; @@ -69,7 +69,7 @@ namespace TestUtil arguments.append(QFile::encodeName(tempSource.fileName())); tempSource.write(cppCode, qint64(strlen(cppCode))); tempSource.close(); - AbstractMetaBuilder *builder = new AbstractMetaBuilder; + auto *builder = new AbstractMetaBuilder; if (!builder->build(arguments)) { delete builder; return Q_NULLPTR; diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp index 930f85d30..144795c6a 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp @@ -51,27 +51,24 @@ static QString wildcardToRegExp(QString w) return w; } -typedef QPair<QRegularExpression, QVersionNumber> ApiVersion; -typedef QVector<ApiVersion> ApiVersions; +using ApiVersion =QPair<QRegularExpression, QVersionNumber>; +using ApiVersions = QVector<ApiVersion>; Q_GLOBAL_STATIC(ApiVersions, apiVersions) -TypeDatabase::TypeDatabase() : m_suppressWarnings(true) +TypeDatabase::TypeDatabase() { addType(new VoidTypeEntry()); addType(new VarargsTypeEntry()); } -TypeDatabase::~TypeDatabase() -{ -} +TypeDatabase::~TypeDatabase() = default; TypeDatabase* TypeDatabase::instance(bool newInstance) { - static TypeDatabase* db = 0; + static TypeDatabase *db = nullptr; if (!db || newInstance) { - if (db) - delete db; + delete db; db = new TypeDatabase; } return db; @@ -85,7 +82,7 @@ struct IntTypeNormalizationEntry QString replacement; }; -typedef QVector<IntTypeNormalizationEntry> IntTypeNormalizationEntries; +using IntTypeNormalizationEntries = QVector<IntTypeNormalizationEntry>; static const IntTypeNormalizationEntries &intTypeNormalizationEntries() { @@ -93,10 +90,8 @@ static const IntTypeNormalizationEntries &intTypeNormalizationEntries() static bool firstTime = true; if (firstTime) { firstTime = false; - static const char *intTypes[] = {"char", "short", "int", "long"}; - const size_t size = sizeof(intTypes) / sizeof(intTypes[0]); - for (size_t i = 0; i < size; ++i) { - const QString intType = QLatin1String(intTypes[i]); + for (auto t : {"char", "short", "int", "long"}) { + const QString intType = QLatin1String(t); if (!TypeDatabase::instance()->findType(QLatin1Char('u') + intType)) { IntTypeNormalizationEntry entry; entry.replacement = QStringLiteral("unsigned ") + intType; @@ -115,8 +110,8 @@ QString TypeDatabase::normalizedSignature(const QString &signature) if (instance() && signature.contains(QLatin1String("unsigned"))) { const IntTypeNormalizationEntries &entries = intTypeNormalizationEntries(); - for (int i = 0, size = entries.size(); i < size; ++i) - normalized.replace(entries.at(i).regex, entries.at(i).replacement); + for (const auto &entry : entries) + normalized.replace(entry.regex, entry.replacement); } return normalized; @@ -146,10 +141,7 @@ void TypeDatabase::addTypesystemPath(const QString& typesystem_paths) IncludeList TypeDatabase::extraIncludes(const QString& className) const { ComplexTypeEntry* typeEntry = findComplexType(className); - if (typeEntry) - return typeEntry->extraIncludes(); - else - return IncludeList(); + return typeEntry ? typeEntry->extraIncludes() : IncludeList(); } ContainerTypeEntry* TypeDatabase::findContainerType(const QString &name) const @@ -163,7 +155,7 @@ ContainerTypeEntry* TypeDatabase::findContainerType(const QString &name) const TypeEntry* type_entry = findType(template_name); if (type_entry && type_entry->isContainer()) return static_cast<ContainerTypeEntry*>(type_entry); - return 0; + return nullptr; } static bool inline useType(const TypeEntry *t) @@ -179,7 +171,7 @@ FunctionTypeEntry* TypeDatabase::findFunctionType(const QString& name) const if (entry->type() == TypeEntry::FunctionType && useType(entry)) return static_cast<FunctionTypeEntry*>(entry); } - return 0; + return nullptr; } void TypeDatabase::addTypeSystemType(const TypeSystemTypeEntry *e) @@ -351,7 +343,7 @@ TypeEntry *TypeDatabase::resolveTypeDefEntry(TypedefEntry *typedefEntry, return nullptr; } - ComplexTypeEntry *result = static_cast<ComplexTypeEntry *>(source->clone()); + auto *result = static_cast<ComplexTypeEntry *>(source->clone()); result->useAsTypedef(typedefEntry); typedefEntry->setSource(source); typedefEntry->setTarget(result); @@ -592,13 +584,13 @@ PrimitiveTypeEntry *TypeDatabase::findPrimitiveType(const QString& name) const const auto entries = findTypes(name); for (TypeEntry *entry : entries) { if (entry->isPrimitive()) { - PrimitiveTypeEntry *pe = static_cast<PrimitiveTypeEntry *>(entry); + auto *pe = static_cast<PrimitiveTypeEntry *>(entry); if (pe->preferredTargetLangType()) return pe; } } - return 0; + return nullptr; } ComplexTypeEntry* TypeDatabase::findComplexType(const QString& name) const @@ -608,7 +600,7 @@ ComplexTypeEntry* TypeDatabase::findComplexType(const QString& name) const if (entry->isComplex() && useType(entry)) return static_cast<ComplexTypeEntry*>(entry); } - return 0; + return nullptr; } ObjectTypeEntry* TypeDatabase::findObjectType(const QString& name) const @@ -618,7 +610,7 @@ ObjectTypeEntry* TypeDatabase::findObjectType(const QString& name) const if (entry && entry->isObject() && useType(entry)) return static_cast<ObjectTypeEntry*>(entry); } - return 0; + return nullptr; } NamespaceTypeEntryList TypeDatabase::findNamespaceTypes(const QString& name) const diff --git a/sources/shiboken2/ApiExtractor/typedatabase.h b/sources/shiboken2/ApiExtractor/typedatabase.h index df614e644..334e88a14 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.h +++ b/sources/shiboken2/ApiExtractor/typedatabase.h @@ -170,7 +170,7 @@ private: TypeEntryMultiMapConstIteratorRange findTypes(const QString &name) const; TypeEntry *resolveTypeDefEntry(TypedefEntry *typedefEntry, QString *errorMessage); - bool m_suppressWarnings; + bool m_suppressWarnings = true; TypeEntryMultiMap m_entries; TypeEntryMap m_flagsEntries; TypedefEntryMap m_typedefEntries; diff --git a/sources/shiboken2/ApiExtractor/typedatabase_typedefs.h b/sources/shiboken2/ApiExtractor/typedatabase_typedefs.h index f9591609e..0bb5cde1d 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase_typedefs.h +++ b/sources/shiboken2/ApiExtractor/typedatabase_typedefs.h @@ -40,8 +40,8 @@ class TemplateEntry; class TypeEntry; class TypedefEntry; -typedef QVector<TypeEntry *> TypeEntryList; -typedef QMap<QString, TemplateEntry *> TemplateEntryMap; +using TypeEntryList = QVector<TypeEntry *>; +using TemplateEntryMap =QMap<QString, TemplateEntry *>; template <class Key, class Value> struct QMultiMapConstIteratorRange // A range of iterator for a range-based for loop @@ -55,14 +55,14 @@ struct QMultiMapConstIteratorRange // A range of iterator for a range-based for ConstIterator m_end; }; -typedef QMultiMap<QString, TypeEntry *> TypeEntryMultiMap; -typedef QMultiMapConstIteratorRange<QString, TypeEntry *> TypeEntryMultiMapConstIteratorRange; +using TypeEntryMultiMap = QMultiMap<QString, TypeEntry *>; +using TypeEntryMultiMapConstIteratorRange = QMultiMapConstIteratorRange<QString, TypeEntry *>; -typedef QMap<QString, TypeEntry *> TypeEntryMap; -typedef QMap<QString, TypedefEntry *> TypedefEntryMap; +using TypeEntryMap = QMap<QString, TypeEntry *>; +using TypedefEntryMap = QMap<QString, TypedefEntry *>; -typedef QVector<const ContainerTypeEntry *> ContainerTypeEntryList; +using ContainerTypeEntryList = QVector<const ContainerTypeEntry *>; using NamespaceTypeEntryList = QVector<NamespaceTypeEntry *>; -typedef QVector<const PrimitiveTypeEntry *> PrimitiveTypeEntryList; +using PrimitiveTypeEntryList = QVector<const PrimitiveTypeEntry *>; #endif // TYPEDATABASE_TYPEDEFS_H diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index b4c94695d..65e3443da 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -510,7 +510,7 @@ Handler::~Handler() = default; static QString readerFileName(const QXmlStreamReader &reader) { - const QFile *file = qobject_cast<const QFile *>(reader.device()); + const auto *file = qobject_cast<const QFile *>(reader.device()); return file != nullptr ? file->fileName() : QString(); } @@ -698,7 +698,7 @@ bool Handler::endElement(const QStringRef &localName) if (m_currentDroppedEntryDepth == 1) { m_current = m_currentDroppedEntry->parent; delete m_currentDroppedEntry; - m_currentDroppedEntry = 0; + m_currentDroppedEntry = nullptr; m_currentDroppedEntryDepth = 0; } else { --m_currentDroppedEntryDepth; @@ -728,7 +728,7 @@ bool Handler::endElement(const QStringRef &localName) case StackElement::ValueTypeEntry: case StackElement::InterfaceTypeEntry: case StackElement::NamespaceTypeEntry: { - ComplexTypeEntry *centry = static_cast<ComplexTypeEntry *>(m_current->entry); + auto *centry = static_cast<ComplexTypeEntry *>(m_current->entry); centry->setAddedFunctions(m_contextStack.top()->addedFunctions); centry->setFunctionModifications(m_contextStack.top()->functionMods); centry->setFieldModifications(m_contextStack.top()->fieldMods); @@ -785,7 +785,7 @@ bool Handler::endElement(const QStringRef &localName) case StackElement::EnumTypeEntry: m_current->entry->setDocModification(m_contextStack.top()->docModifications); m_contextStack.top()->docModifications = DocModificationList(); - m_currentEnum = 0; + m_currentEnum = nullptr; break; case StackElement::Template: m_database->addTemplate(m_current->value.templateEntry); @@ -1148,8 +1148,7 @@ SmartPointerTypeEntry * return nullptr; } - SmartPointerTypeEntry *type = - new SmartPointerTypeEntry(name, getter, smartPointerType, refCountMethodName, since); + auto *type = new SmartPointerTypeEntry(name, getter, smartPointerType, refCountMethodName, since); applyCommonAttributes(type, attributes); return type; } @@ -1159,7 +1158,7 @@ PrimitiveTypeEntry * const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { - PrimitiveTypeEntry *type = new PrimitiveTypeEntry(name, since); + auto *type = new PrimitiveTypeEntry(name, since); applyCommonAttributes(type, attributes); for (int i = attributes->size() - 1; i >= 0; --i) { const QStringRef name = attributes->at(i).qualifiedName(); @@ -1203,7 +1202,7 @@ ContainerTypeEntry * m_error = QLatin1String("there is no container of type ") + typeName.toString(); return nullptr; } - ContainerTypeEntry *type = new ContainerTypeEntry(name, containerType, since); + auto *type = new ContainerTypeEntry(name, containerType, since); applyCommonAttributes(type, attributes); return type; } @@ -1220,7 +1219,7 @@ EnumTypeEntry * scope = fullName.left(sep); name = fullName.right(fullName.size() - sep - 2); } - EnumTypeEntry *entry = new EnumTypeEntry(scope, name, since); + auto *entry = new EnumTypeEntry(scope, name, since); applyCommonAttributes(entry, attributes); entry->setTargetLangPackage(m_defaultPackage); @@ -1258,7 +1257,7 @@ ObjectTypeEntry * const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { - ObjectTypeEntry *otype = new ObjectTypeEntry(name, since); + auto *otype = new ObjectTypeEntry(name, since); applyCommonAttributes(otype, attributes); QString targetLangName = name; bool generate = true; @@ -1331,7 +1330,7 @@ ValueTypeEntry * const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { - ValueTypeEntry *typeEntry = new ValueTypeEntry(name, since); + auto *typeEntry = new ValueTypeEntry(name, since); applyCommonAttributes(typeEntry, attributes); const int defaultCtIndex = indexOfAttribute(*attributes, QStringViewLiteral("default-constructor")); @@ -1356,7 +1355,7 @@ FunctionTypeEntry * TypeEntry *existingType = m_database->findType(name); if (!existingType) { - FunctionTypeEntry *result = new FunctionTypeEntry(name, signature, since); + auto *result = new FunctionTypeEntry(name, signature, since); applyCommonAttributes(result, attributes); return result; } @@ -1367,7 +1366,7 @@ FunctionTypeEntry * return nullptr; } - FunctionTypeEntry *result = reinterpret_cast<FunctionTypeEntry *>(existingType); + auto *result = reinterpret_cast<FunctionTypeEntry *>(existingType); result->addSignature(signature); return result; } @@ -1626,7 +1625,7 @@ TypeSystemTypeEntry *Handler::parseRootElement(const QXmlStreamReader &, } } - TypeSystemTypeEntry *moduleEntry = + auto *moduleEntry = const_cast<TypeSystemTypeEntry *>(m_database->findTypeSystemType(m_defaultPackage)); const bool add = moduleEntry == nullptr; if (add) @@ -1651,8 +1650,8 @@ bool Handler::loadTypesystem(const QXmlStreamReader &, const QStringRef name = attributes->at(i).qualifiedName(); if (name == nameAttribute()) typeSystemName = attributes->takeAt(i).value().toString(); - else if (name == generateAttribute()) - generateChild = convertBoolean(attributes->takeAt(i).value(), generateAttribute(), true); + else if (name == generateAttribute()) + generateChild = convertBoolean(attributes->takeAt(i).value(), generateAttribute(), true); } if (typeSystemName.isEmpty()) { m_error = QLatin1String("No typesystem name specified"); @@ -1768,7 +1767,7 @@ bool Handler::parseCustomConversion(const QXmlStreamReader &, } } - CustomConversion* customConversion = new CustomConversion(m_current->entry); + auto *customConversion = new CustomConversion(m_current->entry); customConversionsForReview.append(customConversion); return true; } @@ -1805,8 +1804,8 @@ bool Handler::parseAddConversion(const QXmlStreamReader &, const QStringRef name = attributes->at(i).qualifiedName(); if (name == QLatin1String("type")) sourceTypeName = attributes->takeAt(i).value().toString(); - else if (name == QLatin1String("check")) - typeCheck = attributes->takeAt(i).value().toString(); + else if (name == QLatin1String("check")) + typeCheck = attributes->takeAt(i).value().toString(); } if (sourceTypeName.isEmpty()) { m_error = QLatin1String("Target to Native conversions must specify the input type with the 'type' attribute."); @@ -2305,7 +2304,7 @@ CustomFunction * else if (name == QLatin1String("param-name")) paramName = attributes->takeAt(i).value().toString(); } - CustomFunction *func = new CustomFunction(functionName); + auto *func = new CustomFunction(functionName); func->paramName = paramName; return func; } @@ -2604,7 +2603,7 @@ bool Handler::startElement(const QXmlStreamReader &reader) return true; } - StackElement* element = new StackElement(m_current); + auto *element = new StackElement(m_current); element->type = elementType; if (element->type == StackElement::Root && m_generate == TypeEntry::GenerateAll) @@ -2807,7 +2806,7 @@ bool Handler::startElement(const QXmlStreamReader &reader) return false; } - StackElement topElement = !m_current ? StackElement(0) : *m_current; + StackElement topElement = !m_current ? StackElement(nullptr) : *m_current; element->entry = topElement.entry; switch (element->type) { @@ -3003,7 +3002,7 @@ QString PrimitiveTypeEntry::targetLangApiName() const PrimitiveTypeEntry *PrimitiveTypeEntry::basicReferencedTypeEntry() const { if (!m_referencedTypeEntry) - return 0; + return nullptr; PrimitiveTypeEntry *baseReferencedTypeEntry = m_referencedTypeEntry->basicReferencedTypeEntry(); return baseReferencedTypeEntry ? baseReferencedTypeEntry : m_referencedTypeEntry; @@ -3043,9 +3042,10 @@ FunctionModificationList ComplexTypeEntry::functionModifications(const QString & FieldModification ComplexTypeEntry::fieldModification(const QString &name) const { - for (int i = 0; i < m_fieldMods.size(); ++i) - if (m_fieldMods.at(i).name == name) - return m_fieldMods.at(i); + for (const auto &fieldMod : m_fieldMods) { + if (fieldMod.name == name) + return fieldMod; + } FieldModification mod; mod.name = name; mod.modifiers = FieldModification::Readable | FieldModification::Writable; @@ -3926,7 +3926,7 @@ struct CustomConversion::CustomConversionPrivate struct CustomConversion::TargetToNativeConversion::TargetToNativeConversionPrivate { TargetToNativeConversionPrivate() - : sourceType(0) + : sourceType(nullptr) { } const TypeEntry* sourceType; diff --git a/sources/shiboken2/ApiExtractor/typesystem.h b/sources/shiboken2/ApiExtractor/typesystem.h index 82a698107..6a88ecd4d 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.h +++ b/sources/shiboken2/ApiExtractor/typesystem.h @@ -55,7 +55,7 @@ QT_END_NAMESPACE class EnumTypeEntry; class FlagsTypeEntry; -typedef QMap<int, QString> ArgumentMap; +using ArgumentMap = QMap<int, QString>; class TemplateInstance; @@ -186,9 +186,9 @@ public: struct ArgumentModification { ArgumentModification() : removedDefaultExpression(false), removed(false), - noNullPointers(false), array(false) {} + noNullPointers(false), resetAfterUse(false), array(false) {} explicit ArgumentModification(int idx) : index(idx), removedDefaultExpression(false), removed(false), - noNullPointers(false), array(false) {} + noNullPointers(false), resetAfterUse(false), array(false) {} // Should the default expression be removed? @@ -548,6 +548,10 @@ class TypeEntry { Q_GADGET public: + TypeEntry &operator=(const TypeEntry &) = delete; + TypeEntry &operator=(TypeEntry &&) = delete; + TypeEntry(TypeEntry &&) = delete; + enum Type { PrimitiveType, VoidType, @@ -770,7 +774,7 @@ public: virtual InterfaceTypeEntry *designatedInterface() const { - return 0; + return nullptr; } void setCustomConstructor(const CustomFunction &func) @@ -901,10 +905,6 @@ protected: TypeEntry(const TypeEntry &); private: - TypeEntry &operator=(const TypeEntry &) = delete; - TypeEntry &operator=(TypeEntry &&) = delete; - TypeEntry(TypeEntry &&) = delete; - QString m_name; QString m_targetLangPackage; Type m_type; @@ -1225,7 +1225,7 @@ public: enum TypeFlag { Deprecated = 0x4 }; - typedef QFlags<TypeFlag> TypeFlags; + Q_DECLARE_FLAGS(TypeFlags, TypeFlag) enum CopyableFlag { CopyableSet, @@ -1366,7 +1366,7 @@ public: { return m_hashFunction; } - void setHashFunction(QString hashFunction) + void setHashFunction(const QString &hashFunction) { m_hashFunction = hashFunction; } @@ -1427,6 +1427,8 @@ private: TypeSystem::AllowThread m_allowThread = TypeSystem::AllowThread::Unspecified; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(ComplexTypeEntry::TypeFlags) + class TypedefEntry : public ComplexTypeEntry { public: @@ -1446,7 +1448,7 @@ public: void setTarget(ComplexTypeEntry *target) { m_target = target; } #ifndef QT_NO_DEBUG_STREAM - virtual void formatDebug(QDebug &d) const override; + void formatDebug(QDebug &d) const override; #endif protected: TypedefEntry(const TypedefEntry &); @@ -1605,7 +1607,7 @@ protected: InterfaceTypeEntry(const InterfaceTypeEntry &); private: - ObjectTypeEntry *m_origin; + ObjectTypeEntry *m_origin = nullptr; }; @@ -1675,7 +1677,7 @@ struct TypeRejection QRegularExpression className; QRegularExpression pattern; - MatchType matchType; + MatchType matchType = Invalid; }; #ifndef QT_NO_DEBUG_STREAM @@ -1722,7 +1724,7 @@ public: bool replaceOriginalTargetToNativeConversions() const; void setReplaceOriginalTargetToNativeConversions(bool replaceOriginalTargetToNativeConversions); - typedef QVector<TargetToNativeConversion*> TargetToNativeConversions; + using TargetToNativeConversions = QVector<TargetToNativeConversion *>; bool hasTargetToNativeConversions() const; TargetToNativeConversions& targetToNativeConversions(); const TargetToNativeConversions& targetToNativeConversions() const; diff --git a/sources/shiboken2/ApiExtractor/typesystem_p.h b/sources/shiboken2/ApiExtractor/typesystem_p.h index 8a8fcb359..5b8b93cee 100644 --- a/sources/shiboken2/ApiExtractor/typesystem_p.h +++ b/sources/shiboken2/ApiExtractor/typesystem_p.h @@ -114,7 +114,7 @@ class StackElement ArgumentModifiers = 0xff000000 }; - StackElement(StackElement *p) : entry(0), type(None), parent(p) { } + StackElement(StackElement *p) : entry(nullptr), type(None), parent(p) { } TypeEntry* entry; ElementType type; diff --git a/sources/shiboken2/ApiExtractor/typesystem_typedefs.h b/sources/shiboken2/ApiExtractor/typesystem_typedefs.h index 5cea587ed..fd702793e 100644 --- a/sources/shiboken2/ApiExtractor/typesystem_typedefs.h +++ b/sources/shiboken2/ApiExtractor/typesystem_typedefs.h @@ -43,9 +43,9 @@ struct FunctionModification; using AddedFunctionPtr = QSharedPointer<AddedFunction>; using AddedFunctionList = QVector<AddedFunctionPtr>; -typedef QVector<CodeSnip> CodeSnipList; -typedef QVector<DocModification> DocModificationList; -typedef QVector<FieldModification> FieldModificationList; -typedef QVector<FunctionModification> FunctionModificationList; +using CodeSnipList = QVector<CodeSnip>; +using DocModificationList = QVector<DocModification>; +using FieldModificationList = QVector<FieldModification>; +using FunctionModificationList = QVector<FunctionModification>; #endif // TYPESYSTEM_TYPEDEFS_H diff --git a/sources/shiboken2/generator/generator.h b/sources/shiboken2/generator/generator.h index b7b002ea6..dde281f0e 100644 --- a/sources/shiboken2/generator/generator.h +++ b/sources/shiboken2/generator/generator.h @@ -147,9 +147,9 @@ private: */ class GeneratorContext { public: - GeneratorContext() : m_metaClass(0), m_preciseClassType(0), m_forSmartPointer(false) {} + GeneratorContext() = default; GeneratorContext(AbstractMetaClass *metaClass, - const AbstractMetaType *preciseType = 0, + const AbstractMetaType *preciseType = nullptr, bool forSmartPointer = false) : m_metaClass(metaClass), m_preciseClassType(preciseType), @@ -161,9 +161,9 @@ public: const AbstractMetaType *preciseType() const { return m_preciseClassType; } private: - AbstractMetaClass *m_metaClass; - const AbstractMetaType *m_preciseClassType; - bool m_forSmartPointer; + AbstractMetaClass *m_metaClass = nullptr; + const AbstractMetaType *m_preciseClassType = nullptr; + bool m_forSmartPointer = false; }; /** @@ -173,8 +173,8 @@ private: class Generator { public: - typedef QPair<QString, QString> OptionDescription; - typedef QVector<OptionDescription> OptionDescriptions; + using OptionDescription = QPair<QString, QString>; + using OptionDescriptions = QVector<OptionDescription>; /// Optiosn used around the generator code enum Option { @@ -414,8 +414,8 @@ private: }; Q_DECLARE_OPERATORS_FOR_FLAGS(Generator::Options) -typedef QSharedPointer<Generator> GeneratorPtr; -typedef QVector<GeneratorPtr> Generators; +using GeneratorPtr = QSharedPointer<Generator>; +using Generators = QVector<GeneratorPtr>; #endif // GENERATOR_H diff --git a/sources/shiboken2/generator/main.cpp b/sources/shiboken2/generator/main.cpp index 4c84e0d47..25daea99e 100644 --- a/sources/shiboken2/generator/main.cpp +++ b/sources/shiboken2/generator/main.cpp @@ -59,9 +59,9 @@ static inline QString skipDeprecatedOption() { return QStringLiteral("skip-depre static const char helpHint[] = "Note: use --help or -h for more information.\n"; -typedef QMap<QString, QString> CommandArgumentMap; +using CommandArgumentMap = QMap<QString, QString>; -typedef Generator::OptionDescriptions OptionDescriptions; +using OptionDescriptions = Generator::OptionDescriptions; static void printOptions(QTextStream &s, const OptionDescriptions &options) { diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp index 6abfde7c9..9cad400f3 100644 --- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.cpp @@ -387,7 +387,7 @@ QtXmlToSphinx::QtXmlToSphinx(QtDocGenerator* generator, const QString& doc, cons void QtXmlToSphinx::pushOutputBuffer() { - QString* buffer = new QString(); + auto *buffer = new QString(); m_buffers << buffer; m_output.setString(buffer); } @@ -427,7 +427,7 @@ QString QtXmlToSphinx::resolveContextForMethod(const QString& methodName) const { const QStringRef currentClass = m_context.splitRef(QLatin1Char('.')).constLast(); - const AbstractMetaClass* metaClass = 0; + const AbstractMetaClass *metaClass = nullptr; const AbstractMetaClassList &classes = m_generator->classes(); for (const AbstractMetaClass *cls : classes) { if (cls->name() == currentClass) { @@ -444,7 +444,7 @@ QString QtXmlToSphinx::resolveContextForMethod(const QString& methodName) const funcList.append(func); } - const AbstractMetaClass* implementingClass = 0; + const AbstractMetaClass *implementingClass = nullptr; for (const AbstractMetaFunction *func : qAsConst(funcList)) { implementingClass = func->implementingClass(); if (implementingClass->name() == currentClass) @@ -528,7 +528,6 @@ static QString resolveFile(const QStringList &locations, const QString &path) QString QtXmlToSphinx::readFromLocations(const QStringList &locations, const QString &path, const QString &identifier, QString *errorMessage) { - QString result; QString resolvedPath; if (path.endsWith(QLatin1String(".cpp"))) { const QString pySnippet = path.left(path.size() - 3) + QLatin1String("py"); @@ -919,7 +918,8 @@ void QtXmlToSphinx::handleListTag(QXmlStreamReader& reader) if (token == QXmlStreamReader::StartElement) { listType = webXmlListType(reader.attributes().value(QLatin1String("type"))); if (listType == EnumeratedList) { - m_currentTable << (TableRow() << "Constant" << "Description"); + m_currentTable << TableRow{TableCell(QLatin1String("Constant")), + TableCell(QLatin1String("Description"))}; m_tableHasHeader = true; } INDENT.indent--; @@ -981,7 +981,7 @@ QtXmlToSphinx::LinkContext *QtXmlToSphinx::handleLinkStart(const QString &type, { ref.replace(QLatin1String("::"), QLatin1String(".")); ref.remove(QLatin1String("()")); - LinkContext *result = new LinkContext(ref); + auto *result = new LinkContext(ref); if (m_insideBold) result->flags |= LinkContext::InsideBold; @@ -1503,7 +1503,7 @@ static QString getFuncName(const AbstractMetaFunction* cppFunc) { return result; } -QtDocGenerator::QtDocGenerator() : m_docParser(0) +QtDocGenerator::QtDocGenerator() : m_docParser(nullptr) { } @@ -1656,8 +1656,8 @@ void QtDocGenerator::generateClass(QTextStream &s, GeneratorContext &classContex "--------------------\n\n" << ".. _More:\n"; - writeInjectDocumentation(s, TypeSystem::DocModificationPrepend, metaClass, 0); - if (!writeInjectDocumentation(s, TypeSystem::DocModificationReplace, metaClass, 0)) + writeInjectDocumentation(s, TypeSystem::DocModificationPrepend, metaClass, nullptr); + if (!writeInjectDocumentation(s, TypeSystem::DocModificationReplace, metaClass, nullptr)) writeFormattedText(s, documentation, metaClass); if (!metaClass->isNamespace()) @@ -1679,7 +1679,7 @@ void QtDocGenerator::generateClass(QTextStream &s, GeneratorContext &classContex writeFunction(s, metaClass, func); } - writeInjectDocumentation(s, TypeSystem::DocModificationAppend, metaClass, 0); + writeInjectDocumentation(s, TypeSystem::DocModificationAppend, metaClass, nullptr); } void QtDocGenerator::writeFunctionList(QTextStream& s, const AbstractMetaClass* cppClass) @@ -1910,7 +1910,7 @@ void QtDocGenerator::writeDocSnips(QTextStream &s, QString codeBlock = code.mid(startBlock, endBlock - startBlock); const QStringList rows = codeBlock.split(QLatin1Char('\n')); - int currenRow = 0; + int currentRow = 0; int offset = 0; for (QString row : rows) { @@ -1918,25 +1918,24 @@ void QtDocGenerator::writeDocSnips(QTextStream &s, row.remove(invalidString); if (row.trimmed().size() == 0) { - if (currenRow == 0) + if (currentRow == 0) continue; s << endl; } - if (currenRow == 0) { + if (currentRow == 0) { //find offset - for (int i=0, i_max = row.size(); i < i_max; i++) { - if (row[i] == QLatin1Char(' ')) + for (auto c : row) { + if (c == QLatin1Char(' ')) offset++; - else if (row[i] == QLatin1Char('\n')) + else if (c == QLatin1Char('\n')) offset = 0; else break; } } - row = row.mid(offset); - s << row << endl; - currenRow++; + s << row.midRef(offset) << endl; + currentRow++; } code = code.mid(endBlock+endMarkup.size()); @@ -2110,7 +2109,7 @@ void QtDocGenerator::writeFunction(QTextStream& s, const AbstractMetaClass* cppC static void writeFancyToc(QTextStream& s, const QStringList& items, int cols = 4) { - typedef QMap<QChar, QStringList> TocMap; + using TocMap = QMap<QChar, QStringList>; TocMap tocMap; QChar Q = QLatin1Char('Q'); QChar idx; diff --git a/sources/shiboken2/generator/qtdoc/qtdocgenerator.h b/sources/shiboken2/generator/qtdoc/qtdocgenerator.h index 21afd0f49..53e292d22 100644 --- a/sources/shiboken2/generator/qtdoc/qtdocgenerator.h +++ b/sources/shiboken2/generator/qtdoc/qtdocgenerator.h @@ -59,21 +59,19 @@ public: struct TableCell { - short rowSpan; - short colSpan; + short rowSpan = 0; + short colSpan = 0; QString data; - TableCell(const QString& text = QString()) : rowSpan(0), colSpan(0), data(text) {} - TableCell(const char* text) : rowSpan(0), colSpan(0), data(QLatin1String(text)) {} + TableCell(const QString& text = QString()) : data(text) {} + TableCell(const char* text) : data(QLatin1String(text)) {} }; - typedef QList<TableCell> TableRow; + using TableRow = QList<TableCell>; class Table : public QList<TableRow> { public: - Table() : m_hasHeader(false), m_normalized(false) - { - } + Table() = default; void enableHeader(bool enable) { @@ -98,8 +96,8 @@ public: } private: - bool m_hasHeader; - bool m_normalized; + bool m_hasHeader = false; + bool m_normalized = false; }; QtXmlToSphinx(QtDocGenerator* generator, const QString& doc, const QString& context = QString()); diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 73e1a7c3e..84f0cd1f5 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -203,19 +203,17 @@ QString CppGenerator::fileNameForContext(GeneratorContext &context) const QString fileNameBase = metaClass->qualifiedCppName().toLower(); fileNameBase.replace(QLatin1String("::"), QLatin1String("_")); return fileNameBase + fileNameSuffix(); - } else { - const AbstractMetaType *smartPointerType = context.preciseType(); - QString fileNameBase = getFileNameBaseForSmartPointer(smartPointerType, metaClass); - return fileNameBase + fileNameSuffix(); } + const AbstractMetaType *smartPointerType = context.preciseType(); + QString fileNameBase = getFileNameBaseForSmartPointer(smartPointerType, metaClass); + return fileNameBase + fileNameSuffix(); } QVector<AbstractMetaFunctionList> CppGenerator::filterGroupedOperatorFunctions(const AbstractMetaClass *metaClass, uint queryIn) { // ( func_name, num_args ) => func_list - typedef QMap<QPair<QString, int >, AbstractMetaFunctionList> ResultMap; - ResultMap results; + QMap<QPair<QString, int>, AbstractMetaFunctionList> results; const AbstractMetaClass::OperatorQueryOptions query(queryIn); const AbstractMetaFunctionList &funcs = metaClass->operatorOverloads(query); for (AbstractMetaFunction *func : funcs) { @@ -237,7 +235,7 @@ QVector<AbstractMetaFunctionList> CppGenerator::filterGroupedOperatorFunctions(c } QVector<AbstractMetaFunctionList> result; result.reserve(results.size()); - for (ResultMap::const_iterator it = results.cbegin(), end = results.cend(); it != end; ++it) + for (auto it = results.cbegin(), end = results.cend(); it != end; ++it) result.append(it.value()); return result; } @@ -257,8 +255,7 @@ const AbstractMetaFunction *CppGenerator::boolCast(const AbstractMetaClass *meta && func->arguments().isEmpty() ? func : nullptr; } -typedef QMap<QString, AbstractMetaFunctionList> FunctionGroupMap; -typedef FunctionGroupMap::const_iterator FunctionGroupMapIt; +using FunctionGroupMap = QMap<QString, AbstractMetaFunctionList>; // Prevent ELF symbol qt_version_tag from being generated into the source static const char includeQDebug[] = @@ -390,7 +387,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) // Create string literal for smart pointer getter method. if (classContext.forSmartPointer()) { - const SmartPointerTypeEntry *typeEntry = + const auto *typeEntry = static_cast<const SmartPointerTypeEntry *>(classContext.preciseType() ->typeEntry()); QString rawGetter = typeEntry->getter(); @@ -509,7 +506,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) else if (!rfunc->isOperatorOverload()) { if (classContext.forSmartPointer()) { - const SmartPointerTypeEntry *smartPointerTypeEntry = + const auto *smartPointerTypeEntry = static_cast<const SmartPointerTypeEntry *>( classContext.preciseType()->typeEntry()); @@ -1426,7 +1423,7 @@ void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaCla pc << INDENT << getFullTypeNameWithoutModifiers(sourceType) << " cppIn"; writeMinimalConstructorExpression(pc, sourceType); pc << ';' << endl; - writeToCppConversion(pc, sourceType, 0, QLatin1String("pyIn"), QLatin1String("cppIn")); + writeToCppConversion(pc, sourceType, nullptr, QLatin1String("pyIn"), QLatin1String("cppIn")); pc << ';'; toCppConv.append(QLatin1String("cppIn")); } else if (!isWrapperType(sourceType)) { @@ -1662,7 +1659,7 @@ void CppGenerator::writeMethodWrapperPreamble(QTextStream &s, OverloadData &over } } -void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFunctionList overloads, +void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFunctionList &overloads, GeneratorContext &classContext) { ErrorCode errorCode(-1); @@ -1823,7 +1820,7 @@ void CppGenerator::writeConstructorWrapper(QTextStream &s, const AbstractMetaFun s << '}' << endl << endl; } -void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunctionList overloads, +void CppGenerator::writeMethodWrapper(QTextStream &s, const AbstractMetaFunctionList &overloads, GeneratorContext &classContext) { OverloadData overloadData(overloads, this); @@ -2150,7 +2147,9 @@ static QString pythonToCppConverterForArgumentName(const QString &argumentName) return result; } -void CppGenerator::writeTypeCheck(QTextStream &s, const AbstractMetaType *argType, QString argumentName, bool isNumber, QString customType, bool rejectNull) +void CppGenerator::writeTypeCheck(QTextStream &s, const AbstractMetaType *argType, + const QString &argumentName, bool isNumber, + const QString &customType, bool rejectNull) { QString customCheck; if (!customType.isEmpty()) { @@ -2265,7 +2264,7 @@ const AbstractMetaType *CppGenerator::getArgumentType(const AbstractMetaFunction if (argPos < 0 || argPos > func->arguments().size()) { qCWarning(lcShiboken).noquote().nospace() << QStringLiteral("Argument index for function '%1' out of range.").arg(func->signature()); - return 0; + return nullptr; } const AbstractMetaType *argType = nullptr; @@ -2403,8 +2402,8 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream &s, static void addConversionRuleCodeSnippet(CodeSnipList &snippetList, QString &rule, TypeSystem::Language /* conversionLanguage */, TypeSystem::Language snippetLanguage, - QString outputName = QString(), - QString inputName = QString()) + const QString &outputName = QString(), + const QString &inputName = QString()) { if (rule.isEmpty()) return; @@ -2513,10 +2512,11 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov s << "; // " << referenceFunction->minimalSignature() << endl; return; + } // To decide if a method call is possible at this point the current overload // data object cannot be the head, since it is just an entry point, or a root, // for the tree of arguments and it does not represent a valid method call. - } else if (!parentOverloadData->isHeadOverloadData()) { + if (!parentOverloadData->isHeadOverloadData()) { bool isLastArgument = parentOverloadData->nextOverloadData().isEmpty(); bool signatureFound = parentOverloadData->overloads().size() == 1; @@ -2600,7 +2600,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream &s, const Ov || od->nextOverloadData().size() != 1 || od->overloads().size() != od->nextOverloadData().constFirst()->overloads().size()) { overloadData = od; - od = 0; + od = nullptr; } else { od = od->nextOverloadData().constFirst(); } @@ -2879,7 +2879,7 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s, const AbstractMetaType *targetType, QString typeCheck, QString conversion, - QString preConversion) + const QString &preConversion) { QString sourcePyType = cpythonTypeNameExt(sourceType); @@ -3065,7 +3065,7 @@ void CppGenerator::writeNamedArgumentResolution(QTextStream &s, const AbstractMe QString CppGenerator::argumentNameFromIndex(const AbstractMetaFunction *func, int argIndex, const AbstractMetaClass **wrappedClass) { - *wrappedClass = 0; + *wrappedClass = nullptr; QString pyArgName; if (argIndex == -1) { pyArgName = QLatin1String("self"); @@ -3765,11 +3765,9 @@ QString CppGenerator::multipleInheritanceInitializerFunctionName(const AbstractM return cpythonBaseName(metaClass->typeEntry()) + QLatin1String("_mi_init"); } -typedef QHash<QString, QPair<QString, QString> >::const_iterator ProtocolIt; - bool CppGenerator::supportsMappingProtocol(const AbstractMetaClass *metaClass) { - for (ProtocolIt it = m_mappingProtocol.cbegin(), end = m_mappingProtocol.cend(); it != end; ++it) { + for (auto it = m_mappingProtocol.cbegin(), end = m_mappingProtocol.cend(); it != end; ++it) { if (metaClass->hasFunction(it.key())) return true; } @@ -3787,7 +3785,7 @@ bool CppGenerator::supportsNumberProtocol(const AbstractMetaClass *metaClass) bool CppGenerator::supportsSequenceProtocol(const AbstractMetaClass *metaClass) { - for (ProtocolIt it = m_sequenceProtocol.cbegin(), end = m_sequenceProtocol.cend(); it != end; ++it) { + for (auto it = m_sequenceProtocol.cbegin(), end = m_sequenceProtocol.cend(); it != end; ++it) { if (metaClass->hasFunction(it.key())) return true; } @@ -4074,7 +4072,7 @@ void CppGenerator::writeTypeAsSequenceDefinition(QTextStream &s, const AbstractM { bool hasFunctions = false; QMap<QString, QString> funcs; - for (ProtocolIt it = m_sequenceProtocol.cbegin(), end = m_sequenceProtocol.cend(); it != end; ++it) { + for (auto it = m_sequenceProtocol.cbegin(), end = m_sequenceProtocol.cend(); it != end; ++it) { const QString &funcName = it.key(); const AbstractMetaFunction *func = metaClass->findFunction(funcName); funcs[funcName] = func ? cpythonFunctionName(func).prepend(QLatin1Char('&')) : QString(); @@ -4107,7 +4105,7 @@ void CppGenerator::writeTypeAsMappingDefinition(QTextStream &s, const AbstractMe { bool hasFunctions = false; QMap<QString, QString> funcs; - for (ProtocolIt it = m_mappingProtocol.cbegin(), end = m_mappingProtocol.cend(); it != end; ++it) { + for (auto it = m_mappingProtocol.cbegin(), end = m_mappingProtocol.cend(); it != end; ++it) { const QString &funcName = it.key(); const AbstractMetaFunction *func = metaClass->findFunction(funcName); funcs[funcName] = func ? cpythonFunctionName(func).prepend(QLatin1Char('&')) : QLatin1String("0"); @@ -4872,7 +4870,7 @@ void CppGenerator::writeFlagsBinaryOperator(QTextStream &s, const AbstractMetaEn s << "#endif" << endl << endl; s << INDENT << "cppResult = " << CPP_SELF_VAR << " " << cppOpName << " cppArg;" << endl; s << INDENT << "return "; - writeToPythonConversion(s, flagsType, 0, QLatin1String("cppResult")); + writeToPythonConversion(s, flagsType, nullptr, QLatin1String("cppResult")); s << ';' << endl; s << '}' << endl << endl; } @@ -4900,7 +4898,7 @@ void CppGenerator::writeFlagsUnaryOperator(QTextStream &s, const AbstractMetaEnu if (boolResult) s << "PyBool_FromLong(cppResult)"; else - writeToPythonConversion(s, flagsType, 0, QLatin1String("cppResult")); + writeToPythonConversion(s, flagsType, nullptr, QLatin1String("cppResult")); s << ';' << endl; s << '}' << endl << endl; } @@ -5479,7 +5477,7 @@ bool CppGenerator::finishGeneration() // Initialize smart pointer types. const QVector<const AbstractMetaType *> &smartPtrs = instantiatedSmartPointers(); for (const AbstractMetaType *metaType : smartPtrs) { - GeneratorContext context(0, metaType, true); + GeneratorContext context(nullptr, metaType, true); QString initFunctionName = getInitFunctionName(context); s_classInitDecl << "void init_" << initFunctionName << "(PyObject *module);" << endl; QString defineStr = QLatin1String("init_") + initFunctionName; diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.h b/sources/shiboken2/generator/shiboken2/cppgenerator.h index 44a04653a..ae6da9582 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.h +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.h @@ -72,8 +72,9 @@ private: void writeMethodWrapperPreamble(QTextStream &s, OverloadData &overloadData, GeneratorContext &context); - void writeConstructorWrapper(QTextStream &s, const AbstractMetaFunctionList overloads, GeneratorContext &classContext); - void writeMethodWrapper(QTextStream &s, const AbstractMetaFunctionList overloads, + void writeConstructorWrapper(QTextStream &s, const AbstractMetaFunctionList &overloads, + GeneratorContext &classContext); + void writeMethodWrapper(QTextStream &s, const AbstractMetaFunctionList &overloads, GeneratorContext &classContext); void writeArgumentsInitializer(QTextStream &s, OverloadData &overloadData); void writeCppSelfAssigment(QTextStream &s, const GeneratorContext &context, @@ -94,8 +95,10 @@ private: /// Writes the check section for the validity of wrapped C++ objects. void writeInvalidPyObjectCheck(QTextStream &s, const QString &pyObj); - void writeTypeCheck(QTextStream &s, const AbstractMetaType *argType, QString argumentName, bool isNumber = false, QString customType = QString(), bool rejectNull = false); - void writeTypeCheck(QTextStream &s, const OverloadData *overloadData, QString argumentName); + void writeTypeCheck(QTextStream &s, const AbstractMetaType *argType, const QString &argumentName, + bool isNumber = false, const QString &customType = QString(), + bool rejectNull = false); + void writeTypeCheck(QTextStream& s, const OverloadData *overloadData, QString argumentName); void writeTypeDiscoveryFunction(QTextStream &s, const AbstractMetaClass *metaClass); @@ -117,7 +120,7 @@ private: */ void writeArgumentConversion(QTextStream &s, const AbstractMetaType *argType, const QString &argName, const QString &pyArgName, - const AbstractMetaClass *context = 0, + const AbstractMetaClass *context = nullptr, const QString &defaultValue = QString(), bool castArgumentAsUnused = false); @@ -138,7 +141,7 @@ private: const AbstractMetaType *type, const QString &pyIn, const QString &cppOut, - const AbstractMetaClass *context = 0, + const AbstractMetaClass *context = nullptr, const QString &defaultValue = QString()); /// Writes the conversion rule for arguments of regular and virtual methods. @@ -213,7 +216,7 @@ private: const AbstractMetaType *targetType, QString typeCheck = QString(), QString conversion = QString(), - QString preConversion = QString()); + const QString &preConversion = QString()); /// Writes a pair of Python to C++ conversion and check functions for implicit conversions. void writePythonToCppConversionFunctions(QTextStream &s, const CustomConversion::TargetToNativeConversion *toNative, diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp index 82b2d96d6..8a2c56232 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp @@ -310,7 +310,7 @@ void HeaderGenerator::writeTypeIndexValueLine(QTextStream &s, const TypeEntry *t const int typeIndex = typeEntry->sbkIndex(); _writeTypeIndexValueLine(s, getTypeIndexVariableName(typeEntry), typeIndex); if (typeEntry->isComplex()) { - const ComplexTypeEntry *cType = static_cast<const ComplexTypeEntry *>(typeEntry); + const auto *cType = static_cast<const ComplexTypeEntry *>(typeEntry); if (cType->baseContainerType()) { const AbstractMetaClass *metaClass = AbstractMetaClass::findClass(classes(), cType); if (metaClass->templateBaseClass()) diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.cpp b/sources/shiboken2/generator/shiboken2/overloaddata.cpp index 89c73576e..5c3d7d0b8 100644 --- a/sources/shiboken2/generator/shiboken2/overloaddata.cpp +++ b/sources/shiboken2/generator/shiboken2/overloaddata.cpp @@ -254,7 +254,7 @@ void OverloadData::sortNextOverloads() // be called. In the case of primitive types, list<double> must come before list<int>. if (instantiation->isPrimitive() && (signedIntegerPrimitives.contains(instantiation->name()))) { for (const QString &primitive : qAsConst(nonIntegerPrimitives)) - sortData.mapType(getImplicitConversionTypeName(ov->argType(), instantiation, 0, primitive)); + sortData.mapType(getImplicitConversionTypeName(ov->argType(), instantiation, nullptr, primitive)); } else { const AbstractMetaFunctionList &funcs = m_generator->implicitConversions(instantiation); for (const AbstractMetaFunction *function : funcs) @@ -346,7 +346,7 @@ void OverloadData::sortNextOverloads() if (instantiation->isPrimitive() && (signedIntegerPrimitives.contains(instantiation->name()))) { for (const QString &primitive : qAsConst(nonIntegerPrimitives)) { - QString convertibleTypeName = getImplicitConversionTypeName(ov->argType(), instantiation, 0, primitive); + QString convertibleTypeName = getImplicitConversionTypeName(ov->argType(), instantiation, nullptr, primitive); if (!graph.containsEdge(targetTypeId, sortData.map[convertibleTypeName])) // Avoid cyclic dependency. graph.addEdge(sortData.map[convertibleTypeName], targetTypeId); } @@ -467,8 +467,8 @@ void OverloadData::sortNextOverloads() * */ OverloadData::OverloadData(const AbstractMetaFunctionList &overloads, const ShibokenGenerator *generator) - : m_minArgs(256), m_maxArgs(0), m_argPos(-1), m_argType(0), - m_headOverloadData(this), m_previousOverloadData(0), m_generator(generator) + : m_minArgs(256), m_maxArgs(0), m_argPos(-1), m_argType(nullptr), + m_headOverloadData(this), m_previousOverloadData(nullptr), m_generator(generator) { for (const AbstractMetaFunction *func : overloads) { m_overloads.append(func); @@ -658,7 +658,7 @@ const AbstractMetaFunction *OverloadData::referenceFunction() const const AbstractMetaArgument *OverloadData::argument(const AbstractMetaFunction *func) const { if (isHeadOverloadData() || !m_overloads.contains(func)) - return 0; + return nullptr; int argPos = 0; int removed = 0; @@ -757,7 +757,7 @@ const AbstractMetaFunction *OverloadData::getFunctionWithDefaultValue() const if (!ShibokenGenerator::getDefaultValue(func, func->arguments().at(m_argPos + removedArgs)).isEmpty()) return func; } - return 0; + return nullptr; } QVector<int> OverloadData::invalidArgumentLengths() const diff --git a/sources/shiboken2/generator/shiboken2/overloaddata.h b/sources/shiboken2/generator/shiboken2/overloaddata.h index c9304d461..4fd4199e5 100644 --- a/sources/shiboken2/generator/shiboken2/overloaddata.h +++ b/sources/shiboken2/generator/shiboken2/overloaddata.h @@ -38,12 +38,12 @@ QT_FORWARD_DECLARE_CLASS(QDebug) class ShibokenGenerator; class OverloadData; -typedef QVector<OverloadData *> OverloadDataList; +using OverloadDataList = QVector<OverloadData *>; class OverloadData { public: - typedef QVector<const AbstractMetaFunction *> MetaFunctionList; + using MetaFunctionList = QVector<const AbstractMetaFunction *>; OverloadData(const AbstractMetaFunctionList &overloads, const ShibokenGenerator *generator); ~OverloadData(); diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 9ed175af4..8e27777d6 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -340,7 +340,7 @@ void ShibokenGenerator::lookForEnumsInClassesNotToBeGenerated(AbstractMetaEnumLi static const AbstractMetaClass *getProperEnclosingClass(const AbstractMetaClass *metaClass) { if (!metaClass) - return 0; + return nullptr; if (metaClass->typeEntry()->codeGeneration() != TypeEntry::GenerateForSubclass) return metaClass; @@ -750,7 +750,7 @@ QString ShibokenGenerator::getFormatUnitString(const AbstractMetaFunction *func, || arg->type()->referenceType() == LValueReference) { result += QLatin1Char(objType); } else if (arg->type()->isPrimitive()) { - const PrimitiveTypeEntry *ptype = + const auto *ptype = static_cast<const PrimitiveTypeEntry *>(arg->type()->typeEntry()); if (ptype->basicReferencedTypeEntry()) ptype = ptype->basicReferencedTypeEntry(); @@ -790,7 +790,7 @@ QString ShibokenGenerator::cpythonBaseName(const TypeEntry *type) if (ShibokenGenerator::isWrapperType(type) || type->isNamespace()) { // && type->referenceType() == NoReference) { baseName = QLatin1String("Sbk_") + type->name(); } else if (type->isPrimitive()) { - const PrimitiveTypeEntry *ptype = static_cast<const PrimitiveTypeEntry *>(type); + const auto *ptype = static_cast<const PrimitiveTypeEntry *>(type); while (ptype->basicReferencedTypeEntry()) ptype = ptype->basicReferencedTypeEntry(); if (ptype->targetLangApiName() == ptype->name()) @@ -802,7 +802,7 @@ QString ShibokenGenerator::cpythonBaseName(const TypeEntry *type) } else if (type->isFlags()) { baseName = cpythonFlagsName(static_cast<const FlagsTypeEntry *>(type)); } else if (type->isContainer()) { - const ContainerTypeEntry *ctype = static_cast<const ContainerTypeEntry *>(type); + const auto *ctype = static_cast<const ContainerTypeEntry *>(type); switch (ctype->type()) { case ContainerTypeEntry::ListContainer: case ContainerTypeEntry::StringListContainer: @@ -883,7 +883,7 @@ QString ShibokenGenerator::converterObject(const TypeEntry *type) } /* the typedef'd primitive types case */ - const PrimitiveTypeEntry *pte = dynamic_cast<const PrimitiveTypeEntry *>(type); + const auto *pte = dynamic_cast<const PrimitiveTypeEntry *>(type); if (!pte) { qDebug() << "Warning: the Qt5 primitive type is unknown" << type->qualifiedCppName(); return QString(); @@ -1104,7 +1104,7 @@ bool ShibokenGenerator::isUserPrimitive(const TypeEntry *type) { if (!type->isPrimitive()) return false; - const PrimitiveTypeEntry *trueType = static_cast<const PrimitiveTypeEntry *>(type); + const auto *trueType = static_cast<const PrimitiveTypeEntry *>(type); if (trueType->basicReferencedTypeEntry()) trueType = trueType->basicReferencedTypeEntry(); return trueType->isPrimitive() && !trueType->isCppPrimitive() @@ -1124,7 +1124,7 @@ bool ShibokenGenerator::isCppPrimitive(const TypeEntry *type) return true; if (!type->isPrimitive()) return false; - const PrimitiveTypeEntry *trueType = static_cast<const PrimitiveTypeEntry *>(type); + const auto *trueType = static_cast<const PrimitiveTypeEntry *>(type); if (trueType->basicReferencedTypeEntry()) trueType = trueType->basicReferencedTypeEntry(); return trueType->qualifiedCppName() == QLatin1String("std::string"); @@ -1252,7 +1252,7 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type, bool gene QString ShibokenGenerator::guessCPythonCheckFunction(const QString &type, AbstractMetaType **metaType) { - *metaType = 0; + *metaType = nullptr; if (type == QLatin1String("PyTypeObject")) return QLatin1String("PyType_Check"); @@ -1510,18 +1510,18 @@ void ShibokenGenerator::writeArgumentNames(QTextStream &s, const AbstractMetaFunction *func, Options options) const { - AbstractMetaArgumentList arguments = func->arguments(); + const AbstractMetaArgumentList arguments = func->arguments(); int argCount = 0; - for (int j = 0, max = arguments.size(); j < max; j++) { - - if ((options & Generator::SkipRemovedArguments) && (func->argumentRemoved(arguments.at(j)->argumentIndex()+1))) + for (auto argument : arguments) { + const int index = argument->argumentIndex() + 1; + if ((options & Generator::SkipRemovedArguments) && (func->argumentRemoved(index))) continue; - s << ((argCount > 0) ? ", " : "") << arguments.at(j)->name(); + s << ((argCount > 0) ? ", " : "") << argument->name(); if (((options & Generator::VirtualCall) == 0) - && (!func->conversionRule(TypeSystem::NativeCode, arguments.at(j)->argumentIndex() + 1).isEmpty() - || !func->conversionRule(TypeSystem::TargetLangCode, arguments.at(j)->argumentIndex() + 1).isEmpty()) + && (!func->conversionRule(TypeSystem::NativeCode, index).isEmpty() + || !func->conversionRule(TypeSystem::TargetLangCode, index).isEmpty()) && !func->isConstructor()) { s << CONV_RULE_OUT_VAR_SUFFIX; } @@ -2011,7 +2011,7 @@ static QString getConverterTypeSystemVariableArgument(const QString &code, int p qFatal("Unbalanced parenthesis on type system converter variable call."); return arg; } -typedef QPair<QString, QString> StringPair; +using StringPair = QPair<QString, QString>; void ShibokenGenerator::replaceConverterTypeSystemVariable(TypeSystemConverterVariable converterVariable, QString &code) { @@ -2323,7 +2323,7 @@ AbstractMetaType *ShibokenGenerator::buildAbstractMetaTypeFromTypeEntry(const Ty typeName.remove(0, 2); if (m_metaTypeFromStringCache.contains(typeName)) return m_metaTypeFromStringCache.value(typeName); - AbstractMetaType *metaType = new AbstractMetaType; + auto *metaType = new AbstractMetaType; metaType->setTypeEntry(typeEntry); metaType->clearIndirections(); metaType->setReferenceType(NoReference); @@ -2663,7 +2663,7 @@ QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaClass *met QString ShibokenGenerator::getTypeIndexVariableName(const TypeEntry *type) { if (type->isCppPrimitive()) { - const PrimitiveTypeEntry *trueType = static_cast<const PrimitiveTypeEntry *>(type); + const auto *trueType = static_cast<const PrimitiveTypeEntry *>(type); if (trueType->basicReferencedTypeEntry()) type = trueType->basicReferencedTypeEntry(); } @@ -2763,7 +2763,7 @@ bool ShibokenGenerator::isCppIntegralPrimitive(const TypeEntry *type) { if (!type->isCppPrimitive()) return false; - const PrimitiveTypeEntry *trueType = static_cast<const PrimitiveTypeEntry *>(type); + const auto *trueType = static_cast<const PrimitiveTypeEntry *>(type); if (trueType->basicReferencedTypeEntry()) trueType = trueType->basicReferencedTypeEntry(); QString typeName = trueType->qualifiedCppName(); diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.h b/sources/shiboken2/generator/shiboken2/shibokengenerator.h index fe6a1dc37..84b3137b8 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.h +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.h @@ -118,7 +118,7 @@ protected: const QVector<CodeSnip> & codeSnips, TypeSystem::CodeSnipPosition position, TypeSystem::Language language, - const AbstractMetaClass *context = 0); + const AbstractMetaClass *context = nullptr); /// Write user's custom code snippets at function level. void writeCodeSnips(QTextStream &s, const QVector<CodeSnip> & codeSnips, @@ -312,8 +312,8 @@ protected: QString cpythonIsConvertibleFunction(const AbstractMetaArgument *metaArg, bool genericNumberType = false); QString cpythonToCppConversionFunction(const AbstractMetaClass *metaClass); - QString cpythonToCppConversionFunction(const AbstractMetaType *type, const AbstractMetaClass *context = 0); - QString cpythonToPythonConversionFunction(const AbstractMetaType *type, const AbstractMetaClass *context = 0); + QString cpythonToCppConversionFunction(const AbstractMetaType *type, const AbstractMetaClass *context = nullptr); + QString cpythonToPythonConversionFunction(const AbstractMetaType *type, const AbstractMetaClass *context = nullptr); QString cpythonToPythonConversionFunction(const AbstractMetaClass *metaClass); QString cpythonToPythonConversionFunction(const TypeEntry *type); @@ -418,7 +418,7 @@ protected: // All data about extended converters: the type entries of the target type, and a // list of AbstractMetaClasses accepted as argument for the conversion. - typedef QHash<const TypeEntry *, QVector<const AbstractMetaClass *> > ExtendedConverterData; + using ExtendedConverterData = QHash<const TypeEntry *, QVector<const AbstractMetaClass *> >; /// Returns all extended conversions for the current module. ExtendedConverterData getExtendedConverters() const; @@ -491,9 +491,9 @@ private: QString functionReturnType(const AbstractMetaFunction *func, Options options = NoOption) const; /// Utility function for writeCodeSnips. - typedef QPair<const AbstractMetaArgument *, QString> ArgumentVarReplacementPair; - typedef QVector<ArgumentVarReplacementPair> ArgumentVarReplacementList; - ArgumentVarReplacementList getArgumentReplacement(const AbstractMetaFunction *func, + using ArgumentVarReplacementPair = QPair<const AbstractMetaArgument *, QString>; + using ArgumentVarReplacementList = QVector<ArgumentVarReplacementPair>; + ArgumentVarReplacementList getArgumentReplacement(const AbstractMetaFunction* func, bool usePyArgs, TypeSystem::Language language, const AbstractMetaArgument *lastArg); @@ -542,7 +542,7 @@ private: bool m_useIsNullAsNbNonZero = false; bool m_avoidProtectedHack = false; - typedef QHash<QString, AbstractMetaType *> AbstractMetaTypeCache; + using AbstractMetaTypeCache = QHash<QString, AbstractMetaType *>; AbstractMetaTypeCache m_metaTypeFromStringCache; /// Type system converter variable replacement names and regular expressions. diff --git a/sources/shiboken2/libshiboken/autodecref.h b/sources/shiboken2/libshiboken/autodecref.h index b2f5a6325..d3353b1e4 100644 --- a/sources/shiboken2/libshiboken/autodecref.h +++ b/sources/shiboken2/libshiboken/autodecref.h @@ -75,14 +75,14 @@ public: Py_XDECREF(m_pyObj); } - inline bool isNull() const { return m_pyObj == 0; } + inline bool isNull() const { return m_pyObj == nullptr; } /// Returns the pointer of the Python object being held. inline PyObject *object() { return m_pyObj; } inline operator PyObject *() { return m_pyObj; } #ifndef Py_LIMITED_API inline operator PyTupleObject *() { return reinterpret_cast<PyTupleObject *>(m_pyObj); } #endif - inline operator bool() const { return m_pyObj != 0; } + inline operator bool() const { return m_pyObj != nullptr; } inline PyObject *operator->() { return m_pyObj; } template<typename T> diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index a12d95982..b9f6735d8 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -86,14 +86,13 @@ static PyGetSetDef SbkObjectType_Type_getsetlist[] = { }; static PyType_Slot SbkObjectType_Type_slots[] = { - {Py_tp_dealloc, (void *)SbkObjectTypeDealloc}, - {Py_tp_setattro, (void *)PyObject_GenericSetAttr}, - {Py_tp_base, (void *)&PyType_Type}, - {Py_tp_alloc, (void *)PyType_GenericAlloc}, - {Py_tp_getset, (void *)SbkObjectType_Type_getsetlist}, - {Py_tp_new, (void *)SbkObjectTypeTpNew}, - {Py_tp_free, (void *)PyObject_GC_Del}, - {0, 0} + {Py_tp_dealloc, reinterpret_cast<void *>(SbkObjectTypeDealloc)}, + {Py_tp_setattro, reinterpret_cast<void *>(PyObject_GenericSetAttr)}, + {Py_tp_base, static_cast<void *>(&PyType_Type)}, + {Py_tp_alloc, reinterpret_cast<void *>(PyType_GenericAlloc)}, + {Py_tp_new, reinterpret_cast<void *>(SbkObjectTypeTpNew)}, + {Py_tp_free, reinterpret_cast<void *>(PyObject_GC_Del)}, + {0, nullptr} }; static PyType_Spec SbkObjectType_Type_spec = { "Shiboken.ObjectType", @@ -207,23 +206,23 @@ PyTypeObject *SbkObjectType_TypeF(void) static PyObject *SbkObjectGetDict(PyObject *pObj, void *) { - SbkObject *obj = reinterpret_cast<SbkObject *>(pObj); + auto *obj = reinterpret_cast<SbkObject *>(pObj); if (!obj->ob_dict) obj->ob_dict = PyDict_New(); if (!obj->ob_dict) - return 0; + return nullptr; Py_INCREF(obj->ob_dict); return obj->ob_dict; } static PyGetSetDef SbkObjectGetSetList[] = { - {const_cast<char *>("__dict__"), SbkObjectGetDict, 0, 0, 0}, - {0, 0, 0, 0, 0} // Sentinel + {const_cast<char *>("__dict__"), SbkObjectGetDict, nullptr, nullptr, nullptr}, + {nullptr, nullptr, nullptr, nullptr, nullptr} // Sentinel }; static int SbkObject_traverse(PyObject *self, visitproc visit, void *arg) { - SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self); + auto *sbkSelf = reinterpret_cast<SbkObject *>(self); //Visit children Shiboken::ParentInfo *pInfo = sbkSelf->d->parentInfo; @@ -246,7 +245,7 @@ static int SbkObject_traverse(PyObject *self, visitproc visit, void *arg) static int SbkObject_clear(PyObject *self) { - SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self); + auto *sbkSelf = reinterpret_cast<SbkObject *>(self); Shiboken::Object::removeParent(sbkSelf); @@ -261,13 +260,13 @@ static int SbkObject_clear(PyObject *self) } static PyType_Slot SbkObject_Type_slots[] = { - {Py_tp_dealloc, (void *)SbkDeallocWrapperWithPrivateDtor}, - {Py_tp_traverse, (void *)SbkObject_traverse}, - {Py_tp_clear, (void *)SbkObject_clear}, + {Py_tp_dealloc, reinterpret_cast<void *>(SbkDeallocWrapperWithPrivateDtor)}, + {Py_tp_traverse, reinterpret_cast<void *>(SbkObject_traverse)}, + {Py_tp_clear, reinterpret_cast<void *>(SbkObject_clear)}, // unsupported: {Py_tp_weaklistoffset, (void *)offsetof(SbkObject, weakreflist)}, - {Py_tp_getset, (void *)SbkObjectGetSetList}, + {Py_tp_getset, reinterpret_cast<void *>(SbkObjectGetSetList)}, // unsupported: {Py_tp_dictoffset, (void *)offsetof(SbkObject, ob_dict)}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkObject_Type_spec = { "Shiboken.Object", @@ -300,7 +299,7 @@ static int mainThreadDeletionHandler(void *) static void SbkDeallocWrapperCommon(PyObject *pyObj, bool canDelete) { - SbkObject *sbkObj = reinterpret_cast<SbkObject *>(pyObj); + auto *sbkObj = reinterpret_cast<SbkObject *>(pyObj); PyTypeObject *pyType = Py_TYPE(pyObj); // Need to decref the type if this is the dealloc func; if type @@ -377,7 +376,7 @@ void SbkDeallocQAppWrapper(PyObject *pyObj) { SbkDeallocWrapper(pyObj); // PYSIDE-571: make sure to create a singleton deleted qApp. - MakeSingletonQAppWrapper(NULL); + MakeSingletonQAppWrapper(nullptr); } void SbkDeallocWrapperWithPrivateDtor(PyObject *self) @@ -427,11 +426,11 @@ PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *k PyObject *dict; static const char *kwlist[] = { "name", "bases", "dict", nullptr}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO!O!:sbktype", (char **)kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO!O!:sbktype", const_cast<char **>(kwlist), &name, &PyTuple_Type, &pyBases, &PyDict_Type, &dict)) - return NULL; + return nullptr; for (int i=0, i_max=PyTuple_GET_SIZE(pyBases); i < i_max; i++) { PyObject *baseType = PyTuple_GET_ITEM(pyBases, i); @@ -449,10 +448,10 @@ PyObject *SbkObjectTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *k } // The meta type creates a new type when the Python programmer extends a wrapped C++ class. - newfunc type_new = reinterpret_cast<newfunc>(PyType_Type.tp_new); - SbkObjectType *newType = reinterpret_cast<SbkObjectType *>(type_new(metatype, args, kwds)); + auto type_new = reinterpret_cast<newfunc>(PyType_Type.tp_new); + auto *newType = reinterpret_cast<SbkObjectType *>(type_new(metatype, args, kwds)); if (!newType) - return 0; + return nullptr; Shiboken::ObjectType::initPrivateData(newType); SbkObjectTypePrivate *sotp = PepType_SOTP(newType); @@ -543,7 +542,7 @@ PyObject *SbkQAppTpNew(PyTypeObject *subtype, PyObject *, PyObject *) } #endif auto self = reinterpret_cast<SbkObject *>(MakeSingletonQAppWrapper(subtype)); - return self == 0 ? 0 : _setupNew(self, subtype); + return self == nullptr ? nullptr : _setupNew(self, subtype); } void @@ -622,7 +621,7 @@ bool importModule(const char *moduleName, PyTypeObject *** cppApiPtr) #ifdef IS_PY3K if (PyCapsule_CheckExact(cppApi)) - *cppApiPtr = reinterpret_cast<PyTypeObject **>(PyCapsule_GetPointer(cppApi, 0)); + *cppApiPtr = reinterpret_cast<PyTypeObject **>(PyCapsule_GetPointer(cppApi, nullptr)); #else // Python 2.6 doesn't have PyCapsule API, so let's keep usign PyCObject on all Python 2.x if (PyCObject_Check(cppApi)) @@ -766,7 +765,7 @@ bool canCallConstructor(PyTypeObject *myType, PyTypeObject *ctorType) bool hasCast(SbkObjectType *type) { - return PepType_SOTP(type)->mi_specialcast != 0; + return PepType_SOTP(type)->mi_specialcast != nullptr; } void *cast(SbkObjectType *sourceType, SbkObject *obj, PyTypeObject *targetType) @@ -842,7 +841,7 @@ introduceWrapperType(PyObject *enclosingObject, PyObject *heaptype = PyType_FromSpecWithBases(typeSpec, baseTypes); Py_TYPE(heaptype) = SbkObjectType_TypeF(); Py_INCREF(Py_TYPE(heaptype)); - SbkObjectType *type = reinterpret_cast<SbkObjectType *>(heaptype); + auto *type = reinterpret_cast<SbkObjectType *>(heaptype); if (baseType) { if (baseTypes) { for (int i = 0; i < PySequence_Fast_GET_SIZE(baseTypes); ++i) @@ -862,7 +861,7 @@ introduceWrapperType(PyObject *enclosingObject, setOriginalName(type, originalName); setDestructorFunction(type, cppObjDtor); - PyObject *ob_type = reinterpret_cast<PyObject *>(type); + auto *ob_type = reinterpret_cast<PyObject *>(type); if (wrapperFlags & InnerClass) return PyDict_SetItemString(enclosingObject, typeName, ob_type) == 0 ? type : nullptr; @@ -1007,7 +1006,7 @@ void callCppDestructors(SbkObject *pyObj) } delete[] pyObj->d->cptr; - pyObj->d->cptr = 0; + pyObj->d->cptr = nullptr; pyObj->d->validCppObject = false; } @@ -1044,7 +1043,7 @@ void getOwnership(PyObject *pyObj) void releaseOwnership(SbkObject *self) { // skip if the ownership have already moved to c++ - SbkObjectType *selfType = reinterpret_cast<SbkObjectType *>(Py_TYPE(self)); + auto *selfType = reinterpret_cast<SbkObjectType *>(Py_TYPE(self)); if (!self->d->hasOwnership || Shiboken::Conversions::pythonTypeIsValueType(PepType_SOTP(selfType)->converter)) return; @@ -1155,7 +1154,7 @@ void *cppPointer(SbkObject *pyObj, PyTypeObject *desiredType) idx = getTypeIndexOnHierarchy(type, desiredType); if (pyObj->d->cptr) return pyObj->d->cptr[idx]; - return 0; + return nullptr; } std::vector<void *> cppPointers(SbkObject *pyObj) @@ -1175,7 +1174,7 @@ bool setCppPointer(SbkObject *sbkObj, PyTypeObject *desiredType, void *cptr) if (PepType_SOTP(type)->is_multicpp) idx = getTypeIndexOnHierarchy(type, desiredType); - const bool alreadyInitialized = sbkObj->d->cptr[idx] != 0; + const bool alreadyInitialized = sbkObj->d->cptr[idx] != nullptr; if (alreadyInitialized) PyErr_SetString(PyExc_RuntimeError, "You can't initialize an object twice!"); else @@ -1249,11 +1248,11 @@ SbkObject *findColocatedChild(SbkObject *wrapper, return wrapper; if (!(wrapper->d && wrapper->d->cptr)) - return 0; + return nullptr; ParentInfo *pInfo = wrapper->d->parentInfo; if (!pInfo) - return 0; + return nullptr; ChildrenList &children = pInfo->children; @@ -1261,13 +1260,11 @@ SbkObject *findColocatedChild(SbkObject *wrapper, if (!(child->d && child->d->cptr)) continue; if (child->d->cptr[0] == wrapper->d->cptr[0]) { - if (reinterpret_cast<const void *>(Py_TYPE(child)) == reinterpret_cast<const void *>(instanceType)) - return child; - else - return findColocatedChild(child, instanceType); + return reinterpret_cast<const void *>(Py_TYPE(child)) == reinterpret_cast<const void *>(instanceType) + ? child : findColocatedChild(child, instanceType); } } - return 0; + return nullptr; } PyObject *newObject(SbkObjectType *instanceType, @@ -1286,7 +1283,7 @@ PyObject *newObject(SbkObjectType *instanceType, bool shouldCreate = true; bool shouldRegister = true; - SbkObject *self = 0; + SbkObject *self = nullptr; // Some logic to ensure that colocated child field does not overwrite the parent if (BindingManager::instance().hasWrapper(cptr)) { @@ -1313,7 +1310,7 @@ PyObject *newObject(SbkObjectType *instanceType, } if (shouldCreate) { - self = reinterpret_cast<SbkObject *>(SbkObjectTpNew(reinterpret_cast<PyTypeObject *>(instanceType), 0, 0)); + self = reinterpret_cast<SbkObject *>(SbkObjectTpNew(reinterpret_cast<PyTypeObject *>(instanceType), nullptr, nullptr)); self->d->cptr[0] = cptr; self->d->hasOwnership = hasOwnership; self->d->validCppObject = 1; @@ -1328,7 +1325,7 @@ PyObject *newObject(SbkObjectType *instanceType, void destroy(SbkObject *self) { - destroy(self, 0); + destroy(self, nullptr); } void destroy(SbkObject *self, void *cppData) @@ -1369,7 +1366,7 @@ void destroy(SbkObject *self, void *cppData) // the cpp object instance was deleted delete[] self->d->cptr; - self->d->cptr = 0; + self->d->cptr = nullptr; } // After this point the object can be death do not use the self pointer bellow @@ -1393,7 +1390,7 @@ void removeParent(SbkObject *child, bool giveOwnershipBack, bool keepReference) oldBrothers.erase(iChild); - pInfo->parent = 0; + pInfo->parent = nullptr; // This will keep the wrapper reference, will wait for wrapper destruction to remove that if (keepReference && @@ -1427,7 +1424,7 @@ void setParent(PyObject *parent, PyObject *child) * follows the sequence protocol. */ if (PySequence_Check(child) && !Object::checkType(child)) { - Shiboken::AutoDecRef seq(PySequence_Fast(child, 0)); + Shiboken::AutoDecRef seq(PySequence_Fast(child, nullptr)); for (Py_ssize_t i = 0, max = PySequence_Size(seq); i < max; ++i) setParent(parent, PySequence_Fast_GET_ITEM(seq.object(), i)); return; @@ -1492,7 +1489,7 @@ void deallocData(SbkObject *self, bool cleanup) // Remove from BindingManager Shiboken::BindingManager::instance().releaseWrapper(self); delete[] self->d->cptr; - self->d->cptr = 0; + self->d->cptr = nullptr; // delete self->d; PYSIDE-205: wrong! } delete self->d; // PYSIDE-205: always delete d. diff --git a/sources/shiboken2/libshiboken/basewrapper_p.h b/sources/shiboken2/libshiboken/basewrapper_p.h index feba6561e..56a647b21 100644 --- a/sources/shiboken2/libshiboken/basewrapper_p.h +++ b/sources/shiboken2/libshiboken/basewrapper_p.h @@ -58,7 +58,7 @@ namespace Shiboken * This mapping associates a method and argument of an wrapper object with the wrapper of * said argument when it needs the binding to help manage its reference count. */ -typedef std::unordered_multimap<std::string, PyObject *> RefCountMap; +using RefCountMap = std::unordered_multimap<std::string, PyObject *> ; /// Linked list of SbkBaseWrapper pointers using ChildrenList = std::set<SbkObject *>; @@ -67,7 +67,7 @@ using ChildrenList = std::set<SbkObject *>; struct ParentInfo { /// Default ctor. - ParentInfo() : parent(0), hasWrapperRef(false) {} + ParentInfo() : parent(nullptr), hasWrapperRef(false) {} /// Pointer to parent object. SbkObject *parent; /// List of object children. @@ -105,9 +105,9 @@ struct SbkObjectPrivate ~SbkObjectPrivate() { delete parentInfo; - parentInfo = 0; + parentInfo = nullptr; delete referredObjects; - referredObjects = 0; + referredObjects = nullptr; } }; @@ -198,7 +198,7 @@ private: class BaseAccumulatorVisitor : public HierarchyVisitor { public: - typedef std::vector<SbkObjectType *> Result; + using Result = std::vector<SbkObjectType *>; bool visit(SbkObjectType *node) override; diff --git a/sources/shiboken2/libshiboken/bindingmanager.cpp b/sources/shiboken2/libshiboken/bindingmanager.cpp index c526d9b2e..725150e87 100644 --- a/sources/shiboken2/libshiboken/bindingmanager.cpp +++ b/sources/shiboken2/libshiboken/bindingmanager.cpp @@ -52,13 +52,13 @@ namespace Shiboken { -typedef std::unordered_map<const void *, SbkObject *> WrapperMap; +using WrapperMap = std::unordered_map<const void *, SbkObject *>; class Graph { public: - typedef std::vector<SbkObjectType *> NodeList; - typedef std::unordered_map<SbkObjectType *, NodeList> Edges; + using NodeList = std::vector<SbkObjectType *>; + using Edges = std::unordered_map<SbkObjectType *, NodeList>; Edges m_edges; @@ -91,7 +91,7 @@ public: SbkObjectType *identifyType(void **cptr, SbkObjectType *type, SbkObjectType *baseType) const { - Edges::const_iterator edgesIt = m_edges.find(type); + auto edgesIt = m_edges.find(type); if (edgesIt != m_edges.end()) { const NodeList &adjNodes = m_edges.find(type)->second; for (SbkObjectType *node : adjNodes) { @@ -154,8 +154,8 @@ bool BindingManager::BindingManagerPrivate::releaseWrapper(void *cptr, SbkObject // The wrapper argument is checked to ensure that the correct wrapper is released. // Returns true if the correct wrapper is found and released. // If wrapper argument is NULL, no such check is performed. - WrapperMap::iterator iter = wrapperMapper.find(cptr); - if (iter != wrapperMapper.end() && (wrapper == 0 || iter->second == wrapper)) { + auto iter = wrapperMapper.find(cptr); + if (iter != wrapperMapper.end() && (wrapper == nullptr || iter->second == wrapper)) { wrapperMapper.erase(iter); return true; } @@ -165,7 +165,7 @@ bool BindingManager::BindingManagerPrivate::releaseWrapper(void *cptr, SbkObject void BindingManager::BindingManagerPrivate::assignWrapper(SbkObject *wrapper, const void *cptr) { assert(cptr); - WrapperMap::iterator iter = wrapperMapper.find(cptr); + auto iter = wrapperMapper.find(cptr); if (iter == wrapperMapper.end()) wrapperMapper.insert(std::make_pair(cptr, wrapper)); } @@ -224,7 +224,7 @@ void BindingManager::registerWrapper(SbkObject *pyObj, void *cptr) int *offset = d->mi_offsets; while (*offset != -1) { if (*offset > 0) - m_d->assignWrapper(pyObj, reinterpret_cast<void *>((std::size_t) cptr + (*offset))); + m_d->assignWrapper(pyObj, reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(cptr) + *offset)); offset++; } } @@ -238,13 +238,13 @@ void BindingManager::releaseWrapper(SbkObject *sbkObj) void ** cptrs = reinterpret_cast<SbkObject *>(sbkObj)->d->cptr; for (int i = 0; i < numBases; ++i) { - unsigned char *cptr = reinterpret_cast<unsigned char *>(cptrs[i]); + auto *cptr = reinterpret_cast<unsigned char *>(cptrs[i]); m_d->releaseWrapper(cptr, sbkObj); if (d && d->mi_offsets) { int *offset = d->mi_offsets; while (*offset != -1) { if (*offset > 0) - m_d->releaseWrapper(reinterpret_cast<void *>((std::size_t) cptr + (*offset)), sbkObj); + m_d->releaseWrapper(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(cptr) + *offset), sbkObj); offset++; } } @@ -266,9 +266,9 @@ void BindingManager::addToDeletionInMainThread(const DestructorEntry &e) SbkObject *BindingManager::retrieveWrapper(const void *cptr) { - WrapperMap::iterator iter = m_d->wrapperMapper.find(cptr); + auto iter = m_d->wrapperMapper.find(cptr); if (iter == m_d->wrapperMapper.end()) - return 0; + return nullptr; return iter->second; } @@ -278,7 +278,7 @@ PyObject *BindingManager::getOverride(const void *cptr, const char *methodName) // The refcount can be 0 if the object is dieing and someone called // a virtual method from the destructor if (!wrapper || reinterpret_cast<const PyObject *>(wrapper)->ob_refcnt == 0) - return 0; + return nullptr; if (wrapper->ob_dict) { PyObject *method = PyDict_GetItemString(wrapper->ob_dict, methodName); @@ -299,7 +299,7 @@ PyObject *BindingManager::getOverride(const void *cptr, const char *methodName) // The first class in the mro (index 0) is the class being checked and it should not be tested. // The last class in the mro (size - 1) is the base Python object class which should not be tested also. for (int i = 1; i < PyTuple_GET_SIZE(mro) - 1; i++) { - PyTypeObject *parent = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, i)); + auto *parent = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, i)); if (parent->tp_dict) { defaultMethod = PyDict_GetItem(parent->tp_dict, pyMethodName); if (defaultMethod && PyMethod_GET_FUNCTION(method) != defaultMethod) { @@ -312,7 +312,7 @@ PyObject *BindingManager::getOverride(const void *cptr, const char *methodName) Py_XDECREF(method); Py_DECREF(pyMethodName); - return 0; + return nullptr; } void BindingManager::addClassInheritance(SbkObjectType *parent, SbkObjectType *child) @@ -335,7 +335,7 @@ std::set<PyObject *> BindingManager::getAllPyObjects() { std::set<PyObject *> pyObjects; const WrapperMap &wrappersMap = m_d->wrapperMapper; - WrapperMap::const_iterator it = wrappersMap.begin(); + auto it = wrappersMap.begin(); for (; it != wrappersMap.end(); ++it) pyObjects.insert(reinterpret_cast<PyObject *>(it->second)); @@ -345,7 +345,7 @@ std::set<PyObject *> BindingManager::getAllPyObjects() void BindingManager::visitAllPyObjects(ObjectVisitor visitor, void *data) { WrapperMap copy = m_d->wrapperMapper; - for (WrapperMap::iterator it = copy.begin(); it != copy.end(); ++it) { + for (auto it = copy.begin(); it != copy.end(); ++it) { if (hasWrapper(it->first)) visitor(it->second, data); } diff --git a/sources/shiboken2/libshiboken/gilstate.cpp b/sources/shiboken2/libshiboken/gilstate.cpp index 64a0b60f3..a59c6f01e 100644 --- a/sources/shiboken2/libshiboken/gilstate.cpp +++ b/sources/shiboken2/libshiboken/gilstate.cpp @@ -43,7 +43,6 @@ namespace Shiboken { GilState::GilState() - : m_locked(false) { if (Py_IsInitialized()) { m_gstate = PyGILState_Ensure(); diff --git a/sources/shiboken2/libshiboken/gilstate.h b/sources/shiboken2/libshiboken/gilstate.h index f0ff45d59..d22f688ba 100644 --- a/sources/shiboken2/libshiboken/gilstate.h +++ b/sources/shiboken2/libshiboken/gilstate.h @@ -59,7 +59,7 @@ public: void release(); private: PyGILState_STATE m_gstate; - bool m_locked; + bool m_locked = false; }; } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/helper.cpp b/sources/shiboken2/libshiboken/helper.cpp index 1a2dc7ab9..fac72d56f 100644 --- a/sources/shiboken2/libshiboken/helper.cpp +++ b/sources/shiboken2/libshiboken/helper.cpp @@ -60,7 +60,7 @@ bool listToArgcArgv(PyObject *argList, int *argc, char ***argv, const char *defa defaultAppName = "PySideApplication"; // Check all items - Shiboken::AutoDecRef args(PySequence_Fast(argList, 0)); + Shiboken::AutoDecRef args(PySequence_Fast(argList, nullptr)); int numArgs = int(PySequence_Fast_GET_SIZE(argList)); for (int i = 0; i < numArgs; ++i) { PyObject *item = PyList_GET_ITEM(args.object(), i); @@ -83,7 +83,7 @@ bool listToArgcArgv(PyObject *argList, int *argc, char ***argv, const char *defa } else { for (int i = 0; i < numArgs; ++i) { PyObject *item = PyList_GET_ITEM(args.object(), i); - char *string = 0; + char *string = nullptr; if (Shiboken::String::check(item)) { string = strdup(Shiboken::String::toCString(item)); } @@ -98,7 +98,7 @@ int *sequenceToIntArray(PyObject *obj, bool zeroTerminated) { AutoDecRef seq(PySequence_Fast(obj, "Sequence of ints expected")); if (seq.isNull()) - return 0; + return nullptr; Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); int *array = new int[size + (zeroTerminated ? 1 : 0)]; @@ -108,10 +108,9 @@ int *sequenceToIntArray(PyObject *obj, bool zeroTerminated) if (!PyInt_Check(item)) { PyErr_SetString(PyExc_TypeError, "Sequence of ints expected"); delete[] array; - return 0; - } else { - array[i] = PyInt_AsLong(item); + return nullptr; } + array[i] = PyInt_AsLong(item); } if (zeroTerminated) @@ -133,7 +132,7 @@ int warning(PyObject *category, int stacklevel, const char *format, ...) #endif // check the necessary memory - int size = vsnprintf(NULL, 0, format, args) + 1; + int size = vsnprintf(nullptr, 0, format, args) + 1; auto message = new char[size]; int result = 0; if (message) { diff --git a/sources/shiboken2/libshiboken/helper.h b/sources/shiboken2/libshiboken/helper.h index 6c29ad728..14aae8028 100644 --- a/sources/shiboken2/libshiboken/helper.h +++ b/sources/shiboken2/libshiboken/helper.h @@ -44,7 +44,7 @@ #include "shibokenmacros.h" #include "autodecref.h" -#define SBK_UNUSED(x) (void)x; +#define SBK_UNUSED(x) (void)(x); namespace Shiboken { @@ -90,7 +90,7 @@ class AutoArrayPointer T *data; }; -typedef unsigned long long ThreadId; +using ThreadId = unsigned long long; LIBSHIBOKEN_API ThreadId currentThreadId(); LIBSHIBOKEN_API ThreadId mainThreadId(); diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index ac0328b6b..fe7157d24 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -67,18 +67,18 @@ datetime_struc *PyDateTimeAPI = NULL; #endif static PyObject * -dummy_func(PyObject *self, PyObject *args) +dummy_func(PyObject * /* self */, PyObject * /* args */) { Py_RETURN_NONE; } static struct PyMethodDef probe_methoddef[] = { {"dummy", dummy_func, METH_NOARGS}, - {0} + {nullptr} }; static PyGetSetDef probe_getseters[] = { - {0} /* Sentinel */ + {nullptr} /* Sentinel */ }; #define probe_tp_call make_dummy(1) @@ -110,7 +110,7 @@ static PyType_Slot typeprobe_slots[] = { {Py_tp_new, probe_tp_new}, {Py_tp_free, probe_tp_free}, {Py_tp_is_gc, probe_tp_is_gc}, - {0, 0} + {0, nullptr} }; static PyType_Spec typeprobe_spec = { probe_tp_name, @@ -121,15 +121,15 @@ static PyType_Spec typeprobe_spec = { }; static void -check_PyTypeObject_valid(void) +check_PyTypeObject_valid() { - PyObject *obtype = reinterpret_cast<PyObject *>(&PyType_Type); - PyTypeObject *probe_tp_base = reinterpret_cast<PyTypeObject *>( + auto *obtype = reinterpret_cast<PyObject *>(&PyType_Type); + auto *probe_tp_base = reinterpret_cast<PyTypeObject *>( PyObject_GetAttrString(obtype, "__base__")); PyObject *probe_tp_bases = PyObject_GetAttrString(obtype, "__bases__"); - PyTypeObject *check = reinterpret_cast<PyTypeObject *>( + auto *check = reinterpret_cast<PyTypeObject *>( PyType_FromSpecWithBases(&typeprobe_spec, probe_tp_bases)); - PyTypeObject *typetype = reinterpret_cast<PyTypeObject *>(obtype); + auto *typetype = reinterpret_cast<PyTypeObject *>(obtype); PyObject *w = PyObject_GetAttrString(obtype, "__weakrefoffset__"); long probe_tp_weakrefoffset = PyLong_AsLong(w); PyObject *d = PyObject_GetAttrString(obtype, "__dictoffset__"); diff --git a/sources/shiboken2/libshiboken/qapp_macro.cpp b/sources/shiboken2/libshiboken/qapp_macro.cpp index ea9cf0c86..df24a8052 100644 --- a/sources/shiboken2/libshiboken/qapp_macro.cpp +++ b/sources/shiboken2/libshiboken/qapp_macro.cpp @@ -87,9 +87,9 @@ static SbkObject _Py_ChameleonQAppWrapper_Struct = { BRACE_CLOSE }; -static PyObject *qApp_var = NULL; -static PyObject *qApp_content = (PyObject *)&_Py_ChameleonQAppWrapper_Struct; -static PyObject *qApp_moduledicts[5] = {0, 0, 0, 0, 0}; +static PyObject *qApp_var = nullptr; +static PyObject *qApp_content = reinterpret_cast<PyObject *>(&_Py_ChameleonQAppWrapper_Struct); +static PyObject *qApp_moduledicts[5] = {nullptr, nullptr, nullptr, nullptr, nullptr}; static int qApp_var_ref = 0; static int qApp_content_ref = 0; @@ -120,17 +120,17 @@ reset_qApp_var(void) PyObject * MakeSingletonQAppWrapper(PyTypeObject *type) { - if (type == NULL) + if (type == nullptr) type = Py_NONE_TYPE; if (!(type == Py_NONE_TYPE || Py_TYPE(qApp_content) == Py_NONE_TYPE)) { const char *res_name = PepType_GetNameStr(Py_TYPE(qApp_content)); const char *type_name = PepType_GetNameStr(type); PyErr_Format(PyExc_RuntimeError, "Please destroy the %s singleton before" " creating a new %s instance.", res_name, type_name); - return NULL; + return nullptr; } if (reset_qApp_var() < 0) - return NULL; + return nullptr; // always know the max of the refs if (Py_REFCNT(qApp_var) > qApp_var_ref) qApp_var_ref = Py_REFCNT(qApp_var); @@ -201,7 +201,7 @@ setup_qApp_var(PyObject *module) Py_NONE_TYPE->tp_as_number = &none_as_number; #endif qApp_var = Py_BuildValue("s", "qApp"); - if (qApp_var == NULL) + if (qApp_var == nullptr) return -1; // This is a borrowed reference qApp_moduledicts[0] = PyEval_GetBuiltins(); diff --git a/sources/shiboken2/libshiboken/sbkarrayconverter.cpp b/sources/shiboken2/libshiboken/sbkarrayconverter.cpp index 58e0b18a8..fd09efdae 100644 --- a/sources/shiboken2/libshiboken/sbkarrayconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkarrayconverter.cpp @@ -83,7 +83,7 @@ inline void convertPySequence(PyObject *pyIn, Converter c, T *out) // Internal, for usage by numpy SbkArrayConverter *createArrayConverter(IsArrayConvertibleToCppFunc toCppCheckFunc) { - SbkArrayConverter *result = new SbkArrayConverter; + auto *result = new SbkArrayConverter; result->toCppConversions.push_back(toCppCheckFunc); return result; } @@ -115,7 +115,7 @@ static short toShort(PyObject *pyIn) { return short(PyLong_AsLong(pyIn)); } static void sequenceToCppShortArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<short> *handle = reinterpret_cast<ArrayHandle<short> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<short> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, toShort, handle->data()); } @@ -148,7 +148,7 @@ static short toUnsignedShort(PyObject *pyIn) { return static_cast<unsigned short static void sequenceToCppUnsignedShortArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<unsigned short> *handle = reinterpret_cast<ArrayHandle<unsigned short> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<unsigned short> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, toUnsignedShort, handle->data()); } @@ -160,7 +160,7 @@ static PythonToCppFunc sequenceToCppUnsignedShortArrayCheck(PyObject *pyIn, int static void sequenceToCppIntArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<int> *handle = reinterpret_cast<ArrayHandle<int> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<int> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, _PepLong_AsInt, handle->data()); } @@ -172,7 +172,7 @@ static PythonToCppFunc sequenceToCppIntArrayCheck(PyObject *pyIn, int dim1, int static void sequenceToCppUnsignedArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<unsigned> *handle = reinterpret_cast<ArrayHandle<unsigned> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<unsigned> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, PyLong_AsUnsignedLong, handle->data()); } @@ -184,7 +184,7 @@ static PythonToCppFunc sequenceToCppUnsignedArrayCheck(PyObject *pyIn, int dim1, static void sequenceToCppLongLongArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<long long> *handle = reinterpret_cast<ArrayHandle<long long> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<long long> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, PyLong_AsLongLong, handle->data()); } @@ -196,7 +196,7 @@ static PythonToCppFunc sequenceToCppLongLongArrayCheck(PyObject *pyIn, int dim1, static void sequenceToCppUnsignedLongLongArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<unsigned long long> *handle = reinterpret_cast<ArrayHandle<unsigned long long> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<unsigned long long> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, PyLong_AsUnsignedLongLong, handle->data()); } @@ -218,7 +218,7 @@ static inline bool floatArrayCheck(PyObject *pyIn, int expectedSize = -1) static void sequenceToCppDoubleArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<double> *handle = reinterpret_cast<ArrayHandle<double> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<double> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, PyFloat_AsDouble, handle->data()); } @@ -227,7 +227,7 @@ static inline float pyToFloat(PyObject *pyIn) { return float(PyFloat_AsDouble(py static void sequenceToCppFloatArray(PyObject *pyIn, void *cppOut) { - ArrayHandle<float> *handle = reinterpret_cast<ArrayHandle<float> *>(cppOut); + auto *handle = reinterpret_cast<ArrayHandle<float> *>(cppOut); handle->allocate(PySequence_Size(pyIn)); convertPySequence(pyIn, pyToFloat, handle->data()); } diff --git a/sources/shiboken2/libshiboken/sbkarrayconverter.h b/sources/shiboken2/libshiboken/sbkarrayconverter.h index 5b26c6e3c..84cb2f57f 100644 --- a/sources/shiboken2/libshiboken/sbkarrayconverter.h +++ b/sources/shiboken2/libshiboken/sbkarrayconverter.h @@ -73,10 +73,13 @@ enum : int { template <class T> class ArrayHandle { - ArrayHandle(const ArrayHandle &) = delete; - ArrayHandle &operator=(const ArrayHandle &) = delete; public: - ArrayHandle() {} + ArrayHandle(const ArrayHandle &) = delete; + ArrayHandle& operator=(const ArrayHandle &) = delete; + ArrayHandle(ArrayHandle &&) = delete; + ArrayHandle& operator=(ArrayHandle &&) = delete; + + ArrayHandle() = default; ~ArrayHandle() { destroy(); } void allocate(Py_ssize_t size); @@ -106,7 +109,7 @@ class Array2Handle public: typedef T RowType[columns]; - Array2Handle() {} + Array2Handle() = default; operator RowType *() const { return m_rows; } diff --git a/sources/shiboken2/libshiboken/sbkconverter.cpp b/sources/shiboken2/libshiboken/sbkconverter.cpp index 15afd5933..29eb19715 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkconverter.cpp @@ -51,7 +51,7 @@ static SbkConverter **PrimitiveTypeConverters; -typedef std::unordered_map<std::string, SbkConverter *> ConvertersMap; +using ConvertersMap = std::unordered_map<std::string, SbkConverter *>; static ConvertersMap converters; namespace Shiboken { @@ -143,7 +143,7 @@ SbkConverter *createConverter(SbkObjectType *type, SbkConverter *createConverter(PyTypeObject *type, CppToPythonFunc toPythonFunc) { - return createConverterObject(type, 0, 0, 0, toPythonFunc); + return createConverterObject(type, nullptr, nullptr, nullptr, toPythonFunc); } void deleteConverter(SbkConverter *converter) @@ -206,7 +206,7 @@ PyObject *referenceToPython(const SbkConverter *converter, const void *cppIn) { assert(cppIn); - PyObject *pyOut = reinterpret_cast<PyObject *>(BindingManager::instance().retrieveWrapper(cppIn)); + auto *pyOut = reinterpret_cast<PyObject *>(BindingManager::instance().retrieveWrapper(cppIn)); if (pyOut) { Py_INCREF(pyOut); return pyOut; @@ -252,7 +252,7 @@ static inline PythonToCppFunc IsPythonToCppConvertible(const SbkConverter *conve if (PythonToCppFunc toCppFunc = c.first(pyIn)) return toCppFunc; } - return 0; + return nullptr; } PythonToCppFunc isPythonToCppValueConvertible(SbkObjectType *type, PyObject *pyIn) { @@ -287,7 +287,7 @@ PythonToCppFunc isPythonToCppReferenceConvertible(SbkObjectType *type, PyObject void nonePythonToCppNullPtr(PyObject *, void *cppOut) { assert(cppOut); - *reinterpret_cast<void **>(cppOut) = nullptr; + *static_cast<void **>(cppOut) = nullptr; } void *cppPointer(PyTypeObject *desiredType, SbkObject *pyIn) @@ -295,7 +295,7 @@ void *cppPointer(PyTypeObject *desiredType, SbkObject *pyIn) assert(pyIn); if (!ObjectType::checkType(desiredType)) return pyIn; - SbkObjectType *inType = reinterpret_cast<SbkObjectType *>(Py_TYPE(pyIn)); + auto *inType = reinterpret_cast<SbkObjectType *>(Py_TYPE(pyIn)); if (ObjectType::hasCast(inType)) return ObjectType::cast(inType, pyIn, desiredType); return Object::cppPointer(pyIn, desiredType); @@ -307,7 +307,7 @@ void pythonToCppPointer(SbkObjectType *type, PyObject *pyIn, void *cppOut) assert(pyIn); assert(cppOut); *reinterpret_cast<void **>(cppOut) = pyIn == Py_None - ? 0 + ? nullptr : cppPointer(reinterpret_cast<PyTypeObject *>(type), reinterpret_cast<SbkObject *>(pyIn)); } @@ -317,7 +317,7 @@ void pythonToCppPointer(const SbkConverter *converter, PyObject *pyIn, void *cpp assert(pyIn); assert(cppOut); *reinterpret_cast<void **>(cppOut) = pyIn == Py_None - ? 0 + ? nullptr : cppPointer(reinterpret_cast<PyTypeObject *>(converter->pythonType), reinterpret_cast<SbkObject *>(pyIn)); } @@ -367,7 +367,7 @@ bool isImplicitConversion(SbkObjectType *type, PythonToCppFunc toCppFunc) void registerConverterName(SbkConverter *converter , const char *typeName) { - ConvertersMap::iterator iter = converters.find(typeName); + auto iter = converters.find(typeName); if (iter == converters.end()) converters.insert(std::make_pair(typeName, converter)); } @@ -379,7 +379,7 @@ SbkConverter *getConverter(const char *typeName) return it->second; if (Py_VerboseFlag > 0) SbkDbg() << "Can't find type resolver for type '" << typeName << "'."; - return 0; + return nullptr; } SbkConverter *primitiveTypeConverter(int index) @@ -518,7 +518,7 @@ PyTypeObject *getPythonTypeObject(const SbkConverter *converter) { if (converter) return converter->pythonType; - return 0; + return nullptr; } PyTypeObject *getPythonTypeObject(const char *typeName) @@ -542,7 +542,7 @@ bool pythonTypeIsObjectType(const SbkConverter *converter) bool pythonTypeIsWrapperType(const SbkConverter *converter) { - return converter->pointerToPython != 0; + return converter->pointerToPython != nullptr; } SpecificConverter::SpecificConverter(const char *typeName) @@ -568,13 +568,13 @@ PyObject *SpecificConverter::toPython(const void *cppIn) case CopyConversion: return copyToPython(m_converter, cppIn); case PointerConversion: - return pointerToPython(m_converter, *((const void **)cppIn)); + return pointerToPython(m_converter, *static_cast<const void * const *>(cppIn)); case ReferenceConversion: return referenceToPython(m_converter, cppIn); default: PyErr_SetString(PyExc_RuntimeError, "tried to use invalid converter in 'C++ to Python' conversion"); } - return 0; + return nullptr; } void SpecificConverter::toCpp(PyObject *pyIn, void *cppOut) diff --git a/sources/shiboken2/libshiboken/sbkconverter.h b/sources/shiboken2/libshiboken/sbkconverter.h index 2d1735f2b..6c7a29300 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.h +++ b/sources/shiboken2/libshiboken/sbkconverter.h @@ -151,7 +151,7 @@ LIBSHIBOKEN_API SbkConverter *createConverter(SbkObjectType *type, PythonToCppFunc toCppPointerConvFunc, IsConvertibleToCppFunc toCppPointerCheckFunc, CppToPythonFunc pointerToPythonFunc, - CppToPythonFunc copyToPythonFunc = 0); + CppToPythonFunc copyToPythonFunc = nullptr); /** * Creates a converter for a non wrapper type (primitive or container type). @@ -343,7 +343,7 @@ LIBSHIBOKEN_API bool pythonTypeIsWrapperType(const SbkConverter *converter); #define SBK_VOIDPTR_IDX 16 #define SBK_NULLPTR_T_IDX 17 -template<typename T> SbkConverter *PrimitiveTypeConverter() { return 0; } +template<typename T> SbkConverter *PrimitiveTypeConverter() { return nullptr; } template<> inline SbkConverter *PrimitiveTypeConverter<PY_LONG_LONG>() { return primitiveTypeConverter(SBK_PY_LONG_LONG_IDX); } template<> inline SbkConverter *PrimitiveTypeConverter<bool>() { return primitiveTypeConverter(SBK_BOOL_IDX_1); } template<> inline SbkConverter *PrimitiveTypeConverter<char>() { return primitiveTypeConverter(SBK_CHAR_IDX); } @@ -371,7 +371,7 @@ template<> inline SbkConverter *PrimitiveTypeConverter<std::nullptr_t>() { retur * T isn't a C++ primitive type. * \see SpecialCastFunction */ -template<typename T> PyTypeObject *SbkType() { return 0; } +template<typename T> PyTypeObject *SbkType() { return nullptr; } // Below are the template specializations for C++ primitive types. template<> inline PyTypeObject *SbkType<PY_LONG_LONG>() { return &PyLong_Type; } diff --git a/sources/shiboken2/libshiboken/sbkconverter_p.h b/sources/shiboken2/libshiboken/sbkconverter_p.h index aa90094af..d87162071 100644 --- a/sources/shiboken2/libshiboken/sbkconverter_p.h +++ b/sources/shiboken2/libshiboken/sbkconverter_p.h @@ -54,8 +54,8 @@ extern "C" { -typedef std::pair<IsConvertibleToCppFunc, PythonToCppFunc> ToCppConversion; -typedef std::vector<ToCppConversion> ToCppConversionVector; +using ToCppConversion = std::pair<IsConvertibleToCppFunc, PythonToCppFunc>; +using ToCppConversionVector = std::vector<ToCppConversion>; /** * \internal @@ -112,11 +112,11 @@ struct SbkConverter template<typename T, typename MaxLimitType, bool isSigned> struct OverFlowCheckerBase { static void formatOverFlowMessage(const MaxLimitType &value, - const std::string *valueAsString = 0) + const std::string *valueAsString = nullptr) { std::ostringstream str; str << "libshiboken: Overflow: Value "; - if (valueAsString != 0 && !valueAsString->empty()) + if (valueAsString != nullptr && !valueAsString->empty()) str << *valueAsString; else str << value; @@ -261,27 +261,27 @@ struct IntPrimitive : TwoPrimitive<INT> double result = PyFloat_AS_DOUBLE(pyIn); // If cast to long directly it could overflow silently. if (OverFlowChecker<INT>::check(result, pyIn)) - PyErr_SetObject(PyExc_OverflowError, 0); + PyErr_SetObject(PyExc_OverflowError, nullptr); *reinterpret_cast<INT * >(cppOut) = static_cast<INT>(result); } static PythonToCppFunc isConvertible(PyObject *pyIn) { if (PyFloat_Check(pyIn)) return toCpp; - return 0; + return nullptr; } static void otherToCpp(PyObject *pyIn, void *cppOut) { PY_LONG_LONG result = PyLong_AsLongLong(pyIn); if (OverFlowChecker<INT>::check(result, pyIn)) - PyErr_SetObject(PyExc_OverflowError, 0); + PyErr_SetObject(PyExc_OverflowError, nullptr); *reinterpret_cast<INT * >(cppOut) = static_cast<INT>(result); } static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return otherToCpp; - return 0; + return nullptr; } }; template <> struct Primitive<int> : IntPrimitive<int> {}; @@ -322,7 +322,7 @@ struct Primitive<PY_LONG_LONG> : OnePrimitive<PY_LONG_LONG> { if (SbkNumber_Check(pyIn)) return toCpp; - return 0; + return nullptr; } }; @@ -331,7 +331,7 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> { static PyObject *toPython(const void *cppIn) { - return PyLong_FromUnsignedLongLong(*reinterpret_cast<const unsigned PY_LONG_LONG *>(cppIn)); + return PyLong_FromUnsignedLongLong(*static_cast<const unsigned PY_LONG_LONG *>(cppIn)); } static void toCpp(PyObject *pyIn, void *cppOut) { @@ -339,7 +339,7 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> if (PyLong_Check(pyIn)) { unsigned PY_LONG_LONG result = PyLong_AsUnsignedLongLong(pyIn); if (OverFlowChecker<unsigned PY_LONG_LONG, unsigned PY_LONG_LONG>::check(result, pyIn)) - PyErr_SetObject(PyExc_OverflowError, 0); + PyErr_SetObject(PyExc_OverflowError, nullptr); *reinterpret_cast<unsigned PY_LONG_LONG * >(cppOut) = result; } else { @@ -366,7 +366,7 @@ struct Primitive<unsigned PY_LONG_LONG> : OnePrimitive<unsigned PY_LONG_LONG> { if (SbkNumber_Check(pyIn)) return toCpp; - return 0; + return nullptr; } }; @@ -387,7 +387,7 @@ struct FloatPrimitive : TwoPrimitive<FLOAT> { if (PyInt_Check(pyIn) || PyLong_Check(pyIn)) return toCpp; - return 0; + return nullptr; } static void otherToCpp(PyObject *pyIn, void *cppOut) { @@ -397,7 +397,7 @@ struct FloatPrimitive : TwoPrimitive<FLOAT> { if (SbkNumber_Check(pyIn)) return otherToCpp; - return 0; + return nullptr; } }; template <> struct Primitive<float> : FloatPrimitive<float> {}; @@ -416,7 +416,7 @@ struct Primitive<bool> : OnePrimitive<bool> { if (SbkNumber_Check(pyIn)) return toCpp; - return 0; + return nullptr; } static void toCpp(PyObject *pyIn, void *cppOut) { @@ -437,20 +437,20 @@ struct CharPrimitive : IntPrimitive<CHAR> { if (Shiboken::String::checkChar(pyIn)) return toCpp; - return 0; + return nullptr; } static void otherToCpp(PyObject *pyIn, void *cppOut) { PY_LONG_LONG result = PyLong_AsLongLong(pyIn); if (OverFlowChecker<CHAR>::check(result, pyIn)) - PyErr_SetObject(PyExc_OverflowError, 0); + PyErr_SetObject(PyExc_OverflowError, nullptr); *reinterpret_cast<CHAR *>(cppOut) = CHAR(result); } static PythonToCppFunc isOtherConvertible(PyObject *pyIn) { if (SbkNumber_Check(pyIn)) return otherToCpp; - return 0; + return nullptr; } static SbkConverter *createConverter() { @@ -484,13 +484,13 @@ struct Primitive<const char *> : TwoPrimitive<const char *> } static void toCpp(PyObject *, void *cppOut) { - *((const char **)cppOut) = 0; + *((const char **)cppOut) = nullptr; } static PythonToCppFunc isConvertible(PyObject *pyIn) { if (pyIn == Py_None) return toCpp; - return 0; + return nullptr; } static void otherToCpp(PyObject *pyIn, void *cppOut) { @@ -500,7 +500,7 @@ struct Primitive<const char *> : TwoPrimitive<const char *> { if (Shiboken::String::check(pyIn)) return otherToCpp; - return 0; + return nullptr; } }; @@ -519,7 +519,7 @@ struct Primitive<std::string> : TwoPrimitive<std::string> { if (pyIn == Py_None) return toCpp; - return 0; + return nullptr; } static void otherToCpp(PyObject *pyIn, void *cppOut) { @@ -529,7 +529,7 @@ struct Primitive<std::string> : TwoPrimitive<std::string> { if (Shiboken::String::check(pyIn)) return otherToCpp; - return 0; + return nullptr; } }; @@ -537,7 +537,7 @@ struct Primitive<std::string> : TwoPrimitive<std::string> template <> struct Primitive<std::nullptr_t> : TwoPrimitive<std::nullptr_t> { - static PyObject *toPython(const void *cppIn) + static PyObject *toPython(const void * /* cppIn */) { return Py_None; } @@ -551,7 +551,7 @@ struct Primitive<std::nullptr_t> : TwoPrimitive<std::nullptr_t> return toCpp; return nullptr; } - static void otherToCpp(PyObject *pyIn, void *cppOut) + static void otherToCpp(PyObject * /* pyIn */, void *cppOut) { *reinterpret_cast<std::nullptr_t *>(cppOut) = nullptr; } diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index 75054ab71..71fcf5f64 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -86,9 +86,9 @@ static PyObject *SbkEnumObject_repr(PyObject *self) static PyObject *SbkEnumObject_name(PyObject *self, void *) { - SbkEnumObject *enum_self = SBK_ENUM(self); + auto *enum_self = SBK_ENUM(self); - if (enum_self->ob_name == NULL) + if (enum_self->ob_name == nullptr) Py_RETURN_NONE; Py_INCREF(enum_self->ob_name); @@ -99,18 +99,18 @@ static PyObject *SbkEnum_tp_new(PyTypeObject *type, PyObject *args, PyObject *) { long itemValue = 0; if (!PyArg_ParseTuple(args, "|l:__new__", &itemValue)) - return 0; + return nullptr; SbkEnumObject *self = PyObject_New(SbkEnumObject, type); if (!self) - return 0; + return nullptr; self->ob_value = itemValue; PyObject *item = Shiboken::Enum::getEnumItemFromValue(type, itemValue); if (item) { - self->ob_name = SbkEnumObject_name(item, 0); + self->ob_name = SbkEnumObject_name(item, nullptr); Py_XDECREF(item); } else { - self->ob_name = 0; + self->ob_name = nullptr; } return reinterpret_cast<PyObject *>(self); } @@ -233,9 +233,8 @@ static PyObject *enum_richcompare(PyObject *self, PyObject *other, int op) if (!(enumA || enumB)) { Py_INCREF(Py_NotImplemented); return Py_NotImplemented; - } else { - result = PyObject_RichCompare(valA, valB, op); } + result = PyObject_RichCompare(valA, valB, op); // Decreasing the reference of the used variables a and b. if (enumA) @@ -256,7 +255,7 @@ static Py_hash_t enum_hash(PyObject *pyObj) static PyGetSetDef SbkEnumGetSetList[] = { {const_cast<char *>("name"), &SbkEnumObject_name, nullptr, nullptr, nullptr}, - {0, 0, 0, 0, 0} // Sentinel + {nullptr, nullptr, nullptr, nullptr, nullptr} // Sentinel }; static void SbkEnumTypeDealloc(PyObject *pyObj); @@ -286,7 +285,7 @@ static PyType_Slot SbkEnumType_Type_slots[] = { {Py_tp_alloc, (void *)PyType_GenericAlloc}, {Py_tp_new, (void *)SbkEnumTypeTpNew}, {Py_tp_free, (void *)PyObject_GC_Del}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkEnumType_Type_spec = { "Shiboken.EnumType", @@ -326,10 +325,10 @@ void SbkEnumTypeDealloc(PyObject *pyObj) PyObject *SbkEnumTypeTpNew(PyTypeObject *metatype, PyObject *args, PyObject *kwds) { - newfunc type_new = reinterpret_cast<newfunc>(PyType_GetSlot(&PyType_Type, Py_tp_new)); + auto type_new = reinterpret_cast<newfunc>(PyType_GetSlot(&PyType_Type, Py_tp_new)); auto newType = reinterpret_cast<SbkEnumType *>(type_new(metatype, args, kwds)); if (!newType) - return 0; + return nullptr; return reinterpret_cast<PyObject *>(newType); } @@ -368,13 +367,13 @@ PyObject *getEnumItemFromValue(PyTypeObject *enumType, long itemValue) PyObject *values = PyDict_GetItemString(enumType->tp_dict, const_cast<char *>("values")); while (PyDict_Next(values, &pos, &key, &value)) { - SbkEnumObject *obj = reinterpret_cast<SbkEnumObject *>(value); + auto *obj = reinterpret_cast<SbkEnumObject *>(value); if (obj->ob_value == itemValue) { Py_INCREF(obj); return value; } } - return 0; + return nullptr; } static PyTypeObject *createEnum(const char *fullName, const char *cppName, @@ -383,7 +382,7 @@ static PyTypeObject *createEnum(const char *fullName, const char *cppName, { PyTypeObject *enumType = newTypeWithName(fullName, cppName, flagsType); if (PyType_Ready(enumType) < 0) - return 0; + return nullptr; return enumType; } @@ -391,10 +390,10 @@ PyTypeObject *createGlobalEnum(PyObject *module, const char *name, const char *f { PyTypeObject *enumType = createEnum(fullName, cppName, name, flagsType); if (enumType && PyModule_AddObject(module, name, reinterpret_cast<PyObject *>(enumType)) < 0) - return 0; + return nullptr; if (flagsType && PyModule_AddObject(module, PepType_GetNameStr(flagsType), reinterpret_cast<PyObject *>(flagsType)) < 0) - return 0; + return nullptr; return enumType; } @@ -415,7 +414,7 @@ static PyObject *createEnumItem(PyTypeObject *enumType, const char *itemName, lo { PyObject *enumItem = newItem(enumType, itemValue, itemName); if (PyDict_SetItemString(enumType->tp_dict, itemName, enumItem) < 0) - return 0; + return nullptr; Py_DECREF(enumItem); return enumItem; } @@ -470,9 +469,9 @@ newItem(PyTypeObject *enumType, long itemValue, const char *itemName) enumObj = PyObject_New(SbkEnumObject, enumType); if (!enumObj) - return 0; + return nullptr; - enumObj->ob_name = itemName ? PyBytes_FromString(itemName) : 0; + enumObj->ob_name = itemName ? PyBytes_FromString(itemName) : nullptr; enumObj->ob_value = itemValue; if (newValue) { @@ -514,7 +513,7 @@ static PyType_Slot SbkNewType_slots[] = { {Py_tp_richcompare, (void *)enum_richcompare}, {Py_tp_hash, (void *)enum_hash}, {Py_tp_dealloc, (void *)object_dealloc}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkNewType_spec = { "missing Enum name", // to be inserted later @@ -587,7 +586,7 @@ newTypeWithName(const char *name, { // Careful: PyType_FromSpec does not allocate the string. PyType_Slot newslots[99] = {}; // enough but not too big for the stack - PyType_Spec *newspec = new PyType_Spec; + auto *newspec = new PyType_Spec; newspec->name = strdup(name); newspec->basicsize = SbkNewType_spec.basicsize; newspec->itemsize = SbkNewType_spec.itemsize; @@ -602,11 +601,11 @@ newTypeWithName(const char *name, if (numbers_fromFlag) copyNumberMethods(numbers_fromFlag, newslots, &idx); newspec->slots = newslots; - PyTypeObject *type = reinterpret_cast<PyTypeObject *>(PyType_FromSpec(newspec)); + auto *type = reinterpret_cast<PyTypeObject *>(PyType_FromSpec(newspec)); Py_TYPE(type) = SbkEnumType_TypeF(); Py_INCREF(Py_TYPE(type)); - SbkEnumType *enumType = reinterpret_cast<SbkEnumType *>(type); + auto *enumType = reinterpret_cast<SbkEnumType *>(type); PepType_SETP(enumType)->cppName = cppName; PepType_SETP(enumType)->converterPtr = &PepType_SETP(enumType)->converter; DeclaredEnumTypes::instance().addEnumType(type); diff --git a/sources/shiboken2/libshiboken/sbkenum.h b/sources/shiboken2/libshiboken/sbkenum.h index 199027836..759d72636 100644 --- a/sources/shiboken2/libshiboken/sbkenum.h +++ b/sources/shiboken2/libshiboken/sbkenum.h @@ -101,7 +101,7 @@ namespace Enum const char *itemName, long itemValue); LIBSHIBOKEN_API bool createScopedEnumItem(PyTypeObject *enumType, SbkObjectType *scope, const char *itemName, long itemValue); - LIBSHIBOKEN_API PyObject *newItem(PyTypeObject *enumType, long itemValue, const char *itemName = 0); + LIBSHIBOKEN_API PyObject *newItem(PyTypeObject *enumType, long itemValue, const char *itemName = nullptr); LIBSHIBOKEN_API PyTypeObject *newTypeWithName(const char *name, const char *cppName, PyTypeObject *numbers_fromFlag=nullptr); diff --git a/sources/shiboken2/libshiboken/sbkmodule.cpp b/sources/shiboken2/libshiboken/sbkmodule.cpp index 7bfbf51a8..9321725d6 100644 --- a/sources/shiboken2/libshiboken/sbkmodule.cpp +++ b/sources/shiboken2/libshiboken/sbkmodule.cpp @@ -43,10 +43,10 @@ #include <unordered_map> /// This hash maps module objects to arrays of Python types. -typedef std::unordered_map<PyObject *, PyTypeObject **> ModuleTypesMap; +using ModuleTypesMap = std::unordered_map<PyObject *, PyTypeObject **> ; /// This hash maps module objects to arrays of converters. -typedef std::unordered_map<PyObject *, SbkConverter **> ModuleConvertersMap; +using ModuleConvertersMap = std::unordered_map<PyObject *, SbkConverter **>; /// All types produced in imported modules are mapped here. static ModuleTypesMap moduleTypes; @@ -84,27 +84,27 @@ PyObject *create(const char *moduleName, void *moduleData) void registerTypes(PyObject *module, PyTypeObject **types) { - ModuleTypesMap::iterator iter = moduleTypes.find(module); + auto iter = moduleTypes.find(module); if (iter == moduleTypes.end()) moduleTypes.insert(std::make_pair(module, types)); } PyTypeObject **getTypes(PyObject *module) { - ModuleTypesMap::iterator iter = moduleTypes.find(module); + auto iter = moduleTypes.find(module); return (iter == moduleTypes.end()) ? 0 : iter->second; } void registerTypeConverters(PyObject *module, SbkConverter **converters) { - ModuleConvertersMap::iterator iter = moduleConverters.find(module); + auto iter = moduleConverters.find(module); if (iter == moduleConverters.end()) moduleConverters.insert(std::make_pair(module, converters)); } SbkConverter **getTypeConverters(PyObject *module) { - ModuleConvertersMap::iterator iter = moduleConverters.find(module); + auto iter = moduleConverters.find(module); return (iter == moduleConverters.end()) ? 0 : iter->second; } diff --git a/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp b/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp index 8bc680796..996968fa1 100644 --- a/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp +++ b/sources/shiboken2/libshiboken/sbknumpyarrayconverter.cpp @@ -138,7 +138,7 @@ static bool isPrimitiveArray(PyObject *pyIn, int expectedNpType) { if (!PyArray_Check(pyIn)) return false; - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); if (debugNumPy) { std::cerr << __FUNCTION__ << "(expectedNpType=" << expectedNpType; if (const char *name = npTypeName(expectedNpType)) @@ -176,7 +176,7 @@ static inline bool primitiveArrayCheck1(PyObject *pyIn, int expectedNpType, int if (!isPrimitiveArray<1>(pyIn, expectedNpType)) return false; if (expectedSize >= 0) { - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); const int size = int(PyArray_DIMS(pya)[0]); if (size < expectedSize) { warning(PyExc_RuntimeWarning, 0, "A numpy array of size %d was passed to a function expects %d.", @@ -191,8 +191,8 @@ static inline bool primitiveArrayCheck1(PyObject *pyIn, int expectedNpType, int template <class T> static void convertArray1(PyObject *pyIn, void *cppOut) { - ArrayHandle<T> *handle = reinterpret_cast<ArrayHandle<T> *>(cppOut); - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *handle = reinterpret_cast<ArrayHandle<T> *>(cppOut); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); const npy_intp size = PyArray_DIMS(pya)[0]; if (debugNumPy) std::cerr << __FUNCTION__ << ' ' << size << '\n'; @@ -204,8 +204,8 @@ template <class T> static void convertArray2(PyObject *pyIn, void *cppOut) { typedef typename Array2Handle<T, 1>::RowType RowType; - Array2Handle<T, 1> *handle = reinterpret_cast<Array2Handle<T, 1> *>(cppOut); - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *handle = reinterpret_cast<Array2Handle<T, 1> *>(cppOut); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); handle->setData(reinterpret_cast<RowType *>(PyArray_DATA(pya))); } @@ -220,7 +220,7 @@ static inline bool primitiveArrayCheck2(PyObject *pyIn, int expectedNpType, int if (!isPrimitiveArray<2>(pyIn, expectedNpType)) return false; if (expectedDim2 >= 0) { - PyArrayObject *pya = reinterpret_cast<PyArrayObject *>(pyIn); + auto *pya = reinterpret_cast<PyArrayObject *>(pyIn); const int dim1 = int(PyArray_DIMS(pya)[0]); const int dim2 = int(PyArray_DIMS(pya)[1]); if (dim1 != expectedDim1 || dim2 != expectedDim2) { diff --git a/sources/shiboken2/libshiboken/sbkstring.cpp b/sources/shiboken2/libshiboken/sbkstring.cpp index d3c337524..9ba5be281 100644 --- a/sources/shiboken2/libshiboken/sbkstring.cpp +++ b/sources/shiboken2/libshiboken/sbkstring.cpp @@ -95,7 +95,7 @@ PyObject *fromCString(const char *value, int len) const char *toCString(PyObject *str, Py_ssize_t *len) { if (str == Py_None) - return NULL; + return nullptr; if (PyUnicode_Check(str)) { if (len) { // We need to encode the unicode string into utf8 to know the size of returned char *. @@ -119,7 +119,7 @@ const char *toCString(PyObject *str, Py_ssize_t *len) *len = PyBytes_GET_SIZE(str); return PyBytes_AS_STRING(str); } - return 0; + return nullptr; } bool concat(PyObject **val1, PyObject *val2) diff --git a/sources/shiboken2/libshiboken/sbkstring.h b/sources/shiboken2/libshiboken/sbkstring.h index ec674ee7b..7f434e1b9 100644 --- a/sources/shiboken2/libshiboken/sbkstring.h +++ b/sources/shiboken2/libshiboken/sbkstring.h @@ -59,7 +59,7 @@ namespace String LIBSHIBOKEN_API bool isConvertible(PyObject *obj); LIBSHIBOKEN_API PyObject *fromCString(const char *value); LIBSHIBOKEN_API PyObject *fromCString(const char *value, int len); - LIBSHIBOKEN_API const char *toCString(PyObject *str, Py_ssize_t *len = 0); + LIBSHIBOKEN_API const char *toCString(PyObject *str, Py_ssize_t *len = nullptr); LIBSHIBOKEN_API bool concat(PyObject **val1, PyObject *val2); LIBSHIBOKEN_API PyObject *fromFormat(const char *format, ...); LIBSHIBOKEN_API PyObject *fromStringAndSize(const char *str, Py_ssize_t size); diff --git a/sources/shiboken2/libshiboken/shibokenbuffer.h b/sources/shiboken2/libshiboken/shibokenbuffer.h index 8c41dad6c..dc9f8d89f 100644 --- a/sources/shiboken2/libshiboken/shibokenbuffer.h +++ b/sources/shiboken2/libshiboken/shibokenbuffer.h @@ -77,7 +77,7 @@ namespace Buffer * * If the \p pyObj is a non-contiguous buffer a Python error is set. */ - LIBSHIBOKEN_API void *getPointer(PyObject *pyObj, Py_ssize_t *size = 0); + LIBSHIBOKEN_API void *getPointer(PyObject *pyObj, Py_ssize_t *size = nullptr); } // namespace Buffer } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp index 8f9c5a459..e62f861a2 100644 --- a/sources/shiboken2/libshiboken/signature.cpp +++ b/sources/shiboken2/libshiboken/signature.cpp @@ -79,7 +79,7 @@ typedef struct safe_globals_struc { PyObject *make_helptext_func; } safe_globals_struc, *safe_globals; -static safe_globals pyside_globals = 0; +static safe_globals pyside_globals = nullptr; static PyObject *GetTypeKey(PyObject *ob); @@ -234,10 +234,10 @@ compute_name_key(PyObject *ob) static int build_name_key_to_func(PyObject *obtype) { - PyTypeObject *type = reinterpret_cast<PyTypeObject *>(obtype); + auto *type = reinterpret_cast<PyTypeObject *>(obtype); PyMethodDef *meth = type->tp_methods; - if (meth == 0) + if (meth == nullptr) return 0; Shiboken::AutoDecRef type_key(GetTypeKey(obtype)); @@ -457,7 +457,7 @@ static safe_globals_struc * init_phase_1(void) { { - safe_globals_struc *p = reinterpret_cast<safe_globals_struc *> + auto *p = reinterpret_cast<safe_globals_struc *> (malloc(sizeof(safe_globals_struc))); if (p == nullptr) goto error; @@ -661,11 +661,11 @@ add_more_getsets(PyTypeObject *type, PyGetSetDef *gsp, PyObject **old_descr) // // keep the original __doc__ functions -static PyObject *old_cf_doc_descr = 0; -static PyObject *old_sm_doc_descr = 0; -static PyObject *old_md_doc_descr = 0; -static PyObject *old_tp_doc_descr = 0; -static PyObject *old_wd_doc_descr = 0; +static PyObject *old_cf_doc_descr = nullptr; +static PyObject *old_sm_doc_descr = nullptr; +static PyObject *old_md_doc_descr = nullptr; +static PyObject *old_tp_doc_descr = nullptr; +static PyObject *old_wd_doc_descr = nullptr; static int handle_doc_in_progress = 0; @@ -675,7 +675,7 @@ handle_doc(PyObject *ob, PyObject *old_descr) init_module_1(); init_module_2(); Shiboken::AutoDecRef ob_type(GetClassOfFunc(ob)); - PyTypeObject *type = reinterpret_cast<PyTypeObject *>(ob_type.object()); + auto *type = reinterpret_cast<PyTypeObject *>(ob_type.object()); if (handle_doc_in_progress || strncmp(type->tp_name, "PySide2.", 8) != 0) return PyObject_CallMethod(old_descr, const_cast<char *>("__get__"), const_cast<char *>("(O)"), ob); handle_doc_in_progress++; @@ -737,35 +737,35 @@ static PyGetSetDef new_PyCFunction_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_cf_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_cf_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; static PyGetSetDef new_PyStaticMethod_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_sm_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_sm_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; static PyGetSetDef new_PyMethodDescr_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_md_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_md_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; static PyGetSetDef new_PyType_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_tp_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_tp_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; static PyGetSetDef new_PyWrapperDescr_getsets[] = { {const_cast<char *>("__doc__"), (getter)pyside_wd_get___doc__}, {const_cast<char *>("__signature__"), (getter)pyside_wd_get___signature__, (setter)pyside_set___signature__}, - {0} + {nullptr} }; //////////////////////////////////////////////////////////////////////////// @@ -795,7 +795,7 @@ get_signature_intern(PyObject *ob, const char *modifier) } static PyObject * -get_signature(PyObject *self, PyObject *args) +get_signature(PyObject * /* self */, PyObject *args) { PyObject *ob; const char *modifier = nullptr; @@ -1056,11 +1056,11 @@ _build_func_to_type(PyObject *obtype) * and record the mapping from static method to this type in a dict. * We also check for hidden methods, see below. */ - PyTypeObject *type = reinterpret_cast<PyTypeObject *>(obtype); + auto *type = reinterpret_cast<PyTypeObject *>(obtype); PyObject *dict = type->tp_dict; PyMethodDef *meth = type->tp_methods; - if (meth == 0) + if (meth == nullptr) return 0; for (; meth->ml_name != nullptr; meth++) { @@ -1123,12 +1123,12 @@ _build_func_to_type(PyObject *obtype) } int -SbkSpecial_Type_Ready(PyObject *module, PyTypeObject *type, +SbkSpecial_Type_Ready(PyObject * /* module */, PyTypeObject *type, const char *signatures[]) { if (PyType_Ready(type) < 0) return -1; - PyObject *ob_type = reinterpret_cast<PyObject *>(type); + auto *ob_type = reinterpret_cast<PyObject *>(type); int ret = PySide_BuildSignatureArgs(ob_type, signatures); if (ret < 0) { PyErr_Print(); diff --git a/sources/shiboken2/libshiboken/threadstatesaver.cpp b/sources/shiboken2/libshiboken/threadstatesaver.cpp index 517341617..0d19528f9 100644 --- a/sources/shiboken2/libshiboken/threadstatesaver.cpp +++ b/sources/shiboken2/libshiboken/threadstatesaver.cpp @@ -42,9 +42,7 @@ namespace Shiboken { -ThreadStateSaver::ThreadStateSaver() - : m_threadState(0) - {} +ThreadStateSaver::ThreadStateSaver() = default; ThreadStateSaver::~ThreadStateSaver() { @@ -61,7 +59,7 @@ void ThreadStateSaver::restore() { if (m_threadState) { PyEval_RestoreThread(m_threadState); - m_threadState = 0; + m_threadState = nullptr; } } diff --git a/sources/shiboken2/libshiboken/threadstatesaver.h b/sources/shiboken2/libshiboken/threadstatesaver.h index 10b3af12b..ddfbcb93b 100644 --- a/sources/shiboken2/libshiboken/threadstatesaver.h +++ b/sources/shiboken2/libshiboken/threadstatesaver.h @@ -59,7 +59,7 @@ public: void save(); void restore(); private: - PyThreadState *m_threadState; + PyThreadState *m_threadState = nullptr; }; } // namespace Shiboken diff --git a/sources/shiboken2/libshiboken/voidptr.cpp b/sources/shiboken2/libshiboken/voidptr.cpp index 4d09adb0c..d4ce58c87 100644 --- a/sources/shiboken2/libshiboken/voidptr.cpp +++ b/sources/shiboken2/libshiboken/voidptr.cpp @@ -61,10 +61,10 @@ PyObject *SbkVoidPtrObject_new(PyTypeObject *type, PyObject *args, PyObject *kwd // SbkVoidPtrObject *self = // reinterpret_cast<SbkVoidPtrObject *>(type->tp_alloc); PyObject *ob = type->tp_alloc(type, 0); - SbkVoidPtrObject *self = reinterpret_cast<SbkVoidPtrObject *>(ob); + auto *self = reinterpret_cast<SbkVoidPtrObject *>(ob); - if (self != 0) { - self->cptr = 0; + if (self != nullptr) { + self->cptr = nullptr; self->size = -1; self->isWritable = false; } @@ -80,9 +80,9 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) PyObject *addressObject; Py_ssize_t size = -1; int isWritable = 0; - SbkVoidPtrObject *sbkSelf = reinterpret_cast<SbkVoidPtrObject *>(self); + auto *sbkSelf = reinterpret_cast<SbkVoidPtrObject *>(self); - static const char *kwlist[] = {"address", "size", "writeable", 0}; + static const char *kwlist[] = {"address", "size", "writeable", nullptr}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ni", const_cast<char **>(kwlist), &addressObject, &size, &isWritable)) @@ -90,7 +90,7 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) // Void pointer. if (SbkVoidPtr_Check(addressObject)) { - SbkVoidPtrObject *sbkOther = reinterpret_cast<SbkVoidPtrObject *>(addressObject); + auto *sbkOther = reinterpret_cast<SbkVoidPtrObject *>(addressObject); sbkSelf->cptr = sbkOther->cptr; sbkSelf->size = sbkOther->size; sbkSelf->isWritable = sbkOther->isWritable; @@ -105,17 +105,17 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) sbkSelf->cptr = bufferView.buf; sbkSelf->size = bufferView.len > 0 ? bufferView.len : size; - sbkSelf->isWritable = bufferView.readonly > 0 ? false : true; + sbkSelf->isWritable = bufferView.readonly <= 0; // Release the buffer. PyBuffer_Release(&bufferView); } // Shiboken::Object wrapper. else if (Shiboken::Object::checkType(addressObject)) { - SbkObject *sbkOther = reinterpret_cast<SbkObject *>(addressObject); + auto *sbkOther = reinterpret_cast<SbkObject *>(addressObject); sbkSelf->cptr = sbkOther->d->cptr[0]; sbkSelf->size = size; - sbkSelf->isWritable = isWritable > 0 ? true : false; + sbkSelf->isWritable = isWritable > 0; } // An integer representing an address. else { @@ -137,7 +137,7 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) } sbkSelf->cptr = cptr; sbkSelf->size = size; - sbkSelf->isWritable = isWritable > 0 ? true : false; + sbkSelf->isWritable = isWritable > 0; } } @@ -147,8 +147,8 @@ int SbkVoidPtrObject_init(PyObject *self, PyObject *args, PyObject *kwds) PyObject *SbkVoidPtrObject_richcmp(PyObject *obj1, PyObject *obj2, int op) { PyObject *result = Py_False; - void *cptr1 = 0; - void *cptr2 = 0; + void *cptr1 = nullptr; + void *cptr2 = nullptr; bool validObjects = true; if (SbkVoidPtr_Check(obj1)) @@ -178,13 +178,13 @@ PyObject *SbkVoidPtrObject_richcmp(PyObject *obj1, PyObject *obj2, int op) PyObject *SbkVoidPtrObject_int(PyObject *v) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); return PyLong_FromVoidPtr(sbkObject->cptr); } PyObject *toBytes(PyObject *self, PyObject *args) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(self); if (sbkObject->size < 0) { PyErr_SetString(PyExc_IndexError, "VoidPtr does not have a size set."); return nullptr; @@ -197,12 +197,12 @@ PyObject *toBytes(PyObject *self, PyObject *args) static struct PyMethodDef SbkVoidPtrObject_methods[] = { {"toBytes", toBytes, METH_NOARGS}, - {0} + {nullptr} }; static Py_ssize_t SbkVoidPtrObject_length(PyObject *v) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); if (sbkObject->size < 0) { PyErr_SetString(PyExc_IndexError, "VoidPtr does not have a size set."); return -1; @@ -218,7 +218,7 @@ PyObject *SbkVoidPtrObject_repr(PyObject *v) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); #ifdef IS_PY3K PyObject *s = PyUnicode_FromFormat("%s(%p, %zd, %s)", #else @@ -234,7 +234,7 @@ PyObject *SbkVoidPtrObject_repr(PyObject *v) PyObject *SbkVoidPtrObject_str(PyObject *v) { - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(v); #ifdef IS_PY3K PyObject *s = PyUnicode_FromFormat("%s(Address %p, Size %zd, isWritable %s)", #else @@ -251,10 +251,10 @@ PyObject *SbkVoidPtrObject_str(PyObject *v) static int SbkVoidPtrObject_getbuffer(PyObject *obj, Py_buffer *view, int flags) { - if (view == NULL) + if (view == nullptr) return -1; - SbkVoidPtrObject *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(obj); + auto *sbkObject = reinterpret_cast<SbkVoidPtrObject *>(obj); if (sbkObject->size < 0) return -1; @@ -273,18 +273,18 @@ static int SbkVoidPtrObject_getbuffer(PyObject *obj, Py_buffer *view, int flags) view->len = sbkObject->size; view->readonly = readonly; view->itemsize = 1; - view->format = NULL; + view->format = nullptr; if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) - view->format = "B"; + view->format = const_cast<char *>("B"); view->ndim = 1; - view->shape = NULL; + view->shape = nullptr; if ((flags & PyBUF_ND) == PyBUF_ND) view->shape = &(view->len); - view->strides = NULL; + view->strides = nullptr; if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) view->strides = &(view->itemsize); - view->suboffsets = NULL; - view->internal = NULL; + view->suboffsets = nullptr; + view->internal = nullptr; return 0; } @@ -321,7 +321,7 @@ PyBufferProcs SbkVoidPtrObjectBufferProc = { static PyBufferProcs SbkVoidPtrObjectBufferProc = { (getbufferproc)SbkVoidPtrObject_getbuffer, // bf_getbuffer - (releasebufferproc)0 // bf_releasebuffer + (releasebufferproc)nullptr // bf_releasebuffer }; #endif @@ -337,7 +337,7 @@ static PyType_Slot SbkVoidPtrType_slots[] = { {Py_tp_new, (void *)SbkVoidPtrObject_new}, {Py_tp_dealloc, (void *)object_dealloc}, {Py_tp_methods, (void *)SbkVoidPtrObject_methods}, - {0, 0} + {0, nullptr} }; static PyType_Spec SbkVoidPtrType_spec = { "shiboken2.libshiboken.VoidPtr", @@ -354,7 +354,7 @@ PyTypeObject *SbkVoidPtrTypeF(void) { static PyTypeObject *type = nullptr; if (!type) - type = (PyTypeObject *)PyType_FromSpec(&SbkVoidPtrType_spec); + type = reinterpret_cast<PyTypeObject *>(PyType_FromSpec(&SbkVoidPtrType_spec)); #if PY_VERSION_HEX < 0x03000000 type->tp_as_buffer = &SbkVoidPtrObjectBufferProc; @@ -410,24 +410,24 @@ static PyObject *toPython(const void *cppIn) static void VoidPtrToCpp(PyObject *pyIn, void *cppOut) { - SbkVoidPtrObject *sbkIn = reinterpret_cast<SbkVoidPtrObject *>(pyIn); + auto *sbkIn = reinterpret_cast<SbkVoidPtrObject *>(pyIn); *reinterpret_cast<void **>(cppOut) = sbkIn->cptr; } static PythonToCppFunc VoidPtrToCppIsConvertible(PyObject *pyIn) { - return SbkVoidPtr_Check(pyIn) ? VoidPtrToCpp : 0; + return SbkVoidPtr_Check(pyIn) ? VoidPtrToCpp : nullptr; } static void SbkObjectToCpp(PyObject *pyIn, void *cppOut) { - SbkObject *sbkIn = reinterpret_cast<SbkObject *>(pyIn); + auto *sbkIn = reinterpret_cast<SbkObject *>(pyIn); *reinterpret_cast<void **>(cppOut) = sbkIn->d->cptr[0]; } static PythonToCppFunc SbkObjectToCppIsConvertible(PyObject *pyIn) { - return Shiboken::Object::checkType(pyIn) ? SbkObjectToCpp : 0; + return Shiboken::Object::checkType(pyIn) ? SbkObjectToCpp : nullptr; } static void PythonBufferToCpp(PyObject *pyIn, void *cppOut) @@ -453,14 +453,14 @@ static PythonToCppFunc PythonBufferToCppIsConvertible(PyObject *pyIn) // Bail out if the object can't provide a simple contiguous buffer. if (PyObject_GetBuffer(pyIn, &bufferView, PyBUF_SIMPLE) < 0) - return 0; + return nullptr; // Release the buffer. PyBuffer_Release(&bufferView); return PythonBufferToCpp; } - return 0; + return nullptr; } SbkConverter *createConverter() diff --git a/sources/shiboken2/tests/libminimal/typedef.h b/sources/shiboken2/tests/libminimal/typedef.h index 8e3455652..b8d6faacd 100644 --- a/sources/shiboken2/tests/libminimal/typedef.h +++ b/sources/shiboken2/tests/libminimal/typedef.h @@ -34,7 +34,7 @@ #include <vector> // Test wrapping of a typedef -typedef std::vector<int> MyArrayInt; +using MyArrayInt = std::vector<int>; LIBMINIMAL_API bool arrayFuncInt(std::vector<int> a); LIBMINIMAL_API bool arrayFuncIntTypedef(MyArrayInt a); @@ -43,7 +43,7 @@ LIBMINIMAL_API std::vector<int> arrayFuncIntReturn(int size); LIBMINIMAL_API MyArrayInt arrayFuncIntReturnTypedef(int size); // Test wrapping of a typedef of a typedef -typedef MyArrayInt MyArray; +using MyArray = MyArrayInt; LIBMINIMAL_API bool arrayFunc(std::vector<int> a); LIBMINIMAL_API bool arrayFuncTypedef(MyArray a); diff --git a/sources/shiboken2/tests/libother/otherderived.cpp b/sources/shiboken2/tests/libother/otherderived.cpp index 5b1714f2a..d23f6ad23 100644 --- a/sources/shiboken2/tests/libother/otherderived.cpp +++ b/sources/shiboken2/tests/libother/otherderived.cpp @@ -51,7 +51,7 @@ OtherDerived::pureVirtual() void* OtherDerived::pureVirtualReturningVoidPtr() { - return 0; + return nullptr; } void diff --git a/sources/shiboken2/tests/libother/othermultiplederived.cpp b/sources/shiboken2/tests/libother/othermultiplederived.cpp index 554df3c76..e7ee4f96d 100644 --- a/sources/shiboken2/tests/libother/othermultiplederived.cpp +++ b/sources/shiboken2/tests/libother/othermultiplederived.cpp @@ -45,6 +45,6 @@ Base1* OtherMultipleDerived::createObject(const std::string& objName) return new MDerived3; else if (objName == "OtherMultipleDerived") return new OtherMultipleDerived; - return 0; + return nullptr; } diff --git a/sources/shiboken2/tests/libsample/abstract.cpp b/sources/shiboken2/tests/libsample/abstract.cpp index c4900d0af..e60c792c4 100644 --- a/sources/shiboken2/tests/libsample/abstract.cpp +++ b/sources/shiboken2/tests/libsample/abstract.cpp @@ -38,7 +38,7 @@ Abstract::Abstract(int id) : m_id(id) { primitiveField = 123; valueTypeField = Point(12, 34); - objectTypeField = 0; + objectTypeField = nullptr; bitField = 0; } diff --git a/sources/shiboken2/tests/libsample/abstract.h b/sources/shiboken2/tests/libsample/abstract.h index 9e7cf5a29..09906f1ee 100644 --- a/sources/shiboken2/tests/libsample/abstract.h +++ b/sources/shiboken2/tests/libsample/abstract.h @@ -74,7 +74,7 @@ public: inline int id() { return m_id; } // factory method - inline static Abstract* createObject() { return 0; } + inline static Abstract* createObject() { return nullptr; } // method that receives an Object Type inline static int getObjectId(Abstract* obj) { return obj->id(); } diff --git a/sources/shiboken2/tests/libsample/blackbox.cpp b/sources/shiboken2/tests/libsample/blackbox.cpp index f3dd57e97..0546ba7c2 100644 --- a/sources/shiboken2/tests/libsample/blackbox.cpp +++ b/sources/shiboken2/tests/libsample/blackbox.cpp @@ -49,7 +49,7 @@ BlackBox::keepObjectType(ObjectType* object) m_ticket++; std::pair<int, ObjectType*> item(m_ticket, object); m_objects.insert(item); - object->setParent(0); + object->setParent(nullptr); return m_ticket; } @@ -63,7 +63,7 @@ BlackBox::retrieveObjectType(int ticket) m_objects.erase(it); return second; } - return 0; + return nullptr; } void @@ -93,7 +93,7 @@ BlackBox::retrievePoint(int ticket) m_points.erase(it); return second; } - return 0; + return nullptr; } void diff --git a/sources/shiboken2/tests/libsample/derived.cpp b/sources/shiboken2/tests/libsample/derived.cpp index 4fa3e4081..0dc026876 100644 --- a/sources/shiboken2/tests/libsample/derived.cpp +++ b/sources/shiboken2/tests/libsample/derived.cpp @@ -54,7 +54,7 @@ Derived::pureVirtual() void* Derived::pureVirtualReturningVoidPtr() { - return 0; + return nullptr; } void @@ -100,7 +100,7 @@ Derived::otherOverloaded(int a, double b) struct SecretClass : public Abstract { virtual void pureVirtual() {} - virtual void* pureVirtualReturningVoidPtr() { return 0; } + virtual void *pureVirtualReturningVoidPtr() { return nullptr; } virtual PrintFormat returnAnEnum() { return Short; } void hideFunction(HideType*){}; private: diff --git a/sources/shiboken2/tests/libsample/expression.cpp b/sources/shiboken2/tests/libsample/expression.cpp index a6051306e..0c255a659 100644 --- a/sources/shiboken2/tests/libsample/expression.cpp +++ b/sources/shiboken2/tests/libsample/expression.cpp @@ -30,18 +30,18 @@ #include "expression.h" #include <sstream> -Expression::Expression() : m_value(0), m_operation(None), m_operand1(0), m_operand2(0) +Expression::Expression() : m_value(0), m_operation(None), m_operand1(nullptr), m_operand2(nullptr) { } -Expression::Expression(int number) : m_value(number), m_operation(None), m_operand1(0), m_operand2(0) +Expression::Expression(int number) : m_value(number), m_operation(None), m_operand1(nullptr), m_operand2(nullptr) { } Expression::Expression(const Expression& other) { - m_operand1 = other.m_operand1 ? new Expression(*other.m_operand1) : 0; - m_operand2 = other.m_operand2 ? new Expression(*other.m_operand2) : 0; + m_operand1 = other.m_operand1 ? new Expression(*other.m_operand1) : nullptr; + m_operand2 = other.m_operand2 ? new Expression(*other.m_operand2) : nullptr; m_value = other.m_value; m_operation = other.m_operation; } @@ -50,8 +50,8 @@ Expression& Expression::operator=(const Expression& other) { delete m_operand1; delete m_operand2; - m_operand1 = other.m_operand1 ? new Expression(*other.m_operand1) : 0; - m_operand2 = other.m_operand2 ? new Expression(*other.m_operand2) : 0; + m_operand1 = other.m_operand1 ? new Expression(*other.m_operand1) : nullptr; + m_operand2 = other.m_operand2 ? new Expression(*other.m_operand2) : nullptr; m_operation = other.m_operation; m_value = other.m_value; return *this; diff --git a/sources/shiboken2/tests/libsample/functions.cpp b/sources/shiboken2/tests/libsample/functions.cpp index 5cc9a1c67..288fa96ee 100644 --- a/sources/shiboken2/tests/libsample/functions.cpp +++ b/sources/shiboken2/tests/libsample/functions.cpp @@ -118,19 +118,19 @@ overloadedFunc(double val) char* returnNullPrimitivePointer() { - return 0; + return nullptr; } ObjectType* returnNullObjectTypePointer() { - return 0; + return nullptr; } Event* returnNullValueTypePointer() { - return 0; + return nullptr; } unsigned int diff --git a/sources/shiboken2/tests/libsample/handle.h b/sources/shiboken2/tests/libsample/handle.h index 400a0a3a6..824c28b9a 100644 --- a/sources/shiboken2/tests/libsample/handle.h +++ b/sources/shiboken2/tests/libsample/handle.h @@ -33,19 +33,19 @@ /* See http://bugs.pyside.org/show_bug.cgi?id=1105. */ namespace Foo { - typedef unsigned long HANDLE; + using HANDLE = unsigned long; } class LIBSAMPLE_API OBJ { }; -typedef OBJ* HANDLE; +using HANDLE = OBJ *; class LIBSAMPLE_API HandleHolder { public: - explicit HandleHolder(HANDLE ptr = 0) : m_handle(ptr) {} + explicit HandleHolder(HANDLE ptr = nullptr) : m_handle(ptr) {} explicit HandleHolder(Foo::HANDLE val): m_handle2(val) {} inline void set(HANDLE ptr) { HANDLE tmp; tmp = m_handle; m_handle = tmp; } @@ -63,7 +63,7 @@ private: }; struct LIBSAMPLE_API PrimitiveStruct {}; -typedef struct PrimitiveStruct* PrimitiveStructPtr; +using PrimitiveStructPtr = struct PrimitiveStruct *; struct LIBSAMPLE_API PrimitiveStructPointerHolder { PrimitiveStructPtr primitiveStructPtr; diff --git a/sources/shiboken2/tests/libsample/listuser.h b/sources/shiboken2/tests/libsample/listuser.h index 92360884f..7e67039d9 100644 --- a/sources/shiboken2/tests/libsample/listuser.h +++ b/sources/shiboken2/tests/libsample/listuser.h @@ -39,7 +39,7 @@ class LIBSAMPLE_API ListUser { public: - typedef std::list<Point*> PointList; + using PointList = std::list<Point *>; enum ListOfSomething { ListOfPoint, diff --git a/sources/shiboken2/tests/libsample/modifications.h b/sources/shiboken2/tests/libsample/modifications.h index 035ec844e..fa32bdec3 100644 --- a/sources/shiboken2/tests/libsample/modifications.h +++ b/sources/shiboken2/tests/libsample/modifications.h @@ -117,7 +117,7 @@ public: double callDifferenceOfPointCoordinates(const Point* pt, bool* ok) { return differenceOfPointCoordinates(pt, ok); } // Sets an ObjectType in the argument and returns true. - bool nonConversionRuleForArgumentWithDefaultValue(ObjectType** object = 0); + bool nonConversionRuleForArgumentWithDefaultValue(ObjectType **object = nullptr); ObjectType* getObject() const { return m_object; } // Inject code with a %CONVERTTOPYTHON that receives an user's primitive type. diff --git a/sources/shiboken2/tests/libsample/objectmodel.h b/sources/shiboken2/tests/libsample/objectmodel.h index e15ce06a4..1890ac47f 100644 --- a/sources/shiboken2/tests/libsample/objectmodel.h +++ b/sources/shiboken2/tests/libsample/objectmodel.h @@ -35,8 +35,8 @@ class LIBSAMPLE_API ObjectModel : public ObjectType { public: - explicit ObjectModel(ObjectType* parent = 0) - : ObjectType(parent), m_data(0) + explicit ObjectModel(ObjectType *parent = nullptr) + : ObjectType(parent), m_data(nullptr) {} void setData(ObjectType* data); diff --git a/sources/shiboken2/tests/libsample/objecttype.cpp b/sources/shiboken2/tests/libsample/objecttype.cpp index f82b7cf0d..855c08611 100644 --- a/sources/shiboken2/tests/libsample/objecttype.cpp +++ b/sources/shiboken2/tests/libsample/objecttype.cpp @@ -35,7 +35,7 @@ using namespace std; -ObjectType::ObjectType(ObjectType* parent) : m_parent(0), m_layout(0), m_call_id(-1) +ObjectType::ObjectType(ObjectType* parent) : m_parent(nullptr), m_layout(nullptr), m_call_id(-1) { setParent(parent); } @@ -66,7 +66,7 @@ ObjectType::removeChild(ObjectType* child) ObjectTypeList::iterator child_iter = std::find(m_children.begin(), m_children.end(), child); if (child_iter != m_children.end()) { m_children.erase(child_iter); - child->m_parent = 0; + child->m_parent = nullptr; } } @@ -74,15 +74,15 @@ ObjectType* ObjectType::takeChild(ObjectType* child) { if (!child) - return 0; + return nullptr; ObjectTypeList::iterator child_iter = std::find(m_children.begin(), m_children.end(), child); if (child_iter != m_children.end()) { m_children.erase(child_iter); - child->m_parent = 0; + child->m_parent = nullptr; return child; } - return 0; + return nullptr; } ObjectType* @@ -101,7 +101,7 @@ ObjectType::findChild(const Str& name) if ((*child_iter)->objectName() == name) return *child_iter; } - return 0; + return nullptr; } void @@ -218,8 +218,8 @@ ObjectTypeLayout* ObjectType::takeLayout() { ObjectTypeLayout* l = layout(); if (!l) - return 0; - m_layout = 0; + return nullptr; + m_layout = nullptr; l->setParent(0); return l; } diff --git a/sources/shiboken2/tests/libsample/objecttype.h b/sources/shiboken2/tests/libsample/objecttype.h index ecd67b684..1f2a9c7e8 100644 --- a/sources/shiboken2/tests/libsample/objecttype.h +++ b/sources/shiboken2/tests/libsample/objecttype.h @@ -69,9 +69,9 @@ class LIBSAMPLE_API ObjectType { public: // ### Fixme: Use uintptr_t in C++ 11 - typedef size_t Identifier; + using Identifier = size_t; - explicit ObjectType(ObjectType* parent = 0); + explicit ObjectType(ObjectType *parent = nullptr); virtual ~ObjectType(); // factory method diff --git a/sources/shiboken2/tests/libsample/objectview.h b/sources/shiboken2/tests/libsample/objectview.h index 6a54057e9..b68d031e9 100644 --- a/sources/shiboken2/tests/libsample/objectview.h +++ b/sources/shiboken2/tests/libsample/objectview.h @@ -38,7 +38,7 @@ class ObjectModel; class LIBSAMPLE_API ObjectView : public ObjectType { public: - ObjectView(ObjectModel* model = 0, ObjectType* parent = 0) + ObjectView(ObjectModel *model = nullptr, ObjectType *parent = nullptr) : ObjectType(parent), m_model(model) {} diff --git a/sources/shiboken2/tests/libsample/overload.h b/sources/shiboken2/tests/libsample/overload.h index 6d0165619..aa2572d50 100644 --- a/sources/shiboken2/tests/libsample/overload.h +++ b/sources/shiboken2/tests/libsample/overload.h @@ -83,7 +83,7 @@ public: FunctionEnum wrapperIntIntOverloads(const Polygon& arg0, int arg1, int arg2) { return Function1; } // Similar to QImage constructor - FunctionEnum strBufferOverloads(const Str& arg0, const char* arg1 = 0, bool arg2 = true) { return Function0; } + FunctionEnum strBufferOverloads(const Str &arg0, const char *arg1 = nullptr, bool arg2 = true) { return Function0; } FunctionEnum strBufferOverloads(unsigned char* arg0, int arg1) { return Function1; } FunctionEnum strBufferOverloads() { return Function2; } diff --git a/sources/shiboken2/tests/libsample/photon.h b/sources/shiboken2/tests/libsample/photon.h index 2a32d511a..1dcb4f83e 100644 --- a/sources/shiboken2/tests/libsample/photon.h +++ b/sources/shiboken2/tests/libsample/photon.h @@ -93,8 +93,8 @@ template class LIBSAMPLE_API TemplateBase<IdentityType>; template class LIBSAMPLE_API TemplateBase<DuplicatorType>; #endif -typedef TemplateBase<IdentityType> ValueIdentity; -typedef TemplateBase<DuplicatorType> ValueDuplicator; +using ValueIdentity = TemplateBase<IdentityType>; +using ValueDuplicator = TemplateBase<DuplicatorType>; LIBSAMPLE_API int callCalculateForValueDuplicatorPointer(ValueDuplicator* value); LIBSAMPLE_API int callCalculateForValueDuplicatorReference(ValueDuplicator& value); @@ -116,7 +116,7 @@ LIBSAMPLE_API int countValueDuplicators(const std::list<TemplateBase<DuplicatorT class Pointer { public: - Pointer() PHOTON_NOEXCEPT : px(0) {} + Pointer() PHOTON_NOEXCEPT : px(nullptr) {} Pointer(int* p) : px(p) {} void reset() PHOTON_NOEXCEPT { Pointer().swap(*this); } diff --git a/sources/shiboken2/tests/libsample/polygon.h b/sources/shiboken2/tests/libsample/polygon.h index 3eafa3094..728332d1a 100644 --- a/sources/shiboken2/tests/libsample/polygon.h +++ b/sources/shiboken2/tests/libsample/polygon.h @@ -37,7 +37,7 @@ class LIBSAMPLE_API Polygon { public: - typedef std::list<Point> PointList; + using PointList = std::list<Point>; Polygon() {} Polygon(double x, double y); diff --git a/sources/shiboken2/tests/libsample/protected.h b/sources/shiboken2/tests/libsample/protected.h index 6cdc66e2b..0f4fbf299 100644 --- a/sources/shiboken2/tests/libsample/protected.h +++ b/sources/shiboken2/tests/libsample/protected.h @@ -50,7 +50,7 @@ protected: inline int protectedSum(int a0, int a1) { return a0 + a1; } inline int modifiedProtectedSum(int a0, int a1) { return a0 + a1; } inline static const char* protectedStatic() { return "protectedStatic"; } - inline const char* dataTypeName(void *data = 0) const { return "pointer"; } + inline const char* dataTypeName(void *data = nullptr) const { return "pointer"; } inline const char* dataTypeName(int data) const { return "integer"; } private: @@ -130,8 +130,8 @@ public: : protectedValueTypeProperty(Point(0, 0)), protectedProperty(0), protectedEnumProperty(Event::NO_EVENT), - protectedValueTypePointerProperty(0), - protectedObjectTypeProperty(0) + protectedValueTypePointerProperty(nullptr), + protectedObjectTypeProperty(nullptr) {} protected: // This is deliberately the first member to test wrapper registration diff --git a/sources/shiboken2/tests/libsample/samplenamespace.cpp b/sources/shiboken2/tests/libsample/samplenamespace.cpp index e066869d2..fc9f6d395 100644 --- a/sources/shiboken2/tests/libsample/samplenamespace.cpp +++ b/sources/shiboken2/tests/libsample/samplenamespace.cpp @@ -78,7 +78,7 @@ getNumber(Option opt) retval = rand() % 100; break; case UnixTime: - retval = (int) time(0); + retval = (int) time(nullptr); break; default: retval = 0; diff --git a/sources/shiboken2/tests/libsample/samplenamespace.h b/sources/shiboken2/tests/libsample/samplenamespace.h index 27fa11290..6868b5f0a 100644 --- a/sources/shiboken2/tests/libsample/samplenamespace.h +++ b/sources/shiboken2/tests/libsample/samplenamespace.h @@ -92,7 +92,7 @@ inline double powerOfTwo(double num) { return num * num; } -LIBSAMPLE_API void doSomethingWithArray(const unsigned char* data, unsigned int size, const char* format = 0); +LIBSAMPLE_API void doSomethingWithArray(const unsigned char *data, unsigned int size, const char *format = nullptr); LIBSAMPLE_API int enumItemAsDefaultValueToIntArgument(int value = ZeroIn); @@ -145,19 +145,19 @@ public: // enum SampleNamespace { // }; virtual OkThisIsRecursiveEnough* someVirtualMethod(OkThisIsRecursiveEnough* arg) { return arg; } - inline OkThisIsRecursiveEnough* methodReturningTypeFromParentScope() { return 0; } + inline OkThisIsRecursiveEnough *methodReturningTypeFromParentScope() { return nullptr; } }; // The combination of the following two overloaded methods could trigger a // problematic behaviour on the overload decisor, if it isn't working properly. -LIBSAMPLE_API void forceDecisorSideA(ObjectType* object = 0); +LIBSAMPLE_API void forceDecisorSideA(ObjectType *object = nullptr); LIBSAMPLE_API void forceDecisorSideA(const Point& pt, const Str& text, ObjectType* object = 0); // The combination of the following two overloaded methods could trigger a // problematic behaviour on the overload decisor, if it isn't working properly. // This is a variation of forceDecisorSideB. -LIBSAMPLE_API void forceDecisorSideB(int a, ObjectType* object = 0); -LIBSAMPLE_API void forceDecisorSideB(int a, const Point& pt, const Str& text, ObjectType* object = 0); +LIBSAMPLE_API void forceDecisorSideB(int a, ObjectType *object = nullptr); +LIBSAMPLE_API void forceDecisorSideB(int a, const Point &pt, const Str &text, ObjectType *object = nullptr); // Add a new signature on type system with only a Point value as parameter. LIBSAMPLE_API double passReferenceToValueType(const Point& point, double multiplier); diff --git a/sources/shiboken2/tests/libsample/simplefile.cpp b/sources/shiboken2/tests/libsample/simplefile.cpp index a47571a01..3b68e02c3 100644 --- a/sources/shiboken2/tests/libsample/simplefile.cpp +++ b/sources/shiboken2/tests/libsample/simplefile.cpp @@ -34,7 +34,7 @@ class SimpleFile_p { public: - SimpleFile_p(const char* filename) : m_descriptor(0), m_size(0) + SimpleFile_p(const char* filename) : m_descriptor(nullptr), m_size(0) { m_filename = strdup(filename); } @@ -73,7 +73,7 @@ long SimpleFile::size() bool SimpleFile::open() { - if ((p->m_descriptor = fopen(p->m_filename, "rb")) == 0) + if ((p->m_descriptor = fopen(p->m_filename, "rb")) == nullptr) return false; fseek(p->m_descriptor, 0, SEEK_END); @@ -88,7 +88,7 @@ SimpleFile::close() { if (p->m_descriptor) { fclose(p->m_descriptor); - p->m_descriptor = 0; + p->m_descriptor = nullptr; } } diff --git a/sources/shiboken2/tests/libsample/size.h b/sources/shiboken2/tests/libsample/size.h index c72021231..76502b416 100644 --- a/sources/shiboken2/tests/libsample/size.h +++ b/sources/shiboken2/tests/libsample/size.h @@ -188,8 +188,8 @@ inline const Size operator/(const Size& s, double div) return Size(s.m_width / div, s.m_height / div); } -typedef double real; -typedef unsigned short ushort; +using real = double; +using ushort = unsigned short; class LIBSAMPLE_API SizeF { public: diff --git a/sources/shiboken2/tests/libsample/sometime.h b/sources/shiboken2/tests/libsample/sometime.h index 319cd7f8f..ef16efa29 100644 --- a/sources/shiboken2/tests/libsample/sometime.h +++ b/sources/shiboken2/tests/libsample/sometime.h @@ -70,7 +70,7 @@ public: NumArgs somethingCompletelyDifferent(); NumArgs somethingCompletelyDifferent(int h, int m, ImplicitConv ic = ImplicitConv::CtorThree, - ObjectType* type = 0); + ObjectType *type = nullptr); Str toString() const; bool operator==(const Time& other) const; diff --git a/sources/shiboken2/tests/libsample/str.h b/sources/shiboken2/tests/libsample/str.h index d3bcbaafc..2f7cee8c3 100644 --- a/sources/shiboken2/tests/libsample/str.h +++ b/sources/shiboken2/tests/libsample/str.h @@ -49,7 +49,7 @@ public: char get_char(int pos) const; bool set_char(int pos, char ch); - int toInt(bool* ok = 0, int base = 10) const; + int toInt(bool *ok = nullptr, int base = 10) const; void show() const; @@ -71,8 +71,8 @@ private: LIBSAMPLE_API Str operator+(int number, const Str& str); LIBSAMPLE_API unsigned int strHash(const Str& str); -typedef Str PStr; +using PStr = Str; LIBSAMPLE_API void changePStr(PStr* pstr, const char* suffix); -LIBSAMPLE_API void duplicatePStr(PStr* pstr = 0); +LIBSAMPLE_API void duplicatePStr(PStr *pstr = nullptr); #endif // STR_H diff --git a/sources/shiboken2/tests/libsample/strlist.h b/sources/shiboken2/tests/libsample/strlist.h index 27fc05e6e..43aa15390 100644 --- a/sources/shiboken2/tests/libsample/strlist.h +++ b/sources/shiboken2/tests/libsample/strlist.h @@ -60,6 +60,6 @@ private: CtorEnum m_ctorUsed; }; -typedef StrList PStrList; +using PStrList = StrList; #endif // STRLIST_H diff --git a/sources/shiboken2/tests/libsample/virtualmethods.cpp b/sources/shiboken2/tests/libsample/virtualmethods.cpp index 2d26bd7c8..294feca60 100644 --- a/sources/shiboken2/tests/libsample/virtualmethods.cpp +++ b/sources/shiboken2/tests/libsample/virtualmethods.cpp @@ -40,7 +40,7 @@ bool VirtualMethods::createStr(const char* text, Str*& ret) { if (!text) { - ret = 0; + ret = nullptr; return false; } diff --git a/sources/shiboken2/tests/libsample/voidholder.h b/sources/shiboken2/tests/libsample/voidholder.h index 23408fad8..367e99ddf 100644 --- a/sources/shiboken2/tests/libsample/voidholder.h +++ b/sources/shiboken2/tests/libsample/voidholder.h @@ -34,7 +34,7 @@ class VoidHolder { public: - explicit VoidHolder(void* ptr = 0) : m_ptr(ptr) {} + explicit VoidHolder(void *ptr = nullptr) : m_ptr(ptr) {} ~VoidHolder() {} inline void* voidPointer() { return m_ptr; } inline static void* gimmeMeSomeVoidPointer() diff --git a/sources/shiboken2/tests/libsmart/smart.h b/sources/shiboken2/tests/libsmart/smart.h index 2e3c96406..3347b22c1 100644 --- a/sources/shiboken2/tests/libsmart/smart.h +++ b/sources/shiboken2/tests/libsmart/smart.h @@ -81,7 +81,7 @@ public: template <class T> class SharedPtr { public: - SharedPtr() : m_refData(0) { + SharedPtr() : m_refData(nullptr) { if (shouldPrint()) std::cout << "shared_ptr default constructor " << this << "\n"; } @@ -122,7 +122,7 @@ public: { if (m_refData) return m_refData->m_heldPtr; - return 0; + return nullptr; } int useCount() const @@ -147,7 +147,7 @@ public: { if (m_refData) return m_refData->m_heldPtr; - return 0; + return nullptr; } bool operator!() const |