mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[NFC] Add helpers for unresolved AST node synthesis
This change adds UnresolvedDotExpr::createImplicit() and UnresolvedDeclRefExpr::createImplicit() helpers. These calls simplify several tedious bits of code synthesis that would otherwise become even more tedious with DeclNameRef in the picture.
This commit is contained in:
@@ -50,9 +50,8 @@ deriveRawValueReturn(AbstractFunctionDecl *funcDecl, void *) {
|
||||
auto &C = parentDC->getASTContext();
|
||||
|
||||
auto *selfRef = DerivedConformance::createSelfDeclRef(funcDecl);
|
||||
auto *memberRef = new (C) UnresolvedDotExpr(selfRef, SourceLoc(),
|
||||
C.Id_rawValue, DeclNameLoc(),
|
||||
/*Implicit=*/true);
|
||||
auto *memberRef =
|
||||
UnresolvedDotExpr::createImplicit(C, selfRef, C.Id_rawValue);
|
||||
|
||||
auto *returnStmt = new (C) ReturnStmt(SourceLoc(), memberRef);
|
||||
auto *body = BraceStmt::create(C, SourceLoc(), ASTNode(returnStmt),
|
||||
@@ -84,13 +83,10 @@ deriveRawValueInit(AbstractFunctionDecl *initDecl, void *) {
|
||||
rawValueDecl->setImplicit();
|
||||
auto *paramList = ParameterList::createWithoutLoc(rawValueDecl);
|
||||
|
||||
// init(rawValue:) constructor name
|
||||
DeclName ctorName(C, DeclBaseName::createConstructor(), paramList);
|
||||
|
||||
// self.init(rawValue:) expr
|
||||
auto *selfRef = DerivedConformance::createSelfDeclRef(initDecl);
|
||||
auto *initExpr = new (C) UnresolvedDotExpr(selfRef, SourceLoc(), ctorName,
|
||||
DeclNameLoc(), /*Implicit=*/true);
|
||||
auto *initExpr = UnresolvedDotExpr::createImplicit(
|
||||
C, selfRef, DeclBaseName::createConstructor(), paramList);
|
||||
|
||||
// Bind the value param in self.init(rawValue: {string,int}Value).
|
||||
Expr *args[1] = {valueParamExpr};
|
||||
|
||||
Reference in New Issue
Block a user