Skip to content

Commit edb4165

Browse files
committed
Java: incorporate SMAP locations into Top.hasLocationInfo
1 parent e2419e8 commit edb4165

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import FileSystem
88
import semmle.code.java.Element
9+
import semmle.code.SMAP
910

1011
/** Holds if element `e` has name `name`. */
1112
predicate hasName(Element e, string name) {
@@ -61,6 +62,18 @@ class Top extends @top {
6162
*/
6263
predicate hasLocationInfo(
6364
string filepath, int startline, int startcolumn, int endline, int endcolumn
65+
) {
66+
hasLocationInfoAux(filepath, startline, startcolumn, endline, endcolumn)
67+
or
68+
exists(string outFilepath, int outStartline, int outEndline |
69+
hasLocationInfoAux(outFilepath, outStartline, _, outEndline, _) and
70+
hasSmapLocationInfo(filepath, startline, startcolumn, endline, endcolumn, outFilepath,
71+
outStartline, outEndline)
72+
)
73+
}
74+
75+
predicate hasLocationInfoAux(
76+
string filepath, int startline, int startcolumn, int endline, int endcolumn
6477
) {
6578
exists(File f, Location l | fixedHasLocation(this, l, f) |
6679
locations_default(l, f, startline, startcolumn, endline, endcolumn) and

java/ql/src/semmle/code/SMAP.qll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import java
2+
3+
predicate smap(File inputFile, int inLine, File outputFile, int outLineStart, int outLineEnd) {
4+
exists(
5+
string defaultStratum, int inputFileNum, int inStart, int inCount, int outStart, int outIncr,
6+
int n
7+
|
8+
smap_header(outputFile, _, defaultStratum) and
9+
smap_files(outputFile, defaultStratum, inputFileNum, _, inputFile) and
10+
smap_lines(outputFile, defaultStratum, inputFileNum, inStart, inCount, outStart, outIncr) and
11+
inLine in [inStart .. inStart + inCount - 1] and
12+
outLineStart = outStart + n * outIncr and
13+
outLineEnd = (n + 1) * outIncr - 1 + outStart and
14+
n = inLine - inStart
15+
)
16+
}
17+
18+
predicate smap(File inputFile, int inLine, File outputFile, int outLine) {
19+
exists(int outLineStart, int outLineEnd |
20+
smap(inputFile, inLine, outputFile, outLineStart, outLineEnd) and
21+
outLine in [outLineStart .. outLineEnd]
22+
)
23+
}
24+
25+
predicate hasSmapLocationInfo(
26+
string inputPath, int isl, int isc, int iel, int iec, string outputPath, int osl, int oel
27+
) {
28+
exists(File inputFile, File outputFile |
29+
inputPath = inputFile.getAbsolutePath() and
30+
outputPath = outputFile.getAbsolutePath() and
31+
smap(inputFile, isl, outputFile, osl) and
32+
smap(inputFile, iel - 1, outputFile, oel) and
33+
isc = 1 and
34+
iec = 0
35+
)
36+
}

0 commit comments

Comments
 (0)