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>
This commit is contained in:
parent
0f08e3e673
commit
e89a06753c
|
@ -212,7 +212,7 @@ public:
|
||||||
AST::ExportClause *ExportClause;
|
AST::ExportClause *ExportClause;
|
||||||
AST::ExportDeclaration *ExportDeclaration;
|
AST::ExportDeclaration *ExportDeclaration;
|
||||||
AST::TypeAnnotation *TypeAnnotation;
|
AST::TypeAnnotation *TypeAnnotation;
|
||||||
AST::TypeArgumentList *TypeArgumentList;
|
AST::TypeArgument *TypeArgument;
|
||||||
AST::Type *Type;
|
AST::Type *Type;
|
||||||
|
|
||||||
AST::UiProgram *UiProgram;
|
AST::UiProgram *UiProgram;
|
||||||
|
@ -1575,28 +1575,16 @@ BindingIdentifier: IdentifierReference;
|
||||||
-- Types
|
-- Types
|
||||||
--------------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
TypeArguments: Type;
|
Type: UiQualifiedId T_LT SimpleType T_GT;
|
||||||
/.
|
/.
|
||||||
case $rule_number: {
|
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;
|
} break;
|
||||||
./
|
./
|
||||||
|
|
||||||
TypeArguments: TypeArguments T_COMMA Type;
|
Type: SimpleType;
|
||||||
/.
|
|
||||||
case $rule_number: {
|
|
||||||
sym(1).TypeArgumentList = new (pool) AST::TypeArgumentList(sym(1).TypeArgumentList, sym(3).Type);
|
|
||||||
} break;
|
|
||||||
./
|
|
||||||
|
|
||||||
Type: UiQualifiedId T_LT TypeArguments T_GT;
|
SimpleType: T_RESERVED_WORD;
|
||||||
/.
|
|
||||||
case $rule_number: {
|
|
||||||
sym(1).Type = new (pool) AST::Type(sym(1).UiQualifiedId, sym(3).TypeArgumentList->finish());
|
|
||||||
} break;
|
|
||||||
./
|
|
||||||
|
|
||||||
Type: T_RESERVED_WORD;
|
|
||||||
/.
|
/.
|
||||||
case $rule_number: {
|
case $rule_number: {
|
||||||
AST::UiQualifiedId *id = new (pool) AST::UiQualifiedId(stringRef(1));
|
AST::UiQualifiedId *id = new (pool) AST::UiQualifiedId(stringRef(1));
|
||||||
|
@ -1605,17 +1593,17 @@ Type: T_RESERVED_WORD;
|
||||||
} break;
|
} break;
|
||||||
./
|
./
|
||||||
|
|
||||||
Type: UiQualifiedId;
|
SimpleType: UiQualifiedId;
|
||||||
/.
|
/.
|
||||||
case $rule_number: {
|
case $rule_number: {
|
||||||
sym(1).Type = new (pool) AST::Type(sym(1).UiQualifiedId);
|
sym(1).Type = new (pool) AST::Type(sym(1).UiQualifiedId);
|
||||||
} break;
|
} break;
|
||||||
./
|
./
|
||||||
|
|
||||||
Type: T_VAR;
|
SimpleType: T_VAR;
|
||||||
/. case $rule_number: Q_FALLTHROUGH(); ./
|
/. case $rule_number: Q_FALLTHROUGH(); ./
|
||||||
|
|
||||||
Type: T_VOID;
|
SimpleType: T_VOID;
|
||||||
/.
|
/.
|
||||||
case $rule_number: {
|
case $rule_number: {
|
||||||
AST::UiQualifiedId *id = new (pool) AST::UiQualifiedId(stringRef(1));
|
AST::UiQualifiedId *id = new (pool) AST::UiQualifiedId(stringRef(1));
|
||||||
|
|
|
@ -1311,17 +1311,7 @@ void Type::accept0(BaseVisitor *visitor)
|
||||||
{
|
{
|
||||||
if (visitor->visit(this)) {
|
if (visitor->visit(this)) {
|
||||||
accept(typeId, visitor);
|
accept(typeId, visitor);
|
||||||
accept(typeArguments, visitor);
|
accept(typeArgument, 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visitor->endVisit(this);
|
visitor->endVisit(this);
|
||||||
|
@ -1563,17 +1553,11 @@ QString Type::toString() const
|
||||||
|
|
||||||
void Type::toString(QString *out) const
|
void Type::toString(QString *out) const
|
||||||
{
|
{
|
||||||
for (QQmlJS::AST::UiQualifiedId *it = typeId; it; it = it->next) {
|
typeId->toString(out);
|
||||||
out->append(it->name);
|
|
||||||
|
|
||||||
if (it->next)
|
if (typeArgument) {
|
||||||
out->append(QLatin1Char('.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeArguments) {
|
|
||||||
out->append(QLatin1Char('<'));
|
out->append(QLatin1Char('<'));
|
||||||
if (auto subType = static_cast<TypeArgumentList*>(typeArguments)->typeId)
|
typeArgument->toString(out);
|
||||||
subType->toString(out);
|
|
||||||
out->append(QLatin1Char('>'));
|
out->append(QLatin1Char('>'));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,7 @@ public:
|
||||||
Kind_PatternProperty,
|
Kind_PatternProperty,
|
||||||
Kind_PatternPropertyList,
|
Kind_PatternPropertyList,
|
||||||
Kind_Type,
|
Kind_Type,
|
||||||
Kind_TypeArgumentList,
|
Kind_TypeArgument,
|
||||||
Kind_TypeAnnotation,
|
Kind_TypeAnnotation,
|
||||||
|
|
||||||
Kind_UiArrayBinding,
|
Kind_UiArrayBinding,
|
||||||
|
@ -329,6 +329,22 @@ public:
|
||||||
SourceLocation lastSourceLocation() const override
|
SourceLocation lastSourceLocation() const override
|
||||||
{ return lastListElement(this)->identifierToken; }
|
{ 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
|
// attributes
|
||||||
UiQualifiedId *next;
|
UiQualifiedId *next;
|
||||||
QStringView name;
|
QStringView name;
|
||||||
|
@ -340,9 +356,9 @@ class QML_PARSER_EXPORT Type: public Node
|
||||||
public:
|
public:
|
||||||
QQMLJS_DECLARE_AST_NODE(Type)
|
QQMLJS_DECLARE_AST_NODE(Type)
|
||||||
|
|
||||||
Type(UiQualifiedId *typeId, Node *typeArguments = nullptr)
|
Type(UiQualifiedId *typeId, Type *typeArgument = nullptr)
|
||||||
: typeId(typeId)
|
: typeId(typeId)
|
||||||
, typeArguments(typeArguments)
|
, typeArgument(typeArgument ? typeArgument->typeId : nullptr)
|
||||||
{ kind = K; }
|
{ kind = K; }
|
||||||
|
|
||||||
void accept0(BaseVisitor *visitor) override;
|
void accept0(BaseVisitor *visitor) override;
|
||||||
|
@ -351,53 +367,14 @@ public:
|
||||||
{ return typeId->firstSourceLocation(); }
|
{ return typeId->firstSourceLocation(); }
|
||||||
|
|
||||||
SourceLocation lastSourceLocation() const override
|
SourceLocation lastSourceLocation() const override
|
||||||
{ return typeArguments ? typeArguments->lastSourceLocation() : typeId->lastSourceLocation(); }
|
{ return typeArgument ? typeArgument->lastSourceLocation() : typeId->lastSourceLocation(); }
|
||||||
|
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
void toString(QString *out) const;
|
void toString(QString *out) const;
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
UiQualifiedId *typeId;
|
UiQualifiedId *typeId;
|
||||||
Node *typeArguments; // TypeArgumentList
|
UiQualifiedId *typeArgument;
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QML_PARSER_EXPORT TypeAnnotation: public Node
|
class QML_PARSER_EXPORT TypeAnnotation: public Node
|
||||||
|
|
|
@ -122,7 +122,7 @@ class NestedExpression;
|
||||||
class ClassExpression;
|
class ClassExpression;
|
||||||
class ClassDeclaration;
|
class ClassDeclaration;
|
||||||
class ClassElementList;
|
class ClassElementList;
|
||||||
class TypeArgumentList;
|
class TypeArgument;
|
||||||
class Type;
|
class Type;
|
||||||
class TypeAnnotation;
|
class TypeAnnotation;
|
||||||
|
|
||||||
|
|
|
@ -378,8 +378,8 @@ public:
|
||||||
virtual bool visit(Type *) = 0;
|
virtual bool visit(Type *) = 0;
|
||||||
virtual void endVisit(Type *) = 0;
|
virtual void endVisit(Type *) = 0;
|
||||||
|
|
||||||
virtual bool visit(TypeArgumentList *) = 0;
|
virtual bool visit(TypeArgument *) = 0;
|
||||||
virtual void endVisit(TypeArgumentList *) = 0;
|
virtual void endVisit(TypeArgument *) = 0;
|
||||||
|
|
||||||
virtual bool visit(TypeAnnotation *) = 0;
|
virtual bool visit(TypeAnnotation *) = 0;
|
||||||
virtual void endVisit(TypeAnnotation *) = 0;
|
virtual void endVisit(TypeAnnotation *) = 0;
|
||||||
|
@ -722,8 +722,8 @@ public:
|
||||||
bool visit(Type *) override { return true; }
|
bool visit(Type *) override { return true; }
|
||||||
void endVisit(Type *) override {}
|
void endVisit(Type *) override {}
|
||||||
|
|
||||||
bool visit(TypeArgumentList *) override { return true; }
|
bool visit(TypeArgument *) override { return true; }
|
||||||
void endVisit(TypeArgumentList *) override {}
|
void endVisit(TypeArgument *) override {}
|
||||||
|
|
||||||
bool visit(TypeAnnotation *) override { return true; }
|
bool visit(TypeAnnotation *) override { return true; }
|
||||||
void endVisit(TypeAnnotation *) override {}
|
void endVisit(TypeAnnotation *) override {}
|
||||||
|
|
|
@ -71,6 +71,11 @@ static QString typeToString(AST::Type *t)
|
||||||
{
|
{
|
||||||
Q_ASSERT(t);
|
Q_ASSERT(t);
|
||||||
QString res = toString(t->typeId);
|
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)
|
if (!t->typeArguments)
|
||||||
return res;
|
return res;
|
||||||
res += u"<";
|
res += u"<";
|
||||||
|
@ -84,6 +89,8 @@ static QString typeToString(AST::Type *t)
|
||||||
res += typeToString(tt->typeId);
|
res += typeToString(tt->typeId);
|
||||||
}
|
}
|
||||||
res += u">";
|
res += u">";
|
||||||
|
#endif
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -990,11 +990,19 @@ public:
|
||||||
}
|
}
|
||||||
void endVisit(AST::Type *) override { stop(u"Type"); }
|
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 {
|
bool visit(AST::TypeArgumentList *) override {
|
||||||
start(u"TypeArgumentList");
|
start(u"TypeArgumentList");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void endVisit(AST::TypeArgumentList *) override { stop(u"TypeArgumentList"); }
|
void endVisit(AST::TypeArgumentList *) override { stop(u"TypeArgumentList"); }
|
||||||
|
#endif
|
||||||
|
|
||||||
bool visit(AST::TypeAnnotation *el) override {
|
bool visit(AST::TypeAnnotation *el) override {
|
||||||
start(QLatin1String("TypeAnnotation colonToken=%1")
|
start(QLatin1String("TypeAnnotation colonToken=%1")
|
||||||
|
|
|
@ -419,7 +419,11 @@ const QSet<int> AstRangesVisitor::kindsToSkip()
|
||||||
AST::Node::Kind_ClassElementList,
|
AST::Node::Kind_ClassElementList,
|
||||||
AST::Node::Kind_PatternElementList,
|
AST::Node::Kind_PatternElementList,
|
||||||
AST::Node::Kind_PatternPropertyList,
|
AST::Node::Kind_PatternPropertyList,
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||||
|
AST::Node::Kind_TypeArgument,
|
||||||
|
#else
|
||||||
AST::Node::Kind_TypeArgumentList,
|
AST::Node::Kind_TypeArgumentList,
|
||||||
|
#endif
|
||||||
})
|
})
|
||||||
.unite(VisitAll::uiKinds());
|
.unite(VisitAll::uiKinds());
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -992,7 +992,11 @@ protected:
|
||||||
bool visit(ESModule *) override { return true; }
|
bool visit(ESModule *) override { return true; }
|
||||||
bool visit(DebuggerStatement *) override { return true; }
|
bool visit(DebuggerStatement *) override { return true; }
|
||||||
bool visit(Type *) 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; }
|
bool visit(TypeArgumentList *) override { return true; }
|
||||||
|
#endif
|
||||||
bool visit(TypeAnnotation *) override { return true; }
|
bool visit(TypeAnnotation *) override { return true; }
|
||||||
|
|
||||||
// overridden to use BasicVisitor (and ensure warnings about new added AST)
|
// overridden to use BasicVisitor (and ensure warnings about new added AST)
|
||||||
|
@ -1109,7 +1113,11 @@ protected:
|
||||||
void endVisit(ESModule *) override { }
|
void endVisit(ESModule *) override { }
|
||||||
void endVisit(DebuggerStatement *) override { }
|
void endVisit(DebuggerStatement *) override { }
|
||||||
void endVisit(Type *) override { }
|
void endVisit(Type *) override { }
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||||
|
void endVisit(TypeArgument *) override { }
|
||||||
|
#else
|
||||||
void endVisit(TypeArgumentList *) override { }
|
void endVisit(TypeArgumentList *) override { }
|
||||||
|
#endif
|
||||||
void endVisit(TypeAnnotation *) override { }
|
void endVisit(TypeAnnotation *) override { }
|
||||||
|
|
||||||
void throwRecursionDepthError() override
|
void throwRecursionDepthError() override
|
||||||
|
|
Loading…
Reference in New Issue