More semantics checks of properties. Property implementation can implicitly use

ivar of same name. 
Better diagnostics to bring home this point.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50065 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fariborz Jahanian 2008-04-21 21:57:36 +00:00
Родитель c35b9e4e2e
Коммит 6cdf16d61d
3 изменённых файлов: 14 добавлений и 11 удалений

Просмотреть файл

@ -492,7 +492,7 @@ DIAG(error_missing_property_context, ERROR,
DIAG(error_bad_property_context, ERROR,
"property implementation must be in a class or category implementation")
DIAG(error_bad_property_decl, ERROR,
"property implementation must have its declaration in the class '%0'")
"property implementation must have its declaration in interface '%0'")
DIAG(error_bad_category_property_decl, ERROR,
"property implementation must have its declaration in the category '%0'")
DIAG(error_property_ivar_decl, ERROR,
@ -502,7 +502,8 @@ DIAG(error_dynamic_property_ivar_decl, ERROR,
DIAG(error_missing_property_interface, ERROR,
"property implementation in a category with no category declaration")
DIAG(error_missing_property_ivar_decl, ERROR,
"property synthesize requires a previously declared ivar")
"synthesized property '%0' must either be named the same as a compatible"
" ivar or must explicitly name an ivar")
DIAG(error_synthesize_category_decl, ERROR,
"@synthesize not allowed in a category's implementation")
DIAG(error_property_ivar_type, ERROR,

Просмотреть файл

@ -998,14 +998,13 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
// Check that we have a valid, previously declared ivar for @synthesize
if (Synthesize) {
// @synthesize
if (!PropertyIvar) {
Diag(PropertyLoc, diag::error_property_ivar_decl);
return 0;
}
if (!PropertyIvar)
PropertyIvar = PropertyId;
// Check that this is a previously declared 'ivar' in 'IDecl' interface
ObjCIvarDecl *Ivar = IDecl->FindIvarDeclaration(PropertyIvar);
if (!Ivar) {
Diag(PropertyLoc, diag::error_missing_property_ivar_decl);
Diag(PropertyLoc, diag::error_missing_property_ivar_decl,
PropertyId->getName());
return 0;
}
// Check that type of property and its ivar match.

Просмотреть файл

@ -3,9 +3,11 @@
@interface I
{
int IVAR;
int name;
}
@property int d1;
@property id prop_id;
@property int name;
@end
@interface I(CAT)
@ -13,10 +15,11 @@
@end
@implementation I
@synthesize d1; // expected-error {{property synthesize requires specification of an ivar}}
@dynamic bad; // expected-error {{property implementation must have its declaration in the class 'I'}}
@synthesize prop_id; // expected-error {{property synthesize requires specification of an ivar}}
@synthesize d1; // expected-error {{synthesized property 'd1' must either be named the same as}}
@dynamic bad; // expected-error {{property implementation must have its declaration in interface 'I'}}
@synthesize prop_id; // expected-error {{synthesized property 'prop_id' must either be named the same}}
@synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' does not match type of ivar 'IVAR'}}
@synthesize name; // OK! property with same name as an accessible ivar of same name
@end
@implementation I(CAT)
@ -25,7 +28,7 @@
@end
@implementation E // expected-warning {{cannot find interface declaration for 'E'}}
@dynamic d; // expected-error {{property implementation must have its declaration in the class 'E'}}
@dynamic d; // expected-error {{property implementation must have its declaration in interface 'E'}}
@end
@implementation Q(MYCAT) // expected-error {{cannot find interface declaration for 'Q'}}