diff options
author | Steve Naroff <snaroff@apple.com> | 2009-01-09 15:36:25 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-01-09 15:36:25 +0000 |
commit | b3a8798253f8e4845034c237d45c33e926d55ae8 (patch) | |
tree | 4298ee172a3020e2eb172f885b81e93f0baceeb9 /clang/lib/AST/DeclObjC.cpp | |
parent | ea1086b7f28fc88e0e65858a68d52f040c951954 (diff) | |
download | bcm5719-llvm-b3a8798253f8e4845034c237d45c33e926d55ae8.tar.gz bcm5719-llvm-b3a8798253f8e4845034c237d45c33e926d55ae8.zip |
Move property API's up to ObjCContainerDecl (removing a lot of duplicate code).
Add isa/cast/dyncast support for ObjCContainerDecl.
Renamed classprop_iterator/begin/end to prop_iterator/begin/end (the class prefix was confusing).
More simplifications to Sema::ActOnAtEnd()...
Added/changed some FIXME's as a result of the above work.
llvm-svn: 61988
Diffstat (limited to 'clang/lib/AST/DeclObjC.cpp')
-rw-r--r-- | clang/lib/AST/DeclObjC.cpp | 129 |
1 files changed, 27 insertions, 102 deletions
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index cf3bd0abeaf..7e62fa1130f 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -62,11 +62,11 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C, } ObjCContainerDecl::~ObjCContainerDecl() { + delete [] PropertyDecl; } ObjCInterfaceDecl::~ObjCInterfaceDecl() { delete [] Ivars; - delete [] PropertyDecl; // FIXME: CategoryList? } @@ -274,37 +274,6 @@ bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const return true; } -/// FindPropertyDeclaration - Finds declaration of the property given its name -/// in 'PropertyId' and returns it. It returns 0, if not found. -/// -ObjCPropertyDecl * - ObjCInterfaceDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { - for (ObjCInterfaceDecl::classprop_iterator I = classprop_begin(), - E = classprop_end(); I != E; ++I) { - ObjCPropertyDecl *property = *I; - if (property->getIdentifier() == PropertyId) - return property; - } - // Look through categories. - for (ObjCCategoryDecl *Category = getCategoryList(); - Category; Category = Category->getNextClassCategory()) { - ObjCPropertyDecl *property = Category->FindPropertyDeclaration(PropertyId); - if (property) - return property; - } - // Look through protocols. - for (ObjCInterfaceDecl::protocol_iterator I = protocol_begin(), - E = protocol_end(); I != E; ++I) { - ObjCProtocolDecl *Protocol = *I; - ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId); - if (property) - return property; - } - if (getSuperClass()) - return getSuperClass()->FindPropertyDeclaration(PropertyId); - return 0; -} - /// FindCategoryDeclaration - Finds category declaration in the list of /// categories for this class and returns it. Name of the category is passed /// in 'CategoryId'. If category not found, return 0; @@ -377,43 +346,6 @@ void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl( } } -/// addProperties - Insert property declaration AST nodes into -/// ObjCInterfaceDecl's PropertyDecl field. -/// -void ObjCInterfaceDecl::addProperties(ObjCPropertyDecl **Properties, - unsigned NumProperties) { - if (NumProperties == 0) return; - - NumPropertyDecl = NumProperties; - PropertyDecl = new ObjCPropertyDecl*[NumProperties]; - memcpy(PropertyDecl, Properties, NumProperties*sizeof(ObjCPropertyDecl*)); -} - -/// mergeProperties - Adds properties to the end of list of current properties -/// for this class. - -void ObjCInterfaceDecl::mergeProperties(ObjCPropertyDecl **Properties, - unsigned NumNewProperties) { - if (NumNewProperties == 0) return; - - if (PropertyDecl) { - ObjCPropertyDecl **newPropertyDecl = - new ObjCPropertyDecl*[NumNewProperties + NumPropertyDecl]; - ObjCPropertyDecl **buf = newPropertyDecl; - // put back original properties in buffer. - memcpy(buf, PropertyDecl, NumPropertyDecl*sizeof(ObjCPropertyDecl*)); - // Add new properties to this buffer. - memcpy(buf+NumPropertyDecl, Properties, - NumNewProperties*sizeof(ObjCPropertyDecl*)); - delete[] PropertyDecl; - PropertyDecl = newPropertyDecl; - NumPropertyDecl += NumNewProperties; - } - else { - addProperties(Properties, NumNewProperties); - } -} - // Get the local instance method declared in this interface. // FIXME: handle overloading, instance & class methods can have the same name. ObjCMethodDecl *ObjCContainerDecl::getInstanceMethod(Selector Sel) const { @@ -447,9 +379,9 @@ unsigned ObjCContainerDecl::getNumClassMethods() const { } /// mergeProperties - Adds properties to the end of list of current properties -/// for this category. +/// for this class. -void ObjCCategoryDecl::mergeProperties(ObjCPropertyDecl **Properties, +void ObjCContainerDecl::mergeProperties(ObjCPropertyDecl **Properties, unsigned NumNewProperties) { if (NumNewProperties == 0) return; @@ -472,22 +404,10 @@ void ObjCCategoryDecl::mergeProperties(ObjCPropertyDecl **Properties, } /// addProperties - Insert property declaration AST nodes into -/// ObjCProtocolDecl's PropertyDecl field. -/// -void ObjCProtocolDecl::addProperties(ObjCPropertyDecl **Properties, - unsigned NumProperties) { - if (NumProperties == 0) return; - - NumPropertyDecl = NumProperties; - PropertyDecl = new ObjCPropertyDecl*[NumProperties]; - memcpy(PropertyDecl, Properties, NumProperties*sizeof(ObjCPropertyDecl*)); -} - -/// addProperties - Insert property declaration AST nodes into -/// ObjCCategoryDecl's PropertyDecl field. +/// ObjCContainerDecl's PropertyDecl field. /// -void ObjCCategoryDecl::addProperties(ObjCPropertyDecl **Properties, - unsigned NumProperties) { +void ObjCContainerDecl::addProperties(ObjCPropertyDecl **Properties, + unsigned NumProperties) { if (NumProperties == 0) return; NumPropertyDecl = NumProperties; @@ -499,26 +419,31 @@ void ObjCCategoryDecl::addProperties(ObjCPropertyDecl **Properties, /// in 'PropertyId' and returns it. It returns 0, if not found. /// ObjCPropertyDecl * -ObjCCategoryDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { - for (ObjCCategoryDecl::classprop_iterator I = classprop_begin(), - E = classprop_end(); I != E; ++I) { +ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { + for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I) { ObjCPropertyDecl *property = *I; if (property->getIdentifier() == PropertyId) return property; } - return 0; -} - -/// FindPropertyDeclaration - Finds declaration of the property given its name -/// in 'PropertyId' and returns it. It returns 0, if not found. -/// -ObjCPropertyDecl * -ObjCProtocolDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const { - for (ObjCProtocolDecl::classprop_iterator I = classprop_begin(), - E = classprop_end(); I != E; ++I) { - ObjCPropertyDecl *property = *I; - if (property->getIdentifier() == PropertyId) - return property; + const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this); + if (OID) { + // Look through categories. + for (ObjCCategoryDecl *Category = OID->getCategoryList(); + Category; Category = Category->getNextClassCategory()) { + ObjCPropertyDecl *property = Category->FindPropertyDeclaration(PropertyId); + if (property) + return property; + } + // Look through protocols. + for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(), + E = OID->protocol_end(); I != E; ++I) { + ObjCProtocolDecl *Protocol = *I; + ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId); + if (property) + return property; + } + if (OID->getSuperClass()) + return OID->getSuperClass()->FindPropertyDeclaration(PropertyId); } return 0; } |