]> granicus.if.org Git - clang/commitdiff
Improve macro dumping to preserve semantically-relevant spelling information.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Nov 2015 20:55:14 +0000 (20:55 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Nov 2015 20:55:14 +0000 (20:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252206 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/MacroInfo.cpp

index 109b6c12b89b7e4a365f44d3feb8819617800144..0b4292fbeae52705ea011c9124ecc638008fd723 100644 (file)
@@ -154,16 +154,20 @@ void MacroInfo::dump() const {
     Out << ")";
   }
 
+  bool First = true;
   for (const Token &Tok : ReplacementTokens) {
-    Out << " ";
+    // Leading space is semantically meaningful in a macro definition,
+    // so preserve it in the dump output.
+    if (First || Tok.hasLeadingSpace())
+      Out << " ";
+    First = false;
+
     if (const char *Punc = tok::getPunctuatorSpelling(Tok.getKind()))
       Out << Punc;
-    else if (const char *Kwd = tok::getKeywordSpelling(Tok.getKind()))
-      Out << Kwd;
-    else if (Tok.is(tok::identifier))
-      Out << Tok.getIdentifierInfo()->getName();
     else if (Tok.isLiteral() && Tok.getLiteralData())
       Out << StringRef(Tok.getLiteralData(), Tok.getLength());
+    else if (auto *II = Tok.getIdentifierInfo())
+      Out << II->getName();
     else
       Out << Tok.getName();
   }