diff options
author | Matthew Woehlke <matthew.woehlke@kitware.com> | 2013-11-10 17:09:31 -0500 |
---|---|---|
committer | John Ehresman <jpe@wingware.com> | 2014-04-16 00:40:02 +0200 |
commit | 35d006a7bf9b33807c1df93f5f9439ff83cd32c0 (patch) | |
tree | c5a9359e631251dd3d5c6a09a159de08b64c7aa3 | |
parent | 5b39f7fd9e216dd16e32ee5950d8d3d781cf1d17 (diff) |
Fix function rejections (i.e. support overloads)
Add an additional check to AbstractMetaBuilder::traverseFunction to also
perform a quick-and-dirty construction of the function signature, and to
check that against the rejections. Add a unit test for matching full
signatures.
Before, we were only testing the function name; as a result, a rejection
like 'foo()' would never match (because the name does not have ()'s).
This is especially helpful for rejecting specific overloads of functions
while allowing others to be wrapped normally. (The unit test shows a
not-so-far-fetched example why one might want to do this.)
The signature building logic isn't very sophisticated and likely
requires a very exacting match to the signature as it appears in the
wrapped sources, but that's likely not a serious issue, and at any rate
this is much better than not being able to match overloads at all.
Change-Id: Ic686377477aacf54f79c7bd2013e9aea8521a4ea
Reviewed-by: John Ehresman <jpe@wingware.com>
-rw-r--r-- | ApiExtractor/abstractmetabuilder.cpp | 12 | ||||
-rw-r--r-- | tests/libsample/photon.cpp | 3 | ||||
-rw-r--r-- | tests/libsample/photon.h | 13 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 5 |
4 files changed, 33 insertions, 0 deletions
diff --git a/ApiExtractor/abstractmetabuilder.cpp b/ApiExtractor/abstractmetabuilder.cpp index a5c31bf..564f6c3 100644 --- a/ApiExtractor/abstractmetabuilder.cpp +++ b/ApiExtractor/abstractmetabuilder.cpp @@ -1850,6 +1850,14 @@ void AbstractMetaBuilder::fixArgumentNames(AbstractMetaFunction* func) } } +static QString functionSignature(FunctionModelItem functionItem) +{ + QStringList args; + foreach (ArgumentModelItem arg, functionItem->arguments()) + args << arg->type().toString(); + return QString("%1(%2)").arg(functionItem->name(), args.join(",")); +} + AbstractMetaFunction* AbstractMetaBuilder::traverseFunction(FunctionModelItem functionItem) { QString functionName = functionItem->name(); @@ -1861,6 +1869,10 @@ AbstractMetaFunction* AbstractMetaBuilder::traverseFunction(FunctionModelItem fu m_rejectedFunctions.insert(className + "::" + functionName, GenerationDisabled); return 0; } + else if (TypeDatabase::instance()->isFunctionRejected(className, functionSignature(functionItem))) { + m_rejectedFunctions.insert(className + "::" + functionName, GenerationDisabled); + return 0; + } Q_ASSERT(functionItem->functionType() == CodeModel::Normal || functionItem->functionType() == CodeModel::Signal diff --git a/tests/libsample/photon.cpp b/tests/libsample/photon.cpp index b1b3328..ae2031c 100644 --- a/tests/libsample/photon.cpp +++ b/tests/libsample/photon.cpp @@ -24,6 +24,9 @@ namespace Photon { +const ClassType Base::staticType; +template <> const ClassType TemplateBase<IdentityType>::staticType; +template <> const ClassType TemplateBase<DuplicatorType>::staticType; int callCalculateForValueDuplicatorPointer(ValueDuplicator* value) { return value->calculate(); diff --git a/tests/libsample/photon.h b/tests/libsample/photon.h index f6c97b7..18917e2 100644 --- a/tests/libsample/photon.h +++ b/tests/libsample/photon.h @@ -33,6 +33,7 @@ namespace Photon { enum ClassType { + BaseType = 0, IdentityType = 1, DuplicatorType = 2 }; @@ -41,9 +42,17 @@ class LIBSAMPLE_API Base { public: explicit Base(int value) : m_value(value) {} + virtual ~Base() {} inline void setValue(int value) { m_value = value; } inline int value() const { return m_value; } + + template <class T> bool isType() { return type() == T::staticType; } + bool isType(ClassType t) { return type() == t; } + protected: + virtual ClassType type() const { return BaseType; }; + static const ClassType staticType = BaseType; + int m_value; }; @@ -68,6 +77,10 @@ public: } static inline TemplateBase<CLASS_TYPE>* passPointerThrough(TemplateBase<CLASS_TYPE>* obj) { return obj; } + +protected: + virtual ClassType type() const { return CLASS_TYPE; } + static const ClassType staticType = CLASS_TYPE; }; #if defined _WIN32 || defined __CYGWIN__ diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index dee0285..5da6ad1 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -2393,6 +2393,11 @@ <rejection class="ListUser" function-name="sumList(std::list<int>)"/> <rejection class="ListUser" function-name="sumList(std::list<double>)"/> + <!-- test rejections using full signatures; this method is a template and + cannot be wrapped, but is otherwise recognized by shiboken and will + result in a compile error if the rejection is not matched --> + <rejection class="Photon::Base" function-name="isType()"/> + <value-type name="ValueAndVirtual" /> <object-type name="ObjectTypeByValue" /> |