diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-10-24 14:51:02 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-31 10:50:38 +0100 |
commit | 34c85bb56c92316a6ce1c79d25f9653fec14791c (patch) | |
tree | 6d3d43de33fa53a1353c52506e989ae126f1361b /src/qml/compiler/qv4jsir_p.h | |
parent | bb7d26ebb0c2e7a9f06a030be8bfcd00e346e06f (diff) |
Initial support for resolving meta-property access for the scope and context objects at QML compile time
This avoids having to do a string lookup for ids and in the import cache at
run-time, before we can do a string hash lookup in the property cache. Instead
we resolve final properties in the context and scope object at compile time and
look them up at run-time using their index instead. The dependencies to these
properties are also tracked separately and recorded in the compiled data.
This is merely the initial patch. There's a lot left to do, such as having
specialized getter and setters for specific property types. Setters are missing
altogether right now and will fall back to name lookup.
Change-Id: If3cb4e7c9454ef4850a615f0935b311c9395b165
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler/qv4jsir_p.h')
-rw-r--r-- | src/qml/compiler/qv4jsir_p.h | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/qml/compiler/qv4jsir_p.h b/src/qml/compiler/qv4jsir_p.h index 1f69ac4964..7e7a972c54 100644 --- a/src/qml/compiler/qv4jsir_p.h +++ b/src/qml/compiler/qv4jsir_p.h @@ -72,6 +72,7 @@ QT_BEGIN_NAMESPACE class QTextStream; class QQmlType; +class QQmlPropertyData; namespace QV4 { struct ExecutionContext; @@ -323,7 +324,9 @@ struct Name: Expr { builtin_define_getter_setter, builtin_define_object_literal, builtin_setup_argument_object, - builtin_qml_id_scope + builtin_qml_id_scope, + builtin_qml_context_object, + builtin_qml_scope_object }; const QString *id; @@ -516,13 +519,15 @@ struct Member: Expr { enum MemberType { MemberByName, // QML extensions - MemberByObjectId // lookup in context's id values + MemberByObjectId, // lookup in context's id values + MemberOfQObject }; MemberType type; Expr *base; const QString *name; int objectId; + QQmlPropertyData *property; void init(Expr *base, const QString *name) { @@ -530,6 +535,7 @@ struct Member: Expr { this->base = base; this->name = name; this->objectId = -1; + this->property = 0; } void initQmlIdObject(Expr *base, const QString *name, int objectId) @@ -538,6 +544,15 @@ struct Member: Expr { this->base = base; this->name = name; this->objectId = objectId; + this->property = 0; + } + + void initMetaProperty(Expr *base, const QString *name, QQmlPropertyData *property) + { + this->type = MemberOfQObject; + this->base = base; + this->name = name; + this->property = property; } virtual void accept(ExprVisitor *v) { v->visitMember(this); } @@ -831,7 +846,8 @@ struct BasicBlock { Expr *NEW(Expr *base, ExprList *args = 0); Expr *SUBSCRIPT(Expr *base, Expr *index); Expr *MEMBER(Expr *base, const QString *name); - Expr *QML_CONTEXT_ID_MEMBER(const QString &id, int idIndex, quint32 line, quint32 column); + Expr *QML_CONTEXT_ID_MEMBER(Expr *base, const QString *id, int idIndex); + Expr *QML_QOBJECT_PROPERTY(Expr *base, const QString *id, QQmlPropertyData *property); Stmt *EXP(Expr *expr); @@ -933,10 +949,14 @@ private: struct QmlDependenciesCollector : public V4IR::StmtVisitor, V4IR::ExprVisitor { - QSet<int> run(Function *function) + void run(Function *function, QSet<int> *idObjectDependencies, QSet<QQmlPropertyData*> *contextPropertyDependencies, QSet<QQmlPropertyData*> *scopePropertyDependencies) { - QSet<int> dependencies; - qSwap(_usedIdObjects, dependencies); + QSet<int> idProperties; + QSet<QQmlPropertyData*> contextProperties; + QSet<QQmlPropertyData*> scopeProperties; + qSwap(_usedIdObjects, idProperties); + qSwap(_usedContextProperties, contextProperties); + qSwap(_usedScopeProperties, scopeProperties); for (int i = 0; i < function->basicBlocks.count(); ++i) { BasicBlock *bb = function->basicBlocks.at(i); for (int j = 0; j < bb->statements.count(); ++j) { @@ -944,12 +964,19 @@ struct QmlDependenciesCollector : public V4IR::StmtVisitor, V4IR::ExprVisitor s->accept(this); } } - qSwap(_usedIdObjects, dependencies); - return dependencies; + qSwap(_usedScopeProperties, scopeProperties); + qSwap(_usedContextProperties, contextProperties); + qSwap(_usedIdObjects, idProperties); + + *idObjectDependencies = idProperties; + *contextPropertyDependencies = contextProperties; + *scopePropertyDependencies = scopeProperties; } protected: QSet<int> _usedIdObjects; + QSet<QQmlPropertyData*> _usedContextProperties; + QSet<QQmlPropertyData*> _usedScopeProperties; virtual void visitConst(Const *) {} virtual void visitString(String *) {} @@ -976,11 +1003,7 @@ protected: e->index->accept(this); } - virtual void visitMember(Member *e) { - e->base->accept(this); - if (e->type == Member::MemberByObjectId) - _usedIdObjects.insert(e->objectId); - } + virtual void visitMember(Member *e); virtual void visitExp(Exp *s) {s->expr->accept(this);} virtual void visitMove(Move *s) { |