mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-05 04:38:37 +00:00
unique_ptrify SourceManager::createFileID
llvm-svn: 216715
This commit is contained in:
parent
0392cf892f
commit
50a5f97e82
@ -205,10 +205,10 @@ namespace SrcMgr {
|
||||
/// this content cache. This is used for performance analysis.
|
||||
llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const;
|
||||
|
||||
void setBuffer(llvm::MemoryBuffer *B) {
|
||||
void setBuffer(std::unique_ptr<llvm::MemoryBuffer> B) {
|
||||
assert(!Buffer.getPointer() && "MemoryBuffer already set.");
|
||||
Buffer.setPointer(B);
|
||||
Buffer.setInt(false);
|
||||
Buffer.setPointer(B.release());
|
||||
Buffer.setInt(0);
|
||||
}
|
||||
|
||||
/// \brief Get the underlying buffer, returning NULL if the buffer is not
|
||||
@ -788,12 +788,12 @@ public:
|
||||
///
|
||||
/// This does no caching of the buffer and takes ownership of the
|
||||
/// MemoryBuffer, so only pass a MemoryBuffer to this once.
|
||||
FileID createFileID(llvm::MemoryBuffer *Buffer,
|
||||
FileID createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer,
|
||||
SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User,
|
||||
int LoadedID = 0, unsigned LoadedOffset = 0,
|
||||
SourceLocation IncludeLoc = SourceLocation()) {
|
||||
return createFileID(createMemBufferContentCache(Buffer), IncludeLoc,
|
||||
FileCharacter, LoadedID, LoadedOffset);
|
||||
return createFileID(createMemBufferContentCache(std::move(Buffer)),
|
||||
IncludeLoc, FileCharacter, LoadedID, LoadedOffset);
|
||||
}
|
||||
|
||||
/// \brief Return a new SourceLocation that encodes the
|
||||
@ -1627,7 +1627,7 @@ private:
|
||||
|
||||
/// \brief Create a new ContentCache for the specified memory buffer.
|
||||
const SrcMgr::ContentCache *
|
||||
createMemBufferContentCache(llvm::MemoryBuffer *Buf);
|
||||
createMemBufferContentCache(std::unique_ptr<llvm::MemoryBuffer> Buf);
|
||||
|
||||
FileID getFileIDSlow(unsigned SLocOffset) const;
|
||||
FileID getFileIDLocal(unsigned SLocOffset) const;
|
||||
|
@ -4922,7 +4922,7 @@ FileID ASTImporter::Import(FileID FromID) {
|
||||
std::unique_ptr<llvm::MemoryBuffer> ToBuf
|
||||
= llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
|
||||
FromBuf->getBufferIdentifier());
|
||||
ToID = ToSM.createFileID(ToBuf.release(),
|
||||
ToID = ToSM.createFileID(std::move(ToBuf),
|
||||
FromSLoc.getFile().getFileCharacteristic());
|
||||
}
|
||||
|
||||
|
@ -456,13 +456,13 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt,
|
||||
|
||||
/// createMemBufferContentCache - Create a new ContentCache for the specified
|
||||
/// memory buffer. This does no caching.
|
||||
const ContentCache *
|
||||
SourceManager::createMemBufferContentCache(llvm::MemoryBuffer *Buffer) {
|
||||
const ContentCache *SourceManager::createMemBufferContentCache(
|
||||
std::unique_ptr<llvm::MemoryBuffer> Buffer) {
|
||||
// Add a new ContentCache to the MemBufferInfos list and return it.
|
||||
ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>();
|
||||
new (Entry) ContentCache();
|
||||
MemBufferInfos.push_back(Entry);
|
||||
Entry->setBuffer(Buffer);
|
||||
Entry->setBuffer(std::move(Buffer));
|
||||
return Entry;
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D,
|
||||
llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
|
||||
LBuf->getBufferIdentifier());
|
||||
// FIXME: Keep a file ID map instead of creating new IDs for each location.
|
||||
FileID FID = CSM.createFileID(CBuf.release());
|
||||
FileID FID = CSM.createFileID(std::move(CBuf));
|
||||
|
||||
// Translate the offset into the file.
|
||||
unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
|
||||
|
@ -700,7 +700,8 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
|
||||
Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
|
||||
|
||||
if (Input.isBuffer()) {
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(Input.getBuffer(), Kind));
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(
|
||||
std::unique_ptr<llvm::MemoryBuffer>(Input.getBuffer()), Kind));
|
||||
assert(!SourceMgr.getMainFileID().isInvalid() &&
|
||||
"Couldn't establish MainFileID!");
|
||||
return true;
|
||||
|
@ -506,7 +506,7 @@ void Preprocessor::EnterMainSourceFile() {
|
||||
std::unique_ptr<llvm::MemoryBuffer> SB =
|
||||
llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>");
|
||||
assert(SB && "Cannot create predefined source buffer");
|
||||
FileID FID = SourceMgr.createFileID(SB.release());
|
||||
FileID FID = SourceMgr.createFileID(std::move(SB));
|
||||
assert(!FID.isInvalid() && "Could not create FileID for predefines?");
|
||||
setPredefinesFileID(FID);
|
||||
|
||||
|
@ -67,7 +67,7 @@ void ScratchBuffer::AllocScratchBuffer(unsigned RequestLen) {
|
||||
std::unique_ptr<llvm::MemoryBuffer> OwnBuf =
|
||||
llvm::MemoryBuffer::getNewMemBuffer(RequestLen, "<scratch space>");
|
||||
llvm::MemoryBuffer &Buf = *OwnBuf;
|
||||
FileID FID = SourceMgr.createFileID(OwnBuf.release());
|
||||
FileID FID = SourceMgr.createFileID(std::move(OwnBuf));
|
||||
BufferStartLoc = SourceMgr.getLocForStartOfFile(FID);
|
||||
CurBuffer = const_cast<char*>(Buf.getBufferStart());
|
||||
BytesUsed = 1;
|
||||
|
@ -1253,7 +1253,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
|
||||
|
||||
std::unique_ptr<llvm::MemoryBuffer> Buffer =
|
||||
llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name);
|
||||
SourceMgr.createFileID(Buffer.release(), FileCharacter, ID,
|
||||
SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
|
||||
BaseOffset + Offset, IncludeLoc);
|
||||
break;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ protected:
|
||||
void CommentLexerTest::lexString(const char *Source,
|
||||
std::vector<Token> &Toks) {
|
||||
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Source);
|
||||
FileID File = SourceMgr.createFileID(Buf.release());
|
||||
FileID File = SourceMgr.createFileID(std::move(Buf));
|
||||
SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
|
||||
|
||||
Lexer L(Allocator, Diags, Traits, Begin, Source, Source + strlen(Source));
|
||||
|
@ -55,7 +55,7 @@ protected:
|
||||
|
||||
FullComment *CommentParserTest::parseString(const char *Source) {
|
||||
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Source);
|
||||
FileID File = SourceMgr.createFileID(Buf.release());
|
||||
FileID File = SourceMgr.createFileID(std::move(Buf));
|
||||
SourceLocation Begin = SourceMgr.getLocForStartOfFile(File);
|
||||
|
||||
Lexer L(Allocator, Diags, Traits, Begin, Source, Source + strlen(Source));
|
||||
|
@ -75,7 +75,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
|
||||
"#define M(x) [x]\n"
|
||||
"M(foo)";
|
||||
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(source);
|
||||
FileID mainFileID = SourceMgr.createFileID(Buf.release());
|
||||
FileID mainFileID = SourceMgr.createFileID(std::move(Buf));
|
||||
SourceMgr.setMainFileID(mainFileID);
|
||||
|
||||
VoidModuleLoader ModLoader;
|
||||
@ -128,7 +128,7 @@ TEST_F(SourceManagerTest, getColumnNumber) {
|
||||
"int y;";
|
||||
|
||||
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Source);
|
||||
FileID MainFileID = SourceMgr.createFileID(Buf.release());
|
||||
FileID MainFileID = SourceMgr.createFileID(std::move(Buf));
|
||||
SourceMgr.setMainFileID(MainFileID);
|
||||
|
||||
bool Invalid;
|
||||
@ -188,7 +188,7 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
|
||||
|
||||
std::unique_ptr<MemoryBuffer> HeaderBuf = MemoryBuffer::getMemBuffer(header);
|
||||
std::unique_ptr<MemoryBuffer> MainBuf = MemoryBuffer::getMemBuffer(main);
|
||||
FileID mainFileID = SourceMgr.createFileID(MainBuf.release());
|
||||
FileID mainFileID = SourceMgr.createFileID(std::move(MainBuf));
|
||||
SourceMgr.setMainFileID(mainFileID);
|
||||
|
||||
const FileEntry *headerFile = FileMgr.getVirtualFile("/test-header.h",
|
||||
@ -287,7 +287,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) {
|
||||
|
||||
std::unique_ptr<MemoryBuffer> HeaderBuf = MemoryBuffer::getMemBuffer(header);
|
||||
std::unique_ptr<MemoryBuffer> MainBuf = MemoryBuffer::getMemBuffer(main);
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(MainBuf.release()));
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(MainBuf)));
|
||||
|
||||
const FileEntry *headerFile = FileMgr.getVirtualFile("/test-header.h",
|
||||
HeaderBuf->getBufferSize(), 0);
|
||||
|
@ -69,9 +69,8 @@ TEST(BufferSourceTest, EmitCXXGlobalInitFunc) {
|
||||
compiler.createSema(clang::TU_Prefix,NULL);
|
||||
|
||||
clang::SourceManager &sm = compiler.getSourceManager();
|
||||
sm.setMainFileID(
|
||||
sm.createFileID(llvm::MemoryBuffer::getMemBuffer(TestProgram).release(),
|
||||
clang::SrcMgr::C_User));
|
||||
sm.setMainFileID(sm.createFileID(
|
||||
llvm::MemoryBuffer::getMemBuffer(TestProgram), clang::SrcMgr::C_User));
|
||||
|
||||
clang::ParseAST(compiler.getSema(), false, false);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ protected:
|
||||
std::vector<Token> CheckLex(StringRef Source,
|
||||
ArrayRef<tok::TokenKind> ExpectedTokens) {
|
||||
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Source);
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(Buf.release()));
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
|
||||
|
||||
VoidModuleLoader ModLoader;
|
||||
HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts,
|
||||
|
@ -161,7 +161,7 @@ protected:
|
||||
CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText,
|
||||
const char* HeaderPath, bool SystemHeader) {
|
||||
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(SourceText);
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(Buf.release()));
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
|
||||
|
||||
VoidModuleLoader ModLoader;
|
||||
|
||||
@ -199,7 +199,7 @@ protected:
|
||||
|
||||
std::unique_ptr<MemoryBuffer> SourceBuf =
|
||||
MemoryBuffer::getMemBuffer(SourceText, "test.cl");
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(SourceBuf.release()));
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(SourceBuf)));
|
||||
|
||||
VoidModuleLoader ModLoader;
|
||||
HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags,
|
||||
|
@ -91,7 +91,7 @@ TEST_F(PPConditionalDirectiveRecordTest, PPRecAPI) {
|
||||
"9\n";
|
||||
|
||||
std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(source);
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(Buf.release()));
|
||||
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
|
||||
|
||||
VoidModuleLoader ModLoader;
|
||||
HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts,
|
||||
|
Loading…
Reference in New Issue
Block a user