Merge pull request #18142 from github/redsun82/swift-6-for-each-vars

Swift: extract variables as children of `ForEachStmt`
This commit is contained in:
Paolo Tranquilli
2024-12-04 11:08:35 +01:00
committed by GitHub
24 changed files with 161 additions and 14 deletions

View File

@@ -0,0 +1,3 @@
| 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 | { ... } |
| 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 | { ... } |
| 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 | { ... } |

View File

@@ -0,0 +1,20 @@
// generated by codegen/codegen.py, do not edit
import codeql.swift.elements
import TestUtils
from
ForEachStmt x, string hasLabel, int getNumberOfVariables, Pattern getPattern, string hasWhere,
string hasIteratorVar, string hasNextCall, BraceStmt getBody
where
toBeTested(x) and
not x.isUnknown() and
(if x.hasLabel() then hasLabel = "yes" else hasLabel = "no") and
getNumberOfVariables = x.getNumberOfVariables() and
getPattern = x.getPattern() and
(if x.hasWhere() then hasWhere = "yes" else hasWhere = "no") and
(if x.hasIteratorVar() then hasIteratorVar = "yes" else hasIteratorVar = "no") and
(if x.hasNextCall() then hasNextCall = "yes" else hasNextCall = "no") and
getBody = x.getBody()
select x, "hasLabel:", hasLabel, "getNumberOfVariables:", getNumberOfVariables, "getPattern:",
getPattern, "hasWhere:", hasWhere, "hasIteratorVar:", hasIteratorVar, "hasNextCall:", hasNextCall,
"getBody:", getBody

View File

@@ -0,0 +1,2 @@
| for.swift:4:5:6:5 | for ... in ... where ... { ... } | file://:0:0:0:0 | var ... = ... |
| for.swift:7:5:9:5 | for ... in ... { ... } | file://:0:0:0:0 | var ... = ... |

View File

@@ -0,0 +1,7 @@
// generated by codegen/codegen.py, do not edit
import codeql.swift.elements
import TestUtils
from ForEachStmt x
where toBeTested(x) and not x.isUnknown()
select x, x.getIteratorVar()

View File

@@ -0,0 +1,7 @@
// generated by codegen/codegen.py, do not edit
import codeql.swift.elements
import TestUtils
from ForEachStmt x
where toBeTested(x) and not x.isUnknown()
select x, x.getLabel()

View File

@@ -0,0 +1,2 @@
| for.swift:4:5:6:5 | for ... in ... where ... { ... } | for.swift:4:5:4:5 | call to next() |
| for.swift:7:5:9:5 | for ... in ... { ... } | for.swift:7:5:7:5 | call to next() |

View File

@@ -0,0 +1,7 @@
// generated by codegen/codegen.py, do not edit
import codeql.swift.elements
import TestUtils
from ForEachStmt x
where toBeTested(x) and not x.isUnknown()
select x, x.getNextCall()

View File

@@ -0,0 +1,5 @@
| for.swift:4:5:6:5 | for ... in ... where ... { ... } | 0 | for.swift:4:9:4:9 | x |
| for.swift:4:5:6:5 | for ... in ... where ... { ... } | 1 | for.swift:4:14:4:14 | $x$generator |
| for.swift:7:5:9:5 | for ... in ... { ... } | 0 | for.swift:7:9:7:9 | s |
| for.swift:7:5:9:5 | for ... in ... { ... } | 1 | for.swift:7:14:7:14 | $s$generator |
| for.swift:13:5:17:5 | for ... in ... { ... } | 0 | for.swift:13:9:13:9 | x |

View File

@@ -0,0 +1,7 @@
// generated by codegen/codegen.py, do not edit
import codeql.swift.elements
import TestUtils
from ForEachStmt x, int index
where toBeTested(x) and not x.isUnknown()
select x, index, x.getVariable(index)

View File

@@ -0,0 +1 @@
| for.swift:4:5:6:5 | for ... in ... where ... { ... } | for.swift:4:25:4:30 | ... .!=(_:_:) ... |

View File

@@ -0,0 +1,7 @@
// generated by codegen/codegen.py, do not edit
import codeql.swift.elements
import TestUtils
from ForEachStmt x
where toBeTested(x) and not x.isUnknown()
select x, x.getWhere()

View File

@@ -1,4 +0,0 @@
// generated by codegen/codegen.py, do not edit
After a source file is added in this directory and codegen/codegen.py is run again, test queries
will appear and this file will be deleted

View File

@@ -0,0 +1,19 @@
struct S {}
func test_sequence(_ ints: [Int], _ elements: [S]) {
for x in ints where x != 0 {
print(x)
}
for s in elements {
print(s)
}
}
func test_variadic_pack<each T>(_ array: repeat [each T]) -> Bool {
for x in repeat each array {
if !x.isEmpty {
return false
}
}
return true
}

View File

@@ -187,6 +187,7 @@ methodlookup.swift:
# 40| getBase(): [TypeExpr] Bar.Type
# 40| getTypeRepr(): [TypeRepr] Bar
# 40| getMethodRef(): [DeclRefExpr] staticMethod()
# 33| getExpr().getFullyConverted(): [FunctionConversionExpr] (@isolated(any) () async -> ()) ...
# 33| [NilLiteralExpr] nil
# 38| [Comment] // Bar.instanceMethod(bar2)() // error: actor-isolated instance method 'instanceMethod()' can not be referenced from a non-isolated context
# 38|
@@ -262,6 +263,7 @@ methodlookup.swift:
# 51| getMethodRef(): [DeclRefExpr] staticMethod()
# 51| getMethodRef().getFullyConverted(): [FunctionConversionExpr] ((Baz.Type) -> @MainActor () -> ()) ...
# 51| getElement(5).getFullyConverted(): [AwaitExpr] await ...
# 43| getExpr().getFullyConverted(): [FunctionConversionExpr] (@isolated(any) () async -> ()) ...
# 43| [NilLiteralExpr] nil
# 47| [Comment] // DotSyntaxCallExpr
# 47|