summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorZhanyong Wan <wan@google.com>2010-10-05 17:56:33 +0000
committerZhanyong Wan <wan@google.com>2010-10-05 17:56:33 +0000
commitea6d7f332d444c3b66dee953c2db90ab07a53d9c (patch)
treef80aed424eabd144c4c1b0b4575390a84793d8ad /clang/lib/Basic/SourceManager.cpp
parent68e37439a94a51a3aee4ae444b7d8ed6702ef9f4 (diff)
downloadbcm5719-llvm-ea6d7f332d444c3b66dee953c2db90ab07a53d9c.tar.gz
bcm5719-llvm-ea6d7f332d444c3b66dee953c2db90ab07a53d9c.zip
Fix handling of the 'Invalid' argument in SourceManager's methods (patch by Dean Sturtevant, reviewed by chandlerc and Sebastian Redl).
llvm-svn: 115638
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 633d86c1eb8..650308b6dd2 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -796,16 +796,25 @@ unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
return FilePos-LineStart+1;
}
+// isInvalid - Return the result of calling loc.isInvalid(), and
+// if Invalid is not null, set its value to same.
+static bool isInvalid(SourceLocation Loc, bool *Invalid) {
+ bool MyInvalid = Loc.isInvalid();
+ if (Invalid)
+ *Invalid = MyInvalid;
+ return MyInvalid;
+}
+
unsigned SourceManager::getSpellingColumnNumber(SourceLocation Loc,
bool *Invalid) const {
- if (Loc.isInvalid()) return 0;
+ if (isInvalid(Loc, Invalid)) return 0;
std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
return getColumnNumber(LocInfo.first, LocInfo.second, Invalid);
}
unsigned SourceManager::getInstantiationColumnNumber(SourceLocation Loc,
bool *Invalid) const {
- if (Loc.isInvalid()) return 0;
+ if (isInvalid(Loc, Invalid)) return 0;
std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
return getColumnNumber(LocInfo.first, LocInfo.second, Invalid);
}
@@ -974,13 +983,13 @@ unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,
unsigned SourceManager::getInstantiationLineNumber(SourceLocation Loc,
bool *Invalid) const {
- if (Loc.isInvalid()) return 0;
+ if (isInvalid(Loc, Invalid)) return 0;
std::pair<FileID, unsigned> LocInfo = getDecomposedInstantiationLoc(Loc);
return getLineNumber(LocInfo.first, LocInfo.second);
}
unsigned SourceManager::getSpellingLineNumber(SourceLocation Loc,
bool *Invalid) const {
- if (Loc.isInvalid()) return 0;
+ if (isInvalid(Loc, Invalid)) return 0;
std::pair<FileID, unsigned> LocInfo = getDecomposedSpellingLoc(Loc);
return getLineNumber(LocInfo.first, LocInfo.second);
}
@@ -1021,7 +1030,7 @@ SourceManager::getFileCharacteristic(SourceLocation Loc) const {
/// for normal clients.
const char *SourceManager::getBufferName(SourceLocation Loc,
bool *Invalid) const {
- if (Loc.isInvalid()) return "<invalid loc>";
+ if (isInvalid(Loc, Invalid)) return "<invalid loc>";
return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
}
OpenPOWER on IntegriCloud