[cfe-commits] r38736 - in /cfe/cfe/trunk: Lex/Lexer.cpp Lex/Preprocessor.cpp test/Preprocessor/macro_paste_bcpl_comment.c

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:24:13 PDT 2007


Author: sabre
Date: Wed Jul 11 11:24:13 2007
New Revision: 38736

URL: http://llvm.org/viewvc/llvm-project?rev=38736&view=rev
Log:
Move LexingRawMode handling of file EOF out of the preprocessor into the
lexer.  This makes more logical sense and also unbreaks the case when the
lexer hasn't been pushed onto the PP include stack.  This is the case when
pasting identifiers.  This patch implements macro_paste_bcpl_comment.c.

Added:
    cfe/cfe/trunk/test/Preprocessor/macro_paste_bcpl_comment.c   (with props)
Modified:
    cfe/cfe/trunk/Lex/Lexer.cpp
    cfe/cfe/trunk/Lex/Preprocessor.cpp

Modified: cfe/cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Lexer.cpp?rev=38736&r1=38735&r2=38736&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:24:13 2007
@@ -904,23 +904,32 @@
     return true;  // Have a token.
   }        
 
-  // If we aren't in raw mode, issue diagnostics. If we are in raw mode, let the
-  // code that put us into raw mode do this: there are multiple possible reasons
-  // for raw mode, and not all want these diagnostics.
-  if (!LexingRawMode) {
-    // If we are in a #if directive, emit an error.
-    while (!ConditionalStack.empty()) {
-      PP.Diag(ConditionalStack.back().IfLoc,
-              diag::err_pp_unterminated_conditional);
-      ConditionalStack.pop_back();
-    }  
-  
-    // If the file was empty or didn't end in a newline, issue a pedwarn.
-    if (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')
-      Diag(BufferEnd, diag::ext_no_newline_eof);
+  // If we are in raw mode, return this event as an EOF token.  Let the caller
+  // that put us in raw mode handle the event.
+  if (LexingRawMode) {
+    Result.StartToken();
+    BufferPtr = BufferEnd;
+    FormTokenWithChars(Result, BufferEnd);
+    Result.SetKind(tok::eof);
+    return true;
   }
   
+  // Otherwise, issue diagnostics for unterminated #if and missing newline.
+
+  // If we are in a #if directive, emit an error.
+  while (!ConditionalStack.empty()) {
+    PP.Diag(ConditionalStack.back().IfLoc,
+            diag::err_pp_unterminated_conditional);
+    ConditionalStack.pop_back();
+  }
+  
+  // If the file was empty or didn't end in a newline, issue a pedwarn.
+  if (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')
+    Diag(BufferEnd, diag::ext_no_newline_eof);
+  
   BufferPtr = CurPtr;
+
+  // Finally, let the preprocessor handle this.
   return PP.HandleEndOfFile(Result);
 }
 

Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38736&r1=38735&r2=38736&view=diff

==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:24:13 2007
@@ -1009,19 +1009,6 @@
   assert(!CurMacroExpander &&
          "Ending a file when currently in a macro!");
   
-  // If we are in a #if 0 block skipping tokens, and we see the end of the file,
-  // this is an error condition.  Just return the EOF token up to
-  // SkipExcludedConditionalBlock.  The code that enabled skipping will issue
-  // errors for the unterminated #if's on the conditional stack if it is
-  // interested.
-  if (isSkipping()) {
-    Result.StartToken();
-    CurLexer->BufferPtr = CurLexer->BufferEnd;
-    CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd);
-    Result.SetKind(tok::eof);
-    return true;
-  }
-  
   // See if this file had a controlling macro.
   if (CurLexer) {  // Not ending a macro, ignore it.
     if (const IdentifierInfo *ControllingMacro = 

Added: cfe/cfe/trunk/test/Preprocessor/macro_paste_bcpl_comment.c
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/macro_paste_bcpl_comment.c?rev=38736&view=auto

==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/macro_paste_bcpl_comment.c (added)
+++ cfe/cfe/trunk/test/Preprocessor/macro_paste_bcpl_comment.c Wed Jul 11 11:24:13 2007
@@ -0,0 +1,5 @@
+// RUN: clang %s -Eonly 2>&1 | grep error
+
+#define COMM1 / ## /
+COMM1
+

Propchange: cfe/cfe/trunk/test/Preprocessor/macro_paste_bcpl_comment.c

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/test/Preprocessor/macro_paste_bcpl_comment.c

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision





More information about the cfe-commits mailing list