Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b776421

Browse files
committed
C#: Fix up tests. Fix cil_class, and add locations for constructed methods and types.
1 parent 02fd51a commit b776421

7 files changed

Lines changed: 13 additions & 27 deletions

File tree

csharp/extractor/Semmle.Extraction.CIL/Entities/Type.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ protected TypeContainer(Context cx) : base(cx)
5757

5858
public abstract void WriteId(TextWriter trapFile);
5959

60-
/// <summary>
61-
/// For debugging purposes.
62-
/// </summary>
63-
string DebugId => this.GetDebugLabel();
64-
6560
public void WriteQuotedId(TextWriter trapFile)
6661
{
6762
trapFile.Write("@\"");
@@ -508,11 +503,10 @@ public override IEnumerable<IExtractionProduct> Contents
508503
if (td.Attributes.HasFlag(TypeAttributes.Abstract))
509504
yield return Tuples.cil_abstract(this);
510505

511-
if (td.Attributes.HasFlag(TypeAttributes.Class))
512-
yield return Tuples.cil_class(this);
513-
514506
if (td.Attributes.HasFlag(TypeAttributes.Interface))
515507
yield return Tuples.cil_interface(this);
508+
else
509+
yield return Tuples.cil_class(this);
516510

517511
if (td.Attributes.HasFlag(TypeAttributes.Public))
518512
yield return Tuples.cil_public(this);

csharp/ql/src/semmle/code/cil/ConsistencyChecks.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ class InvalidOverride extends MethodViolation {
444444

445445
InvalidOverride() {
446446
base = getMethod().getOverriddenMethod() and
447-
not getMethod().getDeclaringType().getABaseType+() = base.getDeclaringType()
447+
not getMethod().getDeclaringType().getABaseType+() = base.getDeclaringType() and
448+
base.getDeclaringType().isSourceDeclaration() // Bases classes of constructed types aren't extracted properly.
448449
}
449450

450451
override string getMessage() {

csharp/ql/src/semmle/code/cil/Generics.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ class ConstructedType extends ConstructedGeneric, Type { }
4040
/** A constructed generic method. */
4141
class ConstructedMethod extends ConstructedGeneric, Method {
4242
final override UnboundGenericMethod getUnboundGeneric() { result = getUnboundMethod() }
43-
44-
final override Location getLocation() { result = getUnboundGeneric().getLocation() }
4543
}

csharp/ql/src/semmle/code/cil/Method.qll

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,11 @@ class Method extends DotNet::Callable, Element, Member, TypeContainer, DataFlowN
8585

8686
override Location getLocation() { result = Element.super.getLocation() }
8787

88-
/**
89-
* Gets a location of this method, if any.
90-
*
91-
* This predicate returns locations both in assemblies and in source code
92-
* if available.
93-
*/
94-
override Location getALocation() { cil_method_location(this, result) }
88+
override Location getALocation() {
89+
cil_method_location(this, result)
90+
or
91+
result = this.getSourceDeclaration().getALocation()
92+
}
9593

9694
override Parameter getRawParameter(int n) { cil_parameter(result, this, n, _) }
9795

csharp/ql/src/semmle/code/cil/Type.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ class Type extends DotNet::Type, Declaration, TypeContainer, @cil_type {
5757
qualifier = this.getParent().getQualifiedName()
5858
}
5959

60-
override Location getLocation() {
60+
override Location getALocation() {
6161
cil_type_location(this, result)
6262
or
63-
result = getUnboundType().getLocation()
63+
result = getSourceDeclaration().getALocation()
6464
}
6565

6666
/** Holds if this type is a class. */
@@ -115,4 +115,6 @@ class Type extends DotNet::Type, Declaration, TypeContainer, @cil_type {
115115
* of a higher index.
116116
*/
117117
int getConversionIndex() { result = 0 }
118+
119+
override Type getSourceDeclaration() { cil_type(this, _, _, _, result) }
118120
}

csharp/ql/test/library-tests/cil/consistency/Handles.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
tooManyMatchingHandles
22
missingCil
3-
cilLocationViolation
43
csharpLocationViolation
54
matchingObjectMethods
65
| Equals(object) | System.Boolean System.Object.Equals(System.Object) |

csharp/ql/test/library-tests/cil/consistency/Handles.ql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ query predicate missingCil(Element e) {
2727
not exists(CIL::Element ce | ce.(MetadataEntity).matchesHandle(e))
2828
}
2929

30-
query predicate cilLocationViolation(CIL::Element e) {
31-
e instanceof MetadataEntity and
32-
exists(e.getALocation()) and
33-
not e.getALocation() = e.(MetadataEntity).getAssembly()
34-
}
35-
3630
query predicate csharpLocationViolation(Element e) {
3731
e.fromLibrary() and
3832
e.(MetadataEntity).hasHandle() and

0 commit comments

Comments
 (0)