[cfe-commits] r136559 - in /cfe/trunk: include/clang/Sema/CodeCompleteConsumer.h lib/Frontend/ASTUnit.cpp lib/Sema/CodeCompleteConsumer.cpp lib/Sema/SemaCodeComplete.cpp test/Index/complete-interfaces.m tools/libclang/CIndexCodeCompletion.cpp

Douglas Gregor dgregor at apple.com
Fri Jul 29 23:55:39 PDT 2011


Author: dgregor
Date: Sat Jul 30 01:55:39 2011
New Revision: 136559

URL: http://llvm.org/viewvc/llvm-project?rev=136559&view=rev
Log:
When performing code completion after at @interface, allow both
already-defined and forward-declared results. Already-defined results
are fine because they could be the start of a category. Fixes
<rdar://problem/9811691>.

Modified:
    cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/Index/complete-interfaces.m
    cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=136559&r1=136558&r2=136559&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Sat Jul 30 01:55:39 2011
@@ -248,9 +248,9 @@
     CCC_ObjCInstanceMessage,
     /// \brief Code completion where an Objective-C class message is expected. 
     CCC_ObjCClassMessage,
-    /// \brief Code completion where a superclass of an Objective-C class is
+    /// \brief Code completion where the name of an Objective-C class is
     /// expected.
-    CCC_ObjCSuperclass,
+    CCC_ObjCInterfaceName,
     /// \brief Code completion where an Objective-C category name is expected.
     CCC_ObjCCategoryName,
     /// \brief An unknown context, in which we are recovering from a parsing 

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=136559&r1=136558&r2=136559&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Sat Jul 30 01:55:39 2011
@@ -186,7 +186,7 @@
     
     // In Objective-C, you can only be a subclass of another Objective-C class
     if (isa<ObjCInterfaceDecl>(ND))
-      Contexts |= (1 << (CodeCompletionContext::CCC_ObjCSuperclass - 1));
+      Contexts |= (1 << (CodeCompletionContext::CCC_ObjCInterfaceName - 1));
 
     // Deal with tag names.
     if (isa<EnumDecl>(ND)) {
@@ -1992,7 +1992,7 @@
   case CodeCompletionContext::CCC_Name:
   case CodeCompletionContext::CCC_PotentiallyQualifiedName:
   case CodeCompletionContext::CCC_ParenthesizedExpression:
-  case CodeCompletionContext::CCC_ObjCSuperclass:
+  case CodeCompletionContext::CCC_ObjCInterfaceName:
     break;
     
   case CodeCompletionContext::CCC_EnumTag:

Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=136559&r1=136558&r2=136559&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Sat Jul 30 01:55:39 2011
@@ -67,7 +67,7 @@
   case CCC_OtherWithMacros:
   case CCC_ObjCInstanceMessage:
   case CCC_ObjCClassMessage:
-  case CCC_ObjCSuperclass:
+  case CCC_ObjCInterfaceName:
   case CCC_ObjCCategoryName:
     return false;
   }

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=136559&r1=136558&r2=136559&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Sat Jul 30 01:55:39 2011
@@ -5325,21 +5325,23 @@
                         CodeCompletionContext::CCC_Other);
   Results.EnterNewScope();
   
-  // Add all classes.
-  AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, true,
-                      false, Results);
-
+  if (CodeCompleter->includeGlobals()) {
+    // Add all classes.
+    AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
+                        false, Results);
+  }
+  
   Results.ExitScope();
-  // FIXME: Use cached global completion results.
+
   HandleCodeCompleteResults(this, CodeCompleter,
-                            CodeCompletionContext::CCC_Other,
+                            CodeCompletionContext::CCC_ObjCInterfaceName,
                             Results.data(),Results.size());
 }
 
 void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName,
                                       SourceLocation ClassNameLoc) { 
   ResultBuilder Results(*this, CodeCompleter->getAllocator(),
-                        CodeCompletionContext::CCC_ObjCSuperclass);
+                        CodeCompletionContext::CCC_ObjCInterfaceName);
   Results.EnterNewScope();
   
   // Make sure that we ignore the class we're currently defining.
@@ -5348,14 +5350,16 @@
   if (CurClass && isa<ObjCInterfaceDecl>(CurClass))
     Results.Ignore(CurClass);
 
-  // Add all classes.
-  AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
-                      false, Results);
-
+  if (CodeCompleter->includeGlobals()) {
+    // Add all classes.
+    AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
+                        false, Results);
+  }
+  
   Results.ExitScope();
-  // FIXME: Use cached global completion results.
+
   HandleCodeCompleteResults(this, CodeCompleter, 
-                            CodeCompletionContext::CCC_ObjCSuperclass,
+                            CodeCompletionContext::CCC_ObjCInterfaceName,
                             Results.data(),Results.size());
 }
 
@@ -5364,14 +5368,16 @@
                         CodeCompletionContext::CCC_Other);
   Results.EnterNewScope();
 
-  // Add all unimplemented classes.
-  AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
-                      true, Results);
-
+  if (CodeCompleter->includeGlobals()) {
+    // Add all unimplemented classes.
+    AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
+                        true, Results);
+  }
+  
   Results.ExitScope();
-  // FIXME: Use cached global completion results.
+
   HandleCodeCompleteResults(this, CodeCompleter, 
-                            CodeCompletionContext::CCC_Other,
+                            CodeCompletionContext::CCC_ObjCInterfaceName,
                             Results.data(),Results.size());
 }
 

Modified: cfe/trunk/test/Index/complete-interfaces.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-interfaces.m?rev=136559&r1=136558&r2=136559&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-interfaces.m (original)
+++ cfe/trunk/test/Index/complete-interfaces.m Sat Jul 30 01:55:39 2011
@@ -27,6 +27,7 @@
 // RUN: c-index-test -code-completion-at=%s:11:12 %s | FileCheck -check-prefix=CHECK-CC2 %s
 // CHECK-CC2: ObjCInterfaceDecl:{TypedText Int1}
 // CHECK-CC2-NEXT: ObjCInterfaceDecl:{TypedText Int2}
+// CHECK-CC2-NEXT: ObjCInterfaceDecl:{TypedText Int3}
 // CHECK-CC2-NEXT: ObjCInterfaceDecl:{TypedText Int4}
 // RUN: c-index-test -code-completion-at=%s:11:19 %s | FileCheck -check-prefix=CHECK-CC3 %s
 // CHECK-CC3: ObjCInterfaceDecl:{TypedText Int1}
@@ -41,3 +42,6 @@
 // CHECK-CC5: ObjCInterfaceDecl:{TypedText Int1}
 // CHECK-CC5-NEXT: ObjCInterfaceDecl:{TypedText Int3}
 // CHECK-CC5-NEXT: ObjCInterfaceDecl:{TypedText Int4}
+
+
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:11:12 %s | FileCheck -check-prefix=CHECK-CC2 %s

Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=136559&r1=136558&r2=136559&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Sat Jul 30 01:55:39 2011
@@ -438,7 +438,7 @@
       contexts = CXCompletionContext_ObjCClassMessage;
       break;
     }
-    case CodeCompletionContext::CCC_ObjCSuperclass: {
+    case CodeCompletionContext::CCC_ObjCInterfaceName: {
       contexts = CXCompletionContext_ObjCInterface;
       break;
     }





More information about the cfe-commits mailing list