Skip to content

Commit 9cdcc3e

Browse files
committed
C++: make files/folders instances of location
1 parent 08a6acc commit 9cdcc3e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import semmle.code.cpp.File
99
* A location of a C/C++ artifact.
1010
*/
1111
class Location extends @location {
12+
Location() { not files(this, "") }
13+
1214
/** Gets the container corresponding to this location. */
1315
pragma[nomagic]
1416
Container getContainer() { this.fullLocationInfo(result, _, _, _, _) }
@@ -53,9 +55,20 @@ class Location extends @location {
5355
predicate fullLocationInfo(
5456
Container container, int startline, int startcolumn, int endline, int endcolumn
5557
) {
56-
locations_default(this, unresolveElement(container), startline, startcolumn, endline, endcolumn) or
57-
locations_expr(this, unresolveElement(container), startline, startcolumn, endline, endcolumn) or
58+
locations_default(this, unresolveElement(container), startline, startcolumn, endline, endcolumn)
59+
or
60+
locations_expr(this, unresolveElement(container), startline, startcolumn, endline, endcolumn)
61+
or
5862
locations_stmt(this, unresolveElement(container), startline, startcolumn, endline, endcolumn)
63+
or
64+
exists(@container c, string name | files(c, name) or folders(c, name) |
65+
container = c and
66+
this = c and
67+
startline = 0 and
68+
startcolumn = 0 and
69+
endline = 0 and
70+
endcolumn = 0
71+
)
5972
}
6073

6174
/**

cpp/ql/lib/semmlecode.cpp.dbscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ header_to_external_package(
224224
int package : @external_package ref
225225
);
226226

227-
@location = @location_stmt | @location_expr | @location_default ;
227+
@location = @location_stmt | @location_expr | @location_default | @container;
228228

229229
/**
230230
* The location of a statement.

0 commit comments

Comments
 (0)