diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-11-09 07:43:42 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-11-09 07:43:42 (GMT) |
commit | d2bcb0dfbc79c382dad87d3d2154ca127ae8fc16 (patch) | |
tree | c0848d1fc8fd2215fe32d75dcbe86354b0344282 /tools/linguist/lupdate | |
parent | dbbe24f0f04e5a0aaf9223b73bee873e208a1fa7 (diff) | |
parent | b8b7f98b01d9ad03fecac7a0f593ac5734d7af1d (diff) | |
download | Qt-d2bcb0dfbc79c382dad87d3d2154ca127ae8fc16.zip Qt-d2bcb0dfbc79c382dad87d3d2154ca127ae8fc16.tar.gz Qt-d2bcb0dfbc79c382dad87d3d2154ca127ae8fc16.tar.bz2 |
Merge branch '4.6' of git://scm.dev.nokia.troll.no/qt/qt into kinetic-declarativeui
Conflicts:
configure.exe
src/corelib/animation/qabstractanimation.cpp
src/gui/graphicsview/qgraphicsview.cpp
src/s60installs/s60installs.pro
tools/configure/configureapp.cpp
tools/qdoc3/node.h
Diffstat (limited to 'tools/linguist/lupdate')
-rw-r--r-- | tools/linguist/lupdate/cpp.cpp | 76 |
1 files changed, 53 insertions, 23 deletions
diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index 4d89156..fb95a95 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -135,6 +135,11 @@ struct Namespace { // Nested classes may be forward-declared inside a definition, and defined in another file. // The latter will detach the class' child list, so clones need a backlink to the original // definition (either one in case of multiple definitions). + // Namespaces can have tr() functions as well, so we need to track parent definitions for + // them as well. The complication is that we may have to deal with a forrest instead of + // a tree - in that case the parent will be arbitrary. However, it seem likely that + // Q_DECLARE_TR_FUNCTIONS would be used either in "class-like" namespaces with a central + // header or only locally in a file. Namespace *classDef; QString trQualification; @@ -256,17 +261,20 @@ private: bool qualifyOneCallbackUsing(const Namespace *ns, void *context) const; bool qualifyOne(const NamespaceList &namespaces, int nsCnt, const HashString &segment, NamespaceList *resolved) const; - bool fullyQualify(const NamespaceList &namespaces, const QList<HashString> &segments, - bool isDeclaration, + bool fullyQualify(const NamespaceList &namespaces, int nsCnt, + const QList<HashString> &segments, bool isDeclaration, NamespaceList *resolved, QStringList *unresolved) const; - bool fullyQualify(const NamespaceList &namespaces, const QString &segments, - bool isDeclaration, + bool fullyQualify(const NamespaceList &namespaces, + const QList<HashString> &segments, bool isDeclaration, + NamespaceList *resolved, QStringList *unresolved) const; + bool fullyQualify(const NamespaceList &namespaces, + const QString &segments, bool isDeclaration, NamespaceList *resolved, QStringList *unresolved) const; bool findNamespaceCallback(const Namespace *ns, void *context) const; const Namespace *findNamespace(const NamespaceList &namespaces, int nsCount = -1) const; void enterNamespace(NamespaceList *namespaces, const HashString &name); void truncateNamespaces(NamespaceList *namespaces, int lenght); - Namespace *modifyNamespace(NamespaceList *namespaces, bool tryOrigin = true); + Namespace *modifyNamespace(NamespaceList *namespaces, bool haveLast = true); enum { Tok_Eof, Tok_class, Tok_friend, Tok_namespace, Tok_using, Tok_return, @@ -780,7 +788,7 @@ uint CppParser::getToken() if (yyCh == EOF) { qWarning("%s:%d: Unterminated C++ comment\n", qPrintable(yyFileName), yyLineNo); - return Tok_Comment; + break; } *ptr++ = yyCh; @@ -958,7 +966,7 @@ void CppParser::loadState(const SavedState *state) pendingContext = state->pendingContext; } -Namespace *CppParser::modifyNamespace(NamespaceList *namespaces, bool tryOrigin) +Namespace *CppParser::modifyNamespace(NamespaceList *namespaces, bool haveLast) { Namespace *pns, *ns = &results->rootNamespace; for (int i = 1; i < namespaces->count(); ++i) { @@ -966,7 +974,7 @@ Namespace *CppParser::modifyNamespace(NamespaceList *namespaces, bool tryOrigin) if (!(ns = pns->children.value(namespaces->at(i)))) { do { ns = new Namespace; - if (tryOrigin) + if (haveLast || i < namespaces->count() - 1) if (const Namespace *ons = findNamespace(*namespaces, i + 1)) ns->classDef = ons->classDef; pns->children.insert(namespaces->at(i), ns); @@ -1052,7 +1060,18 @@ bool CppParser::qualifyOneCallbackOwn(const Namespace *ns, void *context) const } QHash<HashString, NamespaceList>::ConstIterator nsai = ns->aliases.constFind(data->segment); if (nsai != ns->aliases.constEnd()) { - *data->resolved = *nsai; + const NamespaceList &nsl = *nsai; + if (nsl.last().value().isEmpty()) { // Delayed alias resolution + NamespaceList &nslIn = *const_cast<NamespaceList *>(&nsl); + nslIn.removeLast(); + NamespaceList nslOut; + if (!fullyQualify(data->namespaces, data->nsCount, nslIn, false, &nslOut, 0)) { + const_cast<Namespace *>(ns)->aliases.remove(data->segment); + return false; + } + nslIn = nslOut; + } + *data->resolved = nsl; return true; } return false; @@ -1081,8 +1100,8 @@ bool CppParser::qualifyOne(const NamespaceList &namespaces, int nsCnt, const Has return visitNamespace(namespaces, nsCnt, &CppParser::qualifyOneCallbackUsing, &data); } -bool CppParser::fullyQualify(const NamespaceList &namespaces, const QList<HashString> &segments, - bool isDeclaration, +bool CppParser::fullyQualify(const NamespaceList &namespaces, int nsCnt, + const QList<HashString> &segments, bool isDeclaration, NamespaceList *resolved, QStringList *unresolved) const { int nsIdx; @@ -1099,7 +1118,7 @@ bool CppParser::fullyQualify(const NamespaceList &namespaces, const QList<HashSt nsIdx = 0; } else { initSegIdx = 0; - nsIdx = namespaces.count() - 1; + nsIdx = nsCnt - 1; } do { @@ -1122,8 +1141,16 @@ bool CppParser::fullyQualify(const NamespaceList &namespaces, const QList<HashSt return false; } -bool CppParser::fullyQualify(const NamespaceList &namespaces, const QString &quali, - bool isDeclaration, +bool CppParser::fullyQualify(const NamespaceList &namespaces, + const QList<HashString> &segments, bool isDeclaration, + NamespaceList *resolved, QStringList *unresolved) const +{ + return fullyQualify(namespaces, namespaces.count(), + segments, isDeclaration, resolved, unresolved); +} + +bool CppParser::fullyQualify(const NamespaceList &namespaces, + const QString &quali, bool isDeclaration, NamespaceList *resolved, QStringList *unresolved) const { static QString strColons(QLatin1String("::")); @@ -1633,9 +1660,8 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) } if (fullName.isEmpty()) break; - NamespaceList nsl; - if (fullyQualify(namespaces, fullName, false, &nsl, 0)) - modifyNamespace(&namespaces, false)->aliases[ns] = nsl; + fullName.append(HashString(QString())); // Mark as unresolved + modifyNamespace(&namespaces)->aliases[ns] = fullName; } } else if (yyTok == Tok_LeftBrace) { // Anonymous namespace @@ -1661,7 +1687,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) } NamespaceList nsl; if (fullyQualify(namespaces, fullName, false, &nsl, 0)) - modifyNamespace(&namespaces, false)->usings << HashStringList(nsl); + modifyNamespace(&namespaces)->usings << HashStringList(nsl); } else { QList<HashString> fullName; if (yyTok == Tok_ColonColon) @@ -1676,9 +1702,13 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) } if (fullName.isEmpty()) break; - NamespaceList nsl; - if (fullyQualify(namespaces, fullName, false, &nsl, 0)) - modifyNamespace(&namespaces, true)->aliases[nsl.last()] = nsl; + // using-declarations cannot rename classes, so the last element of + // fullName is already the resolved name we actually want. + // As we do no resolution here, we'll collect useless usings of data + // members and methods as well. This is no big deal. + HashString &ns = fullName.last(); + fullName.append(HashString(QString())); // Mark as unresolved + modifyNamespace(&namespaces)->aliases[ns] = fullName; } break; case Tok_tr: @@ -1875,7 +1905,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) break; case Tok_Q_DECLARE_TR_FUNCTIONS: if (getMacroArgs()) { - Namespace *ns = modifyNamespace(&namespaces, true); + Namespace *ns = modifyNamespace(&namespaces); ns->hasTrFunctions = true; ns->trQualification = yyWord; ns->trQualification.detach(); @@ -1883,7 +1913,7 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) yyTok = getToken(); break; case Tok_Q_OBJECT: - modifyNamespace(&namespaces, true)->hasTrFunctions = true; + modifyNamespace(&namespaces)->hasTrFunctions = true; yyTok = getToken(); break; case Tok_Ident: |