if (existing && existing->isValueBinding() == b->isValueBinding() && !(existing->flags & QV4::CompiledData::Binding::IsOnAssignment))
return tr("Property value set multiple times");
}
- if (isListBinding) {
- bindings->append(b);
- } else if (bindingToDefaultProperty) {
- Binding *insertionPoint = bindings->findSortedInsertionPoint<QV4::CompiledData::Location, QV4::CompiledData::Binding, &QV4::CompiledData::Binding::location>(b);
- bindings->insertAfter(insertionPoint, b);
- } else {
+ if (bindingToDefaultProperty)
+ insertSorted(b);
+ else
bindings->prepend(b);
- }
return QString(); // no error
}
return 0;
}
+void QmlObject::insertSorted(Binding *b)
+{
+ Binding *insertionPoint = bindings->findSortedInsertionPoint<QV4::CompiledData::Location, QV4::CompiledData::Binding, &QV4::CompiledData::Binding::valueLocation>(b);
+ bindings->insertAfter(insertionPoint, b);
+}
+
QStringList Signal::parameterStringList(const QStringList &stringPool) const
{
QStringList result;
return false;
}
+ QVarLengthArray<QQmlJS::AST::UiArrayMemberList *, 16> memberList;
QQmlJS::AST::UiArrayMemberList *member = node->members;
while (member) {
+ memberList.append(member);
+ member = member->next;
+ }
+ for (int i = memberList.count() - 1; i >= 0; --i) {
+ member = memberList.at(i);
QQmlJS::AST::UiObjectDefinition *def = QQmlJS::AST::cast<QQmlJS::AST::UiObjectDefinition*>(member->member);
int idx = 0;
if (!defineQMLObject(&idx, def))
return false;
appendBinding(qualifiedNameLocation, name->identifierToken, propertyNameIndex, idx, /*isListItem*/ true);
-
- member = member->next;
}
qSwap(_object, object);
}
}
+ T *unlink(T *before, T *item) {
+ T * const newNext = item->next;
+
+ if (before)
+ before->next = newNext;
+ else
+ first = newNext;
+
+ if (item == last) {
+ if (newNext)
+ last = newNext;
+ else
+ last = first;
+ }
+
+ --count;
+ return newNext;
+ }
+
T *slowAt(int index) const
{
T *result = first;
QString appendBinding(Binding *b, bool isListBinding);
Binding *findBinding(quint32 nameIndex) const;
+ Binding *unlinkBinding(Binding *before, Binding *binding) { return bindings->unlink(before, binding); }
+ void insertSorted(Binding *b);
PoolList<CompiledFunctionOrExpression> *functionsAndExpressions;
FixedPoolArray<int> *runtimeFunctionIndices;
}
{
+ QQmlDefaultPropertyMerger merger(this);
+ merger.mergeDefaultProperties();
+ }
+
+ {
SignalHandlerConverter converter(this);
if (!converter.convertSignalHandlerExpressionsToFunctionDeclarations())
return false;
return true;
}
+QQmlDefaultPropertyMerger::QQmlDefaultPropertyMerger(QQmlTypeCompiler *typeCompiler)
+ : QQmlCompilePass(typeCompiler)
+ , qmlObjects(*typeCompiler->qmlObjects())
+ , propertyCaches(typeCompiler->propertyCaches())
+{
+
+}
+
+void QQmlDefaultPropertyMerger::mergeDefaultProperties()
+{
+ for (int i = 0; i < qmlObjects.count(); ++i)
+ mergeDefaultProperties(i);
+}
+
+void QQmlDefaultPropertyMerger::mergeDefaultProperties(int objectIndex)
+{
+ QQmlPropertyCache *propertyCache = propertyCaches.at(objectIndex);
+ if (!propertyCache)
+ return;
+
+ QmlObject *object = qmlObjects.at(objectIndex);
+
+ QString defaultProperty = object->indexOfDefaultProperty != -1 ? propertyCache->parent()->defaultPropertyName() : propertyCache->defaultPropertyName();
+ Binding *bindingsToReinsert = 0;
+ Binding *tail = 0;
+
+ Binding *previousBinding = 0;
+ Binding *binding = object->firstBinding();
+ while (binding) {
+ if (binding->propertyNameIndex == 0 || stringAt(binding->propertyNameIndex) != defaultProperty) {
+ previousBinding = binding;
+ binding = binding->next;
+ continue;
+ }
+
+ Binding *toReinsert = binding;
+ binding = object->unlinkBinding(previousBinding, binding);
+
+ if (!tail) {
+ bindingsToReinsert = toReinsert;
+ tail = toReinsert;
+ } else {
+ tail->next = toReinsert;
+ tail = tail->next;
+ }
+ tail->next = 0;
+ }
+
+ binding = bindingsToReinsert;
+ while (binding) {
+ Binding *toReinsert = binding;
+ binding = binding->next;
+ object->insertSorted(toReinsert);
+ }
+}
+
QT_END_NAMESPACE
QtQml::JSCodeGen * const v4CodeGen;
};
+class QQmlDefaultPropertyMerger : public QQmlCompilePass
+{
+public:
+ QQmlDefaultPropertyMerger(QQmlTypeCompiler *typeCompiler);
+
+ void mergeDefaultProperties();
+
+private:
+ void mergeDefaultProperties(int objectIndex);
+
+ const QList<QtQml::QmlObject*> &qmlObjects;
+ const QVector<QQmlPropertyCache*> &propertyCaches;
+};
+
QT_END_NAMESPACE
#endif // QQMLTYPECOMPILER_P_H