diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-11-09 19:40:45 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-11-09 19:40:45 +0000 |
commit | ecd27bf256c92f56c7c7ede6f40ec5d31a40b35e (patch) | |
tree | c7318bae561a592d3ff8b282c7a864a175e0ac10 | |
parent | 8616f9af65b9a3662f2c9dfed38eeabc509f8446 (diff) | |
download | clang-ecd27bf256c92f56c7c7ede6f40ec5d31a40b35e.tar.gz clang-ecd27bf256c92f56c7c7ede6f40ec5d31a40b35e.tar.bz2 clang-ecd27bf256c92f56c7c7ede6f40ec5d31a40b35e.tar.xz |
Add a FileCharacteristic parameter to SourceManager::createFileIDForMemBuffer
for completeness and use it in CompilerInstance::InitializeSourceManager if
the input is a memory buffer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167628 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/SourceManager.h | 8 | ||||
-rw-r--r-- | lib/AST/ASTImporter.cpp | 3 | ||||
-rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 10 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 6 |
4 files changed, 20 insertions, 7 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index a8e10ecf75..db6bfd2ad3 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -674,9 +674,10 @@ public: /// /// One example of when this would be used is when the main source is read /// from STDIN. - FileID createMainFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer) { + FileID createMainFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer, + SrcMgr::CharacteristicKind Kind = SrcMgr::C_User) { assert(MainFileID.isInvalid() && "MainFileID already set!"); - MainFileID = createFileIDForMemBuffer(Buffer); + MainFileID = createFileIDForMemBuffer(Buffer, Kind); return MainFileID; } @@ -733,10 +734,11 @@ public: /// This does no caching of the buffer and takes ownership of the /// MemoryBuffer, so only pass a MemoryBuffer to this once. FileID createFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer, + SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User, int LoadedID = 0, unsigned LoadedOffset = 0, SourceLocation IncludeLoc = SourceLocation()) { return createFileID(createMemBufferContentCache(Buffer), IncludeLoc, - SrcMgr::C_User, LoadedID, LoadedOffset); + FileCharacter, LoadedID, LoadedOffset); } /// \brief Return a new SourceLocation that encodes the diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp index dc1afcbd4d..0d4f303af2 100644 --- a/lib/AST/ASTImporter.cpp +++ b/lib/AST/ASTImporter.cpp @@ -4662,7 +4662,8 @@ FileID ASTImporter::Import(FileID FromID) { llvm::MemoryBuffer *ToBuf = llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(), FromBuf->getBufferIdentifier()); - ToID = ToSM.createFileIDForMemBuffer(ToBuf); + ToID = ToSM.createFileIDForMemBuffer(ToBuf, + FromSLoc.getFile().getFileCharacteristic()); } diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 9e7b630bf1..22a74fcc35 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -600,10 +600,18 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, FileManager &FileMgr, SourceManager &SourceMgr, const FrontendOptions &Opts) { - StringRef InputFile = Input.getFile(); SrcMgr::CharacteristicKind Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User; + if (Input.isBuffer()) { + SourceMgr.createMainFileIDForMemBuffer(Input.getBuffer(), Kind); + assert(!SourceMgr.getMainFileID().isInvalid() && + "Couldn't establish MainFileID!"); + return true; + } + + StringRef InputFile = Input.getFile(); + // Figure out where to get and map in the main file. if (InputFile != "-") { const FileEntry *File = FileMgr.getFile(InputFile); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 0f3e553ae2..deba302e21 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -961,6 +961,8 @@ bool ASTReader::ReadSLocEntry(int ID) { case SM_SLOC_BUFFER_ENTRY: { const char *Name = BlobStart; unsigned Offset = Record[0]; + SrcMgr::CharacteristicKind + FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); unsigned Code = SLocEntryCursor.ReadCode(); Record.clear(); @@ -975,8 +977,8 @@ bool ASTReader::ReadSLocEntry(int ID) { llvm::MemoryBuffer *Buffer = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), Name); - SourceMgr.createFileIDForMemBuffer(Buffer, ID, BaseOffset + Offset, - IncludeLoc); + SourceMgr.createFileIDForMemBuffer(Buffer, FileCharacter, ID, + BaseOffset + Offset, IncludeLoc); break; } |