summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--abstractmetabuilder.cpp24
-rw-r--r--abstractmetabuilder.h12
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/testconversionoperator.cpp71
-rw-r--r--tests/testconversionoperator.h35
5 files changed, 143 insertions, 0 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index c98a7bf..2c035cc 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -1157,6 +1157,27 @@ void AbstractMetaBuilder::setupFunctionDefaults(AbstractMetaFunction *metaFuncti
}
}
+void AbstractMetaBuilder::fixReturnTypeOfConversionOperator(AbstractMetaFunction* metaFunction)
+{
+ if (!metaFunction->isConversionOperator()
+ || metaFunction->implementingClass()->typeEntry() != metaFunction->type()->typeEntry())
+ return;
+
+ TypeDatabase* types = TypeDatabase::instance();
+ QString castTo = metaFunction->name().remove(QRegExp("^operator ")).trimmed();
+
+ TypeEntry* retType = types->findType(castTo);
+ if (!retType)
+ return;
+
+ AbstractMetaType* metaType = createMetaType();
+ metaType->setTypeEntry(retType);
+ metaFunction->setType(metaType);
+
+ AbstractMetaClass* metaClass = m_metaClasses.findClass(castTo);
+ metaClass->addExternalConversionOperator(metaFunction);
+}
+
void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scopeItem, AbstractMetaClass *metaClass)
{
foreach (FunctionModelItem function, scopeItem->functions()) {
@@ -1217,6 +1238,9 @@ void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scopeItem, AbstractMe
ReportHandler::warning(warn);
}
+ if (metaFunction->isConversionOperator())
+ fixReturnTypeOfConversionOperator(metaFunction);
+
metaClass->addFunction(metaFunction);
} else if (metaFunction->isDestructor()) {
metaClass->setHasPrivateDestructor(metaFunction->isPrivate());
diff --git a/abstractmetabuilder.h b/abstractmetabuilder.h
index ca4593e..dc38d3b 100644
--- a/abstractmetabuilder.h
+++ b/abstractmetabuilder.h
@@ -112,6 +112,18 @@ public:
void registerHashFunction(FunctionModelItem functionItem);
void registerToStringCapability(FunctionModelItem functionItem);
+ /**
+ * A conversion operator function should not have its owner class as
+ * its return type, but unfortunately it does. This function fixes the
+ * return type of operator functions of this kind making the return type
+ * be the same as it is supposed to generate when used in C++.
+ * If the returned type is a wrapped C++ class, this method also adds the
+ * conversion operator to the collection of external conversions of the
+ * said class.
+ * \param metaFunction conversion operator function to be fixed.
+ */
+ void fixReturnTypeOfConversionOperator(AbstractMetaFunction* metaFunction);
+
void parseQ_Property(AbstractMetaClass *metaClass, const QStringList &declarations);
void setupEquals(AbstractMetaClass *metaClass);
void setupComparable(AbstractMetaClass *metaClass);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 961f80d..71efb9e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -11,6 +11,7 @@ declare_test(testabstractmetaclass)
declare_test(testabstractmetatype)
declare_test(testaddfunction)
declare_test(testcodeinjection)
+declare_test(testconversionoperator)
declare_test(testconversionruletag)
declare_test(testdtorinformation)
declare_test(testenum)
diff --git a/tests/testconversionoperator.cpp b/tests/testconversionoperator.cpp
new file mode 100644
index 0000000..cd4026b
--- /dev/null
+++ b/tests/testconversionoperator.cpp
@@ -0,0 +1,71 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#include "testconversionoperator.h"
+#include <QtTest/QTest>
+#include "testutil.h"
+
+
+void TestConversionOperator::testConversionOperator()
+{
+ const char cppCode[] = "struct A {\
+ };\
+ struct B {\
+ operator A() const;\
+ };\
+ struct C {\
+ operator A() const;\
+ };";
+ const char xmlCode[] = "\
+ <typesystem package=\"Foo\">\
+ <value-type name='A' />\
+ <value-type name='B' />\
+ <value-type name='C' />\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode, false);
+ AbstractMetaClassList classes = t.builder()->classes();
+ AbstractMetaClass* classA = classes.findClass("A");
+ AbstractMetaClass* classB = classes.findClass("B");
+ AbstractMetaClass* classC = classes.findClass("C");
+ QVERIFY(classA);
+ QVERIFY(classB);
+ QVERIFY(classC);
+ QCOMPARE(classA->functions().count(), 1);
+ QCOMPARE(classB->functions().count(), 2);
+ QCOMPARE(classC->functions().count(), 2);
+ QCOMPARE(classA->externalConversionOperators().count(), 2);
+
+ const AbstractMetaFunction* convOp = 0;
+ foreach(const AbstractMetaFunction* func, classB->functions()) {
+ if (func->isConversionOperator())
+ convOp = func;
+ }
+ QVERIFY(convOp);
+ const AbstractMetaFunction* externalConvOp = classA->externalConversionOperators().first();
+ QCOMPARE(convOp, externalConvOp);
+}
+
+QTEST_APPLESS_MAIN(TestConversionOperator)
+
+#include "testconversionoperator.moc"
diff --git a/tests/testconversionoperator.h b/tests/testconversionoperator.h
new file mode 100644
index 0000000..79963db
--- /dev/null
+++ b/tests/testconversionoperator.h
@@ -0,0 +1,35 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#ifndef TESTCONVERSIONOPERATOR_H
+#define TESTCONVERSIONOPERATOR_H
+#include <QObject>
+
+class TestConversionOperator : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testConversionOperator();
+};
+
+#endif