зеркало из https://github.com/microsoft/clang-1.git
More ObjC2 property semantics work. Work in progress.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50508 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
072192bcbb
Коммит
02edb98b45
|
@ -508,6 +508,12 @@ DIAG(error_synthesize_category_decl, ERROR,
|
||||||
"@synthesize not allowed in a category's implementation")
|
"@synthesize not allowed in a category's implementation")
|
||||||
DIAG(error_property_ivar_type, ERROR,
|
DIAG(error_property_ivar_type, ERROR,
|
||||||
"type of property '%0' does not match type of ivar '%1'")
|
"type of property '%0' does not match type of ivar '%1'")
|
||||||
|
DIAG(warn_readonly_property, WARNING,
|
||||||
|
"attribute 'readonly' of property '%0' restricts attribute "
|
||||||
|
"'readwrite' of '%1' property in super class")
|
||||||
|
DIAG(warn_property_attribute, WARNING,
|
||||||
|
"property '%0' '%1' attribute does not match super class '%2' "
|
||||||
|
"property")
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Semantic Analysis
|
// Semantic Analysis
|
||||||
|
|
|
@ -733,13 +733,6 @@ public:
|
||||||
Protocols) {
|
Protocols) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ComparePropertiesInBaseAndSuper - This routine compares property
|
|
||||||
/// declarations in base and its super class, if any, and issues
|
|
||||||
/// diagnostics in a variety of inconsistant situations.
|
|
||||||
///
|
|
||||||
virtual void ComparePropertiesInBaseAndSuper(SourceLocation *PropertyLoc,
|
|
||||||
DeclTy *ClassInterface) {
|
|
||||||
}
|
|
||||||
//===----------------------- Obj-C Expressions --------------------------===//
|
//===----------------------- Obj-C Expressions --------------------------===//
|
||||||
|
|
||||||
virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
|
virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
|
||||||
|
|
|
@ -61,6 +61,7 @@ namespace clang {
|
||||||
class ObjCCategoryDecl;
|
class ObjCCategoryDecl;
|
||||||
class ObjCIvarDecl;
|
class ObjCIvarDecl;
|
||||||
class ObjCMethodDecl;
|
class ObjCMethodDecl;
|
||||||
|
class ObjCPropertyDecl;
|
||||||
|
|
||||||
/// Sema - This implements semantic analysis and AST building for C.
|
/// Sema - This implements semantic analysis and AST building for C.
|
||||||
class Sema : public Action {
|
class Sema : public Action {
|
||||||
|
@ -659,8 +660,10 @@ public:
|
||||||
llvm::SmallVector<DeclTy *, 8> &
|
llvm::SmallVector<DeclTy *, 8> &
|
||||||
Protocols);
|
Protocols);
|
||||||
|
|
||||||
virtual void ComparePropertiesInBaseAndSuper(SourceLocation *PropertyLoc,
|
void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
|
||||||
DeclTy *ClassInterface);
|
ObjCPropertyDecl *SuperProperty,
|
||||||
|
ObjCInterfaceDecl*SuperIDecl);
|
||||||
|
void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
|
||||||
|
|
||||||
virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
|
virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
|
||||||
DeclTy **allMethods = 0, unsigned allNum = 0,
|
DeclTy **allMethods = 0, unsigned allNum = 0,
|
||||||
|
|
|
@ -249,37 +249,47 @@ Sema::FindProtocolDeclaration(SourceLocation TypeLoc,
|
||||||
///
|
///
|
||||||
// TODO: Incomplete.
|
// TODO: Incomplete.
|
||||||
//
|
//
|
||||||
static void
|
void
|
||||||
DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
|
Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
|
||||||
ObjCPropertyDecl *SuperProperty) {
|
ObjCPropertyDecl *SuperProperty,
|
||||||
|
ObjCInterfaceDecl *SuperIDecl) {
|
||||||
ObjCPropertyDecl::PropertyAttributeKind CAttr =
|
ObjCPropertyDecl::PropertyAttributeKind CAttr =
|
||||||
Property->getPropertyAttributes();
|
Property->getPropertyAttributes();
|
||||||
ObjCPropertyDecl::PropertyAttributeKind SAttr =
|
ObjCPropertyDecl::PropertyAttributeKind SAttr =
|
||||||
SuperProperty->getPropertyAttributes();
|
SuperProperty->getPropertyAttributes();
|
||||||
if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
|
if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
|
||||||
&& (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite))
|
&& (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite))
|
||||||
; // ???
|
Diag(Property->getLocation(), diag::warn_readonly_property,
|
||||||
|
Property->getName(), SuperIDecl->getName());
|
||||||
if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy)
|
if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy)
|
||||||
!= (SAttr & ObjCPropertyDecl::OBJC_PR_copy))
|
!= (SAttr & ObjCPropertyDecl::OBJC_PR_copy))
|
||||||
; //
|
Diag(Property->getLocation(), diag::warn_property_attribute,
|
||||||
|
Property->getName(), "copy", SuperIDecl->getName(),
|
||||||
|
SourceRange());
|
||||||
else if ((CAttr & ObjCPropertyDecl::OBJC_PR_retain)
|
else if ((CAttr & ObjCPropertyDecl::OBJC_PR_retain)
|
||||||
!= (SAttr & ObjCPropertyDecl::OBJC_PR_retain))
|
!= (SAttr & ObjCPropertyDecl::OBJC_PR_retain))
|
||||||
; // ???
|
Diag(Property->getLocation(), diag::warn_property_attribute,
|
||||||
|
Property->getName(), "retain", SuperIDecl->getName(),
|
||||||
|
SourceRange());
|
||||||
|
|
||||||
if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)
|
if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)
|
||||||
!= (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic))
|
!= (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic))
|
||||||
; //
|
Diag(Property->getLocation(), diag::warn_property_attribute,
|
||||||
|
Property->getName(), "atomic", SuperIDecl->getName(),
|
||||||
|
SourceRange());
|
||||||
if (Property->getSetterName() != SuperProperty->getSetterName())
|
if (Property->getSetterName() != SuperProperty->getSetterName())
|
||||||
; //
|
Diag(Property->getLocation(), diag::warn_property_attribute,
|
||||||
|
Property->getName(), "setter", SuperIDecl->getName(),
|
||||||
|
SourceRange());
|
||||||
if (Property->getGetterName() != SuperProperty->getGetterName())
|
if (Property->getGetterName() != SuperProperty->getGetterName())
|
||||||
; //
|
Diag(Property->getLocation(), diag::warn_property_attribute,
|
||||||
|
Property->getName(), "getter", SuperIDecl->getName(),
|
||||||
|
SourceRange());
|
||||||
|
|
||||||
if (Property->getCanonicalType() != SuperProperty->getCanonicalType()) {
|
if (Property->getCanonicalType() != SuperProperty->getCanonicalType()) {
|
||||||
if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
|
if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
|
||||||
&& (SAttr & ObjCPropertyDecl::OBJC_PR_readonly))
|
&& (SAttr & ObjCPropertyDecl::OBJC_PR_readonly))
|
||||||
// && objc_compare_types(...))
|
// && objc_compare_types(...))
|
||||||
;
|
;
|
||||||
else
|
else
|
||||||
; //
|
; //
|
||||||
|
@ -292,22 +302,19 @@ DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
|
||||||
/// diagnostics in a variety of inconsistant situations.
|
/// diagnostics in a variety of inconsistant situations.
|
||||||
///
|
///
|
||||||
void
|
void
|
||||||
Sema::ComparePropertiesInBaseAndSuper(SourceLocation *PropertyLoc,
|
Sema::ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl) {
|
||||||
DeclTy *D) {
|
|
||||||
ObjCInterfaceDecl *IDecl =
|
|
||||||
dyn_cast<ObjCInterfaceDecl>(static_cast<Decl *>(D));
|
|
||||||
ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
|
ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
|
||||||
if (!SDecl)
|
if (!SDecl)
|
||||||
return;
|
return;
|
||||||
for (ObjCInterfaceDecl::classprop_iterator I = SDecl->classprop_begin(),
|
for (ObjCInterfaceDecl::classprop_iterator S = SDecl->classprop_begin(),
|
||||||
E = SDecl->classprop_end(); I != E; ++I) {
|
E = SDecl->classprop_end(); S != E; ++S) {
|
||||||
ObjCPropertyDecl *SuperPDecl = (*I);
|
ObjCPropertyDecl *SuperPDecl = (*S);
|
||||||
// Does property in super class has declaration in current class?
|
// Does property in super class has declaration in current class?
|
||||||
for (ObjCInterfaceDecl::classprop_iterator I = IDecl->classprop_begin(),
|
for (ObjCInterfaceDecl::classprop_iterator I = IDecl->classprop_begin(),
|
||||||
E = IDecl->classprop_end(); I != E; ++I) {
|
E = IDecl->classprop_end(); I != E; ++I) {
|
||||||
ObjCPropertyDecl *PDecl = (*I);
|
ObjCPropertyDecl *PDecl = (*I);
|
||||||
if (SuperPDecl->getIdentifier() == PDecl->getIdentifier())
|
if (SuperPDecl->getIdentifier() == PDecl->getIdentifier())
|
||||||
DiagnosePropertyMismatch(PDecl, SuperPDecl);
|
DiagnosePropertyMismatch(PDecl, SuperPDecl, SDecl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -815,6 +822,9 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
|
||||||
if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
|
if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
|
||||||
I->addMethods(&insMethods[0], insMethods.size(),
|
I->addMethods(&insMethods[0], insMethods.size(),
|
||||||
&clsMethods[0], clsMethods.size(), AtEndLoc);
|
&clsMethods[0], clsMethods.size(), AtEndLoc);
|
||||||
|
// Compares properties declaraed in this class to those of its
|
||||||
|
// super class.
|
||||||
|
ComparePropertiesInBaseAndSuper (I);
|
||||||
} else if (ObjCProtocolDecl *P = dyn_cast<ObjCProtocolDecl>(ClassDecl)) {
|
} else if (ObjCProtocolDecl *P = dyn_cast<ObjCProtocolDecl>(ClassDecl)) {
|
||||||
P->addMethods(&insMethods[0], insMethods.size(),
|
P->addMethods(&insMethods[0], insMethods.size(),
|
||||||
&clsMethods[0], clsMethods.size(), AtEndLoc);
|
&clsMethods[0], clsMethods.size(), AtEndLoc);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче