diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-08-05 13:55:56 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:17:08 -0300 |
commit | 50aef1dd4836b5019c60d31c54501ebcd37f72cd (patch) | |
tree | 3e9f41435c3ee0da5fdb5ee32b5b9900ad5a5259 /generator/shibokengenerator.cpp | |
parent | 08f29f0d8f456eb1f994b05c21fd04468c95329c (diff) |
Improved guessCPythonCheckFunction method to produce an AbstractMetaType for known types.
This is in opposition of simply returning a string with a custom type
check. The details are in the docstring in ShibokenGenerator header.
Also added a new modification test and refactored here and there in the
sample binding type system.
Diffstat (limited to 'generator/shibokengenerator.cpp')
-rw-r--r-- | generator/shibokengenerator.cpp | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/generator/shibokengenerator.cpp b/generator/shibokengenerator.cpp index 3e5b8eabb..17cd31a91 100644 --- a/generator/shibokengenerator.cpp +++ b/generator/shibokengenerator.cpp @@ -860,8 +860,18 @@ bool ShibokenGenerator::visibilityModifiedToPrivate(const AbstractMetaFunction* QString ShibokenGenerator::cpythonCheckFunction(const AbstractMetaType* metaType, bool genericNumberType) { - if (metaType->typeEntry()->isCustom()) - return guessCPythonCheckFunction(metaType->typeEntry()->name()); + AbstractMetaType* type; + std::auto_ptr<AbstractMetaType> type_autoptr; + QString customCheck; + if (metaType->typeEntry()->isCustom()) { + customCheck = guessCPythonCheckFunction(metaType->typeEntry()->name(), &type); + if (type) { + type_autoptr = std::auto_ptr<AbstractMetaType>(type); + metaType = type; + } + if (!customCheck.isEmpty()) + return customCheck; + } QString baseName = cpythonBaseName(metaType); if (isNumber(baseName)) @@ -878,8 +888,17 @@ QString ShibokenGenerator::cpythonCheckFunction(const AbstractMetaType* metaType QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry* type, bool genericNumberType) { - if (type->isCustom()) - return guessCPythonCheckFunction(type->name()); + AbstractMetaType* metaType; + std::auto_ptr<AbstractMetaType> metaType_autoptr; + QString customCheck; + if (type->isCustom()) { + customCheck = guessCPythonCheckFunction(type->name(), &metaType); + if (metaType) { + metaType_autoptr = std::auto_ptr<AbstractMetaType>(metaType); + return cpythonCheckFunction(metaType, genericNumberType); + } + return customCheck; + } QString baseName = cpythonBaseName(type); if (isNumber(baseName)) @@ -892,18 +911,18 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry* type, bool gene return QString("%1checkType").arg(baseName); } -QString ShibokenGenerator::guessCPythonCheckFunction(const QString& type) +QString ShibokenGenerator::guessCPythonCheckFunction(const QString& type, AbstractMetaType** metaType) { + *metaType = 0; if (type == "PyTypeObject") return "PyType_Check"; if (type == "PyBuffer") return "Shiboken::Buffer::checkType"; - AbstractMetaType* metaType = buildAbstractMetaTypeFromString(type); - std::auto_ptr<const AbstractMetaType> metaType_autoptr(metaType); - if (metaType && !metaType->typeEntry()->isCustom()) - return cpythonCheckFunction(metaType); + *metaType = buildAbstractMetaTypeFromString(type); + if (*metaType && !(*metaType)->typeEntry()->isCustom()) + return QString(); return QString("%1_Check").arg(type); } @@ -939,8 +958,18 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry* type, b QString ShibokenGenerator::cpythonIsConvertibleFunction(const AbstractMetaType* metaType, bool genericNumberType) { - if (metaType->typeEntry()->isCustom()) - return guessCPythonCheckFunction(metaType->typeEntry()->name()); + AbstractMetaType* type; + std::auto_ptr<AbstractMetaType> type_autoptr; + QString customCheck; + if (metaType->typeEntry()->isCustom()) { + customCheck = guessCPythonCheckFunction(metaType->typeEntry()->name(), &type); + if (type) { + type_autoptr = std::auto_ptr<AbstractMetaType>(type); + metaType = type; + } + if (!customCheck.isEmpty()) + return customCheck; + } QString baseName = cpythonBaseName(metaType); if (isNumber(baseName)) |