diff options
Diffstat (limited to 'clang/lib/Sema/SemaExprObjC.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 75 |
1 files changed, 12 insertions, 63 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 40ab95b6ec5..ae9942b1c3e 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -597,31 +597,6 @@ ExprResult Sema::BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { return MaybeBindToTemporary(BoxedExpr); } -static ObjCMethodDecl *FindAllocMethod(Sema &S, ObjCInterfaceDecl *NSClass) { - ObjCMethodDecl *Method = nullptr; - ASTContext &Context = S.Context; - - // Find +[NSClass alloc] method. - IdentifierInfo *II = &Context.Idents.get("alloc"); - Selector AllocSel = Context.Selectors.getSelector(0, &II); - Method = NSClass->lookupClassMethod(AllocSel); - if (!Method && S.getLangOpts().DebuggerObjCLiteral) { - Method = ObjCMethodDecl::Create(Context, - SourceLocation(), SourceLocation(), AllocSel, - Context.getObjCIdType(), - nullptr /*TypeSourceInfo */, - Context.getTranslationUnitDecl(), - false /*Instance*/, false/*isVariadic*/, - /*isPropertyAccessor=*/false, - /*isImplicitlyDeclared=*/true, /*isDefined=*/false, - ObjCMethodDecl::Required, - false); - SmallVector<ParmVarDecl *, 1> Params; - Method->setMethodParams(Context, Params, None); - } - return Method; -} - /// Build an ObjC subscript pseudo-object expression, given that /// that's supported by the runtime. ExprResult Sema::BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, @@ -655,7 +630,6 @@ 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, @@ -675,29 +649,18 @@ ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) { return ExprError(); } } - if (Arc && !ArrayAllocObjectsMethod) { - // Find +[NSArray alloc] method. - ArrayAllocObjectsMethod = FindAllocMethod(*this, NSArrayDecl); - if (!ArrayAllocObjectsMethod) { - Diag(SR.getBegin(), diag::err_undeclared_alloc); - return ExprError(); - } - } + // Find the arrayWithObjects:count: method, if we haven't done so already. QualType IdT = Context.getObjCIdType(); if (!ArrayWithObjectsMethod) { Selector - Sel = NSAPIObj->getNSArraySelector( - Arc? NSAPI::NSArr_initWithObjectsCount : NSAPI::NSArr_arrayWithObjectsCount); - ObjCMethodDecl *Method = - Arc? NSArrayDecl->lookupInstanceMethod(Sel) - : NSArrayDecl->lookupClassMethod(Sel); + Sel = NSAPIObj->getNSArraySelector(NSAPI::NSArr_arrayWithObjectsCount); + ObjCMethodDecl *Method = NSArrayDecl->lookupClassMethod(Sel); if (!Method && getLangOpts().DebuggerObjCLiteral) { TypeSourceInfo *ReturnTInfo = nullptr; Method = ObjCMethodDecl::Create( Context, SourceLocation(), SourceLocation(), Sel, IdT, ReturnTInfo, - Context.getTranslationUnitDecl(), - Arc /*Instance for Arc, Class for MRR*/, + Context.getTranslationUnitDecl(), false /*Instance*/, false /*isVariadic*/, /*isPropertyAccessor=*/false, /*isImplicitlyDeclared=*/true, /*isDefined=*/false, @@ -777,14 +740,12 @@ ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) { return MaybeBindToTemporary( ObjCArrayLiteral::Create(Context, Elements, Ty, - ArrayWithObjectsMethod, - ArrayAllocObjectsMethod, SR)); + ArrayWithObjectsMethod, SR)); } ExprResult Sema::BuildObjCDictionaryLiteral(SourceRange SR, ObjCDictionaryElement *Elements, unsigned NumElements) { - bool Arc = getLangOpts().ObjCAutoRefCount; // Look up the NSDictionary class, if we haven't done so already. if (!NSDictionaryDecl) { NamedDecl *IF = LookupSingleName(TUScope, @@ -804,32 +765,20 @@ ExprResult Sema::BuildObjCDictionaryLiteral(SourceRange SR, } } - if (Arc && !DictAllocObjectsMethod) { - // Find +[NSDictionary alloc] method. - DictAllocObjectsMethod = FindAllocMethod(*this, NSDictionaryDecl); - if (!DictAllocObjectsMethod) { - Diag(SR.getBegin(), diag::err_undeclared_alloc); - return ExprError(); - } - } - - // Find the dictionaryWithObjects:forKeys:count: or initWithObjects:forKeys:count: - // (for arc) method, if we haven't done so already. + // Find the dictionaryWithObjects:forKeys:count: method, if we haven't done + // so already. QualType IdT = Context.getObjCIdType(); if (!DictionaryWithObjectsMethod) { - Selector Sel = - NSAPIObj->getNSDictionarySelector(Arc? NSAPI::NSDict_initWithObjectsForKeysCount - : NSAPI::NSDict_dictionaryWithObjectsForKeysCount); - ObjCMethodDecl *Method = - Arc ? NSDictionaryDecl->lookupInstanceMethod(Sel) - : NSDictionaryDecl->lookupClassMethod(Sel); + Selector Sel = NSAPIObj->getNSDictionarySelector( + NSAPI::NSDict_dictionaryWithObjectsForKeysCount); + ObjCMethodDecl *Method = NSDictionaryDecl->lookupClassMethod(Sel); if (!Method && getLangOpts().DebuggerObjCLiteral) { Method = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(), Sel, IdT, nullptr /*TypeSourceInfo */, Context.getTranslationUnitDecl(), - Arc /*Instance for Arc, Class for MRR*/, false/*isVariadic*/, + false /*Instance*/, false/*isVariadic*/, /*isPropertyAccessor=*/false, /*isImplicitlyDeclared=*/true, /*isDefined=*/false, ObjCMethodDecl::Required, @@ -976,7 +925,7 @@ ExprResult Sema::BuildObjCDictionaryLiteral(SourceRange SR, Context.getObjCInterfaceType(NSDictionaryDecl)); return MaybeBindToTemporary(ObjCDictionaryLiteral::Create( Context, makeArrayRef(Elements, NumElements), HasPackExpansions, Ty, - DictionaryWithObjectsMethod, DictAllocObjectsMethod, SR)); + DictionaryWithObjectsMethod, SR)); } ExprResult Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, |