mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
C#: Add missing toString() relations
This commit is contained in:
@@ -5,13 +5,6 @@
|
||||
import semmle.code.csharp.Element
|
||||
import semmle.code.csharp.Location
|
||||
|
||||
/** Adapter so that XMLLocatables are elements */
|
||||
library class XMLLocatableElement extends @xmllocatable, Element {
|
||||
override string toString() { result = this.(XMLLocatable).toString() }
|
||||
|
||||
override Location getALocation() { result = this.(XMLLocatable).getALocation() }
|
||||
}
|
||||
|
||||
/** An XML element that has a location. */
|
||||
class XMLLocatable extends @xmllocatable {
|
||||
XMLLocatable() {
|
||||
|
||||
@@ -793,7 +793,10 @@ module Internal {
|
||||
TBooleanValue(boolean b) { b = true or b = false } or
|
||||
TIntegerValue(int i) { i = any(Expr e).getValue().toInt() } or
|
||||
TNullValue(boolean b) { b = true or b = false } or
|
||||
TMatchValue(Case c, boolean b) { b = true or b = false } or
|
||||
TMatchValue(Case c, boolean b) {
|
||||
exists(c.getPattern()) and
|
||||
(b = true or b = false)
|
||||
} or
|
||||
TEmptyCollectionValue(boolean b) { b = true or b = false }
|
||||
|
||||
/** A callable that always returns a `null` value. */
|
||||
|
||||
@@ -355,7 +355,7 @@ private module Cached {
|
||||
TSsaDefinitionNode(Ssa::Definition def) or
|
||||
TInstanceParameterNode(Callable c) { c.hasBody() and not c.(Modifiable).isStatic() } or
|
||||
TCilParameterNode(CIL::Parameter p) { p.getMethod().hasBody() } or
|
||||
TTaintedParameterNode(Parameter p) { p.getCallable().hasBody() } or
|
||||
TTaintedParameterNode(Parameter p) { explicitParameterNode(_, p) } or
|
||||
TTaintedReturnNode(ControlFlow::Nodes::ElementNode cfn) {
|
||||
any(Callable c).canYieldReturn(cfn.getElement())
|
||||
} or
|
||||
|
||||
@@ -295,7 +295,7 @@ class MethodCall extends Call, QualifiableExpr, LateBindableExpr, @method_invoca
|
||||
|
||||
override Method getQualifiedDeclaration() { result = getTarget() }
|
||||
|
||||
override string toString() { result = "call to method " + this.getTarget().getName() }
|
||||
override string toString() { result = "call to method " + concat(this.getTarget().getName()) }
|
||||
|
||||
override Expr getRawArgument(int i) {
|
||||
if exists(getQualifier())
|
||||
|
||||
@@ -116,10 +116,17 @@ private predicate isDynamicElementAccess(@dynamic_element_access_expr e) { any()
|
||||
* A local variable declaration, for example `var i = 0`.
|
||||
*/
|
||||
class LocalVariableDeclExpr extends Expr, @local_var_decl_expr {
|
||||
/** Gets the local variable being declared. */
|
||||
/**
|
||||
* Gets the local variable being declared, if any. The only case where
|
||||
* no variable is declared is when a discard symbol is used, for example
|
||||
* ```
|
||||
* if (int.TryParse(s, out var _))
|
||||
* ...
|
||||
* ```
|
||||
*/
|
||||
LocalVariable getVariable() { localvars(result, _, _, _, _, this) }
|
||||
|
||||
/** Gets the name of the variable being declared. */
|
||||
/** Gets the name of the variable being declared, if any. */
|
||||
string getName() { result = this.getVariable().getName() }
|
||||
|
||||
/** Gets the initializer expression of this local variable declaration, if any. */
|
||||
@@ -136,6 +143,9 @@ class LocalVariableDeclExpr extends Expr, @local_var_decl_expr {
|
||||
|
||||
override string toString() {
|
||||
result = this.getVariable().getType().getName() + " " + this.getName()
|
||||
or
|
||||
not exists(this.getVariable()) and
|
||||
result = "_"
|
||||
}
|
||||
|
||||
/** Gets the variable access used in this declaration, if any. */
|
||||
|
||||
Reference in New Issue
Block a user