summaryrefslogtreecommitdiffstats
path: root/src/linguist/lupdate/qdeclarative.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linguist/lupdate/qdeclarative.cpp')
-rw-r--r--src/linguist/lupdate/qdeclarative.cpp128
1 files changed, 43 insertions, 85 deletions
diff --git a/src/linguist/lupdate/qdeclarative.cpp b/src/linguist/lupdate/qdeclarative.cpp
index 753c239ad..e62cfec15 100644
--- a/src/linguist/lupdate/qdeclarative.cpp
+++ b/src/linguist/lupdate/qdeclarative.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Linguist of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "lupdate.h"
@@ -33,13 +8,13 @@
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QString>
+#include <QtCore/QTextStream>
#include <private/qqmljsengine_p.h>
#include <private/qqmljsparser_p.h>
#include <private/qqmljslexer_p.h>
#include <private/qqmljsastvisitor_p.h>
#include <private/qqmljsast_p.h>
-#include <private/qqmlapiversion_p.h>
#include <QCoreApplication>
#include <QFile>
@@ -53,15 +28,9 @@
QT_BEGIN_NAMESPACE
-#if Q_QML_PRIVATE_API_VERSION < 8
-namespace QQmlJS {
- using SourceLocation = AST::SourceLocation;
-}
-#endif
-
using namespace QQmlJS;
-static QString MagicComment(QLatin1String("TRANSLATOR"));
+using namespace Qt::StringLiterals;
class FindTrCalls: protected AST::Visitor
{
@@ -89,7 +58,17 @@ protected:
using AST::Visitor::endVisit;
void accept(AST::Node *node)
- { AST::Node::acceptChild(node, this); }
+ { AST::Node::accept(node, this); }
+
+ bool visit(AST::UiPragma *node) override
+ {
+ if (!node->name.isNull()) {
+ if (node->name == "Translator"_L1) {
+ m_component = node->values->value.toString();
+ }
+ }
+ return false;
+ }
void endVisit(AST::CallExpression *node) override
{
@@ -112,11 +91,9 @@ protected:
case TrFunctionAliasManager::Function_qsTr:
case TrFunctionAliasManager::Function_QT_TR_NOOP: {
if (!node->arguments) {
- yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
- return;
- }
- if (AST::cast<AST::TemplateLiteral *>(node->arguments->expression)) {
- yyMsg(identLineNo) << qPrintable(LU::tr("%1() cannot be used with template literals. Ignoring\n").arg(name));
+ yyMsg(identLineNo)
+ << qPrintable(QStringLiteral("%1() requires at least one argument.\n")
+ .arg(name));
return;
}
@@ -135,7 +112,7 @@ protected:
}
if (!sourcetext.isEmpty())
- yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
+ yyMsg(identLineNo) << qPrintable(QStringLiteral("//% cannot be used with %1(). Ignoring\n").arg(name));
TranslatorMessage msg(m_component, ParserTool::transcode(source),
comment, QString(), m_fileName,
@@ -150,7 +127,7 @@ protected:
case TrFunctionAliasManager::Function_qsTranslate:
case TrFunctionAliasManager::Function_QT_TRANSLATE_NOOP: {
if (! (node->arguments && node->arguments->next)) {
- yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least two arguments.\n").arg(name));
+ yyMsg(identLineNo) << qPrintable(QStringLiteral("%1() requires at least two arguments.\n").arg(name));
return;
}
@@ -165,7 +142,7 @@ protected:
return;
if (!sourcetext.isEmpty())
- yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name));
+ yyMsg(identLineNo) << qPrintable(QStringLiteral("//% cannot be used with %1(). Ignoring\n").arg(name));
QString comment;
bool plural = false;
@@ -191,7 +168,7 @@ protected:
case TrFunctionAliasManager::Function_qsTrId:
case TrFunctionAliasManager::Function_QT_TRID_NOOP: {
if (!node->arguments) {
- yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name));
+ yyMsg(identLineNo) << qPrintable(QStringLiteral("%1() requires at least one argument.\n").arg(name));
return;
}
@@ -200,7 +177,7 @@ protected:
return;
if (!msgid.isEmpty()) {
- yyMsg(identLineNo) << qPrintable(LU::tr("//= cannot be used with %1(). Ignoring\n").arg(name));
+ yyMsg(identLineNo) << qPrintable(QStringLiteral("//= cannot be used with %1(). Ignoring\n").arg(name));
return;
}
@@ -231,7 +208,7 @@ private:
void throwRecursionDepthError() final
{
std::cerr << qPrintable(m_fileName) << ": "
- << qPrintable(LU::tr("Maximum statement or expression depth exceeded"));
+ << "Maximum statement or expression depth exceeded";
}
@@ -249,6 +226,9 @@ private:
if (createString(binop->right, out))
return true;
}
+ } else if (AST::TemplateLiteral *templit = AST::cast<AST::TemplateLiteral *>(ast)) {
+ out->append(templit->value);
+ return true;
}
return false;
@@ -282,20 +262,15 @@ QString createErrorString(const QString &filename, const QString &code, Parser &
if (m.isWarning())
continue;
-#if Q_QML_PRIVATE_API_VERSION >= 8
const int line = m.loc.startLine;
const int column = m.loc.startColumn;
-#else
- const int line = m.line;
- const int column = m.column;
-#endif
QString error = filename + QLatin1Char(':')
+ QString::number(line) + QLatin1Char(':') + QString::number(column)
+ QLatin1String(": error: ") + m.message + QLatin1Char('\n');
const QString textLine = lines.at(line > 0 ? line - 1 : 0);
error += textLine + QLatin1Char('\n');
- for (int i = 0, end = qMin(column > 0 ? column - 1 : 0, textLine.length()); i < end; ++i) {
+ for (int i = 0, end = qMin(column > 0 ? column - 1 : 0, textLine.size()); i < end; ++i) {
const QChar ch = textLine.at(i);
if (ch.isSpace())
error += ch;
@@ -314,7 +289,7 @@ void FindTrCalls::postVisit(AST::Node *node)
processComments(node->lastSourceLocation().end());
if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) {
- yyMsg(node->lastSourceLocation().startLine) << qPrintable(LU::tr("Discarding unconsumed meta data\n"));
+ yyMsg(node->lastSourceLocation().startLine) << "Discarding unconsumed meta data\n";
consumeComment();
}
}
@@ -347,7 +322,7 @@ void FindTrCalls::processComment(const SourceLocation &loc)
const QStringView commentStr = engine->midRef(loc.begin(), loc.length);
const QChar *chars = commentStr.constData();
- const int length = commentStr.length();
+ const int length = commentStr.size();
// Try to match the logic of the C++ parser.
if (*chars == QLatin1Char(':') && chars[1].isSpace()) {
@@ -359,11 +334,17 @@ void FindTrCalls::processComment(const SourceLocation &loc)
} else if (*chars == QLatin1Char('~') && chars[1].isSpace()) {
QString text = QString(chars+2, length-2).trimmed();
int k = text.indexOf(QLatin1Char(' '));
- if (k > -1)
- extra.insert(text.left(k), text.mid(k + 1).trimmed());
+ if (k > -1) {
+ QString commentvalue = text.mid(k + 1).trimmed();
+ if (commentvalue.startsWith(QLatin1Char('"')) && commentvalue.endsWith(QLatin1Char('"'))
+ && commentvalue.size() != 1) {
+ commentvalue = commentvalue.sliced(1, commentvalue.size() - 2);
+ }
+ extra.insert(text.left(k), commentvalue);
+ }
} else if (*chars == QLatin1Char('%') && chars[1].isSpace()) {
- sourcetext.reserve(sourcetext.length() + length-2);
- ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length();
+ sourcetext.reserve(sourcetext.size() + length-2);
+ ushort *ptr = (ushort *)sourcetext.data() + sourcetext.size();
int p = 2, c;
forever {
if (p >= length)
@@ -372,13 +353,13 @@ void FindTrCalls::processComment(const SourceLocation &loc)
if (std::isspace(c))
continue;
if (c != '"') {
- yyMsg(loc.startLine) << qPrintable(LU::tr("Unexpected character in meta string\n"));
+ yyMsg(loc.startLine) << "Unexpected character in meta string\n";
break;
}
forever {
if (p >= length) {
whoops:
- yyMsg(loc.startLine) << qPrintable(LU::tr("Unterminated meta string\n"));
+ yyMsg(loc.startLine) << "Unterminated meta string\n";
break;
}
c = chars[p++].unicode();
@@ -401,29 +382,6 @@ void FindTrCalls::processComment(const SourceLocation &loc)
ushort c;
while ((c = chars[idx].unicode()) == ' ' || c == '\t' || c == '\r' || c == '\n')
++idx;
- if (!memcmp(chars + idx, MagicComment.unicode(), MagicComment.length() * 2)) {
- idx += MagicComment.length();
- QString comment = QString(chars + idx, length - idx).simplified();
- int k = comment.indexOf(QLatin1Char(' '));
- if (k == -1) {
- trcontext = comment;
- } else {
- trcontext = comment.left(k);
- comment.remove(0, k + 1);
- TranslatorMessage msg(
- trcontext, QString(),
- comment, QString(),
- m_fileName, loc.startLine, QStringList(),
- TranslatorMessage::Finished, /*plural=*/false);
- msg.setExtraComment(extracomment.simplified());
- extracomment.clear();
- m_translator->append(msg);
- m_translator->setExtras(extra);
- extra.clear();
- }
-
- m_component = trcontext;
- }
}
}
@@ -461,7 +419,7 @@ static bool load(Translator &translator, const QString &filename, ConversionData
cd.m_sourceFileName = filename;
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
- cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString()));
+ cd.appendError(QStringLiteral("Cannot open %1: %2").arg(filename, file.errorString()));
return false;
}