]> granicus.if.org Git - clang/commitdiff
AST: Add ObjCIvarDecl::getContainingInterface().
authorDaniel Dunbar <daniel@zuster.org>
Fri, 2 Apr 2010 21:13:59 +0000 (21:13 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 2 Apr 2010 21:13:59 +0000 (21:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100227 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp

index aafbe109f93468eaea93902bafba426d5ef02cd5..9b2b6096e81d902ac5945625f6f1b621c9983177 100644 (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); }
index 63f3e04772423093c18ba2f071fd69633f81e4ed..821e38bdacfd0cc484ec9c45a570bdc3705981e2 100644 (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