aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
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 /src/qml
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>
Diffstat (limited to 'src/qml')
-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
5 files changed, 38 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 {}