<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, May 22, 2015 at 10:23 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Sebastian Edman <<a href="mailto:sebastian.edman@evidente.se">sebastian.edman@evidente.se</a>> writes:<br>
> Hi alexfh, danielmarjamaki,<br>
><br>
> Added possibilty to extract the arguments in a MacroInfo as a<br>
> container in order to use C++11 style for loops.<br>
><br>
> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D9934&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=tN5fi2eoacUO84E4rfiAt8FjWbyMgvLs9qOGyFvb1Hw&s=bGNQWrmsiD-lErZ8r_I3Sm064DNVCjs1J_zK1fg7BrE&e=" target="_blank">http://reviews.llvm.org/D9934</a><br>
><br>
> Files:<br>
>   include/clang/Lex/MacroInfo.h<br>
>   lib/Lex/PPMacroExpansion.cpp<br>
>   lib/Serialization/ASTWriter.cpp<br>
><br>
> Index: include/clang/Lex/MacroInfo.h<br>
> ===================================================================<br>
> --- include/clang/Lex/MacroInfo.h<br>
> +++ include/clang/Lex/MacroInfo.h<br>
> @@ -182,6 +182,9 @@<br>
>    bool arg_empty() const { return NumArguments == 0; }<br>
>    arg_iterator arg_begin() const { return ArgumentList; }<br>
>    arg_iterator arg_end() const { return ArgumentList+NumArguments; }<br>
> +  ArrayRef<IdentifierInfo*> args() const {<br>
> +       return ArrayRef<IdentifierInfo*>(ArgumentList, NumArguments);<br>
> +  }<br>
<br>
</span>It's probably better to use iterator_range from llvm/ADT/iterator_range.h.<br></blockquote><div><br></div><div>Can you explain why you think it's better than ArrayRef here?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Something like:<br>
<br>
  llvm::iterator_range<arg_iterator> args() const {<br>
    llvm::make_range(arg_begin(), arg_end());<br>
<span class="">  }<br>
<br>
>    unsigned getNumArgs() const { return NumArguments; }<br>
><br>
>    /// \brief Return the argument number of the specified identifier,<br>
> Index: lib/Serialization/ASTWriter.cpp<br>
> ===================================================================<br>
> --- lib/Serialization/ASTWriter.cpp<br>
> +++ lib/Serialization/ASTWriter.cpp<br>
> @@ -2135,9 +2135,8 @@<br>
>        Record.push_back(MI->isGNUVarargs());<br>
>        Record.push_back(MI->hasCommaPasting());<br>
>        Record.push_back(MI->getNumArgs());<br>
> -      for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();<br>
> -           I != E; ++I)<br>
> -        AddIdentifierRef(*I, Record);<br>
> +      for (const auto &I : MI->args())<br>
> +        AddIdentifierRef(I, Record);<br>
<br>
</span>Don't use "I" with iterator ranges - name the variable after what it is<br>
(Arg, or something like that).<br>
<span class=""><br>
>      }<br>
><br>
>      // If we have a detailed preprocessing record, record the macro definition<br>
> Index: lib/Lex/PPMacroExpansion.cpp<br>
> ===================================================================<br>
> --- lib/Lex/PPMacroExpansion.cpp<br>
> +++ lib/Lex/PPMacroExpansion.cpp<br>
> @@ -362,9 +362,8 @@<br>
><br>
>    // If this is a function-like macro invocation, it's safe to trivially expand<br>
>    // as long as the identifier is not a macro argument.<br>
> -  for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();<br>
> -       I != E; ++I)<br>
> -    if (*I == II)<br>
> +  for (const auto &I : MI->args())<br>
> +    if (I == II)<br>
>        return false;   // Identifier is a macro argument.<br>
><br>
>    return true;<br>
><br>
> EMAIL PREFERENCES<br>
>   <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_settings_panel_emailpreferences_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=BSqEv9KvKMW_Ob8SyngJ70KdZISM_ASROnREeq0cCxk&m=tN5fi2eoacUO84E4rfiAt8FjWbyMgvLs9qOGyFvb1Hw&s=a0ZKqk608yi5bRK65mMEY_GkVy4zoEluHq7Ev6kKD_Y&e=" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
><br>
</span>> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><div><br></div>
</div></div>