diff options
| -rw-r--r-- | sources/shiboken6/ApiExtractor/apiextractor.cpp | 35 | ||||
| -rw-r--r-- | sources/shiboken6/ApiExtractor/apiextractor.h | 6 | ||||
| -rw-r--r-- | sources/shiboken6/ApiExtractor/typedatabase.cpp | 144 | ||||
| -rw-r--r-- | sources/shiboken6/ApiExtractor/typedatabase.h | 10 | ||||
| -rw-r--r-- | sources/shiboken6/generator/main.cpp | 71 |
5 files changed, 125 insertions, 141 deletions
diff --git a/sources/shiboken6/ApiExtractor/apiextractor.cpp b/sources/shiboken6/ApiExtractor/apiextractor.cpp index 350539869..c754d01e0 100644 --- a/sources/shiboken6/ApiExtractor/apiextractor.cpp +++ b/sources/shiboken6/ApiExtractor/apiextractor.cpp @@ -76,10 +76,6 @@ struct ApiExtractorPrivate ApiExtractor::ApiExtractor() : d(new ApiExtractorPrivate) { - // Environment TYPESYSTEMPATH - QString envTypesystemPaths = QFile::decodeName(qgetenv("TYPESYSTEMPATH")); - if (!envTypesystemPaths.isEmpty()) - TypeDatabase::instance()->addTypesystemPath(envTypesystemPaths); } ApiExtractor::~ApiExtractor() @@ -88,22 +84,6 @@ ApiExtractor::~ApiExtractor() delete d; } -void ApiExtractor::addTypesystemSearchPath (const QString& path) -{ - TypeDatabase::instance()->addTypesystemPath(path); -} - -void ApiExtractor::addTypesystemSearchPath(const QStringList& paths) -{ - for (const QString &path : paths) - addTypesystemSearchPath(path); -} - -void ApiExtractor::setTypesystemKeywords(const QStringList &keywords) -{ - TypeDatabase::instance()->setTypesystemKeywords(keywords); -} - void ApiExtractor::addIncludePath(const HeaderPath& path) { d->m_includePaths << path; @@ -151,26 +131,11 @@ void ApiExtractor::setSkipDeprecated(bool value) d->m_builder->setSkipDeprecated(d->m_skipDeprecated); } -void ApiExtractor::setSuppressWarnings ( bool value ) -{ - TypeDatabase::instance()->setSuppressWarnings(value); -} - void ApiExtractor::setSilent ( bool value ) { ReportHandler::setSilent(value); } -bool ApiExtractor::setApiVersion(const QString& package, const QString &version) -{ - return TypeDatabase::setApiVersion(package, version); -} - -void ApiExtractor::setDropTypeEntries(const QStringList &dropEntries) -{ - TypeDatabase::instance()->setDropTypeEntries(dropEntries); -} - const AbstractMetaEnumList &ApiExtractor::globalEnums() const { Q_ASSERT(d->m_builder); diff --git a/sources/shiboken6/ApiExtractor/apiextractor.h b/sources/shiboken6/ApiExtractor/apiextractor.h index 011a6dd3d..ef8e1b958 100644 --- a/sources/shiboken6/ApiExtractor/apiextractor.h +++ b/sources/shiboken6/ApiExtractor/apiextractor.h @@ -41,17 +41,11 @@ public: void setCppFileNames(const QFileInfoList &cppFileNames); QFileInfoList cppFileNames() const; void setSkipDeprecated(bool value); - static void setSuppressWarnings(bool value); static void setSilent(bool value); - static void addTypesystemSearchPath(const QString &path); - static void addTypesystemSearchPath(const QStringList& paths); - static void setTypesystemKeywords(const QStringList& keywords); void addIncludePath(const HeaderPath& path); void addIncludePath(const HeaderPaths& paths); HeaderPaths includePaths() const; void setLogDirectory(const QString& logDir); - static bool setApiVersion(const QString &package, const QString &version); - static void setDropTypeEntries(const QStringList &dropEntries); LanguageLevel languageLevel() const; void setLanguageLevel(LanguageLevel languageLevel); QStringList clangOptions() const; diff --git a/sources/shiboken6/ApiExtractor/typedatabase.cpp b/sources/shiboken6/ApiExtractor/typedatabase.cpp index eb2f33316..e2d24130d 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken6/ApiExtractor/typedatabase.cpp @@ -11,11 +11,13 @@ #include "containertypeentry.h" #include "customtypenentry.h" #include "debughelpers_p.h" +#include "exception.h" #include "flagstypeentry.h" #include "functiontypeentry.h" #include "namespacetypeentry.h" #include "objecttypeentry.h" #include "primitivetypeentry.h" +#include "optionsparser.h" #include "pythontypeentry.h" #include "smartpointertypeentry.h" #include "typedefentry.h" @@ -109,7 +111,108 @@ struct SuppressedWarning mutable bool matched = false; }; -struct TypeDatabasePrivate +QList<OptionDescription> TypeDatabase::options() +{ + return { + {u"api-version=<\"package mask\">,<\"version\">"_s, + u"Specify the supported api version used to generate the bindings"_s}, + {u"drop-type-entries=\"<TypeEntry0>[;TypeEntry1;...]\""_s, + u"Semicolon separated list of type system entries (classes, namespaces,\n" + "global functions and enums) to be dropped from generation."_s}, + {u"-T<path>"_s, {} }, + {u"typesystem-paths="_s + OptionsParser::pathSyntax(), + u"Paths used when searching for typesystems"_s}, + {u"keywords=keyword1[,keyword2,...]"_s, + u"A comma-separated list of keywords for conditional typesystem parsing"_s}, + }; +} + +struct TypeDatabaseOptions +{ + QStringList m_dropTypeEntries; + QStringList m_systemIncludes; + QStringList m_typesystemKeywords; + QStringList m_typesystemPaths; + bool m_suppressWarnings = true; +}; + +class TypeDatabaseOptionsParser : public OptionsParser +{ +public: + explicit TypeDatabaseOptionsParser(TypeDatabaseOptions *o) : m_options(o) {} + + bool handleBoolOption(const QString &key, OptionSource source) override; + bool handleOption(const QString &key, const QString &value, OptionSource source) override; + +private: + TypeDatabaseOptions *m_options; +}; + +bool TypeDatabaseOptionsParser::handleBoolOption(const QString &key, OptionSource source) +{ + switch (source) { + case OptionSource::CommandLine: + case OptionSource::ProjectFile: + if (key == u"no-suppress-warnings") { + m_options->m_suppressWarnings = false; + return true; + } + break; + case OptionSource::CommandLineSingleDash: + if (key.startsWith(u'T')) { // "-T/path" ends up a bool option + m_options->m_typesystemPaths += key.sliced(1).split(QDir::listSeparator()); + return true; + } + break; + } + return false; +} + +bool TypeDatabaseOptionsParser::handleOption(const QString &key, const QString &value, + OptionSource source) +{ + if (source == OptionSource::CommandLineSingleDash) + return false; + if (key == u"api-version") { + const auto fullVersions = QStringView{value}.split(u'|'); + for (const auto &fullVersion : fullVersions) { + const auto parts = fullVersion.split(u','); + const QString package = parts.size() == 1 + ? u"*"_s : parts.constFirst().toString(); + const QString version = parts.constLast().toString(); + if (!TypeDatabase::setApiVersion(package, version)) + throw Exception(msgInvalidVersion(package, version)); + } + return true; + } + + if (key == u"drop-type-entries") { + m_options->m_dropTypeEntries = value.split(u';'); + m_options->m_dropTypeEntries.sort(); + return true; + } + + if (key == u"keywords") { + m_options->m_typesystemKeywords = value.split(u','); + return true; + } + + if (key == u"typesystem-paths") { + m_options->m_typesystemPaths += value.split(QDir::listSeparator()); + return true; + } + + if (source == OptionSource::ProjectFile) { + if (key == u"typesystem-path") { + m_options->m_typesystemPaths += value; + return true; + } + } + + return false; +} + +struct TypeDatabasePrivate : public TypeDatabaseOptions { TypeSystemTypeEntryCPtr defaultTypeSystemType() const; TypeEntryPtr findType(const QString &name) const; @@ -150,7 +253,6 @@ struct TypeDatabasePrivate void formatDebug(QDebug &d) const; void formatBuiltinTypes(QDebug &d) const; - bool m_suppressWarnings = true; TypeEntryMultiMap m_entries; // Contains duplicate entries (cf addInlineNamespaceLookups). TypeEntryMap m_flagsEntries; TypedefEntryMap m_typedefEntries; @@ -163,18 +265,21 @@ struct TypeDatabasePrivate QStringList m_requiredTargetImports; - QStringList m_typesystemPaths; - QStringList m_typesystemKeywords; QHash<QString, bool> m_parsedTypesystemFiles; QList<TypeRejection> m_rejections; - - QStringList m_dropTypeEntries; - QStringList m_systemIncludes; }; +static const char ENV_TYPESYSTEMPATH[] = "TYPESYSTEMPATH"; + TypeDatabase::TypeDatabase() : d(new TypeDatabasePrivate) { + // Environment TYPESYSTEMPATH + if (qEnvironmentVariableIsSet(ENV_TYPESYSTEMPATH)) { + d->m_typesystemPaths + += qEnvironmentVariable(ENV_TYPESYSTEMPATH).split(QDir::listSeparator()); + } + d->addBuiltInType(TypeEntryPtr(new VoidTypeEntry())); d->addBuiltInType(TypeEntryPtr(new VarargsTypeEntry())); for (const auto &pt : builtinPythonTypes()) @@ -189,6 +294,11 @@ TypeDatabase::~TypeDatabase() delete d; } +std::shared_ptr<OptionsParser> TypeDatabase::createOptionsParser() +{ + return std::make_shared<TypeDatabaseOptionsParser>(d); +} + TypeDatabase *TypeDatabase::instance(bool newInstance) { static TypeDatabase *db = nullptr; @@ -306,21 +416,6 @@ void TypeDatabase::addRequiredTargetImport(const QString& moduleName) d->m_requiredTargetImports << moduleName; } -void TypeDatabase::addTypesystemPath(const QString& typesystem_paths) -{ - #if defined(Q_OS_WIN32) - const char path_splitter = ';'; - #else - const char path_splitter = ':'; - #endif - d->m_typesystemPaths += typesystem_paths.split(QLatin1Char(path_splitter)); -} - -void TypeDatabase::setTypesystemKeywords(const QStringList &keywords) -{ - d->m_typesystemKeywords = keywords; -} - QStringList TypeDatabase::typesystemKeywords() const { QStringList result = d->m_typesystemKeywords; @@ -789,11 +884,6 @@ FunctionModificationList return lst; } -void TypeDatabase::setSuppressWarnings(bool on) -{ - d->m_suppressWarnings = on; -} - bool TypeDatabase::addSuppressedWarning(const QString &warning, bool generate, QString *errorMessage) { diff --git a/sources/shiboken6/ApiExtractor/typedatabase.h b/sources/shiboken6/ApiExtractor/typedatabase.h index 5c12bc277..a0fc0fcd2 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.h +++ b/sources/shiboken6/ApiExtractor/typedatabase.h @@ -16,6 +16,8 @@ QT_FORWARD_DECLARE_CLASS(QIODevice) +struct OptionDescription; +class OptionsParser; struct TypeDatabasePrivate; struct TypeDatabaseParserContext; @@ -65,6 +67,9 @@ class TypeDatabase public: ~TypeDatabase(); + static QList<OptionDescription> options(); + std::shared_ptr<OptionsParser> createOptionsParser(); + /** * Return the type system instance. * \param newInstance This parameter is useful just for unit testing, because singletons causes @@ -79,9 +84,6 @@ public: void addRequiredTargetImport(const QString &moduleName); - void addTypesystemPath(const QString &typesystem_paths); - - void setTypesystemKeywords(const QStringList &keywords); QStringList typesystemKeywords() const; IncludeList extraIncludes(const QString &className) const; @@ -157,8 +159,6 @@ public: FunctionModificationList globalFunctionModifications(const QStringList &signatures) const; - void setSuppressWarnings(bool on); - bool addSuppressedWarning(const QString &warning, bool generate, QString *errorMessage); bool isSuppressedWarning(QStringView s) const; diff --git a/sources/shiboken6/generator/main.cpp b/sources/shiboken6/generator/main.cpp index 73e7e9bde..37d9272d3 100644 --- a/sources/shiboken6/generator/main.cpp +++ b/sources/shiboken6/generator/main.cpp @@ -28,23 +28,15 @@ using namespace Qt::StringLiterals; static const QChar clangOptionsSplitter = u','; -static const QChar keywordsSplitter = u','; -static const QChar dropTypeEntriesSplitter = u';'; -static const QChar apiVersionSplitter = u'|'; - -static inline QString keywordsOption() { return QStringLiteral("keywords"); } static inline QString clangOptionOption() { return QStringLiteral("clang-option"); } static inline QString clangOptionsOption() { return QStringLiteral("clang-options"); } static inline QString compilerOption() { return QStringLiteral("compiler"); } static inline QString compilerPathOption() { return QStringLiteral("compiler-path"); } static inline QString platformOption() { return QStringLiteral("platform"); } -static inline QString apiVersionOption() { return QStringLiteral("api-version"); } -static inline QString dropTypeEntriesOption() { return QStringLiteral("drop-type-entries"); } static inline QString languageLevelOption() { return QStringLiteral("language-level"); } static inline QString includePathOption() { return QStringLiteral("include-paths"); } static inline QString frameworkIncludePathOption() { return QStringLiteral("framework-include-paths"); } static inline QString systemIncludePathOption() { return QStringLiteral("system-include-paths"); } -static inline QString typesystemPathOption() { return QStringLiteral("typesystem-paths"); } static inline QString logUnmatchedOption() { return QStringLiteral("log-unmatched"); } static inline QString helpOption() { return QStringLiteral("help"); } static inline QString diffOption() { return QStringLiteral("diff"); } @@ -123,12 +115,6 @@ bool CommandLineArguments::addCommonOption(const QString &option, options.insert(option, QStringList(value)); } else if (option == clangOptionsOption()) { addToOptionsList(option, value, clangOptionsSplitter); - } else if (option == apiVersionOption()) { - addToOptionsList(option, value, apiVersionSplitter); - } else if (option == keywordsOption()) { - addToOptionsList(option, value, keywordsSplitter); - } else if (option == dropTypeEntriesOption()) { - addToOptionsList(option, value, dropTypeEntriesSplitter); } else { result = false; } @@ -142,8 +128,6 @@ static QString projectFileKeywordToCommandLineOption(const QString &p) return includePathOption(); // "include-paths", ... if (p == u"framework-include-path") return frameworkIncludePathOption(); - if (p == u"typesystem-path") - return typesystemPathOption(); if (p == u"system-include-paths") return systemIncludePathOption(); return {}; @@ -238,7 +222,7 @@ static void getCommandLineArg(QString arg, int &argNum, CommandLineArguments &ar const QString value = arg.mid(split + 1).trimmed(); if (args.addCommonOption(option, value)) { } else if (option == includePathOption() || option == frameworkIncludePathOption() - || option == systemIncludePathOption() || option == typesystemPathOption()) { + || option == systemIncludePathOption()) { // Add platform path-separator separated list value to path list args.addToOptionsPathList(option, value); } else { @@ -254,8 +238,6 @@ static void getCommandLineArg(QString arg, int &argNum, CommandLineArguments &ar args.addToOptionsPathList(frameworkIncludePathOption(), arg.mid(1)); else if (arg.startsWith(u"isystem")) args.addToOptionsPathList(systemIncludePathOption(), arg.mid(7)); - else if (arg.startsWith(u'T')) - args.addToOptionsPathList(typesystemPathOption(), arg.mid(1)); else if (arg == u"h") args.options.insert(helpOption(), QString()); else if (arg.startsWith(u"std=")) @@ -310,17 +292,10 @@ void printUsage() << "shiboken [options] header-file(s) typesystem-file\n\n" << "General options:\n"; OptionDescriptions generalOptions = { - {u"api-version=<\"package mask\">,<\"version\">"_s, - u"Specify the supported api version used to generate the bindings"_s}, {u"debug-level=[sparse|medium|full]"_s, u"Set the debug level"_s}, {u"documentation-only"_s, u"Do not generates any code, just the documentation"_s}, - {u"drop-type-entries=\"<TypeEntry0>[;TypeEntry1;...]\""_s, - u"Semicolon separated list of type system entries (classes, namespaces,\n" - "global functions and enums) to be dropped from generation."_s}, - {keywordsOption() + QStringLiteral("=keyword1[,keyword2,...]"), - u"A comma-separated list of keywords for conditional typesystem parsing"_s}, {clangOptionOption(), u"Option to be passed to clang"_s}, {clangOptionsOption(), @@ -362,9 +337,6 @@ void printUsage() u"text file containing a description of the binding project.\n" "Replaces and overrides command line arguments"_s}, {u"silent"_s, u"Avoid printing any message"_s}, - {u"-T<path>"_s, {} }, - {u"typesystem-paths="_s + OptionsParser::pathSyntax(), - u"Paths used when searching for typesystems"_s}, {printBuiltinTypesOption(), u"Print information about builtin types"_s}, {u"version"_s, @@ -372,6 +344,7 @@ void printUsage() }; s << generalOptions + << TypeDatabase::options() << "\nSource generator options:\n\n" << generatorOptions << ShibokenGenerator::options(); @@ -450,6 +423,7 @@ int shibokenMain(const QStringList &argV) OptionsParserList optionParser; optionParser.append(Generator::createOptionsParser()); + optionParser.append(TypeDatabase::instance()->createOptionsParser()); // Pre-defined generator sets. if (generatorSet == u"qtdoc") { @@ -552,45 +526,6 @@ int shibokenMain(const QStringList &argV) args.options.erase(ait); } } - ait = args.options.find(u"no-suppress-warnings"_s); - if (ait != args.options.end()) { - args.options.erase(ait); - extractor.setSuppressWarnings(false); - } - ait = args.options.find(apiVersionOption()); - if (ait != args.options.end()) { - const QStringList &versions = ait.value().toStringList(); - args.options.erase(ait); - for (const QString &fullVersion : versions) { - QStringList parts = fullVersion.split(u','); - QString package; - QString version; - package = parts.size() == 1 ? u"*"_s : parts.constFirst(); - version = parts.constLast(); - if (!extractor.setApiVersion(package, version)) { - errorPrint(msgInvalidVersion(package, version), argV); - return EXIT_FAILURE; - } - } - } - - ait = args.options.find(dropTypeEntriesOption()); - if (ait != args.options.end()) { - extractor.setDropTypeEntries(ait.value().toStringList()); - args.options.erase(ait); - } - - ait = args.options.find(keywordsOption()); - if (ait != args.options.end()) { - extractor.setTypesystemKeywords(ait.value().toStringList()); - args.options.erase(ait); - } - - ait = args.options.find(typesystemPathOption()); - if (ait != args.options.end()) { - extractor.addTypesystemSearchPath(ait.value().toStringList()); - args.options.erase(ait); - } ait = args.options.find(clangOptionsOption()); if (ait != args.options.end()) { |
