AST: Add ObjCIvarDecl::getContainingInterface().

llvm-svn: 100227
This commit is contained in:
Daniel Dunbar 2010-04-02 21:13:59 +00:00
parent e16cdb407a
commit 89947ea894
2 changed files with 29 additions and 0 deletions

View File

@ -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); }

View File

@ -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<ObjCContainerDecl>(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<ObjCCategoryDecl>(DC);
assert(CD->IsClassExtension() && "invalid container for ivar!");
return CD->getClassInterface();
}
case ObjCImplementation:
return cast<ObjCImplementationDecl>(DC)->getClassInterface();
case ObjCInterface:
return cast<ObjCInterfaceDecl>(DC);
}
}
//===----------------------------------------------------------------------===//
// ObjCAtDefsFieldDecl