diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-07-05 19:11:04 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-09 19:10:17 -0300 |
commit | 2cc6e2afa7b9845ccfc62b9dce72b498034e8de9 (patch) | |
tree | ae6f0d89c25cd95233010dfab80f3af74bf79de4 | |
parent | 31df158c68385c300f6c9b7cb0fe06bb3a789300 (diff) |
Added revision attribute to type entries tags and flags-revision to enum-type tag.
These attributes will be useful to separate the wrapped API in revisions and ease
the task of producing ABI compatible bindings.
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/testtyperevision.cpp | 64 | ||||
-rw-r--r-- | tests/testtyperevision.h | 36 | ||||
-rw-r--r-- | typedatabase.cpp | 14 | ||||
-rw-r--r-- | typedatabase.h | 3 | ||||
-rw-r--r-- | typesystem.cpp | 12 |
6 files changed, 128 insertions, 2 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5d991e68b..02537dea9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -41,6 +41,7 @@ declare_test(testreverseoperators) declare_test(testtemplates) declare_test(testtoposort) declare_test(testvoidarg) +declare_test(testtyperevision) if (NOT DISABLE_DOCSTRINGS) declare_test(testmodifydocumentation) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/a.xml" diff --git a/tests/testtyperevision.cpp b/tests/testtyperevision.cpp new file mode 100644 index 000000000..6fadfa9fa --- /dev/null +++ b/tests/testtyperevision.cpp @@ -0,0 +1,64 @@ +/* +* This file is part of the API Extractor project. +* +* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +* +* Contact: PySide team <contact@pyside.org> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +*/ + +#include "testtyperevision.h" +#include <QtTest/QTest> +#include "testutil.h" + + +void TestTypeRevision::testRevisionAttr() +{ + const char* cppCode = "class Rev_0 {};" + "class Rev_1 {};" + "class Rev_2 { public: enum Rev_3 { X }; enum Rev_5 { Y }; };"; + const char* xmlCode = "<typesystem package=\"Foo\">" + "<value-type name=\"Rev_0\"/>" + "<value-type name=\"Rev_1\" revision=\"1\"/>" + "<object-type name=\"Rev_2\" revision=\"2\">" + " <enum-type name=\"Rev_3\" revision=\"3\" flags=\"Flag_4\" flags-revision=\"4\" />" + " <enum-type name=\"Rev_5\" revision=\"5\" flags=\"Flag_5\" />" + "</object-type>" + "</typesystem>"; + TestUtil t(cppCode, xmlCode); + AbstractMetaClassList classes = t.builder()->classes(); + AbstractMetaClass* rev0 = classes.findClass("Rev_0"); + QCOMPARE(getTypeRevision(rev0->typeEntry()), 0); + + AbstractMetaClass* rev1 = classes.findClass("Rev_1"); + QCOMPARE(getTypeRevision(rev1->typeEntry()), 1); + + AbstractMetaClass* rev2 = classes.findClass("Rev_2"); + QCOMPARE(getTypeRevision(rev2->typeEntry()), 2); + + AbstractMetaEnum* rev3 = rev2->findEnum("Rev_3"); + QCOMPARE(getTypeRevision(rev3->typeEntry()), 3); + FlagsTypeEntry* rev4 = rev3->typeEntry()->flags(); + QCOMPARE(getTypeRevision(rev4), 4); + AbstractMetaEnum* rev5 = rev2->findEnum("Rev_5"); + QCOMPARE(getTypeRevision(rev5->typeEntry()), 5); + QCOMPARE(getTypeRevision(rev5->typeEntry()->flags()), 5); +} + +QTEST_APPLESS_MAIN(TestTypeRevision) + +#include "testtyperevision.moc" + diff --git a/tests/testtyperevision.h b/tests/testtyperevision.h new file mode 100644 index 000000000..24e94739f --- /dev/null +++ b/tests/testtyperevision.h @@ -0,0 +1,36 @@ +/* +* This file is part of the API Extractor project. +* +* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +* +* Contact: PySide team <contact@pyside.org> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +*/ + +#ifndef TESTTYPEREVISION_H +#define TESTTYPEREVISION_H + +#include <QObject> + +class TestTypeRevision : public QObject +{ + Q_OBJECT + +private slots: + void testRevisionAttr(); +}; + +#endif diff --git a/typedatabase.cpp b/typedatabase.cpp index 5ba658bd7..338c40394 100644 --- a/typedatabase.cpp +++ b/typedatabase.cpp @@ -415,3 +415,17 @@ void TypeDatabase::setDropTypeEntries(QStringList dropTypeEntries) m_dropTypeEntries.sort(); } +typedef QHash<TypeEntry*, int> TypeRevisionMap; +Q_GLOBAL_STATIC(TypeRevisionMap, typeRevisions); + +int getTypeRevision(TypeEntry* typeEntry) +{ + return typeRevisions()->value(typeEntry); +} + +void setTypeRevision(TypeEntry* typeEntry, int revision) +{ + typeRevisions()->insert(typeEntry, revision); +} + + diff --git a/typedatabase.h b/typedatabase.h index 583813882..d6ceeecc7 100644 --- a/typedatabase.h +++ b/typedatabase.h @@ -27,6 +27,9 @@ #include <QStringList> #include "typesystem.h" +APIEXTRACTOR_API void setTypeRevision(TypeEntry* typeEntry, int revision); +APIEXTRACTOR_API int getTypeRevision(TypeEntry* typeEntry); + class ContainerTypeEntry; class PrimitiveTypeEntry; class APIEXTRACTOR_API TypeDatabase diff --git a/typesystem.cpp b/typesystem.cpp index 896374a8b..b653bd57b 100644 --- a/typesystem.cpp +++ b/typesystem.cpp @@ -409,6 +409,7 @@ bool Handler::startElement(const QString &, const QString &n, QHash<QString, QString> attributes; attributes["name"] = QString(); attributes["since"] = QString("0"); + attributes["revision"] = QString("0"); switch (element->type) { case StackElement::PrimitiveTypeEntry: @@ -423,6 +424,7 @@ bool Handler::startElement(const QString &, const QString &n, break; case StackElement::EnumTypeEntry: attributes["flags"] = QString(); + attributes["flags-revision"] = QString(); attributes["upper-bound"] = QString(); attributes["lower-bound"] = QString(); attributes["force-integer"] = "no"; @@ -526,6 +528,7 @@ bool Handler::startElement(const QString &, const QString &n, m_error = "no 'name' attribute specified"; return false; } + switch (element->type) { case StackElement::PrimitiveTypeEntry: { QString targetLangName = attributes["target-lang-name"]; @@ -619,6 +622,9 @@ bool Handler::startElement(const QString &, const QString &n, m_database->addFlagsType(ftype); m_database->addType(ftype); + + QString revision = attributes["flags-revision"].isEmpty() ? attributes["revision"] : attributes["flags-revision"]; + setTypeRevision(ftype, revision.toInt()); } } break; @@ -746,10 +752,12 @@ bool Handler::startElement(const QString &, const QString &n, Q_ASSERT(false); }; - if (element->entry) + if (element->entry) { m_database->addType(element->entry); - else + setTypeRevision(element->entry, attributes["revision"].toInt()); + } else { ReportHandler::warning(QString("Type: %1 was rejected by typesystem").arg(name)); + } } else if (element->type == StackElement::InjectDocumentation) { // check the XML tag attributes |