From 8d9d66484195501f7f9a57d527b39964b384bfde Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Mon, 17 Jan 2011 14:52:44 -0200 Subject: Fix bug 616 - "error compiling when public and private methods differ by the const-ness" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewer: Marcelo Lira Renato Araújo --- generator/cppgenerator.cpp | 12 ++++++-- generator/headergenerator.cpp | 46 ++++++++++++++++++++++++++++++- generator/headergenerator.h | 6 ++-- tests/libsample/overload.h | 18 ++++++++++++ tests/samplebinding/CMakeLists.txt | 1 + tests/samplebinding/typesystem_sample.xml | 13 +++++---- 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_castownerClass()->hasProtectedMembers(); + mc << (hasProtectedMembers ? wrapperName(func->ownerClass()) : func->ownerClass()->qualifiedCppName()); + mc << "*>(" CPP_SELF_VAR ")->"; +#else + mc << "const_castownerClass()->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(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 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 @@ - + @@ -1117,7 +1117,8 @@ - + + @@ -1220,11 +1221,11 @@ - + - - - + + + -- cgit v1.2.3