From: Craig Topper Date: Thu, 22 Oct 2015 04:59:52 +0000 (+0000) Subject: Change MacroInfo::setArgumentList to take an ArrayRef instead of pointer and size... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75792d186a545bc3a38fe1d4dd0f3ab7750014e9;p=clang Change MacroInfo::setArgumentList to take an ArrayRef instead of pointer and size. While there use std::copy intead of a manual loop. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250987 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h index 8b82a5bc93..320645e238 100644 --- a/include/clang/Lex/MacroInfo.h +++ b/include/clang/Lex/MacroInfo.h @@ -158,17 +158,16 @@ public: /// \brief Set the specified list of identifiers as the argument list for /// this macro. - void setArgumentList(IdentifierInfo *const *List, unsigned NumArgs, + void setArgumentList(ArrayRef List, llvm::BumpPtrAllocator &PPAllocator) { assert(ArgumentList == nullptr && NumArguments == 0 && "Argument list already set!"); - if (NumArgs == 0) + if (List.empty()) return; - NumArguments = NumArgs; - ArgumentList = PPAllocator.Allocate(NumArgs); - for (unsigned i = 0; i != NumArgs; ++i) - ArgumentList[i] = List[i]; + NumArguments = List.size(); + ArgumentList = PPAllocator.Allocate(List.size()); + std::copy(List.begin(), List.end(), ArgumentList); } /// Arguments - The list of arguments for a function-like macro. This can be diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index cba00a40ce..fd16168203 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1951,7 +1951,7 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI, Token &Tok) { // Add the __VA_ARGS__ identifier as an argument. Arguments.push_back(Ident__VA_ARGS__); MI->setIsC99Varargs(); - MI->setArgumentList(&Arguments[0], Arguments.size(), BP); + MI->setArgumentList(Arguments, BP); return false; case tok::eod: // #define X( Diag(Tok, diag::err_pp_missing_rparen_in_macro_def); @@ -1985,7 +1985,7 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI, Token &Tok) { Diag(Tok, diag::err_pp_expected_comma_in_arg_list); return true; case tok::r_paren: // #define X(A) - MI->setArgumentList(&Arguments[0], Arguments.size(), BP); + MI->setArgumentList(Arguments, BP); return false; case tok::comma: // #define X(A, break; @@ -2001,7 +2001,7 @@ bool Preprocessor::ReadMacroDefinitionArgList(MacroInfo *MI, Token &Tok) { } MI->setIsGNUVarargs(); - MI->setArgumentList(&Arguments[0], Arguments.size(), BP); + MI->setArgumentList(Arguments, BP); return false; } } diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 59347de9c1..4838a43e03 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1450,8 +1450,7 @@ MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { if (isC99VarArgs) MI->setIsC99Varargs(); if (isGNUVarArgs) MI->setIsGNUVarargs(); if (hasCommaPasting) MI->setHasCommaPasting(); - MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), - PP.getPreprocessorAllocator()); + MI->setArgumentList(MacroArgs, PP.getPreprocessorAllocator()); } // Remember that we saw this macro last so that we add the tokens that