Skip to content

Commit f81a3ec

Browse files
committed
Swift: add VarDecl children to CaptureListExpr
1 parent 91d224e commit f81a3ec

File tree

13 files changed

+180
-13
lines changed

13 files changed

+180
-13
lines changed

swift/extractor/translators/ExprTranslator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ 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()));
122123
}
123124
return entry;
124125
}

swift/ql/.generated.list

Lines changed: 3 additions & 3 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/ParentChild.qll

Lines changed: 7 additions & 3 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/Raw.qll

Lines changed: 5 additions & 0 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: 21 additions & 0 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: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swift/ql/test/extractor-tests/declarations/all.expected

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,29 @@
274274
| declarations.swift:182:7:182:7 | self | |
275275
| declarations.swift:183:1:183:15 | A | getAliasedType:B |
276276
| declarations.swift:184:1:184:18 | C | getAliasedType:Int? |
277+
| declarations.swift:186:1:194:1 | S | |
278+
| declarations.swift:186:7:186:7 | S.deinit() | |
279+
| declarations.swift:186:7:186:7 | S.init() | |
280+
| declarations.swift:186:7:186:7 | self | |
281+
| declarations.swift:186:7:186:7 | self | |
282+
| declarations.swift:187:3:187:13 | var ... = ... | |
283+
| declarations.swift:187:7:187:7 | _modify | |
284+
| declarations.swift:187:7:187:7 | bf1 | |
285+
| declarations.swift:187:7:187:7 | get | |
286+
| declarations.swift:187:7:187:7 | self | |
287+
| declarations.swift:187:7:187:7 | self | |
288+
| declarations.swift:187:7:187:7 | self | |
289+
| declarations.swift:187:7:187:7 | set | |
290+
| declarations.swift:187:7:187:7 | value | |
291+
| declarations.swift:188:3:193:3 | captureThis() | |
292+
| declarations.swift:188:8:188:8 | self | |
293+
| declarations.swift:189:5:189:13 | var ... = ... | |
294+
| declarations.swift:189:9:189:9 | x | |
295+
| declarations.swift:190:5:192:5 | var ... = ... | |
296+
| declarations.swift:190:9:190:9 | f | |
297+
| declarations.swift:190:16:190:16 | self | |
298+
| declarations.swift:190:16:190:16 | var ... = ... | |
299+
| declarations.swift:190:22:190:22 | var ... = ... | |
300+
| declarations.swift:190:22:190:22 | x | |
301+
| declarations.swift:191:7:191:7 | self | |
302+
| declarations.swift:191:18:191:18 | x | |

