Skip to content

Commit 5935670

Browse files
committed
Support functions with statements in their body.
1 parent d58a01d commit 5935670

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

include/swift/AST/CASTBridging.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ void *SwiftIntegerLiteralExpr_create(void *ctx, const char *_Nullable string,
101101

102102
void *SwiftBooleanLiteralExpr_create(void *ctx, _Bool value, void *TokenLoc);
103103

104-
void *SwiftVarDecl_create(void *ctx, const char *_Nullable name,
104+
void *SwiftVarDecl_create(void *ctx, const char *_Nullable name,
105105
void *loc, _Bool isStatic, _Bool isLet, void *dc);
106106

107107
void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then, void *_Nullable elseLoc,
108108
void *_Nullable elseStmt);
109109

110-
void *BraceStmt_create(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc);
110+
void *BraceStmt_createExpr(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc);
111+
void *BraceStmt_createStmt(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc);
111112

112113
void *BridgedSourceLoc_advanced(void *loc, long len);
113114

lib/AST/CASTBridging.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,23 @@ void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then, vo
145145
(Stmt *)elseStmt, None, Context);
146146
}
147147

148-
void *BraceStmt_create(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc) {
149-
return BraceStmt::create(*static_cast<ASTContext *>(ctx), *(SourceLoc *)&lbloc,
150-
getArrayRef<ASTNode>(elements),
151-
*(SourceLoc *)&rbloc);
148+
void *BraceStmt_createExpr(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc) {
149+
ASTContext &Context = *static_cast<ASTContext *>(ctx);
150+
return BraceStmt::create(Context, *(SourceLoc *)&lbloc,
151+
getArrayRef<ASTNode>(elements),
152+
*(SourceLoc *)&rbloc);
153+
}
154+
155+
void *BraceStmt_createStmt(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc) {
156+
llvm::SmallVector<ASTNode, 6> nodes;
157+
for (auto stmt : getArrayRef<Stmt *>(elements)) {
158+
nodes.push_back(stmt);
159+
}
160+
161+
ASTContext &Context = *static_cast<ASTContext *>(ctx);
162+
return BraceStmt::create(Context, *(SourceLoc *)&lbloc,
163+
Context.AllocateCopy(nodes),
164+
*(SourceLoc *)&rbloc);
152165
}
153166

154167
void *ParamDecl_create(void *ctx, void *loc,

lib/ASTGen/Sources/ASTGen/Decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension ASTGenVisitor {
5959
let loc = self.base.advanced(by: node.position.utf8Offset).raw
6060

6161
return statements.withBridgedArrayRef { ref in
62-
BraceStmt_create(ctx, loc, ref, loc)
62+
BraceStmt_createStmt(ctx, loc, ref, loc)
6363
}
6464
}
6565

lib/ASTGen/Sources/ASTGen/Exprs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extension ASTGenVisitor {
99
let loc = self.base.advanced(by: node.position.utf8Offset).raw
1010

1111
let body = statements.withBridgedArrayRef { ref in
12-
BraceStmt_create(ctx, loc, ref, loc)
12+
BraceStmt_createExpr(ctx, loc, ref, loc)
1313
}
1414

1515
return ClosureExpr_create(ctx, body, declContext)

0 commit comments

Comments
 (0)