C#: Add library support for list- and slice patterns.

This commit is contained in:
Michael Nebel
2022-12-08 10:45:05 +01:00
parent cfd3c1fcbe
commit 98e125fa98

View File

@@ -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. */