aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-07-29 15:41:23 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:07 -0300
commite05e6ef74efbfef002b98b64ad4d1105bcef2ad5 (patch)
tree311cd9eef9b7f8392a883a288f50702428c2c7e8 /generator
parent5afdf1fae25fdb7f8e090c24d6526dccbba18e21 (diff)
The rich comparison function writer now makes use of the C++ self variable writer.
That was the last one.
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp45
-rw-r--r--generator/cppgenerator.h2
2 files changed, 27 insertions, 20 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 79b168f89..7ce32faad 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -1363,22 +1363,29 @@ void CppGenerator::writeArgumentsInitializer(QTextStream& s, OverloadData& overl
s << endl;
}
-void CppGenerator::writeCppSelfDefinition(QTextStream& s, const AbstractMetaClass* metaClass, bool hasStaticOverload)
+void CppGenerator::writeCppSelfDefinition(QTextStream& s, const AbstractMetaClass* metaClass, bool hasStaticOverload, bool cppSelfAsReference)
{
- QString className;
- if (avoidProtectedHack() && metaClass->hasProtectedMembers())
- className = wrapperName(metaClass);
- else
- className = QString("::%1").arg(metaClass->qualifiedCppName());
- s << INDENT << className << "* " CPP_SELF_VAR " = 0;" << endl;
-
- QString cppSelfAttribution = CPP_SELF_VAR" = ";
- if (avoidProtectedHack() && metaClass->hasProtectedMembers())
- cppSelfAttribution += QString("(%1*)").arg(className);
- cppSelfAttribution += cpythonWrapperCPtr(metaClass, "self");
+ bool useWrapperClass = avoidProtectedHack() && metaClass->hasProtectedMembers();
+ QString className = useWrapperClass ? wrapperName(metaClass) : QString("::%1").arg(metaClass->qualifiedCppName());
+
+ QString cppSelfAttribution;
+ if (cppSelfAsReference) {
+ QString cast = useWrapperClass ? QString("(%1*)").arg(className) : QString();
+ cppSelfAttribution = QString("%1& %2 = *(%3%4)")
+ .arg(className)
+ .arg(CPP_SELF_VAR)
+ .arg(cast)
+ .arg(cpythonWrapperCPtr(metaClass, "self"));
+ } else {
+ s << INDENT << className << "* " CPP_SELF_VAR " = 0;" << endl;
+ cppSelfAttribution = QString("%1 = %2%3")
+ .arg(CPP_SELF_VAR)
+ .arg(useWrapperClass ? QString("(%1*)").arg(className) : "")
+ .arg(cpythonWrapperCPtr(metaClass, "self"));
+ }
// Checks if the underlying C++ object is valid.
- if (hasStaticOverload) {
+ if (hasStaticOverload && !cppSelfAsReference) {
s << INDENT << "if (self) {" << endl;
{
Indentation indent(INDENT);
@@ -1386,10 +1393,11 @@ void CppGenerator::writeCppSelfDefinition(QTextStream& s, const AbstractMetaClas
s << INDENT << cppSelfAttribution << ';' << endl;
}
s << INDENT << '}' << endl;
- } else {
- writeInvalidPyObjectCheck(s, "self");
- s << INDENT << cppSelfAttribution << ';' << endl;
+ return;
}
+
+ writeInvalidPyObjectCheck(s, "self");
+ s << INDENT << cppSelfAttribution << ';' << endl;
}
void CppGenerator::writeCppSelfDefinition(QTextStream& s, const AbstractMetaFunction* func, bool hasStaticOverload)
@@ -2984,15 +2992,14 @@ void CppGenerator::writeRichCompareFunction(QTextStream& s, const AbstractMetaCl
s << "static PyObject* ";
s << baseName << "_richcompare(PyObject* self, PyObject* arg, int op)" << endl;
s << '{' << endl;
- QList<AbstractMetaFunctionList> cmpOverloads = filterGroupedOperatorFunctions(metaClass, AbstractMetaClass::ComparisonOp);
+ writeCppSelfDefinition(s, metaClass, false, true);
s << INDENT << "PyObject* " PYTHON_RETURN_VAR " = 0;" << endl;
- s << INDENT << metaClass->qualifiedCppName() << "& " CPP_SELF_VAR " = *" << cpythonWrapperCPtr(metaClass) << ';' << endl;
s << endl;
s << INDENT << "switch (op) {" << endl;
{
Indentation indent(INDENT);
- foreach (AbstractMetaFunctionList overloads, cmpOverloads) {
+ foreach (AbstractMetaFunctionList overloads, filterGroupedOperatorFunctions(metaClass, AbstractMetaClass::ComparisonOp)) {
const AbstractMetaFunction* rfunc = overloads[0];
QString operatorId = ShibokenGenerator::pythonRichCompareOperatorId(rfunc);
diff --git a/generator/cppgenerator.h b/generator/cppgenerator.h
index 9ab2fbab5..cd8cfb97b 100644
--- a/generator/cppgenerator.h
+++ b/generator/cppgenerator.h
@@ -54,7 +54,7 @@ private:
void writeMethodWrapper(QTextStream& s, const AbstractMetaFunctionList overloads);
void writeArgumentsInitializer(QTextStream& s, OverloadData& overloadData);
void writeCppSelfDefinition(QTextStream& s, const AbstractMetaFunction* func, bool hasStaticOverload = false);
- void writeCppSelfDefinition(QTextStream& s, const AbstractMetaClass* metaClass, bool hasStaticOverload = false);
+ void writeCppSelfDefinition(QTextStream& s, const AbstractMetaClass* metaClass, bool hasStaticOverload = false, bool cppSelfAsReference = false);
void writeErrorSection(QTextStream& s, OverloadData& overloadData);
void writeFunctionReturnErrorCheckSection(QTextStream& s, bool hasReturnValue = true);