]> granicus.if.org Git - clang/commitdiff
Clean up our handling of Objective-C definitions in AST files. Rather
authorDouglas Gregor <dgregor@apple.com>
Sat, 10 Sep 2011 00:22:34 +0000 (00:22 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 10 Sep 2011 00:22:34 +0000 (00:22 +0000)
than having CodeGen check whether a declaration comes from an AST file
(which it shouldn't know or care about), make sure that the AST writer and
reader pass along "interesting" declarations that CodeGen needs to
know about.

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

lib/AST/ASTContext.cpp
lib/CodeGen/CGObjCMac.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp

index 5fa6704dbab9eb5673095a91d921f365a08b3c16..e3a6f4a86ffc1a8c81b68f7a367101c6b1a84fcc 100644 (file)
@@ -6387,7 +6387,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
   if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
     if (!VD->isFileVarDecl())
       return false;
-  } else if (!isa<FunctionDecl>(D))
+  } else if (!isa<FunctionDecl>(D) && !isa<ObjCMethodDecl>(D))
     return false;
 
   // Weak references don't produce any output by themselves.
@@ -6428,6 +6428,9 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
     return true;
   }
 
+  if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D))
+    return Method->hasBody();
+  
   const VarDecl *VD = cast<VarDecl>(D);
   assert(VD->isFileVarDecl() && "Expected file scoped var");
 
index f0ff9eb4326dfb247f953909494fa9a1773d92e4..fa49f1e09fe78b91073ccd9cd83d608177288fa1 100644 (file)
@@ -3549,13 +3549,6 @@ llvm::Function *CGObjCCommonMac::GetMethodDefinition(const ObjCMethodDecl *MD) {
   if (I != MethodDefinitions.end())
     return I->second;
 
-  if (MD->hasBody() && MD->isFromASTFile()) {
-    // MD isn't emitted yet because it comes from PCH.
-    CGM.EmitTopLevelDecl(const_cast<ObjCMethodDecl*>(MD));
-    assert(MethodDefinitions[MD] && "EmitTopLevelDecl didn't emit the method!");
-    return MethodDefinitions[MD];
-  }
-
   return NULL;
 }
 
index 594dc933257a61436b7334a491536035c2392f46..9210056fbbc3b3de22b3b20ff88716489d2d5fbf 100644 (file)
@@ -1393,14 +1393,19 @@ inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
 /// code generation, e.g., inline function definitions, Objective-C
 /// declarations with metadata, etc.
 static bool isConsumerInterestedIn(Decl *D) {
-  if (isa<FileScopeAsmDecl>(D))
+  if (isa<FileScopeAsmDecl>(D) || 
+      isa<ObjCProtocolDecl>(D) || 
+      isa<ObjCImplDecl>(D))
     return true;
   if (VarDecl *Var = dyn_cast<VarDecl>(D))
     return Var->isFileVarDecl() &&
            Var->isThisDeclarationADefinition() == VarDecl::Definition;
   if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
     return Func->doesThisDeclarationHaveABody();
-  return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
+  if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D))
+    return Method->hasBody();
+  
+  return false;
 }
 
 /// \brief Get the correct cursor and offset for loading a declaration.
@@ -1732,9 +1737,15 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
   // AST consumer might need to know about, queue it.
   // We don't pass it to the consumer immediately because we may be in recursive
   // loading, and some declarations may still be initializing.
-  if (isConsumerInterestedIn(D))
-    InterestingDecls.push_back(D);
-
+  if (isConsumerInterestedIn(D)) {
+    if (Consumer) {
+      DeclGroupRef DG(D);
+      Consumer->HandleInterestingDecl(DG);
+    } else {
+      InterestingDecls.push_back(D);
+    }
+  }
+  
   return D;
 }
 
index 112ccb1d4bae60b5bdae366a8432cb0b4d641d9f..55f1a6f9ce5a2cacff683f8371a8938a784ba37a 100644 (file)
@@ -1595,7 +1595,7 @@ void ASTWriter::WriteDeclsBlockAbbrevs() {
 /// decls.
 static bool isRequiredDecl(const Decl *D, ASTContext &Context) {
   // File scoped assembly or obj-c implementation must be seen.
-  if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplementationDecl>(D))
+  if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
     return true;
 
   return Context.DeclMustBeEmitted(D);