aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-25 00:41:30 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-25 00:41:30 +0000
commitc62a2fe1957626bc4b29402b2d0a3694dfaa3280 (patch)
treeb0db208a9e5fe4953dfa60aabd72f47d523e26dc
parentde9a81b92e9098daa8ca19df138e4807b4d8afe8 (diff)
Make sure that the consumer sees all interested decls. This fixes Preview
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70007 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Frontend/PCHReader.h8
-rw-r--r--lib/Frontend/PCHReader.cpp41
2 files changed, 34 insertions, 15 deletions
diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h
index 34cf3e12d0..941e92426f 100644
--- a/include/clang/Frontend/PCHReader.h
+++ b/include/clang/Frontend/PCHReader.h
@@ -209,6 +209,14 @@ private:
/// \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,
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index b10778a1e1..4c3e248c64 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -2404,6 +2404,20 @@ inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
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 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
}
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 @@ void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) {
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() {