From: Richard Smith Date: Thu, 5 Nov 2015 20:55:14 +0000 (+0000) Subject: Improve macro dumping to preserve semantically-relevant spelling information. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3aa919df2730d506ce5f1f526472446b5e8f805d;p=clang Improve macro dumping to preserve semantically-relevant spelling information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252206 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/MacroInfo.cpp b/lib/Lex/MacroInfo.cpp index 109b6c12b8..0b4292fbea 100644 --- a/lib/Lex/MacroInfo.cpp +++ b/lib/Lex/MacroInfo.cpp @@ -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(); }