Skip to content

Commit 10d96ee

Browse files
committed
C#: Address review comments.
1 parent fc689ef commit 10d96ee

File tree

13 files changed

+34
-80
lines changed

13 files changed

+34
-80
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import csharp
2-
import semmle.code.csharp.commons.QualifiedName
32

4-
from Class c, string qualifier, string name
5-
where c.fromSource() and c.getBaseClass().hasFullyQualifiedName(qualifier, name)
6-
select c, getQualifiedName(qualifier, name)
3+
from Class c
4+
where c.fromSource()
5+
select c, c.getBaseClass().getFullyQualifiedNameDebug()

csharp/ql/lib/semmle/code/csharp/Element.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class NamedElement extends Element, @named_element {
145145
* Unbound generic types, such as `IList<T>`, are represented as
146146
* ``System.Collections.Generic.IList`1``.
147147
*/
148+
bindingset[this]
149+
pragma[inline_late]
148150
final string getFullyQualifiedNameDebug() {
149151
exists(string qualifier, string name | this.hasFullyQualifiedName(qualifier, name) |
150152
if qualifier = "" then result = name else result = qualifier + "." + name

csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
import csharp
6-
private import semmle.code.csharp.commons.QualifiedName
76

87
/**
98
* Provides classes for working with static single assignment (SSA) form.
@@ -121,12 +120,7 @@ module Ssa {
121120
result = prefix + "." + this.getAssignable()
122121
|
123122
if f.(Modifiable).isStatic()
124-
then
125-
exists(string qualifier, string name |
126-
f.getDeclaringType().hasFullyQualifiedName(qualifier, name)
127-
|
128-
prefix = getQualifiedName(qualifier, name)
129-
)
123+
then prefix = f.getDeclaringType().getName()
130124
else prefix = "this"
131125
)
132126
}
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import csharp
2-
import semmle.code.csharp.commons.QualifiedName
32

4-
from Attributable element, Attribute attribute, string qualifier, string name
3+
from Attributable element, Attribute attribute
54
where
65
attribute = element.getAnAttribute() and
7-
(attribute.fromSource() or element.(Assembly).getName() in ["attributes", "Assembly1"]) and
8-
attribute.getType().hasFullyQualifiedName(qualifier, name)
9-
select element, attribute, getQualifiedName(qualifier, name)
6+
(attribute.fromSource() or element.(Assembly).getName() in ["attributes", "Assembly1"])
7+
select element, attribute, attribute.getType().getFullyQualifiedNameDebug()

csharp/ql/test/library-tests/constructors/Destructors1.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
*/
44

55
import csharp
6-
import semmle.code.csharp.commons.QualifiedName
76

87
from Destructor c, string qualifier, string name
98
where
109
c.getDeclaringType().hasFullyQualifiedName(qualifier, name) and
1110
qualifier = "Constructors" and
1211
name = "Class"
13-
select c, getQualifiedName(qualifier, name)
12+
select c, c.getDeclaringType().getFullyQualifiedNameDebug()

csharp/ql/test/library-tests/csharp11/fileScoped.ql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import csharp
2-
private import semmle.code.csharp.commons.QualifiedName
32

43
private predicate isInteresting(Type t) {
54
(
@@ -20,10 +19,7 @@ query predicate typemodifiers(Type t, string modifier) {
2019

2120
query predicate qualifiedtypes(Type t, string qualifiedName) {
2221
isInteresting(t) and
23-
exists(string qualifier, string name |
24-
t.hasFullyQualifiedName(qualifier, name) and
25-
qualifiedName = getQualifiedName(qualifier, name)
26-
)
22+
qualifiedName = t.getFullyQualifiedNameDebug()
2723
}
2824

2925
query predicate filetypes(Type t) {
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import csharp
2-
import semmle.code.csharp.commons.QualifiedName
32

4-
from LocalVariable v1, LocalVariable v2, Type t, string qualifier, string name
3+
from LocalVariable v1, LocalVariable v2, Type t
54
where
65
v1.getFile().getStem() = "NativeInt" and
76
v2.getFile().getStem() = "NativeInt" and
87
t = v1.getType() and
98
t = v2.getType() and
10-
t.hasFullyQualifiedName(qualifier, name) and
119
v1 != v2
12-
select v1, v2, getQualifiedName(qualifier, name)
10+
select v1, v2, t.getFullyQualifiedNameDebug()
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import csharp
2-
import semmle.code.csharp.commons.QualifiedName
32

4-
from
5-
Method m, Method overrider, string mnamespace, string mtype, string mname, string onamespace,
6-
string otype, string oname
3+
from Method m, Method overrider
74
where
85
m.getAnOverrider() = overrider and
9-
m.getFile().getStem() = "CovariantReturn" and
10-
m.hasFullyQualifiedName(mnamespace, mtype, mname) and
11-
overrider.hasFullyQualifiedName(onamespace, otype, oname)
12-
select getQualifiedName(mnamespace, mtype, mname), m.getReturnType().toString(),
13-
getQualifiedName(onamespace, otype, oname), overrider.getReturnType().toString()
6+
m.getFile().getStem() = "CovariantReturn"
7+
select m.getFullyQualifiedNameDebug(), m.getReturnType().toString(),
8+
overrider.getFullyQualifiedNameDebug(), overrider.getReturnType().toString()
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import csharp
2-
import semmle.code.csharp.commons.QualifiedName
32

43
private string getLocation(Member m) {
54
if m.fromSource() then result = m.getALocation().(SourceLocation).toString() else result = "-"
@@ -9,13 +8,9 @@ private string getIsAsync(ForeachStmt f) {
98
if f.isAsync() then result = "async" else result = "sync"
109
}
1110

12-
from
13-
ForeachStmt f, string qualifier1, string type1, string qualifier2, string type2,
14-
string qualifier3, string type3
15-
where
16-
f.getGetEnumerator().getDeclaringType().hasFullyQualifiedName(qualifier1, type1) and
17-
f.getCurrent().getDeclaringType().hasFullyQualifiedName(qualifier2, type2) and
18-
f.getMoveNext().getDeclaringType().hasFullyQualifiedName(qualifier3, type3)
19-
select f, f.getElementType().toString(), getIsAsync(f), getQualifiedName(qualifier1, type1),
20-
getLocation(f.getGetEnumerator()), getQualifiedName(qualifier2, type2),
21-
getLocation(f.getCurrent()), getQualifiedName(qualifier3, type3), getLocation(f.getMoveNext())
11+
from ForeachStmt f
12+
select f, f.getElementType().toString(), getIsAsync(f),
13+
f.getGetEnumerator().getDeclaringType().getFullyQualifiedNameDebug(),
14+
getLocation(f.getGetEnumerator()), f.getCurrent().getDeclaringType().getFullyQualifiedNameDebug(),
15+
getLocation(f.getCurrent()), f.getMoveNext().getDeclaringType().getFullyQualifiedNameDebug(),
16+
getLocation(f.getMoveNext())

csharp/ql/test/library-tests/csharp9/record.ql

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,10 @@ query predicate records(RecordClass t, string i, RecordCloneMethod clone) {
77
t.fromSource()
88
}
99

10-
private string getMemberName(Member m) {
11-
exists(string qualifier, string name |
12-
m.getDeclaringType().hasFullyQualifiedName(qualifier, name)
13-
|
14-
result = getQualifiedName(qualifier, name) + "." + m.toStringWithTypes()
15-
)
16-
}
17-
1810
query predicate members(RecordClass t, string ms, string l) {
1911
t.fromSource() and
2012
exists(Member m | t.hasMember(m) |
21-
ms = getMemberName(m) and
13+
ms = getFullyQualifiedNameWithTypes(m) and
2214
if m.fromSource() then l = m.getLocation().toString() else l = "no location"
2315
)
2416
}

0 commit comments

Comments
 (0)