aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-01-07 15:59:24 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-10 10:26:39 +0100
commitb681bd3e4ad20eb558da68ba1a2e2dfddfab9cf1 (patch)
treeb2ff2bdc1ec91fb332c405466e9a6e29d7d40c3c
parentc96a5432f9d34925c55753d592842a3bf7172cf2 (diff)
[new compiler] Cleanups
Tie QQmlCompilePass and QQmlTypeCompiler together, so that we can eliminate the battery of parameters to the individual compiler phases. Change-Id: If2b6cf8416e6c2253c8f054048d1fd5ae12282b6 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp73
-rw-r--r--src/qml/compiler/qqmltypecompiler_p.h42
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp80
-rw-r--r--src/qml/qml/qqmlobjectcreator_p.h44
-rw-r--r--src/qml/qml/qqmltypeloader.cpp2
5 files changed, 155 insertions, 86 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index 96b69d02e5..b5a48f3611 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -90,9 +90,7 @@ bool QQmlTypeCompiler::compile()
compiledData->datas.reserve(objectCount);
compiledData->propertyCaches.reserve(objectCount);
- QQmlPropertyCacheCreator propertyCacheBuilder(engine,
- parsedQML->jsGenerator.strings, compiledData->url,
- &typeData->imports(), &compiledData->resolvedTypes);
+ QQmlPropertyCacheCreator propertyCacheBuilder(this);
for (int i = 0; i < objectCount; ++i) {
const QtQml::QmlObject *obj = parsedQML->objects.at(i);
@@ -155,8 +153,7 @@ bool QQmlTypeCompiler::compile()
{
// Scan for components, determine their scopes and resolve aliases within the scope.
- QQmlComponentAndAliasResolver resolver(compiledData->url, parsedQML->jsGenerator.strings, parsedQML->objects, parsedQML->indexOfRootObject, compiledData->resolvedTypes, compiledData->propertyCaches,
- &compiledData->datas, &compiledData->objectIndexToIdForRoot, &compiledData->objectIndexToIdPerComponent);
+ QQmlComponentAndAliasResolver resolver(this);
if (!resolver.resolve()) {
errors << resolver.errors;
return false;
@@ -206,9 +203,7 @@ bool QQmlTypeCompiler::compile()
}
// Sanity check property bindings
- QQmlPropertyValidator validator(compiledData->url, compiledData->qmlUnit, compiledData->resolvedTypes,
- compiledData->propertyCaches, compiledData->objectIndexToIdPerComponent,
- &compiledData->customParserData);
+ QQmlPropertyValidator validator(this);
if (!validator.validate()) {
errors << validator.errors;
return false;
@@ -217,4 +212,66 @@ bool QQmlTypeCompiler::compile()
return errors.isEmpty();
}
+void QQmlTypeCompiler::recordError(const QQmlError &error)
+{
+ QQmlError e = error;
+ e.setUrl(compiledData->url);
+ errors << e;
+}
+
+QString QQmlTypeCompiler::stringAt(int idx) const
+{
+ return parsedQML->stringAt(idx);
+}
+
+const QV4::CompiledData::QmlUnit *QQmlTypeCompiler::qmlUnit() const
+{
+ return compiledData->qmlUnit;
+}
+
+const QQmlImports *QQmlTypeCompiler::imports() const
+{
+ return &typeData->imports();
+}
+
+QHash<int, QQmlCompiledData::TypeReference> *QQmlTypeCompiler::resolvedTypes()
+{
+ return &compiledData->resolvedTypes;
+}
+
+QList<QmlObject *> *QQmlTypeCompiler::qmlObjects()
+{
+ return &parsedQML->objects;
+}
+
+int QQmlTypeCompiler::rootObjectIndex() const
+{
+ return parsedQML->indexOfRootObject;
+}
+
+const QList<QQmlPropertyCache *> &QQmlTypeCompiler::propertyCaches() const
+{
+ return compiledData->propertyCaches;
+}
+
+QList<QByteArray> *QQmlTypeCompiler::vmeMetaObjects() const
+{
+ return &compiledData->datas;
+}
+
+QHash<int, int> *QQmlTypeCompiler::objectIndexToIdForRoot()
+{
+ return &compiledData->objectIndexToIdForRoot;
+}
+
+QHash<int, QHash<int, int> > *QQmlTypeCompiler::objectIndexToIdPerComponent()
+{
+ return &compiledData->objectIndexToIdPerComponent;
+}
+
+QHash<int, QByteArray> *QQmlTypeCompiler::customParserData()
+{
+ return &compiledData->customParserData;
+}
+
QT_END_NAMESPACE
diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h
index 9592e5d611..9ce8313d8d 100644
--- a/src/qml/compiler/qqmltypecompiler_p.h
+++ b/src/qml/compiler/qqmltypecompiler_p.h
@@ -43,6 +43,8 @@
#include <qglobal.h>
#include <qqmlerror.h>
+#include <qhash.h>
+#include <private/qqmlcompiler_p.h>
QT_BEGIN_NAMESPACE
@@ -50,26 +52,64 @@ class QQmlEnginePrivate;
class QQmlCompiledData;
class QQmlError;
class QQmlTypeData;
+class QQmlImports;
namespace QtQml {
struct ParsedQML;
}
+namespace QV4 {
+namespace CompiledData {
+struct QmlUnit;
+struct Location;
+}
+}
+
struct QQmlTypeCompiler
{
QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlCompiledData *compiledData, QQmlTypeData *typeData, QtQml::ParsedQML *parsedQML);
bool compile();
- QList<QQmlError> errors;
+ QList<QQmlError> compilationErrors() const { return errors; }
+ void recordError(const QQmlError &error);
+
+ QString stringAt(int idx) const;
+
+ const QV4::CompiledData::QmlUnit *qmlUnit() const;
+
+ QQmlEnginePrivate *enginePrivate() const { return engine; }
+ const QQmlImports *imports() const;
+ QHash<int, QQmlCompiledData::TypeReference> *resolvedTypes();
+ QList<QtQml::QmlObject*> *qmlObjects();
+ int rootObjectIndex() const;
+ const QList<QQmlPropertyCache *> &propertyCaches() const;
+ QList<QByteArray> *vmeMetaObjects() const;
+ QHash<int, int> *objectIndexToIdForRoot();
+ QHash<int, QHash<int, int> > *objectIndexToIdPerComponent();
+ QHash<int, QByteArray> *customParserData();
private:
+ QList<QQmlError> errors;
QQmlEnginePrivate *engine;
QQmlCompiledData *compiledData;
QQmlTypeData *typeData;
QtQml::ParsedQML *parsedQML;
};
+struct QQmlCompilePass
+{
+ QQmlCompilePass(QQmlTypeCompiler *typeCompiler);
+ QList<QQmlError> errors;
+
+ QString stringAt(int idx) const { return compiler->stringAt(idx); }
+protected:
+ void recordError(const QV4::CompiledData::Location &location, const QString &description);
+
+ const QUrl url;
+ QQmlTypeCompiler *compiler;
+};
+
QT_END_NAMESPACE
#endif // QQMLTYPECOMPILER_P_H
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 0c363b4dbb..1067a8dd0a 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -71,28 +71,18 @@ struct ActiveOCRestorer
};
}
-QQmlCompilePass::QQmlCompilePass(const QUrl &url, const QV4::CompiledData::QmlUnit *unit)
- : url(url)
- , jsUnit(&unit->header)
+QQmlCompilePass::QQmlCompilePass(QQmlTypeCompiler *typeCompiler)
+ : compiler(typeCompiler)
{
}
-QQmlCompilePass::QQmlCompilePass(const QUrl &url, const QStringList &stringTable)
- : url(url)
- , jsUnit(0)
- , stringTable(stringTable)
-{
-
-}
-
void QQmlCompilePass::recordError(const QV4::CompiledData::Location &location, const QString &description)
{
QQmlError error;
- error.setUrl(url);
error.setLine(location.line);
error.setColumn(location.column);
error.setDescription(description);
- errors << error;
+ compiler->recordError(error);
}
#define COMPILE_EXCEPTION(token, desc) \
@@ -103,12 +93,11 @@ void QQmlCompilePass::recordError(const QV4::CompiledData::Location &location, c
static QAtomicInt classIndexCounter(0);
-QQmlPropertyCacheCreator::QQmlPropertyCacheCreator(QQmlEnginePrivate *enginePrivate, const QStringList &stringTable, const QUrl &url, const QQmlImports *imports,
- QHash<int, QQmlCompiledData::TypeReference> *resolvedTypes)
- : QQmlCompilePass(url, stringTable)
- , enginePrivate(enginePrivate)
- , imports(imports)
- , resolvedTypes(resolvedTypes)
+QQmlPropertyCacheCreator::QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler)
+ : QQmlCompilePass(typeCompiler)
+ , enginePrivate(typeCompiler->enginePrivate())
+ , imports(typeCompiler->imports())
+ , resolvedTypes(typeCompiler->resolvedTypes())
{
}
@@ -477,8 +466,8 @@ static void removeBindingOnProperty(QObject *o, int index)
}
QmlObjectCreator::QmlObjectCreator(QQmlContextData *parentContext, QQmlCompiledData *compiledData)
- : QQmlCompilePass(compiledData->url, compiledData->qmlUnit)
- , componentAttached(0)
+ : componentAttached(0)
+ , url(compiledData->url)
, engine(parentContext->engine)
, qmlUnit(compiledData->qmlUnit)
, jsUnit(compiledData->compilationUnit)
@@ -1241,6 +1230,16 @@ void QmlObjectCreator::setupFunctions()
}
}
+void QmlObjectCreator::recordError(const QV4::CompiledData::Location &location, const QString &description)
+{
+ QQmlError error;
+ error.setUrl(url);
+ error.setLine(location.line);
+ error.setColumn(location.column);
+ error.setDescription(description);
+ errors << error;
+}
+
QObject *QmlObjectCreator::createInstance(int index, QObject *parent)
{
ActiveOCRestorer ocRestorer(this, QQmlEnginePrivate::get(engine));
@@ -1469,21 +1468,17 @@ bool QmlObjectCreator::populateInstance(int index, QObject *instance, QQmlRefPoi
}
-QQmlComponentAndAliasResolver::QQmlComponentAndAliasResolver(const QUrl &url, const QStringList &stringTable, const QList<QmlObject *> &qmlObjects, int indexOfRootObject,
- const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes,
- const QList<QQmlPropertyCache *> &propertyCaches, QList<QByteArray> *vmeMetaObjectData,
- QHash<int, int> *objectIndexToIdForRoot,
- QHash<int, QHash<int, int> > *objectIndexToIdPerComponent)
- : QQmlCompilePass(url, stringTable)
- , qmlObjects(qmlObjects)
- , indexOfRootObject(indexOfRootObject)
+QQmlComponentAndAliasResolver::QQmlComponentAndAliasResolver(QQmlTypeCompiler *typeCompiler)
+ : QQmlCompilePass(typeCompiler)
+ , qmlObjects(*typeCompiler->qmlObjects())
+ , indexOfRootObject(typeCompiler->rootObjectIndex())
, _componentIndex(-1)
, _objectIndexToIdInScope(0)
- , resolvedTypes(resolvedTypes)
- , propertyCaches(propertyCaches)
- , vmeMetaObjectData(vmeMetaObjectData)
- , objectIndexToIdForRoot(objectIndexToIdForRoot)
- , objectIndexToIdPerComponent(objectIndexToIdPerComponent)
+ , resolvedTypes(*typeCompiler->resolvedTypes())
+ , propertyCaches(typeCompiler->propertyCaches())
+ , vmeMetaObjectData(typeCompiler->vmeMetaObjects())
+ , objectIndexToIdForRoot(typeCompiler->objectIndexToIdForRoot())
+ , objectIndexToIdPerComponent(typeCompiler->objectIndexToIdPerComponent())
{
}
@@ -1745,16 +1740,13 @@ bool QQmlComponentAndAliasResolver::resolveAliases()
}
-QQmlPropertyValidator::QQmlPropertyValidator(const QUrl &url, const QV4::CompiledData::QmlUnit *qmlUnit,
- const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes,
- const QList<QQmlPropertyCache *> &propertyCaches, const QHash<int, QHash<int, int> > &objectIndexToIdPerComponent,
- QHash<int, QByteArray> *customParserData)
- : QQmlCompilePass(url, qmlUnit)
- , qmlUnit(qmlUnit)
- , resolvedTypes(resolvedTypes)
- , propertyCaches(propertyCaches)
- , objectIndexToIdPerComponent(objectIndexToIdPerComponent)
- , customParserData(customParserData)
+QQmlPropertyValidator::QQmlPropertyValidator(QQmlTypeCompiler *typeCompiler)
+ : QQmlCompilePass(typeCompiler)
+ , qmlUnit(typeCompiler->qmlUnit())
+ , resolvedTypes(*typeCompiler->resolvedTypes())
+ , propertyCaches(typeCompiler->propertyCaches())
+ , objectIndexToIdPerComponent(*typeCompiler->objectIndexToIdPerComponent())
+ , customParserData(typeCompiler->customParserData())
{
}
diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h
index 796d92a1e6..92f40648d3 100644
--- a/src/qml/qml/qqmlobjectcreator_p.h
+++ b/src/qml/qml/qqmlobjectcreator_p.h
@@ -45,34 +45,19 @@
#include <private/qqmltypenamecache_p.h>
#include <private/qv4compileddata_p.h>
#include <private/qqmlcompiler_p.h>
+#include <private/qqmltypecompiler_p.h>
#include <QLinkedList>
QT_BEGIN_NAMESPACE
class QQmlAbstractBinding;
-
-struct QQmlCompilePass
-{
- QQmlCompilePass(const QUrl &url, const QV4::CompiledData::QmlUnit *unit);
- QQmlCompilePass(const QUrl &url, const QStringList &stringTable);
- QList<QQmlError> errors;
-
- QString stringAt(int idx) const { return jsUnit ? jsUnit->stringAt(idx): stringTable.at(idx); }
-protected:
- void recordError(const QV4::CompiledData::Location &location, const QString &description);
-
- const QUrl url;
- const QV4::CompiledData::Unit *jsUnit;
- const QStringList stringTable;
-};
+struct QQmlTypeCompiler;
class QQmlPropertyCacheCreator : public QQmlCompilePass
{
Q_DECLARE_TR_FUNCTIONS(QQmlPropertyCacheCreator)
public:
- QQmlPropertyCacheCreator(QQmlEnginePrivate *enginePrivate, const QStringList &stringTable,
- const QUrl &url, const QQmlImports *imports,
- QHash<int, QQmlCompiledData::TypeReference> *resolvedTypes);
+ QQmlPropertyCacheCreator(QQmlTypeCompiler *typeCompiler);
bool create(const QtQml::QmlObject *obj, QQmlPropertyCache **cache, QByteArray *vmeMetaObjectData);
@@ -86,14 +71,7 @@ class QQmlComponentAndAliasResolver : public QQmlCompilePass
{
Q_DECLARE_TR_FUNCTIONS(QQmlAnonymousComponentResolver)
public:
- QQmlComponentAndAliasResolver(const QUrl &url, const QStringList &stringTable,
- const QList<QtQml::QmlObject*> &qmlObjects,
- int indexOfRootObject,
- const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes,
- const QList<QQmlPropertyCache *> &propertyCaches,
- QList<QByteArray> *vmeMetaObjectData,
- QHash<int, int> *objectIndexToIdForRoot,
- QHash<int, QHash<int, int> > *objectIndexToIdPerComponent);
+ QQmlComponentAndAliasResolver(QQmlTypeCompiler *typeCompiler);
bool resolve();
@@ -126,11 +104,7 @@ class QQmlPropertyValidator : public QQmlCompilePass
{
Q_DECLARE_TR_FUNCTIONS(QQmlPropertyValidator)
public:
- QQmlPropertyValidator(const QUrl &url, const QV4::CompiledData::QmlUnit *qmlUnit,
- const QHash<int, QQmlCompiledData::TypeReference> &resolvedTypes,
- const QList<QQmlPropertyCache *> &propertyCaches,
- const QHash<int, QHash<int, int> > &objectIndexToIdPerComponent,
- QHash<int, QByteArray> *customParserData);
+ QQmlPropertyValidator(QQmlTypeCompiler *typeCompiler);
bool validate();
@@ -146,7 +120,7 @@ private:
QHash<int, QByteArray> *customParserData;
};
-class QmlObjectCreator : public QQmlCompilePass
+class QmlObjectCreator
{
Q_DECLARE_TR_FUNCTIONS(QmlObjectCreator)
public:
@@ -158,6 +132,8 @@ public:
QQmlComponentAttached *componentAttached;
QList<QQmlEnginePrivate::FinalizeCallback> finalizeCallbacks;
+ QList<QQmlError> errors;
+
private:
QObject *createInstance(int index, QObject *parent = 0);
@@ -169,6 +145,10 @@ private:
void setPropertyValue(QQmlPropertyData *property, const QV4::CompiledData::Binding *binding);
void setupFunctions();
+ QString stringAt(int idx) const { return qmlUnit->header.stringAt(idx); }
+ void recordError(const QV4::CompiledData::Location &location, const QString &description);
+
+ QUrl url;
QQmlEngine *engine;
const QV4::CompiledData::QmlUnit *qmlUnit;
const QV4::CompiledData::CompilationUnit *jsUnit;
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 9e23b0b1a5..278bb017d0 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -2309,7 +2309,7 @@ void QQmlTypeData::compile()
if (m_useNewCompiler) {
QQmlTypeCompiler compiler(QQmlEnginePrivate::get(typeLoader()->engine()), m_compiledData, this, parsedQML.data());
if (!compiler.compile()) {
- setError(compiler.errors);
+ setError(compiler.compilationErrors());
m_compiledData->release();
m_compiledData = 0;
}