mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Merge pull request #6010 from geoffw0/charloc
C++: Test and fix maxCols / charLoc
This commit is contained in:
@@ -128,7 +128,9 @@ deprecated library class LocationExpr extends Location, @location_expr { }
|
||||
* 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()) }
|
||||
private int maxCols(File f) {
|
||||
result = max(Location l | l.getFile() = f | l.getStartColumn().maximum(l.getEndColumn()))
|
||||
}
|
||||
|
||||
/**
|
||||
* A C/C++ element that has a location in a file
|
||||
|
||||
8
cpp/ql/test/library-tests/locations/charloc/charloc.cpp
Normal file
8
cpp/ql/test/library-tests/locations/charloc/charloc.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
void test()
|
||||
{
|
||||
1;
|
||||
2 + 3;
|
||||
(
|
||||
4);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
| charloc.cpp | 1 | 47 | 47 | 1 |
|
||||
| charloc.cpp | 2 | 58 | 58 | 2 |
|
||||
| charloc.cpp | 3 | 62 | 62 | 3 |
|
||||
| charloc.cpp | 4 | 78 | 78 | 4 |
|
||||
| charloc.cpp | (...) | 77 | 79 | (...), 4 |
|
||||
| charloc.cpp | ... + ... | 58 | 62 | ... + ..., 2, 3 |
|
||||
8
cpp/ql/test/library-tests/locations/charloc/charloc.ql
Normal file
8
cpp/ql/test/library-tests/locations/charloc/charloc.ql
Normal file
@@ -0,0 +1,8 @@
|
||||
import cpp
|
||||
|
||||
from File f, Expr e, Location l, int start, int end
|
||||
where
|
||||
e.getLocation() = l and
|
||||
l.charLoc(f, start, end)
|
||||
select f.getBaseName(), e.toString(), start, end,
|
||||
concat(Expr e2, Location l2 | e2.getLocation() = l2 and l.subsumes(l2) | e2.toString(), ", ")
|
||||
@@ -11,7 +11,9 @@ class Link extends Top {
|
||||
* 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()) }
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user