C#: Add missing toString() relations

This commit is contained in:
Tom Hvitved
2019-12-16 10:52:37 +01:00
parent 648c19978a
commit f1193d084b
10 changed files with 29 additions and 17 deletions

View File

@@ -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() {

View File

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

View File

@@ -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

View File

@@ -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())

View File

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