diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-10-28 12:58:10 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-10-30 14:24:20 -0300 |
commit | b01f0b159a5edf42de817fada68e9852a65e8bc9 (patch) | |
tree | b8b769100e9118dae4e5545881f8620c94ee785d | |
parent | f369860e8f9d080cf248d257aa3b2febe4093324 (diff) |
the Python check macros are generated once again since it is a
convention for every type to have the said macros; also, there are
some situations where one needs to now if a type is of this or
that kind, and not if it is convertible to other types;
the two ShibokenGenerator::cpythonCheckFunction reverted to the
previous behavior and the new stuff was moved to the methods
ShibokenGenerator::cpythonIsConvertibleFunction, and the places
from where they are called were changed accordingly
-rw-r--r-- | cppgenerator.cpp | 10 | ||||
-rw-r--r-- | headergenerator.cpp | 7 | ||||
-rw-r--r-- | shibokengenerator.cpp | 30 | ||||
-rw-r--r-- | shibokengenerator.h | 4 |
4 files changed, 36 insertions, 15 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index 62a78f1bc..4bf739d81 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -694,11 +694,11 @@ void CppGenerator::writeTypeCheck(QTextStream& s, const OverloadData* overloadDa if (implicitConvs.size() > 0) s << '('; - s << cpythonCheckFunction(argType, numberType) << '(' << argumentName << ')'; + s << cpythonIsConvertibleFunction(argType, numberType) << '(' << argumentName << ')'; foreach (const AbstractMetaFunction* ctor, implicitConvs) { s << " || "; - s << cpythonCheckFunction(ctor->arguments().first()->type(), numberType); + s << cpythonIsConvertibleFunction(ctor->arguments().first()->type(), numberType); s << '(' << argumentName << ')'; } @@ -1557,7 +1557,7 @@ void CppGenerator::writeFlagsBinaryOperator(QTextStream& s, const AbstractMetaEn Q_ASSERT(flagsEntry); QString cppName = cppEnum->typeEntry()->name(); QString cpythonName = cpythonEnumName(cppEnum); - QString checkFunction = cpythonCheckFunction(cppEnum->typeEntry()); + QString checkFunction = cpythonIsConvertibleFunction(cppEnum->typeEntry()); s << "PyObject*" << endl; s << cpythonName << "___" << pyOpName << "__(PyObject* self, PyObject* arg)" << endl; @@ -1598,7 +1598,7 @@ void CppGenerator::writeFlagsInplaceOperator(QTextStream& s, const AbstractMetaE Q_ASSERT(flagsEntry); QString cppName = cppEnum->typeEntry()->name(); QString cpythonName = cpythonEnumName(cppEnum); - QString checkFunction = cpythonCheckFunction(cppEnum->typeEntry()); + QString checkFunction = cpythonIsConvertibleFunction(cppEnum->typeEntry()); s << "PyObject*" << endl; s << cpythonName << "___" << pyOpName << "__(PyObject* self, PyObject* arg)" << endl; @@ -1638,7 +1638,7 @@ void CppGenerator::writeFlagsUnaryOperator(QTextStream& s, const AbstractMetaEnu Q_ASSERT(flagsEntry); QString cppName = cppEnum->typeEntry()->name(); QString cpythonName = cpythonEnumName(cppEnum); - QString checkFunction = cpythonCheckFunction(cppEnum->typeEntry()); + QString checkFunction = cpythonIsConvertibleFunction(cppEnum->typeEntry()); s << "PyObject*" << endl; s << cpythonName << "___" << pyOpName << "__(PyObject* self, PyObject* arg)" << endl; diff --git a/headergenerator.cpp b/headergenerator.cpp index fea228fd3..dcdfa948c 100644 --- a/headergenerator.cpp +++ b/headergenerator.cpp @@ -171,7 +171,12 @@ void HeaderGenerator::writeVirtualDispatcher(QTextStream& s, const AbstractMetaF void HeaderGenerator::writeTypeCheckMacro(QTextStream& s, const TypeEntry* type) { QString pyTypeName = cpythonTypeName(type); + QString checkFunction = cpythonCheckFunction(type); s << "PyAPI_DATA(PyTypeObject) " << pyTypeName << ';' << endl; + s << "#define " << checkFunction << "(op) PyObject_TypeCheck(op, &"; + s << pyTypeName << ')' << endl; + s << "#define " << checkFunction << "Exact(op) ((op)->ob_type == &"; + s << pyTypeName << ')' << endl; } void HeaderGenerator::writeTypeConverterDecl(QTextStream& s, const TypeEntry* type) @@ -264,7 +269,7 @@ void HeaderGenerator::writeTypeConverterImpl(QTextStream& s, const TypeEntry* ty firstImplicitIf = false; else s << "else "; - s << "if (" << cpythonCheckFunction(argType) << "(pyobj))" << endl; + s << "if (" << cpythonIsConvertibleFunction(argType) << "(pyobj))" << endl; { Indentation indent(INDENT); s << INDENT << "return " << cppName << '('; diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp index c97a4f807..121ded578 100644 --- a/shibokengenerator.cpp +++ b/shibokengenerator.cpp @@ -486,27 +486,41 @@ bool ShibokenGenerator::isReverseOperator(const AbstractMetaFunction* func) args[1]->type()->typeEntry() == cppClass->typeEntry(); } -QString ShibokenGenerator::cpythonCheckFunction(const AbstractMetaType* type, bool genericNumberType) +static QString checkFunctionName(QString baseName, bool genericNumberType) { - if (genericNumberType && ShibokenGenerator::isNumber(cpythonBaseName(type))) + if (genericNumberType && ShibokenGenerator::isNumber(baseName)) + baseName = "PyNumber"; + return baseName + "_Check"; +} + +QString ShibokenGenerator::cpythonCheckFunction(const AbstractMetaType* metaType, bool genericNumberType) +{ + return checkFunctionName(cpythonBaseName(metaType), genericNumberType); +} + +QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry* type, bool genericNumberType) +{ + return checkFunctionName(cpythonBaseName(type), genericNumberType); +} + +QString ShibokenGenerator::cpythonIsConvertibleFunction(const AbstractMetaType* metaType, bool genericNumberType) +{ + if (genericNumberType && ShibokenGenerator::isNumber(cpythonBaseName(metaType))) return "PyNumber_Check"; QString baseName; QTextStream s(&baseName); - writeBaseConversion(s, type, 0); + writeBaseConversion(s, metaType, 0); s << "isConvertible"; s.flush(); return baseName; } -QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry* type, bool genericNumberType) +QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry* type, bool genericNumberType) { if (genericNumberType && ShibokenGenerator::isNumber(cpythonBaseName(type))) return "PyNumber_Check"; - else { - QString typeName; - return "Converter<" + type->qualifiedCppName() + " >::isConvertible"; - } + return "Converter<" + type->qualifiedCppName() + " >::isConvertible"; } QString ShibokenGenerator::argumentString(const AbstractMetaFunction *func, diff --git a/shibokengenerator.h b/shibokengenerator.h index dff062d52..8463628e9 100644 --- a/shibokengenerator.h +++ b/shibokengenerator.h @@ -151,7 +151,9 @@ public: QString cpythonTypeName(const AbstractMetaClass* metaClass); QString cpythonTypeName(const TypeEntry* type); QString cpythonCheckFunction(const TypeEntry* type, bool genericNumberType = false); - QString cpythonCheckFunction(const AbstractMetaType* type, bool genericNumberType = false); + QString cpythonCheckFunction(const AbstractMetaType* metaType, bool genericNumberType = false); + QString cpythonIsConvertibleFunction(const TypeEntry* type, bool genericNumberType = false); + QString cpythonIsConvertibleFunction(const AbstractMetaType* metaType, bool genericNumberType = false); QString cpythonFunctionName(const AbstractMetaFunction* func); QString cpythonWrapperCPtr(const AbstractMetaClass* metaClass, QString argName = "self"); |