diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-03-28 10:58:58 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-02 14:17:21 +0000 |
commit | 851c28d140c398990513640047a20aab36ccc655 (patch) | |
tree | dd9391f74c6a98a234cf2b5ac09bc41b7b7d3b98 /src/qml/compiler/qv4compilercontext_p.h | |
parent | 13cc936859518b5fa378c7b8242d56ebf49ebce9 (diff) |
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 <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilercontext_p.h')
-rw-r--r-- | src/qml/compiler/qv4compilercontext_p.h | 51 |
1 files changed, 24 insertions, 27 deletions
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); }; |