From 1fc951da6aa0bff05af37b20744aba810a2d2988 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 24 Oct 2013 10:38:29 +0200 Subject: Cleanup QML specific JS code generator Move parameters global to the entire QML file to the constructor, pass component/context specific parameters to the generate function. Change-Id: I6c3ab41b3bab19b066bbe20f971c5cafaeb70b98 Reviewed-by: Lars Knoll --- src/qml/compiler/qqmlcodegenerator.cpp | 15 ++++++++------- src/qml/compiler/qqmlcodegenerator_p.h | 14 +++++++------- src/qml/qml/qqmlcompiler.cpp | 7 +++---- src/qml/qml/qqmltypeloader.cpp | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index cbf58599ac..fc485e82f2 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -1198,22 +1198,23 @@ int QmlUnitGenerator::getStringId(const QString &str) const return jsUnitGenerator->getStringId(str); } -QVector JSCodeGen::generateJSCodeForFunctionsAndBindings(const QString &fileName, ParsedQML *output) +JSCodeGen::JSCodeGen(const QString &fileName, const QString &sourceCode, V4IR::Module *jsModule, Engine *jsEngine, AST::UiProgram *qmlRoot) + : QQmlJS::Codegen(/*strict mode*/false) + , sourceCode(sourceCode) + , jsEngine(jsEngine) + , qmlRoot(qmlRoot) { - return generateJSCodeForFunctionsAndBindings(fileName, output->code, &output->jsModule, &output->jsParserEngine, - output->program, /* ### */output->program, output->functions); + _module = jsModule; + _module->setFileName(fileName); } -QVector JSCodeGen::generateJSCodeForFunctionsAndBindings(const QString &fileName, const QString &sourceCode, V4IR::Module *jsModule, - QQmlJS::Engine *jsEngine, AST::UiProgram *qmlRoot, AST::Node *contextRoot, +QVector JSCodeGen::generateJSCodeForFunctionsAndBindings(AST::Node *contextRoot, const QList &functions, const ObjectIdMapping &objectIds) { this->idObjects = objectIds; QVector runtimeFunctionIndices(functions.size()); - _module = jsModule; - _module->setFileName(fileName); ScanFunctions scan(this, sourceCode, GlobalCode); scan.enterEnvironment(0, QmlBinding); diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 0f4c2b145a..1b72e96097 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -345,9 +345,8 @@ private: struct Q_QML_EXPORT JSCodeGen : public QQmlJS::Codegen { - JSCodeGen() - : QQmlJS::Codegen(/*strict mode*/false) - {} + JSCodeGen(const QString &fileName, const QString &sourceCode, V4IR::Module *jsModule, + QQmlJS::Engine *jsEngine, AST::UiProgram *qmlRoot); struct IdMapping { @@ -357,15 +356,16 @@ struct Q_QML_EXPORT JSCodeGen : public QQmlJS::Codegen typedef QVector ObjectIdMapping; // Returns mapping from input functions to index in V4IR::Module::functions / compiledData->runtimeFunctions - QVector generateJSCodeForFunctionsAndBindings(const QString &fileName, ParsedQML *output); - QVector generateJSCodeForFunctionsAndBindings(const QString &fileName, const QString &sourceCode, V4IR::Module *jsModule, - QQmlJS::Engine *jsEngine, AST::UiProgram *qmlRoot, AST::Node *contextRoot, const QList &functions, - const ObjectIdMapping &objectIds = ObjectIdMapping()); + QVector generateJSCodeForFunctionsAndBindings(AST::Node *contextRoot, const QList &functions, const ObjectIdMapping &objectIds = ObjectIdMapping()); protected: virtual V4IR::Expr *fallbackNameLookup(const QString &name, int line, int col) const; private: + QString sourceCode; + QQmlJS::Engine *jsEngine; // needed for memory pool + AST::UiProgram *qmlRoot; + ObjectIdMapping idObjects; }; diff --git a/src/qml/qml/qqmlcompiler.cpp b/src/qml/qml/qqmlcompiler.cpp index 0462c0b61a..58495bb1bf 100644 --- a/src/qml/qml/qqmlcompiler.cpp +++ b/src/qml/qml/qqmlcompiler.cpp @@ -3649,11 +3649,11 @@ bool QQmlCompiler::completeComponentBuild() } if (!compileState->functionsToCompile.isEmpty()) { - JSCodeGen jsCodeGen; - const QString &sourceCode = jsEngine->code(); AST::UiProgram *qmlRoot = parser.qmlRoot(); + JSCodeGen jsCodeGen(unit->finalUrlString(), sourceCode, jsModule.data(), jsEngine, qmlRoot); + JSCodeGen::ObjectIdMapping idMapping; if (compileState->ids.count() > 0) { idMapping.reserve(compileState->ids.count()); @@ -3665,8 +3665,7 @@ bool QQmlCompiler::completeComponentBuild() } } - const QVector runtimeFunctionIndices = jsCodeGen.generateJSCodeForFunctionsAndBindings(unit->finalUrlString(), sourceCode, jsModule.data(), jsEngine, - qmlRoot, compileState->root->astNode, + const QVector runtimeFunctionIndices = jsCodeGen.generateJSCodeForFunctionsAndBindings(compileState->root->astNode, compileState->functionsToCompile, idMapping); compileState->runtimeFunctionIndices = runtimeFunctionIndices; diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 733f057aee..6f718e5b5b 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -2357,8 +2357,8 @@ void QQmlTypeData::compile() // Compile JS binding expressions and signal handlers - JSCodeGen jsCodeGen; - const QVector runtimeFunctionIndices = jsCodeGen.generateJSCodeForFunctionsAndBindings(finalUrlString(), parsedQML.data()); + JSCodeGen jsCodeGen(finalUrlString(), parsedQML->code, &parsedQML->jsModule, &parsedQML->jsParserEngine, parsedQML->program); + const QVector runtimeFunctionIndices = jsCodeGen.generateJSCodeForFunctionsAndBindings(/*### context root*/0, parsedQML->functions); QV4::ExecutionEngine *v4 = QV8Engine::getV4(m_typeLoader->engine()); -- cgit v1.2.3