mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
Some files that will change in #1736 have been spared. ./build -j4 target/jars/qlformat find ql/cpp/ql -name "*.ql" -print0 | xargs -0 target/jars/qlformat --input find ql/cpp/ql -name "*.qll" -print0 | xargs -0 target/jars/qlformat --input (cd ql && git checkout 'cpp/ql/src/semmle/code/cpp/ir/implementation/**/*SSA*.qll') buildutils-internal/scripts/pr-checks/sync-identical-files.py --latest
50 lines
1.4 KiB
Plaintext
50 lines
1.4 KiB
Plaintext
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.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
|
|
result = "overlaps another link"
|
|
}
|
|
|
|
from Link e
|
|
select e, issues(e)
|