diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-05-29 14:59:09 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-06-25 10:45:28 +0200 |
commit | 4ccfd8de6462ce2ed938587eb0518038640c310f (patch) | |
tree | dbb4a1ff15a6729c2b4a213669f23861da779d3f /sources/shiboken2/generator/shiboken2 | |
parent | 3680a489521e4c13488b4f3f462b8e34cebd0e47 (diff) |
shiboken: Fix various clang warnings
- Avoid copying complex types by using const ref
- Use isEmpty() to check for container emptyness
- Use range-based for
- Use Q_DISABLE_COPY in 'public:' area
- Fix spelling error
- Use '= default' for trivial constructors/destructors
- Remove non-null checks before deletion
- Fix misleading indentation
- Fix else after return
- Simplify boolean expressions
- Fix unused parameters, streamline code
Change-Id: I8c6cadd8653e220ba8e5bdb4dd55524d13a81768
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/generator/shiboken2')
3 files changed, 28 insertions, 23 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 0d197eab3..84f0cd1f5 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -203,11 +203,10 @@ 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, @@ -1660,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); @@ -1821,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); @@ -2148,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()) { @@ -2401,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; @@ -2511,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; @@ -2877,7 +2879,7 @@ void CppGenerator::writePythonToCppConversionFunctions(QTextStream &s, const AbstractMetaType *targetType, QString typeCheck, QString conversion, - QString preConversion) + const QString &preConversion) { QString sourcePyType = cpythonTypeNameExt(sourceType); diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.h b/sources/shiboken2/generator/shiboken2/cppgenerator.h index 9a4a02093..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); @@ -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/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index bfd14d20c..8e27777d6 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -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; } |