From: Daniel Dunbar Date: Fri, 2 Apr 2010 21:13:59 +0000 (+0000) Subject: AST: Add ObjCIvarDecl::getContainingInterface(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27a961a6adab85cfcf7e48485bbec9237719ae96;p=clang AST: Add ObjCIvarDecl::getContainingInterface(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100227 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index aafbe109f9..9b2b6096e8 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -635,6 +635,12 @@ public: TypeSourceInfo *TInfo, AccessControl ac, Expr *BW = NULL); + /// \brief Return the class interface that this ivar is logically contained + /// in; this is either the interface where the ivar was declared, or the + /// interface the ivar is conceptually a part of in the case of synthesized + /// ivars. + const ObjCInterfaceDecl *getContainingInterface() const; + void setAccessControl(AccessControl ac) { DeclAccess = ac; } AccessControl getAccessControl() const { return AccessControl(DeclAccess); } diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 63f3e04772..821e38bdac 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -584,7 +584,30 @@ ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC, return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW); } +const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const { + const ObjCContainerDecl *DC = cast(getDeclContext()); + + switch (DC->getKind()) { + default: + case ObjCCategoryImpl: + case ObjCProtocol: + assert(0 && "invalid ivar container!"); + return 0; + + // Ivars can only appear in class extension categories. + case ObjCCategory: { + const ObjCCategoryDecl *CD = cast(DC); + assert(CD->IsClassExtension() && "invalid container for ivar!"); + return CD->getClassInterface(); + } + + case ObjCImplementation: + return cast(DC)->getClassInterface(); + case ObjCInterface: + return cast(DC); + } +} //===----------------------------------------------------------------------===// // ObjCAtDefsFieldDecl