diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-03-19 11:41:42 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-03-19 15:22:21 -0300 |
commit | 18939a16a6ec9963887e00fd63918b7deb740fde (patch) | |
tree | 96592157a029d190e7c97b628de5dd1d92cacaae /shibokengenerator.cpp | |
parent | 72786ec7a77908530080f1e44a12080128b8c367 (diff) |
Adds ShibokenGenerator::buildAbstractMetaTypeFromString.
This method tries to build an AbstractMetaType from a string, it is
used by guessCPythonCheckFunction to better handle type replacements
identifying types already known by the type database for the currently
generated, instead of treating said replacements as mere blobs.
Diffstat (limited to 'shibokengenerator.cpp')
-rw-r--r-- | shibokengenerator.cpp | 47 |
1 files changed, 44 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) { |