summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw <brettw@chromium.org>2014-09-30 14:44:05 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-30 21:44:36 +0000
commitd1033b6b2a898deb3707b6f657fb94a918297a84 (patch)
treebc9df796076e6f5977f131ea31d542235a4bc320
parent9c578f786808b5b4925722fd95e328e226d813ad (diff)
downloadchromium_src-d1033b6b2a898deb3707b6f657fb94a918297a84.zip
chromium_src-d1033b6b2a898deb3707b6f657fb94a918297a84.tar.gz
chromium_src-d1033b6b2a898deb3707b6f657fb94a918297a84.tar.bz2
Replace more for loops in GN
Review URL: https://codereview.chromium.org/610293003 Cr-Commit-Position: refs/heads/master@{#297508}
-rw-r--r--tools/gn/args.cc51
-rw-r--r--tools/gn/binary_target_generator.cc10
-rw-r--r--tools/gn/builder.cc77
-rw-r--r--tools/gn/command_args.cc17
-rw-r--r--tools/gn/command_desc.cc31
-rw-r--r--tools/gn/command_help.cc36
-rw-r--r--tools/gn/command_ls.cc22
-rw-r--r--tools/gn/command_refs.cc33
-rw-r--r--tools/gn/commands.cc6
-rw-r--r--tools/gn/err.cc4
-rw-r--r--tools/gn/function_exec_script.cc12
-rw-r--r--tools/gn/function_foreach.cc4
-rw-r--r--tools/gn/function_get_path_info.cc5
-rw-r--r--tools/gn/function_get_target_outputs.cc8
-rw-r--r--tools/gn/function_process_file_template.cc4
-rw-r--r--tools/gn/function_rebase_path.cc4
-rw-r--r--tools/gn/function_toolchain.cc6
-rw-r--r--tools/gn/function_write_file.cc4
-rw-r--r--tools/gn/gn_main.cc4
-rw-r--r--tools/gn/header_checker.cc72
-rw-r--r--tools/gn/input_conversion.cc4
-rw-r--r--tools/gn/input_file_manager.cc11
-rw-r--r--tools/gn/loader.cc19
-rw-r--r--tools/gn/loader_unittest.cc9
-rw-r--r--tools/gn/ninja_action_target_writer.cc12
-rw-r--r--tools/gn/ninja_binary_target_writer.cc30
-rw-r--r--tools/gn/operators.cc15
-rw-r--r--tools/gn/parse_tree.cc32
-rw-r--r--tools/gn/parser.cc35
-rw-r--r--tools/gn/path_output.cc4
-rw-r--r--tools/gn/scope.cc76
-rw-r--r--tools/gn/setup.cc7
-rw-r--r--tools/gn/standard_out.cc4
-rw-r--r--tools/gn/substitution_list.cc4
-rw-r--r--tools/gn/substitution_writer.cc80
-rw-r--r--tools/gn/trace.cc44
-rw-r--r--tools/gn/value.cc7
-rw-r--r--tools/gn/value_extractors.cc12
-rw-r--r--tools/gn/visibility.cc13
39 files changed, 349 insertions, 479 deletions
diff --git a/tools/gn/args.cc b/tools/gn/args.cc
index 846b8b8..bce1ad2 100644
--- a/tools/gn/args.cc
+++ b/tools/gn/args.cc
@@ -89,10 +89,9 @@ void Args::AddArgOverride(const char* name, const Value& value) {
void Args::AddArgOverrides(const Scope::KeyValueMap& overrides) {
base::AutoLock lock(lock_);
- for (Scope::KeyValueMap::const_iterator i = overrides.begin();
- i != overrides.end(); ++i) {
- overrides_[i->first] = i->second;
- all_overrides_[i->first] = i->second;
+ for (const auto& cur_override : overrides) {
+ overrides_[cur_override.first] = cur_override.second;
+ all_overrides_[cur_override.first] = cur_override.second;
}
}
@@ -126,8 +125,7 @@ bool Args::DeclareArgs(const Scope::KeyValueMap& args,
Err* err) const {
base::AutoLock lock(lock_);
- for (Scope::KeyValueMap::const_iterator i = args.begin();
- i != args.end(); ++i) {
+ for (const auto& arg : args) {
// Verify that the value hasn't already been declared. We want each value
// to be declared only once.
//
@@ -135,11 +133,12 @@ bool Args::DeclareArgs(const Scope::KeyValueMap& args,
// when used from different toolchains, so we can't just check that we've
// seen it before. Instead, we check that the location matches.
Scope::KeyValueMap::iterator previously_declared =
- declared_arguments_.find(i->first);
+ declared_arguments_.find(arg.first);
if (previously_declared != declared_arguments_.end()) {
- if (previously_declared->second.origin() != i->second.origin()) {
+ if (previously_declared->second.origin() != arg.second.origin()) {
// Declaration location mismatch.
- *err = Err(i->second.origin(), "Duplicate build argument declaration.",
+ *err = Err(arg.second.origin(),
+ "Duplicate build argument declaration.",
"Here you're declaring an argument that was already declared "
"elsewhere.\nYou can only declare each argument once in the entire "
"build so there is one\ncanonical place for documentation and the "
@@ -153,15 +152,15 @@ bool Args::DeclareArgs(const Scope::KeyValueMap& args,
return false;
}
} else {
- declared_arguments_.insert(*i);
+ declared_arguments_.insert(arg);
}
// Only set on the current scope to the new value if it hasn't been already
// set. Mark the variable used so the build script can override it in
// certain cases without getting unused value errors.
- if (!scope_to_set->GetValue(i->first)) {
- scope_to_set->SetValue(i->first, i->second, i->second.origin());
- scope_to_set->MarkUsed(i->first);
+ if (!scope_to_set->GetValue(arg.first)) {
+ scope_to_set->SetValue(arg.first, arg.second, arg.second.origin());
+ scope_to_set->MarkUsed(arg.first);
}
}
@@ -177,9 +176,8 @@ bool Args::VerifyAllOverridesUsed(
const Scope::KeyValueMap& overrides,
const Scope::KeyValueMap& declared_arguments,
Err* err) {
- for (Scope::KeyValueMap::const_iterator i = overrides.begin();
- i != overrides.end(); ++i) {
- if (declared_arguments.find(i->first) == declared_arguments.end()) {
+ for (const auto& override : overrides) {
+ if (declared_arguments.find(override.first) == declared_arguments.end()) {
// Get a list of all possible overrides for help with error finding.
//
// It might be nice to do edit distance checks to see if we can find one
@@ -193,8 +191,9 @@ bool Args::VerifyAllOverridesUsed(
all_declared_str += cur_str->first.as_string();
}
- *err = Err(i->second.origin(), "Build argument has no effect.",
- "The variable \"" + i->first.as_string() + "\" was set as a build "
+ *err = Err(override.second.origin(), "Build argument has no effect.",
+ "The variable \"" + override.first.as_string() +
+ "\" was set as a build "
"argument\nbut never appeared in a declare_args() block in any "
"buildfile.\n\nPossible arguments: " + all_declared_str);
return false;
@@ -205,10 +204,8 @@ bool Args::VerifyAllOverridesUsed(
void Args::MergeDeclaredArguments(Scope::KeyValueMap* dest) const {
base::AutoLock lock(lock_);
-
- for (Scope::KeyValueMap::const_iterator i = declared_arguments_.begin();
- i != declared_arguments_.end(); ++i)
- (*dest)[i->first] = i->second;
+ for (const auto& arg : declared_arguments_)
+ (*dest)[arg.first] = arg.second;
}
void Args::SetSystemVarsLocked(Scope* dest) const {
@@ -289,14 +286,12 @@ void Args::SetSystemVarsLocked(Scope* dest) const {
void Args::ApplyOverridesLocked(const Scope::KeyValueMap& values,
Scope* scope) const {
lock_.AssertAcquired();
- for (Scope::KeyValueMap::const_iterator i = values.begin();
- i != values.end(); ++i)
- scope->SetValue(i->first, i->second, i->second.origin());
+ for (const auto& val : values)
+ scope->SetValue(val.first, val.second, val.second.origin());
}
void Args::SaveOverrideRecordLocked(const Scope::KeyValueMap& values) const {
lock_.AssertAcquired();
- for (Scope::KeyValueMap::const_iterator i = values.begin();
- i != values.end(); ++i)
- all_overrides_[i->first] = i->second;
+ for (const auto& val : values)
+ all_overrides_[val.first] = val.second;
}
diff --git a/tools/gn/binary_target_generator.cc b/tools/gn/binary_target_generator.cc
index d73c76e..deee2161 100644
--- a/tools/gn/binary_target_generator.cc
+++ b/tools/gn/binary_target_generator.cc
@@ -118,17 +118,17 @@ bool BinaryTargetGenerator::FillAllowCircularIncludesFrom() {
return false;
// Validate that all circular includes entries are in the deps.
- for (size_t circular_i = 0; circular_i < circular.size(); circular_i++) {
+ for (const auto& cur : circular) {
bool found_dep = false;
for (const auto& dep_pair : target_->GetDeps(Target::DEPS_LINKED)) {
- if (dep_pair.label == circular[circular_i]) {
+ if (dep_pair.label == cur) {
found_dep = true;
break;
}
}
if (!found_dep) {
*err_ = Err(*value, "Label not in deps.",
- "The label \"" + circular[circular_i].GetUserVisibleName(false) +
+ "The label \"" + cur.GetUserVisibleName(false) +
"\"\nwas not in the deps of this target. "
"allow_circular_includes_from only allows\ntargets present in the "
"deps.");
@@ -137,7 +137,7 @@ bool BinaryTargetGenerator::FillAllowCircularIncludesFrom() {
}
// Add to the set.
- for (size_t i = 0; i < circular.size(); i++)
- target_->allow_circular_includes_from().insert(circular[i]);
+ for (const auto& cur : circular)
+ target_->allow_circular_includes_from().insert(cur);
return true;
}
diff --git a/tools/gn/builder.cc b/tools/gn/builder.cc
index e92a7e0..ddc338a 100644
--- a/tools/gn/builder.cc
+++ b/tools/gn/builder.cc
@@ -29,13 +29,7 @@ typedef BuilderRecord::BuilderRecordSet BuilderRecordSet;
bool RecursiveFindCycle(const BuilderRecord* search_in,
std::vector<const BuilderRecord*>* path) {
path->push_back(search_in);
-
- const BuilderRecord::BuilderRecordSet& unresolved =
- search_in->unresolved_deps();
- for (BuilderRecord::BuilderRecordSet::const_iterator i = unresolved.begin();
- i != unresolved.end(); ++i) {
- const BuilderRecord* cur = *i;
-
+ for (const auto& cur : search_in->unresolved_deps()) {
std::vector<const BuilderRecord*>::iterator found =
std::find(path->begin(), path->end(), cur);
if (found != path->end()) {
@@ -132,20 +126,18 @@ const Toolchain* Builder::GetToolchain(const Label& label) const {
std::vector<const BuilderRecord*> Builder::GetAllRecords() const {
std::vector<const BuilderRecord*> result;
result.reserve(records_.size());
- for (RecordMap::const_iterator i = records_.begin();
- i != records_.end(); ++i)
- result.push_back(i->second);
+ for (const auto& record : records_)
+ result.push_back(record.second);
return result;
}
std::vector<const Target*> Builder::GetAllResolvedTargets() const {
std::vector<const Target*> result;
result.reserve(records_.size());
- for (RecordMap::const_iterator i = records_.begin();
- i != records_.end(); ++i) {
- if (i->second->type() == BuilderRecord::ITEM_TARGET &&
- i->second->should_generate() && i->second->item())
- result.push_back(i->second->item()->AsTarget());
+ for (const auto& record : records_) {
+ if (record.second->type() == BuilderRecord::ITEM_TARGET &&
+ record.second->should_generate() && record.second->item())
+ result.push_back(record.second->item()->AsTarget());
}
return result;
}
@@ -174,9 +166,8 @@ bool Builder::CheckForBadItems(Err* err) const {
// that below.
std::vector<const BuilderRecord*> bad_records;
std::string depstring;
- for (RecordMap::const_iterator i = records_.begin();
- i != records_.end(); ++i) {
- const BuilderRecord* src = i->second;
+ for (const auto& record_pair : records_) {
+ const BuilderRecord* src = record_pair.second;
if (!src->should_generate())
continue; // Skip ungenerated nodes.
@@ -184,11 +175,7 @@ bool Builder::CheckForBadItems(Err* err) const {
bad_records.push_back(src);
// Check dependencies.
- for (BuilderRecord::BuilderRecordSet::const_iterator dest_iter =
- src->unresolved_deps().begin();
- dest_iter != src->unresolved_deps().end();
- ++dest_iter) {
- const BuilderRecord* dest = *dest_iter;
+ for (const auto& dest : src->unresolved_deps()) {
if (!dest->item()) {
depstring += src->label().GetUserVisibleName(true) +
"\n needs " + dest->label().GetUserVisibleName(true) + "\n";
@@ -210,9 +197,9 @@ bool Builder::CheckForBadItems(Err* err) const {
// Something's very wrong, just dump out the bad nodes.
depstring = "I have no idea what went wrong, but these are unresolved, "
"possibly due to an\ninternal error:";
- for (size_t i = 0; i < bad_records.size(); i++) {
+ for (const auto& bad_record : bad_records) {
depstring += "\n\"" +
- bad_records[i]->label().GetUserVisibleName(false) + "\"";
+ bad_record->label().GetUserVisibleName(false) + "\"";
}
*err = Err(Location(), "", depstring);
} else {
@@ -328,9 +315,9 @@ BuilderRecord* Builder::GetResolvedRecordOfType(const Label& label,
bool Builder::AddDeps(BuilderRecord* record,
const LabelConfigVector& configs,
Err* err) {
- for (size_t i = 0; i < configs.size(); i++) {
+ for (const auto& config : configs) {
BuilderRecord* dep_record = GetOrCreateRecordOfType(
- configs[i].label, configs[i].origin, BuilderRecord::ITEM_CONFIG, err);
+ config.label, config.origin, BuilderRecord::ITEM_CONFIG, err);
if (!dep_record)
return false;
record->AddDep(dep_record);
@@ -341,9 +328,9 @@ bool Builder::AddDeps(BuilderRecord* record,
bool Builder::AddDeps(BuilderRecord* record,
const UniqueVector<LabelConfigPair>& configs,
Err* err) {
- for (size_t i = 0; i < configs.size(); i++) {
+ for (const auto& config : configs) {
BuilderRecord* dep_record = GetOrCreateRecordOfType(
- configs[i].label, configs[i].origin, BuilderRecord::ITEM_CONFIG, err);
+ config.label, config.origin, BuilderRecord::ITEM_CONFIG, err);
if (!dep_record)
return false;
record->AddDep(dep_record);
@@ -354,9 +341,9 @@ bool Builder::AddDeps(BuilderRecord* record,
bool Builder::AddDeps(BuilderRecord* record,
const LabelTargetVector& targets,
Err* err) {
- for (size_t i = 0; i < targets.size(); i++) {
+ for (const auto& target : targets) {
BuilderRecord* dep_record = GetOrCreateRecordOfType(
- targets[i].label, targets[i].origin, BuilderRecord::ITEM_TARGET, err);
+ target.label, target.origin, BuilderRecord::ITEM_TARGET, err);
if (!dep_record)
return false;
record->AddDep(dep_record);
@@ -383,10 +370,7 @@ void Builder::RecursiveSetShouldGenerate(BuilderRecord* record,
return; // Already set.
record->set_should_generate(true);
- const BuilderRecordSet& deps = record->all_deps();
- for (BuilderRecordSet::const_iterator i = deps.begin();
- i != deps.end(); i++) {
- BuilderRecord* cur = *i;
+ for (const auto& cur : record->all_deps()) {
if (!cur->should_generate()) {
ScheduleItemLoadIfNecessary(cur);
RecursiveSetShouldGenerate(cur, false);
@@ -428,10 +412,7 @@ bool Builder::ResolveItem(BuilderRecord* record, Err* err) {
resolved_callback_.Run(record);
// Recursively update everybody waiting on this item to be resolved.
- BuilderRecordSet& waiting_set = record->waiting_on_resolution();
- for (BuilderRecordSet::iterator i = waiting_set.begin();
- i != waiting_set.end(); ++i) {
- BuilderRecord* waiting = *i;
+ for (BuilderRecord* waiting : record->waiting_on_resolution()) {
DCHECK(waiting->unresolved_deps().find(record) !=
waiting->unresolved_deps().end());
waiting->unresolved_deps().erase(record);
@@ -441,13 +422,12 @@ bool Builder::ResolveItem(BuilderRecord* record, Err* err) {
return false;
}
}
- waiting_set.clear();
+ record->waiting_on_resolution().clear();
return true;
}
bool Builder::ResolveDeps(LabelTargetVector* deps, Err* err) {
- for (size_t i = 0; i < deps->size(); i++) {
- LabelTargetPair& cur = (*deps)[i];
+ for (LabelTargetPair& cur : *deps) {
DCHECK(!cur.ptr);
BuilderRecord* record = GetResolvedRecordOfType(
@@ -460,8 +440,7 @@ bool Builder::ResolveDeps(LabelTargetVector* deps, Err* err) {
}
bool Builder::ResolveConfigs(UniqueVector<LabelConfigPair>* configs, Err* err) {
- for (size_t i = 0; i < configs->size(); i++) {
- const LabelConfigPair& cur = (*configs)[i];
+ for (const auto& cur : *configs) {
DCHECK(!cur.ptr);
BuilderRecord* record = GetResolvedRecordOfType(
@@ -480,24 +459,24 @@ bool Builder::ResolveForwardDependentConfigs(Target* target, Err* err) {
target->forward_dependent_configs();
// Assume that the lists are small so that brute-force n^2 is appropriate.
- for (size_t config_i = 0; config_i < configs.size(); config_i++) {
+ for (const auto& config : configs) {
for (const auto& dep_pair : target->GetDeps(Target::DEPS_LINKED)) {
- if (configs[config_i].label == dep_pair.label) {
+ if (config.label == dep_pair.label) {
DCHECK(dep_pair.ptr); // Should already be resolved.
// UniqueVector's contents are constant so uniqueness is preserved, but
// we want to update this pointer which doesn't change uniqueness
// (uniqueness in this vector is determined by the label only).
- const_cast<LabelTargetPair&>(configs[config_i]).ptr = dep_pair.ptr;
+ const_cast<LabelTargetPair&>(config).ptr = dep_pair.ptr;
break;
}
}
- if (!configs[config_i].ptr) {
+ if (!config.ptr) {
*err = Err(target->defined_from(),
"Target in forward_dependent_configs_from was not listed in the deps",
"This target has a forward_dependent_configs_from entry that was "
"not present in\nthe deps. A target can only forward things it "
"depends on. It was forwarding:\n " +
- configs[config_i].label.GetUserVisibleName(false));
+ config.label.GetUserVisibleName(false));
return false;
}
}
diff --git a/tools/gn/command_args.cc b/tools/gn/command_args.cc
index 8b1478f..e2f4a9c 100644
--- a/tools/gn/command_args.cc
+++ b/tools/gn/command_args.cc
@@ -128,9 +128,8 @@ int ListArgs(const std::string& build_dir) {
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kSwitchList);
if (list_value.empty()) {
// List all values.
- for (Scope::KeyValueMap::const_iterator i = build_args.begin();
- i != build_args.end(); ++i)
- sorted_args.insert(*i);
+ for (const auto& arg : build_args)
+ sorted_args.insert(arg);
} else {
// List just the one specified as the parameter to --list.
Scope::KeyValueMap::const_iterator found_arg = build_args.find(list_value);
@@ -145,20 +144,18 @@ int ListArgs(const std::string& build_dir) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(kSwitchShort)) {
// Short key=value output.
- for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin();
- i != sorted_args.end(); ++i) {
- OutputString(i->first.as_string());
+ for (const auto& arg : sorted_args) {
+ OutputString(arg.first.as_string());
OutputString(" = ");
- OutputString(i->second.ToString(true));
+ OutputString(arg.second.ToString(true));
OutputString("\n");
}
return 0;
}
// Long output.
- for (std::map<base::StringPiece, Value>::iterator i = sorted_args.begin();
- i != sorted_args.end(); ++i) {
- PrintArgHelp(i->first, i->second);
+ for (const auto& arg : sorted_args) {
+ PrintArgHelp(arg.first, arg.second);
OutputString("\n");
}
diff --git a/tools/gn/command_desc.cc b/tools/gn/command_desc.cc
index d43577e..4cdc3f2 100644
--- a/tools/gn/command_desc.cc
+++ b/tools/gn/command_desc.cc
@@ -71,8 +71,8 @@ void RecursivePrintDeps(const Target* target,
LabelPtrLabelLess<Target>());
std::string indent(indent_level * 2, ' ');
- for (size_t i = 0; i < sorted_deps.size(); i++) {
- const Target* cur_dep = sorted_deps[i].ptr;
+ for (const auto& pair : sorted_deps) {
+ const Target* cur_dep = pair.ptr;
OutputString(indent +
cur_dep->label().GetUserVisibleName(default_toolchain));
@@ -130,9 +130,8 @@ void PrintDeps(const Target* target, bool display_header) {
std::set<Label> all_deps;
RecursiveCollectChildDeps(target, &all_deps);
- for (std::set<Label>::iterator i = all_deps.begin();
- i != all_deps.end(); ++i)
- deps.push_back(*i);
+ for (const auto& dep : all_deps)
+ deps.push_back(dep);
} else {
// Show direct dependencies only.
if (display_header) {
@@ -145,8 +144,8 @@ void PrintDeps(const Target* target, bool display_header) {
}
std::sort(deps.begin(), deps.end());
- for (size_t i = 0; i < deps.size(); i++)
- OutputString(" " + deps[i].GetUserVisibleName(toolchain_label) + "\n");
+ for (const auto& dep : deps)
+ OutputString(" " + dep.GetUserVisibleName(toolchain_label) + "\n");
}
void PrintForwardDependentConfigsFrom(const Target* target,
@@ -159,13 +158,13 @@ void PrintForwardDependentConfigsFrom(const Target* target,
// Collect the sorted list of deps.
std::vector<Label> forward;
- for (size_t i = 0; i < target->forward_dependent_configs().size(); i++)
- forward.push_back(target->forward_dependent_configs()[i].label);
+ for (const auto& pair : target->forward_dependent_configs())
+ forward.push_back(pair.label);
std::sort(forward.begin(), forward.end());
Label toolchain_label = target->label().GetToolchainLabel();
- for (size_t i = 0; i < forward.size(); i++)
- OutputString(" " + forward[i].GetUserVisibleName(toolchain_label) + "\n");
+ for (const auto& fwd : forward)
+ OutputString(" " + fwd.GetUserVisibleName(toolchain_label) + "\n");
}
// libs and lib_dirs are special in that they're inherited. We don't currently
@@ -206,8 +205,8 @@ void PrintPublic(const Target* target, bool display_header) {
Target::FileList public_headers = target->public_headers();
std::sort(public_headers.begin(), public_headers.end());
- for (size_t i = 0; i < public_headers.size(); i++)
- OutputString(" " + public_headers[i].value() + "\n");
+ for (const auto& hdr : public_headers)
+ OutputString(" " + hdr.value() + "\n");
}
void PrintCheckIncludes(const Target* target, bool display_header) {
@@ -225,10 +224,8 @@ void PrintAllowCircularIncludesFrom(const Target* target, bool display_header) {
OutputString("\nallow_circular_includes_from:\n");
Label toolchain_label = target->label().GetToolchainLabel();
- const std::set<Label>& allow = target->allow_circular_includes_from();
- for (std::set<Label>::const_iterator iter = allow.begin();
- iter != allow.end(); ++iter)
- OutputString(" " + iter->GetUserVisibleName(toolchain_label) + "\n");
+ for (const auto& cur : target->allow_circular_includes_from())
+ OutputString(" " + cur.GetUserVisibleName(toolchain_label) + "\n");
}
void PrintVisibility(const Target* target, bool display_header) {
diff --git a/tools/gn/command_help.cc b/tools/gn/command_help.cc
index ef5f70b..d207572 100644
--- a/tools/gn/command_help.cc
+++ b/tools/gn/command_help.cc
@@ -22,11 +22,8 @@ namespace {
void PrintToplevelHelp() {
OutputString("Commands (type \"gn help <command>\" for more details):\n");
-
- const commands::CommandInfoMap& command_map = commands::GetCommands();
- for (commands::CommandInfoMap::const_iterator i = command_map.begin();
- i != command_map.end(); ++i)
- PrintShortHelp(i->second.help_short);
+ for (const auto& cmd : commands::GetCommands())
+ PrintShortHelp(cmd.second.help_short);
OutputString(
"\n"
@@ -56,39 +53,30 @@ void PrintToplevelHelp() {
// Target declarations.
OutputString("\nTarget declarations (type \"gn help <function>\" for more "
"details):\n");
- const functions::FunctionInfoMap& function_map = functions::GetFunctions();
- for (functions::FunctionInfoMap::const_iterator i = function_map.begin();
- i != function_map.end(); ++i) {
- if (i->second.is_target)
- PrintShortHelp(i->second.help_short);
+ for (const auto& func : functions::GetFunctions()) {
+ if (func.second.is_target)
+ PrintShortHelp(func.second.help_short);
}
// Functions.
OutputString("\nBuildfile functions (type \"gn help <function>\" for more "
"details):\n");
- for (functions::FunctionInfoMap::const_iterator i = function_map.begin();
- i != function_map.end(); ++i) {
- if (!i->second.is_target)
- PrintShortHelp(i->second.help_short);
+ for (const auto& func : functions::GetFunctions()) {
+ if (!func.second.is_target)
+ PrintShortHelp(func.second.help_short);
}
// Built-in variables.
OutputString("\nBuilt-in predefined variables (type \"gn help <variable>\" "
"for more details):\n");
- const variables::VariableInfoMap& builtin_vars =
- variables::GetBuiltinVariables();
- for (variables::VariableInfoMap::const_iterator i = builtin_vars.begin();
- i != builtin_vars.end(); ++i)
- PrintShortHelp(i->second.help_short);
+ for (const auto& builtin : variables::GetBuiltinVariables())
+ PrintShortHelp(builtin.second.help_short);
// Target variables.
OutputString("\nVariables you set in targets (type \"gn help <variable>\" "
"for more details):\n");
- const variables::VariableInfoMap& target_vars =
- variables::GetTargetVariables();
- for (variables::VariableInfoMap::const_iterator i = target_vars.begin();
- i != target_vars.end(); ++i)
- PrintShortHelp(i->second.help_short);
+ for (const auto& target : variables::GetTargetVariables())
+ PrintShortHelp(target.second.help_short);
OutputString("\nOther help topics:\n");
PrintShortHelp("buildargs: How build arguments work.");
diff --git a/tools/gn/command_ls.cc b/tools/gn/command_ls.cc
index 2069709..c22129a 100644
--- a/tools/gn/command_ls.cc
+++ b/tools/gn/command_ls.cc
@@ -85,32 +85,30 @@ int RunLs(const std::vector<std::string>& args) {
matches = setup->builder()->GetAllResolvedTargets();
} else {
// List all resolved targets in the default toolchain.
- std::vector<const Target*> all_targets =
- setup->builder()->GetAllResolvedTargets();
- for (size_t i = 0; i < all_targets.size(); i++) {
- if (all_targets[i]->settings()->is_default())
- matches.push_back(all_targets[i]);
+ for (const auto& target : setup->builder()->GetAllResolvedTargets()) {
+ if (target->settings()->is_default())
+ matches.push_back(target);
}
}
if (cmdline->HasSwitch("out")) {
// List results as build files.
- for (size_t i = 0; i < matches.size(); i++) {
- OutputString(matches[i]->dependency_output_file().value());
+ for (const auto& match : matches) {
+ OutputString(match->dependency_output_file().value());
OutputString("\n");
}
} else {
// List results as sorted labels.
std::vector<Label> sorted_matches;
- for (size_t i = 0; i < matches.size(); i++)
- sorted_matches.push_back(matches[i]->label());
+ for (const auto& match : matches)
+ sorted_matches.push_back(match->label());
std::sort(sorted_matches.begin(), sorted_matches.end());
Label default_tc_label = setup->loader()->default_toolchain_label();
- for (size_t i = 0; i < sorted_matches.size(); i++) {
+ for (const auto& match : sorted_matches) {
// Print toolchain only for ones not in the default toolchain.
- OutputString(sorted_matches[i].GetUserVisibleName(
- sorted_matches[i].GetToolchainLabel() != default_tc_label));
+ OutputString(match.GetUserVisibleName(
+ match.GetToolchainLabel() != default_tc_label));
OutputString("\n");
}
}
diff --git a/tools/gn/command_refs.cc b/tools/gn/command_refs.cc
index c55726b..86fed87 100644
--- a/tools/gn/command_refs.cc
+++ b/tools/gn/command_refs.cc
@@ -48,31 +48,26 @@ void OutputResultSet(const TargetSet& results, bool as_files) {
if (as_files) {
// Output the set of unique source files.
std::set<std::string> unique_files;
- for (TargetSet::const_iterator iter = results.begin();
- iter != results.end(); ++iter)
- unique_files.insert(FilePathToUTF8(FilePathForItem(*iter)));
+ for (const auto& cur : results)
+ unique_files.insert(FilePathToUTF8(FilePathForItem(cur)));
- for (std::set<std::string>::const_iterator iter = unique_files.begin();
- iter != unique_files.end(); ++iter) {
- OutputString(*iter + "\n");
- }
+ for (const auto& cur : unique_files)
+ OutputString(cur + "\n");
} else {
// Output sorted and uniquified list of labels. The set will sort the
// labels.
std::set<Label> unique_labels;
- for (TargetSet::const_iterator iter = results.begin();
- iter != results.end(); ++iter)
- unique_labels.insert((*iter)->label());
+ for (const auto& cur : results)
+ unique_labels.insert(cur->label());
// Grab the label of the default toolchain from a random target.
Label default_tc_label =
(*results.begin())->settings()->default_toolchain_label();
- for (std::set<Label>::const_iterator iter = unique_labels.begin();
- iter != unique_labels.end(); ++iter) {
+ for (const auto& cur : unique_labels) {
// Print toolchain only for ones not in the default toolchain.
- OutputString(iter->GetUserVisibleName(
- iter->GetToolchainLabel() != default_tc_label));
+ OutputString(cur.GetUserVisibleName(
+ cur.GetToolchainLabel() != default_tc_label));
OutputString("\n");
}
}
@@ -259,15 +254,15 @@ int RunRefs(const std::vector<std::string>& args) {
} else if (all) {
// Output recursive dependencies, uniquified and flattened.
TargetSet results;
- for (size_t query_i = 0; query_i < query.size(); query_i++)
- RecursiveCollectChildRefs(dep_map, query[query_i], &results);
+ for (const auto& cur_query : query)
+ RecursiveCollectChildRefs(dep_map, cur_query, &results);
OutputResultSet(results, files);
} else {
// Output direct references of everything in the query.
TargetSet results;
- for (size_t query_i = 0; query_i < query.size(); query_i++) {
- DepMap::const_iterator dep_begin = dep_map.lower_bound(query[query_i]);
- DepMap::const_iterator dep_end = dep_map.upper_bound(query[query_i]);
+ for (const auto& cur_query : query) {
+ DepMap::const_iterator dep_begin = dep_map.lower_bound(cur_query);
+ DepMap::const_iterator dep_end = dep_map.upper_bound(cur_query);
for (DepMap::const_iterator cur_dep = dep_begin;
cur_dep != dep_end; cur_dep++)
results.insert(cur_dep->second);
diff --git a/tools/gn/commands.cc b/tools/gn/commands.cc
index 6dde4b2..0ad1bd7 100644
--- a/tools/gn/commands.cc
+++ b/tools/gn/commands.cc
@@ -113,9 +113,9 @@ bool ResolveTargetsFromCommandLinePattern(
std::vector<const Target*> all_targets =
setup->builder()->GetAllResolvedTargets();
- for (size_t i = 0; i < all_targets.size(); i++) {
- if (pattern.Matches(all_targets[i]->label()))
- matches->push_back(all_targets[i]);
+ for (const auto& target : all_targets) {
+ if (pattern.Matches(target->label()))
+ matches->push_back(target);
}
return true;
}
diff --git a/tools/gn/err.cc b/tools/gn/err.cc
index 8038bad..6a9033d 100644
--- a/tools/gn/err.cc
+++ b/tools/gn/err.cc
@@ -186,6 +186,6 @@ void Err::InternalPrintToStdout(bool is_sub_err) const {
OutputString(help_text_ + "\n");
// Sub errors.
- for (size_t i = 0; i < sub_errs_.size(); i++)
- sub_errs_[i].InternalPrintToStdout(true);
+ for (const auto& sub_err : sub_errs_)
+ sub_err.InternalPrintToStdout(true);
}
diff --git a/tools/gn/function_exec_script.cc b/tools/gn/function_exec_script.cc
index ce697e5..eb30a6e 100644
--- a/tools/gn/function_exec_script.cc
+++ b/tools/gn/function_exec_script.cc
@@ -325,12 +325,12 @@ Value RunExecScript(Scope* scope,
if (!deps_value.VerifyTypeIs(Value::LIST, err))
return Value();
- for (size_t i = 0; i < deps_value.list_value().size(); i++) {
- if (!deps_value.list_value()[0].VerifyTypeIs(Value::STRING, err))
+ for (const auto& dep : deps_value.list_value()) {
+ if (!dep.VerifyTypeIs(Value::STRING, err))
return Value();
g_scheduler->AddGenDependency(
build_settings->GetFullPath(cur_dir.ResolveRelativeFile(
- deps_value.list_value()[0].string_value())));
+ dep.string_value())));
}
}
@@ -344,10 +344,10 @@ Value RunExecScript(Scope* scope,
const Value& script_args = args[1];
if (!script_args.VerifyTypeIs(Value::LIST, err))
return Value();
- for (size_t i = 0; i < script_args.list_value().size(); i++) {
- if (!script_args.list_value()[i].VerifyTypeIs(Value::STRING, err))
+ for (const auto& arg : script_args.list_value()) {
+ if (!arg.VerifyTypeIs(Value::STRING, err))
return Value();
- cmdline.AppendArg(script_args.list_value()[i].string_value());
+ cmdline.AppendArg(arg.string_value());
}
}
diff --git a/tools/gn/function_foreach.cc b/tools/gn/function_foreach.cc
index 06a2dc1..321bd0a 100644
--- a/tools/gn/function_foreach.cc
+++ b/tools/gn/function_foreach.cc
@@ -101,8 +101,8 @@ Value RunForEach(Scope* scope,
if (old_loop_value_ptr)
old_loop_value = *old_loop_value_ptr;
- for (size_t i = 0; i < list.size(); i++) {
- scope->SetValue(loop_var, list[i], function);
+ for (const auto& cur : list) {
+ scope->SetValue(loop_var, cur, function);
block->ExecuteBlockInScope(scope, err);
if (err->has_error())
return Value();
diff --git a/tools/gn/function_get_path_info.cc b/tools/gn/function_get_path_info.cc
index ea6651c..67f9344 100644
--- a/tools/gn/function_get_path_info.cc
+++ b/tools/gn/function_get_path_info.cc
@@ -222,10 +222,9 @@ Value RunGetPathInfo(Scope* scope,
} else if (args[0].type() == Value::LIST) {
const std::vector<Value>& input_list = args[0].list_value();
Value result(function, Value::LIST);
- for (size_t i = 0; i < input_list.size(); i++) {
+ for (const auto& cur : input_list) {
result.list_value().push_back(Value(function,
- GetOnePathInfo(scope->settings(), current_dir, what,
- input_list[i], err)));
+ GetOnePathInfo(scope->settings(), current_dir, what, cur, err)));
if (err->has_error())
return Value();
}
diff --git a/tools/gn/function_get_target_outputs.cc b/tools/gn/function_get_target_outputs.cc
index e3a63ee..163b187 100644
--- a/tools/gn/function_get_target_outputs.cc
+++ b/tools/gn/function_get_target_outputs.cc
@@ -92,8 +92,8 @@ Value RunGetTargetOutputs(Scope* scope,
*err = Err(function, "No targets defined in this context.");
return Value();
}
- for (size_t i = 0; i < collector->size(); i++) {
- const Item* item = (*collector)[i]->get();
+ for (const auto& cur : *collector) {
+ const Item* item = cur->get();
if (item->label() != label)
continue;
@@ -132,8 +132,8 @@ Value RunGetTargetOutputs(Scope* scope,
// Convert to Values.
Value ret(function, Value::LIST);
ret.list_value().reserve(files.size());
- for (size_t i = 0; i < files.size(); i++)
- ret.list_value().push_back(Value(function, files[i].value()));
+ for (const auto& file : files)
+ ret.list_value().push_back(Value(function, file.value()));
return ret;
}
diff --git a/tools/gn/function_process_file_template.cc b/tools/gn/function_process_file_template.cc
index 540d1ed..b7828a6 100644
--- a/tools/gn/function_process_file_template.cc
+++ b/tools/gn/function_process_file_template.cc
@@ -98,8 +98,8 @@ Value RunProcessFileTemplate(Scope* scope,
// Convert the list of strings to the return Value.
Value ret(function, Value::LIST);
ret.list_value().reserve(result_files.size());
- for (size_t i = 0; i < result_files.size(); i++)
- ret.list_value().push_back(Value(function, result_files[i]));
+ for (const auto& file : result_files)
+ ret.list_value().push_back(Value(function, file));
return ret;
}
diff --git a/tools/gn/function_rebase_path.cc b/tools/gn/function_rebase_path.cc
index dd5e903..078f007 100644
--- a/tools/gn/function_rebase_path.cc
+++ b/tools/gn/function_rebase_path.cc
@@ -260,9 +260,9 @@ Value RunRebasePath(Scope* scope,
result = Value(function, Value::LIST);
result.list_value().reserve(inputs.list_value().size());
- for (size_t i = 0; i < inputs.list_value().size(); i++) {
+ for (const auto& input : inputs.list_value()) {
result.list_value().push_back(
- ConvertOnePath(scope, function, inputs.list_value()[i],
+ ConvertOnePath(scope, function, input,
from_dir, to_dir, convert_to_system_absolute, err));
if (err->has_error()) {
result = Value();
diff --git a/tools/gn/function_toolchain.cc b/tools/gn/function_toolchain.cc
index 0ac1558..85163c1 100644
--- a/tools/gn/function_toolchain.cc
+++ b/tools/gn/function_toolchain.cc
@@ -62,8 +62,7 @@ bool ValidateSubstitutionList(const std::vector<SubstitutionType>& list,
bool (*validate)(SubstitutionType),
const Value* origin,
Err* err) {
- for (size_t i = 0; i < list.size(); i++) {
- SubstitutionType cur_type = list[i];
+ for (const auto& cur_type : list) {
if (!validate(cur_type)) {
*err = Err(*origin, "Pattern not valid here.",
"You used the pattern " + std::string(kSubstitutionNames[cur_type]) +
@@ -179,8 +178,7 @@ bool IsLinkerTool(Toolchain::ToolType type) {
bool IsPatternInOutputList(const SubstitutionList& output_list,
const SubstitutionPattern& pattern) {
- for (size_t output_i = 0; output_i < output_list.list().size(); output_i++) {
- const SubstitutionPattern& cur = output_list.list()[output_i];
+ for (const auto& cur : output_list.list()) {
if (pattern.ranges().size() == cur.ranges().size() &&
std::equal(pattern.ranges().begin(), pattern.ranges().end(),
cur.ranges().begin()))
diff --git a/tools/gn/function_write_file.cc b/tools/gn/function_write_file.cc
index 69ae59ec..55f4d5d 100644
--- a/tools/gn/function_write_file.cc
+++ b/tools/gn/function_write_file.cc
@@ -67,8 +67,8 @@ Value RunWriteFile(Scope* scope,
std::ostringstream contents;
if (args[1].type() == Value::LIST) {
const std::vector<Value>& list = args[1].list_value();
- for (size_t i = 0; i < list.size(); i++)
- contents << list[i].ToString(false) << std::endl;
+ for (const auto& cur : list)
+ contents << cur.ToString(false) << std::endl;
} else {
contents << args[1].ToString(false);
}
diff --git a/tools/gn/gn_main.cc b/tools/gn/gn_main.cc
index 05291e9..60d181f 100644
--- a/tools/gn/gn_main.cc
+++ b/tools/gn/gn_main.cc
@@ -24,8 +24,8 @@ std::vector<std::string> GetArgs(const CommandLine& cmdline) {
CommandLine::StringVector in_args = cmdline.GetArgs();
#if defined(OS_WIN)
std::vector<std::string> out_args;
- for (size_t i = 0; i < in_args.size(); i++)
- out_args.push_back(base::WideToUTF8(in_args[i]));
+ for (const auto& arg : in_args)
+ out_args.push_back(base::WideToUTF8(arg));
return out_args;
#else
return in_args;
diff --git a/tools/gn/header_checker.cc b/tools/gn/header_checker.cc
index 26bc222..9092638 100644
--- a/tools/gn/header_checker.cc
+++ b/tools/gn/header_checker.cc
@@ -121,8 +121,8 @@ HeaderChecker::HeaderChecker(const BuildSettings* build_settings,
const std::vector<const Target*>& targets)
: main_loop_(base::MessageLoop::current()),
build_settings_(build_settings) {
- for (size_t i = 0; i < targets.size(); i++)
- AddTargetToFileMap(targets[i], &file_map_);
+ for (const auto& target : targets)
+ AddTargetToFileMap(target, &file_map_);
}
HeaderChecker::~HeaderChecker() {
@@ -137,8 +137,8 @@ bool HeaderChecker::Run(const std::vector<const Target*>& to_check,
} else {
// Run only over the files in the given targets.
FileMap files_to_check;
- for (size_t i = 0; i < to_check.size(); i++)
- AddTargetToFileMap(to_check[i], &files_to_check);
+ for (const auto& check : to_check)
+ AddTargetToFileMap(check, &files_to_check);
RunCheckOverFiles(files_to_check, force_check);
}
@@ -154,12 +154,9 @@ void HeaderChecker::RunCheckOverFiles(const FileMap& files, bool force_check) {
scoped_refptr<base::SequencedWorkerPool> pool(
new base::SequencedWorkerPool(16, "HeaderChecker"));
- for (FileMap::const_iterator file_i = files.begin();
- file_i != files.end(); ++file_i) {
- const TargetVector& vect = file_i->second;
-
+ for (const auto& file : files) {
// Only check C-like source files (RC files also have includes).
- SourceFileType type = GetSourceFileType(file_i->first);
+ SourceFileType type = GetSourceFileType(file.first);
if (type != SOURCE_CC && type != SOURCE_H && type != SOURCE_C &&
type != SOURCE_M && type != SOURCE_MM && type != SOURCE_RC)
continue;
@@ -171,19 +168,18 @@ void HeaderChecker::RunCheckOverFiles(const FileMap& files, bool force_check) {
if (!force_check) {
bool check_includes = false;
bool is_generated = false;
- for (size_t vect_i = 0; vect_i < vect.size(); ++vect_i) {
- check_includes |= vect[vect_i].target->check_includes();
- is_generated |= vect[vect_i].is_generated;
+ for (const auto& vect_i : file.second) {
+ check_includes |= vect_i.target->check_includes();
+ is_generated |= vect_i.is_generated;
}
if (!check_includes || is_generated)
continue;
}
- for (size_t vect_i = 0; vect_i < vect.size(); ++vect_i) {
+ for (const auto& vect_i : file.second) {
pool->PostWorkerTaskWithShutdownBehavior(
FROM_HERE,
- base::Bind(&HeaderChecker::DoWork, this,
- vect[vect_i].target, file_i->first),
+ base::Bind(&HeaderChecker::DoWork, this, vect_i.target, file.first),
base::SequencedWorkerPool::BLOCK_SHUTDOWN);
}
}
@@ -212,19 +208,17 @@ void HeaderChecker::AddTargetToFileMap(const Target* target, FileMap* dest) {
// action, but those are often then wired into the sources of a compiled
// target to actually compile generated code. If you depend on the compiled
// target, it should be enough to be able to include the header.
- const Target::FileList& sources = target->sources();
- for (size_t i = 0; i < sources.size(); i++) {
- SourceFile file = RemoveRootGenDirFromFile(target, sources[i]);
+ for (const auto& source : target->sources()) {
+ SourceFile file = RemoveRootGenDirFromFile(target, source);
files_to_public[file].is_public = default_public;
}
// Add in the public files, forcing them to public. This may overwrite some
// entries, and it may add new ones.
- const Target::FileList& public_list = target->public_headers();
- if (default_public)
- DCHECK(public_list.empty()); // List only used when default is not public.
- for (size_t i = 0; i < public_list.size(); i++) {
- SourceFile file = RemoveRootGenDirFromFile(target, public_list[i]);
+ if (default_public) // List only used when default is not public.
+ DCHECK(target->public_headers().empty());
+ for (const auto& source : target->public_headers()) {
+ SourceFile file = RemoveRootGenDirFromFile(target, source);
files_to_public[file].is_public = true;
}
@@ -232,23 +226,21 @@ void HeaderChecker::AddTargetToFileMap(const Target* target, FileMap* dest) {
// targets can't use them, then there wouldn't be any point in outputting).
std::vector<SourceFile> outputs;
target->action_values().GetOutputsAsSourceFiles(target, &outputs);
- for (size_t i = 0; i < outputs.size(); i++) {
+ for (const auto& output : outputs) {
// For generated files in the "gen" directory, add the filename to the
// map assuming "gen" is the source root. This means that when files include
// the generated header relative to there (the recommended practice), we'll
// find the file.
- SourceFile output_file = RemoveRootGenDirFromFile(target, outputs[i]);
+ SourceFile output_file = RemoveRootGenDirFromFile(target, output);
PublicGeneratedPair* pair = &files_to_public[output_file];
pair->is_public = true;
pair->is_generated = true;
}
// Add the merged list to the master list of all files.
- for (std::map<SourceFile, PublicGeneratedPair>::const_iterator i =
- files_to_public.begin();
- i != files_to_public.end(); ++i) {
- (*dest)[i->first].push_back(TargetInfo(
- target, i->second.is_public, i->second.is_generated));
+ for (const auto& cur : files_to_public) {
+ (*dest)[cur.first].push_back(TargetInfo(
+ target, cur.second.is_public, cur.second.is_generated));
}
}
@@ -396,8 +388,8 @@ bool HeaderChecker::CheckInclude(const Target* from_target,
std::string msg = "It is not in any dependency of " +
from_target->label().GetUserVisibleName(false);
msg += "\nThe include file is in the target(s):\n";
- for (size_t i = 0; i < targets.size(); i++)
- msg += " " + targets[i].target->label().GetUserVisibleName(false) + "\n";
+ for (const auto& target : targets)
+ msg += " " + target.target->label().GetUserVisibleName(false) + "\n";
if (targets.size() > 1)
msg += "at least one of ";
msg += "which should somehow be reachable from " +
@@ -502,11 +494,9 @@ bool HeaderChecker::IsDependencyOf(const Target* search_for,
}
// Always consider public dependencies as possibilities.
- const LabelTargetVector& public_deps = target->public_deps();
- for (size_t i = 0; i < public_deps.size(); i++) {
- if (breadcrumbs.insert(
- std::make_pair(public_deps[i].ptr, cur_link)).second)
- work_queue.push(ChainLink(public_deps[i].ptr, true));
+ for (const auto& dep : target->public_deps()) {
+ if (breadcrumbs.insert(std::make_pair(dep.ptr, cur_link)).second)
+ work_queue.push(ChainLink(dep.ptr, true));
}
if (first_time || !require_permitted) {
@@ -515,11 +505,9 @@ bool HeaderChecker::IsDependencyOf(const Target* search_for,
// a target can include headers from its direct deps regardless of
// public/private-ness.
first_time = false;
- const LabelTargetVector& private_deps = target->private_deps();
- for (size_t i = 0; i < private_deps.size(); i++) {
- if (breadcrumbs.insert(
- std::make_pair(private_deps[i].ptr, cur_link)).second)
- work_queue.push(ChainLink(private_deps[i].ptr, false));
+ for (const auto& dep : target->private_deps()) {
+ if (breadcrumbs.insert(std::make_pair(dep.ptr, cur_link)).second)
+ work_queue.push(ChainLink(dep.ptr, false));
}
}
}
diff --git a/tools/gn/input_conversion.cc b/tools/gn/input_conversion.cc
index 2534f4d..6369d2d 100644
--- a/tools/gn/input_conversion.cc
+++ b/tools/gn/input_conversion.cc
@@ -105,8 +105,8 @@ Value ParseList(const std::string& input, const ParseNode* origin, Err* err) {
as_lines.resize(as_lines.size() - 1);
ret.list_value().reserve(as_lines.size());
- for (size_t i = 0; i < as_lines.size(); i++)
- ret.list_value().push_back(Value(origin, as_lines[i]));
+ for (const auto& line : as_lines)
+ ret.list_value().push_back(Value(origin, line));
return ret;
}
diff --git a/tools/gn/input_file_manager.cc b/tools/gn/input_file_manager.cc
index f358fdc..0b6159c 100644
--- a/tools/gn/input_file_manager.cc
+++ b/tools/gn/input_file_manager.cc
@@ -255,10 +255,9 @@ void InputFileManager::GetAllPhysicalInputFileNames(
std::vector<base::FilePath>* result) const {
base::AutoLock lock(lock_);
result->reserve(input_files_.size());
- for (InputFileMap::const_iterator i = input_files_.begin();
- i != input_files_.end(); ++i) {
- if (!i->second->file.physical_name().empty())
- result->push_back(i->second->file.physical_name());
+ for (const auto& file : input_files_) {
+ if (!file.second->file.physical_name().empty())
+ result->push_back(file.second->file.physical_name());
}
}
@@ -320,8 +319,8 @@ bool InputFileManager::LoadFile(const LocationRange& origin,
// separately to get some parallelism. But normally there will only be one
// item in the list, so that's extra overhead and complexity for no gain.
if (success) {
- for (size_t i = 0; i < callbacks.size(); i++)
- callbacks[i].Run(unowned_root);
+ for (const auto& cb : callbacks)
+ cb.Run(unowned_root);
}
return success;
}
diff --git a/tools/gn/loader.cc b/tools/gn/loader.cc
index b49ebfd..be5f5cc 100644
--- a/tools/gn/loader.cc
+++ b/tools/gn/loader.cc
@@ -265,8 +265,8 @@ void LoaderImpl::BackgroundLoadFile(const Settings* settings,
g_scheduler->FailWithError(err);
// Pass all of the items that were defined off to the builder.
- for (size_t i = 0; i < collected_items.size(); i++)
- settings->build_settings()->ItemDefined(collected_items[i]->Pass());
+ for (const auto& item : collected_items)
+ settings->build_settings()->ItemDefined(item->Pass());
trace.Done();
@@ -371,14 +371,13 @@ void LoaderImpl::DidLoadBuildConfig(const Label& label) {
// is OK.
LoadIDSet old_loads;
invocations_.swap(old_loads);
- for (LoadIDSet::iterator i = old_loads.begin();
- i != old_loads.end(); ++i) {
- if (i->toolchain_name.is_null()) {
+ for (const auto& load : old_loads) {
+ if (load.toolchain_name.is_null()) {
// Fix up toolchain label
- invocations_.insert(LoadID(i->file, label));
+ invocations_.insert(LoadID(load.file, label));
} else {
// Can keep the old one.
- invocations_.insert(*i);
+ invocations_.insert(load);
}
}
} else {
@@ -390,10 +389,8 @@ void LoaderImpl::DidLoadBuildConfig(const Label& label) {
record->is_config_loaded = true;
// Schedule all waiting file loads.
- for (size_t i = 0; i < record->waiting_on_me.size(); i++) {
- ScheduleLoadFile(&record->settings, record->waiting_on_me[i].origin,
- record->waiting_on_me[i].file);
- }
+ for (const auto& waiting : record->waiting_on_me)
+ ScheduleLoadFile(&record->settings, waiting.origin, waiting.file);
record->waiting_on_me.clear();
DecrementPendingLoads();
diff --git a/tools/gn/loader_unittest.cc b/tools/gn/loader_unittest.cc
index e5a3d86..fc4fa56 100644
--- a/tools/gn/loader_unittest.cc
+++ b/tools/gn/loader_unittest.cc
@@ -100,13 +100,12 @@ bool MockInputFileManager::HasTwoPending(const SourceFile& f1,
void MockInputFileManager::IssueAllPending() {
BlockNode block(false); // Default response.
- for (size_t i = 0; i < pending_.size(); i++) {
- CannedResponseMap::const_iterator found =
- canned_responses_.find(pending_[i].first);
+ for (const auto& cur : pending_) {
+ CannedResponseMap::const_iterator found = canned_responses_.find(cur.first);
if (found == canned_responses_.end())
- pending_[i].second.Run(&block);
+ cur.second.Run(&block);
else
- pending_[i].second.Run(found->second->root.get());
+ cur.second.Run(found->second->root.get());
}
pending_.clear();
}
diff --git a/tools/gn/ninja_action_target_writer.cc b/tools/gn/ninja_action_target_writer.cc
index ccbb570..25c8633 100644
--- a/tools/gn/ninja_action_target_writer.cc
+++ b/tools/gn/ninja_action_target_writer.cc
@@ -80,8 +80,8 @@ void NinjaActionTargetWriter::Run() {
// runtime and should be compiled when the action is, but don't need to be
// done before we run the action.
std::vector<OutputFile> data_outs;
- for (size_t i = 0; i < target_->data_deps().size(); i++)
- data_outs.push_back(target_->data_deps()[i].ptr->dependency_output_file());
+ for (const auto& dep : target_->data_deps())
+ data_outs.push_back(dep.ptr->dependency_output_file());
WriteStampForTarget(output_files, data_outs);
}
@@ -124,10 +124,10 @@ std::string NinjaActionTargetWriter::WriteRuleDefinition() {
path_output_.WriteFile(out_, settings_->build_settings()->python_path());
out_ << " ";
path_output_.WriteFile(out_, target_->action_values().script());
- for (size_t i = 0; i < args.list().size(); i++) {
+ for (const auto& arg : args.list()) {
out_ << " ";
SubstitutionWriter::WriteWithNinjaVariables(
- args.list()[i], args_escape_options, out_);
+ arg, args_escape_options, out_);
}
out_ << std::endl;
} else {
@@ -137,10 +137,10 @@ std::string NinjaActionTargetWriter::WriteRuleDefinition() {
path_output_.WriteFile(out_, settings_->build_settings()->python_path());
out_ << " ";
path_output_.WriteFile(out_, target_->action_values().script());
- for (size_t i = 0; i < args.list().size(); i++) {
+ for (const auto& arg : args.list()) {
out_ << " ";
SubstitutionWriter::WriteWithNinjaVariables(
- args.list()[i], args_escape_options, out_);
+ arg, args_escape_options, out_);
}
out_ << std::endl;
out_ << " description = ACTION " << target_label << std::endl;
diff --git a/tools/gn/ninja_binary_target_writer.cc b/tools/gn/ninja_binary_target_writer.cc
index ebd9282..b341639 100644
--- a/tools/gn/ninja_binary_target_writer.cc
+++ b/tools/gn/ninja_binary_target_writer.cc
@@ -133,8 +133,7 @@ void NinjaBinaryTargetWriter::WriteCompilerVars() {
void NinjaBinaryTargetWriter::WriteSources(
std::vector<OutputFile>* object_files) {
- const Target::FileList& sources = target_->sources();
- object_files->reserve(sources.size());
+ object_files->reserve(target_->sources().size());
OutputFile input_dep =
WriteInputDepsStampAndGetDep(std::vector<const Target*>());
@@ -142,9 +141,9 @@ void NinjaBinaryTargetWriter::WriteSources(
std::string rule_prefix = GetNinjaRulePrefixForToolchain(settings_);
std::vector<OutputFile> tool_outputs; // Prevent reallocation in loop.
- for (size_t i = 0; i < sources.size(); i++) {
+ for (const auto& source : target_->sources()) {
Toolchain::ToolType tool_type = Toolchain::TYPE_NONE;
- if (!GetOutputFilesForSource(target_, sources[i],
+ if (!GetOutputFilesForSource(target_, source,
&tool_type, &tool_outputs))
continue; // No output for this source.
@@ -153,7 +152,7 @@ void NinjaBinaryTargetWriter::WriteSources(
path_output_.WriteFiles(out_, tool_outputs);
out_ << ": " << rule_prefix << Toolchain::ToolTypeToName(tool_type);
out_ << " ";
- path_output_.WriteFile(out_, sources[i]);
+ path_output_.WriteFile(out_, source);
if (!input_dep.value().empty()) {
// Write out the input dependencies as an order-only dependency. This
// will cause Ninja to make sure the inputs are up-to-date before
@@ -212,21 +211,19 @@ void NinjaBinaryTargetWriter::WriteLinkerStuff(
GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps);
// Object files.
- for (size_t i = 0; i < object_files.size(); i++) {
+ for (const auto& obj : object_files) {
out_ << " ";
- path_output_.WriteFile(out_, object_files[i]);
+ path_output_.WriteFile(out_, obj);
}
- for (size_t i = 0; i < extra_object_files.size(); i++) {
+ for (const auto& obj : extra_object_files) {
out_ << " ";
- path_output_.WriteFile(out_, extra_object_files[i]);
+ path_output_.WriteFile(out_, obj);
}
std::vector<OutputFile> implicit_deps;
std::vector<OutputFile> solibs;
- for (size_t i = 0; i < linkable_deps.size(); i++) {
- const Target* cur = linkable_deps[i];
-
+ for (const Target* cur : linkable_deps) {
// All linkable deps should have a link output file.
DCHECK(!cur->link_output_file().value().empty())
<< "No link output file for "
@@ -365,8 +362,8 @@ void NinjaBinaryTargetWriter::WriteSourceSetStamp(
DCHECK(extra_object_files.empty());
std::vector<OutputFile> order_only_deps;
- for (size_t i = 0; i < non_linkable_deps.size(); i++)
- order_only_deps.push_back(non_linkable_deps[i]->dependency_output_file());
+ for (const auto& dep : non_linkable_deps)
+ order_only_deps.push_back(dep->dependency_output_file());
WriteStampForTarget(object_files, order_only_deps);
}
@@ -418,10 +415,9 @@ void NinjaBinaryTargetWriter::ClassifyDependency(
// Linking in a source set to an executable, shared library, or
// complete static library, so copy its object files.
std::vector<OutputFile> tool_outputs; // Prevent allocation in loop.
- for (size_t i = 0; i < dep->sources().size(); i++) {
+ for (const auto& source : dep->sources()) {
Toolchain::ToolType tool_type = Toolchain::TYPE_NONE;
- if (GetOutputFilesForSource(dep, dep->sources()[i], &tool_type,
- &tool_outputs)) {
+ if (GetOutputFilesForSource(dep, source, &tool_type, &tool_outputs)) {
// Only link the first output if there are more than one.
extra_object_files->push_back(tool_outputs[0]);
}
diff --git a/tools/gn/operators.cc b/tools/gn/operators.cc
index 3a815ea..78ea31b 100644
--- a/tools/gn/operators.cc
+++ b/tools/gn/operators.cc
@@ -36,20 +36,19 @@ void AppendFilteredSourcesToValue(const Scope* scope,
return;
}
- const std::vector<Value>& source_list = source.list_value();
if (!filter || filter->is_empty()) {
// No filter, append everything.
- for (size_t i = 0; i < source_list.size(); i++)
- dest->list_value().push_back(source_list[i]);
+ for (const auto& source_entry : source.list_value())
+ dest->list_value().push_back(source_entry);
return;
}
// Note: don't reserve() the dest vector here since that actually hurts
// the allocation pattern when the build script is doing multiple small
// additions.
- for (size_t i = 0; i < source_list.size(); i++) {
- if (!filter->MatchesValue(source_list[i]))
- dest->list_value().push_back(source_list[i]);
+ for (const auto& source_entry : source.list_value()) {
+ if (!filter->MatchesValue(source_entry))
+ dest->list_value().push_back(source_entry);
}
}
@@ -228,8 +227,8 @@ void ValuePlusEquals(const Scope* scope,
AppendFilteredSourcesToValue(scope, right, left);
} else {
// Normal list concat.
- for (size_t i = 0; i < right.list_value().size(); i++)
- left->list_value().push_back(right.list_value()[i]);
+ for (const auto& value : right.list_value())
+ left->list_value().push_back(value);
}
return;
diff --git a/tools/gn/parse_tree.cc b/tools/gn/parse_tree.cc
index f2ddb1c..9b2fc3f 100644
--- a/tools/gn/parse_tree.cc
+++ b/tools/gn/parse_tree.cc
@@ -59,21 +59,12 @@ Comments* ParseNode::comments_mutable() {
void ParseNode::PrintComments(std::ostream& out, int indent) const {
if (comments_) {
std::string ind = IndentFor(indent + 1);
- for (std::vector<Token>::const_iterator i(comments_->before().begin());
- i != comments_->before().end();
- ++i) {
- out << ind << "+BEFORE_COMMENT(\"" << i->value() << "\")\n";
- }
- for (std::vector<Token>::const_iterator i(comments_->suffix().begin());
- i != comments_->suffix().end();
- ++i) {
- out << ind << "+SUFFIX_COMMENT(\"" << i->value() << "\")\n";
- }
- for (std::vector<Token>::const_iterator i(comments_->after().begin());
- i != comments_->after().end();
- ++i) {
- out << ind << "+AFTER_COMMENT(\"" << i->value() << "\")\n";
- }
+ for (const auto& token : comments_->before())
+ out << ind << "+BEFORE_COMMENT(\"" << token.value() << "\")\n";
+ for (const auto& token : comments_->suffix())
+ out << ind << "+SUFFIX_COMMENT(\"" << token.value() << "\")\n";
+ for (const auto& token : comments_->after())
+ out << ind << "+AFTER_COMMENT(\"" << token.value() << "\")\n";
}
}
@@ -281,8 +272,8 @@ Err BlockNode::MakeErrorDescribing(const std::string& msg,
void BlockNode::Print(std::ostream& out, int indent) const {
out << IndentFor(indent) << "BLOCK\n";
PrintComments(out, indent);
- for (size_t i = 0; i < statements_.size(); i++)
- statements_[i]->Print(out, indent + 1);
+ for (const auto& statement : statements_)
+ statement->Print(out, indent + 1);
if (end_ && end_->comments())
end_->Print(out, indent + 1);
}
@@ -463,8 +454,7 @@ Value ListNode::Execute(Scope* scope, Err* err) const {
std::vector<Value>& results = result_value.list_value();
results.reserve(contents_.size());
- for (size_t i = 0; i < contents_.size(); i++) {
- const ParseNode* cur = contents_[i];
+ for (const auto& cur : contents_) {
if (cur->AsBlockComment())
continue;
results.push_back(cur->Execute(scope, err));
@@ -493,8 +483,8 @@ Err ListNode::MakeErrorDescribing(const std::string& msg,
void ListNode::Print(std::ostream& out, int indent) const {
out << IndentFor(indent) << "LIST\n";
PrintComments(out, indent);
- for (size_t i = 0; i < contents_.size(); i++)
- contents_[i]->Print(out, indent + 1);
+ for (const auto& cur : contents_)
+ cur->Print(out, indent + 1);
if (end_ && end_->comments())
end_->Print(out, indent + 1);
}
diff --git a/tools/gn/parser.cc b/tools/gn/parser.cc
index fe17aac..51e6fe3 100644
--- a/tools/gn/parser.cc
+++ b/tools/gn/parser.cc
@@ -82,19 +82,18 @@ ParserHelper Parser::expressions_[] = {
Parser::Parser(const std::vector<Token>& tokens, Err* err)
: err_(err), cur_(0) {
- for (std::vector<Token>::const_iterator i(tokens.begin()); i != tokens.end();
- ++i) {
- switch(i->type()) {
+ for (const auto& token : tokens) {
+ switch(token.type()) {
case Token::LINE_COMMENT:
- line_comment_tokens_.push_back(*i);
+ line_comment_tokens_.push_back(token);
break;
case Token::SUFFIX_COMMENT:
- suffix_comment_tokens_.push_back(*i);
+ suffix_comment_tokens_.push_back(token);
break;
default:
// Note that BLOCK_COMMENTs (top-level standalone comments) are passed
// through the real parser.
- tokens_.push_back(*i);
+ tokens_.push_back(token);
break;
}
}
@@ -520,12 +519,8 @@ void Parser::TraverseOrder(const ParseNode* root,
TraverseOrder(binop->left(), pre, post);
TraverseOrder(binop->right(), pre, post);
} else if (const BlockNode* block = root->AsBlock()) {
- const std::vector<ParseNode*>& statements = block->statements();
- for (std::vector<ParseNode*>::const_iterator i(statements.begin());
- i != statements.end();
- ++i) {
- TraverseOrder(*i, pre, post);
- }
+ for (const auto& statement : block->statements())
+ TraverseOrder(statement, pre, post);
TraverseOrder(block->End(), pre, post);
} else if (const ConditionNode* condition = root->AsConditionNode()) {
TraverseOrder(condition->condition(), pre, post);
@@ -537,12 +532,8 @@ void Parser::TraverseOrder(const ParseNode* root,
} else if (root->AsIdentifier()) {
// Nothing.
} else if (const ListNode* list = root->AsList()) {
- const std::vector<const ParseNode*>& contents = list->contents();
- for (std::vector<const ParseNode*>::const_iterator i(contents.begin());
- i != contents.end();
- ++i) {
- TraverseOrder(*i, pre, post);
- }
+ for (const auto& node : list->contents())
+ TraverseOrder(node, pre, post);
TraverseOrder(list->End(), pre, post);
} else if (root->AsLiteral()) {
// Nothing.
@@ -569,13 +560,11 @@ void Parser::AssignComments(ParseNode* file) {
// Assign line comments to syntax immediately following.
int cur_comment = 0;
- for (std::vector<const ParseNode*>::const_iterator i = pre.begin();
- i != pre.end();
- ++i) {
- const Location& start = (*i)->GetRange().begin();
+ for (const auto& node : pre) {
+ const Location& start = node->GetRange().begin();
while (cur_comment < static_cast<int>(line_comment_tokens_.size())) {
if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) {
- const_cast<ParseNode*>(*i)->comments_mutable()->append_before(
+ const_cast<ParseNode*>(node)->comments_mutable()->append_before(
line_comment_tokens_[cur_comment]);
++cur_comment;
} else {
diff --git a/tools/gn/path_output.cc b/tools/gn/path_output.cc
index 2ef060a..de398ec 100644
--- a/tools/gn/path_output.cc
+++ b/tools/gn/path_output.cc
@@ -77,9 +77,9 @@ void PathOutput::WriteFile(std::ostream& out, const OutputFile& file) const {
void PathOutput::WriteFiles(std::ostream& out,
const std::vector<OutputFile>& files) const {
- for (size_t i = 0; i < files.size(); i++) {
+ for (const auto& file : files) {
out << " ";
- WriteFile(out, files[i]);
+ WriteFile(out, file);
}
}
diff --git a/tools/gn/scope.cc b/tools/gn/scope.cc
index 232ed06..7153b323 100644
--- a/tools/gn/scope.cc
+++ b/tools/gn/scope.cc
@@ -57,9 +57,8 @@ Scope::~Scope() {
const Value* Scope::GetValue(const base::StringPiece& ident,
bool counts_as_used) {
// First check for programatically-provided values.
- for (ProviderSet::const_iterator i = programmatic_providers_.begin();
- i != programmatic_providers_.end(); ++i) {
- const Value* v = (*i)->GetProgrammaticValue(ident);
+ for (const auto& provider : programmatic_providers_) {
+ const Value* v = provider->GetProgrammaticValue(ident);
if (v)
return v;
}
@@ -142,13 +141,13 @@ void Scope::RemovePrivateIdentifiers() {
// I'm not sure if all of them support mutating while iterating. Since this
// is not perf-critical, do the safe thing.
std::vector<base::StringPiece> to_remove;
- for (RecordMap::const_iterator i = values_.begin(); i != values_.end(); ++i) {
- if (IsPrivateVar(i->first))
- to_remove.push_back(i->first);
+ for (const auto& cur : values_) {
+ if (IsPrivateVar(cur.first))
+ to_remove.push_back(cur.first);
}
- for (size_t i = 0; i < to_remove.size(); i++)
- values_.erase(to_remove[i]);
+ for (const auto& cur : to_remove)
+ values_.erase(cur);
}
bool Scope::AddTemplate(const std::string& name, const Template* templ) {
@@ -196,20 +195,20 @@ bool Scope::IsSetButUnused(const base::StringPiece& ident) const {
}
bool Scope::CheckForUnusedVars(Err* err) const {
- for (RecordMap::const_iterator i = values_.begin();
- i != values_.end(); ++i) {
- if (!i->second.used) {
- std::string help = "You set the variable \"" + i->first.as_string() +
+ for (const auto& pair : values_) {
+ if (!pair.second.used) {
+ std::string help = "You set the variable \"" + pair.first.as_string() +
"\" here and it was unused before it went\nout of scope.";
- const BinaryOpNode* binary = i->second.value.origin()->AsBinaryOp();
+ const BinaryOpNode* binary = pair.second.value.origin()->AsBinaryOp();
if (binary && binary->op().type() == Token::EQUAL) {
// Make a nicer error message for normal var sets.
*err = Err(binary->left()->GetRange(), "Assignment had no effect.",
help);
} else {
// This will happen for internally-generated variables.
- *err = Err(i->second.value.origin(), "Assignment had no effect.", help);
+ *err = Err(pair.second.value.origin(), "Assignment had no effect.",
+ help);
}
return false;
}
@@ -218,8 +217,8 @@ bool Scope::CheckForUnusedVars(Err* err) const {
}
void Scope::GetCurrentScopeValues(KeyValueMap* output) const {
- for (RecordMap::const_iterator i = values_.begin(); i != values_.end(); ++i)
- (*output)[i->first] = i->second.value;
+ for (const auto& pair : values_)
+ (*output)[pair.first] = pair.second.value;
}
bool Scope::NonRecursiveMergeTo(Scope* dest,
@@ -228,20 +227,20 @@ bool Scope::NonRecursiveMergeTo(Scope* dest,
const char* desc_for_err,
Err* err) const {
// Values.
- for (RecordMap::const_iterator i = values_.begin(); i != values_.end(); ++i) {
- if (options.skip_private_vars && IsPrivateVar(i->first))
+ for (const auto& pair : values_) {
+ if (options.skip_private_vars && IsPrivateVar(pair.first))
continue; // Skip this private var.
- const Value& new_value = i->second.value;
+ const Value& new_value = pair.second.value;
if (!options.clobber_existing) {
- const Value* existing_value = dest->GetValue(i->first);
+ const Value* existing_value = dest->GetValue(pair.first);
if (existing_value && new_value != *existing_value) {
// Value present in both the source and the dest.
std::string desc_string(desc_for_err);
*err = Err(node_for_err, "Value collision.",
- "This " + desc_string + " contains \"" + i->first.as_string() +
+ "This " + desc_string + " contains \"" + pair.first.as_string() +
"\"");
- err->AppendSubErr(Err(i->second.value, "defined here.",
+ err->AppendSubErr(Err(pair.second.value, "defined here.",
"Which would clobber the one in your current scope"));
err->AppendSubErr(Err(*existing_value, "defined here.",
"Executing " + desc_string + " should not conflict with anything "
@@ -249,24 +248,23 @@ bool Scope::NonRecursiveMergeTo(Scope* dest,
return false;
}
}
- dest->values_[i->first] = i->second;
+ dest->values_[pair.first] = pair.second;
if (options.mark_used)
- dest->MarkUsed(i->first);
+ dest->MarkUsed(pair.first);
}
// Target defaults are owning pointers.
- for (NamedScopeMap::const_iterator i = target_defaults_.begin();
- i != target_defaults_.end(); ++i) {
+ for (const auto& pair : target_defaults_) {
if (!options.clobber_existing) {
- if (dest->GetTargetDefaults(i->first)) {
+ if (dest->GetTargetDefaults(pair.first)) {
// TODO(brettw) it would be nice to know the origin of a
// set_target_defaults so we can give locations for the colliding target
// defaults.
std::string desc_string(desc_for_err);
*err = Err(node_for_err, "Target defaults collision.",
"This " + desc_string + " contains target defaults for\n"
- "\"" + i->first + "\" which would clobber one for the\n"
+ "\"" + pair.first + "\" which would clobber one for the\n"
"same target type in your current scope. It's unfortunate that I'm "
"too stupid\nto tell you the location of where the target defaults "
"were set. Usually\nthis happens in the BUILDCONFIG.gn file.");
@@ -275,12 +273,12 @@ bool Scope::NonRecursiveMergeTo(Scope* dest,
}
// Be careful to delete any pointer we're about to clobber.
- Scope** dest_scope = &dest->target_defaults_[i->first];
+ Scope** dest_scope = &dest->target_defaults_[pair.first];
if (*dest_scope)
delete *dest_scope;
*dest_scope = new Scope(settings_);
- i->second->NonRecursiveMergeTo(*dest_scope, options, node_for_err,
- "<SHOULDN'T HAPPEN>", err);
+ pair.second->NonRecursiveMergeTo(*dest_scope, options, node_for_err,
+ "<SHOULDN'T HAPPEN>", err);
}
// Sources assignment filter.
@@ -300,23 +298,23 @@ bool Scope::NonRecursiveMergeTo(Scope* dest,
}
// Templates.
- for (TemplateMap::const_iterator i = templates_.begin();
- i != templates_.end(); ++i) {
- if (options.skip_private_vars && IsPrivateVar(i->first))
+ for (const auto& pair : templates_) {
+ if (options.skip_private_vars && IsPrivateVar(pair.first))
continue; // Skip this private template.
if (!options.clobber_existing) {
- const Template* existing_template = dest->GetTemplate(i->first);
+ const Template* existing_template = dest->GetTemplate(pair.first);
// Since templates are refcounted, we can check if it's the same one by
// comparing pointers.
- if (existing_template && i->second.get() != existing_template) {
+ if (existing_template && pair.second.get() != existing_template) {
// Rule present in both the source and the dest, and they're not the
// same one.
std::string desc_string(desc_for_err);
*err = Err(node_for_err, "Template collision.",
"This " + desc_string + " contains a template \"" +
- i->first + "\"");
- err->AppendSubErr(Err(i->second->GetDefinitionRange(), "defined here.",
+ pair.first + "\"");
+ err->AppendSubErr(Err(pair.second->GetDefinitionRange(),
+ "defined here.",
"Which would clobber the one in your current scope"));
err->AppendSubErr(Err(existing_template->GetDefinitionRange(),
"defined here.",
@@ -327,7 +325,7 @@ bool Scope::NonRecursiveMergeTo(Scope* dest,
}
// Be careful to delete any pointer we're about to clobber.
- dest->templates_[i->first] = i->second;
+ dest->templates_[pair.first] = pair.second;
}
return true;
diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc
index fa9ecf6..fdbf0f2 100644
--- a/tools/gn/setup.cc
+++ b/tools/gn/setup.cc
@@ -351,12 +351,9 @@ bool Setup::FillArgsFromArgsInputFile() {
bool Setup::SaveArgsToFile() {
ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Save args file");
- Scope::KeyValueMap args = build_settings_.build_args().GetAllOverrides();
-
std::ostringstream stream;
- for (Scope::KeyValueMap::const_iterator i = args.begin();
- i != args.end(); ++i) {
- stream << i->first.as_string() << " = " << i->second.ToString(true);
+ for (const auto& pair : build_settings_.build_args().GetAllOverrides()) {
+ stream << pair.first.as_string() << " = " << pair.second.ToString(true);
stream << std::endl;
}
diff --git a/tools/gn/standard_out.cc b/tools/gn/standard_out.cc
index ba9a23a..98e0680 100644
--- a/tools/gn/standard_out.cc
+++ b/tools/gn/standard_out.cc
@@ -167,9 +167,7 @@ void PrintLongHelp(const std::string& text) {
std::vector<std::string> lines;
base::SplitStringDontTrim(text, '\n', &lines);
- for (size_t i = 0; i < lines.size(); i++) {
- const std::string& line = lines[i];
-
+ for (const auto& line : lines) {
// Check for a heading line.
if (!line.empty() && line[0] != ' ') {
// Highlight up to the colon (if any).
diff --git a/tools/gn/substitution_list.cc b/tools/gn/substitution_list.cc
index 826f2c1..85f2d71 100644
--- a/tools/gn/substitution_list.cc
+++ b/tools/gn/substitution_list.cc
@@ -64,6 +64,6 @@ SubstitutionList SubstitutionList::MakeForTest(
}
void SubstitutionList::FillRequiredTypes(SubstitutionBits* bits) const {
- for (size_t i = 0; i < list_.size(); i++)
- list_[i].FillRequiredTypes(bits);
+ for (const auto& item : list_)
+ item.FillRequiredTypes(bits);
}
diff --git a/tools/gn/substitution_writer.cc b/tools/gn/substitution_writer.cc
index 0cab497..65a1d1f 100644
--- a/tools/gn/substitution_writer.cc
+++ b/tools/gn/substitution_writer.cc
@@ -151,8 +151,7 @@ void SubstitutionWriter::WriteWithNinjaVariables(
bool needs_quotes = false;
std::string result;
- for (size_t i = 0; i < pattern.ranges().size(); i++) {
- const SubstitutionPattern::Subrange range = pattern.ranges()[i];
+ for (const auto& range : pattern.ranges()) {
if (range.type == SUBSTITUTION_LITERAL) {
result.append(EscapeString(range.literal, no_quoting, &needs_quotes));
} else {
@@ -172,8 +171,7 @@ void SubstitutionWriter::WriteWithNinjaVariables(
void SubstitutionWriter::GetListAsSourceFiles(
const SubstitutionList& list,
std::vector<SourceFile>* output) {
- for (size_t i = 0; i < list.list().size(); i++) {
- const SubstitutionPattern& pattern = list.list()[i];
+ for (const auto& pattern : list.list()) {
CHECK(pattern.ranges().size() == 1 &&
pattern.ranges()[0].type == SUBSTITUTION_LITERAL)
<< "The substitution patterm \""
@@ -195,10 +193,8 @@ void SubstitutionWriter::GetListAsOutputFiles(
std::vector<OutputFile>* output) {
std::vector<SourceFile> output_as_sources;
GetListAsSourceFiles(list, &output_as_sources);
- for (size_t i = 0; i < output_as_sources.size(); i++) {
- output->push_back(OutputFile(settings->build_settings(),
- output_as_sources[i]));
- }
+ for (const auto& file : output_as_sources)
+ output->push_back(OutputFile(settings->build_settings(), file));
}
// static
@@ -221,8 +217,7 @@ std::string SubstitutionWriter::ApplyPatternToSourceAsString(
const SubstitutionPattern& pattern,
const SourceFile& source) {
std::string result_value;
- for (size_t i = 0; i < pattern.ranges().size(); i++) {
- const SubstitutionPattern::Subrange& subrange = pattern.ranges()[i];
+ for (const auto& subrange : pattern.ranges()) {
if (subrange.type == SUBSTITUTION_LITERAL) {
result_value.append(subrange.literal);
} else {
@@ -253,10 +248,8 @@ void SubstitutionWriter::ApplyListToSource(
const SubstitutionList& list,
const SourceFile& source,
std::vector<SourceFile>* output) {
- for (size_t i = 0; i < list.list().size(); i++) {
- output->push_back(ApplyPatternToSource(
- settings, list.list()[i], source));
- }
+ for (const auto& item : list.list())
+ output->push_back(ApplyPatternToSource(settings, item, source));
}
// static
@@ -265,10 +258,8 @@ void SubstitutionWriter::ApplyListToSourceAsString(
const SubstitutionList& list,
const SourceFile& source,
std::vector<std::string>* output) {
- for (size_t i = 0; i < list.list().size(); i++) {
- output->push_back(ApplyPatternToSourceAsString(
- settings, list.list()[i], source));
- }
+ for (const auto& item : list.list())
+ output->push_back(ApplyPatternToSourceAsString(settings, item, source));
}
// static
@@ -277,10 +268,8 @@ void SubstitutionWriter::ApplyListToSourceAsOutputFile(
const SubstitutionList& list,
const SourceFile& source,
std::vector<OutputFile>* output) {
- for (size_t i = 0; i < list.list().size(); i++) {
- output->push_back(ApplyPatternToSourceAsOutputFile(
- settings, list.list()[i], source));
- }
+ for (const auto& item : list.list())
+ output->push_back(ApplyPatternToSourceAsOutputFile(settings, item, source));
}
// static
@@ -290,8 +279,8 @@ void SubstitutionWriter::ApplyListToSources(
const std::vector<SourceFile>& sources,
std::vector<SourceFile>* output) {
output->clear();
- for (size_t i = 0; i < sources.size(); i++)
- ApplyListToSource(settings, list, sources[i], output);
+ for (const auto& source : sources)
+ ApplyListToSource(settings, list, source, output);
}
// static
@@ -301,8 +290,8 @@ void SubstitutionWriter::ApplyListToSourcesAsString(
const std::vector<SourceFile>& sources,
std::vector<std::string>* output) {
output->clear();
- for (size_t i = 0; i < sources.size(); i++)
- ApplyListToSourceAsString(settings, list, sources[i], output);
+ for (const auto& source : sources)
+ ApplyListToSourceAsString(settings, list, source, output);
}
// static
@@ -312,8 +301,8 @@ void SubstitutionWriter::ApplyListToSourcesAsOutputFile(
const std::vector<SourceFile>& sources,
std::vector<OutputFile>* output) {
output->clear();
- for (size_t i = 0; i < sources.size(); i++)
- ApplyListToSourceAsOutputFile(settings, list, sources[i], output);
+ for (const auto& source : sources)
+ ApplyListToSourceAsOutputFile(settings, list, source, output);
}
// static
@@ -323,14 +312,14 @@ void SubstitutionWriter::WriteNinjaVariablesForSource(
const std::vector<SubstitutionType>& types,
const EscapeOptions& escape_options,
std::ostream& out) {
- for (size_t i = 0; i < types.size(); i++) {
+ for (const auto& type : types) {
// Don't write SOURCE since that just maps to Ninja's $in variable, which
// is implicit in the rule.
- if (types[i] != SUBSTITUTION_SOURCE) {
- out << " " << kSubstitutionNinjaNames[types[i]] << " = ";
+ if (type != SUBSTITUTION_SOURCE) {
+ out << " " << kSubstitutionNinjaNames[type] << " = ";
EscapeStringToStream(
out,
- GetSourceSubstitution(settings, source, types[i], OUTPUT_RELATIVE,
+ GetSourceSubstitution(settings, source, type, OUTPUT_RELATIVE,
settings->build_settings()->build_dir()),
escape_options);
out << std::endl;
@@ -402,8 +391,7 @@ OutputFile SubstitutionWriter::ApplyPatternToTargetAsOutputFile(
const Tool* tool,
const SubstitutionPattern& pattern) {
std::string result_value;
- for (size_t i = 0; i < pattern.ranges().size(); i++) {
- const SubstitutionPattern::Subrange& subrange = pattern.ranges()[i];
+ for (const auto& subrange : pattern.ranges()) {
if (subrange.type == SUBSTITUTION_LITERAL) {
result_value.append(subrange.literal);
} else {
@@ -421,10 +409,8 @@ void SubstitutionWriter::ApplyListToTargetAsOutputFile(
const Tool* tool,
const SubstitutionList& list,
std::vector<OutputFile>* output) {
- for (size_t i = 0; i < list.list().size(); i++) {
- output->push_back(ApplyPatternToTargetAsOutputFile(
- target, tool, list.list()[i]));
- }
+ for (const auto& item : list.list())
+ output->push_back(ApplyPatternToTargetAsOutputFile(target, tool, item));
}
// static
@@ -482,8 +468,7 @@ OutputFile SubstitutionWriter::ApplyPatternToCompilerAsOutputFile(
const SourceFile& source,
const SubstitutionPattern& pattern) {
OutputFile result;
- for (size_t i = 0; i < pattern.ranges().size(); i++) {
- const SubstitutionPattern::Subrange& subrange = pattern.ranges()[i];
+ for (const auto& subrange : pattern.ranges()) {
if (subrange.type == SUBSTITUTION_LITERAL) {
result.value().append(subrange.literal);
} else {
@@ -500,10 +485,8 @@ void SubstitutionWriter::ApplyListToCompilerAsOutputFile(
const SourceFile& source,
const SubstitutionList& list,
std::vector<OutputFile>* output) {
- for (size_t i = 0; i < list.list().size(); i++) {
- output->push_back(ApplyPatternToCompilerAsOutputFile(
- target, source, list.list()[i]));
- }
+ for (const auto& item : list.list())
+ output->push_back(ApplyPatternToCompilerAsOutputFile(target, source, item));
}
// static
@@ -528,8 +511,7 @@ OutputFile SubstitutionWriter::ApplyPatternToLinkerAsOutputFile(
const Tool* tool,
const SubstitutionPattern& pattern) {
OutputFile result;
- for (size_t i = 0; i < pattern.ranges().size(); i++) {
- const SubstitutionPattern::Subrange& subrange = pattern.ranges()[i];
+ for (const auto& subrange : pattern.ranges()) {
if (subrange.type == SUBSTITUTION_LITERAL) {
result.value().append(subrange.literal);
} else {
@@ -545,10 +527,8 @@ void SubstitutionWriter::ApplyListToLinkerAsOutputFile(
const Tool* tool,
const SubstitutionList& list,
std::vector<OutputFile>* output) {
- for (size_t i = 0; i < list.list().size(); i++) {
- output->push_back(ApplyPatternToLinkerAsOutputFile(
- target, tool, list.list()[i]));
- }
+ for (const auto& item : list.list())
+ output->push_back(ApplyPatternToLinkerAsOutputFile(target, tool, item));
}
// static
diff --git a/tools/gn/trace.cc b/tools/gn/trace.cc
index df97c34..14b0a14 100644
--- a/tools/gn/trace.cc
+++ b/tools/gn/trace.cc
@@ -65,11 +65,9 @@ void SummarizeParses(std::vector<const TraceItem*>& loads,
out << "File parse times: (time in ms, name)\n";
std::sort(loads.begin(), loads.end(), &DurationGreater);
-
- for (size_t i = 0; i < loads.size(); i++) {
- out << base::StringPrintf(" %8.2f ",
- loads[i]->delta().InMillisecondsF());
- out << loads[i]->name() << std::endl;
+ for (const auto& load : loads) {
+ out << base::StringPrintf(" %8.2f ", load->delta().InMillisecondsF());
+ out << load->name() << std::endl;
}
}
@@ -77,24 +75,22 @@ void SummarizeCoalesced(std::vector<const TraceItem*>& items,
std::ostream& out) {
// Group by file name.
std::map<std::string, Coalesced> coalesced;
- for (size_t i = 0; i < items.size(); i++) {
- Coalesced& c = coalesced[items[i]->name()];
- c.name_ptr = &items[i]->name();
- c.total_duration += items[i]->delta().InMillisecondsF();
+ for (const auto& item : items) {
+ Coalesced& c = coalesced[item->name()];
+ c.name_ptr = &item->name();
+ c.total_duration += item->delta().InMillisecondsF();
c.count++;
}
// Sort by duration.
std::vector<Coalesced> sorted;
- for (std::map<std::string, Coalesced>::iterator iter = coalesced.begin();
- iter != coalesced.end(); ++iter)
- sorted.push_back(iter->second);
+ for (const auto& pair : coalesced)
+ sorted.push_back(pair.second);
std::sort(sorted.begin(), sorted.end(), &CoalescedDurationGreater);
- for (size_t i = 0; i < sorted.size(); i++) {
- out << base::StringPrintf(" %8.2f %d ",
- sorted[i].total_duration, sorted[i].count);
- out << *sorted[i].name_ptr << std::endl;
+ for (const auto& cur : sorted) {
+ out << base::StringPrintf(" %8.2f %d ", cur.total_duration, cur.count);
+ out << *cur.name_ptr << std::endl;
}
}
@@ -187,19 +183,19 @@ std::string SummarizeTraces() {
std::vector<const TraceItem*> script_execs;
std::vector<const TraceItem*> check_headers;
int headers_checked = 0;
- for (size_t i = 0; i < events.size(); i++) {
- switch (events[i]->type()) {
+ for (const auto& event : events) {
+ switch (event->type()) {
case TraceItem::TRACE_FILE_PARSE:
- parses.push_back(events[i]);
+ parses.push_back(event);
break;
case TraceItem::TRACE_FILE_EXECUTE:
- file_execs.push_back(events[i]);
+ file_execs.push_back(event);
break;
case TraceItem::TRACE_SCRIPT_EXECUTE:
- script_execs.push_back(events[i]);
+ script_execs.push_back(event);
break;
case TraceItem::TRACE_CHECK_HEADERS:
- check_headers.push_back(events[i]);
+ check_headers.push_back(event);
break;
case TraceItem::TRACE_CHECK_HEADER:
headers_checked++;
@@ -225,8 +221,8 @@ std::string SummarizeTraces() {
// parallel. Just report the total of all of them.
if (!check_headers.empty()) {
float check_headers_time = 0;
- for (size_t i = 0; i < check_headers.size(); i++)
- check_headers_time += check_headers[i]->delta().InMillisecondsF();
+ for (const auto& cur : check_headers)
+ check_headers_time += cur->delta().InMillisecondsF();
out << "Header check time: (total time in ms, files checked)\n";
out << base::StringPrintf(" %8.2f %d\n",
diff --git a/tools/gn/value.cc b/tools/gn/value.cc
index 0c1f461..f800bf3 100644
--- a/tools/gn/value.cc
+++ b/tools/gn/value.cc
@@ -152,10 +152,9 @@ std::string Value::ToString(bool quote_string) const {
return std::string("{ }");
std::string result = "{\n";
- for (Scope::KeyValueMap::const_iterator i = scope_values.begin();
- i != scope_values.end(); ++i) {
- result += " " + i->first.as_string() + " = " +
- i->second.ToString(true) + "\n";
+ for (const auto& pair : scope_values) {
+ result += " " + pair.first.as_string() + " = " +
+ pair.second.ToString(true) + "\n";
}
result += "}";
diff --git a/tools/gn/value_extractors.cc b/tools/gn/value_extractors.cc
index fe86bd3..9e6a37e 100644
--- a/tools/gn/value_extractors.cc
+++ b/tools/gn/value_extractors.cc
@@ -42,13 +42,13 @@ bool ListValueUniqueExtractor(const Value& value,
return false;
const std::vector<Value>& input_list = value.list_value();
- for (size_t i = 0; i < input_list.size(); i++) {
+ for (const auto& item : input_list) {
T new_one;
- if (!converter(input_list[i], &new_one, err))
+ if (!converter(item, &new_one, err))
return false;
if (!dest->push_back(new_one)) {
// Already in the list, throw error.
- *err = Err(input_list[i], "Duplicate item in list");
+ *err = Err(item, "Duplicate item in list");
size_t previous_index = dest->IndexOf(new_one);
err->AppendSubErr(Err(input_list[previous_index],
"This was the previous definition."));
@@ -143,10 +143,10 @@ bool ExtractListOfStringValues(const Value& value,
return false;
const std::vector<Value>& input_list = value.list_value();
dest->reserve(input_list.size());
- for (size_t i = 0; i < input_list.size(); i++) {
- if (!input_list[i].VerifyTypeIs(Value::STRING, err))
+ for (const auto& item : input_list) {
+ if (!item.VerifyTypeIs(Value::STRING, err))
return false;
- dest->push_back(input_list[i].string_value());
+ dest->push_back(item.string_value());
}
return true;
}
diff --git a/tools/gn/visibility.cc b/tools/gn/visibility.cc
index 0dbad16..a61a5cd 100644
--- a/tools/gn/visibility.cc
+++ b/tools/gn/visibility.cc
@@ -30,9 +30,8 @@ bool Visibility::Set(const SourceDir& current_dir,
return false;
}
- const std::vector<Value>& list = value.list_value();
- for (size_t i = 0; i < list.size(); i++) {
- patterns_.push_back(LabelPattern::GetPattern(current_dir, list[i], err));
+ for (const auto& item : value.list_value()) {
+ patterns_.push_back(LabelPattern::GetPattern(current_dir, item, err));
if (err->has_error())
return false;
}
@@ -54,8 +53,8 @@ void Visibility::SetPrivate(const SourceDir& current_dir) {
}
bool Visibility::CanSeeMe(const Label& label) const {
- for (size_t i = 0; i < patterns_.size(); i++) {
- if (patterns_[i].Matches(label))
+ for (const auto& pattern : patterns_) {
+ if (pattern.Matches(label))
return true;
}
return false;
@@ -76,8 +75,8 @@ std::string Visibility::Describe(int indent, bool include_brackets) const {
inner_indent_string += " ";
}
- for (size_t i = 0; i < patterns_.size(); i++)
- result += inner_indent_string + patterns_[i].Describe() + "\n";
+ for (const auto& pattern : patterns_)
+ result += inner_indent_string + pattern.Describe() + "\n";
if (include_brackets)
result += outer_indent_string + "]\n";