diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-07-03 08:08:16 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-07-03 13:38:08 +0000 |
commit | 1283f7c3b34ebd441b9679ce3981d216ba530e98 (patch) | |
tree | d968f0bf6fe3744ebea6d5500a372707c8f9b9d8 /src/qml | |
parent | 540cad8cef8c1e59859c57a8960467bea4be8ee8 (diff) |
Move the Runtime codegen into it's own file
Change-Id: I3d09fc4b8aebe19acae0ba5a688491428a4af715
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 43 | ||||
-rw-r--r-- | src/qml/compiler/qv4codegen_p.h | 22 | ||||
-rw-r--r-- | src/qml/jsruntime/jsruntime.pri | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject_p.h | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtimecodegen.cpp | 79 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtimecodegen_p.h | 82 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 2 |
8 files changed, 168 insertions, 67 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index befebba9a3..ba69227089 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** 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. @@ -39,7 +39,6 @@ #include "qv4codegen_p.h" #include "qv4util_p.h" -#include "qv4engine_p.h" #include <QtCore/QCoreApplication> #include <QtCore/QStringList> @@ -57,10 +56,6 @@ #include <private/qv4compilationunit_moth_p.h> #include <private/qv4compilerscanfunctions_p.h> -#ifndef V4_BOOTSTRAP -#include <qv4context_p.h> -#endif - #include <cmath> #include <iostream> @@ -153,26 +148,6 @@ void Codegen::generateFromProgram(const QString &fileName, defineFunction(QStringLiteral("%entry"), node, 0, node->elements); } -void Codegen::generateFromFunctionExpression(const QString &fileName, - const QString &sourceCode, - AST::FunctionExpression *ast, - Module *module) -{ - _module = module; - _module->fileName = fileName; - _context = 0; - - ScanFunctions scan(this, sourceCode, GlobalCode); - // fake a global environment - scan.enterEnvironment(0, FunctionCode); - scan(ast); - scan.leaveEnvironment(); - - int index = defineFunction(ast->name.toString(), ast, ast->formals, ast->body ? ast->body->elements : 0); - _module->rootContext = _module->functions.at(index); -} - - void Codegen::enterContext(Node *node) { _context = _module->contextMap.value(node); @@ -2486,22 +2461,6 @@ QList<QQmlError> Codegen::qmlErrors() const return qmlErrors; } -void RuntimeCodegen::throwSyntaxError(const AST::SourceLocation &loc, const QString &detail) -{ - if (hasError) - return; - hasError = true; - engine->throwSyntaxError(detail, _module->fileName, loc.startLine, loc.startColumn); -} - -void RuntimeCodegen::throwReferenceError(const AST::SourceLocation &loc, const QString &detail) -{ - if (hasError) - return; - hasError = true; - engine->throwReferenceError(detail, _module->fileName, loc.startLine, loc.startColumn); -} - #endif // V4_BOOTSTRAP Codegen::Reference::Reference(const Codegen::Reference &other) diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h index 6341070d0e..93d3ad85c2 100644 --- a/src/qml/compiler/qv4codegen_p.h +++ b/src/qml/compiler/qv4codegen_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** 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. @@ -101,10 +101,6 @@ public: AST::Program *ast, Module *module, CompilationMode mode = GlobalCode); - void generateFromFunctionExpression(const QString &fileName, - const QString &sourceCode, - AST::FunctionExpression *ast, - Module *module); public: struct Reference { @@ -517,22 +513,6 @@ protected: QList<QQmlJS::DiagnosticMessage> _errors; }; -#ifndef V4_BOOTSTRAP -class RuntimeCodegen : public Codegen -{ -public: - RuntimeCodegen(QV4::ExecutionEngine *engine, QV4::Compiler::JSUnitGenerator *jsUnitGenerator, bool strict) - : Codegen(jsUnitGenerator, strict) - , engine(engine) - {} - - void throwSyntaxError(const AST::SourceLocation &loc, const QString &detail) override; - void throwReferenceError(const AST::SourceLocation &loc, const QString &detail) override; -private: - QV4::ExecutionEngine *engine; -}; -#endif // V4_BOOTSTRAP - } } diff --git a/src/qml/jsruntime/jsruntime.pri b/src/qml/jsruntime/jsruntime.pri index 9938f60aea..811014607a 100644 --- a/src/qml/jsruntime/jsruntime.pri +++ b/src/qml/jsruntime/jsruntime.pri @@ -33,6 +33,7 @@ SOURCES += \ $$PWD/qv4variantobject.cpp \ $$PWD/qv4objectiterator.cpp \ $$PWD/qv4regexp.cpp \ + $$PWD/qv4runtimecodegen.cpp \ $$PWD/qv4serialize.cpp \ $$PWD/qv4script.cpp \ $$PWD/qv4sequenceobject.cpp \ @@ -76,6 +77,7 @@ HEADERS += \ $$PWD/qv4objectproto_p.h \ $$PWD/qv4qmlcontext_p.h \ $$PWD/qv4regexpobject_p.h \ + $$PWD/qv4runtimecodegen_p.h \ $$PWD/qv4stringobject_p.h \ $$PWD/qv4variantobject_p.h \ $$PWD/qv4property_p.h \ diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index fbce1e0cda..85a86ee84f 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -53,7 +53,7 @@ #include <private/qqmljsast_p.h> #include <private/qqmljavascriptexpression_p.h> #include <private/qqmlengine_p.h> -#include <qv4codegen_p.h> +#include <qv4runtimecodegen_p.h> #include "private/qlocale_tools_p.h" #include "private/qqmlbuiltinfunctions_p.h" @@ -219,7 +219,7 @@ void FunctionCtor::construct(const Managed *that, Scope &scope, CallData *callDa Compiler::Module module(scope.engine->debugger() != 0); Compiler::JSUnitGenerator jsGenerator(&module); - Compiler::RuntimeCodegen cg(scope.engine, &jsGenerator, f->strictMode()); + RuntimeCodegen cg(scope.engine, &jsGenerator, f->strictMode()); cg.generateFromFunctionExpression(QString(), function, fe, &module); QQmlRefPointer<CompiledData::CompilationUnit> compilationUnit = cg.generateCompilationUnit(); diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index a02d5926a7..f6e7df978b 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -55,7 +55,6 @@ #include "qv4context_p.h" #include "qv4functionobject_p.h" #include "qv4string_p.h" -#include "qv4codegen_p.h" #include "qv4managed_p.h" #include "qv4property_p.h" #include "qv4objectiterator_p.h" diff --git a/src/qml/jsruntime/qv4runtimecodegen.cpp b/src/qml/jsruntime/qv4runtimecodegen.cpp new file mode 100644 index 0000000000..9c115099b5 --- /dev/null +++ b/src/qml/jsruntime/qv4runtimecodegen.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "qv4runtimecodegen_p.h" +#include "qv4compilerscanfunctions_p.h" + +using namespace QV4; + +void RuntimeCodegen::generateFromFunctionExpression(const QString &fileName, + const QString &sourceCode, + AST::FunctionExpression *ast, + Compiler::Module *module) +{ + _module = module; + _module->fileName = fileName; + _context = 0; + + Compiler::ScanFunctions scan(this, sourceCode, Compiler::GlobalCode); + // fake a global environment + scan.enterEnvironment(0, Compiler::FunctionCode); + scan(ast); + scan.leaveEnvironment(); + + int index = defineFunction(ast->name.toString(), ast, ast->formals, ast->body ? ast->body->elements : 0); + _module->rootContext = _module->functions.at(index); +} + +void RuntimeCodegen::throwSyntaxError(const AST::SourceLocation &loc, const QString &detail) +{ + if (hasError) + return; + hasError = true; + engine->throwSyntaxError(detail, _module->fileName, loc.startLine, loc.startColumn); +} + +void RuntimeCodegen::throwReferenceError(const AST::SourceLocation &loc, const QString &detail) +{ + if (hasError) + return; + hasError = true; + engine->throwReferenceError(detail, _module->fileName, loc.startLine, loc.startColumn); +} + diff --git a/src/qml/jsruntime/qv4runtimecodegen_p.h b/src/qml/jsruntime/qv4runtimecodegen_p.h new file mode 100644 index 0000000000..be66dc57ca --- /dev/null +++ b/src/qml/jsruntime/qv4runtimecodegen_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +#ifndef QV4RUNTIMECODEGEN_P_H +#define QV4RUNTIMECODEGEN_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <private/qv4codegen_p.h> + +QT_BEGIN_NAMESPACE + +namespace QV4 { + +class RuntimeCodegen : public Compiler::Codegen +{ +public: + RuntimeCodegen(ExecutionEngine *engine, Compiler::JSUnitGenerator *jsUnitGenerator, bool strict) + : Codegen(jsUnitGenerator, strict) + , engine(engine) + {} + + void generateFromFunctionExpression(const QString &fileName, + const QString &sourceCode, + AST::FunctionExpression *ast, + Compiler::Module *module); + + void throwSyntaxError(const AST::SourceLocation &loc, const QString &detail) override; + void throwReferenceError(const AST::SourceLocation &loc, const QString &detail) override; +private: + ExecutionEngine *engine; +}; + +} + +QT_END_NAMESPACE + +#endif // QV4CODEGEN_P_H diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 0370531579..30cc4c664c 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -52,7 +52,7 @@ #include <private/qqmljsast_p.h> #include <private/qqmlengine_p.h> #include <private/qv4profiling_p.h> -#include <qv4codegen_p.h> +#include <qv4runtimecodegen_p.h> #include <QtCore/QDebug> #include <QtCore/QString> |