[cfe-commits] r140657 - in /cfe/trunk: lib/Sema/SemaObjCProperty.cpp test/Index/complete-synthesized.m test/SemaObjC/default-synthesize-1.m test/SemaObjC/default-synthesize-2.m test/SemaObjC/direct-synthesized-ivar-access.m test/SemaObjC/synth-provisional-ivars.m test/SemaObjC/synthesized-ivar.m
Ted Kremenek
kremenek at apple.com
Tue Sep 27 16:39:40 PDT 2011
Author: kremenek
Date: Tue Sep 27 18:39:40 2011
New Revision: 140657
URL: http://llvm.org/viewvc/llvm-project?rev=140657&view=rev
Log:
Include prefix with default synthesized ivars.
Modified:
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/Index/complete-synthesized.m
cfe/trunk/test/SemaObjC/default-synthesize-1.m
cfe/trunk/test/SemaObjC/default-synthesize-2.m
cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m
cfe/trunk/test/SemaObjC/synth-provisional-ivars.m
cfe/trunk/test/SemaObjC/synthesized-ivar.m
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=140657&r1=140656&r2=140657&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue Sep 27 18:39:40 2011
@@ -1249,10 +1249,20 @@
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 @@
// to help users.
ActOnPropertyImplDecl(S, SourceLocation(), SourceLocation(),
true,
- Prop->getIdentifier(), Prop->getIdentifier(),
+ /* property = */ Prop->getIdentifier(),
+ /* ivar = */ getDefaultSynthIvarName(Prop, Context),
SourceLocation());
}
}
Modified: cfe/trunk/test/Index/complete-synthesized.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-synthesized.m?rev=140657&r1=140656&r2=140657&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-synthesized.m (original)
+++ cfe/trunk/test/Index/complete-synthesized.m Tue Sep 27 18:39:40 2011
@@ -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)
Modified: cfe/trunk/test/SemaObjC/default-synthesize-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-1.m?rev=140657&r1=140656&r2=140657&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-1.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize-1.m Tue Sep 27 18:39:40 2011
@@ -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
Modified: cfe/trunk/test/SemaObjC/default-synthesize-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-2.m?rev=140657&r1=140656&r2=140657&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-2.m (original)
+++ cfe/trunk/test/SemaObjC/default-synthesize-2.m Tue Sep 27 18:39:40 2011
@@ -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;
- at interface Test7 {
-id _object;
-}
+ at 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
Modified: cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m?rev=140657&r1=140656&r2=140657&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m (original)
+++ cfe/trunk/test/SemaObjC/direct-synthesized-ivar-access.m Tue Sep 27 18:39:40 2011
@@ -10,6 +10,6 @@
@end
@implementation I
-- (int) Meth { return IVAR; }
+- (int) Meth { return _IVAR; }
- (int) OK { return self.IVAR; }
@end
Modified: cfe/trunk/test/SemaObjC/synth-provisional-ivars.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/synth-provisional-ivars.m?rev=140657&r1=140656&r2=140657&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/synth-provisional-ivars.m (original)
+++ cfe/trunk/test/SemaObjC/synth-provisional-ivars.m Tue Sep 27 18:39:40 2011
@@ -18,7 +18,7 @@
@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 @@
@synthesize PROP3=IVAR;
- (int) Meth4 { return PROP4; }
- at synthesize PROP4=PROP4;
+ at 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
Modified: cfe/trunk/test/SemaObjC/synthesized-ivar.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/synthesized-ivar.m?rev=140657&r1=140656&r2=140657&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/synthesized-ivar.m (original)
+++ cfe/trunk/test/SemaObjC/synthesized-ivar.m Tue Sep 27 18:39:40 2011
@@ -31,8 +31,8 @@
@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 @@
@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
More information about the cfe-commits
mailing list