From 615315f30787266701bb4fefb00a86b3f67ff9db Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 9 Dec 2007 20:31:55 +0000 Subject: [PATCH] Add dumping support for locations, make -dumptokens print out the location info of each token. llvm-svn: 44741 --- clang/Lex/Preprocessor.cpp | 21 ++++++++++++++++++++- clang/include/clang/Lex/Preprocessor.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp index a685b0b27b8c..d2630584a598 100644 --- a/clang/Lex/Preprocessor.cpp +++ b/clang/Lex/Preprocessor.cpp @@ -133,6 +133,7 @@ void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const { << getSpelling(Tok) << "'"; if (!DumpFlags) return; + std::cerr << "\t"; if (Tok.isAtStartOfLine()) std::cerr << " [StartOfLine]"; @@ -145,6 +146,24 @@ void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const { std::cerr << " [UnClean='" << std::string(Start, Start+Tok.getLength()) << "']"; } + + std::cerr << "\tLoc=<"; + DumpLocation(Tok.getLocation()); + std::cerr << ">"; +} + +void Preprocessor::DumpLocation(SourceLocation Loc) const { + SourceLocation LogLoc = SourceMgr.getLogicalLoc(Loc); + std::cerr << SourceMgr.getSourceName(LogLoc) << ':' + << SourceMgr.getLineNumber(LogLoc) << ':' + << SourceMgr.getLineNumber(LogLoc); + + SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(Loc); + if (PhysLoc != LogLoc) { + std::cerr << " "; + } } void Preprocessor::DumpMacro(const MacroInfo &MI) const { @@ -1140,7 +1159,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { Tok.setLocation(CreateString(TmpBuffer, Len, Tok.getLocation())); } else { assert(0 && "Unknown identifier!"); - } + } } //===----------------------------------------------------------------------===// diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 707a93243fe3..98b946ab5488 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -310,6 +310,7 @@ public: /// DumpToken - Print the token to stderr, used for debugging. /// void DumpToken(const Token &Tok, bool DumpFlags = false) const; + void DumpLocation(SourceLocation Loc) const; void DumpMacro(const MacroInfo &MI) const; /// AdvanceToTokenCharacter - Given a location that specifies the start of a