r209266 - SourceManager: Use setMainFileID() consistently
Alp Toker
alp at nuanti.com
Tue May 20 18:12:41 PDT 2014
Author: alp
Date: Tue May 20 20:12:41 2014
New Revision: 209266
URL: http://llvm.org/viewvc/llvm-project?rev=209266&view=rev
Log:
SourceManager: Use setMainFileID() consistently
Eliminate createMainFileID() / createMainFileIDForMemBuffer() utility
functions. These didn't add much convenience and conflated two distinct
operations.
This change makes things easier to follow by providing a consistent interface
and getting rid of a bunch of cast-to-voids.
Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/unittests/Basic/SourceManagerTest.cpp
cfe/trunk/unittests/Lex/LexerTest.cpp
cfe/trunk/unittests/Lex/PPCallbacksTest.cpp
cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=209266&r1=209265&r2=209266&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue May 20 20:12:41 2014
@@ -746,18 +746,6 @@ public:
StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
}
- /// \brief Create the FileID for a memory buffer that will represent the
- /// FileID for the main source.
- ///
- /// One example of when this would be used is when the main source is read
- /// from STDIN.
- FileID createMainFileIDForMemBuffer(const llvm::MemoryBuffer *Buffer,
- SrcMgr::CharacteristicKind Kind = SrcMgr::C_User) {
- assert(MainFileID.isInvalid() && "MainFileID already set!");
- MainFileID = createFileID(Buffer, Kind);
- return MainFileID;
- }
-
//===--------------------------------------------------------------------===//
// MainFileID creation and querying methods.
//===--------------------------------------------------------------------===//
@@ -765,14 +753,6 @@ public:
/// \brief Returns the FileID of the main source file.
FileID getMainFileID() const { return MainFileID; }
- /// \brief Create the FileID for the main source file.
- FileID createMainFileID(const FileEntry *SourceFile,
- SrcMgr::CharacteristicKind Kind = SrcMgr::C_User) {
- assert(MainFileID.isInvalid() && "MainFileID already set!");
- MainFileID = createFileID(SourceFile, SourceLocation(), Kind);
- return MainFileID;
- }
-
/// \brief Set the file ID for the main source file.
void setMainFileID(FileID FID) {
assert(MainFileID.isInvalid() && "MainFileID already set!");
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=209266&r1=209265&r2=209266&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue May 20 20:12:41 2014
@@ -621,7 +621,7 @@ bool CompilerInstance::InitializeSourceM
Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
if (Input.isBuffer()) {
- SourceMgr.createMainFileIDForMemBuffer(Input.getBuffer(), Kind);
+ SourceMgr.setMainFileID(SourceMgr.createFileID(Input.getBuffer(), Kind));
assert(!SourceMgr.getMainFileID().isInvalid() &&
"Couldn't establish MainFileID!");
return true;
@@ -655,7 +655,8 @@ bool CompilerInstance::InitializeSourceM
}
}
- SourceMgr.createMainFileID(File, Kind);
+ SourceMgr.setMainFileID(
+ SourceMgr.createFileID(File, SourceLocation(), Kind));
} else {
std::unique_ptr<llvm::MemoryBuffer> SB;
if (llvm::error_code ec = llvm::MemoryBuffer::getSTDIN(SB)) {
@@ -664,7 +665,8 @@ bool CompilerInstance::InitializeSourceM
}
const FileEntry *File = FileMgr.getVirtualFile(SB->getBufferIdentifier(),
SB->getBufferSize(), 0);
- SourceMgr.createMainFileID(File, Kind);
+ SourceMgr.setMainFileID(
+ SourceMgr.createFileID(File, SourceLocation(), Kind));
SourceMgr.overrideFileContents(File, SB.release());
}
Modified: cfe/trunk/unittests/Basic/SourceManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/SourceManagerTest.cpp?rev=209266&r1=209265&r2=209266&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/SourceManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/SourceManagerTest.cpp Tue May 20 20:12:41 2014
@@ -75,7 +75,8 @@ TEST_F(SourceManagerTest, isBeforeInTran
"#define M(x) [x]\n"
"M(foo)";
MemoryBuffer *buf = MemoryBuffer::getMemBuffer(source);
- FileID mainFileID = SourceMgr.createMainFileIDForMemBuffer(buf);
+ FileID mainFileID = SourceMgr.createFileID(buf);
+ SourceMgr.setMainFileID(mainFileID);
VoidModuleLoader ModLoader;
HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts,
@@ -127,7 +128,8 @@ TEST_F(SourceManagerTest, getColumnNumbe
"int y;";
MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(Source);
- FileID MainFileID = SourceMgr.createMainFileIDForMemBuffer(Buf);
+ FileID MainFileID = SourceMgr.createFileID(Buf);
+ SourceMgr.setMainFileID(MainFileID);
bool Invalid;
@@ -186,7 +188,8 @@ TEST_F(SourceManagerTest, getMacroArgExp
MemoryBuffer *headerBuf = MemoryBuffer::getMemBuffer(header);
MemoryBuffer *mainBuf = MemoryBuffer::getMemBuffer(main);
- FileID mainFileID = SourceMgr.createMainFileIDForMemBuffer(mainBuf);
+ FileID mainFileID = SourceMgr.createFileID(mainBuf);
+ SourceMgr.setMainFileID(mainFileID);
const FileEntry *headerFile = FileMgr.getVirtualFile("/test-header.h",
headerBuf->getBufferSize(), 0);
@@ -284,7 +287,7 @@ TEST_F(SourceManagerTest, isBeforeInTran
MemoryBuffer *headerBuf = MemoryBuffer::getMemBuffer(header);
MemoryBuffer *mainBuf = MemoryBuffer::getMemBuffer(main);
- SourceMgr.createMainFileIDForMemBuffer(mainBuf);
+ SourceMgr.setMainFileID(SourceMgr.createFileID(mainBuf));
const FileEntry *headerFile = FileMgr.getVirtualFile("/test-header.h",
headerBuf->getBufferSize(), 0);
Modified: cfe/trunk/unittests/Lex/LexerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/LexerTest.cpp?rev=209266&r1=209265&r2=209266&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/LexerTest.cpp (original)
+++ cfe/trunk/unittests/Lex/LexerTest.cpp Tue May 20 20:12:41 2014
@@ -64,7 +64,7 @@ protected:
std::vector<Token> CheckLex(StringRef Source,
ArrayRef<tok::TokenKind> ExpectedTokens) {
MemoryBuffer *buf = MemoryBuffer::getMemBuffer(Source);
- (void) SourceMgr.createMainFileIDForMemBuffer(buf);
+ SourceMgr.setMainFileID(SourceMgr.createFileID(buf));
VoidModuleLoader ModLoader;
HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts,
Modified: cfe/trunk/unittests/Lex/PPCallbacksTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/PPCallbacksTest.cpp?rev=209266&r1=209265&r2=209266&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/PPCallbacksTest.cpp (original)
+++ cfe/trunk/unittests/Lex/PPCallbacksTest.cpp Tue May 20 20:12:41 2014
@@ -163,7 +163,7 @@ protected:
CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText,
const char* HeaderPath, bool SystemHeader) {
MemoryBuffer *Buf = MemoryBuffer::getMemBuffer(SourceText);
- (void)SourceMgr.createMainFileIDForMemBuffer(Buf);
+ SourceMgr.setMainFileID(SourceMgr.createFileID(Buf));
VoidModuleLoader ModLoader;
@@ -200,7 +200,7 @@ protected:
OpenCLLangOpts.OpenCL = 1;
MemoryBuffer* sourceBuf = MemoryBuffer::getMemBuffer(SourceText, "test.cl");
- (void)SourceMgr.createMainFileIDForMemBuffer(sourceBuf);
+ SourceMgr.setMainFileID(SourceMgr.createFileID(sourceBuf));
VoidModuleLoader ModLoader;
HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags,
Modified: cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp?rev=209266&r1=209265&r2=209266&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp (original)
+++ cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp Tue May 20 20:12:41 2014
@@ -92,7 +92,7 @@ TEST_F(PPConditionalDirectiveRecordTest,
"9\n";
MemoryBuffer *buf = MemoryBuffer::getMemBuffer(source);
- SourceMgr.createMainFileIDForMemBuffer(buf);
+ SourceMgr.setMainFileID(SourceMgr.createFileID(buf));
VoidModuleLoader ModLoader;
HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts,
More information about the cfe-commits
mailing list