aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2024-04-19 10:34:05 +0200
committerOlivier De Cannière <olivier.decanniere@qt.io>2024-04-22 15:50:28 +0200
commit04eca69846a531ec26c8bb9be20dddd75fb111fe (patch)
tree9a870bda4485618b32b86621679d363471a36cc7
parent152e6716baeffd22c381df8c37c188b8eab7d9df (diff)
qv4codegen: Store the location of binary expressions
This location is then used later, for example, to improve the accuracy of warnings. OLD Warning: Main.qml:22:30: function without return type annotation returns double of double [compiler] function type() { return 1 + 1 } ^^^^^^ NEW Warning: Main.qml:22:30: function without return type annotation returns double of double [compiler] function type() { return 1 + 1 } ^^^^^ The location stored is the combined locations of the left operand, the operator, and the right operator. We should investigate if this is the right approach. Created QTBUG-124548. Task-number: QTBUG-124548 Task-number: QTBUG-124220 Pick-to: 6.7 Change-Id: Icac335d53349c05d0e9ee6e436bc6ab08ad970d2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/compiler/qv4codegen.cpp11
-rw-r--r--src/qml/compiler/qv4codegen_p.h3
2 files changed, 9 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 7c312d9a3e..25831eab73 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -1511,7 +1511,7 @@ bool Codegen::visit(BinaryExpression *ast)
if (hasError())
return false;
- binopHelper(baseOp(ast->op), tempLeft, right).loadInAccumulator();
+ binopHelper(ast, baseOp(ast->op), tempLeft, right).loadInAccumulator();
setExprResult(left.storeRetainAccumulator());
break;
@@ -1524,7 +1524,7 @@ bool Codegen::visit(BinaryExpression *ast)
Reference right = expression(ast->right);
if (hasError())
return false;
- setExprResult(binopHelper(static_cast<QSOperator::Op>(ast->op), right, left));
+ setExprResult(binopHelper(ast, static_cast<QSOperator::Op>(ast->op), right, left));
break;
}
Q_FALLTHROUGH();
@@ -1559,7 +1559,7 @@ bool Codegen::visit(BinaryExpression *ast)
if (hasError())
return false;
- setExprResult(binopHelper(static_cast<QSOperator::Op>(ast->op), left, right));
+ setExprResult(binopHelper(ast, static_cast<QSOperator::Op>(ast->op), left, right));
break;
}
@@ -1568,8 +1568,11 @@ bool Codegen::visit(BinaryExpression *ast)
return false;
}
-Codegen::Reference Codegen::binopHelper(QSOperator::Op oper, Reference &left, Reference &right)
+Codegen::Reference Codegen::binopHelper(BinaryExpression *ast, QSOperator::Op oper, Reference &left,
+ Reference &right)
{
+ auto loc = combine(ast->left->firstSourceLocation(), ast->right->lastSourceLocation());
+ bytecodeGenerator->setLocation(loc);
switch (oper) {
case QSOperator::Add: {
left = left.storeOnStack();
diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h
index d9a04dcd92..3a27cb1487 100644
--- a/src/qml/compiler/qv4codegen_p.h
+++ b/src/qml/compiler/qv4codegen_p.h
@@ -711,7 +711,8 @@ public:
QQmlJS::DiagnosticMessage error() const;
QUrl url() const;
- Reference binopHelper(QSOperator::Op oper, Reference &left, Reference &right);
+ Reference binopHelper(QQmlJS::AST::BinaryExpression *ast, QSOperator::Op oper, Reference &left,
+ Reference &right);
Reference jumpBinop(QSOperator::Op oper, Reference &left, Reference &right);
struct Arguments { int argc; int argv; bool hasSpread; };
Arguments pushArgs(QQmlJS::AST::ArgumentList *args);