[PATCH] Preprocessor: preserve whitespace in -traditional-cpp mode.

Richard Smith richard at metafoo.co.uk
Tue Feb 12 15:22:25 PST 2013



================
Comment at: test/Preprocessor/traditional-cpp.c:16-17
@@ +15,4 @@
+/* The following lines contain tab characters; do not change them! */
+/* CHECK:	{{i}}ndented!
+ * CHECK: {{tab}}	{{separated}}	{{values}}
+ */
----------------
What are the {{ }} for here? Is this some oddity of -strict-whitespace?

================
Comment at: lib/Lex/Lexer.cpp:2661-2666
@@ -2649,8 +2660,8 @@
       << makeCharRange(*this, BufferPtr, CurPtr);
 
-    Result.setFlag(Token::LeadingSpace);
     if (SkipWhitespace(Result, CurPtr))
       return; // KeepWhitespaceMode
 
+    Result.setFlag(Token::LeadingSpace);
     return LexTokenInternal(Result);
   }
----------------
If the sequence of whitespace ends in a newline, we would previously not set the LeadingSpace flag, now we always set it. Is that what we want? (Likewise for all the similar changes below.)

================
Comment at: lib/Lex/Lexer.cpp:2813-2814
@@ -2797,3 +2812,4 @@
     Result.setFlag(Token::StartOfLine);
     // No leading whitespace seen so far.
     Result.clearFlag(Token::LeadingSpace);
+      
----------------
This is no longer correct.

================
Comment at: lib/Lex/Lexer.cpp:1879-1882
@@ -1877,4 +1878,6 @@
   if (isKeepWhitespaceMode()) {
     FormTokenWithChars(Result, CurPtr, tok::unknown);
+    if (SawNewline)
+      IsAtStartOfLine = true;
     return true;
   }
----------------
Could we handle all the changes to this function by just setting IsAtStartOfLine to Result.hasFlag(Token::StartOfLine) and clearing the Token::StartOfLine flag here?

I'm also not sure whether the current approach does the right thing if (for instance) a file starts with <space>#define <...>. Will we set the StartOfLine flag for the '#' token?


http://llvm-reviews.chandlerc.com/D399



More information about the cfe-commits mailing list