Skip to content

Commit 025043a

Browse files
authored
Merge pull request github#6010 from geoffw0/charloc
C++: Test and fix maxCols / charLoc
2 parents 561c8d0 + 6f05fd4 commit 025043a

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ deprecated library class LocationExpr extends Location, @location_expr { }
128128
* Gets the length of the longest line in file `f`.
129129
*/
130130
pragma[nomagic]
131-
private int maxCols(File f) { result = max(Location l | l.getFile() = f | l.getEndColumn()) }
131+
private int maxCols(File f) {
132+
result = max(Location l | l.getFile() = f | l.getStartColumn().maximum(l.getEndColumn()))
133+
}
132134

133135
/**
134136
* A C/C++ element that has a location in a file
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
void test()
3+
{
4+
1;
5+
2 + 3;
6+
(
7+
4);
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| charloc.cpp | 1 | 47 | 47 | 1 |
2+
| charloc.cpp | 2 | 58 | 58 | 2 |
3+
| charloc.cpp | 3 | 62 | 62 | 3 |
4+
| charloc.cpp | 4 | 78 | 78 | 4 |
5+
| charloc.cpp | (...) | 77 | 79 | (...), 4 |
6+
| charloc.cpp | ... + ... | 58 | 62 | ... + ..., 2, 3 |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cpp
2+
3+
from File f, Expr e, Location l, int start, int end
4+
where
5+
e.getLocation() = l and
6+
l.charLoc(f, start, end)
7+
select f.getBaseName(), e.toString(), start, end,
8+
concat(Expr e2, Location l2 | e2.getLocation() = l2 and l.subsumes(l2) | e2.toString(), ", ")

cpp/ql/test/query-tests/definitions/locationInfo.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class Link extends Top {
1111
* Gets the length of the longest line in file `f`.
1212
*/
1313
pragma[nomagic]
14-
private int maxCols(File f) { result = max(Location l | l.getFile() = f | l.getEndColumn()) }
14+
private int maxCols(File f) {
15+
result = max(Location l | l.getFile() = f | l.getStartColumn().maximum(l.getEndColumn()))
16+
}
1517

1618
/**
1719
* Gets the location of an element that has a link-to-definition (in a similar manner to

0 commit comments

Comments
 (0)