Skip to content

Commit ffff10a

Browse files
committed
Swift: synthesize CaptureListExpr::getVariable in QL instead of extracting it
1 parent 7bae2d9 commit ffff10a

File tree

7 files changed

+14
-22
lines changed

7 files changed

+14
-22
lines changed

swift/extractor/translators/ExprTranslator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ codeql::CaptureListExpr ExprTranslator::translateCaptureListExpr(
119119
entry.closure_body = dispatcher.fetchLabel(expr.getClosureBody());
120120
for (const auto& item : const_cast<swift::CaptureListExpr&>(expr).getCaptureList()) {
121121
entry.binding_decls.push_back(dispatcher.fetchLabel(item.PBD));
122-
entry.variables.push_back(dispatcher.fetchLabel(item.getVar()));
123122
}
124123
return entry;
125124
}

swift/ql/.generated.list

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
private import codeql.swift.generated.expr.CaptureListExpr
2+
private import codeql.swift.elements.decl.VarDecl
3+
private import codeql.swift.elements.pattern.NamedPattern
24

35
class CaptureListExpr extends Generated::CaptureListExpr {
46
override string toString() { result = this.getClosureBody().toString() }
7+
8+
override VarDecl getVariable(int index) {
9+
result = this.getBindingDecl(index).getPattern(0).(NamedPattern).getVarDecl()
10+
}
511
}

swift/ql/lib/codeql/swift/generated/Raw.qll

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/lib/codeql/swift/generated/expr/CaptureListExpr.qll

Lines changed: 3 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/lib/swift.dbscheme

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ class CapturedDecl(Decl):
411411

412412
class CaptureListExpr(Expr):
413413
binding_decls: list[PatternBindingDecl] | child
414-
variables: list[VarDecl] | child
414+
variables: list[VarDecl] | child | synth | desc("""
415+
These are the variables introduced by this capture in the closure's scope, not the captured ones.
416+
""")
415417
closure_body: "ClosureExpr" | child
416418

417419
class CollectionExpr(Expr):

0 commit comments

Comments
 (0)