From 5b42f97fdfc0334e7628bbe30149227d0834edcd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 15 Apr 2019 15:23:38 +0200 Subject: 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 --- .../ApiExtractor/tests/testaddfunction.cpp | 35 ++++++++++++++-------- sources/shiboken2/ApiExtractor/typesystem.cpp | 7 ++++- 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[] = "\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n\ - \n"; + const char cppCode[] = R"CPP( +struct B {}; +struct A { + void a(int); +};)CPP"; + const char xmlCode[] = R"XML( + + + + + + + + +)XML"; + QScopedPointer 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 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; -- cgit v1.2.3