Skip to content

Commit cbe8c49

Browse files
hvitvedCopilot
andcommitted
Unified: Add shared CFG pattern stubs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 59b2c99 commit cbe8c49

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,28 @@ module Ast implements AstSig<Location> {
293293
boolean getValue() { result.toString() = super.getValue() }
294294
}
295295

296+
class Pattern extends AstNode {
297+
Pattern() { none() }
298+
}
299+
300+
class AndPattern extends Pattern {
301+
AndPattern() { none() }
302+
}
303+
304+
class OrPattern extends Pattern {
305+
OrPattern() { none() }
306+
}
307+
308+
class NotPattern extends Pattern {
309+
NotPattern() { none() }
310+
311+
Pattern getNegatedPattern() { none() }
312+
}
313+
314+
class BindingPattern extends Pattern {
315+
BindingPattern() { none() }
316+
}
317+
296318
class PatternMatchExpr extends U::PatternGuardExpr {
297319
Expr getExpr() { result = super.getValue() }
298320

‎unified/ql/test/library-tests/controlflow/basicblock-slices.expected‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@
189189
| 163 | cfg.swift:163:15:165:3 | Block | 'Block' |
190190
| 164 | cfg.swift:164:12:164:15 | true | 'true -^ ReturnExpr' |
191191
| 167 | cfg.swift:167:3:167:25 | let xOptional | 'let xOptional -V xOptional -> Optional -> Int -^ GenericTypeExpr -> x' |
192-
| 168 | cfg.swift:168:3:172:3 | IfExpr | 'IfExpr -V xOptional -^ PatternGuardExpr' |
193-
| 168 | cfg.swift:168:11:168:11 | . | '. -^ ... .some -> Argument -V x -^ ExprPattern -^ ... .some(...) -> Block' |
192+
| 168 | cfg.swift:168:3:172:3 | IfExpr | 'IfExpr -V PatternGuardExpr -V xOptional -? . -^ ... .some -> Argument -V x -^ ExprPattern -^ ... .some(...)' |
193+
| 168 | cfg.swift:168:36:170:3 | Block | 'Block' |
194194
| 169 | cfg.swift:169:12:169:12 | x | 'x -> 0 -^ ... == ... -^ ReturnExpr' |
195195
| 170 | cfg.swift:170:10:172:3 | Block | 'Block' |
196196
| 171 | cfg.swift:171:12:171:16 | false | 'false -^ ReturnExpr' |

‎unified/ql/test/library-tests/controlflow/cfg.expected‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ bbStep
4848
| cfg.swift:159:11:159:16 | ... > ... | '... > ... : true -> Block(+0)' |
4949
| cfg.swift:163:6:163:13 | TypeTestExpr | 'TypeTestExpr : false -> let xOptional(+4)' |
5050
| cfg.swift:163:6:163:13 | TypeTestExpr | 'TypeTestExpr : true -> Block(+0)' |
51-
| cfg.swift:168:6:168:34 | PatternGuardExpr | 'PatternGuardExpr : false -> Block(+2)' |
52-
| cfg.swift:168:6:168:34 | PatternGuardExpr | 'PatternGuardExpr : true -> .(+0)' |
51+
| cfg.swift:168:11:168:22 | ... .some(...) | '... .some(...) : match -> Block(+0)' |
52+
| cfg.swift:168:11:168:22 | ... .some(...) | '... .some(...) : no-match -> Block(+2)' |
5353
| cfg.swift:196:6:196:10 | ... > ... | '... > ... : false -> IfExpr(+3)' |
5454
| cfg.swift:196:6:196:10 | ... > ... | '... > ... : true -> Block(+0)' |
5555
| cfg.swift:199:11:199:16 | ... <= ... | '... <= ... : false,false,false -> Block(+5)' |
@@ -226,6 +226,7 @@ noCfg
226226
nonSimple
227227
| cfg.swift:12:17:12:25 | withParam | 'withParam -? Block' |
228228
| cfg.swift:35:5:35:5 | CatchClause | 'CatchClause -V MyError -^ ... .error1 -> isZero -> Argument -V x -^ isZero(...) -? MyError -^ ... .error2 -^ ConditionalPattern -^ OrPattern' |
229+
| cfg.swift:168:3:168:3 | IfExpr | 'IfExpr -V PatternGuardExpr -V xOptional -? . -^ ... .some -> Argument -V x -^ ExprPattern -^ ... .some(...)' |
229230
| cfg.swift:627:5:627:5 | SwitchCase | 'SwitchCase -V flag -? . -^ ... .error1 -^ ConditionalPattern' |
230231
| fallthrough.swift:10:3:10:3 | SwitchCase | 'SwitchCase -V flag -? 1 -^ ConditionalPattern' |
231232
| fallthrough.swift:51:3:51:3 | SwitchCase | 'SwitchCase -V flag -? 1 -^ ConditionalPattern' |

‎unified/ql/test/library-tests/controlflow/cfg.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func patterns(x : Int) -> Bool {
165165
}
166166

167167
let xOptional: Int? = x
168-
if case .some(let x) = xOptional { // $ bbStep='PatternGuardExpr : false -> Block(+2)' bbStep='PatternGuardExpr : true -> .(+0)'
168+
if case .some(let x) = xOptional { // $ bbStep='... .some(...) : match -> Block(+0)' bbStep='... .some(...) : no-match -> Block(+2)' nonSimple='IfExpr -V PatternGuardExpr -V xOptional -? . -^ ... .some -> Argument -V x -^ ExprPattern -^ ... .some(...)'
169169
return x == 0
170170
} else {
171171
return false

0 commit comments

Comments
 (0)