diff options
Diffstat (limited to 'src/qml/qml/qqmlcustomparser.cpp')
-rw-r--r-- | src/qml/qml/qqmlcustomparser.cpp | 76 |
1 files changed, 73 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlcustomparser.cpp b/src/qml/qml/qqmlcustomparser.cpp index 19e49009ce..ca23451774 100644 --- a/src/qml/qml/qqmlcustomparser.cpp +++ b/src/qml/qml/qqmlcustomparser.cpp @@ -230,6 +230,13 @@ void QQmlCustomParser::clearErrors() exceptions.clear(); } +QByteArray QQmlCustomParser::compile(const QV4::CompiledData::QmlUnit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &bindings) +{ + Q_UNUSED(qmlUnit) + Q_UNUSED(bindings) + return QByteArray(); +} + /*! Reports an error with the given \a description. @@ -256,7 +263,6 @@ void QQmlCustomParser::error(const QString& description) void QQmlCustomParser::error(const QQmlCustomParserProperty& prop, const QString& description) { QQmlError error; - QString exceptionDescription; error.setLine(prop.location().line); error.setColumn(prop.location().column); error.setDescription(description); @@ -271,7 +277,6 @@ void QQmlCustomParser::error(const QQmlCustomParserProperty& prop, const QString void QQmlCustomParser::error(const QQmlCustomParserNode& node, const QString& description) { QQmlError error; - QString exceptionDescription; error.setLine(node.location().line); error.setColumn(node.location().column); error.setDescription(description); @@ -279,6 +284,34 @@ void QQmlCustomParser::error(const QQmlCustomParserNode& node, const QString& de } /*! + Reports an error in parsing \a binding, with the given \a description. + + An error is generated referring to the position of \a node in the source file. +*/ +void QQmlCustomParser::error(const QV4::CompiledData::Binding *binding, const QString &description) +{ + QQmlError error; + error.setLine(binding->location.line); + error.setColumn(binding->location.column); + error.setDescription(description); + exceptions << error; +} + +/*! + Reports an error in parsing \a object, with the given \a description. + + An error is generated referring to the position of \a object in the source file. +*/ +void QQmlCustomParser::error(const QV4::CompiledData::Object *object, const QString &description) +{ + QQmlError error; + error.setLine(object->location.line); + error.setColumn(object->location.column); + error.setDescription(description); + exceptions << error; +} + +/*! If \a script is a simple enumeration expression (eg. Text.AlignLeft), returns the integer equivalent (eg. 1), and sets \a ok to true. @@ -313,7 +346,44 @@ const QMetaObject *QQmlCustomParser::resolveType(const QString& name) const */ QQmlBinding::Identifier QQmlCustomParser::bindingIdentifier(const QQmlScript::Variant &value, const QString& name) { - return compiler->bindingIdentifier(name, value, QQmlCompilerTypes::BindingContext(object)); + return compiler->bindingIdentifier(value, name, this); +} + +struct StaticQtMetaObject : public QObject +{ + static const QMetaObject *get() + { return &staticQtMetaObject; } +}; + +int QQmlCustomParserCompilerBackend::evaluateEnum(const QString &scope, const QByteArray &enumValue, bool *ok) const +{ + Q_ASSERT_X(ok, "QQmlCompiler::evaluateEnum", "ok must not be a null pointer"); + *ok = false; + + if (scope != QLatin1String("Qt")) { + QQmlType *type = 0; + imports().resolveType(scope, &type, 0, 0, 0); + return type ? type->enumValue(QHashedCStringRef(enumValue.constData(), enumValue.length()), ok) : -1; + } + + 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; +} + +const QMetaObject *QQmlCustomParserCompilerBackend::resolveType(const QString &name) const +{ + QQmlType *qmltype = 0; + if (!imports().resolveType(name, &qmltype, 0, 0, 0)) + return 0; + if (!qmltype) + return 0; + return qmltype->metaObject(); } QT_END_NAMESPACE |