summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Basic/SourceLocation.cpp6
-rw-r--r--clang/lib/Basic/SourceManager.cpp12
-rw-r--r--clang/lib/Driver/TextDiagnosticPrinter.cpp16
-rw-r--r--clang/lib/Lex/Lexer.cpp4
4 files changed, 23 insertions, 15 deletions
diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp
index 84fac86a6df..dcfd547eec4 100644
--- a/clang/lib/Basic/SourceLocation.cpp
+++ b/clang/lib/Basic/SourceLocation.cpp
@@ -37,6 +37,12 @@ SourceRange SourceRange::ReadVal(llvm::Deserializer& D) {
return SourceRange(A,B);
}
+FileID FullSourceLoc::getFileID() const {
+ assert(isValid());
+ return SrcMgr->getCanonicalFileID(*this);
+}
+
+
FullSourceLoc FullSourceLoc::getInstantiationLoc() const {
assert(isValid());
return FullSourceLoc(SrcMgr->getInstantiationLoc(*this), *SrcMgr);
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index b6c4ffab4db..f793c978ccb 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -121,7 +121,7 @@ FileID SourceManager::createFileID(const ContentCache *File,
unsigned FileSize = File->getSize();
if (FileSize+1 < (1 << SourceLocation::FilePosBits)) {
FileIDs.push_back(FileIDInfo::get(IncludePos, 0, File, FileCharacter));
- assert(FileIDs.size() < (1 << SourceLocation::FileIDBits) &&
+ assert(FileIDs.size() < (1 << SourceLocation::ChunkIDBits) &&
"Ran out of file ID's!");
return FileID::Create(FileIDs.size());
}
@@ -138,7 +138,7 @@ FileID SourceManager::createFileID(const ContentCache *File,
FileSize -= (1 << SourceLocation::FilePosBits);
}
- assert(FileIDs.size() < (1 << SourceLocation::FileIDBits) &&
+ assert(FileIDs.size() < (1 << SourceLocation::ChunkIDBits) &&
"Ran out of file ID's!");
return FileID::Create(Result);
}
@@ -165,7 +165,7 @@ SourceLocation SourceManager::getInstantiationLoc(SourceLocation SpellingLoc,
// The instanitation point and source SpellingLoc have to exactly match to
// reuse (for now). We could allow "nearby" instantiations in the future.
if (LastOne.getInstantiationLoc() != InstantLoc ||
- LastOne.getSpellingLoc().getFileID() != SpellingLoc.getFileID())
+ LastOne.getSpellingLoc().getChunkID() != SpellingLoc.getChunkID())
continue;
// Check to see if the spellloc of the token came from near enough to reuse.
@@ -215,7 +215,7 @@ const char *SourceManager::getCharacterData(SourceLocation SL) const {
/// this is significantly cheaper to compute than the line number. This returns
/// zero if the column number isn't known.
unsigned SourceManager::getColumnNumber(SourceLocation Loc) const {
- if (Loc.getFileID() == 0) return 0;
+ if (Loc.getChunkID() == 0) return 0;
std::pair<FileID, unsigned> LocInfo = getDecomposedFileLoc(Loc);
unsigned FilePos = LocInfo.second;
@@ -232,7 +232,7 @@ unsigned SourceManager::getColumnNumber(SourceLocation Loc) const {
/// the SourceLocation specifies. This can be modified with #line directives,
/// etc.
const char *SourceManager::getSourceName(SourceLocation Loc) const {
- if (Loc.getFileID() == 0) return "";
+ if (Loc.getChunkID() == 0) return "";
// To get the source name, first consult the FileEntry (if one exists) before
// the MemBuffer as this will avoid unnecessarily paging in the MemBuffer.
@@ -290,7 +290,7 @@ static void ComputeLineNumbers(ContentCache* FI) {
/// line offsets for the MemoryBuffer, so this is not cheap: use only when
/// about to emit a diagnostic.
unsigned SourceManager::getLineNumber(SourceLocation Loc) const {
- if (Loc.getFileID() == 0) return 0;
+ if (Loc.getChunkID() == 0) return 0;
ContentCache *Content;
diff --git a/clang/lib/Driver/TextDiagnosticPrinter.cpp b/clang/lib/Driver/TextDiagnosticPrinter.cpp
index 8523723278f..4080b748ad5 100644
--- a/clang/lib/Driver/TextDiagnosticPrinter.cpp
+++ b/clang/lib/Driver/TextDiagnosticPrinter.cpp
@@ -36,8 +36,8 @@ PrintIncludeStack(FullSourceLoc Pos) {
/// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s)
/// any characters in LineNo that intersect the SourceRange.
void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
- const SourceManager& SourceMgr,
- unsigned LineNo, unsigned FileID,
+ const SourceManager &SourceMgr,
+ unsigned LineNo, FileID FID,
std::string &CaretLine,
const std::string &SourceLine) {
assert(CaretLine.size() == SourceLine.size() &&
@@ -47,12 +47,14 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
SourceLocation InstantiationStart =
SourceMgr.getInstantiationLoc(R.getBegin());
unsigned StartLineNo = SourceMgr.getLineNumber(InstantiationStart);
- if (StartLineNo > LineNo || InstantiationStart.getFileID() != FileID)
+ if (StartLineNo > LineNo ||
+ SourceMgr.getCanonicalFileID(InstantiationStart) != FID)
return; // No intersection.
SourceLocation InstantiationEnd = SourceMgr.getInstantiationLoc(R.getEnd());
unsigned EndLineNo = SourceMgr.getLineNumber(InstantiationEnd);
- if (EndLineNo < LineNo || InstantiationEnd.getFileID() != FileID)
+ if (EndLineNo < LineNo ||
+ SourceMgr.getCanonicalFileID(InstantiationEnd) != FID)
return; // No intersection.
// Compute the column number of the start.
@@ -98,14 +100,14 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
const DiagnosticInfo &Info) {
unsigned LineNo = 0, ColNo = 0;
- unsigned FileID = 0;
+ FileID FID;
const char *LineStart = 0, *LineEnd = 0;
const FullSourceLoc &Pos = Info.getLocation();
if (Pos.isValid()) {
FullSourceLoc LPos = Pos.getInstantiationLoc();
+ FID = LPos.getFileID();
LineNo = LPos.getLineNumber();
- FileID = LPos.getFileID();
// First, if this diagnostic is not in the main file, print out the
// "included from" lines.
@@ -161,7 +163,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
// Highlight all of the characters covered by Ranges with ~ characters.
for (unsigned i = 0; i != Info.getNumRanges(); ++i)
- HighlightRange(Info.getRange(i), Pos.getManager(), LineNo, FileID,
+ HighlightRange(Info.getRange(i), Pos.getManager(), LineNo, FID,
CaretLine, SourceLine);
// Next, insert the caret itself.
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 90785b5e193..6e5402e8a37 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -321,7 +321,7 @@ static SourceLocation GetMappedTokenLoc(Preprocessor &PP,
// characters come from spelling(FileLoc)+Offset.
SourceLocation InstLoc = SourceMgr.getInstantiationLoc(FileLoc);
SourceLocation SpellingLoc = SourceMgr.getSpellingLoc(FileLoc);
- SpellingLoc = SourceLocation::getFileLoc(SpellingLoc.getFileID(), CharNo);
+ SpellingLoc = SourceLocation::getFileLoc(SpellingLoc.getChunkID(), CharNo);
return SourceMgr.getInstantiationLoc(SpellingLoc, InstLoc);
}
@@ -335,7 +335,7 @@ SourceLocation Lexer::getSourceLocation(const char *Loc) const {
// the file id from FileLoc with the offset specified.
unsigned CharNo = Loc-BufferStart;
if (FileLoc.isFileID())
- return SourceLocation::getFileLoc(FileLoc.getFileID(), CharNo);
+ return SourceLocation::getFileLoc(FileLoc.getChunkID(), CharNo);
// Otherwise, this is the _Pragma lexer case, which pretends that all of the
// tokens are lexed from where the _Pragma was defined.
OpenPOWER on IntegriCloud