diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-01-15 16:17:22 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-17 08:10:07 +0100 |
commit | 814504306df0b76da1654a74524bdc353527d06f (patch) | |
tree | d20bd388b6992e2e36c66f809070428235e7522b /src/qml/qml/qqmlcompiler.cpp | |
parent | 8fc545de4166eb3c73833e9d9136dfbebf43539a (diff) |
[new compiler] Add support for type and enum resolution for custom parsers
This is in preparation for listmodel support, share the code for resolving
types and enums between the old and the new compiler, as all it needs is the
imports.
Change-Id: I4908d71eee50c769108e0e2b68b03496722fa49d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlcompiler.cpp')
-rw-r--r-- | src/qml/qml/qqmlcompiler.cpp | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/qml/qml/qqmlcompiler.cpp b/src/qml/qml/qqmlcompiler.cpp index 6717c97d88..069345ecd3 100644 --- a/src/qml/qml/qqmlcompiler.cpp +++ b/src/qml/qml/qqmlcompiler.cpp @@ -2614,7 +2614,7 @@ bool QQmlCompiler::testQualifiedEnumAssignment(QQmlScript::Property *prop, if (isIntProp) { // Allow enum assignment to ints. bool ok; - int enumval = evaluateEnum(typeName, enumValue.toUtf8(), &ok); + int enumval = evaluateEnum(typeName.toString(), enumValue.toUtf8(), &ok); if (ok) { v->type = Value::Literal; v->value = QQmlScript::Variant((double)enumval); @@ -2665,46 +2665,38 @@ bool QQmlCompiler::testQualifiedEnumAssignment(QQmlScript::Property *prop, return true; } -// Similar logic to above, but not knowing target property. -int QQmlCompiler::evaluateEnum(const QHashedStringRef &scope, const QByteArray& enumValue, bool *ok) const +int QQmlCompiler::bindingIdentifier(const QString &name, const Variant &value, const BindingContext &ctxt) { - Q_ASSERT_X(ok, "QQmlCompiler::evaluateEnum", "ok must not be a null pointer"); - *ok = false; + JSBindingReference *reference = pool->New<JSBindingReference>(); + reference->expression = value; + reference->property = pool->New<Property>(); + reference->property->setName(name); + reference->value = 0; + reference->bindingContext = ctxt; + reference->bindingContext.owner++; + // Unfortunately this is required for example for PropertyChanges where the bindings + // will be executed in the dynamic scope of the target, so we can't resolve any lookups + // at run-time. + reference->disableLookupAcceleration = true; - if (scope != QLatin1String("Qt")) { - QQmlType *type = 0; - unit->imports().resolveType(scope, &type, 0, 0, 0); - return type ? type->enumValue(QHashedCStringRef(enumValue.constData(), enumValue.length()), ok) : -1; - } + const int id = output->customParserBindings.count(); + output->customParserBindings.append(0); // Filled in later. + reference->customParserBindingsIndex = id; - const QMetaObject *mo = StaticQtMetaObject::get(); - int i = mo->enumeratorCount(); - while (i--) { - int v = mo->enumerator(i).keyToValue(enumValue.constData(), ok); - if (*ok) - return v; - } - return -1; -} + compileState->totalBindingsCount++; + compileState->bindings.prepend(reference); -const QMetaObject *QQmlCompiler::resolveType(const QString& name) const -{ - QQmlType *qmltype = 0; - if (!unit->imports().resolveType(name, &qmltype, 0, 0, 0)) - return 0; - if (!qmltype) - return 0; - return qmltype->metaObject(); + return id; } -int QQmlCompiler::bindingIdentifier(const QString &name, const Variant &value, const BindingContext &ctxt) +QQmlBinding::Identifier QQmlCompiler::bindingIdentifier(const Variant &value, const QString &name, QQmlCustomParser *customParser) { JSBindingReference *reference = pool->New<JSBindingReference>(); reference->expression = value; reference->property = pool->New<Property>(); reference->property->setName(name); reference->value = 0; - reference->bindingContext = ctxt; + reference->bindingContext = QQmlCompilerTypes::BindingContext(customParser->object); reference->bindingContext.owner++; // Unfortunately this is required for example for PropertyChanges where the bindings // will be executed in the dynamic scope of the target, so we can't resolve any lookups |