|
1 | 1 | private import codeql.swift.generated.pattern.NamedPattern |
2 | | -private import codeql.swift.elements.pattern.BindingPattern |
3 | | -private import codeql.swift.elements.pattern.EnumElementPattern |
4 | | -private import codeql.swift.elements.pattern.IsPattern |
5 | | -private import codeql.swift.elements.pattern.OptionalSomePattern |
6 | | -private import codeql.swift.elements.pattern.ParenPattern |
7 | | -private import codeql.swift.elements.pattern.TuplePattern |
8 | | -private import codeql.swift.elements.pattern.TypedPattern |
9 | 2 | private import codeql.swift.elements.decl.VarDecl |
10 | | -private import codeql.swift.elements.stmt.LabeledConditionalStmt |
11 | | -private import codeql.swift.elements.stmt.ConditionElement |
12 | 3 |
|
13 | 4 | class NamedPattern extends Generated::NamedPattern { |
14 | 5 | /** Holds if this named pattern has a corresponding `VarDecl` */ |
15 | 6 | predicate hasVarDecl() { exists(this.getVarDecl()) } |
16 | 7 |
|
17 | 8 | /** Gets the `VarDecl` bound by this named pattern, if any. */ |
18 | 9 | VarDecl getVarDecl() { |
19 | | - isSubPattern*(result.getParentPattern().getFullyUnresolved(), this) and |
| 10 | + this.getEnclosingPattern*() = result.getParentPattern().getFullyUnresolved() and |
20 | 11 | result.getName() = this.getName() |
21 | 12 | } |
22 | 13 |
|
23 | 14 | override string toString() { result = this.getName() } |
24 | 15 | } |
25 | | - |
26 | | -private predicate isSubPattern(Pattern p, Pattern sub) { |
27 | | - sub = p.(BindingPattern).getImmediateSubPattern() |
28 | | - or |
29 | | - sub = p.(EnumElementPattern).getImmediateSubPattern() |
30 | | - or |
31 | | - sub = p.(IsPattern).getImmediateSubPattern() |
32 | | - or |
33 | | - sub = p.(OptionalSomePattern).getImmediateSubPattern() |
34 | | - or |
35 | | - sub = p.(ParenPattern).getImmediateSubPattern() |
36 | | - or |
37 | | - sub = p.(TuplePattern).getImmediateElement(_) |
38 | | - or |
39 | | - sub = p.(TypedPattern).getImmediateSubPattern() |
40 | | -} |
0 commit comments