Skip to content

Commit 73d56e1

Browse files
authored
Merge pull request #881 from hvitved/csharp/remove-get-url
C#: Remove `getUrl()` predicate
2 parents 47ad280 + 8812f26 commit 73d56e1

File tree

10 files changed

+86
-104
lines changed

10 files changed

+86
-104
lines changed

csharp/ql/src/Useless code/DefaultToString.ql

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,22 @@ predicate alwaysDefaultToString(ValueOrRefType t) {
5858
((t.isAbstract() or t instanceof Interface) implies not t.isEffectivelyPublic())
5959
}
6060

61-
newtype TDefaultToStringType = TDefaultToStringType0(ValueOrRefType t) { alwaysDefaultToString(t) }
62-
63-
class DefaultToStringType extends TDefaultToStringType {
64-
ValueOrRefType t;
65-
66-
DefaultToStringType() { this = TDefaultToStringType0(t) }
67-
68-
ValueOrRefType getType() { result = t }
69-
70-
string toString() { result = t.toString() }
61+
class DefaultToStringType extends ValueOrRefType {
62+
DefaultToStringType() { alwaysDefaultToString(this) }
7163

7264
// A workaround for generating empty URLs for non-source locations, because qltest
7365
// does not support non-source locations
74-
string getURL() {
75-
exists(Location l | l = t.getLocation() |
76-
if l instanceof SourceLocation
77-
then
78-
exists(string path, int a, int b, int c, int d | l.hasLocationInfo(path, a, b, c, d) |
79-
toUrl(path, a, b, c, d, result)
80-
)
81-
else result = ""
82-
)
66+
override Location getLocation() {
67+
result = super.getLocation() and
68+
result instanceof SourceLocation
69+
or
70+
not super.getLocation() instanceof SourceLocation and
71+
result instanceof EmptyLocation
8372
}
8473
}
8574

8675
from Expr e, DefaultToStringType t
87-
where invokesToString(e, t.getType())
76+
where invokesToString(e, t)
8877
select e,
8978
"Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing.",
90-
t, t.getType().getName()
79+
t, t.getName()

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class Element extends DotNet::Element, @element {
2424
*/
2525
override Location getLocation() { result = ExprOrStmtParentCached::bestLocation(this) }
2626

27-
/** Gets the URL of this element. */
28-
string getURL() { result = ExprOrStmtParentCached::getURL(this) }
29-
3027
/** Gets a location of this element, including sources and assemblies. */
3128
override Location getALocation() { none() }
3229

csharp/ql/src/semmle/code/csharp/ExprOrStmtParent.qll

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,17 +370,9 @@ module ExprOrStmtParentCached {
370370
or
371371
hasNoSourceLocation(e) and
372372
result = min(Location l | l = e.getALocation() | l order by l.getFile().toString())
373-
}
374-
375-
cached
376-
string getURL(Element e) {
377-
exists(Location l, string path, int a, int b, int c, int d | l = bestLocation(e) |
378-
l.hasLocationInfo(path, a, b, c, d) and
379-
toUrl(path, a, b, c, d, result)
380-
)
381373
or
382-
not exists(bestLocation(e)) and
383-
result = ""
374+
not exists(e.getALocation()) and
375+
result instanceof EmptyLocation
384376
}
385377
}
386378
private import ExprOrStmtParentCached

csharp/ql/src/semmle/code/csharp/Location.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class Location extends @location {
5151
final int getEndColumn() { this.hasLocationInfo(_, _, _, _, result) }
5252
}
5353

54+
/** An empty location. */
55+
class EmptyLocation extends Location { EmptyLocation() { this.hasLocationInfo("", 0, 0, 0, 0) } }
56+
5457
/**
5558
* A location in source code, comprising of a source file and a segment of text
5659
* within the file.

csharp/ql/src/semmle/code/csharp/frameworks/Format.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ class InvalidFormatString extends StringLiteral {
149149
result = this.getValue().regexpFind(getValidFormatRegex(), 0, 0).length()
150150
}
151151

152-
override string getURL() {
152+
/** Gets the URL of this element. */
153+
string getURL() {
153154
exists(
154155
string filepath, int startline, int startcolumn, int endline, int endcolumn,
155156
int oldstartcolumn, int padding
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
| async.cs:11:29:11:32 | Main | | private |
2-
| async.cs:11:29:11:32 | Main | | static |
3-
| async.cs:22:35:22:57 | PrintContentLengthAsync | | async |
4-
| async.cs:22:35:22:57 | PrintContentLengthAsync | | private |
5-
| async.cs:22:35:22:57 | PrintContentLengthAsync | | static |
6-
| async.cs:28:40:28:57 | ContentLengthAsync | | async |
7-
| async.cs:28:40:28:57 | ContentLengthAsync | | private |
8-
| async.cs:28:40:28:57 | ContentLengthAsync | | static |
9-
| async.cs:38:35:38:47 | AsyncIterator | | async |
10-
| async.cs:38:35:38:47 | AsyncIterator | | private |
11-
| async.cs:38:35:38:47 | AsyncIterator | | static |
12-
| async.cs:50:49:50:57 | OpenAsync | | async |
13-
| async.cs:50:49:50:57 | OpenAsync | | private |
14-
| async.cs:50:49:50:57 | OpenAsync | | static |
1+
| async.cs:11:29:11:32 | Main | file://:0:0:0:0 | private |
2+
| async.cs:11:29:11:32 | Main | file://:0:0:0:0 | static |
3+
| async.cs:22:35:22:57 | PrintContentLengthAsync | file://:0:0:0:0 | async |
4+
| async.cs:22:35:22:57 | PrintContentLengthAsync | file://:0:0:0:0 | private |
5+
| async.cs:22:35:22:57 | PrintContentLengthAsync | file://:0:0:0:0 | static |
6+
| async.cs:28:40:28:57 | ContentLengthAsync | file://:0:0:0:0 | async |
7+
| async.cs:28:40:28:57 | ContentLengthAsync | file://:0:0:0:0 | private |
8+
| async.cs:28:40:28:57 | ContentLengthAsync | file://:0:0:0:0 | static |
9+
| async.cs:38:35:38:47 | AsyncIterator | file://:0:0:0:0 | async |
10+
| async.cs:38:35:38:47 | AsyncIterator | file://:0:0:0:0 | private |
11+
| async.cs:38:35:38:47 | AsyncIterator | file://:0:0:0:0 | static |
12+
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | async |
13+
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | private |
14+
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | static |
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
| Modifiers.cs:4:18:4:18 | C | | internal |
2-
| Modifiers.cs:4:18:4:18 | C | | unsafe |
3-
| Modifiers.cs:7:9:7:9 | C | | private |
4-
| Modifiers.cs:9:16:9:16 | C | | public |
5-
| Modifiers.cs:12:14:12:15 | M1 | | private |
6-
| Modifiers.cs:14:22:14:23 | M2 | | private |
7-
| Modifiers.cs:16:24:16:25 | M3 | | protected |
8-
| Modifiers.cs:18:35:18:36 | M4 | | extern |
9-
| Modifiers.cs:18:35:18:36 | M4 | | public |
10-
| Modifiers.cs:18:35:18:36 | M4 | | static |
11-
| Modifiers.cs:21:20:21:21 | M5 | | async |
12-
| Modifiers.cs:21:20:21:21 | M5 | | private |
13-
| Modifiers.cs:24:22:24:23 | C1 | | private |
14-
| Modifiers.cs:24:22:24:23 | C1 | | sealed |
15-
| Modifiers.cs:26:20:26:21 | C1 | | public |
16-
| Modifiers.cs:29:34:29:35 | C2 | | abstract |
17-
| Modifiers.cs:29:34:29:35 | C2 | | protected |
18-
| Modifiers.cs:31:23:31:24 | C2 | | protected |
19-
| Modifiers.cs:33:22:33:23 | M2 | | new |
20-
| Modifiers.cs:33:22:33:23 | M2 | | private |
21-
| Modifiers.cs:35:34:35:35 | M6 | | abstract |
22-
| Modifiers.cs:35:34:35:35 | M6 | | public |
23-
| Modifiers.cs:38:32:38:33 | C3 | | internal |
24-
| Modifiers.cs:38:32:38:33 | C3 | | partial |
25-
| Modifiers.cs:41:20:41:21 | F1 | | private |
26-
| Modifiers.cs:41:20:41:21 | F1 | | static |
27-
| Modifiers.cs:43:26:43:27 | F2 | | const |
28-
| Modifiers.cs:43:26:43:27 | F2 | | public |
29-
| Modifiers.cs:43:26:43:27 | F2 | | static |
30-
| Modifiers.cs:45:41:45:42 | F3 | | internal |
31-
| Modifiers.cs:45:41:45:42 | F3 | | protected |
32-
| Modifiers.cs:45:41:45:42 | F3 | | readonly |
33-
| Modifiers.cs:47:30:47:31 | F4 | | private |
34-
| Modifiers.cs:47:30:47:31 | F4 | | volatile |
35-
| Modifiers.cs:50:24:50:24 | I | | internal |
36-
| Modifiers.cs:52:19:52:19 | S | | public |
37-
| Modifiers.cs:52:19:52:19 | S | | sealed |
38-
| Modifiers.cs:54:20:54:21 | P1 | | public |
39-
| Modifiers.cs:54:36:54:38 | get_P1 | | public |
40-
| Modifiers.cs:54:52:54:54 | set_P1 | | public |
41-
| Modifiers.cs:55:20:55:21 | P2 | | public |
42-
| Modifiers.cs:55:36:55:38 | get_P2 | | public |
43-
| Modifiers.cs:55:49:55:51 | set_P2 | | private |
44-
| Modifiers.cs:57:13:57:14 | P3 | | private |
45-
| Modifiers.cs:57:30:57:32 | get_P3 | | private |
46-
| Modifiers.cs:57:47:57:49 | set_P3 | | private |
1+
| Modifiers.cs:4:18:4:18 | C | file://:0:0:0:0 | internal |
2+
| Modifiers.cs:4:18:4:18 | C | file://:0:0:0:0 | unsafe |
3+
| Modifiers.cs:7:9:7:9 | C | file://:0:0:0:0 | private |
4+
| Modifiers.cs:9:16:9:16 | C | file://:0:0:0:0 | public |
5+
| Modifiers.cs:12:14:12:15 | M1 | file://:0:0:0:0 | private |
6+
| Modifiers.cs:14:22:14:23 | M2 | file://:0:0:0:0 | private |
7+
| Modifiers.cs:16:24:16:25 | M3 | file://:0:0:0:0 | protected |
8+
| Modifiers.cs:18:35:18:36 | M4 | file://:0:0:0:0 | extern |
9+
| Modifiers.cs:18:35:18:36 | M4 | file://:0:0:0:0 | public |
10+
| Modifiers.cs:18:35:18:36 | M4 | file://:0:0:0:0 | static |
11+
| Modifiers.cs:21:20:21:21 | M5 | file://:0:0:0:0 | async |
12+
| Modifiers.cs:21:20:21:21 | M5 | file://:0:0:0:0 | private |
13+
| Modifiers.cs:24:22:24:23 | C1 | file://:0:0:0:0 | private |
14+
| Modifiers.cs:24:22:24:23 | C1 | file://:0:0:0:0 | sealed |
15+
| Modifiers.cs:26:20:26:21 | C1 | file://:0:0:0:0 | public |
16+
| Modifiers.cs:29:34:29:35 | C2 | file://:0:0:0:0 | abstract |
17+
| Modifiers.cs:29:34:29:35 | C2 | file://:0:0:0:0 | protected |
18+
| Modifiers.cs:31:23:31:24 | C2 | file://:0:0:0:0 | protected |
19+
| Modifiers.cs:33:22:33:23 | M2 | file://:0:0:0:0 | new |
20+
| Modifiers.cs:33:22:33:23 | M2 | file://:0:0:0:0 | private |
21+
| Modifiers.cs:35:34:35:35 | M6 | file://:0:0:0:0 | abstract |
22+
| Modifiers.cs:35:34:35:35 | M6 | file://:0:0:0:0 | public |
23+
| Modifiers.cs:38:32:38:33 | C3 | file://:0:0:0:0 | internal |
24+
| Modifiers.cs:38:32:38:33 | C3 | file://:0:0:0:0 | partial |
25+
| Modifiers.cs:41:20:41:21 | F1 | file://:0:0:0:0 | private |
26+
| Modifiers.cs:41:20:41:21 | F1 | file://:0:0:0:0 | static |
27+
| Modifiers.cs:43:26:43:27 | F2 | file://:0:0:0:0 | const |
28+
| Modifiers.cs:43:26:43:27 | F2 | file://:0:0:0:0 | public |
29+
| Modifiers.cs:43:26:43:27 | F2 | file://:0:0:0:0 | static |
30+
| Modifiers.cs:45:41:45:42 | F3 | file://:0:0:0:0 | internal |
31+
| Modifiers.cs:45:41:45:42 | F3 | file://:0:0:0:0 | protected |
32+
| Modifiers.cs:45:41:45:42 | F3 | file://:0:0:0:0 | readonly |
33+
| Modifiers.cs:47:30:47:31 | F4 | file://:0:0:0:0 | private |
34+
| Modifiers.cs:47:30:47:31 | F4 | file://:0:0:0:0 | volatile |
35+
| Modifiers.cs:50:24:50:24 | I | file://:0:0:0:0 | internal |
36+
| Modifiers.cs:52:19:52:19 | S | file://:0:0:0:0 | public |
37+
| Modifiers.cs:52:19:52:19 | S | file://:0:0:0:0 | sealed |
38+
| Modifiers.cs:54:20:54:21 | P1 | file://:0:0:0:0 | public |
39+
| Modifiers.cs:54:36:54:38 | get_P1 | file://:0:0:0:0 | public |
40+
| Modifiers.cs:54:52:54:54 | set_P1 | file://:0:0:0:0 | public |
41+
| Modifiers.cs:55:20:55:21 | P2 | file://:0:0:0:0 | public |
42+
| Modifiers.cs:55:36:55:38 | get_P2 | file://:0:0:0:0 | public |
43+
| Modifiers.cs:55:49:55:51 | set_P2 | file://:0:0:0:0 | private |
44+
| Modifiers.cs:57:13:57:14 | P3 | file://:0:0:0:0 | private |
45+
| Modifiers.cs:57:30:57:32 | get_P3 | file://:0:0:0:0 | private |
46+
| Modifiers.cs:57:47:57:49 | set_P3 | file://:0:0:0:0 | private |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| | Q1 | namespaces.cs:50:11:50:15 | Q1.Q2 |
1+
| file://:0:0:0:0 | Q1 | namespaces.cs:50:11:50:15 | Q1.Q2 |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| | null |
1+
| file://:0:0:0:0 | null |
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
| DefaultToString.cs:9:27:9:27 | access to local variable d | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | DefaultToString.cs:4:14:4:28 | DefaultToString | DefaultToString |
22
| DefaultToString.cs:10:28:10:28 | access to local variable d | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | DefaultToString.cs:4:14:4:28 | DefaultToString | DefaultToString |
3-
| DefaultToString.cs:16:27:16:30 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | | Int32[] | Int32[] |
4-
| DefaultToString.cs:19:24:19:27 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | | Int32[] | Int32[] |
3+
| DefaultToString.cs:16:27:16:30 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | Int32[] | Int32[] |
4+
| DefaultToString.cs:19:24:19:27 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | Int32[] | Int32[] |
55
| DefaultToString.cs:34:27:34:27 | access to local variable f | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | DefaultToString.cs:62:23:62:30 | IPrivate | IPrivate |
66
| DefaultToStringBad.cs:8:35:8:35 | access to local variable p | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | DefaultToStringBad.cs:14:11:14:16 | Person | Person |
7-
| DefaultToStringBad.cs:11:38:11:41 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | | Int32[] | Int32[] |
8-
| WriteLineArray.cs:7:23:7:26 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | | String[] | String[] |
9-
| WriteLineArray.cs:8:27:8:30 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | | String[] | String[] |
10-
| WriteLineArray.cs:10:36:10:39 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | | String[] | String[] |
11-
| WriteLineArray.cs:11:40:11:43 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | | String[] | String[] |
7+
| DefaultToStringBad.cs:11:38:11:41 | access to local variable ints | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | Int32[] | Int32[] |
8+
| WriteLineArray.cs:7:23:7:26 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | String[] | String[] |
9+
| WriteLineArray.cs:8:27:8:30 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | String[] | String[] |
10+
| WriteLineArray.cs:10:36:10:39 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | String[] | String[] |
11+
| WriteLineArray.cs:11:40:11:43 | access to parameter args | Default 'ToString()': $@ inherits 'ToString()' from 'Object', and so is not suitable for printing. | file://:0:0:0:0 | String[] | String[] |

0 commit comments

Comments
 (0)