summaryrefslogtreecommitdiffstats
path: root/tools/linguist
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2010-06-24 01:45:59 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2010-06-24 01:49:30 (GMT)
commit52b3d6263bb58ca82a8f00d42af801f5ed521f6b (patch)
tree96cb8092d544ccd5261381bb79ddca6bdb44eeb1 /tools/linguist
parentbb3ae9779730b6d4a0442ea5553b0dfab1a3da2b (diff)
downloadQt-52b3d6263bb58ca82a8f00d42af801f5ed521f6b.zip
Qt-52b3d6263bb58ca82a8f00d42af801f5ed521f6b.tar.gz
Qt-52b3d6263bb58ca82a8f00d42af801f5ed521f6b.tar.bz2
Update lupdate to recognize concatenated text in QML files.
Also fixes a potential crash with non-string-literal nodes. Task-number: QTBUG-11580
Diffstat (limited to 'tools/linguist')
-rw-r--r--tools/linguist/lupdate/qdeclarative.cpp72
1 files changed, 56 insertions, 16 deletions
diff --git a/tools/linguist/lupdate/qdeclarative.cpp b/tools/linguist/lupdate/qdeclarative.cpp
index 1b35c14..3eef2d7 100644
--- a/tools/linguist/lupdate/qdeclarative.cpp
+++ b/tools/linguist/lupdate/qdeclarative.cpp
@@ -87,17 +87,25 @@ protected:
virtual void endVisit(AST::CallExpression *node)
{
+ m_bSource.clear();
if (AST::IdentifierExpression *idExpr = AST::cast<AST::IdentifierExpression *>(node->base)) {
if (idExpr->name->asString() == QLatin1String("qsTr") ||
idExpr->name->asString() == QLatin1String("QT_TR_NOOP")) {
- if (node->arguments && AST::cast<AST::StringLiteral *>(node->arguments->expression)) {
- AST::StringLiteral *literal = AST::cast<AST::StringLiteral *>(node->arguments->expression);
- const QString source = literal->value->asString();
+ if (!node->arguments)
+ return;
+ AST::BinaryExpression *binary = AST::cast<AST::BinaryExpression *>(node->arguments->expression);
+ if (binary) {
+ if (!createString(binary))
+ m_bSource.clear();
+ }
+ AST::StringLiteral *literal = AST::cast<AST::StringLiteral *>(node->arguments->expression);
+ if (literal || !m_bSource.isEmpty()) {
+ const QString source = literal ? literal->value->asString() : m_bSource;
QString comment;
bool plural = false;
AST::ArgumentList *commentNode = node->arguments->next;
- if (commentNode) {
+ if (commentNode && AST::cast<AST::StringLiteral *>(commentNode->expression)) {
literal = AST::cast<AST::StringLiteral *>(commentNode->expression);
comment = literal->value->asString();
@@ -122,18 +130,25 @@ protected:
QString comment;
bool plural = false;
AST::ArgumentList *sourceNode = node->arguments->next;
- if (sourceNode) {
- literal = AST::cast<AST::StringLiteral *>(sourceNode->expression);
- source = literal->value->asString();
- AST::ArgumentList *commentNode = sourceNode->next;
- if (commentNode) {
- literal = AST::cast<AST::StringLiteral *>(commentNode->expression);
- comment = literal->value->asString();
-
- AST::ArgumentList *nNode = commentNode->next;
- if (nNode)
- plural = true;
- }
+ if (!sourceNode)
+ return;
+ literal = AST::cast<AST::StringLiteral *>(sourceNode->expression);
+ AST::BinaryExpression *binary = AST::cast<AST::BinaryExpression *>(sourceNode->expression);
+ if (binary) {
+ if (!createString(binary))
+ m_bSource.clear();
+ }
+ if (!literal && m_bSource.isEmpty())
+ return;
+ source = literal ? literal->value->asString() : m_bSource;
+ AST::ArgumentList *commentNode = sourceNode->next;
+ if (commentNode && AST::cast<AST::StringLiteral *>(commentNode->expression)) {
+ literal = AST::cast<AST::StringLiteral *>(commentNode->expression);
+ comment = literal->value->asString();
+
+ AST::ArgumentList *nNode = commentNode->next;
+ if (nNode)
+ plural = true;
}
TranslatorMessage msg(context, source,
@@ -148,9 +163,34 @@ protected:
}
private:
+ bool createString(AST::BinaryExpression *b) {
+ if (!b or b->op != 0)
+ return false;
+ AST::BinaryExpression *l = AST::cast<AST::BinaryExpression *>(b->left);
+ AST::BinaryExpression *r = AST::cast<AST::BinaryExpression *>(b->right);
+ AST::StringLiteral *ls = AST::cast<AST::StringLiteral *>(b->left);
+ AST::StringLiteral *rs = AST::cast<AST::StringLiteral *>(b->right);
+ if ((!l && !ls) || (!r && !rs))
+ return false;
+ if (l) {
+ if (!createString(l))
+ return false;
+ } else
+ m_bSource.prepend(ls->value->asString());
+
+ if (r) {
+ if (!createString(r))
+ return false;
+ } else
+ m_bSource.append(rs->value->asString());
+
+ return true;
+ }
+
Translator *m_translator;
QString m_fileName;
QString m_component;
+ QString m_bSource;
};
QString createErrorString(const QString &filename, const QString &code, Parser &parser)