diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmlcompiler/qqmljscompiler.cpp | 2 | ||||
| -rw-r--r-- | src/qmlcompiler/qqmljscompilerstats.cpp | 14 | ||||
| -rw-r--r-- | src/qmlcompiler/qqmljscompilerstats_p.h | 10 | ||||
| -rw-r--r-- | src/qmlcompiler/qqmljsutils_p.h | 2 | ||||
| -rw-r--r-- | src/qmlls/qqmllsutils.cpp | 136 |
5 files changed, 86 insertions, 78 deletions
diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp index ba796b388f..5aa8a62786 100644 --- a/src/qmlcompiler/qqmljscompiler.cpp +++ b/src/qmlcompiler/qqmljscompiler.cpp @@ -791,7 +791,7 @@ QQmlJSAotFunction QQmlJSAotCompiler::doCompileAndRecordAotStats( QQmlJS::DiagnosticMessage *error, const QString &name, QQmlJS::SourceLocation location) { auto t1 = std::chrono::high_resolution_clock::now(); - auto &&result = doCompile(context, function, error); + QQmlJSAotFunction result = doCompile(context, function, error); auto t2 = std::chrono::high_resolution_clock::now(); if (QQmlJS::QQmlJSAotCompilerStats::recordAotStats()) { diff --git a/src/qmlcompiler/qqmljscompilerstats.cpp b/src/qmlcompiler/qqmljscompilerstats.cpp index b65afd412f..9e564834e7 100644 --- a/src/qmlcompiler/qqmljscompilerstats.cpp +++ b/src/qmlcompiler/qqmljscompilerstats.cpp @@ -26,7 +26,7 @@ bool QQmlJS::AotStatsEntry::operator<(const AotStatsEntry &other) const return line < other.line; } -void AotStats::insert(AotStats other) +void AotStats::insert(const AotStats &other) { for (const auto &[moduleUri, moduleStats] : other.m_entries.asKeyValueRange()) { m_entries[moduleUri].insert(moduleStats); @@ -111,10 +111,10 @@ AotStats AotStats::fromJsonDocument(const QJsonDocument &document) } std::sort(stats.begin(), stats.end()); - files[filepath] = stats; + files[filepath] = std::move(stats); } - result.m_entries[moduleId] = files; + result.m_entries[moduleId] = std::move(files); } return result; @@ -160,7 +160,8 @@ QJsonDocument AotStats::toJsonDocument() const return QJsonDocument(modulesArray); } -void AotStats::addEntry(const QString &moduleId, const QString &filepath, AotStatsEntry entry) +void AotStats::addEntry( + const QString &moduleId, const QString &filepath, const AotStatsEntry &entry) { m_entries[moduleId][filepath].append(entry); } @@ -177,10 +178,9 @@ bool AotStats::saveToDisk(const QString &filepath) const return true; } -void QQmlJSAotCompilerStats::addEntry(QString filepath, QQmlJS::AotStatsEntry entry) +void QQmlJSAotCompilerStats::addEntry(const QString &filepath, const QQmlJS::AotStatsEntry &entry) { - auto *aotstats = QQmlJSAotCompilerStats::instance(); - aotstats->addEntry(s_moduleId, filepath, entry); + QQmlJSAotCompilerStats::instance()->addEntry(s_moduleId, filepath, entry); } } // namespace QQmlJS diff --git a/src/qmlcompiler/qqmljscompilerstats_p.h b/src/qmlcompiler/qqmljscompilerstats_p.h index abd89c4a20..53ebb9f777 100644 --- a/src/qmlcompiler/qqmljscompilerstats_p.h +++ b/src/qmlcompiler/qqmljscompilerstats_p.h @@ -50,8 +50,8 @@ public: return m_entries; } - void addEntry(const QString &moduleId, const QString &filepath, AotStatsEntry entry); - void insert(AotStats other); + void addEntry(const QString &moduleId, const QString &filepath, const AotStatsEntry &entry); + void insert(const AotStats &other); bool saveToDisk(const QString &filepath) const; @@ -74,10 +74,10 @@ public: static bool recordAotStats() { return s_recordAotStats; } static void setRecordAotStats(bool recordAotStats) { s_recordAotStats = recordAotStats; } - static const QString &moduleId() { return s_moduleId; } - static void setModuleId(QString moduleId) { s_moduleId = moduleId; } + static QString moduleId() { return s_moduleId; } + static void setModuleId(const QString &moduleId) { s_moduleId = moduleId; } - static void addEntry(QString filepath, QQmlJS::AotStatsEntry entry); + static void addEntry(const QString &filepath, const QQmlJS::AotStatsEntry &entry); private: static std::unique_ptr<AotStats> s_instance; diff --git a/src/qmlcompiler/qqmljsutils_p.h b/src/qmlcompiler/qqmljsutils_p.h index bca4b1df38..c23399e9ae 100644 --- a/src/qmlcompiler/qqmljsutils_p.h +++ b/src/qmlcompiler/qqmljsutils_p.h @@ -202,7 +202,7 @@ struct Q_QMLCOMPILER_EXPORT QQmlJSUtils const AliasResolutionVisitor &visitor); template<typename QQmlJSScopePtr, typename Action> - static bool searchBaseAndExtensionTypes(QQmlJSScopePtr type, const Action &check) + static bool searchBaseAndExtensionTypes(const QQmlJSScopePtr &type, const Action &check) { if (!type) return false; diff --git a/src/qmlls/qqmllsutils.cpp b/src/qmlls/qqmllsutils.cpp index e290cdad1c..2bad86dff7 100644 --- a/src/qmlls/qqmllsutils.cpp +++ b/src/qmlls/qqmllsutils.cpp @@ -711,10 +711,12 @@ static QStringList namesOfPossibleUsages(const QString &name, } template<typename Predicate> -QQmlJSScope::ConstPtr findDefiningScopeIf(QQmlJSScope::ConstPtr referrerScope, Predicate &&check) +QQmlJSScope::ConstPtr findDefiningScopeIf( + const QQmlJSScope::ConstPtr &referrerScope, Predicate &&check) { QQmlJSScope::ConstPtr result; - QQmlJSUtils::searchBaseAndExtensionTypes(referrerScope, [&](QQmlJSScope::ConstPtr scope) { + QQmlJSUtils::searchBaseAndExtensionTypes( + referrerScope, [&](const QQmlJSScope::ConstPtr &scope) { if (check(scope)) { result = scope; return true; @@ -732,8 +734,8 @@ QQmlJSScope::ConstPtr findDefiningScopeIf(QQmlJSScope::ConstPtr referrerScope, P Starts looking for the name starting from the given scope and traverse through base and extension types. */ -static QQmlJSScope::ConstPtr findDefiningScopeForProperty(QQmlJSScope::ConstPtr referrerScope, - const QString &nameToCheck) +static QQmlJSScope::ConstPtr findDefiningScopeForProperty( + const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck) { return findDefiningScopeIf(referrerScope, [&nameToCheck](const QQmlJSScope::ConstPtr &scope) { return scope->hasOwnProperty(nameToCheck); @@ -746,8 +748,8 @@ See also findDefiningScopeForProperty(). Special case: you can also bind to a signal handler. */ -static QQmlJSScope::ConstPtr findDefiningScopeForBinding(QQmlJSScope::ConstPtr referrerScope, - const QString &nameToCheck) +static QQmlJSScope::ConstPtr findDefiningScopeForBinding( + const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck) { return findDefiningScopeIf(referrerScope, [&nameToCheck](const QQmlJSScope::ConstPtr &scope) { return scope->hasOwnProperty(nameToCheck) || scope->hasOwnMethod(nameToCheck); @@ -758,8 +760,8 @@ static QQmlJSScope::ConstPtr findDefiningScopeForBinding(QQmlJSScope::ConstPtr r \internal See also findDefiningScopeForProperty(). */ -static QQmlJSScope::ConstPtr findDefiningScopeForMethod(QQmlJSScope::ConstPtr referrerScope, - const QString &nameToCheck) +static QQmlJSScope::ConstPtr findDefiningScopeForMethod( + const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck) { return findDefiningScopeIf(referrerScope, [&nameToCheck](const QQmlJSScope::ConstPtr &scope) { return scope->hasOwnMethod(nameToCheck); @@ -770,8 +772,8 @@ static QQmlJSScope::ConstPtr findDefiningScopeForMethod(QQmlJSScope::ConstPtr re \internal See also findDefiningScopeForProperty(). */ -static QQmlJSScope::ConstPtr findDefiningScopeForEnumeration(QQmlJSScope::ConstPtr referrerScope, - const QString &nameToCheck) +static QQmlJSScope::ConstPtr findDefiningScopeForEnumeration( + const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck) { return findDefiningScopeIf(referrerScope, [&nameToCheck](const QQmlJSScope::ConstPtr &scope) { return scope->hasOwnEnumeration(nameToCheck); @@ -782,8 +784,8 @@ static QQmlJSScope::ConstPtr findDefiningScopeForEnumeration(QQmlJSScope::ConstP \internal See also findDefiningScopeForProperty(). */ -static QQmlJSScope::ConstPtr findDefiningScopeForEnumerationKey(QQmlJSScope::ConstPtr referrerScope, - const QString &nameToCheck) +static QQmlJSScope::ConstPtr findDefiningScopeForEnumerationKey( + const QQmlJSScope::ConstPtr &referrerScope, const QString &nameToCheck) { return findDefiningScopeIf(referrerScope, [&nameToCheck](const QQmlJSScope::ConstPtr &scope) { return scope->hasOwnEnumerationKey(nameToCheck); @@ -964,7 +966,7 @@ static void findUsagesHelper(const DomItem &item, const QString &name, Usages &r const QString fileName = item.canonicalFilePath(); result.appendUsage({ fileName, location }); return true; - } else if (QQmlJSScope::ConstPtr scope = item.semanticScope(); + } else if (const QQmlJSScope::ConstPtr scope = item.semanticScope(); scope && scope->ownJSIdentifier(name)) { // current JS identifier has been redefined, do not visit children return false; @@ -1130,18 +1132,16 @@ static std::optional<ExpressionType> propertyBindingFromReferrerScope(const QQmlJSScope::ConstPtr &referrerScope, const QString &name, ResolveOptions options, QQmlJSTypeResolver *resolverForIds) { - auto bindings = referrerScope->propertyBindings(name); + const auto bindings = referrerScope->propertyBindings(name); if (bindings.isEmpty()) return {}; - const auto binding = bindings.front(); - - if ((binding.bindingType() != QQmlSA::BindingType::AttachedProperty) - && (binding.bindingType() != QQmlSA::BindingType::GroupProperty)) + const auto binding = bindings.begin(); + const auto bindingType = binding->bindingType(); + const bool bindingIsAttached = bindingType == QQmlSA::BindingType::AttachedProperty; + if (!bindingIsAttached && bindingType != QQmlSA::BindingType::GroupProperty) return {}; - const bool bindingIsAttached = binding.bindingType() == QQmlSA::BindingType::AttachedProperty; - // Generalized grouped properties, like Bindings or PropertyChanges, for example, have bindings // starting in an id (like `someId.someProperty: ...`). // If `someid` is not a property and is a deferred name, then it should be an id. @@ -1162,11 +1162,11 @@ propertyBindingFromReferrerScope(const QQmlJSScope::ConstPtr &referrerScope, con const auto typeIdentifier = bindingIsAttached ? AttachedTypeIdentifier : GroupedPropertyIdentifier; - const auto getScope = [&bindingIsAttached, &binding]() -> QQmlJSScope::ConstPtr { + const auto getScope = [bindingIsAttached, binding]() -> QQmlJSScope::ConstPtr { if (bindingIsAttached) - return binding.attachingType(); + return binding->attachingType(); - return binding.groupType(); + return binding->groupType(); }; switch (options) { @@ -1190,7 +1190,8 @@ propertyBindingFromReferrerScope(const QQmlJSScope::ConstPtr &referrerScope, con Finds the scope within the special elements like Connections, PropertyChanges, Bindings or AnchorChanges. */ -static QQmlJSScope::ConstPtr findScopeOfSpecialItems(QQmlJSScope::ConstPtr scope, const DomItem &item) +static QQmlJSScope::ConstPtr findScopeOfSpecialItems( + const QQmlJSScope::ConstPtr &scope, const DomItem &item) { if (!scope) return {}; @@ -1201,7 +1202,7 @@ static QQmlJSScope::ConstPtr findScopeOfSpecialItems(QQmlJSScope::ConstPtr scope u"QQuickAnchorChanges"_s}; const auto special = QQmlJSUtils::searchBaseAndExtensionTypes( - scope, [&specialItems](QQmlJSScope::ConstPtr visitedScope) { + scope, [&specialItems](const QQmlJSScope::ConstPtr &visitedScope) { const auto typeName = visitedScope->internalName(); if (specialItems.contains(typeName)) return true; @@ -1309,20 +1310,19 @@ static std::optional<ExpressionType> resolveIdentifierExpressionType(const DomIt const QString name = item.field(Fields::identifier).value().toString(); - if (DomItem definitionOfItem = findJSIdentifierDefinition(item, name)) { + if (const DomItem definitionOfItem = findJSIdentifierDefinition(item, name)) { Q_ASSERT_X(!definitionOfItem.semanticScope().isNull() && definitionOfItem.semanticScope()->ownJSIdentifier(name), "QQmlLSUtils::findDefinitionOf", "JS definition does not actually define the JS identifer. " "It should be empty."); - auto scope = definitionOfItem.semanticScope(); - auto jsIdentifier = scope->ownJSIdentifier(name); - if (jsIdentifier->scope) { - return ExpressionType{ name, jsIdentifier->scope.toStrongRef(), - IdentifierType::JavaScriptIdentifier }; - } else { - return ExpressionType{ name, scope, IdentifierType::JavaScriptIdentifier }; - } + const auto scope = definitionOfItem.semanticScope(); + const auto jsIdentifier = scope->ownJSIdentifier(name); + return ExpressionType { + name, + jsIdentifier->scope ? QQmlJSScope::ConstPtr(jsIdentifier->scope.toStrongRef()) : scope, + IdentifierType::JavaScriptIdentifier + }; } const auto referrerScope = item.nearestSemanticScope(); @@ -1338,28 +1338,29 @@ static std::optional<ExpressionType> resolveIdentifierExpressionType(const DomIt return {}; // check if its found as a property binding - if (auto scope = propertyBindingFromReferrerScope(referrerScope, name, options, resolver.get())) + if (const auto scope = propertyBindingFromReferrerScope( + referrerScope, name, options, resolver.get())) { return *scope; + } // check if its an (unqualified) property - if (auto scope = propertyFromReferrerScope(referrerScope, name, options)) + if (const auto scope = propertyFromReferrerScope(referrerScope, name, options)) return *scope; // Returns the baseType, can't use it with options. - if (auto scope = resolver->typeForName(name)) { + if (const auto scope = resolver->typeForName(name)) { if (scope->isSingleton()) return ExpressionType{ name, scope, IdentifierType::SingletonIdentifier }; - if (auto attachedScope = scope->attachedType()) { + if (const auto attachedScope = scope->attachedType()) return ExpressionType{ name, attachedScope, IdentifierType::AttachedTypeIdentifier }; - } // its a (inline) component! return ExpressionType{ name, scope, QmlComponentIdentifier }; } // check if its an id - QQmlJSRegisterContent fromId = + const QQmlJSRegisterContent fromId = resolver->scopedType(referrerScope, name, QQmlJSRegisterContent::InvalidLookupIndex, AssumeComponentsAreBound); if (fromId.variant() == QQmlJSRegisterContent::ObjectById) @@ -1367,11 +1368,11 @@ static std::optional<ExpressionType> resolveIdentifierExpressionType(const DomIt const QQmlJSScope::ConstPtr jsGlobal = resolver->jsGlobalObject(); // check if its a JS global method - if (auto scope = methodFromReferrerScope(jsGlobal, name, options)) + if (const auto scope = methodFromReferrerScope(jsGlobal, name, options)) return scope; // check if its an JS global property - if (auto scope = propertyFromReferrerScope(jsGlobal, name, options)) + if (const auto scope = propertyFromReferrerScope(jsGlobal, name, options)) return *scope; return {}; @@ -1381,7 +1382,7 @@ static std::optional<ExpressionType> resolveSignalOrPropertyExpressionType(const QString &name, const QQmlJSScope::ConstPtr &scope, ResolveOptions options) { - auto signalOrProperty = resolveNameInQmlScope(name, scope); + const auto signalOrProperty = resolveNameInQmlScope(name, scope); if (!signalOrProperty) return {}; @@ -1463,7 +1464,8 @@ std::optional<ExpressionType> resolveExpressionType(const QQmlJS::Dom::DomItem & if (name == u"id") return ExpressionType{ name, owner.value(), QmlObjectIdIdentifier }; - if (QQmlJSScope::ConstPtr targetScope = findScopeOfSpecialItems(owner.value(), item)) { + if (const QQmlJSScope::ConstPtr targetScope + = findScopeOfSpecialItems(owner.value(), item)) { const auto signalOrProperty = resolveNameInQmlScope(name, targetScope); if (!signalOrProperty) return {}; @@ -1527,13 +1529,13 @@ std::optional<ExpressionType> resolveExpressionType(const QQmlJS::Dom::DomItem & Q_UNREACHABLE_RETURN({}); } case DomType::MethodInfo: { - auto object = item.as<MethodInfo>(); + const auto object = item.as<MethodInfo>(); if (object && object->semanticScope()) { std::optional<QQmlJSScope::ConstPtr> scope = object->semanticScope(); if (!scope) return {}; - if (QQmlJSScope::ConstPtr targetScope = + if (const QQmlJSScope::ConstPtr targetScope = findScopeOfSpecialItems(scope.value()->parentScope(), item)) { const auto signalOrProperty = resolveNameInQmlScope(object->name, targetScope); if (!signalOrProperty) @@ -1556,8 +1558,8 @@ std::optional<ExpressionType> resolveExpressionType(const QQmlJS::Dom::DomItem & if (scope.value()->scopeType() == QQmlJSScope::ScopeType::JSFunctionScope) scope = scope.value()->parentScope(); - if (auto result = resolveSignalOrPropertyExpressionType(object->name, scope.value(), - options)) { + if (const auto result = resolveSignalOrPropertyExpressionType( + object->name, scope.value(), options)) { return result; } qDebug(QQmlLSUtilsLog) << "QQmlLSUtils::resolveExpressionType() could not resolve the" @@ -1578,7 +1580,7 @@ std::optional<ExpressionType> resolveExpressionType(const QQmlJS::Dom::DomItem & */ const auto scope = item.qmlObject().semanticScope(); const auto name = item.field(Fields::value).value().toString(); - if (QQmlJSScope::ConstPtr targetScope = findScopeOfSpecialItems(scope, item)) { + if (const QQmlJSScope::ConstPtr targetScope = findScopeOfSpecialItems(scope, item)) { const auto signalOrProperty = resolveNameInQmlScope(name, targetScope); if (!signalOrProperty) return {}; @@ -1598,32 +1600,38 @@ std::optional<ExpressionType> resolveExpressionType(const QQmlJS::Dom::DomItem & } case DomType::EnumItem: { const QString enumValue = item.field(Fields::name).value().toString(); - QQmlJSScope::ConstPtr referrerScope = item.rootQmlObject(GoTo::MostLikely).semanticScope(); - if (!referrerScope->hasEnumerationKey(enumValue)) - return {}; - switch (options) { - // special case: use the owner's scope here, as enums do not have their own - // QQmlJSScope. - case ResolveActualTypeForFieldMemberExpression: - case ResolveOwnerType: - return ExpressionType{ enumValue, - findDefiningScopeForEnumerationKey(referrerScope, enumValue), - EnumeratorValueIdentifier }; + const QQmlJSScope::ConstPtr referrerScope + = item.rootQmlObject(GoTo::MostLikely).semanticScope(); + if (!referrerScope->hasEnumerationKey(enumValue)) + return {}; + switch (options) { + // special case: use the owner's scope here, as enums do not have their own + // QQmlJSScope. + case ResolveActualTypeForFieldMemberExpression: + case ResolveOwnerType: + return ExpressionType { + enumValue, + findDefiningScopeForEnumerationKey(referrerScope, enumValue), + EnumeratorValueIdentifier + }; } Q_UNREACHABLE_RETURN({}); } case DomType::EnumDecl: { const QString enumName = item.field(Fields::name).value().toString(); - QQmlJSScope::ConstPtr referrerScope = item.rootQmlObject(GoTo::MostLikely).semanticScope(); + const QQmlJSScope::ConstPtr referrerScope + = item.rootQmlObject(GoTo::MostLikely).semanticScope(); if (!referrerScope->hasEnumeration(enumName)) return {}; switch (options) { // special case: use the owner's scope here, as enums do not have their own QQmlJSScope. case ResolveActualTypeForFieldMemberExpression: case ResolveOwnerType: - return ExpressionType{ enumName, - findDefiningScopeForEnumeration(referrerScope, enumName), - EnumeratorIdentifier }; + return ExpressionType { + enumName, + findDefiningScopeForEnumeration(referrerScope, enumName), + EnumeratorIdentifier + }; } Q_UNREACHABLE_RETURN({}); |
