[cfe-commits] r44741 - in /cfe/trunk: Lex/Preprocessor.cpp include/clang/Lex/Preprocessor.h
Chris Lattner
sabre at nondot.org
Sun Dec 9 12:31:55 PST 2007
Author: lattner
Date: Sun Dec 9 14:31:55 2007
New Revision: 44741
URL: http://llvm.org/viewvc/llvm-project?rev=44741&view=rev
Log:
Add dumping support for locations, make -dumptokens print out the location
info of each token.
Modified:
cfe/trunk/Lex/Preprocessor.cpp
cfe/trunk/include/clang/Lex/Preprocessor.h
Modified: cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Preprocessor.cpp?rev=44741&r1=44740&r2=44741&view=diff
==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Sun Dec 9 14:31:55 2007
@@ -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!");
- }
+ }
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=44741&r1=44740&r2=44741&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sun Dec 9 14:31:55 2007
@@ -310,6 +310,7 @@
/// 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
More information about the cfe-commits
mailing list