[cfe-commits] r50508 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def include/clang/Parse/Action.h lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Apr 30 17:03:38 PDT 2008
Author: fjahanian
Date: Wed Apr 30 19:03:38 2008
New Revision: 50508
URL: http://llvm.org/viewvc/llvm-project?rev=50508&view=rev
Log:
More ObjC2 property semantics work. Work in progress.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=50508&r1=50507&r2=50508&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Apr 30 19:03:38 2008
@@ -508,6 +508,12 @@
"@synthesize not allowed in a category's implementation")
DIAG(error_property_ivar_type, ERROR,
"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
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=50508&r1=50507&r2=50508&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Apr 30 19:03:38 2008
@@ -733,13 +733,6 @@
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 --------------------------===//
virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=50508&r1=50507&r2=50508&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Apr 30 19:03:38 2008
@@ -61,6 +61,7 @@
class ObjCCategoryDecl;
class ObjCIvarDecl;
class ObjCMethodDecl;
+ class ObjCPropertyDecl;
/// Sema - This implements semantic analysis and AST building for C.
class Sema : public Action {
@@ -658,9 +659,11 @@
unsigned NumProtocols,
llvm::SmallVector<DeclTy *, 8> &
Protocols);
-
- virtual void ComparePropertiesInBaseAndSuper(SourceLocation *PropertyLoc,
- DeclTy *ClassInterface);
+
+ void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
+ ObjCPropertyDecl *SuperProperty,
+ ObjCInterfaceDecl*SuperIDecl);
+ void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
DeclTy **allMethods = 0, unsigned allNum = 0,
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=50508&r1=50507&r2=50508&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Apr 30 19:03:38 2008
@@ -249,37 +249,47 @@
///
// TODO: Incomplete.
//
-static void
-DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
- ObjCPropertyDecl *SuperProperty) {
+void
+Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
+ ObjCPropertyDecl *SuperProperty,
+ ObjCInterfaceDecl *SuperIDecl) {
ObjCPropertyDecl::PropertyAttributeKind CAttr =
Property->getPropertyAttributes();
ObjCPropertyDecl::PropertyAttributeKind SAttr =
SuperProperty->getPropertyAttributes();
if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
&& (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite))
- ; // ???
-
+ Diag(Property->getLocation(), diag::warn_readonly_property,
+ Property->getName(), SuperIDecl->getName());
if ((CAttr & 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)
!= (SAttr & ObjCPropertyDecl::OBJC_PR_retain))
- ; // ???
+ Diag(Property->getLocation(), diag::warn_property_attribute,
+ Property->getName(), "retain", SuperIDecl->getName(),
+ SourceRange());
if ((CAttr & 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())
- ; //
+ Diag(Property->getLocation(), diag::warn_property_attribute,
+ Property->getName(), "setter", SuperIDecl->getName(),
+ SourceRange());
if (Property->getGetterName() != SuperProperty->getGetterName())
- ; //
+ Diag(Property->getLocation(), diag::warn_property_attribute,
+ Property->getName(), "getter", SuperIDecl->getName(),
+ SourceRange());
if (Property->getCanonicalType() != SuperProperty->getCanonicalType()) {
if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
&& (SAttr & ObjCPropertyDecl::OBJC_PR_readonly))
- // && objc_compare_types(...))
+ // && objc_compare_types(...))
;
else
; //
@@ -292,22 +302,19 @@
/// diagnostics in a variety of inconsistant situations.
///
void
-Sema::ComparePropertiesInBaseAndSuper(SourceLocation *PropertyLoc,
- DeclTy *D) {
- ObjCInterfaceDecl *IDecl =
- dyn_cast<ObjCInterfaceDecl>(static_cast<Decl *>(D));
+Sema::ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl) {
ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
if (!SDecl)
return;
- for (ObjCInterfaceDecl::classprop_iterator I = SDecl->classprop_begin(),
- E = SDecl->classprop_end(); I != E; ++I) {
- ObjCPropertyDecl *SuperPDecl = (*I);
+ for (ObjCInterfaceDecl::classprop_iterator S = SDecl->classprop_begin(),
+ E = SDecl->classprop_end(); S != E; ++S) {
+ ObjCPropertyDecl *SuperPDecl = (*S);
// Does property in super class has declaration in current class?
for (ObjCInterfaceDecl::classprop_iterator I = IDecl->classprop_begin(),
E = IDecl->classprop_end(); I != E; ++I) {
ObjCPropertyDecl *PDecl = (*I);
if (SuperPDecl->getIdentifier() == PDecl->getIdentifier())
- DiagnosePropertyMismatch(PDecl, SuperPDecl);
+ DiagnosePropertyMismatch(PDecl, SuperPDecl, SDecl);
}
}
}
@@ -815,6 +822,9 @@
if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
I->addMethods(&insMethods[0], insMethods.size(),
&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)) {
P->addMethods(&insMethods[0], insMethods.size(),
&clsMethods[0], clsMethods.size(), AtEndLoc);
More information about the cfe-commits
mailing list