]> granicus.if.org Git - clang/commitdiff
don't inform comment handlers about comments in #if 0 blocks,
authorChris Lattner <sabre@nondot.org>
Wed, 3 Feb 2010 21:06:21 +0000 (21:06 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 3 Feb 2010 21:06:21 +0000 (21:06 +0000)
doing so invalidates the file guard optimization and is not
in the spirit of "#if 0" because it is supposed to completely
skip everything, even if it isn't lexically valid. Patch by
Abramo Bagnara!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95253 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Lexer.cpp

index afd1ba885167f942c951ae1f5825e55b51c0f1f3..3207062ccadd623ba1a87b7589bfae3ce3b3cdcd 100644 (file)
@@ -985,10 +985,11 @@ bool Lexer::SkipBCPLComment(Token &Result, const char *CurPtr) {
     if (CurPtr == BufferEnd+1) { --CurPtr; break; }
   } while (C != '\n' && C != '\r');
 
-  // Found but did not consume the newline.
-  if (PP && PP->HandleComment(Result,
-                              SourceRange(getSourceLocation(BufferPtr),
-                                          getSourceLocation(CurPtr)))) {
+  // Found but did not consume the newline.  Notify comment handlers about the
+  // comment unless we're in a #if 0 block.
+  if (PP && !isLexingRawMode() &&
+      PP->HandleComment(Result, SourceRange(getSourceLocation(BufferPtr),
+                                            getSourceLocation(CurPtr)))) {
     BufferPtr = CurPtr;
     return true; // A token has to be returned.
   }
@@ -1235,9 +1236,10 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) {
     C = *CurPtr++;
   }
 
-  if (PP && PP->HandleComment(Result,
-                              SourceRange(getSourceLocation(BufferPtr),
-                                          getSourceLocation(CurPtr)))) {
+  // Notify comment handlers about the comment unless we're in a #if 0 block.
+  if (PP && !isLexingRawMode() &&
+      PP->HandleComment(Result, SourceRange(getSourceLocation(BufferPtr),
+                                            getSourceLocation(CurPtr)))) {
     BufferPtr = CurPtr;
     return true; // A token has to be returned.
   }