From d58d918bafb26af9fd0c65cd61058ad29c5d2f4b Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Wed, 7 Dec 2011 09:38:10 -0800 Subject: make Node::out_edges_ private --- src/build.cc | 8 ++++---- src/graph.cc | 2 +- src/graph.h | 7 ++++--- src/ninja.cc | 8 ++++---- src/state.cc | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/build.cc b/src/build.cc index 3b478fa..a6d8bf1 100644 --- a/src/build.cc +++ b/src/build.cc @@ -286,8 +286,8 @@ void Plan::EdgeFinished(Edge* edge) { void Plan::NodeFinished(Node* node) { // See if we we want any edges from this node. - for (vector::iterator i = node->out_edges_.begin(); - i != node->out_edges_.end(); ++i) { + for (vector::const_iterator i = node->out_edges().begin(); + i != node->out_edges().end(); ++i) { map::iterator want_i = want_.find(*i); if (want_i == want_.end()) continue; @@ -308,8 +308,8 @@ void Plan::NodeFinished(Node* node) { void Plan::CleanNode(BuildLog* build_log, Node* node) { node->set_dirty(false); - for (vector::iterator ei = node->out_edges_.begin(); - ei != node->out_edges_.end(); ++ei) { + for (vector::const_iterator ei = node->out_edges().begin(); + ei != node->out_edges().end(); ++ei) { // Don't process edges that we don't actually want. map::iterator want_i = want_.find(*ei); if (want_i == want_.end() || !want_i->second) diff --git a/src/graph.cc b/src/graph.cc index 15df856..fdbbb0a 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -234,7 +234,7 @@ bool Edge::LoadDepFile(State* state, DiskInterface* disk_interface, Node* node = state->GetNode(path); *implicit_dep = node; - node->out_edges_.push_back(this); + node->AddOutEdge(this); // If we don't have a edge that generates this input already, // create one; this makes us not abort if the input is missing, diff --git a/src/graph.h b/src/graph.h index b6f5139..6756417 100644 --- a/src/graph.h +++ b/src/graph.h @@ -71,6 +71,9 @@ struct Node { Edge* in_edge() const { return in_edge_; } void set_in_edge(Edge* edge) { in_edge_ = edge; } + const vector& out_edges() const { return out_edges_; } + void AddOutEdge(Edge* edge) { out_edges_.push_back(edge); } + private: string path_; /// Possible values of mtime_: @@ -88,9 +91,7 @@ private: /// known edge to produce it. Edge* in_edge_; - // TODO: make these private as well. But don't just blindly add - // setters/getters, instead pay attention to the proper API. -public: + /// All Edges that use this Node as an input. vector out_edges_; }; diff --git a/src/ninja.cc b/src/ninja.cc index 1024401..8535d57 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -151,11 +151,11 @@ bool CollectTargetsFromArgs(State* state, int argc, char* argv[], Node* node = state->LookupNode(path); if (node) { if (first_dependent) { - if (node->out_edges_.empty()) { + if (node->out_edges().empty()) { *err = "'" + path + "' has no out edge"; return false; } - Edge* edge = node->out_edges_[0]; + Edge* edge = node->out_edges()[0]; if (edge->outputs_.empty()) { edge->Dump(); Fatal("edge has no outputs"); @@ -210,8 +210,8 @@ int CmdQuery(State* state, int argc, char* argv[]) { printf(" %s\n", (*in)->path().c_str()); } } - for (vector::iterator edge = node->out_edges_.begin(); - edge != node->out_edges_.end(); ++edge) { + for (vector::const_iterator edge = node->out_edges().begin(); + edge != node->out_edges().end(); ++edge) { printf(" output: %s\n", (*edge)->rule_->name_.c_str()); for (vector::iterator out = (*edge)->outputs_.begin(); out != (*edge)->outputs_.end(); ++out) { diff --git a/src/state.cc b/src/state.cc index 930c361..00192b0 100644 --- a/src/state.cc +++ b/src/state.cc @@ -83,7 +83,7 @@ Node* State::SpellcheckNode(const string& path) { void State::AddIn(Edge* edge, const string& path) { Node* node = GetNode(path); edge->inputs_.push_back(node); - node->out_edges_.push_back(edge); + node->AddOutEdge(edge); } void State::AddOut(Edge* edge, const string& path) { @@ -112,7 +112,7 @@ vector State::RootNodes(string* err) { for (vector::iterator e = edges_.begin(); e != edges_.end(); ++e) { for (vector::iterator out = (*e)->outputs_.begin(); out != (*e)->outputs_.end(); ++out) { - if ((*out)->out_edges_.empty()) + if ((*out)->out_edges().empty()) root_nodes.push_back(*out); } } -- cgit v0.12