[Constraint system] Move solution application for closures to CSClosure.

Slim down CSApply.cpp by moving the logic for applying a solution to a
closure into CSClosure.cpp. Also, eliminate duplicated logic for applying
function builders to the body of a closure or function. This should
not change semantics at all.
This commit is contained in:
Doug Gregor
2020-05-30 22:44:30 -07:00
parent b9b8f08f54
commit af048d6953
4 changed files with 291 additions and 203 deletions

View File

@@ -89,6 +89,20 @@ public:
return TheFunction.get<AbstractClosureExpr *>()->getSingleExpressionBody();
}
void setSingleExpressionBody(Expr *expr) {
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
AFD->setSingleExpressionBody(expr);
return;
}
auto ACE = TheFunction.get<AbstractClosureExpr *>();
if (auto CE = dyn_cast<ClosureExpr>(ACE)) {
CE->setSingleExpressionBody(expr);
} else {
cast<AutoClosureExpr>(ACE)->setBody(expr);
}
}
Type getType() const {
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
return AFD->getInterfaceType();
@@ -123,6 +137,21 @@ public:
return cast<AutoClosureExpr>(ACE)->getBody();
}
void setBody(BraceStmt *stmt, bool isSingleExpression) {
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
AFD->setBody(stmt);
AFD->setHasSingleExpressionBody(isSingleExpression);
return;
}
auto *ACE = TheFunction.get<AbstractClosureExpr *>();
if (auto *CE = dyn_cast<ClosureExpr>(ACE)) {
return CE->setBody(stmt, isSingleExpression);
}
llvm_unreachable("autoclosures don't have statement bodies");
}
DeclContext *getAsDeclContext() const {
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
return AFD;