diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-07-03 08:45:20 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-07-04 10:22:30 +0000 |
commit | 968033e33ba2d7d9dd614994ecfca8b68f972032 (patch) | |
tree | 03b73b72890cac1a4f5fca978537233719a6e862 /src/qml/compiler/qv4compilerscanfunctions.cpp | |
parent | 1283f7c3b34ebd441b9679ce3981d216ba530e98 (diff) |
Properly calculate escaping variables
Change-Id: Ia9f0b6d3f31bd3a7bd4316ee3f3e9ff977f973b7
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index 80980cf394..2a217fbb99 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -69,6 +69,8 @@ void ScanFunctions::operator()(Node *node) { if (node) node->accept(this); + + calcEscapingVariables(); } void ScanFunctions::enterEnvironment(Node *node, CompilationMode compilationMode) @@ -220,6 +222,7 @@ bool ScanFunctions::visit(IdentifierExpression *ast) checkName(ast->name, ast->identifierToken); if (_context->usesArgumentsObject == Context::ArgumentsObjectUnknown && ast->name == QLatin1String("arguments")) _context->usesArgumentsObject = Context::ArgumentsObjectUsed; + _context->addUsedVariable(ast->name.toString()); return true; } @@ -410,3 +413,40 @@ void ScanFunctions::enterFunction(Node *ast, const QString &name, FormalParamete _context->arguments += arg; } } + +void ScanFunctions::calcEscapingVariables() +{ + Module *m = _cg->_module; + + for (Context *inner : m->contextMap) { + for (const QString &var : qAsConst(inner->usedVariables)) { + Context *c = inner; + while (c) { + Context::MemberMap::const_iterator it = c->members.find(var); + if (it != c->members.end()) { + if (c != inner) + it->canEscape = true; + break; + } + if (c->findArgument(var) != -1) { + if (c != inner) + c->argumentsCanEscape = true; + break; + } + c = c->parent; + } + } + } + + static const bool showEscapingVars = qEnvironmentVariableIsSet("QV4_SHOW_ESCAPING_VARS"); + if (showEscapingVars) { + qDebug() << "==== escaping variables ===="; + for (Context *c : m->contextMap) { + qDebug() << "Context" << c->name << ":"; + qDebug() << " Arguments escape" << c->argumentsCanEscape; + for (auto it = c->members.constBegin(); it != c->members.constEnd(); ++it) { + qDebug() << " " << it.key() << it.value().canEscape; + } + } + } +} |