diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-09-16 18:20:50 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:17:15 -0300 |
commit | 2cc05efe4c28c90d5dd6126d251f5ca9a9ebde07 (patch) | |
tree | b82b4c09435e9de971b87d84d1c329b9bb018fdf /generator | |
parent | fd5dd85d0d0dcc4faaf3a1ca5bd6a5df857f7844 (diff) |
Use ErrorCode class when writing enums.
Diffstat (limited to 'generator')
-rw-r--r-- | generator/cppgenerator.cpp | 16 | ||||
-rw-r--r-- | generator/cppgenerator.h | 10 |
2 files changed, 15 insertions, 11 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index c9e599319..d54a02ab6 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -36,7 +36,7 @@ QHash<QString, QString> CppGenerator::m_nbFuncs = QHash<QString, QString>(); QHash<QString, QString> CppGenerator::m_sqFuncs = QHash<QString, QString>(); QHash<QString, QString> CppGenerator::m_mpFuncs = QHash<QString, QString>(); -int CppGenerator::m_currentErrorCode = 0; +QString CppGenerator::m_currentErrorCode("0"); // utility functions inline AbstractMetaType* getTypeWithoutContainer(AbstractMetaType* arg) @@ -61,8 +61,6 @@ static QString reduceTypeName(const AbstractMetaClass* metaClass) CppGenerator::CppGenerator() { - m_currentErrorCode = 0; - // Number protocol structure members names m_nbFuncs["__add__"] = "nb_add"; m_nbFuncs["__sub__"] = "nb_subtract"; @@ -3169,7 +3167,7 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu s << INDENT << "if (!" << cpythonTypeNameExt(cppEnum->typeEntry()) << ')' << endl; { Indentation indent(INDENT); - s << INDENT << "return;" << endl << endl; + s << INDENT << "return " << m_currentErrorCode << ';' << endl << endl; } } @@ -3197,7 +3195,7 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu s << ")->super.ht_type.tp_dict, \"" << enumValue->name() << "\", anonEnumItem) < 0)" << endl; { Indentation indent(INDENT); - s << INDENT << "return;" << endl; + s << INDENT << "return " << m_currentErrorCode << ';' << endl; } s << INDENT << "Py_DECREF(anonEnumItem);" << endl; } @@ -3207,7 +3205,7 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu s << enumValueText << ") < 0)" << endl; { Indentation indent(INDENT); - s << INDENT << "return;" << endl; + s << INDENT << "return " << m_currentErrorCode << ';' << endl; } } } else { @@ -3217,7 +3215,7 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu Indentation indent(INDENT); s << INDENT << enclosingObjectVariable << ", \"" << enumValue->name() << "\", "; s << enumValueText << "))" << endl; - s << INDENT << "return;" << endl; + s << INDENT << "return " << m_currentErrorCode << ';' << endl; } } @@ -3528,6 +3526,7 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m foreach (AbstractMetaClass* innerClass, metaClass->innerClasses()) lookForEnumsInClassesNotToBeGenerated(classEnums, innerClass); + ErrorCode errorCode(""); writeEnumsInitialization(s, classEnums); if (metaClass->hasSignals()) @@ -3919,6 +3918,7 @@ void CppGenerator::finishGeneration() s << "extern \"C\" SBK_EXPORT_MODULE void init" << moduleName() << "()" << endl; s << '{' << endl; + ErrorCode errorCode(""); // module inject-code target/beginning if (!snips.isEmpty()) { writeCodeSnips(s, snips, CodeSnip::Beginning, TypeSystem::TargetLangCode); @@ -4148,7 +4148,7 @@ void CppGenerator::writeStdListWrapperMethods(QTextStream& s, const AbstractMeta s << '}' << endl; // __setitem__ - m_currentErrorCode = -1; + ErrorCode errorCode2(-1); s << "int " << cpythonBaseName(metaClass->typeEntry()) << "__setitem__(PyObject* " PYTHON_SELF_VAR ", Py_ssize_t _i, PyObject* _value)" << endl; s << '{' << endl; writeCppSelfDefinition(s, metaClass); diff --git a/generator/cppgenerator.h b/generator/cppgenerator.h index 82e89dece..eb5e2bc0e 100644 --- a/generator/cppgenerator.h +++ b/generator/cppgenerator.h @@ -252,20 +252,24 @@ private: // Mapping protocol structure members names. static QHash<QString, QString> m_mpFuncs; - static int m_currentErrorCode; + static QString m_currentErrorCode; /// Helper class to set and restore the current error code. class ErrorCode { public: - explicit ErrorCode(int errorCode) { + explicit ErrorCode(QString errorCode) { m_savedErrorCode = CppGenerator::m_currentErrorCode; CppGenerator::m_currentErrorCode = errorCode; } + explicit ErrorCode(int errorCode) { + m_savedErrorCode = CppGenerator::m_currentErrorCode; + CppGenerator::m_currentErrorCode = QString::number(errorCode); + } ~ErrorCode() { CppGenerator::m_currentErrorCode = m_savedErrorCode; } private: - int m_savedErrorCode; + QString m_savedErrorCode; }; }; |