From 851c28d140c398990513640047a20aab36ccc655 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 28 Mar 2018 10:58:58 +0200 Subject: Refactor variable resolving Move variable resolving into the context, and avoid creating ExecutionContext's whereever we can. This prepares things for block scoping, where this becomes rather important to be able to achieve decent performance. Change-Id: Idf3d3c12cf348a2c3da01989c26c8529ceb36c12 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4compilercontext_p.h | 51 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'src/qml/compiler/qv4compilercontext_p.h') diff --git a/src/qml/compiler/qv4compilercontext_p.h b/src/qml/compiler/qv4compilercontext_p.h index 2864d759f9..1047af973d 100644 --- a/src/qml/compiler/qv4compilercontext_p.h +++ b/src/qml/compiler/qv4compilercontext_p.h @@ -149,6 +149,7 @@ struct Context { bool hasWith = false; bool returnsClosure = false; mutable bool argumentsCanEscape = false; + bool requiresExecutionContext = false; enum UsesArgumentsObject { ArgumentsObjectUnknown, @@ -217,7 +218,6 @@ struct Context { bool forceLookupByName(); - bool canUseSimpleCall() const { return nestedContexts.isEmpty() && locals.isEmpty() && @@ -256,36 +256,33 @@ struct Context { return true; } + bool requiresImplicitReturnValue() const { + return type == ContextType::Binding || + type == ContextType::Eval || + type == ContextType::Global; + } + void addUsedVariable(const QString &name) { usedVariables.insert(name); } - bool addLocalVar(const QString &name, MemberType type, QQmlJS::AST::VariableScope scope, QQmlJS::AST::FunctionExpression *function = nullptr) - { - if (name.isEmpty()) - return true; - - if (type != FunctionDefinition) { - if (formals && formals->containsName(name)) - return (scope == QQmlJS::AST::VariableScope::Var); - } - MemberMap::iterator it = members.find(name); - if (it != members.end()) { - if (scope != QQmlJS::AST::VariableScope::Var || (*it).scope != QQmlJS::AST::VariableScope::Var) - return false; - if ((*it).type <= type) { - (*it).type = type; - (*it).function = function; - } - return true; - } - Member m; - m.type = type; - m.function = function; - m.scope = scope; - members.insert(name, m); - return true; - } + bool addLocalVar(const QString &name, MemberType type, QQmlJS::AST::VariableScope scope, QQmlJS::AST::FunctionExpression *function = nullptr); + + struct ResolvedName { + enum Type { + Unresolved, + Global, + Local, + Stack + }; + Type type = Unresolved; + bool isArgOrEval = false; + int scope = -1; + int index = -1; + bool isValid() const { return type != Unresolved; } + }; + ResolvedName resolveName(const QString &name); + void emitHeaderBytecode(Compiler::Codegen *codegen); }; -- cgit v1.2.3