diff options
author | Chris Lattner <sabre@nondot.org> | 2008-09-29 21:46:13 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-09-29 21:46:13 +0000 |
commit | d9a663aeb9d10869b1a84a7f05d4a4f06f546a35 (patch) | |
tree | 76a96fdac9fc3e26aab9db56192f59a59d3c21ac /clang/lib/Basic/SourceLocation.cpp | |
parent | 9bb37fec6a73196ea36ba248e1b7fa3d5f4821fe (diff) | |
download | llvm-d9a663aeb9d10869b1a84a7f05d4a4f06f546a35.zip llvm-d9a663aeb9d10869b1a84a7f05d4a4f06f546a35.tar.gz llvm-d9a663aeb9d10869b1a84a7f05d4a4f06f546a35.tar.bz2 |
Make some methods const, add some helpers to FullSourceLoc,
and add a dump method to FullSourceLoc! Patch by Nico Weber!
llvm-svn: 56806
Diffstat (limited to 'clang/lib/Basic/SourceLocation.cpp')
-rw-r--r-- | clang/lib/Basic/SourceLocation.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp index 12a4962..5236bfa 100644 --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -16,7 +16,6 @@ #include "clang/Basic/SourceManager.h" #include "llvm/Bitcode/Serialize.h" #include "llvm/Bitcode/Deserialize.h" - using namespace clang; void SourceLocation::Emit(llvm::Serializer& S) const { @@ -38,14 +37,19 @@ SourceRange SourceRange::ReadVal(llvm::Deserializer& D) { return SourceRange(A,B); } -FullSourceLoc FullSourceLoc::getLogicalLoc() { +FullSourceLoc FullSourceLoc::getLogicalLoc() const { + assert (isValid()); + return FullSourceLoc(SrcMgr->getLogicalLoc(Loc), *SrcMgr); +} + +FullSourceLoc FullSourceLoc::getPhysicalLoc() const { assert (isValid()); - return FullSourceLoc(SrcMgr->getLogicalLoc(Loc),*SrcMgr); + return FullSourceLoc(SrcMgr->getPhysicalLoc(Loc), *SrcMgr); } -FullSourceLoc FullSourceLoc::getIncludeLoc() { +FullSourceLoc FullSourceLoc::getIncludeLoc() const { assert (isValid()); - return FullSourceLoc(SrcMgr->getIncludeLoc(Loc),*SrcMgr); + return FullSourceLoc(SrcMgr->getIncludeLoc(Loc), *SrcMgr); } unsigned FullSourceLoc::getLineNumber() const { @@ -69,6 +73,16 @@ unsigned FullSourceLoc::getLogicalColumnNumber() const { return SrcMgr->getLogicalColumnNumber(Loc); } +unsigned FullSourceLoc::getPhysicalLineNumber() const { + assert (isValid()); + return SrcMgr->getPhysicalLineNumber(Loc); +} + +unsigned FullSourceLoc::getPhysicalColumnNumber() const { + assert (isValid()); + return SrcMgr->getPhysicalColumnNumber(Loc); +} + const char* FullSourceLoc::getSourceName() const { assert (isValid()); return SrcMgr->getSourceName(Loc); @@ -98,3 +112,23 @@ const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const { unsigned FullSourceLoc::getCanonicalFileID() const { return SrcMgr->getCanonicalFileID(Loc); } + +void FullSourceLoc::dump() const { + if (!isValid()) { + fprintf(stderr, "Invalid Loc\n"); + return; + } + + if (isFileID()) { + // The logical and physical pos is identical for file locs. + fprintf(stderr, "File Loc from '%s': %d: %d\n", + getSourceName(), getLogicalLineNumber(), + getLogicalColumnNumber()); + } else { + fprintf(stderr, "Macro Loc (\n Physical: "); + getPhysicalLoc().dump(); + fprintf(stderr, " Logical: "); + getLogicalLoc().dump(); + fprintf(stderr, ")\n"); + } +} |