[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:
Brent Royal-Gordon
2019-12-10 15:53:59 -08:00
parent 027e4b7941
commit a3035eb925
7 changed files with 79 additions and 71 deletions

View File

@@ -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};