aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--abstractmetabuilder.cpp2
-rw-r--r--doc/typesystem_specifying_types.rst6
-rw-r--r--tests/testfunctiontag.cpp25
-rw-r--r--tests/testfunctiontag.h1
-rw-r--r--typesystem.cpp14
5 files changed, 46 insertions, 2 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index ea1fed6b0..9b36447d0 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -433,6 +433,8 @@ bool AbstractMetaBuilder::build(QIODevice* input)
continue;
}
+ applyFunctionModifications(metaFunc);
+
setInclude(funcEntry, func->fileName());
if (metaFunc->typeEntry())
delete metaFunc->typeEntry();
diff --git a/doc/typesystem_specifying_types.rst b/doc/typesystem_specifying_types.rst
index 2d9ad3a94..e0d2d3c76 100644
--- a/doc/typesystem_specifying_types.rst
+++ b/doc/typesystem_specifying_types.rst
@@ -304,11 +304,13 @@ function
.. code-block:: xml
<typesystem>
- <function signature="..." since="..."/>
+ <function signature="..." rename="..." since="..."/>
</typesystem>
This tag has some limitations, it doesn't support function modifications, besides you
can't add a function overload using :ref:`add-function` tag to an existent function.
These limitation will be addressed in future versions of ApiExtractor.
- The *optional* **since** value is used to specify the API version of this function.
+ The function tag has two *optional* attributes: **since**, whose value is used to specify
+ the API version of this function, and **rename**, to modify the function name.
+
diff --git a/tests/testfunctiontag.cpp b/tests/testfunctiontag.cpp
index 79e3142a5..378baf479 100644
--- a/tests/testfunctiontag.cpp
+++ b/tests/testfunctiontag.cpp
@@ -58,6 +58,31 @@ void TestFunctionTag::testFunctionTagForAllSignatures()
QCOMPARE(t.builder()->globalFunctions().size(), 2);
}
+void TestFunctionTag::testRenameGlobalFunction()
+{
+ const char* cppCode ="void global_function_with_ugly_name();";
+ const char* xmlCode = "\
+ <typesystem package='Foo'> \
+ <function signature='global_function_with_ugly_name()' rename='smooth' />\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode, false);
+
+ FunctionTypeEntry* func = (FunctionTypeEntry*) TypeDatabase::instance()->findType("global_function_with_ugly_name");
+ QVERIFY(func);
+
+ QCOMPARE(t.builder()->globalFunctions().size(), 1);
+ const AbstractMetaFunction* metaFunc = t.builder()->globalFunctions().first();
+
+ QVERIFY(metaFunc);
+ QCOMPARE(metaFunc->modifications().size(), 1);
+ QVERIFY(metaFunc->modifications().first().isRenameModifier());
+ QCOMPARE(metaFunc->modifications().first().renamedTo(), QString("smooth"));
+
+ QCOMPARE(metaFunc->name(), QString("smooth"));
+ QCOMPARE(metaFunc->originalName(), QString("global_function_with_ugly_name"));
+ QCOMPARE(metaFunc->minimalSignature(), QString("global_function_with_ugly_name()"));
+}
+
QTEST_APPLESS_MAIN(TestFunctionTag)
#include "testfunctiontag.moc"
diff --git a/tests/testfunctiontag.h b/tests/testfunctiontag.h
index 8f42774c6..2edd1c4de 100644
--- a/tests/testfunctiontag.h
+++ b/tests/testfunctiontag.h
@@ -31,6 +31,7 @@ class TestFunctionTag : public QObject
private slots:
void testFunctionTagForSpecificSignature();
void testFunctionTagForAllSignatures();
+ void testRenameGlobalFunction();
};
#endif
diff --git a/typesystem.cpp b/typesystem.cpp
index 20ee8650f..736627bf4 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -418,6 +418,7 @@ bool Handler::startElement(const QString &, const QString &n,
break;
case StackElement::FunctionTypeEntry:
attributes["signature"] = QString();
+ attributes["rename"] = QString();
break;
default:
{ } // nada
@@ -432,6 +433,19 @@ bool Handler::startElement(const QString &, const QString &n,
if (element->type == StackElement::FunctionTypeEntry) {
QString signature = attributes["signature"];
name = signature.left(signature.indexOf('(')).trimmed();
+ QString rename = attributes["rename"];
+ if (!rename.isEmpty()) {
+ static QRegExp functionNameRegExp("^[a-zA-Z_][a-zA-Z0-9_]*$");
+ if (!functionNameRegExp.exactMatch(rename)) {
+ m_error = "can not rename '" + signature + "', '" + rename + "' is not a valid function name";
+ return false;
+ }
+ FunctionModification mod(since);
+ mod.signature = signature;
+ mod.renamedToName = attributes["rename"];
+ mod.modifiers |= Modification::Rename;
+ m_contextStack.top()->functionMods << mod;
+ }
}
// We need to be able to have duplicate primitive type entries,