Commit b9cf968c authored by tfarina's avatar tfarina Committed by Commit bot

tools/gn: Convert for loops to use the new range-based loops in C++11.

range-based loops is one of the C++11 allowed features. See
https://chromium-cpp.appspot.com/ and
https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/hpzz4EqbVmc.

This patch was generated with the following command lines:

$ ninja -C out/Debug -t compdb cxx > out/Debug/compile_commands.json
$ cd out/Debug
$ find ../../tools/gn -name '*.cc'  | xargs -n 16 -P 32 \
~/src/repos/llvm/build/bin/clang-modernize -loop-convert -p . -include \
tools/gn -format -style=Chromium
$ ninja gn gn_unittests
$ ./gn_unittests

BUG=None
TEST=gn && gn_unittests
R=brettw@chromium.org

Review URL: https://codereview.chromium.org/986113002

Cr-Commit-Position: refs/heads/master@{#322177}
parent 0392dbf5
...@@ -30,10 +30,10 @@ std::string ExtractGNBuildCommands(const base::FilePath& build_ninja_file) { ...@@ -30,10 +30,10 @@ std::string ExtractGNBuildCommands(const base::FilePath& build_ninja_file) {
std::string result; std::string result;
int num_blank_lines = 0; int num_blank_lines = 0;
for (size_t i = 0; i < lines.size(); ++i) { for (const auto& line : lines) {
result += lines[i]; result += line;
result += "\n"; result += "\n";
if (lines[i].empty()) { if (line.empty()) {
++num_blank_lines; ++num_blank_lines;
} }
if (num_blank_lines == 2) if (num_blank_lines == 2)
......
...@@ -257,9 +257,9 @@ void PrintConfigsVector(const Target* target, ...@@ -257,9 +257,9 @@ void PrintConfigsVector(const Target* target,
OutputString("\n" + heading + " (in order applying):\n"); OutputString("\n" + heading + " (in order applying):\n");
Label toolchain_label = target->label().GetToolchainLabel(); Label toolchain_label = target->label().GetToolchainLabel();
for (size_t i = 0; i < configs.size(); i++) { for (const auto& config : configs) {
OutputString(" " + OutputString(" " + config.label.GetUserVisibleName(toolchain_label) +
configs[i].label.GetUserVisibleName(toolchain_label) + "\n"); "\n");
} }
} }
...@@ -275,9 +275,9 @@ void PrintConfigsVector(const Target* target, ...@@ -275,9 +275,9 @@ void PrintConfigsVector(const Target* target,
OutputString("\n" + heading + " (in order applying):\n"); OutputString("\n" + heading + " (in order applying):\n");
Label toolchain_label = target->label().GetToolchainLabel(); Label toolchain_label = target->label().GetToolchainLabel();
for (size_t i = 0; i < configs.size(); i++) { for (const auto& config : configs) {
OutputString(" " + OutputString(" " + config.label.GetUserVisibleName(toolchain_label) +
configs[i].label.GetUserVisibleName(toolchain_label) + "\n"); "\n");
} }
} }
...@@ -310,8 +310,8 @@ void PrintFileList(const Target::FileList& files, ...@@ -310,8 +310,8 @@ void PrintFileList(const Target::FileList& files,
Target::FileList sorted = files; Target::FileList sorted = files;
std::sort(sorted.begin(), sorted.end()); std::sort(sorted.begin(), sorted.end());
for (size_t i = 0; i < sorted.size(); i++) for (const auto& elem : sorted)
OutputString(indent + sorted[i].value() + "\n"); OutputString(indent + elem.value() + "\n");
} }
void PrintSources(const Target* target, bool display_header) { void PrintSources(const Target* target, bool display_header) {
...@@ -328,11 +328,8 @@ void PrintOutputs(const Target* target, bool display_header) { ...@@ -328,11 +328,8 @@ void PrintOutputs(const Target* target, bool display_header) {
if (target->output_type() == Target::ACTION) { if (target->output_type() == Target::ACTION) {
// Action, print out outputs, don't apply sources to it. // Action, print out outputs, don't apply sources to it.
for (size_t i = 0; i < target->action_values().outputs().list().size(); for (const auto& elem : target->action_values().outputs().list()) {
i++) { OutputString(" " + elem.AsString() + "\n");
OutputString(" " +
target->action_values().outputs().list()[i].AsString() +
"\n");
} }
} else { } else {
const SubstitutionList& outputs = target->action_values().outputs(); const SubstitutionList& outputs = target->action_values().outputs();
...@@ -340,8 +337,8 @@ void PrintOutputs(const Target* target, bool display_header) { ...@@ -340,8 +337,8 @@ void PrintOutputs(const Target* target, bool display_header) {
// Display the pattern and resolved pattern separately, since there are // Display the pattern and resolved pattern separately, since there are
// subtitutions used. // subtitutions used.
OutputString(" Output pattern:\n"); OutputString(" Output pattern:\n");
for (size_t i = 0; i < outputs.list().size(); i++) for (const auto& elem : outputs.list())
OutputString(" " + outputs.list()[i].AsString() + "\n"); OutputString(" " + elem.AsString() + "\n");
// Now display what that resolves to given the sources. // Now display what that resolves to given the sources.
OutputString("\n Resolved output file list:\n"); OutputString("\n Resolved output file list:\n");
...@@ -364,9 +361,8 @@ void PrintScript(const Target* target, bool display_header) { ...@@ -364,9 +361,8 @@ void PrintScript(const Target* target, bool display_header) {
void PrintArgs(const Target* target, bool display_header) { void PrintArgs(const Target* target, bool display_header) {
if (display_header) if (display_header)
OutputString("\nargs:\n"); OutputString("\nargs:\n");
for (size_t i = 0; i < target->action_values().args().list().size(); i++) { for (const auto& elem : target->action_values().args().list()) {
OutputString(" " + OutputString(" " + elem.AsString() + "\n");
target->action_values().args().list()[i].AsString() + "\n");
} }
} }
......
...@@ -64,8 +64,8 @@ void OutputHighlighedPosition(const Location& location, ...@@ -64,8 +64,8 @@ void OutputHighlighedPosition(const Location& location,
highlight[i] = ' '; highlight[i] = ' ';
// Highlight all the ranges on the line. // Highlight all the ranges on the line.
for (size_t i = 0; i < ranges.size(); i++) for (const auto& range : ranges)
FillRangeOnLine(ranges[i], location.line_number(), &highlight); FillRangeOnLine(range, location.line_number(), &highlight);
// Allow the marker to be one past the end of the line for marking the end. // Allow the marker to be one past the end of the line for marking the end.
highlight.push_back(' '); highlight.push_back(' ');
......
...@@ -44,18 +44,18 @@ void EscapeStringToString_Ninja(const base::StringPiece& str, ...@@ -44,18 +44,18 @@ void EscapeStringToString_Ninja(const base::StringPiece& str,
const EscapeOptions& options, const EscapeOptions& options,
DestString* dest, DestString* dest,
bool* needed_quoting) { bool* needed_quoting) {
for (size_t i = 0; i < str.size(); i++) for (const auto& elem : str)
NinjaEscapeChar(str[i], dest); NinjaEscapeChar(elem, dest);
} }
template<typename DestString> template<typename DestString>
void EscapeStringToString_NinjaPreformatted(const base::StringPiece& str, void EscapeStringToString_NinjaPreformatted(const base::StringPiece& str,
DestString* dest) { DestString* dest) {
// Only Ninja-escape $. // Only Ninja-escape $.
for (size_t i = 0; i < str.size(); i++) { for (const auto& elem : str) {
if (str[i] == '$') if (elem == '$')
dest->push_back('$'); dest->push_back('$');
dest->push_back(str[i]); dest->push_back(elem);
} }
} }
...@@ -118,26 +118,26 @@ void EscapeStringToString_PosixNinjaFork(const base::StringPiece& str, ...@@ -118,26 +118,26 @@ void EscapeStringToString_PosixNinjaFork(const base::StringPiece& str,
const EscapeOptions& options, const EscapeOptions& options,
DestString* dest, DestString* dest,
bool* needed_quoting) { bool* needed_quoting) {
for (size_t i = 0; i < str.size(); i++) { for (const auto& elem : str) {
if (str[i] == '$' || str[i] == ' ') { if (elem == '$' || elem == ' ') {
// Space and $ are special to both Ninja and the shell. '$' escape for // Space and $ are special to both Ninja and the shell. '$' escape for
// Ninja, then backslash-escape for the shell. // Ninja, then backslash-escape for the shell.
dest->push_back('\\'); dest->push_back('\\');
dest->push_back('$'); dest->push_back('$');
dest->push_back(str[i]); dest->push_back(elem);
} else if (str[i] == ':') { } else if (elem == ':') {
// Colon is the only other Ninja special char, which is not special to // Colon is the only other Ninja special char, which is not special to
// the shell. // the shell.
dest->push_back('$'); dest->push_back('$');
dest->push_back(':'); dest->push_back(':');
} else if (static_cast<unsigned>(str[i]) >= 0x80 || } else if (static_cast<unsigned>(elem) >= 0x80 ||
!kShellValid[static_cast<int>(str[i])]) { !kShellValid[static_cast<int>(elem)]) {
// All other invalid shell chars get backslash-escaped. // All other invalid shell chars get backslash-escaped.
dest->push_back('\\'); dest->push_back('\\');
dest->push_back(str[i]); dest->push_back(elem);
} else { } else {
// Everything else is a literal. // Everything else is a literal.
dest->push_back(str[i]); dest->push_back(elem);
} }
} }
} }
......
...@@ -194,8 +194,8 @@ bool ExecProcess(const base::CommandLine& cmdline, ...@@ -194,8 +194,8 @@ bool ExecProcess(const base::CommandLine& cmdline,
// Adding another element here? Remeber to increase the argument to // Adding another element here? Remeber to increase the argument to
// reserve(), above. // reserve(), above.
for (size_t i = 0; i < fd_shuffle1.size(); ++i) for (const auto& elem : fd_shuffle1)
fd_shuffle2.push_back(fd_shuffle1[i]); fd_shuffle2.push_back(elem);
if (!ShuffleFileDescriptors(&fd_shuffle1)) if (!ShuffleFileDescriptors(&fd_shuffle1))
_exit(127); _exit(127);
......
...@@ -30,8 +30,8 @@ std::string FilePathToUTF8(const base::FilePath& path) { ...@@ -30,8 +30,8 @@ std::string FilePathToUTF8(const base::FilePath& path) {
base::FilePath RepoPathToPathName(const std::vector<int>& repo_path) { base::FilePath RepoPathToPathName(const std::vector<int>& repo_path) {
base::FilePath ret; base::FilePath ret;
for (size_t i = 0; i < repo_path.size(); i++) { for (const auto& elem : repo_path) {
ret = ret.Append(UTF8ToFilePath(base::IntToString(repo_path[i]))); ret = ret.Append(UTF8ToFilePath(base::IntToString(elem)));
} }
return ret; return ret;
} }
...@@ -58,9 +58,9 @@ std::string RepoPathToTargetName(const std::vector<int>& repo_path, ...@@ -58,9 +58,9 @@ std::string RepoPathToTargetName(const std::vector<int>& repo_path,
std::string RepoPathToFullTargetName(const std::vector<int>& repo_path, std::string RepoPathToFullTargetName(const std::vector<int>& repo_path,
int target_index) { int target_index) {
std::string ret; std::string ret;
for (size_t i = 0; i < repo_path.size(); i++) { for (const auto& elem : repo_path) {
ret.push_back('/'); ret.push_back('/');
ret.append(base::IntToString(repo_path[i])); ret.append(base::IntToString(elem));
} }
ret += ":" + RepoPathToTargetName(repo_path, target_index); ret += ":" + RepoPathToTargetName(repo_path, target_index);
......
...@@ -330,10 +330,10 @@ bool HeaderChecker::CheckInclude(const Target* from_target, ...@@ -330,10 +330,10 @@ bool HeaderChecker::CheckInclude(const Target* from_target,
Err last_error; Err last_error;
bool found_dependency = false; bool found_dependency = false;
for (size_t i = 0; i < targets.size(); i++) { for (const auto& target : targets) {
// We always allow source files in a target to include headers also in that // We always allow source files in a target to include headers also in that
// target. // target.
const Target* to_target = targets[i].target; const Target* to_target = target.target;
if (to_target == from_target) if (to_target == from_target)
return true; return true;
...@@ -357,20 +357,19 @@ bool HeaderChecker::CheckInclude(const Target* from_target, ...@@ -357,20 +357,19 @@ bool HeaderChecker::CheckInclude(const Target* from_target,
found_dependency = true; found_dependency = true;
if (targets[i].is_public && is_permitted_chain) { if (target.is_public && is_permitted_chain) {
// This one is OK, we're done. // This one is OK, we're done.
last_error = Err(); last_error = Err();
break; break;
} }
// Diagnose the error. // Diagnose the error.
if (!targets[i].is_public) { if (!target.is_public) {
// Danger: must call CreatePersistentRange to put in Err. // Danger: must call CreatePersistentRange to put in Err.
last_error = Err( last_error = Err(CreatePersistentRange(source_file, range),
CreatePersistentRange(source_file, range), "Including a private header.",
"Including a private header.", "This file is private to the target " +
"This file is private to the target " + target.target->label().GetUserVisibleName(false));
targets[i].target->label().GetUserVisibleName(false));
} else if (!is_permitted_chain) { } else if (!is_permitted_chain) {
last_error = Err( last_error = Err(
CreatePersistentRange(source_file, range), CreatePersistentRange(source_file, range),
......
...@@ -441,10 +441,9 @@ void NinjaBinaryTargetWriter::WriteOrderOnlyDependencies( ...@@ -441,10 +441,9 @@ void NinjaBinaryTargetWriter::WriteOrderOnlyDependencies(
out_ << " ||"; out_ << " ||";
// Non-linkable targets. // Non-linkable targets.
for (size_t i = 0; i < non_linkable_deps.size(); i++) { for (const auto& non_linkable_dep : non_linkable_deps) {
out_ << " "; out_ << " ";
path_output_.WriteFile( path_output_.WriteFile(out_, non_linkable_dep->dependency_output_file());
out_, non_linkable_deps[i]->dependency_output_file());
} }
} }
} }
......
...@@ -157,13 +157,13 @@ void NinjaBuildWriter::WriteNinjaRules() { ...@@ -157,13 +157,13 @@ void NinjaBuildWriter::WriteNinjaRules() {
dep_out_ << "build.ninja:"; dep_out_ << "build.ninja:";
std::vector<base::FilePath> input_files; std::vector<base::FilePath> input_files;
g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files); g_scheduler->input_file_manager()->GetAllPhysicalInputFileNames(&input_files);
for (size_t i = 0; i < input_files.size(); i++) for (const auto& input_file : input_files)
dep_out_ << " " << FilePathToUTF8(input_files[i]); dep_out_ << " " << FilePathToUTF8(input_file);
// Other files read by the build. // Other files read by the build.
std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies(); std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies();
for (size_t i = 0; i < other_files.size(); i++) for (const auto& other_file : other_files)
dep_out_ << " " << FilePathToUTF8(other_files[i]); dep_out_ << " " << FilePathToUTF8(other_file);
out_ << std::endl; out_ << std::endl;
} }
...@@ -175,9 +175,9 @@ void NinjaBuildWriter::WriteLinkPool() { ...@@ -175,9 +175,9 @@ void NinjaBuildWriter::WriteLinkPool() {
} }
void NinjaBuildWriter::WriteSubninjas() { void NinjaBuildWriter::WriteSubninjas() {
for (size_t i = 0; i < all_settings_.size(); i++) { for (const auto& elem : all_settings_) {
out_ << "subninja "; out_ << "subninja ";
path_output_.WriteFile(out_, GetNinjaFileForToolchain(all_settings_[i])); path_output_.WriteFile(out_, GetNinjaFileForToolchain(elem));
out_ << std::endl; out_ << std::endl;
} }
out_ << std::endl; out_ << std::endl;
...@@ -193,8 +193,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -193,8 +193,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
std::map<std::string, int> small_name_count; std::map<std::string, int> small_name_count;
std::vector<const Target*> toplevel_targets; std::vector<const Target*> toplevel_targets;
base::hash_set<std::string> target_files; base::hash_set<std::string> target_files;
for (size_t i = 0; i < default_toolchain_targets_.size(); i++) { for (const auto& target : default_toolchain_targets_) {
const Target* target = default_toolchain_targets_[i];
const Label& label = target->label(); const Label& label = target->label();
small_name_count[label.name()]++; small_name_count[label.name()]++;
...@@ -211,8 +210,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -211,8 +210,7 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
toplevel_targets.push_back(target); toplevel_targets.push_back(target);
} }
for (size_t i = 0; i < default_toolchain_targets_.size(); i++) { for (const auto& target : default_toolchain_targets_) {
const Target* target = default_toolchain_targets_[i];
const Label& label = target->label(); const Label& label = target->label();
OutputFile target_file(target->dependency_output_file()); OutputFile target_file(target->dependency_output_file());
// The output files may have leading "./" so normalize those away. // The output files may have leading "./" so normalize those away.
...@@ -249,11 +247,10 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -249,11 +247,10 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
// Pick up phony rules for the toplevel targets with non-unique names (which // Pick up phony rules for the toplevel targets with non-unique names (which
// would have been skipped in the above loop). // would have been skipped in the above loop).
for (size_t i = 0; i < toplevel_targets.size(); i++) { for (const auto& toplevel_target : toplevel_targets) {
if (small_name_count[toplevel_targets[i]->label().name()] > 1) { if (small_name_count[toplevel_target->label().name()] > 1) {
const Target* target = toplevel_targets[i]; WritePhonyRule(toplevel_target, toplevel_target->dependency_output_file(),
WritePhonyRule(target, target->dependency_output_file(), toplevel_target->label().name());
target->label().name());
} }
} }
...@@ -261,8 +258,8 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) { ...@@ -261,8 +258,8 @@ bool NinjaBuildWriter::WritePhonyAndAllRules(Err* err) {
// target (rather than building 'all' by default). By convention // target (rather than building 'all' by default). By convention
// we use group("default") but it doesn't have to be a group. // we use group("default") but it doesn't have to be a group.
bool default_target_exists = false; bool default_target_exists = false;
for (size_t i = 0; i < default_toolchain_targets_.size(); i++) { for (const auto& target : default_toolchain_targets_) {
const Label& label = default_toolchain_targets_[i]->label(); const Label& label = target->label();
if (label.dir().value() == "//" && label.name() == "default") if (label.dir().value() == "//" && label.name() == "default")
default_target_exists = true; default_target_exists = true;
} }
......
...@@ -100,9 +100,7 @@ void NinjaCopyTargetWriter::WriteCopyRules( ...@@ -100,9 +100,7 @@ void NinjaCopyTargetWriter::WriteCopyRules(
// where a command might need to make sure something else runs before it runs // where a command might need to make sure something else runs before it runs
// to avoid conflicts. Such cases should be avoided where possible, but // to avoid conflicts. Such cases should be avoided where possible, but
// sometimes that's not possible. // sometimes that's not possible.
for (size_t i = 0; i < target_->sources().size(); i++) { for (const auto& input_file : target_->sources()) {
const SourceFile& input_file = target_->sources()[i];
OutputFile output_file = OutputFile output_file =
SubstitutionWriter::ApplyPatternToSourceAsOutputFile( SubstitutionWriter::ApplyPatternToSourceAsOutputFile(
target_->settings(), output_subst, input_file); target_->settings(), output_subst, input_file);
......
...@@ -195,16 +195,14 @@ OutputFile NinjaTargetWriter::WriteInputDepsStampAndGetDep( ...@@ -195,16 +195,14 @@ OutputFile NinjaTargetWriter::WriteInputDepsStampAndGetDep(
} }
// Input files are order-only deps. // Input files are order-only deps.
const Target::FileList& prereqs = target_->inputs(); for (const auto& input : target_->inputs()) {
for (size_t i = 0; i < prereqs.size(); i++) {
out_ << " "; out_ << " ";
path_output_.WriteFile(out_, prereqs[i]); path_output_.WriteFile(out_, input);
} }
if (list_sources_as_input_deps) { if (list_sources_as_input_deps) {
const Target::FileList& sources = target_->sources(); for (const auto& source : target_->sources()) {
for (size_t i = 0; i < sources.size(); i++) {
out_ << " "; out_ << " ";
path_output_.WriteFile(out_, sources[i]); path_output_.WriteFile(out_, source);
} }
} }
...@@ -225,8 +223,8 @@ OutputFile NinjaTargetWriter::WriteInputDepsStampAndGetDep( ...@@ -225,8 +223,8 @@ OutputFile NinjaTargetWriter::WriteInputDepsStampAndGetDep(
// toolchains often have more than one dependency, we could consider writing // toolchains often have more than one dependency, we could consider writing
// a toolchain-specific stamp file and only include the stamp here. // a toolchain-specific stamp file and only include the stamp here.
const LabelTargetVector& toolchain_deps = target_->toolchain()->deps(); const LabelTargetVector& toolchain_deps = target_->toolchain()->deps();
for (size_t i = 0; i < toolchain_deps.size(); i++) for (const auto& toolchain_dep : toolchain_deps)
unique_deps.insert(toolchain_deps[i].ptr); unique_deps.insert(toolchain_dep.ptr);
for (const auto& dep : unique_deps) { for (const auto& dep : unique_deps) {
DCHECK(!dep->dependency_output_file().value().empty()); DCHECK(!dep->dependency_output_file().value().empty());
......
...@@ -128,9 +128,9 @@ void NinjaToolchainWriter::WriteRulePattern(const char* name, ...@@ -128,9 +128,9 @@ void NinjaToolchainWriter::WriteRulePattern(const char* name,
void NinjaToolchainWriter::WriteSubninjas() { void NinjaToolchainWriter::WriteSubninjas() {
// Write subninja commands for each generated target. // Write subninja commands for each generated target.
for (size_t i = 0; i < targets_.size(); i++) { for (const auto& target : targets_) {
OutputFile ninja_file(targets_[i]->settings()->build_settings(), OutputFile ninja_file(target->settings()->build_settings(),
GetNinjaFileForTarget(targets_[i])); GetNinjaFileForTarget(target));
out_ << "subninja "; out_ << "subninja ";
path_output_.WriteFile(out_, ninja_file); path_output_.WriteFile(out_, ninja_file);
out_ << std::endl; out_ << std::endl;
......
...@@ -52,11 +52,11 @@ bool NinjaWriter::WriteToolchains(std::vector<const Settings*>* all_settings, ...@@ -52,11 +52,11 @@ bool NinjaWriter::WriteToolchains(std::vector<const Settings*>* all_settings,
CategorizedMap categorized; CategorizedMap categorized;
std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords(); std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords();
for (size_t i = 0; i < all_records.size(); i++) { for (const auto& all_record : all_records) {
if (all_records[i]->type() == BuilderRecord::ITEM_TARGET && if (all_record->type() == BuilderRecord::ITEM_TARGET &&
all_records[i]->should_generate()) { all_record->should_generate()) {
categorized[all_records[i]->label().GetToolchainLabel()].push_back( categorized[all_record->label().GetToolchainLabel()].push_back(
all_records[i]->item()->AsTarget()); all_record->item()->AsTarget());
} }
} }
if (categorized.empty()) { if (categorized.empty()) {
......
...@@ -98,10 +98,10 @@ void RemoveMatchesFromList(const BinaryOpNode* op_node, ...@@ -98,10 +98,10 @@ void RemoveMatchesFromList(const BinaryOpNode* op_node,
} }
case Value::LIST: // Filter out each individual thing. case Value::LIST: // Filter out each individual thing.
for (size_t i = 0; i < to_remove.list_value().size(); i++) { for (const auto& elem : to_remove.list_value()) {
// TODO(brettw) if the nested item is a list, we may want to search // TODO(brettw) if the nested item is a list, we may want to search
// for the literal list rather than remote the items in it. // for the literal list rather than remote the items in it.
RemoveMatchesFromList(op_node, list, to_remove.list_value()[i], err); RemoveMatchesFromList(op_node, list, elem, err);
if (err->has_error()) if (err->has_error())
return; return;
} }
......
...@@ -167,16 +167,16 @@ void PatternList::SetFromValue(const Value& v, Err* err) { ...@@ -167,16 +167,16 @@ void PatternList::SetFromValue(const Value& v, Err* err) {
} }
const std::vector<Value>& list = v.list_value(); const std::vector<Value>& list = v.list_value();
for (size_t i = 0; i < list.size(); i++) { for (const auto& elem : list) {
if (!list[i].VerifyTypeIs(Value::STRING, err)) if (!elem.VerifyTypeIs(Value::STRING, err))
return; return;
patterns_.push_back(Pattern(list[i].string_value())); patterns_.push_back(Pattern(elem.string_value()));
} }
} }
bool PatternList::MatchesString(const std::string& s) const { bool PatternList::MatchesString(const std::string& s) const {
for (size_t i = 0; i < patterns_.size(); i++) { for (const auto& pattern : patterns_) {
if (patterns_[i].MatchesString(s)) if (pattern.MatchesString(s))
return true; return true;
} }
return false; return false;
......
...@@ -179,12 +179,12 @@ void PrintLongHelp(const std::string& text) { ...@@ -179,12 +179,12 @@ void PrintLongHelp(const std::string& text) {
// Check for a comment. // Check for a comment.
TextDecoration dec = DECORATION_NONE; TextDecoration dec = DECORATION_NONE;
for (size_t char_i = 0; char_i < line.size(); char_i++) { for (const auto& elem : line) {
if (line[char_i] == '#') { if (elem == '#') {
// Got a comment, draw dimmed. // Got a comment, draw dimmed.
dec = DECORATION_DIM; dec = DECORATION_DIM;
break; break;
} else if (line[char_i] != ' ') { } else if (elem != ' ') {
break; break;
} }
} }
......
...@@ -101,19 +101,19 @@ SubstitutionPattern SubstitutionPattern::MakeForTest(const char* str) { ...@@ -101,19 +101,19 @@ SubstitutionPattern SubstitutionPattern::MakeForTest(const char* str) {
std::string SubstitutionPattern::AsString() const { std::string SubstitutionPattern::AsString() const {
std::string result; std::string result;
for (size_t i = 0; i < ranges_.size(); i++) { for (const auto& elem : ranges_) {
if (ranges_[i].type == SUBSTITUTION_LITERAL) if (elem.type == SUBSTITUTION_LITERAL)
result.append(ranges_[i].literal); result.append(elem.literal);
else else
result.append(kSubstitutionNames[ranges_[i].type]); result.append(kSubstitutionNames[elem.type]);
} }
return result; return result;
} }
void SubstitutionPattern::FillRequiredTypes(SubstitutionBits* bits) const { void SubstitutionPattern::FillRequiredTypes(SubstitutionBits* bits) const {
for (size_t i = 0; i < ranges_.size(); i++) { for (const auto& elem : ranges_) {
if (ranges_[i].type != SUBSTITUTION_LITERAL) if (elem.type != SUBSTITUTION_LITERAL)
bits->used[static_cast<size_t>(ranges_[i].type)] = true; bits->used[static_cast<size_t>(elem.type)] = true;
} }
} }
......
...@@ -89,9 +89,9 @@ void Toolchain::SetTool(ToolType type, scoped_ptr<Tool> t) { ...@@ -89,9 +89,9 @@ void Toolchain::SetTool(ToolType type, scoped_ptr<Tool> t) {
void Toolchain::ToolchainSetupComplete() { void Toolchain::ToolchainSetupComplete() {
// Collect required bits from all tools. // Collect required bits from all tools.
for (size_t i = 0; i < TYPE_NUMTYPES; i++) { for (const auto& tool : tools_) {
if (tools_[i]) if (tool)
substitution_bits_.MergeFrom(tools_[i]->substitution_bits()); substitution_bits_.MergeFrom(tool->substitution_bits());
} }
setup_complete_ = true; setup_complete_ = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment