[cfe-commits] r70007 - in /cfe/trunk: include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp

Douglas Gregor dgregor at apple.com
Fri Apr 24 17:41:30 PDT 2009


Author: dgregor
Date: Fri Apr 24 19:41:30 2009
New Revision: 70007

URL: http://llvm.org/viewvc/llvm-project?rev=70007&view=rev
Log:
Make sure that the consumer sees all interested decls. This fixes Preview

Modified:
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/lib/Frontend/PCHReader.cpp

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=70007&r1=70006&r2=70007&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Fri Apr 24 19:41:30 2009
@@ -209,6 +209,14 @@
   /// \brief FIXME: document!
   llvm::SmallVector<uint64_t, 4> SpecialTypes;
 
+  /// \brief Contains declarations and definitions that will be
+  /// "interesting" to the ASTConsumer, when we get that AST consumer.
+  ///
+  /// "Interesting" declarations are those that have data that may
+  /// need to be emitted, such as inline function definitions or
+  /// Objective-C protocols.
+  llvm::SmallVector<Decl *, 16> InterestingDecls;
+
   PCHReadResult ReadPCHBlock(uint64_t &PreprocessorBlockOffset,
                              uint64_t &SelectorBlockOffset);
   bool CheckPredefinesBuffer(const char *PCHPredef, 

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=70007&r1=70006&r2=70007&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 24 19:41:30 2009
@@ -2404,6 +2404,20 @@
   DeclOffsets[Index] = reinterpret_cast<uint64_t>(D);
 }
 
+/// \brief Determine whether the consumer will be interested in seeing
+/// this declaration (via HandleTopLevelDecl).
+///
+/// This routine should return true for anything that might affect
+/// code generation, e.g., inline function definitions, Objective-C
+/// declarations with metadata, etc.
+static bool isConsumerInterestedIn(Decl *D) {
+  if (VarDecl *Var = dyn_cast<VarDecl>(D))
+    return Var->isFileVarDecl() && Var->getInit();
+  if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
+    return Func->isThisDeclarationADefinition();
+  return isa<ObjCProtocolDecl>(D);
+}
+
 /// \brief Read the declaration at the given offset from the PCH file.
 Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
   // Keep track of where we are in the stream, then jump back there
@@ -2581,23 +2595,15 @@
   }
   assert(Idx == Record.size());
 
-  if (Consumer) {
-    // If we have deserialized a declaration that has a definition the
-    // AST consumer might need to know about, notify the consumer
-    // about that definition now.
-    if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
-      if (Var->isFileVarDecl() && Var->getInit()) {
-        DeclGroupRef DG(Var);
-        Consumer->HandleTopLevelDecl(DG);
-      }
-    } else if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) {
-      if (Func->isThisDeclarationADefinition()) {
-        DeclGroupRef DG(Func);
-        Consumer->HandleTopLevelDecl(DG);
-      }
-    } else if (isa<ObjCProtocolDecl>(D)) {
+  // If we have deserialized a declaration that has a definition the
+  // AST consumer might need to know about, notify the consumer
+  // about that definition now or queue it for later.
+  if (isConsumerInterestedIn(D)) {
+    if (Consumer) {
       DeclGroupRef DG(D);
       Consumer->HandleTopLevelDecl(DG);
+    } else {
+      InterestingDecls.push_back(D);
     }
   }
 
@@ -2755,6 +2761,11 @@
     DeclGroupRef DG(D);
     Consumer->HandleTopLevelDecl(DG);
   }
+
+  for (unsigned I = 0, N = InterestingDecls.size(); I != N; ++I) {
+    DeclGroupRef DG(InterestingDecls[I]);
+    Consumer->HandleTopLevelDecl(DG);
+  }
 }
 
 void PCHReader::PrintStats() {





More information about the cfe-commits mailing list