Skip to content

Commit 7375dcd

Browse files
committed
[AST] Add a way to set parsed version of function/closure body via AnyFunctionRef
1 parent 568174c commit 7375dcd

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

include/swift/AST/AnyFunctionRef.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ class AnyFunctionRef {
150150
return cast<AutoClosureExpr>(ACE)->getBody();
151151
}
152152

153+
void setParsedBody(BraceStmt *stmt, bool isSingleExpression) {
154+
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
155+
AFD->setBody(stmt, AbstractFunctionDecl::BodyKind::Parsed);
156+
AFD->setHasSingleExpressionBody(isSingleExpression);
157+
return;
158+
}
159+
160+
auto *ACE = TheFunction.get<AbstractClosureExpr *>();
161+
if (auto *CE = dyn_cast<ClosureExpr>(ACE)) {
162+
CE->setBody(stmt, isSingleExpression);
163+
CE->setBodyState(ClosureExpr::BodyState::ReadyForTypeChecking);
164+
return;
165+
}
166+
167+
llvm_unreachable("autoclosures don't have statement bodies");
168+
}
169+
153170
void setTypecheckedBody(BraceStmt *stmt, bool isSingleExpression) {
154171
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
155172
AFD->setBody(stmt, AbstractFunctionDecl::BodyKind::TypeChecked);
@@ -159,7 +176,9 @@ class AnyFunctionRef {
159176

160177
auto *ACE = TheFunction.get<AbstractClosureExpr *>();
161178
if (auto *CE = dyn_cast<ClosureExpr>(ACE)) {
162-
return CE->setBody(stmt, isSingleExpression);
179+
CE->setBody(stmt, isSingleExpression);
180+
CE->setBodyState(ClosureExpr::BodyState::TypeCheckedWithSignature);
181+
return;
163182
}
164183

165184
llvm_unreachable("autoclosures don't have statement bodies");

0 commit comments

Comments
 (0)