diff options
-rw-r--r-- | shibokengenerator.cpp | 47 | ||||
-rw-r--r-- | shibokengenerator.h | 8 |
2 files changed, 52 insertions, 3 deletions
diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp index d14535cda..d20268184 100644 --- a/shibokengenerator.cpp +++ b/shibokengenerator.cpp @@ -624,9 +624,17 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry* type, bool gene QString ShibokenGenerator::guessCPythonCheckFunction(const QString& type) { - if (type == "PyTypeObject") - return "PyType_Check"; - return type+"_Check"; + QString retval; + AbstractMetaType* metaType = buildAbstractMetaTypeFromString(type); + if (metaType) { + retval = cpythonCheckFunction(metaType); + delete metaType; + } else if (type == "PyTypeObject") { + retval = "PyType_Check"; + } else { + retval = QString("%1_Check").arg(type); + } + return retval; } QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry* type) @@ -1287,6 +1295,39 @@ bool ShibokenGenerator::isCopyable(const AbstractMetaClass *metaClass) return false; } +AbstractMetaType* ShibokenGenerator::buildAbstractMetaTypeFromString(QString typeString) +{ + typeString = typeString.trimmed(); + bool isConst = typeString.startsWith("const "); + if (isConst) + typeString.remove(0, sizeof("const ") / sizeof(char) - 1); + + int indirections = typeString.count("*"); + while (typeString.endsWith("*")) { + typeString.chop(1); + typeString = typeString.trimmed(); + } + + bool isReference = typeString.endsWith("&"); + if (isReference) { + typeString.chop(1); + typeString = typeString.trimmed(); + } + + TypeEntry* typeEntry = TypeDatabase::instance()->findType(typeString); + AbstractMetaType* metaType = 0; + if (typeEntry) { + metaType = new AbstractMetaType(); + metaType->setTypeEntry(typeEntry); + metaType->setIndirections(indirections); + metaType->setReference(isReference); + metaType->setConstant(isConst); + if (metaType->name() == "char" && metaType->indirections() == 1) + metaType->setTypeUsagePattern(AbstractMetaType::NativePointerPattern); + } + return metaType; +} + /* static void dumpFunction(AbstractMetaFunctionList lst) { diff --git a/shibokengenerator.h b/shibokengenerator.h index 529027e98..52a3d7b65 100644 --- a/shibokengenerator.h +++ b/shibokengenerator.h @@ -301,6 +301,14 @@ public: /// Returns true if the user don't want verbose error messages on the generated bindings. bool verboseErrorMessagesDisabled() const; + /** + * Builds an AbstractMetaType object from a QString. + * Returns NULL if no type could be built from the string. + * \param typeString The string describing the type to be built. + * \return A new AbstractMetaType object that must be deleted by the caller, or a NULL pointer in case of failure. + */ + AbstractMetaType* buildAbstractMetaTypeFromString(QString typeString); + protected: bool doSetup(const QMap<QString, QString>& args); // verify whether the class is copyable |