From e9b3bdb96e008060a0e78815a3995015e5e4598d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 22 Jun 2018 09:20:43 +0200 Subject: Various fixes for class support Add support for a default constructor if none is given. Fix support for computed method names, by unifying the handling between static and non static methods. Fix our table generation, so that we write UINT_MAX as the string index for undefined strings and not a reference to the empty string, as that can actually be a valid method name. Add support for getter and setter methods in classes. Change-Id: If52c57d6a67424b0218b86339b95aed9d0351e47 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4compiler.cpp | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'src/qml/compiler/qv4compiler.cpp') diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index eb38ba564d..f1afad4965 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -396,6 +396,10 @@ void QV4::Compiler::JSUnitGenerator::writeFunction(char *f, QV4::Compiler::Conte memcpy(f + function->codeOffset, irFunction->code.constData(), irFunction->code.size()); } +static_assert(int(QV4::Compiler::Class::Method::Regular) == int(QV4::CompiledData::Method::Regular), "Incompatible layout"); +static_assert(int(QV4::Compiler::Class::Method::Getter) == int(QV4::CompiledData::Method::Getter), "Incompatible layout"); +static_assert(int(QV4::Compiler::Class::Method::Setter) == int(QV4::CompiledData::Method::Setter), "Incompatible layout"); + void QV4::Compiler::JSUnitGenerator::writeClass(char *b, const QV4::Compiler::Class &c) { QV4::CompiledData::Class *cls = reinterpret_cast(b); @@ -406,31 +410,40 @@ void QV4::Compiler::JSUnitGenerator::writeClass(char *b, const QV4::Compiler::Cl allMethods += c.methods; cls->constructorFunction = c.constructorIndex; - cls->nameIndex = getStringId(c.name); + cls->nameIndex = c.nameIndex; cls->nMethods = c.methods.size(); cls->nStaticMethods = c.staticMethods.size(); - cls->nameTableOffset = currentOffset; - quint32_le *names = reinterpret_cast(b + currentOffset); - currentOffset += allMethods.size() * sizeof(quint32); cls->methodTableOffset = currentOffset; - quint32_le *methods = reinterpret_cast(b + currentOffset); - currentOffset += cls->nMethods * sizeof(quint32); + CompiledData::Method *method = reinterpret_cast(b + currentOffset); // write methods for (int i = 0; i < allMethods.size(); ++i) { - names[i] = getStringId(allMethods.at(i).name); - methods[i] = allMethods.at(i).functionIndex; - // ### fix getter and setter methods + method->name = allMethods.at(i).nameIndex; + method->type = allMethods.at(i).type; + method->function = allMethods.at(i).functionIndex; + ++method; } static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_BYTECODE"); if (showCode) { qDebug() << "=== Class " << stringForIndex(cls->nameIndex) << "static methods" << cls->nStaticMethods << "methods" << cls->nMethods; qDebug() << " constructor:" << cls->constructorFunction; - for (uint i = 0; i < cls->nStaticMethods; ++i) - qDebug() << " " << i << ": static" << stringForIndex(cls->nameTable()[i]); - for (uint i = 0; i < cls->nMethods; ++i) - qDebug() << " " << i << ": " << stringForIndex(cls->nameTable()[cls->nStaticMethods + i]); + const char *staticString = ": static "; + for (uint i = 0; i < cls->nStaticMethods + cls->nMethods; ++i) { + if (i == cls->nStaticMethods) + staticString = ": "; + const char *type; + switch (cls->methodTable()[i].type) { + case CompiledData::Method::Getter: + type = "get "; break; + case CompiledData::Method::Setter: + type = "set "; break; + default: + type = ""; + + } + qDebug() << " " << i << staticString << type << stringForIndex(cls->methodTable()[i].name) << cls->methodTable()[i].function; + } qDebug(); } } -- cgit v1.2.3