diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-07-01 12:00:57 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-07-03 08:09:17 +0000 |
commit | d31541fd9d7d52ef3eae29e7e5d36733d7f55375 (patch) | |
tree | c5d17bea0119c9f0eb26e97eb523b281e9900783 /src/qml/compiler/qv4codegen.cpp | |
parent | 6e79a00cad2f5dd09bdf40e594a65af58b370d9d (diff) | |
download | qtdeclarative-d31541fd9d7d52ef3eae29e7e5d36733d7f55375.tar.gz |
Add support for super properties
Those are mostly working now, but when calling super properties
the this object is not setup correctly.
Change-Id: Ib42129ae6e729eeca00275f707f480371b7e42a5
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 7e22966302..2f28320697 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -1109,6 +1109,11 @@ bool Codegen::visit(ArrayMemberExpression *ast) Reference base = expression(ast->base); if (hasError) return false; + if (base.isSuper()) { + Reference index = expression(ast->expression).storeOnStack(); + _expr.setResult(Reference::fromSuperProperty(index)); + return false; + } base = base.storeOnStack(); if (hasError) return false; @@ -1957,6 +1962,9 @@ bool Codegen::visit(DeleteExpression *ast) return false; switch (expr.type) { + case Reference::SuperProperty: + // ### this should throw a reference error at runtime. + return false; case Reference::StackSlot: if (!expr.stackSlotIsLocalOrArgument) break; @@ -2052,6 +2060,14 @@ bool Codegen::visit(FieldMemberExpression *ast) Reference base = expression(ast->base); if (hasError) return false; + if (base.isSuper()) { + Instruction::LoadRuntimeString load; + load.stringId = registerString(ast->name.toString()); + bytecodeGenerator->addInstruction(load); + Reference property = Reference::fromAccumulator(this).storeOnStack(); + _expr.setResult(Reference::fromSuperProperty(property)); + return false; + } _expr.setResult(Reference::fromMember(base, ast->name.toString())); return false; } @@ -3710,6 +3726,9 @@ Codegen::Reference &Codegen::Reference::operator =(const Reference &other) break; case Super: break; + case SuperProperty: + property = other.property; + break; case StackSlot: theStackSlot = other.theStackSlot; break; @@ -3761,6 +3780,8 @@ bool Codegen::Reference::operator==(const Codegen::Reference &other) const break; case Super: return true; + case SuperProperty: + return property == other.property; case StackSlot: return theStackSlot == other.theStackSlot; case ScopedLocal: @@ -3941,7 +3962,12 @@ void Codegen::Reference::storeAccumulator() const } switch (type) { case Super: - codegen->throwSyntaxError(SourceLocation(), QStringLiteral("storing super properties not implemented.")); + Q_UNREACHABLE(); + return; + case SuperProperty: + Instruction::StoreSuperProperty store; + store.property = property.stackSlot(); + codegen->bytecodeGenerator->addInstruction(store); return; case StackSlot: { Instruction::StoreReg store; @@ -4021,7 +4047,12 @@ void Codegen::Reference::loadInAccumulator() const case Accumulator: return; case Super: - codegen->throwSyntaxError(AST::SourceLocation(), QStringLiteral("Super property access not implemented.")); + Q_UNREACHABLE(); + return; + case SuperProperty: + Instruction::LoadSuperProperty load; + load.property = property.stackSlot(); + codegen->bytecodeGenerator->addInstruction(load); return; case Const: { QT_WARNING_PUSH |