[cfe-commits] r57395 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def include/clang/Lex/Lexer.h lib/Lex/Lexer.cpp lib/Lex/TokenLexer.cpp

Chris Lattner sabre at nondot.org
Sat Oct 11 18:31:52 PDT 2008


Author: lattner
Date: Sat Oct 11 20:31:51 2008
New Revision: 57395

URL: http://llvm.org/viewvc/llvm-project?rev=57395&view=rev
Log:
Simplify raw mode lexing by treating an unterminate /**/ comment the
same we we do an unterminated string or character literal.  This makes
it so we can guarantee that the lexer never calls into the 
preprocessor (which would be suicide for a raw lexer).

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/include/clang/Lex/Lexer.h
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/lib/Lex/TokenLexer.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=57395&r1=57394&r2=57395&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sat Oct 11 20:31:51 2008
@@ -32,7 +32,7 @@
      "null character(s) preserved in character literal")
 DIAG(null_in_file  , WARNING,
      "null character ignored")
-DIAG(nested_block_comment, WARNING,
+DIAG(warn_nested_block_comment, WARNING,
      "\"/*\" within block comment")
 DIAG(escaped_newline_block_comment_end, WARNING,
      "escaped newline between */ characters at block comment end")

Modified: cfe/trunk/include/clang/Lex/Lexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Lexer.h?rev=57395&r1=57394&r2=57395&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Sat Oct 11 20:31:51 2008
@@ -60,9 +60,8 @@
   ///     effect of this, implicit macro expansion is naturally disabled.
   ///  3. "#" tokens at the start of a line are treated as normal tokens, not
   ///     implicitly transformed by the lexer.
-  ///  4. All diagnostic messages are disabled, except for unterminated /*.
-  ///  5. The only callback made into the preprocessor is to report a hard error
-  ///     on an unterminated '/*' comment.
+  ///  4. All diagnostic messages are disabled.
+  ///  5. No callbacks are made into the preprocessor.
   ///
   /// Note that in raw mode that the PP pointer may be null.
   bool LexingRawMode;

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

==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Sat Oct 11 20:31:51 2008
@@ -931,7 +931,8 @@
   unsigned char C = getCharAndSize(CurPtr, CharSize);
   CurPtr += CharSize;
   if (C == 0 && CurPtr == BufferEnd+1) {
-    Diag(BufferPtr, diag::err_unterminated_block_comment);
+    if (!LexingRawMode)
+      Diag(BufferPtr, diag::err_unterminated_block_comment);
     BufferPtr = CurPtr-1;
     return true;
   }
@@ -1000,10 +1001,10 @@
         // If this is a /* inside of the comment, emit a warning.  Don't do this
         // if this is a /*/, which will end the comment.  This misses cases with
         // embedded escaped newlines, but oh well.
-        Diag(CurPtr-1, diag::nested_block_comment);
+        Diag(CurPtr-1, diag::warn_nested_block_comment);
       }
     } else if (C == 0 && CurPtr == BufferEnd+1) {
-      Diag(BufferPtr, diag::err_unterminated_block_comment);
+      if (!LexingRawMode) Diag(BufferPtr, diag::err_unterminated_block_comment);
       // Note: the user probably forgot a */.  We could continue immediately
       // after the /*, but this would involve lexing a lot of what really is the
       // comment, which surely would confuse the parser.

Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=57395&r1=57394&r2=57395&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Sat Oct 11 20:31:51 2008
@@ -377,11 +377,7 @@
     // Lex the resultant pasted token into Result.
     Token Result;
     
-    // Avoid testing /*, as the lexer would think it is the start of a comment
-    // and emit an error that it is unterminated.
-    if (Tok.is(tok::slash) && RHS.is(tok::star)) {
-      isInvalid = true;
-    } else if (Tok.is(tok::identifier) && RHS.is(tok::identifier)) {
+    if (Tok.is(tok::identifier) && RHS.is(tok::identifier)) {
       // Common paste case: identifier+identifier = identifier.  Avoid creating
       // a lexer and other overhead.
       PP.IncrementPasteCounter(true);





More information about the cfe-commits mailing list