Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: tools/gn/builder.cc

Issue 610043002: Convert GN's deps iterator to work with range-based for loops. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/builder.h" 5 #include "tools/gn/builder.h"
6 6
7 #include "tools/gn/config.h" 7 #include "tools/gn/config.h"
8 #include "tools/gn/deps_iterator.h" 8 #include "tools/gn/deps_iterator.h"
9 #include "tools/gn/err.h" 9 #include "tools/gn/err.h"
10 #include "tools/gn/loader.h" 10 #include "tools/gn/loader.h"
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 474 }
475 475
476 // "Forward dependent configs" should refer to targets in the deps that should 476 // "Forward dependent configs" should refer to targets in the deps that should
477 // have their configs forwarded. 477 // have their configs forwarded.
478 bool Builder::ResolveForwardDependentConfigs(Target* target, Err* err) { 478 bool Builder::ResolveForwardDependentConfigs(Target* target, Err* err) {
479 const UniqueVector<LabelTargetPair>& configs = 479 const UniqueVector<LabelTargetPair>& configs =
480 target->forward_dependent_configs(); 480 target->forward_dependent_configs();
481 481
482 // Assume that the lists are small so that brute-force n^2 is appropriate. 482 // Assume that the lists are small so that brute-force n^2 is appropriate.
483 for (size_t config_i = 0; config_i < configs.size(); config_i++) { 483 for (size_t config_i = 0; config_i < configs.size(); config_i++) {
484 for (DepsIterator dep_iter(target, DepsIterator::LINKED_ONLY); 484 for (const auto& dep_pair : target->GetDeps(Target::DEPS_LINKED)) {
485 !dep_iter.done(); dep_iter.Advance()) { 485 if (configs[config_i].label == dep_pair.label) {
486 if (configs[config_i].label == dep_iter.label()) { 486 DCHECK(dep_pair.ptr); // Should already be resolved.
487 DCHECK(dep_iter.target()); // Should already be resolved.
488 // UniqueVector's contents are constant so uniqueness is preserved, but 487 // UniqueVector's contents are constant so uniqueness is preserved, but
489 // we want to update this pointer which doesn't change uniqueness 488 // we want to update this pointer which doesn't change uniqueness
490 // (uniqueness in this vector is determined by the label only). 489 // (uniqueness in this vector is determined by the label only).
491 const_cast<LabelTargetPair&>(configs[config_i]).ptr = dep_iter.target(); 490 const_cast<LabelTargetPair&>(configs[config_i]).ptr = dep_pair.ptr;
492 break; 491 break;
493 } 492 }
494 } 493 }
495 if (!configs[config_i].ptr) { 494 if (!configs[config_i].ptr) {
496 *err = Err(target->defined_from(), 495 *err = Err(target->defined_from(),
497 "Target in forward_dependent_configs_from was not listed in the deps", 496 "Target in forward_dependent_configs_from was not listed in the deps",
498 "This target has a forward_dependent_configs_from entry that was " 497 "This target has a forward_dependent_configs_from entry that was "
499 "not present in\nthe deps. A target can only forward things it " 498 "not present in\nthe deps. A target can only forward things it "
500 "depends on. It was forwarding:\n " + 499 "depends on. It was forwarding:\n " +
501 configs[config_i].label.GetUserVisibleName(false)); 500 configs[config_i].label.GetUserVisibleName(false));
(...skipping 30 matching lines...) Expand all
532 std::string ret; 531 std::string ret;
533 for (size_t i = 0; i < cycle.size(); i++) { 532 for (size_t i = 0; i < cycle.size(); i++) {
534 ret += " " + cycle[i]->label().GetUserVisibleName(false); 533 ret += " " + cycle[i]->label().GetUserVisibleName(false);
535 if (i != cycle.size() - 1) 534 if (i != cycle.size() - 1)
536 ret += " ->"; 535 ret += " ->";
537 ret += "\n"; 536 ret += "\n";
538 } 537 }
539 538
540 return ret; 539 return ret;
541 } 540 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698