aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-09-25 10:13:26 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-09-25 15:21:41 +0200
commit5458f379ac5d5d88dd7f5ddeafd370dbeee3a436 (patch)
treec032ca45fff744cbe41b55c357a73b4a09eb057c
parent5a88c06665d5c0295691e216740210a5172fcc9e (diff)
ScopeTree: Remove the "name" property
It was rarely used and only caused confusion. Use internalName instead. Change-Id: I196b1d77db04a2cb6e3cd0447d34ce9bae0b9cd5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--tools/qmllint/checkidentifiers.cpp2
-rw-r--r--tools/qmllint/findwarnings.cpp9
-rw-r--r--tools/shared/qmljstypereader.cpp15
-rw-r--r--tools/shared/scopetree.cpp15
-rw-r--r--tools/shared/scopetree.h7
5 files changed, 25 insertions, 23 deletions
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index 79a861b4c7..c5897b1df3 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -137,7 +137,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &
return false;
}
- const QString scopeName = scope->name().isEmpty() ? scope->internalName() : scope->name();
+ const QString scopeName = scope->internalName();
if (!detectedRestrictiveKind.isEmpty()) {
if (expectedNext.contains(access.m_name)) {
diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp
index 3877379a3b..3caf72633a 100644
--- a/tools/qmllint/findwarnings.cpp
+++ b/tools/qmllint/findwarnings.cpp
@@ -60,7 +60,8 @@ static QQmlDirParser createQmldirParserForFile(const QString &filename)
void FindWarningVisitor::enterEnvironment(ScopeType type, const QString &name)
{
- m_currentScope = ScopeTree::create(type, name, m_currentScope);
+ m_currentScope = ScopeTree::create(type, m_currentScope);
+ m_currentScope->setInternalName(name);
}
void FindWarningVisitor::leaveEnvironment()
@@ -484,7 +485,6 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiScriptBinding *uisb)
// found id
auto expstat = cast<ExpressionStatement *>(uisb->statement);
auto identexp = cast<IdentifierExpression *>(expstat->expression);
- QString elementName = m_currentScope->name();
m_qmlid2scope.insert(identexp->name.toString(), m_currentScope);
if (m_currentScope->isVisualRootScope())
m_rootId = identexp->name.toString();
@@ -564,7 +564,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::IdentifierExpression *idexp)
FindWarningVisitor::FindWarningVisitor(
QStringList qmltypeDirs, QStringList qmltypesFiles, QString code, QString fileName,
bool silent, bool warnUnqualified, bool warnWithStatement, bool warnInheritanceCycle)
- : m_rootScope(ScopeTree::create(ScopeType::JSFunctionScope, "global")),
+ : m_rootScope(ScopeTree::create(ScopeType::JSFunctionScope)),
m_qmltypesFiles(std::move(qmltypesFiles)),
m_code(std::move(code)),
m_rootId(QLatin1String("<id>")),
@@ -575,6 +575,7 @@ FindWarningVisitor::FindWarningVisitor(
m_warnInheritanceCycle(warnInheritanceCycle),
m_importer(QFileInfo(m_filePath).path(), qmltypeDirs)
{
+ m_rootScope->setInternalName("global");
m_currentScope = m_rootScope;
// setup color output
@@ -810,7 +811,7 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectDefinition *uiod)
do {
scope = scope->parentScope(); // TODO: rename method
} while (scope->scopeType() != ScopeType::QMLScope);
- targetScope = m_rootScopeImports.value(scope->name());
+ targetScope = m_rootScopeImports.value(scope->internalName());
} else {
// there was a target, check if we already can find it
auto scopeIt = m_qmlid2scope.find(target);
diff --git a/tools/shared/qmljstypereader.cpp b/tools/shared/qmljstypereader.cpp
index 527dba4535..4adacf96b4 100644
--- a/tools/shared/qmljstypereader.cpp
+++ b/tools/shared/qmljstypereader.cpp
@@ -69,7 +69,8 @@ static QList<QmlJSTypeReader::Import> parseHeaders(QQmlJS::AST::UiHeaderItemList
static ScopeTree::Ptr parseProgram(QQmlJS::AST::Program *program, const QString &name)
{
using namespace QQmlJS::AST;
- ScopeTree::Ptr result = ScopeTree::create(ScopeType::JSLexicalScope, name);
+ ScopeTree::Ptr result = ScopeTree::create(ScopeType::JSLexicalScope);
+ result->setInternalName(name);
for (auto *statement = program->statements; statement; statement = statement->next) {
if (auto *function = cast<FunctionDeclaration *>(statement->statement)) {
MetaMethod method(function->name.toString());
@@ -99,8 +100,10 @@ ScopeTree::Ptr QmlJSTypeReader::operator()()
QFile file(m_file);
if (!file.open(QFile::ReadOnly)) {
- return ScopeTree::create(isJavaScript ? ScopeType::JSLexicalScope : ScopeType::QMLScope,
- scopeName);
+ ScopeTree::Ptr result = ScopeTree::create(
+ isJavaScript ? ScopeType::JSLexicalScope : ScopeType::QMLScope);
+ result->setInternalName(scopeName);
+ return result;
}
QString code = QString::fromUtf8(file.readAll());
@@ -113,8 +116,10 @@ ScopeTree::Ptr QmlJSTypeReader::operator()()
: parser.parseProgram())
: parser.parse();
if (!success) {
- return ScopeTree::create(isJavaScript ? ScopeType::JSLexicalScope : ScopeType::QMLScope,
- scopeName);
+ ScopeTree::Ptr result = ScopeTree::create(
+ isJavaScript ? ScopeType::JSLexicalScope : ScopeType::QMLScope);
+ result->setInternalName(scopeName);
+ return result;
}
if (!isJavaScript) {
diff --git a/tools/shared/scopetree.cpp b/tools/shared/scopetree.cpp
index ea5175d2d6..6cbabf4b51 100644
--- a/tools/shared/scopetree.cpp
+++ b/tools/shared/scopetree.cpp
@@ -33,18 +33,17 @@
#include <algorithm>
-ScopeTree::ScopeTree(ScopeType type, const QString &name, const ScopeTree::Ptr &parentScope)
- : m_parentScope(parentScope), m_name(name), m_scopeType(type) {}
+ScopeTree::ScopeTree(ScopeType type, const ScopeTree::Ptr &parentScope)
+ : m_parentScope(parentScope), m_scopeType(type) {}
-ScopeTree::Ptr ScopeTree::create(ScopeType type, const QString &name,
- const ScopeTree::Ptr &parentScope)
+ScopeTree::Ptr ScopeTree::create(ScopeType type, const ScopeTree::Ptr &parentScope)
{
- ScopeTree::Ptr childScope(new ScopeTree{type, name, parentScope});
+ ScopeTree::Ptr childScope(new ScopeTree{type, parentScope});
if (parentScope) {
Q_ASSERT(type != ScopeType::QMLScope
|| !parentScope->m_parentScope
|| parentScope->parentScope()->m_scopeType == ScopeType::QMLScope
- || parentScope->parentScope()->m_name == QLatin1String("global"));
+ || parentScope->parentScope()->m_internalName == QLatin1String("global"));
parentScope->m_childScopes.push_back(childScope);
}
return childScope;
@@ -168,8 +167,8 @@ void ScopeTree::updateParentProperty(const ScopeTree::ConstPtr &scope)
{
auto it = m_properties.find(QLatin1String("parent"));
if (it != m_properties.end()
- && scope->name() != QLatin1String("Component")
- && scope->name() != QLatin1String("program"))
+ && scope->internalName() != QLatin1String("Component")
+ && scope->internalName() != QLatin1String("program"))
it->setType(scope);
}
diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h
index f505ed7457..9c16f6b05f 100644
--- a/tools/shared/scopetree.h
+++ b/tools/shared/scopetree.h
@@ -109,7 +109,7 @@ public:
int m_metaObjectRevision = 0;
};
- static ScopeTree::Ptr create(ScopeType type = ScopeType::QMLScope, const QString &name = QString(),
+ static ScopeTree::Ptr create(ScopeType type = ScopeType::QMLScope,
const ScopeTree::Ptr &parentScope = ScopeTree::Ptr());
static ScopeTree::ConstPtr findCurrentQMLScope(const ScopeTree::ConstPtr &scope);
@@ -129,7 +129,6 @@ public:
const QQmlJS::SourceLocation &location);
bool isVisualRootScope() const;
- QString name() const { return m_name; }
ScopeType scopeType() const { return m_scopeType; }
@@ -209,8 +208,7 @@ public:
}
private:
- ScopeTree(ScopeType type, const QString &name = QString(),
- const ScopeTree::Ptr &parentScope = ScopeTree::Ptr());
+ ScopeTree(ScopeType type, const ScopeTree::Ptr &parentScope = ScopeTree::Ptr());
QSet<QString> m_jsIdentifiers;
QMultiHash<QString, MethodUsage> m_injectedSignalIdentifiers;
@@ -226,7 +224,6 @@ private:
ScopeTree::WeakPtr m_parentScope;
QString m_fileName;
- QString m_name;
QString m_internalName;
QString m_baseTypeName;