Changeset 846 for trunk/tools/linguist/lupdate/cpp.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/tools/linguist/lupdate/cpp.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 51 51 #include <QtCore/QTextCodec> 52 52 #include <QtCore/QTextStream> 53 #include <QtCore/QCoreApplication> 54 55 #include <iostream> 53 56 54 57 #include <ctype.h> // for isXXX() 55 58 56 59 QT_BEGIN_NAMESPACE 60 61 class LU { 62 Q_DECLARE_TR_FUNCTIONS(LUpdate) 63 }; 57 64 58 65 /* qmake ignore Q_OBJECT */ … … 226 233 int elseLine; 227 234 }; 235 236 std::ostream &yyMsg(int line = 0); 228 237 229 238 uint getChar(); … … 353 362 } 354 363 364 365 std::ostream &CppParser::yyMsg(int line) 366 { 367 return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": "; 368 } 369 355 370 void CppParser::setInput(const QString &in) 356 371 { … … 475 490 STRING(friend); 476 491 STRING(namespace); 492 STRING(operator); 477 493 STRING(qtTrId); 478 494 STRING(return); … … 614 630 || yyBraceDepth != is.braceDepth1st 615 631 || 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")); 619 635 } else { 620 636 is.bracketDepth1st = yyBracketDepth; … … 637 653 || yyBraceDepth != is.braceDepth1st 638 654 || 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")); 642 658 yyBracketDepth = is.bracketDepth1st; 643 659 yyBraceDepth = is.braceDepth1st; … … 665 681 yyCh = getChar(); 666 682 if (yyCh == EOF) { 667 qWarning("%s:%d: Unterminated C++ comment\n", 668 qPrintable(yyFileName), yyLineNo); 683 yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n")); 669 684 break; 670 685 } … … 740 755 return Tok_namespace; 741 756 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; 742 771 case 'q': 743 772 if (yyWord == strqtTrId) … … 796 825 yyCh = getChar(); 797 826 if (yyCh == EOF) { 798 qWarning("%s:%d: Unterminated C++ comment\n", 799 qPrintable(yyFileName), yyLineNo); 827 yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n")); 800 828 break; 801 829 } … … 830 858 831 859 if (yyCh != '"') 832 qWarning("%s:%d: Unterminated C++ string\n", 833 qPrintable(yyFileName), yyLineNo); 860 yyMsg() << qPrintable(LU::tr("Unterminated C++ string\n")); 834 861 else 835 862 yyCh = getChar(); … … 868 895 forever { 869 896 if (yyCh == EOF || yyCh == '\n') { 870 qWarning("%s:%d: Unterminated C++ character\n", 871 qPrintable(yyFileName), yyLineNo); 897 yyMsg() << "Unterminated C++ character\n"; 872 898 break; 873 899 } … … 888 914 if (yyBraceDepth == yyMinBraceDepth) { 889 915 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")); 893 919 // Avoid things getting messed up even more 894 920 yyCh = getChar(); … … 906 932 case ')': 907 933 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")); 911 937 else 912 938 yyParenDepth--; … … 921 947 case ']': 922 948 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")); 926 952 else 927 953 yyBracketDepth--; … … 1291 1317 1292 1318 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)); 1295 1320 return; 1296 1321 } … … 1316 1341 QFile f(cleanFile); 1317 1342 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())); 1321 1344 return; 1322 1345 } … … 1657 1680 NamespaceList nsl; 1658 1681 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"; 1661 1683 break; 1662 1684 } … … 1672 1694 prospectiveContext.clear(); 1673 1695 pendingContext.clear(); 1696 1697 yyTok = getToken(); 1674 1698 } 1675 1699 break; … … 1685 1709 namespaceDepths.push(namespaces.count()); 1686 1710 enterNamespace(&namespaces, ns); 1711 1712 functionContext = namespaces; 1713 functionContextUnresolved.clear(); 1714 prospectiveContext.clear(); 1715 pendingContext.clear(); 1687 1716 yyTok = getToken(); 1688 1717 } else if (yyTok == Tok_Equals) { … … 1758 1787 goto case_default; 1759 1788 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")); 1762 1790 utf8 = (yyTok == Tok_trUtf8); 1763 1791 line = yyLineNo; … … 1780 1808 if (!fullyQualify(namespaces, pendingContext, true, &functionContext, &unresolved)) { 1781 1809 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())); 1786 1812 } 1787 1813 pendingContext.clear(); … … 1791 1817 int idx = functionContext.length(); 1792 1818 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")); 1795 1820 break; 1796 1821 } … … 1801 1826 fctx = findNamespace(functionContext)->classDef; 1802 1827 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)); 1806 1830 fctx->complained = true; 1807 1831 } … … 1831 1855 QString className = prefix.mid(last == -1 ? 0 : last + 2); 1832 1856 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)); 1836 1859 } 1837 1860 #endif … … 1848 1871 } 1849 1872 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)); 1853 1874 fctx->complained = true; 1854 1875 } … … 1862 1883 recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural); 1863 1884 } 1885 sourcetext.clear(); // Will have warned about that already 1864 1886 extracomment.clear(); 1865 1887 msgid.clear(); … … 1871 1893 goto case_default; 1872 1894 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")); 1875 1896 utf8 = (yyTok == Tok_translateUtf8); 1876 1897 line = yyLineNo; … … 1918 1939 recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural); 1919 1940 } 1941 sourcetext.clear(); // Will have warned about that already 1920 1942 extracomment.clear(); 1921 1943 msgid.clear(); … … 1926 1948 goto case_default; 1927 1949 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")); 1930 1951 //utf8 = false; // Maybe use //%% or something like that 1931 1952 line = yyLineNo; … … 1994 2015 continue; 1995 2016 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")); 1998 2018 break; 1999 2019 } … … 2001 2021 if (p >= yyWord.length()) { 2002 2022 whoops: 2003 qWarning("%s:%d: Unterminated meta string\n", 2004 qPrintable(yyFileName), yyLineNo); 2023 yyMsg() << qPrintable(LU::tr("Unterminated meta string\n")); 2005 2024 break; 2006 2025 } … … 2055 2074 yyTok = getToken(); 2056 2075 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")); 2059 2077 break; 2060 2078 case Tok_ColonColon: … … 2088 2106 prospectiveContext.clear(); 2089 2107 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 } 2093 2115 yyTokColonSeen = false; 2094 2116 yyTok = getToken(); … … 2124 2146 2125 2147 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")); 2129 2151 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")); 2133 2155 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")); 2137 2159 } 2138 2160 … … 2195 2217 QFile file(filename); 2196 2218 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())); 2199 2220 continue; 2200 2221 }
Note:
See TracChangeset
for help on using the changeset viewer.