diff options
Diffstat (limited to 'sources/shiboken6/generator/shiboken/shibokengenerator.h')
-rw-r--r-- | sources/shiboken6/generator/shiboken/shibokengenerator.h | 403 |
1 files changed, 179 insertions, 224 deletions
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h index c4c93a600..22ee73fa2 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.h +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h @@ -1,66 +1,42 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef SHIBOKENGENERATOR_H #define SHIBOKENGENERATOR_H -extern const char *CPP_ARG; -extern const char *CPP_ARG_REMOVED; -extern const char *CPP_RETURN_VAR; -extern const char *CPP_SELF_VAR; -extern const char *NULL_PTR; -extern const char *PYTHON_ARG; -extern const char *PYTHON_ARGS; -extern const char *PYTHON_OVERRIDE_VAR; -extern const char *PYTHON_RETURN_VAR; -extern const char *PYTHON_TO_CPP_VAR; -extern const char *SMART_POINTER_GETTER; - -extern const char *CONV_RULE_OUT_VAR_SUFFIX; -extern const char *BEGIN_ALLOW_THREADS; -extern const char *END_ALLOW_THREADS; - #include <generator.h> -#include "typesystem.h" +#include "customconversion_typedefs.h" +#include "abstractmetalang_enums.h" +#include "typesystem_typedefs.h" +#include "typesystem_enums.h" #include <QtCore/QRegularExpression> #include <array> +#include <optional> +class EnumTypeEntry; +class FlagsTypeEntry; class DocParser; class CodeSnip; class QPropertySpec; class OverloadData; -class TextStream; +class TargetToNativeConversion; struct GeneratorClassInfoCacheEntry; +struct IncludeGroup; +struct ShibokenGeneratorOptions; -QT_FORWARD_DECLARE_CLASS(TextStream) +class TextStream; + +// Function to be used for implementing nb_bool +struct BoolCastFunction +{ + AbstractMetaFunctionCPtr function; + bool invert = false; // Function is "isNull()", (invert result). +}; + +using BoolCastFunctionOptional = std::optional<BoolCastFunction>; /** * Abstract generator that contains common methods used in CppGenerator and HeaderGenerator. @@ -68,6 +44,29 @@ QT_FORWARD_DECLARE_CLASS(TextStream) class ShibokenGenerator : public Generator { public: + Q_DISABLE_COPY_MOVE(ShibokenGenerator) + + /// Besides the actual bindings (see AbstractMetaFunction::generateBinding(), + /// some functions need to be generated into the wrapper class + /// (virtual method/avoid protected hack expose). + enum class FunctionGenerationFlag + { + None = 0x0, + /// Virtual method overridable in Python + VirtualMethod = 0x1, + /// Special QObject virtuals + QMetaObjectMethod = 0x2, + /// Needs a protected wrapper for avoidProtectedHack() + /// public "foo_protected()" calling "foo()" + ProtectedWrapper = 0x4, // + /// Pass through constructor + WrapperConstructor = 0x8, + /// Generate a special copy constructor + /// "FooBar_Wrapper(const Foo&)" for constructing a wrapper from a value + WrapperSpecialCopyConstructor = 0x10 + }; + Q_DECLARE_FLAGS(FunctionGeneration, FunctionGenerationFlag); + enum class AttroCheckFlag { None = 0x0, @@ -90,13 +89,18 @@ public: const char *name() const override { return "Shiboken"; } - /// Returns true if the user enabled PySide extensions. - bool usePySideExtensions() const; + static QList<OptionDescription> options(); + static std::shared_ptr<OptionsParser> createOptionsParser(); + + static QString minimalConstructorExpression(const ApiExtractorResult &api, + const AbstractMetaType &type); + static QString minimalConstructorExpression(const ApiExtractorResult &api, + const TypeEntryCPtr &type); protected: bool doSetup() override; - GeneratorContext contextForClass(const AbstractMetaClass *c) const override; + GeneratorContext contextForClass(const AbstractMetaClassCPtr &c) const override; /** * Returns a map with all functions grouped, the function name is used as key. @@ -104,7 +108,12 @@ protected: * \param scope Where to search for functions, null means all global functions. */ FunctionGroups getGlobalFunctionGroups() const; - static FunctionGroups getFunctionGroups(const AbstractMetaClass *scope); + static FunctionGroups getFunctionGroups(const AbstractMetaClassCPtr &scope); + + static QList<AbstractMetaFunctionCList> + numberProtocolOperators(const AbstractMetaClassCPtr &scope); + + static BoolCastFunctionOptional boolCast(const AbstractMetaClassCPtr &scope); /** * Returns all different inherited overloads of func, and includes func as well. @@ -117,24 +126,26 @@ protected: /// Write user's custom code snippets at class or module level. void writeClassCodeSnips(TextStream &s, - const CodeSnipList &codeSnips, + const QList<CodeSnip> &codeSnips, TypeSystem::CodeSnipPosition position, TypeSystem::Language language, const GeneratorContext &context) const; void writeCodeSnips(TextStream &s, - const CodeSnipList &codeSnips, + const QList<CodeSnip> &codeSnips, TypeSystem::CodeSnipPosition position, TypeSystem::Language language) const; /// Write user's custom code snippets at function level. void writeCodeSnips(TextStream &s, - const CodeSnipList &codeSnips, + const QList<CodeSnip> &codeSnips, TypeSystem::CodeSnipPosition position, TypeSystem::Language language, const AbstractMetaFunctionCPtr &func, - const AbstractMetaArgument *lastArg = nullptr) const; + bool usePyArgs, + const AbstractMetaArgument *lastArg) const; /// Replaces variables for the user's custom code at global or class level. void processCodeSnip(QString &code) const; + void processCodeSnip(QString &code, const QString &context) const; void processClassCodeSnip(QString &code, const GeneratorContext &context) const; /** @@ -160,213 +171,166 @@ protected: int arg_count = -1) const; /// Returns the top-most class that has multiple inheritance in the ancestry. - static const AbstractMetaClass *getMultipleInheritingClass(const AbstractMetaClass *metaClass); + static AbstractMetaClassCPtr + getMultipleInheritingClass(const AbstractMetaClassCPtr &metaClass); - static bool useOverrideCaching(const AbstractMetaClass *metaClass); - AttroCheck checkAttroFunctionNeeds(const AbstractMetaClass *metaClass) const; + static bool useOverrideCaching(const AbstractMetaClassCPtr &metaClass); + static AttroCheck checkAttroFunctionNeeds(const AbstractMetaClassCPtr &metaClass); - /// Returns a list of methods of the given class where each one is part of a different overload with both static and non-static method. + /// Returns a list of methods of the given class where each one is part of + /// a different overload with both static and non-static method. static AbstractMetaFunctionCList - getMethodsWithBothStaticAndNonStaticMethods(const AbstractMetaClass *metaClass); + getMethodsWithBothStaticAndNonStaticMethods(const AbstractMetaClassCPtr &metaClass); static void writeToPythonConversion(TextStream &s, const AbstractMetaType &type, - const AbstractMetaClass *context, + const AbstractMetaClassCPtr &context, const QString &argumentName); static void writeToCppConversion(TextStream &s, const AbstractMetaType &type, - const AbstractMetaClass *context, const QString &inArgName, const QString &outArgName); static void writeToCppConversion(TextStream &s, - const AbstractMetaClass *metaClass, const QString &inArgName, + const AbstractMetaClassCPtr &metaClass, + const QString &inArgName, const QString &outArgName); /// Returns true if the argument is a pointer that rejects nullptr values. - static bool shouldRejectNullPointerArgument(const ApiExtractorResult &api, - const AbstractMetaFunctionCPtr &func, + static bool shouldRejectNullPointerArgument(const AbstractMetaFunctionCPtr &func, int argIndex); - /// Verifies if the class should have a C++ wrapper generated for it, instead of only a Python wrapper. - bool shouldGenerateCppWrapper(const AbstractMetaClass *metaClass) const; + /// Verifies if the class should have a C++ wrapper generated for it, + /// instead of only a Python wrapper. + static bool shouldGenerateCppWrapper(const AbstractMetaClassCPtr &metaClass); + + static bool shouldGenerateMetaObjectFunctions(const AbstractMetaClassCPtr &metaClass); + + /// Returns which functions need to be generated into the wrapper class + static FunctionGeneration functionGeneration(const AbstractMetaFunctionCPtr &func); + + // Return a list of implicit conversions if generation is enabled. + AbstractMetaFunctionCList implicitConversions(const TypeEntryCPtr &t) const; - /// Condition to call WriteVirtualMethodNative. Was extracted because also used to count these calls. - bool shouldWriteVirtualMethodNative(const AbstractMetaFunctionCPtr &func) const; + static QString wrapperName(const AbstractMetaClassCPtr &metaClass); - QString wrapperName(const AbstractMetaClass *metaClass) const; + static QString fullPythonClassName(const AbstractMetaClassCPtr &metaClass); + + static QString headerFileNameForContext(const GeneratorContext &context); + IncludeGroup baseWrapperIncludes(const GeneratorContext &classContext) const; - static QString fullPythonClassName(const AbstractMetaClass *metaClass); static QString fullPythonFunctionName(const AbstractMetaFunctionCPtr &func, bool forceFunc); - bool wrapperDiagnostics() const { return m_wrapperDiagnostics; } + static bool wrapperDiagnostics(); static QString protectedEnumSurrogateName(const AbstractMetaEnum &metaEnum); static QString pythonPrimitiveTypeName(const QString &cppTypeName); - static QString pythonPrimitiveTypeName(const PrimitiveTypeEntry *type); - static QString pythonOperatorFunctionName(const QString &cppOpFuncName); static QString pythonOperatorFunctionName(const AbstractMetaFunctionCPtr &func); - static QString pythonRichCompareOperatorId(const QString &cppOpFuncName); - static QString pythonRichCompareOperatorId(const AbstractMetaFunctionCPtr &func); + static QList<AbstractMetaFunctionCList> + filterGroupedOperatorFunctions(const AbstractMetaClassCPtr &metaClass, + OperatorQueryOptions query); - static QString fixedCppTypeName(const CustomConversion::TargetToNativeConversion *toNative); + static QString fixedCppTypeName(const TargetToNativeConversion &toNative); static QString fixedCppTypeName(const AbstractMetaType &type); - static QString fixedCppTypeName(const TypeEntry *type, QString typeName = QString()); + static QString fixedCppTypeName(const TypeEntryCPtr &type, QString typeName = {}); static bool isNumber(const QString &cpythonApiName); - static bool isNumber(const TypeEntry *type); + static bool isNumber(const TypeEntryCPtr &type); static bool isNumber(const AbstractMetaType &type); - static bool isPyInt(const TypeEntry *type); + static bool isPyInt(const TypeEntryCPtr &type); static bool isPyInt(const AbstractMetaType &type); - /// Returns whether the underlying type is a value type with copy constructor only - static bool isValueTypeWithCopyConstructorOnly(const ApiExtractorResult &api, - const TypeEntry *type); - static bool isValueTypeWithCopyConstructorOnly(const ApiExtractorResult &api, - const AbstractMetaType &type); - /// Returns whether the type (function argument) is a value type with - /// copy constructor only is passed as value or const-ref and thus - /// no default value can be constructed. - static bool valueTypeWithCopyConstructorOnlyPassed(const ApiExtractorResult &api, - const AbstractMetaType &type); - static bool isNullPtr(const QString &value); static QString converterObject(const AbstractMetaType &type) ; - static QString converterObject(const TypeEntry *type); + static QString converterObject(const TypeEntryCPtr &type); - static QString cpythonBaseName(const AbstractMetaClass *metaClass); - static QString cpythonBaseName(const TypeEntry *type); + static QString cpythonBaseName(const AbstractMetaClassCPtr &metaClass); + static QString cpythonBaseName(const TypeEntryCPtr &type); + static QString containerCpythonBaseName(const ContainerTypeEntryCPtr &ctype); static QString cpythonBaseName(const AbstractMetaType &type); - static QString cpythonTypeName(const AbstractMetaClass *metaClass); - static QString cpythonTypeName(const TypeEntry *type); - static QString cpythonTypeNameExt(const TypeEntry *type); - static QString cpythonTypeNameExt(const AbstractMetaType &type) ; - QString cpythonCheckFunction(const TypeEntry *type, bool genericNumberType = false) const; - QString cpythonCheckFunction(AbstractMetaType metaType, bool genericNumberType = false) const; - /** - * Receives the argument \p type and tries to find the appropriate AbstractMetaType for it - * or a custom type check. - * \param type A string representing the type to be discovered. - * \param metaType A pointer to an AbstractMetaType pointer, to where write a new meta type object - * if one is produced from the \p type string. This object must be deallocated by - * the caller. It will set the target variable to nullptr, is \p type is a Python type. - * \return A custom check if \p type is a custom type, or an empty string if \p metaType - * receives an existing type object. - */ - struct CPythonCheckFunctionResult - { - QString checkFunction; - std::optional<AbstractMetaType> type; - }; - static CPythonCheckFunctionResult guessCPythonCheckFunction(const QString &type); - static QString cpythonIsConvertibleFunction(const ApiExtractorResult &api, - const TypeEntry *type, - bool genericNumberType = false, - bool checkExact = false); - QString cpythonIsConvertibleFunction(AbstractMetaType metaType, - bool genericNumberType = false) const; - QString cpythonIsConvertibleFunction(const AbstractMetaArgument &metaArg, - bool genericNumberType = false) const; - - static QString cpythonToCppConversionFunction(const AbstractMetaClass *metaClass) ; - static QString cpythonToCppConversionFunction(const AbstractMetaType &type, - const AbstractMetaClass *context = nullptr); - static QString cpythonToPythonConversionFunction(const AbstractMetaType &type, - const AbstractMetaClass *context = nullptr); - static QString cpythonToPythonConversionFunction(const AbstractMetaClass *metaClass); - static QString cpythonToPythonConversionFunction(const TypeEntry *type); + static QString cpythonTypeName(const AbstractMetaClassCPtr &metaClass); + static QString cpythonTypeName(const TypeEntryCPtr &type); + static QString cpythonTypeNameExtSet(const TypeEntryCPtr &type); + static QString cpythonTypeNameExtSet(const AbstractMetaType &type); + static QString cpythonTypeNameExt(const TypeEntryCPtr &type); + static QString cpythonTypeNameExt(const AbstractMetaType &type); + static QString cpythonCheckFunction(TypeEntryCPtr type); + static QString cpythonCheckFunction(AbstractMetaType metaType); + static QString cpythonIsConvertibleFunction(const TypeEntryCPtr &type); + static QString cpythonIsConvertibleFunction(const AbstractMetaType &metaType); + static QString cpythonIsConvertibleFunction(const AbstractMetaArgument &metaArg); + + static QString cpythonToCppConversionFunction(const AbstractMetaClassCPtr &metaClass) ; + static QString cpythonToCppConversionFunction(const AbstractMetaType &type); + static QString cpythonToPythonConversionFunction(const AbstractMetaType &type); + static QString cpythonToPythonConversionFunction(const AbstractMetaClassCPtr &metaClass); + static QString cpythonToPythonConversionFunction(const TypeEntryCPtr &type); static QString cpythonFunctionName(const AbstractMetaFunctionCPtr &func) ; static QString cpythonMethodDefinitionName(const AbstractMetaFunctionCPtr &func); - static QString cpythonGettersSettersDefinitionName(const AbstractMetaClass *metaClass); - static QString cpythonGetattroFunctionName(const AbstractMetaClass *metaClass); - static QString cpythonSetattroFunctionName(const AbstractMetaClass *metaClass); + static QString cpythonGettersSettersDefinitionName(const AbstractMetaClassCPtr &metaClass); + static QString cpythonGetattroFunctionName(const AbstractMetaClassCPtr &metaClass); + static QString cpythonSetattroFunctionName(const AbstractMetaClassCPtr &metaClass); static QString cpythonGetterFunctionName(const AbstractMetaField &metaField); static QString cpythonSetterFunctionName(const AbstractMetaField &metaField); static QString cpythonGetterFunctionName(const QPropertySpec &property, - const AbstractMetaClass *metaClass); + const AbstractMetaClassCPtr &metaClass); static QString cpythonSetterFunctionName(const QPropertySpec &property, - const AbstractMetaClass *metaClass); - static QString cpythonWrapperCPtr(const AbstractMetaClass *metaClass, - const QString &argName = QLatin1String("self")); - static QString cpythonWrapperCPtr(const AbstractMetaType &metaType, + const AbstractMetaClassCPtr &metaClass); + static QString cpythonWrapperCPtr(const AbstractMetaClassCPtr &metaClass, + const QString &argName = QLatin1StringView("self")); + static QString cpythonWrapperCPtr(const AbstractMetaType &metaType, const QString &argName); - static QString cpythonWrapperCPtr(const TypeEntry *type, const QString &argName); - - /// Guesses the scope to where belongs an argument's default value. - QString guessScopeForDefaultValue(const AbstractMetaFunctionCPtr &func, - const AbstractMetaArgument &arg) const; - QString guessScopeForDefaultFlagsValue(const AbstractMetaFunctionCPtr &func, - const AbstractMetaArgument &arg, - const QString &value) const; + static QString cpythonWrapperCPtr(const TypeEntryCPtr &type, const QString &argName); - static QString cpythonEnumName(const EnumTypeEntry *enumEntry); + static QString cpythonEnumName(const EnumTypeEntryCPtr &enumEntry); static QString cpythonEnumName(const AbstractMetaEnum &metaEnum); - static QString cpythonFlagsName(const FlagsTypeEntry *flagsEntry); + static QString cpythonFlagsName(const FlagsTypeEntryCPtr &flagsEntry); static QString cpythonFlagsName(const AbstractMetaEnum *metaEnum); - /// Returns the special cast function name, the function used to proper cast class with multiple inheritance. - static QString cpythonSpecialCastFunctionName(const AbstractMetaClass *metaClass); + /// Returns the special cast function name, the function used to proper cast + /// class with multiple inheritance. + static QString cpythonSpecialCastFunctionName(const AbstractMetaClassCPtr &metaClass); - static QString getFormatUnitString(const AbstractMetaFunctionCPtr &func, bool incRef = false); - - /// Returns the file name for the module global header. If no module name is provided the current will be used. + /// Returns the file name for the module global header. If no module name + /// is provided the current will be used. static QString getModuleHeaderFileName(const QString &moduleName = QString()); static QString getPrivateModuleHeaderFileName(const QString &moduleName = QString()); - OptionDescriptions options() const override; - bool handleOption(const QString &key, const QString &value) override; + /// Includes for header (native wrapper class) or binding source + QList<IncludeGroup> classIncludes(const AbstractMetaClassCPtr &metaClass) const; /// Returns true if the user enabled the so called "parent constructor heuristic". - bool useCtorHeuristic() const; + static bool useCtorHeuristic(); /// Returns true if the user enabled the so called "return value heuristic". - bool useReturnValueHeuristic() const; + static bool useReturnValueHeuristic(); /// Returns true if the generator should use the result of isNull()const to compute boolean casts. - bool useIsNullAsNbNonZero() const; + static bool useIsNullAsNbBool(); + /// Whether to generate lean module headers + static bool leanHeaders(); /// Returns true if the generator should use operator bool to compute boolean casts. - bool useOperatorBoolAsNbNonZero() const; - /// Returns true if the generated code should use the "#define protected public" hack. - bool avoidProtectedHack() const; + static bool useOperatorBoolAsNbBool(); + /// Generate implicit conversions of function arguments + static bool generateImplicitConversions(); + static QString cppApiVariableNameOld(const QString &moduleName = {}); static QString cppApiVariableName(const QString &moduleName = QString()); static QString pythonModuleObjectName(const QString &moduleName = QString()); static QString convertersVariableName(const QString &moduleName = QString()); /// Returns the type index variable name for a given class. - static QString getTypeIndexVariableName(const AbstractMetaClass *metaClass); + static QString getTypeIndexVariableName(const AbstractMetaClassCPtr &metaClass); /// Returns the type index variable name for a given typedef for a template /// class instantiation made of the template class and the instantiation values - static QString getTypeAlternateTemplateIndexVariableName(const AbstractMetaClass *metaClass); - static QString getTypeIndexVariableName(const TypeEntry *type); + static QString getTypeAlternateTemplateIndexVariableName(const AbstractMetaClassCPtr &metaClass); + static QString getTypeIndexVariableName(TypeEntryCPtr type); static QString getTypeIndexVariableName(const AbstractMetaType &type) ; - /// Returns true if the user don't want verbose error messages on the generated bindings. - bool verboseErrorMessagesDisabled() const; + /// Collect all type names as an array for initializing the type/name struct. + void collectFullTypeNamesArray(QStringList &typeNames); - /** - * Builds an AbstractMetaType object from a QString. - * Returns nullptr if no type could be built from the string. - * \param typeSignature The string describing the type to be built. - * \return A new AbstractMetaType object that must be deleted by the caller, - * or a nullptr pointer in case of failure. - */ - static std::optional<AbstractMetaType> - buildAbstractMetaTypeFromString(QString typeSignature, - QString *errorMessage = nullptr); - - /// Creates an AbstractMetaType object from a TypeEntry. - static AbstractMetaType - buildAbstractMetaTypeFromTypeEntry(const TypeEntry *typeEntry); - /// Creates an AbstractMetaType object from an AbstractMetaClass. - static AbstractMetaType - buildAbstractMetaTypeFromAbstractMetaClass(const AbstractMetaClass *metaClass); - - static void writeMinimalConstructorExpression(TextStream &s, const ApiExtractorResult &api, - const AbstractMetaType &type, - const QString &defaultCtor = QString()); - static void writeMinimalConstructorExpression(TextStream &s, const ApiExtractorResult &api, - const TypeEntry *type, - const QString &defaultCtor = QString()); + /// Returns true if the user don't want verbose error messages on the generated bindings. + static bool verboseErrorMessagesDisabled(); void collectContainerTypesFromConverterMacros(const QString &code, bool toPythonMacro); @@ -374,42 +338,45 @@ protected: const AbstractMetaFunctionCPtr &metaFunc, Options options = NoOption); - static void writeUnusedVariableCast(TextStream &s, const QString &variableName); - - AbstractMetaFunctionCList filterFunctions(const AbstractMetaClass *metaClass) const; - // All data about extended converters: the type entries of the target type, and a // list of AbstractMetaClasses accepted as argument for the conversion. - using ExtendedConverterData = QHash<const TypeEntry *, AbstractMetaClassCList>; + using ExtendedConverterData = QHash<TypeEntryCPtr, AbstractMetaClassCList>; /// Returns all extended conversions for the current module. ExtendedConverterData getExtendedConverters() const; /// Returns a list of converters for the non wrapper types of the current module. - static QList<const CustomConversion *> getPrimitiveCustomConversions() ; + static QList<CustomConversionPtr> getPrimitiveCustomConversions(); /// Returns true if the Python wrapper for the received OverloadData must accept a list of arguments. - static bool pythonFunctionWrapperUsesListOfArguments(const OverloadData &overloadData); + bool pythonFunctionWrapperUsesListOfArguments(const AbstractMetaFunctionCPtr &func) const; static const QRegularExpression &convertToCppRegEx() { return typeSystemConvRegExps()[TypeSystemToCppFunction]; } static QString pythonArgsAt(int i); - static const QHash<QString, QString> &formatUnits(); + /// Return the format character for C++->Python->C++ conversion (Py_BuildValue) + static const QHash<QString, QChar> &formatUnits(); + + static QString stdMove(const QString &c); private: static QString getModuleHeaderFileBaseName(const QString &moduleName = QString()); static QString cpythonGetterFunctionName(const QString &name, - const AbstractMetaClass *enclosingClass); + const AbstractMetaClassCPtr &enclosingClass); static QString cpythonSetterFunctionName(const QString &name, - const AbstractMetaClass *enclosingClass); + const AbstractMetaClassCPtr &enclosingClass); - static const GeneratorClassInfoCacheEntry &getGeneratorClassInfo(const AbstractMetaClass *scope); - static FunctionGroups getFunctionGroupsImpl(const AbstractMetaClass *scope); - static bool classNeedsGetattroFunctionImpl(const AbstractMetaClass *metaClass); + static const GeneratorClassInfoCacheEntry & + getGeneratorClassInfo(const AbstractMetaClassCPtr &scope); + static FunctionGroups getFunctionGroupsImpl(const AbstractMetaClassCPtr &scope); + static QList<AbstractMetaFunctionCList> + getNumberProtocolOperators(const AbstractMetaClassCPtr &metaClass); + static BoolCastFunctionOptional getBoolCast(const AbstractMetaClassCPtr &metaClass); + static bool classNeedsGetattroFunctionImpl(const AbstractMetaClassCPtr &metaClass); QString translateTypeForWrapperMethod(const AbstractMetaType &cType, - const AbstractMetaClass *context, + const AbstractMetaClassCPtr &context, Options opt = NoOption) const; /** @@ -418,16 +385,10 @@ private: * \param func the metafunction to be searched in subclasses. * \param seen the function's minimal signatures already seen. */ - static AbstractMetaFunctionCList getInheritedOverloads(const AbstractMetaFunctionCPtr & func, - QSet<QString> *seen); + static void getInheritedOverloads(const AbstractMetaClassCPtr &scope, + AbstractMetaFunctionCList *overloads); + - /** - * Returns all overloads for a function named \p functionName. - * \param scope scope used to search for overloads. - * \param functionName the function name. - */ - AbstractMetaFunctionCList getFunctionOverloads(const AbstractMetaClass *scope, - const QString &functionName) const; /** * Write a function argument in the C++ in the text stream \p s. * This function just call \code s << argumentString(); \endcode @@ -453,7 +414,7 @@ private: QString functionReturnType(const AbstractMetaFunctionCPtr &func, Options options = NoOption) const; /// Utility function for writeCodeSnips. - using ArgumentVarReplacementPair = QPair<AbstractMetaArgument, QString>; + using ArgumentVarReplacementPair = std::pair<AbstractMetaArgument, QString>; using ArgumentVarReplacementList = QList<ArgumentVarReplacementPair>; static ArgumentVarReplacementList getArgumentReplacement(const AbstractMetaFunctionCPtr &func, @@ -461,7 +422,7 @@ private: const AbstractMetaArgument *lastArg); /// Returns a string with the user's custom code snippets that comply with \p position and \p language. - static QString getCodeSnippets(const CodeSnipList &codeSnips, + static QString getCodeSnippets(const QList<CodeSnip> &codeSnips, TypeSystem::CodeSnipPosition position, TypeSystem::Language language); @@ -515,14 +476,7 @@ private: void replaceTemplateVariables(QString &code, const AbstractMetaFunctionCPtr &func) const; - bool m_useCtorHeuristic = false; - bool m_userReturnValueHeuristic = false; - bool m_usePySideExtensions = false; - bool m_verboseErrorMessagesDisabled = false; - bool m_useIsNullAsNbNonZero = false; - bool m_useOperatorBoolAsNbNonZero = false; - bool m_avoidProtectedHack = false; - bool m_wrapperDiagnostics = false; + static ShibokenGeneratorOptions m_options; /// Type system converter variable replacement names and regular expressions. static const QHash<int, QString> &typeSystemConvName(); @@ -531,6 +485,7 @@ private: static const TypeSystemConverterRegExps &typeSystemConvRegExps(); }; +Q_DECLARE_OPERATORS_FOR_FLAGS(ShibokenGenerator::FunctionGeneration); Q_DECLARE_OPERATORS_FOR_FLAGS(ShibokenGenerator::AttroCheck); #endif // SHIBOKENGENERATOR_H |