summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-10-08 15:51:48 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:11 -0300
commit99862b71c95e1e061ac743fb864a041fa0a1fbf8 (patch)
treebfabc643047c934084caa8a5ba9ab0f1d0812977
parent6ab94ebbe402a92a7587e5b947f821712b6ee605 (diff)
Implemented support to added functions for TypeAlias.sb-0.8.1
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Lauro Moura <lauro.neto@openbossa.org>
-rw-r--r--abstractmetabuilder.cpp9
-rw-r--r--abstractmetabuilder.h1
-rw-r--r--abstractmetalang.cpp3
-rw-r--r--tests/testaddfunction.cpp27
-rw-r--r--tests/testaddfunction.h1
-rw-r--r--typesystem.cpp2
6 files changed, 42 insertions, 1 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index 60b687a6..3cdfc1a6 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -402,6 +402,7 @@ bool AbstractMetaBuilder::build(QIODevice* input)
foreach (ClassModelItem item, typeValues)
traverseClassMembers(item);
+
foreach (NamespaceModelItem item, namespaceTypeValues)
traverseNamespaceMembers(item);
@@ -1050,6 +1051,8 @@ AbstractMetaClass* AbstractMetaBuilder::traverseTypeAlias(TypeAliasModelItem typ
if (!type->include().isValid())
setInclude(type, typeAlias->fileName());
+ fillAddedFunctions(metaClass);
+
return metaClass;
}
@@ -1425,6 +1428,11 @@ void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scopeItem, AbstractMe
}
}
+ fillAddedFunctions(metaClass);
+}
+
+void AbstractMetaBuilder::fillAddedFunctions(AbstractMetaClass* metaClass)
+{
// Add the functions added by the typesystem
foreach (AddedFunction addedFunc, metaClass->typeEntry()->addedFunctions()) {
AbstractMetaFunction* func = traverseFunction(addedFunc);
@@ -1440,6 +1448,7 @@ void AbstractMetaBuilder::traverseFunctions(ScopeModelItem scopeItem, AbstractMe
func->setDeclaringClass(metaClass);
func->setImplementingClass(metaClass);
metaClass->addFunction(func);
+ metaClass->setHasNonPrivateConstructor(true);
}
}
diff --git a/abstractmetabuilder.h b/abstractmetabuilder.h
index d45b34aa..893ebece 100644
--- a/abstractmetabuilder.h
+++ b/abstractmetabuilder.h
@@ -234,6 +234,7 @@ private:
AbstractMetaArgumentList reverseList(const AbstractMetaArgumentList& list);
void setInclude(TypeEntry* te, const QString& fileName) const;
void fixArgumentNames(AbstractMetaFunction* func);
+ void fillAddedFunctions(AbstractMetaClass* metaClass);
AbstractMetaClassList m_metaClasses;
AbstractMetaClassList m_templates;
diff --git a/abstractmetalang.cpp b/abstractmetalang.cpp
index ed793426..de3451d3 100644
--- a/abstractmetalang.cpp
+++ b/abstractmetalang.cpp
@@ -1335,6 +1335,7 @@ bool AbstractMetaClass::hasDefaultToStringFunction() const
void AbstractMetaClass::addFunction(AbstractMetaFunction *function)
{
+ Q_ASSERT(!function->signature().startsWith("("));
function->setOwnerClass(this);
if (!function->isDestructor())
@@ -1596,6 +1597,7 @@ bool AbstractMetaClass::hasPrivateCopyConstructor() const
void AbstractMetaClass::addDefaultConstructor()
{
AbstractMetaFunction *f = new AbstractMetaFunction;
+ f->setOriginalName(name());
f->setName(name());
f->setOwnerClass(this);
f->setFunctionType(AbstractMetaFunction::ConstructorFunction);
@@ -1616,6 +1618,7 @@ void AbstractMetaClass::addDefaultConstructor()
void AbstractMetaClass::addDefaultCopyConstructor(bool isPrivate)
{
AbstractMetaFunction* f = new AbstractMetaFunction;
+ f->setOriginalName(name());
f->setName(name());
f->setOwnerClass(this);
f->setFunctionType(AbstractMetaFunction::ConstructorFunction);
diff --git a/tests/testaddfunction.cpp b/tests/testaddfunction.cpp
index 0346a636..4e03c962 100644
--- a/tests/testaddfunction.cpp
+++ b/tests/testaddfunction.cpp
@@ -380,6 +380,33 @@ void TestAddFunction::testModifyAddedFunction()
QCOMPARE(method->argumentName(2), QString("varName"));
}
+void TestAddFunction::testAddFunctionOnTypedef()
+{
+ const char cppCode[] = "template<class T> class Foo { }; typedef Foo<int> FooInt;";
+ const char xmlCode[] = "\
+ <typesystem package='Package'>\
+ <primitive-type name='int'/>\
+ <value-type name='FooInt'>\
+ <add-function signature='FooInt(PySequence*)'>\
+ <inject-code class='target' position='beginning'>custom_code();</inject-code>\
+ </add-function>\
+ <add-function signature='method()'>\
+ <inject-code class='target' position='beginning'>custom_code();</inject-code>\
+ </add-function>\
+ </value-type>\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode);
+ AbstractMetaClassList classes = t.builder()->classes();
+ AbstractMetaClass* foo = classes.findClass("FooInt");
+ QVERIFY(foo->hasNonPrivateConstructor());
+ AbstractMetaFunctionList lst = foo->queryFunctions(AbstractMetaClass::Constructors);
+ foreach(AbstractMetaFunction* f, lst)
+ QVERIFY(f->signature().startsWith(f->name()));
+ QCOMPARE(lst.size(), 2);
+ const AbstractMetaFunction* method = foo->findFunction("method");
+ QVERIFY(method);
+}
+
QTEST_APPLESS_MAIN(TestAddFunction)
#include "testaddfunction.moc"
diff --git a/tests/testaddfunction.h b/tests/testaddfunction.h
index 09d80622..8fa44040 100644
--- a/tests/testaddfunction.h
+++ b/tests/testaddfunction.h
@@ -42,6 +42,7 @@ private slots:
void testAddGlobalFunction();
void testAddFunctionWithApiVersion();
void testModifyAddedFunction();
+ void testAddFunctionOnTypedef();
};
#endif
diff --git a/typesystem.cpp b/typesystem.cpp
index b31e8366..b407f2e0 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -982,7 +982,7 @@ bool Handler::startElement(const QString &, const QString &n,
const char* conversionFlag = NATIVE_CONVERSION_RULE_FLAG;
if (lang == TypeSystem::TargetLangCode)
conversionFlag = TARGET_CONVERSION_RULE_FLAG;
-
+
QFile conversionSource(sourceFile);
if (conversionSource.open(QIODevice::ReadOnly | QIODevice::Text)) {
topElement.entry->setConversionRule(conversionFlag + QString::fromUtf8(conversionSource.readAll()));