-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathlocationInfo.ql
More file actions
53 lines (48 loc) · 1.52 KB
/
locationInfo.ql
File metadata and controls
53 lines (48 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import definitions
/**
* An element that is the source of a jump-to-definition link.
*/
class Link extends Top {
Link() { exists(definitionOf(this, _)) }
}
/**
* Gets the length of the longest line in file `f`.
*/
pragma[nomagic]
private int maxCols(File f) {
result = max(Location l | l.getFile() = f | l.getStartColumn().maximum(l.getEndColumn()))
}
/**
* Gets the location of an element that has a link-to-definition (in a similar manner to
* `Location.charLoc`)
*/
predicate linkLocationInfo(Link e, string filepath, int begin, int end) {
exists(File f, int maxCols, int startline, int startcolumn, int endline, int endcolumn |
e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
f.getAbsolutePath() = filepath and
maxCols = maxCols(f) and
begin = (startline * maxCols) + startcolumn and
end = (endline * maxCols) + endcolumn
)
}
/**
* Gets a string describing a problem with a `Link`.
*/
string issues(Link e) {
strictcount(Top def | def = definitionOf(e, _)) > 1 and
result = "has more than one definition"
or
exists(string filepath1, int begin1, int end1, Link e2, string filepath2, int begin2, int end2 |
linkLocationInfo(e, filepath1, begin1, end1) and
linkLocationInfo(e2, filepath2, begin2, end2) and
filepath1 = filepath2 and
not end1 < begin2 and
not begin1 > end2 and
e != e2 and
not e.isFromTemplateInstantiation(_) and
not e2.isFromTemplateInstantiation(_)
) and
result = "overlaps another link"
}
from Link e
select e, issues(e)