Skip to content

Commit 4595a9c

Browse files
committed
Swift: Extract parameters to closure expressions.
1 parent 70e5cf7 commit 4595a9c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

swift/codegen/schema.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ ValueDecl:
288288

289289
AbstractClosureExpr:
290290
_extends: Expr
291+
_children:
292+
params: ParamDecl*
291293

292294
AnyTryExpr:
293295
_extends: Expr

swift/extractor/visitors/ExprVisitor.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,15 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
368368
assert(expr->getBody() && "ClosureExpr has getBody()");
369369
auto bodyLabel = dispatcher_.fetchLabel(expr->getBody());
370370
dispatcher_.emit(ClosureExprsTrap{label, bodyLabel});
371+
emitAbstractClosureExpr(expr, label);
371372
}
372373

373374
void visitAutoClosureExpr(swift::AutoClosureExpr* expr) {
374375
auto label = dispatcher_.assignNewLabel(expr);
375376
assert(expr->getBody() && "AutoClosureExpr has getBody()");
376377
auto bodyLabel = dispatcher_.fetchLabel(expr->getBody());
377378
dispatcher_.emit(AutoClosureExprsTrap{label, bodyLabel});
379+
emitAbstractClosureExpr(expr, label);
378380
}
379381

380382
void visitCoerceExpr(swift::CoerceExpr* expr) {
@@ -534,6 +536,16 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
534536
}
535537

536538
private:
539+
void emitAbstractClosureExpr(swift::AbstractClosureExpr* expr,
540+
TrapLabel<AbstractClosureExprTag> label) {
541+
assert(expr->getParameters() && "AbstractClosureExpr has getParameters()");
542+
auto params = expr->getParameters();
543+
for (auto i = 0u; i < params->size(); ++i) {
544+
dispatcher_.emit(
545+
AbstractClosureExprParamsTrap{label, i, dispatcher_.fetchLabel(params->get(i))});
546+
}
547+
}
548+
537549
TrapLabel<ArgumentTag> emitArgument(const swift::Argument& arg) {
538550
auto argLabel = dispatcher_.createLabel<ArgumentTag>();
539551
assert(arg.getExpr() && "Argument has getExpr");

0 commit comments

Comments
 (0)