diff options
Diffstat (limited to 'src/libs/qmljs/parser/qmljsast.cpp')
-rw-r--r-- | src/libs/qmljs/parser/qmljsast.cpp | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/src/libs/qmljs/parser/qmljsast.cpp b/src/libs/qmljs/parser/qmljsast.cpp index af12c480d3..fd99d9e4d5 100644 --- a/src/libs/qmljs/parser/qmljsast.cpp +++ b/src/libs/qmljs/parser/qmljsast.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -23,11 +23,11 @@ ** ****************************************************************************/ +#include <QLocale> #include "qmljsast_p.h" #include "qmljsastvisitor_p.h" - -#include <QLocale> +#include <qlocale.h> QT_QML_BEGIN_NAMESPACE @@ -104,6 +104,44 @@ ExpressionNode *ExpressionNode::expressionCast() return this; } +bool ExpressionNode::containsOptionalChain() const +{ + for (const Node *node = this;;) { + switch (node->kind) { + case Kind_FieldMemberExpression: { + const auto *fme = AST::cast<const FieldMemberExpression*>(node); + if (fme->isOptional) + return true; + node = fme->base; + break; + } + case Kind_ArrayMemberExpression: { + const auto *ame = AST::cast<const ArrayMemberExpression*>(node); + if (ame->isOptional) + return true; + node = ame->base; + break; + } + case Kind_CallExpression: { + const auto *ce = AST::cast<const CallExpression*>(node); + if (ce->isOptional) + return true; + node = ce->base; + break; + } + case Kind_NestedExpression: { + const auto *ne = AST::cast<const NestedExpression*>(node); + node = ne->expression; + break; + } + default: + // These unhandled nodes lead to invalid lvalues anyway, so they do not need to be handled here. + return false; + } + } + return false; +} + FormalParameterList *ExpressionNode::reparseAsFormalParameterList(MemoryPool *pool) { AST::ExpressionNode *expr = this; @@ -145,6 +183,12 @@ BinaryExpression *BinaryExpression::binaryExpressionCast() return this; } +void TypeExpression::accept0(BaseVisitor *visitor) +{ + visitor->visit(this); + visitor->endVisit(this); +} + Statement *Statement::statementCast() { return this; @@ -989,7 +1033,13 @@ BoundNames FormalParameterList::formals() const // change the name of the earlier argument to enforce the lookup semantics from the spec formals[duplicateIndex].id += QLatin1String("#") + QString::number(i); } - formals += {name, it->element->typeAnnotation}; + formals += { + name, + it->element->typeAnnotation, + it->element->isInjectedSignalParameter + ? BoundName::Injected + : BoundName::Declared + }; } ++i; } @@ -1392,7 +1442,8 @@ void PatternElement::boundNames(BoundNames *names) else if (PatternPropertyList *p = propertyList()) p->boundNames(names); } else { - names->append({bindingIdentifier.toString(), typeAnnotation}); + names->append({bindingIdentifier.toString(), typeAnnotation, + isInjectedSignalParameter ? BoundName::Injected : BoundName::Declared}); } } @@ -1531,7 +1582,7 @@ QString Type::toString() const void Type::toString(QString *out) const { for (QmlJS::AST::UiQualifiedId *it = typeId; it; it = it->next) { - out->append(it->name.toString()); + out->append(it->name); if (it->next) out->append(QLatin1Char('.')); |