[AST] Simplify construction of EnumElementPattern

Add `EnumElementPattern::create` and
`EnumElementPattern::createImplicit`, and replace
existing constructions with them.
This commit is contained in:
Hamish Knight
2024-07-06 22:56:30 +01:00
parent 1490a27dec
commit fe68fab1e2
9 changed files with 101 additions and 103 deletions

View File

@@ -214,12 +214,9 @@ deriveBodyCodingKey_enum_stringValue(AbstractFunctionDecl *strValDecl, void *) {
} else {
SmallVector<ASTNode, 4> cases;
for (auto *elt : elements) {
auto *baseTE = TypeExpr::createImplicit(enumType, C);
auto *pat = new (C) EnumElementPattern(baseTE, SourceLoc(), DeclNameLoc(),
DeclNameRef(), elt, nullptr,
/*DC*/ strValDecl);
pat->setImplicit();
auto *pat = EnumElementPattern::createImplicit(enumType, elt,
/*subPattern*/ nullptr,
/*DC*/ strValDecl);
auto labelItem = CaseLabelItem(pat);
auto *caseValue = new (C) StringLiteralExpr(elt->getNameStr(),