diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-11-16 20:05:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-11-16 20:05:18 +0000 |
commit | a081da5e44600d02983d6562bed1b4fd61e410fd (patch) | |
tree | 4e375ae850fd64690541ca5d5a57b440a2d27d40 /lib/Serialization/ASTWriter.cpp | |
parent | 3d5f24ae1ad6241e630b7824eb8d02a8576193ab (diff) |
Implement (de-)serialization of the buffer contents for an overridden
file in the source manager. This allows us to properly create and use
modules described by module map files without umbrella headers (or
with incompletely umbrella headers). More generally, we can actually
build a PCH file that makes use of file -> buffer remappings, which
could be useful in libclang in the future.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144830 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTWriter.cpp')
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 6893dbd9f5..51aadb35e5 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1174,6 +1174,7 @@ static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { // FileEntry fields. Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time + Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // BufferOverridden Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls @@ -1421,7 +1422,8 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, // Figure out which record code to use. unsigned Code; if (SLoc->isFile()) { - if (SLoc->getFile().getContentCache()->OrigEntry) { + const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); + if (Cache->OrigEntry) { Code = SM_SLOC_FILE_ENTRY; SLocFileEntryOffsets.push_back(Stream.GetCurrentBitNo()); } else @@ -1442,7 +1444,7 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, const SrcMgr::ContentCache *Content = File.getContentCache(); if (Content->OrigEntry) { assert(Content->OrigEntry == Content->ContentsEntry && - "Writing to AST an overriden file is not supported"); + "Writing to AST an overridden file is not supported"); // The source location entry is a file. The blob associated // with this entry is the file name. @@ -1450,7 +1452,7 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, // Emit size/modification time for this file. Record.push_back(Content->OrigEntry->getSize()); Record.push_back(Content->OrigEntry->getModificationTime()); - + Record.push_back(Content->BufferOverridden); Record.push_back(File.NumCreatedFIDs); FileDeclIDsTy::iterator FDI = FileDeclIDs.find(SLoc); @@ -1461,7 +1463,7 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, Record.push_back(0); Record.push_back(0); } - + // Turn the file name into an absolute path, if it isn't already. const char *Filename = Content->OrigEntry->getName(); llvm::SmallString<128> FilePath(Filename); @@ -1477,6 +1479,16 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, Filename = adjustFilenameForRelocatablePCH(Filename, isysroot); Stream.EmitRecordWithBlob(SLocFileAbbrv, Record, Filename); + + if (Content->BufferOverridden) { + Record.clear(); + Record.push_back(SM_SLOC_BUFFER_BLOB); + const llvm::MemoryBuffer *Buffer + = Content->getBuffer(PP.getDiagnostics(), PP.getSourceManager()); + Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, + StringRef(Buffer->getBufferStart(), + Buffer->getBufferSize() + 1)); + } } else { // The source location entry is a buffer. The blob associated // with this entry contains the contents of the buffer. |