Skip to content

Commit 8cae9d0

Browse files
committed
C#: Introduce a general local variable declaration pattern class.
1 parent 96f98aa commit 8cae9d0

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎csharp/ql/lib/semmle/code/csharp/Assignable.qll‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,31 @@ module AssignableInternal {
277277
def = TParameterDefaultDefinition(_, result)
278278
}
279279

280-
/** A local variable declaration at the top-level of a pattern. */
281-
class TopLevelPatternDecl extends LocalVariableDeclExpr {
280+
/** A pattern containing a local variable declaration. */
281+
class LocalVariablePatternDecl extends LocalVariableDeclExpr {
282282
private PatternMatch pm;
283283

284-
TopLevelPatternDecl() { this = pm.getPattern().(BindingPatternExpr).getVariableDeclExpr() }
284+
LocalVariablePatternDecl() {
285+
exists(BindingPatternExpr bpe |
286+
this = bpe.getVariableDeclExpr() and pm = bpe.getPatternMatch()
287+
)
288+
}
289+
290+
/** Holds if the local variable definition is at the top level of the pattern. */
291+
predicate isTopLevel() { this = pm.getPattern().(BindingPatternExpr).getVariableDeclExpr() }
285292

293+
/** Holds of this local variable definition is a part of a tuple pattern. */
294+
predicate isInTuple() { this.getParent() instanceof TuplePatternExpr }
295+
296+
/** Gets the pattern match that this local variable declaration (pattern) belongs to. */
286297
PatternMatch getMatch() { result = pm }
287298
}
288299

300+
/** A local variable declaration at the top-level of a pattern. */
301+
class TopLevelPatternDecl extends LocalVariablePatternDecl {
302+
TopLevelPatternDecl() { this.isTopLevel() }
303+
}
304+
289305
cached
290306
private module Cached {
291307
cached

0 commit comments

Comments
 (0)