diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-23 13:48:50 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-23 13:18:58 +0000 |
commit | 3e6d5d9cd1de1373f67f2ff31373a59c37f7b576 (patch) | |
tree | cbf317a1ebbf9674e5f1a79d95411a534298713c /src/qml/compiler | |
parent | 20b376b64a11b4bda18aa1abda543586f04688e8 (diff) |
Set the name of the context as early as possible
We used to set the name later on when calling
Codegen::defineFunction(), but this is too late in some
cases, especially when using the name to determine if
this function could be a QML signal handler.
Change-Id: Ie620a65ac8f17906cd9eba338cbdd3563004375d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 12 | ||||
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 29 | ||||
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions_p.h | 2 |
3 files changed, 21 insertions, 22 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 6b75f8b8b7..fcd535905b 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1810,6 +1810,12 @@ void JSCodeGen::beginObjectScope(QQmlPropertyCache *scopeObject) QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QList<CompiledFunctionOrExpression> &functions) { + auto qmlName = [&](const CompiledFunctionOrExpression &c) { + if (c.nameIndex != 0) + return stringPool->stringForIndex(c.nameIndex); + else + return QStringLiteral("%qml-expression-entry"); + }; QVector<int> runtimeFunctionIndices(functions.size()); QV4::Compiler::ScanFunctions scan(this, sourceCode, QV4::Compiler::ContextType::Global); @@ -1823,7 +1829,7 @@ QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QList<Compil scan.enterQmlFunction(function); } else { Q_ASSERT(f.node != f.parentNode); - scan.enterEnvironment(f.parentNode, QV4::Compiler::ContextType::Binding); + scan.enterEnvironment(f.parentNode, QV4::Compiler::ContextType::Binding, qmlName(f)); } scan(function ? function->body : f.node); @@ -1846,10 +1852,8 @@ QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QList<Compil QString name; if (function) name = function->name.toString(); - else if (qmlFunction.nameIndex != 0) - name = stringPool->stringForIndex(qmlFunction.nameIndex); else - name = QStringLiteral("%qml-expression-entry"); + name = qmlName(qmlFunction); QQmlJS::AST::StatementList *body; if (function) { diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index eeb051046b..ef69706f5d 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -75,16 +75,17 @@ void ScanFunctions::operator()(Node *node) void ScanFunctions::enterGlobalEnvironment(ContextType compilationMode) { - enterEnvironment(astNodeForGlobalEnvironment, compilationMode); + enterEnvironment(astNodeForGlobalEnvironment, compilationMode, QStringLiteral("%GlobalCode")); } -void ScanFunctions::enterEnvironment(Node *node, ContextType compilationMode) +void ScanFunctions::enterEnvironment(Node *node, ContextType compilationMode, const QString &name) { Context *c = _cg->_module->contextMap.value(node); if (!c) c = _cg->_module->newContext(node, _context, compilationMode); if (!c->isStrict) c->isStrict = _cg->_strictMode; + c->name = name; _contextStack.append(c); _context = c; } @@ -92,7 +93,7 @@ void ScanFunctions::enterEnvironment(Node *node, ContextType compilationMode) void ScanFunctions::leaveEnvironment() { _contextStack.pop(); - _context = _contextStack.isEmpty() ? 0 : _contextStack.top(); + _context = _contextStack.isEmpty() ? nullptr : _contextStack.top(); } void ScanFunctions::checkDirectivePrologue(StatementList *ast) @@ -138,7 +139,7 @@ void ScanFunctions::checkName(const QStringRef &name, const SourceLocation &loc) bool ScanFunctions::visit(Program *ast) { - enterEnvironment(ast, defaultProgramType); + enterEnvironment(ast, defaultProgramType, QStringLiteral("%ProgramCode")); checkDirectivePrologue(ast->statements); return true; } @@ -320,8 +321,7 @@ bool ScanFunctions::visit(DoWhileStatement *ast) { } bool ScanFunctions::visit(ForStatement *ast) { - enterEnvironment(ast, ContextType::Block); - _context->name = QLatin1String("For"); + enterEnvironment(ast, ContextType::Block, QStringLiteral("%For")); Node::accept(ast->initialiser, this); Node::accept(ast->declarations, this); Node::accept(ast->condition, this); @@ -339,8 +339,7 @@ void ScanFunctions::endVisit(ForStatement *) } bool ScanFunctions::visit(ForEachStatement *ast) { - enterEnvironment(ast, ContextType::Block); - _context->name = QLatin1String("Foreach"); + enterEnvironment(ast, ContextType::Block, QStringLiteral("%Foreach")); Node::accept(ast->lhs, this); Node::accept(ast->expression, this); @@ -364,8 +363,7 @@ bool ScanFunctions::visit(ThisExpression *) bool ScanFunctions::visit(Block *ast) { TemporaryBoolAssignment allowFuncDecls(_allowFuncDecls, _context->isStrict ? false : _allowFuncDecls); - enterEnvironment(ast, ContextType::Block); - _context->name = QLatin1String("Block"); + enterEnvironment(ast, ContextType::Block, QStringLiteral("%Block")); Node::accept(ast->statements, this); return false; } @@ -377,8 +375,7 @@ void ScanFunctions::endVisit(Block *) bool ScanFunctions::visit(CaseBlock *ast) { - enterEnvironment(ast, ContextType::Block); - _context->name = QLatin1String("CaseBlock"); + enterEnvironment(ast, ContextType::Block, QStringLiteral("%CaseBlock")); return true; } @@ -390,8 +387,7 @@ void ScanFunctions::endVisit(CaseBlock *) bool ScanFunctions::visit(Catch *ast) { TemporaryBoolAssignment allowFuncDecls(_allowFuncDecls, _context->isStrict ? false : _allowFuncDecls); - enterEnvironment(ast, ContextType::Block); - _context->name = QLatin1String("CatchBlock"); + enterEnvironment(ast, ContextType::Block, QStringLiteral("%CatchBlock")); _context->isCatchBlock = true; QString caughtVar = ast->patternElement->bindingIdentifier; if (caughtVar.isEmpty()) @@ -420,8 +416,7 @@ bool ScanFunctions::visit(WithStatement *ast) Node::accept(ast->expression, this); TemporaryBoolAssignment allowFuncDecls(_allowFuncDecls, _context->isStrict ? false : _allowFuncDecls); - enterEnvironment(ast, ContextType::Block); - _context->name = QLatin1String("WithBlock"); + enterEnvironment(ast, ContextType::Block, QStringLiteral("%WithBlock")); _context->isWithBlock = true; if (_context->isStrict) { @@ -441,7 +436,7 @@ void ScanFunctions::endVisit(WithStatement *) bool ScanFunctions::enterFunction(Node *ast, const QString &name, FormalParameterList *formals, StatementList *body, bool enterName) { Context *outerContext = _context; - enterEnvironment(ast, ContextType::Function); + enterEnvironment(ast, ContextType::Function, name); FunctionExpression *expr = AST::cast<FunctionExpression *>(ast); if (!expr) diff --git a/src/qml/compiler/qv4compilerscanfunctions_p.h b/src/qml/compiler/qv4compilerscanfunctions_p.h index cb3866c596..e43feea5eb 100644 --- a/src/qml/compiler/qv4compilerscanfunctions_p.h +++ b/src/qml/compiler/qv4compilerscanfunctions_p.h @@ -85,7 +85,7 @@ public: void operator()(AST::Node *node); void enterGlobalEnvironment(ContextType compilationMode); - void enterEnvironment(AST::Node *node, ContextType compilationMode); + void enterEnvironment(AST::Node *node, ContextType compilationMode, const QString &name); void leaveEnvironment(); void enterQmlFunction(AST::FunctionDeclaration *ast) |