aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-10-17 09:18:06 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-10-19 20:32:01 +0200
commite89a06753c772bd96b3299e03b2f7ad78ffc9fb9 (patch)
tree970133e681a0452ee3a1799925763d240d67030f
parent0f08e3e673ece32fc9ada041115a0df631b447f3 (diff)
Parser: Simplify argument "lists" for type annotations
There can in fact only be one type argument, and we don't need a finish() method. In fact the finish() method didn't return the type argument at all. Task-number: QTBUG-107171 Change-Id: Ifb7d85ca42a38d37da71b6453b458c7ec10cd64d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qml/parser/qqmljs.g28
-rw-r--r--src/qml/parser/qqmljsast.cpp24
-rw-r--r--src/qml/parser/qqmljsast_p.h65
-rw-r--r--src/qml/parser/qqmljsastfwd_p.h2
-rw-r--r--src/qml/parser/qqmljsastvisitor_p.h8
-rw-r--r--src/qmldom/qqmldomastcreator.cpp7
-rw-r--r--src/qmldom/qqmldomastdumper.cpp8
-rw-r--r--src/qmldom/qqmldomcomments.cpp4
-rw-r--r--src/qmldom/qqmldomreformatter.cpp8
9 files changed, 65 insertions, 89 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g
index afda0f27aa..181b49242a 100644
--- a/src/qml/parser/qqmljs.g
+++ b/src/qml/parser/qqmljs.g
@@ -212,7 +212,7 @@ public:
AST::ExportClause *ExportClause;
AST::ExportDeclaration *ExportDeclaration;
AST::TypeAnnotation *TypeAnnotation;
- AST::TypeArgumentList *TypeArgumentList;
+ AST::TypeArgument *TypeArgument;
AST::Type *Type;
AST::UiProgram *UiProgram;
@@ -1575,28 +1575,16 @@ BindingIdentifier: IdentifierReference;
-- Types
--------------------------------------------------------------------------------------------------------
-TypeArguments: Type;
+Type: UiQualifiedId T_LT SimpleType T_GT;
/.
case $rule_number: {
- sym(1).TypeArgumentList = new (pool) AST::TypeArgumentList(sym(1).Type);
+ sym(1).Type = new (pool) AST::Type(sym(1).UiQualifiedId, sym(3).Type);
} break;
./
-TypeArguments: TypeArguments T_COMMA Type;
-/.
- case $rule_number: {
- sym(1).TypeArgumentList = new (pool) AST::TypeArgumentList(sym(1).TypeArgumentList, sym(3).Type);
- } break;
-./
-
-Type: UiQualifiedId T_LT TypeArguments T_GT;
-/.
- case $rule_number: {
- sym(1).Type = new (pool) AST::Type(sym(1).UiQualifiedId, sym(3).TypeArgumentList->finish());
- } break;
-./
+Type: SimpleType;
-Type: T_RESERVED_WORD;
+SimpleType: T_RESERVED_WORD;
/.
case $rule_number: {
AST::UiQualifiedId *id = new (pool) AST::UiQualifiedId(stringRef(1));
@@ -1605,17 +1593,17 @@ Type: T_RESERVED_WORD;
} break;
./
-Type: UiQualifiedId;
+SimpleType: UiQualifiedId;
/.
case $rule_number: {
sym(1).Type = new (pool) AST::Type(sym(1).UiQualifiedId);
} break;
./
-Type: T_VAR;
+SimpleType: T_VAR;
/. case $rule_number: Q_FALLTHROUGH(); ./
-Type: T_VOID;
+SimpleType: T_VOID;
/.
case $rule_number: {
AST::UiQualifiedId *id = new (pool) AST::UiQualifiedId(stringRef(1));
diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp
index 1001fd976e..5408f29900 100644
--- a/src/qml/parser/qqmljsast.cpp
+++ b/src/qml/parser/qqmljsast.cpp
@@ -1311,17 +1311,7 @@ void Type::accept0(BaseVisitor *visitor)
{
if (visitor->visit(this)) {
accept(typeId, visitor);
- accept(typeArguments, visitor);
- }
-
- visitor->endVisit(this);
-}
-
-void TypeArgumentList::accept0(BaseVisitor *visitor)
-{
- if (visitor->visit(this)) {
- for (TypeArgumentList *it = this; it; it = it->next)
- accept(it->typeId, visitor);
+ accept(typeArgument, visitor);
}
visitor->endVisit(this);
@@ -1563,17 +1553,11 @@ QString Type::toString() const
void Type::toString(QString *out) const
{
- for (QQmlJS::AST::UiQualifiedId *it = typeId; it; it = it->next) {
- out->append(it->name);
-
- if (it->next)
- out->append(QLatin1Char('.'));
- }
+ typeId->toString(out);
- if (typeArguments) {
+ if (typeArgument) {
out->append(QLatin1Char('<'));
- if (auto subType = static_cast<TypeArgumentList*>(typeArguments)->typeId)
- subType->toString(out);
+ typeArgument->toString(out);
out->append(QLatin1Char('>'));
};
}
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index 3c2b50abd1..90a1199ce5 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -211,7 +211,7 @@ public:
Kind_PatternProperty,
Kind_PatternPropertyList,
Kind_Type,
- Kind_TypeArgumentList,
+ Kind_TypeArgument,
Kind_TypeAnnotation,
Kind_UiArrayBinding,
@@ -329,6 +329,22 @@ public:
SourceLocation lastSourceLocation() const override
{ return lastListElement(this)->identifierToken; }
+ QString toString() const
+ {
+ QString result;
+ toString(&result);
+ return result;
+ }
+
+ void toString(QString *out) const
+ {
+ for (const UiQualifiedId *it = this; it; it = it->next) {
+ out->append(it->name);
+ if (it->next)
+ out->append(QLatin1Char('.'));
+ }
+ }
+
// attributes
UiQualifiedId *next;
QStringView name;
@@ -340,9 +356,9 @@ class QML_PARSER_EXPORT Type: public Node
public:
QQMLJS_DECLARE_AST_NODE(Type)
- Type(UiQualifiedId *typeId, Node *typeArguments = nullptr)
+ Type(UiQualifiedId *typeId, Type *typeArgument = nullptr)
: typeId(typeId)
- , typeArguments(typeArguments)
+ , typeArgument(typeArgument ? typeArgument->typeId : nullptr)
{ kind = K; }
void accept0(BaseVisitor *visitor) override;
@@ -351,53 +367,14 @@ public:
{ return typeId->firstSourceLocation(); }
SourceLocation lastSourceLocation() const override
- { return typeArguments ? typeArguments->lastSourceLocation() : typeId->lastSourceLocation(); }
+ { return typeArgument ? typeArgument->lastSourceLocation() : typeId->lastSourceLocation(); }
QString toString() const;
void toString(QString *out) const;
// attributes
UiQualifiedId *typeId;
- Node *typeArguments; // TypeArgumentList
-};
-
-
-class QML_PARSER_EXPORT TypeArgumentList: public Node
-{
-public:
- QQMLJS_DECLARE_AST_NODE(TypeArgumentList)
-
- TypeArgumentList(Type *typeId)
- : typeId(typeId)
- , next(this)
- { kind = K; }
-
- TypeArgumentList(TypeArgumentList *previous, Type *typeId)
- : typeId(typeId)
- {
- kind = K;
- next = previous->next;
- previous->next = this;
- }
-
- void accept0(BaseVisitor *visitor) override;
-
- SourceLocation firstSourceLocation() const override
- { return typeId->firstSourceLocation(); }
-
- SourceLocation lastSourceLocation() const override
- { return lastListElement(this)->typeId->lastSourceLocation(); }
-
- inline TypeArgumentList *finish()
- {
- TypeArgumentList *front = next;
- next = nullptr;
- return front;
- }
-
-// attributes
- Type *typeId;
- TypeArgumentList *next;
+ UiQualifiedId *typeArgument;
};
class QML_PARSER_EXPORT TypeAnnotation: public Node
diff --git a/src/qml/parser/qqmljsastfwd_p.h b/src/qml/parser/qqmljsastfwd_p.h
index dabcdef9e3..e06da8b4c1 100644
--- a/src/qml/parser/qqmljsastfwd_p.h
+++ b/src/qml/parser/qqmljsastfwd_p.h
@@ -122,7 +122,7 @@ class NestedExpression;
class ClassExpression;
class ClassDeclaration;
class ClassElementList;
-class TypeArgumentList;
+class TypeArgument;
class Type;
class TypeAnnotation;
diff --git a/src/qml/parser/qqmljsastvisitor_p.h b/src/qml/parser/qqmljsastvisitor_p.h
index e749f4a509..450cfaad40 100644
--- a/src/qml/parser/qqmljsastvisitor_p.h
+++ b/src/qml/parser/qqmljsastvisitor_p.h
@@ -378,8 +378,8 @@ public:
virtual bool visit(Type *) = 0;
virtual void endVisit(Type *) = 0;
- virtual bool visit(TypeArgumentList *) = 0;
- virtual void endVisit(TypeArgumentList *) = 0;
+ virtual bool visit(TypeArgument *) = 0;
+ virtual void endVisit(TypeArgument *) = 0;
virtual bool visit(TypeAnnotation *) = 0;
virtual void endVisit(TypeAnnotation *) = 0;
@@ -722,8 +722,8 @@ public:
bool visit(Type *) override { return true; }
void endVisit(Type *) override {}
- bool visit(TypeArgumentList *) override { return true; }
- void endVisit(TypeArgumentList *) override {}
+ bool visit(TypeArgument *) override { return true; }
+ void endVisit(TypeArgument *) override {}
bool visit(TypeAnnotation *) override { return true; }
void endVisit(TypeAnnotation *) override {}
diff --git a/src/qmldom/qqmldomastcreator.cpp b/src/qmldom/qqmldomastcreator.cpp
index 68df2e0388..9378483216 100644
--- a/src/qmldom/qqmldomastcreator.cpp
+++ b/src/qmldom/qqmldomastcreator.cpp
@@ -71,6 +71,11 @@ static QString typeToString(AST::Type *t)
{
Q_ASSERT(t);
QString res = toString(t->typeId);
+
+#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
+ if (UiQualifiedId *arg = t->typeArgument)
+ res += u'<' + toString(arg) + u'>';
+#else
if (!t->typeArguments)
return res;
res += u"<";
@@ -84,6 +89,8 @@ static QString typeToString(AST::Type *t)
res += typeToString(tt->typeId);
}
res += u">";
+#endif
+
return res;
}
diff --git a/src/qmldom/qqmldomastdumper.cpp b/src/qmldom/qqmldomastdumper.cpp
index 3150c05bc5..9eaf88a3c8 100644
--- a/src/qmldom/qqmldomastdumper.cpp
+++ b/src/qmldom/qqmldomastdumper.cpp
@@ -990,11 +990,19 @@ public:
}
void endVisit(AST::Type *) override { stop(u"Type"); }
+#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
+ bool visit(AST::TypeArgument *) override {
+ start(u"TypeArgument");
+ return true;
+ }
+ void endVisit(AST::TypeArgument *) override { stop(u"TypeArgument"); }
+#else
bool visit(AST::TypeArgumentList *) override {
start(u"TypeArgumentList");
return true;
}
void endVisit(AST::TypeArgumentList *) override { stop(u"TypeArgumentList"); }
+#endif
bool visit(AST::TypeAnnotation *el) override {
start(QLatin1String("TypeAnnotation colonToken=%1")
diff --git a/src/qmldom/qqmldomcomments.cpp b/src/qmldom/qqmldomcomments.cpp
index 257916cffa..fe883cb53e 100644
--- a/src/qmldom/qqmldomcomments.cpp
+++ b/src/qmldom/qqmldomcomments.cpp
@@ -419,7 +419,11 @@ const QSet<int> AstRangesVisitor::kindsToSkip()
AST::Node::Kind_ClassElementList,
AST::Node::Kind_PatternElementList,
AST::Node::Kind_PatternPropertyList,
+#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
+ AST::Node::Kind_TypeArgument,
+#else
AST::Node::Kind_TypeArgumentList,
+#endif
})
.unite(VisitAll::uiKinds());
return res;
diff --git a/src/qmldom/qqmldomreformatter.cpp b/src/qmldom/qqmldomreformatter.cpp
index bb76f8f772..6c495bc5ec 100644
--- a/src/qmldom/qqmldomreformatter.cpp
+++ b/src/qmldom/qqmldomreformatter.cpp
@@ -992,7 +992,11 @@ protected:
bool visit(ESModule *) override { return true; }
bool visit(DebuggerStatement *) override { return true; }
bool visit(Type *) override { return true; }
+#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
+ bool visit(TypeArgument *) override { return true; }
+#else
bool visit(TypeArgumentList *) override { return true; }
+#endif
bool visit(TypeAnnotation *) override { return true; }
// overridden to use BasicVisitor (and ensure warnings about new added AST)
@@ -1109,7 +1113,11 @@ protected:
void endVisit(ESModule *) override { }
void endVisit(DebuggerStatement *) override { }
void endVisit(Type *) override { }
+#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
+ void endVisit(TypeArgument *) override { }
+#else
void endVisit(TypeArgumentList *) override { }
+#endif
void endVisit(TypeAnnotation *) override { }
void throwRecursionDepthError() override