Author: jrose
Date: Mon Aug 20 15:01:13 2012
New Revision: 162220

URL: http://llvm.org/viewvc/llvm-project?rev=162220&view=rev
Log:
Code-complete 'weak' for properties under ARC-with-weak-references (or GC)

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>

Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/Index/complete-property-flags.m

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=162220&r1=162219&r2=162220&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Aug 20 15:01:13 2012
@@ -4595,26 +4595,23 @@
   
   // 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 @@
     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());

Modified: cfe/trunk/test/Index/complete-property-flags.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-property-flags.m?rev=162220&r1=162219&r2=162220&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-property-flags.m (original)
+++ cfe/trunk/test/Index/complete-property-flags.m Mon Aug 20 15:01:13 2012
@@ -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}
@@ -18,9 +19,26 @@
 // 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


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to