r238547 - Refactor MacroInfo so macro arguments can be iterated with range-based for loops.

David Blaikie dblaikie at gmail.com
Fri May 29 10:35:53 PDT 2015


On Fri, May 29, 2015 at 2:15 AM, Daniel Marjamaki <
daniel.marjamaki at evidente.se> wrote:

> Author: danielmarjamaki
> Date: Fri May 29 04:15:24 2015
> New Revision: 238547
>
> URL: http://llvm.org/viewvc/llvm-project?rev=238547&view=rev
> Log:
> Refactor MacroInfo so macro arguments can be iterated with range-based for
> loops.
>
> No functional change intended.
>
> Patch by Sebastian Edman!
>
> Modified:
>     cfe/trunk/include/clang/Lex/MacroInfo.h
>     cfe/trunk/lib/Lex/PPMacroExpansion.cpp
>     cfe/trunk/lib/Serialization/ASTWriter.cpp
>
> Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=238547&r1=238546&r2=238547&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
> +++ cfe/trunk/include/clang/Lex/MacroInfo.h Fri May 29 04:15:24 2015
> @@ -178,10 +178,13 @@ public:
>    arg_iterator arg_begin() const { return ArgumentList; }
>    arg_iterator arg_end() const { return ArgumentList + NumArguments; }
>    unsigned getNumArgs() const { return NumArguments; }
> +  ArrayRef<const IdentifierInfo *> args() const {
> +    return ArrayRef<const IdentifierInfo *>(ArgumentList, NumArguments);
>

Perhaps we should just roll these two members into one ArrayRef member to
begin with?


> +  }
>
>    /// \brief Return the argument number of the specified identifier,
>    /// or -1 if the identifier is not a formal argument identifier.
> -  int getArgumentNum(IdentifierInfo *Arg) const {
> +  int getArgumentNum(const IdentifierInfo *Arg) const {
>      for (arg_iterator I = arg_begin(), E = arg_end(); I != E; ++I)
>        if (*I == Arg)
>          return I - arg_begin();
>
> Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=238547&r1=238546&r2=238547&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
> +++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Fri May 29 04:15:24 2015
> @@ -362,12 +362,8 @@ static bool isTrivialSingleTokenExpansio
>
>    // If this is a function-like macro invocation, it's safe to trivially
> expand
>    // as long as the identifier is not a macro argument.
> -  for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();
> -       I != E; ++I)
> -    if (*I == II)
> -      return false;   // Identifier is a macro argument.
> +  return std::find(MI->arg_begin(), MI->arg_end(), II) == MI->arg_end();
>
> -  return true;
>  }
>
>
>
> Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=238547&r1=238546&r2=238547&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri May 29 04:15:24 2015
> @@ -2135,9 +2135,8 @@ void ASTWriter::WritePreprocessor(const
>        Record.push_back(MI->isGNUVarargs());
>        Record.push_back(MI->hasCommaPasting());
>        Record.push_back(MI->getNumArgs());
> -      for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();
> -           I != E; ++I)
> -        AddIdentifierRef(*I, Record);
> +      for (const IdentifierInfo *Arg : MI->args())
> +        AddIdentifierRef(Arg, Record);
>      }
>
>      // If we have a detailed preprocessing record, record the macro
> definition
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150529/78e88bc4/attachment.html>


More information about the cfe-commits mailing list