r215043 - Objective-C ARC. More code for Objective-C's
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 6 16:40:31 PDT 2014
Author: fjahanian
Date: Wed Aug 6 18:40:31 2014
New Revision: 215043
URL: http://llvm.org/viewvc/llvm-project?rev=215043&view=rev
Log:
Objective-C ARC. More code for Objective-C's
new APIs for literals. nfc. wip. rdar://17554063
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/CodeGenObjC/Inputs/literal-support.h
cfe/trunk/test/CodeGenObjCXX/Inputs/literal-support.h
cfe/trunk/test/SemaObjC/arc.m
cfe/trunk/test/SemaObjC/objc-literal-comparison.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=215043&r1=215042&r2=215043&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Aug 6 18:40:31 2014
@@ -2007,6 +2007,8 @@ def err_undeclared_nsarray : Error<
def err_undeclared_nsdictionary : Error<
"NSDictionary must be available to use Objective-C dictionary "
"literals">;
+def err_undeclared_alloc : Error<
+ "alloc must be available to use Objective-C literals">;
def err_undeclared_boxing_method : Error<
"declaration of %0 is missing in %1 class">;
def err_objc_literal_method_sig : Error<
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=215043&r1=215042&r2=215043&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Aug 6 18:40:31 2014
@@ -685,8 +685,8 @@ public:
/// \brief The declaration of the initWithObjects:forKeys:count: method.
ObjCMethodDecl *InitDictionaryWithObjectsMethod;
- /// \brief The declaration for + (id) alloc method.
- ObjCMethodDecl *AllocObjectsMethod;
+ /// \brief The declaration for + (id) alloc method used in [NSDictionary alloc]
+ ObjCMethodDecl *DictAllocObjectsMethod;
/// \brief id<NSCopying> type.
QualType QIDNSCopying;
Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=215043&r1=215042&r2=215043&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Wed Aug 6 18:40:31 2014
@@ -98,7 +98,7 @@ Sema::Sema(Preprocessor &pp, ASTContext
InitArrayWithObjectsMethod(nullptr),
NSDictionaryDecl(nullptr), DictionaryWithObjectsMethod(nullptr),
InitDictionaryWithObjectsMethod(nullptr),
- AllocObjectsMethod(nullptr),
+ DictAllocObjectsMethod(nullptr),
GlobalNewDeleteDeclared(false),
TUKind(TUKind),
NumSFINAEErrors(0),
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=215043&r1=215042&r2=215043&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Aug 6 18:40:31 2014
@@ -746,6 +746,7 @@ ExprResult Sema::BuildObjCArrayLiteral(S
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,
@@ -765,9 +766,34 @@ ExprResult Sema::BuildObjCDictionaryLite
}
}
+ QualType IdT = Context.getObjCIdType();
+ if (Arc && !DictAllocObjectsMethod) {
+ // Find +[NSDictionary alloc] method.
+ IdentifierInfo *II = &Context.Idents.get("alloc");
+ Selector AllocSel = Context.Selectors.getSelector(0, &II);
+ DictAllocObjectsMethod = NSDictionaryDecl->lookupClassMethod(AllocSel);
+ if (!DictAllocObjectsMethod && getLangOpts().DebuggerObjCLiteral) {
+ DictAllocObjectsMethod = 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;
+ DictAllocObjectsMethod->setMethodParams(Context, Params, None);
+ }
+ if (!DictAllocObjectsMethod) {
+ Diag(SR.getBegin(), diag::err_undeclared_alloc);
+ return ExprError();
+ }
+ }
+
// Find the dictionaryWithObjects:forKeys:count: method, if we haven't done
// so already.
- QualType IdT = Context.getObjCIdType();
if (!DictionaryWithObjectsMethod) {
Selector Sel = NSAPIObj->getNSDictionarySelector(
NSAPI::NSDict_dictionaryWithObjectsForKeysCount);
@@ -925,7 +951,7 @@ ExprResult Sema::BuildObjCDictionaryLite
Context.getObjCInterfaceType(NSDictionaryDecl));
return MaybeBindToTemporary(ObjCDictionaryLiteral::Create(
Context, makeArrayRef(Elements, NumElements), HasPackExpansions, Ty,
- DictionaryWithObjectsMethod, nullptr, SR));
+ DictionaryWithObjectsMethod, DictAllocObjectsMethod, SR));
}
ExprResult Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
Modified: cfe/trunk/test/CodeGenObjC/Inputs/literal-support.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/Inputs/literal-support.h?rev=215043&r1=215042&r2=215043&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/Inputs/literal-support.h (original)
+++ cfe/trunk/test/CodeGenObjC/Inputs/literal-support.h Wed Aug 6 18:40:31 2014
@@ -3,6 +3,10 @@
typedef unsigned char BOOL;
+ at interface NSObject
++ (id)alloc;
+ at end
+
@interface NSNumber @end
@interface NSNumber (NSNumberCreation)
@@ -21,14 +25,14 @@ typedef unsigned char BOOL;
+ (NSNumber *)numberWithBool:(BOOL)value;
@end
- at interface NSArray
+ at interface NSArray : NSObject
@end
@interface NSArray (NSArrayCreation)
+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
@end
- at interface NSDictionary
+ at interface NSDictionary : NSObject
+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
@end
Modified: cfe/trunk/test/CodeGenObjCXX/Inputs/literal-support.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/Inputs/literal-support.h?rev=215043&r1=215042&r2=215043&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/Inputs/literal-support.h (original)
+++ cfe/trunk/test/CodeGenObjCXX/Inputs/literal-support.h Wed Aug 6 18:40:31 2014
@@ -3,6 +3,10 @@
typedef unsigned char BOOL;
+ at interface NSObject
++ (id)alloc;
+ at end
+
@interface NSNumber @end
@interface NSNumber (NSNumberCreation)
@@ -21,14 +25,14 @@ typedef unsigned char BOOL;
+ (NSNumber *)numberWithBool:(BOOL)value;
@end
- at interface NSArray
+ at interface NSArray : NSObject
@end
@interface NSArray (NSArrayCreation)
+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
@end
- at interface NSDictionary
+ at interface NSDictionary : NSObject
+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
@end
Modified: cfe/trunk/test/SemaObjC/arc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc.m?rev=215043&r1=215042&r2=215043&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc.m (original)
+++ cfe/trunk/test/SemaObjC/arc.m Wed Aug 6 18:40:31 2014
@@ -5,7 +5,11 @@ typedef const void * CFTypeRef;
CFTypeRef CFBridgingRetain(id X);
id CFBridgingRelease(CFTypeRef);
@protocol NSCopying @end
- at interface NSDictionary
+ at interface NSObject
++ (id)alloc;
+ at end
+
+ at interface NSDictionary : NSObject
+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
- (void)setObject:(id)object forKeyedSubscript:(id)key;
@end
Modified: cfe/trunk/test/SemaObjC/objc-literal-comparison.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-literal-comparison.m?rev=215043&r1=215042&r2=215043&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-literal-comparison.m (original)
+++ cfe/trunk/test/SemaObjC/objc-literal-comparison.m Wed Aug 6 18:40:31 2014
@@ -16,6 +16,7 @@ typedef signed char BOOL;
@interface NSObject : BaseObject
- (BOOL)isEqual:(id)other;
++ (id)alloc;
@end
@interface NSNumber : NSObject
More information about the cfe-commits
mailing list