mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Merge pull request #17855 from hvitved/csharp/comments-mapped-locations
C#: Take mapped locations into account in `Comments.qll`
This commit is contained in:
@@ -8,6 +8,13 @@
|
||||
import Element
|
||||
import Location
|
||||
|
||||
private Location unmapLoc(Location l) {
|
||||
result.(SourceLocation).getMappedLocation() = l
|
||||
or
|
||||
not exists(result.(SourceLocation).getMappedLocation()) and
|
||||
result = l
|
||||
}
|
||||
|
||||
/**
|
||||
* A single line of comment.
|
||||
*
|
||||
@@ -19,7 +26,7 @@ class CommentLine extends @commentline {
|
||||
string toString() { none() }
|
||||
|
||||
/** Gets the location of this comment line. */
|
||||
Location getLocation() { commentline_location(this, result) }
|
||||
Location getLocation() { commentline_location(this, unmapLoc(result)) }
|
||||
|
||||
/** Gets the containing comment block. */
|
||||
CommentBlock getParent() { result.getAChild() = this }
|
||||
@@ -159,7 +166,7 @@ class CommentBlock extends @commentblock {
|
||||
string toString() { result = this.getChild(0).toString() }
|
||||
|
||||
/** Gets the location of this comment block */
|
||||
Location getLocation() { commentblock_location(this, result) }
|
||||
Location getLocation() { commentblock_location(this, unmapLoc(result)) }
|
||||
|
||||
/** Gets the number of lines in this comment block. */
|
||||
int getNumLines() { result = count(this.getAChild()) }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
| comments1.cs:1:1:2:46 | // ... | comments1.cs:9:7:9:7 | C | Start of comment1.cs |
|
||||
| comments1.cs:1:16:1:46 | // ... | comments1.cs:2:9:2:14 | ... ...; | A mapped single-line comment |
|
||||
| comments1.cs:4:1:4:25 | // ... | comments1.cs:9:7:9:7 | C | 1) Basic comment types |
|
||||
| comments1.cs:6:1:6:24 | // ... | comments1.cs:9:7:9:7 | C | A single-line comment |
|
||||
| comments1.cs:8:1:8:18 | /// ... | comments1.cs:9:7:9:7 | C | An XML comment |
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
| comments1.cs:1:16:1:46 | // ... | comments1.cs:1:9:1:14 | ... ...; | A mapped single-line comment |
|
||||
| comments1.cs:11:1:11:25 | /* ... */ | comments1.cs:9:7:9:7 | C | A multiline comment |
|
||||
| comments1.cs:13:1:13:20 | // ... | comments1.cs:9:7:9:7 | C | 2) Comment blocks |
|
||||
| comments1.cs:15:1:15:38 | // ... | comments1.cs:9:7:9:7 | C | A line on its own is a commentblock |
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
| comments1.cs:1:16:1:46 | // ... | trivia.cs:17:5:29:5 | {...} | A mapped single-line comment |
|
||||
| comments1.cs:36:5:38:41 | /* ... */ | comments1.cs:34:7:34:9 | Foo | |
|
||||
| comments1.cs:39:13:40:51 | // ... | comments1.cs:34:7:34:9 | Foo | as this line |
|
||||
| comments1.cs:42:15:42:36 | // ... | comments1.cs:34:7:34:9 | Foo | These are different |
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
| comments1.cs:1:16:1:46 | // ... | comments1.cs:1:9:1:14 | ... ...; | A mapped single-line comment |
|
||||
| comments1.cs:8:1:8:18 | /// ... | comments1.cs:9:7:9:7 | C | An XML comment |
|
||||
| comments1.cs:36:5:38:41 | /* ... */ | comments1.cs:39:9:39:9 | x | |
|
||||
| comments1.cs:39:13:40:51 | // ... | comments1.cs:39:9:39:9 | x | as this line |
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
singlelineComment
|
||||
| comments1.cs:1:1:2:46 | // ... | comments1.cs:1:1:1:23 | // ... | 2 | Start of comment1.cs | // Start of comment1.cs |
|
||||
| comments1.cs:1:1:2:46 | // ... | comments1.cs:2:1:2:46 | // ... | 2 | This tests the basic types of comment block | // This tests the basic types of comment block |
|
||||
| comments1.cs:1:16:1:46 | // ... | comments1.cs:1:16:1:46 | // ... | 1 | A mapped single-line comment | // A mapped single-line comment |
|
||||
| comments1.cs:4:1:4:25 | // ... | comments1.cs:4:1:4:25 | // ... | 1 | 1) Basic comment types | // 1) Basic comment types |
|
||||
| comments1.cs:6:1:6:24 | // ... | comments1.cs:6:1:6:24 | // ... | 1 | A single-line comment | // A single-line comment |
|
||||
| comments1.cs:13:1:13:20 | // ... | comments1.cs:13:1:13:20 | // ... | 1 | 2) Comment blocks | // 2) Comment blocks |
|
||||
|
||||
@@ -16,6 +16,7 @@ mapped
|
||||
| trivia.cs:19:9:19:11 | trivia.cs:19:9:19:11 | comments1.cs:1:9:1:11 | comments1.cs:1:9:1:11 |
|
||||
| trivia.cs:19:9:19:14 | trivia.cs:19:9:19:14 | comments1.cs:1:9:1:14 | comments1.cs:1:9:1:14 |
|
||||
| trivia.cs:19:13:19:13 | trivia.cs:19:13:19:13 | comments1.cs:1:13:1:13 | comments1.cs:1:13:1:13 |
|
||||
| trivia.cs:19:16:19:46 | trivia.cs:19:16:19:46 | comments1.cs:1:16:1:46 | comments1.cs:1:16:1:46 |
|
||||
| trivia.cs:20:9:20:11 | trivia.cs:20:9:20:11 | comments1.cs:2:9:2:11 | comments1.cs:2:9:2:11 |
|
||||
| trivia.cs:20:9:20:14 | trivia.cs:20:9:20:14 | comments1.cs:2:9:2:14 | comments1.cs:2:9:2:14 |
|
||||
| trivia.cs:20:13:20:13 | trivia.cs:20:13:20:13 | comments1.cs:2:13:2:13 | comments1.cs:2:13:2:13 |
|
||||
|
||||
@@ -16,7 +16,7 @@ class Tr1
|
||||
static void M1()
|
||||
{
|
||||
#line 1 "comments1.cs"
|
||||
int i;
|
||||
int i; // A mapped single-line comment
|
||||
int j;
|
||||
#line default
|
||||
char c;
|
||||
|
||||
Reference in New Issue
Block a user