Skip to content

Commit 7939b84

Browse files
authored
Merge pull request github#11168 from github/redsun82/swift-postfix-expr
Swift: extract `PostfixUnaryExpr`
2 parents 6a5f37b + cbae72d commit 7939b84

File tree

10 files changed

+46
-4
lines changed

10 files changed

+46
-4
lines changed

swift/extractor/translators/ExprTranslator.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ codeql::PrefixUnaryExpr ExprTranslator::translatePrefixUnaryExpr(
8484
return entry;
8585
}
8686

87+
codeql::PostfixUnaryExpr ExprTranslator::translatePostfixUnaryExpr(
88+
const swift::PostfixUnaryExpr& expr) {
89+
auto entry = createExprEntry(expr);
90+
fillApplyExpr(expr, entry);
91+
return entry;
92+
}
93+
8794
codeql::DeclRefExpr ExprTranslator::translateDeclRefExpr(const swift::DeclRefExpr& expr) {
8895
auto entry = createExprEntry(expr);
8996
entry.decl = dispatcher.fetchLabel(expr.getDecl());
@@ -518,4 +525,5 @@ codeql::UnresolvedPatternExpr ExprTranslator::translateUnresolvedPatternExpr(
518525
entry.sub_pattern = dispatcher.fetchLabel(expr.getSubPattern());
519526
return entry;
520527
}
528+
521529
} // namespace codeql

swift/extractor/translators/ExprTranslator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ExprTranslator : public AstTranslatorBase<ExprTranslator> {
2020
codeql::NilLiteralExpr translateNilLiteralExpr(const swift::NilLiteralExpr& expr);
2121
codeql::CallExpr translateCallExpr(const swift::CallExpr& expr);
2222
codeql::PrefixUnaryExpr translatePrefixUnaryExpr(const swift::PrefixUnaryExpr& expr);
23+
codeql::PostfixUnaryExpr translatePostfixUnaryExpr(const swift::PostfixUnaryExpr& expr);
2324
codeql::DeclRefExpr translateDeclRefExpr(const swift::DeclRefExpr& expr);
2425
codeql::AssignExpr translateAssignExpr(const swift::AssignExpr& expr);
2526
codeql::BindOptionalExpr translateBindOptionalExpr(const swift::BindOptionalExpr& expr);

swift/ql/test/extractor-tests/generated/expr/PostfixUnaryExpr/MISSING_SOURCE.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| postfix.swift:1:5:1:6 | call to ...(_:) | getFunction: | postfix.swift:1:6:1:6 | ....(_:) |
2+
| postfix.swift:7:1:7:2 | call to **(_:) | getFunction: | postfix.swift:7:2:7:2 | **(_:) |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from PostfixUnaryExpr x, Expr getFunction
6+
where
7+
toBeTested(x) and
8+
not x.isUnknown() and
9+
getFunction = x.getFunction()
10+
select x, "getFunction:", getFunction
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| postfix.swift:1:5:1:6 | call to ...(_:) | 0 | postfix.swift:1:5:1:5 | : 3 |
2+
| postfix.swift:7:1:7:2 | call to **(_:) | 0 | postfix.swift:7:1:7:1 | : 3 |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from PostfixUnaryExpr x, int index
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, index, x.getArgument(index)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| postfix.swift:1:5:1:6 | call to ...(_:) | PartialRangeFrom<Int> |
2+
| postfix.swift:7:1:7:2 | call to **(_:) | () |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from PostfixUnaryExpr x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getType()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_ = 3...
2+
3+
postfix operator **
4+
5+
postfix func **(_ n: Int) {}
6+
7+
3**

0 commit comments

Comments
 (0)