aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-02-17 10:15:45 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:15 -0300
commitd63acce85c01257af96809f1081ab479d1f703a8 (patch)
treee78a9e9f566dff5aac4795c325745d4996b3f269
parent2ca6e422c0a4c58fad74fe523abb25716df81ce2 (diff)
Added a depth counter to avoid segmentation faults when discarding type entries.
And an unit test was added. Reviewed by Lauro Moura <lauro.neto@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--tests/testdroptypeentries.cpp28
-rw-r--r--tests/testdroptypeentries.h2
-rw-r--r--typesystem.cpp27
-rw-r--r--typesystem_p.h3
4 files changed, 50 insertions, 10 deletions
diff --git a/tests/testdroptypeentries.cpp b/tests/testdroptypeentries.cpp
index 159bb67a9..5e646eac9 100644
--- a/tests/testdroptypeentries.cpp
+++ b/tests/testdroptypeentries.cpp
@@ -104,6 +104,34 @@ void TestDropTypeEntries::testDontDropEntries()
QVERIFY(td->findType("funcB"));
}
+static const char* cppCode2 ="\
+ struct ValueA {\
+ void func();\
+ };\
+";
+
+static const char* xmlCode2 = "\
+<typesystem package='Foo'>\
+ <value-type name='ValueA'>\
+ <modify-function signature='func()'>\
+ <remove class='all' />\
+ </modify-function>\
+ </value-type>\
+</typesystem>";
+
+void TestDropTypeEntries::testDropEntryWithChildTags()
+{
+ QStringList droppedEntries("Foo.ValueA");
+ TestUtil t(cppCode2, xmlCode2, false, 0, droppedEntries);
+ QVERIFY(!t.builder()->classes().findClass("ValueA"));
+}
+
+void TestDropTypeEntries::testDontDropEntryWithChildTags()
+{
+ TestUtil t(cppCode2, xmlCode2, false);
+ QVERIFY(t.builder()->classes().findClass("ValueA"));
+}
+
QTEST_APPLESS_MAIN(TestDropTypeEntries)
#include "testdroptypeentries.moc"
diff --git a/tests/testdroptypeentries.h b/tests/testdroptypeentries.h
index d03f82742..e91292c12 100644
--- a/tests/testdroptypeentries.h
+++ b/tests/testdroptypeentries.h
@@ -32,6 +32,8 @@ class TestDropTypeEntries : public QObject
private slots:
void testDropEntries();
void testDontDropEntries();
+ void testDropEntryWithChildTags();
+ void testDontDropEntryWithChildTags();
};
#endif
diff --git a/typesystem.cpp b/typesystem.cpp
index 3ccb33543..c9f6ac734 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -38,7 +38,8 @@ Handler::Handler(TypeDatabase* database, bool generate)
{
m_currentEnum = 0;
m_current = 0;
- m_currentOptional = 0;
+ m_currentDroppedEntry = 0;
+ m_currentDroppedEntryDepth = 0;
tagNames["rejection"] = StackElement::Rejection;
tagNames["primitive-type"] = StackElement::PrimitiveTypeEntry;
@@ -124,10 +125,15 @@ void Handler::fetchAttributeValues(const QString &name, const QXmlAttributes &at
bool Handler::endElement(const QString &, const QString &localName, const QString &)
{
- if (m_currentOptional) {
- m_current = m_currentOptional->parent;
- delete m_currentOptional;
- m_currentOptional = 0;
+ if (m_currentDroppedEntry) {
+ if (m_currentDroppedEntryDepth == 1) {
+ m_current = m_currentDroppedEntry->parent;
+ delete m_currentDroppedEntry;
+ m_currentDroppedEntry = 0;
+ m_currentDroppedEntryDepth = 0;
+ } else {
+ ++m_currentDroppedEntryDepth;
+ }
return true;
}
@@ -216,7 +222,7 @@ bool Handler::endElement(const QString &, const QString &localName, const QStrin
bool Handler::characters(const QString &ch)
{
- if (m_currentOptional)
+ if (m_currentDroppedEntry)
return true;
if (m_current->type == StackElement::Template) {
@@ -383,8 +389,10 @@ bool Handler::startElement(const QString &, const QString &n,
return false;
}
- if (m_currentOptional)
+ if (m_currentDroppedEntry) {
+ ++m_currentDroppedEntryDepth;
return true;
+ }
StackElement* element = new StackElement(m_current);
element->type = tagNames[tagName];
@@ -461,8 +469,9 @@ bool Handler::startElement(const QString &, const QString &n,
QString identifier = getNamePrefix(element) + '.';
identifier += (element->type == StackElement::FunctionTypeEntry ? attributes["signature"] : name);
if (m_database->shouldDropTypeEntry(identifier)) {
- m_currentOptional = element;
- ReportHandler::debugSparse(QString("Optional type system entry '%1' was dropped from generation.").arg(identifier));
+ m_currentDroppedEntry = element;
+ m_currentDroppedEntryDepth = 1;
+ ReportHandler::debugSparse(QString("Type system entry '%1' was intentionally dropped from generation.").arg(identifier));
return true;
}
}
diff --git a/typesystem_p.h b/typesystem_p.h
index 97859425a..d69de3fcb 100644
--- a/typesystem_p.h
+++ b/typesystem_p.h
@@ -149,7 +149,8 @@ private:
TypeDatabase* m_database;
StackElement* m_current;
- StackElement* m_currentOptional;
+ StackElement* m_currentDroppedEntry;
+ int m_currentDroppedEntryDepth;
QString m_defaultPackage;
QString m_defaultSuperclass;
QString m_error;