Add support for Objective-C class properties.

Added test cases to exiting tests to cover the new functionality.

<rdar://problem/24311282> 

llvm-svn: 275459
This commit is contained in:
Greg Clayton 2016-07-14 19:31:18 +00:00
parent ecea07c50e
commit 7853dd5dec
3 changed files with 43 additions and 7 deletions

View File

@ -113,3 +113,17 @@ class ObjCPropertyTestCase(TestBase):
idWithProtocol_error = idWithProtocol_value.GetError()
self.assertTrue (idWithProtocol_error.Success())
self.assertTrue (idWithProtocol_value.GetTypeName() == "id")
# Make sure that class property getter works as expected
value = frame.EvaluateExpression("BaseClass.classInt", False)
self.assertTrue (value.GetError().Success())
self.assertTrue (value.GetValueAsUnsigned (11111) == 123)
# Make sure that class property setter works as expected
value = frame.EvaluateExpression("BaseClass.classInt = 234", False)
self.assertTrue (value.GetError().Success())
# Verify that setter above actually worked
value = frame.EvaluateExpression("BaseClass.classInt", False)
self.assertTrue (value.GetError().Success())
self.assertTrue (value.GetValueAsUnsigned (11111) == 234)

View File

@ -6,6 +6,8 @@
@end
static int _class_int = 123;
@interface BaseClass : NSObject
{
int _backedInt;
@ -25,6 +27,7 @@
@property(getter=myGetUnbackedInt,setter=mySetUnbackedInt:) int unbackedInt;
@property int backedInt;
@property (nonatomic, assign) id <MyProtocol> idWithProtocol;
@property(class) int classInt;
@end
@implementation BaseClass
@ -68,6 +71,16 @@
_access_count++;
}
+ (int) classInt
{
return _class_int;
}
+ (void) setClassInt:(int) n
{
_class_int = n;
}
- (int) getAccessCount
{
return _access_count;

View File

@ -8264,10 +8264,19 @@ ClangASTContext::AddObjCClassProperty (const CompilerType& type,
property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_copy);
if (property_attributes & DW_APPLE_PROPERTY_nonatomic)
property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_nonatomic);
if (!getter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(getter_sel))
if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_nullability)
property_decl->setPropertyAttributes(clang::ObjCPropertyDecl::OBJC_PR_nullability);
if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_null_resettable)
property_decl->setPropertyAttributes(clang::ObjCPropertyDecl::OBJC_PR_null_resettable);
if (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class)
property_decl->setPropertyAttributes(clang::ObjCPropertyDecl::OBJC_PR_class);
const bool isInstance = (property_attributes & clang::ObjCPropertyDecl::OBJC_PR_class) == 0;
if (!getter_sel.isNull() &&
!(isInstance ? class_interface_decl->lookupInstanceMethod(getter_sel)
: class_interface_decl->lookupClassMethod(getter_sel)))
{
const bool isInstance = true;
const bool isVariadic = false;
const bool isSynthesized = false;
const bool isImplicitlyDeclared = true;
@ -8291,12 +8300,12 @@ ClangASTContext::AddObjCClassProperty (const CompilerType& type,
class_interface_decl->addDecl(getter);
}
}
if (!setter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(setter_sel))
if (!setter_sel.isNull() &&
!(isInstance ? class_interface_decl->lookupInstanceMethod(setter_sel)
: class_interface_decl->lookupClassMethod(setter_sel)))
{
clang::QualType result_type = clang_ast->VoidTy;
const bool isInstance = true;
const bool isVariadic = false;
const bool isSynthesized = false;
const bool isImplicitlyDeclared = true;