From 8775c4d1e3630230dcea202f2d1647e56a81c20f Mon Sep 17 00:00:00 2001 From: Robert Iannucci Date: Mon, 1 Oct 2012 13:51:00 -0700 Subject: Pull out base changes to state --- src/state.cc | 17 ++++++++++++++++- src/state.h | 25 ++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/state.cc b/src/state.cc index 4c7168b..0697e48 100644 --- a/src/state.cc +++ b/src/state.cc @@ -22,10 +22,12 @@ #include "metrics.h" #include "util.h" +const Pool State::kDefaultPool("", 0); const Rule State::kPhonyRule("phony"); State::State() { AddRule(&kPhonyRule); + AddPool(&kDefaultPool); } void State::AddRule(const Rule* rule) { @@ -40,7 +42,20 @@ const Rule* State::LookupRule(const string& rule_name) { return i->second; } -Edge* State::AddEdge(const Rule* rule) { +void State::AddPool(const Pool* pool) { + assert(LookupPool(pool->name()) == NULL); + pools_[pool->name()] = pool; +} + +const Pool* State::LookupPool(const string& pool_name) { + map::iterator i = pools_.find(pool_name); + if (i == pools_.end()) + return NULL; + return i->second; +} + +Edge* State::AddEdge(const Rule* rule, const Pool* pool) { + // FIXME(iannucci): do something with pool Edge* edge = new Edge(); edge->rule_ = rule; edge->env_ = &bindings_; diff --git a/src/state.h b/src/state.h index 026acf3..38fc74f 100644 --- a/src/state.h +++ b/src/state.h @@ -27,16 +27,36 @@ struct Edge; struct Node; struct Rule; +/// A pool for delayed edges +struct Pool { + explicit Pool(const string& name, int depth) + : name_(name), depth_(depth) { } + + // A depth of 0 is infinite + bool isValid() const { return depth_ >= 0; } + int depth() const { return depth_; } + string name() const { return name_; } + +private: + string name_; + + int depth_; +}; + /// Global state (file status, loaded rules) for a single run. struct State { static const Rule kPhonyRule; + static const Pool kDefaultPool; State(); void AddRule(const Rule* rule); const Rule* LookupRule(const string& rule_name); - Edge* AddEdge(const Rule* rule); + void AddPool(const Pool* pool); + const Pool* LookupPool(const string& pool_name); + + Edge* AddEdge(const Rule* rule, const Pool* pool); Node* GetNode(StringPiece path); Node* LookupNode(StringPiece path); @@ -65,6 +85,9 @@ struct State { /// All the rules used in the graph. map rules_; + /// All the pools used in the graph. + map pools_; + /// All the edges of the graph. vector edges_; -- cgit v0.12