aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator/shiboken
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-11-14 10:50:57 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-11-17 18:14:28 +0100
commitcf4f1a7488ba3202b44081eade36debf1d665e8f (patch)
tree15c65874973b87de4e96ec08f80c3ab0a264ae8b /sources/shiboken6/generator/shiboken
parente9a406d871a74242555f4b75715fe36950e6788c (diff)
shiboken6: Make some TypeEntry query functions free functions
Some query functions like TypeEntry::typeSystemTypeEntry() search in the hierarchy, starting with "this". This cannot be ported to smart pointers, so the functions are changed to be free functions where the first element has to be passed in. Change-Id: I3122b648ad499a2236577f6a101e8637a2f87d55 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/shiboken6/generator/shiboken')
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp14
-rw-r--r--sources/shiboken6/generator/shiboken/overloaddata.cpp4
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp24
3 files changed, 21 insertions, 21 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index ce4f8a74c..fbe7f183e 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1295,7 +1295,7 @@ QPair<QString, QChar> CppGenerator::virtualMethodNativeArg(const AbstractMetaFun
auto *argTypeEntry = type.typeEntry();
// Check for primitive types convertible by Py_BuildValue()
if (argTypeEntry->isPrimitive() && !type.isCString()) {
- const auto *pte = argTypeEntry->asPrimitive()->basicReferencedTypeEntry();
+ const auto *pte = basicReferencedTypeEntry(argTypeEntry->asPrimitive());
auto it = formatUnits().constFind(pte->name());
if (it != formatUnits().constEnd())
return {arg.name(), it.value()};
@@ -2828,7 +2828,7 @@ void CppGenerator::writeTypeCheck(TextStream &s, const AbstractMetaType &argType
if (!argType.typeEntry()->isCustom()) {
typeCheck = u'(' + pythonToCppConverterForArgumentName(argumentName)
+ u" = "_s + typeCheck + u"))"_s;
- if (!isNumber && argType.typeEntry()->isCppPrimitive()) {
+ if (!isNumber && isCppPrimitive(argType.typeEntry())) {
typeCheck.prepend(cpythonCheckFunction(argType) + u'('
+ argumentName + u") && "_s);
}
@@ -5393,7 +5393,7 @@ static ComparisonOperatorList smartPointeeComparisons(const GeneratorContext &co
{
Q_ASSERT(context.forSmartPointer());
auto *te = context.preciseType().instantiations().constFirst().typeEntry();
- if (te->isExtendedCppPrimitive()) { // Primitive pointee types have all
+ if (isExtendedCppPrimitive(te)) { // Primitive pointee types have all
return {AbstractMetaFunction::OperatorEqual,
AbstractMetaFunction::OperatorNotEqual,
AbstractMetaFunction::OperatorLess,
@@ -6623,7 +6623,7 @@ bool CppGenerator::finishGeneration()
if (shouldGenerate(te)) {
writeInitFunc(s_classInitDecl, s_classPythonDefines,
getSimpleClassInitFunctionName(cls),
- te->targetLangEnclosingEntry());
+ targetLangEnclosingEntry(te));
if (cls->hasStaticFields()) {
s_classInitDecl << "void "
<< getSimpleClassStaticFieldsInitFunctionName(cls) << "();\n";
@@ -6638,7 +6638,7 @@ bool CppGenerator::finishGeneration()
auto *enclosingClass = context.metaClass()->enclosingClass();
auto *enclosingTypeEntry = enclosingClass != nullptr
? enclosingClass->typeEntry()
- : smp.type.typeEntry()->targetLangEnclosingEntry();
+ : targetLangEnclosingEntry(smp.type.typeEntry());
writeInitFunc(s_classInitDecl, s_classPythonDefines,
getInitFunctionName(context),
enclosingTypeEntry);
@@ -6946,11 +6946,11 @@ bool CppGenerator::finishGeneration()
s << "// Register primitive types converters.\n";
const PrimitiveTypeEntryCList &primitiveTypeList = primitiveTypes();
for (const PrimitiveTypeEntry *pte : primitiveTypeList) {
- if (!pte->generateCode() || !pte->isCppPrimitive())
+ if (!pte->generateCode() || !isCppPrimitive(pte))
continue;
if (!pte->referencesType())
continue;
- const TypeEntry *referencedType = pte->basicReferencedTypeEntry();
+ const auto *referencedType = basicReferencedTypeEntry(pte);
QString converter = converterObject(referencedType);
QStringList cppSignature = pte->qualifiedCppName().split(u"::"_s, Qt::SkipEmptyParts);
while (!cppSignature.isEmpty()) {
diff --git a/sources/shiboken6/generator/shiboken/overloaddata.cpp b/sources/shiboken6/generator/shiboken/overloaddata.cpp
index 6bcadd83a..e42e52990 100644
--- a/sources/shiboken6/generator/shiboken/overloaddata.cpp
+++ b/sources/shiboken6/generator/shiboken/overloaddata.cpp
@@ -33,14 +33,14 @@ static QString getTypeName(const AbstractMetaType &type)
{
const TypeEntry *typeEntry = type.typeEntry();
if (typeEntry->isPrimitive())
- typeEntry = typeEntry->asPrimitive()->basicReferencedTypeEntry();
+ typeEntry = basicReferencedTypeEntry(typeEntry->asPrimitive());
QString typeName = typeEntry->name();
if (typeEntry->isContainer()) {
QStringList types;
for (const auto &cType : type.instantiations()) {
const TypeEntry *typeEntry = cType.typeEntry();
if (typeEntry->isPrimitive())
- typeEntry = typeEntry->asPrimitive()->basicReferencedTypeEntry();
+ typeEntry = basicReferencedTypeEntry(typeEntry->asPrimitive());
types << typeEntry->name();
}
typeName += u'<' + types.join(u',') + u" >"_s;
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index e549ef982..a39fe1f5e 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -538,7 +538,7 @@ QString ShibokenGenerator::cpythonBaseName(const TypeEntry *type)
if (type->isWrapperType() || type->isNamespace()) { // && type->referenceType() == NoReference) {
baseName = u"Sbk_"_s + type->name();
} else if (type->isPrimitive()) {
- const auto *ptype = type->asPrimitive()->basicReferencedTypeEntry();
+ const auto *ptype = basicReferencedTypeEntry(type->asPrimitive());
baseName = ptype->hasTargetLangApiType()
? ptype->targetLangApiName() : pythonPrimitiveTypeName(ptype->name());
} else if (type->isEnum()) {
@@ -611,7 +611,7 @@ QString ShibokenGenerator::converterObject(const AbstractMetaType &type)
QString ShibokenGenerator::converterObject(const TypeEntry *type)
{
- if (type->isExtendedCppPrimitive())
+ if (isExtendedCppPrimitive(type))
return QString::fromLatin1("Shiboken::Conversions::PrimitiveTypeConverter<%1>()")
.arg(type->qualifiedCppName());
if (type->isWrapperType())
@@ -635,8 +635,8 @@ QString ShibokenGenerator::converterObject(const TypeEntry *type)
qDebug() << "Warning: the Qt5 primitive type is unknown" << type->qualifiedCppName();
return QString();
}
- pte = pte->basicReferencedTypeEntry();
- if (pte->isPrimitive() && !pte->isCppPrimitive() && !pte->customConversion()) {
+ pte = basicReferencedTypeEntry(pte);
+ if (pte->isPrimitive() && !isCppPrimitive(pte) && !pte->customConversion()) {
return u"Shiboken::Conversions::PrimitiveTypeConverter<"_s
+ pte->qualifiedCppName() + u">()"_s;
}
@@ -737,7 +737,7 @@ bool ShibokenGenerator::isNumber(const TypeEntry *type)
{
if (!type->isPrimitive())
return false;
- const auto *pte = type->asPrimitive()->basicReferencedTypeEntry();
+ const auto *pte = basicReferencedTypeEntry(type->asPrimitive());
const auto cPythonTypeOpt = targetLangApiCPythonType(pte);
// FIXME PYSIDE-1660: Return false here after making primitive types built-in?
if (!cPythonTypeOpt.has_value()) {
@@ -760,7 +760,7 @@ bool ShibokenGenerator::isPyInt(const TypeEntry *type)
{
if (!type->isPrimitive())
return false;
- const auto *pte = type->asPrimitive()->basicReferencedTypeEntry();
+ const auto *pte = basicReferencedTypeEntry(type->asPrimitive());
const auto cPythonTypeOpt = targetLangApiCPythonType(pte);
// FIXME PYSIDE-1660: Return false here after making primitive types built-in?
if (!cPythonTypeOpt.has_value()) {
@@ -864,14 +864,14 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type)
return u"SbkObject_TypeCheck("_s + cpythonTypeNameExt(type) + u", "_s;
if (type->isPrimitive())
- type = type->asPrimitive()->basicReferencedTypeEntry();
+ type = basicReferencedTypeEntry(type->asPrimitive());
if (auto *tla = type->targetLangApiType()) {
if (tla->hasCheckFunction())
return tla->checkFunction();
}
- if (type->isExtendedCppPrimitive()) {
+ if (isExtendedCppPrimitive(type)) {
const auto *pte = type->asPrimitive();
return pythonPrimitiveTypeName(pte->name()) + u"_Check"_s;
}
@@ -1178,7 +1178,7 @@ QList<CustomConversionPtr> ShibokenGenerator::getPrimitiveCustomConversions()
QList<CustomConversionPtr> conversions;
const auto &primitiveTypeList = primitiveTypes();
for (const PrimitiveTypeEntry *type : primitiveTypeList) {
- if (type->shouldGenerate() && type->isUserPrimitive() && type->hasCustomConversion())
+ if (type->shouldGenerate() && isUserPrimitive(type) && type->hasCustomConversion())
conversions << type->customConversion();
}
return conversions;
@@ -2216,8 +2216,8 @@ QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaClass *met
}
QString ShibokenGenerator::getTypeIndexVariableName(const TypeEntry *type)
{
- if (type->isCppPrimitive())
- type = type->asPrimitive()->basicReferencedTypeEntry();
+ if (isCppPrimitive(type))
+ type = basicReferencedTypeEntry(type->asPrimitive());
QString result = u"SBK_"_s;
// Disambiguate namespaces per module to allow for extending them.
if (type->isNamespace()) {
@@ -2273,7 +2273,7 @@ QString ShibokenGenerator::minimalConstructorExpression(const ApiExtractorResult
QString ShibokenGenerator::minimalConstructorExpression(const ApiExtractorResult &api,
const TypeEntry *type)
{
- if (type->isExtendedCppPrimitive())
+ if (isExtendedCppPrimitive(type))
return {};
const auto ctor = minimalConstructor(api, type);
if (ctor.has_value())