summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-12-07 17:43:29 (GMT)
committerEvan Martin <martine@danga.com>2011-12-07 17:46:19 (GMT)
commit2863acbe2a3ab11c0a6d5efa93c0491cac63d72a (patch)
tree47f16ec855905ca14a88615a38223508fc0e6ddc
parent63d136fb891f365b551621220ce3dd1022c14182 (diff)
downloadNinja-2863acbe2a3ab11c0a6d5efa93c0491cac63d72a.zip
Ninja-2863acbe2a3ab11c0a6d5efa93c0491cac63d72a.tar.gz
Ninja-2863acbe2a3ab11c0a6d5efa93c0491cac63d72a.tar.bz2
make Rule::name_ private
-rw-r--r--src/build_test.cc10
-rw-r--r--src/clean.cc11
-rw-r--r--src/graph.cc2
-rw-r--r--src/graph.h7
-rw-r--r--src/graphviz.cc4
-rw-r--r--src/ninja.cc10
-rw-r--r--src/parsers_test.cc4
-rw-r--r--src/state.cc2
8 files changed, 29 insertions, 21 deletions
diff --git a/src/build_test.cc b/src/build_test.cc
index 43d5c47..cf75e04 100644
--- a/src/build_test.cc
+++ b/src/build_test.cc
@@ -233,14 +233,14 @@ bool BuildTest::CanRunMore() {
bool BuildTest::StartCommand(Edge* edge) {
assert(!last_command_);
commands_ran_.push_back(edge->EvaluateCommand());
- if (edge->rule().name_ == "cat" || edge->rule_->name_ == "cc" ||
- edge->rule().name_ == "touch") {
+ if (edge->rule().name() == "cat" || edge->rule_->name() == "cc" ||
+ edge->rule().name() == "touch") {
for (vector<Node*>::iterator out = edge->outputs_.begin();
out != edge->outputs_.end(); ++out) {
fs_.Create((*out)->path(), now_, "");
}
- } else if (edge->rule().name_ == "true" ||
- edge->rule().name_ == "fail") {
+ } else if (edge->rule().name() == "true" ||
+ edge->rule().name() == "fail") {
// Don't do anything.
} else {
printf("unknown command\n");
@@ -253,7 +253,7 @@ bool BuildTest::StartCommand(Edge* edge) {
Edge* BuildTest::WaitForCommand(bool* success, string* output) {
if (Edge* edge = last_command_) {
- if (edge->rule().name_ == "fail")
+ if (edge->rule().name() == "fail")
*success = false;
else
*success = true;
diff --git a/src/clean.cc b/src/clean.cc
index dcdff84..9a39ec9 100644
--- a/src/clean.cc
+++ b/src/clean.cc
@@ -176,13 +176,14 @@ void Cleaner::DoCleanRule(const Rule* rule) {
assert(rule);
for (vector<Edge*>::iterator e = state_->edges_.begin();
- e != state_->edges_.end();
- ++e)
- if ((*e)->rule().name_ == rule->name_)
+ e != state_->edges_.end(); ++e) {
+ if ((*e)->rule().name() == rule->name()) {
for (vector<Node*>::iterator out_node = (*e)->outputs_.begin();
- out_node != (*e)->outputs_.end();
- ++out_node)
+ out_node != (*e)->outputs_.end(); ++out_node) {
Remove((*out_node)->path());
+ }
+ }
+ }
}
int Cleaner::CleanRule(const Rule* rule) {
diff --git a/src/graph.cc b/src/graph.cc
index fdbbb0a..dcfa622 100644
--- a/src/graph.cc
+++ b/src/graph.cc
@@ -262,7 +262,7 @@ void Edge::Dump() {
for (vector<Node*>::iterator i = inputs_.begin(); i != inputs_.end(); ++i) {
printf("%s ", (*i)->path().c_str());
}
- printf("--%s-> ", rule_->name_.c_str());
+ printf("--%s-> ", rule_->name().c_str());
for (vector<Node*>::iterator i = outputs_.begin(); i != outputs_.end(); ++i) {
printf("%s ", (*i)->path().c_str());
}
diff --git a/src/graph.h b/src/graph.h
index 97b0644..e8c6c57 100644
--- a/src/graph.h
+++ b/src/graph.h
@@ -99,7 +99,14 @@ private:
struct Rule {
Rule(const string& name) : name_(name), generator_(false), restat_(false) { }
+ const string& name() const { return name_; }
+
+private:
string name_;
+
+ // TODO: make these private. But adding set/getters for each is so boring
+ // and doesn't really contribute to the readability of the code...
+public:
EvalString command_;
EvalString description_;
EvalString depfile_;
diff --git a/src/graphviz.cc b/src/graphviz.cc
index d5dbcd0..3dfa716 100644
--- a/src/graphviz.cc
+++ b/src/graphviz.cc
@@ -38,10 +38,10 @@ void GraphViz::AddTarget(Node* node) {
// Note extra space before label text -- this is cosmetic and feels
// like a graphviz bug.
printf("\"%p\" -> \"%p\" [label=\" %s\"]\n",
- edge->inputs_[0], edge->outputs_[0], edge->rule_->name_.c_str());
+ edge->inputs_[0], edge->outputs_[0], edge->rule_->name().c_str());
} else {
printf("\"%p\" [label=\"%s\", shape=ellipse]\n",
- edge, edge->rule_->name_.c_str());
+ edge, edge->rule_->name().c_str());
for (vector<Node*>::iterator out = edge->outputs_.begin();
out != edge->outputs_.end(); ++out) {
printf("\"%p\" -> \"%p\"\n", edge, *out);
diff --git a/src/ninja.cc b/src/ninja.cc
index 8535d57..25d5bfa 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -204,7 +204,7 @@ int CmdQuery(State* state, int argc, char* argv[]) {
if (node) {
printf("%s:\n", argv[i]);
if (node->in_edge()) {
- printf(" input: %s\n", node->in_edge()->rule_->name_.c_str());
+ printf(" input: %s\n", node->in_edge()->rule_->name().c_str());
for (vector<Node*>::iterator in = node->in_edge()->inputs_.begin();
in != node->in_edge()->inputs_.end(); ++in) {
printf(" %s\n", (*in)->path().c_str());
@@ -212,7 +212,7 @@ int CmdQuery(State* state, int argc, char* argv[]) {
}
for (vector<Edge*>::const_iterator edge = node->out_edges().begin();
edge != node->out_edges().end(); ++edge) {
- printf(" output: %s\n", (*edge)->rule_->name_.c_str());
+ printf(" output: %s\n", (*edge)->rule_->name().c_str());
for (vector<Node*>::iterator out = (*edge)->outputs_.begin();
out != (*edge)->outputs_.end(); ++out) {
printf(" %s\n", (*out)->path().c_str());
@@ -259,7 +259,7 @@ int CmdTargetsList(const vector<Node*>& nodes, int depth, int indent) {
printf(" ");
const char* target = (*n)->path().c_str();
if ((*n)->in_edge()) {
- printf("%s: %s\n", target, (*n)->in_edge()->rule_->name_.c_str());
+ printf("%s: %s\n", target, (*n)->in_edge()->rule_->name().c_str());
if (depth > 1 || depth <= 0)
CmdTargetsList((*n)->in_edge()->inputs_, depth - 1, indent + 1);
} else {
@@ -291,7 +291,7 @@ int CmdTargetsList(State* state, const string& rule_name) {
// Gather the outputs.
for (vector<Edge*>::iterator e = state->edges_.begin();
e != state->edges_.end(); ++e) {
- if ((*e)->rule_->name_ == rule_name) {
+ if ((*e)->rule_->name() == rule_name) {
for (vector<Node*>::iterator out_node = (*e)->outputs_.begin();
out_node != (*e)->outputs_.end(); ++out_node) {
rules.insert((*out_node)->path());
@@ -315,7 +315,7 @@ int CmdTargetsList(State* state) {
out_node != (*e)->outputs_.end(); ++out_node) {
printf("%s: %s\n",
(*out_node)->path().c_str(),
- (*e)->rule_->name_.c_str());
+ (*e)->rule_->name().c_str());
}
}
return 0;
diff --git a/src/parsers_test.cc b/src/parsers_test.cc
index 7b502f8..f23a178 100644
--- a/src/parsers_test.cc
+++ b/src/parsers_test.cc
@@ -60,7 +60,7 @@ TEST_F(ParserTest, Rules) {
ASSERT_EQ(3u, state.rules_.size());
const Rule* rule = state.rules_.begin()->second;
- EXPECT_EQ("cat", rule->name_);
+ EXPECT_EQ("cat", rule->name());
EXPECT_EQ("cat $in > $out", rule->command_.unparsed());
}
@@ -117,7 +117,7 @@ TEST_F(ParserTest, Continuation) {
ASSERT_EQ(2u, state.rules_.size());
const Rule* rule = state.rules_.begin()->second;
- EXPECT_EQ("link", rule->name_);
+ EXPECT_EQ("link", rule->name());
EXPECT_EQ("foo bar baz", rule->command_.unparsed());
}
diff --git a/src/state.cc b/src/state.cc
index 00192b0..06adf8b 100644
--- a/src/state.cc
+++ b/src/state.cc
@@ -29,7 +29,7 @@ State::State() : build_log_(NULL) {
void State::AddRule(const Rule* rule) {
assert(LookupRule(rule->name_) == NULL);
- rules_[rule->name_] = rule;
+ rules_[rule->name()] = rule;
}
const Rule* State::LookupRule(const string& rule_name) {