mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
C++: Fix bad join in 'definitionOf'.
This commit is contained in:
@@ -123,6 +123,13 @@ private predicate constructorCallTypeMention(ConstructorCall cc, TypeMention tm)
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if `loc` has the container `container` and is on the line starting at `startLine`. */
|
||||
pragma[nomagic]
|
||||
private predicate hasContainerAndStartLine(Location loc, Container container, int startLine) {
|
||||
loc.getStartLine() = startLine and
|
||||
loc.getContainer() = container
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element, of kind `kind`, that element `e` uses, if any.
|
||||
* Attention: This predicate yields multiple definitions for a single location.
|
||||
@@ -184,11 +191,9 @@ Top definitionOf(Top e, string kind) {
|
||||
kind = "I" and
|
||||
result = e.(Include).getIncludedFile() and
|
||||
// exclude `#include` directives containing macros
|
||||
not exists(MacroInvocation mi, Location l1, Location l2 |
|
||||
l1 = e.(Include).getLocation() and
|
||||
l2 = mi.getLocation() and
|
||||
l1.getContainer() = l2.getContainer() and
|
||||
l1.getStartLine() = l2.getStartLine()
|
||||
not exists(MacroInvocation mi, Container container, int startLine |
|
||||
hasContainerAndStartLine(e.(Include).getLocation(), container, startLine) and
|
||||
hasContainerAndStartLine(mi.getLocation(), container, startLine)
|
||||
// (an #include directive must be always on it's own line)
|
||||
)
|
||||
) and
|
||||
|
||||
@@ -10,12 +10,14 @@ import semmle.code.cpp.File
|
||||
*/
|
||||
class Location extends @location {
|
||||
/** Gets the container corresponding to this location. */
|
||||
pragma[nomagic]
|
||||
Container getContainer() { this.fullLocationInfo(result, _, _, _, _) }
|
||||
|
||||
/** Gets the file corresponding to this location, if any. */
|
||||
File getFile() { result = this.getContainer() }
|
||||
|
||||
/** Gets the 1-based line number (inclusive) where this location starts. */
|
||||
pragma[nomagic]
|
||||
int getStartLine() { this.fullLocationInfo(_, result, _, _, _) }
|
||||
|
||||
/** Gets the 1-based column number (inclusive) where this location starts. */
|
||||
|
||||
Reference in New Issue
Block a user