diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-08 14:49:41 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-14 13:07:46 +0000 |
commit | e600b04282e964f64f9db7795cef15da32a51b21 (patch) | |
tree | 826eab0863f8cea4ca60415bc03020de41120a79 /src | |
parent | f136724f2cefe97fda13e942674a5e3677c8cd2e (diff) |
Cleanup: Fix const'ness of the property binding validator code
The property validator is supposed to validate the proposed property bindings
and abort type compilation if necessary. As such it is a read-only pass through
the data structures and therefore we make it const. However it does have a
side-effect of collecting some state, which however is "write-only" and
therefore marked as mutable. Those variables are written to, but not read
during this pass.
Change-Id: I6a3655fedbd6691b7498cf82ca1c8e21dd635bd3
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qqmltypecompiler.cpp | 14 | ||||
-rw-r--r-- | src/qml/compiler/qqmltypecompiler_p.h | 15 | ||||
-rw-r--r-- | src/qml/qml/qqmlcustomparser_p.h | 2 |
3 files changed, 16 insertions, 15 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index ec8e6ac33c..b249d9ad9e 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -402,7 +402,7 @@ QQmlCompilePass::QQmlCompilePass(QQmlTypeCompiler *typeCompiler) { } -void QQmlCompilePass::recordError(const QV4::CompiledData::Location &location, const QString &description) +void QQmlCompilePass::recordError(const QV4::CompiledData::Location &location, const QString &description) const { QQmlError error; error.setLine(location.line); @@ -1714,7 +1714,7 @@ bool QQmlPropertyValidator::validate() { if (!validateObject(qmlUnit->indexOfRootObject, /*instantiatingBinding*/0)) return false; - compiler->setDeferredBindingsPerObject(deferredBindingsPerObject); + compiler->setDeferredBindingsPerObject(_deferredBindingsPerObject); return true; } @@ -1752,7 +1752,7 @@ struct BindingFinder } }; -bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledData::Binding *instantiatingBinding, bool populatingValueTypeGroupProperty) +bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledData::Binding *instantiatingBinding, bool populatingValueTypeGroupProperty) const { const QV4::CompiledData::Object *obj = qmlUnit->objectAt(objectIndex); if (obj->idIndex != 0) @@ -2007,12 +2007,12 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD } if (!deferredBindings.isEmpty()) - deferredBindingsPerObject.insert(objectIndex, deferredBindings); + _deferredBindingsPerObject.insert(objectIndex, deferredBindings); return true; } -bool QQmlPropertyValidator::validateLiteralBinding(QQmlPropertyCache *propertyCache, QQmlPropertyData *property, const QV4::CompiledData::Binding *binding) +bool QQmlPropertyValidator::validateLiteralBinding(QQmlPropertyCache *propertyCache, QQmlPropertyData *property, const QV4::CompiledData::Binding *binding) const { if (property->isQList()) { recordError(binding->valueLocation, tr("Cannot assign primitives to lists")); @@ -2288,7 +2288,7 @@ bool QQmlPropertyValidator::validateLiteralBinding(QQmlPropertyCache *propertyCa Returns true if from can be assigned to a (QObject) property of type to. */ -bool QQmlPropertyValidator::canCoerce(int to, QQmlPropertyCache *fromMo) +bool QQmlPropertyValidator::canCoerce(int to, QQmlPropertyCache *fromMo) const { QQmlPropertyCache *toMo = enginePrivate->rawPropertyCacheForType(to); @@ -2300,7 +2300,7 @@ bool QQmlPropertyValidator::canCoerce(int to, QQmlPropertyCache *fromMo) return false; } -bool QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *property, const QString &propertyName, const QV4::CompiledData::Binding *binding) +bool QQmlPropertyValidator::validateObjectBinding(QQmlPropertyData *property, const QString &propertyName, const QV4::CompiledData::Binding *binding) const { if (binding->flags & QV4::CompiledData::Binding::IsOnAssignment) { Q_ASSERT(binding->type == QV4::CompiledData::Binding::Type_Object); diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h index 025718dd96..0982058e14 100644 --- a/src/qml/compiler/qqmltypecompiler_p.h +++ b/src/qml/compiler/qqmltypecompiler_p.h @@ -116,7 +116,7 @@ struct QQmlCompilePass QString stringAt(int idx) const { return compiler->stringAt(idx); } protected: - void recordError(const QV4::CompiledData::Location &location, const QString &description); + void recordError(const QV4::CompiledData::Location &location, const QString &description) const; QQmlTypeCompiler *compiler; }; @@ -276,13 +276,13 @@ public: virtual QString bindingAsString(int objectIndex, const QV4::CompiledData::Binding *binding) const; private: - bool validateObject(int objectIndex, const QV4::CompiledData::Binding *instantiatingBinding, bool populatingValueTypeGroupProperty = false); - bool validateLiteralBinding(QQmlPropertyCache *propertyCache, QQmlPropertyData *property, const QV4::CompiledData::Binding *binding); - bool validateObjectBinding(QQmlPropertyData *property, const QString &propertyName, const QV4::CompiledData::Binding *binding); + bool validateObject(int objectIndex, const QV4::CompiledData::Binding *instantiatingBinding, bool populatingValueTypeGroupProperty = false) const; + bool validateLiteralBinding(QQmlPropertyCache *propertyCache, QQmlPropertyData *property, const QV4::CompiledData::Binding *binding) const; + bool validateObjectBinding(QQmlPropertyData *property, const QString &propertyName, const QV4::CompiledData::Binding *binding) const; bool isComponent(int objectIndex) const { return objectIndexToIdPerComponent.contains(objectIndex); } - bool canCoerce(int to, QQmlPropertyCache *fromMo); + bool canCoerce(int to, QQmlPropertyCache *fromMo) const; QQmlEnginePrivate *enginePrivate; const QV4::CompiledData::Unit *qmlUnit; @@ -291,9 +291,10 @@ private: const QVector<QQmlPropertyCache *> &propertyCaches; const QHash<int, QHash<int, int> > objectIndexToIdPerComponent; QHash<int, QBitArray> *customParserBindingsPerObject; - QHash<int, QBitArray> deferredBindingsPerObject; - bool _seenObjectWithId; + // collected state variables, essentially write-only + mutable QHash<int, QBitArray> _deferredBindingsPerObject; + mutable bool _seenObjectWithId; }; // ### merge with QtQml::JSCodeGen and operate directly on object->functionsAndExpressions once old compiler is gone. diff --git a/src/qml/qml/qqmlcustomparser_p.h b/src/qml/qml/qqmlcustomparser_p.h index 15ca126365..88282b1bbc 100644 --- a/src/qml/qml/qqmlcustomparser_p.h +++ b/src/qml/qml/qqmlcustomparser_p.h @@ -100,7 +100,7 @@ protected: private: QList<QQmlError> exceptions; - QQmlCustomParserCompilerBackend *compiler; + const QQmlCustomParserCompilerBackend *compiler; Flags m_flags; QBiPointer<const QQmlImports, QQmlTypeNameCache> imports; friend class QQmlPropertyValidator; |