diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-29 17:33:17 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-10-02 15:32:42 +0200 |
commit | e548c8576d1794cdac4b9a679b90cb74cf307e44 (patch) | |
tree | b743c5c080032db37e3cc477c820eb78adcfe112 /tools/qmllint | |
parent | d9e98c7f6b6c3331a486cabfe6cd0c07f7bfffe9 (diff) |
qmllint: Don't use C++ names of QML types
The C++ names are an implementation detail of the importer, and qmllint
has no business messing with them. All the types are supplied as
ScopeTree by the importer now.
Change-Id: I3ef2b5da1dc19f95c7f2a5d80fa1297ba10bef8f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint')
-rw-r--r-- | tools/qmllint/checkidentifiers.cpp | 61 | ||||
-rw-r--r-- | tools/qmllint/findwarnings.cpp | 4 |
2 files changed, 23 insertions, 42 deletions
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index eaf6f0e876..c3037a8774 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -84,7 +84,6 @@ void CheckIdentifiers::printContext(const QQmlJS::SourceLocation &location) cons } static bool walkViaParentAndAttachedScopes(ScopeTree::ConstPtr rootType, - const QmlJSImporter::ImportedTypes &allTypes, std::function<bool(ScopeTree::ConstPtr)> visit) { if (rootType == nullptr) @@ -98,15 +97,10 @@ static bool walkViaParentAndAttachedScopes(ScopeTree::ConstPtr rootType, if (visit(type)) return true; - if (type->isComposite()) { - if (auto superType = allTypes.qmlNames.value(type->baseTypeName())) - stack.push(superType); - } else { - if (auto superType = allTypes.cppNames.value(type->baseTypeName())) - stack.push(superType); - } + if (auto superType = type->baseType()) + stack.push(superType); - if (auto attachedType = allTypes.cppNames.value(type->attachedTypeName())) + if (auto attachedType = type->attachedType()) stack.push(attachedType); } return false; @@ -180,31 +174,29 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> & continue; } - if (const ScopeTree::ConstPtr type = scopeIt->type()) { - if (access.m_parentType.isEmpty()) { - scope = type; - continue; + if (access.m_parentType.isEmpty()) { + scope = scopeIt->type(); + if (scope.isNull()) { + // Properties should always have a type. Otherwise something + // was missing from the import already. + detectedRestrictiveKind = typeName; + detectedRestrictiveName = access.m_name; } + continue; } if (unknownBuiltins.contains(typeName)) return true; - auto findNextScope = [&](const QHash<QString, ScopeTree::Ptr> &types) { - const auto it = types.find(typeName); - if (it == types.end()) { - detectedRestrictiveKind = typeName; - detectedRestrictiveName = access.m_name; - scope = nullptr; - } else { - scope = *it; - } - }; + const auto it = m_types.qmlNames.find(typeName); + if (it == m_types.qmlNames.end()) { + detectedRestrictiveKind = typeName; + detectedRestrictiveName = access.m_name; + scope = nullptr; + } else { + scope = *it; + } - if (access.m_parentType.isEmpty() && scope->isComposite()) - findNextScope(m_types.cppNames); - else - findNextScope(m_types.qmlNames); continue; } @@ -245,17 +237,11 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> & rootType = scope; bool typeFound = - walkViaParentAndAttachedScopes(rootType, m_types, [&](ScopeTree::ConstPtr type) { + walkViaParentAndAttachedScopes(rootType, [&](ScopeTree::ConstPtr type) { const auto typeProperties = type->properties(); const auto typeIt = typeProperties.find(access.m_name); if (typeIt != typeProperties.end()) { - const ScopeTree::ConstPtr propType = typeIt->type(); - if (propType) - scope = propType; - else if (scope->isComposite()) - scope = m_types.qmlNames.value(typeIt->typeName()); - else - scope = m_types.cppNames.value(typeIt->typeName()); + scope = typeIt->type(); return true; } @@ -276,9 +262,8 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> & // may be an attached type 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; + if (const auto attached = (*it)->attachedType()) { + scope = attached; continue; } } diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 74c70ce731..c7d3bb828d 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -118,7 +118,6 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiProgram *) if (!m_qmltypesFiles.isEmpty()) { const auto baseTypes = m_importer.importQmltypes(m_qmltypesFiles); 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 @@ -127,7 +126,6 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiProgram *) const auto imported = m_importer.importFileOrDirectory(QFileInfo(m_filePath).path()); m_rootScopeImports.qmlNames.insert(imported.qmlNames); - m_rootScopeImports.cppNames.insert(imported.cppNames); const QStringList warnings = m_importer.takeWarnings(); for (const QString &warning : warnings) { @@ -481,7 +479,6 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiImport *import) file.isRelative() ? QFileInfo(m_filePath).dir().filePath(filename) : filename, prefix); m_rootScopeImports.qmlNames.insert(imported.qmlNames); - m_rootScopeImports.cppNames.insert(imported.cppNames); } QString path {}; @@ -502,7 +499,6 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiImport *import) path, prefix, import->version ? import->version->version : QTypeRevision()); m_rootScopeImports.qmlNames.insert(imported.qmlNames); - m_rootScopeImports.cppNames.insert(imported.cppNames); const QStringList warnings = m_importer.takeWarnings(); for (const QString &warning : warnings) { |