diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-11-24 09:48:26 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-11-29 13:32:56 +0100 |
commit | d37c69526fdf6cf79e8c2695c19460fbb12e833f (patch) | |
tree | 6a621924846b2e112f81628ff3d9142153055c3a | |
parent | 51636b43d90bc29996f3bbd8372f333eb1a321d0 (diff) |
shiboken6: Remove inline functions using QStringLiteral
Replace the formely used
static inline QString foo() { return QStringLiteral("foo"); }
by latin1 literals.
Task-number: PYSIDE-2537
Change-Id: Ia4e9827e2b2a2f65f06751d549e8d79002386878
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
13 files changed, 179 insertions, 190 deletions
diff --git a/sources/shiboken6/ApiExtractor/addedfunction.cpp b/sources/shiboken6/ApiExtractor/addedfunction.cpp index efb5fb997..15ae1056f 100644 --- a/sources/shiboken6/ApiExtractor/addedfunction.cpp +++ b/sources/shiboken6/ApiExtractor/addedfunction.cpp @@ -9,7 +9,7 @@ using namespace Qt::StringLiterals; -static inline QString callOperator() { return QStringLiteral("operator()"); } +constexpr auto callOperator = "operator()"_L1; // Helpers to split a parameter list of <add-function>, <declare-function> // (@ denoting names), like @@ -143,8 +143,8 @@ AddedFunction::AddedFunctionPtr QStringView signature = QStringView{signatureIn}.trimmed(); // Skip past "operator()(...)" - const auto parenSearchStartPos = signature.startsWith(callOperator()) - ? callOperator().size() : 0; + const auto parenSearchStartPos = signature.startsWith(callOperator) + ? callOperator.size() : 0; const auto openParenPos = signature.indexOf(u'(', parenSearchStartPos); if (openParenPos < 0) { return AddedFunctionPtr(new AddedFunction(signature.toString(), diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp index 57604ceac..c0b73a7f5 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp @@ -26,8 +26,6 @@ using namespace Qt::StringLiterals; namespace clang { -static inline QString templateBrackets() { return QStringLiteral("<>"); } - static inline bool isClassCursor(const CXCursor &c) { return c.kind == CXCursor_ClassDecl || c.kind == CXCursor_StructDecl @@ -969,8 +967,8 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor) || !d->addClass(cursor, CodeModel::Class)) { return Skip; } - d->m_currentClass->setName(d->m_currentClass->name() + templateBrackets()); - d->m_scope.back() += templateBrackets(); + d->m_currentClass->setName(d->m_currentClass->name() + "<>"_L1); + d->m_scope.back() += "<>"_L1; break; case CXCursor_EnumDecl: { QString name = enumType(cursor); diff --git a/sources/shiboken6/ApiExtractor/parser/typeinfo.cpp b/sources/shiboken6/ApiExtractor/parser/typeinfo.cpp index 5fa9374ed..65e1acf73 100644 --- a/sources/shiboken6/ApiExtractor/parser/typeinfo.cpp +++ b/sources/shiboken6/ApiExtractor/parser/typeinfo.cpp @@ -457,20 +457,17 @@ QString TypeInfo::indirectionKeyword(Indirection i) ? QStringLiteral("*") : QStringLiteral("*const"); } -static inline QString constQualifier() { return QStringLiteral("const"); } -static inline QString volatileQualifier() { return QStringLiteral("volatile"); } - bool TypeInfo::stripLeadingConst(QString *s) { - return stripLeadingQualifier(constQualifier(), s); + return stripLeadingQualifier("const"_L1, s); } bool TypeInfo::stripLeadingVolatile(QString *s) { - return stripLeadingQualifier(volatileQualifier(), s); + return stripLeadingQualifier("volatile"_L1, s); } -bool TypeInfo::stripLeadingQualifier(const QString &qualifier, QString *s) +bool TypeInfo::stripLeadingQualifier(QLatin1StringView qualifier, QString *s) { // "const int x" const auto qualifierSize = qualifier.size(); diff --git a/sources/shiboken6/ApiExtractor/parser/typeinfo.h b/sources/shiboken6/ApiExtractor/parser/typeinfo.h index 0f1a04f6f..895197927 100644 --- a/sources/shiboken6/ApiExtractor/parser/typeinfo.h +++ b/sources/shiboken6/ApiExtractor/parser/typeinfo.h @@ -103,7 +103,7 @@ public: static bool stripLeadingConst(QString *s); static bool stripLeadingVolatile(QString *s); - static bool stripLeadingQualifier(const QString &qualifier, QString *s); + static bool stripLeadingQualifier(QLatin1StringView qualifier, QString *s); static void stripQualifiers(QString *s); void simplifyStdType(); diff --git a/sources/shiboken6/ApiExtractor/qtdocparser.cpp b/sources/shiboken6/ApiExtractor/qtdocparser.cpp index badf6b7af..78c271ee1 100644 --- a/sources/shiboken6/ApiExtractor/qtdocparser.cpp +++ b/sources/shiboken6/ApiExtractor/qtdocparser.cpp @@ -26,8 +26,8 @@ using namespace Qt::StringLiterals; enum { debugFunctionSearch = 0 }; -static inline QString briefStartElement() { return QStringLiteral("<brief>"); } -static inline QString briefEndElement() { return QStringLiteral("</brief>"); } +constexpr auto briefStartElement = "<brief>"_L1; +constexpr auto briefEndElement = "</brief>"_L1; Documentation QtDocParser::retrieveModuleDocumentation() { @@ -187,16 +187,16 @@ QString QtDocParser::queryFunctionDocumentation(const QString &sourceFileName, // from the source. static QString extractBrief(QString *value) { - const auto briefStart = value->indexOf(briefStartElement()); + const auto briefStart = value->indexOf(briefStartElement); if (briefStart < 0) return {}; - const auto briefEnd = value->indexOf(briefEndElement(), - briefStart + briefStartElement().size()); + const auto briefEnd = value->indexOf(briefEndElement, + briefStart + briefStartElement.size()); if (briefEnd < briefStart) return {}; - const auto briefLength = briefEnd + briefEndElement().size() - briefStart; + const auto briefLength = briefEnd + briefEndElement.size() - briefStart; QString briefValue = value->mid(briefStart, briefLength); - briefValue.insert(briefValue.size() - briefEndElement().size(), + briefValue.insert(briefValue.size() - briefEndElement.size(), u"<rst> More_...</rst>"_s); value->remove(briefStart, briefLength); return briefValue; diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp index ef61a077b..17b2e90bb 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp @@ -91,9 +91,9 @@ static QString propertyRefTarget(const AbstractMetaClassCPtr &cppClass, const QS return result; } -static inline QString additionalDocumentationOption() { return QStringLiteral("additional-documentation"); } +constexpr auto additionalDocumentationOption = "additional-documentation"_L1; -static inline QString none() { return QStringLiteral("None"); } +constexpr auto none = "None"_L1; static bool shouldSkip(const AbstractMetaFunctionCPtr &func) { @@ -557,13 +557,13 @@ QString QtDocGenerator::formatArgs(const AbstractMetaFunctionCPtr &func) || defValue.startsWith(u"QList")) { defValue = u"list()"_s; } else if (defValue == u"QVariant()") { - defValue = none(); + defValue = none; } else { defValue.replace(u"::"_s, u"."_s); if (defValue == u"nullptr") - defValue = none(); + defValue = none; else if (defValue == u"0" && arg.type().isObject()) - defValue = none(); + defValue = none; } ret += u'=' + defValue; } @@ -686,25 +686,25 @@ QString QtDocGenerator::translateToPythonType(const AbstractMetaType &type, bool createRef) const { static const QStringList nativeTypes = - {boolT(), floatT(), intT(), pyObjectT(), pyStrT()}; + {boolT, floatT, intT, pyObjectT, pyStrT}; const QString name = type.name(); if (nativeTypes.contains(name)) return name; static const QMap<QString, QString> typeMap = { - { cPyObjectT(), pyObjectT() }, - { qStringT(), pyStrT() }, - { u"uchar"_s, pyStrT() }, + { cPyObjectT, pyObjectT }, + { qStringT, pyStrT }, + { u"uchar"_s, pyStrT }, { u"QStringList"_s, u"list of strings"_s }, - { qVariantT(), pyObjectT() }, - { u"quint32"_s, intT() }, - { u"uint32_t"_s, intT() }, - { u"quint64"_s, intT() }, - { u"qint64"_s, intT() }, - { u"size_t"_s, intT() }, - { u"int64_t"_s, intT() }, - { u"qreal"_s, floatT() } + { qVariantT, pyObjectT }, + { u"quint32"_s, intT }, + { u"uint32_t"_s, intT }, + { u"quint64"_s, intT }, + { u"qint64"_s, intT }, + { u"size_t"_s, intT }, + { u"int64_t"_s, intT }, + { u"qreal"_s, floatT } }; const auto found = typeMap.find(name); if (found != typeMap.end()) @@ -713,10 +713,10 @@ QString QtDocGenerator::translateToPythonType(const AbstractMetaType &type, QString strType; if (type.isConstant() && name == u"char" && type.indirections() == 1) { strType = u"str"_s; - } else if (name.startsWith(unsignedShortT())) { - strType = intT(); - } else if (name.startsWith(unsignedT())) { // uint and ulong - strType = intT(); + } else if (name.startsWith(unsignedShortT)) { + strType = intT; + } else if (name.startsWith(unsignedT)) { // uint and ulong + strType = intT; } else if (type.isContainer()) { QString strType = translateType(type, cppClass, Options(ExcludeConst) | ExcludeReference); strType.remove(u'*'); @@ -1119,7 +1119,7 @@ QList<OptionDescription> QtDocGenerator::options() u"Directory used to search for extra documentation sections"_s}, {u"library-source-dir=<dir>"_s, u"Directory where library source code is located"_s}, - {additionalDocumentationOption() + u"=<file>"_s, + {additionalDocumentationOption + u"=<file>"_s, u"List of additional XML files to be converted to .rst files\n" "(for example, tutorials)."_s}, {u"inheritance-file=<file>"_s, @@ -1175,7 +1175,7 @@ bool QtDocGeneratorOptionsParser::handleOption(const QString &key, const QString m_options->doxygen = true; return true; } - if (key == additionalDocumentationOption()) { + if (key == additionalDocumentationOption) { m_options->additionalDocumentationList = value; return true; } diff --git a/sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp b/sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp index 2fd016218..f9bb33373 100644 --- a/sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp +++ b/sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp @@ -19,10 +19,6 @@ using namespace Qt::StringLiterals; -static inline QString nameAttribute() { return QStringLiteral("name"); } -static inline QString titleAttribute() { return QStringLiteral("title"); } -static inline QString fullTitleAttribute() { return QStringLiteral("fulltitle"); } - QString msgTagWarning(const QXmlStreamReader &reader, const QString &context, const QString &tag, const QString &message) { @@ -849,23 +845,23 @@ void QtXmlToSphinx::handleArgumentTag(QXmlStreamReader& reader) } } -static inline QString functionLinkType() { return QStringLiteral("function"); } -static inline QString classLinkType() { return QStringLiteral("class"); } +constexpr auto functionLinkType = "function"_L1; +constexpr auto classLinkType = "class"_L1; static inline QString fixLinkType(QStringView type) { // TODO: create a flag PROPERTY-AS-FUNCTION to ask if the properties // are recognized as such or not in the binding if (type == u"property") - return functionLinkType(); + return functionLinkType; if (type == u"typedef") - return classLinkType(); + return classLinkType; return type.toString(); } static inline QString linkSourceAttribute(const QString &type) { - if (type == functionLinkType() || type == classLinkType()) + if (type == functionLinkType || type == classLinkType) return u"raw"_s; return type == u"enum" || type == u"page" ? type : u"href"_s; @@ -891,7 +887,7 @@ void QtXmlToSphinx::handleSeeAlsoTag(QXmlStreamReader& reader) const QString text = textR.toString(); if (m_seeAlsoContext.isNull()) { const QString type = text.endsWith(u"()") - ? functionLinkType() : classLinkType(); + ? functionLinkType : classLinkType; m_seeAlsoContext.reset(handleLinkStart(type, text)); } handleLinkText(m_seeAlsoContext.data(), text); @@ -910,7 +906,7 @@ void QtXmlToSphinx::handleSeeAlsoTag(QXmlStreamReader& reader) } } -static inline QString fallbackPathAttribute() { return QStringLiteral("path"); } +constexpr auto fallbackPathAttribute = "path"_L1; template <class Indent> // const char*/class Indentor void formatSnippet(TextStream &str, Indent indent, const QString &snippet) @@ -950,8 +946,8 @@ void QtXmlToSphinx::handleSnippetTag(QXmlStreamReader& reader) QString location = reader.attributes().value(u"location"_s).toString(); QString identifier = reader.attributes().value(u"identifier"_s).toString(); QString fallbackPath; - if (reader.attributes().hasAttribute(fallbackPathAttribute())) - fallbackPath = reader.attributes().value(fallbackPathAttribute()).toString(); + if (reader.attributes().hasAttribute(fallbackPathAttribute)) + fallbackPath = reader.attributes().value(fallbackPathAttribute).toString(); QString errorMessage; const Snippet snippet = readSnippetFromLocations(location, identifier, @@ -1165,7 +1161,7 @@ QtXmlToSphinxLink *QtXmlToSphinx::handleLinkStart(const QString &type, QString r if (type == u"external" || isHttpLink(ref)) { result->type = QtXmlToSphinxLink::External; - } else if (type == functionLinkType() && !m_context.isEmpty()) { + } else if (type == functionLinkType && !m_context.isEmpty()) { result->type = QtXmlToSphinxLink::Method; const auto rawlinklist = QStringView{result->linkRef}.split(u'.'); if (rawlinklist.size() == 1 || rawlinklist.constFirst() == m_context) { @@ -1176,9 +1172,9 @@ QtXmlToSphinxLink *QtXmlToSphinx::handleLinkStart(const QString &type, QString r } else { result->linkRef = m_generator->expandFunction(result->linkRef); } - } else if (type == functionLinkType() && m_context.isEmpty()) { + } else if (type == functionLinkType && m_context.isEmpty()) { result->type = QtXmlToSphinxLink::Function; - } else if (type == classLinkType()) { + } else if (type == classLinkType) { result->type = QtXmlToSphinxLink::Class; result->linkRef = m_generator->expandClass(m_context, result->linkRef); } else if (type == u"enum") { @@ -1397,11 +1393,11 @@ void QtXmlToSphinx::handlePageTag(QXmlStreamReader &reader) m_output << disableIndent; - const auto title = reader.attributes().value(titleAttribute()); + const auto title = reader.attributes().value("title"); if (!title.isEmpty()) m_output << rstLabel(title.toString()); - const auto fullTitle = reader.attributes().value(fullTitleAttribute()); + const auto fullTitle = reader.attributes().value("fulltitle"); const int size = fullTitle.isEmpty() ? writeEscapedRstText(m_output, title) : writeEscapedRstText(m_output, fullTitle); @@ -1414,7 +1410,7 @@ void QtXmlToSphinx::handleTargetTag(QXmlStreamReader &reader) { if (reader.tokenType() != QXmlStreamReader::StartElement) return; - const auto name = reader.attributes().value(nameAttribute()); + const auto name = reader.attributes().value("name"); if (!name.isEmpty()) m_output << rstLabel(name.toString()); } diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 4d30c7ad2..aa1d587fd 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -130,7 +130,7 @@ const ProtocolEntries &mappingProtocols() u"PyObject*"_s}, {u"__msetitem__"_s, u"PyObject *self, PyObject *_key, PyObject *_value"_s, - intT()}}; + intT}}; return result; } @@ -147,16 +147,16 @@ const ProtocolEntries &sequenceProtocols() u"PyObject*"_s}, {u"__setitem__"_s, u"PyObject *self, Py_ssize_t _i, PyObject *_value"_s, - intT()}, + intT}, {u"__getslice__"_s, u"PyObject *self, Py_ssize_t _i1, Py_ssize_t _i2"_s, u"PyObject*"_s}, {u"__setslice__"_s, u"PyObject *self, Py_ssize_t _i1, Py_ssize_t _i2, PyObject *_value"_s, - intT()}, + intT}, {u"__contains__"_s, u"PyObject *self, PyObject *_value"_s, - intT()}, + intT}, {u"__concat__"_s, u"PyObject *self, PyObject *_other"_s, u"PyObject*"_s} @@ -1258,7 +1258,7 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s, if (!func->isVoid()) { - if (func->modifiedTypeName() != cPyObjectT()) { + if (func->modifiedTypeName() != cPyObjectT) { s << "// Check return type\n"; @@ -2874,7 +2874,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(TextStream &s, int sequenceArgCount = 0; while (od && !od->argType().isVarargs()) { const bool typeReplacedByPyObject = od->isTypeModified() - && od->modifiedArgType().name() == cPyObjectT(); + && od->modifiedArgType().name() == cPyObjectT; if (!typeReplacedByPyObject) { if (usePyArgs) pyArgName = pythonArgsAt(od->argPos()); @@ -3141,10 +3141,10 @@ void CppGenerator::writeCppToPythonFunction(TextStream &s, QString CppGenerator::containerNativeToTargetTypeName(const ContainerTypeEntryCPtr &type) { QString result = type->targetLangApiName(); - if (result != cPyObjectT()) { + if (result != cPyObjectT) { result = containerCpythonBaseName(type); - if (result == cPySequenceT()) - result = cPyListT(); + if (result == cPySequenceT) + result = cPyListT; } return result; } @@ -4041,7 +4041,7 @@ void CppGenerator::writePrimitiveConverterInitialization(TextStream &s, << converter << " = Shiboken::Conversions::createConverter("; if (!type->hasTargetLangApiType()) s << "nullptr"; - else if (type->targetLangApiName() == cPyObjectT()) + else if (type->targetLangApiName() == cPyObjectT) s << "&PyBaseObject_Type"; else s << '&' << type->targetLangApiName() << "_Type"; @@ -4108,7 +4108,7 @@ QString CppGenerator::writeContainerConverterInitialization(TextStream &s, const auto typeEntry = std::static_pointer_cast<const ContainerTypeEntry>(type.typeEntry()); const QString targetTypeName = containerNativeToTargetTypeName(typeEntry); - if (targetTypeName == cPyObjectT()) { + if (targetTypeName == cPyObjectT) { s << "&PyBaseObject_Type"; } else { s << '&' << targetTypeName << "_Type"; @@ -5721,7 +5721,7 @@ QString CppGenerator::qObjectGetAttroFunction() const { static QString result; if (result.isEmpty()) { - auto qobjectClass = AbstractMetaClass::findClass(api().classes(), qObjectT()); + auto qobjectClass = AbstractMetaClass::findClass(api().classes(), qObjectT); Q_ASSERT(qobjectClass); result = u"PySide::getHiddenDataFromQObject("_s + cpythonWrapperCPtr(qobjectClass, u"self"_s) diff --git a/sources/shiboken6/generator/shiboken/ctypenames.h b/sources/shiboken6/generator/shiboken/ctypenames.h index 0444c99f2..f665b30ff 100644 --- a/sources/shiboken6/generator/shiboken/ctypenames.h +++ b/sources/shiboken6/generator/shiboken/ctypenames.h @@ -6,26 +6,26 @@ #include <QtCore/QString> -static inline QString boolT() { return QStringLiteral("bool"); } -static inline QString intT() { return QStringLiteral("int"); } -static inline QString unsignedT() { return QStringLiteral("unsigned"); } -static inline QString unsignedIntT() { return QStringLiteral("unsigned int"); } -static inline QString longT() { return QStringLiteral("long"); } -static inline QString unsignedLongT() { return QStringLiteral("unsigned long"); } -static inline QString shortT() { return QStringLiteral("short"); } -static inline QString unsignedShortT() { return QStringLiteral("unsigned short"); } -static inline QString unsignedCharT() { return QStringLiteral("unsigned char"); } -static inline QString longLongT() { return QStringLiteral("long long"); } -static inline QString unsignedLongLongT() { return QStringLiteral("unsigned long long"); } -static inline QString charT() { return QStringLiteral("char"); } -static inline QString floatT() { return QStringLiteral("float"); } -static inline QString doubleT() { return QStringLiteral("double"); } -static inline QString constCharPtrT() { return QStringLiteral("const char*"); } +constexpr auto boolT = QLatin1StringView("bool"); +constexpr auto intT = QLatin1StringView("int"); +constexpr auto unsignedT = QLatin1StringView("unsigned"); +constexpr auto unsignedIntT = QLatin1StringView("unsigned int"); +constexpr auto longT = QLatin1StringView("long"); +constexpr auto unsignedLongT = QLatin1StringView("unsigned long"); +constexpr auto shortT = QLatin1StringView("short"); +constexpr auto unsignedShortT = QLatin1StringView("unsigned short"); +constexpr auto unsignedCharT = QLatin1StringView("unsigned char"); +constexpr auto longLongT = QLatin1StringView("long long"); +constexpr auto unsignedLongLongT = QLatin1StringView("unsigned long long"); +constexpr auto charT = QLatin1StringView("char"); +constexpr auto floatT = QLatin1StringView("float"); +constexpr auto doubleT = QLatin1StringView("double"); +constexpr auto constCharPtrT = QLatin1StringView("const char*"); -static inline QString qByteArrayT() { return QStringLiteral("QByteArray"); } -static inline QString qMetaObjectT() { return QStringLiteral("QMetaObject"); } -static inline QString qObjectT() { return QStringLiteral("QObject"); } -static inline QString qStringT() { return QStringLiteral("QString"); } -static inline QString qVariantT() { return QStringLiteral("QVariant"); } +constexpr auto qByteArrayT = QLatin1StringView("QByteArray"); +constexpr auto qMetaObjectT = QLatin1StringView("QMetaObject"); +constexpr auto qObjectT = QLatin1StringView("QObject"); +constexpr auto qStringT = QLatin1StringView("QString"); +constexpr auto qVariantT = QLatin1StringView("QVariant"); #endif // CTYPENAMES_H diff --git a/sources/shiboken6/generator/shiboken/overloaddata.cpp b/sources/shiboken6/generator/shiboken/overloaddata.cpp index c1e965fec..c28fcdc1a 100644 --- a/sources/shiboken6/generator/shiboken/overloaddata.cpp +++ b/sources/shiboken6/generator/shiboken/overloaddata.cpp @@ -135,10 +135,10 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) // Primitive types that are not int, long, short, // char and their respective unsigned counterparts. - static const QStringList nonIntegerPrimitives{floatT(), doubleT(), boolT()}; + static const QStringList nonIntegerPrimitives{floatT, doubleT, boolT}; // Signed integer primitive types. - static const QStringList signedIntegerPrimitives{intT(), shortT(), longT(), longLongT()}; + static const QStringList signedIntegerPrimitives{intT, shortT, longT, longLongT}; // sort the children overloads for (const auto &ov : std::as_const(m_children)) @@ -162,15 +162,15 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) it.value().append(ov); } - if (!checkPyObject && typeName == cPyObjectT()) + if (!checkPyObject && typeName == cPyObjectT) checkPyObject = true; - else if (!checkPySequence && typeName == cPySequenceT()) + else if (!checkPySequence && typeName == cPySequenceT) checkPySequence = true; - else if (!checkPyBuffer && typeName == cPyBufferT()) + else if (!checkPyBuffer && typeName == cPyBufferT) checkPyBuffer = true; - else if (!checkQVariant && typeName == qVariantT()) + else if (!checkQVariant && typeName == qVariantT) checkQVariant = true; - else if (!checkQString && typeName == qStringT()) + else if (!checkQString && typeName == qStringT) checkQString = true; for (const auto &instantiation : ov->argType().instantiations()) { @@ -196,9 +196,9 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) // Create the graph of type dependencies based on implicit conversions. // All C++ primitive types, add any forgotten type AT THE END OF THIS LIST! - static const QStringList primitiveTypes{intT(), unsignedIntT(), longT(), unsignedLongT(), - shortT(), unsignedShortT(), boolT(), unsignedCharT(), charT(), floatT(), - doubleT(), constCharPtrT()}; + static const QStringList primitiveTypes{intT, unsignedIntT, longT, unsignedLongT, + shortT, unsignedShortT, boolT, unsignedCharT, charT, floatT, + doubleT, constCharPtrT}; QStringList foundPrimitiveTypeIds; for (const auto &p : primitiveTypes) { @@ -207,7 +207,7 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) } if (checkPySequence && checkPyObject) - graph.addEdge(cPySequenceT(), cPyObjectT()); + graph.addEdge(cPySequenceT, cPyObjectT); QStringList classesWithIntegerImplicitConversion; @@ -226,7 +226,7 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) else convertibleType = getTypeName(function->arguments().constFirst().type()); - if (convertibleType == intT() || convertibleType == unsignedIntT()) + if (convertibleType == intT || convertibleType == unsignedIntT) classesWithIntegerImplicitConversion << targetTypeEntryName; if (!graph.hasNode(convertibleType)) @@ -288,28 +288,28 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) if ((checkPySequence || checkPyObject || checkPyBuffer) - && !targetTypeEntryName.contains(cPyObjectT()) - && !targetTypeEntryName.contains(cPyBufferT()) - && !targetTypeEntryName.contains(cPySequenceT())) { + && !targetTypeEntryName.contains(cPyObjectT) + && !targetTypeEntryName.contains(cPyBufferT) + && !targetTypeEntryName.contains(cPySequenceT)) { if (checkPySequence) { // PySequence will be checked after all more specific types, but before PyObject. - graph.addEdge(targetTypeEntryName, cPySequenceT()); + graph.addEdge(targetTypeEntryName, cPySequenceT); } else if (checkPyBuffer) { // PySequence will be checked after all more specific types, but before PyObject. - graph.addEdge(targetTypeEntryName, cPyBufferT()); + graph.addEdge(targetTypeEntryName, cPyBufferT); } else { // Add dependency on PyObject, so its check is the last one (too generic). - graph.addEdge(targetTypeEntryName, cPyObjectT()); + graph.addEdge(targetTypeEntryName, cPyObjectT); } - } else if (checkQVariant && targetTypeEntryName != qVariantT()) { - if (!graph.containsEdge(qVariantT(), targetTypeEntryName)) // Avoid cyclic dependency. - graph.addEdge(targetTypeEntryName, qVariantT()); + } else if (checkQVariant && targetTypeEntryName != qVariantT) { + if (!graph.containsEdge(qVariantT, targetTypeEntryName)) // Avoid cyclic dependency. + graph.addEdge(targetTypeEntryName, qVariantT); } else if (checkQString && ov->argType().isPointer() - && targetTypeEntryName != qStringT() - && targetTypeEntryName != qByteArrayT() - && (!checkPyObject || targetTypeEntryName != cPyObjectT())) { - if (!graph.containsEdge(qStringT(), targetTypeEntryName)) // Avoid cyclic dependency. - graph.addEdge(targetTypeEntryName, qStringT()); + && targetTypeEntryName != qStringT + && targetTypeEntryName != qByteArrayT + && (!checkPyObject || targetTypeEntryName != cPyObjectT)) { + if (!graph.containsEdge(qStringT, targetTypeEntryName)) // Avoid cyclic dependency. + graph.addEdge(targetTypeEntryName, qStringT); } if (targetType.isEnum()) { @@ -320,14 +320,14 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) } // QByteArray args need to be checked after QString args - if (graph.hasNode(qStringT()) && graph.hasNode(qByteArrayT())) - graph.addEdge(qStringT(), qByteArrayT()); + if (graph.hasNode(qStringT) && graph.hasNode(qByteArrayT)) + graph.addEdge(qStringT, qByteArrayT); static const Edge rangeOrder[] = - {{doubleT(), floatT()}, - {longLongT(), longT()}, {longLongT(), intT()}, {intT(), shortT()}, - {unsignedLongLongT(), unsignedLongT()}, {unsignedLongLongT(), unsignedT()}, - {unsignedLongLongT(), unsignedIntT()}, {unsignedT(), unsignedShortT()} + {{doubleT, floatT}, + {longLongT, longT}, {longLongT, intT}, {intT, shortT}, + {unsignedLongLongT, unsignedLongT}, {unsignedLongLongT, unsignedT}, + {unsignedLongLongT, unsignedIntT}, {unsignedT, unsignedShortT} }; for (const auto &r : rangeOrder) { if (graph.hasNode(r.first) && graph.hasNode(r.second)) diff --git a/sources/shiboken6/generator/shiboken/pytypenames.h b/sources/shiboken6/generator/shiboken/pytypenames.h index 696e0d88d..6c7658ff6 100644 --- a/sources/shiboken6/generator/shiboken/pytypenames.h +++ b/sources/shiboken6/generator/shiboken/pytypenames.h @@ -6,24 +6,24 @@ #include <QtCore/QString> -static inline QString pyBoolT() { return QStringLiteral("PyBool"); } -static inline QString pyFloatT() { return QStringLiteral("PyFloat"); } -static inline QString pyLongT() { return QStringLiteral("PyLong"); } -static inline QString pyObjectT() { return QStringLiteral("object"); } -static inline QString pyStrT() { return QStringLiteral("str"); } +constexpr auto pyBoolT = QLatin1StringView ("PyBool"); +constexpr auto pyFloatT = QLatin1StringView ("PyFloat"); +constexpr auto pyLongT = QLatin1StringView ("PyLong"); +constexpr auto pyObjectT = QLatin1StringView ("object"); +constexpr auto pyStrT = QLatin1StringView ("str"); // PYSIDE-1499: A custom type determined by existence of an `__fspath__` attribute. -static inline QString pyPathLikeT() { return QStringLiteral("PyPathLike"); } +constexpr auto pyPathLikeT = QLatin1StringView ("PyPathLike"); -static inline QString cPyBufferT() { return QStringLiteral("PyBuffer"); } -static inline QString cPyListT() { return QStringLiteral("PyList"); } -static inline QString cPyObjectT() { return QStringLiteral("PyObject"); } -static inline QString cPySequenceT() { return QStringLiteral("PySequence"); } -static inline QString cPyTypeObjectT() { return QStringLiteral("PyTypeObject"); } +constexpr auto cPyBufferT = QLatin1StringView ("PyBuffer"); +constexpr auto cPyListT = QLatin1StringView ("PyList"); +constexpr auto cPyObjectT = QLatin1StringView ("PyObject"); +constexpr auto cPySequenceT = QLatin1StringView ("PySequence"); +constexpr auto cPyTypeObjectT = QLatin1StringView ("PyTypeObject"); // numpy -static inline QString cPyArrayObjectT() { return QStringLiteral("PyArrayObject"); } +constexpr auto cPyArrayObjectT = QLatin1StringView ("PyArrayObject"); -static inline QString sbkCharT() { return QStringLiteral("SbkChar"); } +constexpr auto sbkCharT = QLatin1StringView ("SbkChar"); #endif // PYTYPENAMES_H diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index d4a9e0031..766fa863f 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -163,32 +163,32 @@ ShibokenGenerator::~ShibokenGenerator() = default; static const QHash<QString, QString> &primitiveTypesCorrespondences() { static const QHash<QString, QString> result = { - {u"bool"_s, pyBoolT()}, - {u"char"_s, sbkCharT()}, - {u"signed char"_s, sbkCharT()}, - {u"unsigned char"_s, sbkCharT()}, - {intT(), pyLongT()}, - {u"signed int"_s, pyLongT()}, - {u"uint"_s, pyLongT()}, - {u"unsigned int"_s, pyLongT()}, - {shortT(), pyLongT()}, - {u"ushort"_s, pyLongT()}, - {u"signed short"_s, pyLongT()}, - {u"signed short int"_s, pyLongT()}, - {unsignedShortT(), pyLongT()}, - {u"unsigned short int"_s, pyLongT()}, - {longT(), pyLongT()}, - {doubleT(), pyFloatT()}, - {floatT(), pyFloatT()}, - {u"unsigned long"_s, pyLongT()}, - {u"signed long"_s, pyLongT()}, - {u"ulong"_s, pyLongT()}, - {u"unsigned long int"_s, pyLongT()}, - {u"long long"_s, pyLongT()}, - {u"__int64"_s, pyLongT()}, - {u"unsigned long long"_s, pyLongT()}, - {u"unsigned __int64"_s, pyLongT()}, - {u"size_t"_s, pyLongT()} + {u"bool"_s, pyBoolT}, + {u"char"_s, sbkCharT}, + {u"signed char"_s, sbkCharT}, + {u"unsigned char"_s, sbkCharT}, + {intT, pyLongT}, + {u"signed int"_s, pyLongT}, + {u"uint"_s, pyLongT}, + {u"unsigned int"_s, pyLongT}, + {shortT, pyLongT}, + {u"ushort"_s, pyLongT}, + {u"signed short"_s, pyLongT}, + {u"signed short int"_s, pyLongT}, + {unsignedShortT, pyLongT}, + {u"unsigned short int"_s, pyLongT}, + {longT, pyLongT}, + {doubleT, pyFloatT}, + {floatT, pyFloatT}, + {u"unsigned long"_s, pyLongT}, + {u"signed long"_s, pyLongT}, + {u"ulong"_s, pyLongT}, + {u"unsigned long int"_s, pyLongT}, + {u"long long"_s, pyLongT}, + {u"__int64"_s, pyLongT}, + {u"unsigned long long"_s, pyLongT}, + {u"unsigned __int64"_s, pyLongT}, + {u"size_t"_s, pyLongT} }; return result; } @@ -198,18 +198,18 @@ const QHash<QString, QChar> &ShibokenGenerator::formatUnits() static const QHash<QString, QChar> result = { {u"char"_s, u'b'}, {u"unsigned char"_s, u'B'}, - {intT(), u'i'}, + {intT, u'i'}, {u"unsigned int"_s, u'I'}, - {shortT(), u'h'}, - {unsignedShortT(), u'H'}, - {longT(), u'l'}, - {unsignedLongLongT(), u'k'}, - {longLongT(), u'L'}, + {shortT, u'h'}, + {unsignedShortT, u'H'}, + {longT, u'l'}, + {unsignedLongLongT, u'k'}, + {longLongT, u'L'}, {u"__int64"_s, u'L'}, - {unsignedLongLongT(), u'K'}, + {unsignedLongLongT, u'K'}, {u"unsigned __int64"_s, u'K'}, - {doubleT(), u'd'}, - {floatT(), u'f'}, + {doubleT, u'd'}, + {floatT, u'f'}, }; return result; } @@ -639,7 +639,7 @@ QString ShibokenGenerator::containerCpythonBaseName(const ContainerTypeEntryCPtr default: Q_ASSERT(false); } - return cPySequenceT(); + return cPySequenceT; } QString ShibokenGenerator::cpythonBaseName(const TypeEntryCPtr &type) @@ -659,7 +659,7 @@ QString ShibokenGenerator::cpythonBaseName(const TypeEntryCPtr &type) const auto ctype = std::static_pointer_cast<const ContainerTypeEntry>(type); baseName = containerCpythonBaseName(ctype); } else { - baseName = cPyObjectT(); + baseName = cPyObjectT; } return baseName.replace(u"::"_s, u"_"_s); } @@ -741,8 +741,6 @@ QString ShibokenGenerator::cpythonTypeNameExt(const AbstractMetaType &type) + getTypeIndexVariableName(type) + u']'; } -static inline QString unknownOperator() { return QStringLiteral("__UNKNOWN_OPERATOR__"); } - QString ShibokenGenerator::fixedCppTypeName(const TargetToNativeConversion &toNative) { if (toNative.sourceType()) @@ -791,7 +789,7 @@ QString ShibokenGenerator::pythonOperatorFunctionName(const AbstractMetaFunction QString op = Generator::pythonOperatorFunctionName(func->originalName()); if (op.isEmpty()) { qCWarning(lcShiboken).noquote().nospace() << msgUnknownOperator(func.get()); - return unknownOperator(); + return "__UNKNOWN_OPERATOR__"_L1; } if (func->arguments().isEmpty()) { if (op == u"__sub__") @@ -808,8 +806,8 @@ QString ShibokenGenerator::pythonOperatorFunctionName(const AbstractMetaFunction bool ShibokenGenerator::isNumber(const QString &cpythonApiName) { - return cpythonApiName == pyFloatT() || cpythonApiName == pyLongT() - || cpythonApiName == pyBoolT(); + return cpythonApiName == pyFloatT || cpythonApiName == pyLongT + || cpythonApiName == pyBoolT; } static std::optional<TypeSystem::CPythonType> @@ -856,7 +854,7 @@ bool ShibokenGenerator::isPyInt(const TypeEntryCPtr &type) if (!cPythonTypeOpt.has_value()) { const auto &mapping = primitiveTypesCorrespondences(); const auto it = mapping.constFind(pte->name()); - return it != mapping.cend() && it.value() == pyLongT(); + return it != mapping.cend() && it.value() == pyLongT; } return cPythonTypeOpt.value() == TypeSystem::CPythonType::Integer; } @@ -1768,7 +1766,7 @@ void ShibokenGenerator::replaceConverterTypeSystemVariable(TypeSystemConverterVa case TypeSystemCheckFunction: conversion = cpythonCheckFunction(conversionType); if (conversionType.typeEntry()->isPrimitive() - && (conversionType.typeEntry()->name() == cPyObjectT() + && (conversionType.typeEntry()->name() == cPyObjectT || !conversion.endsWith(u' '))) { conversion += u'('; break; @@ -1844,7 +1842,7 @@ ShibokenGenerator::AttroCheck ShibokenGenerator::checkAttroFunctionNeeds( FunctionQueryOption::GetAttroFunction)) { result |= AttroCheckFlag::GetattroUser; } - if (usePySideExtensions() && metaClass->qualifiedCppName() == qObjectT()) + if (usePySideExtensions() && metaClass->qualifiedCppName() == qObjectT) result |= AttroCheckFlag::SetattroQObject; if (useOverrideCaching(metaClass)) result |= AttroCheckFlag::SetattroMethodOverride; diff --git a/sources/shiboken6/tests/dumpcodemodel/main.cpp b/sources/shiboken6/tests/dumpcodemodel/main.cpp index f69d67e46..eb876634c 100644 --- a/sources/shiboken6/tests/dumpcodemodel/main.cpp +++ b/sources/shiboken6/tests/dumpcodemodel/main.cpp @@ -48,14 +48,14 @@ static const char *primitiveTypes[] = { "float", "double" }; -static inline QString nameAttribute() { return QStringLiteral("name"); } +constexpr auto nameAttribute = "name"_L1; static void formatXmlClass(QXmlStreamWriter &writer, const ClassModelItem &klass); static void formatXmlEnum(QXmlStreamWriter &writer, const EnumModelItem &en) { writer.writeStartElement(u"enum-type"_s); - writer.writeAttribute(nameAttribute(), en->name()); + writer.writeAttribute(nameAttribute, en->name()); writer.writeEndElement(); } @@ -97,7 +97,7 @@ static void formatXmlClass(QXmlStreamWriter &writer, const ClassModelItem &klass formatXmlLocationComment(writer, klass); writer.writeStartElement(isValueType ? u"value-type"_s : u"object-type"_s); - writer.writeAttribute(nameAttribute(), klass->name()); + writer.writeAttribute(nameAttribute, klass->name()); formatXmlScopeMembers(writer, klass); writer.writeEndElement(); } @@ -118,7 +118,7 @@ static void startXmlNamespace(QXmlStreamWriter &writer, const NamespaceModelItem { formatXmlLocationComment(writer, nsp); writer.writeStartElement(u"namespace-type"_s); - writer.writeAttribute(nameAttribute(), nsp->name()); + writer.writeAttribute(nameAttribute, nsp->name()); } static void formatXmlNamespaceMembers(QXmlStreamWriter &writer, const NamespaceModelItem &nsp) @@ -170,7 +170,7 @@ static void formatXmlOutput(const FileModelItem &dom) QDateTime::currentDateTime().toString(Qt::ISODate)); for (auto p : primitiveTypes) { writer.writeStartElement(u"primitive-type"_s); - writer.writeAttribute(nameAttribute(), QLatin1StringView(p)); + writer.writeAttribute(nameAttribute, QLatin1StringView(p)); writer.writeEndElement(); } formatXmlNamespaceMembers(writer, dom); |