aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compilercontext_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-03-26 22:59:28 +0200
committerLars Knoll <lars.knoll@qt.io>2018-05-02 14:17:46 +0000
commit20d30b6b3a253eebedc927dbb91685bbec52cfee (patch)
tree0e91a6c519829bd279258f3fe807519e6c8a1e3d /src/qml/compiler/qv4compilercontext_p.h
parentd499a995292629d3522f5e77b7c958bacdf5d0ae (diff)
Add support for proper lexical scoping
This is still to some extend work in progress as lexically scoped for loops won't yet do the right thing. let and const variables are still accessible before they are declared, and the global scope doesn't yet have a proper context for lexically declared variables. Change-Id: Ie39f74a8fccdaead437fbf07f9fc228a444c26ed 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.h21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/qml/compiler/qv4compilercontext_p.h b/src/qml/compiler/qv4compilercontext_p.h
index 289488cbc8..189a623703 100644
--- a/src/qml/compiler/qv4compilercontext_p.h
+++ b/src/qml/compiler/qv4compilercontext_p.h
@@ -91,6 +91,7 @@ struct Module {
QHash<QQmlJS::AST::Node *, Context *> contextMap;
QList<Context *> functions;
+ QList<Context *> blocks;
Context *rootContext;
QString fileName;
QString finalUrl;
@@ -107,6 +108,7 @@ struct Context {
int column = 0;
int registerCountInFunction = 0;
int functionIndex = -1;
+ int blockIndex = -1;
enum MemberType {
UndefinedMember,
@@ -152,6 +154,7 @@ struct Context {
bool returnsClosure = false;
mutable bool argumentsCanEscape = false;
bool requiresExecutionContext = false;
+ bool forceLookupByName = false;
enum UsesArgumentsObject {
ArgumentsObjectUnknown,
@@ -161,7 +164,7 @@ struct Context {
UsesArgumentsObject usesArgumentsObject = ArgumentsObjectUnknown;
- ContextType type;
+ ContextType contextType;
template <typename T>
class SmallSet: public QVarLengthArray<T, 8>
@@ -212,14 +215,12 @@ struct Context {
Context(Context *parent, ContextType type)
: parent(parent)
- , type(type)
+ , contextType(type)
{
if (parent && parent->isStrict)
isStrict = true;
}
- bool forceLookupByName();
-
int findArgument(const QString &name)
{
// search backwards to handle duplicate argument names correctly
@@ -252,16 +253,16 @@ struct Context {
}
bool requiresImplicitReturnValue() const {
- return type == ContextType::Binding ||
- type == ContextType::Eval ||
- type == ContextType::Global;
+ return contextType == ContextType::Binding ||
+ contextType == ContextType::Eval ||
+ contextType == 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);
+ bool addLocalVar(const QString &name, MemberType contextType, QQmlJS::AST::VariableScope scope, QQmlJS::AST::FunctionExpression *function = nullptr);
struct ResolvedName {
enum Type {
@@ -277,7 +278,9 @@ struct Context {
bool isValid() const { return type != Unresolved; }
};
ResolvedName resolveName(const QString &name);
- void emitHeaderBytecode(Compiler::Codegen *codegen);
+ int emitBlockHeader(Compiler::Codegen *codegen);
+ void emitBlockFooter(Compiler::Codegen *codegen, int oldContextReg);
+
void setupFunctionIndices(Moth::BytecodeGenerator *bytecodeGenerator);
};