CPP: Resolve #endif FPs.

This commit is contained in:
Geoffrey White
2019-04-11 10:31:15 +01:00
parent 4beb77588a
commit 9e6b178d48
2 changed files with 27 additions and 9 deletions

View File

@@ -47,12 +47,27 @@ private predicate looksLikeCode(string line) {
)
}
/**
* Holds if there is a preprocessor directive on the line indicated by
* `f` and `line`.
*/
private predicate preprocLine(File f, int line) {
exists(PreprocessorDirective pd, Location l |
pd.getLocation() = l and
l.getFile() = f and
l.getStartLine() = line
)
}
/**
* The line of a C++-style comment within its file `f`.
*/
private int lineInFile(CppStyleComment c, File f) {
f = c.getFile() and
result = c.getLocation().getStartLine()
result = c.getLocation().getStartLine() and
// Ignore comments on the same line as a preprocessor directive.
not preprocLine(f, result)
}
/**
@@ -89,9 +104,17 @@ private int commentId(CppStyleComment c, File f, int line) {
*/
class CommentBlock extends Comment {
CommentBlock() {
this instanceof CppStyleComment
implies
not exists(CppStyleComment pred, File f | lineInFile(pred, f) + 1 = lineInFile(this, f))
(
this instanceof CppStyleComment
implies
not exists(CppStyleComment pred, File f | lineInFile(pred, f) + 1 = lineInFile(this, f))
) and (
// Ignore comments on the same line as a preprocessor directive.
not exists(Location l |
l = this.getLocation() and
preprocLine(l.getFile(), l.getStartLine())
)
)
}
/**