diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-01-07 15:35:20 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-10 10:26:43 +0100 |
commit | 5c40193f8223a8bdefcf694c719396807a83f0ea (patch) | |
tree | 626991eb96b9da976cf0ebe6c944012e81effe0b /src/qml/compiler | |
parent | b681bd3e4ad20eb558da68ba1a2e2dfddfab9cf1 (diff) |
[new compiler] Add support for implicitly defined components
Use-cases like
itemDelegate: Item { ... }
implicitly define a component without the item-surrounding Component {}, base
on the fact that the property itself is of type QQmlComponent (or derived).
This means we have to synthesize a Component {} object and insert it into
the data structure.
Change-Id: I8992451a5a6732c7fd898eaf83c276dc6a8b7d19
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 27 | ||||
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator_p.h | 4 | ||||
-rw-r--r-- | src/qml/compiler/qqmltypecompiler.cpp | 10 | ||||
-rw-r--r-- | src/qml/compiler/qqmltypecompiler_p.h | 2 |
4 files changed, 31 insertions, 12 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index a4da07ab66..f0dfc9b7ea 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -64,6 +64,21 @@ using namespace QtQml; return false; \ } +void QmlObject::init(MemoryPool *pool, int typeNameIndex, int id, const AST::SourceLocation &loc) +{ + inheritedTypeNameIndex = typeNameIndex; + + location.line = loc.startLine; + location.column = loc.startColumn; + + idIndex = id; + indexOfDefaultProperty = -1; + properties = pool->New<PoolList<QmlProperty> >(); + qmlSignals = pool->New<PoolList<Signal> >(); + bindings = pool->New<PoolList<Binding> >(); + functions = pool->New<PoolList<Function> >(); +} + void QmlObject::dump(DebugStream &out) { out << inheritedTypeNameIndex << " {" << endl; @@ -306,20 +321,10 @@ int QQmlCodeGenerator::defineQMLObject(AST::UiQualifiedId *qualifiedTypeNameId, const int objectIndex = _objects.size() - 1; qSwap(_object, obj); - _object->inheritedTypeNameIndex = registerString(asString(qualifiedTypeNameId)); - AST::SourceLocation loc; if (qualifiedTypeNameId) loc = qualifiedTypeNameId->firstSourceLocation(); - _object->location.line = loc.startLine; - _object->location.column = loc.startColumn; - - _object->idIndex = emptyStringIndex; - _object->indexOfDefaultProperty = -1; - _object->properties = New<PoolList<QmlProperty> >(); - _object->qmlSignals = New<PoolList<Signal> >(); - _object->bindings = New<PoolList<Binding> >(); - _object->functions = New<PoolList<Function> >(); + _object->init(pool, registerString(asString(qualifiedTypeNameId)), emptyStringIndex, loc); QSet<QString> propertyNames; qSwap(_propertyNames, propertyNames); diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 18193eea2b..4b126ef5ea 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -155,6 +155,8 @@ struct QmlObject PoolList<Binding> *bindings; PoolList<Function> *functions; + void init(QQmlJS::MemoryPool *pool, int typeNameIndex, int id, const AST::SourceLocation &location = AST::SourceLocation()); + void dump(DebugStream &out); }; @@ -274,7 +276,7 @@ public: static QQmlScript::LocationSpan location(AST::SourceLocation start, AST::SourceLocation end); int registerString(const QString &str) const { return jsGenerator->registerString(str); } - template <typename _Tp> _Tp *New() { return new (pool->allocate(sizeof(_Tp))) _Tp(); } + template <typename _Tp> _Tp *New() { return pool->New<_Tp>(); } QString stringAt(int index) const { return jsGenerator->strings.at(index); } diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index b5a48f3611..f39ea2f3c7 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -224,6 +224,11 @@ QString QQmlTypeCompiler::stringAt(int idx) const return parsedQML->stringAt(idx); } +int QQmlTypeCompiler::registerString(const QString &str) +{ + return parsedQML->jsGenerator.registerString(str); +} + const QV4::CompiledData::QmlUnit *QQmlTypeCompiler::qmlUnit() const { return compiledData->qmlUnit; @@ -274,4 +279,9 @@ QHash<int, QByteArray> *QQmlTypeCompiler::customParserData() return &compiledData->customParserData; } +MemoryPool *QQmlTypeCompiler::memoryPool() +{ + return parsedQML->jsParserEngine.pool(); +} + QT_END_NAMESPACE diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h index 9ce8313d8d..442911093c 100644 --- a/src/qml/compiler/qqmltypecompiler_p.h +++ b/src/qml/compiler/qqmltypecompiler_p.h @@ -75,6 +75,7 @@ struct QQmlTypeCompiler void recordError(const QQmlError &error); QString stringAt(int idx) const; + int registerString(const QString &str); const QV4::CompiledData::QmlUnit *qmlUnit() const; @@ -88,6 +89,7 @@ struct QQmlTypeCompiler QHash<int, int> *objectIndexToIdForRoot(); QHash<int, QHash<int, int> > *objectIndexToIdPerComponent(); QHash<int, QByteArray> *customParserData(); + QQmlJS::MemoryPool *memoryPool(); private: QList<QQmlError> errors; |