From: Daniel Marjamaki Date: Fri, 29 May 2015 09:15:24 +0000 (+0000) Subject: Refactor MacroInfo so macro arguments can be iterated with range-based for loops. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f1fdc07f94a53eaa49b0cd31948a5b256f9aecff;p=clang Refactor MacroInfo so macro arguments can be iterated with range-based for loops. No functional change intended. Patch by Sebastian Edman! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238547 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h index 73f140f5e8..8b82a5bc93 100644 --- a/include/clang/Lex/MacroInfo.h +++ b/include/clang/Lex/MacroInfo.h @@ -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 args() const { + return ArrayRef(ArgumentList, NumArguments); + } /// \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(); diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 9046ad51c1..03784e2045 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -362,12 +362,8 @@ static bool isTrivialSingleTokenExpansion(const MacroInfo *MI, // 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; } diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index bf74c8471c..e689234c20 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -2135,9 +2135,8 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { 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