diff options
| author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-07-09 10:44:28 +0200 |
|---|---|---|
| committer | Maximilian Goldstein <max.goldstein@qt.io> | 2021-07-13 11:07:19 +0200 |
| commit | 31032a26311fe1582af75357d7990601696eb122 (patch) | |
| tree | e7581e906054cfac8fbf4510c3e343cd07dfe323 /src/qml/compiler/qv4bytecodegenerator.cpp | |
| parent | 675f3d0082a4a069ed84c7b3edb14d95aeed1417 (diff) | |
qv4bytecodegenerator: Supply SourceLocations in compiler context
This is required for better warnings in qmlcompiler's type propagator.
Remains optional as to not consume superfluous memory when not needed (during normal QML engine operation).
Change-Id: I50293f878e4f6659935925f5f2266427d2f64d7b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator.cpp')
| -rw-r--r-- | src/qml/compiler/qv4bytecodegenerator.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp index f8a41edb6a..ea7469cd67 100644 --- a/src/qml/compiler/qv4bytecodegenerator.cpp +++ b/src/qml/compiler/qv4bytecodegenerator.cpp @@ -48,6 +48,7 @@ using namespace Moth; void BytecodeGenerator::setLocation(const QQmlJS::SourceLocation &loc) { currentLine = static_cast<int>(loc.startLine); + currentSourceLocation = loc; } int BytecodeGenerator::newRegister() @@ -165,21 +166,27 @@ void BytecodeGenerator::finalize(Compiler::Context *context) // collect content and line numbers QByteArray code; QVector<CompiledData::CodeOffsetToLine> lineNumbers; + currentLine = -1; Q_UNUSED(startLine); - for (const auto &i : qAsConst(instructions)) { - if (i.line != currentLine) { - currentLine = i.line; + for (qsizetype i = 0; i < instructions.size(); i++) { + if (instructions[i].line != currentLine) { + currentLine = instructions[i].line; CompiledData::CodeOffsetToLine entry; entry.codeOffset = code.size(); entry.line = currentLine; lineNumbers.append(entry); } - code.append(reinterpret_cast<const char *>(i.packed), i.size); + + if (m_sourceLocationTable) + m_sourceLocationTable->entries[i].offset = static_cast<quint32>(code.size()); + + code.append(reinterpret_cast<const char *>(instructions[i].packed), instructions[i].size); } context->code = code; context->lineNumberMapping = lineNumbers; + context->sourceLocationTable = std::move(m_sourceLocationTable); for (const auto &li : _labelInfos) { context->labelInfo.push_back(instructions.at(labels.at(li.labelIndex)).position); @@ -215,6 +222,7 @@ QT_WARNING_DISABLE_GCC("-Wmaybe-uninitialized") // broken gcc warns about Instru currentLine = -currentLine; addInstruction(Instruction::Debug()); currentLine = -currentLine; + currentSourceLocation = QQmlJS::SourceLocation(); } QT_WARNING_POP } @@ -235,6 +243,8 @@ QT_WARNING_POP } instructions.append(instr); + if (m_sourceLocationTable) + m_sourceLocationTable->entries.append({ 0, currentSourceLocation }); return pos; } |
