r240674 - Use more range-based for loops
Sean Silva
chisophugis at gmail.com
Thu Jun 25 15:54:24 PDT 2015
Thanks!
On Thu, Jun 25, 2015 at 11:51 AM, Douglas Katzman <dougk at google.com> wrote:
> Author: dougk
> Date: Thu Jun 25 13:51:37 2015
> New Revision: 240674
>
> URL: http://llvm.org/viewvc/llvm-project?rev=240674&view=rev
> Log:
> Use more range-based for loops
>
> Differential Revision: http://reviews.llvm.org/D10738
>
> Modified:
> cfe/trunk/lib/Driver/Driver.cpp
> cfe/trunk/lib/Driver/ToolChains.cpp
> cfe/trunk/lib/Driver/Tools.cpp
>
> Modified: cfe/trunk/lib/Driver/Driver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=240674&r1=240673&r2=240674&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/Driver.cpp (original)
> +++ cfe/trunk/lib/Driver/Driver.cpp Thu Jun 25 13:51:37 2015
> @@ -83,11 +83,11 @@ void Driver::ParseDriverMode(ArrayRef<co
> const std::string OptName =
> getOpts().getOption(options::OPT_driver_mode).getPrefixedName();
>
> - for (size_t I = 0, E = Args.size(); I != E; ++I) {
> + for (const char *ArgPtr : Args) {
> // Ingore nullptrs, they are response file's EOL markers
> - if (Args[I] == nullptr)
> + if (ArgPtr == nullptr)
> continue;
> - const StringRef Arg = Args[I];
> + const StringRef Arg = ArgPtr;
> if (!Arg.startswith(OptName))
> continue;
>
> @@ -613,10 +613,9 @@ int Driver::ExecuteCompilation(Compilati
>
> // Otherwise, remove result files and print extra information about
> abnormal
> // failures.
> - for (SmallVectorImpl< std::pair<int, const Command *> >::iterator it =
> - FailingCommands.begin(), ie = FailingCommands.end(); it != ie;
> ++it) {
> - int Res = it->first;
> - const Command *FailingCommand = it->second;
> + for (const auto &CmdPair : FailingCommands) {
> + int Res = CmdPair.first;
> + const Command *FailingCommand = CmdPair.second;
>
> // Remove result files if we're not saving temps.
> if (!isSaveTempsEnabled()) {
> @@ -792,13 +791,11 @@ bool Driver::HandleImmediateArgs(const C
> }
>
> if (C.getArgs().hasArg(options::OPT_print_multi_directory)) {
> - const MultilibSet &Multilibs = TC.getMultilibs();
> - for (MultilibSet::const_iterator I = Multilibs.begin(), E =
> Multilibs.end();
> - I != E; ++I) {
> - if (I->gccSuffix().empty())
> + for (const auto &Multilib : TC.getMultilibs()) {
> + if (Multilib.gccSuffix().empty())
> llvm::outs() << ".\n";
> else {
> - StringRef Suffix(I->gccSuffix());
> + StringRef Suffix(Multilib.gccSuffix());
> assert(Suffix.front() == '/');
> llvm::outs() << Suffix.substr(1) << "\n";
> }
>
> Modified: cfe/trunk/lib/Driver/ToolChains.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=240674&r1=240673&r2=240674&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/ToolChains.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Jun 25 13:51:37 2015
> @@ -697,11 +697,9 @@ DerivedArgList *MachO::TranslateArgs(con
> // "input arguments".
> if (A->getOption().hasFlag(options::LinkerInput)) {
> // Convert the argument into individual Zlinker_input_args.
> - for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
> - DAL->AddSeparateArg(OriginalArg,
> - Opts.getOption(options::OPT_Zlinker_input),
> - A->getValue(i));
> -
> + for (const char *Value : A->getValues()) {
> + DAL->AddSeparateArg(
> + OriginalArg, Opts.getOption(options::OPT_Zlinker_input),
> Value);
> }
> continue;
> }
> @@ -1231,25 +1229,22 @@ Generic_GCC::GCCInstallationDetector::in
> // Loop over the various components which exist and select the best GCC
> // installation available. GCC installs are ranked by version number.
> Version = GCCVersion::Parse("0.0.0");
> - for (unsigned i = 0, ie = Prefixes.size(); i < ie; ++i) {
> - if (!llvm::sys::fs::exists(Prefixes[i]))
> + for (const std::string &Prefix : Prefixes) {
> + if (!llvm::sys::fs::exists(Prefix))
> continue;
> - for (unsigned j = 0, je = CandidateLibDirs.size(); j < je; ++j) {
> - const std::string LibDir = Prefixes[i] + CandidateLibDirs[j].str();
> + for (const StringRef Suffix : CandidateLibDirs) {
> + const std::string LibDir = Prefix + Suffix.str();
> if (!llvm::sys::fs::exists(LibDir))
> continue;
> - for (unsigned k = 0, ke = CandidateTripleAliases.size(); k < ke;
> ++k)
> - ScanLibDirForGCCTriple(TargetTriple, Args, LibDir,
> - CandidateTripleAliases[k]);
> + for (const StringRef Candidate : CandidateTripleAliases)
> + ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate);
> }
> - for (unsigned j = 0, je = CandidateBiarchLibDirs.size(); j < je; ++j)
> {
> - const std::string LibDir = Prefixes[i] +
> CandidateBiarchLibDirs[j].str();
> + for (const StringRef Suffix : CandidateBiarchLibDirs) {
> + const std::string LibDir = Prefix + Suffix.str();
> if (!llvm::sys::fs::exists(LibDir))
> continue;
> - for (unsigned k = 0, ke = CandidateBiarchTripleAliases.size(); k <
> ke;
> - ++k)
> - ScanLibDirForGCCTriple(TargetTriple, Args, LibDir,
> - CandidateBiarchTripleAliases[k],
> + for (const StringRef Candidate : CandidateBiarchTripleAliases)
> + ScanLibDirForGCCTriple(TargetTriple, Args, LibDir, Candidate,
> /*NeedsBiarchSuffix=*/ true);
> }
> }
> @@ -2165,9 +2160,9 @@ static void GetHexagonLibraryPaths(
>
> //----------------------------------------------------------------------------
> // -L Args
>
> //----------------------------------------------------------------------------
> - for (const Arg *A : Args.filtered(options::OPT_L))
> - for (unsigned i = 0, e = A->getNumValues(); i != e; ++i)
> - LibPaths->push_back(A->getValue(i));
> + for (Arg *A : Args.filtered(options::OPT_L))
> + for (const char *Value : A->getValues())
> + LibPaths->push_back(Value);
>
>
> //----------------------------------------------------------------------------
> // Other standard paths
> @@ -2959,25 +2954,25 @@ static Distro DetectDistro(llvm::Triple:
> SmallVector<StringRef, 16> Lines;
> Data.split(Lines, "\n");
> Distro Version = UnknownDistro;
> - for (unsigned i = 0, s = Lines.size(); i != s; ++i)
> - if (Version == UnknownDistro &&
> Lines[i].startswith("DISTRIB_CODENAME="))
> - Version = llvm::StringSwitch<Distro>(Lines[i].substr(17))
> - .Case("hardy", UbuntuHardy)
> - .Case("intrepid", UbuntuIntrepid)
> - .Case("jaunty", UbuntuJaunty)
> - .Case("karmic", UbuntuKarmic)
> - .Case("lucid", UbuntuLucid)
> - .Case("maverick", UbuntuMaverick)
> - .Case("natty", UbuntuNatty)
> - .Case("oneiric", UbuntuOneiric)
> - .Case("precise", UbuntuPrecise)
> - .Case("quantal", UbuntuQuantal)
> - .Case("raring", UbuntuRaring)
> - .Case("saucy", UbuntuSaucy)
> - .Case("trusty", UbuntuTrusty)
> - .Case("utopic", UbuntuUtopic)
> - .Case("vivid", UbuntuVivid)
> - .Default(UnknownDistro);
> + for (const StringRef Line : Lines)
> + if (Version == UnknownDistro &&
> Line.startswith("DISTRIB_CODENAME="))
> + Version = llvm::StringSwitch<Distro>(Line.substr(17))
> + .Case("hardy", UbuntuHardy)
> + .Case("intrepid", UbuntuIntrepid)
> + .Case("jaunty", UbuntuJaunty)
> + .Case("karmic", UbuntuKarmic)
> + .Case("lucid", UbuntuLucid)
> + .Case("maverick", UbuntuMaverick)
> + .Case("natty", UbuntuNatty)
> + .Case("oneiric", UbuntuOneiric)
> + .Case("precise", UbuntuPrecise)
> + .Case("quantal", UbuntuQuantal)
> + .Case("raring", UbuntuRaring)
> + .Case("saucy", UbuntuSaucy)
> + .Case("trusty", UbuntuTrusty)
> + .Case("utopic", UbuntuUtopic)
> + .Case("vivid", UbuntuVivid)
> + .Default(UnknownDistro);
> return Version;
> }
>
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=240674&r1=240673&r2=240674&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Thu Jun 25 13:51:37 2015
> @@ -2188,8 +2188,7 @@ static void CollectArgsForIntegratedAsse
> Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
> A->claim();
>
> - for (unsigned i = 0, e = A->getNumValues(); i != e; ++i) {
> - StringRef Value = A->getValue(i);
> + for (const StringRef Value : A->getValues()) {
> if (TakeNextArg) {
> CmdArgs.push_back(Value.data());
> TakeNextArg = false;
> @@ -4828,9 +4827,9 @@ void Clang::ConstructJob(Compilation &C,
>
> SmallString<256> Flags;
> Flags += Exec;
> - for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) {
> + for (const char *OriginalArg : OriginalArgs) {
> SmallString<128> EscapedArg;
> - EscapeSpacesAndBackslashes(OriginalArgs[i], EscapedArg);
> + EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
> Flags += " ";
> Flags += EscapedArg;
> }
> @@ -5291,9 +5290,9 @@ void ClangAs::ConstructJob(Compilation &
> SmallString<256> Flags;
> const char *Exec = getToolChain().getDriver().getClangProgramPath();
> Flags += Exec;
> - for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) {
> + for (const char *OriginalArg : OriginalArgs) {
> SmallString<128> EscapedArg;
> - EscapeSpacesAndBackslashes(OriginalArgs[i], EscapedArg);
> + EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
> Flags += " ";
> Flags += EscapedArg;
> }
>
>
> _______________________________________________
> 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/20150625/af7d34b4/attachment.html>
More information about the cfe-commits
mailing list