-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
190 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
private import csharp | ||
|
||
private SourceLocation fromMappedLocation(SourceLocation loc) { result.getMappedLocation() = loc } | ||
|
||
/** Holds if `l1` and `l2` are in the same file. */ | ||
bindingset[l1, l2] | ||
pragma[inline_late] | ||
predicate inSameFile(Location l1, Location l2) { | ||
[l1, fromMappedLocation(l1)].getFile() = [l2, fromMappedLocation(l2)].getFile() | ||
} | ||
|
||
/** Gets a source location for `e`, if any. */ | ||
pragma[nomagic] | ||
SourceLocation getASourceLocation(Element e) { | ||
result = e.getALocation().(SourceLocation) and | ||
Check warning Code scanning / CodeQL Redundant cast Warning
Redundant cast to
SourceLocation Error loading related location Loading |
||
not exists(e.getALocation().(SourceLocation).getMappedLocation()) | ||
or | ||
result = e.getALocation().(SourceLocation).getMappedLocation() | ||
} | ||
|
||
/** Provides the input to `NearestLocation`. */ | ||
signature module NearestLocationInputSig { | ||
class C { | ||
string toString(); | ||
|
||
Location getLocation(); | ||
} | ||
|
||
predicate relevantLocations(C c, Location l1, Location l2); | ||
} | ||
|
||
private Location unmap(Location l) { | ||
result = fromMappedLocation(l) | ||
or | ||
not exists(fromMappedLocation(l)) and | ||
result = l | ||
} | ||
|
||
module NearestLocation<NearestLocationInputSig Input> { | ||
pragma[nomagic] | ||
predicate nearestLocation( | ||
Input::C c, Location l1, Location l2, Location l1unmapped, Location l2unmapped | ||
) { | ||
Input::relevantLocations(c, l1, l2) and | ||
l1unmapped = unmap(l1) and | ||
l2unmapped = unmap(l2) and | ||
l1unmapped.before(l2unmapped) | ||
} | ||
|
||
pragma[nomagic] | ||
predicate nearestLocation(Input::C c, Location l1, Location l2) { | ||
l1 = | ||
max(Location loc, Location l1unmapped, Location l2unmapped, int startline1, int startcolumn1 | | ||
nearestLocation(c, loc, l2, l1unmapped, l2unmapped) and | ||
l1unmapped.hasLocationInfo(_, startline1, startcolumn1, _, _) | ||
| | ||
loc order by startline1, startcolumn1 | ||
) | ||
} | ||
} |
Oops, something went wrong.