aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compiler.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-06-22 09:20:43 +0200
committerLars Knoll <lars.knoll@qt.io>2018-06-26 10:04:11 +0000
commite9b3bdb96e008060a0e78815a3995015e5e4598d (patch)
treeb3213bc461329723e9fd119a65a5556c12209a21 /src/qml/compiler/qv4compiler.cpp
parent046d1c5db44f409c67244bd70b13077cc03219b2 (diff)
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 <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compiler.cpp')
-rw-r--r--src/qml/compiler/qv4compiler.cpp39
1 files changed, 26 insertions, 13 deletions
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<QV4::CompiledData::Class *>(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<quint32_le *>(b + currentOffset);
- currentOffset += allMethods.size() * sizeof(quint32);
cls->methodTableOffset = currentOffset;
- quint32_le *methods = reinterpret_cast<quint32_le *>(b + currentOffset);
- currentOffset += cls->nMethods * sizeof(quint32);
+ CompiledData::Method *method = reinterpret_cast<CompiledData::Method *>(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();
}
}