]> granicus.if.org Git - clang/commitdiff
Implement a special code-completion pattern for "IBAction". Fixes
authorDouglas Gregor <dgregor@apple.com>
Tue, 15 Feb 2011 22:19:42 +0000 (22:19 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 15 Feb 2011 22:19:42 +0000 (22:19 +0000)
<rdar://problem/8767704>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125604 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Parse/ParseObjc.cpp
lib/Sema/SemaCodeComplete.cpp
test/Index/complete-method-decls.m

index 80b7952ad98324c65fd2c7b2c4da24fdfe741768..e76bd67a3c6dc05f8b96b2899c7fbfd5b6a3af3d 100644 (file)
@@ -4984,7 +4984,8 @@ public:
   void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS);
   void CodeCompleteObjCPropertyGetter(Scope *S, Decl *ClassDecl);
   void CodeCompleteObjCPropertySetter(Scope *S, Decl *ClassDecl);
-  void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS);
+  void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, 
+                                   bool IsParameter);
   void CodeCompleteObjCMessageReceiver(Scope *S);
   void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc,
                                     IdentifierInfo **SelIdents,
index 0aae43adb859e005f1d5de2ed6bfedb2156bedcf..f32a322f024ad7142b8a1350508c7899a0063973 100644 (file)
@@ -723,7 +723,7 @@ bool Parser::isTokIdentifier_in() const {
 void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter) {
   while (1) {
     if (Tok.is(tok::code_completion)) {
-      Actions.CodeCompleteObjCPassingType(getCurScope(), DS);
+      Actions.CodeCompleteObjCPassingType(getCurScope(), DS, IsParameter);
       ConsumeCodeCompletionToken();
     }
     
index e7a9a8d83865d04018bcb041019fcdffd3b7a5ef..1d7cf98264957f372f7b8a472b7046e2c5f01eb3 100644 (file)
@@ -4307,7 +4307,8 @@ void Sema::CodeCompleteObjCPropertySetter(Scope *S, Decl *ObjCImplDecl) {
                             Results.data(),Results.size());
 }
 
-void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS) {
+void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS,
+                                       bool IsParameter) {
   typedef CodeCompletionResult Result;
   ResultBuilder Results(*this, CodeCompleter->getAllocator(),
                         CodeCompletionContext::CCC_Type);
@@ -4335,6 +4336,26 @@ void Sema::CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS) {
      Results.AddResult("oneway");
   }
   
+  // If we're completing the return type of an Objective-C method and the 
+  // identifier IBAction refers to a macro, provide a completion item for
+  // an action, e.g.,
+  //   IBAction)<#selector#>:(id)sender
+  if (DS.getObjCDeclQualifier() == 0 && !IsParameter &&
+      Context.Idents.get("IBAction").hasMacroDefinition()) {
+    typedef CodeCompletionString::Chunk Chunk;
+    CodeCompletionBuilder Builder(Results.getAllocator(), CCP_CodePattern, 
+                                  CXAvailability_Available);
+    Builder.AddTypedTextChunk("IBAction");
+    Builder.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    Builder.AddPlaceholderChunk("selector");
+    Builder.AddChunk(Chunk(CodeCompletionString::CK_Colon));
+    Builder.AddChunk(Chunk(CodeCompletionString::CK_LeftParen));
+    Builder.AddTextChunk("id");
+    Builder.AddChunk(Chunk(CodeCompletionString::CK_RightParen));
+    Builder.AddTextChunk("sender");
+    Results.AddResult(CodeCompletionResult(Builder.TakeString()));
+  }
+  
   // Add various builtin type names and specifiers.
   AddOrdinaryNameResults(PCC_Type, S, *this, Results);
   Results.ExitScope();
index 5e7ba204f9bfffc29338fc7a43dd8adaed6d40ca..92208910e04cce6c2e8484eee793d9f4d99eca5d 100644 (file)
@@ -1,6 +1,6 @@
 /* Note: the RUN lines are near the end of the file, since line/column
    matter for this test. */
-
+#define IBAction void
 @protocol P1
 - (id)abc;
 - (id)initWithInt:(int)x;
 // CHECK-CCH: NotImplemented:{TypedText unsigned} (50)
 // CHECK-CCH: NotImplemented:{TypedText void} (50)
 // CHECK-CCH: NotImplemented:{TypedText volatile} (50)
+
+// IBAction completion
+// RUN: c-index-test -code-completion-at=%s:5:4 %s | FileCheck -check-prefix=CHECK-IBACTION %s
+// CHECK-IBACTION: NotImplemented:{TypedText IBAction}{RightParen )}{Placeholder selector}{Colon :}{LeftParen (}{Text id}{RightParen )}{Text sender} (40)
+