7#include <private/qqmlobjectcreator_p.h>
8#include <private/qqmlcustomparser_p.h>
9#include <private/qqmlvmemetaobject_p.h>
10#include <private/qqmlcomponent_p.h>
11#include <private/qqmlpropertyresolver_p.h>
12#include <private/qqmlcomponentandaliasresolver_p.h>
13#include <private/qqmlsignalnames_p.h>
15#include <QtCore/qtyperevision.h>
17#define COMPILE_EXCEPTION(token, desc)
19 recordError((token)->location, desc);
25DEFINE_BOOL_CONFIG_OPTION(
26 disableInternalDeferredProperties, QML_DISABLE_INTERNAL_DEFERRED_PROPERTIES);
31 QQmlTypeLoader *typeLoader, QQmlTypeData *typeData,
QmlIR::Document *parsedQML,
32 QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache,
33 const QV4::CompiledData::DependentTypesHasher &dependencyHasher)
34 : resolvedTypes(resolvedTypeCache)
36 , dependencyHasher(dependencyHasher)
46 for (
auto it = resolvedTypes->constBegin(), end = resolvedTypes->constEnd();
48 QQmlCustomParser *customParser = (*it)->type().customParser();
50 customParsers.insert(it.key(), customParser);
53 QQmlPendingGroupPropertyBindings pendingGroupPropertyBindings;
57 QQmlPropertyCacheCreator<QQmlTypeCompiler> propertyCacheBuilder(
58 &m_propertyCaches, &pendingGroupPropertyBindings,
59 loader,
this, imports(), typeData->typeClassName());
60 QQmlError cycleError = propertyCacheBuilder.verifyNoICCycle();
61 if (cycleError.isValid()) {
65 QQmlPropertyCacheCreatorBase::IncrementalResult result;
67 result = propertyCacheBuilder.buildMetaObjectsIncrementally();
68 const QQmlError &error = result.error;
69 if (error.isValid()) {
75 QQmlComponentAndAliasResolver resolver(
this, &m_propertyCaches);
76 if (QQmlError error = resolver.resolve(result.processedRoot); error.isValid()) {
80 pendingGroupPropertyBindings.resolveMissingPropertyCaches(&m_propertyCaches);
81 pendingGroupPropertyBindings.clear();
83 }
while (result.canResume);
114 if (!document->javaScriptCompilationUnit || !document->javaScriptCompilationUnit->unitData()) {
123 Q_ASSERT(document->jsModule.fileName == typeData->urlString());
124 Q_ASSERT(document->jsModule.finalUrl == typeData->finalUrlString());
125 QmlIR::JSCodeGen v4CodeGenerator(document);
126 for (QmlIR::Object *object : std::as_const(document->objects)) {
127 if (!v4CodeGenerator.generateRuntimeFunctions(object)) {
128 Q_ASSERT(v4CodeGenerator.hasError());
129 recordError(v4CodeGenerator.error());
133 document->javaScriptCompilationUnit = v4CodeGenerator.generateCompilationUnit(
false);
138 QmlIR::QmlUnitGenerator qmlGenerator;
139 qmlGenerator.generate(*document, dependencyHasher);
141 if (!errors.isEmpty())
144 return std::move(document->javaScriptCompilationUnit);
150 error.setLine(qmlConvertSourceCoordinate<quint32,
int>(location.line()));
151 error.setColumn(qmlConvertSourceCoordinate<quint32,
int>(location.column()));
152 error.setDescription(description);
160 error.setDescription(message.message);
161 error.setLine(qmlConvertSourceCoordinate<quint32,
int>(message.loc.startLine));
162 error.setColumn(qmlConvertSourceCoordinate<quint32,
int>(message.loc.startColumn));
176 return document->stringAt(idx);
181 return document->jsGenerator.registerString(str);
188 const auto *p = m_propertyCaches.at(index)->defaultProperty();
189 Q_ASSERT(p && p->isComponentWrapper());
190 return p->wrappedObjectIndex();
195 for (
int i =
objectCount(), end = m_propertyCaches.count(); i < end; ++i) {
196 const auto *p = m_propertyCaches.at(i)->defaultProperty();
197 Q_ASSERT(p && p->isComponentWrapper());
198 if (p->wrappedObjectIndex() == childIndex)
206 return document->jsGenerator.registerConstant(v);
211 return document->javaScriptCompilationUnit->unitData();
216 return typeData->imports();
221 return &document->objects;
226 return &m_propertyCaches;
231 return &m_propertyCaches;
236 return document->jsParserEngine.pool();
241 return document->jsParserEngine.newStringRef(string);
246 return &document->jsGenerator.stringTable;
251 return object->bindingAsString(document, scriptIndex);
256 const quint32 moduleIdx = registerString(module);
257 const quint32 qualifierIdx = registerString(qualifier);
259 for (
int i = 0, count = document->imports.size(); i < count; ++i) {
260 const QV4::CompiledData::Import *existingImport = document->imports.at(i);
261 if (existingImport->type == QV4::CompiledData::Import::ImportLibrary
262 && existingImport->uriIndex == moduleIdx
263 && existingImport->qualifierIndex == qualifierIdx)
266 auto pool = memoryPool();
267 QV4::CompiledData::Import *import = pool->New<QV4::CompiledData::Import>();
268 import->type = QV4::CompiledData::Import::ImportLibrary;
269 import->version = version;
270 import->uriIndex = moduleIdx;
271 import->qualifierIndex = qualifierIdx;
272 document->imports.append(import);
277 return typeData->qmlType(inlineComponentName);
287 , typeLoader(typeCompiler->typeLoader())
288 , qmlObjects(*typeCompiler->qmlObjects())
290 , customParsers(typeCompiler->customParserCache())
291 , propertyCaches(typeCompiler->propertyCaches())
297 for (
int objectIndex = 0; objectIndex < qmlObjects.size(); ++objectIndex) {
298 const QmlIR::Object *
const obj = qmlObjects.at(objectIndex);
299 QQmlPropertyCache::ConstPtr cache = propertyCaches->at(objectIndex);
302 if (QQmlCustomParser *customParser = customParsers.value(obj->inheritedTypeNameIndex)) {
303 if (!(customParser->flags() & QQmlCustomParser::AcceptsSignalHandlers))
306 const QString elementName = stringAt(obj->inheritedTypeNameIndex);
314 const QmlIR::Object *obj,
const QString &typeName,
315 const QQmlPropertyCache::ConstPtr &propertyCache,
316 QQmlPropertyResolver::RevisionCheck checkRevision)
319 QHash<QString, QStringList> customSignals;
321 for (QmlIR::Binding *binding = obj->firstBinding(); binding; binding = binding->next) {
322 const QString bindingPropertyName = stringAt(binding->propertyNameIndex);
324 const QV4::CompiledData::Binding::Type bindingType = binding->type();
325 if (bindingType == QV4::CompiledData::Binding::Type_AttachedProperty) {
326 const QmlIR::Object *attachedObj = qmlObjects.at(binding->value.objectIndex);
327 auto *typeRef = resolvedType(binding->propertyNameIndex);
328 QQmlType type = typeRef ? typeRef->type() : QQmlType();
330 imports->resolveType(typeLoader, bindingPropertyName, &type,
nullptr,
nullptr);
332 const QMetaObject *attachedType = type.attachedPropertiesType(typeLoader);
335 QQmlPropertyCache::ConstPtr cache = QQmlMetaType::propertyCache(attachedType);
339 attachedObj, bindingPropertyName, cache,
340 QQmlPropertyResolver::IgnoreRevision)) {
347 QString qPropertyName;
349 if (
auto propertyName =
350 QQmlSignalNames::changedHandlerNameToPropertyName(bindingPropertyName)) {
351 qPropertyName = *propertyName;
352 signalName = *QQmlSignalNames::changedHandlerNameToSignalName(bindingPropertyName);
354 signalName = QQmlSignalNames::handlerNameToSignalName(bindingPropertyName)
355 .value_or(QString());
357 if (signalName.isEmpty())
360 QQmlPropertyResolver resolver(propertyCache);
362 bool notInRevision =
false;
363 const QQmlPropertyData *
const signal
364 = resolver.signal(signalName, ¬InRevision, checkRevision);
365 const QQmlPropertyData *
const signalPropertyData
366 = resolver.property(signalName,
nullptr, checkRevision);
367 const QQmlPropertyData *
const qPropertyData = !qPropertyName.isEmpty()
368 ? resolver.property(qPropertyName,
nullptr, checkRevision)
370 QString finalSignalHandlerPropertyName = signalName;
371 QV4::CompiledData::Binding::Flag flag
372 = QV4::CompiledData::Binding::IsSignalHandlerExpression;
374 const bool isPropertyObserver
375 = !signalPropertyData && qPropertyData && qPropertyData->notifiesViaBindable();
376 if (signal && !(qPropertyData && qPropertyData->isAlias() && isPropertyObserver)) {
377 int sigIndex = propertyCache->methodIndexToSignalIndex(signal->coreIndex());
378 sigIndex = propertyCache->originalClone(sigIndex);
380 bool unnamedParameter =
false;
382 QList<QByteArray> parameterNames = propertyCache->signalParameterNames(sigIndex);
383 for (
int i = 0; i < parameterNames.size(); ++i) {
384 const QString param = QString::fromUtf8(parameterNames.at(i));
386 unnamedParameter =
true;
387 else if (unnamedParameter) {
388 COMPILE_EXCEPTION(binding, tr(
"Signal uses unnamed parameter followed by named parameter."));
389 }
else if (QV4::Compiler::Codegen::isNameGlobal(param)) {
390 COMPILE_EXCEPTION(binding, tr(
"Signal parameter \"%1\" hides global variable.").arg(param));
393 }
else if (isPropertyObserver) {
394 finalSignalHandlerPropertyName = qPropertyName;
395 flag = QV4::CompiledData::Binding::IsPropertyObserver;
399 if (signalPropertyData)
402 const QString &originalPropertyName = stringAt(binding->propertyNameIndex);
404 auto *typeRef = resolvedType(obj->inheritedTypeNameIndex);
405 const QQmlType type = typeRef ? typeRef->type() : QQmlType();
406 if (type.isValid()) {
408 .arg(typeName, originalPropertyName, type.module())
409 .arg(type.version().majorVersion())
410 .arg(type.version().minorVersion()));
414 tr(
"\"%1.%2\" is not available due to component versioning.")
415 .arg(typeName, originalPropertyName));
422 if (customSignals.isEmpty()) {
423 for (
const QmlIR::Signal *signal = obj->firstSignal(); signal; signal = signal->next) {
424 const QString &signalName = stringAt(signal->nameIndex);
425 customSignals.insert(signalName, signal->parameterStringList(compiler->stringPool()));
428 for (
const QmlIR::Property *property = obj->firstProperty(); property; property = property->next) {
429 const QString propName = stringAt(property->nameIndex());
430 customSignals.insert(propName, QStringList());
434 QHash<QString, QStringList>::ConstIterator entry = customSignals.constFind(signalName);
435 if (entry == customSignals.constEnd() && !qPropertyName.isEmpty())
436 entry = customSignals.constFind(qPropertyName);
438 if (entry == customSignals.constEnd()) {
446 if (bindingType == QV4::CompiledData::Binding::Type_Object) {
447 binding->setFlag(QV4::CompiledData::Binding::IsSignalHandlerObject);
451 if (bindingType != QV4::CompiledData::Binding::Type_Script) {
452 if (bindingType < QV4::CompiledData::Binding::Type_Script) {
453 COMPILE_EXCEPTION(binding, tr(
"Cannot assign a value to a signal (expecting a script to be run)"));
459 binding->propertyNameIndex = compiler->registerString(finalSignalHandlerPropertyName);
460 binding->setFlag(flag);
467 , qmlObjects(*typeCompiler->qmlObjects())
468 , propertyCaches(typeCompiler->propertyCaches())
475 for (
int i = 0; i < qmlObjects.size(); ++i) {
476 QQmlPropertyCache::ConstPtr propertyCache = propertyCaches->at(i);
479 const QmlIR::Object *obj = qmlObjects.at(i);
481 QQmlPropertyResolver resolver(propertyCache);
483 for (QmlIR::Binding *binding = obj->firstBinding(); binding; binding = binding->next) {
484 const QV4::CompiledData::Binding::Flags bindingFlags = binding->flags();
485 if (bindingFlags & QV4::CompiledData::Binding::IsSignalHandlerExpression
486 || bindingFlags & QV4::CompiledData::Binding::IsSignalHandlerObject
487 || bindingFlags & QV4::CompiledData::Binding::IsPropertyObserver)
490 if (binding->type() != QV4::CompiledData::Binding::Type_Script)
493 const QString propertyName = stringAt(binding->propertyNameIndex);
494 bool notInRevision =
false;
495 const QQmlPropertyData *pd = resolver.property(propertyName, ¬InRevision);
496 if (!pd || pd->isQList())
499 if (!pd->isEnum() && pd->propType().id() != QMetaType::Int)
502 if (!tryQualifiedEnumAssignment(obj, propertyCache, pd, binding))
510bool QQmlEnumTypeResolver::assignEnumToBinding(QmlIR::Binding *binding, QStringView,
int enumValue)
512 binding->setType(QV4::CompiledData::Binding::Type_Number);
517 binding->value.resolvedEnumValue = enumValue;
518 binding->setFlag(QV4::CompiledData::Binding::IsResolvedEnum);
523 const QmlIR::Object *obj,
const QQmlPropertyCache::ConstPtr &propertyCache,
524 const QQmlPropertyData *prop, QmlIR::Binding *binding)
526 bool isIntProp = (prop->propType().id() == QMetaType::Int) && !prop->isEnum();
527 if (!prop->isEnum() && !isIntProp)
530 if (!prop->isWritable()
531 && !(binding->hasFlag(QV4::CompiledData::Binding::InitializerForReadOnlyDeclaration))) {
532 COMPILE_EXCEPTION(binding, tr(
"Invalid property assignment: \"%1\" is a read-only property")
533 .arg(stringAt(binding->propertyNameIndex)));
536 Q_ASSERT(binding->type() == QV4::CompiledData::Binding::Type_Script);
537 const QString string = compiler->bindingAsString(obj, binding->value.compiledScriptIndex);
538 const int dot = QmlIR::qualifiedEnumDot(string);
542 int dot2 = string.indexOf(QLatin1Char(
'.'), dot+1);
543 if (dot2 != -1 && dot2 != string.size()-1) {
544 if (!string.at(dot+1).isUpper())
546 if (string.indexOf(QLatin1Char(
'.'), dot2+1) != -1)
550 QHashedStringRef typeName(string.constData(), dot);
551 const bool isQtObject = (typeName == QLatin1String(
"Qt"));
552 const QStringView scopedEnumName = (dot2 != -1 ? QStringView{string}.mid(dot + 1, dot2 - dot - 1) : QStringView());
554 const QStringView enumValue = QStringView{string}.mid(!isQtObject && dot2 != -1 ? dot2 + 1 : dot + 1);
559 int enumval = evaluateEnum(typeName.toString(), scopedEnumName, enumValue, &ok);
561 if (!assignEnumToBinding(binding, enumValue, enumval))
567 imports->resolveType(compiler->typeLoader(), typeName, &type,
nullptr,
nullptr);
569 if (!type.isValid() && !isQtObject)
575 auto *tr = resolvedType(obj->inheritedTypeNameIndex);
578 bool useFastPath = type.isValid() && tr && tr->type() == type;
582 mprop = propertyCache->firstCppMetaObject()->property(prop->coreIndex());
583 menum = mprop.enumerator();
586 if (!menum.isScoped() && scopedEnumName.isEmpty() && typeName != QString::fromUtf8(menum.scope()))
587 useFastPath =
false;;
590 QByteArray enumName = enumValue.toUtf8();
591 if (menum.isScoped() && !scopedEnumName.isEmpty() && enumName != scopedEnumName.toUtf8())
594 if (mprop.isFlagType()) {
595 value = menum.keysToValue(enumName.constData(), &ok);
597 value = menum.keyToValue(enumName.constData(), &ok);
601 if (type.isValid()) {
602 if (!scopedEnumName.isEmpty()) {
603 value = type.scopedEnumValue(
604 compiler->typeLoader(), scopedEnumName, enumValue, &ok);
606 value = type.enumValue(compiler->typeLoader(), QHashedStringRef(enumValue), &ok);
609 QByteArray enumName = enumValue.toUtf8();
610 const QMetaObject *metaObject = &Qt::staticMetaObject;
611 for (
int ii = metaObject->enumeratorCount() - 1; !ok && ii >= 0; --ii) {
612 QMetaEnum e = metaObject->enumerator(ii);
613 value = e.keyToValue(enumName.constData(), &ok);
621 return assignEnumToBinding(binding, enumValue, value);
624int QQmlEnumTypeResolver::evaluateEnum(
const QString &scope, QStringView enumName, QStringView enumValue,
bool *ok)
const
626 Q_ASSERT_X(ok,
"QQmlEnumTypeResolver::evaluateEnum",
"ok must not be a null pointer");
629 if (scope != QLatin1String(
"Qt")) {
631 imports->resolveType(compiler->typeLoader(), scope, &type,
nullptr,
nullptr);
634 if (!enumName.isEmpty())
635 return type.scopedEnumValue(compiler->typeLoader(), enumName, enumValue, ok);
636 return type.enumValue(
637 compiler->typeLoader(),
638 QHashedStringRef(enumValue.constData(), enumValue.size()), ok);
641 const QMetaObject *mo = &Qt::staticMetaObject;
642 int i = mo->enumeratorCount();
643 const QByteArray ba = enumValue.toUtf8();
645 int v = mo->enumerator(i).keyToValue(ba.constData(), ok);
661 scanObjectRecursively(0);
662 for (
int i = 0; i < qmlObjects.size(); ++i)
663 if (qmlObjects.at(i)->flags & QV4::CompiledData::Object::IsInlineComponentRoot)
664 scanObjectRecursively(i);
669 const QmlIR::Object *
const obj = qmlObjects.at(objectIndex);
670 if (!annotateScriptBindings)
671 annotateScriptBindings = customParsers.contains(obj->inheritedTypeNameIndex);
672 for (QmlIR::Binding *binding = obj->firstBinding(); binding; binding = binding->next) {
673 switch (binding->type()) {
674 case QV4::CompiledData::Binding::Type_Script:
675 if (annotateScriptBindings) {
676 binding->stringIndex = compiler->registerString(
677 compiler->bindingAsString(obj, binding->value.compiledScriptIndex));
680 case QV4::CompiledData::Binding::Type_Object:
681 case QV4::CompiledData::Binding::Type_AttachedProperty:
682 case QV4::CompiledData::Binding::Type_GroupProperty:
683 scanObjectRecursively(binding->value.objectIndex, annotateScriptBindings);
700 for (
int i = 0; i < qmlObjects.size(); ++i) {
701 QQmlPropertyCache::ConstPtr propertyCache = propertyCaches->at(i);
705 const QmlIR::Object *obj = qmlObjects.at(i);
707 QQmlPropertyResolver resolver(propertyCache);
708 const QQmlPropertyData *defaultProperty = obj->indexOfDefaultPropertyOrAlias != -1 ? propertyCache->parent()->defaultProperty() : propertyCache->defaultProperty();
710 for (QmlIR::Binding *binding = obj->firstBinding(); binding; binding = binding->next) {
711 if (!binding->isValueBinding())
713 bool notInRevision =
false;
714 const QQmlPropertyData *pd = binding->propertyNameIndex != quint32(0) ? resolver.property(stringAt(binding->propertyNameIndex), ¬InRevision) : defaultProperty;
715 if (pd && pd->isAlias())
716 binding->setFlag(QV4::CompiledData::Binding::IsBindingToAlias);
731 const QMetaType scriptStringMetaType = QMetaType::fromType<QQmlScriptString>();
732 for (
int i = 0; i < qmlObjects.size(); ++i) {
733 QQmlPropertyCache::ConstPtr propertyCache = propertyCaches->at(i);
737 const QmlIR::Object *obj = qmlObjects.at(i);
739 QQmlPropertyResolver resolver(propertyCache);
740 const QQmlPropertyData *defaultProperty = obj->indexOfDefaultPropertyOrAlias != -1 ? propertyCache->parent()->defaultProperty() : propertyCache->defaultProperty();
742 for (QmlIR::Binding *binding = obj->firstBinding(); binding; binding = binding->next) {
743 if (binding->type() != QV4::CompiledData::Binding::Type_Script)
745 bool notInRevision =
false;
746 const QQmlPropertyData *pd = binding->propertyNameIndex != quint32(0) ? resolver.property(stringAt(binding->propertyNameIndex), ¬InRevision) : defaultProperty;
747 if (!pd || pd->propType() != scriptStringMetaType)
750 QString script = compiler->bindingAsString(obj, binding->value.compiledScriptIndex);
751 binding->stringIndex = compiler->registerString(script);
757void QQmlComponentAndAliasResolver<QQmlTypeCompiler>::allocateNamedObjects(
758 QmlIR::Object *object)
const
760 object->namedObjectsInComponent.allocate(m_compiler->memoryPool(), m_idToObjectIndex);
764bool QQmlComponentAndAliasResolver<QQmlTypeCompiler>::markAsComponent(
int index)
const
766 m_compiler->qmlObjects()->at(index)->flags |= QV4::CompiledData::Object::IsComponent;
771void QQmlComponentAndAliasResolver<QQmlTypeCompiler>::setObjectId(
int index)
const
773 m_compiler->qmlObjects()->at(index)->id = m_idToObjectIndex.size();
777void QQmlComponentAndAliasResolver<QQmlTypeCompiler>::resolveGeneralizedGroupProperty(
778 const CompiledObject &component, CompiledBinding *binding)
782 const int targetObjectIndex = m_idToObjectIndex.value(binding->propertyNameIndex, -1);
783 if (targetObjectIndex != -1)
784 m_propertyCaches->set(binding->value.objectIndex, m_propertyCaches->at(targetObjectIndex));
788
789
790
791
792
793
794
795
796
797
798
799
800
801
804 QStringView property, QStringView subProperty,
805 QQmlPropertyIndex &propIdx, QMetaType targetPropertyType,
806 const QQmlPropertyCacheVector *propertyCaches,
807 const QMap<
int,
int> &idToObjectIndex)
809 for (
auto it = targetObject->bindingsBegin(), end = targetObject->bindingsEnd();
812 if (compiler->stringAt(binding.propertyNameIndex) != property)
814 const auto &cache = propertyCaches->at(binding.value.objectIndex);
817 QQmlPropertyResolver resolver(cache);
818 const QQmlPropertyData *pd = resolver.property(subProperty.toString());
821 propIdx = QQmlPropertyIndex(propIdx.coreIndex(), pd->coreIndex());
825 for (
auto it = targetObject->aliasesBegin(), end = targetObject->aliasesEnd();
827 auto innerAlias = *it;
828 if (compiler->stringAt(innerAlias.nameIndex()) != property)
830 const int innerObjectIndex = idToObjectIndex.value(innerAlias.idIndex(), -1);
831 if (innerObjectIndex == -1)
833 const auto &cache = propertyCaches->at(innerObjectIndex);
836 QQmlPropertyResolver resolver(cache);
837 const QQmlPropertyData *pd = resolver.property(subProperty.toString());
840 propIdx = QQmlPropertyIndex(propIdx.coreIndex(), pd->coreIndex());
844 const QQmlPropertyCache::ConstPtr typeCache
845 = QQmlMetaType::propertyCacheForType(targetPropertyType);
847 const QQmlPropertyResolver resolver(typeCache);
848 const QQmlPropertyData *pd = resolver.property(subProperty.toString());
850 propIdx = QQmlPropertyIndex(propIdx.coreIndex(), pd->coreIndex());
859typename QQmlComponentAndAliasResolver<QQmlTypeCompiler>::AliasResolutionResult
860QQmlComponentAndAliasResolver<QQmlTypeCompiler>::resolveAliasesInObject(
861 const CompiledObject &component,
int objectIndex,
862 QQmlPropertyCacheAliasCreator<QQmlTypeCompiler> *aliasCacheCreator, QQmlError *error)
866 const QmlIR::Object *obj = m_compiler->objectAt(objectIndex);
867 if (!obj->aliasCount())
868 return AllAliasesResolved;
871 int numSkippedAliases = 0;
872 bool hasUnresolvedLocalAliases =
false;
874 for (
const QmlIR::Alias *alias = obj->firstAlias(); alias; alias = alias->next, ++aliasIndex) {
875 if (resolvedAliases.contains(alias)) {
881 const int idIndex = alias->idIndex();
882 const int targetObjectIndex = m_idToObjectIndex.value(idIndex, -1);
883 if (targetObjectIndex == -1) {
884 *error = qQmlCompileError(
885 alias->referenceLocation(),
886 QQmlComponentAndAliasResolverBase::tr(
887 "Invalid alias reference. Unable to find id \"%1\"")
888 .arg(stringAt(idIndex)));
892 const QmlIR::Object *targetObject = m_compiler->objectAt(targetObjectIndex);
893 Q_ASSERT(targetObject->id >= 0);
894 const int resolvedTargetObjectId = targetObject->id;
896 const QString aliasPropertyValue = stringAt(alias->propertyNameIndex());
898 QStringView property;
899 QStringView subProperty;
901 const int propertySeparator = aliasPropertyValue.indexOf(QLatin1Char(
'.'));
902 if (propertySeparator != -1) {
903 property = QStringView{aliasPropertyValue}.left(propertySeparator);
904 subProperty = QStringView{aliasPropertyValue}.mid(propertySeparator + 1);
906 property = QStringView(aliasPropertyValue);
908 QQmlPropertyIndex propIdx;
910 if (property.isEmpty()) {
913 QQmlPropertyCache::ConstPtr targetCache = m_propertyCaches->at(targetObjectIndex);
915 *error = qQmlCompileError(
916 alias->referenceLocation(),
917 QQmlComponentAndAliasResolverBase::tr(
"Invalid alias target location: %1")
918 .arg(property.toString()));
922 QQmlPropertyResolver resolver(targetCache);
924 const QQmlPropertyData *targetProperty = resolver.property(
925 property.toString(),
nullptr, QQmlPropertyResolver::IgnoreRevision);
928 if (!targetProperty) {
929 bool aliasPointsToOtherAlias =
false;
930 auto targetAlias = targetObject->aliasesBegin();
931 for (
const auto end = targetObject->aliasesEnd(); targetAlias != end;
933 if (stringAt(targetAlias->nameIndex()) == property) {
934 aliasPointsToOtherAlias =
true;
938 if (aliasPointsToOtherAlias) {
939 if (targetObjectIndex != objectIndex) {
941 return aliasIndex == numSkippedAliases
943 : SomeAliasesResolved;
946 if (resolvedAliases.contains(targetAlias)) {
948 if (!appendAliasToPropertyCache(
949 &component, alias, objectIndex, aliasIndex, -1,
950 resolvedTargetObjectId, aliasCacheCreator, error)) {
960 hasUnresolvedLocalAliases =
true;
965 if (!targetProperty || targetProperty->coreIndex() > 0x0000FFFF) {
966 *error = qQmlCompileError(
967 alias->referenceLocation(),
968 QQmlComponentAndAliasResolverBase::tr(
"Invalid alias target location: %1")
969 .arg(property.toString()));
973 propIdx = QQmlPropertyIndex(targetProperty->coreIndex());
975 if (!subProperty.isEmpty()) {
976 const QMetaObject *valueTypeMetaObject = QQmlMetaType::metaObjectForValueType(targetProperty->propType());
977 if (!valueTypeMetaObject) {
979 bool isDeepAlias = subProperty.at(0).isLower();
981 isDeepAlias = resolveDeepAlias(
982 m_compiler, targetObject, property, subProperty, propIdx,
983 targetProperty->propType(), m_propertyCaches, m_idToObjectIndex);
986 *error = qQmlCompileError(
987 alias->referenceLocation(),
988 QQmlComponentAndAliasResolverBase::tr(
989 "Invalid alias target location: %1")
990 .arg(subProperty.toString()));
996 valueTypeMetaObject->indexOfProperty(subProperty.toString().toUtf8().constData());
997 if (valueTypeIndex == -1) {
998 *error = qQmlCompileError(
999 alias->referenceLocation(),
1000 QQmlComponentAndAliasResolverBase::tr(
1001 "Invalid alias target location: %1")
1002 .arg(subProperty.toString()));
1005 Q_ASSERT(valueTypeIndex <= 0x0000FFFF);
1007 propIdx = QQmlPropertyIndex(propIdx.coreIndex(), valueTypeIndex);
1012 if (!appendAliasToPropertyCache(
1013 &component, alias, objectIndex, aliasIndex, propIdx.toEncoded(),
1014 resolvedTargetObjectId, aliasCacheCreator, error)) {
1019 if (numSkippedAliases == aliasIndex)
1020 return NoAliasResolved;
1022 if (aliasIndex == obj->aliasCount() && !hasUnresolvedLocalAliases)
1023 return AllAliasesResolved;
1025 return SomeAliasesResolved;
1030 , qmlObjects(typeCompiler->qmlObjects())
1031 , propertyCaches(typeCompiler->propertyCaches())
1032 , customParsers(typeCompiler->customParserCache())
1033 , _seenObjectWithId(
false)
1039 for (
int i = 0; i < qmlObjects->size(); ++i) {
1040 if ((qmlObjects->at(i)->flags & QV4::CompiledData::Object::IsInlineComponentRoot)
1041 && !scanObject(i, ScopeDeferred::False)) {
1045 return scanObject(0, ScopeDeferred::False);
1049 int objectIndex, ScopeDeferred scopeDeferred)
1053 QmlIR::Object *obj = qmlObjects->at(objectIndex);
1054 if (obj->idNameIndex != 0)
1055 _seenObjectWithId =
true;
1057 if (obj->flags & Object::IsComponent) {
1058 Q_ASSERT(obj->bindingCount() == 1);
1059 const Binding *componentBinding = obj->firstBinding();
1060 Q_ASSERT(componentBinding->type() == Binding::Type_Object);
1062 return scanObject(componentBinding->value.objectIndex, ScopeDeferred::False);
1065 QQmlPropertyCache::ConstPtr propertyCache = propertyCaches->at(objectIndex);
1069 QString defaultPropertyName;
1070 const QQmlPropertyData *defaultProperty =
nullptr;
1071 if (obj->indexOfDefaultPropertyOrAlias != -1) {
1072 const QQmlPropertyCache *cache = propertyCache->parent().data();
1073 defaultPropertyName = cache->defaultPropertyName();
1074 defaultProperty = cache->defaultProperty();
1076 defaultPropertyName = propertyCache->defaultPropertyName();
1077 defaultProperty = propertyCache->defaultProperty();
1080 QQmlCustomParser *customParser = customParsers.value(obj->inheritedTypeNameIndex);
1082 QQmlPropertyResolver propertyResolver(propertyCache);
1084 QStringList deferredPropertyNames;
1085 QStringList immediatePropertyNames;
1087 const QMetaObject *mo = propertyCache->firstCppMetaObject();
1088 const int deferredNamesIndex = mo->indexOfClassInfo(
"DeferredPropertyNames");
1089 const int immediateNamesIndex = mo->indexOfClassInfo(
"ImmediatePropertyNames");
1090 if (deferredNamesIndex != -1) {
1091 if (immediateNamesIndex != -1) {
1093 "ImmediatePropertyNames on the same type."));
1095 const QMetaClassInfo classInfo = mo->classInfo(deferredNamesIndex);
1096 deferredPropertyNames = QString::fromUtf8(classInfo.value()).split(u',');
1097 }
else if (immediateNamesIndex != -1) {
1098 const QMetaClassInfo classInfo = mo->classInfo(immediateNamesIndex);
1099 immediatePropertyNames = QString::fromUtf8(classInfo.value()).split(u',');
1102 if (immediatePropertyNames.isEmpty())
1103 immediatePropertyNames.append(QString());
1107 for (QmlIR::Binding *binding = obj->firstBinding(); binding; binding = binding->next) {
1108 QString name = stringAt(binding->propertyNameIndex);
1111 if (binding->type() == Binding::Type_AttachedProperty) {
1112 if (customParser->flags() & QQmlCustomParser::AcceptsAttachedProperties) {
1113 binding->setFlag(Binding::IsCustomParserBinding);
1114 obj->flags |= Object::HasCustomParserBindings;
1117 }
else if (QQmlSignalNames::isHandlerName(name)
1118 && !(customParser->flags() & QQmlCustomParser::AcceptsSignalHandlers)) {
1119 obj->flags |= Object::HasCustomParserBindings;
1120 binding->setFlag(Binding::IsCustomParserBinding);
1125 const bool hasPropertyData = [&]() {
1126 if (name.isEmpty()) {
1127 name = defaultPropertyName;
1128 if (defaultProperty)
1130 }
else if (name.constData()->isUpper()) {
1135 bool notInRevision =
false;
1136 if (propertyResolver.property(
1137 name, ¬InRevision, QQmlPropertyResolver::CheckRevision)) {
1145 const Binding::Flags bindingFlags = binding->flags();
1146 if (bindingFlags & Binding::IsSignalHandlerExpression
1147 || bindingFlags & Binding::IsSignalHandlerObject
1148 || bindingFlags & Binding::IsPropertyObserver) {
1155 obj->flags |= Object::HasCustomParserBindings;
1156 binding->setFlag(Binding::IsCustomParserBinding);
1160 bool seenSubObjectWithId =
false;
1161 bool isExternal =
false;
1162 if (binding->type() >= Binding::Type_Object) {
1163 const bool isOwnProperty = hasPropertyData || binding->isAttachedProperty();
1164 isExternal = !isOwnProperty && binding->isGroupProperty();
1165 if (isOwnProperty || isExternal) {
1166 qSwap(_seenObjectWithId, seenSubObjectWithId);
1169 const bool isImplicitComponent
1170 = compiler->implicitComponentForObject(binding->value.objectIndex) != -1;
1172 const ScopeDeferred objectScope =
1173 !isImplicitComponent && (isExternal || scopeDeferred == ScopeDeferred::True)
1174 ? ScopeDeferred::True
1175 : ScopeDeferred::False;
1176 const bool subObjectValid = scanObject(binding->value.objectIndex, objectScope);
1177 qSwap(_seenObjectWithId, seenSubObjectWithId);
1178 if (!subObjectValid)
1180 _seenObjectWithId |= seenSubObjectWithId;
1184 bool isDeferred =
false;
1185 if (!immediatePropertyNames.isEmpty() && !immediatePropertyNames.contains(name)) {
1186 if (seenSubObjectWithId) {
1188 "to a deferred property."));
1190 if (isExternal || !disableInternalDeferredProperties())
1192 }
else if (!deferredPropertyNames.isEmpty() && deferredPropertyNames.contains(name)) {
1193 if (!seenSubObjectWithId && binding->type() != Binding::Type_GroupProperty) {
1194 if (isExternal || !disableInternalDeferredProperties())
1199 if (binding->type() >= Binding::Type_Object) {
1200 if (isExternal && !isDeferred && !customParser) {
1202 binding, tr(
"Cannot assign to non-existent property \"%1\"").arg(name));
1207 binding->setFlag(Binding::IsDeferredBinding);
1208 obj->flags |= Object::HasDeferredBindings;
void annotateBindingsToAliases()
QQmlAliasAnnotator(QQmlTypeCompiler *typeCompiler)
void annotateBindingsWithScriptStrings()
QQmlCustomParserScriptIndexer(QQmlTypeCompiler *typeCompiler)
bool resolveEnumBindings()
QQmlScriptStringScanner(QQmlTypeCompiler *typeCompiler)
Combined button and popup list for selecting options.
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
#define COMPILE_EXCEPTION(location, desc)
static bool resolveDeepAlias(QQmlTypeCompiler *compiler, const QmlIR::Object *targetObject, QStringView property, QStringView subProperty, QQmlPropertyIndex &propIdx, QMetaType targetPropertyType, const QQmlPropertyCacheVector *propertyCaches, const QMap< int, int > &idToObjectIndex)
QQmlCompilePass(QQmlTypeCompiler *typeCompiler)
QQmlTypeCompiler * compiler
int implicitComponentForObject(int childIndex) const
int registerConstant(QV4::ReturnedValue v)
void recordError(const QQmlJS::DiagnosticMessage &message)
const QV4::CompiledData::Unit * qmlUnit() const
QQmlType qmlTypeForComponent(const QString &inlineComponentName=QString()) const
QList< QmlIR::Object * > * qmlObjects() const
QQmlPropertyCacheVector * propertyCaches()
QQmlJS::MemoryPool * memoryPool()
void recordError(const QQmlError &e)
QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const
const QQmlPropertyCacheVector * propertyCaches() const
int registerString(const QString &str)
const QV4::Compiler::StringTableGenerator * stringPool() const
void recordError(const QV4::CompiledData::Location &location, const QString &description)
QStringView newStringRef(const QString &string)
int resolvedIndex(int index) const
void addImport(const QString &module, const QString &qualifier, QTypeRevision version)
QQmlRefPointer< QV4::CompiledData::CompilationUnit > compile()
QString stringAt(int idx) const
const QQmlImports * imports() const
bool resolveSignalHandlerExpressions()