From a8b3536d6e5e7eb1c51fb20df071185dbce317a2 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 8 May 2019 13:29:50 +0200 Subject: Move compileModule() into qv4codegen.cpp This is a better fit for the method. In turn, remove all the V4_BOOTSTRAP conditions from qv4engine_p.h and make sure we don't include or compile it in bootstrap mode. Change-Id: I5933b0724e561313ca20c420b83e4d70e63bddf5 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4codegen.cpp | 45 +++++++++++++++++++++++++ src/qml/compiler/qv4codegen_p.h | 6 ++++ src/qml/jsruntime/jsruntime.pri | 2 +- src/qml/jsruntime/qv4engine.cpp | 60 ++------------------------------- src/qml/jsruntime/qv4engine_p.h | 18 ++-------- src/qml/jsruntime/qv4runtime.cpp | 4 ++- src/qml/jsruntime/qv4runtime_p.h | 1 - src/qml/jsruntime/qv4runtimecodegen.cpp | 1 + src/qml/jsruntime/qv4value.cpp | 2 +- src/qml/qml/qqmltypeloader.cpp | 3 +- tools/qmlcachegen/qmlcachegen.cpp | 3 +- 11 files changed, 66 insertions(+), 79 deletions(-) diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 1bf0e7147d..3c669c9b1a 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -45,6 +45,8 @@ #include #include #include +#include +#include #include #include #include @@ -3800,6 +3802,49 @@ QQmlRefPointer Codegen::createUnitForLoading() return result; } +QQmlRefPointer Codegen::compileModule( + bool debugMode, const QString &url, const QString &sourceCode, + const QDateTime &sourceTimeStamp, QList *diagnostics) +{ + QQmlJS::Engine ee; + QQmlJS::Lexer lexer(&ee); + lexer.setCode(sourceCode, /*line*/1, /*qml mode*/false); + QQmlJS::Parser parser(&ee); + + const bool parsed = parser.parseModule(); + + if (diagnostics) + *diagnostics = parser.diagnosticMessages(); + + if (!parsed) + return nullptr; + + QQmlJS::AST::ESModule *moduleNode = QQmlJS::AST::cast(parser.rootNode()); + if (!moduleNode) { + // if parsing was successful, and we have no module, then + // the file was empty. + if (diagnostics) + diagnostics->clear(); + return nullptr; + } + + using namespace QV4::Compiler; + Compiler::Module compilerModule(debugMode); + compilerModule.unitFlags |= CompiledData::Unit::IsESModule; + compilerModule.sourceTimeStamp = sourceTimeStamp; + JSUnitGenerator jsGenerator(&compilerModule); + Codegen cg(&jsGenerator, /*strictMode*/true); + cg.generateFromModule(url, url, sourceCode, moduleNode, &compilerModule); + auto errors = cg.errors(); + if (diagnostics) + *diagnostics << errors; + + if (!errors.isEmpty()) + return nullptr; + + return cg.generateCompilationUnit(); +} + class Codegen::VolatileMemoryLocationScanner: protected QQmlJS::AST::Visitor { VolatileMemoryLocations locs; diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h index ad86483132..ece76e4406 100644 --- a/src/qml/compiler/qv4codegen_p.h +++ b/src/qml/compiler/qv4codegen_p.h @@ -52,6 +52,7 @@ #include "private/qv4global_p.h" #include +#include #include #include #include @@ -59,6 +60,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE using namespace QQmlJS; @@ -683,6 +686,9 @@ public: QQmlRefPointer generateCompilationUnit(bool generateUnitData = true); static QQmlRefPointer createUnitForLoading(); + static QQmlRefPointer compileModule( + bool debugMode, const QString &url, const QString &sourceCode, + const QDateTime &sourceTimeStamp, QList *diagnostics); Context *currentContext() const { return _context; } BytecodeGenerator *generator() const { return bytecodeGenerator; } diff --git a/src/qml/jsruntime/jsruntime.pri b/src/qml/jsruntime/jsruntime.pri index ae9a36ca22..de2e0603e8 100644 --- a/src/qml/jsruntime/jsruntime.pri +++ b/src/qml/jsruntime/jsruntime.pri @@ -3,6 +3,7 @@ INCLUDEPATH += $$OUT_PWD !qmldevtools_build { SOURCES += \ + $$PWD/qv4engine.cpp \ $$PWD/qv4context.cpp \ $$PWD/qv4persistent.cpp \ $$PWD/qv4lookup.cpp \ @@ -149,7 +150,6 @@ HEADERS += \ $$PWD/qv4functiontable_p.h SOURCES += \ - $$PWD/qv4engine.cpp \ $$PWD/qv4runtime.cpp \ $$PWD/qv4string.cpp \ $$PWD/qv4value.cpp \ diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index e10bf3cf79..b65a2f2dad 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -38,9 +38,6 @@ ****************************************************************************/ #include -#include -#include -#include #include #include #include @@ -55,8 +52,6 @@ #include #endif -#ifndef V4_BOOTSTRAP - #include #include #include @@ -134,14 +129,10 @@ #include #endif -#endif // #ifndef V4_BOOTSTRAP - QT_BEGIN_NAMESPACE using namespace QV4; -#ifndef V4_BOOTSTRAP - static QBasicAtomicInt engineSerial = Q_BASIC_ATOMIC_INITIALIZER(1); ReturnedValue throwTypeError(const FunctionObject *b, const QV4::Value *, const QV4::Value *, int) @@ -1702,7 +1693,8 @@ QQmlRefPointer ExecutionEngine::compileModule(con QQmlRefPointer ExecutionEngine::compileModule(const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp) { QList diagnostics; - auto unit = compileModule(/*debugMode*/debugger() != nullptr, url.toString(), sourceCode, sourceTimeStamp, &diagnostics); + auto unit = Compiler::Codegen::compileModule(/*debugMode*/debugger() != nullptr, url.toString(), + sourceCode, sourceTimeStamp, &diagnostics); for (const QQmlJS::DiagnosticMessage &m : diagnostics) { if (m.isError()) { throwSyntaxError(m.message, url.toString(), m.loc.startLine, m.loc.startColumn); @@ -1715,52 +1707,6 @@ QQmlRefPointer ExecutionEngine::compileModule(con return unit; } -#endif // ifndef V4_BOOTSTRAP - -QQmlRefPointer ExecutionEngine::compileModule(bool debugMode, const QString &url, const QString &sourceCode, - const QDateTime &sourceTimeStamp, QList *diagnostics) -{ - QQmlJS::Engine ee; - QQmlJS::Lexer lexer(&ee); - lexer.setCode(sourceCode, /*line*/1, /*qml mode*/false); - QQmlJS::Parser parser(&ee); - - const bool parsed = parser.parseModule(); - - if (diagnostics) - *diagnostics = parser.diagnosticMessages(); - - if (!parsed) - return nullptr; - - QQmlJS::AST::ESModule *moduleNode = QQmlJS::AST::cast(parser.rootNode()); - if (!moduleNode) { - // if parsing was successful, and we have no module, then - // the file was empty. - if (diagnostics) - diagnostics->clear(); - return nullptr; - } - - using namespace QV4::Compiler; - Compiler::Module compilerModule(debugMode); - compilerModule.unitFlags |= CompiledData::Unit::IsESModule; - compilerModule.sourceTimeStamp = sourceTimeStamp; - JSUnitGenerator jsGenerator(&compilerModule); - Codegen cg(&jsGenerator, /*strictMode*/true); - cg.generateFromModule(url, url, sourceCode, moduleNode, &compilerModule); - auto errors = cg.errors(); - if (diagnostics) - *diagnostics << errors; - - if (!errors.isEmpty()) - return nullptr; - - return cg.generateCompilationUnit(); -} - -#ifndef V4_BOOTSTRAP - void ExecutionEngine::injectModule(const QQmlRefPointer &moduleUnit) { // Injection can happen from the QML type loader thread for example, but instantiation and @@ -2050,6 +1996,4 @@ static QObject *qtObjectFromJS(QV4::ExecutionEngine *engine, const QV4::Value &v return wrapper->object(); } -#endif // ifndef V4_BOOTSTRAP - QT_END_NAMESPACE diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index d0c58eee8f..4ce854bc52 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -58,11 +58,9 @@ #include #include -#ifndef V4_BOOTSTRAP -# include "qv4function_p.h" -# include -# include -#endif +#include "qv4function_p.h" +#include +#include namespace WTF { class BumpPointerAllocator; @@ -128,13 +126,8 @@ public: Function *globalCode; -#ifdef V4_BOOTSTRAP - QJSEngine *jsEngine() const; - QQmlEngine *qmlEngine() const; -#else // !V4_BOOTSTRAP QJSEngine *jsEngine() const { return publicEngine; } QQmlEngine *qmlEngine() const { return v8Engine ? v8Engine->engine() : nullptr; } -#endif // V4_BOOTSTRAP QV8Engine *v8Engine; QJSEngine *publicEngine; @@ -438,9 +431,7 @@ public: Symbol *symbol_unscopables() const { return reinterpret_cast(jsSymbols + Symbol_unscopables); } Symbol *symbol_revokableProxy() const { return reinterpret_cast(jsSymbols + Symbol_revokableProxy); } -#ifndef V4_BOOTSTRAP QIntrusiveList compilationUnits; -#endif quint32 m_engineId; @@ -611,8 +602,6 @@ public: double localTZA = 0.0; // local timezone, initialized at startup - static QQmlRefPointer compileModule(bool debugMode, const QString &url, const QString &sourceCode, const QDateTime &sourceTimeStamp, QList *diagnostics); -#ifndef V4_BOOTSTRAP QQmlRefPointer compileModule(const QUrl &url); QQmlRefPointer compileModule(const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp); @@ -621,7 +610,6 @@ public: void injectModule(const QQmlRefPointer &moduleUnit); QQmlRefPointer moduleForUrl(const QUrl &_url, const CompiledData::CompilationUnit *referrer = nullptr) const; QQmlRefPointer loadModule(const QUrl &_url, const CompiledData::CompilationUnit *referrer = nullptr); -#endif private: #if QT_CONFIG(qml_debug) diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index e95dfa775f..f404aac580 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -38,9 +38,9 @@ ****************************************************************************/ #include "qv4global_p.h" -#include "qv4engine_p.h" #include "qv4runtime_p.h" #ifndef V4_BOOTSTRAP +#include "qv4engine_p.h" #include "qv4object_p.h" #include "qv4objectproto_p.h" #include "qv4globalobject_p.h" @@ -2170,6 +2170,7 @@ ReturnedValue Runtime::LessEqual::call(const Value &left, const Value &right) return Encode(r); } +#ifndef V4_BOOTSTRAP struct LazyScope { ExecutionEngine *engine = nullptr; @@ -2189,6 +2190,7 @@ struct LazyScope **scopedValue = value; } }; +#endif Bool Runtime::CompareEqual::call(const Value &left, const Value &right) { diff --git a/src/qml/jsruntime/qv4runtime_p.h b/src/qml/jsruntime/qv4runtime_p.h index 72af90d1dc..78ab6a1822 100644 --- a/src/qml/jsruntime/qv4runtime_p.h +++ b/src/qml/jsruntime/qv4runtime_p.h @@ -53,7 +53,6 @@ #include "qv4global_p.h" #include "qv4value_p.h" #include "qv4context_p.h" -#include "qv4engine_p.h" #include "qv4math_p.h" #include "qv4runtimeapi_p.h" #include diff --git a/src/qml/jsruntime/qv4runtimecodegen.cpp b/src/qml/jsruntime/qv4runtimecodegen.cpp index 9866966936..99d0de5ec6 100644 --- a/src/qml/jsruntime/qv4runtimecodegen.cpp +++ b/src/qml/jsruntime/qv4runtimecodegen.cpp @@ -37,6 +37,7 @@ ** ****************************************************************************/ +#include "qv4engine_p.h" #include "qv4runtimecodegen_p.h" #include "qv4compilerscanfunctions_p.h" diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp index cbc153bb86..9b50938ccb 100644 --- a/src/qml/jsruntime/qv4value.cpp +++ b/src/qml/jsruntime/qv4value.cpp @@ -36,7 +36,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include + #include #include #include diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 1f80e1905e..a953e677fa 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -3049,7 +3049,8 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data) if (m_isModule) { QList diagnostics; - unit = QV4::ExecutionEngine::compileModule(isDebugging(), urlString(), source, data.sourceTimeStamp(), &diagnostics); + unit = QV4::Compiler::Codegen::compileModule(isDebugging(), urlString(), source, + data.sourceTimeStamp(), &diagnostics); QList errors = QQmlEnginePrivate::qmlErrorFromDiagnostics(urlString(), diagnostics); if (!errors.isEmpty()) { setError(errors); diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index df7468eaef..bf0bcaf04e 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -262,7 +262,8 @@ static bool compileJSFile(const QString &inputFileName, const QString &inputFile QList diagnostics; // Precompiled files are relocatable and the final location will be set when loading. QString url; - unit = QV4::ExecutionEngine::compileModule(/*debugMode*/false, url, sourceCode, QDateTime(), &diagnostics); + unit = QV4::Compiler::Codegen::compileModule(/*debugMode*/false, url, sourceCode, + QDateTime(), &diagnostics); error->appendDiagnostics(inputFileName, diagnostics); if (!unit) return false; -- cgit v1.2.3