Skip to content

Commit 4820d16

Browse files
committed
[AST] Separate out the operations that set *parsed* bodies of functions.
When the parser wires up the body of a function, it's a legitimate use of setting a parsed body. Separate these out from the other uses of setBody() that we want to eliminate over time.
1 parent c138722 commit 4820d16

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5773,6 +5773,11 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
57735773
setBodyKind(BodyKind::Unparsed);
57745774
}
57755775

5776+
/// Provide the parsed body for the function.
5777+
void setBodyParsed(BraceStmt *S) {
5778+
setBody(S, BodyKind::Parsed);
5779+
}
5780+
57765781
/// Note that parsing for the body was delayed.
57775782
///
57785783
/// The function should return the body statement and a flag indicating

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4636,9 +4636,9 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags,
46364636
Indices, ElementTy, StaticLoc, Flags, AccessorKind::Get,
46374637
storage, this, /*AccessorKeywordLoc*/ SourceLoc());
46384638
CCE = new (Context) CodeCompletionExpr(Tok.getLoc());
4639-
getter->setBody(BraceStmt::create(Context, Tok.getLoc(),
4640-
ASTNode(CCE), Tok.getLoc(),
4641-
/*implicit*/ true));
4639+
getter->setBodyParsed(BraceStmt::create(Context, Tok.getLoc(),
4640+
ASTNode(CCE), Tok.getLoc(),
4641+
/*implicit*/ true));
46424642
accessors.add(getter);
46434643
CodeCompletion->setParsedDecl(getter);
46444644
} else {
@@ -5763,7 +5763,7 @@ void Parser::parseAbstractFunctionBody(AbstractFunctionDecl *AFD) {
57635763
ParserResult<BraceStmt> Body = parseBraceItemList(diag::invalid_diagnostic);
57645764
if (!Body.isNull()) {
57655765
BraceStmt * BS = Body.get();
5766-
AFD->setBody(BS);
5766+
AFD->setBodyParsed(BS);
57675767

57685768
// If the body consists of a single expression, turn it into a return
57695769
// statement.
@@ -5853,7 +5853,7 @@ bool Parser::parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD) {
58535853
// FIXME: Should do some sort of error recovery here?
58545854
return true;
58555855
} else {
5856-
AFD->setBody(Body.get());
5856+
AFD->setBodyParsed(Body.get());
58575857
}
58585858

58595859
return false;

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ ParserResult<Stmt> Parser::parseStmtDefer() {
988988
if (Body.isNull())
989989
return nullptr;
990990
Status |= Body;
991-
tempDecl->setBody(Body.get());
991+
tempDecl->setBodyParsed(Body.get());
992992
}
993993

994994
SourceLoc loc = tempDecl->getBodySourceRange().Start;

0 commit comments

Comments
 (0)