Skip to content

Commit

Permalink
Add a FileCharacteristic parameter to SourceManager::createFileIDForM…
Browse files Browse the repository at this point in the history
…emBuffer

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
  • Loading branch information
akyrtzi committed Nov 9, 2012
1 parent 8616f9a commit ecd27bf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
8 changes: 5 additions & 3 deletions include/clang/Basic/SourceManager.h
Expand Up @@ -674,9 +674,10 @@ class SourceManager : public RefCountedBase<SourceManager> {
///
/// 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;
}

Expand Down Expand Up @@ -733,10 +734,11 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// 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
Expand Down
3 changes: 2 additions & 1 deletion lib/AST/ASTImporter.cpp
Expand Up @@ -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());
}


Expand Down
10 changes: 9 additions & 1 deletion lib/Frontend/CompilerInstance.cpp
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions lib/Serialization/ASTReader.cpp
Expand Up @@ -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();
Expand All @@ -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;
}

Expand Down

0 comments on commit ecd27bf

Please sign in to comment.