this massive patch introduces a simple new abstraction: it makes
"FileID" a concept that is now enforced by the compiler's type checker
instead of yet-another-random-unsigned floating around.
This is an important distinction from the "FileID" currently tracked by
SourceLocation. *That* FileID may refer to the start of a file or to a
chunk within it. The new FileID *only* refers to the file (and its
#include stack and eventually #line data), it cannot refer to a chunk.
FileID is a completely opaque datatype to all clients, only SourceManager
is allowed to poke and prod it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62407 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp
index bbe0f5c..976e1a2 100644
--- a/lib/Lex/Preprocessor.cpp
+++ b/lib/Lex/Preprocessor.cpp
@@ -200,9 +200,7 @@
if (PTH) {
SourceLocation SLoc = SourceMgr.getSpellingLoc(Tok.getLocation());
- unsigned fid = SourceMgr.getCanonicalFileID(SLoc);
- unsigned fpos = SourceMgr.getFullFilePos(SLoc);
- if (unsigned Len = PTH->getSpelling(fid, fpos, TokStart)) {
+ if (unsigned Len = PTH->getSpelling(SLoc, TokStart)) {
assert(!Tok.needsCleaning());
return std::string(TokStart, TokStart+Len);
}
@@ -256,10 +254,8 @@
if (CurPTHLexer) {
Len = CurPTHLexer.get()->getSpelling(Tok.getLocation(), Buffer);
} else {
- SourceLocation SLoc = SourceMgr.getSpellingLoc(Tok.getLocation());
- unsigned FID = SourceMgr.getCanonicalFileID(SLoc);
- unsigned FPos = SourceMgr.getFullFilePos(SLoc);
- Len = PTH->getSpelling(FID, FPos, Buffer);
+ Len = PTH->getSpelling(SourceMgr.getSpellingLoc(Tok.getLocation()),
+ Buffer);
}
// Did we find a spelling? If so return its length. Otherwise fall
@@ -656,15 +652,14 @@
/// which implicitly adds the builtin defines etc.
void Preprocessor::EnterMainSourceFile() {
- unsigned MainFileID = SourceMgr.getMainFileID();
+ FileID MainFileID = SourceMgr.getMainFileID();
// Enter the main file source buffer.
EnterSourceFile(MainFileID, 0);
// Tell the header info that the main file was entered. If the file is later
// #imported, it won't be re-entered.
- if (const FileEntry *FE =
- SourceMgr.getFileEntryForLoc(SourceLocation::getFileLoc(MainFileID, 0)))
+ if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID))
HeaderInfo.IncrementIncludeCount(FE);
std::vector<char> PrologFile;
@@ -685,11 +680,11 @@
llvm::MemoryBuffer::getMemBufferCopy(&PrologFile.front(),&PrologFile.back(),
"<predefines>");
assert(SB && "Cannot fail to create predefined source buffer");
- unsigned FileID = SourceMgr.createFileIDForMemBuffer(SB);
- assert(FileID && "Could not create FileID for predefines?");
+ FileID FID = SourceMgr.createFileIDForMemBuffer(SB);
+ assert(!FID.isInvalid() && "Could not create FileID for predefines?");
// Start parsing the predefines.
- EnterSourceFile(FileID, 0);
+ EnterSourceFile(FID, 0);
}