Skip to content

Commit 184e5d3

Browse files
committed
Extract common library for location handling
1 parent 52e6467 commit 184e5d3

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import cpp
2+
3+
/** Holds if `lineNumber` is an indexed line number in file `f`. */
4+
predicate isLineNumber(File f, int lineNumber) {
5+
exists(Location l | l.getFile() = f |
6+
l.getStartLine() = lineNumber
7+
or
8+
l.getEndLine() = lineNumber
9+
)
10+
}
11+
12+
/** Gets the last line number in `f`. */
13+
int getLastLineNumber(File f) { result = max(int lineNumber | isLineNumber(f, lineNumber)) }
14+
15+
/** Gets the last column number on the last line of `f`. */
16+
int getLastColumnNumber(File f) {
17+
result =
18+
max(Location l |
19+
l.getFile() = f and
20+
l.getEndLine() = getLastLineNumber(f)
21+
|
22+
l.getEndColumn()
23+
)
24+
}

cpp/common/src/codingstandards/cpp/deviations/DeviationsSuppression.ql

+4-27
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,7 @@
77

88
import cpp
99
import Deviations
10-
11-
/** Holds if `lineNumber` is an indexed line number in file `f`. */
12-
private predicate isLineNumber(File f, int lineNumber) {
13-
exists(Location l | l.getFile() = f |
14-
l.getStartLine() = lineNumber
15-
or
16-
l.getEndLine() = lineNumber
17-
)
18-
}
19-
20-
/** Gets the last line number in `f`. */
21-
private int getLastLineNumber(File f) { result = max(int lineNumber | isLineNumber(f, lineNumber)) }
22-
23-
/** Gets the last column number on the last line of `f`. */
24-
int getLastColumnNumber(File f) {
25-
result =
26-
max(Location l |
27-
l.getFile() = f and
28-
l.getEndLine() = getLastLineNumber(f)
29-
|
30-
l.getEndColumn()
31-
)
32-
}
10+
import codingstandards.cpp.Locations
3311

3412
newtype TDeviationScope =
3513
TDeviationRecordFileScope(DeviationRecord dr, File file) {
@@ -71,10 +49,9 @@ class DeviationRecordFileScope extends DeviationScope, TDeviationRecordFileScope
7149
string filepath, int startline, int startcolumn, int endline, int endcolumn
7250
) {
7351
// In an ideal world, we would produce a URL here that informed the AlertSuppression code that
74-
// the whole file was suppressed. However, experimentation suggestions the alert suppression
75-
// code only works with locations with lines and columns, so we generate a location that covers
76-
// the whole "indexed" file, by finding the location indexed in the database with the latest
77-
// line and column number.
52+
// the whole file was suppressed. However, the alert suppression code only works with locations
53+
// with lines and columns, so we generate a location that covers the whole "indexed" file, by
54+
// finding the location indexed in the database with the latest line and column number.
7855
exists(File f | f = getFile() |
7956
f.getLocation().hasLocationInfo(filepath, _, _, _, _) and
8057
startline = 1 and

0 commit comments

Comments
 (0)