mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user