[cfe-commits] r110933 - in /cfe/trunk: lib/Lex/Lexer.cpp lib/Lex/PPDirectives.cpp lib/Lex/PTHLexer.cpp test/Index/complete-unterminated.c

Douglas Gregor dgregor at apple.com
Thu Aug 12 10:04:55 PDT 2010


Author: dgregor
Date: Thu Aug 12 12:04:55 2010
New Revision: 110933

URL: http://llvm.org/viewvc/llvm-project?rev=110933&view=rev
Log:
Don't emit end-of-file diagnostics like "unterminated conditional" or
"unterminated string" when we're performing code completion.

Added:
    cfe/trunk/test/Index/complete-unterminated.c   (with props)
Modified:
    cfe/trunk/lib/Lex/Lexer.cpp
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PTHLexer.cpp

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=110933&r1=110932&r2=110933&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Thu Aug 12 12:04:55 2010
@@ -962,7 +962,8 @@
     
     if (C == '\n' || C == '\r' ||             // Newline.
         (C == 0 && CurPtr-1 == BufferEnd)) {  // End of file.
-      if (!isLexingRawMode() && !Features.AsmPreprocessor)
+      if (!isLexingRawMode() && !Features.AsmPreprocessor &&
+          !PP->isCodeCompletionFile(FileLoc))
         Diag(BufferPtr, diag::err_unterminated_string);
       FormTokenWithChars(Result, CurPtr-1, tok::unknown);
       return;
@@ -1039,7 +1040,8 @@
       C = getAndAdvanceChar(CurPtr, Result);
     } else if (C == '\n' || C == '\r' ||             // Newline.
                (C == 0 && CurPtr-1 == BufferEnd)) {  // End of file.
-      if (!isLexingRawMode() && !Features.AsmPreprocessor)
+      if (!isLexingRawMode() && !Features.AsmPreprocessor &&
+          !PP->isCodeCompletionFile(FileLoc))
         Diag(BufferPtr, diag::err_unterminated_char);
       FormTokenWithChars(Result, CurPtr-1, tok::unknown);
       return;
@@ -1564,8 +1566,9 @@
   
   // If we are in a #if directive, emit an error.
   while (!ConditionalStack.empty()) {
-    PP->Diag(ConditionalStack.back().IfLoc,
-             diag::err_pp_unterminated_conditional);
+    if (!PP->isCodeCompletionFile(FileLoc))
+      PP->Diag(ConditionalStack.back().IfLoc,
+               diag::err_pp_unterminated_conditional);
     ConditionalStack.pop_back();
   }
 

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=110933&r1=110932&r2=110933&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Thu Aug 12 12:04:55 2010
@@ -171,8 +171,9 @@
       // Emit errors for each unterminated conditional on the stack, including
       // the current one.
       while (!CurPPLexer->ConditionalStack.empty()) {
-        Diag(CurPPLexer->ConditionalStack.back().IfLoc,
-             diag::err_pp_unterminated_conditional);
+        if (!isCodeCompletionFile(Tok.getLocation()))
+          Diag(CurPPLexer->ConditionalStack.back().IfLoc,
+               diag::err_pp_unterminated_conditional);
         CurPPLexer->ConditionalStack.pop_back();
       }
 

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=110933&r1=110932&r2=110933&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Thu Aug 12 12:04:55 2010
@@ -146,8 +146,9 @@
 
   // If we are in a #if directive, emit an error.
   while (!ConditionalStack.empty()) {
-    PP->Diag(ConditionalStack.back().IfLoc,
-             diag::err_pp_unterminated_conditional);
+    if (!PP->isCodeCompletionFile(FileStartLoc))
+      PP->Diag(ConditionalStack.back().IfLoc,
+               diag::err_pp_unterminated_conditional);
     ConditionalStack.pop_back();
   }
 

Added: cfe/trunk/test/Index/complete-unterminated.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-unterminated.c?rev=110933&view=auto
==============================================================================
--- cfe/trunk/test/Index/complete-unterminated.c (added)
+++ cfe/trunk/test/Index/complete-unterminated.c Thu Aug 12 12:04:55 2010
@@ -0,0 +1,30 @@
+typedef int Integer;
+
+#if 0
+
+
+#endif
+
+/* blah */
+
+void f0(const char*);
+void f1(char);
+
+const char *hello = "Hello, world";
+const char a = 'a';
+
+#define FOO(a, b) a b
+
+FOO(int, x);
+
+// RUN: c-index-test -code-completion-at=%s:5:1 -pedantic %s 2> %t.err | FileCheck %s
+// RUN: not grep error %t.err
+// CHECK: {TypedText Integer}
+// RUN: c-index-test -code-completion-at=%s:8:6 -pedantic %s 2> %t.err
+// RUN: not grep error %t.err
+// RUN: c-index-test -code-completion-at=%s:10:28 -pedantic %s 2> %t.err
+// RUN: not grep unterminated %t.err
+// RUN: c-index-test -code-completion-at=%s:11:17 -pedantic %s 2> %t.err
+// RUN: not grep unterminated %t.err
+// RUN: c-index-test -code-completion-at=%s:18:10 -pedantic %s 2> %t.err
+// RUN: not grep unterminated %t.err

Propchange: cfe/trunk/test/Index/complete-unterminated.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Index/complete-unterminated.c
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/Index/complete-unterminated.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list