Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/linguist/lupdate/cpp.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    5151#include <QtCore/QTextCodec>
    5252#include <QtCore/QTextStream>
     53#include <QtCore/QCoreApplication>
     54
     55#include <iostream>
    5356
    5457#include <ctype.h>              // for isXXX()
    5558
    5659QT_BEGIN_NAMESPACE
     60
     61class LU {
     62    Q_DECLARE_TR_FUNCTIONS(LUpdate)
     63};
    5764
    5865/* qmake ignore Q_OBJECT */
     
    226233        int elseLine;
    227234    };
     235
     236    std::ostream &yyMsg(int line = 0);
    228237
    229238    uint getChar();
     
    353362}
    354363
     364
     365std::ostream &CppParser::yyMsg(int line)
     366{
     367    return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": ";
     368}
     369
    355370void CppParser::setInput(const QString &in)
    356371{
     
    475490STRING(friend);
    476491STRING(namespace);
     492STRING(operator);
    477493STRING(qtTrId);
    478494STRING(return);
     
    614630                                || yyBraceDepth != is.braceDepth1st
    615631                                || yyParenDepth != is.parenDepth1st)
    616                                 qWarning("%s:%d: Parenthesis/bracket/brace mismatch between "
    617                                          "#if and #else branches; using #if branch\n",
    618                                          qPrintable(yyFileName), is.elseLine);
     632                                yyMsg(is.elseLine)
     633                                    << qPrintable(LU::tr("Parenthesis/bracket/brace mismatch between "
     634                                                         "#if and #else branches; using #if branch\n"));
    619635                        } else {
    620636                            is.bracketDepth1st = yyBracketDepth;
     
    637653                                || yyBraceDepth != is.braceDepth1st
    638654                                || yyParenDepth != is.parenDepth1st)
    639                                 qWarning("%s:%d: Parenthesis/brace mismatch between "
    640                                          "#if and #else branches; using #if branch\n",
    641                                          qPrintable(yyFileName), is.elseLine);
     655                                yyMsg(is.elseLine)
     656                                    << qPrintable(LU::tr("Parenthesis/brace mismatch between "
     657                                                         "#if and #else branches; using #if branch\n"));
    642658                            yyBracketDepth = is.bracketDepth1st;
    643659                            yyBraceDepth = is.braceDepth1st;
     
    665681                            yyCh = getChar();
    666682                            if (yyCh == EOF) {
    667                                 qWarning("%s:%d: Unterminated C++ comment\n",
    668                                          qPrintable(yyFileName), yyLineNo);
     683                                yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n"));
    669684                                break;
    670685                            }
     
    740755                    return Tok_namespace;
    741756                break;
     757            case 'o':
     758                if (yyWord == stroperator) {
     759                    // Operator overload declaration/definition.
     760                    // We need to prevent those characters from confusing the followup
     761                    // parsing. Actually using them does not add value, so just eat them.
     762                    while (isspace(yyCh))
     763                       yyCh = getChar();
     764                    while (yyCh == '+' || yyCh == '-' || yyCh == '*' || yyCh == '/' || yyCh == '%'
     765                           || yyCh == '=' || yyCh == '<' || yyCh == '>' || yyCh == '!'
     766                           || yyCh == '&' || yyCh == '|' || yyCh == '~' || yyCh == '^'
     767                           || yyCh == '[' || yyCh == ']')
     768                        yyCh = getChar();
     769                }
     770                break;
    742771            case 'q':
    743772                if (yyWord == strqtTrId)
     
    796825                        yyCh = getChar();
    797826                        if (yyCh == EOF) {
    798                             qWarning("%s:%d: Unterminated C++ comment\n",
    799                                      qPrintable(yyFileName), yyLineNo);
     827                            yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n"));
    800828                            break;
    801829                        }
     
    830858
    831859                if (yyCh != '"')
    832                     qWarning("%s:%d: Unterminated C++ string\n",
    833                               qPrintable(yyFileName), yyLineNo);
     860                    yyMsg() << qPrintable(LU::tr("Unterminated C++ string\n"));
    834861                else
    835862                    yyCh = getChar();
     
    868895                forever {
    869896                    if (yyCh == EOF || yyCh == '\n') {
    870                         qWarning("%s:%d: Unterminated C++ character\n",
    871                                   qPrintable(yyFileName), yyLineNo);
     897                        yyMsg() << "Unterminated C++ character\n";
    872898                        break;
    873899                    }
     
    888914                if (yyBraceDepth == yyMinBraceDepth) {
    889915                    if (!inDefine)
    890                         qWarning("%s:%d: Excess closing brace in C++ code"
    891                                   " (or abuse of the C++ preprocessor)\n",
    892                                   qPrintable(yyFileName), yyCurLineNo);
     916                        yyMsg(yyCurLineNo)
     917                            << qPrintable(LU::tr("Excess closing brace in C++ code"
     918                                                 " (or abuse of the C++ preprocessor)\n"));
    893919                    // Avoid things getting messed up even more
    894920                    yyCh = getChar();
     
    906932            case ')':
    907933                if (yyParenDepth == 0)
    908                     qWarning("%s:%d: Excess closing parenthesis in C++ code"
    909                              " (or abuse of the C++ preprocessor)\n",
    910                              qPrintable(yyFileName), yyCurLineNo);
     934                    yyMsg(yyCurLineNo)
     935                        << qPrintable(LU::tr("Excess closing parenthesis in C++ code"
     936                                             " (or abuse of the C++ preprocessor)\n"));
    911937                else
    912938                    yyParenDepth--;
     
    921947            case ']':
    922948                if (yyBracketDepth == 0)
    923                     qWarning("%s:%d: Excess closing bracket in C++ code"
    924                              " (or abuse of the C++ preprocessor)\n",
    925                              qPrintable(yyFileName), yyCurLineNo);
     949                    yyMsg(yyCurLineNo)
     950                        << qPrintable(LU::tr("Excess closing bracket in C++ code"
     951                                             " (or abuse of the C++ preprocessor)\n"));
    926952                else
    927953                    yyBracketDepth--;
     
    12911317
    12921318    if (inclusions.contains(cleanFile)) {
    1293         qWarning("%s:%d: circular inclusion of %s\n",
    1294                  qPrintable(yyFileName), yyLineNo, qPrintable(cleanFile));
     1319        yyMsg() << qPrintable(LU::tr("circular inclusion of %1\n").arg(cleanFile));
    12951320        return;
    12961321    }
     
    13161341    QFile f(cleanFile);
    13171342    if (!f.open(QIODevice::ReadOnly)) {
    1318         qWarning("%s:%d: Cannot open %s: %s\n",
    1319                  qPrintable(yyFileName), yyLineNo,
    1320                  qPrintable(cleanFile), qPrintable(f.errorString()));
     1343        yyMsg() << qPrintable(LU::tr("Cannot open %1: %2\n").arg(cleanFile, f.errorString()));
    13211344        return;
    13221345    }
     
    16571680                    NamespaceList nsl;
    16581681                    if (!fullyQualify(namespaces, quali, true, &nsl, 0)) {
    1659                         qWarning("%s:%d: Ignoring definition of undeclared qualified class\n",
    1660                                  qPrintable(yyFileName), yyLineNo);
     1682                        yyMsg() << "Ignoring definition of undeclared qualified class\n";
    16611683                        break;
    16621684                    }
     
    16721694                prospectiveContext.clear();
    16731695                pendingContext.clear();
     1696
     1697                yyTok = getToken();
    16741698            }
    16751699            break;
     
    16851709                    namespaceDepths.push(namespaces.count());
    16861710                    enterNamespace(&namespaces, ns);
     1711
     1712                    functionContext = namespaces;
     1713                    functionContextUnresolved.clear();
     1714                    prospectiveContext.clear();
     1715                    pendingContext.clear();
    16871716                    yyTok = getToken();
    16881717                } else if (yyTok == Tok_Equals) {
     
    17581787                goto case_default;
    17591788            if (!sourcetext.isEmpty())
    1760                 qWarning("%s:%d: //%% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n",
    1761                          qPrintable(yyFileName), yyLineNo);
     1789                yyMsg() << qPrintable(LU::tr("//% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n"));
    17621790            utf8 = (yyTok == Tok_trUtf8);
    17631791            line = yyLineNo;
     
    17801808                    if (!fullyQualify(namespaces, pendingContext, true, &functionContext, &unresolved)) {
    17811809                        functionContextUnresolved = unresolved.join(strColons);
    1782                         qWarning("%s:%d: Qualifying with unknown namespace/class %s::%s\n",
    1783                                  qPrintable(yyFileName), yyLineNo,
    1784                                  qPrintable(stringifyNamespace(functionContext)),
    1785                                  qPrintable(unresolved.first()));
     1810                        yyMsg() << qPrintable(LU::tr("Qualifying with unknown namespace/class %1::%2\n")
     1811                                              .arg(stringifyNamespace(functionContext)).arg(unresolved.first()));
    17861812                    }
    17871813                    pendingContext.clear();
     
    17911817                        int idx = functionContext.length();
    17921818                        if (idx < 2) {
    1793                             qWarning("%s:%d: tr() cannot be called without context\n",
    1794                                      qPrintable(yyFileName), yyLineNo);
     1819                            yyMsg() << qPrintable(LU::tr("tr() cannot be called without context\n"));
    17951820                            break;
    17961821                        }
     
    18011826                                fctx = findNamespace(functionContext)->classDef;
    18021827                                if (!fctx->complained) {
    1803                                     qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n",
    1804                                              qPrintable(yyFileName), yyLineNo,
    1805                                              qPrintable(context));
     1828                                    yyMsg() << qPrintable(LU::tr("Class '%1' lacks Q_OBJECT macro\n")
     1829                                                         .arg(context));
    18061830                                    fctx->complained = true;
    18071831                                }
     
    18311855                    QString className = prefix.mid(last == -1 ? 0 : last + 2);
    18321856                    if (!className.isEmpty() && className == functionName) {
    1833                         qWarning("%s::%d: It is not recommended to call tr() from within a constructor '%s::%s' ",
    1834                                   qPrintable(yyFileName), yyLineNo,
    1835                                   className.constData(), functionName.constData());
     1857                        yyMsg() << qPrintable(LU::tr("It is not recommended to call tr() from within a constructor '%1::%2'\n")
     1858                                .arg(className).arg(functionName));
    18361859                    }
    18371860#endif
     
    18481871                        }
    18491872                        if (!fctx->hasTrFunctions && !fctx->complained) {
    1850                             qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n",
    1851                                      qPrintable(yyFileName), yyLineNo,
    1852                                      qPrintable(context));
     1873                            yyMsg() << qPrintable(LU::tr("Class '%1' lacks Q_OBJECT macro\n").arg(context));
    18531874                            fctx->complained = true;
    18541875                        }
     
    18621883                recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural);
    18631884            }
     1885            sourcetext.clear(); // Will have warned about that already
    18641886            extracomment.clear();
    18651887            msgid.clear();
     
    18711893                goto case_default;
    18721894            if (!sourcetext.isEmpty())
    1873                 qWarning("%s:%d: //%% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n",
    1874                          qPrintable(yyFileName), yyLineNo);
     1895                yyMsg() << qPrintable(LU::tr("//% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n"));
    18751896            utf8 = (yyTok == Tok_translateUtf8);
    18761897            line = yyLineNo;
     
    19181939                recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural);
    19191940            }
     1941            sourcetext.clear(); // Will have warned about that already
    19201942            extracomment.clear();
    19211943            msgid.clear();
     
    19261948                goto case_default;
    19271949            if (!msgid.isEmpty())
    1928                 qWarning("%s:%d: //= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n",
    1929                          qPrintable(yyFileName), yyLineNo);
     1950                yyMsg() << qPrintable(LU::tr("//= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n"));
    19301951            //utf8 = false; // Maybe use //%% or something like that
    19311952            line = yyLineNo;
     
    19942015                        continue;
    19952016                    if (c != '"') {
    1996                         qWarning("%s:%d: Unexpected character in meta string\n",
    1997                                  qPrintable(yyFileName), yyLineNo);
     2017                        yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n"));
    19982018                        break;
    19992019                    }
     
    20012021                        if (p >= yyWord.length()) {
    20022022                          whoops:
    2003                             qWarning("%s:%d: Unterminated meta string\n",
    2004                                      qPrintable(yyFileName), yyLineNo);
     2023                            yyMsg() << qPrintable(LU::tr("Unterminated meta string\n"));
    20052024                            break;
    20062025                        }
     
    20552074            yyTok = getToken();
    20562075            if (yyTok == Tok_tr || yyTok == Tok_trUtf8)
    2057                 qWarning("%s:%d: Cannot invoke tr() like this\n",
    2058                           qPrintable(yyFileName), yyLineNo);
     2076                yyMsg() << qPrintable(LU::tr("Cannot invoke tr() like this\n"));
    20592077            break;
    20602078        case Tok_ColonColon:
     
    20882106            prospectiveContext.clear();
    20892107            prefix.clear();
    2090             extracomment.clear();
    2091             msgid.clear();
    2092             extra.clear();
     2108            if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) {
     2109                yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n"));
     2110                sourcetext.clear();
     2111                extracomment.clear();
     2112                msgid.clear();
     2113                extra.clear();
     2114            }
    20932115            yyTokColonSeen = false;
    20942116            yyTok = getToken();
     
    21242146
    21252147    if (yyBraceDepth != 0)
    2126         qWarning("%s:%d: Unbalanced opening brace in C++ code"
    2127                   " (or abuse of the C++ preprocessor)\n",
    2128                   qPrintable(yyFileName), yyBraceLineNo);
     2148        yyMsg(yyBraceLineNo)
     2149            << qPrintable(LU::tr("Unbalanced opening brace in C++ code"
     2150                                 " (or abuse of the C++ preprocessor)\n"));
    21292151    else if (yyParenDepth != 0)
    2130         qWarning("%s:%d: Unbalanced opening parenthesis in C++ code"
    2131                  " (or abuse of the C++ preprocessor)\n",
    2132                  qPrintable(yyFileName), yyParenLineNo);
     2152        yyMsg(yyParenLineNo)
     2153            << qPrintable(LU::tr("Unbalanced opening parenthesis in C++ code"
     2154                                 " (or abuse of the C++ preprocessor)\n"));
    21332155    else if (yyBracketDepth != 0)
    2134         qWarning("%s:%d: Unbalanced opening bracket in C++ code"
    2135                  " (or abuse of the C++ preprocessor)\n",
    2136                  qPrintable(yyFileName), yyBracketLineNo);
     2156        yyMsg(yyBracketLineNo)
     2157            << qPrintable(LU::tr("Unbalanced opening bracket in C++ code"
     2158                                 " (or abuse of the C++ preprocessor)\n"));
    21372159}
    21382160
     
    21952217        QFile file(filename);
    21962218        if (!file.open(QIODevice::ReadOnly)) {
    2197             cd.appendError(QString::fromLatin1("Cannot open %1: %2")
    2198                 .arg(filename, file.errorString()));
     2219            cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
    21992220            continue;
    22002221        }
Note: See TracChangeset for help on using the changeset viewer.