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/qqmljsimportvisitor.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/qqmljsimportvisitor.cpp')
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 41e8b4da88..0e16b02846 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -129,6 +129,7 @@ bool QQmlJSImportVisitor::visit(UiObjectDefinition *definition) void QQmlJSImportVisitor::endVisit(UiObjectDefinition *) { + m_currentScope->resolveTypes(m_rootScopeImports); m_currentScope->resolveGroupedScopes(); leaveEnvironment(); } @@ -178,13 +179,19 @@ void QQmlJSImportVisitor::visitFunctionExpressionHelper(QQmlJS::AST::FunctionExp auto name = fexpr->name.toString(); if (!name.isEmpty()) { if (m_currentScope->scopeType() == QQmlJSScope::QMLScope) { - QQmlJSMetaMethod method(name, QStringLiteral("void")); + QQmlJSMetaMethod method(name); method.setMethodType(QQmlJSMetaMethod::Method); - FormalParameterList *parameters = fexpr->formals; - while (parameters) { - method.addParameter(parameters->element->bindingIdentifier.toString(), QString()); - parameters = parameters->next; + if (const auto *formals = fexpr->formals) { + const auto parameters = formals->formals(); + for (const auto ¶meter : parameters) { + const QString type = parameter.typeName(); + method.addParameter(parameter.id, + type.isEmpty() ? QStringLiteral("var") : type); + } } + method.setReturnTypeName(fexpr->typeAnnotation + ? fexpr->typeAnnotation->type->toString() + : QStringLiteral("var")); m_currentScope->addOwnMethod(method); } else { m_currentScope->insertJSIdentifier( @@ -487,6 +494,7 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiObjectBinding *uiob) void QQmlJSImportVisitor::endVisit(QQmlJS::AST::UiObjectBinding *uiob) { + m_currentScope->resolveTypes(m_rootScopeImports); m_currentScope->resolveGroupedScopes(); const QQmlJSScope::ConstPtr childScope = m_currentScope; leaveEnvironment(); |