diff options
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator_p.h')
-rw-r--r-- | src/qml/compiler/qv4bytecodegenerator_p.h | 81 |
1 files changed, 35 insertions, 46 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator_p.h b/src/qml/compiler/qv4bytecodegenerator_p.h index 8c509dd9f1..fa14754f85 100644 --- a/src/qml/compiler/qv4bytecodegenerator_p.h +++ b/src/qml/compiler/qv4bytecodegenerator_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QV4BYTECODEGENERATOR_P_H #define QV4BYTECODEGENERATOR_P_H @@ -52,14 +16,16 @@ // #include <private/qv4instr_moth_p.h> #include <private/qv4compileddata_p.h> +#include <private/qv4compilercontext_p.h> +#include <private/qqmljssourcelocation_p.h> + +#include <memory> QT_BEGIN_NAMESPACE namespace QQmlJS { -namespace AST { class SourceLocation; } -} namespace QV4 { @@ -71,8 +37,12 @@ namespace Moth { class BytecodeGenerator { public: - BytecodeGenerator(int line, bool debug) - : startLine(line), debugMode(debug) {} + BytecodeGenerator(int line, bool debug, bool storeSourceLocation = false) + : startLine(line), debugMode(debug) + { + if (storeSourceLocation) + m_sourceLocationTable.reset(new QV4::Compiler::Context::SourceLocationTable {}); + } struct Label { enum LinkMode { @@ -88,7 +58,7 @@ public: link(); } - void link() { + void link() const { Q_ASSERT(index >= 0); Q_ASSERT(generator->labels[index] == -1); generator->labels[index] = generator->instructions.size(); @@ -188,13 +158,27 @@ QT_WARNING_POP Q_REQUIRED_RESULT Jump jumpNotUndefined() { - Instruction::JumpNotUndefined data; + Instruction::JumpNotUndefined data{}; return addJumpInstruction(data); } Q_REQUIRED_RESULT Jump jumpNoException() { - Instruction::JumpNoException data; + Instruction::JumpNoException data{}; + return addJumpInstruction(data); + } + + Q_REQUIRED_RESULT Jump jumpOptionalLookup(int index) + { + Instruction::GetOptionalLookup data{}; + data.index = index; + return addJumpInstruction(data); + } + + Q_REQUIRED_RESULT Jump jumpOptionalProperty(int name) + { + Instruction::LoadOptionalProperty data{}; + data.name = name; return addJumpInstruction(data); } @@ -244,7 +228,8 @@ QT_WARNING_POP - void setLocation(const QQmlJS::AST::SourceLocation &loc); + void setLocation(const QQmlJS::SourceLocation &loc); + void incrementStatement(); ExceptionHandler *exceptionHandler() const { return currentExceptionHandler; @@ -295,6 +280,7 @@ private: short size; uint position; int line; + int statement; int offsetForJump; int linkedLabel; unsigned char packed[sizeof(Instr) + 2]; // 2 for instruction type @@ -313,6 +299,9 @@ public: private: int startLine = 0; int currentLine = 0; + int currentStatement = 0; + QQmlJS::SourceLocation currentSourceLocation; + std::unique_ptr<QV4::Compiler::Context::SourceLocationTable> m_sourceLocationTable; bool debugMode = false; int lastInstrType = -1; |