swift/ql/test/extractor-tests/declarations/declarations.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,14 @@ func ifConfig() {
181181

182182
class B {}
183183
typealias A = B
184-
typealias C = Int?
184+
typealias C = Int?
185+
186+
class S {
187+
var bf1 = 0
188+
func captureThis() {
189+
var x = 0
190+
var f = { [self, x] () in
191+
self.bf1 = x
192+
};
193+
}
194+
}

swift/ql/test/library-tests/ast/PrintAst.expected

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,15 +2444,15 @@ cfg.swift:
24442444
# 368| getBindingDecl(1): [PatternBindingDecl] var ... = ...
24452445
# 368| getInit(0): [StringLiteralExpr] literal
24462446
# 368| getPattern(0): [NamedPattern] t
2447+
# 368| getVariable(0): [ConcreteVarDecl] z
2448+
# 368| Type = Int
2449+
# 368| getVariable(1): [ConcreteVarDecl] t
2450+
# 368| Type = String
24472451
# 368| getClosureBody(): [ExplicitClosureExpr] { ... }
24482452
# 368| getBody(): [BraceStmt] { ... }
24492453
# 369| getElement(0): [ReturnStmt] return ...
24502454
# 369| getResult(): [DeclRefExpr] z
24512455
# 369| getCapture(0): [CapturedDecl] z
2452-
# 368| [ConcreteVarDecl] z
2453-
# 368| Type = Int
2454-
# 368| [ConcreteVarDecl] t
2455-
# 368| Type = String
24562456
# 373| [NamedFunction] testTupleElement(t:)
24572457
# 373| InterfaceType = ((a: Int, Int, c: Int)) -> Int
24582458
# 373| getParam(0): [ParamDecl] t
@@ -4543,6 +4543,86 @@ declarations.swift:
45434543
# 182| getElement(0): [ReturnStmt] return
45444544
# 183| [TypeAliasDecl] A
45454545
# 184| [TypeAliasDecl] C
4546+
# 186| [ClassDecl] S
4547+
# 187| getMember(0): [PatternBindingDecl] var ... = ...
4548+
# 187| getInit(0): [IntegerLiteralExpr] 0
4549+
# 187| getPattern(0): [NamedPattern] bf1
4550+
# 187| getMember(1): [ConcreteVarDecl] bf1
4551+
# 187| Type = Int
4552+
# 187| getAccessor(0): [Accessor] get
4553+
# 187| InterfaceType = (S) -> () -> Int
4554+
# 187| getSelfParam(): [ParamDecl] self
4555+
# 187| Type = S
4556+
# 187| getBody(): [BraceStmt] { ... }
4557+
#-----| getElement(0): [ReturnStmt] return ...
4558+
#-----| getResult(): [MemberRefExpr] .bf1
4559+
#-----| getBase(): [DeclRefExpr] self
4560+
# 187| getAccessor(1): [Accessor] set
4561+
# 187| InterfaceType = (S) -> (Int) -> ()
4562+
# 187| getSelfParam(): [ParamDecl] self
4563+
# 187| Type = S
4564+
# 187| getParam(0): [ParamDecl] value
4565+
# 187| Type = Int
4566+
# 187| getBody(): [BraceStmt] { ... }
4567+
#-----| getElement(0): [AssignExpr] ... = ...
4568+
#-----| getDest(): [MemberRefExpr] .bf1
4569+
#-----| getBase(): [DeclRefExpr] self
4570+
#-----| getSource(): [DeclRefExpr] value
4571+
# 187| getAccessor(2): [Accessor] _modify
4572+
# 187| InterfaceType = (S) -> () -> ()
4573+
# 187| getSelfParam(): [ParamDecl] self
4574+
# 187| Type = S
4575+
# 187| getBody(): [BraceStmt] { ... }
4576+
# 187| getElement(0): [YieldStmt] yield ...
4577+
#-----| getResult(0): [MemberRefExpr] .bf1
4578+
#-----| getBase(): [DeclRefExpr] self
4579+
#-----| getResult(0).getFullyConverted(): [InOutExpr] &...
4580+
# 188| getMember(2): [NamedFunction] captureThis()
4581+
# 188| InterfaceType = (S) -> () -> ()
4582+
# 188| getSelfParam(): [ParamDecl] self
4583+
# 188| Type = S
4584+
# 188| getBody(): [BraceStmt] { ... }
4585+
# 189| getVariable(0): [ConcreteVarDecl] x
4586+
# 189| Type = Int
4587+
# 190| getVariable(1): [ConcreteVarDecl] f
4588+
# 190| Type = () -> ()
4589+
# 189| getElement(0): [PatternBindingDecl] var ... = ...
4590+
# 189| getInit(0): [IntegerLiteralExpr] 0
4591+
# 189| getPattern(0): [NamedPattern] x
4592+
# 190| getElement(1): [PatternBindingDecl] var ... = ...
4593+
# 190| getInit(0): [CaptureListExpr] { ... }
4594+
# 190| getBindingDecl(0): [PatternBindingDecl] var ... = ...
4595+
# 190| getInit(0): [DeclRefExpr] self
4596+
# 190| getPattern(0): [NamedPattern] self
4597+
# 190| getBindingDecl(1): [PatternBindingDecl] var ... = ...
4598+
# 190| getInit(0): [DeclRefExpr] x
4599+
# 190| getInit(0).getFullyConverted(): [LoadExpr] (Int) ...
4600+
# 190| getPattern(0): [NamedPattern] x
4601+
# 190| getVariable(0): [ConcreteVarDecl] self
4602+
# 190| Type = S
4603+
# 190| getVariable(1): [ConcreteVarDecl] x
4604+
# 190| Type = Int
4605+
# 190| getClosureBody(): [ExplicitClosureExpr] { ... }
4606+
# 190| getBody(): [BraceStmt] { ... }
4607+
# 191| getElement(0): [ReturnStmt] return ...
4608+
# 191| getResult(): [AssignExpr] ... = ...
4609+
# 191| getDest(): [MemberRefExpr] .bf1
4610+
# 191| getBase(): [DeclRefExpr] self
4611+
# 191| getSource(): [DeclRefExpr] x
4612+
# 191| getCapture(0): [CapturedDecl] self
4613+
# 191| getCapture(1): [CapturedDecl] x
4614+
# 190| getPattern(0): [NamedPattern] f
4615+
# 186| getMember(3): [Deinitializer] S.deinit()
4616+
# 186| InterfaceType = (S) -> () -> ()
4617+
# 186| getSelfParam(): [ParamDecl] self
4618+
# 186| Type = S
4619+
# 186| getBody(): [BraceStmt] { ... }
4620+
# 186| getMember(4): [Initializer] S.init()
4621+
# 186| InterfaceType = (S.Type) -> () -> S
4622+
# 186| getSelfParam(): [ParamDecl] self
4623+
# 186| Type = S
4624+
# 186| getBody(): [BraceStmt] { ... }
4625+
# 186| getElement(0): [ReturnStmt] return
45464626
expressions.swift:
45474627
# 1| [TopLevelCodeDecl] { ... }
45484628
# 1| getBody(): [BraceStmt] { ... }

swift/ql/test/library-tests/ast/declarations.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,14 @@ func ifConfig() {
181181

182182
class B {}
183183
typealias A = B
184-
typealias C = Int?
184+
typealias C = Int?
185+
186+
class S {
187+
var bf1 = 0
188+
func captureThis() {
189+
var x = 0
190+
var f = { [self, x] () in
191+
self.bf1 = x
192+
};
193+
}
194+
}

0 commit comments

Comments
 (0)