aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2016-06-15 08:57:33 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-06-16 19:05:57 +0000
commit4da7ca32bb271355ae3e707499a3f5627de069d4 (patch)
tree73d6398c6f9c9fd16279b9b0b905934e0ce78441 /src/qml
parentf2c97b4e307a62b831f68a0278551d4375170336 (diff)
Minor QQmlPropertyCacheCreator API cleanup
As part of removing the QQmlTypeCompiler dependency, the property cache vector output of the creator is now passed explicitly as an out parameter to the constructor. Similarly the error handling is made explicit in the API instead of implicitly passing any generated errors to the QQmlTypeCompiler. Change-Id: Ia3013011518f59f57f2eecb526f64dec7d82cb91 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/compiler/qqmlpropertycachecreator.cpp29
-rw-r--r--src/qml/compiler/qqmlpropertycachecreator_p.h8
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp57
-rw-r--r--src/qml/compiler/qqmltypecompiler_p.h31
4 files changed, 57 insertions, 68 deletions
diff --git a/src/qml/compiler/qqmlpropertycachecreator.cpp b/src/qml/compiler/qqmlpropertycachecreator.cpp
index a0bcba01ce..bd5bb3620d 100644
--- a/src/qml/compiler/qqmlpropertycachecreator.cpp
+++ b/src/qml/compiler/qqmlpropertycachecreator.cpp
@@ -68,34 +68,25 @@ QQmlPropertyCacheCreator::InstantiationContext::InstantiationContext(int referen
}
}
-QQmlPropertyCacheCreator::QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler)
+QQmlPropertyCacheCreator::QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler, QQmlPropertyCacheVector *propertyCaches)
: QQmlCompilePass(typeCompiler)
, enginePrivate(typeCompiler->enginePrivate())
, qmlObjects(*typeCompiler->qmlObjects())
, imports(typeCompiler->imports())
, resolvedTypes(typeCompiler->resolvedTypes())
+ , propertyCaches(propertyCaches)
{
+ propertyCaches->resize(qmlObjects.count());
}
QQmlPropertyCacheCreator::~QQmlPropertyCacheCreator()
{
}
-bool QQmlPropertyCacheCreator::buildMetaObjects()
+QQmlCompileError QQmlPropertyCacheCreator::buildMetaObjects()
{
- propertyCaches.resize(qmlObjects.count());
-
InstantiationContext context;
-
- QQmlCompileError error = buildMetaObjectRecursively(compiler->rootObjectIndex(), context);
- if (error.isSet()) {
- recordError(error);
- return false;
- }
-
- compiler->setPropertyCaches(std::move(propertyCaches));
-
- return true;
+ return buildMetaObjectRecursively(compiler->rootObjectIndex(), context);
}
QQmlCompileError QQmlPropertyCacheCreator::buildMetaObjectRecursively(int objectIndex, const InstantiationContext &context)
@@ -111,7 +102,7 @@ QQmlCompileError QQmlPropertyCacheCreator::buildMetaObjectRecursively(int object
// the property that references us, for the latter we only need a meta-object on the referencing object
// because interceptors can't go to the shared value type instances.
if (context.instantiatingProperty && QQmlValueTypeFactory::isValueType(context.instantiatingProperty->propType)) {
- if (!propertyCaches.needsVMEMetaObject(context.referencingObjectIndex)) {
+ if (!propertyCaches->needsVMEMetaObject(context.referencingObjectIndex)) {
const QmlIR::Object *obj = qmlObjects.at(context.referencingObjectIndex);
auto *typeRef = resolvedTypes->value(obj->inheritedTypeNameIndex);
Q_ASSERT(typeRef);
@@ -143,11 +134,11 @@ QQmlCompileError QQmlPropertyCacheCreator::buildMetaObjectRecursively(int object
if (error.isSet())
return error;
} else {
- propertyCaches.set(objectIndex, baseTypeCache);
+ propertyCaches->set(objectIndex, baseTypeCache);
}
}
- if (QQmlPropertyCache *thisCache = propertyCaches.at(objectIndex)) {
+ if (QQmlPropertyCache *thisCache = propertyCaches->at(objectIndex)) {
for (auto binding = obj->bindingsBegin(), end = obj->bindingsEnd(); binding != end; ++binding)
if (binding->type >= QV4::CompiledData::Binding::Type_Object) {
InstantiationContext context(objectIndex, &(*binding), stringAt(binding->propertyNameIndex), thisCache);
@@ -226,8 +217,8 @@ QQmlCompileError QQmlPropertyCacheCreator::createMetaObject(int objectIndex, con
obj->functionCount() + obj->propertyCount() + obj->aliasCount() + obj->signalCount(),
obj->signalCount() + obj->propertyCount() + obj->aliasCount()));
- propertyCaches.set(objectIndex, cache);
- propertyCaches.setNeedsVMEMetaObject(objectIndex);
+ propertyCaches->set(objectIndex, cache);
+ propertyCaches->setNeedsVMEMetaObject(objectIndex);
struct TypeData {
QV4::CompiledData::Property::Type dtype;
diff --git a/src/qml/compiler/qqmlpropertycachecreator_p.h b/src/qml/compiler/qqmlpropertycachecreator_p.h
index 126bdbb017..8dd4b2bc0f 100644
--- a/src/qml/compiler/qqmlpropertycachecreator_p.h
+++ b/src/qml/compiler/qqmlpropertycachecreator_p.h
@@ -58,12 +58,12 @@ class QQmlPropertyCacheCreator : public QQmlCompilePass
{
Q_DECLARE_TR_FUNCTIONS(QQmlPropertyCacheCreator)
public:
- QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler);
+ QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler, QQmlPropertyCacheVector *propertyCaches);
~QQmlPropertyCacheCreator();
- bool buildMetaObjects();
-protected:
+ QQmlCompileError buildMetaObjects();
+protected:
struct InstantiationContext {
InstantiationContext();
InstantiationContext(int referencingObjectIndex, const QV4::CompiledData::Binding *instantiatingBinding, const QString &instantiatingPropertyName, const QQmlPropertyCache *referencingObjectPropertyCache);
@@ -81,7 +81,7 @@ protected:
const QVector<QmlIR::Object*> &qmlObjects;
const QQmlImports *imports;
QHash<int, QV4::CompiledData::CompilationUnit::ResolvedTypeReference*> *resolvedTypes;
- QQmlPropertyCacheVector propertyCaches;
+ QQmlPropertyCacheVector *propertyCaches;
};
QT_END_NAMESPACE
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index c75f951adb..f2a8538b4c 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -84,12 +84,7 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile()
QQmlType *qmlType = resolvedType->type;
if (resolvedType->typeData) {
if (resolvedType->needsCreation && qmlType->isCompositeSingleton()) {
- QQmlError error;
- QString reason = tr("Composite Singleton Type %1 is not creatable.").arg(qmlType->qmlTypeName());
- error.setDescription(reason);
- error.setColumn(resolvedType->location.column);
- error.setLine(resolvedType->location.line);
- recordError(error);
+ recordError(resolvedType->location, tr("Composite Singleton Type %1 is not creatable.").arg(qmlType->qmlTypeName()));
return nullptr;
}
ref->compilationUnit = resolvedType->typeData->compilationUnit();
@@ -102,23 +97,13 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile()
QString reason = ref->type->noCreationReason();
if (reason.isEmpty())
reason = tr("Element is not creatable.");
- error.setDescription(reason);
- error.setColumn(resolvedType->location.column);
- error.setLine(resolvedType->location.line);
- recordError(error);
+ recordError(resolvedType->location, reason);
return nullptr;
}
if (ref->type->containsRevisionedAttributes()) {
ref->typePropertyCache = engine->cache(ref->type,
resolvedType->minorVersion);
- if (!ref->typePropertyCache) {
- QQmlError cacheError;
- cacheError.setColumn(resolvedType->location.column);
- cacheError.setLine(resolvedType->location.line);
- recordError(cacheError);
- return nullptr;
- }
}
}
ref->majorVersion = resolvedType->majorVersion;
@@ -137,9 +122,12 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile()
}
{
- QQmlPropertyCacheCreator propertyCacheBuilder(this);
- if (!propertyCacheBuilder.buildMetaObjects())
+ QQmlPropertyCacheCreator propertyCacheBuilder(this, &m_propertyCaches);
+ QQmlCompileError error = propertyCacheBuilder.buildMetaObjects();
+ if (error.isSet()) {
+ recordError(error);
return nullptr;
+ }
}
{
@@ -299,11 +287,25 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile()
return nullptr;
}
-void QQmlTypeCompiler::recordError(const QQmlError &error)
+void QQmlTypeCompiler::recordError(QQmlError error)
+{
+ error.setUrl(url());
+ errors << error;
+}
+
+void QQmlTypeCompiler::recordError(const QV4::CompiledData::Location &location, const QString &description)
+{
+ QQmlError error;
+ error.setLine(location.line);
+ error.setColumn(location.column);
+ error.setDescription(description);
+ error.setUrl(url());
+ errors << error;
+}
+
+void QQmlTypeCompiler::recordError(const QQmlCompileError &error)
{
- QQmlError e = error;
- e.setUrl(url());
- errors << e;
+ recordError(error.location, error.description);
}
QString QQmlTypeCompiler::stringAt(int idx) const
@@ -392,14 +394,7 @@ QQmlCompilePass::QQmlCompilePass(QQmlTypeCompiler *typeCompiler)
{
}
-void QQmlCompilePass::recordError(const QV4::CompiledData::Location &location, const QString &description) const
-{
- QQmlError error;
- error.setLine(location.line);
- error.setColumn(location.column);
- error.setDescription(description);
- compiler->recordError(error);
-}
+
SignalHandlerConverter::SignalHandlerConverter(QQmlTypeCompiler *typeCompiler)
: QQmlCompilePass(typeCompiler)
diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h
index 351c4f7294..29712e73e7 100644
--- a/src/qml/compiler/qqmltypecompiler_p.h
+++ b/src/qml/compiler/qqmltypecompiler_p.h
@@ -74,6 +74,17 @@ struct Location;
}
}
+struct QQmlCompileError
+{
+ QQmlCompileError() {}
+ QQmlCompileError(const QV4::CompiledData::Location &location, const QString &description)
+ : location(location), description(description) {}
+ QV4::CompiledData::Location location;
+ QString description;
+
+ bool isSet() const { return !description.isEmpty(); }
+};
+
struct QQmlTypeCompiler
{
Q_DECLARE_TR_FUNCTIONS(QQmlTypeCompiler)
@@ -89,7 +100,9 @@ public:
QV4::CompiledData::CompilationUnit *compile();
QList<QQmlError> compilationErrors() const { return errors; }
- void recordError(const QQmlError &error);
+ void recordError(QQmlError error);
+ void recordError(const QV4::CompiledData::Location &location, const QString &description);
+ void recordError(const QQmlCompileError &error);
int registerString(const QString &str);
@@ -132,17 +145,6 @@ private:
QQmlPropertyCacheVector m_propertyCaches;
};
-struct QQmlCompileError
-{
- QQmlCompileError() {}
- QQmlCompileError(const QV4::CompiledData::Location &location, const QString &description)
- : location(location), description(description) {}
- QV4::CompiledData::Location location;
- QString description;
-
- bool isSet() const { return !description.isEmpty(); }
-};
-
struct QQmlCompilePass
{
virtual ~QQmlCompilePass() {}
@@ -151,9 +153,10 @@ struct QQmlCompilePass
QString stringAt(int idx) const { return compiler->stringAt(idx); }
protected:
- void recordError(const QV4::CompiledData::Location &location, const QString &description) const;
+ void recordError(const QV4::CompiledData::Location &location, const QString &description) const
+ { compiler->recordError(location, description); }
void recordError(const QQmlCompileError &error)
- { recordError(error.location, error.description); }
+ { compiler->recordError(error); }
QQmlTypeCompiler *compiler;
};