summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaExprObjC.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2014-08-08 17:31:14 +0000
committerFariborz Jahanian <fjahanian@apple.com>2014-08-08 17:31:14 +0000
commit422dd7b9f75e21132e832cbe4c65ca25bd90610f (patch)
tree5a4248726e9d0fabb5386d8ecd3bb5d4137bf380 /lib/Sema/SemaExprObjC.cpp
parent22efa1bf39c566e0a5073e392664b523379b63c3 (diff)
Objective-C ARC. Use of non-retain/autorelease API
for building Objective-C array literals in ARC mode. rdar://17554063 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215232 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprObjC.cpp')
-rw-r--r--lib/Sema/SemaExprObjC.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index e4625bc98c..786637c205 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -630,6 +630,7 @@ ExprResult Sema::BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr,
}
ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) {
+ bool Arc = getLangOpts().ObjCAutoRefCount;
// Look up the NSArray class, if we haven't done so already.
if (!NSArrayDecl) {
NamedDecl *IF = LookupSingleName(TUScope,
@@ -649,18 +650,45 @@ ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) {
return ExprError();
}
}
-
- // Find the arrayWithObjects:count: method, if we haven't done so already.
QualType IdT = Context.getObjCIdType();
+ if (Arc && !ArrayAllocObjectsMethod) {
+ // Find +[NSArray alloc] method.
+ IdentifierInfo *II = &Context.Idents.get("alloc");
+ Selector AllocSel = Context.Selectors.getSelector(0, &II);
+ ArrayAllocObjectsMethod = NSArrayDecl->lookupClassMethod(AllocSel);
+ if (!ArrayAllocObjectsMethod && getLangOpts().DebuggerObjCLiteral) {
+ ArrayAllocObjectsMethod = ObjCMethodDecl::Create(Context,
+ SourceLocation(), SourceLocation(), AllocSel,
+ IdT,
+ nullptr /*TypeSourceInfo */,
+ Context.getTranslationUnitDecl(),
+ false /*Instance*/, false/*isVariadic*/,
+ /*isPropertyAccessor=*/false,
+ /*isImplicitlyDeclared=*/true, /*isDefined=*/false,
+ ObjCMethodDecl::Required,
+ false);
+ SmallVector<ParmVarDecl *, 1> Params;
+ ArrayAllocObjectsMethod->setMethodParams(Context, Params, None);
+ }
+ if (!ArrayAllocObjectsMethod) {
+ Diag(SR.getBegin(), diag::err_undeclared_alloc);
+ return ExprError();
+ }
+ }
+ // Find the arrayWithObjects:count: method, if we haven't done so already.
if (!ArrayWithObjectsMethod) {
Selector
- Sel = NSAPIObj->getNSArraySelector(NSAPI::NSArr_arrayWithObjectsCount);
- ObjCMethodDecl *Method = NSArrayDecl->lookupClassMethod(Sel);
+ Sel = NSAPIObj->getNSArraySelector(
+ Arc? NSAPI::NSArr_initWithObjectsCount : NSAPI::NSArr_arrayWithObjectsCount);
+ ObjCMethodDecl *Method =
+ Arc? NSArrayDecl->lookupInstanceMethod(Sel)
+ : NSArrayDecl->lookupClassMethod(Sel);
if (!Method && getLangOpts().DebuggerObjCLiteral) {
TypeSourceInfo *ReturnTInfo = nullptr;
Method = ObjCMethodDecl::Create(
Context, SourceLocation(), SourceLocation(), Sel, IdT, ReturnTInfo,
- Context.getTranslationUnitDecl(), false /*Instance*/,
+ Context.getTranslationUnitDecl(),
+ Arc /*Instance for Arc, Class for MRR*/,
false /*isVariadic*/,
/*isPropertyAccessor=*/false,
/*isImplicitlyDeclared=*/true, /*isDefined=*/false,
@@ -740,7 +768,8 @@ ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) {
return MaybeBindToTemporary(
ObjCArrayLiteral::Create(Context, Elements, Ty,
- ArrayWithObjectsMethod, nullptr, SR));
+ ArrayWithObjectsMethod,
+ ArrayAllocObjectsMethod, SR));
}
ExprResult Sema::BuildObjCDictionaryLiteral(SourceRange SR,