aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-12-28 16:38:22 -0200
committerHugo Lima <hugo.lima@openbossa.org>2010-01-07 16:03:40 -0200
commit8dded56b403fd979f0b567666017dc12f7c1a9b6 (patch)
tree4fd6f0a769132021fed7cdfbaaad6702b9c04db9
parent11679b1008b9443ee817e382731ea9049eb2fe64 (diff)
Added function can be tagged as static methods.
Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--abstractmetabuilder.cpp3
-rw-r--r--doc/typesystem_manipulating_objects.rst4
-rw-r--r--tests/testaddfunction.cpp22
-rw-r--r--tests/testaddfunction.h1
-rw-r--r--typesystem.cpp2
-rw-r--r--typesystem.h12
6 files changed, 41 insertions, 3 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index bc78cdd31..3043e5729 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -1411,7 +1411,8 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(const AddedFunction&
int visibility = addedFunc.access() == AddedFunction::Public ? AbstractMetaAttributes::Public : AbstractMetaAttributes::Protected;
metaFunction->setVisibility(visibility);
metaFunction->setUserAdded(true);
- metaFunction->setAttributes(metaFunction->attributes() | AbstractMetaAttributes::Final);
+ AbstractMetaAttributes::Attribute isStatic = addedFunc.isStatic() ? AbstractMetaFunction::Static : AbstractMetaFunction::None;
+ metaFunction->setAttributes(metaFunction->attributes() | AbstractMetaAttributes::Final | isStatic);
metaFunction->setType(translateType(addedFunc.returnType()));
QList<AddedFunction::TypeInfo> args = addedFunc.arguments();
diff --git a/doc/typesystem_manipulating_objects.rst b/doc/typesystem_manipulating_objects.rst
index 397dfa6ec..84a5c1ad7 100644
--- a/doc/typesystem_manipulating_objects.rst
+++ b/doc/typesystem_manipulating_objects.rst
@@ -93,10 +93,10 @@ add-function
.. code-block:: xml
<object-type>
- <add-function signature="..." return-type="..." access="public | protected" />
+ <add-function signature="..." return-type="..." access="public | protected" static="yes | no" />
</object-type>
- The ``return-type`` attribute defaults to *void*, and the ``access`` to *public*.
+ The ``return-type`` attribute defaults to *void*, the ``access`` to *public* and the ``static`` one to *no*.
.. _conversion-rule-on-types:
diff --git a/tests/testaddfunction.cpp b/tests/testaddfunction.cpp
index 4d98de18b..e3472c390 100644
--- a/tests/testaddfunction.cpp
+++ b/tests/testaddfunction.cpp
@@ -289,6 +289,28 @@ void TestAddFunction::testAddFunctionWithVarargs()
QVERIFY(arg->type()->typeEntry()->isVarargs());
}
+void TestAddFunction::testAddStaticFunction()
+{
+ const char cppCode[] = "struct A { };";
+ const char xmlCode[] = "\
+ <typesystem package=\"Foo\">\
+ <primitive-type name='int'/> \
+ <value-type name='A'>\
+ <add-function signature='func(int, int)' static='yes'>\
+ <inject-code class='target' position='beginning'>custom_code();</inject-code>\
+ </add-function>\
+ </value-type>\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode, false);
+ AbstractMetaClassList classes = t.builder()->classes();
+ AbstractMetaClass* classA = classes.findClass("A");
+ QVERIFY(classA);
+ qDebug() << classes[0]->name();
+ const AbstractMetaFunction* addedFunc = classA->findFunction("func");
+ QVERIFY(addedFunc);
+ QVERIFY(addedFunc->isStatic());
+}
+
QTEST_APPLESS_MAIN(TestAddFunction)
#include "testaddfunction.moc"
diff --git a/tests/testaddfunction.h b/tests/testaddfunction.h
index 56815cf99..4d5764309 100644
--- a/tests/testaddfunction.h
+++ b/tests/testaddfunction.h
@@ -38,6 +38,7 @@ private slots:
void testAddFunctionWithDefaultArgs();
void testAddFunctionAtModuleLevel();
void testAddFunctionWithVarargs();
+ void testAddStaticFunction();
};
#endif
diff --git a/typesystem.cpp b/typesystem.cpp
index 7c58dab56..f6c6d7e50 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -846,6 +846,7 @@ bool Handler::startElement(const QString &, const QString &n,
attributes["signature"] = QString();
attributes["return-type"] = QString("void");
attributes["access"] = QString("public");
+ attributes["static"] = QString("no");
break;
case StackElement::ModifyFunction:
attributes["signature"] = QString();
@@ -1300,6 +1301,7 @@ bool Handler::startElement(const QString &, const QString &n,
}
AddedFunction func(signature, attributes["return-type"]);
+ func.setStatic(attributes["static"] == "yes");
if (!signature.contains("("))
signature += "()";
m_currentSignature = signature;
diff --git a/typesystem.h b/typesystem.h
index 21c770889..635ae43d8 100644
--- a/typesystem.h
+++ b/typesystem.h
@@ -504,12 +504,24 @@ struct APIEXTRACTOR_API AddedFunction
return m_isConst;
}
+ /// Set this method static.
+ void setStatic(bool value)
+ {
+ m_isStatic = value;
+ }
+
+ /// Returns true if this is a static method.
+ bool isStatic() const
+ {
+ return m_isStatic;
+ }
private:
QString m_name;
Access m_access;
QList<TypeInfo> m_arguments;
TypeInfo m_returnType;
bool m_isConst;
+ bool m_isStatic;
};
typedef QList<AddedFunction> AddedFunctionList;