aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-04-15 15:23:38 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-04-15 18:56:52 +0000
commit5b42f97fdfc0334e7628bbe30149227d0834edcd (patch)
treedd2fda6adac647dfe082d750239763cadf10539e /sources/shiboken2/ApiExtractor
parentf42fe9365ba04e31aa8adb7d6d3942990b80104d (diff)
shiboken: Enable adding call operators
The code parsing the add-function tag would clobber call operators (operator()(...)) since it looked for the first '(' to determine the functions name. Add a check for operator(). Change-Id: I3641f670abc0b24c92b539cfba3d227798e84fae Fixes: PYSIDE-995 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor')
-rw-r--r--sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp35
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.cpp7
2 files changed, 28 insertions, 14 deletions
diff --git a/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp b/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp
index 53b9467b1..8c443527e 100644
--- a/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp
+++ b/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp
@@ -71,26 +71,32 @@ void TestAddFunction::testParsingFuncNameAndConstness()
void TestAddFunction::testAddFunction()
{
- const char cppCode[] = "struct B {}; struct A { void a(int); };\n";
- const char xmlCode[] = "\
- <typesystem package='Foo'>\n\
- <primitive-type name='int'/>\n\
- <primitive-type name='float'/>\n\
- <value-type name='B'/>\n\
- <value-type name='A'>\n\
- <add-function signature='b(int, float = 4.6, const B&amp;)' return-type='int' access='protected'>\n\
- </add-function>\n\
- </value-type>\n\
- </typesystem>\n";
+ const char cppCode[] = R"CPP(
+struct B {};
+struct A {
+ void a(int);
+};)CPP";
+ const char xmlCode[] = R"XML(
+<typesystem package='Foo'>
+ <primitive-type name='int'/>
+ <primitive-type name='float'/>
+ <value-type name='B'/>
+ <value-type name='A'>
+ <add-function signature='b(int, float = 4.6, const B&amp;)' return-type='int' access='protected'/>
+ <add-function signature='operator()(int)' return-type='int' access='public'/>
+ </value-type>
+</typesystem>)XML";
+
QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode));
QVERIFY(!builder.isNull());
TypeDatabase* typeDb = TypeDatabase::instance();
AbstractMetaClassList classes = builder->classes();
const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A"));
QVERIFY(classA);
- QCOMPARE(classA->functions().count(), 4); // default ctor, default copy ctor, func a() and the added function
+ QCOMPARE(classA->functions().count(), 5); // default ctor, default copy ctor, func a() and the added functions
- AbstractMetaFunction* addedFunc = classA->functions().last();
+ auto addedFunc = classA->findFunction(QLatin1String("b"));
+ QVERIFY(addedFunc);
QCOMPARE(addedFunc->visibility(), AbstractMetaFunction::Protected);
QCOMPARE(addedFunc->functionType(), AbstractMetaFunction::NormalFunction);
QVERIFY(addedFunc->isUserAdded());
@@ -109,6 +115,9 @@ void TestAddFunction::testAddFunction()
QCOMPARE(args[0]->type()->typeEntry(), returnType->typeEntry());
QCOMPARE(args[1]->defaultValueExpression(), QLatin1String("4.6"));
QCOMPARE(args[2]->type()->typeEntry(), typeDb->findType(QLatin1String("B")));
+
+ auto addedCallOperator = classA->findFunction(QLatin1String("operator()"));
+ QVERIFY(addedCallOperator);
}
void TestAddFunction::testAddFunctionConstructor()
diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp
index 079be5377..52dc2a82f 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystem.cpp
@@ -105,6 +105,8 @@ static inline QString yesAttributeValue() { return QStringLiteral("yes"); }
static inline QString trueAttributeValue() { return QStringLiteral("true"); }
static inline QString falseAttributeValue() { return QStringLiteral("false"); }
+static inline QString callOperator() { return QStringLiteral("operator()"); }
+
static QVector<CustomConversion *> customConversionsForReview;
// Set a regular expression for rejection from text. By legacy, those are fixed
@@ -3244,7 +3246,10 @@ AddedFunction::AddedFunction(QString signature, const QString &returnType) :
Q_ASSERT(!returnType.isEmpty());
m_returnType = parseType(returnType);
signature = signature.trimmed();
- int endPos = signature.indexOf(QLatin1Char('('));
+ // Skip past "operator()(...)"
+ const int parenStartPos = signature.startsWith(callOperator())
+ ? callOperator().size() : 0;
+ int endPos = signature.indexOf(QLatin1Char('('), parenStartPos);
if (endPos < 0) {
m_isConst = false;
m_name = signature;