diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-18 12:53:19 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-20 17:19:19 +0100 |
commit | b4d85c037f1dcfb84298395447af2e5dc6ac28b5 (patch) | |
tree | 8964106df1a65da28ca6b208554141a291c02889 | |
parent | b60cdf97b41ab6db977c5acd96d491003a5a046d (diff) |
shiboken6: Refactor Generate::shouldGenerate()
Change it to take TypeEntry instead of a meta class with the goal of
getting rid of smart pointer meta classes.
Add a GeneratorContext::typeEntry() to return the class or
smart pointer meta type entry.
Move static helper Generator::shouldGenerateTypeEntry() to TypeEntry.
Task-number: PYSIDE-454
Change-Id: I7aa3f0252c292efaed7acff553f6c0da159c8db0
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
9 files changed, 29 insertions, 25 deletions
diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index da320088b..e0a6f6085 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -414,6 +414,11 @@ bool TypeEntry::generateCode() const return m_d->m_codeGeneration == GenerateCode; } +bool TypeEntry::shouldGenerate() const +{ + return generateCode() && NamespaceTypeEntry::isVisibleScope(this); +} + int TypeEntry::revision() const { return m_d->m_revision; diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h index db7c23d57..d0894dac1 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.h +++ b/sources/shiboken6/ApiExtractor/typesystem.h @@ -173,6 +173,9 @@ public: // on 'load-typesystem' tag bool generateCode() const; + /// Returns whether the C++ generators should generate this entry + bool shouldGenerate() const; + int revision() const; void setRevision(int r); // see typedatabase.cpp int sbkIndex() const; // see typedatabase.cpp diff --git a/sources/shiboken6/generator/generator.cpp b/sources/shiboken6/generator/generator.cpp index 0512e88b1..2c80ec93f 100644 --- a/sources/shiboken6/generator/generator.cpp +++ b/sources/shiboken6/generator/generator.cpp @@ -484,8 +484,9 @@ void Generator::setOutputDirectory(const QString &outDir) bool Generator::generateFileForContext(const GeneratorContext &context) { const AbstractMetaClass *cls = context.metaClass(); + auto *typeEntry = cls->typeEntry(); - if (!shouldGenerate(cls)) + if (!shouldGenerate(typeEntry)) return true; const QString fileName = fileNameForContext(context); @@ -538,7 +539,8 @@ bool Generator::generate() for (auto cls : m_d->api.classes()) { if (!generateFileForContext(contextForClass(cls))) return false; - if (shouldGenerate(cls) && cls->typeEntry()->isPrivate()) + auto *te = cls->typeEntry(); + if (shouldGenerate(te) && te->isPrivate()) m_d->m_hasPrivateClasses = true; } @@ -564,14 +566,9 @@ bool Generator::generate() return finishGeneration(); } -bool Generator::shouldGenerateTypeEntry(const TypeEntry *type) +bool Generator::shouldGenerate(const TypeEntry *typeEntry) const { - return type->generateCode() && NamespaceTypeEntry::isVisibleScope(type); -} - -bool Generator::shouldGenerate(const AbstractMetaClass *metaClass) const -{ - return shouldGenerateTypeEntry(metaClass->typeEntry()); + return typeEntry->shouldGenerate(); } const ApiExtractorResult &Generator::api() const diff --git a/sources/shiboken6/generator/generator.h b/sources/shiboken6/generator/generator.h index f2efcc859..db42b83c5 100644 --- a/sources/shiboken6/generator/generator.h +++ b/sources/shiboken6/generator/generator.h @@ -278,11 +278,8 @@ protected: /// Returns the file base name for a smart pointer. static QString getFileNameBaseForSmartPointer(const AbstractMetaType &smartPointerType); - /// Returns true if the generator should generate any code for the TypeEntry. - static bool shouldGenerateTypeEntry(const TypeEntry *) ; - /// Returns true if the generator should generate any code for the AbstractMetaClass. - virtual bool shouldGenerate(const AbstractMetaClass *) const; + virtual bool shouldGenerate(const TypeEntry *t) const; /// Returns the subdirectory used to write the binding code of an AbstractMetaClass. virtual QString subDirectoryForClass(const AbstractMetaClass *clazz) const; diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp index 094efc904..951561c85 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp @@ -121,10 +121,10 @@ QString QtDocGenerator::fileNameSuffix() return u".rst"_qs; } -bool QtDocGenerator::shouldGenerate(const AbstractMetaClass *cls) const +bool QtDocGenerator::shouldGenerate(const TypeEntry *te) const { - return Generator::shouldGenerate(cls) - && cls->typeEntry()->type() != TypeEntry::SmartPointerType; + return Generator::shouldGenerate(te) + && te->type() != TypeEntry::SmartPointerType; } QString QtDocGenerator::fileNameForContext(const GeneratorContext &context) const diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.h b/sources/shiboken6/generator/qtdoc/qtdocgenerator.h index e6b976442..09065af30 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.h +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.h @@ -69,7 +69,7 @@ public: QtXmlToSphinxLink resolveLink(const QtXmlToSphinxLink &) const override; protected: - bool shouldGenerate(const AbstractMetaClass *) const override; + bool shouldGenerate(const TypeEntry *) const override; static QString fileNameSuffix(); QString fileNameForContext(const GeneratorContext &context) const override; void generateClass(TextStream &ts, const GeneratorContext &classContext) override; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 9585dd19a..d4110ae6c 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -454,8 +454,9 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon s << '\n' << "// inner classes\n"; const AbstractMetaClassList &innerClasses = metaClass->innerClasses(); for (AbstractMetaClass *innerClass : innerClasses) { - GeneratorContext innerClassContext = contextForClass(innerClass); - if (shouldGenerate(innerClass) && !innerClass->typeEntry()->isSmartPointer()) { + auto *innerTypeEntry = innerClass->typeEntry(); + if (shouldGenerate(innerTypeEntry) && !innerTypeEntry->isSmartPointer()) { + GeneratorContext innerClassContext = contextForClass(innerClass); s << "#include \"" << HeaderGenerator::headerFileNameForContext(innerClassContext) << "\"\n"; } @@ -6283,10 +6284,11 @@ bool CppGenerator::finishGeneration() AbstractMetaClassCList classesWithStaticFields; for (auto cls : api().classes()){ - if (shouldGenerate(cls)) { + auto *te = cls->typeEntry(); + if (shouldGenerate(te)) { writeInitFunc(s_classInitDecl, s_classPythonDefines, getSimpleClassInitFunctionName(cls), - cls->typeEntry()->targetLangEnclosingEntry()); + te->targetLangEnclosingEntry()); if (cls->hasStaticFields()) { s_classInitDecl << "void " << getSimpleClassStaticFieldsInitFunctionName(cls) << "();\n"; diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp index e159f44f0..31d22fcba 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.cpp +++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp @@ -529,11 +529,11 @@ bool HeaderGenerator::finishGeneration() StringStream protEnumsSurrogates(TextStream::Language::Cpp); for (auto metaClass : classList) { - if (!shouldGenerate(metaClass)) + const TypeEntry *classType = metaClass->typeEntry(); + if (!shouldGenerate(classType)) continue; //Includes - const TypeEntry *classType = metaClass->typeEntry(); const bool isPrivate = classType->isPrivate(); auto &includeList = isPrivate ? privateIncludes : includes; includeList << classType->include(); diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index fac268bdc..dcc94587b 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -1186,7 +1186,7 @@ ShibokenGenerator::ExtendedConverterData ShibokenGenerator::getExtendedConverter ExtendedConverterData extConvs; for (auto metaClass : api().classes()) { // Use only the classes for the current module. - if (!shouldGenerate(metaClass)) + if (!shouldGenerate(metaClass->typeEntry())) continue; const auto &overloads = metaClass->operatorOverloads(OperatorQueryOption::ConversionOp); for (const auto &convOp : overloads) { @@ -1207,7 +1207,7 @@ QList<const CustomConversion *> ShibokenGenerator::getPrimitiveCustomConversions QList<const CustomConversion *> conversions; const PrimitiveTypeEntryList &primitiveTypeList = primitiveTypes(); for (const PrimitiveTypeEntry *type : primitiveTypeList) { - if (!shouldGenerateTypeEntry(type) || !type->isUserPrimitive() || !type->customConversion()) + if (!type->shouldGenerate() || !type->isUserPrimitive() || !type->customConversion()) continue; conversions << type->customConversion(); |