[cfe-commits] r126220 - in /cfe/trunk: include/clang/Lex/TokenLexer.h lib/Lex/PPDirectives.cpp lib/Lex/Pragma.cpp lib/Lex/TokenLexer.cpp

Peter Collingbourne peter at pcc.me.uk
Tue Feb 22 05:49:00 PST 2011


Author: pcc
Date: Tue Feb 22 07:49:00 2011
New Revision: 126220

URL: http://llvm.org/viewvc/llvm-project?rev=126220&view=rev
Log:
Make TokenLexer capable of storing preprocessor directive tokens

Modified:
    cfe/trunk/include/clang/Lex/TokenLexer.h
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/Pragma.cpp
    cfe/trunk/lib/Lex/TokenLexer.cpp

Modified: cfe/trunk/include/clang/Lex/TokenLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/TokenLexer.h?rev=126220&r1=126219&r2=126220&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/TokenLexer.h (original)
+++ cfe/trunk/include/clang/Lex/TokenLexer.h Tue Feb 22 07:49:00 2011
@@ -121,6 +121,10 @@
   /// Lex - Lex and return a token from this macro stream.
   void Lex(Token &Tok);
 
+  /// isParsingPreprocessorDirective - Return true if we are in the middle of a
+  /// preprocessor directive.
+  bool isParsingPreprocessorDirective() const;
+
 private:
   void destroy();
 

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=126220&r1=126219&r2=126220&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Feb 22 07:49:00 2011
@@ -167,10 +167,12 @@
 
   if (Tmp.isNot(tok::eom)) {
     // Add a fixit in GNU/C99/C++ mode.  Don't offer a fixit for strict-C89,
-    // because it is more trouble than it is worth to insert /**/ and check that
-    // there is no /**/ in the range also.
+    // or if this is a macro-style preprocessing directive, because it is more
+    // trouble than it is worth to insert /**/ and check that there is no /**/
+    // in the range also.
     FixItHint Hint;
-    if (Features.GNUMode || Features.C99 || Features.CPlusPlus)
+    if ((Features.GNUMode || Features.C99 || Features.CPlusPlus) &&
+        !CurTokenLexer)
       Hint = FixItHint::CreateInsertion(Tmp.getLocation(),"//");
     Diag(Tmp, diag::ext_pp_extra_tokens_at_eol) << DirType << Hint;
     DiscardUntilEndOfDirective();

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=126220&r1=126219&r2=126220&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Tue Feb 22 07:49:00 2011
@@ -110,7 +110,8 @@
   PragmaHandlers->HandlePragma(*this, PragmaIntroducerKind(Introducer), Tok);
 
   // If the pragma handler didn't read the rest of the line, consume it now.
-  if (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective)
+  if ((CurTokenLexer && CurTokenLexer->isParsingPreprocessorDirective()) 
+   || (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective))
     DiscardUntilEndOfDirective();
 }
 

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=126220&r1=126219&r2=126220&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Tue Feb 22 07:49:00 2011
@@ -543,6 +543,11 @@
   return Tokens[CurToken].is(tok::l_paren);
 }
 
+/// isParsingPreprocessorDirective - Return true if we are in the middle of a
+/// preprocessor directive.
+bool TokenLexer::isParsingPreprocessorDirective() const {
+  return Tokens[NumTokens-1].is(tok::eom) && !isAtEnd();
+}
 
 /// HandleMicrosoftCommentPaste - In microsoft compatibility mode, /##/ pastes
 /// together to form a comment that comments out everything in the current





More information about the cfe-commits mailing list