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

Skip to content

Commit 899e52a

Browse files
committed
Adjust getMappedLocation to not include line directives
1 parent a1d227d commit 899e52a

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,9 @@ private module Cached {
5858
cached
5959
Location bestLocation(Element e) {
6060
result = e.getALocation().(SourceLocation) and
61-
(
62-
not exists(e.getALocation().(SourceLocation).getMappedLocation()) or
63-
e instanceof LineDirective
64-
)
61+
not exists(e.getALocation().(SourceLocation).getMappedLocation())
6562
or
66-
result = e.getALocation().(SourceLocation).getMappedLocation() and
67-
not e instanceof LineDirective
63+
result = e.getALocation().(SourceLocation).getMappedLocation()
6864
or
6965
hasNoSourceLocation(e) and
7066
result = min(Location l | l = e.getALocation() | l order by l.getFile().toString())

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ class EmptyLocation extends Location {
6363
*/
6464
class SourceLocation extends Location, @location_default {
6565
/** Gets the location that takes into account `#line` directives, if any. */
66-
Location getMappedLocation() { locations_mapped(this, result) }
66+
Location getMappedLocation() {
67+
locations_mapped(this, result) and
68+
not exists(LineDirective l | l.getALocation() = this)
69+
}
6770

6871
override File getFile() { locations_default(this, result, _, _, _, _) }
6972

csharp/ql/test/library-tests/comments/LineDirectives.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ mapped
1919
| trivia.cs:20:9:20:11 | trivia.cs:20:9:20:11 | comments1.cs:2:9:2:11 | comments1.cs:2:9:2:11 |
2020
| trivia.cs:20:9:20:14 | trivia.cs:20:9:20:14 | comments1.cs:2:9:2:14 | comments1.cs:2:9:2:14 |
2121
| trivia.cs:20:13:20:13 | trivia.cs:20:13:20:13 | comments1.cs:2:13:2:13 | comments1.cs:2:13:2:13 |
22-
| trivia.cs:21:1:21:13 | trivia.cs:21:1:21:13 | comments1.cs:3:1:3:13 | comments1.cs:3:1:3:13 |

0 commit comments

Comments
 (0)