aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-09-14 10:44:35 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-09-20 14:55:46 +0200
commit95314e809969bf38714a7b63651ce877621618d8 (patch)
tree77e960cf40ff6db1c5a98f58ff8c01bdef6e5763 /sources/shiboken6/ApiExtractor
parented069c99be37364bf28ff3834d9e635389ea7af6 (diff)
shiboken6: Move options parsing into API extractor
Similar to the previous change for the TypeDatabase, add an OptionsParser for ApiExtractor and let it handle the its options directly instead of passing them from main. via ApiExtractor. Many ApiExtractor setters can then be removed. Pick-to: 6.6 Change-Id: I3fe37e2903edcc4f6e4a91181917d008df1e5ca8 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor')
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractor.cpp221
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractor.h12
-rw-r--r--sources/shiboken6/ApiExtractor/messages.cpp5
-rw-r--r--sources/shiboken6/ApiExtractor/messages.h2
4 files changed, 188 insertions, 52 deletions
diff --git a/sources/shiboken6/ApiExtractor/apiextractor.cpp b/sources/shiboken6/ApiExtractor/apiextractor.cpp
index c754d01e0..7b8ddf340 100644
--- a/sources/shiboken6/ApiExtractor/apiextractor.cpp
+++ b/sources/shiboken6/ApiExtractor/apiextractor.cpp
@@ -13,6 +13,7 @@
#include "exception.h"
#include "messages.h"
#include "modifications.h"
+#include "optionsparser.h"
#include "reporthandler.h"
#include "typedatabase.h"
#include "customconversion.h"
@@ -42,7 +43,181 @@ struct InstantiationCollectContext
QStringList instantiatedContainersNames;
};
-struct ApiExtractorPrivate
+struct ApiExtractorOptions
+{
+ QString m_typeSystemFileName;
+ QFileInfoList m_cppFileNames;
+ HeaderPaths m_includePaths;
+ QStringList m_clangOptions;
+ QString m_logDirectory;
+ LanguageLevel m_languageLevel = LanguageLevel::Default;
+ bool m_skipDeprecated = false;
+};
+
+static inline QString languageLevelDescription()
+{
+ return u"C++ Language level (c++11..c++17, default="_s
+ + QLatin1StringView(clang::languageLevelOption(clang::emulatedCompilerLanguageLevel()))
+ + u')';
+}
+
+QList<OptionDescription> ApiExtractor::options()
+{
+ return {
+ {u"use-global-header"_s,
+ u"Use the global headers in generated code."_s},
+ {u"clang-option"_s,
+ u"Option to be passed to clang"_s},
+ {u"clang-options"_s,
+ u"A comma-separated list of options to be passed to clang"_s},
+ {u"skip-deprecated"_s,
+ u"Skip deprecated functions"_s},
+ {u"-F<path>"_s, {} },
+ {u"framework-include-paths="_s + OptionsParser::pathSyntax(),
+ u"Framework include paths used by the C++ parser"_s},
+ {u"-isystem<path>"_s, {} },
+ {u"system-include-paths="_s + OptionsParser::pathSyntax(),
+ u"System include paths used by the C++ parser"_s},
+ {u"language-level=, -std=<level>"_s,
+ languageLevelDescription()},
+ };
+}
+
+class ApiExtractorOptionsParser : public OptionsParser
+{
+public:
+ explicit ApiExtractorOptionsParser(ApiExtractorOptions *o) : m_options(o) {}
+
+ bool handleBoolOption(const QString &key, OptionSource source) override;
+ bool handleOption(const QString &key, const QString &value,
+ OptionSource source) override;
+
+private:
+ void parseIncludePathOption(const QString &value, HeaderType headerType);
+ void parseIncludePathOption(const QStringList &values, HeaderType headerType);
+ void setLanguageLevel(const QString &value);
+
+ ApiExtractorOptions *m_options;
+};
+
+void ApiExtractorOptionsParser::parseIncludePathOption(const QString &value,
+ HeaderType headerType)
+{
+ const auto path = QFile::encodeName(QDir::cleanPath(value));
+ m_options->m_includePaths.append(HeaderPath{path, headerType});
+}
+
+void ApiExtractorOptionsParser::parseIncludePathOption(const QStringList &values,
+ HeaderType headerType)
+{
+ for (const auto &value : values)
+ parseIncludePathOption(value, headerType);
+}
+
+void ApiExtractorOptionsParser::setLanguageLevel(const QString &value)
+{
+ const QByteArray languageLevelBA = value.toLatin1();
+ const LanguageLevel level = clang::languageLevelFromOption(languageLevelBA.constData());
+ if (level == LanguageLevel::Default)
+ throw Exception(msgInvalidLanguageLevel(value));
+ m_options->m_languageLevel = level;
+}
+
+bool ApiExtractorOptionsParser::handleBoolOption(const QString &key, OptionSource source)
+{
+ static const auto isystemOption = "isystem"_L1;
+
+ switch (source) {
+ case OptionSource::CommandLine:
+ case OptionSource::ProjectFile:
+ if (key == u"use-global-header") {
+ AbstractMetaBuilder::setUseGlobalHeader(true);
+ return true;
+ }
+ if (key == u"skip-deprecated") {
+ m_options->m_skipDeprecated = true;
+ return true;
+ }
+ break;
+
+ case OptionSource::CommandLineSingleDash:
+ if (key.startsWith(u'I')) { // Shorthand path arguments -I/usr/include...
+ parseIncludePathOption(key.sliced(1), HeaderType::Standard);
+ return true;
+ }
+ if (key.startsWith(u'F')) {
+ parseIncludePathOption(key.sliced(1), HeaderType::Framework);
+ return true;
+ }
+ if (key.startsWith(isystemOption)) {
+ parseIncludePathOption(key.sliced(isystemOption.size()), HeaderType::System);
+ return true;
+ }
+ break;
+ }
+ return false;
+}
+
+bool ApiExtractorOptionsParser::handleOption(const QString &key, const QString &value,
+ OptionSource source)
+{
+ if (source == OptionSource::CommandLineSingleDash) {
+ if (key == u"std") {
+ setLanguageLevel(value);
+ return true;
+ }
+ return false;
+ }
+
+ if (key == u"clang-option") {
+ m_options->m_clangOptions.append(value);
+ return true;
+ }
+ if (key == u"clang-options") {
+ m_options->m_clangOptions.append(value.split(u','));
+ return true;
+ }
+ if (key == u"include-paths") {
+ parseIncludePathOption(value.split(QDir::listSeparator()), HeaderType::Standard);
+ return true;
+ }
+ if (key == u"framework-include-paths") {
+ parseIncludePathOption(value.split(QDir::listSeparator()), HeaderType::Framework);
+ return true;
+ }
+ if (key == u"system-include-paths") {
+ parseIncludePathOption(value.split(QDir::listSeparator()), HeaderType::System);
+ return true;
+ }
+ if (key == u"language-level") {
+ setLanguageLevel(value);
+ return true;
+ }
+
+ if (source == OptionSource::ProjectFile) {
+ if (key == u"include-path") {
+ parseIncludePathOption(value, HeaderType::Standard);
+ return true;
+ }
+ if (key == u"framework-include-path") {
+ parseIncludePathOption(value, HeaderType::Framework);
+ return true;
+ }
+ if (key == u"system-include-path") {
+ parseIncludePathOption(value, HeaderType::System);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+std::shared_ptr<OptionsParser> ApiExtractor::createOptionsParser()
+{
+ return std::make_shared<ApiExtractorOptionsParser>(d);
+}
+
+struct ApiExtractorPrivate : public ApiExtractorOptions
{
bool runHelper(ApiExtractorFlags flags);
@@ -63,14 +238,7 @@ struct ApiExtractorPrivate
void addInstantiatedSmartPointer(InstantiationCollectContext &context,
const AbstractMetaType &type);
- QString m_typeSystemFileName;
- QFileInfoList m_cppFileNames;
- HeaderPaths m_includePaths;
- QStringList m_clangOptions;
AbstractMetaBuilder *m_builder = nullptr;
- QString m_logDirectory;
- LanguageLevel m_languageLevel = LanguageLevel::Default;
- bool m_skipDeprecated = false;
};
ApiExtractor::ApiExtractor() :
@@ -84,16 +252,6 @@ ApiExtractor::~ApiExtractor()
delete d;
}
-void ApiExtractor::addIncludePath(const HeaderPath& path)
-{
- d->m_includePaths << path;
-}
-
-void ApiExtractor::addIncludePath(const HeaderPaths& paths)
-{
- d->m_includePaths << paths;
-}
-
HeaderPaths ApiExtractor::includePaths() const
{
return d->m_includePaths;
@@ -124,18 +282,6 @@ QString ApiExtractor::typeSystem() const
return d->m_typeSystemFileName;
}
-void ApiExtractor::setSkipDeprecated(bool value)
-{
- d->m_skipDeprecated = value;
- if (d->m_builder)
- d->m_builder->setSkipDeprecated(d->m_skipDeprecated);
-}
-
-void ApiExtractor::setSilent ( bool value )
-{
- ReportHandler::setSilent(value);
-}
-
const AbstractMetaEnumList &ApiExtractor::globalEnums() const
{
Q_ASSERT(d->m_builder);
@@ -281,26 +427,11 @@ LanguageLevel ApiExtractor::languageLevel() const
return d->m_languageLevel;
}
-void ApiExtractor::setLanguageLevel(LanguageLevel languageLevel)
-{
- d->m_languageLevel = languageLevel;
-}
-
QStringList ApiExtractor::clangOptions() const
{
return d->m_clangOptions;
}
-void ApiExtractor::setClangOptions(const QStringList &co)
-{
- d->m_clangOptions = co;
-}
-
-void ApiExtractor::setUseGlobalHeader(bool h)
-{
- AbstractMetaBuilder::setUseGlobalHeader(h);
-}
-
AbstractMetaFunctionPtr
ApiExtractor::inheritTemplateFunction(const AbstractMetaFunctionCPtr &function,
const AbstractMetaTypeList &templateTypes)
diff --git a/sources/shiboken6/ApiExtractor/apiextractor.h b/sources/shiboken6/ApiExtractor/apiextractor.h
index ef8e1b958..feae9454c 100644
--- a/sources/shiboken6/ApiExtractor/apiextractor.h
+++ b/sources/shiboken6/ApiExtractor/apiextractor.h
@@ -20,6 +20,8 @@ class AbstractMetaClass;
class AbstractMetaEnum;
class AbstractMetaFunction;
class ComplexTypeEntry;
+struct OptionDescription;
+class OptionsParser;
QT_BEGIN_NAMESPACE
class QDebug;
@@ -36,21 +38,17 @@ public:
ApiExtractor();
~ApiExtractor();
+ static QList<OptionDescription> options();
+ std::shared_ptr<OptionsParser> createOptionsParser();
+
void setTypeSystem(const QString& typeSystemFileName);
QString typeSystem() const;
void setCppFileNames(const QFileInfoList &cppFileNames);
QFileInfoList cppFileNames() const;
- void setSkipDeprecated(bool value);
- static void setSilent(bool value);
- void addIncludePath(const HeaderPath& path);
- void addIncludePath(const HeaderPaths& paths);
HeaderPaths includePaths() const;
void setLogDirectory(const QString& logDir);
LanguageLevel languageLevel() const;
- void setLanguageLevel(LanguageLevel languageLevel);
QStringList clangOptions() const;
- void setClangOptions(const QStringList &co);
- static void setUseGlobalHeader(bool h);
const AbstractMetaEnumList &globalEnums() const;
const AbstractMetaFunctionCList &globalFunctions() const;
diff --git a/sources/shiboken6/ApiExtractor/messages.cpp b/sources/shiboken6/ApiExtractor/messages.cpp
index 0393fa3b3..c3ad3d5c1 100644
--- a/sources/shiboken6/ApiExtractor/messages.cpp
+++ b/sources/shiboken6/ApiExtractor/messages.cpp
@@ -953,3 +953,8 @@ QString msgMissingProjectFileMarker(const QString &name, const QByteArray &start
return u"First line of project file \""_s + QDir::toNativeSeparators(name)
+ u"\" must be the string \""_s + QString::fromLatin1(startMarker) + u"\"."_s;
}
+
+QString msgInvalidLanguageLevel(const QString &l)
+{
+ return u"Invalid argument for language level: \""_s + l + u"\"."_s;
+}
diff --git a/sources/shiboken6/ApiExtractor/messages.h b/sources/shiboken6/ApiExtractor/messages.h
index 93b9d10f1..833899b68 100644
--- a/sources/shiboken6/ApiExtractor/messages.h
+++ b/sources/shiboken6/ApiExtractor/messages.h
@@ -253,4 +253,6 @@ QString msgUnknownArrayPointerConversion(const QString &s);
QString msgMissingProjectFileMarker(const QString &name, const QByteArray &startMarker);
+QString msgInvalidLanguageLevel(const QString &l);
+
#endif // MESSAGES_H