diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-09-29 13:30:42 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-10-13 22:13:12 +0200 |
commit | ae49af00b59628623bc15e19974ee5af5f0121ba (patch) | |
tree | 91488d095e7a5b52bb1b8df05e56fb668039ea7b /src/qml/jsruntime/qv4stackframe.cpp | |
parent | 9cfc19faf5d1ce2b9626914ab4528998b072385d (diff) |
QML: Track the statement indices together with line numbers
We will need the statement indices when tracking value type references.
New value type references shall only be written back in the same
statement they were created in.
Task-number: QTBUG-99766
Change-Id: I83f908df034e7da8ba46ccacaa29bd9d78020d20
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4stackframe.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4stackframe.cpp | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/qml/jsruntime/qv4stackframe.cpp b/src/qml/jsruntime/qv4stackframe.cpp index a02ce0edc5..e8ff9a89bc 100644 --- a/src/qml/jsruntime/qv4stackframe.cpp +++ b/src/qml/jsruntime/qv4stackframe.cpp @@ -17,21 +17,37 @@ QString CppStackFrame::function() const return v4Function ? v4Function->name()->toQString() : QString(); } -int CppStackFrame::lineNumber() const +static const CompiledData::CodeOffsetToLineAndStatement *lineAndStatement(const CppStackFrame *frame) { - if (!v4Function || instructionPointer <= 0) - return -1; + if (!frame->v4Function || frame->instructionPointer <= 0) + return nullptr; - auto findLine = [](const CompiledData::CodeOffsetToLine &entry, uint offset) { + auto findLine = [](const CompiledData::CodeOffsetToLineAndStatement &entry, uint offset) { return entry.codeOffset < offset; }; - const QV4::CompiledData::Function *cf = v4Function->compiledFunction; - const uint offset = instructionPointer; - const CompiledData::CodeOffsetToLine *lineNumbers = cf->lineNumberTable(); - const uint nLineNumbers = cf->nLineNumbers; - const CompiledData::CodeOffsetToLine *line = std::lower_bound(lineNumbers, lineNumbers + nLineNumbers, offset, findLine) - 1; - return line->line; + const QV4::CompiledData::Function *cf = frame->v4Function->compiledFunction; + const uint offset = frame->instructionPointer; + const CompiledData::CodeOffsetToLineAndStatement *lineAndStatementNumbers + = cf->lineAndStatementNumberTable(); + const uint nLineAndStatementNumbers = cf->nLineAndStatementNumbers; + return std::lower_bound( + lineAndStatementNumbers, lineAndStatementNumbers + nLineAndStatementNumbers, + offset, findLine) - 1; +} + +int CppStackFrame::lineNumber() const +{ + if (auto *line = lineAndStatement(this)) + return line->line; + return -1; +} + +int CppStackFrame::statementNumber() const +{ + if (auto *statement = lineAndStatement(this)) + return statement->statement; + return -1; } ReturnedValue QV4::CppStackFrame::thisObject() const |