mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
CPP: Better fileHeaderLimit.
This commit is contained in:
@@ -48,14 +48,45 @@ predicate hasPragmaDifferentFile(File f) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum line number we consider to be "near the beginning" of file `f`.
|
||||
* The line where the first comment in file `f` begins (maximum of 5). This allows
|
||||
* us to skip past any preprocessor logic or similar code before the first comment.
|
||||
*/
|
||||
private int fileFirstComment(File f) {
|
||||
result = min(int line |
|
||||
exists(Comment c |
|
||||
c.getFile() = f and
|
||||
c.getLocation().getStartLine() = line and
|
||||
line < 5
|
||||
)
|
||||
).minimum(5)
|
||||
}
|
||||
|
||||
/**
|
||||
* The line where the initial comments of file `f` end. This is just before the
|
||||
* first bit of code, excluding anything skipped over by `fileFirstComment`.
|
||||
*/
|
||||
private int fileHeaderLimit(File f) {
|
||||
result = max(int head, int line |
|
||||
head <= 5 and
|
||||
locations_default(_, underlyingElement(f), head, _, line, _) |
|
||||
line
|
||||
) + 5
|
||||
exists(int fc |
|
||||
fc = fileFirstComment(f) and
|
||||
result = min(int line |
|
||||
exists(DeclarationEntry de, Location l |
|
||||
l = de.getLocation() and
|
||||
l.getFile() = f and
|
||||
line = l.getStartLine() - 1 and
|
||||
line > fc
|
||||
) or exists(PreprocessorDirective pd, Location l |
|
||||
l = pd.getLocation() and
|
||||
l.getFile() = f and
|
||||
line = l.getStartLine() - 1 and
|
||||
line > fc
|
||||
) or exists(NamespaceDeclarationEntry nde, Location l |
|
||||
l = nde.getLocation() and
|
||||
l.getFile() = f and
|
||||
line = l.getStartLine() - 1 and
|
||||
line > fc
|
||||
) or line = f.getMetrics().getNumberOfLines()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,10 +100,13 @@ private int fileHeaderLimit(File f) {
|
||||
*/
|
||||
class AutogeneratedFile extends File {
|
||||
cached AutogeneratedFile() {
|
||||
exists(Comment c |
|
||||
c.getFile() = this and
|
||||
c.getLocation().getStartLine() <= fileHeaderLimit(this) and
|
||||
autogeneratedComment(c)
|
||||
) or hasPragmaDifferentFile(this)
|
||||
autogeneratedComment(
|
||||
concat(Comment c |
|
||||
c.getFile() = this and
|
||||
c.getLocation().getStartLine() <= fileHeaderLimit(this) |
|
||||
c.getContents() order by c.getLocation().getStartLine()
|
||||
)
|
||||
) or
|
||||
hasPragmaDifferentFile(this)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user