aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-09-12 08:05:50 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-09-19 09:35:08 +0200
commitf2cc10c24014a41c9b92ae1f1aed04445fcf608e (patch)
tree594595307dcddbd0387dd344c8a28afa66841f53
parent766f4de0d00c598ab647f88f50ae5423edd2690b (diff)
shiboken6: Move OptionsParser out of the generator
Move the interface out to a separate class in ApiExtractor so that it can be used for options handling of ApiExtractor and type database as well. Add a class OptionsParserList that aggregates option parser instances. Replace it by static functions creating OptionsParser instances. Pick-to: 6.6 Change-Id: Ic1b3a2020af6d18f682f7026a7e9c2c7ba704d6e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r--sources/shiboken6/ApiExtractor/optionsparser.cpp18
-rw-r--r--sources/shiboken6/ApiExtractor/optionsparser.h17
-rw-r--r--sources/shiboken6/generator/generator.cpp24
-rw-r--r--sources/shiboken6/generator/generator.h7
-rw-r--r--sources/shiboken6/generator/main.cpp17
-rw-r--r--sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp39
-rw-r--r--sources/shiboken6/generator/qtdoc/qtdocgenerator.h3
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp37
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.h3
9 files changed, 127 insertions, 38 deletions
diff --git a/sources/shiboken6/ApiExtractor/optionsparser.cpp b/sources/shiboken6/ApiExtractor/optionsparser.cpp
index 21f19612c..b41d13e7d 100644
--- a/sources/shiboken6/ApiExtractor/optionsparser.cpp
+++ b/sources/shiboken6/ApiExtractor/optionsparser.cpp
@@ -53,3 +53,21 @@ bool OptionsParser::handleOption(const QString &, const QString &, OptionSource)
{
return false;
}
+
+bool OptionsParserList::handleBoolOption(const QString &key, OptionSource source)
+{
+ for (const auto &p : std::as_const(m_parsers)) {
+ if (p->handleBoolOption(key, source))
+ return true;
+ }
+ return false;
+}
+
+bool OptionsParserList::handleOption(const QString &key, const QString &value, OptionSource source)
+{
+ for (const auto &p : std::as_const(m_parsers)) {
+ if (p->handleOption(key, value, source))
+ return true;
+ }
+ return false;
+}
diff --git a/sources/shiboken6/ApiExtractor/optionsparser.h b/sources/shiboken6/ApiExtractor/optionsparser.h
index a73edf12c..7ce33f5ba 100644
--- a/sources/shiboken6/ApiExtractor/optionsparser.h
+++ b/sources/shiboken6/ApiExtractor/optionsparser.h
@@ -7,6 +7,8 @@
#include <QtCore/QString>
#include <QtCore/QList>
+#include <memory>
+
QT_FORWARD_DECLARE_CLASS(QTextStream)
enum class OptionSource
@@ -44,4 +46,19 @@ protected:
OptionsParser() noexcept;
};
+class OptionsParserList : public OptionsParser
+{
+public:
+ using OptionsParserPtr = std::shared_ptr<OptionsParser>;
+
+ void append(const OptionsParserPtr &parser) { m_parsers.append(parser); }
+ void clear() { m_parsers.clear(); }
+
+ bool handleBoolOption(const QString &key, OptionSource source) override;
+ bool handleOption(const QString &key, const QString &value, OptionSource source) override;
+
+private:
+ QList<OptionsParserPtr> m_parsers;
+};
+
#endif // OPTIONSPARSER_H
diff --git a/sources/shiboken6/generator/generator.cpp b/sources/shiboken6/generator/generator.cpp
index ab8a86864..f5323cd94 100644
--- a/sources/shiboken6/generator/generator.cpp
+++ b/sources/shiboken6/generator/generator.cpp
@@ -10,6 +10,7 @@
#include "abstractmetafunction.h"
#include "abstractmetalang.h"
#include "messages.h"
+#include <optionsparser.h>
#include "reporthandler.h"
#include "fileout.h"
#include "arraytypeentry.h"
@@ -96,18 +97,33 @@ QList<OptionDescription> Generator::options()
};
}
-bool Generator::handleBoolOption(const QString & key, OptionSource source)
+class GeneratorOptionsParser : public OptionsParser
+{
+public:
+ explicit GeneratorOptionsParser(GeneratorOptions *o) : m_options(o) {}
+
+ bool handleBoolOption(const QString &key, OptionSource source) override;
+
+private:
+ GeneratorOptions *m_options;
+};
+
+bool GeneratorOptionsParser::handleBoolOption(const QString & key, OptionSource source)
{
if (source == OptionSource::CommandLineSingleDash)
return false;
- auto &options = GeneratorPrivate::m_options;
if (key == QLatin1StringView(ENABLE_PYSIDE_EXTENSIONS))
- return ( options.usePySideExtensions = true);
+ return ( m_options->usePySideExtensions = true);
if (key == QLatin1StringView(AVOID_PROTECTED_HACK))
- return ( options.avoidProtectedHack = true);
+ return ( m_options->avoidProtectedHack = true);
return false;
}
+std::shared_ptr<OptionsParser> Generator::createOptionsParser()
+{
+ return std::make_shared<GeneratorOptionsParser>(&GeneratorPrivate::m_options);
+}
+
QString Generator::fileNameForContextHelper(const GeneratorContext &context,
const QString &suffix,
FileNameFlags flags)
diff --git a/sources/shiboken6/generator/generator.h b/sources/shiboken6/generator/generator.h
index 859ca8886..52fc1d468 100644
--- a/sources/shiboken6/generator/generator.h
+++ b/sources/shiboken6/generator/generator.h
@@ -6,7 +6,6 @@
#include <abstractmetalang_typedefs.h>
#include <typedatabase_typedefs.h>
-#include <optionsparser.h>
#include <QtCore/QList>
#include <memory>
@@ -16,6 +15,8 @@
class ApiExtractorResult;
class GeneratorContext;
class DefaultValue;
+struct OptionDescription;
+class OptionsParser;
class TextStream;
QString getClassTargetFullName(const AbstractMetaClassCPtr &metaClass,
@@ -28,7 +29,7 @@ QString getFilteredCppSignatureString(QString signature);
* Base class for all generators. The default implementations does nothing,
* you must subclass this to create your own generators.
*/
-class Generator : public OptionsParser
+class Generator
{
public:
/// Optiosn used around the generator code
@@ -58,7 +59,7 @@ public:
bool setup(const ApiExtractorResult &api);
static QList<OptionDescription> options();
- bool handleBoolOption(const QString &key, OptionSource source) override;
+ static std::shared_ptr<OptionsParser> createOptionsParser();
/// Returns the top namespace made invisible
const AbstractMetaClassCList &invisibleTopNamespaces() const;
diff --git a/sources/shiboken6/generator/main.cpp b/sources/shiboken6/generator/main.cpp
index b4cc436e2..8510c471e 100644
--- a/sources/shiboken6/generator/main.cpp
+++ b/sources/shiboken6/generator/main.cpp
@@ -11,6 +11,7 @@
#include <apiextractorresult.h>
#include <fileout.h>
#include <messages.h>
+#include <optionsparser.h>
#include <reporthandler.h>
#include <typedatabase.h>
@@ -444,6 +445,9 @@ int shibokenMain(const QStringList &argV)
args.options.erase(ait);
}
+ OptionsParserList optionParser;
+ optionParser.append(Generator::createOptionsParser());
+
// Pre-defined generator sets.
if (generatorSet == u"qtdoc") {
generators = docGenerators();
@@ -451,8 +455,12 @@ int shibokenMain(const QStringList &argV)
errorPrint(u"Doc strings extractions was not enabled in this shiboken build."_s, argV);
return EXIT_FAILURE;
}
+#ifdef DOCSTRINGS_ENABLED
+ optionParser.append(QtDocGenerator::createOptionsParser());
+#endif
} else if (generatorSet.isEmpty() || generatorSet == u"shiboken") {
generators = shibokenGenerators();
+ optionParser.append(ShibokenGenerator::createOptionsParser());
} else {
errorPrint(u"Unknown generator set, try \"shiboken\" or \"qtdoc\"."_s, argV);
return EXIT_FAILURE;
@@ -654,17 +662,16 @@ int shibokenMain(const QStringList &argV)
bool found = false;
if (ait.value().metaType().id() == QMetaType::QString) {
const QString value = ait.value().toString();
- for (const GeneratorPtr &generator : std::as_const(generators)) {
- found |= value.isEmpty()
- ? generator->handleBoolOption(ait.key(), OptionSource::CommandLine)
- : generator->handleOption(ait.key(), value, OptionSource::CommandLine);
- }
+ found |= value.isEmpty()
+ ? optionParser.handleBoolOption(ait.key(), OptionSource::CommandLine)
+ : optionParser.handleOption(ait.key(), value, OptionSource::CommandLine);
}
if (found)
ait = args.options.erase(ait);
else
++ait;
}
+ optionParser.clear();
ait = args.options.find(languageLevelOption());
if (ait != args.options.end()) {
diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp
index 57dfb7017..49d8638bd 100644
--- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp
+++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp
@@ -1127,22 +1127,32 @@ QList<OptionDescription> QtDocGenerator::options()
};
}
-bool QtDocGenerator::handleOption(const QString &key, const QString &value, OptionSource source)
+class QtDocGeneratorOptionsParser : public OptionsParser
+{
+public:
+ explicit QtDocGeneratorOptionsParser(DocGeneratorOptions *o) : m_options(o) {}
+
+ bool handleOption(const QString &key, const QString &value, OptionSource source) override;
+
+private:
+ DocGeneratorOptions *m_options;
+};
+
+bool QtDocGeneratorOptionsParser::handleOption(const QString &key, const QString &value,
+ OptionSource source)
{
- if (Generator::handleOption(key, value, source))
- return true;
if (source == OptionSource::CommandLineSingleDash)
return false;
if (key == u"library-source-dir") {
- m_options.parameters.libSourceDir = value;
+ m_options->parameters.libSourceDir = value;
return true;
}
if (key == u"documentation-data-dir") {
- m_options.parameters.docDataDir = value;
+ m_options->parameters.docDataDir = value;
return true;
}
if (key == u"documentation-code-snippets-dir") {
- m_options.parameters.codeSnippetDirs = value.split(QLatin1Char(PATH_SEP));
+ m_options->parameters.codeSnippetDirs = value.split(QLatin1Char(PATH_SEP));
return true;
}
@@ -1150,34 +1160,39 @@ bool QtDocGenerator::handleOption(const QString &key, const QString &value, Opti
const auto pos = value.indexOf(u':');
if (pos == -1)
return false;
- m_options.parameters.codeSnippetRewriteOld= value.left(pos);
- m_options.parameters.codeSnippetRewriteNew = value.mid(pos + 1);
+ m_options->parameters.codeSnippetRewriteOld= value.left(pos);
+ m_options->parameters.codeSnippetRewriteNew = value.mid(pos + 1);
return true;
}
if (key == u"documentation-extra-sections-dir") {
- m_options.extraSectionDir = value;
+ m_options->extraSectionDir = value;
return true;
}
if (key == u"doc-parser") {
qCDebug(lcShibokenDoc).noquote().nospace() << "doc-parser: " << value;
if (value == u"doxygen")
- m_options.doxygen = true;
+ m_options->doxygen = true;
return true;
}
if (key == additionalDocumentationOption()) {
- m_options.additionalDocumentationList = value;
+ m_options->additionalDocumentationList = value;
return true;
}
if (key == u"inheritance-file") {
- m_options.inheritanceFile = value;
+ m_options->inheritanceFile = value;
return true;
}
return false;
}
+std::shared_ptr<OptionsParser> QtDocGenerator::createOptionsParser()
+{
+ return std::make_shared<QtDocGeneratorOptionsParser>(&m_options);
+}
+
bool QtDocGenerator::convertToRst(const QString &sourceFileName,
const QString &targetFileName,
const QString &context,
diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.h b/sources/shiboken6/generator/qtdoc/qtdocgenerator.h
index 957db740d..23d45f173 100644
--- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.h
+++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.h
@@ -9,6 +9,7 @@
#include "generator.h"
#include "documentation.h"
+#include <optionsparser.h>
#include "typesystem_enums.h"
#include "modifications_typedefs.h"
#include "qtxmltosphinxinterface.h"
@@ -34,7 +35,7 @@ public:
}
static QList<OptionDescription> options();
- bool handleOption(const QString &key, const QString &value, OptionSource source) override;
+ static std::shared_ptr<OptionsParser> createOptionsParser();
// QtXmlToSphinxDocGeneratorInterface
QString expandFunction(const QString &function) const override;
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index 7d6520a18..f9f52a257 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -20,6 +20,7 @@
#include <messages.h>
#include <modifications.h>
#include "overloaddata.h"
+#include <optionsparser.h>
#include "propertyspec.h"
#include "pytypenames.h"
#include <reporthandler.h>
@@ -2319,37 +2320,51 @@ QList<OptionDescription> ShibokenGenerator::options()
};
}
-bool ShibokenGenerator::handleBoolOption(const QString &key, OptionSource source)
+class ShibokenGeneratorOptionsParser : public OptionsParser
+{
+public:
+ explicit ShibokenGeneratorOptionsParser(ShibokenGeneratorOptions *o) : m_options(o) {}
+
+ bool handleBoolOption(const QString & key, OptionSource source) override;
+
+private:
+ ShibokenGeneratorOptions *m_options;
+};
+
+bool ShibokenGeneratorOptionsParser::handleBoolOption(const QString &key, OptionSource source)
{
- if (Generator::handleBoolOption(key, source))
- return true;
if (source == OptionSource::CommandLineSingleDash)
return false;
if (key == QLatin1StringView(PARENT_CTOR_HEURISTIC))
- return (m_options.useCtorHeuristic = true);
+ return (m_options->useCtorHeuristic = true);
if (key == QLatin1StringView(RETURN_VALUE_HEURISTIC))
- return (m_options.userReturnValueHeuristic = true);
+ return (m_options->userReturnValueHeuristic = true);
if (key == QLatin1StringView(DISABLE_VERBOSE_ERROR_MESSAGES))
- return (m_options.verboseErrorMessagesDisabled = true);
+ return (m_options->verboseErrorMessagesDisabled = true);
if (key == QLatin1StringView(USE_ISNULL_AS_NB_BOOL)
|| key == QLatin1StringView(USE_ISNULL_AS_NB_NONZERO)) {
- return (m_options.useIsNullAsNbBool = true);
+ return (m_options->useIsNullAsNbBool = true);
}
if (key == QLatin1StringView(LEAN_HEADERS))
- return (m_options.leanHeaders= true);
+ return (m_options->leanHeaders= true);
if (key == QLatin1StringView(USE_OPERATOR_BOOL_AS_NB_BOOL)
|| key == QLatin1StringView(USE_OPERATOR_BOOL_AS_NB_NONZERO)) {
- return (m_options.useOperatorBoolAsNbBool = true);
+ return (m_options->useOperatorBoolAsNbBool = true);
}
if (key == QLatin1StringView(NO_IMPLICIT_CONVERSIONS)) {
- m_options.generateImplicitConversions = false;
+ m_options->generateImplicitConversions = false;
return true;
}
if (key == QLatin1StringView(WRAPPER_DIAGNOSTICS))
- return (m_options.wrapperDiagnostics = true);
+ return (m_options->wrapperDiagnostics = true);
return false;
}
+std::shared_ptr<OptionsParser> ShibokenGenerator::createOptionsParser()
+{
+ return std::make_shared<ShibokenGeneratorOptionsParser>(&m_options);
+}
+
bool ShibokenGenerator::doSetup()
{
return true;
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h
index 2ab3e7f31..b8d8263ac 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.h
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h
@@ -88,6 +88,7 @@ public:
const char *name() const override { return "Shiboken"; }
static QList<OptionDescription> options();
+ static std::shared_ptr<OptionsParser> createOptionsParser();
static QString minimalConstructorExpression(const ApiExtractorResult &api,
const AbstractMetaType &type);
@@ -297,8 +298,6 @@ protected:
/// Includes for header (native wrapper class) or binding source
QList<IncludeGroup> classIncludes(const AbstractMetaClassCPtr &metaClass) const;
- bool handleBoolOption(const QString &key, OptionSource source) override;
-
/// Returns true if the user enabled the so called "parent constructor heuristic".
static bool useCtorHeuristic();
/// Returns true if the user enabled the so called "return value heuristic".