diff options
author | Chris Lattner <sabre@nondot.org> | 2009-01-27 07:57:44 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-01-27 07:57:44 +0000 |
commit | f1ca7d3e02e0fb4d5fa6ed56459a31776e82a605 (patch) | |
tree | 872fc3a12f4820197ea23bf6e061c048bdce7b14 /clang/lib/Basic/SourceLocation.cpp | |
parent | c360bf2e4868ec6455cea10e26764456098adc5e (diff) | |
download | llvm-f1ca7d3e02e0fb4d5fa6ed56459a31776e82a605.zip llvm-f1ca7d3e02e0fb4d5fa6ed56459a31776e82a605.tar.gz llvm-f1ca7d3e02e0fb4d5fa6ed56459a31776e82a605.tar.bz2 |
Introduce a new PresumedLoc class to represent the concept of a location
as reported to the user and as manipulated by #line. This is what __FILE__,
__INCLUDE_LEVEL__, diagnostics and other things should follow (but not
dependency generation!).
This patch also includes several cleanups along the way:
- SourceLocation now has a dump method, and several other places
that did similar things now use it.
- I cleaned up some code in AnalysisConsumer, but it should probably be
simplified further now that NamedDecl is better.
- TextDiagnosticPrinter is now simplified and cleaned up a bit.
This patch is a prerequisite for #line, but does not actually provide
any #line functionality.
llvm-svn: 63098
Diffstat (limited to 'clang/lib/Basic/SourceLocation.cpp')
-rw-r--r-- | clang/lib/Basic/SourceLocation.cpp | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp index f0c8274..5d48472 100644 --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -26,6 +26,29 @@ SourceLocation SourceLocation::ReadVal(llvm::Deserializer& D) { return SourceLocation::getFromRawEncoding(D.ReadInt()); } +void SourceLocation::dump(const SourceManager &SM) const { + if (!isValid()) { + fprintf(stderr, "<invalid loc>"); + return; + } + + if (isFileID()) { + PresumedLoc PLoc = SM.getPresumedLoc(*this); + + // The instantiation and spelling pos is identical for file locs. + fprintf(stderr, "%s:%d:%d", + PLoc.getFilename(), PLoc.getLine(), PLoc.getColumn()); + return; + } + + SM.getInstantiationLoc(*this).dump(SM); + + fprintf(stderr, " <Spelling="); + SM.getSpellingLoc(*this).dump(SM); + fprintf(stderr, ">"); +} + + void SourceRange::Emit(llvm::Serializer& S) const { B.Emit(S); E.Emit(S); @@ -53,11 +76,6 @@ FullSourceLoc FullSourceLoc::getSpellingLoc() const { return FullSourceLoc(SrcMgr->getSpellingLoc(*this), *SrcMgr); } -FullSourceLoc FullSourceLoc::getIncludeLoc() const { - assert(isValid()); - return FullSourceLoc(SrcMgr->getIncludeLoc(*this), *SrcMgr); -} - unsigned FullSourceLoc::getLineNumber() const { assert(isValid()); return SrcMgr->getLineNumber(*this); @@ -89,11 +107,6 @@ unsigned FullSourceLoc::getSpellingColumnNumber() const { return SrcMgr->getSpellingColumnNumber(*this); } -const char* FullSourceLoc::getSourceName() const { - assert(isValid()); - return SrcMgr->getSourceName(*this); -} - bool FullSourceLoc::isInSystemHeader() const { assert(isValid()); return SrcMgr->isInSystemHeader(*this); @@ -109,22 +122,3 @@ const llvm::MemoryBuffer* FullSourceLoc::getBuffer() const { return SrcMgr->getBuffer(SrcMgr->getFileID(*this)); } -void FullSourceLoc::dump() const { - if (!isValid()) { - fprintf(stderr, "Invalid Loc\n"); - return; - } - - if (isFileID()) { - // The instantiation and spelling pos is identical for file locs. - fprintf(stderr, "File Loc from '%s': %d: %d\n", - getSourceName(), getInstantiationLineNumber(), - getInstantiationColumnNumber()); - } else { - fprintf(stderr, "Macro Loc (\n Spelling: "); - getSpellingLoc().dump(); - fprintf(stderr, " Instantiation: "); - getInstantiationLoc().dump(); - fprintf(stderr, ")\n"); - } -} |