From 7c2db9e2b91da953701be233336c5bfa1f3c4af0 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 19 Dec 2022 14:32:43 +0200 Subject: [PATCH] Replace basic for loops with range-based loops or algorithms In remaining cases use auto as a shortcut for the iterator type. --- source/analyzer.cpp | 38 ++++++------- source/androidapplicationcomponent.cpp | 24 ++++---- source/androidassetpackagingtool.cpp | 19 +++---- source/androidmanifestgenerator.cpp | 5 +- source/androidpackagefile.cpp | 4 +- source/androidresourcebundle.cpp | 4 +- source/androidtools.cpp | 28 ++++----- source/apkbuilder.cpp | 17 +++--- source/architecture.cpp | 46 +++++++-------- source/binary.cpp | 34 +++++------ source/binarycomponent.cpp | 34 ++++++----- source/binarypackage.cpp | 78 +++++++++++++------------- source/booleanevaluator.cpp | 2 +- source/builder.cpp | 65 +++++++++------------ source/buildercli.cpp | 68 ++++++++++------------ source/buildgraph.cpp | 14 ++--- source/buildinfo.cpp | 34 ++++++----- source/cache.cpp | 12 ++-- source/chainedtask.cpp | 14 ++--- source/compilecommandsgenerator.cpp | 9 ++- source/compilecommandsjson.cpp | 7 +-- source/component.cpp | 76 +++++++++++-------------- source/config.cpp | 4 +- source/csourcefile.cpp | 7 +-- source/datacollection.cpp | 5 +- source/datapack.cpp | 4 +- source/datapackcomponent.cpp | 11 ++-- source/datatool.cpp | 9 ++- source/datatransform.cpp | 14 ++--- source/exportdefinitions.cpp | 4 +- source/externaltask.cpp | 10 ++-- source/filetarget.cpp | 29 +++++----- source/gnuarchiver.cpp | 9 ++- source/gnucompiler.cpp | 16 +++--- source/gnulinker.cpp | 25 ++++----- source/installcomponent.cpp | 8 +-- source/installmap.cpp | 20 +++---- source/mingwdlltool.cpp | 12 ++-- source/msvcarchiver.cpp | 9 ++- source/msvccompiler.cpp | 22 ++++---- source/msvclinker.cpp | 21 ++++--- source/objectfile.cpp | 44 +++++++-------- source/package.cpp | 4 +- source/packagemanager.cpp | 54 ++++++++---------- source/pattern.cpp | 4 +- source/pkgconfiggenerator.cpp | 27 +++++---- source/sharedlibrary.cpp | 4 +- source/sourcearchivecomponent.cpp | 17 +++--- source/sourcegenerator.cpp | 17 +++--- source/sourcepackage.cpp | 34 +++++------ source/staticlibrary.cpp | 4 +- source/tar.cpp | 9 ++- source/target.cpp | 34 +++++------ source/task.cpp | 8 +-- source/toolchain.cpp | 30 +++++----- source/vcxprojectgenerator.cpp | 56 +++++++++--------- source/virtualfilesystem.cpp | 37 ++++++------ source/virtualtarget.cpp | 7 ++- source/vssolutionfile.cpp | 9 ++- source/vssolutiongenerator.cpp | 36 ++++++------ 60 files changed, 608 insertions(+), 698 deletions(-) diff --git a/source/analyzer.cpp b/source/analyzer.cpp index 2c9cf05..4cebafa 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -24,15 +24,12 @@ void Analyzer::analyze() if(mode==RDEPS) { rdepends.clear(); - const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets(); - for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) + for(const auto &kvp: builder.get_build_graph().get_targets()) { - const Target::Dependencies &depends = i->second->get_dependencies(); - for(Target::Dependencies::const_iterator j=depends.begin(); j!=depends.end(); ++j) - rdepends[*j].insert(i->second); - const Target::Dependencies &tdepends = i->second->get_transitive_dependencies(); - for(Target::Dependencies::const_iterator j=tdepends.begin(); j!=tdepends.end(); ++j) - rdepends[*j].insert(i->second); + for(Target *d: kvp.second->get_dependencies()) + rdepends[d].insert(kvp.second); + for(Target *d: kvp.second->get_transitive_dependencies()) + rdepends[d].insert(kvp.second); } } @@ -49,9 +46,8 @@ void Analyzer::analyze() Target &goals = builder.get_build_graph().get_goals(); if(mode==RDEPS) { - const Target::Dependencies &deps = goals.get_dependencies(); - for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) - build_depend_table(**i, 0); + for(Target *d: goals.get_dependencies()) + build_depend_table(*d, 0); } else build_depend_table(goals, 0); @@ -120,8 +116,8 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth) depends.sort(full_paths ? target_order_full : target_order); - for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) - build_depend_table(**i, depth+1); + for(Target *d: depends) + build_depend_table(*d, depth+1); } } @@ -130,22 +126,22 @@ void Analyzer::print_table() const vector col_width; // Determine column widths - for(Table::const_iterator i=table.begin(); i!=table.end(); ++i) + for(const vector &r: table) { - if(col_width.size()size()) - col_width.resize(i->size(), 0); - for(unsigned j=0; jsize(); ++j) - col_width[j] = max(col_width[j], (*i)[j].size()); + if(col_width.size() &r: table) { string line; - for(unsigned j=0; jsize(); ++j) + for(unsigned j=0; j0) line += " "; - line += lexical_cast((*i)[j], Fmt("%-s").width(col_width[j])); + line += lexical_cast(r[j], Fmt("%-s").width(col_width[j])); } IO::print("%s\n", line); } diff --git a/source/androidapplicationcomponent.cpp b/source/androidapplicationcomponent.cpp index 99f1440..26277c8 100644 --- a/source/androidapplicationcomponent.cpp +++ b/source/androidapplicationcomponent.cpp @@ -21,27 +21,25 @@ void AndroidApplicationComponent::create_targets() const Builder &builder = package.get_builder(); BuildGraph &build_graph = builder.get_build_graph(); - const BuildGraph::TargetMap &targets = build_graph.get_targets(); list contents; - for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->get_package()==&package) - if(InstalledFile *inst = dynamic_cast(i->second)) + for(const auto &kvp: build_graph.get_targets()) + if(kvp.second->get_package()==&package) + if(InstalledFile *inst = dynamic_cast(kvp.second)) contents.push_back(inst->get_real_target()); AndroidManifestFile *manifest = new AndroidManifestFile(builder, *this); manifest->set_orientation(orientation); - for(set::const_iterator i=permissions.begin(); i!=permissions.end(); ++i) - manifest->add_permission(*i); + for(const string &p: permissions) + manifest->add_permission(p); list resource_sources; resource_sources.push_back(manifest); const Toolchain &toolchain = builder.get_toolchain(); Tool © = toolchain.get_tool("CP"); - SourceList source_filenames = collect_source_files(); - for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i) + for(const FS::Path &s: collect_source_files()) { - Target *tgt = new AndroidResourceFile(builder, *this, *i); + Target *tgt = new AndroidResourceFile(builder, *this, s); resource_sources.push_back(copy.create_target(*tgt, "//")); } @@ -63,16 +61,16 @@ void AndroidApplicationComponent::create_targets() const lib_dir += arch.get_type(); string assets_dir = "//"+name+"/assets"; - for(list::const_iterator i=contents.begin(); i!=contents.end(); ++i) + for(Target *t: contents) { Target *staged = 0; - if(SharedLibrary *shlib = dynamic_cast(*i)) + if(SharedLibrary *shlib = dynamic_cast(t)) { manifest->set_native_library(shlib); - staged = copy.create_target(**i, lib_dir); + staged = copy.create_target(*t, lib_dir); } else - staged = copy.create_target(**i, assets_dir); + staged = copy.create_target(*t, assets_dir); apk_sources.push_back(staged); } diff --git a/source/androidassetpackagingtool.cpp b/source/androidassetpackagingtool.cpp index 9e0fef7..0ef99a7 100644 --- a/source/androidassetpackagingtool.cpp +++ b/source/androidassetpackagingtool.cpp @@ -29,11 +29,11 @@ Target *AndroidAssetPackagingTool::create_target(const list &sources, { AndroidManifestFile *manifest = 0; list resources; - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) + for(Target *s: sources) { - if(AndroidManifestFile *m = dynamic_cast(*i)) + if(AndroidManifestFile *m = dynamic_cast(s)) manifest = m; - else if(FileTarget *f = dynamic_cast(*i)) + else if(FileTarget *f = dynamic_cast(s)) resources.push_back(f); } @@ -61,12 +61,11 @@ Task *AndroidAssetPackagingTool::run(const Target &tgt) const argv.push_back("-F"); argv.push_back(FS::relative(res.get_path(), work_dir).str()); - const Target::Dependencies &depends = res.get_dependencies(); list resource_dirs; - for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) + for(Target *d: res.get_dependencies()) { - FileTarget *file = dynamic_cast(*i); - Target *real = (*i)->get_real_target(); + FileTarget *file = dynamic_cast(d); + Target *real = d->get_real_target(); if(dynamic_cast(real)) { @@ -81,11 +80,11 @@ Task *AndroidAssetPackagingTool::run(const Target &tgt) const } set seen_dirs; - for(list::const_iterator i=resource_dirs.begin(); i!=resource_dirs.end(); ++i) - if(seen_dirs.insert(i->str()).second) + for(const FS::Path &d: resource_dirs) + if(seen_dirs.insert(d.str()).second) { argv.push_back("-S"); - argv.push_back(FS::relative(*i, work_dir).str()); + argv.push_back(FS::relative(d, work_dir).str()); } return new ExternalTask(argv, work_dir); diff --git a/source/androidmanifestgenerator.cpp b/source/androidmanifestgenerator.cpp index a7cda04..1d2f330 100644 --- a/source/androidmanifestgenerator.cpp +++ b/source/androidmanifestgenerator.cpp @@ -60,9 +60,8 @@ void AndroidManifestGenerator::Worker::main() out.write("\t\t\n"); } out.write("\t\n"); - const set &permissions = manifest.get_permissions(); - for(set::const_iterator i=permissions.begin(); i!=permissions.end(); ++i) - IO::print(out, "\t\n", *i); + for(const string &p: manifest.get_permissions()) + IO::print(out, "\t\n", p); out.write("\n"); status = Task::SUCCESS; diff --git a/source/androidpackagefile.cpp b/source/androidpackagefile.cpp index 1400d0f..22eedec 100644 --- a/source/androidpackagefile.cpp +++ b/source/androidpackagefile.cpp @@ -11,6 +11,6 @@ AndroidPackageFile::AndroidPackageFile(Builder &b, const Component &c, AndroidRe component = &c; add_dependency(resource_bundle); - for(list::const_iterator i=other_files.begin(); i!=other_files.end(); ++i) - add_dependency(**i); + for(FileTarget *f: other_files) + add_dependency(*f); } diff --git a/source/androidresourcebundle.cpp b/source/androidresourcebundle.cpp index d327126..2918b05 100644 --- a/source/androidresourcebundle.cpp +++ b/source/androidresourcebundle.cpp @@ -11,6 +11,6 @@ AndroidResourceBundle::AndroidResourceBundle(Builder &b, const Component &c, And component = &c; add_dependency(manifest); - for(list::const_iterator i=resources.begin(); i!=resources.end(); ++i) - add_dependency(**i); + for(FileTarget *f: resources) + add_dependency(*f); } diff --git a/source/androidtools.cpp b/source/androidtools.cpp index 118926e..5ef2bec 100644 --- a/source/androidtools.cpp +++ b/source/androidtools.cpp @@ -53,10 +53,8 @@ AndroidDevKit::AndroidDevKit(Builder &b, const string &type, const FS::Path &def return; builder.get_logger().log("files", format("Traversing %s", platforms_dir.str())); - vector platforms = list_filtered(platforms_dir, "^android-[1-9][0-9]*$"); - - for(vector::const_iterator i=platforms.begin(); i!=platforms.end(); ++i) - supported_api_levels.insert(lexical_cast(i->substr(8))); + for(const string &p: list_filtered(platforms_dir, "^android-[1-9][0-9]*$")) + supported_api_levels.insert(lexical_cast(p.substr(8))); } void AndroidDevKit::select_api_level(unsigned api) @@ -84,16 +82,14 @@ void AndroidSdk::find_build_tools_dir() } builder.get_logger().log("files", format("Traversing %s", bt_dir.str())); - vector tool_versions = list_files(bt_dir); - string use_tools; unsigned latest_version = 0; - for(vector::const_iterator i=tool_versions.begin(); i!=tool_versions.end(); ++i) + for(const string &v: list_files(bt_dir)) { - unsigned version = parse_version(*i); + unsigned version = parse_version(v); if(version>latest_version) { - use_tools = *i; + use_tools = v; latest_version = version; } } @@ -152,13 +148,11 @@ void AndroidNdk::find_toolchain_dir() builder.get_logger().log("files", format("Traversing %s", toolchains_dir.str())); string prefix = architecture.get_cross_prefix()+"-"; - vector toolchains = list_filtered(toolchains_dir, "^"+prefix); - string use_toolchain; unsigned latest_version = 0; - for(vector::const_iterator i=toolchains.begin(); i!=toolchains.end(); ++i) + for(const string &t: list_filtered(toolchains_dir, "^"+prefix)) { - string version_str = i->substr(prefix.size()); + string version_str = t.substr(prefix.size()); string compiler = "gcc"; if(!isdigit(version_str[0])) { @@ -174,7 +168,7 @@ void AndroidNdk::find_toolchain_dir() unsigned version = parse_version(version_str); if(version>latest_version) { - use_toolchain = *i; + use_toolchain = t; latest_version = version; } } @@ -206,8 +200,8 @@ void AndroidNdk::init_api_level(unsigned api) FS::Path platform_archs_dir = root/"platforms"/format("android-%d", api); builder.get_logger().log("files", format("Traversing %s", platform_archs_dir.str())); vector platform_archs = list_filtered(platform_archs_dir, "^arch-"); - for(vector::iterator i=platform_archs.begin(); i!=platform_archs.end(); ++i) - i->erase(0, 5); + for(string &a: platform_archs) + a.erase(0, 5); string use_arch = architecture.best_match(platform_archs); if(use_arch.empty()) @@ -228,7 +222,7 @@ AndroidTools::AndroidTools(Builder &builder, const Architecture &arch): const set &sdk_api_levels = sdk.get_supported_api_levels(); const set &ndk_api_levels = ndk.get_supported_api_levels(); unsigned highest_common = 0; - for(set::const_reverse_iterator i=sdk_api_levels.rbegin(); (!highest_common && i!=sdk_api_levels.rend()); ++i) + for(auto i=sdk_api_levels.rbegin(); (!highest_common && i!=sdk_api_levels.rend()); ++i) if(ndk_api_levels.count(*i)) highest_common = *i; diff --git a/source/apkbuilder.cpp b/source/apkbuilder.cpp index 9cd1a16..2568f33 100644 --- a/source/apkbuilder.cpp +++ b/source/apkbuilder.cpp @@ -25,11 +25,11 @@ Target *ApkBuilder::create_target(const list &sources, const string &) { AndroidResourceBundle *resource_bundle = 0; list other_files; - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) + for(Target *s: sources) { - if(AndroidResourceBundle *r = dynamic_cast(*i)) + if(AndroidResourceBundle *r = dynamic_cast(s)) resource_bundle = r; - else if(FileTarget *f = dynamic_cast(*i)) + else if(FileTarget *f = dynamic_cast(s)) other_files.push_back(f); } AndroidPackageFile *apk = new AndroidPackageFile(builder, *resource_bundle->get_component(), *resource_bundle, other_files); @@ -51,13 +51,12 @@ Task *ApkBuilder::run(const Target &tgt) const argv.push_back(executable->get_path().str()); argv.push_back("u"); - const Target::Dependencies &depends = apk.get_dependencies(); FS::Path input_path; list files; - for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) + for(Target *d: apk.get_dependencies()) { - FileTarget *file = dynamic_cast(*i); - Target *real = (*i)->get_real_target(); + FileTarget *file = dynamic_cast(d); + Target *real = d->get_real_target(); if(dynamic_cast(real)) input_path = file->get_path(); @@ -67,8 +66,8 @@ Task *ApkBuilder::run(const Target &tgt) const FS::Path work_dir = FS::dirname(input_path); - for(list::const_iterator i=files.begin(); i!=files.end(); ++i) - argv.push_back(FS::relative(*i, work_dir).str()); + for(const FS::Path &f: files) + argv.push_back(FS::relative(f, work_dir).str()); ExternalTask *task = new ExternalTask(argv, work_dir); task->set_stdin(FS::basename(input_path)); diff --git a/source/architecture.cpp b/source/architecture.cpp index 212f148..2efcd5e 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -182,11 +182,11 @@ bool Architecture::match_name(const string &pattern) const bool negate = (pattern[0]=='!'); vector parts = split(pattern.substr(negate), "-"); resolve_aliases(parts); - for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) + for(const string &p: parts) { - if((*i=="32" && bits==32) || (*i=="64" && bits==64)) + if((p=="32" && bits==32) || (p=="64" && bits==64)) ; - else if(*i!=type && *i!=cpu && *i!=fpu && *i!=system && *i!=toolchain) + else if(p!=type && p!=cpu && p!=fpu && p!=system && p!=toolchain) return negate; } return !negate; @@ -196,19 +196,19 @@ string Architecture::best_match(const vector &names) const { string best; unsigned best_size = 0; - for(vector::const_iterator i=names.begin(); i!=names.end(); ++i) - if(match_name(*i)) + for(const string &n: names) + if(match_name(n)) { /* TODO Do full parse and alias resolution here? Otherwise x86 and x86_64 are treated as equally good, even though the latter is more specific. */ unsigned size = 1; - for(string::const_iterator j=i->begin(); j!=i->end(); ++j) - size += (*j=='-'); + for(char c: n) + size += (c=='-'); if(size>best_size) { - best = *i; + best = n; best_size = size; } } @@ -255,61 +255,61 @@ void Architecture::parse_specification(const string &spec) { vector parts = split(spec, "-"); resolve_aliases(parts); - for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) + for(const string &p: parts) { bool ok = false; for(unsigned j=0; (!ok && types[j]); ++j) - if(*i==types[j]) + if(p==types[j]) { - if(!type.empty() && *i!=type) + if(!type.empty() && p!=type) throw invalid_argument("Conflicting type specification"); - type = *i; + type = p; ok = true; } for(unsigned j=0; (!ok && cpus[j]); j+=2) - if(*i==cpus[j]) + if(p==cpus[j]) { if(type.empty()) type = cpus[j+1]; else if(cpus[j+1]!=type) throw invalid_argument("Conflicting CPU specification"); - cpu = *i; + cpu = p; ok = true; } for(unsigned j=0; (!ok && fpus[j]); j+=2) - if(*i==fpus[j]) + if(p==fpus[j]) { if(fpus[j+1]!=type) throw invalid_argument("Conflicting FPU specification"); - fpu = *i; + fpu = p; ok = true; } for(unsigned j=0; (!ok && systems[j]); ++j) - if(*i==systems[j]) + if(p==systems[j]) { - system = *i; + system = p; ok = true; } for(unsigned j=0; (!ok && toolchains[j]); ++j) - if(*i==toolchains[j]) + if(p==toolchains[j]) { - toolchain = *i; + toolchain = p; ok = true; } - if(!ok && (*i=="32" || *i=="64")) + if(!ok && (p=="32" || p=="64")) { - bits = lexical_cast(*i); + bits = lexical_cast(p); ok = true; } if(!ok) - throw invalid_argument("Unrecognized part in arch specification: "+*i); + throw invalid_argument("Unrecognized part in arch specification: "+p); } } diff --git a/source/binary.cpp b/source/binary.cpp index fcf30f1..c8011d7 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -22,8 +23,8 @@ Binary::Binary(Builder &b, const Component &c, const string &p, const list::const_iterator i=objects.begin(); i!=objects.end(); ++i) - add_dependency(**i); + for(ObjectFile *o: objects) + add_dependency(*o); nested_build_sig = true; arch_in_build_sig = true; @@ -31,8 +32,8 @@ Binary::Binary(Builder &b, const Component &c, const string &p, const list::const_iterator i=objects.begin(); i!=objects.end(); ++i) - if(const Tool *obj_tool = (*i)->get_tool()) + for(ObjectFile *o: objects) + if(const Tool *obj_tool = o->get_tool()) binfo.update_from(obj_tool->get_build_info()); Target::collect_build_info(binfo); @@ -49,7 +50,7 @@ void Binary::find_dependencies() list dep_libs; set missing_libs; queue.push_back(this); - for(list::iterator j=queue.begin(); j!=queue.end(); ++j) + for(auto j=queue.begin(); j!=queue.end(); ++j) { Target *tgt = *j; @@ -63,15 +64,15 @@ void Binary::find_dependencies() static_binfo.threads = true; } - list::iterator insert_pos = j; + auto insert_pos = j; ++insert_pos; - for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i) + for(const string &l: binfo.libs) { - if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework")) + if(l.size()>10 && !l.compare(l.size()-10, 10, ".framework")) continue; - BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i); - Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode); + BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(l); + Target *lib = builder.get_vfs().find_library(l, binfo.libpath, libmode); if(lib) { Target *real = lib->get_real_target(); @@ -80,8 +81,8 @@ void Binary::find_dependencies() else dep_libs.push_back(lib); } - else if(missing_libs.insert(*i).second) - problems.push_back(format("Required library %s not found", *i)); + else if(missing_libs.insert(l).second) + problems.push_back(format("Required library %s not found", l)); } } @@ -90,12 +91,7 @@ void Binary::find_dependencies() /* Add only the last occurrence of each library to the actual dependencies. This ensures that static library ordering is correct. */ - for(list::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i) - { - bool last = true; - for(list::iterator j=i; (last && j!=dep_libs.end()); ++j) - last = (j==i || *j!=*i); - if(last) + for(auto i=dep_libs.begin(); i!=dep_libs.end(); ++i) + if(!any_of(next(i), dep_libs.end(), [i](Target *d){ return d==*i; })) add_dependency(**i); - } } diff --git a/source/binarycomponent.cpp b/source/binarycomponent.cpp index 49c4897..2cd6f85 100644 --- a/source/binarycomponent.cpp +++ b/source/binarycomponent.cpp @@ -17,22 +17,21 @@ void BinaryComponent::create_build_info() { Component::create_build_info(); - for(UseList::const_iterator i=uses.begin(); i!=uses.end(); ++i) + for(const Component *u: uses) { /* Select an include path that contains all the sources for this and the used component. This should produce a sensible result in most cases. */ FS::Path base; - for(SourceList::const_iterator j=sources.begin(); j!=sources.end(); ++j) - base = base.empty() ? *j : FS::common_ancestor(base, *j); - const SourceList &use_sources = (*i)->get_sources(); - for(SourceList::const_iterator j=use_sources.begin(); j!=use_sources.end(); ++j) - base = FS::common_ancestor(base, *j); + for(const FS::Path &s: sources) + base = base.empty() ? s : FS::common_ancestor(base, s); + for(const FS::Path &s: u->get_sources()) + base = FS::common_ancestor(base, s); build_info.incpath.push_back(base); - build_info.libs.push_back((*i)->get_name()); - if(!(*i)->get_install()) + build_info.libs.push_back(u->get_name()); + if(!u->get_install()) { - build_info.libmodes[(*i)->get_name()] = BuildInfo::STATIC; - build_info.libpath.push_back((*i)->get_package().get_output_directory()); + build_info.libmodes[u->get_name()] = BuildInfo::STATIC; + build_info.libpath.push_back(u->get_package().get_output_directory()); } } @@ -56,7 +55,7 @@ void BinaryComponent::create_targets() const list objs; SourceList source_filenames = collect_source_files(); - for(SourceList::iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i) + for(auto i=source_filenames.begin(); i!=source_filenames.end(); ++i) { string ext = FS::extpart(FS::basename(*i)); Target *src = 0; @@ -109,10 +108,9 @@ void BinaryComponent::create_targets() const if(dynamic_cast(src)->is_installable()) build_graph.add_installed_target(*src); - const Target::Dependencies &side_effects = src->get_side_effects(); - for(Target::Dependencies::const_iterator j=side_effects.begin(); j!=side_effects.end(); ++j) - if(dynamic_cast(*j)->is_installable()) - build_graph.add_installed_target(**j); + for(Target *s: src->get_side_effects()) + if(dynamic_cast(s)->is_installable()) + build_graph.add_installed_target(*s); } } } @@ -131,11 +129,11 @@ void BinaryComponent::create_targets() const else results.push_back(linker.create_target(objs)); - for(list::const_iterator i=results.begin(); i!=results.end(); ++i) + for(Target *r: results) { - build_graph.add_primary_target(**i); + build_graph.add_primary_target(*r); if(install) - build_graph.add_installed_target(**i); + build_graph.add_installed_target(*r); } } diff --git a/source/binarypackage.cpp b/source/binarypackage.cpp index e48f17c..2c32d87 100644 --- a/source/binarypackage.cpp +++ b/source/binarypackage.cpp @@ -23,9 +23,9 @@ BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, c process_flags(flags, pkg->export_binfo); Flags exclusive_static_flags; - for(Flags::const_iterator i=static_flags.begin(); i!=static_flags.end(); ++i) - if(find(flags.begin(), flags.end(), *i)==flags.end()) - exclusive_static_flags.push_back(*i); + for(const string &f: static_flags) + if(find(flags.begin(), flags.end(), f)==flags.end()) + exclusive_static_flags.push_back(f); process_flags(exclusive_static_flags, pkg->static_binfo); return pkg; @@ -33,34 +33,32 @@ BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, c void BinaryPackage::process_flags(const Flags &flags, BuildInfo &binfo) { - for(Flags::const_iterator i=flags.begin(); i!=flags.end(); ++i) + for(const string &f: flags) { - if(!i->compare(0, 2, "-I")) - binfo.incpath.push_back(i->substr(2)); - else if(!i->compare(0, 2, "-D")) + if(!f.compare(0, 2, "-I")) + binfo.incpath.push_back(f.substr(2)); + else if(!f.compare(0, 2, "-D")) { - string::size_type equals = i->find('='); + string::size_type equals = f.find('='); if(equals!=string::npos) - binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1); + binfo.defines[f.substr(2, equals-2)] = f.substr(equals+1); else - binfo.defines[i->substr(2)] = string(); + binfo.defines[f.substr(2)] = string(); } - else if(!i->compare(0, 2, "-L")) - binfo.libpath.push_back(i->substr(2)); - else if(!i->compare(0, 2, "-l")) - binfo.libs.push_back(i->substr(2)); - else if(*i=="-pthread") + else if(!f.compare(0, 2, "-L")) + binfo.libpath.push_back(f.substr(2)); + else if(!f.compare(0, 2, "-l")) + binfo.libs.push_back(f.substr(2)); + else if(f=="-pthread") binfo.threads = true; } } void BinaryPackage::do_prepare() { - bool has_relative_paths = false; - for(BuildInfo::PathList::const_iterator i=export_binfo.libpath.begin(); (!has_relative_paths && i!=export_binfo.libpath.end()); ++i) - has_relative_paths = !i->is_absolute(); - for(BuildInfo::PathList::const_iterator i=export_binfo.incpath.begin(); (!has_relative_paths && i!=export_binfo.incpath.end()); ++i) - has_relative_paths = !i->is_absolute(); + auto is_relative = [](const FS::Path &p){ return !p.is_absolute(); }; + bool has_relative_paths = any_of(export_binfo.libpath.begin(), export_binfo.libpath.end(), is_relative) || + any_of(export_binfo.incpath.begin(), export_binfo.incpath.end(), is_relative); list bases; @@ -73,9 +71,9 @@ void BinaryPackage::do_prepare() bases.push_back(FS::Path()); bool system = false; - for(list::const_iterator i=bases.begin(); i!=bases.end(); ++i) + for(const FS::Path &b: bases) { - FS::Path prefix = *i; + FS::Path prefix = b; system = prefix.empty(); if(system) { @@ -88,21 +86,21 @@ void BinaryPackage::do_prepare() BuildInfo::PathList libpath = export_binfo.libpath; if(!system && libpath.empty()) libpath.push_back("lib"); - for(BuildInfo::PathList::iterator j=libpath.begin(); j!=libpath.end(); ++j) - *j = prefix/ *j; + for(FS::Path &p: libpath) + p = prefix/p; bool all_found = true; - for(BuildInfo::WordList::const_iterator j=export_binfo.libs.begin(); j!=export_binfo.libs.end(); ++j) - all_found &= (builder.get_vfs().find_library(*j, libpath, export_binfo.libmode, system)!=0); + for(const string &l: export_binfo.libs) + all_found &= (builder.get_vfs().find_library(l, libpath, export_binfo.libmode, system)!=0); BuildInfo::PathList incpath = export_binfo.incpath; if(!system && incpath.empty()) incpath.push_back("include"); - for(BuildInfo::PathList::iterator j=incpath.begin(); j!=incpath.end(); ++j) - *j = prefix/ *j; + for(FS::Path &p: incpath) + p = prefix/p; - for(HeaderList::const_iterator j=headers.begin(); j!=headers.end(); ++j) - all_found &= (builder.get_vfs().find_header(*j, 0, incpath, system)!=0); + for(const string &h: headers) + all_found &= (builder.get_vfs().find_header(h, 0, incpath, system)!=0); if(all_found) { @@ -129,10 +127,10 @@ void BinaryPackage::do_prepare() if(has_relative_paths) { - for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i) - *i = base_path/ *i; - for(BuildInfo::PathList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i) - *i = base_path/ *i; + for(FS::Path &p: export_binfo.incpath) + p = base_path/p; + for(FS::Path &p: export_binfo.libpath) + p = base_path/p; } if(!static_binfo.libs.empty()) @@ -140,14 +138,14 @@ void BinaryPackage::do_prepare() BuildInfo::PathList combined_libpath = static_binfo.libpath; combined_libpath.insert(combined_libpath.end(), export_binfo.libpath.begin(), export_binfo.libpath.end()); - for(BuildInfo::WordList::const_iterator i=export_binfo.libs.begin(); i!=export_binfo.libs.end(); ++i) - if(Target *lib = builder.get_vfs().find_library(*i, export_binfo.libpath, BuildInfo::FORCE_STATIC, system)) + for(const string &l: export_binfo.libs) + if(Target *lib = builder.get_vfs().find_library(l, export_binfo.libpath, BuildInfo::FORCE_STATIC, system)) if(StaticLibrary *stlib = dynamic_cast(lib)) { - for(BuildInfo::WordList::const_iterator j=static_binfo.libs.begin(); j!=static_binfo.libs.end(); ++j) - stlib->add_required_library(*j); - for(BuildInfo::PathList::const_iterator j=combined_libpath.begin(); j!=combined_libpath.end(); ++j) - stlib->add_library_path(*j); + for(const string &s: static_binfo.libs) + stlib->add_required_library(s); + for(const FS::Path &p: combined_libpath) + stlib->add_library_path(p); } } } diff --git a/source/booleanevaluator.cpp b/source/booleanevaluator.cpp index ecb38fb..0103741 100644 --- a/source/booleanevaluator.cpp +++ b/source/booleanevaluator.cpp @@ -14,7 +14,7 @@ bool BooleanEvaluator::evaluate(const string &str) { string buf; last_was_op = true; - for(string::const_iterator i=str.begin();; ++i) + for(auto i=str.begin();; ++i) { if(i!=str.end() && (isalnum(*i) || (!buf.empty() && (*i=='_' || *i=='-')))) buf += *i; diff --git a/source/builder.cpp b/source/builder.cpp index e26c115..5475c7d 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -65,8 +65,8 @@ vector Builder::get_build_types() const { vector keys; keys.reserve(build_types.size()); - for(BuildTypeMap::const_iterator i=build_types.begin(); i!=build_types.end(); ++i) - keys.push_back(i->first); + for(const auto &kvp: build_types) + keys.push_back(kvp.first); return keys; } @@ -112,48 +112,37 @@ list Builder::collect_problems() const set broken_components; set broken_tools; - const BuildGraph::TargetMap &targets = build_graph.get_targets(); - for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->is_broken()) + for(const auto &kvp: build_graph.get_targets()) + if(kvp.second->is_broken()) { - const list &tgt_problems = i->second->get_problems(); - for(list::const_iterator j=tgt_problems.begin(); j!=tgt_problems.end(); ++j) - problems.push_back(format("%s: %s", i->second->get_name(), *j)); + for(const string &p: kvp.second->get_problems()) + problems.push_back(format("%s: %s", kvp.second->get_name(), p)); - const Package *package = i->second->get_package(); + const Package *package = kvp.second->get_package(); if(package && !package->get_problems().empty()) broken_packages.insert(package); - const Component *component = i->second->get_component(); + const Component *component = kvp.second->get_component(); if(component && !component->get_problems().empty()) broken_components.insert(component); - const Tool *tool = i->second->get_tool(); + const Tool *tool = kvp.second->get_tool(); if(tool && !tool->get_problems().empty()) broken_tools.insert(tool); } // TODO Sort components after their packages, and targets last - for(set::const_iterator i=broken_packages.begin(); i!=broken_packages.end(); ++i) - { - const list &pkg_problems = (*i)->get_problems(); - for(list::const_iterator j=pkg_problems.begin(); j!=pkg_problems.end(); ++j) - problems.push_back(format("%s: %s", (*i)->get_name(), *j)); - } + for(const Package *p: broken_packages) + for(const string &b: p->get_problems()) + problems.push_back(format("%s: %s", p->get_name(), b)); - for(set::const_iterator i=broken_components.begin(); i!=broken_components.end(); ++i) - { - const list &comp_problems = (*i)->get_problems(); - for(list::const_iterator j=comp_problems.begin(); j!=comp_problems.end(); ++j) - problems.push_back(format("%s/%s: %s", (*i)->get_package().get_name(), (*i)->get_name(), *j)); - } + for(const Component *c: broken_components) + for(const string &b: c->get_problems()) + problems.push_back(format("%s/%s: %s", c->get_package().get_name(), c->get_name(), b)); - for(set::const_iterator i=broken_tools.begin(); i!=broken_tools.end(); ++i) - { - const list &tool_problems = (*i)->get_problems(); - for(list::const_iterator j=tool_problems.begin(); j!=tool_problems.end(); ++j) - problems.push_back(format("%s: %s", (*i)->get_tag(), *j)); - } + for(const Tool *t: broken_tools) + for(const string &b: t->get_problems()) + problems.push_back(format("%s: %s", t->get_tag(), b)); return problems; } @@ -171,9 +160,8 @@ void Builder::load_build_file(const FS::Path &fn, const Config::InputOptions *op void Builder::save_caches() { - const PackageManager::PackageMap &packages = package_manager.get_packages(); - for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) - i->second->save_caches(); + for(const auto &kvp: package_manager.get_packages()) + kvp.second->save_caches(); } int Builder::build(unsigned jobs, bool dry_run, bool show_progress) @@ -282,17 +270,16 @@ int Builder::clean(bool all, bool dry_run) if(tgt->is_buildable() && (tgt->get_package()==&package_manager.get_main_package() || all)) clean_tgts.insert(tgt); - const Target::Dependencies &deps = tgt->get_dependencies(); - for(list::const_iterator i=deps.begin(); i!=deps.end(); ++i) - if(!clean_tgts.count(*i)) - queue.push_back(*i); + for(Target *t: tgt->get_dependencies()) + if(!clean_tgts.count(t)) + queue.push_back(t); } - for(set::iterator i=clean_tgts.begin(); i!=clean_tgts.end(); ++i) + for(Target *t: clean_tgts) { - get_logger().log("tasks", format("RM %s", (*i)->get_name())); + get_logger().log("tasks", format("RM %s", t->get_name())); if(!dry_run) - (*i)->clean(); + t->clean(); } return 0; diff --git a/source/buildercli.cpp b/source/buildercli.cpp index c7a2817..bf53c29 100644 --- a/source/buildercli.cpp +++ b/source/buildercli.cpp @@ -95,12 +95,9 @@ BuilderCLI::BuilderCLI(int argc, char **argv): logger.enable_channel("files"); logger.enable_channel("auxcommands"); } - for(list::const_iterator i=log_channels.begin(); i!=log_channels.end(); ++i) - { - vector parts = split(*i, ','); - for(vector::const_iterator j=parts.begin(); j!=parts.end(); ++j) - logger.enable_channel(*j); - } + for(const string &c: log_channels) + for(const string &p: split(c, ',')) + logger.enable_channel(p); builder.set_logger(&logger); if(!analyze_mode.empty()) @@ -124,7 +121,7 @@ BuilderCLI::BuilderCLI(int argc, char **argv): else if(!clean && !create_makefile) build = true; - for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ) + for(auto i=cmdline_targets.begin(); i!=cmdline_targets.end(); ) { string::size_type equal = i->find('='); if(equal!=string::npos) @@ -154,9 +151,9 @@ BuilderCLI::BuilderCLI(int argc, char **argv): list start_files; start_files.push_back(FS::get_sys_data_dir()/"builderrc"); start_files.push_back(FS::get_user_data_dir()/"rc"); - for(list::const_iterator i=start_files.begin(); i!=start_files.end(); ++i) - if(FS::exists(*i)) - builder.load_build_file(*i); + for(const FS::Path &f: start_files) + if(FS::exists(f)) + builder.load_build_file(f); if(!prefix.empty()) builder.set_prefix(cwd/prefix); @@ -170,7 +167,7 @@ BuilderCLI::BuilderCLI(int argc, char **argv): builder.add_default_tools(); const Toolchain &toolchain = builder.get_toolchain(); - for(Config::InputOptions::iterator i=cmdline_options.begin(); i!=cmdline_options.end(); ) + for(auto i=cmdline_options.begin(); i!=cmdline_options.end(); ) { if(toolchain.has_tool(i->first)) { @@ -233,26 +230,24 @@ int BuilderCLI::main() BuildGraph &build_graph = builder.get_build_graph(); PackageManager &package_manager = builder.get_package_manager(); - const PackageManager::PackageMap &packages = package_manager.get_packages(); list package_details; - for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) + for(const auto &kvp: package_manager.get_packages()) { - if(!i->second->is_prepared()) + if(!kvp.second->is_prepared()) continue; - string line = i->second->get_name(); - if(dynamic_cast(i->second)) + string line = kvp.second->get_name(); + if(dynamic_cast(kvp.second)) { line += '*'; unsigned count = 0; unsigned to_be_built = 0; - const BuildGraph::TargetMap &targets = build_graph.get_targets(); - for(BuildGraph::TargetMap::const_iterator j=targets.begin(); j!=targets.end(); ++j) - if(j->second->get_package()==i->second) + for(const auto &kvp2: build_graph.get_targets()) + if(kvp2.second->get_package()==kvp.second) { ++count; - if(j->second->needs_rebuild()) + if(kvp2.second->needs_rebuild()) ++to_be_built; } if(count) @@ -268,8 +263,8 @@ int BuilderCLI::main() } logger.log("summary", format("%d active packages, %d targets", package_details.size(), build_graph.get_targets().size())); - for(list::const_iterator i=package_details.begin(); i!=package_details.end(); ++i) - logger.log("packages", *i); + for(const string &d: package_details) + logger.log("packages", d); if(analyzer) analyzer->analyze(); @@ -278,8 +273,8 @@ int BuilderCLI::main() { list problems = builder.collect_problems(); IO::print(IO::cerr, "The following problems were detected:\n"); - for(list::const_iterator i=problems.begin(); i!=problems.end(); ++i) - IO::print(IO::cerr, " %s\n", *i); + for(const string &p: problems) + IO::print(IO::cerr, " %s\n", p); if(!analyzer) IO::print(IO::cerr, "Please fix them and try again.\n"); return 1; @@ -307,12 +302,12 @@ bool BuilderCLI::prepare_build() package_manager.get_main_package().prepare(); // Add targets from command line as goals - for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i) + for(const string &t: cmdline_targets) { - Target *tgt = resolve_target(*i); + Target *tgt = resolve_target(t); if(!tgt) { - IO::print("I don't know anything about %s\n", *i); + IO::print("I don't know anything about %s\n", t); return false; } @@ -322,12 +317,12 @@ bool BuilderCLI::prepare_build() build_graph.prepare(); // Apply what-ifs - for(NameList::iterator i=what_if.begin(); i!=what_if.end(); ++i) + for(const string &w: what_if) { - FileTarget *tgt = dynamic_cast(resolve_target(*i)); + FileTarget *tgt = dynamic_cast(resolve_target(w)); if(!tgt) { - IO::print(IO::cerr, "Unknown what-if target %s\n", *i); + IO::print(IO::cerr, "Unknown what-if target %s\n", w); return false; } tgt->touch(); @@ -367,7 +362,7 @@ void BuilderCLI::package_help() if(!requires.empty()) { IO::print("\nRequired packages:\n "); - for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i) + for(auto i=requires.begin(); i!=requires.end(); ++i) { if(i!=requires.begin()) IO::print(", "); @@ -379,19 +374,14 @@ void BuilderCLI::package_help() if(!options.empty()) { IO::print("\nPackage configuration:\n"); - for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i) + for(const auto &kvp: options) { - const Config::Option &opt = i->second; + const Config::Option &opt = kvp.second; string line = format(" %s: %s (%s)", opt.name, opt.description, opt.value); if(!opt.choices.empty()) { line += " {"; - for(list::const_iterator j=opt.choices.begin(); j!=opt.choices.end(); ++j) - { - if(j!=opt.choices.begin()) - line += ' '; - line += *j; - } + line += join(opt.choices.begin(), opt.choices.end(), " "); line += '}'; } else if(opt.value!=opt.default_value) diff --git a/source/buildgraph.cpp b/source/buildgraph.cpp index 6ae13dc..a3af685 100644 --- a/source/buildgraph.cpp +++ b/source/buildgraph.cpp @@ -19,8 +19,8 @@ BuildGraph::BuildGraph(Builder &b): BuildGraph::~BuildGraph() { - for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i) - delete i->second; + for(const auto &kvp: targets) + delete kvp.second; } Target *BuildGraph::get_target(const string &n) const @@ -69,16 +69,16 @@ void BuildGraph::prepare() void BuildGraph::force_full_rebuild() { - for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->is_buildable() && !i->second->needs_rebuild()) - i->second->force_rebuild(); + for(const auto &kvp: targets) + if(kvp.second->is_buildable() && !kvp.second->needs_rebuild()) + kvp.second->force_rebuild(); } unsigned BuildGraph::count_rebuild_targets() const { unsigned count = 0; - for(map::const_iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->is_buildable() && i->second->needs_rebuild()) + for(const auto &kvp: targets) + if(kvp.second->is_buildable() && kvp.second->needs_rebuild()) ++count; return count; } diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index af48654..48b4832 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include "buildinfo.h" @@ -14,7 +14,7 @@ template void unique(list &l) { set seen; - for(typename list::iterator i=l.begin(); i!=l.end(); ) + for(auto i=l.begin(); i!=l.end(); ) { if(seen.count(*i)) l.erase(i++); @@ -47,22 +47,22 @@ BuildInfo::LibraryMode BuildInfo::get_libmode_for(const string &lib) const void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level) { - for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i) - defines[i->first] = i->second; + for(const auto &kvp: bi.defines) + defines[kvp.first] = kvp.second; incpath.insert(incpath.begin(), bi.incpath.begin(), bi.incpath.end()); threads = bi.threads; - for(StandardMap::const_iterator i=bi.standards.begin(); i!=bi.standards.end(); ++i) + for(const auto &kvp: bi.standards) { - StandardMap::iterator j = standards.find(i->first); + StandardMap::iterator j = standards.find(kvp.first); if(j==standards.end()) - standards.insert(*i); - else if(i->second.type!=j->second.type || i->second.year!=j->second.year) + standards.insert(kvp); + else if(kvp.second.type!=j->second.type || kvp.second.year!=j->second.year) { - if(!i->second.type.compare(0, 3, "gnu")) - j->second.type = i->second.type; - if(i->second.year>j->second.year) - j->second.year = i->second.year; + if(!kvp.second.type.compare(0, 3, "gnu")) + j->second.type = kvp.second.type; + if(kvp.second.year>j->second.year) + j->second.year = kvp.second.year; } } @@ -78,8 +78,8 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level) local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end()); libmode = bi.libmode; rpath_mode = bi.rpath_mode; - for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i) - libmodes[i->first] = i->second; + for(const auto &kvp: bi.libmodes) + libmodes[kvp.first] = kvp.second; keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end()); debug = bi.debug; optimize = bi.optimize; @@ -98,10 +98,8 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level) BuildInfo::LanguageStandard::LanguageStandard(const string &std) { - string::size_type num = string::npos; - for(string::size_type i=0; (num==string::npos && i(std[i]))) - num = i; + auto i = find_if(std, [](char c){ return isdigit(static_cast(c)); }); + string::size_type num = i-std.begin(); type = std.substr(0, num); year = lexical_cast(std.substr(num)); year += (year<70 ? 2000 : 1900); diff --git a/source/cache.cpp b/source/cache.cpp index de4643c..b8c71af 100644 --- a/source/cache.cpp +++ b/source/cache.cpp @@ -141,13 +141,13 @@ void Cache::save() const package.get_builder().get_logger().log("files", format("Writing %s", filename)); IO::BufferedFile out(filename.str(), IO::M_WRITE); - for(DataMap::const_iterator i=data.begin(); i!=data.end(); ++i) + for(const auto &kvp: data) { - write_string(out, i->first.first); - write_string(out, i->first.second); - write_count(out, i->second.size()); - for(ValueList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j) - write_string(out, *j); + write_string(out, kvp.first.first); + write_string(out, kvp.first.second); + write_count(out, kvp.second.size()); + for(const string &v: kvp.second) + write_string(out, v); } changed = false; diff --git a/source/chainedtask.cpp b/source/chainedtask.cpp index 066dc22..a5a6d86 100644 --- a/source/chainedtask.cpp +++ b/source/chainedtask.cpp @@ -1,6 +1,8 @@ +#include #include "chainedtask.h" using namespace std; +using namespace Msp; ChainedTask::ChainedTask(Task *t): current(0), @@ -11,8 +13,8 @@ ChainedTask::ChainedTask(Task *t): ChainedTask::~ChainedTask() { - for(vector::iterator i=tasks.begin(); i!=tasks.end(); ++i) - delete *i; + for(Task *t: tasks) + delete t; } void ChainedTask::add_task(Task *t) @@ -23,12 +25,8 @@ void ChainedTask::add_task(Task *t) string ChainedTask::get_command() const { string cmd; - for(vector::const_iterator i=tasks.begin(); i!=tasks.end(); ++i) - { - if(i!=tasks.begin()) - cmd += '\n'; - cmd += (*i)->get_command(); - } + for(Task *t: tasks) + append(cmd, "\n", t->get_command()); return cmd; } diff --git a/source/compilecommandsgenerator.cpp b/source/compilecommandsgenerator.cpp index 07ee15e..2f4e07b 100644 --- a/source/compilecommandsgenerator.cpp +++ b/source/compilecommandsgenerator.cpp @@ -41,13 +41,12 @@ void CompileCommandsGenerator::Worker::main() IO::print(out, "["); bool first = true; - const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets(); - for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->is_buildable() && i->second->get_package()==&spkg) - if(ObjectFile *obj = dynamic_cast(i->second)) + for(const auto &kvp: builder.get_build_graph().get_targets()) + if(kvp.second->is_buildable() && kvp.second->get_package()==&spkg) + if(ObjectFile *obj = dynamic_cast(kvp.second)) { FS::Path src_path = obj->get_source().get_path(); - Task *task = i->second->build(); + Task *task = kvp.second->build(); if(!first) out.put(','); IO::print(out, "\n\t{\n"); diff --git a/source/compilecommandsjson.cpp b/source/compilecommandsjson.cpp index a8a1929..ff24d7e 100644 --- a/source/compilecommandsjson.cpp +++ b/source/compilecommandsjson.cpp @@ -11,8 +11,7 @@ CompileCommandsJson::CompileCommandsJson(Builder &b, const SourcePackage &p): void CompileCommandsJson::find_dependencies() { - const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets(); - for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->is_buildable() && i->second->get_package()==package && dynamic_cast(i->second)) - i->second->prepare(); + for(const auto &kvp: builder.get_build_graph().get_targets()) + if(kvp.second->is_buildable() && kvp.second->get_package()==package && dynamic_cast(kvp.second)) + kvp.second->prepare(); } diff --git a/source/component.cpp b/source/component.cpp index 2d09f8a..0e183b5 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -19,8 +19,8 @@ Component::Component(SourcePackage &p, const string &n): void Component::prepare() { - for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i) - (*i)->prepare(); + for(Package *r: requires) + r->prepare(); } void Component::create_build_info() @@ -32,27 +32,26 @@ void Component::create_build_info() direct_reqs.insert(direct_reqs.end(), pkg_reqs.begin(), pkg_reqs.end()); Package::Requirements all_reqs = direct_reqs; - for(Package::Requirements::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i) + for(Package *r: all_reqs) { BuildInfo::UpdateLevel level = BuildInfo::CHAINED; - if(find(direct_reqs.begin(), direct_reqs.end(), *i)!=direct_reqs.end()) + if(find(direct_reqs.begin(), direct_reqs.end(), r)!=direct_reqs.end()) level = BuildInfo::DEPENDENCY; - final_build_info.update_from((*i)->get_exported_build_info(), level); + final_build_info.update_from(r->get_exported_build_info(), level); - const Package::Requirements &reqs = (*i)->get_required_packages(); - for(Package::Requirements::const_iterator j=reqs.begin(); j!=reqs.end(); ++j) - if(find(all_reqs.begin(), all_reqs.end(), *j)==all_reqs.end()) - all_reqs.push_back(*j); + for(Package *q: r->get_required_packages()) + if(find(all_reqs.begin(), all_reqs.end(), q)==all_reqs.end()) + all_reqs.push_back(q); } final_build_info.update_from(package.get_build_info()); final_build_info.update_from(build_info); build_info = final_build_info; - for(BuildInfo::PathList::iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i) - *i = (package.get_source_directory() / *i).str(); - for(BuildInfo::PathList::iterator i=build_info.libpath.begin(); i!=build_info.libpath.end(); ++i) - *i = (package.get_source_directory() / *i).str(); + for(FS::Path &p: build_info.incpath) + p = (package.get_source_directory()/p).str(); + for(FS::Path &p: build_info.libpath) + p = (package.get_source_directory()/p).str(); } BuildInfo Component::get_build_info_for_path(const FS::Path &path) const @@ -76,20 +75,15 @@ BuildInfo Component::get_build_info_for_path(const FS::Path &path) const { FS::Path dir = FS::dirname(path); string last = FS::basename(dir); - for(OverlayList::const_iterator i=overlays.begin(); i!=overlays.end(); ++i) - if(last==*i) - { - dir = FS::dirname(dir); - break; - } + if(any_equals(overlays, last)) + dir = FS::dirname(dir); - for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i) - if(dir==*i) - { - binfo.local_incpath.push_back(dir); - for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j) - binfo.local_incpath.push_back(*i/ *j); - } + if(any_equals(sources, dir)) + { + binfo.local_incpath.push_back(dir); + for(const string &o: overlays) + binfo.local_incpath.push_back(dir/o); + } } return binfo; } @@ -97,33 +91,31 @@ BuildInfo Component::get_build_info_for_path(const FS::Path &path) const Component::SourceList Component::collect_source_files() const { SourceList files; - for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i) + for(const FS::Path &p: sources) { - FS::Path path(*i); - if(FS::is_dir(path)) + if(FS::is_dir(p)) { SourceList dirs; - dirs.push_back(path); - for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j) + dirs.push_back(p); + for(const string &o: overlays) { - FS::Path opath = path / *j; + FS::Path opath = p/o; if(FS::is_dir(opath)) dirs.push_back(opath); } set overlay_files; - for(SourceList::const_iterator j=dirs.begin(); j!=dirs.end(); ++j) + for(auto j=dirs.begin(); j!=dirs.end(); ++j) { package.get_builder().get_logger().log("files", format("Traversing %s", *j)); - vector sfiles = list_files(*j); - for(vector::iterator k=sfiles.begin(); k!=sfiles.end(); ++k) + for(const string &f: list_files(*j)) { if(j!=dirs.begin()) { - if(overlay_files.count(*k)) + if(overlay_files.count(f)) continue; - overlay_files.insert(*k); + overlay_files.insert(f); } - FS::Path fn = *j / *k; + FS::Path fn = *j/f; if(!FS::is_dir(fn)) files.push_back(fn); } @@ -131,10 +123,10 @@ Component::SourceList Component::collect_source_files() const } else { - files.push_back(path); - for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j) + files.push_back(p); + for(const string &o: overlays) { - FS::Path opath = FS::dirname(path)/ *j/FS::basename(path); + FS::Path opath = FS::dirname(p)/o/FS::basename(p); if(FS::is_reg(opath)) files.push_back(opath); } diff --git a/source/config.cpp b/source/config.cpp index 36e7870..3e862ec 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -82,8 +82,8 @@ void Config::save() const package.get_builder().get_logger().log("files", format("Writing %s", fn)); IO::BufferedFile out(fn.str(), IO::M_WRITE); - for(OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i) - IO::print(out, "option \"%s\" \"%s\";\n", i->second.name, i->second.value); + for(const auto &kvp: options) + IO::print(out, "option \"%s\" \"%s\";\n", kvp.second.name, kvp.second.value); changed = false; } diff --git a/source/csourcefile.cpp b/source/csourcefile.cpp index 0034ebd..954fdba 100644 --- a/source/csourcefile.cpp +++ b/source/csourcefile.cpp @@ -62,12 +62,9 @@ void CSourceFile::find_dependencies() Tool *compiler = builder.get_toolchain().get_tool_for_suffix(FS::extpart(FS::basename(path)), true); if(compiler) compiler->prepare(); - for(IncludeList::iterator i=includes.begin(); i!=includes.end(); ++i) - { - Target *hdr = builder.get_vfs().find_header(i->substr(1), compiler, ((*i)[0]=='"' ? local_incpath : incpath)); - if(hdr) + for(const string &i: includes) + if(Target *hdr = builder.get_vfs().find_header(i.substr(1), compiler, (i[0]=='"' ? local_incpath : incpath))) add_transitive_dependency(*hdr); - } } void CSourceFile::modified() diff --git a/source/datacollection.cpp b/source/datacollection.cpp index 66e9a04..c34c9cc 100644 --- a/source/datacollection.cpp +++ b/source/datacollection.cpp @@ -22,7 +22,6 @@ Msp::FS::Path DataCollection::generate_target_path(const Component &comp, const void DataCollection::find_dependencies() { source.prepare(); - const Target::Dependencies &tdeps = source.get_transitive_dependencies(); - for(Target::Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i) - add_dependency(**i); + for(Target *d: source.get_transitive_dependencies()) + add_dependency(*d); } diff --git a/source/datapack.cpp b/source/datapack.cpp index 2b3d9f2..cb207d4 100644 --- a/source/datapack.cpp +++ b/source/datapack.cpp @@ -9,8 +9,8 @@ DataPack::DataPack(Builder &b, const Component &c, const list &f): files(f) { component = &c; - for(list::const_iterator i=files.begin(); i!=files.end(); ++i) - add_dependency(**i); + for(FileTarget *t: files) + add_dependency(*t); install_location = Msp::FS::Path("share")/package->get_name(); } diff --git a/source/datapackcomponent.cpp b/source/datapackcomponent.cpp index 0b8d020..b95770f 100644 --- a/source/datapackcomponent.cpp +++ b/source/datapackcomponent.cpp @@ -18,19 +18,18 @@ void DataPackComponent::create_targets() const Tool &dcomp = builder.get_toolchain().get_tool("DATA"); list files; - SourceList source_filenames = collect_source_files(); - for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i) + for(const FS::Path &s: collect_source_files()) { - string ext = FS::extpart(FS::basename(*i)); + string ext = FS::extpart(FS::basename(s)); if(ext==".mdt") { - Target *src = dcomp.create_source(*this, *i); + Target *src = dcomp.create_source(*this, s); files.push_back(dcomp.create_target(*src, "collection")); } - else if(Target *tgt = builder.get_vfs().get_target(*i)) + else if(Target *tgt = builder.get_vfs().get_target(s)) files.push_back(tgt); else - files.push_back(new DataSourceFile(builder, *this, *i)); + files.push_back(new DataSourceFile(builder, *this, s)); } Target *result = dcomp.create_target(files, "pack"); diff --git a/source/datatool.cpp b/source/datatool.cpp index 75ec2da..ca2f2e4 100644 --- a/source/datatool.cpp +++ b/source/datatool.cpp @@ -38,8 +38,8 @@ Target *DataTool::create_target(const list &sources, const string &arg else if(arg=="pack") { list files; - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) - files.push_back(&dynamic_cast(**i)); + for(Target *t: sources) + files.push_back(&dynamic_cast(*t)); DataPack *pack = new DataPack(builder, *files.front()->get_component(), files); pack->set_tool(*this); return pack; @@ -92,9 +92,8 @@ Task *DataTool::run(const Target &tgt) const else if(const DataPack *pack = dynamic_cast(&tgt)) { argv.push_back("-p"); - const DataPack::FileList &files = pack->get_files(); - for(DataPack::FileList::const_iterator i=files.begin(); i!=files.end(); ++i) - argv.push_back(FS::relative((*i)->get_path(), work_dir).str()); + for(const FileTarget *f: pack->get_files()) + argv.push_back(FS::relative(f->get_path(), work_dir).str()); } return new ExternalTask(argv, work_dir); diff --git a/source/datatransform.cpp b/source/datatransform.cpp index 7b221b3..4f5806c 100644 --- a/source/datatransform.cpp +++ b/source/datatransform.cpp @@ -49,12 +49,12 @@ void DataTransform::find_dependencies() dir_files = list_files(dir); } - for(DataFile::Statement::Arguments::const_iterator i=st.args.begin(); i!=st.args.end(); ++i) + for(const DataFile::Value &a: st.args) { - Regex re(i->get()); - for(vector::const_iterator j=dir_files.begin(); j!=dir_files.end(); ++j) - if(re.match(*j)) - files.push_back(*j); + Regex re(a.get()); + for(const string &f: dir_files) + if(re.match(f)) + files.push_back(f); } } else if(st.keyword=="file" && st.args.size()==1) @@ -64,9 +64,9 @@ void DataTransform::find_dependencies() cache.set_values(this, "files", files); } - for(list::iterator i=files.begin(); i!=files.end(); ++i) + for(const string &f: files) { - FS::Path file_path = FS::dirname(path)/ *i; + FS::Path file_path = FS::dirname(path)/f; if(Target *tgt = builder.get_vfs().get_target(file_path)) add_transitive_dependency(*tgt); else diff --git a/source/exportdefinitions.cpp b/source/exportdefinitions.cpp index 7e49721..1af7603 100644 --- a/source/exportdefinitions.cpp +++ b/source/exportdefinitions.cpp @@ -10,8 +10,8 @@ ExportDefinitions::ExportDefinitions(Builder &b, const Component &c, const list< FileTarget(b, c.get_package(), generate_target_path(c)) { component = &c; - for(list::const_iterator i=objs.begin(); i!=objs.end(); ++i) - add_dependency(**i); + for(ObjectFile *o: objs) + add_dependency(*o); } FS::Path ExportDefinitions::generate_target_path(const Component &comp) diff --git a/source/externaltask.cpp b/source/externaltask.cpp index 16d1df0..33ffceb 100644 --- a/source/externaltask.cpp +++ b/source/externaltask.cpp @@ -31,16 +31,16 @@ ExternalTask::~ExternalTask() string ExternalTask::get_command() const { string cmd; - for(vector::const_iterator i=argv.begin(); i!=argv.end(); ++i) + for(const string &a: argv) { - if(i!=argv.begin()) + if(!cmd.empty()) cmd += ' '; - for(string::const_iterator j=i->begin(); j!=i->end(); ++j) + for(char c: a) { - if(*j=='"' || *j=='\'' || *j==' ' || *j=='\\' || *j=='&') + if(c=='"' || c=='\'' || c==' ' || c=='\\' || c=='&') cmd += '\\'; - cmd += *j; + cmd += c; } } diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 51a92d1..493f020 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -79,22 +80,24 @@ void FileTarget::check_rebuild() mark_rebuild("Does not exist"); else { - for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i) + for(Target *d: depends) { - FileTarget *ft = dynamic_cast(*i); + FileTarget *ft = dynamic_cast(d); if(ft && ft->get_mtime()>mtime) - mark_rebuild((*i)->get_name()+" has changed"); - else if((*i)->needs_rebuild()) - mark_rebuild((*i)->get_name()+" needs rebuilding"); + mark_rebuild(d->get_name()+" has changed"); + else if(d->needs_rebuild()) + mark_rebuild(d->get_name()+" needs rebuilding"); + if(needs_rebuild()) + break; } } if(!needs_rebuild()) { // Some side effects might not exist - for(Dependencies::iterator i=side_effects.begin(); (i!=side_effects.end() && !needs_rebuild()); ++i) - if((*i)->needs_rebuild()) - mark_rebuild((*i)->get_name()+" needs rebuilding"); + auto i = find_if(side_effects, [](const Target *s){ return s->needs_rebuild(); }); + if(i!=side_effects.end()) + mark_rebuild((*i)->get_name()+" needs rebuilding"); } if(!needs_rebuild() && package) @@ -124,12 +127,12 @@ string FileTarget::create_build_signature() const if(nested_build_sig && component) { set depend_tools; - for(Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) - if((*i)->get_component()==component && (*i)->get_tool()) - depend_tools.insert((*i)->get_tool()); + for(Target *d: depends) + if(d->get_component()==component && d->get_tool()) + depend_tools.insert(d->get_tool()); - for(set::const_iterator i=depend_tools.begin(); i!=depend_tools.end(); ++i) - sigs.push_back((*i)->create_build_signature(binfo)); + for(const Tool *t: depend_tools) + sigs.push_back(t->create_build_signature(binfo)); sigs.sort(); sigs.push_front(tool->create_build_signature(binfo)); } diff --git a/source/gnuarchiver.cpp b/source/gnuarchiver.cpp index 1700070..7e79ec0 100644 --- a/source/gnuarchiver.cpp +++ b/source/gnuarchiver.cpp @@ -27,9 +27,9 @@ Target *GnuArchiver::create_target(const list &sources, const string & throw invalid_argument("GnuArchiver::create_target"); list objs; - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) + for(Target *s: sources) { - if(ObjectFile *obj = dynamic_cast(*i)) + if(ObjectFile *obj = dynamic_cast(s)) objs.push_back(obj); else throw invalid_argument("GnuArchiver::create_target"); @@ -59,9 +59,8 @@ Task *GnuArchiver::run(const Target &target) const argv.push_back(relative(lib.get_path(), work_dir).str()); - const Target::Dependencies &deps = lib.get_dependencies(); - for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) - if(ObjectFile *obj = dynamic_cast(*i)) + for(Target *d: lib.get_dependencies()) + if(ObjectFile *obj = dynamic_cast(d)) argv.push_back(relative(obj->get_path(), work_dir).str()); return new ExternalTask(argv, work_dir); diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index 2752ff4..3903c6a 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -254,20 +254,20 @@ Task *GnuCompiler::run(const Target &target) const const FS::Path &sysroot = binfo.sysroot; if(!sysroot.empty()) argv.push_back("--sysroot="+sysroot.str()); - for(BuildInfo::PathList::const_iterator i=binfo.local_incpath.begin(); i!=binfo.local_incpath.end(); ++i) + for(const FS::Path &p: binfo.local_incpath) { argv.push_back("-iquote"); - argv.push_back(i->str()); + argv.push_back(p.str()); } - for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i) - argv.push_back("-I"+i->str()); + for(const FS::Path &p: binfo.incpath) + argv.push_back("-I"+p.str()); - for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i) + for(const auto &kvp: binfo.defines) { - if(i->second.empty()) - argv.push_back(format("-D%s", i->first)); + if(kvp.second.empty()) + argv.push_back(format("-D%s", kvp.first)); else - argv.push_back(format("-D%s=%s", i->first, i->second)); + argv.push_back(format("-D%s=%s", kvp.first, kvp.second)); } if(binfo.debug) diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 2d37a4d..c592cc8 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -45,9 +45,9 @@ Target *GnuLinker::create_target(const list &sources, const string &ar throw invalid_argument("GnuLinker::create_target"); list objs; Linker *linker = default_linker; - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) + for(Target *s: sources) { - if(ObjectFile *obj = dynamic_cast(*i)) + if(ObjectFile *obj = dynamic_cast(s)) { objs.push_back(obj); if(obj->get_tool()->get_tag()=="CXX") @@ -280,8 +280,8 @@ Task *GnuLinker::Linker::run(const Target &target) const argv.push_back("-Wl,-rpath-link,"+lib_dir.str()); } - for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i) - argv.push_back("-L"+i->str()); + for(const FS::Path &p: binfo.libpath) + argv.push_back("-L"+p.str()); if(binfo.strip) argv.push_back("-s"); if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin") @@ -294,16 +294,15 @@ Task *GnuLinker::Linker::run(const Target &target) const argv.push_back("-o"); argv.push_back(relative(bin.get_path(), work_dir).str()); - for(BuildInfo::WordList::const_iterator i=binfo.keep_symbols.begin(); i!=binfo.keep_symbols.end(); ++i) - argv.push_back("-u"+*i); + for(const string &s: binfo.keep_symbols) + argv.push_back("-u"+s); bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC); - const Target::Dependencies &depends = target.get_dependencies(); - for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) + for(Target *d: target.get_dependencies()) { - FileTarget *file = dynamic_cast(*i); - Target *tgt = (*i)->get_real_target(); + FileTarget *file = dynamic_cast(d); + Target *tgt = d->get_real_target(); if(ObjectFile *obj = dynamic_cast(tgt)) argv.push_back(relative(obj->get_path(), work_dir).str()); @@ -325,11 +324,11 @@ Task *GnuLinker::Linker::run(const Target &target) const } } - for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i) - if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework")) + for(const string &l: binfo.libs) + if(l.size()>10 && !l.compare(l.size()-10, 10, ".framework")) { argv.push_back("-framework"); - argv.push_back(i->substr(0, i->size()-10)); + argv.push_back(l.substr(0, l.size()-10)); } if(static_link_ok) diff --git a/source/installcomponent.cpp b/source/installcomponent.cpp index ed3c191..319053f 100644 --- a/source/installcomponent.cpp +++ b/source/installcomponent.cpp @@ -5,6 +5,7 @@ #include "tool.h" using namespace std; +using namespace Msp; InstallComponent::InstallComponent(SourcePackage &p, const string &n): Component(p, n) @@ -16,12 +17,11 @@ void InstallComponent::create_targets() const Target *inst = builder.get_build_graph().get_target("install"); Tool © = builder.get_toolchain().get_tool("CP"); - SourceList source_filenames = collect_source_files(); - for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i) + for(const FS::Path &s: collect_source_files()) { - Target *tgt = builder.get_vfs().get_target(*i); + Target *tgt = builder.get_vfs().get_target(s); if(!tgt) - tgt = new File(builder, package, *i); + tgt = new File(builder, package, s); inst->add_dependency(*copy.create_target(*tgt, name)); } } diff --git a/source/installmap.cpp b/source/installmap.cpp index 8f1995b..448f997 100644 --- a/source/installmap.cpp +++ b/source/installmap.cpp @@ -1,3 +1,4 @@ +#include #include #include "component.h" #include "filetarget.h" @@ -23,11 +24,9 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const if(comp && !comp->get_overlays().empty()) { // Check if the target resides in an overlay directory - const Component::OverlayList &overlays = comp->get_overlays(); string last_dir = FS::basename(FS::dirname(target.get_path())); - for(Component::OverlayList::const_iterator i=overlays.begin(); i!=overlays.end(); ++i) - if(last_dir==*i) - overlay_depth = 1; + if(any_equals(comp->get_overlays(), last_dir)) + overlay_depth = 1; } FS::Path source = target.get_path(); @@ -40,9 +39,8 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const if(temp_depth>0) { // If it is, use the generating template's directory instead - const Target::Dependencies &deps = target.get_dependencies(); - for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) - if(const TemplateFile *tmpl = dynamic_cast(*i)) + for(Target *d: target.get_dependencies()) + if(const TemplateFile *tmpl = dynamic_cast(d)) { source = FS::dirname(tmpl->get_path())/FS::basename(source); break; @@ -53,15 +51,15 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const /* Look for a mapping entry matching both the target's original location and default install location */ FS::Path install = target.get_install_location(); - for(list::const_iterator i=entries.begin(); i!=entries.end(); ++i) + for(const Entry &e: entries) { - int source_depth = FS::descendant_depth(source, i->source); + int source_depth = FS::descendant_depth(source, e.source); if(source_depth>=0) { - FS::Path install_base = FS::common_ancestor(install, i->install); + FS::Path install_base = FS::common_ancestor(install, e.install); if(install_base.size()>1) { - install = i->install/source.subpath(i->source.size(), source_depth-1-overlay_depth); + install = e.install/source.subpath(e.source.size(), source_depth-1-overlay_depth); break; } } diff --git a/source/mingwdlltool.cpp b/source/mingwdlltool.cpp index 03babd4..dc9022e 100644 --- a/source/mingwdlltool.cpp +++ b/source/mingwdlltool.cpp @@ -28,9 +28,8 @@ Target *MingwDllTool::create_target(const list &sources, const string SharedLibrary &shlib = dynamic_cast(*sources.front()); list objs; - const Target::Dependencies &depends = shlib.get_dependencies(); - for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) - if(ObjectFile *obj = dynamic_cast(*i)) + for(Target *d: shlib.get_dependencies()) + if(ObjectFile *obj = dynamic_cast(d)) objs.push_back(obj); ExportDefinitions *exp = new ExportDefinitions(builder, *shlib.get_component(), objs); @@ -100,12 +99,9 @@ Task *MingwDllTool::run(const Target &target) const } else { - const Target::Dependencies &depends = exp->get_dependencies(); - for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) - { - if(ObjectFile *obj = dynamic_cast(*i)) + for(Target *d: exp->get_dependencies()) + if(ObjectFile *obj = dynamic_cast(d)) argv.push_back(relative(obj->get_path(), work_dir).str()); - } // XXX Should use dllexport, but that has some other problems to solve argv.push_back("--export-all-symbols"); diff --git a/source/msvcarchiver.cpp b/source/msvcarchiver.cpp index 1481184..a724eb1 100644 --- a/source/msvcarchiver.cpp +++ b/source/msvcarchiver.cpp @@ -25,9 +25,9 @@ Target *MsvcArchiver::create_target(const list &sources, const string throw invalid_argument("MsvcArchiver::create_target"); list objs; - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) + for(Target *s: sources) { - if(ObjectFile *obj = dynamic_cast(*i)) + if(ObjectFile *obj = dynamic_cast(s)) objs.push_back(obj); else throw invalid_argument("MsvcArchiver::create_target"); @@ -57,9 +57,8 @@ Task *MsvcArchiver::run(const Target &target) const argv.push_back("/OUT:"+relative(lib.get_path(), work_dir).str()); - const Target::Dependencies &deps = lib.get_dependencies(); - for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) - if(ObjectFile *obj = dynamic_cast(*i)) + for(Target *d: lib.get_dependencies()) + if(ObjectFile *obj = dynamic_cast(d)) argv.push_back(relative(obj->get_path(), work_dir).str()); return new ExternalTask(argv, work_dir); diff --git a/source/msvccompiler.cpp b/source/msvccompiler.cpp index 0e1a1f4..c676790 100644 --- a/source/msvccompiler.cpp +++ b/source/msvccompiler.cpp @@ -84,10 +84,10 @@ void MsvcCompiler::do_prepare() system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"um"); string path; - for(SearchPath::const_iterator i=system_path.begin(); i!=system_path.end(); ++i) + for(const FS::Path &p: system_path) { - append(path, ";", i->str()); - builder.get_logger().log("tools", format("Got %s system path: %s", tag, *i)); + append(path, ";", p.str()); + builder.get_logger().log("tools", format("Got %s system path: %s", tag, p)); } setenv("INCLUDE", path); @@ -130,24 +130,24 @@ Task *MsvcCompiler::run(const Target &target) const else argv.push_back("/w"); - for(BuildInfo::PathList::const_iterator i=binfo.local_incpath.begin(); i!=binfo.local_incpath.end(); ++i) + for(const FS::Path &p: binfo.local_incpath) { argv.push_back("/I"); - argv.push_back(i->str()); + argv.push_back(p.str()); } - for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i) + for(const FS::Path &p: binfo.incpath) { argv.push_back("/I"); - argv.push_back(i->str()); + argv.push_back(p.str()); } - for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i) + for(const auto &kvp: binfo.defines) { argv.push_back("/D"); - if(i->second.empty()) - argv.push_back(i->first); + if(kvp.second.empty()) + argv.push_back(kvp.first); else - argv.push_back(format("%s=%s", i->first, i->second)); + argv.push_back(format("%s=%s", kvp.first, kvp.second)); } if(binfo.debug) diff --git a/source/msvclinker.cpp b/source/msvclinker.cpp index 46d89f7..4974428 100644 --- a/source/msvclinker.cpp +++ b/source/msvclinker.cpp @@ -35,9 +35,9 @@ Target *MsvcLinker::create_target(const list &sources, const string &a throw invalid_argument("MsvcLinker::create_target"); list objs; - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) + for(Target *s: sources) { - if(ObjectFile *obj = dynamic_cast(*i)) + if(ObjectFile *obj = dynamic_cast(s)) objs.push_back(obj); else throw invalid_argument("MsvcLinker::create_target"); @@ -80,10 +80,10 @@ void MsvcLinker::do_prepare() system_path.push_back(win_sdk_dir/"lib"/win_sdk_ver/"um"/arch_dir); string path; - for(SearchPath::const_iterator i=system_path.begin(); i!=system_path.end(); ++i) + for(const FS::Path &p: system_path) { - append(path, ";", i->str()); - builder.get_logger().log("tools", format("Got %s system path: %s", tag, *i)); + append(path, ";", p.str()); + builder.get_logger().log("tools", format("Got %s system path: %s", tag, p)); } setenv("LIB", path); @@ -105,8 +105,8 @@ Task *MsvcLinker::run(const Target &target) const BuildInfo binfo; target.collect_build_info(binfo); - /*for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i) - argv.push_back("/LIBPATH:"+i->str());*/ + /*for(const FS::Path &p: binfo.libpath) + argv.push_back("/LIBPATH:"+p.str());*/ if(binfo.strip) argv.push_back("/INCREMENTAL:NO"); else @@ -114,11 +114,10 @@ Task *MsvcLinker::run(const Target &target) const argv.push_back("/OUT:"+relative(bin.get_path(), work_dir).str()); - const Target::Dependencies &depends = target.get_dependencies(); - for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i) + for(Target *d: target.get_dependencies()) { - FileTarget *file = dynamic_cast(*i); - Target *tgt = (*i)->get_real_target(); + FileTarget *file = dynamic_cast(d); + Target *tgt = d->get_real_target(); if(ObjectFile *obj = dynamic_cast(tgt)) argv.push_back(relative(obj->get_path(), work_dir).str()); diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 8196ef7..f78686e 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "builder.h" #include "component.h" @@ -28,12 +28,12 @@ FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path else rel_src = FS::relative(src, pkg.get_source_directory()); string fn; - for(FS::Path::Iterator i=rel_src.begin(); i!=rel_src.end(); ++i) + for(const string &c: rel_src) { if(!fn.empty()) fn += '_'; - if(*i!=".") - fn += *i; + if(c!=".") + fn += c; } const Architecture &arch = comp.get_package().get_builder().get_current_arch(); return temp_dir/comp.get_name()/arch.create_filename(FS::basepart(fn)); @@ -52,10 +52,10 @@ void ObjectFile::collect_build_info(BuildInfo &binfo) const void ObjectFile::find_dependencies() { - for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i) + for(Target *d: depends) { - (*i)->prepare(); - find_dependencies(dynamic_cast(*i)); + d->prepare(); + find_dependencies(dynamic_cast(d)); } } @@ -76,9 +76,9 @@ void ObjectFile::find_dependencies(FileTarget *tgt) /* The target has been displaced by installing it. Displace any dependencies that come from the same package as well. */ const SourcePackage *tpkg = rtgt->get_package(); - for(Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i) + for(Target *d: tdeps) { - FileTarget *file = dynamic_cast(*i); + FileTarget *file = dynamic_cast(d); if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source_directory())>=0) { const Component *tcomp = file->get_component(); @@ -88,27 +88,25 @@ void ObjectFile::find_dependencies(FileTarget *tgt) deps_to_add.push_back(ddep); else { - const Component::OverlayList &overlays = tcomp->get_overlays(); string last_dir = FS::basename(FS::dirname(displaced)); - for(Component::OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j) - if(last_dir==*j) - { - displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path()); - if((ddep = builder.get_vfs().get_target(displaced))) - deps_to_add.push_back(ddep); - } + if(any_equals(tcomp->get_overlays(), last_dir)) + { + displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path()); + if((ddep = builder.get_vfs().get_target(displaced))) + deps_to_add.push_back(ddep); + } } } else - deps_to_add.push_back(*i); + deps_to_add.push_back(d); } } - for(Dependencies::const_iterator i=deps_to_add.begin(); i!=deps_to_add.end(); ++i) - if(find(depends.begin(), depends.end(), *i)==depends.end()) + for(Target *d: deps_to_add) + if(find(depends.begin(), depends.end(), d)==depends.end()) { - add_dependency(**i); - if((*i)->get_real_target()->is_buildable()) - (*i)->signal_modified.connect(sigc::mem_fun(this, static_cast(&ObjectFile::find_dependencies))); + add_dependency(*d); + if(d->get_real_target()->is_buildable()) + d->signal_modified.connect(sigc::mem_fun(this, static_cast(&ObjectFile::find_dependencies))); } } diff --git a/source/package.cpp b/source/package.cpp index e16cd37..6e570c8 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -20,8 +20,8 @@ void Package::prepare() if(prepared) return; - for(Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i) - (*i)->prepare(); + for(Package *r: requires) + r->prepare(); do_prepare(); prepared = true; diff --git a/source/packagemanager.cpp b/source/packagemanager.cpp index 35c752e..f54606f 100644 --- a/source/packagemanager.cpp +++ b/source/packagemanager.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -25,8 +26,8 @@ PackageManager::PackageManager(Builder &b): PackageManager::~PackageManager() { - for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i) - delete i->second; + for(const auto &kvp: packages) + delete kvp.second; } void PackageManager::append_package_path(const FS::Path &p) @@ -135,10 +136,7 @@ string PackageManager::run_pkgconfig(const string &pkg, const string &what) if(const char *pcp = getenv("PKG_CONFIG_PATH")) { vector path = split(pcp, ':'); - bool found = false; - for(vector::const_iterator i=path.begin(); (!found && i!=path.end()); ++i) - found = (*i==pcdir.str()); - if(!found) + if(!any_equals(path, pcdir.str())) { path.push_back(pcdir.str()); setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true); @@ -190,14 +188,13 @@ FS::Path PackageManager::get_package_location(const string &name) if(pkg_dirs.empty()) { - for(SearchPath::const_iterator i=pkg_path.begin(); i!=pkg_path.end(); ++i) + for(const FS::Path &p: pkg_path) { - builder.get_logger().log("files", format("Traversing %s", *i)); - vector files = list_files(*i); + builder.get_logger().log("files", format("Traversing %s", p)); unsigned count = 0; - for(vector::const_iterator j=files.begin(); j!=files.end(); ++j) + for(const string &f: list_files(p)) { - FS::Path full = *i / *j; + FS::Path full = p/f; if(FS::exists(full/"Build")) { pkg_dirs.push_back(full); @@ -205,22 +202,22 @@ FS::Path PackageManager::get_package_location(const string &name) } } - builder.get_logger().log("packagemgr", format("%d source packages found in %s", count, *i)); + builder.get_logger().log("packagemgr", format("%d source packages found in %s", count, p)); } builder.get_logger().log("packagemgr", format("%d source packages found", pkg_dirs.size())); } bool msp = !name.compare(0, 3, "msp"); - for(SearchPath::const_iterator i=pkg_dirs.begin(); i!=pkg_dirs.end(); ++i) + for(const FS::Path &p: pkg_dirs) { - string base = FS::basename(*i); + string base = FS::basename(p); unsigned dash = base.rfind('-'); if(!base.compare(0, dash, name)) - return *i; + return p; else if(msp && !base.compare(0, dash, name, 3, string::npos)) - return *i; + return p; } return FS::Path(); @@ -232,30 +229,27 @@ FS::Path PackageManager::get_binary_package_file(const string &name) if(binpkg_files.empty()) { - for(list::const_iterator i=binpkg_path.begin(); i!=binpkg_path.end(); ++i) + for(const FS::Path &p: binpkg_path) { - builder.get_logger().log("files", format("Traversing %s", *i)); - vector files = list_filtered(*i, "\\.bpk$"); - for(vector::const_iterator j=files.begin(); j!=files.end(); ++j) - binpkg_files.push_back(*i / *j); - builder.get_logger().log("packagemgr", format("%d binary packages found in %s", files.size(), *i)); + builder.get_logger().log("files", format("Traversing %s", p)); + vector files = list_filtered(p, "\\.bpk$"); + for(const string &f: files) + binpkg_files.push_back(p/f); + builder.get_logger().log("packagemgr", format("%d binary packages found in %s", files.size(), p)); } builder.get_logger().log("packagemgr", format("%d binary packages found", binpkg_files.size())); } - for(SearchPath::const_iterator i=binpkg_files.begin(); i!=binpkg_files.end(); ++i) - { - string base = FS::basepart(FS::basename(*i)); - if(base==name) - return *i; - } + auto i = find_if(binpkg_files, [&name](const FS::Path &p){ return FS::basepart(FS::basename(p))==name; }); + if(i!=binpkg_files.end()) + return *i; return FS::Path(); } void PackageManager::save_all_caches() const { - for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) - i->second->save_caches(); + for(const auto &kvp: packages) + kvp.second->save_caches(); } diff --git a/source/pattern.cpp b/source/pattern.cpp index 91929f6..d910f19 100644 --- a/source/pattern.cpp +++ b/source/pattern.cpp @@ -25,7 +25,7 @@ string Pattern::apply(const string &body) const list Pattern::apply_list(const list &patterns, const string &body) { list result; - for(list::const_iterator i=patterns.begin(); i!=patterns.end(); ++i) - result.push_back(i->apply(body)); + for(const Pattern &p: patterns) + result.push_back(p.apply(body)); return result; } diff --git a/source/pkgconfiggenerator.cpp b/source/pkgconfiggenerator.cpp index 949a4df..e932044 100644 --- a/source/pkgconfiggenerator.cpp +++ b/source/pkgconfiggenerator.cpp @@ -44,30 +44,29 @@ void PkgConfigGenerator::Worker::main() IO::print(out, "Version: %s\n", spkg.get_version()); IO::print(out, "Requires:"); - const Package::Requirements &reqs = spkg.get_required_packages(); - for(Package::Requirements::const_iterator i=reqs.begin(); i!=reqs.end(); ++i) - if((*i)->uses_pkgconfig()) - IO::print(out, " %s", (*i)->get_name()); + for(const Package *r: spkg.get_required_packages()) + if(r->uses_pkgconfig()) + IO::print(out, " %s", r->get_name()); out.put('\n'); const BuildInfo &binfo = spkg.get_exported_build_info(); IO::print(out, "Libs:"); - for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i) - IO::print(out, " -L%s", prefixify(*i, builder.get_prefix())); - for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i) - IO::print(out, " -l%s", *i); + for(const FS::Path &p: binfo.libpath) + IO::print(out, " -L%s", prefixify(p, builder.get_prefix())); + for(const string &l: binfo.libs) + IO::print(out, " -l%s", l); if(binfo.threads) out.write("-pthread"); out.put('\n'); IO::print(out, "Cflags:"); - for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i) - IO::print(out, " -I%s", prefixify(*i, builder.get_prefix())); - for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i) - if(i->second.empty()) - IO::print(out, " -D%s", i->first); + for(const FS::Path &p: binfo.incpath) + IO::print(out, " -I%s", prefixify(p, builder.get_prefix())); + for(const auto &kvp: binfo.defines) + if(kvp.second.empty()) + IO::print(out, " -D%s", kvp.first); else - IO::print(out, " -D%s=%s", i->first, i->second); + IO::print(out, " -D%s=%s", kvp.first, kvp.second); out.put('\n'); status = Task::SUCCESS; diff --git a/source/sharedlibrary.cpp b/source/sharedlibrary.cpp index 5e479f3..a6e8239 100644 --- a/source/sharedlibrary.cpp +++ b/source/sharedlibrary.cpp @@ -48,8 +48,8 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list::const_iterator i=objects.begin(); i!=objects.end(); ++i) - (*i)->set_used_in_shared_library(true); + for(ObjectFile *o: objects) + o->set_used_in_shared_library(true); } string SharedLibrary::generate_filename(const Component &comp) diff --git a/source/sourcearchivecomponent.cpp b/source/sourcearchivecomponent.cpp index 3304e6b..fdf82e5 100644 --- a/source/sourcearchivecomponent.cpp +++ b/source/sourcearchivecomponent.cpp @@ -6,6 +6,7 @@ #include "tool.h" using namespace std; +using namespace Msp; SourceArchiveComponent::SourceArchiveComponent(SourcePackage &p): Component(p, p.get_name()+"-source") @@ -18,21 +19,19 @@ void SourceArchiveComponent::create_targets() const list files; files.insert(files.begin(), &package.get_build_file()); - SourceList source_filenames = collect_source_files(); - for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i) + for(const FS::Path &s: collect_source_files()) { - FileTarget *file = builder.get_vfs().get_target(*i); + FileTarget *file = builder.get_vfs().get_target(s); if(!file) - file = new File(builder, package, *i); + file = new File(builder, package, s); files.push_back(file); } BuildGraph &build_graph = builder.get_build_graph(); - const BuildGraph::TargetMap &targets = build_graph.get_targets(); - for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->get_package()==&package && !i->second->is_buildable()) - if(find(files.begin(), files.end(), i->second)==files.end()) - files.push_back(i->second); + for(const auto &kvp: build_graph.get_targets()) + if(kvp.second->get_package()==&package && !kvp.second->is_buildable()) + if(find(files.begin(), files.end(), kvp.second)==files.end()) + files.push_back(kvp.second); const Toolchain &toolchain = builder.get_toolchain(); string archive_name = package.get_name(); diff --git a/source/sourcegenerator.cpp b/source/sourcegenerator.cpp index 584822a..f4b43a8 100644 --- a/source/sourcegenerator.cpp +++ b/source/sourcegenerator.cpp @@ -47,23 +47,23 @@ Target *SourceGenerator::create_target(const list &sources, const stri } Target *primary = 0; - for(list::const_iterator i=out_suffixes.begin(); i!=out_suffixes.end(); ++i) + for(const string &s: out_suffixes) { - Tool *tool = builder.get_toolchain().get_tool_for_suffix(*i, true); + Tool *tool = builder.get_toolchain().get_tool_for_suffix(s, true); if(tool) { - FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+*i); + FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+s); Target *target = tool->create_source(*comp, fn); target->set_tool(*this); - for(list::const_iterator j=sources.begin(); j!=sources.end(); ++j) - target->add_dependency(**j); + for(Target *t: sources) + target->add_dependency(*t); if(primary) primary->add_side_effect(*target); else primary = target; } else - throw runtime_error("No tool found for suffix "+*i); + throw runtime_error("No tool found for suffix "+s); } return primary; @@ -78,9 +78,8 @@ Task *SourceGenerator::run(const Target &target) const args.push_back(executable->get_path().str()); args.insert(args.end(), arguments.begin(), arguments.end()); - const Target::Dependencies &deps = target.get_dependencies(); - for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) - if(const TemplateFile *tmpl = dynamic_cast(*i)) + for(const Target *d: target.get_dependencies()) + if(const TemplateFile *tmpl = dynamic_cast(d)) args.push_back(FS::relative(tmpl->get_path(), work_dir).str()); if(!out_argument.empty()) diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index b98cd75..a89feb2 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include #include @@ -42,8 +42,8 @@ SourcePackage::SourcePackage(Builder &b, const string &n, const FS::Path &f): SourcePackage::~SourcePackage() { - for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) - delete *i; + for(Component *c: components) + delete c; } FS::Path SourcePackage::get_temp_directory() const @@ -73,9 +73,9 @@ FS::Path SourcePackage::get_output_directory() const const Component &SourcePackage::get_component(const string &n) const { - for(ComponentList::const_iterator i=components.begin(); i!=components.end(); ++i) - if((*i)->get_name()==n) - return **i; + auto i = find_if(components, [&n](const Component *c){ return c->get_name()==n; }); + if(i!=components.end()) + return **i; throw key_error(n); } @@ -106,12 +106,12 @@ void SourcePackage::do_prepare() build_info.incpath.push_back((builder.get_prefix()/"include").str()); build_info.libpath.push_back((builder.get_prefix()/"lib").str()); - for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i) + for(const Feature &f: features) { - string ident = "WITH_"+toupper(i->name); - string value = config.get_option("with_"+i->name).value; + string ident = "WITH_"+toupper(f.name); + string value = config.get_option("with_"+f.name).value; - if(i->choices.empty()) + if(f.choices.empty()) { if(!lexical_cast(value)) continue; @@ -119,22 +119,22 @@ void SourcePackage::do_prepare() } build_info.defines[ident] = value; - if(i->exported) + if(f.exported) export_binfo.defines[ident] = value; } - for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) + for(Component *c: components) { - (*i)->prepare(); - (*i)->create_build_info(); + c->prepare(); + c->create_build_info(); - (*i)->update_exported_build_info(export_binfo); + c->update_exported_build_info(export_binfo); } cache.load(); - for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i) - (*i)->create_targets(); + for(Component *c: components) + c->create_targets(); const Architecture &arch = builder.get_native_arch(); if(!export_binfo.libs.empty()) diff --git a/source/staticlibrary.cpp b/source/staticlibrary.cpp index 92a3af0..853d1b4 100644 --- a/source/staticlibrary.cpp +++ b/source/staticlibrary.cpp @@ -15,8 +15,8 @@ StaticLibrary::StaticLibrary(Builder &b, const Component &c, const list::const_iterator i=objs.begin(); i!=objs.end(); ++i) - add_dependency(**i); + for(ObjectFile *o: objs) + add_dependency(*o); install_location = "lib"; nested_build_sig = true; diff --git a/source/tar.cpp b/source/tar.cpp index 6dee843..46f95ca 100644 --- a/source/tar.cpp +++ b/source/tar.cpp @@ -23,8 +23,8 @@ Target *Tar::create_target(const list &sources, const string &arg) throw invalid_argument("Tar::create_target"); TarBall *tarball = new TarBall(builder, *sources.front()->get_package(), arg); - for(list::const_iterator i=sources.begin(); i!=sources.end(); ++i) - tarball->add_dependency(**i); + for(Target *s: sources) + tarball->add_dependency(*s); tarball->set_tool(*this); @@ -49,10 +49,9 @@ void Tar::Worker::main() FS::Path basedir = FS::basepart(FS::basename(tarball.get_path())); IO::File out(tarball.get_path().str(), IO::M_WRITE); - const Target::Dependencies &deps = tarball.get_dependencies(); - for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) + for(Target *d: tarball.get_dependencies()) { - FileTarget *ft = dynamic_cast(*i); + FileTarget *ft = dynamic_cast(d); if(!ft) continue; diff --git a/source/target.cpp b/source/target.cpp index 9006a57..49a7693 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -59,16 +59,16 @@ Target *Target::get_buildable_target() return 0; bool self_ok = state!=BUILDING; - for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i) + for(Target *d: depends) { // Avoid infinite recursion if a target repends on its own side effect - if(find(side_effects.begin(), side_effects.end(), *i)!=side_effects.end()) + if(find(side_effects.begin(), side_effects.end(), d)!=side_effects.end()) continue; - Target *tgt = (*i)->get_buildable_target(); + Target *tgt = d->get_buildable_target(); if(tgt) return tgt; - else if((*i)->needs_rebuild()) + else if(d->needs_rebuild()) self_ok = false; } @@ -81,8 +81,8 @@ Target *Target::get_buildable_target() void Target::set_tool(Tool &t) { tool = &t; - for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i) - (*i)->set_tool(t); + for(Target *s: side_effects) + s->set_tool(t); } void Target::collect_build_info(BuildInfo &binfo) const @@ -146,13 +146,13 @@ void Target::prepare() broken |= (component && !component->get_problems().empty()); } - for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i) + for(Target *d: depends) { - (*i)->prepare(); - broken |= (*i)->is_broken(); + d->prepare(); + broken |= d->is_broken(); } - for(Dependencies::iterator i=trans_depends.begin(); i!=trans_depends.end(); ++i) - (*i)->prepare(); + for(Target *d: trans_depends) + d->prepare(); check_rebuild(); if(broken) @@ -160,8 +160,8 @@ void Target::prepare() else if(state==PREPARING) state = UPTODATE; - for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i) - (*i)->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild)); + for(Target *d: depends) + d->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild)); } Task *Target::build() @@ -174,8 +174,8 @@ Task *Target::build() state = BUILDING; build(*task); - for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i) - (*i)->build(*task); + for(Target *s: side_effects) + s->build(*task); return task; } @@ -186,8 +186,8 @@ void Target::build_finished(bool success) if(success) { modified(); - for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i) - (*i)->build_finished(success); + for(Target *s: side_effects) + s->build_finished(success); signal_modified.emit(); } } diff --git a/source/task.cpp b/source/task.cpp index 75b725e..d969a7a 100644 --- a/source/task.cpp +++ b/source/task.cpp @@ -22,16 +22,16 @@ void Task::set_unlink(bool u) void Task::prepare() { - for(list::const_iterator i=files.begin(); i!=files.end(); ++i) + for(const FS::Path &f: files) { - if(FS::exists(*i)) + if(FS::exists(f)) { // If the file exists, the directory it's in must exist too - FS::unlink(*i); + FS::unlink(f); } else { - FS::Path dir = FS::dirname(*i); + FS::Path dir = FS::dirname(f); if(!FS::exists(dir)) FS::mkpath(dir, 0755); } diff --git a/source/toolchain.cpp b/source/toolchain.cpp index 953fe11..8790c83 100644 --- a/source/toolchain.cpp +++ b/source/toolchain.cpp @@ -1,3 +1,4 @@ +#include #include #include "tool.h" #include "toolchain.h" @@ -7,10 +8,10 @@ using namespace Msp; Toolchain::~Toolchain() { - for(ToolMap::iterator i=tools.begin(); i!=tools.end(); ++i) - delete i->second; - for(ToolchainList::iterator i=chains.begin(); i!=chains.end(); ++i) - delete *i; + for(const auto &kvp: tools) + delete kvp.second; + for(Toolchain *c: chains) + delete c; } void Toolchain::add_tool(Tool *tool) @@ -27,19 +28,16 @@ bool Toolchain::has_tool(const string &tag) const { if(tools.count(tag)) return true; - for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i) - if((*i)->has_tool(tag)) - return true; - return false; + return any_of(chains.begin(), chains.end(), [&tag](Toolchain *tc){ return tc->has_tool(tag); }); } Tool &Toolchain::get_tool(const string &tag) const { if(!tools.count(tag)) { - for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i) - if((*i)->has_tool(tag)) - return (*i)->get_tool(tag); + for(const Toolchain *c: chains) + if(c->has_tool(tag)) + return c->get_tool(tag); } return *get_item(tools, tag); @@ -47,12 +45,12 @@ Tool &Toolchain::get_tool(const string &tag) const Tool *Toolchain::get_tool_for_suffix(const string &suffix, bool aux) const { - for(ToolMap::const_iterator i=tools.begin(); i!=tools.end(); ++i) - if(i->second->accepts_suffix(suffix, aux)) - return i->second; + for(const auto &kvp: tools) + if(kvp.second->accepts_suffix(suffix, aux)) + return kvp.second; - for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i) - if(Tool *tool = (*i)->get_tool_for_suffix(suffix, aux)) + for(const Toolchain *c: chains) + if(Tool *tool = c->get_tool_for_suffix(suffix, aux)) return tool; return 0; diff --git a/source/vcxprojectgenerator.cpp b/source/vcxprojectgenerator.cpp index a173829..8535197 100644 --- a/source/vcxprojectgenerator.cpp +++ b/source/vcxprojectgenerator.cpp @@ -43,13 +43,13 @@ void VcxProjectGenerator::Worker::main() IO::print(out, "\t\n"); vector build_types = builder.get_build_types(); - const char *platforms[] = { "Win32", "x64", 0 }; - for(const char **i=platforms; *i; ++i) - for(vector::const_iterator j=build_types.begin(); j!=build_types.end(); ++j) + const char *platforms[] = { "Win32", "x64" }; + for(const char *p: platforms) + for(const string &b: build_types) { - IO::print(out, "\t\t\n", *j, *i); - IO::print(out, "\t\t\t%s\n", *j); - IO::print(out, "\t\t\t%s\n", *i); + IO::print(out, "\t\t\n", b, p); + IO::print(out, "\t\t\t%s\n", b); + IO::print(out, "\t\t\t%s\n", p); IO::print(out, "\t\t\n"); } IO::print(out, "\t\n"); @@ -62,20 +62,19 @@ void VcxProjectGenerator::Worker::main() IO::print(out, "\t\n"); - const Target *world = builder.get_build_graph().get_target("world"); - const Target::Dependencies &world_deps = world->get_dependencies(); const Executable *exe = 0; - for(Target::Dependencies::const_iterator i=world_deps.begin(); (!exe && i!=world_deps.end()); ++i) - if((*i)->get_package()==&spkg) - exe = dynamic_cast(*i); + for(const Target *t: builder.get_build_graph().get_target("world")->get_dependencies()) + if(t->get_package()==&spkg) + if((exe = dynamic_cast(t))) + break; const char *argv0 = Application::get_argv0(); const string &toolchain = builder.get_current_arch().get_toolchain(); - for(const char **i=platforms; *i; ++i) - for(vector::const_iterator j=build_types.begin(); j!=build_types.end(); ++j) + for(const char *p: platforms) + for(const string &b: build_types) { - string base_cmd = format("%s --arch=%s-%s --build-type=%s --prefix=%s", argv0, *i, toolchain, *j, builder.get_prefix()); - IO::print(out, "\t\n", *j, *i); + string base_cmd = format("%s --arch=%s-%s --build-type=%s --prefix=%s", argv0, p, toolchain, b, builder.get_prefix()); + IO::print(out, "\t\n", b, p); IO::print(out, "\t\tMakeFile\n"); IO::print(out, "\t\t%s\n", base_cmd); IO::print(out, "\t\t%s -c\n", base_cmd); @@ -87,21 +86,20 @@ void VcxProjectGenerator::Worker::main() IO::print(out, "\t\n"); - const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets(); vector sources; vector includes; vector others; BuildInfo build_info; - for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i) - if(i->second->get_package()==&spkg) + for(const auto &kvp: builder.get_build_graph().get_targets()) + if(kvp.second->get_package()==&spkg) { - if(i->second->is_buildable()) + if(kvp.second->is_buildable()) { BuildInfo tgt_binfo; - i->second->collect_build_info(tgt_binfo); + kvp.second->collect_build_info(tgt_binfo); build_info.update_from(tgt_binfo, BuildInfo::CHAINED); } - else if(const FileTarget *file = dynamic_cast(i->second)) + else if(const FileTarget *file = dynamic_cast(kvp.second)) { if(dynamic_cast(file)) { @@ -120,25 +118,25 @@ void VcxProjectGenerator::Worker::main() { IO::print(out, "\t\n"); string path_str; - for(BuildInfo::PathList::const_iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i) - append(path_str, ";", i->str()); + for(const FS::Path &p: build_info.incpath) + append(path_str, ";", p.str()); IO::print(out, "\t\t%s\n", path_str); IO::print(out, "\t\n"); } IO::print(out, "\t\n"); - for(vector::const_iterator i=sources.begin(); i!=sources.end(); ++i) - IO::print(out, "\t\t\n", (*i)->get_path()); + for(const FileTarget *s: sources) + IO::print(out, "\t\t\n", s->get_path()); IO::print(out, "\t\n"); IO::print(out, "\t\n"); - for(vector::const_iterator i=includes.begin(); i!=includes.end(); ++i) - IO::print(out, "\t\t\n", (*i)->get_path()); + for(const FileTarget *i: includes) + IO::print(out, "\t\t\n", i->get_path()); IO::print(out, "\t\n"); IO::print(out, "\t\n"); - for(vector::const_iterator i=others.begin(); i!=others.end(); ++i) - IO::print(out, "\t\t\n", (*i)->get_path()); + for(const FileTarget *t: others) + IO::print(out, "\t\t\n", t->get_path()); IO::print(out, "\t\n"); IO::print(out, "\t\n"); diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index e240fb9..935600d 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -51,21 +51,21 @@ FileTarget *VirtualFileSystem::find_header(const string &name, Tool *tool, const combined_path.insert(combined_path.end(), syspath.begin(), syspath.end()); } - for(list::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i) + for(const FS::Path &p: combined_path) { - FS::Path filename = *i/name; + FS::Path filename = p/name; if(FileTarget *tgt = get_target(filename)) { - builder.get_logger().log("vfs", format("Header %s found in %s as existing %s", name, i->str(), tgt->get_type())); + builder.get_logger().log("vfs", format("Header %s found in %s as existing %s", name, p.str(), tgt->get_type())); return tgt; } else if(file_exists(filename)) { - builder.get_logger().log("vfs", format("Header %s found in %s", name, i->str())); + builder.get_logger().log("vfs", format("Header %s found in %s", name, p.str())); return dynamic_cast(tool->create_source(filename)); } - builder.get_logger().log("vfs", format("Header %s not found in %s", name, i->str())); + builder.get_logger().log("vfs", format("Header %s not found in %s", name, p.str())); } return 0; @@ -97,20 +97,20 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath if(mode!=BuildInfo::FORCE_DYNAMIC) static_names = Pattern::apply_list(arch.get_patterns(), lib); - for(list::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i) + for(const FS::Path &p: combined_path) { const list *cur_names = (mode>=BuildInfo::DYNAMIC ? &shared_names : &static_names); - for(list::const_iterator j=cur_names->begin(); j!=cur_names->end(); ) + for(auto j=cur_names->begin(); j!=cur_names->end(); ) { - FS::Path filename = *i / *j; + FS::Path filename = p / *j; if(FileTarget *tgt = get_target(filename)) { - builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, i->str(), tgt->get_type())); + builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, p.str(), tgt->get_type())); return tgt; } else if(file_exists(filename)) { - builder.get_logger().log("vfs", format("Library %s (%s) found in %s", lib, *j, i->str())); + builder.get_logger().log("vfs", format("Library %s (%s) found in %s", lib, *j, p.str())); if(cur_names==&shared_names) { if(use_import_lib) @@ -133,7 +133,7 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath } } - builder.get_logger().log("vfs", format("Library %s not found in %s", lib, i->str())); + builder.get_logger().log("vfs", format("Library %s not found in %s", lib, p.str())); } return 0; @@ -149,9 +149,8 @@ FileTarget *VirtualFileSystem::find_binary(const string &name) string env_path = Msp::getenv("PATH"); if(!env_path.empty()) { - vector parts = split(env_path, ':'); - for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) - path.push_back(*i); + for(const string &p: split(env_path, ':')) + path.push_back(p); } else { @@ -160,21 +159,21 @@ FileTarget *VirtualFileSystem::find_binary(const string &name) } } - for(SearchPath::const_iterator i=path.begin(); i!=path.end(); ++i) + for(const FS::Path &p: path) { - FS::Path filename = *i/name; + FS::Path filename = p/name; if(FileTarget *tgt = get_target(filename)) { - builder.get_logger().log("vfs", format("Binary %s found in %s as existing %s", name, *i, tgt->get_type())); + builder.get_logger().log("vfs", format("Binary %s found in %s as existing %s", name, p, tgt->get_type())); return tgt; } else if(file_exists(filename)) { - builder.get_logger().log("vfs", format("Binary %s found in %s", name, *i)); + builder.get_logger().log("vfs", format("Binary %s found in %s", name, p)); return new Executable(builder, filename); } - builder.get_logger().log("vfs", format("Binary %s not found in %s", name, *i)); + builder.get_logger().log("vfs", format("Binary %s not found in %s", name, p)); } return 0; diff --git a/source/virtualtarget.cpp b/source/virtualtarget.cpp index a7b4cd7..44a3524 100644 --- a/source/virtualtarget.cpp +++ b/source/virtualtarget.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "builder.h" @@ -13,9 +14,9 @@ VirtualTarget::VirtualTarget(Builder &b, const string &n): void VirtualTarget::check_rebuild() { // Virtual targets are only rebuilt if their dependencies need rebuilding. - for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i) - if((*i)->needs_rebuild()) - mark_rebuild((*i)->get_name()+" needs rebuilding"); + auto i = find_if(depends, [](Target *d){ return d->needs_rebuild(); }); + if(i!=depends.end()) + mark_rebuild((*i)->get_name()+" needs rebuilding"); } Task *VirtualTarget::build() diff --git a/source/vssolutionfile.cpp b/source/vssolutionfile.cpp index fd13d5f..c667fc5 100644 --- a/source/vssolutionfile.cpp +++ b/source/vssolutionfile.cpp @@ -18,15 +18,14 @@ void VsSolutionFile::find_dependencies() add_dependency(*project); Package::Requirements reqs = package->get_required_packages(); - for(Package::Requirements::iterator i=reqs.begin(); i!=reqs.end(); ++i) + for(auto i=reqs.begin(); i!=reqs.end(); ++i) if(const SourcePackage *spkg = dynamic_cast(*i)) { if(FileTarget *project = builder.get_vfs().get_target(spkg->get_source_directory()/(spkg->get_name()+".vcxproj"))) add_dependency(*project); - const Package::Requirements &rreqs = spkg->get_required_packages(); - for(Package::Requirements::const_iterator j=rreqs.begin(); j!=rreqs.end(); ++j) - if(find(reqs, *j)==reqs.end()) - reqs.push_back(*j); + for(Package *r: spkg->get_required_packages()) + if(find(reqs, r)==reqs.end()) + reqs.push_back(r); } } diff --git a/source/vssolutiongenerator.cpp b/source/vssolutiongenerator.cpp index 43ed761..0c60689 100644 --- a/source/vssolutiongenerator.cpp +++ b/source/vssolutiongenerator.cpp @@ -33,43 +33,43 @@ VsSolutionGenerator::Worker::Worker(const VsSolutionFile &t): void VsSolutionGenerator::Worker::main() { - Builder &builder = target.get_package()->get_builder(); + const SourcePackage &spkg = *target.get_package(); + Builder &builder = spkg.get_builder(); IO::BufferedFile out(target.get_path().str(), IO::M_WRITE); IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n"); IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n"); - const Target::Dependencies &deps = target.get_dependencies(); vector projects; - for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i) - if(const VcxProjectFile *project = dynamic_cast(*i)) + for(const Target *t: target.get_dependencies()) + if(const VcxProjectFile *project = dynamic_cast(t)) projects.push_back(project); - for(vector::const_iterator i=projects.begin(); i!=projects.end(); ++i) + for(const VcxProjectFile *p: projects) { - const SourcePackage *pkg = (*i)->get_package(); + const SourcePackage *pkg = p->get_package(); IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n", - pkg->get_name(), (*i)->get_path(), (*i)->get_guid()); + pkg->get_name(), p->get_path(), p->get_guid()); } vector build_types = builder.get_build_types(); - const char *platforms[] = { "x86", "x64", 0 }; + const char *platforms[] = { "x86", "x64" }; IO::print(out, "Global\n"); IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n"); - for(vector::const_iterator i=build_types.begin(); i!=build_types.end(); ++i) - for(const char **j=platforms; *j; ++j) - IO::print(out, "\t\t%s|%s = %s|%s\n", *i, *j, *i, *j); + for(const string &t: build_types) + for(const char *p: platforms) + IO::print(out, "\t\t%s|%s = %s|%s\n", t, p, t, p); IO::print(out, "\tEndGlobalSection\n"); IO::print(out, "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n"); - for(vector::const_iterator i=projects.begin(); i!=projects.end(); ++i) - for(vector::const_iterator j=build_types.begin(); j!=build_types.end(); ++j) - for(const char **k=platforms; *k; ++k) + for(const VcxProjectFile *p: projects) + for(const string &t: build_types) + for(const char *f: platforms) { - const char *project_platform = (!strcmp(*k, "x86") ? "Win32" : *k); - IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform); - if(i==projects.begin()) - IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform); + const char *project_platform = (!strcmp(f, "x86") ? "Win32" : f); + IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", p->get_guid(), t, f, t, project_platform); + if(p->get_package()==&spkg) + IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", p->get_guid(), t, f, t, project_platform); } IO::print(out, "\tEndGlobalSection\n"); IO::print(out, "EndGlobal\n"); -- 2.45.2