@@ -47,12 +47,27 @@ private predicate looksLikeCode(string line) {
4747 )
4848}
4949
50+ /**
51+ * Holds if there is a preprocessor directive on the line indicated by
52+ * `f` and `line`.
53+ */
54+ private predicate preprocLine ( File f , int line ) {
55+ exists ( PreprocessorDirective pd , Location l |
56+ pd .getLocation ( ) = l and
57+ l .getFile ( ) = f and
58+ l .getStartLine ( ) = line
59+ )
60+ }
61+
5062/**
5163 * The line of a C++-style comment within its file `f`.
5264 */
5365private int lineInFile ( CppStyleComment c , File f ) {
5466 f = c .getFile ( ) and
55- result = c .getLocation ( ) .getStartLine ( )
67+ result = c .getLocation ( ) .getStartLine ( ) and
68+
69+ // Ignore comments on the same line as a preprocessor directive.
70+ not preprocLine ( f , result )
5671}
5772
5873/**
@@ -89,9 +104,17 @@ private int commentId(CppStyleComment c, File f, int line) {
89104 */
90105class CommentBlock extends Comment {
91106 CommentBlock ( ) {
92- this instanceof CppStyleComment
93- implies
94- not exists ( CppStyleComment pred , File f | lineInFile ( pred , f ) + 1 = lineInFile ( this , f ) )
107+ (
108+ this instanceof CppStyleComment
109+ implies
110+ not exists ( CppStyleComment pred , File f | lineInFile ( pred , f ) + 1 = lineInFile ( this , f ) )
111+ ) and (
112+ // Ignore comments on the same line as a preprocessor directive.
113+ not exists ( Location l |
114+ l = this .getLocation ( ) and
115+ preprocLine ( l .getFile ( ) , l .getStartLine ( ) )
116+ )
117+ )
95118 }
96119
97120 /**
0 commit comments