From d9e98c7f6b6c3331a486cabfe6cd0c07f7bfffe9 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 29 Sep 2020 17:02:37 +0200 Subject: qmllint: Remove exportedQmlNames from import results We don't need to expose them anymore. Change-Id: Ibb25f688459972f718f9a051fbb7265c7e5b5f92 Reviewed-by: Fabian Kosmale --- tools/qmllint/checkidentifiers.cpp | 20 ++++++++++---------- tools/qmllint/findwarnings.cpp | 22 +++++++++++----------- tools/shared/qmljsimporter.cpp | 25 +++++++++---------------- tools/shared/qmljsimporter.h | 7 ++----- 4 files changed, 32 insertions(+), 42 deletions(-) (limited to 'tools') diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index 9a6495310d..eaf6f0e876 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -99,7 +99,7 @@ static bool walkViaParentAndAttachedScopes(ScopeTree::ConstPtr rootType, return true; if (type->isComposite()) { - if (auto superType = allTypes.importedQmlNames.value(type->baseTypeName())) + if (auto superType = allTypes.qmlNames.value(type->baseTypeName())) stack.push(superType); } else { if (auto superType = allTypes.cppNames.value(type->baseTypeName())) @@ -204,7 +204,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector & if (access.m_parentType.isEmpty() && scope->isComposite()) findNextScope(m_types.cppNames); else - findNextScope(m_types.importedQmlNames); + findNextScope(m_types.qmlNames); continue; } @@ -240,7 +240,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector & ScopeTree::ConstPtr rootType; if (!access.m_parentType.isEmpty()) - rootType = m_types.importedQmlNames.value(access.m_parentType); + rootType = m_types.qmlNames.value(access.m_parentType); else rootType = scope; @@ -253,7 +253,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector & if (propType) scope = propType; else if (scope->isComposite()) - scope = m_types.importedQmlNames.value(typeIt->typeName()); + scope = m_types.qmlNames.value(typeIt->typeName()); else scope = m_types.cppNames.value(typeIt->typeName()); return true; @@ -274,8 +274,8 @@ bool CheckIdentifiers::checkMemberAccess(const QVector & if (access.m_name.front().isUpper() && scope->scopeType() == ScopeType::QMLScope) { // may be an attached type - const auto it = m_types.importedQmlNames.find(access.m_name); - if (it != m_types.importedQmlNames.end() && !(*it)->attachedTypeName().isEmpty()) { + const auto it = m_types.qmlNames.find(access.m_name); + if (it != m_types.qmlNames.end() && !(*it)->attachedTypeName().isEmpty()) { const auto attached = m_types.cppNames.find((*it)->attachedTypeName()); if (attached != m_types.cppNames.end()) { scope = *attached; @@ -341,8 +341,8 @@ bool CheckIdentifiers::operator()(const QHash &qml if (scopedName.front().isUpper()) { const QString qualified = memberAccessBase.m_name + QLatin1Char('.') + scopedName; - const auto typeIt = m_types.importedQmlNames.find(qualified); - if (typeIt != m_types.importedQmlNames.end()) { + const auto typeIt = m_types.qmlNames.find(qualified); + if (typeIt != m_types.qmlNames.end()) { memberAccessChain.takeFirst(); if (!checkMemberAccess(memberAccessChain, *typeIt)) noUnqualifiedIdentifier = false; @@ -385,8 +385,8 @@ bool CheckIdentifiers::operator()(const QHash &qml if (memberAccessBase.m_name == QLatin1String("Qt")) continue; - const auto typeIt = m_types.importedQmlNames.find(memberAccessBase.m_name); - if (typeIt != m_types.importedQmlNames.end()) { + const auto typeIt = m_types.qmlNames.find(memberAccessBase.m_name); + if (typeIt != m_types.qmlNames.end()) { if (!checkMemberAccess(memberAccessChain, *typeIt)) noUnqualifiedIdentifier = false; continue; diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 742c1a8d35..74c70ce731 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -117,16 +117,16 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiProgram *) if (!m_qmltypesFiles.isEmpty()) { const auto baseTypes = m_importer.importQmltypes(m_qmltypesFiles); - m_rootScopeImports.importedQmlNames.insert(baseTypes.importedQmlNames); + m_rootScopeImports.qmlNames.insert(baseTypes.qmlNames); m_rootScopeImports.cppNames.insert(baseTypes.cppNames); } // add "self" (as we only ever check the first part of a qualified identifier, we get away with // using an empty ScopeTree - m_rootScopeImports.importedQmlNames.insert(QFileInfo { m_filePath }.baseName(), {}); + m_rootScopeImports.qmlNames.insert(QFileInfo { m_filePath }.baseName(), {}); const auto imported = m_importer.importFileOrDirectory(QFileInfo(m_filePath).path()); - m_rootScopeImports.importedQmlNames.insert(imported.importedQmlNames); + m_rootScopeImports.qmlNames.insert(imported.qmlNames); m_rootScopeImports.cppNames.insert(imported.cppNames); const QStringList warnings = m_importer.takeWarnings(); @@ -330,7 +330,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiPublicMember *uipm) uipm->memberType ? uipm->memberType->name.toString() : QString(), uipm->typeModifier == QLatin1String("list"), !uipm->isReadonlyMember, false, uipm->memberType ? (uipm->memberType->name == QLatin1String("alias")) : false, 0); - property.setType(m_rootScopeImports.importedQmlNames.value(property.typeName())); + property.setType(m_rootScopeImports.qmlNames.value(property.typeName())); m_currentScope->insertPropertyIdentifier(property); } return true; @@ -480,7 +480,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiImport *import) const auto imported = m_importer.importFileOrDirectory( file.isRelative() ? QFileInfo(m_filePath).dir().filePath(filename) : filename, prefix); - m_rootScopeImports.importedQmlNames.insert(imported.importedQmlNames); + m_rootScopeImports.qmlNames.insert(imported.qmlNames); m_rootScopeImports.cppNames.insert(imported.cppNames); } @@ -488,7 +488,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiImport *import) if (!import->importId.isEmpty()) { // TODO: do not put imported ids into the same space as qml IDs const QString importId = import->importId.toString(); - m_qmlid2scope.insert(importId, m_rootScopeImports.importedQmlNames.value(importId)); + m_qmlid2scope.insert(importId, m_rootScopeImports.qmlNames.value(importId)); } auto uri = import->importUri; while (uri) { @@ -501,7 +501,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiImport *import) const auto imported = m_importer.importModule( path, prefix, import->version ? import->version->version : QTypeRevision()); - m_rootScopeImports.importedQmlNames.insert(imported.importedQmlNames); + m_rootScopeImports.qmlNames.insert(imported.qmlNames); m_rootScopeImports.cppNames.insert(imported.cppNames); const QStringList warnings = m_importer.takeWarnings(); @@ -534,11 +534,11 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob) MetaProperty prop(uiob->qualifiedId->name.toString(), name, false, true, true, name == QLatin1String("alias"), 0); - prop.setType(m_rootScopeImports.importedQmlNames.value(uiob->qualifiedTypeNameId->name.toString())); + prop.setType(m_rootScopeImports.qmlNames.value(uiob->qualifiedTypeNameId->name.toString())); m_currentScope->addProperty(prop); enterEnvironment(ScopeType::QMLScope, name); - m_currentScope->resolveTypes(m_rootScopeImports.importedQmlNames); + m_currentScope->resolveTypes(m_rootScopeImports.qmlNames); importExportedNames(m_currentScope); return true; } @@ -569,7 +569,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectDefinition *uiod) if (name.isLower()) return false; // Ignore grouped properties for now - m_currentScope->resolveTypes(m_rootScopeImports.importedQmlNames); + m_currentScope->resolveTypes(m_rootScopeImports.qmlNames); importExportedNames(m_currentScope); if (name.endsWith("Connections")) { @@ -599,7 +599,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectDefinition *uiod) do { scope = scope->parentScope(); // TODO: rename method } while (scope->scopeType() != ScopeType::QMLScope); - targetScope = m_rootScopeImports.importedQmlNames.value(scope->baseTypeName()); + targetScope = m_rootScopeImports.qmlNames.value(scope->baseTypeName()); } else { // there was a target, check if we already can find it auto scopeIt = m_qmlid2scope.find(target); diff --git a/tools/shared/qmljsimporter.cpp b/tools/shared/qmljsimporter.cpp index 4412ec01fd..4dac5466e2 100644 --- a/tools/shared/qmljsimporter.cpp +++ b/tools/shared/qmljsimporter.cpp @@ -137,10 +137,8 @@ void QmlJSImporter::processImport( QmlJSImporter::ImportedTypes *types, const QString &prefix) { - for (auto it = import.scripts.begin(); it != import.scripts.end(); ++it) { - types->importedQmlNames.insert(prefixedName(prefix, it.key()), it.value()); - types->exportedQmlNames.insert(it.key(), it.value()); - } + for (auto it = import.scripts.begin(); it != import.scripts.end(); ++it) + types->qmlNames.insert(prefixedName(prefix, it.key()), it.value()); // add objects for (auto it = import.objects.begin(); it != import.objects.end(); ++it) { @@ -148,10 +146,8 @@ void QmlJSImporter::processImport( types->cppNames.insert(val->internalName(), val); const auto exports = val->exports(); - for (const auto &valExport : exports) { - types->importedQmlNames.insert(prefixedName(prefix, valExport.type()), val); - types->exportedQmlNames.insert(valExport.type(), val); - } + for (const auto &valExport : exports) + types->qmlNames.insert(prefixedName(prefix, valExport.type()), val); } for (auto it = import.objects.begin(); it != import.objects.end(); ++it) { @@ -257,14 +253,14 @@ ScopeTree::Ptr QmlJSImporter::localFile2ScopeTree(const QString &filePath) while (it.hasNext()) { ScopeTree::Ptr scope(localFile2ScopeTree(it.next())); if (!scope->internalName().isEmpty()) - types.importedQmlNames.insert(scope->internalName(), scope); + types.qmlNames.insert(scope->internalName(), scope); } const auto imports = typeReader.imports(); for (const auto &import : imports) importHelper(import.module, &types, import.prefix, import.version); - result->resolveTypes(types.importedQmlNames); + result->resolveTypes(types.qmlNames); return result; } @@ -278,8 +274,7 @@ QmlJSImporter::ImportedTypes QmlJSImporter::importFileOrDirectory( QFileInfo fileInfo(name); if (fileInfo.isFile()) { ScopeTree::Ptr scope(localFile2ScopeTree(fileInfo.canonicalFilePath())); - result.importedQmlNames.insert(prefix.isEmpty() ? scope->internalName() : prefix, scope); - result.exportedQmlNames.insert(scope->internalName(), scope); + result.qmlNames.insert(prefix.isEmpty() ? scope->internalName() : prefix, scope); return result; } @@ -290,10 +285,8 @@ QmlJSImporter::ImportedTypes QmlJSImporter::importFileOrDirectory( }; while (it.hasNext()) { ScopeTree::Ptr scope(localFile2ScopeTree(it.next())); - if (!scope->internalName().isEmpty()) { - result.importedQmlNames.insert(prefixedName(prefix, scope->internalName()), scope); - result.exportedQmlNames.insert(scope->internalName(), scope); - } + if (!scope->internalName().isEmpty()) + result.qmlNames.insert(prefixedName(prefix, scope->internalName()), scope); } return result; diff --git a/tools/shared/qmljsimporter.h b/tools/shared/qmljsimporter.h index 8212afc6d4..960effef40 100644 --- a/tools/shared/qmljsimporter.h +++ b/tools/shared/qmljsimporter.h @@ -50,11 +50,8 @@ public: // C++ names used in qmltypes files for non-composite types QHash cppNames; - // Names a component intends to export, without prefix - QHash exportedQmlNames; - - // Names the importing component sees, possibly adding a prefix - QHash importedQmlNames; + // Names the importing component sees, including any prefixes + QHash qmlNames; }; QmlJSImporter(const QStringList &importPaths) : m_importPaths(importPaths) {} -- cgit v1.2.3