From ddaa4643c1ee96c9dfc16b1c247481a240e2e16b Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Fri, 5 Mar 2010 15:59:37 +0100 Subject: fix "using namespace" recursion crash Task-number: QTBUG-8360 --- .../lupdate/testdata/good/namespaces/main.cpp | 60 ++++++++++++++++++++++ .../testdata/good/namespaces/project.ts.result | 24 +++++++++ tools/linguist/lupdate/cpp.cpp | 28 +++++++--- 3 files changed, 104 insertions(+), 8 deletions(-) diff --git a/tests/auto/linguist/lupdate/testdata/good/namespaces/main.cpp b/tests/auto/linguist/lupdate/testdata/good/namespaces/main.cpp index 42cc55b..a5b36ca 100644 --- a/tests/auto/linguist/lupdate/testdata/good/namespaces/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/namespaces/main.cpp @@ -135,4 +135,64 @@ Q_OBJECT } }; +// QTBUG-8360 +namespace A { + +void foo() +{ + using namespace A; +} + +void goo() +{ + return QObject::tr("Bla"); +} + +} + + +namespace AA { +namespace B { + +using namespace AA; + +namespace C { + +class Test : public QObject { + Q_OBJECT +}; + +} + +} + +using namespace B; +using namespace C; + +void goo() +{ + AA::Test::tr("howdy?"); +} + +} + + +namespace A1 { +namespace B { + +class Test : public QObject { + Q_OBJECT +}; + +using namespace A1; + +void foo() +{ + B::B::B::Test::tr("yeeee-ha!"); +} + +} +} + + #include "main.moc" diff --git a/tests/auto/linguist/lupdate/testdata/good/namespaces/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/namespaces/project.ts.result index c1a34bd..94df9d3 100644 --- a/tests/auto/linguist/lupdate/testdata/good/namespaces/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/namespaces/project.ts.result @@ -2,6 +2,22 @@ + A1::B::Test + + + yeeee-ha! + + + + + AA::B::C::Test + + + howdy? + + + + Class @@ -79,4 +95,12 @@ + + QObject + + + Bla + + + diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index 6bd9108..2d5620e 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -260,6 +260,8 @@ private: bool qualifyOneCallbackOwn(const Namespace *ns, void *context) const; bool qualifyOneCallbackUsing(const Namespace *ns, void *context) const; bool qualifyOne(const NamespaceList &namespaces, int nsCnt, const HashString &segment, + NamespaceList *resolved, QSet *visitedUsings) const; + bool qualifyOne(const NamespaceList &namespaces, int nsCnt, const HashString &segment, NamespaceList *resolved) const; bool fullyQualify(const NamespaceList &namespaces, int nsCnt, const QList &segments, bool isDeclaration, @@ -1036,15 +1038,16 @@ QStringList CppParser::stringListifySegments(const QList &segments) } struct QualifyOneData { - QualifyOneData(const NamespaceList &ns, int nsc, const HashString &seg, NamespaceList *rslvd) - : namespaces(ns), nsCount(nsc), segment(seg), resolved(rslvd) + QualifyOneData(const NamespaceList &ns, int nsc, const HashString &seg, NamespaceList *rslvd, + QSet *visited) + : namespaces(ns), nsCount(nsc), segment(seg), resolved(rslvd), visitedUsings(visited) {} const NamespaceList &namespaces; int nsCount; const HashString &segment; NamespaceList *resolved; - QSet visitedUsings; + QSet *visitedUsings; }; bool CppParser::qualifyOneCallbackOwn(const Namespace *ns, void *context) const @@ -1078,18 +1081,19 @@ bool CppParser::qualifyOneCallbackUsing(const Namespace *ns, void *context) cons { QualifyOneData *data = (QualifyOneData *)context; foreach (const HashStringList &use, ns->usings) - if (!data->visitedUsings.contains(use)) { - data->visitedUsings.insert(use); - if (qualifyOne(use.value(), use.value().count(), data->segment, data->resolved)) + if (!data->visitedUsings->contains(use)) { + data->visitedUsings->insert(use); + if (qualifyOne(use.value(), use.value().count(), data->segment, data->resolved, + data->visitedUsings)) return true; } return false; } bool CppParser::qualifyOne(const NamespaceList &namespaces, int nsCnt, const HashString &segment, - NamespaceList *resolved) const + NamespaceList *resolved, QSet *visitedUsings) const { - QualifyOneData data(namespaces, nsCnt, segment, resolved); + QualifyOneData data(namespaces, nsCnt, segment, resolved, visitedUsings); if (visitNamespace(namespaces, nsCnt, &CppParser::qualifyOneCallbackOwn, &data)) return true; @@ -1097,6 +1101,14 @@ bool CppParser::qualifyOne(const NamespaceList &namespaces, int nsCnt, const Has return visitNamespace(namespaces, nsCnt, &CppParser::qualifyOneCallbackUsing, &data); } +bool CppParser::qualifyOne(const NamespaceList &namespaces, int nsCnt, const HashString &segment, + NamespaceList *resolved) const +{ + QSet visitedUsings; + + return qualifyOne(namespaces, nsCnt, segment, resolved, &visitedUsings); +} + bool CppParser::fullyQualify(const NamespaceList &namespaces, int nsCnt, const QList &segments, bool isDeclaration, NamespaceList *resolved, QStringList *unresolved) const -- cgit v0.12