aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsscope.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-01-20 14:20:48 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-01-21 08:45:16 +0100
commit39944e8467e5e5d4457e9fec202413adf0fbb2d2 (patch)
treeabf0b4dd17837649a42e0860be754f4f321d9aca /src/qmlcompiler/qqmljsscope.cpp
parent90be89d771425044a84e9e79e4e668e065acc825 (diff)
qmllint: Remove exceptions for most unknown builtins
All those types are properly defined in the qmltypes files now. We just need to search the enumerations the same way as methods and properties in order to find everything. Also, deduplicate the code that resolves properties, methods, and enums by using a common template for iterating the scopes. Change-Id: I0bf1423974d0ec8f602ecd0342522b3e981a8586 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsscope.cpp')
-rw-r--r--src/qmlcompiler/qqmljsscope.cpp127
1 files changed, 73 insertions, 54 deletions
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp
index 5bca7ffcd4..11a2b4a619 100644
--- a/src/qmlcompiler/qqmljsscope.cpp
+++ b/src/qmlcompiler/qqmljsscope.cpp
@@ -38,6 +38,30 @@
QT_BEGIN_NAMESPACE
+template<typename Action>
+static bool searchBaseAndExtensionTypes(const QQmlJSScope *type, const Action &check)
+{
+ const QQmlJSScope *nonCompositeBase = nullptr;
+ for (const QQmlJSScope *scope = type; scope; scope = scope->baseType().data()) {
+ if (check(scope))
+ return true;
+
+ if (!nonCompositeBase && !scope->isComposite())
+ nonCompositeBase = scope;
+ }
+
+ if (!nonCompositeBase)
+ return false;
+
+ for (const QQmlJSScope *scope = nonCompositeBase->extensionType().data(); scope;
+ scope = scope->baseType().data()) {
+ if (check(scope))
+ return true;
+ }
+
+ return false;
+}
+
QQmlJSScope::QQmlJSScope(ScopeType type, const QQmlJSScope::Ptr &parentScope)
: m_parentScope(parentScope), m_scopeType(type) {}
@@ -78,39 +102,53 @@ bool QQmlJSScope::isIdInCurrentScope(const QString &id) const
bool QQmlJSScope::hasMethod(const QString &name) const
{
- const QQmlJSScope *nonCompositeBase = isComposite() ? this : nullptr;
- for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) {
- if (scope->m_methods.contains(name))
- return true;
- if (!nonCompositeBase && !scope->isComposite())
- nonCompositeBase = scope;
- }
-
- if (nonCompositeBase && nonCompositeBase != this) {
- if (QQmlJSScope::ConstPtr extension = nonCompositeBase->extensionType())
- return extension->hasMethod(name);
- }
-
- return false;
+ return searchBaseAndExtensionTypes(this, [&](const QQmlJSScope *scope) {
+ return scope->m_methods.contains(name);
+ });
}
QList<QQmlJSMetaMethod> QQmlJSScope::methods(const QString &name) const
{
QList<QQmlJSMetaMethod> results;
- const QQmlJSScope *nonCompositeBase = isComposite() ? this : nullptr;
- for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) {
+ searchBaseAndExtensionTypes(this, [&](const QQmlJSScope *scope) {
results.append(scope->ownMethods(name));
- if (!nonCompositeBase && !scope->isComposite())
- nonCompositeBase = scope;
- }
+ return false;
+ });
+ return results;
+}
- if (nonCompositeBase && nonCompositeBase != this) {
- if (QQmlJSScope::ConstPtr extension = nonCompositeBase->extensionType())
- results.append(extension->methods(name));
- }
+bool QQmlJSScope::hasEnumeration(const QString &name) const
+{
+ return searchBaseAndExtensionTypes(this, [&](const QQmlJSScope *scope) {
+ return scope->m_enumerations.contains(name);
+ });
+}
- return results;
+bool QQmlJSScope::hasEnumerationKey(const QString &name) const
+{
+ return searchBaseAndExtensionTypes(this, [&](const QQmlJSScope *scope) {
+ for (const auto &e : scope->m_enumerations) {
+ if (e.keys().contains(name))
+ return true;
+ }
+ return false;
+ });
+}
+
+QQmlJSMetaEnum QQmlJSScope::enumeration(const QString &name) const
+{
+ QQmlJSMetaEnum result;
+
+ searchBaseAndExtensionTypes(this, [&](const QQmlJSScope *scope) {
+ const auto it = scope->m_enumerations.find(name);
+ if (it == scope->m_enumerations.end())
+ return false;
+ result = *it;
+ return true;
+ });
+
+ return result;
}
bool QQmlJSScope::isIdInCurrentQmlScopes(const QString &id) const
@@ -262,41 +300,22 @@ void QQmlJSScope::addExport(const QString &name, const QString &package,
bool QQmlJSScope::hasProperty(const QString &name) const
{
- const QQmlJSScope *nonCompositeBase = isComposite() ? this : nullptr;
- for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) {
- if (scope->m_properties.contains(name))
- return true;
-
- if (!nonCompositeBase && !scope->isComposite())
- nonCompositeBase = scope;
- }
-
- if (nonCompositeBase && nonCompositeBase != this) {
- if (QQmlJSScope::ConstPtr extension = nonCompositeBase->extensionType())
- return extension->hasProperty(name);
- }
-
- return false;
+ return searchBaseAndExtensionTypes(this, [&](const QQmlJSScope *scope) {
+ return scope->m_properties.contains(name);
+ });
}
QQmlJSMetaProperty QQmlJSScope::property(const QString &name) const
{
- const QQmlJSScope *nonCompositeBase = isComposite() ? this : nullptr;
- for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) {
+ QQmlJSMetaProperty prop;
+ searchBaseAndExtensionTypes(this, [&](const QQmlJSScope *scope) {
const auto it = scope->m_properties.find(name);
- if (it != scope->m_properties.end())
- return *it;
-
- if (!nonCompositeBase && !scope->isComposite())
- nonCompositeBase = scope;
- }
-
- if (nonCompositeBase && nonCompositeBase != this) {
- if (QQmlJSScope::ConstPtr extension = nonCompositeBase->extensionType())
- return extension->property(name);
- }
-
- return {};
+ if (it == scope->m_properties.end())
+ return false;
+ prop = *it;
+ return true;
+ });
+ return prop;
}
QQmlJSScope::Export::Export(QString package, QString type, const QTypeRevision &version) :