]> granicus.if.org Git - clang/commitdiff
Add dumping support for locations, make -dumptokens print out the location
authorChris Lattner <sabre@nondot.org>
Sun, 9 Dec 2007 20:31:55 +0000 (20:31 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 9 Dec 2007 20:31:55 +0000 (20:31 +0000)
info of each token.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44741 91177308-0d34-0410-b5e6-96231b3b80d8

Lex/Preprocessor.cpp
include/clang/Lex/Preprocessor.h

index a685b0b27b8cc15abd29696022a4b62cb72150d0..d2630584a59811e18e58002c0176bc5f5ac76eac 100644 (file)
@@ -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!");
-  }  
+  }
 }
 
 //===----------------------------------------------------------------------===//
index 707a93243fe393b8c2c83fe2765bf4a919213f5a..98b946ab54880db1937af1bb120544c991896c2c 100644 (file)
@@ -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