diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-13 13:40:56 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-18 08:54:47 +0100 |
commit | df179c52ec02aec91058d6977e08a405932af2bd (patch) | |
tree | 8415bb0adb85ecdfe43e2f0cd8182acb76c45dd9 /src/qmlcompiler/qqmljsscope.cpp | |
parent | 7e3f5f2224ba0e57a9dffa6251bb002cde564f56 (diff) |
QmlCompiler: Fix resolution of method and property types
We need to resolve the types for QML elements in two passes because only
after finishing the parsing we have the QML-declared methods and
properties available. We already need the base type before, though.
Also, there can be multiple methods of the same name. We need API to
access them.
It also turns out that the internal name of the "var" type has to be
QVariant in order to match reality. "var" properties and unnamed
arguments to JS functions are implemented as QVariant.
Change-Id: I541f11e96db72d832f4e4443d3a5d31079a56575
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsscope.cpp')
-rw-r--r-- | src/qmlcompiler/qqmljsscope.cpp | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/src/qmlcompiler/qqmljsscope.cpp b/src/qmlcompiler/qqmljsscope.cpp index 388de620b0..202e292838 100644 --- a/src/qmlcompiler/qqmljsscope.cpp +++ b/src/qmlcompiler/qqmljsscope.cpp @@ -85,14 +85,12 @@ bool QQmlJSScope::hasMethod(const QString &name) const return false; } -QQmlJSMetaMethod QQmlJSScope::method(const QString &name) const +QList<QQmlJSMetaMethod> QQmlJSScope::methods(const QString &name) const { - for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) { - const auto it = scope->m_methods.find(name); - if (it != scope->m_methods.end()) - return *it; - } - return {}; + QList<QQmlJSMetaMethod> results; + for (const QQmlJSScope *scope = this; scope; scope = scope->baseType().data()) + results.append(scope->ownMethods(name)); + return results; } bool QQmlJSScope::isIdInCurrentQMlScopes(const QString &id) const @@ -150,20 +148,37 @@ void QQmlJSScope::resolveTypes(const QHash<QString, QQmlJSScope::ConstPtr> &cont return QQmlJSScope::ConstPtr(); }; - m_baseType = findType(m_baseTypeName); - m_attachedType = findType(m_attachedTypeName); - m_valueType = findType(m_valueTypeName); + if (!m_baseType && !m_baseTypeName.isEmpty()) + m_baseType = findType(m_baseTypeName); - for (auto it = m_properties.begin(), end = m_properties.end(); it != end; ++it) - it->setType(findType(it->typeName())); + if (!m_attachedType && !m_attachedTypeName.isEmpty()) + m_attachedType = findType(m_attachedTypeName); - for (auto it = m_methods.begin(), end = m_methods.end(); it != end; ++it) { - it->setReturnType(findType(it->returnTypeName())); - const auto paramNames = it->parameterTypeNames(); - QList<QSharedPointer<const QQmlJSScope>> paramTypes; + if (!m_valueType && !m_valueTypeName.isEmpty()) + m_valueType = findType(m_valueTypeName); - for (const QString ¶mName: paramNames) - paramTypes.append(findType(paramName)); + for (auto it = m_properties.begin(), end = m_properties.end(); it != end; ++it) { + const QString typeName = it->typeName(); + if (!it->type() && !typeName.isEmpty()) + it->setType(findType(typeName)); + } + + for (auto it = m_methods.begin(), end = m_methods.end(); it != end; ++it) { + const QString returnTypeName = it->returnTypeName(); + if (!it->returnType() && !returnTypeName.isEmpty()) + it->setReturnType(findType(returnTypeName)); + + const auto paramTypeNames = it->parameterTypeNames(); + QList<QSharedPointer<const QQmlJSScope>> paramTypes = it->parameterTypes(); + if (paramTypes.length() < paramTypeNames.length()) + paramTypes.resize(paramTypeNames.length()); + + for (int i = 0, length = paramTypes.length(); i < length; ++i) { + auto ¶mType = paramTypes[i]; + const auto paramTypeName = paramTypeNames[i]; + if (!paramType && !paramTypeName.isEmpty()) + paramType = findType(paramTypeName); + } it->setParameterTypes(paramTypes); } |