aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp28
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator_container.cpp34
-rw-r--r--sources/shiboken6/generator/shiboken/generatorstrings.h33
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp25
4 files changed, 51 insertions, 69 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 95367b21d..6e26e565a 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -2103,7 +2103,7 @@ void CppGenerator::writeMethodWrapper(TextStream &s, const OverloadData &overloa
}
s << ")\n{\n" << indent;
if (rfunc->ownerClass() == nullptr || overloadData.hasStaticFunction())
- s << sbkUnusedVariableCast("self");
+ s << sbkUnusedVariableCast(PYTHON_SELF_VAR);
if (hasKwdArgs)
s << sbkUnusedVariableCast("kwds");
@@ -2259,10 +2259,9 @@ void CppGenerator::writeCppSelfConversion(TextStream &s, const GeneratorContext
return;
}
- static const QString pythonSelfVar = u"self"_s;
if (useWrapperClass)
s << "static_cast<" << className << " *>(";
- s << cpythonWrapperCPtr(context.metaClass(), pythonSelfVar);
+ s << cpythonWrapperCPtr(context.metaClass(), PYTHON_SELF_VAR);
if (useWrapperClass)
s << ')';
}
@@ -2298,7 +2297,7 @@ void CppGenerator::writeCppSelfDefinition(TextStream &s,
? context.wrapperName()
: (u"::"_s + metaClass->qualifiedCppName());
- writeInvalidPyObjectCheck(s, u"self"_s, errorReturn);
+ writeInvalidPyObjectCheck(s, PYTHON_SELF_VAR, errorReturn);
if (flags.testFlag(CppSelfAsReference)) {
writeCppSelfVarDef(s, flags);
@@ -3034,10 +3033,9 @@ void CppGenerator::writeSingleFunctionCall(TextStream &s,
continue;
auto argType = getArgumentType(func, argIdx);
int argPos = argIdx - removedArgs;
- QString argName = CPP_ARG(argPos);
QString pyArgName = usePyArgs ? pythonArgsAt(argPos) : PYTHON_ARG;
indirections[argIdx] =
- writeArgumentConversion(s, argType, argName, pyArgName, errorReturn,
+ writeArgumentConversion(s, argType, CPP_ARG_N(argPos), pyArgName, errorReturn,
func->implementingClass(), arg.defaultValueExpression(),
func->isUserAdded());
}
@@ -3459,7 +3457,7 @@ QString CppGenerator::argumentNameFromIndex(const ApiExtractorResult &api,
{
switch (argIndex) {
case -1:
- return u"self"_s;
+ return PYTHON_SELF_VAR;
case 0:
return PYTHON_RETURN_VAR;
case 1: { // Single argument?
@@ -3609,7 +3607,7 @@ void CppGenerator::writeMethodCall(TextStream &s, const AbstractMetaFunctionCPtr
const int idx = arg.argumentIndex() - removedArgs;
const auto deRef = argumentIndirections.at(i);
QString argName = AbstractMetaType::dereferencePrefix(deRef)
- + CPP_ARG(idx);
+ + CPP_ARG_N(idx);
userArgs.append(argName);
}
}
@@ -5019,7 +5017,7 @@ void CppGenerator::writeSignatureInfo(TextStream &s, const OverloadData &overloa
// PYSIDE-1328: `self`-ness cannot be computed in Python because there are mixed cases.
// Toplevel functions like `PySide6.QtCore.QEnum` are always self-less.
if (!(f->isStatic()) && f->ownerClass())
- args << u"self"_s;
+ args << PYTHON_SELF_VAR;
const auto &arguments = f->arguments();
for (qsizetype i = 0, size = arguments.size(); i < size; ++i) {
const auto n = i + 1;
@@ -5683,7 +5681,7 @@ void CppGenerator::writeSetattroFunction(TextStream &s, AttroCheck attroCheck,
if (attroCheck.testFlag(AttroCheckFlag::SetattroMethodOverride)
&& context.useWrapper()) {
s << "if (value != nullptr && PyCallable_Check(value) != 0) {\n" << indent
- << "auto plain_inst = " << cpythonWrapperCPtr(metaClass, u"self"_s) << ";\n"
+ << "auto plain_inst = " << cpythonWrapperCPtr(metaClass, PYTHON_SELF_VAR) << ";\n"
<< "auto *inst = dynamic_cast<" << context.wrapperName() << " *>(plain_inst);\n"
<< "if (inst != nullptr)\n" << indent
<< "inst->resetPyMethodCache();\n" << outdent << outdent
@@ -5702,7 +5700,7 @@ void CppGenerator::writeSetattroFunction(TextStream &s, AttroCheck attroCheck,
Q_ASSERT(func);
s << "{\n" << indent
<< "auto " << CPP_SELF_VAR << " = "
- << cpythonWrapperCPtr(metaClass, u"self"_s) << ";\n";
+ << cpythonWrapperCPtr(metaClass, PYTHON_SELF_VAR) << ";\n";
writeClassCodeSnips(s, func->injectedCodeSnips(), TypeSystem::CodeSnipPositionAny,
TypeSystem::TargetLangCode, context);
s << outdent << "}\n";
@@ -5724,7 +5722,7 @@ QString CppGenerator::qObjectGetAttroFunction() const
auto qobjectClass = AbstractMetaClass::findClass(api().classes(), qObjectT);
Q_ASSERT(qobjectClass);
result = u"PySide::getHiddenDataFromQObject("_s
- + cpythonWrapperCPtr(qobjectClass, u"self"_s)
+ + cpythonWrapperCPtr(qobjectClass, PYTHON_SELF_VAR)
+ u", self, name)"_s;
}
return result;
@@ -5784,7 +5782,7 @@ void CppGenerator::writeGetattroFunction(TextStream &s, AttroCheck attroCheck,
Q_ASSERT(func);
s << "{\n" << indent
<< "auto " << CPP_SELF_VAR << " = "
- << cpythonWrapperCPtr(metaClass, u"self"_s) << ";\n";
+ << cpythonWrapperCPtr(metaClass, PYTHON_SELF_VAR) << ";\n";
writeClassCodeSnips(s, func->injectedCodeSnips(), TypeSystem::CodeSnipPositionAny,
TypeSystem::TargetLangCode, context);
s << outdent << "}\n";
@@ -6351,7 +6349,7 @@ bool CppGenerator::writeParentChildManagement(TextStream &s, const AbstractMetaF
if (parentIndex == 0) {
parentVariable = PYTHON_RETURN_VAR;
} else if (parentIndex == -1) {
- parentVariable = u"self"_s;
+ parentVariable = PYTHON_SELF_VAR;
} else {
parentVariable = usePyArgs
? pythonArgsAt(parentIndex - 1) : PYTHON_ARG;
@@ -6361,7 +6359,7 @@ bool CppGenerator::writeParentChildManagement(TextStream &s, const AbstractMetaF
if (childIndex == 0) {
childVariable = PYTHON_RETURN_VAR;
} else if (childIndex == -1) {
- childVariable = u"self"_s;
+ childVariable = PYTHON_SELF_VAR;
} else {
childVariable = usePyArgs
? pythonArgsAt(childIndex - 1) : PYTHON_ARG;
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
index f746ea714..00e0cabea 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp
@@ -101,20 +101,17 @@ void CppGenerator::writeOpaqueContainerValueConverter(TextStream &s,
const AbstractMetaType &valueType) const
{
// Generate template specialization of value converter helper unless it is already there
- const QString pyArg = u"pyArg"_s;
- const QString cppArg = u"cppArg"_s;
-
const QString valueTypeName = valueType.cppSignature();
const QString checkFunction = cpythonCheckFunction(valueType);
s << "template <>\nstruct ShibokenContainerValueConverter<"
<< valueTypeName << ">\n{\n";
// Type check
- s << indent << "static bool checkValue(PyObject *" << pyArg << ")\n{\n"
+ s << indent << "static bool checkValue(PyObject *" << PYTHON_ARG << ")\n{\n"
<< indent << "return " << checkFunction;
if (!checkFunction.contains(u'('))
s << '(';
- s << pyArg << ");\n"
+ s << PYTHON_ARG << ");\n"
<< outdent << "}\n\n";
// C++ to Python
@@ -126,21 +123,21 @@ void CppGenerator::writeOpaqueContainerValueConverter(TextStream &s,
s << valueTypeName << ' ';
if (passByConstRef)
s << '&';
- s << cppArg << ")\n{\n" << indent << "return ";
- writeToPythonConversion(s, valueType, nullptr, cppArg);
+ s << CPP_ARG << ")\n{\n" << indent << "return ";
+ writeToPythonConversion(s, valueType, nullptr, CPP_ARG);
s << ";\n" << outdent << "}\n\n";
// Python to C++
s << "static std::optional<" << valueTypeName << "> convertValueToCpp(PyObject *"
- << pyArg << ")\n{\n" << indent;
+ << PYTHON_ARG << ")\n{\n" << indent;
s << PYTHON_TO_CPPCONVERSION_STRUCT << ' ' << PYTHON_TO_CPP_VAR << ";\n"
<< "if (!(";
- writeTypeCheck(s, valueType, pyArg), isNumber(valueType.typeEntry());
+ writeTypeCheck(s, valueType, PYTHON_ARG), isNumber(valueType.typeEntry());
s << ")) {\n" << indent
<< "Shiboken::Errors::setWrongContainerType();\n"
<< "return {};\n" << outdent << "}\n";
- writePythonToCppTypeConversion(s, valueType, pyArg, cppArg, nullptr, {});
- s << "return " << cppArg << ";\n" << outdent << "}\n" << outdent << "};\n\n";
+ writePythonToCppTypeConversion(s, valueType, PYTHON_ARG, CPP_ARG, nullptr, {});
+ s << "return " << CPP_ARG << ";\n" << outdent << "}\n" << outdent << "};\n\n";
}
// Generate code for a type wrapping a C++ container instantiation
@@ -245,26 +242,25 @@ CppGenerator::OpaqueContainerData
// Check function
result.checkFunctionName = result.name + u"_Check"_s;
- const QString pyArg = u"pyArg"_s;
- s << "extern \"C\" int " << result.checkFunctionName << "(PyObject *" << pyArg
- << ")\n{\n" << indent << "return " << pyArg << " != nullptr && "
- << pyArg << " != Py_None && " << pyArg << "->ob_type == "
+ s << "extern \"C\" int " << result.checkFunctionName << "(PyObject *" << PYTHON_ARG
+ << ")\n{\n" << indent << "return " << PYTHON_ARG << " != nullptr && "
+ << PYTHON_ARG << " != Py_None && " << PYTHON_ARG << "->ob_type == "
<< typeFName << "();\n" << outdent << "}\n\n";
// SBK converter Python to C++
result.pythonToConverterFunctionName = u"PythonToCpp"_s + result.name;
s << "extern \"C\" void " << result.pythonToConverterFunctionName
- << "(PyObject *" << pyArg << ", void *cppOut)\n{\n" << indent
+ << "(PyObject *" << PYTHON_ARG << ", void *cppOut)\n{\n" << indent
<< "auto *d = ShibokenSequenceContainerPrivate<" << cppSignature
- << ">::get(" << pyArg << ");\n"
+ << ">::get(" << PYTHON_ARG << ");\n"
<< "*reinterpret_cast<" << cppSignature << "**>(cppOut) = d->m_list;\n"
<< outdent << "}\n\n";
// SBK check function for converting Python to C++ that returns the converter
result.converterCheckFunctionName = u"is"_s + result.name + u"PythonToCppConvertible"_s;
s << "extern \"C\" PythonToCppFunc " << result.converterCheckFunctionName
- << "(PyObject *" << pyArg << ")\n{\n" << indent << "if ("
- << result.checkFunctionName << '(' << pyArg << "))\n" << indent
+ << "(PyObject *" << PYTHON_ARG << ")\n{\n" << indent << "if ("
+ << result.checkFunctionName << '(' << PYTHON_ARG << "))\n" << indent
<< "return " << result.pythonToConverterFunctionName << ";\n"
<< outdent << "return {};\n" << outdent << "}\n\n";
diff --git a/sources/shiboken6/generator/shiboken/generatorstrings.h b/sources/shiboken6/generator/shiboken/generatorstrings.h
index 6751d5216..9ce91e599 100644
--- a/sources/shiboken6/generator/shiboken/generatorstrings.h
+++ b/sources/shiboken6/generator/shiboken/generatorstrings.h
@@ -6,25 +6,30 @@
#include <QtCore/QString>
-QString CPP_ARG(int i);
+QString CPP_ARG_N(int i);
QString CPP_ARG_REMOVED(int i);
-extern const QString CPP_RETURN_VAR;
-extern const QString CPP_SELF_VAR;
-extern const QString NULL_PTR;
-extern const QString PYTHON_ARG;
-extern const QString PYTHON_ARGS;
-extern const QString PYTHON_OVERRIDE_VAR;
-extern const QString PYTHON_RETURN_VAR;
-extern const QString PYTHON_TO_CPP_VAR;
+constexpr auto CPP_RETURN_VAR = QLatin1StringView("cppResult");
+constexpr auto CPP_SELF_VAR = QLatin1StringView("cppSelf");
+constexpr auto CPP_ARG = QLatin1StringView("cppArg");
+constexpr auto NULL_PTR = QLatin1StringView("nullptr");
+constexpr auto PYTHON_ARG = QLatin1StringView("pyArg");
+constexpr auto PYTHON_ARGS = QLatin1StringView("pyArgs");
+constexpr auto PYTHON_OVERRIDE_VAR = QLatin1StringView("pyOverride");
+constexpr auto PYTHON_RETURN_VAR = QLatin1StringView("pyResult");
+constexpr auto PYTHON_SELF_VAR = QLatin1StringView("self");
+constexpr auto PYTHON_TO_CPP_VAR = QLatin1StringView("pythonToCpp");
-extern const QString CONV_RULE_OUT_VAR_SUFFIX;
-extern const QString BEGIN_ALLOW_THREADS;
-extern const QString END_ALLOW_THREADS;
+constexpr auto CONV_RULE_OUT_VAR_SUFFIX = QLatin1StringView("_out");
+constexpr auto BEGIN_ALLOW_THREADS
+ = QLatin1StringView("PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS");
+constexpr auto END_ALLOW_THREADS
+ = QLatin1StringView("PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS");
-extern const QString REPR_FUNCTION;
+constexpr auto REPR_FUNCTION = QLatin1StringView("__repr__");
+
+constexpr auto CPP_ARG0 = QLatin1StringView("cppArg0");
-extern const QString CPP_ARG0;
extern const char *const METHOD_DEF_SENTINEL;
extern const char *const PYTHON_TO_CPPCONVERSION_STRUCT;
extern const char *const openTargetExternC;
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index 81d5c1f55..18632a13b 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -64,35 +64,18 @@ static const char WRAPPER_DIAGNOSTICS[] = "wrapper-diagnostics";
static const char NO_IMPLICIT_CONVERSIONS[] = "no-implicit-conversions";
static const char LEAN_HEADERS[] = "lean-headers";
-QString CPP_ARG(int i)
+QString CPP_ARG_N(int i)
{
- return u"cppArg"_s + QString::number(i);
+ return CPP_ARG + QString::number(i);
}
-static const QString CPP_ARG_REMOVED_PREFIX = u"removed_cppArg"_s;
+constexpr auto CPP_ARG_REMOVED_PREFIX = "removed_cppArg"_L1;
QString CPP_ARG_REMOVED(int i)
{
return CPP_ARG_REMOVED_PREFIX + QString::number(i);
}
-const QString CPP_RETURN_VAR = u"cppResult"_s;
-const QString CPP_SELF_VAR = u"cppSelf"_s;
-const QString NULL_PTR = u"nullptr"_s;
-const QString PYTHON_ARG = u"pyArg"_s;
-const QString PYTHON_ARGS = u"pyArgs"_s;
-const QString PYTHON_OVERRIDE_VAR = u"pyOverride"_s;
-const QString PYTHON_RETURN_VAR = u"pyResult"_s;
-const QString PYTHON_TO_CPP_VAR = u"pythonToCpp"_s;
-
-const QString CONV_RULE_OUT_VAR_SUFFIX = u"_out"_s;
-const QString BEGIN_ALLOW_THREADS =
- u"PyThreadState *_save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS"_s;
-const QString END_ALLOW_THREADS = u"PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS"_s;
-
-const QString REPR_FUNCTION = u"__repr__"_s;
-
-const QString CPP_ARG0 = u"cppArg0"_s;
const char *const METHOD_DEF_SENTINEL = "{nullptr, nullptr, 0, nullptr} // Sentinel\n";
const char *const PYTHON_TO_CPPCONVERSION_STRUCT = "Shiboken::Conversions::PythonToCppConversion";
@@ -1372,7 +1355,7 @@ ShibokenGenerator::ArgumentVarReplacementList
} else {
argValue = hasConversionRule
? arg.name() + CONV_RULE_OUT_VAR_SUFFIX
- : CPP_ARG(argPos);
+ : CPP_ARG_N(argPos);
const auto generatorArg = GeneratorArgument::fromMetaType(type);
AbstractMetaType::applyDereference(&argValue, generatorArg.indirections);
}