From: Daniel Marjamaki Date: Mon, 11 May 2015 08:25:54 +0000 (+0000) Subject: Refactor MacroInfo so range for loops can be used to iterate its tokens. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dbb471465f63304bed11ab1f75f1946a76250910;p=clang Refactor MacroInfo so range for loops can be used to iterate its tokens. Differential Revision: http://reviews.llvm.org/D9079 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236975 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h index fdd422f160..81d075cb00 100644 --- a/include/clang/Lex/MacroInfo.h +++ b/include/clang/Lex/MacroInfo.h @@ -245,6 +245,7 @@ public: tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); } tokens_iterator tokens_end() const { return ReplacementTokens.end(); } bool tokens_empty() const { return ReplacementTokens.empty(); } + ArrayRef tokens() const { return ReplacementTokens; } /// \brief Add the specified token to the replacement text for the macro. void AddTokenToBody(const Token &Tok) { diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index 8ca36489ee..037a6a525e 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -64,12 +64,11 @@ static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI, OS << ' '; SmallString<128> SpellingBuffer; - for (MacroInfo::tokens_iterator I = MI.tokens_begin(), E = MI.tokens_end(); - I != E; ++I) { - if (I->hasLeadingSpace()) + for (const auto &T : MI.tokens()) { + if (T.hasLeadingSpace()) OS << ' '; - OS << PP.getSpelling(*I, SpellingBuffer); + OS << PP.getSpelling(T, SpellingBuffer); } }