aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/generator/shiboken/shibokengenerator.h
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/generator/shiboken/shibokengenerator.h')
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.h109
1 files changed, 58 insertions, 51 deletions
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h
index 4189753cc..22ee73fa2 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.h
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h
@@ -7,12 +7,14 @@
#include <generator.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;
@@ -23,8 +25,18 @@ class OverloadData;
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.
@@ -32,6 +44,8 @@ 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).
@@ -75,6 +89,9 @@ 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);
static QString minimalConstructorExpression(const ApiExtractorResult &api,
@@ -93,6 +110,11 @@ protected:
FunctionGroups getGlobalFunctionGroups() const;
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.
* The function can be called multiple times without duplication.
@@ -123,6 +145,7 @@ protected:
/// 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;
/**
@@ -152,7 +175,7 @@ protected:
getMultipleInheritingClass(const AbstractMetaClassCPtr &metaClass);
static bool useOverrideCaching(const AbstractMetaClassCPtr &metaClass);
- AttroCheck checkAttroFunctionNeeds(const AbstractMetaClassCPtr &metaClass) const;
+ 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.
@@ -165,7 +188,6 @@ protected:
const QString &argumentName);
static void writeToCppConversion(TextStream &s,
const AbstractMetaType &type,
- const AbstractMetaClassCPtr &context,
const QString &inArgName,
const QString &outArgName);
static void writeToCppConversion(TextStream &s,
@@ -179,15 +201,17 @@ protected:
/// Verifies if the class should have a C++ wrapper generated for it,
/// instead of only a Python wrapper.
- bool shouldGenerateCppWrapper(const AbstractMetaClassCPtr &metaClass) const;
+ static bool shouldGenerateCppWrapper(const AbstractMetaClassCPtr &metaClass);
+
+ static bool shouldGenerateMetaObjectFunctions(const AbstractMetaClassCPtr &metaClass);
/// Returns which functions need to be generated into the wrapper class
- FunctionGeneration functionGeneration(const AbstractMetaFunctionCPtr &func) const;
+ static FunctionGeneration functionGeneration(const AbstractMetaFunctionCPtr &func);
// Return a list of implicit conversions if generation is enabled.
AbstractMetaFunctionCList implicitConversions(const TypeEntryCPtr &t) const;
- QString wrapperName(const AbstractMetaClassCPtr &metaClass) const;
+ static QString wrapperName(const AbstractMetaClassCPtr &metaClass);
static QString fullPythonClassName(const AbstractMetaClassCPtr &metaClass);
@@ -196,13 +220,16 @@ protected:
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 pythonOperatorFunctionName(const AbstractMetaFunctionCPtr &func);
+ static QList<AbstractMetaFunctionCList>
+ filterGroupedOperatorFunctions(const AbstractMetaClassCPtr &metaClass,
+ OperatorQueryOptions query);
static QString fixedCppTypeName(const TargetToNativeConversion &toNative);
static QString fixedCppTypeName(const AbstractMetaType &type);
@@ -225,19 +252,19 @@ protected:
static QString cpythonBaseName(const AbstractMetaType &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 cpythonTypeNameExt(const AbstractMetaType &type);
static QString cpythonCheckFunction(TypeEntryCPtr type);
static QString cpythonCheckFunction(AbstractMetaType metaType);
static QString cpythonIsConvertibleFunction(const TypeEntryCPtr &type);
- static QString cpythonIsConvertibleFunction(AbstractMetaType metaType);
+ static QString cpythonIsConvertibleFunction(const AbstractMetaType &metaType);
static QString cpythonIsConvertibleFunction(const AbstractMetaArgument &metaArg);
static QString cpythonToCppConversionFunction(const AbstractMetaClassCPtr &metaClass) ;
- static QString cpythonToCppConversionFunction(const AbstractMetaType &type,
- AbstractMetaClassCPtr context = {});
- static QString cpythonToPythonConversionFunction(const AbstractMetaType &type,
- AbstractMetaClassCPtr context = {});
+ static QString cpythonToCppConversionFunction(const AbstractMetaType &type);
+ static QString cpythonToPythonConversionFunction(const AbstractMetaType &type);
static QString cpythonToPythonConversionFunction(const AbstractMetaClassCPtr &metaClass);
static QString cpythonToPythonConversionFunction(const TypeEntryCPtr &type);
@@ -253,8 +280,8 @@ protected:
static QString cpythonSetterFunctionName(const QPropertySpec &property,
const AbstractMetaClassCPtr &metaClass);
static QString cpythonWrapperCPtr(const AbstractMetaClassCPtr &metaClass,
- const QString &argName = QStringLiteral("self"));
- static QString cpythonWrapperCPtr(const AbstractMetaType &metaType,
+ const QString &argName = QLatin1StringView("self"));
+ static QString cpythonWrapperCPtr(const AbstractMetaType &metaType,
const QString &argName);
static QString cpythonWrapperCPtr(const TypeEntryCPtr &type, const QString &argName);
@@ -275,21 +302,19 @@ protected:
/// Includes for header (native wrapper class) or binding source
QList<IncludeGroup> classIncludes(const AbstractMetaClassCPtr &metaClass) const;
- OptionDescriptions options() const override;
- bool handleOption(const QString &key, const QString &value) override;
-
/// 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
- bool leanHeaders() const;
+ static bool leanHeaders();
/// Returns true if the generator should use operator bool to compute boolean casts.
- bool useOperatorBoolAsNbNonZero() const;
+ static bool useOperatorBoolAsNbBool();
/// Generate implicit conversions of function arguments
- bool generateImplicitConversions() const;
+ 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());
@@ -301,8 +326,11 @@ protected:
static QString getTypeIndexVariableName(TypeEntryCPtr type);
static QString getTypeIndexVariableName(const AbstractMetaType &type) ;
+ /// Collect all type names as an array for initializing the type/name struct.
+ void collectFullTypeNamesArray(QStringList &typeNames);
+
/// Returns true if the user don't want verbose error messages on the generated bindings.
- bool verboseErrorMessagesDisabled() const;
+ static bool verboseErrorMessagesDisabled();
void collectContainerTypesFromConverterMacros(const QString &code, bool toPythonMacro);
@@ -342,6 +370,9 @@ private:
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,
@@ -383,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,
@@ -445,16 +476,7 @@ private:
void replaceTemplateVariables(QString &code,
const AbstractMetaFunctionCPtr &func) const;
- bool m_useCtorHeuristic = false;
- bool m_userReturnValueHeuristic = false;
- bool m_verboseErrorMessagesDisabled = false;
- bool m_useIsNullAsNbNonZero = false;
- // FIXME PYSIDE 7 Flip m_leanHeaders default or remove?
- bool m_leanHeaders = false;
- bool m_useOperatorBoolAsNbNonZero = false;
- // FIXME PYSIDE 7 Flip generateImplicitConversions default or remove?
- bool m_generateImplicitConversions = true;
- bool m_wrapperDiagnostics = false;
+ static ShibokenGeneratorOptions m_options;
/// Type system converter variable replacement names and regular expressions.
static const QHash<int, QString> &typeSystemConvName();
@@ -466,19 +488,4 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(ShibokenGenerator::FunctionGeneration);
Q_DECLARE_OPERATORS_FOR_FLAGS(ShibokenGenerator::AttroCheck);
-extern const QString CPP_ARG;
-extern const QString CPP_ARG_REMOVED;
-extern const QString CPP_RETURN_VAR;
-extern const QString CPP_SELF_VAR;
-extern const QString NULL_PTR;
-extern const QString PYTHON_ARG;
-extern const QString PYTHON_ARGS;
-extern const QString PYTHON_OVERRIDE_VAR;
-extern const QString PYTHON_RETURN_VAR;
-extern const QString PYTHON_TO_CPP_VAR;
-
-extern const QString CONV_RULE_OUT_VAR_SUFFIX;
-extern const QString BEGIN_ALLOW_THREADS;
-extern const QString END_ALLOW_THREADS;
-
#endif // SHIBOKENGENERATOR_H