C#: Address more review comments.

This commit is contained in:
Michael Nebel
2024-03-06 14:59:43 +01:00
parent 43ee62ad64
commit 990dec67d0
7 changed files with 33 additions and 62 deletions

View File

@@ -22,17 +22,17 @@ private import TypeRef
*/
class Callable extends Parameterizable, ExprOrStmtParent, @callable {
pragma[noinline]
private string getDeclaringTypeLabel() { result = this.getDeclaringType().getLabel() }
deprecated private string getDeclaringTypeLabel() { result = this.getDeclaringType().getLabel() }
pragma[noinline]
private string getParameterTypeLabelNonGeneric(int p) {
deprecated private string getParameterTypeLabelNonGeneric(int p) {
not this instanceof Generic and
result = this.getParameter(p).getType().getLabel()
}
language[monotonicAggregates]
pragma[nomagic]
private string getMethodParamListNonGeneric() {
deprecated private string getMethodParamListNonGeneric() {
result =
concat(int p |
p in [0 .. this.getNumberOfParameters() - 1]
@@ -42,14 +42,14 @@ class Callable extends Parameterizable, ExprOrStmtParent, @callable {
}
pragma[noinline]
private string getParameterTypeLabelGeneric(int p) {
deprecated private string getParameterTypeLabelGeneric(int p) {
this instanceof Generic and
result = this.getParameter(p).getType().getLabel()
}
language[monotonicAggregates]
pragma[nomagic]
private string getMethodParamListGeneric() {
deprecated private string getMethodParamListGeneric() {
result =
concat(int p |
p in [0 .. this.getNumberOfParameters() - 1]
@@ -59,7 +59,7 @@ class Callable extends Parameterizable, ExprOrStmtParent, @callable {
}
pragma[noinline]
private string getLabelNonGeneric() {
deprecated private string getLabelNonGeneric() {
not this instanceof Generic and
result =
this.getReturnTypeLabel() + " " + this.getDeclaringTypeLabel() + "." +
@@ -67,19 +67,19 @@ class Callable extends Parameterizable, ExprOrStmtParent, @callable {
}
pragma[noinline]
private string getLabelGeneric() {
deprecated private string getLabelGeneric() {
result =
this.getReturnTypeLabel() + " " + this.getDeclaringTypeLabel() + "." +
this.getUndecoratedName() + getGenericsLabel(this) + "(" + this.getMethodParamListGeneric() +
")"
}
final override string getLabel() {
deprecated final override string getLabel() {
result = this.getLabelNonGeneric() or
result = this.getLabelGeneric()
}
private string getReturnTypeLabel() {
deprecated private string getReturnTypeLabel() {
result = this.getReturnType().getLabel()
or
not exists(this.getReturnType()) and result = "System.Void"
@@ -579,8 +579,8 @@ class RecordCloneMethod extends Method {
this.hasName("<Clone>$") and
this.getNumberOfParameters() = 0 and
this.getReturnType() = getARecordBaseType(this.getDeclaringType()) and
this.(Member).isPublic() and
not this.(Member).isStatic()
this.isPublic() and
not this.isStatic()
}
/** Gets the constructor that this clone method calls. */

View File

@@ -31,7 +31,7 @@ class Element extends @element {
* Gets the "language" of this program element, as defined by the extension of the filename.
* For example, C# has language "cs", and Visual Basic has language "vb".
*/
final string getLanguage() { result = this.getLocation().getFile().getExtension() }
deprecated final string getLanguage() { result = this.getLocation().getFile().getExtension() }
/**
* Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.
@@ -160,10 +160,10 @@ class NamedElement extends Element, @named_element {
/** Gets a unique string label for this element. */
cached
string getLabel() { none() }
deprecated string getLabel() { none() }
/** Holds if `other` has the same metadata handle in the same assembly. */
predicate matchesHandle(NamedElement other) {
deprecated predicate matchesHandle(NamedElement other) {
exists(Assembly asm, int handle |
metadata_handle(this, asm, handle) and
metadata_handle(other, asm, handle)
@@ -174,7 +174,7 @@ class NamedElement extends Element, @named_element {
* Holds if this element was compiled from source code that is also present in the
* database. That is, this element corresponds to another element from source.
*/
predicate compiledFromSource() {
deprecated predicate compiledFromSource() {
not this.fromSource() and
exists(NamedElement other | other != this |
this.matchesHandle(other) and

View File

@@ -108,20 +108,20 @@ class ConstructedGeneric extends Generic {
*
* Constructs the label suffix for a generic method or type.
*/
string getGenericsLabel(Generic g) {
deprecated string getGenericsLabel(Generic g) {
result = "`" + g.(UnboundGeneric).getNumberOfTypeParameters()
or
result = "<" + typeArgs(g) + ">"
}
pragma[noinline]
private string getTypeArgumentLabel(ConstructedGeneric generic, int p) {
deprecated private string getTypeArgumentLabel(ConstructedGeneric generic, int p) {
result = generic.getTypeArgument(p).getLabel()
}
language[monotonicAggregates]
pragma[nomagic]
private string typeArgs(ConstructedGeneric generic) {
deprecated private string typeArgs(ConstructedGeneric generic) {
result =
concat(int p |
p in [0 .. generic.getNumberOfTypeArguments() - 1]
@@ -264,7 +264,7 @@ class TypeParameter extends Type, @type_parameter {
/** Gets the index of this type parameter. For example the index of `U` in `Func<T,U>` is 1. */
override int getIndex() { type_parameters(this, result, _, _) }
final override string getLabel() { result = "!" + this.getIndex() }
deprecated final override string getLabel() { result = "!" + this.getIndex() }
override string getUndecoratedName() { result = "!" + this.getIndex() }

View File

@@ -263,33 +263,6 @@ class Member extends Modifiable, @member {
/** Gets an access to this member. */
MemberAccess getAnAccess() { result.getTarget() = this }
/** Holds if this member is declared `public`. */
override predicate isPublic() { Modifiable.super.isPublic() }
/** Holds if this member is declared `protected.` */
override predicate isProtected() { Modifiable.super.isProtected() }
/** Holds if this member is `private`. */
override predicate isPrivate() { Modifiable.super.isPrivate() }
/** Holds if this member is `internal`. */
override predicate isInternal() { Modifiable.super.isInternal() }
/** Holds if this member is `sealed`. */
override predicate isSealed() { Modifiable.super.isSealed() }
/** Holds if this member is `abstract`. */
override predicate isAbstract() { Modifiable.super.isAbstract() }
/** Holds if this member is `static`. */
override predicate isStatic() { Modifiable.super.isStatic() }
/** Holds if this member is declared `required`. */
override predicate isRequired() { Modifiable.super.isRequired() }
/** Holds if this member is declared `file` local. */
override predicate isFile() { Modifiable.super.isFile() }
/**
* DEPRECATED: Use `hasFullyQualifiedName` instead.
*

View File

@@ -76,7 +76,7 @@ class ValueOrRefType extends Type, Attributable, @value_or_ref_type {
/** Gets a nested child type, if any. */
NestedType getAChildType() { nested_types(result, this, _) }
private string getPrefixWithTypes() {
deprecated private string getPrefixWithTypes() {
result = this.getDeclaringType().getLabel() + "."
or
if this.getDeclaringNamespace().isGlobalNamespace()
@@ -85,17 +85,17 @@ class ValueOrRefType extends Type, Attributable, @value_or_ref_type {
}
pragma[noinline]
private string getLabelNonGeneric() {
deprecated private string getLabelNonGeneric() {
not this instanceof Generic and
result = this.getPrefixWithTypes() + this.getUndecoratedName()
}
pragma[noinline]
private string getLabelGeneric() {
deprecated private string getLabelGeneric() {
result = this.getPrefixWithTypes() + this.getUndecoratedName() + getGenericsLabel(this)
}
override string getLabel() {
deprecated override string getLabel() {
result = this.getLabelNonGeneric() or
result = this.getLabelGeneric()
}
@@ -997,7 +997,7 @@ class FunctionPointerType extends Type, Parameterizable, @function_pointer_type
override string getAPrimaryQlClass() { result = "FunctionPointerType" }
override string getLabel() { result = this.getName() }
deprecated override string getLabel() { result = this.getName() }
}
/**
@@ -1116,7 +1116,7 @@ class ArrayType extends RefType, @array_type {
array_element_type(this, _, _, getTypeRef(result))
}
final override string getLabel() { result = this.getElementType().getLabel() + "[]" }
deprecated final override string getLabel() { result = this.getElementType().getLabel() + "[]" }
/** Holds if this array type has the same shape (dimension and rank) as `that` array type. */
predicate hasSameShapeAs(ArrayType that) {
@@ -1180,7 +1180,7 @@ class PointerType extends Type, @pointer_type {
final override string getName() { types(this, _, result) }
final override string getLabel() { result = this.getReferentType().getLabel() + "*" }
deprecated final override string getLabel() { result = this.getReferentType().getLabel() + "*" }
final override string getUndecoratedName() {
result = this.getReferentType().getUndecoratedName()
@@ -1271,7 +1271,7 @@ class TupleType extends ValueType, @tuple_type {
")"
}
override string getLabel() { result = this.getUnderlyingType().getLabel() }
deprecated override string getLabel() { result = this.getUnderlyingType().getLabel() }
override Type getChild(int i) { result = this.getUnderlyingType().getChild(i) }

View File

@@ -14,11 +14,9 @@ private import semmle.code.csharp.frameworks.system.collections.Generic
* a flow summary.
*/
Callable getCallableForDataFlow(Callable c) {
exists(Callable unboundDecl | unboundDecl = c.getUnboundDeclaration() |
unboundDecl.hasBody() and
unboundDecl.getFile().fromSource() and
result = unboundDecl
)
result = c.getUnboundDeclaration() and
result.hasBody() and
result.getFile().fromSource()
}
newtype TReturnKind =

View File

@@ -1,5 +1,5 @@
import csharp
from NamedElement ne
where ne.fromSource()
select ne, ne.getLabel()
deprecated query predicate labels(NamedElement ne, string label) {
ne.getLabel() = label and ne.fromSource()
}