Add dumping support for locations, make -dumptokens print out the location
info of each token.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44741 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp
index a685b0b..d263058 100644
--- a/Lex/Preprocessor.cpp
+++ b/Lex/Preprocessor.cpp
@@ -133,6 +133,7 @@
<< getSpelling(Tok) << "'";
if (!DumpFlags) return;
+
std::cerr << "\t";
if (Tok.isAtStartOfLine())
std::cerr << " [StartOfLine]";
@@ -145,6 +146,24 @@
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 @@
Tok.setLocation(CreateString(TmpBuffer, Len, Tok.getLocation()));
} else {
assert(0 && "Unknown identifier!");
- }
+ }
}
//===----------------------------------------------------------------------===//