Skip to content

Commit 814218c

Browse files
author
Paolo Tranquilli
committed
Swift: extract variables as children of ForEachStmt
1 parent 8bcc5f4 commit 814218c

24 files changed

+161
-14
lines changed

swift/extractor/translators/StmtTranslator.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ codeql::ForEachStmt StmtTranslator::translateForEachStmt(const swift::ForEachStm
7777
entry.iteratorVar = dispatcher.fetchLabel(stmt.getIteratorVar());
7878
entry.where = dispatcher.fetchOptionalLabel(stmt.getWhere());
7979
entry.nextCall = dispatcher.fetchOptionalLabel(stmt.getNextCall());
80+
auto add_variable = [&](swift::VarDecl* var) {
81+
entry.variables.push_back(dispatcher.fetchLabel(var));
82+
};
83+
if (auto pattern = stmt.getPattern()) {
84+
pattern->forEachVariable(add_variable);
85+
}
86+
if (auto iteratorVar = stmt.getIteratorVar()) {
87+
for (auto i = 0u; i < iteratorVar->getNumPatternEntries(); ++i) {
88+
iteratorVar->getPattern(i)->forEachVariable(add_variable);
89+
}
90+
}
8091
return entry;
8192
}
8293

swift/ql/.generated.list

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

swift/ql/.gitattributes

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

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

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

Lines changed: 10 additions & 4 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/stmt/ForEachStmt.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.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| for.swift:4:5:6:5 | for ... in ... where ... { ... } | hasLabel: | no | getNumberOfVariables: | 2 | getPattern: | for.swift:4:9:4:9 | x | hasWhere: | yes | hasIteratorVar: | yes | hasNextCall: | yes | getBody: | for.swift:4:32:6:5 | { ... } |
2+
| for.swift:7:5:9:5 | for ... in ... { ... } | hasLabel: | no | getNumberOfVariables: | 2 | getPattern: | for.swift:7:9:7:9 | s | hasWhere: | no | hasIteratorVar: | yes | hasNextCall: | yes | getBody: | for.swift:7:23:9:5 | { ... } |
3+
| for.swift:13:5:17:5 | for ... in ... { ... } | hasLabel: | no | getNumberOfVariables: | 1 | getPattern: | for.swift:13:9:13:9 | x | hasWhere: | no | hasIteratorVar: | no | hasNextCall: | no | getBody: | for.swift:13:32:17:5 | { ... } |

swift/ql/test/extractor-tests/generated/stmt/ForEachStmt/ForEachStmt.ql

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

0 commit comments

Comments
 (0)