aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4codegen.cpp
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-07-13 11:58:26 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2021-07-14 15:10:45 +0200
commit5b1a3d50e618bb0ee9a7a095d65b24f26b633b00 (patch)
tree93f8b0e50d29bff955a59438b396b79910cf337a /src/qml/compiler/qv4codegen.cpp
parent7ca78c28eb1440a1b4b7c1830bea024ba69e32bb (diff)
qv4codegen: Provide more accurate SourceLocations
Previously the source locations in the bytecodegenerator were often imprecise due to them not being updated often enough. This change makes sure that FieldMemberExpressions and IdentifierExpressions report more accurate locations instead. Change-Id: Ib53cda5cc927551c25ed32ed34d4b65d82f5e199 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r--src/qml/compiler/qv4codegen.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 7787f1541a..2b4168e155 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -1293,7 +1293,9 @@ bool Codegen::visit(ArrayMemberExpression *ast)
if (arrayIndex == UINT_MAX) {
auto jumpLabel = ast->isOptional ? m_optionalChainLabels.take(ast) : Moth::BytecodeGenerator::Label();
- setExprResult(Reference::fromMember(base, str->value.toString(), jumpLabel, targetLabel));
+ setExprResult(Reference::fromMember(base, str->value.toString(),
+ ast->expression->firstSourceLocation(), jumpLabel,
+ targetLabel));
return false;
}
@@ -2489,9 +2491,10 @@ bool Codegen::visit(FieldMemberExpression *ast)
return false;
}
- setExprResult(Reference::fromMember(base, ast->name.toString(),
- ast->isOptional ? m_optionalChainLabels.take(ast) : Moth::BytecodeGenerator::Label(),
- label.has_value() ? label.value() : Moth::BytecodeGenerator::Label()));
+ setExprResult(Reference::fromMember(
+ base, ast->name.toString(), ast->firstSourceLocation(),
+ ast->isOptional ? m_optionalChainLabels.take(ast) : Moth::BytecodeGenerator::Label(),
+ label.has_value() ? label.value() : Moth::BytecodeGenerator::Label()));
return false;
}
@@ -2625,12 +2628,14 @@ Codegen::Reference Codegen::referenceForName(const QString &name, bool isLhs, co
r.isReferenceToConst = resolved.isConst;
r.requiresTDZCheck = resolved.requiresTDZCheck;
r.name = name; // used to show correct name at run-time when TDZ check fails.
+ r.sourceLocation = accessLocation;
return r;
}
Reference r = Reference::fromName(this, name);
r.global = useFastLookups && (resolved.type == Context::ResolvedName::Global || resolved.type == Context::ResolvedName::QmlGlobal);
r.qmlGlobal = resolved.type == Context::ResolvedName::QmlGlobal;
+ r.sourceLocation = accessLocation;
if (!r.global && !r.qmlGlobal && m_globalNames.contains(name))
r.global = true;
return r;
@@ -4640,6 +4645,10 @@ QT_WARNING_POP
return;
}
}
+
+ if (sourceLocation.isValid())
+ codegen->bytecodeGenerator->setLocation(sourceLocation);
+
if (!disable_lookups && global) {
if (qmlGlobal) {
Instruction::LoadQmlContextPropertyLookup load;
@@ -4659,6 +4668,10 @@ QT_WARNING_POP
case Member:
propertyBase.loadInAccumulator();
tdzCheck(requiresTDZCheck);
+
+ if (sourceLocation.isValid())
+ codegen->bytecodeGenerator->setLocation(sourceLocation);
+
if (!disable_lookups && codegen->useFastLookups) {
if (optionalChainJumpLabel->isValid()) { // If we got a valid jump label, this means it's an optional lookup
auto jump = codegen->bytecodeGenerator->jumpOptionalLookup(codegen->registerGetterLookup(propertyNameIndex));