r210738 - Driver: use more range-based for loops
Saleem Abdulrasool
compnerd at compnerd.org
Wed Jun 11 19:08:04 PDT 2014
Author: compnerd
Date: Wed Jun 11 21:08:04 2014
New Revision: 210738
URL: http://llvm.org/viewvc/llvm-project?rev=210738&view=rev
Log:
Driver: use more range-based for loops
Mechanical change converting some of the simpler for loops into range-based for
loops. NFC.
Modified:
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=210738&r1=210737&r2=210738&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Jun 11 21:08:04 2014
@@ -177,10 +177,7 @@ static void AddLinkerInputs(const ToolCh
// (constructed via -Xarch_).
Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
-
+ for (const auto &II : Inputs) {
if (!TC.HasNativeLLVMSupport()) {
// Don't try to pass LLVM inputs unless we have native support.
if (II.getType() == types::TY_LLVM_IR ||
@@ -201,11 +198,11 @@ static void AddLinkerInputs(const ToolCh
const Arg &A = II.getInputArg();
// Handle reserved library options.
- if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx)) {
+ if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
TC.AddCXXStdlibLibArgs(Args, CmdArgs);
- } else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext)) {
+ else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
TC.AddCCKextLibArgs(Args, CmdArgs);
- } else
+ else
A.renderAsInput(Args, CmdArgs);
}
@@ -1764,8 +1761,8 @@ static bool ContainsCompileAction(const
if (isa<CompileJobAction>(A))
return true;
- for (Action::const_iterator it = A->begin(), ie = A->end(); it != ie; ++it)
- if (ContainsCompileAction(*it))
+ for (const auto &Act : *A)
+ if (ContainsCompileAction(Act))
return true;
return false;
@@ -1781,9 +1778,8 @@ static bool UseRelaxAll(Compilation &C,
if (RelaxDefault) {
RelaxDefault = false;
- for (ActionList::const_iterator it = C.getActions().begin(),
- ie = C.getActions().end(); it != ie; ++it) {
- if (ContainsCompileAction(*it)) {
+ for (const auto &Act : C.getActions()) {
+ if (ContainsCompileAction(Act)) {
RelaxDefault = true;
break;
}
@@ -3921,9 +3917,8 @@ void Clang::ConstructJob(Compilation &C,
// Support both clang's -f[no-]color-diagnostics and gcc's
// -f[no-]diagnostics-colors[=never|always|auto].
enum { Colors_On, Colors_Off, Colors_Auto } ShowColors = Colors_Auto;
- for (ArgList::const_iterator it = Args.begin(), ie = Args.end();
- it != ie; ++it) {
- const Option &O = (*it)->getOption();
+ for (const auto &Arg : Args) {
+ const Option &O = Arg->getOption();
if (!O.matches(options::OPT_fcolor_diagnostics) &&
!O.matches(options::OPT_fdiagnostics_color) &&
!O.matches(options::OPT_fno_color_diagnostics) &&
@@ -3931,7 +3926,7 @@ void Clang::ConstructJob(Compilation &C,
!O.matches(options::OPT_fdiagnostics_color_EQ))
continue;
- (*it)->claim();
+ Arg->claim();
if (O.matches(options::OPT_fcolor_diagnostics) ||
O.matches(options::OPT_fdiagnostics_color)) {
ShowColors = Colors_On;
@@ -3940,7 +3935,7 @@ void Clang::ConstructJob(Compilation &C,
ShowColors = Colors_Off;
} else {
assert(O.matches(options::OPT_fdiagnostics_color_EQ));
- StringRef value((*it)->getValue());
+ StringRef value(Arg->getValue());
if (value == "always")
ShowColors = Colors_On;
else if (value == "never")
@@ -4097,10 +4092,7 @@ void Clang::ConstructJob(Compilation &C,
assert(Output.isNothing() && "Invalid output.");
}
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
-
+ for (const auto &II : Inputs) {
addDashXForInput(Args, II, CmdArgs);
if (II.isFilename())
@@ -4117,9 +4109,8 @@ void Clang::ConstructJob(Compilation &C,
// analysis.
if (getToolChain().UseDwarfDebugFlags()) {
ArgStringList OriginalArgs;
- for (ArgList::const_iterator it = Args.begin(),
- ie = Args.end(); it != ie; ++it)
- (*it)->render(Args, OriginalArgs);
+ for (const auto &Arg : Args)
+ Arg->render(Args, OriginalArgs);
SmallString<256> Flags;
Flags += Exec;
@@ -4494,9 +4485,8 @@ void ClangAs::ConstructJob(Compilation &
// analysis.
if (getToolChain().UseDwarfDebugFlags()) {
ArgStringList OriginalArgs;
- for (ArgList::const_iterator it = Args.begin(),
- ie = Args.end(); it != ie; ++it)
- (*it)->render(Args, OriginalArgs);
+ for (const auto &Arg : Args)
+ Arg->render(Args, OriginalArgs);
SmallString<256> Flags;
const char *Exec = getToolChain().getDriver().getClangProgramPath();
@@ -4553,9 +4543,7 @@ void gcc::Common::ConstructJob(Compilati
const Driver &D = getToolChain().getDriver();
ArgStringList CmdArgs;
- for (ArgList::const_iterator
- it = Args.begin(), ie = Args.end(); it != ie; ++it) {
- Arg *A = *it;
+ for (const auto &A : Args) {
if (forwardToGCC(A->getOption())) {
// Don't forward any -g arguments to assembly steps.
if (isa<AssembleJobAction>(JA) &&
@@ -4624,10 +4612,7 @@ void gcc::Common::ConstructJob(Compilati
//
// FIXME: For the linker case specifically, can we safely convert
// inputs into '-Wl,' options?
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
-
+ for (const auto &II : Inputs) {
// Don't try to pass LLVM or AST inputs to a generic gcc.
if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR ||
II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC)
@@ -4746,10 +4731,7 @@ void hexagon::Assemble::ConstructJob(Com
//
// FIXME: For the linker case specifically, can we safely convert
// inputs into '-Wl,' options?
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
-
+ for (const auto &II : Inputs) {
// Don't try to pass LLVM or AST inputs to a generic gcc.
if (II.getType() == types::TY_LLVM_IR || II.getType() == types::TY_LTO_IR ||
II.getType() == types::TY_LLVM_BC || II.getType() == types::TY_LTO_BC)
@@ -4770,11 +4752,10 @@ void hexagon::Assemble::ConstructJob(Com
}
const char *GCCName = "hexagon-as";
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath(GCCName));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(GCCName));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
-
}
+
void hexagon::Link::RenderExtraToolArgs(const JobAction &JA,
ArgStringList &CmdArgs) const {
// The types are (hopefully) good enough.
@@ -4816,10 +4797,8 @@ void hexagon::Link::ConstructJob(Compila
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
- for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(),
- e = ToolChain.ExtraOpts.end();
- i != e; ++i)
- CmdArgs.push_back(i->c_str());
+ for (const auto &Opt : ToolChain.ExtraOpts)
+ CmdArgs.push_back(Opt.c_str());
std::string MarchString = toolchains::Hexagon_TC::GetTargetCPU(Args);
CmdArgs.push_back(Args.MakeArgString("-m" + MarchString));
@@ -4895,12 +4874,8 @@ void hexagon::Link::ConstructJob(Compila
// Library Search Paths
//----------------------------------------------------------------------------
const ToolChain::path_list &LibPaths = ToolChain.getFilePaths();
- for (ToolChain::path_list::const_iterator
- i = LibPaths.begin(),
- e = LibPaths.end();
- i != e;
- ++i)
- CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i));
+ for (const auto &LibPath : LibPaths)
+ CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
//----------------------------------------------------------------------------
//
@@ -5267,9 +5242,8 @@ bool darwin::Link::NeedsTempPath(const I
// We only need to generate a temp path for LTO if we aren't compiling object
// files. When compiling source files, we run 'dsymutil' after linking. We
// don't run 'dsymutil' when compiling object files.
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it)
- if (it->getType() != types::TY_Object)
+ for (const auto &Input : Inputs)
+ if (Input.getType() != types::TY_Object)
return true;
return false;
@@ -5470,8 +5444,8 @@ void darwin::Link::ConstructJob(Compilat
/// Hack(tm) to ignore linking errors when we are doing ARC migration.
if (Args.hasArg(options::OPT_ccc_arcmt_check,
options::OPT_ccc_arcmt_migrate)) {
- for (ArgList::const_iterator I = Args.begin(), E = Args.end(); I != E; ++I)
- (*I)->claim();
+ for (const auto &Arg : Args)
+ Arg->claim();
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("touch"));
CmdArgs.push_back(Output.getFilename());
@@ -5589,14 +5563,12 @@ void darwin::Lipo::ConstructJob(Compilat
CmdArgs.push_back("-output");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs) {
assert(II.isFilename() && "Unexpected lipo input.");
CmdArgs.push_back(II.getFilename());
}
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("lipo"));
+
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
@@ -5656,18 +5628,13 @@ void solaris::Assemble::ConstructJob(Com
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("as"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
-
void solaris::Link::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -5786,14 +5753,10 @@ void auroraux::Assemble::ConstructJob(Co
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("gas"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("gas"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
@@ -5947,11 +5910,8 @@ void openbsd::Assemble::ConstructJob(Com
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("as"));
@@ -6103,14 +6063,10 @@ void bitrig::Assemble::ConstructJob(Comp
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("as"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
@@ -6304,14 +6260,10 @@ void freebsd::Assemble::ConstructJob(Com
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("as"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
@@ -6412,9 +6364,8 @@ void freebsd::Link::ConstructJob(Compila
Args.AddAllArgs(CmdArgs, options::OPT_L);
const ToolChain::path_list Paths = ToolChain.getFilePaths();
- for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end();
- i != e; ++i)
- CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i));
+ for (const auto &Path : Paths)
+ CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path));
Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
Args.AddAllArgs(CmdArgs, options::OPT_e);
Args.AddAllArgs(CmdArgs, options::OPT_s);
@@ -6566,11 +6517,8 @@ void netbsd::Assemble::ConstructJob(Comp
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
const char *Exec = Args.MakeArgString((getToolChain().GetProgramPath("as")));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
@@ -6871,14 +6819,10 @@ void gnutools::Assemble::ConstructJob(Co
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("as"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
// Handle the debug info splitting at object creation time if we're
@@ -7028,10 +6972,8 @@ void gnutools::Link::ConstructJob(Compil
if (Args.hasArg(options::OPT_s))
CmdArgs.push_back("-s");
- for (std::vector<std::string>::const_iterator i = ToolChain.ExtraOpts.begin(),
- e = ToolChain.ExtraOpts.end();
- i != e; ++i)
- CmdArgs.push_back(i->c_str());
+ for (const auto &Opt : ToolChain.ExtraOpts)
+ CmdArgs.push_back(Opt.c_str());
if (!Args.hasArg(options::OPT_static)) {
CmdArgs.push_back("--eh-frame-hdr");
@@ -7149,9 +7091,8 @@ void gnutools::Link::ConstructJob(Compil
const ToolChain::path_list Paths = ToolChain.getFilePaths();
- for (ToolChain::path_list::const_iterator i = Paths.begin(), e = Paths.end();
- i != e; ++i)
- CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + *i));
+ for (const auto &Path : Paths)
+ CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path));
if (D.IsUsingLTO(Args))
AddGoldPlugin(ToolChain, Args, CmdArgs);
@@ -7249,20 +7190,15 @@ void minix::Assemble::ConstructJob(Compi
const char *LinkingOutput) const {
ArgStringList CmdArgs;
- Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
- options::OPT_Xassembler);
+ Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("as"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
@@ -7336,20 +7272,15 @@ void dragonfly::Assemble::ConstructJob(C
if (getToolChain().getArch() == llvm::Triple::x86)
CmdArgs.push_back("--32");
- Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
- options::OPT_Xassembler);
+ Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("as"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
@@ -7499,8 +7430,7 @@ void dragonfly::Link::ConstructJob(Compi
addProfileRT(getToolChain(), Args, CmdArgs);
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("ld"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("ld"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
@@ -7567,13 +7497,11 @@ void visualstudio::Link::ConstructJob(Co
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
// Add filenames immediately.
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- if (it->isFilename())
- CmdArgs.push_back(it->getFilename());
+ for (const auto &Input : Inputs)
+ if (Input.isFilename())
+ CmdArgs.push_back(Input.getFilename());
else
- it->getInputArg().renderAsInput(Args, CmdArgs);
- }
+ Input.getInputArg().renderAsInput(Args, CmdArgs);
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("link.exe"));
@@ -7673,8 +7601,8 @@ Command *visualstudio::Compile::GetComma
CmdArgs.push_back("/Z7");
std::vector<std::string> Includes = Args.getAllArgValues(options::OPT_include);
- for (size_t I = 0, E = Includes.size(); I != E; ++I)
- CmdArgs.push_back(Args.MakeArgString(std::string("/FI") + Includes[I]));
+ for (const auto &Include : Includes)
+ CmdArgs.push_back(Args.MakeArgString(std::string("/FI") + Include));
// Flags that can simply be passed through.
Args.AddAllArgs(CmdArgs, options::OPT__SLASH_LD);
@@ -7704,7 +7632,6 @@ Command *visualstudio::Compile::GetComma
const Driver &D = getToolChain().getDriver();
std::string Exec = FindFallback("cl.exe", D.getClangProgramPath());
-
return new Command(JA, *this, Args.MakeArgString(Exec), CmdArgs);
}
@@ -7738,14 +7665,10 @@ void XCore::Assemble::ConstructJob(Compi
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
options::OPT_Xassembler);
- for (InputInfoList::const_iterator
- it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
- const InputInfo &II = *it;
+ for (const auto &II : Inputs)
CmdArgs.push_back(II.getFilename());
- }
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
@@ -7772,7 +7695,6 @@ void XCore::Link::ConstructJob(Compilati
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
- const char *Exec =
- Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
+ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc"));
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
More information about the cfe-commits
mailing list