[PATCH] Refactor MacroInfo for easier access in for-loops
Alexander Kornienko
alexfh at google.com
Fri May 22 05:56:44 PDT 2015
Looks good with comments.
================
Comment at: include/clang/Lex/MacroInfo.h:185
@@ -184,1 +184,3 @@
arg_iterator arg_end() const { return ArgumentList+NumArguments; }
+ ArrayRef<IdentifierInfo*> args() const {
+ return ArrayRef<IdentifierInfo*>(ArgumentList, NumArguments);
----------------
I'd probably go with ArrayRef<const IdentifierInfo*>, if no potential users need a non-const version.
================
Comment at: lib/Lex/PPMacroExpansion.cpp:365
@@ -364,4 +364,3 @@
// 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)
+ for (const auto &I : MI->args())
+ if (I == II)
----------------
Lines 365-369 can be replaced with:
return std::find(MI->args_begin(), MI->args_end(), II) == MI->args_end();
================
Comment at: lib/Serialization/ASTWriter.cpp:2138
@@ -2137,4 +2137,3 @@
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 auto &I : MI->args())
+ AddIdentifierRef(I, Record);
----------------
Specifying the exact type would make the code more readable here, imho:
for (const IdentifierInfo *I : MI->args())
...
http://reviews.llvm.org/D9934
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list