diff options
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator_p.h')
-rw-r--r-- | src/qml/compiler/qv4bytecodegenerator_p.h | 113 |
1 files changed, 61 insertions, 52 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator_p.h b/src/qml/compiler/qv4bytecodegenerator_p.h index 4f3dc27acc..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 @@ -51,22 +15,34 @@ // We mean it. // #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 { + +namespace Compiler { +struct Context; +} + 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 { @@ -82,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(); @@ -172,25 +148,37 @@ QT_WARNING_POP Q_REQUIRED_RESULT Jump jumpTrue() { - Instruction::JumpTrue data; - return addJumpInstruction(data); + return addJumpInstruction(Instruction::JumpTrue()); } Q_REQUIRED_RESULT Jump jumpFalse() { - Instruction::JumpFalse data; - return addJumpInstruction(data); + return addJumpInstruction(Instruction::JumpFalse()); } 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); } @@ -198,7 +186,7 @@ QT_WARNING_POP { Instruction::CmpStrictEqual cmp; cmp.lhs = lhs; - addInstruction(cmp); + addInstruction(std::move(cmp)); addJumpInstruction(Instruction::JumpTrue()).link(target); } @@ -206,10 +194,16 @@ QT_WARNING_POP { Instruction::CmpStrictNotEqual cmp; cmp.lhs = lhs; - addInstruction(cmp); + addInstruction(std::move(cmp)); addJumpInstruction(Instruction::JumpTrue()).link(target); } + void checkException() + { + Instruction::CheckException chk; + addInstruction(chk); + } + void setUnwindHandler(ExceptionHandler *handler) { currentExceptionHandler = handler; @@ -234,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; @@ -268,6 +263,11 @@ QT_WARNING_POP lastInstrType = -1; } + void addLoopStart(const Label &start) + { + _labelInfos.push_back({ start.index }); + } + private: friend struct Jump; friend struct Label; @@ -280,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 @@ -298,10 +299,18 @@ 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; Moth::Instr lastInstr; + + struct LabelInfo { + int labelIndex; + }; + std::vector<LabelInfo> _labelInfos; }; } |