diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-03-28 10:46:44 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2017-03-28 15:14:05 +0000 |
commit | 7e508c15e9f6037a332b9055b04146287b20fb8f (patch) | |
tree | 5fecb66fed0a0fb07e1711ac8ee3fb85c4367062 | |
parent | b294c7e0adb23b9063ddf1cd76cf1b5244761919 (diff) |
Generators: Generate reinterpret_cast<> for SbkObjectType *
Change-Id: I27196d4f5be0257e3ab87c291e4ecb6ff234a505
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | generator/shiboken2/cppgenerator.cpp | 30 | ||||
-rw-r--r-- | generator/shiboken2/shibokengenerator.cpp | 68 |
2 files changed, 54 insertions, 44 deletions
diff --git a/generator/shiboken2/cppgenerator.cpp b/generator/shiboken2/cppgenerator.cpp index f0c2fe4..f5bcdce 100644 --- a/generator/shiboken2/cppgenerator.cpp +++ b/generator/shiboken2/cppgenerator.cpp @@ -2229,8 +2229,8 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream& s, if (!defaultValue.isEmpty()) s << '{' << endl << INDENT; - s << "if (Shiboken::Conversions::isImplicitConversion((SbkObjectType*)"; - s << cpythonTypeNameExt(type) << ", " << pythonToCppFunc << "))" << endl; + s << "if (Shiboken::Conversions::isImplicitConversion(reinterpret_cast<const SbkObjectType *>(" + << cpythonTypeNameExt(type) << "), " << pythonToCppFunc << "))" << endl; { Indentation indent(INDENT); s << INDENT << pythonToCppFunc << '(' << pyIn << ", &" << cppOutAux << ");" << endl; @@ -3207,8 +3207,8 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f && !injectedCodeHasReturnValueAttribution(func, TypeSystem::TargetLangCode)) { s << INDENT << PYTHON_RETURN_VAR " = "; if (isObjectTypeUsedAsValueType(func->type())) { - s << "Shiboken::Object::newObject((SbkObjectType*)" << cpythonTypeNameExt(func->type()->typeEntry()); - s << ", " << CPP_RETURN_VAR << ", true, true)"; + s << "Shiboken::Object::newObject(reinterpret_cast<SbkObjectType *>(" << cpythonTypeNameExt(func->type()->typeEntry()) + << "), " << CPP_RETURN_VAR << ", true, true)"; } else { writeToPythonConversion(s, func->type(), func->ownerClass(), QLatin1String(CPP_RETURN_VAR)); } @@ -3503,9 +3503,9 @@ void CppGenerator::writeExtendedConverterInitialization(QTextStream& s, const Ty { s << INDENT << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << endl; foreach (const AbstractMetaClass* sourceClass, conversions) { - QString converterVar = QString::fromLatin1("(SbkObjectType*)%1[%2]") - .arg(cppApiVariableName(externalType->targetLangPackage()), - getTypeIndexVariableName(externalType)); + const QString converterVar = QLatin1String("reinterpret_cast<SbkObjectType *>(") + + cppApiVariableName(externalType->targetLangPackage()) + QLatin1Char('[') + + getTypeIndexVariableName(externalType) + QLatin1String("])"); QString sourceTypeName = fixedCppTypeName(sourceClass->typeEntry()); QString targetTypeName = fixedCppTypeName(externalType); QString toCpp = pythonToCppFunctionName(sourceTypeName, targetTypeName); @@ -4028,10 +4028,10 @@ void CppGenerator::writeGetterFunction(QTextStream &s, << CPP_SELF_VAR << ")) {\n"; { Indentation indent(INDENT); - s << INDENT << "pyOut = (PyObject*)Shiboken::Object::findColocatedChild(" - << "(SbkObject*)self , (SbkObjectType*)" + s << INDENT << "pyOut = reinterpret_cast<PyObject *>(Shiboken::Object::findColocatedChild(" + << "reinterpret_cast<SbkObject *>(self), reinterpret_cast<const SbkObjectType *>(" << cpythonTypeNameExt(fieldType) - << ");" << "\n"; + << ")));\n"; s << INDENT << "if (pyOut) {Py_IncRef(pyOut); return pyOut;}\n"; } s << INDENT << "}\n"; @@ -4046,8 +4046,8 @@ void CppGenerator::writeGetterFunction(QTextStream &s, s << INDENT << "}\n"; // Create and register new wrapper s << INDENT << "pyOut = "; - s << "Shiboken::Object::newObject((SbkObjectType*)" << cpythonTypeNameExt(fieldType); - s << ", " << cppField << ", false, true);" << endl; + s << "Shiboken::Object::newObject(reinterpret_cast<SbkObjectType *>(" << cpythonTypeNameExt(fieldType) + << "), " << cppField << ", false, true);" << endl; s << INDENT << "Shiboken::Object::setParent(" PYTHON_SELF_VAR ", pyOut)"; } else { s << INDENT << "pyOut = "; @@ -4357,8 +4357,8 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu { Indentation indent(INDENT); s << INDENT << "PyObject* anonEnumItem = PyInt_FromLong(" << enumValueText << ");" << endl; - s << INDENT << "if (PyDict_SetItemString(((SbkObjectType*)" << enclosingObjectVariable; - s << ")->super.ht_type.tp_dict, \"" << enumValue->name() << "\", anonEnumItem) < 0)" << endl; + s << INDENT << "if (PyDict_SetItemString(reinterpret_cast<SbkObjectType *>(" << enclosingObjectVariable + << ")->super.ht_type.tp_dict, \"" << enumValue->name() << "\", anonEnumItem) < 0)" << endl; { Indentation indent(INDENT); s << INDENT << "return " << m_currentErrorCode << ';' << endl; @@ -4677,7 +4677,7 @@ void CppGenerator::writeClassRegister(QTextStream &s, // Base type if (metaClass->baseClass()) { - s << ", (SbkObjectType*)" << cpythonTypeNameExt(metaClass->baseClass()->typeEntry()); + s << ", reinterpret_cast<SbkObjectType *>(" << cpythonTypeNameExt(metaClass->baseClass()->typeEntry()) << ')'; // The other base types if (metaClass->baseClassNames().size() > 1) s << ", " << pyTypeBasesVariable; diff --git a/generator/shiboken2/shibokengenerator.cpp b/generator/shiboken2/shibokengenerator.cpp index 766265b..be39143 100644 --- a/generator/shiboken2/shibokengenerator.cpp +++ b/generator/shiboken2/shibokengenerator.cpp @@ -1082,12 +1082,15 @@ QString ShibokenGenerator::cpythonCheckFunction(const AbstractMetaType* metaType || type == ContainerTypeEntry::SetContainer || type == ContainerTypeEntry::QueueContainer) { const AbstractMetaType* type = metaType->instantiations().first(); - if (isPointerToWrapperType(type)) + if (isPointerToWrapperType(type)) { typeCheck += QString::fromLatin1("checkSequenceTypes(%1, ").arg(cpythonTypeNameExt(type)); - else if (isWrapperType(type)) - typeCheck += QString::fromLatin1("convertibleSequenceTypes((SbkObjectType*)%1, ").arg(cpythonTypeNameExt(type)); - else + } else if (isWrapperType(type)) { + typeCheck += QLatin1String("convertibleSequenceTypes(reinterpret_cast<const SbkObjectType *>("); + typeCheck += cpythonTypeNameExt(type); + typeCheck += QLatin1String("), "); + } else { typeCheck += QString::fromLatin1("convertibleSequenceTypes(%1, ").arg(converterObject(type)); + } } else if (type == ContainerTypeEntry::MapContainer || type == ContainerTypeEntry::MultiMapContainer || type == ContainerTypeEntry::HashContainer @@ -1173,11 +1176,13 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry* type, bool /* checkExact */) { if (isWrapperType(type)) { - QString isConv = (type->isValue() && !isValueTypeWithCopyConstructorOnly(type)) + QString result = QLatin1String("Shiboken::Conversions::"); + result += (type->isValue() && !isValueTypeWithCopyConstructorOnly(type)) ? QLatin1String("isPythonToCppValueConvertible") : QLatin1String("isPythonToCppPointerConvertible"); - return QString::fromLatin1("Shiboken::Conversions::%1((SbkObjectType*)%2, ") - .arg(isConv, cpythonTypeNameExt(type)); + result += QLatin1String("(reinterpret_cast<SbkObjectType *>(") + + cpythonTypeNameExt(type) + QLatin1String("), "); + return result; } return QString::fromLatin1("Shiboken::Conversions::isPythonToCppConvertible(%1, ") .arg(converterObject(type)); @@ -1196,15 +1201,16 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const AbstractMetaType* } if (isWrapperType(metaType)) { - QString isConv; + QString result = QLatin1String("Shiboken::Conversions::"); if (isPointer(metaType) || isValueTypeWithCopyConstructorOnly(metaType)) - isConv = QLatin1String("isPythonToCppPointerConvertible"); + result += QLatin1String("isPythonToCppPointerConvertible"); else if (metaType->referenceType() == LValueReference) - isConv = QLatin1String("isPythonToCppReferenceConvertible"); + result += QLatin1String("isPythonToCppReferenceConvertible"); else - isConv = QLatin1String("isPythonToCppValueConvertible"); - return QStringLiteral("Shiboken::Conversions::%1((SbkObjectType*)%2, ") - .arg(isConv, cpythonTypeNameExt(metaType)); + result += QLatin1String("isPythonToCppValueConvertible"); + result += QLatin1String("(reinterpret_cast<const SbkObjectType *>(") + + cpythonTypeNameExt(metaType) + QLatin1String("), "); + return result; } return QStringLiteral("Shiboken::Conversions::isPythonToCppConvertible(%1, ") .arg(converterObject(metaType)); @@ -1217,16 +1223,18 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const AbstractMetaArgume QString ShibokenGenerator::cpythonToCppConversionFunction(const AbstractMetaClass* metaClass) { - return QStringLiteral("Shiboken::Conversions::pythonToCppPointer((SbkObjectType*)%1, ") - .arg(cpythonTypeNameExt(metaClass->typeEntry())); + return QLatin1String("Shiboken::Conversions::pythonToCppPointer(reinterpret_cast<SbkObjectType *>(") + + cpythonTypeNameExt(metaClass->typeEntry()) + QLatin1String("), "); } + QString ShibokenGenerator::cpythonToCppConversionFunction(const AbstractMetaType *type, const AbstractMetaClass * /* context */) { if (isWrapperType(type)) { - return QStringLiteral("Shiboken::Conversions::pythonToCpp%1((SbkObjectType*)%2, ") - .arg(isPointer(type) ? QLatin1String("Pointer") : QLatin1String("Copy")) - .arg(cpythonTypeNameExt(type)); + return QLatin1String("Shiboken::Conversions::pythonToCpp") + + (isPointer(type) ? QLatin1String("Pointer") : QLatin1String("Copy")) + + QLatin1String("(reinterpret_cast<SbkObjectType *>(") + + cpythonTypeNameExt(type) + QLatin1String("), "); } return QStringLiteral("Shiboken::Conversions::pythonToCppCopy(%1, ") .arg(converterObject(type)); @@ -1243,9 +1251,12 @@ QString ShibokenGenerator::cpythonToPythonConversionFunction(const AbstractMetaT conversion = QLatin1String("copy"); else conversion = QLatin1String("pointer"); - return QStringLiteral("Shiboken::Conversions::%1ToPython((SbkObjectType*)%2, %3") - .arg(conversion, cpythonTypeNameExt(type), - conversion == QLatin1String("pointer") ? QString() : QLatin1String("&")); + QString result = QLatin1String("Shiboken::Conversions::") + conversion + + QLatin1String("ToPython(reinterpret_cast<const SbkObjectType *>(") + + cpythonTypeNameExt(type) + QLatin1String("), "); + if (conversion != QLatin1String("pointer")) + result += QLatin1Char('&'); + return result; } return QStringLiteral("Shiboken::Conversions::copyToPython(%1, %2") .arg(converterObject(type), @@ -1260,14 +1271,13 @@ QString ShibokenGenerator::cpythonToPythonConversionFunction(const AbstractMetaC QString ShibokenGenerator::cpythonToPythonConversionFunction(const TypeEntry* type) { if (isWrapperType(type)) { - QString conversion; - if (type->isValue()) - conversion = QLatin1String("copy"); - else - conversion = QLatin1String("pointer"); - return QStringLiteral("Shiboken::Conversions::%1ToPython((SbkObjectType*)%2, %3") - .arg(conversion, cpythonTypeNameExt(type), - conversion == QLatin1String("pointer") ? QString() : QLatin1String("&")); + const QString conversion = type->isValue() ? QLatin1String("copy") : QLatin1String("pointer"); + QString result = QLatin1String("Shiboken::Conversions::") + conversion + + QLatin1String("ToPython(reinterpret_cast<const SbkObjectType *>(") + cpythonTypeNameExt(type) + + QLatin1String("), "); + if (conversion != QLatin1String("pointer")) + result += QLatin1Char('&'); + return result; } return QStringLiteral("Shiboken::Conversions::copyToPython(%1, &").arg(converterObject(type)); |