]> granicus.if.org Git - clang/commitdiff
Code-complete 'weak' for properties under ARC-with-weak-references (or GC)
authorJordan Rose <jordan_rose@apple.com>
Mon, 20 Aug 2012 20:01:13 +0000 (20:01 +0000)
committerJordan Rose <jordan_rose@apple.com>
Mon, 20 Aug 2012 20:01:13 +0000 (20:01 +0000)
Also, suggest 'readonly' even if the property has been given an ownership
attribute ('strong', 'weak', etc). This is used when properties are declared
readonly in the public interface but readwrite in a class extension.

<rdar://problem/11500004&11932285>

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

lib/Sema/SemaCodeComplete.cpp
test/Index/complete-property-flags.m

index adf132715738a8c2966b9dac43e2157ee6eadf69..eb03d253a51cbc210d4bd683b7486e622828b239 100644 (file)
@@ -4595,26 +4595,23 @@ static bool ObjCPropertyFlagConflicts(unsigned Attributes, unsigned NewFlag) {
   
   // Check for collisions with "readonly".
   if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
-      (Attributes & (ObjCDeclSpec::DQ_PR_readwrite |
-                     ObjCDeclSpec::DQ_PR_assign |
-                     ObjCDeclSpec::DQ_PR_unsafe_unretained |
-                     ObjCDeclSpec::DQ_PR_copy |
-                     ObjCDeclSpec::DQ_PR_retain |
-                     ObjCDeclSpec::DQ_PR_strong)))
+      (Attributes & ObjCDeclSpec::DQ_PR_readwrite))
     return true;
   
-  // Check for more than one of { assign, copy, retain, strong }.
+  // Check for more than one of { assign, copy, retain, strong, weak }.
   unsigned AssignCopyRetMask = Attributes & (ObjCDeclSpec::DQ_PR_assign |
                                          ObjCDeclSpec::DQ_PR_unsafe_unretained |
                                              ObjCDeclSpec::DQ_PR_copy |
-                                             ObjCDeclSpec::DQ_PR_retain|
-                                             ObjCDeclSpec::DQ_PR_strong);
+                                             ObjCDeclSpec::DQ_PR_retain |
+                                             ObjCDeclSpec::DQ_PR_strong |
+                                             ObjCDeclSpec::DQ_PR_weak);
   if (AssignCopyRetMask &&
       AssignCopyRetMask != ObjCDeclSpec::DQ_PR_assign &&
       AssignCopyRetMask != ObjCDeclSpec::DQ_PR_unsafe_unretained &&
       AssignCopyRetMask != ObjCDeclSpec::DQ_PR_copy &&
       AssignCopyRetMask != ObjCDeclSpec::DQ_PR_retain &&
-      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_strong)
+      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_strong &&
+      AssignCopyRetMask != ObjCDeclSpec::DQ_PR_weak)
     return true;
   
   return false;
@@ -4650,6 +4647,13 @@ void Sema::CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS) {
     Results.AddResult(CodeCompletionResult("nonatomic"));
   if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_atomic))
     Results.AddResult(CodeCompletionResult("atomic"));
+
+  // Only suggest "weak" if we're compiling for ARC-with-weak-references or GC.
+  if ((getLangOpts().ObjCAutoRefCount && getLangOpts().ObjCRuntimeHasWeak) ||
+      getLangOpts().getGC() != LangOptions::NonGC)
+    if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_weak))
+      Results.AddResult(CodeCompletionResult("weak"));
+
   if (!ObjCPropertyFlagConflicts(Attributes, ObjCDeclSpec::DQ_PR_setter)) {
     CodeCompletionBuilder Setter(Results.getAllocator(),
                                  Results.getCodeCompletionTUInfo());
index f2e08c36607c5658b63742d3b6770f2a16e4ad3a..3c5b0e231c3bf2355ddb8b45ed905b323569f94a 100644 (file)
@@ -6,7 +6,8 @@
 }
 @property(copy) Foo *myprop;
 @property(retain, nonatomic) id xx;
-// RUN: c-index-test -code-completion-at=%s:7:11 %s | FileCheck -check-prefix=CHECK-CC1 %s
+
+// RUN: c-index-test -code-completion-at=%s:7:11 %s -fno-objc-arc | FileCheck -check-prefix=CHECK-CC1 %s
 // CHECK-CC1: {TypedText assign}
 // CHECK-CC1-NEXT: {TypedText atomic}
 // CHECK-CC1-NEXT: {TypedText copy}
 // CHECK-CC1-NEXT: {TypedText setter}{Text  = }{Placeholder method}
 // CHECK-CC1-NEXT: {TypedText strong}
 // CHECK-CC1-NEXT: {TypedText unsafe_unretained}
+// CHECK-CC1-NOT: {TypedText weak}
+
+// RUN: c-index-test -code-completion-at=%s:7:11 %s -fobjc-arc -fobjc-runtime-has-weak | FileCheck -check-prefix=CHECK-CC1-ARC %s
+// CHECK-CC1-ARC: {TypedText assign}
+// CHECK-CC1-ARC-NEXT: {TypedText atomic}
+// CHECK-CC1-ARC-NEXT: {TypedText copy}
+// CHECK-CC1-ARC-NEXT: {TypedText getter}{Text  = }{Placeholder method}
+// CHECK-CC1-ARC-NEXT: {TypedText nonatomic}
+// CHECK-CC1-ARC-NEXT: {TypedText readonly}
+// CHECK-CC1-ARC-NEXT: {TypedText readwrite}
+// CHECK-CC1-ARC-NEXT: {TypedText retain}
+// CHECK-CC1-ARC-NEXT: {TypedText setter}{Text  = }{Placeholder method}
+// CHECK-CC1-ARC-NEXT: {TypedText strong}
+// CHECK-CC1-ARC-NEXT: {TypedText unsafe_unretained}
+// CHECK-CC1-ARC-NEXT: {TypedText weak}
+
 // RUN: c-index-test -code-completion-at=%s:8:18 %s | FileCheck -check-prefix=CHECK-CC2 %s
 // CHECK-CC2: {TypedText getter}{Text  = }{Placeholder method}
 // CHECK-CC2-NEXT: {TypedText nonatomic}
+// CHECK-CC2-NEXT: {TypedText readonly}
 // CHECK-CC2-NEXT: {TypedText readwrite}
 // CHECK-CC2-NEXT: {TypedText setter}{Text  = }{Placeholder method}
 @end