Skip to content

Commit 387cde5

Browse files
committed
Swift: add BraceStmt.getVariable(_) child with logic in QL.
1 parent 2529312 commit 387cde5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

swift/ql/lib/codeql/swift/elements/stmt/BraceStmt.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,23 @@ class BraceStmt extends Generated::BraceStmt {
1111
}
1212

1313
override string toString() { result = "{ ... }" }
14+
15+
override AstNode getImmediateElement(int index) {
16+
result =
17+
rank[index + 1](AstNode element, int i |
18+
element = super.getImmediateElement(i) and
19+
not element instanceof VarDecl
20+
|
21+
element order by i
22+
)
23+
}
24+
25+
override VarDecl getVariable(int index) {
26+
result =
27+
rank[index + 1](VarDecl variable, int i |
28+
variable = super.getImmediateElement(i)
29+
|
30+
variable order by i
31+
)
32+
}
1433
}

swift/schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ class StmtCondition(AstNode):
935935
elements: list[ConditionElement] | child
936936

937937
class BraceStmt(Stmt):
938+
variables: list[VarDecl] | child | doc("variable declared in the scope of this brace statement")
938939
elements: list[AstNode] | child
939940

940941
class BreakStmt(Stmt):

0 commit comments

Comments
 (0)