summaryrefslogtreecommitdiffstats
path: root/clang/Lex
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-12-09 20:31:55 +0000
committerChris Lattner <sabre@nondot.org>2007-12-09 20:31:55 +0000
commit615315f30787266701bb4fefb00a86b3f67ff9db (patch)
tree746787818a538fa769632db1522312b7af007e6e /clang/Lex
parent64443973c0c1f68625413cd50ffecd8b812b19af (diff)
downloadbcm5719-llvm-615315f30787266701bb4fefb00a86b3f67ff9db.tar.gz
bcm5719-llvm-615315f30787266701bb4fefb00a86b3f67ff9db.zip
Add dumping support for locations, make -dumptokens print out the location
info of each token. llvm-svn: 44741
Diffstat (limited to 'clang/Lex')
-rw-r--r--clang/Lex/Preprocessor.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp
index a685b0b27b8..d2630584a59 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 << " <PhysLoc=";
+ DumpLocation(PhysLoc);
+ 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!");
- }
+ }
}
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud