mirror of
https://github.com/github/codeql.git
synced 2026-02-27 12:23:41 +01:00
Parameters and local variables: add isAnonymous predicate
This commit is contained in:
@@ -1691,6 +1691,9 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
|
||||
/** Gets the name of the variable declared by this local variable declaration expression. */
|
||||
string getName() { result = this.getVariable().getName() }
|
||||
|
||||
/** Holds if this is an anonymous local variable, `_` */
|
||||
predicate isAnonymous() { this.getName() = "" }
|
||||
|
||||
/**
|
||||
* Gets the switch statement or expression whose pattern declares this identifier, if any.
|
||||
*/
|
||||
@@ -1763,7 +1766,9 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
|
||||
}
|
||||
|
||||
/** Gets a printable representation of this expression. */
|
||||
override string toString() { result = this.getName() }
|
||||
override string toString() {
|
||||
if this.getName() = "" then result = "<anonymous local variable>" else result = this.getName()
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "LocalVariableDeclExpr" }
|
||||
}
|
||||
|
||||
@@ -117,4 +117,11 @@ class Parameter extends Element, @param, LocalScopeVariable {
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Parameter" }
|
||||
|
||||
override string toString() {
|
||||
if this.getName() = "" then result = "<anonymous parameter>" else result = super.toString()
|
||||
}
|
||||
|
||||
/** Holds if this is an anonymous parameter, `_` */
|
||||
predicate isAnonymous() { this.getName() = "" }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user