diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-08-20 20:01:13 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-08-20 20:01:13 +0000 |
commit | d7403a70176a50b8f71cb4e2e18ac6ed49fe357e (patch) | |
tree | ce70ba7459eb0980122636d1ac6cc8f70477699b | |
parent | 1833d284346b9fa11aae4e6aa07381347c04745c (diff) |
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>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162220 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 24 | ||||
-rw-r--r-- | test/Index/complete-property-flags.m | 20 |
2 files changed, 33 insertions, 11 deletions
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index adf1327157..eb03d253a5 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -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()); diff --git a/test/Index/complete-property-flags.m b/test/Index/complete-property-flags.m index f2e08c3660..3c5b0e231c 100644 --- a/test/Index/complete-property-flags.m +++ b/test/Index/complete-property-flags.m @@ -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 |