C#: Rename getSourceDeclaration() to getUnboundDeclaration()

This commit is contained in:
Tom Hvitved
2020-11-05 14:23:15 +01:00
parent 2cf10a7658
commit cd77f14a75
67 changed files with 302 additions and 254 deletions

View File

@@ -17,7 +17,7 @@ where
add.hasName("Add") and add.hasName("Add") and
add add
.getDeclaringType() .getDeclaringType()
.getSourceDeclaration() .getUnboundDeclaration()
.hasQualifiedName("System.Collections.Generic.ICollection<>") and .hasQualifiedName("System.Collections.Generic.ICollection<>") and
call.getAnArgument() instanceof NullLiteral call.getAnArgument() instanceof NullLiteral
select call select call

View File

@@ -56,7 +56,7 @@ class LocalScopeDisposableCreation extends Call {
exists(Method create | this.getTarget() = create | exists(Method create | this.getTarget() = create |
create.hasName("Create") and create.hasName("Create") and
create.isStatic() and create.isStatic() and
create.getDeclaringType().getSourceDeclaration() = t.getSourceDeclaration() create.getDeclaringType().getUnboundDeclaration() = t.getUnboundDeclaration()
) )
) )
} }

View File

@@ -28,7 +28,7 @@ predicate nonOverridingMethod(Method m, Method vm) {
not m.overrides() and not m.overrides() and
not m.isOverride() and not m.isOverride() and
not m.isNew() and not m.isNew() and
m = m.getSourceDeclaration() and m.isUnboundDeclaration() and
m.getNumberOfParameters() = vm.getNumberOfParameters() and m.getNumberOfParameters() = vm.getNumberOfParameters() and
forall(int i, Parameter p1, Parameter p2 | p1 = m.getParameter(i) and p2 = vm.getParameter(i) | forall(int i, Parameter p1, Parameter p2 | p1 = m.getParameter(i) and p2 = vm.getParameter(i) |
p1.getType() = p2.getType() p1.getType() = p2.getType()
@@ -41,4 +41,4 @@ where
m.fromSource() and m.fromSource() and
nonOverridingMethod(m, vm) nonOverridingMethod(m, vm)
select m, "Method '" + m.getName() + "' looks like it should override $@ but does not do so.", select m, "Method '" + m.getName() + "' looks like it should override $@ but does not do so.",
vm.getSourceDeclaration(), vm.getQualifiedName() vm.getUnboundDeclaration(), vm.getQualifiedName()

View File

@@ -15,7 +15,7 @@ import semmle.code.csharp.frameworks.System
from MethodCall c, EqualsMethod equals from MethodCall c, EqualsMethod equals
where where
c.getTarget().getSourceDeclaration() = equals and c.getTarget().getUnboundDeclaration() = equals and
c.getArgument(0) instanceof NullLiteral and c.getArgument(0) instanceof NullLiteral and
not c.getQualifier().getType() instanceof NullableType not c.getQualifier().getType() instanceof NullableType
select c, "Equality test with 'null' will never be true, but may throw a 'NullReferenceException'." select c, "Equality test with 'null' will never be true, but may throw a 'NullReferenceException'."

View File

@@ -32,7 +32,7 @@ predicate important(Method m) {
/** Holds if the return type of `m` is an instantiated type parameter from `m`. */ /** Holds if the return type of `m` is an instantiated type parameter from `m`. */
predicate methodHasGenericReturnType(ConstructedMethod cm) { predicate methodHasGenericReturnType(ConstructedMethod cm) {
exists(UnboundGenericMethod ugm | exists(UnboundGenericMethod ugm |
ugm = cm.getSourceDeclaration() and ugm = cm.getUnboundGeneric() and
ugm.getReturnType() = ugm.getATypeParameter() ugm.getReturnType() = ugm.getATypeParameter()
) )
} }
@@ -46,16 +46,16 @@ predicate dubious(Method m, int percentage) {
// Suppress on methods designed for chaining // Suppress on methods designed for chaining
not designedForChaining(m) and not designedForChaining(m) and
exists(int used, int total, Method target | exists(int used, int total, Method target |
target = m.getSourceDeclaration() and target = m.getUnboundDeclaration() and
used = used =
count(MethodCall mc | count(MethodCall mc |
mc.getTarget().getSourceDeclaration() = target and mc.getTarget().getUnboundDeclaration() = target and
not mc instanceof DiscardedMethodCall and not mc instanceof DiscardedMethodCall and
(methodHasGenericReturnType(m) implies m.getReturnType() = mc.getTarget().getReturnType()) (methodHasGenericReturnType(m) implies m.getReturnType() = mc.getTarget().getReturnType())
) and ) and
total = total =
count(MethodCall mc | count(MethodCall mc |
mc.getTarget().getSourceDeclaration() = target and mc.getTarget().getUnboundDeclaration() = target and
(methodHasGenericReturnType(m) implies m.getReturnType() = mc.getTarget().getReturnType()) (methodHasGenericReturnType(m) implies m.getReturnType() = mc.getTarget().getReturnType())
) and ) and
used != total and used != total and

View File

@@ -16,10 +16,10 @@ import csharp
Member getAUsedMember(Method m) { Member getAUsedMember(Method m) {
exists(MemberAccess ma | ma.getEnclosingCallable() = m | exists(MemberAccess ma | ma.getEnclosingCallable() = m |
result = ma.getTarget().getSourceDeclaration() result = ma.getTarget().getUnboundDeclaration()
) )
or or
exists(Call c | c.getEnclosingCallable() = m | result = c.getTarget().getSourceDeclaration()) exists(Call c | c.getEnclosingCallable() = m | result = c.getTarget().getUnboundDeclaration())
} }
int dependencyCount(Method source, RefType target) { int dependencyCount(Method source, RefType target) {
@@ -50,8 +50,8 @@ predicate query(Method m, RefType targetType, int selfCount, int depCount) {
not m instanceof ExtensionMethod and not m instanceof ExtensionMethod and
// Do not move up/down the class hierarchy // Do not move up/down the class hierarchy
not ( not (
sourceType.getABaseType*().getSourceDeclaration() = targetType or sourceType.getABaseType*().getUnboundDeclaration() = targetType or
targetType.getABaseType*().getSourceDeclaration() = sourceType targetType.getABaseType*().getUnboundDeclaration() = sourceType
) and ) and
// Do not move between nested types // Do not move between nested types
not (sourceType.getDeclaringType*() = targetType or targetType.getDeclaringType*() = sourceType) and not (sourceType.getDeclaringType*() = targetType or targetType.getDeclaringType*() = sourceType) and

View File

@@ -22,9 +22,9 @@ class CollectionInterface extends Interface {
CollectionInterface() { CollectionInterface() {
exists(Interface i | i = this.getABaseInterface*() | exists(Interface i | i = this.getABaseInterface*() |
i instanceof SystemCollectionsICollectionInterface or i instanceof SystemCollectionsICollectionInterface or
i.getSourceDeclaration() instanceof SystemCollectionsGenericICollectionInterface or i.getUnboundDeclaration() instanceof SystemCollectionsGenericICollectionInterface or
i instanceof SystemCollectionsIEnumerableInterface or i instanceof SystemCollectionsIEnumerableInterface or
i.getSourceDeclaration() instanceof SystemCollectionsGenericIEnumerableTInterface i.getUnboundDeclaration() instanceof SystemCollectionsGenericIEnumerableTInterface
) )
} }
} }

View File

@@ -15,7 +15,7 @@ import semmle.code.csharp.commons.Collections
import DataFlow import DataFlow
predicate storesCollection(Callable c, Parameter p, Field f) { predicate storesCollection(Callable c, Parameter p, Field f) {
f.getDeclaringType() = c.getDeclaringType().getABaseType*().getSourceDeclaration() and f.getDeclaringType() = c.getDeclaringType().getABaseType*().getUnboundDeclaration() and
f.getType() instanceof CollectionType and f.getType() instanceof CollectionType and
p = c.getAParameter() and p = c.getAParameter() and
f.getAnAssignedValue() = p.getAnAccess() and f.getAnAssignedValue() = p.getAnAccess() and
@@ -23,7 +23,7 @@ predicate storesCollection(Callable c, Parameter p, Field f) {
} }
predicate returnsCollection(Callable c, Field f) { predicate returnsCollection(Callable c, Field f) {
f.getDeclaringType() = c.getDeclaringType().getABaseType*().getSourceDeclaration() and f.getDeclaringType() = c.getDeclaringType().getABaseType*().getUnboundDeclaration() and
f.getType() instanceof CollectionType and f.getType() instanceof CollectionType and
c.canReturn(f.getAnAccess()) and c.canReturn(f.getAnAccess()) and
not c.(Modifiable).isStatic() not c.(Modifiable).isStatic()

View File

@@ -36,8 +36,8 @@ Expr getAnAccessByDynamicCall(Method m) {
Expr getAMethodAccess(Method m) { Expr getAMethodAccess(Method m) {
result = getAnAccessByDynamicCall(m) or result = getAnAccessByDynamicCall(m) or
result = getAnAccessByReflection(m) or result = getAnAccessByReflection(m) or
result.(MethodCall).getTarget().getSourceDeclaration() = m or result.(MethodCall).getTarget().getUnboundDeclaration() = m or
result.(MethodAccess).getTarget().getSourceDeclaration() = m result.(MethodAccess).getTarget().getUnboundDeclaration() = m
} }
predicate potentiallyAccessedByForEach(Method m) { predicate potentiallyAccessedByForEach(Method m) {
@@ -63,7 +63,7 @@ predicate isRecursivelyLiveMethod(Method m) {
or or
potentiallyAccessedByForEach(m) potentiallyAccessedByForEach(m)
or or
isRecursivelyLiveMethod(m.(ConstructedMethod).getSourceDeclaration()) isRecursivelyLiveMethod(m.(ConstructedMethod).getUnboundDeclaration())
or or
nunitValueSource(m) nunitValueSource(m)
or or
@@ -78,7 +78,7 @@ predicate nunitValueSource(Method m) {
} }
predicate nunitTestCaseSource(Declaration f) { predicate nunitTestCaseSource(Declaration f) {
exists(TestCaseSourceAttribute attribute | attribute.getSourceDeclaration() = f) exists(TestCaseSourceAttribute attribute | attribute.getUnboundDeclaration() = f)
} }
predicate isDeadMethod(Method m) { predicate isDeadMethod(Method m) {
@@ -89,9 +89,9 @@ predicate isDeadMethod(Method m) {
predicate isDeadField(Field f) { predicate isDeadField(Field f) {
f.isPrivate() and f.isPrivate() and
not f.getDeclaringType() instanceof AnonymousClass and not f.getDeclaringType() instanceof AnonymousClass and
f.getSourceDeclaration() = f and f.getUnboundDeclaration() = f and
not nunitTestCaseSource(f) and not nunitTestCaseSource(f) and
forall(FieldAccess fc | fc.getTarget().getSourceDeclaration() = f | forall(FieldAccess fc | fc.getTarget().getUnboundDeclaration() = f |
isDeadMethod(fc.getEnclosingCallable()) isDeadMethod(fc.getEnclosingCallable())
or or
not fc instanceof FieldRead and not fc.isRefArgument() not fc instanceof FieldRead and not fc.isRefArgument()

View File

@@ -32,7 +32,7 @@ from RefType t
where where
not extractionIsStandalone() and not extractionIsStandalone() and
t.fromSource() and t.fromSource() and
t = t.getSourceDeclaration() and t.isUnboundDeclaration() and
not t instanceof AnonymousClass and not t instanceof AnonymousClass and
not (t.isPublic() or t.isProtected()) and not (t.isPublic() or t.isProtected()) and
not exists(ValueOrRefType dependent | depends(dependent, t) and dependent != t) and not exists(ValueOrRefType dependent | depends(dependent, t) and dependent != t) and

View File

@@ -85,31 +85,31 @@ where
not f.getType() instanceof Struct and not f.getType() instanceof Struct and
not exists(Assignment ae, Field g | not exists(Assignment ae, Field g |
ae.getLValue().(FieldAccess).getTarget() = g and ae.getLValue().(FieldAccess).getTarget() = g and
g.getSourceDeclaration() = f and g.getUnboundDeclaration() = f and
not ae.getRValue() instanceof NullLiteral not ae.getRValue() instanceof NullLiteral
) and ) and
not exists(MethodCall mc, int i, Field g | not exists(MethodCall mc, int i, Field g |
exists(Parameter p | mc.getTarget().getParameter(i) = p | p.isOut() or p.isRef()) and exists(Parameter p | mc.getTarget().getParameter(i) = p | p.isOut() or p.isRef()) and
mc.getArgument(i) = g.getAnAccess() and mc.getArgument(i) = g.getAnAccess() and
g.getSourceDeclaration() = f g.getUnboundDeclaration() = f
) and ) and
not isFieldExternallyInitialized(f) and not isFieldExternallyInitialized(f) and
not exists(f.getAnAttribute()) and not exists(f.getAnAttribute()) and
not exists(Expr init, Field g | not exists(Expr init, Field g |
g.getSourceDeclaration() = f and g.getUnboundDeclaration() = f and
g.getInitializer() = init and g.getInitializer() = init and
not init instanceof NullLiteral not init instanceof NullLiteral
) and ) and
not exists(AssignOperation ua, Field g | not exists(AssignOperation ua, Field g |
ua.getLValue().(FieldAccess).getTarget() = g and ua.getLValue().(FieldAccess).getTarget() = g and
g.getSourceDeclaration() = f g.getUnboundDeclaration() = f
) and ) and
not exists(MutatorOperation op | not exists(MutatorOperation op |
op.getAnOperand().(FieldAccess).getTarget().getSourceDeclaration() = f op.getAnOperand().(FieldAccess).getTarget().getUnboundDeclaration() = f
) and ) and
exists(Field g | exists(Field g |
fa.getTarget() = g and fa.getTarget() = g and
g.getSourceDeclaration() = f g.getUnboundDeclaration() = f
) )
select f, select f,
"The field '" + f.getName() + "' is never explicitly assigned a value, yet it is read $@.", fa, "The field '" + f.getName() + "' is never explicitly assigned a value, yet it is read $@.", fa,

View File

@@ -44,7 +44,7 @@ predicate declarationHasXmlComment(Declaration d) { exists(getADeclarationXmlCom
/** Whether a declaration should have documentation. */ /** Whether a declaration should have documentation. */
predicate isDocumentationNeeded(Modifiable decl) { predicate isDocumentationNeeded(Modifiable decl) {
decl.getSourceDeclaration() = decl and // Exclude constructed types and methods decl.isUnboundDeclaration() and // Exclude constructed types and methods
not exists(decl.(Attributable).getAnAttribute()) and // An attribute may serve to document not exists(decl.(Attributable).getAnAttribute()) and // An attribute may serve to document
decl.isPublic() and decl.isPublic() and
( (

View File

@@ -19,7 +19,7 @@ int isCountForIfChain(IfStmt is) {
exists(int rest | exists(int rest |
(if is.getElse() instanceof IfStmt then rest = isCountForIfChain(is.getElse()) else rest = 0) and (if is.getElse() instanceof IfStmt then rest = isCountForIfChain(is.getElse()) else rest = 0) and
( (
if getTypeCondition(is).getCheckedType().getSourceDeclaration().fromSource() if getTypeCondition(is).getCheckedType().fromSource()
then result = 1 + rest then result = 1 + rest
else result = rest else result = rest
) )

View File

@@ -78,7 +78,7 @@ Element getCollectionAssignmentTarget(Expr e) {
MethodCall mc, Method m, LibraryTypeDataFlow ltdf, CallableFlowSource source, MethodCall mc, Method m, LibraryTypeDataFlow ltdf, CallableFlowSource source,
CallableFlowSink sink CallableFlowSink sink
| |
m = mc.getTarget().getSourceDeclaration() and m = mc.getTarget().getUnboundDeclaration() and
ltdf.callableFlow(source, AccessPath::empty(), sink, AccessPath::element(), m, _) and ltdf.callableFlow(source, AccessPath::empty(), sink, AccessPath::element(), m, _) and
e = source.getSource(mc) and e = source.getSource(mc) and
result.(Variable).getAnAccess() = sink.getSink(mc) result.(Variable).getAnAccess() = sink.getSink(mc)

View File

@@ -13,7 +13,7 @@
import csharp import csharp
predicate defTargetsField(AssignableDefinition def, Field f) { predicate defTargetsField(AssignableDefinition def, Field f) {
def.getTarget().getSourceDeclaration() = f def.getTarget().getUnboundDeclaration() = f
} }
predicate isReadonlyCompatibleDefinition(AssignableDefinition def, Field f) { predicate isReadonlyCompatibleDefinition(AssignableDefinition def, Field f) {

View File

@@ -15,7 +15,7 @@ import semmle.code.csharp.commons.Assertions
private predicate propertyOverrides(Property p, string baseClass, string property) { private predicate propertyOverrides(Property p, string baseClass, string property) {
exists(Property p2 | exists(Property p2 |
p2.getSourceDeclaration().getDeclaringType().hasQualifiedName(baseClass) and p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(baseClass) and
p2.hasName(property) p2.hasName(property)
| |
p.overridesOrImplementsOrEquals(p2) p.overridesOrImplementsOrEquals(p2)

View File

@@ -18,7 +18,7 @@ where
compareTo = any(SystemIComparableInterface i).getCompareToMethod() compareTo = any(SystemIComparableInterface i).getCompareToMethod()
or or
compareTo = any(SystemIComparableTInterface i).getAConstructedGeneric().getAMethod() and compareTo = any(SystemIComparableTInterface i).getAConstructedGeneric().getAMethod() and
compareTo.getSourceDeclaration() = any(SystemIComparableTInterface i).getCompareToMethod() compareTo.getUnboundDeclaration() = any(SystemIComparableTInterface i).getCompareToMethod()
) and ) and
compareToImpl = c.getAMethod() and compareToImpl = c.getAMethod() and
compareToImpl = compareTo.getAnUltimateImplementor() and compareToImpl = compareTo.getAnUltimateImplementor() and

View File

@@ -17,7 +17,7 @@ predicate generateRandomNumberMethod(string s) { s = "Next" or s = "NextBytes" o
from ObjectCreation c, MethodCall m from ObjectCreation c, MethodCall m
where where
c.getType().getSourceDeclaration().(ValueOrRefType).hasQualifiedName("System", "Random") and c.getType().getUnboundDeclaration().(ValueOrRefType).hasQualifiedName("System", "Random") and
m.getQualifier() = c and m.getQualifier() = c and
generateRandomNumberMethod(m.getTarget().getName()) generateRandomNumberMethod(m.getTarget().getName())
select m, "Random object created and used only once." select m, "Random object created and used only once."

View File

@@ -150,16 +150,18 @@ private class IndirectType extends GeneratedType {
or or
this.(UnboundGenericType).getAConstructedGeneric().getASubType() instanceof GeneratedType this.(UnboundGenericType).getAConstructedGeneric().getASubType() instanceof GeneratedType
or or
exists(GeneratedType t | this = getAContainedType(t.getAGeneratedType()).getSourceDeclaration()) exists(GeneratedType t |
this = getAContainedType(t.getAGeneratedType()).getUnboundDeclaration()
)
or or
exists(GeneratedDeclaration decl | exists(GeneratedDeclaration decl |
decl.(Member).getDeclaringType().getSourceDeclaration() = this decl.(Member).getDeclaringType().getUnboundDeclaration() = this
) )
} }
} }
private class RootGeneratedType extends GeneratedType { private class RootGeneratedType extends GeneratedType {
RootGeneratedType() { this = any(GeneratedDeclaration decl).getSourceDeclaration() } RootGeneratedType() { this = any(GeneratedDeclaration decl).getUnboundDeclaration() }
} }
private Type getAContainedType(Type t) { private Type getAContainedType(Type t) {
@@ -169,7 +171,7 @@ private Type getAContainedType(Type t) {
} }
private class RootGeneratedMember extends GeneratedMember { private class RootGeneratedMember extends GeneratedMember {
RootGeneratedMember() { this = any(GeneratedDeclaration d).getSourceDeclaration() } RootGeneratedMember() { this = any(GeneratedDeclaration d).getUnboundDeclaration() }
} }
private predicate declarationExists(Virtualizable m) { private predicate declarationExists(Virtualizable m) {

View File

@@ -19,7 +19,7 @@ predicate methodInClass(ValueOrRefType t, Method m, string name) {
predicate callIn(MethodCall mc, Method fromMethod) { fromMethod = mc.getEnclosingCallable() } predicate callIn(MethodCall mc, Method fromMethod) { fromMethod = mc.getEnclosingCallable() }
predicate callTo(MethodCall mc, Method toMethod) { predicate callTo(MethodCall mc, Method toMethod) {
toMethod = mc.getTarget().getSourceDeclaration() toMethod = mc.getTarget().getUnboundDeclaration()
} }
predicate candidates(Method forwarder, Method forwardee) { predicate candidates(Method forwarder, Method forwardee) {
@@ -45,6 +45,6 @@ where
candidates(forwarder, forwardee) and candidates(forwarder, forwardee) and
forex(MethodCall c | callTo(c, forwardee) | callIn(c, forwarder)) and forex(MethodCall c | callTo(c, forwardee) | callIn(c, forwarder)) and
forex(MethodCall c | callIn(c, forwarder) | callTo(c, forwardee)) forex(MethodCall c | callIn(c, forwarder) | callTo(c, forwardee))
select forwarder.getSourceDeclaration(), select forwarder.getUnboundDeclaration(),
"This method is a forwarder for $@, which is not called independently - the methods can be merged.", "This method is a forwarder for $@, which is not called independently - the methods can be merged.",
forwardee.getSourceDeclaration(), forwardee.getName() forwardee.getUnboundDeclaration(), forwardee.getName()

View File

@@ -83,7 +83,7 @@ private class MethodUse extends Use, QualifiableExpr {
) )
} }
override Method getDefinition() { result = getQualifiedDeclaration().getSourceDeclaration() } override Method getDefinition() { result = getQualifiedDeclaration().getUnboundDeclaration() }
override string getUseType() { result = "M" } override string getUseType() { result = "M" }
@@ -122,7 +122,7 @@ private class AccessUse extends Access, Use {
Use.super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) Use.super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
} }
override Declaration getDefinition() { result = this.getTarget().getSourceDeclaration() } override Declaration getDefinition() { result = this.getTarget().getUnboundDeclaration() }
override string getUseType() { override string getUseType() {
if this instanceof Call or this instanceof LocalFunctionAccess if this instanceof Call or this instanceof LocalFunctionAccess
@@ -169,7 +169,7 @@ private class TypeMentionUse extends Use, TypeMention {
Use.super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) Use.super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
} }
override Type getDefinition() { result = this.getType().getSourceDeclaration() } override Type getDefinition() { result = this.getType().getUnboundDeclaration() }
override string getUseType() { override string getUseType() {
if this.getTarget() instanceof ObjectCreation if this.getTarget() instanceof ObjectCreation

View File

@@ -380,7 +380,7 @@ class TypeIsBothConstructedAndUnbound extends TypeViolation {
*/ */
class InconsistentTypeLocation extends TypeViolation { class InconsistentTypeLocation extends TypeViolation {
InconsistentTypeLocation() { InconsistentTypeLocation() {
this.getType().getLocation() != this.getType().getSourceDeclaration().getLocation() this.getType().getLocation() != this.getType().getUnboundDeclaration().getLocation()
} }
override string getMessage() { result = "Inconsistent constructed type location" } override string getMessage() { result = "Inconsistent constructed type location" }
@@ -423,7 +423,7 @@ class MethodViolation extends ConsistencyViolation, DeclarationCheck {
*/ */
class InconsistentMethodLocation extends MethodViolation { class InconsistentMethodLocation extends MethodViolation {
InconsistentMethodLocation() { InconsistentMethodLocation() {
this.getMethod().getLocation() != this.getMethod().getSourceDeclaration().getLocation() this.getMethod().getLocation() != this.getMethod().getUnboundDeclaration().getLocation()
} }
override string getMessage() { result = "Inconsistent constructed method location" } override string getMessage() { result = "Inconsistent constructed method location" }
@@ -435,13 +435,13 @@ class InconsistentMethodLocation extends MethodViolation {
class ConstructedMethodTypeParams extends MethodViolation { class ConstructedMethodTypeParams extends MethodViolation {
ConstructedMethodTypeParams() { ConstructedMethodTypeParams() {
getMethod().(ConstructedGeneric).getNumberOfTypeArguments() != getMethod().(ConstructedGeneric).getNumberOfTypeArguments() !=
getMethod().getSourceDeclaration().(UnboundGeneric).getNumberOfTypeParameters() getMethod().getUnboundDeclaration().(UnboundGeneric).getNumberOfTypeParameters()
} }
override string getMessage() { override string getMessage() {
result = result =
"The constructed method " + getMethod().toStringWithTypes() + "The constructed method " + getMethod().toStringWithTypes() +
" does not match unbound method " + getMethod().getSourceDeclaration().toStringWithTypes() " does not match unbound method " + getMethod().getUnboundDeclaration().toStringWithTypes()
} }
} }
@@ -530,7 +530,9 @@ class KindViolation extends TypeViolation {
* unbound generic. * unbound generic.
*/ */
class InconsistentKind extends TypeViolation { class InconsistentKind extends TypeViolation {
InconsistentKind() { typeKind(this.getType()) != typeKind(this.getType().getSourceDeclaration()) } InconsistentKind() {
typeKind(this.getType()) != typeKind(this.getType().getUnboundDeclaration())
}
override string getMessage() { result = "Inconsistent type kind of source declaration" } override string getMessage() { result = "Inconsistent type kind of source declaration" }
} }
@@ -672,7 +674,7 @@ class MissingCilDeclaration extends ConsistencyViolation, MissingCSharpCheck {
* Holds if the C# declaration is expected to have a CIl declaration. * Holds if the C# declaration is expected to have a CIl declaration.
*/ */
private predicate expectedCilDeclaration(CS::Declaration decl) { private predicate expectedCilDeclaration(CS::Declaration decl) {
decl = decl.getSourceDeclaration() and decl = decl.getUnboundDeclaration() and
not decl instanceof CS::ArrayType and not decl instanceof CS::ArrayType and
decl.getALocation() instanceof CS::Assembly and decl.getALocation() instanceof CS::Assembly and
not decl.(CS::Modifiable).isInternal() and not decl.(CS::Modifiable).isInternal() and
@@ -724,7 +726,7 @@ class ConstructedSourceDeclarationMethod extends MethodViolation {
ConstructedSourceDeclarationMethod() { ConstructedSourceDeclarationMethod() {
method = getMethod() and method = getMethod() and
method = method.getSourceDeclaration() and method = method.getUnboundDeclaration() and
( (
method instanceof ConstructedGeneric or method instanceof ConstructedGeneric or
method.getDeclaringType() instanceof ConstructedGeneric method.getDeclaringType() instanceof ConstructedGeneric

View File

@@ -22,10 +22,17 @@ class Declaration extends DotNet::Declaration, Element, @cil_declaration {
result = toCSharpTypeParameter(this) result = toCSharpTypeParameter(this)
} }
override Declaration getSourceDeclaration() { result = this } override Declaration getUnboundDeclaration() { result = this }
/** Holds if this declaration is a source declaration. */ /** Holds if this declaration is a source declaration. */
final predicate isSourceDeclaration() { this = getSourceDeclaration() } final predicate isUnboundDeclaration() { this = getUnboundDeclaration() }
/**
* DEPRECATED: Use `isUnboundDeclaration()` instead.
*
* Holds if this declaration is a source declaration.
*/
deprecated final predicate isSourceDeclaration() { this.isUnboundDeclaration() }
} }
private CS::Declaration toCSharpNonTypeParameter(Declaration d) { result.matchesHandle(d) } private CS::Declaration toCSharpNonTypeParameter(Declaration d) { result.matchesHandle(d) }

View File

@@ -86,7 +86,7 @@ class Method extends DotNet::Callable, Element, Member, TypeContainer, DataFlowN
override Location getLocation() { result = Element.super.getLocation() } override Location getLocation() { result = Element.super.getLocation() }
override Location getALocation() { cil_method_location(this.getSourceDeclaration(), result) } override Location getALocation() { cil_method_location(this.getUnboundDeclaration(), result) }
override Parameter getRawParameter(int n) { cil_parameter(result, this, n, _) } override Parameter getRawParameter(int n) { cil_parameter(result, this, n, _) }
@@ -128,7 +128,7 @@ class Method extends DotNet::Callable, Element, Member, TypeContainer, DataFlowN
/** Gets the unbound declaration of this method, or the method itself. */ /** Gets the unbound declaration of this method, or the method itself. */
Method getUnboundMethod() { cil_method_source_declaration(this, result) } Method getUnboundMethod() { cil_method_source_declaration(this, result) }
override Method getSourceDeclaration() { result = getUnboundMethod() } override Method getUnboundDeclaration() { result = getUnboundMethod() }
/** Holds if this method is an instance constructor. */ /** Holds if this method is an instance constructor. */
predicate isInstanceConstructor() { isSpecial() and getName() = ".ctor" } predicate isInstanceConstructor() { isSpecial() and getName() = ".ctor" }

View File

@@ -57,7 +57,7 @@ class Type extends DotNet::Type, Declaration, TypeContainer, @cil_type {
qualifier = this.getParent().getQualifiedName() qualifier = this.getParent().getQualifiedName()
} }
override Location getALocation() { cil_type_location(this.getSourceDeclaration(), result) } override Location getALocation() { cil_type_location(this.getUnboundDeclaration(), result) }
/** Holds if this type is a class. */ /** Holds if this type is a class. */
predicate isClass() { cil_class(this) } predicate isClass() { cil_class(this) }
@@ -112,5 +112,5 @@ class Type extends DotNet::Type, Declaration, TypeContainer, @cil_type {
*/ */
int getConversionIndex() { result = 0 } int getConversionIndex() { result = 0 }
override Type getSourceDeclaration() { cil_type(this, _, _, _, result) } override Type getUnboundDeclaration() { cil_type(this, _, _, _, result) }
} }

View File

@@ -108,8 +108,8 @@ class Parameter extends DotNet::Parameter, StackVariable, @cil_parameter {
result = getMethod().getOverriddenMethod().getRawParameter(getRawPosition()) result = getMethod().getOverriddenMethod().getRawParameter(getRawPosition())
} }
override Parameter getSourceDeclaration() { override Parameter getUnboundDeclaration() {
result = getMethod().getSourceDeclaration().getRawParameter(getRawPosition()) result = getMethod().getUnboundDeclaration().getRawParameter(getRawPosition())
} }
} }

View File

@@ -192,8 +192,8 @@ private class RefArg extends AssignableAccess {
) )
} }
private Callable getSourceDeclarationTarget(Parameter p) { private Callable getUnboundDeclarationTarget(Parameter p) {
p = this.getParameter().getSourceDeclaration() and p = this.getParameter().getUnboundDeclaration() and
result.getAParameter() = p result.getAParameter() = p
} }
@@ -203,7 +203,7 @@ private class RefArg extends AssignableAccess {
* source. * source.
*/ */
predicate isAnalyzable(Parameter p) { predicate isAnalyzable(Parameter p) {
exists(Callable callable | callable = this.getSourceDeclarationTarget(p) | exists(Callable callable | callable = this.getUnboundDeclarationTarget(p) |
not callable.(Virtualizable).isOverridableOrImplementable() and not callable.(Virtualizable).isOverridableOrImplementable() and
callable.hasBody() callable.hasBody()
) )
@@ -223,7 +223,7 @@ private class RefArg extends AssignableAccess {
private predicate isNonAnalyzable() { private predicate isNonAnalyzable() {
call instanceof @delegate_invocation_expr call instanceof @delegate_invocation_expr
or or
exists(Callable callable | callable = this.getSourceDeclarationTarget(_) | exists(Callable callable | callable = this.getUnboundDeclarationTarget(_) |
callable.(Virtualizable).isOverridableOrImplementable() or callable.(Virtualizable).isOverridableOrImplementable() or
not callable.hasBody() not callable.hasBody()
) )

View File

@@ -26,7 +26,9 @@ class Callable extends DotNet::Callable, Parameterizable, ExprOrStmtParent, @cal
/** Gets the annotated return type of this callable. */ /** Gets the annotated return type of this callable. */
final AnnotatedType getAnnotatedReturnType() { result.appliesTo(this) } final AnnotatedType getAnnotatedReturnType() { result.appliesTo(this) }
override Callable getSourceDeclaration() { result = Parameterizable.super.getSourceDeclaration() } override Callable getUnboundDeclaration() {
result = Parameterizable.super.getUnboundDeclaration()
}
/** /**
* Gets the body of this callable, if any. * Gets the body of this callable, if any.
@@ -241,7 +243,7 @@ class Method extends Callable, Virtualizable, Attributable, @method {
override Type getReturnType() { methods(this, _, _, getTypeRef(result), _) } override Type getReturnType() { methods(this, _, _, getTypeRef(result), _) }
override Method getSourceDeclaration() { methods(this, _, _, _, result) } override Method getUnboundDeclaration() { methods(this, _, _, _, result) }
override Method getOverridee() { result = Virtualizable.super.getOverridee() } override Method getOverridee() { result = Virtualizable.super.getOverridee() }
@@ -350,7 +352,7 @@ class Constructor extends DotNet::Constructor, Callable, Member, Attributable, @
override ValueOrRefType getDeclaringType() { constructors(this, _, result, _) } override ValueOrRefType getDeclaringType() { constructors(this, _, result, _) }
override Constructor getSourceDeclaration() { constructors(this, _, _, result) } override Constructor getUnboundDeclaration() { constructors(this, _, _, result) }
override Location getALocation() { constructor_location(this, result) } override Location getALocation() { constructor_location(this, result) }
@@ -420,7 +422,7 @@ class Destructor extends DotNet::Destructor, Callable, Member, Attributable, @de
override ValueOrRefType getDeclaringType() { destructors(this, _, result, _) } override ValueOrRefType getDeclaringType() { destructors(this, _, result, _) }
override Destructor getSourceDeclaration() { destructors(this, _, _, result) } override Destructor getUnboundDeclaration() { destructors(this, _, _, result) }
override Location getALocation() { destructor_location(this, result) } override Location getALocation() { destructor_location(this, result) }
@@ -450,7 +452,7 @@ class Operator extends Callable, Member, Attributable, @operator {
override Type getReturnType() { operators(this, _, _, _, getTypeRef(result), _) } override Type getReturnType() { operators(this, _, _, _, getTypeRef(result), _) }
override Operator getSourceDeclaration() { operators(this, _, _, _, _, result) } override Operator getUnboundDeclaration() { operators(this, _, _, _, _, result) }
override Location getALocation() { operator_location(this, result) } override Location getALocation() { operator_location(this, result) }
@@ -973,14 +975,14 @@ class ExplicitConversionOperator extends ConversionOperator {
class LocalFunction extends Callable, Modifiable, @local_function { class LocalFunction extends Callable, Modifiable, @local_function {
override string getName() { local_functions(this, result, _, _) } override string getName() { local_functions(this, result, _, _) }
override LocalFunction getSourceDeclaration() { local_functions(this, _, _, result) } override LocalFunction getUnboundDeclaration() { local_functions(this, _, _, result) }
override Type getReturnType() { local_functions(this, _, result, _) } override Type getReturnType() { local_functions(this, _, result, _) }
override Element getParent() { result = getStatement().getParent() } override Element getParent() { result = getStatement().getParent() }
/** Gets the local function statement defining this function. */ /** Gets the local function statement defining this function. */
LocalFunctionStmt getStatement() { result.getLocalFunction() = getSourceDeclaration() } LocalFunctionStmt getStatement() { result.getLocalFunction() = getUnboundDeclaration() }
override Callable getEnclosingCallable() { result = this.getStatement().getEnclosingCallable() } override Callable getEnclosingCallable() { result = this.getStatement().getEnclosingCallable() }

View File

@@ -43,7 +43,7 @@ class Event extends DeclarationWithAccessors, @event {
not this.getAnEventAccessor().hasBody() not this.getAnEventAccessor().hasBody()
} }
override Event getSourceDeclaration() { events(this, _, _, _, result) } override Event getUnboundDeclaration() { events(this, _, _, _, result) }
override Event getOverridee() { result = DeclarationWithAccessors.super.getOverridee() } override Event getOverridee() { result = DeclarationWithAccessors.super.getOverridee() }
@@ -88,7 +88,7 @@ class EventAccessor extends Accessor, @event_accessor {
override string getAssemblyName() { event_accessors(this, _, result, _, _) } override string getAssemblyName() { event_accessors(this, _, result, _, _) }
override EventAccessor getSourceDeclaration() { event_accessors(this, _, _, _, result) } override EventAccessor getUnboundDeclaration() { event_accessors(this, _, _, _, result) }
override Event getDeclaration() { event_accessors(this, _, _, result, _) } override Event getDeclaration() { event_accessors(this, _, _, result, _) }

View File

@@ -9,7 +9,7 @@
* and its constructed generics (`ConstructedGeneric*`). * and its constructed generics (`ConstructedGeneric*`).
* *
* Generics can be partially constructed if they are unbound generics contained * Generics can be partially constructed if they are unbound generics contained
* within constructed generic types. The predicate `getSourceDeclaration` refers * within constructed generic types. The predicate `getUnboundDeclaration` refers
* to the ultimate `UnboundGeneric` type/method as defined in the source code. * to the ultimate `UnboundGeneric` type/method as defined in the source code.
*/ */
@@ -58,8 +58,8 @@ class ConstructedGeneric extends DotNet::ConstructedGeneric, Generic {
override UnboundGeneric getUnboundGeneric() { constructed_generic(this, result) } override UnboundGeneric getUnboundGeneric() { constructed_generic(this, result) }
override UnboundGeneric getSourceDeclaration() { override UnboundGeneric getUnboundDeclaration() {
result = getUnboundGeneric().getSourceDeclaration() result = getUnboundGeneric().getUnboundDeclaration()
} }
override int getNumberOfTypeArguments() { result = count(int i | type_arguments(_, i, this)) } override int getNumberOfTypeArguments() { result = count(int i | type_arguments(_, i, this)) }
@@ -114,8 +114,8 @@ class UnboundGenericType extends ValueOrRefType, UnboundGeneric {
result = getNameWithoutBrackets() + "<" + this.typeParametersToString() + ">" result = getNameWithoutBrackets() + "<" + this.typeParametersToString() + ">"
} }
override UnboundGenericType getSourceDeclaration() { override UnboundGenericType getUnboundDeclaration() {
result = ValueOrRefType.super.getSourceDeclaration() result = ValueOrRefType.super.getUnboundDeclaration()
} }
final override Type getChild(int n) { result = getTypeParameter(n) } final override Type getChild(int n) { result = getTypeParameter(n) }
@@ -168,7 +168,7 @@ class TypeParameter extends DotNet::TypeParameter, Type, @type_parameter {
// A<int>.B<int> is a ConstructedGenericClass. // A<int>.B<int> is a ConstructedGenericClass.
exists(ConstructedGeneric c, UnboundGeneric u, int tpi | exists(ConstructedGeneric c, UnboundGeneric u, int tpi |
this = u.getTypeParameter(tpi) and this = u.getTypeParameter(tpi) and
(u = c.getUnboundGeneric() or u = c.getSourceDeclaration()) and (u = c.getUnboundGeneric() or u = c.getUnboundDeclaration()) and
result = c.getTypeArgument(tpi) result = c.getTypeArgument(tpi)
) )
} }
@@ -251,8 +251,8 @@ class UnboundGenericStruct extends Struct, UnboundGenericType {
result = UnboundGenericType.super.getAConstructedGeneric() result = UnboundGenericType.super.getAConstructedGeneric()
} }
override UnboundGenericStruct getSourceDeclaration() { override UnboundGenericStruct getUnboundDeclaration() {
result = UnboundGenericType.super.getSourceDeclaration() result = UnboundGenericType.super.getUnboundDeclaration()
} }
} }
@@ -274,8 +274,8 @@ class UnboundGenericClass extends Class, UnboundGenericType {
result = UnboundGenericType.super.getAConstructedGeneric() result = UnboundGenericType.super.getAConstructedGeneric()
} }
override UnboundGenericClass getSourceDeclaration() { override UnboundGenericClass getUnboundDeclaration() {
result = UnboundGenericType.super.getSourceDeclaration() result = UnboundGenericType.super.getUnboundDeclaration()
} }
} }
@@ -297,8 +297,8 @@ class UnboundGenericInterface extends Interface, UnboundGenericType {
result = UnboundGenericType.super.getAConstructedGeneric() result = UnboundGenericType.super.getAConstructedGeneric()
} }
override UnboundGenericInterface getSourceDeclaration() { override UnboundGenericInterface getUnboundDeclaration() {
result = UnboundGenericType.super.getSourceDeclaration() result = UnboundGenericType.super.getUnboundDeclaration()
} }
} }
@@ -321,8 +321,8 @@ class UnboundGenericDelegateType extends DelegateType, UnboundGenericType {
result = UnboundGenericType.super.getAConstructedGeneric() result = UnboundGenericType.super.getAConstructedGeneric()
} }
override UnboundGenericDelegateType getSourceDeclaration() { override UnboundGenericDelegateType getUnboundDeclaration() {
result = UnboundGenericType.super.getSourceDeclaration() result = UnboundGenericType.super.getUnboundDeclaration()
} }
override string toStringWithTypes() { override string toStringWithTypes() {
@@ -345,11 +345,11 @@ class UnboundGenericDelegateType extends DelegateType, UnboundGenericType {
* or constructed method (`ConstructedMethod`). * or constructed method (`ConstructedMethod`).
*/ */
class ConstructedType extends ValueOrRefType, ConstructedGeneric { class ConstructedType extends ValueOrRefType, ConstructedGeneric {
override UnboundGenericType getSourceDeclaration() { override UnboundGenericType getUnboundDeclaration() {
result = ConstructedGeneric.super.getSourceDeclaration() result = ConstructedGeneric.super.getUnboundDeclaration()
} }
override Location getALocation() { result = this.getSourceDeclaration().getALocation() } override Location getALocation() { result = this.getUnboundDeclaration().getALocation() }
override Type getTypeArgument(int n) { type_arguments(getTypeRef(result), n, getTypeRef(this)) } override Type getTypeArgument(int n) { type_arguments(getTypeRef(result), n, getTypeRef(this)) }
@@ -387,8 +387,8 @@ class ConstructedType extends ValueOrRefType, ConstructedGeneric {
* ``` * ```
*/ */
class ConstructedStruct extends Struct, ConstructedType { class ConstructedStruct extends Struct, ConstructedType {
override UnboundGenericStruct getSourceDeclaration() { override UnboundGenericStruct getUnboundDeclaration() {
result = ConstructedType.super.getSourceDeclaration() result = ConstructedType.super.getUnboundDeclaration()
} }
override UnboundGenericStruct getUnboundGeneric() { override UnboundGenericStruct getUnboundGeneric() {
@@ -410,8 +410,8 @@ class ConstructedStruct extends Struct, ConstructedType {
* ``` * ```
*/ */
class ConstructedClass extends Class, ConstructedType { class ConstructedClass extends Class, ConstructedType {
override UnboundGenericClass getSourceDeclaration() { override UnboundGenericClass getUnboundDeclaration() {
result = ConstructedType.super.getSourceDeclaration() result = ConstructedType.super.getUnboundDeclaration()
} }
override UnboundGenericClass getUnboundGeneric() { override UnboundGenericClass getUnboundGeneric() {
@@ -433,8 +433,8 @@ class ConstructedClass extends Class, ConstructedType {
* ``` * ```
*/ */
class ConstructedInterface extends Interface, ConstructedType { class ConstructedInterface extends Interface, ConstructedType {
override UnboundGenericInterface getSourceDeclaration() { override UnboundGenericInterface getUnboundDeclaration() {
result = ConstructedType.super.getSourceDeclaration() result = ConstructedType.super.getUnboundDeclaration()
} }
override UnboundGenericInterface getUnboundGeneric() { override UnboundGenericInterface getUnboundGeneric() {
@@ -456,8 +456,8 @@ class ConstructedInterface extends Interface, ConstructedType {
* ``` * ```
*/ */
class ConstructedDelegateType extends DelegateType, ConstructedType { class ConstructedDelegateType extends DelegateType, ConstructedType {
override UnboundGenericDelegateType getSourceDeclaration() { override UnboundGenericDelegateType getUnboundDeclaration() {
result = ConstructedType.super.getSourceDeclaration() result = ConstructedType.super.getUnboundDeclaration()
} }
override UnboundGenericDelegateType getUnboundGeneric() { override UnboundGenericDelegateType getUnboundGeneric() {
@@ -510,7 +510,7 @@ class UnboundGenericMethod extends Method, UnboundGeneric {
* corresponds to `UnboundGenericType`. * corresponds to `UnboundGenericType`.
*/ */
class ConstructedMethod extends Method, ConstructedGeneric { class ConstructedMethod extends Method, ConstructedGeneric {
override Location getALocation() { result = this.getSourceDeclaration().getALocation() } override Location getALocation() { result = this.getUnboundDeclaration().getALocation() }
override Type getTypeArgument(int n) { type_arguments(getTypeRef(result), n, this) } override Type getTypeArgument(int n) { type_arguments(getTypeRef(result), n, this) }
@@ -521,8 +521,8 @@ class ConstructedMethod extends Method, ConstructedGeneric {
getName() + "<" + this.typeArgumentsToString() + ">" + "(" + parameterTypesToString() + ")" getName() + "<" + this.typeArgumentsToString() + ">" + "(" + parameterTypesToString() + ")"
} }
override UnboundGenericMethod getSourceDeclaration() { override UnboundGenericMethod getUnboundDeclaration() {
result = Method.super.getSourceDeclaration() result = Method.super.getUnboundDeclaration()
} }
} }
@@ -557,8 +557,8 @@ class UnboundLocalFunction extends LocalFunction, UnboundGeneric {
* ``` * ```
*/ */
class ConstructedLocalFunction extends LocalFunction, ConstructedGeneric { class ConstructedLocalFunction extends LocalFunction, ConstructedGeneric {
override UnboundLocalFunction getSourceDeclaration() { override UnboundLocalFunction getUnboundDeclaration() {
result = LocalFunction.super.getSourceDeclaration() result = LocalFunction.super.getUnboundDeclaration()
} }
override UnboundLocalFunction getUnboundGeneric() { override UnboundLocalFunction getUnboundGeneric() {

View File

@@ -351,7 +351,7 @@ private module Gvn {
private Unification::GenericType getConstructedGenericDeclaringTypeAt(int i) { private Unification::GenericType getConstructedGenericDeclaringTypeAt(int i) {
i = 0 and i = 0 and
result = this.getKind().getConstructedSourceDeclaration() result = this.getKind().getConstructedUnboundDeclaration()
or or
result = this.getConstructedGenericDeclaringTypeAt(i - 1).getGenericDeclaringType() result = this.getConstructedGenericDeclaringTypeAt(i - 1).getGenericDeclaringType()
} }

View File

@@ -16,8 +16,11 @@ private import TypeRef
class Declaration extends DotNet::Declaration, Element, @declaration { class Declaration extends DotNet::Declaration, Element, @declaration {
override ValueOrRefType getDeclaringType() { none() } override ValueOrRefType getDeclaringType() { none() }
/** Holds if this declaration is unbound. */
final predicate isUnboundDeclaration() { this = this.getUnboundDeclaration() }
/** Holds if this declaration is unconstructed and in source code. */ /** Holds if this declaration is unconstructed and in source code. */
predicate isSourceDeclaration() { fromSource() and this = getSourceDeclaration() } final predicate isSourceDeclaration() { this.fromSource() and this.isUnboundDeclaration() }
override string toString() { result = this.getName() } override string toString() { result = this.getName() }

View File

@@ -147,7 +147,7 @@ class Property extends DotNet::Property, DeclarationWithGetSetAccessors, @proper
not this.getAnAccessor().hasBody() not this.getAnAccessor().hasBody()
} }
override Property getSourceDeclaration() { properties(this, _, _, _, result) } override Property getUnboundDeclaration() { properties(this, _, _, _, result) }
override Property getOverridee() { result = DeclarationWithGetSetAccessors.super.getOverridee() } override Property getOverridee() { result = DeclarationWithGetSetAccessors.super.getOverridee() }
@@ -274,7 +274,7 @@ class Indexer extends DeclarationWithGetSetAccessors, Parameterizable, @indexer
result = DeclarationWithGetSetAccessors.super.getExpressionBody() result = DeclarationWithGetSetAccessors.super.getExpressionBody()
} }
override Indexer getSourceDeclaration() { indexers(this, _, _, _, result) } override Indexer getUnboundDeclaration() { indexers(this, _, _, _, result) }
override Indexer getOverridee() { result = DeclarationWithGetSetAccessors.super.getOverridee() } override Indexer getOverridee() { result = DeclarationWithGetSetAccessors.super.getOverridee() }
@@ -370,7 +370,7 @@ class Accessor extends Callable, Modifiable, Attributable, @callable_accessor {
not (result instanceof AccessModifier and exists(getAnAccessModifier())) not (result instanceof AccessModifier and exists(getAnAccessModifier()))
} }
override Accessor getSourceDeclaration() { accessors(this, _, _, _, result) } override Accessor getUnboundDeclaration() { accessors(this, _, _, _, result) }
override Location getALocation() { accessor_location(this, result) } override Location getALocation() { accessor_location(this, result) }

View File

@@ -21,7 +21,7 @@ private import TypeRef
class Type extends DotNet::Type, Member, TypeContainer, @type { class Type extends DotNet::Type, Member, TypeContainer, @type {
override string getName() { types(this, _, result) } override string getName() { types(this, _, result) }
override Type getSourceDeclaration() { result = this } override Type getUnboundDeclaration() { result = this }
/** Holds if this type is implicitly convertible to `that` type. */ /** Holds if this type is implicitly convertible to `that` type. */
predicate isImplicitlyConvertibleTo(Type that) { implicitConversion(this, that) } predicate isImplicitlyConvertibleTo(Type that) { implicitConversion(this, that) }
@@ -367,11 +367,11 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
/** Gets the number of callables in this type. */ /** Gets the number of callables in this type. */
int getNumberOfCallables() { result = count(Callable c | this.getAMember() = c) } int getNumberOfCallables() { result = count(Callable c | this.getAMember() = c) }
override ValueOrRefType getSourceDeclaration() { override ValueOrRefType getUnboundDeclaration() {
result = this and result = this and
not this instanceof NestedType not this instanceof NestedType
or or
// We must use `nested_types` here, rather than overriding `getSourceDeclaration` // We must use `nested_types` here, rather than overriding `getUnboundDeclaration`
// in the class `NestedType` below. Otherwise, the overrides in `UnboundGenericType` // in the class `NestedType` below. Otherwise, the overrides in `UnboundGenericType`
// and its subclasses will not work // and its subclasses will not work
nested_types(this, _, result) nested_types(this, _, result)

View File

@@ -94,13 +94,13 @@ module Gvn {
or or
this = TArrayTypeKind(_, _) and result = 1 this = TArrayTypeKind(_, _) and result = 1
or or
exists(GenericType t | this = TConstructedType(t.getSourceDeclaration()) | exists(GenericType t | this = TConstructedType(t.getUnboundDeclaration()) |
result = t.getNumberOfArguments() result = t.getNumberOfArguments()
) )
} }
/** Gets the source declaration type that this kind corresponds to, if any. */ /** Gets the unbound declaration type that this kind corresponds to, if any. */
GenericType getConstructedSourceDeclaration() { this = TConstructedType(result) } GenericType getConstructedUnboundDeclaration() { this = TConstructedType(result) }
/** /**
* Gets a textual representation of this kind when applied to arguments `args`. * Gets a textual representation of this kind when applied to arguments `args`.
@@ -123,7 +123,7 @@ module Gvn {
string toString() { string toString() {
result = this.toStringBuiltin("") result = this.toStringBuiltin("")
or or
result = this.getConstructedSourceDeclaration().toStringNested() result = this.getConstructedUnboundDeclaration().toStringNested()
} }
/** Gets the location of this kind. */ /** Gets the location of this kind. */
@@ -138,9 +138,9 @@ module Gvn {
or or
t = any(ArrayType at | result = TArrayTypeKind(at.getDimension(), at.getRank())) t = any(ArrayType at | result = TArrayTypeKind(at.getDimension(), at.getRank()))
or or
result = TConstructedType(t.getSourceDeclaration()) result = TConstructedType(t.getUnboundDeclaration())
or or
result = TConstructedType(t.(TupleType).getUnderlyingType().getSourceDeclaration()) result = TConstructedType(t.(TupleType).getUnderlyingType().getUnboundDeclaration())
} }
/** /**
@@ -230,7 +230,7 @@ module Gvn {
private GenericType getConstructedGenericDeclaringTypeAt(int i) { private GenericType getConstructedGenericDeclaringTypeAt(int i) {
i = 0 and i = 0 and
result = this.getKind().getConstructedSourceDeclaration() result = this.getKind().getConstructedUnboundDeclaration()
or or
result = this.getConstructedGenericDeclaringTypeAt(i - 1).getGenericDeclaringType() result = this.getConstructedGenericDeclaringTypeAt(i - 1).getGenericDeclaringType()
} }
@@ -499,12 +499,12 @@ module Gvn {
TArrayTypeKind(int dim, int rnk) { TArrayTypeKind(int dim, int rnk) {
exists(ArrayType at | dim = at.getDimension() and rnk = at.getRank()) exists(ArrayType at | dim = at.getDimension() and rnk = at.getRank())
} or } or
TConstructedType(GenericType sourceDecl) { TConstructedType(GenericType unboundDecl) {
sourceDecl = any(GenericType t).getSourceDeclaration() and unboundDecl = any(GenericType t).getUnboundDeclaration() and
not sourceDecl instanceof PointerType and not unboundDecl instanceof PointerType and
not sourceDecl instanceof NullableType and not unboundDecl instanceof NullableType and
not sourceDecl instanceof ArrayType and not unboundDecl instanceof ArrayType and
not sourceDecl instanceof TupleType not unboundDecl instanceof TupleType
} }
cached cached

View File

@@ -15,7 +15,7 @@ private import TypeRef
* A variable. Either a variable with local scope (`LocalScopeVariable`) or a field (`Field`). * A variable. Either a variable with local scope (`LocalScopeVariable`) or a field (`Field`).
*/ */
class Variable extends Assignable, DotNet::Variable, @variable { class Variable extends Assignable, DotNet::Variable, @variable {
override Variable getSourceDeclaration() { result = this } override Variable getUnboundDeclaration() { result = this }
override VariableAccess getAnAccess() { result.getTarget() = this } override VariableAccess getAnAccess() { result.getTarget() = this }
@@ -179,7 +179,7 @@ class Parameter extends DotNet::Parameter, LocalScopeVariable, Attributable, Top
/** Gets the declaring element of this parameter. */ /** Gets the declaring element of this parameter. */
Parameterizable getDeclaringElement() { params(this, _, _, _, _, result, _) } Parameterizable getDeclaringElement() { params(this, _, _, _, _, result, _) }
override Parameter getSourceDeclaration() { params(this, _, _, _, _, _, result) } override Parameter getUnboundDeclaration() { params(this, _, _, _, _, _, result) }
override ValueOrRefType getDeclaringType() { override ValueOrRefType getDeclaringType() {
exists(Parameterizable p | p = this.getDeclaringElement() | exists(Parameterizable p | p = this.getDeclaringElement() |
@@ -207,7 +207,7 @@ class Parameter extends DotNet::Parameter, LocalScopeVariable, Attributable, Top
* } * }
* ``` * ```
*/ */
Expr getDefaultValue() { result = this.getSourceDeclaration().getChildExpr(0) } Expr getDefaultValue() { result = this.getUnboundDeclaration().getChildExpr(0) }
/** Holds if this parameter has a default value. */ /** Holds if this parameter has a default value. */
predicate hasDefaultValue() { exists(getDefaultValue()) } predicate hasDefaultValue() { exists(getDefaultValue()) }
@@ -397,7 +397,7 @@ class Field extends Variable, AssignableMember, Attributable, TopLevelExprParent
/** Holds if this field is `readonly`. */ /** Holds if this field is `readonly`. */
predicate isReadOnly() { this.hasModifier("readonly") } predicate isReadOnly() { this.hasModifier("readonly") }
override Field getSourceDeclaration() { fields(this, _, _, _, _, result) } override Field getUnboundDeclaration() { fields(this, _, _, _, _, result) }
override FieldAccess getAnAccess() { result = Variable.super.getAnAccess() } override FieldAccess getAnAccess() { result = Variable.super.getAnAccess() }

View File

@@ -105,7 +105,7 @@ private newtype TComparisonTest =
m = any(SystemIComparableInterface i).getCompareToMethod() m = any(SystemIComparableInterface i).getCompareToMethod()
or or
m = any(SystemIComparableTInterface i).getAConstructedGeneric().getAMethod() and m = any(SystemIComparableTInterface i).getAConstructedGeneric().getAMethod() and
m.getSourceDeclaration() = any(SystemIComparableTInterface i).getCompareToMethod() m.getUnboundDeclaration() = any(SystemIComparableTInterface i).getCompareToMethod()
) )
} or } or
TCompareCall(MethodCall mc) { TCompareCall(MethodCall mc) {
@@ -116,7 +116,7 @@ private newtype TComparisonTest =
m = any(SystemCollectionsIComparerInterface i).getCompareMethod() m = any(SystemCollectionsIComparerInterface i).getCompareMethod()
or or
m = any(SystemCollectionsGenericIComparerTInterface i).getAConstructedGeneric().getAMethod() and m = any(SystemCollectionsGenericIComparerTInterface i).getAConstructedGeneric().getAMethod() and
m.getSourceDeclaration() = m.getUnboundDeclaration() =
any(SystemCollectionsGenericIComparerTInterface i).getCompareMethod() any(SystemCollectionsGenericIComparerTInterface i).getCompareMethod()
) )
} or } or

View File

@@ -23,7 +23,7 @@ private predicate disposedCilVariable(CIL::Variable variable) {
) )
or or
// A parameter is disposed if its source declaration is disposed // A parameter is disposed if its source declaration is disposed
disposedCilVariable(variable.(CIL::Parameter).getSourceDeclaration()) disposedCilVariable(variable.(CIL::Parameter).getUnboundDeclaration())
or or
// A variable is disposed if it's assigned to another variable // A variable is disposed if it's assigned to another variable
// that may be disposed. // that may be disposed.
@@ -59,7 +59,7 @@ private predicate disposedCSharpVariable(Variable variable) {
) )
or or
// A parameter is disposed if its source declaration is disposed // A parameter is disposed if its source declaration is disposed
disposedCSharpVariable(variable.(Parameter).getSourceDeclaration()) disposedCSharpVariable(variable.(Parameter).getUnboundDeclaration())
or or
// A variable is disposed if it's assigned to another variable that is disposed // A variable is disposed if it's assigned to another variable that is disposed
exists(AssignableDefinition assign | exists(AssignableDefinition assign |

View File

@@ -484,14 +484,14 @@ class CollectionExpr extends Expr {
pr pr
.getTarget() .getTarget()
.overridesOrImplementsOrEquals(any(Property p | .overridesOrImplementsOrEquals(any(Property p |
p.getSourceDeclaration() = p.getUnboundDeclaration() =
any(SystemCollectionsGenericICollectionInterface x).getCountProperty() any(SystemCollectionsGenericICollectionInterface x).getCountProperty()
)) ))
) )
or or
result = result =
any(MethodCall mc | any(MethodCall mc |
mc.getTarget().getSourceDeclaration() = mc.getTarget().getUnboundDeclaration() =
any(SystemLinq::SystemLinqEnumerableClass x).getACountMethod() and any(SystemLinq::SystemLinqEnumerableClass x).getACountMethod() and
this = mc.getArgument(0) and this = mc.getArgument(0) and
if mc.getNumberOfArguments() = 1 then lowerBound = false else lowerBound = true if mc.getNumberOfArguments() = 1 then lowerBound = false else lowerBound = true
@@ -544,7 +544,7 @@ class CollectionExpr extends Expr {
or or
result = result =
any(MethodCall mc | any(MethodCall mc |
mc.getTarget().getSourceDeclaration() = mc.getTarget().getUnboundDeclaration() =
any(SystemLinq::SystemLinqEnumerableClass x).getAnAnyMethod() and any(SystemLinq::SystemLinqEnumerableClass x).getAnAnyMethod() and
this = mc.getArgument(0) and this = mc.getArgument(0) and
branch = isEmpty.booleanNot() and branch = isEmpty.booleanNot() and
@@ -842,7 +842,7 @@ module Internal {
or or
e instanceof DefaultValueExpr and e.getType().isRefType() e instanceof DefaultValueExpr and e.getType().isRefType()
or or
e.(Call).getTarget().getSourceDeclaration() instanceof NullCallable e.(Call).getTarget().getUnboundDeclaration() instanceof NullCallable
} }
/** Holds if expression `e2` is a `null` value whenever `e1` is. */ /** Holds if expression `e2` is a `null` value whenever `e1` is. */
@@ -893,7 +893,7 @@ module Internal {
or or
e.(DefaultValueExpr).getType().isValueType() e.(DefaultValueExpr).getType().isValueType()
or or
e.(Call).getTarget().getSourceDeclaration() instanceof NonNullCallable and e.(Call).getTarget().getUnboundDeclaration() instanceof NonNullCallable and
not e.(QualifiableExpr).isConditional() not e.(QualifiableExpr).isConditional()
or or
e instanceof SuppressNullableWarningExpr e instanceof SuppressNullableWarningExpr
@@ -1428,8 +1428,8 @@ module Internal {
cached cached
predicate isCustomNullCheck(Call call, Expr arg, BooleanValue v, boolean isNull) { predicate isCustomNullCheck(Call call, Expr arg, BooleanValue v, boolean isNull) {
exists(Callable callable, Parameter p | exists(Callable callable, Parameter p |
arg = call.getArgumentForParameter(any(Parameter p0 | p0.getSourceDeclaration() = p)) and arg = call.getArgumentForParameter(any(Parameter p0 | p0.getUnboundDeclaration() = p)) and
call.getTarget().getSourceDeclaration() = callable and call.getTarget().getUnboundDeclaration() = callable and
callable = customNullCheck(p, v, isNull) callable = customNullCheck(p, v, isNull)
) )
} }
@@ -1645,7 +1645,7 @@ module Internal {
exists(PreSsa::Definition def | emptyDef(def) | firstReadSameVarUniquePredecesssor(def, e)) exists(PreSsa::Definition def | emptyDef(def) | firstReadSameVarUniquePredecesssor(def, e))
or or
exists(MethodCall mc | exists(MethodCall mc |
mc.getTarget().getAnUltimateImplementee().getSourceDeclaration() = mc.getTarget().getAnUltimateImplementee().getUnboundDeclaration() =
any(SystemCollectionsGenericICollectionInterface c).getClearMethod() and any(SystemCollectionsGenericICollectionInterface c).getClearMethod() and
adjacentReadPairSameVarUniquePredecessor(mc.getQualifier(), e) adjacentReadPairSameVarUniquePredecessor(mc.getQualifier(), e)
) )
@@ -1670,7 +1670,7 @@ module Internal {
) )
or or
exists(MethodCall mc | exists(MethodCall mc |
mc.getTarget().getAnUltimateImplementee().getSourceDeclaration() = mc.getTarget().getAnUltimateImplementee().getUnboundDeclaration() =
any(SystemCollectionsGenericICollectionInterface c).getAddMethod() and any(SystemCollectionsGenericICollectionInterface c).getAddMethod() and
adjacentReadPairSameVarUniquePredecessor(mc.getQualifier(), e) adjacentReadPairSameVarUniquePredecessor(mc.getQualifier(), e)
) )

View File

@@ -245,7 +245,7 @@ module InitializerSplitting {
* of member `m`. * of member `m`.
*/ */
predicate constructorInitializes(Constructor c, InitializedInstanceMember m) { predicate constructorInitializes(Constructor c, InitializedInstanceMember m) {
c = c.getSourceDeclaration() and c.isUnboundDeclaration() and
not c.isStatic() and not c.isStatic() and
c.getDeclaringType().hasMember(m) and c.getDeclaringType().hasMember(m) and
( (

View File

@@ -27,13 +27,13 @@ module ContentList {
/** Gets a singleton property content list. */ /** Gets a singleton property content list. */
ContentList property(Property p) { ContentList property(Property p) {
result = result =
singleton(any(DataFlowPublic::PropertyContent c | c.getProperty() = p.getSourceDeclaration())) singleton(any(DataFlowPublic::PropertyContent c | c.getProperty() = p.getUnboundDeclaration()))
} }
/** Gets a singleton field content list. */ /** Gets a singleton field content list. */
ContentList field(Field f) { ContentList field(Field f) {
result = result =
singleton(any(DataFlowPublic::FieldContent c | c.getField() = f.getSourceDeclaration())) singleton(any(DataFlowPublic::FieldContent c | c.getField() = f.getUnboundDeclaration()))
} }
} }

View File

@@ -94,12 +94,12 @@ module AccessPath {
/** Gets a singleton property access path. */ /** Gets a singleton property access path. */
AccessPath property(Property p) { AccessPath property(Property p) {
result = singleton(any(PropertyContent c | c.getProperty() = p.getSourceDeclaration())) result = singleton(any(PropertyContent c | c.getProperty() = p.getUnboundDeclaration()))
} }
/** Gets a singleton field access path. */ /** Gets a singleton field access path. */
AccessPath field(Field f) { AccessPath field(Field f) {
result = singleton(any(FieldContent c | c.getField() = f.getSourceDeclaration())) result = singleton(any(FieldContent c | c.getField() = f.getUnboundDeclaration()))
} }
/** Gets an access path representing a property inside a collection. */ /** Gets an access path representing a property inside a collection. */
@@ -108,7 +108,7 @@ module AccessPath {
/** An unbound callable. */ /** An unbound callable. */
class SourceDeclarationCallable extends Callable { class SourceDeclarationCallable extends Callable {
SourceDeclarationCallable() { this = this.getSourceDeclaration() } SourceDeclarationCallable() { this.isUnboundDeclaration() }
} }
/** An unbound method. */ /** An unbound method. */
@@ -301,7 +301,7 @@ class CallableFlowSinkDelegateArg extends CallableFlowSink, TCallableFlowSinkDel
/** A specification of data flow for a library (non-source code) type. */ /** A specification of data flow for a library (non-source code) type. */
abstract class LibraryTypeDataFlow extends Type { abstract class LibraryTypeDataFlow extends Type {
LibraryTypeDataFlow() { this = this.getSourceDeclaration() } LibraryTypeDataFlow() { this = this.getUnboundDeclaration() }
/** /**
* Holds if data may flow from `source` to `sink` when calling callable `c`. * Holds if data may flow from `source` to `sink` when calling callable `c`.
@@ -779,7 +779,7 @@ class SystemLazyFlow extends LibraryTypeDataFlow, SystemLazyClass {
preservesValue = true and preservesValue = true and
exists(SystemFuncDelegateType t, int i | t.getNumberOfTypeParameters() = 1 | exists(SystemFuncDelegateType t, int i | t.getNumberOfTypeParameters() = 1 |
c.(Constructor).getDeclaringType() = this and c.(Constructor).getDeclaringType() = this and
c.getParameter(i).getType().getSourceDeclaration() = t and c.getParameter(i).getType().getUnboundDeclaration() = t and
source = getDelegateFlowSourceArg(c, i) and source = getDelegateFlowSourceArg(c, i) and
sourceAp = AccessPath::empty() and sourceAp = AccessPath::empty() and
sink = TCallableFlowSinkReturn() and sink = TCallableFlowSinkReturn() and
@@ -917,7 +917,7 @@ class IEnumerableFlow extends LibraryTypeDataFlow, RefType {
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp, CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
SourceDeclarationMethod m SourceDeclarationMethod m
) { ) {
m.(ExtensionMethod).getExtendedType().getSourceDeclaration() = this and m.(ExtensionMethod).getExtendedType().getUnboundDeclaration() = this and
exists(string name, int arity | name = m.getName() and arity = m.getNumberOfParameters() | exists(string name, int arity | name = m.getName() and arity = m.getNumberOfParameters() |
name = "Aggregate" and name = "Aggregate" and
( (
@@ -1123,7 +1123,7 @@ class IEnumerableFlow extends LibraryTypeDataFlow, RefType {
sink = getDelegateFlowSinkArg(m, 2, 0) and sink = getDelegateFlowSinkArg(m, 2, 0) and
sinkAp = AccessPath::empty() sinkAp = AccessPath::empty()
or or
not m.getParameter(2).getType().getSourceDeclaration() instanceof not m.getParameter(2).getType().getUnboundDeclaration() instanceof
SystemCollectionsGenericIEqualityComparerTInterface and SystemCollectionsGenericIEqualityComparerTInterface and
source = getDelegateFlowSourceArg(m, 2) and source = getDelegateFlowSourceArg(m, 2) and
sourceAp = AccessPath::empty() and sourceAp = AccessPath::empty() and
@@ -1437,7 +1437,7 @@ class IEnumerableFlow extends LibraryTypeDataFlow, RefType {
/** Data flow for `System.Collections.[Generic.]ICollection` (and sub types). */ /** Data flow for `System.Collections.[Generic.]ICollection` (and sub types). */
class ICollectionFlow extends LibraryTypeDataFlow, RefType { class ICollectionFlow extends LibraryTypeDataFlow, RefType {
ICollectionFlow() { ICollectionFlow() {
exists(Interface i | i = this.getABaseType*().getSourceDeclaration() | exists(Interface i | i = this.getABaseType*().getUnboundDeclaration() |
i instanceof SystemCollectionsICollectionInterface i instanceof SystemCollectionsICollectionInterface
or or
i instanceof SystemCollectionsGenericICollectionInterface i instanceof SystemCollectionsGenericICollectionInterface
@@ -1486,7 +1486,7 @@ class ICollectionFlow extends LibraryTypeDataFlow, RefType {
/** Data flow for `System.Collections.[Generic.]IList` (and sub types). */ /** Data flow for `System.Collections.[Generic.]IList` (and sub types). */
class IListFlow extends LibraryTypeDataFlow, RefType { class IListFlow extends LibraryTypeDataFlow, RefType {
IListFlow() { IListFlow() {
exists(Interface i | i = this.getABaseType*().getSourceDeclaration() | exists(Interface i | i = this.getABaseType*().getUnboundDeclaration() |
i instanceof SystemCollectionsIListInterface i instanceof SystemCollectionsIListInterface
or or
i instanceof SystemCollectionsGenericIListInterface i instanceof SystemCollectionsGenericIListInterface
@@ -1536,7 +1536,7 @@ class IListFlow extends LibraryTypeDataFlow, RefType {
/** Data flow for `System.Collections.[Generic.]IDictionary` (and sub types). */ /** Data flow for `System.Collections.[Generic.]IDictionary` (and sub types). */
class IDictionaryFlow extends LibraryTypeDataFlow, RefType { class IDictionaryFlow extends LibraryTypeDataFlow, RefType {
IDictionaryFlow() { IDictionaryFlow() {
exists(Interface i | i = this.getABaseType*().getSourceDeclaration() | exists(Interface i | i = this.getABaseType*().getUnboundDeclaration() |
i instanceof SystemCollectionsIDictionaryInterface i instanceof SystemCollectionsIDictionaryInterface
or or
i instanceof SystemCollectionsGenericIDictionaryInterface i instanceof SystemCollectionsGenericIDictionaryInterface
@@ -1776,13 +1776,13 @@ class SystemTupleFlow extends LibraryTypeDataFlow, ValueOrRefType {
t = this t = this
or or
c = this.getAMethod(any(string name | name.regexpMatch("Create(<,*>)?"))) and c = this.getAMethod(any(string name | name.regexpMatch("Create(<,*>)?"))) and
t = c.getReturnType().getSourceDeclaration() t = c.getReturnType().getUnboundDeclaration()
) )
or or
c = c =
any(ExtensionMethod m | any(ExtensionMethod m |
m.hasName("Deconstruct") and m.hasName("Deconstruct") and
this = m.getExtendedType().getSourceDeclaration() and this = m.getExtendedType().getUnboundDeclaration() and
exists(int i | exists(int i |
m.getParameter(i).isOut() and m.getParameter(i).isOut() and
source = getFlowSourceArg(c, 0, _) and source = getFlowSourceArg(c, 0, _) and
@@ -2179,7 +2179,7 @@ library class SystemTextEncodingFlow extends LibraryTypeDataFlow, SystemTextEnco
) { ) {
preservesValue = false and preservesValue = false and
c = this.getAMethod() and c = this.getAMethod() and
exists(Method m | m.getAnOverrider*().getSourceDeclaration() = c | exists(Method m | m.getAnOverrider*().getUnboundDeclaration() = c |
m = getGetBytesMethod() and m = getGetBytesMethod() and
source = getFlowSourceArg(m, 0, sourceAp) and source = getFlowSourceArg(m, 0, sourceAp) and
sink = TCallableFlowSinkReturn() and sink = TCallableFlowSinkReturn() and

View File

@@ -153,7 +153,7 @@ private predicate isMaybeNullArgument(Ssa::ExplicitDefinition def, MaybeNullExpr
exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p | exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p |
pdef = def.getADefinition() pdef = def.getADefinition()
| |
p = pdef.getParameter().getSourceDeclaration() and p = pdef.getParameter().getUnboundDeclaration() and
arg = p.getAnAssignedArgument() and arg = p.getAnAssignedArgument() and
not arg.getEnclosingCallable().getEnclosingCallable*() instanceof TestMethod not arg.getEnclosingCallable().getEnclosingCallable*() instanceof TestMethod
) )
@@ -163,7 +163,7 @@ private predicate isNullDefaultArgument(Ssa::ExplicitDefinition def, AlwaysNullE
exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p | exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p |
pdef = def.getADefinition() pdef = def.getADefinition()
| |
p = pdef.getParameter().getSourceDeclaration() and p = pdef.getParameter().getUnboundDeclaration() and
arg = p.getDefaultValue() and arg = p.getDefaultValue() and
not arg.getEnclosingCallable().getEnclosingCallable*() instanceof TestMethod not arg.getEnclosingCallable().getEnclosingCallable*() instanceof TestMethod
) )
@@ -498,7 +498,7 @@ class Dereference extends G::DereferenceableExpr {
| |
pdef = def.getADefinition() pdef = def.getADefinition()
| |
p.getSourceDeclaration() = pdef.getParameter() and p.getUnboundDeclaration() = pdef.getParameter() and
def.getARead() instanceof Dereference def.getARead() instanceof Dereference
) )
) )

View File

@@ -1050,7 +1050,7 @@ module Ssa {
Callable getARuntimeTarget(Call c, boolean libraryDelegateCall) { Callable getARuntimeTarget(Call c, boolean libraryDelegateCall) {
// Non-delegate call: use dispatch library // Non-delegate call: use dispatch library
exists(DispatchCall dc | dc.getCall() = c | exists(DispatchCall dc | dc.getCall() = c |
result = dc.getADynamicTarget().getSourceDeclaration() and result = dc.getADynamicTarget().getUnboundDeclaration() and
libraryDelegateCall = false libraryDelegateCall = false
) )
or or
@@ -1090,7 +1090,7 @@ module Ssa {
or or
e = e =
any(CallableAccess ca | any(CallableAccess ca |
c = ca.getTarget().getSourceDeclaration() and c = ca.getTarget().getUnboundDeclaration() and
dt = ca.getType() dt = ca.getType()
) )
} }
@@ -1099,7 +1099,7 @@ module Ssa {
Steps::stepClosed(pred, succ) Steps::stepClosed(pred, succ)
or or
exists(Call call, Callable callable | exists(Call call, Callable callable |
callable.getSourceDeclaration().canReturn(pred) and callable.getUnboundDeclaration().canReturn(pred) and
call = succ call = succ
| |
callable = call.getTarget() or callable = call.getTarget() or

View File

@@ -17,30 +17,30 @@ private import semmle.code.csharp.frameworks.system.collections.Generic
* code version. * code version.
*/ */
DotNet::Callable getCallableForDataFlow(DotNet::Callable c) { DotNet::Callable getCallableForDataFlow(DotNet::Callable c) {
exists(DotNet::Callable sourceDecl | sourceDecl = c.getSourceDeclaration() | exists(DotNet::Callable unboundDecl | unboundDecl = c.getUnboundDeclaration() |
result = sourceDecl and result = unboundDecl and
result instanceof SummarizedCallable result instanceof SummarizedCallable
or or
result = sourceDecl and result = unboundDecl and
FlowSummaryImpl::Private::summary(_, _, _, SummaryOutput::jump(result, _), _, _) FlowSummaryImpl::Private::summary(_, _, _, SummaryOutput::jump(result, _), _, _)
or or
result.hasBody() and result.hasBody() and
if sourceDecl.getFile().fromSource() if unboundDecl.getFile().fromSource()
then then
// C# callable with C# implementation in the database // C# callable with C# implementation in the database
result = sourceDecl result = unboundDecl
else else
if sourceDecl instanceof CIL::Callable if unboundDecl instanceof CIL::Callable
then then
// CIL callable with C# implementation in the database // CIL callable with C# implementation in the database
sourceDecl.matchesHandle(result.(Callable)) unboundDecl.matchesHandle(result.(Callable))
or or
// CIL callable without C# implementation in the database // CIL callable without C# implementation in the database
not sourceDecl.matchesHandle(any(Callable k | k.hasBody())) and not unboundDecl.matchesHandle(any(Callable k | k.hasBody())) and
result = sourceDecl result = unboundDecl
else else
// C# callable without C# implementation in the database // C# callable without C# implementation in the database
sourceDecl.matchesHandle(result.(CIL::Callable)) unboundDecl.matchesHandle(result.(CIL::Callable))
) )
} }
@@ -172,7 +172,7 @@ private module DispatchImpl {
.(NonDelegateDataFlowCall) .(NonDelegateDataFlowCall)
.getDispatchCall() .getDispatchCall()
.getADynamicTargetInCallContext(ctx.(NonDelegateDataFlowCall).getDispatchCall()) .getADynamicTargetInCallContext(ctx.(NonDelegateDataFlowCall).getDispatchCall())
.getSourceDeclaration() .getUnboundDeclaration()
} }
} }

View File

@@ -459,9 +459,9 @@ private predicate fieldOrPropertyStore(Expr e, Content c, Expr src, Expr q, bool
/** Holds if property `p1` overrides or implements source declaration property `p2`. */ /** Holds if property `p1` overrides or implements source declaration property `p2`. */
private predicate overridesOrImplementsSourceDecl(Property p1, Property p2) { private predicate overridesOrImplementsSourceDecl(Property p1, Property p2) {
p1.getOverridee*().getSourceDeclaration() = p2 p1.getOverridee*().getUnboundDeclaration() = p2
or or
p1.getAnUltimateImplementee().getSourceDeclaration() = p2 p1.getAnUltimateImplementee().getUnboundDeclaration() = p2
} }
/** /**
@@ -706,8 +706,8 @@ private module Cached {
cached cached
newtype TContent = newtype TContent =
TFieldContent(Field f) { f = f.getSourceDeclaration() } or TFieldContent(Field f) { f.isUnboundDeclaration() } or
TPropertyContent(Property p) { p = p.getSourceDeclaration() } or TPropertyContent(Property p) { p.isUnboundDeclaration() } or
TElementContent() TElementContent()
/** /**
@@ -1448,7 +1448,7 @@ private module OutNodes {
/** A valid return type for a method that uses `yield return`. */ /** A valid return type for a method that uses `yield return`. */
private class YieldReturnType extends Type { private class YieldReturnType extends Type {
YieldReturnType() { YieldReturnType() {
exists(Type t | t = this.getSourceDeclaration() | exists(Type t | t = this.getUnboundDeclaration() |
t instanceof SystemCollectionsIEnumerableInterface t instanceof SystemCollectionsIEnumerableInterface
or or
t instanceof SystemCollectionsIEnumeratorInterface t instanceof SystemCollectionsIEnumeratorInterface
@@ -1562,7 +1562,7 @@ private module OutNodes {
override DataFlowCall getCall(ReturnKind kind) { override DataFlowCall getCall(ReturnKind kind) {
result = csharpCall(_, cfn) and result = csharpCall(_, cfn) and
exists(Parameter p | exists(Parameter p |
p.getSourceDeclaration().getPosition() = kind.(OutRefReturnKind).getPosition() and p.getUnboundDeclaration().getPosition() = kind.(OutRefReturnKind).getPosition() and
outRefDef.getTargetAccess() = result.getExpr().(Call).getArgumentForParameter(p) outRefDef.getTargetAccess() = result.getExpr().(Call).getArgumentForParameter(p)
) )
} }
@@ -1674,9 +1674,9 @@ class FieldOrProperty extends Assignable, Modifiable {
/** Gets the content that matches this field or property. */ /** Gets the content that matches this field or property. */
Content getContent() { Content getContent() {
result.(FieldContent).getField() = this.getSourceDeclaration() result.(FieldContent).getField() = this.getUnboundDeclaration()
or or
result.(PropertyContent).getProperty() = this.getSourceDeclaration() result.(PropertyContent).getProperty() = this.getUnboundDeclaration()
} }
} }

View File

@@ -21,7 +21,7 @@ private class DelegateFlowSource extends DataFlow::ExprNode {
this.getExpr() = this.getExpr() =
any(Expr e | any(Expr e |
c = e.(AnonymousFunctionExpr) or c = e.(AnonymousFunctionExpr) or
c = e.(CallableAccess).getTarget().getSourceDeclaration() c = e.(CallableAccess).getTarget().getUnboundDeclaration()
) )
} }

View File

@@ -135,7 +135,7 @@ module Public {
/** An unbound callable. */ /** An unbound callable. */
class SummarizableCallable extends Callable { class SummarizableCallable extends Callable {
SummarizableCallable() { this = this.getSourceDeclaration() } SummarizableCallable() { this.isUnboundDeclaration() }
} }
/** A flow-summary input specification. */ /** A flow-summary input specification. */

View File

@@ -52,7 +52,7 @@ module Steps {
private predicate flowIn(Parameter p, Expr pred, AssignableRead succ) { private predicate flowIn(Parameter p, Expr pred, AssignableRead succ) {
exists(AssignableDefinitions::ImplicitParameterDefinition def, Call c | succ = getARead(def) | exists(AssignableDefinitions::ImplicitParameterDefinition def, Call c | succ = getARead(def) |
pred = getArgumentForOverridderParameter(c, p) and pred = getArgumentForOverridderParameter(c, p) and
p.getSourceDeclaration() = def.getParameter() p.getUnboundDeclaration() = def.getParameter()
) )
} }

View File

@@ -154,7 +154,7 @@ private module Impl {
*/ */
predicate propertyOverrides(Property p, string baseClass, string property) { predicate propertyOverrides(Property p, string baseClass, string property) {
exists(Property p2 | exists(Property p2 |
p2.getSourceDeclaration().getDeclaringType().hasQualifiedName(baseClass) and p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(baseClass) and
p2.hasName(property) p2.hasName(property)
| |
p.overridesOrImplementsOrEquals(p2) p.overridesOrImplementsOrEquals(p2)

View File

@@ -239,7 +239,7 @@ private module Internal {
pragma[noinline] pragma[noinline]
private predicate hasCallable(OverridableCallable source, ValueOrRefType t, OverridableCallable c) { private predicate hasCallable(OverridableCallable source, ValueOrRefType t, OverridableCallable c) {
c.getSourceDeclaration() = source and c.getUnboundDeclaration() = source and
t.hasCallable(c) and t.hasCallable(c) and
hasOverrider(c, t) and hasOverrider(c, t) and
hasQualifierTypeOverridden0(t, _) and hasQualifierTypeOverridden0(t, _) and
@@ -284,9 +284,9 @@ private module Internal {
OverridableCallable c, DispatchMethodOrAccessorCall call OverridableCallable c, DispatchMethodOrAccessorCall call
) { ) {
exists(OverridableCallable target | call.getAStaticTarget() = target | exists(OverridableCallable target | call.getAStaticTarget() = target |
c = target.getSourceDeclaration() c = target.getUnboundDeclaration()
or or
c = target.getAnUltimateImplementor().getSourceDeclaration() c = target.getAnUltimateImplementor().getUnboundDeclaration()
) )
} }
@@ -309,8 +309,8 @@ private module Internal {
* have a more precise type. * have a more precise type.
*/ */
predicate mayBenefitFromCallContext(Callable c, int i) { predicate mayBenefitFromCallContext(Callable c, int i) {
1 < strictcount(this.getADynamicTarget().getSourceDeclaration()) and 1 < strictcount(this.getADynamicTarget().getUnboundDeclaration()) and
c = this.getCall().getEnclosingCallable().getSourceDeclaration() and c = this.getCall().getEnclosingCallable().getUnboundDeclaration() and
( (
exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p | exists(AssignableDefinitions::ImplicitParameterDefinition pdef, Parameter p |
this.getQualifier() = BaseSsa::getARead(pdef, p) and this.getQualifier() = BaseSsa::getARead(pdef, p) and
@@ -331,7 +331,7 @@ private module Internal {
*/ */
pragma[nomagic] pragma[nomagic]
private predicate relevantContext(DispatchCall ctx, int i) { private predicate relevantContext(DispatchCall ctx, int i) {
this.mayBenefitFromCallContext(ctx.getADynamicTarget().getSourceDeclaration(), i) this.mayBenefitFromCallContext(ctx.getADynamicTarget().getUnboundDeclaration(), i)
} }
/** /**
@@ -356,7 +356,7 @@ private module Internal {
exists(Callable staticTarget, Type declType | exists(Callable staticTarget, Type declType |
staticTarget = this.getAStaticTarget() and staticTarget = this.getAStaticTarget() and
declType = staticTarget.getDeclaringType() and declType = staticTarget.getDeclaringType() and
result = staticTarget.getSourceDeclaration() and result = staticTarget.getUnboundDeclaration() and
Unification::subsumes(declType, t) Unification::subsumes(declType, t)
) )
} }
@@ -370,7 +370,7 @@ private module Internal {
private Callable getASubsumedStaticTarget() { private Callable getASubsumedStaticTarget() {
result = this.getAStaticTarget() result = this.getAStaticTarget()
or or
result.getSourceDeclaration() = this.getASubsumedStaticTarget0(result.getDeclaringType()) result.getUnboundDeclaration() = this.getASubsumedStaticTarget0(result.getDeclaringType())
} }
/** /**

View File

@@ -278,7 +278,7 @@ private int getAccessorKind(Accessor a) {
event_accessors(a, -result, _, _, _) event_accessors(a, -result, _, _, _)
} }
/** A source declared type. */ /** An unbound type. */
class SourceDeclarationType extends Type { class UnboundDeclarationType extends Type {
SourceDeclarationType() { this = this.getSourceDeclaration() } UnboundDeclarationType() { this.isUnboundDeclaration() }
} }

View File

@@ -410,11 +410,11 @@ class ConstructorInitializer extends Call, @constructor_init_expr {
override string getAPrimaryQlClass() { result = "ConstructorInitializer" } override string getAPrimaryQlClass() { result = "ConstructorInitializer" }
private ValueOrRefType getTargetType() { private ValueOrRefType getTargetType() {
result = this.getTarget().getDeclaringType().getSourceDeclaration() result = this.getTarget().getDeclaringType().getUnboundDeclaration()
} }
private ValueOrRefType getConstructorType() { private ValueOrRefType getConstructorType() {
result = this.getConstructor().getDeclaringType().getSourceDeclaration() result = this.getConstructor().getDeclaringType().getUnboundDeclaration()
} }
/** /**

View File

@@ -415,7 +415,7 @@ class AnonymousFunctionExpr extends Expr, Callable, @anonymous_function_expr {
this.getType().(SystemLinqExpressions::DelegateExtType).getDelegateType().getReturnType() this.getType().(SystemLinqExpressions::DelegateExtType).getDelegateType().getReturnType()
} }
override AnonymousFunctionExpr getSourceDeclaration() { result = this } override AnonymousFunctionExpr getUnboundDeclaration() { result = this }
override Callable getEnclosingCallable() { result = Expr.super.getEnclosingCallable() } override Callable getEnclosingCallable() { result = Expr.super.getEnclosingCallable() }

View File

@@ -263,7 +263,7 @@ module EntityFramework {
/** A DB Context. */ /** A DB Context. */
private class DbContextClass extends Class { private class DbContextClass extends Class {
DbContextClass() { this.getBaseClass*().getSourceDeclaration() instanceof DbContext } DbContextClass() { this.getBaseClass*().getUnboundDeclaration() instanceof DbContext }
/** /**
* Gets a `DbSet<elementType>` property belonging to this DB context. * Gets a `DbSet<elementType>` property belonging to this DB context.
@@ -281,9 +281,9 @@ module EntityFramework {
private Property getADbSetProperty(Class elementType) { private Property getADbSetProperty(Class elementType) {
exists(ConstructedClass c | exists(ConstructedClass c |
result.getType() = c and result.getType() = c and
c.getSourceDeclaration() instanceof DbSet and c.getUnboundDeclaration() instanceof DbSet and
elementType = c.getTypeArgument(0) and elementType = c.getTypeArgument(0) and
this.hasMember(any(Property p | result = p.getSourceDeclaration())) and this.hasMember(any(Property p | result = p.getUnboundDeclaration())) and
not isNotMapped([result.(Attributable), elementType]) not isNotMapped([result.(Attributable), elementType])
) )
} }
@@ -320,7 +320,7 @@ module EntityFramework {
c1 instanceof PropertyContent and c1 instanceof PropertyContent and
t1.(ValueOrRefType).getABaseType*() = ci and t1.(ValueOrRefType).getABaseType*() = ci and
not t1 instanceof StringType and not t1 instanceof StringType and
ci.getSourceDeclaration() instanceof SystemCollectionsGenericIEnumerableTInterface and ci.getUnboundDeclaration() instanceof SystemCollectionsGenericIEnumerableTInterface and
c2 instanceof ElementContent and c2 instanceof ElementContent and
t2 = ci.getTypeArgument(0) t2 = ci.getTypeArgument(0)
) )

View File

@@ -554,7 +554,7 @@ class IEquatableEqualsMethod extends Method {
IEquatableEqualsMethod() { IEquatableEqualsMethod() {
exists(Method m | exists(Method m |
m = any(SystemIEquatableTInterface i).getAConstructedGeneric().getAMethod() and m = any(SystemIEquatableTInterface i).getAConstructedGeneric().getAMethod() and
m.getSourceDeclaration() = any(SystemIEquatableTInterface i).getEqualsMethod() m.getUnboundDeclaration() = any(SystemIEquatableTInterface i).getEqualsMethod()
| |
this = m or getAnUltimateImplementee() = m this = m or getAnUltimateImplementee() = m
) )
@@ -626,8 +626,8 @@ private IEquatableEqualsMethod getInvokedIEquatableEqualsMethod(ValueOrRefType t
/** Whether `eq` calls `ieem` */ /** Whether `eq` calls `ieem` */
private predicate callsEqualsMethod(EqualsMethod eq, IEquatableEqualsMethod ieem) { private predicate callsEqualsMethod(EqualsMethod eq, IEquatableEqualsMethod ieem) {
exists(MethodCall callToDerivedEquals | exists(MethodCall callToDerivedEquals |
callToDerivedEquals.getEnclosingCallable() = eq.getSourceDeclaration() and callToDerivedEquals.getEnclosingCallable() = eq.getUnboundDeclaration() and
callToDerivedEquals.getTarget() = ieem.getSourceDeclaration() callToDerivedEquals.getTarget() = ieem.getUnboundDeclaration()
) )
} }
@@ -709,8 +709,8 @@ private DisposeBoolMethod getInvokedDiposeBoolMethod(ValueOrRefType t, DisposeMe
not disp.fromSource() not disp.fromSource()
or or
exists(MethodCall callToDerivedDispose | exists(MethodCall callToDerivedDispose |
callToDerivedDispose.getEnclosingCallable() = disp.getSourceDeclaration() and callToDerivedDispose.getEnclosingCallable() = disp.getUnboundDeclaration() and
callToDerivedDispose.getTarget() = dbm.getSourceDeclaration() callToDerivedDispose.getTarget() = dbm.getUnboundDeclaration()
) )
) )
} }

View File

@@ -39,7 +39,7 @@ module SystemDataEntity {
/** The `System.Data.Entity.DbSet` class. */ /** The `System.Data.Entity.DbSet` class. */
class DbSet extends Class { class DbSet extends Class {
DbSet() { DbSet() {
this.getSourceDeclaration().(csharp::UnboundGenericClass).getNameWithoutBrackets() = "DbSet" this.getUnboundDeclaration().(csharp::UnboundGenericClass).getNameWithoutBrackets() = "DbSet"
} }
/** Gets the `SqlQuery` method. */ /** Gets the `SqlQuery` method. */
@@ -99,7 +99,7 @@ module SystemDataEntityInfrastructure {
DbRawSqlQuery() { DbRawSqlQuery() {
this this
.getABaseType*() .getABaseType*()
.getSourceDeclaration() .getUnboundDeclaration()
.(csharp::UnboundGenericClass) .(csharp::UnboundGenericClass)
.getNameWithoutBrackets() = "DbRawSqlQuery" .getNameWithoutBrackets() = "DbRawSqlQuery"
} }

View File

@@ -112,7 +112,7 @@ class TestCaseSourceAttribute extends Attribute {
} }
/** Gets the declaration where the values are declared. */ /** Gets the declaration where the values are declared. */
Declaration getSourceDeclaration() { Declaration getUnboundDeclaration() {
result.getDeclaringType() = this.getSourceType() and result.getDeclaringType() = this.getSourceType() and
result.getName() = this.getFieldName() result.getName() = this.getFieldName()
} }

View File

@@ -57,41 +57,41 @@ predicate depends(ValueOrRefType t, ValueOrRefType u) {
exists(MethodCall mc, Method m | exists(MethodCall mc, Method m |
mc.getEnclosingCallable().getDeclaringType() = t and mc.getEnclosingCallable().getDeclaringType() = t and
mc.getTarget() = m and mc.getTarget() = m and
usesType(m.getSourceDeclaration().getDeclaringType(), u) usesType(m.getUnboundDeclaration().getDeclaringType(), u)
) )
or or
exists(ObjectCreation oc | exists(ObjectCreation oc |
oc.getEnclosingCallable().getDeclaringType() = t and oc.getEnclosingCallable().getDeclaringType() = t and
usesType(oc.getObjectType().getSourceDeclaration(), u) usesType(oc.getObjectType().getUnboundDeclaration(), u)
) )
or or
exists(ObjectCreation oc, Field f | exists(ObjectCreation oc, Field f |
f.getDeclaringType() = t and f.getDeclaringType() = t and
f.getInitializer().getAChild*() = oc and f.getInitializer().getAChild*() = oc and
usesType(oc.getObjectType().getSourceDeclaration(), u) usesType(oc.getObjectType().getUnboundDeclaration(), u)
) )
or or
exists(DelegateCreation oc | exists(DelegateCreation oc |
oc.getEnclosingCallable().getDeclaringType() = t and oc.getEnclosingCallable().getDeclaringType() = t and
usesType(oc.getDelegateType().getSourceDeclaration(), u) usesType(oc.getDelegateType().getUnboundDeclaration(), u)
) )
or or
exists(DelegateCall dc, DelegateType dt | exists(DelegateCall dc, DelegateType dt |
dc.getEnclosingCallable().getDeclaringType() = t and dc.getEnclosingCallable().getDeclaringType() = t and
dc.getDelegateExpr().getType() = dt and dc.getDelegateExpr().getType() = dt and
usesType(dt.getSourceDeclaration(), u) usesType(dt.getUnboundDeclaration(), u)
) )
or or
exists(OperatorCall oc, Operator o | exists(OperatorCall oc, Operator o |
oc.getEnclosingCallable().getDeclaringType() = t and oc.getEnclosingCallable().getDeclaringType() = t and
oc.getTarget() = o and oc.getTarget() = o and
usesType(o.getSourceDeclaration().getDeclaringType(), u) usesType(o.getUnboundDeclaration().getDeclaringType(), u)
) )
or or
exists(MemberAccess ma, Member m | exists(MemberAccess ma, Member m |
ma.getEnclosingCallable().getDeclaringType() = t and ma.getEnclosingCallable().getDeclaringType() = t and
ma.getTarget() = m and ma.getTarget() = m and
usesType(m.getSourceDeclaration().getDeclaringType(), u) usesType(m.getUnboundDeclaration().getDeclaringType(), u)
) )
or or
exists(LocalVariableDeclExpr e, LocalVariable v | exists(LocalVariableDeclExpr e, LocalVariable v |
@@ -121,7 +121,7 @@ predicate depends(ValueOrRefType t, ValueOrRefType u) {
/** does t use dep in any way? */ /** does t use dep in any way? */
predicate usesType(Type t, Type u) { predicate usesType(Type t, Type u) {
t.(ValueOrRefType).getSourceDeclaration() = u or t.(ValueOrRefType).getUnboundDeclaration() = u or
usesType(t.(ConstructedType).getATypeArgument(), u) or usesType(t.(ConstructedType).getATypeArgument(), u) or
usesType(t.(ArrayType).getElementType(), u) usesType(t.(ArrayType).getElementType(), u)
} }

View File

@@ -18,7 +18,7 @@ class Callable extends Declaration, @dotnet_callable {
/** Holds if this callable has a body or an implementation. */ /** Holds if this callable has a body or an implementation. */
predicate hasBody() { none() } predicate hasBody() { none() }
override Callable getSourceDeclaration() { result = Declaration.super.getSourceDeclaration() } override Callable getUnboundDeclaration() { result = Declaration.super.getUnboundDeclaration() }
/** Gets the number of parameters of this callable. */ /** Gets the number of parameters of this callable. */
int getNumberOfParameters() { result = count(getAParameter()) } int getNumberOfParameters() { result = count(getAParameter()) }

View File

@@ -18,8 +18,40 @@ class Declaration extends NamedElement, @dotnet_declaration {
/** Gets the type containing this declaration, if any. */ /** Gets the type containing this declaration, if any. */
Type getDeclaringType() { none() } Type getDeclaringType() { none() }
/** Gets the unbound version of this declaration. */ /**
Declaration getSourceDeclaration() { result = this } * DEPRECATED: Use `getUnboundDeclaration()` instaed.
*
* Gets the unbound version of this declaration.
*/
deprecated final Declaration getSourceDeclaration() { result = this.getUnboundDeclaration() }
/**
* Gets the unbound version of this declaration, that is, the declaration where
* all type arguments have been removed. For example, in
*
* ```csharp
* class C<T>
* {
* class Nested
* {
* }
*
* void Method<S>() { }
* }
* ```
*
* we have the following
*
* | Declaration | Unbound declaration |
* |-------------------------|---------------------|
* | `C<int>` | `C<>` |
* | `C<>.Nested` | `C<>.Nested` |
* | `C<int>.Nested` | `C<>.Nested` |
* | `C<>.Method<>` | `C<>.Method<>` |
* | `C<int>.Method<>` | `C<>.Method<>` |
* | `C<int>.Method<string>` | `C<>.Method<>` |
*/
Declaration getUnboundDeclaration() { result = this }
} }
/** A member of a type. */ /** A member of a type. */

View File

@@ -5,7 +5,7 @@ from DispatchCall call, Method m
where where
call.getCall().getEnclosingCallable().getName() = "Run" and call.getCall().getEnclosingCallable().getName() = "Run" and
call.getLocation().getFile().getStem() = "ExactCallable" and call.getLocation().getFile().getStem() = "ExactCallable" and
strictcount(call.getADynamicTarget().getSourceDeclaration()) = 1 and strictcount(call.getADynamicTarget().getUnboundDeclaration()) = 1 and
m = call.getADynamicTarget().getSourceDeclaration() and m = call.getADynamicTarget().getUnboundDeclaration() and
m.fromSource() m.fromSource()
select call, m.toString(), m.getDeclaringType().toString() select call, m.toString(), m.getDeclaringType().toString()

View File

@@ -4,7 +4,7 @@ import semmle.code.csharp.dispatch.Dispatch
from DispatchCall call, Callable c from DispatchCall call, Callable c
where where
call.getLocation().getFile().getStem() = "ViableCallable" and call.getLocation().getFile().getStem() = "ViableCallable" and
c = call.getADynamicTarget().getSourceDeclaration() and c = call.getADynamicTarget().getUnboundDeclaration() and
(c.fromSource() implies c.getFile().getStem() = "ViableCallable") and (c.fromSource() implies c.getFile().getStem() = "ViableCallable") and
(c instanceof Method implies c.getName().regexpMatch("M[0-9]*")) and (c instanceof Method implies c.getName().regexpMatch("M[0-9]*")) and
(c instanceof Accessor implies c.fromSource()) and (c instanceof Accessor implies c.fromSource()) and

View File

@@ -6,7 +6,7 @@ import semmle.code.csharp.frameworks.system.collections.Generic
predicate implementsMethod(Method m, int i) { predicate implementsMethod(Method m, int i) {
exists(Method other, Method imp | exists(Method other, Method imp |
m.overridesOrImplementsOrEquals(imp) and m.overridesOrImplementsOrEquals(imp) and
other = imp.getSourceDeclaration() other = imp.getUnboundDeclaration()
| |
other = any(SystemObjectClass c).getEqualsMethod() and i = 1 other = any(SystemObjectClass c).getEqualsMethod() and i = 1
or or

View File

@@ -2,4 +2,4 @@ import csharp
import semmle.code.csharp.frameworks.test.NUnit import semmle.code.csharp.frameworks.test.NUnit
from TestCaseSourceAttribute attribute from TestCaseSourceAttribute attribute
select attribute.getTarget(), attribute.getSourceDeclaration() select attribute.getTarget(), attribute.getUnboundDeclaration()

View File

@@ -9,7 +9,7 @@ where
framework = e.(TestMethod).getAQlClass() and type = "TestMethod" framework = e.(TestMethod).getAQlClass() and type = "TestMethod"
) and ) and
not framework = "NonNestedType" and not framework = "NonNestedType" and
not framework = "SourceDeclarationType" and not framework = "UnboundDeclarationType" and
not framework = "SourceDeclarationCallable" and not framework = "SourceDeclarationCallable" and
not framework = "SourceDeclarationMethod" and not framework = "SourceDeclarationMethod" and
not framework = "NonConstructedMethod" and not framework = "NonConstructedMethod" and

View File

@@ -45,8 +45,8 @@ query predicate test6(ConstructedClass at, UnboundGenericClass b, ConstructedCla
query predicate test7(ConstructedClass aString, ConstructedClass bString) { query predicate test7(ConstructedClass aString, ConstructedClass bString) {
aString.hasName("A<String>") and aString.hasName("A<String>") and
bString.hasName("B<String>") and bString.hasName("B<String>") and
aString.getSourceDeclaration().hasName("A<>") and aString.getUnboundDeclaration().hasName("A<>") and
bString.getSourceDeclaration().hasName("B<>") bString.getUnboundDeclaration().hasName("B<>")
} }
query predicate test8(ConstructedClass bString, Method m) { query predicate test8(ConstructedClass bString, Method m) {
@@ -54,7 +54,7 @@ query predicate test8(ConstructedClass bString, Method m) {
m.getDeclaringType() = bString and m.getDeclaringType() = bString and
m.hasName("fooParams") and m.hasName("fooParams") and
m.getParameter(0).getType().(ArrayType).getElementType() instanceof StringType and m.getParameter(0).getType().(ArrayType).getElementType() instanceof StringType and
m.getSourceDeclaration().getDeclaringType() = m.getDeclaringType().getSourceDeclaration() m.getUnboundDeclaration().getDeclaringType() = m.getDeclaringType().getUnboundDeclaration()
} }
query predicate test9(ConstructedClass bString, Setter sourceSetter, Setter setter) { query predicate test9(ConstructedClass bString, Setter sourceSetter, Setter setter) {
@@ -62,11 +62,11 @@ query predicate test9(ConstructedClass bString, Setter sourceSetter, Setter sett
bString.hasName("B<String>") and bString.hasName("B<String>") and
p.getDeclaringType() = bString and p.getDeclaringType() = bString and
p.hasName("Name") and p.hasName("Name") and
p.getSourceDeclaration().getDeclaringType() = p.getDeclaringType().getSourceDeclaration() and p.getUnboundDeclaration().getDeclaringType() = p.getDeclaringType().getUnboundDeclaration() and
p.getSetter().getParameter(0).getType() instanceof StringType and p.getSetter().getParameter(0).getType() instanceof StringType and
p.getSetter().getSourceDeclaration() = p.getSourceDeclaration().getSetter() and p.getSetter().getUnboundDeclaration() = p.getUnboundDeclaration().getSetter() and
p.getGetter().getSourceDeclaration() = p.getSourceDeclaration().getGetter() and p.getGetter().getUnboundDeclaration() = p.getUnboundDeclaration().getGetter() and
sourceSetter = p.getSourceDeclaration().getSetter() and sourceSetter = p.getUnboundDeclaration().getSetter() and
setter = p.getSetter() setter = p.getSetter()
) )
} }
@@ -75,26 +75,26 @@ query predicate test10(ConstructedClass bString, Event e) {
bString.hasName("B<String>") and bString.hasName("B<String>") and
e.getDeclaringType() = bString and e.getDeclaringType() = bString and
e.hasName("myEvent") and e.hasName("myEvent") and
e.getSourceDeclaration().getDeclaringType() = e.getDeclaringType().getSourceDeclaration() and e.getUnboundDeclaration().getDeclaringType() = e.getDeclaringType().getUnboundDeclaration() and
e.getType().(ConstructedDelegateType).getTypeArgument(0) instanceof StringType and e.getType().(ConstructedDelegateType).getTypeArgument(0) instanceof StringType and
e.getAddEventAccessor().getSourceDeclaration() = e.getSourceDeclaration().getAddEventAccessor() and e.getAddEventAccessor().getUnboundDeclaration() = e.getUnboundDeclaration().getAddEventAccessor() and
e.getRemoveEventAccessor().getSourceDeclaration() = e.getRemoveEventAccessor().getUnboundDeclaration() =
e.getSourceDeclaration().getRemoveEventAccessor() e.getUnboundDeclaration().getRemoveEventAccessor()
} }
query predicate test11(ConstructedClass bString, Operator o) { query predicate test11(ConstructedClass bString, Operator o) {
bString.hasName("B<String>") and bString.hasName("B<String>") and
o.getDeclaringType() = bString and o.getDeclaringType() = bString and
o instanceof IncrementOperator and o instanceof IncrementOperator and
o.getSourceDeclaration().getDeclaringType() = o.getDeclaringType().getSourceDeclaration() o.getUnboundDeclaration().getDeclaringType() = o.getDeclaringType().getUnboundDeclaration()
} }
query predicate test12(ConstructedClass gridInt, Indexer i) { query predicate test12(ConstructedClass gridInt, Indexer i) {
gridInt.hasName("Grid<Int32>") and gridInt.hasName("Grid<Int32>") and
i.getDeclaringType() = gridInt and i.getDeclaringType() = gridInt and
i.getSourceDeclaration().getDeclaringType() = i.getDeclaringType().getSourceDeclaration() and i.getUnboundDeclaration().getDeclaringType() = i.getDeclaringType().getUnboundDeclaration() and
i.getGetter().getSourceDeclaration() = i.getSourceDeclaration().getGetter() and i.getGetter().getUnboundDeclaration() = i.getUnboundDeclaration().getGetter() and
i.getSetter().getSourceDeclaration() = i.getSourceDeclaration().getSetter() i.getSetter().getUnboundDeclaration() = i.getUnboundDeclaration().getSetter()
} }
query predicate test13(ConstructedClass gridInt, Indexer i) { query predicate test13(ConstructedClass gridInt, Indexer i) {
@@ -198,11 +198,11 @@ query predicate test25(ConstructedMethod cm) {
cm.getParameter(0).getType() instanceof DoubleType and cm.getParameter(0).getType() instanceof DoubleType and
cm.getParameter(1).getType() instanceof IntType and cm.getParameter(1).getType() instanceof IntType and
cm.getReturnType() instanceof DoubleType and cm.getReturnType() instanceof DoubleType and
exists(Method sourceDeclaration | exists(Method unboundDeclaration |
sourceDeclaration = cm.getSourceDeclaration() and unboundDeclaration = cm.getUnboundDeclaration() and
sourceDeclaration.getParameter(0).getType().(TypeParameter).hasName("T2") and unboundDeclaration.getParameter(0).getType().(TypeParameter).hasName("T2") and
sourceDeclaration.getParameter(1).getType().(TypeParameter).hasName("T1") and unboundDeclaration.getParameter(1).getType().(TypeParameter).hasName("T1") and
sourceDeclaration.getReturnType().(TypeParameter).hasName("T2") unboundDeclaration.getReturnType().(TypeParameter).hasName("T2")
) and ) and
exists(Method unbound | exists(Method unbound |
unbound = cm.getUnboundGeneric() and unbound = cm.getUnboundGeneric() and
@@ -215,7 +215,7 @@ query predicate test25(ConstructedMethod cm) {
query predicate test26(ConstructedGeneric cg, string s) { query predicate test26(ConstructedGeneric cg, string s) {
// Source declaration and unbound generic must be unique // Source declaration and unbound generic must be unique
( (
strictcount(cg.getSourceDeclaration+()) > 1 or strictcount(cg.getUnboundDeclaration+()) > 1 or
strictcount(cg.getUnboundGeneric()) > 1 strictcount(cg.getUnboundGeneric()) > 1
) and ) and
s = "Non-unique source decl or unbound generic" s = "Non-unique source decl or unbound generic"
@@ -224,7 +224,7 @@ query predicate test26(ConstructedGeneric cg, string s) {
query predicate test27(ConstructedType ct, UnboundGenericType ugt, UnboundGenericType sourceDecl) { query predicate test27(ConstructedType ct, UnboundGenericType ugt, UnboundGenericType sourceDecl) {
ct instanceof NestedType and ct instanceof NestedType and
ugt = ct.getUnboundGeneric() and ugt = ct.getUnboundGeneric() and
sourceDecl = ct.getSourceDeclaration() and sourceDecl = ct.getUnboundDeclaration() and
ugt != sourceDecl ugt != sourceDecl
} }
@@ -242,7 +242,7 @@ query predicate test30(Declaration d, string s) {
d.fromSource() and d.fromSource() and
d instanceof @generic and d instanceof @generic and
s = d.getQualifiedNameWithTypes() and s = d.getQualifiedNameWithTypes() and
d != d.getSourceDeclaration() and d != d.getUnboundDeclaration() and
not d instanceof Generic not d instanceof Generic
} }