forked from OSchip/llvm-project
Include prefix with default synthesized ivars.
llvm-svn: 140657
This commit is contained in:
parent
75acd925d0
commit
ab2dcc8de6
|
@ -1249,10 +1249,20 @@ ObjCPropertyDecl *Sema::LookupPropertyDecl(const ObjCContainerDecl *CDecl,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static IdentifierInfo * getDefaultSynthIvarName(ObjCPropertyDecl *Prop,
|
||||
ASTContext &Ctx) {
|
||||
llvm::SmallString<128> ivarName;
|
||||
{
|
||||
llvm::raw_svector_ostream os(ivarName);
|
||||
os << '_' << Prop->getIdentifier()->getName();
|
||||
}
|
||||
return &Ctx.Idents.get(ivarName.str());
|
||||
}
|
||||
|
||||
/// DefaultSynthesizeProperties - This routine default synthesizes all
|
||||
/// properties which must be synthesized in class's @implementation.
|
||||
void Sema::DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
|
||||
ObjCInterfaceDecl *IDecl) {
|
||||
void Sema::DefaultSynthesizeProperties(Scope *S, ObjCImplDecl* IMPDecl,
|
||||
ObjCInterfaceDecl *IDecl) {
|
||||
|
||||
llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> PropMap;
|
||||
CollectClassPropertyImplementations(IDecl, PropMap);
|
||||
|
@ -1289,7 +1299,8 @@ void Sema::DefaultSynthesizeProperties (Scope *S, ObjCImplDecl* IMPDecl,
|
|||
// to help users.
|
||||
ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
|
||||
true,
|
||||
Prop->getIdentifier(), Prop->getIdentifier(),
|
||||
/* property = */ Prop->getIdentifier(),
|
||||
/* ivar = */ getDefaultSynthIvarName(Prop, Context),
|
||||
SourceLocation());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
@dynamic prop3;
|
||||
|
||||
- (short)method2 {
|
||||
return prop4;
|
||||
return _prop4;
|
||||
}
|
||||
|
||||
- (short)method3 {
|
||||
|
@ -43,4 +43,4 @@
|
|||
// CHECK: ObjCIvarDecl:{ResultType float}{TypedText _prop2} (35)
|
||||
// CHECK-NOT: prop2
|
||||
// CHECK-NOT: prop3
|
||||
// CHECK: ObjCIvarDecl:{ResultType double}{TypedText prop4} (37)
|
||||
// CHECK: ObjCIvarDecl:{ResultType double}{TypedText _prop4} (37)
|
||||
|
|
|
@ -25,12 +25,12 @@
|
|||
//@synthesize howMany, what;
|
||||
|
||||
- (int) howMany {
|
||||
return howMany;
|
||||
return _howMany;
|
||||
}
|
||||
// - (void) setHowMany: (int) value
|
||||
|
||||
- (NSString*) what {
|
||||
return what;
|
||||
return _what;
|
||||
}
|
||||
// - (void) setWhat: (NSString*) value
|
||||
@end
|
||||
|
@ -46,14 +46,14 @@
|
|||
|
||||
// - (int) howMany
|
||||
- (void) setHowMany: (int) value {
|
||||
howMany = value;
|
||||
_howMany = value;
|
||||
}
|
||||
|
||||
// - (NSString*) what
|
||||
- (void) setWhat: (NSString*) value {
|
||||
if (what != value) {
|
||||
[what release];
|
||||
what = [value retain];
|
||||
if (_what != value) {
|
||||
[_what release];
|
||||
_what = [value retain];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
// @synthesize name, rank, serialNumber;
|
||||
// default synthesis allows direct access to property ivars.
|
||||
- (id)init {
|
||||
name = rank = serialNumber = 0;
|
||||
_name = _rank = _serialNumber = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
|||
// Test3
|
||||
@interface Test3
|
||||
{
|
||||
id _uid;
|
||||
id uid;
|
||||
}
|
||||
@property (readwrite, assign) id uid;
|
||||
@end
|
||||
|
@ -50,8 +50,8 @@
|
|||
// Oops, forgot to write @synthesize! will be default synthesized
|
||||
- (void) myMethod {
|
||||
self.uid = 0; // Use of the “setter”
|
||||
_uid = 0; // Use of the wrong instance variable
|
||||
uid = 0; // Use of the property instance variable
|
||||
uid = 0; // Use of the wrong instance variable
|
||||
_uid = 0; // Use of the property instance variable
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
|||
// default synthesize property named 'var'
|
||||
@implementation Test4
|
||||
- (id) myMethod {
|
||||
return self->var; // compiles because 'var' is synthesized by default
|
||||
return self->_var; // compiles because 'var' is synthesized by default
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -80,7 +80,7 @@
|
|||
@implementation Test5
|
||||
- (id) myMethod {
|
||||
Test5 *foo = 0;
|
||||
return foo->var; // OK
|
||||
return foo->_var; // OK
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -100,19 +100,17 @@
|
|||
@synthesize var = _var;
|
||||
@end
|
||||
|
||||
int* object;
|
||||
int* _object;
|
||||
|
||||
@interface Test7 {
|
||||
id _object;
|
||||
}
|
||||
@interface Test7
|
||||
@property (readwrite, assign) id object;
|
||||
@end
|
||||
|
||||
// With default synthesis, 'object' is be the synthesized ivar not the global
|
||||
// With default synthesis, '_object' is be the synthesized ivar not the global
|
||||
// 'int*' object. So no error.
|
||||
@implementation Test7
|
||||
- (id) myMethod {
|
||||
return object;
|
||||
return _object;
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
@end
|
||||
|
||||
@implementation I
|
||||
- (int) Meth { return IVAR; }
|
||||
- (int) Meth { return _IVAR; }
|
||||
- (int) OK { return self.IVAR; }
|
||||
@end
|
||||
|
|
|
@ -18,7 +18,7 @@ int bar;
|
|||
@end
|
||||
|
||||
@implementation I
|
||||
- (int) Meth { return PROP; }
|
||||
- (int) Meth { return _PROP; }
|
||||
|
||||
@dynamic PROP1;
|
||||
- (int) Meth1 { return PROP1; } // expected-error {{use of undeclared identifier 'PROP1'}}
|
||||
|
@ -30,12 +30,12 @@ int bar;
|
|||
@synthesize PROP3=IVAR;
|
||||
|
||||
- (int) Meth4 { return PROP4; }
|
||||
@synthesize PROP4=PROP4;
|
||||
@synthesize PROP4=PROP4; // expected-note 4 {{'PROP4' declared here}}
|
||||
|
||||
- (int) Meth5 { return bar; }
|
||||
@synthesize bar = _bar;
|
||||
|
||||
- (int) Meth6 { return bar1; }
|
||||
- (int) Meth6 { return _bar1; }
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ int f0(I *a) { return a->IP; } // expected-error {{instance variable 'IP' is pri
|
|||
|
||||
@implementation I1
|
||||
- (int) Meth {
|
||||
PROP_INMAIN = 1;
|
||||
PROP_INCLASSEXT = 2;
|
||||
_PROP_INMAIN = 1;
|
||||
_PROP_INCLASSEXT = 2;
|
||||
protected_ivar = 1; // OK
|
||||
return private_ivar; // OK
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ int f0(I *a) { return a->IP; } // expected-error {{instance variable 'IP' is pri
|
|||
@implementation DER
|
||||
- (int) Meth {
|
||||
protected_ivar = 1; // OK
|
||||
PROP_INMAIN = 1; // expected-error {{instance variable 'PROP_INMAIN' is private}}
|
||||
PROP_INCLASSEXT = 2; // expected-error {{instance variable 'PROP_INCLASSEXT' is private}}
|
||||
_PROP_INMAIN = 1; // expected-error {{instance variable '_PROP_INMAIN' is private}}
|
||||
_PROP_INCLASSEXT = 2; // expected-error {{instance variable '_PROP_INCLASSEXT' is private}}
|
||||
return private_ivar; // expected-error {{instance variable 'private_ivar' is private}}
|
||||
}
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue