diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-25 09:50:09 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-25 15:21:41 +0200 |
commit | 5a88c06665d5c0295691e216740210a5172fcc9e (patch) | |
tree | 76d61e5749420afd57f7a01939502fc593afd9f3 /tools | |
parent | 88fd9c3996fd0280be639ad116ebc3a1b30ae0c4 (diff) |
qmllint: Clarify the meaning of the various names a scope can have
... and notice that they are misused everywhere.
Change-Id: I2254993dc5d11e967e7e83c6f0efb37fa17744be
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmllint/checkidentifiers.cpp | 4 | ||||
-rw-r--r-- | tools/qmllint/findwarnings.cpp | 10 | ||||
-rw-r--r-- | tools/shared/importedmembersvisitor.cpp | 6 | ||||
-rw-r--r-- | tools/shared/scopetree.h | 16 | ||||
-rw-r--r-- | tools/shared/typedescriptionreader.cpp | 10 |
5 files changed, 25 insertions, 21 deletions
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index 6f28709a87..79a861b4c7 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -98,7 +98,7 @@ static bool walkViaParentAndAttachedScopes(ScopeTree::ConstPtr rootType, if (visit(type)) return true; - if (auto superType = allTypes.value(type->superclassName())) + if (auto superType = allTypes.value(type->baseTypeName())) stack.push(superType); if (auto attachedType = allTypes.value(type->attachedTypeName())) @@ -137,7 +137,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> & return false; } - const QString scopeName = scope->name().isEmpty() ? scope->className() : scope->name(); + const QString scopeName = scope->name().isEmpty() ? scope->internalName() : scope->name(); if (!detectedRestrictiveKind.isEmpty()) { if (expectedNext.contains(access.m_name)) { diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 9686194c92..3877379a3b 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -156,7 +156,7 @@ void FindWarningVisitor::Importer::processImport( // add objects for (auto it = import.objects.begin(); it != import.objects.end(); ++it) { const auto &val = it.value(); - m_exportedName2Scope.insert(val->className(), val); + m_exportedName2Scope.insert(val->internalName(), val); const auto exports = val->exports(); for (const auto &valExport : exports) @@ -272,8 +272,8 @@ QHash<QString, ScopeTree::ConstPtr> FindWarningVisitor::Importer::importFileOrDi QDirIterator it { name, QStringList() << QLatin1String("*.qml"), QDir::NoFilter }; while (it.hasNext()) { ScopeTree::Ptr scope(localFile2ScopeTree(it.next())); - if (!scope->className().isEmpty()) - m_exportedName2Scope.insert(prefixedName(prefix, scope->className()), scope); + if (!scope->internalName().isEmpty()) + m_exportedName2Scope.insert(prefixedName(prefix, scope->internalName()), scope); } result.swap(m_exportedName2Scope); @@ -291,7 +291,7 @@ void FindWarningVisitor::importExportedNames(QStringView prefix, QString name) QString inheritenceCycle = name; for (const auto &seen: qAsConst(scopes)) { inheritenceCycle.append(QLatin1String(" -> ")); - inheritenceCycle.append(seen->superclassName()); + inheritenceCycle.append(seen->baseTypeName()); } @@ -314,7 +314,7 @@ void FindWarningVisitor::importExportedNames(QStringView prefix, QString name) } m_currentScope->addMethods(scope->methods()); - name = scope->superclassName(); + name = scope->baseTypeName(); if (name.isEmpty() || name == QLatin1String("QObject")) break; } else { diff --git a/tools/shared/importedmembersvisitor.cpp b/tools/shared/importedmembersvisitor.cpp index 0806e27aea..559c0533f7 100644 --- a/tools/shared/importedmembersvisitor.cpp +++ b/tools/shared/importedmembersvisitor.cpp @@ -35,8 +35,8 @@ ScopeTree::Ptr ImportedMembersVisitor::result(const QString &scopeName) const { ScopeTree::Ptr result = ScopeTree::create(); result->setIsComposite(true); - result->setClassName(scopeName); - result->setSuperclassName(m_rootObject->superclassName()); + result->setInternalName(scopeName); + result->setBaseTypeName(m_rootObject->baseTypeName()); const auto properties = m_rootObject->properties(); for (auto property : properties) { if (property.isAlias()) { @@ -67,7 +67,7 @@ bool ImportedMembersVisitor::visit(UiObjectDefinition *definition) superType.append(u'.'); superType.append(segment->name.toString()); } - scope->setSuperclassName(superType); + scope->setBaseTypeName(superType); if (!m_rootObject) m_rootObject = scope; m_currentObjects.append(scope); diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h index 08d529acc9..f505ed7457 100644 --- a/tools/shared/scopetree.h +++ b/tools/shared/scopetree.h @@ -143,15 +143,19 @@ public: QString fileName() const { return m_fileName; } void setFileName(const QString &file) { m_fileName = file; } - QString className() const { return m_className; } - void setClassName(const QString &name) { m_className = name; } + // The name the type uses to refer to itself. Either C++ class name or base name of + // QML file. isComposite tells us if this is a C++ or a QML name. + QString internalName() const { return m_internalName; } + void setInternalName(const QString &internalName) { m_internalName = internalName; } void addExport(const QString &name, const QString &package, const ComponentVersion &version); void setExportMetaObjectRevision(int exportIndex, int metaObjectRevision); QList<Export> exports() const { return m_exports; } - void setSuperclassName(const QString &superclass) { m_superName = superclass; } - QString superclassName() const { return m_superName; } + // If isComposite(), this is the QML/JS name of the prototype. Otherwise it's the + // relevant base class (in the hierarchy starting from QObject) of a C++ type. + void setBaseTypeName(const QString &baseTypeName) { m_baseTypeName = baseTypeName; } + QString baseTypeName() const { return m_baseTypeName; } void addProperty(const MetaProperty &prop) { m_properties.insert(prop.propertyName(), prop); } QHash<QString, MetaProperty> properties() const { return m_properties; } @@ -223,8 +227,8 @@ private: QString m_fileName; QString m_name; - QString m_className; - QString m_superName; + QString m_internalName; + QString m_baseTypeName; ScopeType m_scopeType = ScopeType::QMLScope; QList<Export> m_exports; diff --git a/tools/shared/typedescriptionreader.cpp b/tools/shared/typedescriptionreader.cpp index ae2e481397..717dbdf843 100644 --- a/tools/shared/typedescriptionreader.cpp +++ b/tools/shared/typedescriptionreader.cpp @@ -211,9 +211,9 @@ void TypeDescriptionReader::readComponent(UiObjectDefinition *ast) if (name == QLatin1String("file")) { scope->setFileName(readStringBinding(script)); } else if (name == QLatin1String("name")) { - scope->setClassName(readStringBinding(script)); + scope->setInternalName(readStringBinding(script)); } else if (name == QLatin1String("prototype")) { - scope->setSuperclassName(readStringBinding(script)); + scope->setBaseTypeName(readStringBinding(script)); } else if (name == QLatin1String("defaultProperty")) { scope->setDefaultPropertyName(readStringBinding(script)); } else if (name == QLatin1String("exports")) { @@ -252,14 +252,14 @@ void TypeDescriptionReader::readComponent(UiObjectDefinition *ast) } } - if (scope->className().isEmpty()) { + if (scope->internalName().isEmpty()) { addError(ast->firstSourceLocation(), tr("Component definition is missing a name binding.")); return; } // ### add implicit export into the package of c++ types - scope->addExport(scope->className(), QStringLiteral("<cpp>"), ComponentVersion()); - m_objects->insert(scope->className(), scope); + scope->addExport(scope->internalName(), QStringLiteral("<cpp>"), ComponentVersion()); + m_objects->insert(scope->internalName(), scope); } void TypeDescriptionReader::readSignalOrMethod(UiObjectDefinition *ast, bool isMethod, |