summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization/ASTWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-11-30 06:16:57 +0000
committerDouglas Gregor <dgregor@apple.com>2010-11-30 06:16:57 +0000
commitf88e35ba0b0fc4b0327fe9705e9eee80c8c6ba21 (patch)
tree661c87e22ab5d34cbd3eaa8e706d5a9f1a290083 /clang/lib/Serialization/ASTWriter.cpp
parentb42f34b652700e6d62aeced2513132f0d364c4ef (diff)
downloadbcm5719-llvm-f88e35ba0b0fc4b0327fe9705e9eee80c8c6ba21.tar.gz
bcm5719-llvm-f88e35ba0b0fc4b0327fe9705e9eee80c8c6ba21.zip
When using a precompiled preamble with detailed preprocessing records,
trap the serialized preprocessing records (macro definitions, macro instantiations, macro definitions) from the generation of the precompiled preamble, then replay those when walking the list of preprocessed entities. This eliminates a bug where clang_getCursor() wasn't able to find preprocessed-entity cursors in the preamble. llvm-svn: 120396
Diffstat (limited to 'clang/lib/Serialization/ASTWriter.cpp')
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index b143ce4b1b5..9a5085da279 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Serialization/ASTWriter.h"
+#include "clang/Serialization/ASTSerializationListener.h"
#include "ASTCommon.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/IdentifierResolver.h"
@@ -1358,33 +1359,28 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
E != EEnd; ++E) {
Record.clear();
- if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) {
- Record.push_back(IndexBase + NumPreprocessingRecords++);
- AddSourceLocation(MI->getSourceRange().getBegin(), Record);
- AddSourceLocation(MI->getSourceRange().getEnd(), Record);
- AddIdentifierRef(MI->getName(), Record);
- Record.push_back(getMacroDefinitionID(MI->getDefinition()));
- Stream.EmitRecord(PP_MACRO_INSTANTIATION, Record);
- continue;
- }
-
if (MacroDefinition *MD = dyn_cast<MacroDefinition>(*E)) {
// Record this macro definition's location.
MacroID ID = getMacroDefinitionID(MD);
-
+
// Don't write the macro definition if it is from another AST file.
if (ID < FirstMacroID)
continue;
+
+ // Notify the serialization listener that we're serializing this entity.
+ if (SerializationListener)
+ SerializationListener->SerializedPreprocessedEntity(*E,
+ Stream.GetCurrentBitNo());
unsigned Position = ID - FirstMacroID;
if (Position != MacroDefinitionOffsets.size()) {
if (Position > MacroDefinitionOffsets.size())
MacroDefinitionOffsets.resize(Position + 1);
-
+
MacroDefinitionOffsets[Position] = Stream.GetCurrentBitNo();
} else
MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo());
-
+
Record.push_back(IndexBase + NumPreprocessingRecords++);
Record.push_back(ID);
AddSourceLocation(MD->getSourceRange().getBegin(), Record);
@@ -1395,6 +1391,21 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
continue;
}
+ // Notify the serialization listener that we're serializing this entity.
+ if (SerializationListener)
+ SerializationListener->SerializedPreprocessedEntity(*E,
+ Stream.GetCurrentBitNo());
+
+ if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) {
+ Record.push_back(IndexBase + NumPreprocessingRecords++);
+ AddSourceLocation(MI->getSourceRange().getBegin(), Record);
+ AddSourceLocation(MI->getSourceRange().getEnd(), Record);
+ AddIdentifierRef(MI->getName(), Record);
+ Record.push_back(getMacroDefinitionID(MI->getDefinition()));
+ Stream.EmitRecord(PP_MACRO_INSTANTIATION, Record);
+ continue;
+ }
+
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(*E)) {
Record.push_back(PP_INCLUSION_DIRECTIVE);
Record.push_back(IndexBase + NumPreprocessingRecords++);
@@ -1409,6 +1420,8 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer);
continue;
}
+
+ llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter");
}
}
@@ -2232,7 +2245,8 @@ void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) {
}
ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream)
- : Stream(Stream), Chain(0), FirstDeclID(1), NextDeclID(FirstDeclID),
+ : Stream(Stream), Chain(0), SerializationListener(0),
+ FirstDeclID(1), NextDeclID(FirstDeclID),
FirstTypeID(NUM_PREDEF_TYPE_IDS), NextTypeID(FirstTypeID),
FirstIdentID(1), NextIdentID(FirstIdentID), FirstSelectorID(1),
NextSelectorID(FirstSelectorID), FirstMacroID(1), NextMacroID(FirstMacroID),
@@ -3415,3 +3429,5 @@ void ASTWriter::AddedCXXTemplateSpecialization(const ClassTemplateDecl *TD,
Record.push_back(UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION);
AddDeclRef(D, Record);
}
+
+ASTSerializationListener::~ASTSerializationListener() { }
OpenPOWER on IntegriCloud