diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-09-22 18:27:26 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-09-23 13:45:04 (GMT) |
commit | 178945342d0d46ddde460f230c22d2acb9f930a8 (patch) | |
tree | b1d0dacb0caafc5d4e89a40b5525737c5695117b /tools/linguist/lupdate/cpp.cpp | |
parent | 158a48e06134845a72dcab14452390641747d211 (diff) | |
download | Qt-178945342d0d46ddde460f230c22d2acb9f930a8.zip Qt-178945342d0d46ddde460f230c22d2acb9f930a8.tar.gz Qt-178945342d0d46ddde460f230c22d2acb9f930a8.tar.bz2 |
actually use the argument of Q_DECLARE_TR_FUNCTIONS
which means that one can set an arbitrary context.
as a side effect, this caches the stringified context of
Q_OBJECT-derived classes.
Diffstat (limited to 'tools/linguist/lupdate/cpp.cpp')
-rw-r--r-- | tools/linguist/lupdate/cpp.cpp | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/tools/linguist/lupdate/cpp.cpp b/tools/linguist/lupdate/cpp.cpp index 81623ab..44a8feb 100644 --- a/tools/linguist/lupdate/cpp.cpp +++ b/tools/linguist/lupdate/cpp.cpp @@ -133,6 +133,8 @@ struct Namespace { // definition (either one in case of multiple definitions). Namespace *classDef; + QString trQualification; + bool hasTrFunctions; bool complained; // ... that tr functions are missing. }; @@ -221,6 +223,7 @@ private: uint getChar(); uint getToken(); + bool getMacroArgs(); bool match(uint t); bool matchString(QString *s); bool matchEncoding(bool *utf8); @@ -416,6 +419,34 @@ uint CppParser::getChar() } } +// This ignores commas, parens and comments. +// IOW, it understands only a single, simple argument. +bool CppParser::getMacroArgs() +{ + // Failing this assertion would mean losing the preallocated buffer. + Q_ASSERT(yyWord.isDetached()); + yyWord.resize(0); + + while (isspace(yyCh)) + yyCh = getChar(); + if (yyCh != '(') + return false; + do { + yyCh = getChar(); + } while (isspace(yyCh)); + ushort *ptr = (ushort *)yyWord.unicode(); + while (yyCh != ')') { + if (yyCh == EOF) + return false; + *ptr++ = yyCh; + yyCh = getChar(); + } + yyCh = getChar(); + for (; ptr != (ushort *)yyWord.unicode() && isspace(*(ptr - 1)); --ptr) ; + yyWord.resize(ptr - (ushort *)yyWord.unicode()); + return true; +} + STRING(Q_OBJECT); STRING(Q_DECLARE_TR_FUNCTIONS); STRING(QT_TR_NOOP); @@ -1666,10 +1697,11 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) qPrintable(yyFileName), yyLineNo); break; } - while (!findNamespace(functionContext, idx)->classDef->hasTrFunctions) { + Namespace *fctx; + while (!(fctx = findNamespace(functionContext, idx)->classDef)->hasTrFunctions) { if (idx == 1) { context = stringifyNamespace(functionContext); - Namespace *fctx = findNamespace(functionContext)->classDef; + fctx = findNamespace(functionContext)->classDef; if (!fctx->complained) { qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n", qPrintable(yyFileName), yyLineNo, @@ -1680,12 +1712,17 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) } --idx; } - context.clear(); - for (int i = 1;;) { - context += functionContext.at(i).value(); - if (++i == idx) - break; - context += strColons; + if (fctx->trQualification.isEmpty()) { + context.clear(); + for (int i = 1;;) { + context += functionContext.at(i).value(); + if (++i == idx) + break; + context += strColons; + } + fctx->trQualification = context; + } else { + context = fctx->trQualification; } } else { context = (stringListifyNamespace(functionContext) @@ -1705,8 +1742,13 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) NamespaceList nsl; QStringList unresolved; if (fullyQualify(functionContext, prefix, false, &nsl, &unresolved)) { - context = stringifyNamespace(nsl); Namespace *fctx = findNamespace(nsl)->classDef; + if (fctx->trQualification.isEmpty()) { + context = stringifyNamespace(nsl); + fctx->trQualification = context; + } else { + context = fctx->trQualification; + } if (!fctx->hasTrFunctions && !fctx->complained) { qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n", qPrintable(yyFileName), yyLineNo, @@ -1806,6 +1848,14 @@ void CppParser::parseInternal(ConversionData &cd, QSet<QString> &inclusions) extra.clear(); break; case Tok_Q_DECLARE_TR_FUNCTIONS: + if (getMacroArgs()) { + Namespace *ns = modifyNamespace(&namespaces, true); + ns->hasTrFunctions = true; + ns->trQualification = yyWord; + ns->trQualification.detach(); + } + yyTok = getToken(); + break; case Tok_Q_OBJECT: modifyNamespace(&namespaces, true)->hasTrFunctions = true; yyTok = getToken(); |