mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
C#: Add library support for list- and slice patterns.
This commit is contained in:
@@ -321,6 +321,18 @@ private predicate hasChildPattern(ControlFlowElement pm, Expr child) {
|
||||
mid instanceof @tuple_expr and
|
||||
child = mid.getAChildExpr()
|
||||
)
|
||||
or
|
||||
exists(Expr mid |
|
||||
hasChildPattern(pm, mid) and
|
||||
mid instanceof @list_pattern_expr and
|
||||
child = mid.getAChildExpr()
|
||||
)
|
||||
or
|
||||
exists(Expr mid |
|
||||
hasChildPattern(pm, mid) and
|
||||
mid instanceof @slice_pattern_expr and
|
||||
child = mid.getAChildExpr()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -506,6 +518,26 @@ class PositionalPatternExpr extends PatternExpr, @positional_pattern_expr {
|
||||
override string getAPrimaryQlClass() { result = "PositionalPatternExpr" }
|
||||
}
|
||||
|
||||
/** A list pattern. For example `[1, 2, int y]` in `x is [1, 2, int y]`. */
|
||||
class ListPatternExpr extends PatternExpr, @list_pattern_expr {
|
||||
override string toString() { result = "[ ... ]" }
|
||||
|
||||
/** Gets the `n`th pattern. */
|
||||
PatternExpr getPattern(int n) { result = this.getChild(n) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "ListPatternExpr" }
|
||||
}
|
||||
|
||||
/** A slice pattern. For example `..` in `x is [1, .., 2]. */
|
||||
class SlicePatternExpr extends PatternExpr, @slice_pattern_expr {
|
||||
override string toString() { result = ".." }
|
||||
|
||||
/** Gets the subpattern, if any. */
|
||||
PatternExpr getPattern() { result = this.getChild(0) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "SlicePatternExpr" }
|
||||
}
|
||||
|
||||
/** A unary pattern. For example, `not 1`. */
|
||||
class UnaryPatternExpr extends PatternExpr, @unary_pattern_expr {
|
||||
/** Gets the underlying pattern. */
|
||||
|
||||
Reference in New Issue
Block a user