diff options
Diffstat (limited to 'sources/shiboken2')
-rw-r--r-- | sources/shiboken2/ApiExtractor/messages.cpp | 17 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/messages.h | 2 | ||||
-rw-r--r-- | sources/shiboken2/doc/typesystemvariables.rst | 23 | ||||
-rw-r--r-- | sources/shiboken2/generator/shiboken2/shibokengenerator.cpp | 9 |
4 files changed, 47 insertions, 4 deletions
diff --git a/sources/shiboken2/ApiExtractor/messages.cpp b/sources/shiboken2/ApiExtractor/messages.cpp index a6e75aac3..5b3a57fcc 100644 --- a/sources/shiboken2/ApiExtractor/messages.cpp +++ b/sources/shiboken2/ApiExtractor/messages.cpp @@ -311,6 +311,23 @@ QString msgCannotUseEnumAsInt(const QString &name) "Compilation errors may occur when used as a function argument."); } +QString msgConversionTypesDiffer(const QString &varType, const QString &conversionType) +{ + QString result; + QTextStream str(&result); + str << "Types of receiver variable ('" << varType + << "') and %%CONVERTTOCPP type system variable ('" << conversionType + << "') differ"; + QString strippedVarType = varType; + QString strippedConversionType = conversionType; + TypeInfo::stripQualifiers(&strippedVarType); + TypeInfo::stripQualifiers(&strippedConversionType); + if (strippedVarType == strippedConversionType) + str << " in qualifiers. Please make sure the type is a distinct token"; + str << '.'; + return result; +} + // main.cpp QString msgLeftOverArguments(const QMap<QString, QString> &remainingArgs) diff --git a/sources/shiboken2/ApiExtractor/messages.h b/sources/shiboken2/ApiExtractor/messages.h index ab2bf64b6..2fee0de8f 100644 --- a/sources/shiboken2/ApiExtractor/messages.h +++ b/sources/shiboken2/ApiExtractor/messages.h @@ -115,6 +115,8 @@ QString msgCannotOpenForWriting(const QFile &f); QString msgCannotUseEnumAsInt(const QString &name); +QString msgConversionTypesDiffer(const QString &varType, const QString &conversionType); + QString msgLeftOverArguments(const QMap<QString, QString> &remainingArgs); QString msgInvalidVersion(const QString &package, const QString &version); diff --git a/sources/shiboken2/doc/typesystemvariables.rst b/sources/shiboken2/doc/typesystemvariables.rst index a07ba0d8c..b1b9bbfe6 100644 --- a/sources/shiboken2/doc/typesystemvariables.rst +++ b/sources/shiboken2/doc/typesystemvariables.rst @@ -126,6 +126,29 @@ Variables Replaced by a |project| conversion call that converts a Python variable to a C++ variable of the type indicated by ``CPPTYPE``. + Typically, this is a variable assignment: + + .. code-block:: c++ + + double value = %CONVERTTOCPP[double](pyValue); + + Pointer assignments are also possible: + + .. code-block:: c++ + + void f(double *valuePtr) + { + *valuePtr = %CONVERTTOCPP[double](pyValue); + + Note however, that for variable definitions, the type must + be a space-delimited token: + + .. code-block:: c++ + + double * valuePtr = %CONVERTTOCPP[double](pyValue); + + since it otherwise would be indistinguishable from the pointer assignment + above. .. _converttopython: diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 8e27777d6..e41c91716 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -149,6 +149,8 @@ ShibokenGenerator::ShibokenGenerator() const char CHECKTYPE_REGEX[] = R"(%CHECKTYPE\[([^\[]*)\]\()"; const char ISCONVERTIBLE_REGEX[] = R"(%ISCONVERTIBLE\[([^\[]*)\]\()"; const char CONVERTTOPYTHON_REGEX[] = R"(%CONVERTTOPYTHON\[([^\[]*)\]\()"; + // Capture a '*' leading the variable name into the target + // so that "*valuePtr = %CONVERTTOCPP..." works as expected. const char CONVERTTOCPP_REGEX[] = R"((\*?%?[a-zA-Z_][\w\.]*(?:\[[^\[^<^>]+\])*)(?:\s+)=(?:\s+)%CONVERTTOCPP\[([^\[]*)\]\()"; m_typeSystemConvRegEx[TypeSystemCheckFunction] = QRegularExpression(QLatin1String(CHECKTYPE_REGEX)); @@ -2044,10 +2046,9 @@ void ShibokenGenerator::replaceConverterTypeSystemVariable(TypeSystemConverterVa varType = miniNormalizer(varType); QString varName = list.at(1).trimmed(); if (!varType.isEmpty()) { - if (varType != conversionType->cppSignature()) { - qFatal("Types of receiver variable ('%s') and %%CONVERTTOCPP type system variable ('%s') differ.", - qPrintable(varType), qPrintable(conversionType->cppSignature())); - } + const QString conversionSignature = conversionType->cppSignature(); + if (varType != conversionSignature) + qFatal("%s", qPrintable(msgConversionTypesDiffer(varType, conversionSignature))); c << getFullTypeName(conversionType) << ' ' << varName; writeMinimalConstructorExpression(c, conversionType); c << ';' << endl; |