diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-08-14 11:44:49 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-28 04:32:48 +0200 |
commit | 70a2c0491d66aa05f9e9e67f8a845f4df84da857 (patch) | |
tree | 08d7828cfb6950926e1176ee420d5e15dedd9817 /src/qml/qml/v4 | |
parent | 3912bbaceab166eb116447311eb16453e4f26edf (diff) |
Refactor singleton type registration code
Previously each singleton type was registered as an implicit separate
import. This commit changes the code so that these types are treated
just like any other type in the registration sense.
It also ensures that singleton types are instantiated per-engine.
Change-Id: I5c81c4ca5bf65210f7125d74a62a282a21838068
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'src/qml/qml/v4')
-rw-r--r-- | src/qml/qml/v4/qv4bindings.cpp | 22 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4compiler.cpp | 10 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4instruction.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4instruction_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4ir.cpp | 8 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4ir_p.h | 14 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4irbuilder.cpp | 12 |
7 files changed, 34 insertions, 38 deletions
diff --git a/src/qml/qml/v4/qv4bindings.cpp b/src/qml/qml/v4/qv4bindings.cpp index ddc94d8ce4..7d64de707f 100644 --- a/src/qml/qml/v4/qv4bindings.cpp +++ b/src/qml/qml/v4/qv4bindings.cpp @@ -1020,7 +1020,7 @@ void QV4Bindings::run(int instrIndex, quint32 &executedBlocks, registers[instr->load.reg].setQObject(context->contextObject); QML_V4_END_INSTR(LoadRoot, load) - QML_V4_BEGIN_INSTR(LoadModuleObject, load) + QML_V4_BEGIN_INSTR(LoadSingletonObject, load) { Register ® = registers[instr->load.reg]; @@ -1028,20 +1028,18 @@ void QV4Bindings::run(int instrIndex, quint32 &executedBlocks, QQmlTypeNameCache::Result r = context->imports->query(*name); reg.cleanupString(); - if (r.isValid() && r.importNamespace) { - QQmlMetaType::SingletonInstance *singletonType = context->imports->singletonType(r.importNamespace); - if (singletonType) { - if (singletonType->qobjectCallback) { - singletonType->qobjectApi = singletonType->qobjectCallback(context->engine, context->engine); - singletonType->qobjectCallback = 0; - singletonType->scriptCallback = 0; - } - if (singletonType->qobjectApi) - reg.setQObject(singletonType->qobjectApi); + if (r.isValid() && r.type) { + if (r.type->isSingleton()) { + QQmlEngine *e = context->engine; + QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo(); + siinfo->init(e); // note: this will also create QJSValue singleton, which is not strictly required here. + QObject *qobjectSingleton = siinfo->qobjectApi(e); + if (qobjectSingleton) + reg.setQObject(qobjectSingleton); } } } - QML_V4_END_INSTR(LoadModuleObject, load) + QML_V4_END_INSTR(LoadSingletonObject, load) QML_V4_BEGIN_INSTR(LoadAttached, attached) { diff --git a/src/qml/qml/v4/qv4compiler.cpp b/src/qml/qml/v4/qv4compiler.cpp index 1506d09ce9..d5f44c4085 100644 --- a/src/qml/qml/v4/qv4compiler.cpp +++ b/src/qml/qml/v4/qv4compiler.cpp @@ -330,18 +330,18 @@ void QV4CompilerPrivate::visitName(IR::Name *e) gen(attached); } break; - case IR::Name::ModuleObject: { + case IR::Name::SingletonObject: { /* - Existing module object lookup methods include: - 1. string -> module object (search via importCache->query(name)) - 2. QQmlMetaType::SingletonType -> module object (via QQmlEnginePrivate::singletonTypeInstance() cache) + Existing singleton type object lookup methods include: + 1. string -> singleton object (search via importCache->query(name)) + 2. typeid -> singleton object QQmlType (search via ???) We currently use 1, which is not ideal for performance */ _subscribeName << *e->id; registerLiteralString(currentReg, e->id); - Instr::LoadModuleObject module; + Instr::LoadSingletonObject module; module.reg = currentReg; gen(module); } break; diff --git a/src/qml/qml/v4/qv4instruction.cpp b/src/qml/qml/v4/qv4instruction.cpp index 1fbdf3e325..252c9e9a7a 100644 --- a/src/qml/qml/v4/qv4instruction.cpp +++ b/src/qml/qml/v4/qv4instruction.cpp @@ -114,8 +114,8 @@ void Bytecode::dump(const V4Instr *i, int address) const case V4Instr::LoadRoot: INSTR_DUMP << '\t' << "LoadRoot" << "\t\t" << "-> Output_Reg(" << i->load.reg << ')'; break; - case V4Instr::LoadModuleObject: - INSTR_DUMP << '\t' << "LoadModuleObject" << "\t\t" << ") -> Output_Reg(" << i->load.reg << ')'; + case V4Instr::LoadSingletonObject: + INSTR_DUMP << '\t' << "LoadSingletonObject" << "\t\t" << ") -> Output_Reg(" << i->load.reg << ')'; break; case V4Instr::LoadAttached: INSTR_DUMP << '\t' << "LoadAttached" << "\t\t" << "Object_Reg(" << i->attached.reg << ") Attached_Index(" << i->attached.id << ") -> Output_Reg(" << i->attached.output << ')'; diff --git a/src/qml/qml/v4/qv4instruction_p.h b/src/qml/qml/v4/qv4instruction_p.h index 763cd2d67b..34d483b079 100644 --- a/src/qml/qml/v4/qv4instruction_p.h +++ b/src/qml/qml/v4/qv4instruction_p.h @@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE F(LoadId, load) \ F(LoadScope, load) \ F(LoadRoot, load) \ - F(LoadModuleObject, load) \ + F(LoadSingletonObject, load) \ F(LoadAttached, attached) \ F(UnaryNot, unaryop) \ F(UnaryMinusNumber, unaryop) \ diff --git a/src/qml/qml/v4/qv4ir.cpp b/src/qml/qml/v4/qv4ir.cpp index 931a377610..99631cfea6 100644 --- a/src/qml/qml/v4/qv4ir.cpp +++ b/src/qml/qml/v4/qv4ir.cpp @@ -551,13 +551,13 @@ Name *BasicBlock::ATTACH_TYPE(const QString &id, const QQmlType *attachType, Nam return name; } -Name *BasicBlock::MODULE_OBJECT(const QString &id, const QQmlMetaObject &meta, Name::Storage storage, +Name *BasicBlock::SINGLETON_OBJECT(const QString &id, const QQmlMetaObject &meta, Name::Storage storage, quint16 line, quint16 column) { Name *name = function->pool->New<Name>(); name->init(/*base = */ 0, IR::ObjectType, function->newString(id), - Name::ModuleObject, line, column); + Name::SingletonObject, line, column); name->meta = meta; name->storage = storage; return name; @@ -700,8 +700,8 @@ static const char *symbolname(Name::Symbol s) return "IdObject"; case Name::AttachType: return "AttachType"; - case Name::ModuleObject: - return "ModuleObject"; + case Name::SingletonObject: + return "SingletonObject"; case Name::Object: return "Object"; case Name::Property: diff --git a/src/qml/qml/v4/qv4ir_p.h b/src/qml/qml/v4/qv4ir_p.h index f6e20a7187..2c31d644e8 100644 --- a/src/qml/qml/v4/qv4ir_p.h +++ b/src/qml/qml/v4/qv4ir_p.h @@ -255,12 +255,12 @@ enum BuiltinSymbol { struct Name: Expr { enum Symbol { Unbound, - IdObject, // This is a load of a id object. Storage will always be IdStorage - AttachType, // This is a load of an attached object - ModuleObject, // This is a load of a module object - Object, // XXX what is this for? - Property, // This is a load of a regular property - Slot // XXX what is this for? + IdObject, // This is a load of a id object. Storage will always be IdStorage + AttachType, // This is a load of an attached object + SingletonObject, // This is a load of a singleton object + Object, // XXX what is this for? + Property, // This is a load of a regular property + Slot // XXX what is this for? }; enum Storage { @@ -545,7 +545,7 @@ struct BasicBlock { Name *SYMBOL(Name *base, Type type, const QString &id, const QQmlMetaObject &meta, QQmlPropertyData *property, Name::Storage storage, quint16 line, quint16 column); Name *ID_OBJECT(const QString &id, const QQmlScript::Object *object, quint16 line, quint16 column); Name *ATTACH_TYPE(const QString &id, const QQmlType *attachType, Name::Storage storage, quint16 line, quint16 column); - Name *MODULE_OBJECT(const QString &id, const QQmlMetaObject &meta, Name::Storage storage, quint16 line, quint16 column); + Name *SINGLETON_OBJECT(const QString &id, const QQmlMetaObject &meta, Name::Storage storage, quint16 line, quint16 column); Expr *UNOP(AluOp op, Expr *expr); Expr *BINOP(AluOp op, Expr *left, Expr *right); diff --git a/src/qml/qml/v4/qv4irbuilder.cpp b/src/qml/qml/v4/qv4irbuilder.cpp index 45e3a72986..55381f73a0 100644 --- a/src/qml/qml/v4/qv4irbuilder.cpp +++ b/src/qml/qml/v4/qv4irbuilder.cpp @@ -444,20 +444,18 @@ bool QV4IRBuilder::visit(AST::IdentifierExpression *ast) QQmlTypeNameCache::Result r = m_expression->importCache->query(name); if (r.isValid()) { if (r.type) { - _expr.code = _block->ATTACH_TYPE(name, r.type, IR::Name::ScopeStorage, line, column); - } else if (r.importNamespace) { - QQmlMetaType::SingletonInstance *singletonType = m_expression->importCache->singletonType(r.importNamespace); - if (singletonType && singletonType->instanceMetaObject) { + if (r.type->isSingleton()) { // Note: we don't need to check singletonType->qobjectCallback here, since // we did that check in registerSingletonType() in qqmlmetatype.cpp. // We cannot create the QObject Singleton Type Instance here, // as we might be running in a loader thread. // Thus, V4 can only handle bindings which use Singleton Types which // were registered with the templated registration function. - _expr.code = _block->MODULE_OBJECT(name, singletonType->instanceMetaObject, IR::Name::MemberStorage, line, column); + _expr.code = _block->SINGLETON_OBJECT(name, r.type->singletonInstanceInfo()->instanceMetaObject, IR::Name::MemberStorage, line, column); + } else { + _expr.code = _block->ATTACH_TYPE(name, r.type, IR::Name::ScopeStorage, line, column); } } - // We don't support anything else } else { bool found = false; @@ -625,7 +623,7 @@ bool QV4IRBuilder::visit(AST::FieldMemberExpression *ast) } break; - case IR::Name::ModuleObject: { + case IR::Name::SingletonObject: { if (name.at(0).isUpper()) { QByteArray utf8Name = name.toUtf8(); const char *enumName = utf8Name.constData(); |