mirror of
https://github.com/github/codeql.git
synced 2026-05-02 12:15:17 +02:00
Merge pull request #20525 from michaelnebel/csharp/reducelocationtuples
C#: Reduce location tuples.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* The extraction of the location for bound generic entities (methods, accessors, indexers, properties, and events) has been optimized. Previously, location information was extracted multiple times for each bound generic. Now, only the location of the unbound generic declaration is extracted during the extraction phase, and the QL library explicitly reuses this location for all bound instances of the same generic.
|
||||
@@ -265,7 +265,7 @@ class Method extends Callable, Virtualizable, Attributable, @method {
|
||||
result = Virtualizable.super.getAnUltimateImplementor()
|
||||
}
|
||||
|
||||
override Location getALocation() { method_location(this, result) }
|
||||
override Location getALocation() { method_location(this.getUnboundDeclaration(), result) }
|
||||
|
||||
/** Holds if this method is an extension method. */
|
||||
predicate isExtensionMethod() { this.getParameter(0).hasExtensionMethodModifier() }
|
||||
|
||||
@@ -68,7 +68,7 @@ class Event extends DeclarationWithAccessors, @event {
|
||||
result = DeclarationWithAccessors.super.getAnUltimateImplementor()
|
||||
}
|
||||
|
||||
override Location getALocation() { event_location(this, result) }
|
||||
override Location getALocation() { event_location(this.getUnboundDeclaration(), result) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Event" }
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class EventAccessor extends Accessor, @event_accessor {
|
||||
|
||||
override Event getDeclaration() { event_accessors(this, _, _, result, _) }
|
||||
|
||||
override Location getALocation() { event_accessor_location(this, result) }
|
||||
override Location getALocation() { event_accessor_location(this.getUnboundDeclaration(), result) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -196,7 +196,7 @@ class Property extends DeclarationWithGetSetAccessors, @property {
|
||||
|
||||
override PropertyAccess getAnAccess() { result.getTarget() = this }
|
||||
|
||||
override Location getALocation() { property_location(this, result) }
|
||||
override Location getALocation() { property_location(this.getUnboundDeclaration(), result) }
|
||||
|
||||
override Expr getAnAssignedValue() {
|
||||
result = DeclarationWithGetSetAccessors.super.getAnAssignedValue()
|
||||
@@ -328,7 +328,7 @@ class Indexer extends DeclarationWithGetSetAccessors, Parameterizable, @indexer
|
||||
result = DeclarationWithGetSetAccessors.super.getAnUltimateImplementor()
|
||||
}
|
||||
|
||||
override Location getALocation() { indexer_location(this, result) }
|
||||
override Location getALocation() { indexer_location(this.getUnboundDeclaration(), result) }
|
||||
|
||||
override string toStringWithTypes() {
|
||||
result = this.getName() + "[" + this.parameterTypesToString() + "]"
|
||||
@@ -408,7 +408,7 @@ class Accessor extends Callable, Modifiable, Attributable, Overridable, @callabl
|
||||
|
||||
override Accessor getUnboundDeclaration() { accessors(this, _, _, _, result) }
|
||||
|
||||
override Location getALocation() { accessor_location(this, result) }
|
||||
override Location getALocation() { accessor_location(this.getUnboundDeclaration(), result) }
|
||||
|
||||
override string toString() { result = this.getName() }
|
||||
}
|
||||
|
||||
35
csharp/ql/test/library-tests/locations/A.cs
Normal file
35
csharp/ql/test/library-tests/locations/A.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
|
||||
public abstract class A<T>
|
||||
{
|
||||
public abstract T Prop { get; }
|
||||
public abstract T this[int index] { get; set; }
|
||||
public abstract event EventHandler Event;
|
||||
public void Apply(T t) { }
|
||||
public abstract object ToObject(T t);
|
||||
}
|
||||
|
||||
public class A2 : A<string>
|
||||
{
|
||||
public override string Prop => "";
|
||||
|
||||
public override string this[int i]
|
||||
{
|
||||
get { return ""; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public override event EventHandler Event
|
||||
{
|
||||
add { }
|
||||
remove { }
|
||||
}
|
||||
|
||||
public override object ToObject(string t) => t;
|
||||
|
||||
public void M()
|
||||
{
|
||||
A2 other = new();
|
||||
other.Apply("");
|
||||
}
|
||||
}
|
||||
20
csharp/ql/test/library-tests/locations/B.cs
Normal file
20
csharp/ql/test/library-tests/locations/B.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
public class B : A<int>
|
||||
{
|
||||
public override int Prop => 0;
|
||||
|
||||
public override int this[int i]
|
||||
{
|
||||
get { return 0; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public override event EventHandler Event
|
||||
{
|
||||
add { }
|
||||
remove { }
|
||||
}
|
||||
|
||||
public override object ToObject(int t) => t;
|
||||
}
|
||||
12
csharp/ql/test/library-tests/locations/C.cs
Normal file
12
csharp/ql/test/library-tests/locations/C.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
class C
|
||||
{
|
||||
public void M()
|
||||
{
|
||||
B b = new B();
|
||||
b.Apply(0);
|
||||
A2 a2 = new A2();
|
||||
a2.Apply("");
|
||||
}
|
||||
}
|
||||
52
csharp/ql/test/library-tests/locations/locations.expected
Normal file
52
csharp/ql/test/library-tests/locations/locations.expected
Normal file
@@ -0,0 +1,52 @@
|
||||
member_locations
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:5:23:5:26 | Prop | A.cs:5:23:5:26 | A.cs:5:23:5:26 |
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:6:23:6:26 | Item | A.cs:6:23:6:26 | A.cs:6:23:6:26 |
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:7:40:7:44 | Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:8:17:8:21 | Apply | A.cs:8:17:8:21 | A.cs:8:17:8:21 |
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:9:28:9:35 | ToObject | A.cs:9:28:9:35 | A.cs:9:28:9:35 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:5:23:5:26 | Prop | A.cs:5:23:5:26 | A.cs:5:23:5:26 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:6:23:6:26 | Item | A.cs:6:23:6:26 | A.cs:6:23:6:26 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:7:40:7:44 | Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:8:17:8:21 | Apply | A.cs:8:17:8:21 | A.cs:8:17:8:21 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:9:28:9:35 | ToObject | A.cs:9:28:9:35 | A.cs:9:28:9:35 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:5:23:5:26 | Prop | A.cs:5:23:5:26 | A.cs:5:23:5:26 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:6:23:6:26 | Item | A.cs:6:23:6:26 | A.cs:6:23:6:26 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:7:40:7:44 | Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:8:17:8:21 | Apply | A.cs:8:17:8:21 | A.cs:8:17:8:21 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:9:28:9:35 | ToObject | A.cs:9:28:9:35 | A.cs:9:28:9:35 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:14:28:14:31 | Prop | A.cs:14:28:14:31 | A.cs:14:28:14:31 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:16:28:16:31 | Item | A.cs:16:28:16:31 | A.cs:16:28:16:31 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:22:40:22:44 | Event | A.cs:22:40:22:44 | A.cs:22:40:22:44 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:28:28:28:35 | ToObject | A.cs:28:28:28:35 | A.cs:28:28:28:35 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:30:17:30:17 | M | A.cs:30:17:30:17 | A.cs:30:17:30:17 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:5:25:5:28 | Prop | B.cs:5:25:5:28 | B.cs:5:25:5:28 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:7:25:7:28 | Item | B.cs:7:25:7:28 | B.cs:7:25:7:28 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:13:40:13:44 | Event | B.cs:13:40:13:44 | B.cs:13:40:13:44 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:19:28:19:35 | ToObject | B.cs:19:28:19:35 | B.cs:19:28:19:35 |
|
||||
| C.cs:3:7:3:7 | C | C.cs:5:17:5:17 | M | C.cs:5:17:5:17 | C.cs:5:17:5:17 |
|
||||
accessor_location
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:5:30:5:32 | get_Prop | A.cs:5:30:5:32 | A.cs:5:30:5:32 |
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:6:41:6:43 | get_Item | A.cs:6:41:6:43 | A.cs:6:41:6:43 |
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:6:46:6:48 | set_Item | A.cs:6:46:6:48 | A.cs:6:46:6:48 |
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:7:40:7:44 | add_Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:3:23:3:26 | A<Int32> | A.cs:7:40:7:44 | remove_Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:5:30:5:32 | get_Prop | A.cs:5:30:5:32 | A.cs:5:30:5:32 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:6:41:6:43 | get_Item | A.cs:6:41:6:43 | A.cs:6:41:6:43 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:6:46:6:48 | set_Item | A.cs:6:46:6:48 | A.cs:6:46:6:48 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:7:40:7:44 | add_Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:3:23:3:26 | A<String> | A.cs:7:40:7:44 | remove_Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:5:30:5:32 | get_Prop | A.cs:5:30:5:32 | A.cs:5:30:5:32 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:6:41:6:43 | get_Item | A.cs:6:41:6:43 | A.cs:6:41:6:43 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:6:46:6:48 | set_Item | A.cs:6:46:6:48 | A.cs:6:46:6:48 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:7:40:7:44 | add_Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:3:23:3:26 | A`1 | A.cs:7:40:7:44 | remove_Event | A.cs:7:40:7:44 | A.cs:7:40:7:44 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:14:36:14:37 | get_Prop | A.cs:14:36:14:37 | A.cs:14:36:14:37 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:18:9:18:11 | get_Item | A.cs:18:9:18:11 | A.cs:18:9:18:11 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:19:9:19:11 | set_Item | A.cs:19:9:19:11 | A.cs:19:9:19:11 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:24:9:24:11 | add_Event | A.cs:24:9:24:11 | A.cs:24:9:24:11 |
|
||||
| A.cs:12:14:12:15 | A2 | A.cs:25:9:25:14 | remove_Event | A.cs:25:9:25:14 | A.cs:25:9:25:14 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:5:33:5:33 | get_Prop | B.cs:5:33:5:33 | B.cs:5:33:5:33 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:9:9:9:11 | get_Item | B.cs:9:9:9:11 | B.cs:9:9:9:11 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:10:9:10:11 | set_Item | B.cs:10:9:10:11 | B.cs:10:9:10:11 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:15:9:15:11 | add_Event | B.cs:15:9:15:11 | B.cs:15:9:15:11 |
|
||||
| B.cs:3:14:3:14 | B | B.cs:16:9:16:14 | remove_Event | B.cs:16:9:16:14 | B.cs:16:9:16:14 |
|
||||
14
csharp/ql/test/library-tests/locations/locations.ql
Normal file
14
csharp/ql/test/library-tests/locations/locations.ql
Normal file
@@ -0,0 +1,14 @@
|
||||
import csharp
|
||||
|
||||
query predicate member_locations(Type t, Member m, SourceLocation l) {
|
||||
t = m.getDeclaringType() and
|
||||
l = m.getLocation() and
|
||||
not l instanceof EmptyLocation and
|
||||
not m instanceof Constructor
|
||||
}
|
||||
|
||||
query predicate accessor_location(Type t, Accessor a, SourceLocation l) {
|
||||
t = a.getDeclaringType() and
|
||||
l = a.getLocation() and
|
||||
not l instanceof EmptyLocation
|
||||
}
|
||||
Reference in New Issue
Block a user