aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-01-17 14:52:44 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:13:52 -0300
commit8d9d66484195501f7f9a57d527b39964b384bfde (patch)
tree9b930218e9318d18230f1c5caa3209bae31a9034
parent3b22ffebad4736fafde0ff5a23bb3508be8d4b6d (diff)
Fix bug 616 - "error compiling when public and private methods differ by the const-ness"
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Renato Araújo <renato.filho@openbossa.org>
-rw-r--r--generator/cppgenerator.cpp12
-rw-r--r--generator/headergenerator.cpp46
-rw-r--r--generator/headergenerator.h6
-rw-r--r--tests/libsample/overload.h18
-rw-r--r--tests/samplebinding/CMakeLists.txt1
-rw-r--r--tests/samplebinding/typesystem_sample.xml13
6 files changed, 83 insertions, 13 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index d5697ab72..b7148017c 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -2092,12 +2092,18 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f
if (func->isStatic())
mc << func->ownerClass()->qualifiedCppName() << "::";
else {
+ if (func->isConstant()) {
#ifdef AVOID_PROTECTED_HACK
- if (!func->isVirtual() && func->ownerClass()->hasProtectedMembers())
- mc << "((" << func->ownerClass()->qualifiedCppName() << "*)" << CPP_SELF_VAR << ")->";
- else
+ mc << "const_cast<const ";
+ bool hasProtectedMembers = func->ownerClass()->hasProtectedMembers();
+ mc << (hasProtectedMembers ? wrapperName(func->ownerClass()) : func->ownerClass()->qualifiedCppName());
+ mc << "*>(" CPP_SELF_VAR ")->";
+#else
+ mc << "const_cast<const " << func->ownerClass()->qualifiedCppName() << "*>(" CPP_SELF_VAR ")->";
#endif
+ } else {
mc << CPP_SELF_VAR "->";
+ }
}
if (!func->isAbstract() && func->isVirtual())
diff --git a/generator/headergenerator.cpp b/generator/headergenerator.cpp
index bb8f341a1..b7e2bbdc9 100644
--- a/generator/headergenerator.cpp
+++ b/generator/headergenerator.cpp
@@ -73,6 +73,7 @@ void HeaderGenerator::writeProtectedFieldAccessors(QTextStream& s, const Abstrac
void HeaderGenerator::generateClass(QTextStream& s, const AbstractMetaClass* metaClass)
{
ReportHandler::debugSparse("Generating header for " + metaClass->fullName());
+ m_inheritedOverloads.clear();
Indentation indent(INDENT);
// write license comment
@@ -143,13 +144,18 @@ void HeaderGenerator::generateClass(QTextStream& s, const AbstractMetaClass* met
}
#endif
+ if (m_inheritedOverloads.size()) {
+ s << INDENT << "// Inherited overloads, because the using keyword sux" << endl;
+ writeInheritedOverloads(s);
+ }
+
s << "};" << endl << endl;
}
s << "#endif // SBK_" << headerGuard << "_H" << endl << endl;
}
-void HeaderGenerator::writeFunction(QTextStream& s, const AbstractMetaFunction* func) const
+void HeaderGenerator::writeFunction(QTextStream& s, const AbstractMetaFunction* func)
{
// do not write copy ctors here.
@@ -206,6 +212,20 @@ void HeaderGenerator::writeFunction(QTextStream& s, const AbstractMetaFunction*
s << functionSignature(func, "", "", virtualOption) << ';' << endl;
+ // Check if this method hide other methods in base classes
+ foreach (const AbstractMetaFunction* f, func->ownerClass()->functions()) {
+ if (f != func
+ && !f->isConstructor()
+ && !f->isPrivate()
+ && !f->isVirtual()
+ && !f->isAbstract()
+ && !f->isStatic()
+ && f->name() == func->name()) {
+ m_inheritedOverloads << f;
+ break;
+ }
+ }
+
// TODO: when modified an abstract method ceases to be virtual but stays abstract
//if (func->isModifiedRemoved() && func->isAbstract()) {
//}
@@ -621,3 +641,27 @@ void HeaderGenerator::writeTypeConverterImpl(QTextStream& s, const TypeEntry* ty
s << '}' << endl << endl;
}
+void HeaderGenerator::writeInheritedOverloads(QTextStream& s)
+{
+ foreach (const AbstractMetaFunction* func, m_inheritedOverloads) {
+ s << INDENT << "inline ";
+ s << functionSignature(func, "", "", Generator::EnumAsInts|Generator::OriginalTypeDescription) << " { ";
+ s << (func->type() ? "return " : "");
+ s << func->ownerClass()->qualifiedCppName() << "::" << func->originalName() << '(';
+ QStringList args;
+ foreach (const AbstractMetaArgument* arg, func->arguments()) {
+ QString argName = arg->name();
+ const TypeEntry* enumTypeEntry = 0;
+ if (arg->type()->isFlags())
+ enumTypeEntry = reinterpret_cast<const FlagsTypeEntry*>(arg->type()->typeEntry())->originator();
+ else if (arg->type()->isEnum())
+ enumTypeEntry = arg->type()->typeEntry();
+ if (enumTypeEntry)
+ argName = QString("%1(%2)").arg(arg->type()->cppSignature()).arg(argName);
+ args << argName;
+ }
+ s << args.join(", ") << ')';
+ s << "; }" << endl;
+ }
+}
+
diff --git a/generator/headergenerator.h b/generator/headergenerator.h
index d7502a9e1..6710b9948 100644
--- a/generator/headergenerator.h
+++ b/generator/headergenerator.h
@@ -41,9 +41,7 @@ protected:
private:
void writeCopyCtor(QTextStream &s, const AbstractMetaClass* metaClass) const;
void writeProtectedFieldAccessors(QTextStream& s, const AbstractMetaField* field) const;
- void writeFunction(QTextStream& s, const AbstractMetaFunction* func) const;
- void writePureVirtualEmptyImpl(QTextStream& , const AbstractMetaFunction* func) const;
- void writeDefaultImplementation(QTextStream& s, const AbstractMetaFunction* func) const;
+ void writeFunction(QTextStream& s, const AbstractMetaFunction* func);
void writeTypeConverterDecl(QTextStream& s, const TypeEntry* type);
void writeSbkTypeFunction(QTextStream& s, const AbstractMetaEnum* cppEnum);
void writeSbkTypeFunction(QTextStream& s, const AbstractMetaClass* cppClass);
@@ -51,7 +49,9 @@ private:
void writeTypeIndexDefine(QTextStream& s, const AbstractMetaClass* metaClass, int& idx);
void writeTypeConverterImpl(QTextStream& s, const TypeEntry* type);
void writeProtectedEnumSurrogate(QTextStream& s, const AbstractMetaEnum* cppEnum);
+ void writeInheritedOverloads(QTextStream& s);
+ QSet<const AbstractMetaFunction*> m_inheritedOverloads;
};
#endif // HEADERGENERATOR_H
diff --git a/tests/libsample/overload.h b/tests/libsample/overload.h
index 36b30f2be..0660f3799 100644
--- a/tests/libsample/overload.h
+++ b/tests/libsample/overload.h
@@ -61,5 +61,23 @@ public:
void singleOverload(Point* x) {}
Point* singleOverload() {return new Point();}
};
+
+class LIBSAMPLE_API Overload2 : public Overload
+{
+public:
+ // test bug#616, public and private method differ only by const
+ void doNothingInPublic() const {}
+ void doNothingInPublic(int) {}
+ virtual void doNothingInPublic3() const {}
+ void doNothingInPublic3(int) const {}
+protected:
+ void doNothingInPublic2() const {}
+ void doNothingInPublic2(int) {}
+private:
+ void doNothingInPublic() {}
+ void doNothingInPublic2() {}
+ void doNothingInPublic3() {}
+};
+
#endif // OVERLOAD_H
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
index 3421c0d5e..abe982aab 100644
--- a/tests/samplebinding/CMakeLists.txt
+++ b/tests/samplebinding/CMakeLists.txt
@@ -51,6 +51,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/objectview_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/objtypereference_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/oddbooluser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/overload_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/overload2_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/pen_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/point_wrapper.cpp
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 636916057..faa940dfb 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -1101,7 +1101,7 @@
<value-type name="NoImplicitConversion" />
<value-type name="NonDefaultCtor" />
<value-type name="OddBoolUser" />
- <value-type name="Overload">
+ <object-type name="Overload">
<enum-type name="FunctionEnum"/>
<enum-type name="ParamEnum"/>
<modify-function signature="intOverloads(int, int, double)">
@@ -1117,7 +1117,8 @@
<define-ownership owner="c++"/>
</modify-argument>
</modify-function>
- </value-type>
+ </object-type>
+ <object-type name="Overload2" />
<object-type name="Collector" stream="yes"/>
<value-type name="IntWrapper" />
@@ -1220,11 +1221,11 @@
<object-type name="PrivateDtor" />
<object-type name="Base1"/>
- <interface-type name="Base2"/>
+ <object-type name="Base2"/>
<object-type name="Base3"/>
- <interface-type name="Base4"/>
- <interface-type name="Base5"/>
- <interface-type name="Base6"/>
+ <object-type name="Base4"/>
+ <object-type name="Base5"/>
+ <object-type name="Base6"/>
<object-type name="MDerived1"/>
<object-type name="MDerived2"/>
<object-type name="MDerived3"/>