r252206 - Improve macro dumping to preserve semantically-relevant spelling information.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 5 12:55:15 PST 2015


Author: rsmith
Date: Thu Nov  5 14:55:14 2015
New Revision: 252206

URL: http://llvm.org/viewvc/llvm-project?rev=252206&view=rev
Log:
Improve macro dumping to preserve semantically-relevant spelling information.

Modified:
    cfe/trunk/lib/Lex/MacroInfo.cpp

Modified: cfe/trunk/lib/Lex/MacroInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=252206&r1=252205&r2=252206&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/MacroInfo.cpp (original)
+++ cfe/trunk/lib/Lex/MacroInfo.cpp Thu Nov  5 14:55:14 2015
@@ -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();
   }




More information about the cfe-commits mailing list