]> granicus.if.org Git - clang/commitdiff
Sema/Obj-C: Narrow type of ObjCIvarDecl::Create, and check additional invariants...
authorDaniel Dunbar <daniel@zuster.org>
Fri, 2 Apr 2010 20:10:03 +0000 (20:10 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 2 Apr 2010 20:10:03 +0000 (20:10 +0000)
 - Doug, please see the FIXME in DeclObjC.cpp -- I am not sure what the right fix is.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100213 91177308-0d34-0410-b5e6-96231b3b80d8

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

index a1f565341e2c3af7d17f2e649d8a0e5a0f76e338..aafbe109f93468eaea93902bafba426d5ef02cd5 100644 (file)
@@ -624,14 +624,14 @@ public:
   };
 
 private:
-  ObjCIvarDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
+  ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation L, IdentifierInfo *Id,
                QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW)
     : FieldDecl(ObjCIvar, DC, L, Id, T, TInfo, BW, /*Mutable=*/false),
       DeclAccess(ac) {}
 
 public:
-  static ObjCIvarDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L,
-                              IdentifierInfo *Id, QualType T,
+  static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
+                              SourceLocation L, IdentifierInfo *Id, QualType T,
                               TypeSourceInfo *TInfo,
                               AccessControl ac, Expr *BW = NULL);
 
index 75cf1380a112623e19752e9f5f79cdb8f3fcdab2..f7d08e8b77bb3b2a9df9615c865e699700f9efb3 100644 (file)
@@ -2013,7 +2013,8 @@ Decl *ASTNodeImporter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
   if (!BitWidth && D->getBitWidth())
     return 0;
   
-  ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(), DC, 
+  ObjCIvarDecl *ToIvar = ObjCIvarDecl::Create(Importer.getToContext(),
+                                              cast<ObjCContainerDecl>(DC),
                                               Loc, Name.getAsIdentifierInfo(),
                                               T, TInfo, D->getAccessControl(),
                                               BitWidth);
index ab6b9e1f45ad7f7d255c598cfba60f03b2c89930..63f3e04772423093c18ba2f071fd69633f81e4ed 100644 (file)
@@ -561,10 +561,26 @@ bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
 // ObjCIvarDecl
 //===----------------------------------------------------------------------===//
 
-ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, DeclContext *DC,
+ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
                                    SourceLocation L, IdentifierInfo *Id,
                                    QualType T, TypeSourceInfo *TInfo,
                                    AccessControl ac, Expr *BW) {
+  if (DC) {
+    // Ivar's can only appear in interfaces, implementations (via synthesized
+    // properties), and class extensions (via direct declaration, or synthesized
+    // properties).
+    //
+    // FIXME: This should really be asserting this:
+    //   (isa<ObjCCategoryDecl>(DC) &&
+    //    cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
+    // but unfortunately we sometimes place ivars into non-class extension
+    // categories on error. This breaks an AST invariant, and should not be
+    // fixed.
+    assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
+            isa<ObjCCategoryDecl>(DC)) &&
+           "Invalid ivar decl context!");
+  }
+
   return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW);
 }