aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2016-06-20 08:32:21 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-06-20 14:15:40 +0000
commitc884f85863d5cbb90d8a1f3972ddb37b3d3f7e14 (patch)
tree50b965353b684fc30647393e483f737ef956a29d
parent7a1b5b1cfece18d5f4b2d8beb340d3cbe8f54451 (diff)
Move type compilation independent bits out of QQmlTypeCompiler
The type validation is something that works on the final compilation unit, so it can be done separately. The same applies to the composite type registration and object/binding calculation. Both steps will be shared with compilation units loaded from disk. Change-Id: I43636d7ac76077c76289d7c1c9eba5e9c6b8239a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp29
-rw-r--r--src/qml/compiler/qv4compileddata.cpp17
-rw-r--r--src/qml/compiler/qv4compileddata_p.h2
-rw-r--r--src/qml/qml/qqmltypeloader.cpp30
-rw-r--r--src/qml/qml/qqmltypeloader_p.h1
5 files changed, 48 insertions, 31 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index e40666864c..d73ce6f09d 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -47,7 +47,6 @@
#include <private/qv4ssa_p.h>
#include "qqmlpropertycachecreator_p.h"
-#include "qqmlpropertyvalidator_p.h"
#define COMPILE_EXCEPTION(token, desc) \
{ \
@@ -168,34 +167,6 @@ QV4::CompiledData::CompilationUnit *QQmlTypeCompiler::compile()
compilationUnit->propertyCaches = std::move(m_propertyCaches);
Q_ASSERT(compilationUnit->propertyCaches.count() == static_cast<int>(compilationUnit->data->nObjects));
- // Add to type registry of composites
- if (compilationUnit->propertyCaches.needsVMEMetaObject(qmlUnit->indexOfRootObject))
- engine->registerInternalCompositeType(compilationUnit);
- else {
- const QV4::CompiledData::Object *obj = qmlUnit->objectAt(qmlUnit->indexOfRootObject);
- auto *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex);
- Q_ASSERT(typeRef);
- if (typeRef->compilationUnit) {
- compilationUnit->metaTypeId = typeRef->compilationUnit->metaTypeId;
- compilationUnit->listMetaTypeId = typeRef->compilationUnit->listMetaTypeId;
- } else {
- compilationUnit->metaTypeId = typeRef->type->typeId();
- compilationUnit->listMetaTypeId = typeRef->type->qListTypeId();
- }
- }
-
- {
- // Sanity check property bindings
- QQmlPropertyValidator validator(engine, *imports(), compilationUnit);
- QVector<QQmlCompileError> errors = validator.validate();
- if (!errors.isEmpty()) {
- for (const QQmlCompileError &error: qAsConst(errors))
- recordError(error);
- return nullptr;
- }
- }
-
- compilationUnit->updateBindingAndObjectCounters();
if (errors.isEmpty())
return compilationUnit;
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index d2587a547c..b05abdc0c8 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -239,8 +239,23 @@ IdentifierHash<int> CompilationUnit::namedObjectsPerComponent(int componentObjec
return *it;
}
-void CompilationUnit::updateBindingAndObjectCounters()
+void CompilationUnit::finalize(QQmlEnginePrivate *engine)
{
+ // Add to type registry of composites
+ if (propertyCaches.needsVMEMetaObject(data->indexOfRootObject))
+ engine->registerInternalCompositeType(this);
+ else {
+ const QV4::CompiledData::Object *obj = objectAt(data->indexOfRootObject);
+ auto *typeRef = resolvedTypes.value(obj->inheritedTypeNameIndex);
+ Q_ASSERT(typeRef);
+ if (typeRef->compilationUnit) {
+ metaTypeId = typeRef->compilationUnit->metaTypeId;
+ listMetaTypeId = typeRef->compilationUnit->listMetaTypeId;
+ } else {
+ metaTypeId = typeRef->type->typeId();
+ listMetaTypeId = typeRef->type->qListTypeId();
+ }
+ }
// Collect some data for instantiation later.
int bindingCount = 0;
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index b960901402..a9a0ebbf51 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -766,7 +766,7 @@ struct Q_QML_PRIVATE_EXPORT CompilationUnit : public QQmlRefCount
QHash<int, IdentifierHash<int>> namedObjectsPerComponentCache;
IdentifierHash<int> namedObjectsPerComponent(int componentObjectIndex);
- void updateBindingAndObjectCounters();
+ void finalize(QQmlEnginePrivate *engine);
int totalBindingsCount; // Number of bindings used in this type
int totalParserStatusCount; // Number of instantiated types that are QQmlParserStatus subclasses
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 0ba0384c60..1158cde5ca 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -49,6 +49,7 @@
#include <private/qqmlprofiler_p.h>
#include <private/qqmlmemoryprofiler_p.h>
#include <private/qqmltypecompiler_p.h>
+#include <private/qqmlpropertyvalidator_p.h>
#include <QtCore/qdir.h>
#include <QtCore/qfile.h>
@@ -445,6 +446,21 @@ void QQmlDataBlob::setError(const QQmlCompileError &error)
setError(e);
}
+void QQmlDataBlob::setError(const QVector<QQmlCompileError> &errors)
+{
+ QList<QQmlError> finalErrors;
+ finalErrors.reserve(errors.count());
+ for (const QQmlCompileError &error: errors) {
+ QQmlError e;
+ e.setColumn(error.location.column);
+ e.setLine(error.location.line);
+ e.setDescription(error.description);
+ e.setUrl(url());
+ finalErrors << e;
+ }
+ setError(finalErrors);
+}
+
void QQmlDataBlob::setError(const QString &description)
{
QQmlError e;
@@ -2081,6 +2097,20 @@ void QQmlTypeData::done()
compile();
if (!isError()) {
+ QQmlEnginePrivate * const engine = QQmlEnginePrivate::get(typeLoader()->engine());
+ {
+ // Sanity check property bindings
+ QQmlPropertyValidator validator(engine, m_importCache, m_compiledData);
+ QVector<QQmlCompileError> errors = validator.validate();
+ if (!errors.isEmpty()) {
+ setError(errors);
+ }
+ }
+
+ m_compiledData->finalize(engine);
+ }
+
+ if (!isError()) {
QQmlType *type = QQmlMetaType::qmlType(finalUrl(), true);
if (m_compiledData && m_compiledData->data->flags & QV4::CompiledData::Unit::IsSingleton) {
if (!type) {
diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h
index 9fd7fb9f51..2030dbf427 100644
--- a/src/qml/qml/qqmltypeloader_p.h
+++ b/src/qml/qml/qqmltypeloader_p.h
@@ -146,6 +146,7 @@ protected:
void setError(const QQmlError &);
void setError(const QList<QQmlError> &errors);
void setError(const QQmlCompileError &error);
+ void setError(const QVector<QQmlCompileError> &errors);
void setError(const QString &description);
void addDependency(QQmlDataBlob *);