Shinichiro Hamaji | 1d545aa | 2015-06-23 15:29:13 +0900 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 15 | // +build ignore |
| 16 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 17 | #include "dep.h" |
| 18 | |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 19 | #include <algorithm> |
Shinichiro Hamaji | 485f912 | 2015-06-26 07:06:14 +0900 | [diff] [blame] | 20 | #include <iterator> |
Dan Willemsen | b248caa | 2015-10-01 16:07:48 -0700 | [diff] [blame] | 21 | #include <map> |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 22 | #include <memory> |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 23 | #include <unordered_map> |
| 24 | #include <unordered_set> |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 25 | |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 26 | #include "eval.h" |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 27 | #include "fileutil.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 28 | #include "log.h" |
| 29 | #include "rule.h" |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 30 | #include "strutil.h" |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 31 | #include "symtab.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 32 | #include "var.h" |
| 33 | |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 34 | namespace { |
| 35 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 36 | static vector<DepNode*>* g_dep_node_pool; |
| 37 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 38 | static Symbol ReplaceSuffix(Symbol s, Symbol newsuf) { |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 39 | string r; |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 40 | AppendString(StripExt(s.str()), &r); |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 41 | r += '.'; |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 42 | AppendString(newsuf.str(), &r); |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 43 | return Intern(r); |
| 44 | } |
| 45 | |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 46 | class RuleTrie { |
| 47 | struct Entry { |
| 48 | Entry(shared_ptr<Rule> r, StringPiece s) |
| 49 | : rule(r), suffix(s) { |
| 50 | } |
| 51 | shared_ptr<Rule> rule; |
| 52 | StringPiece suffix; |
| 53 | }; |
| 54 | |
| 55 | public: |
| 56 | RuleTrie() {} |
| 57 | ~RuleTrie() { |
| 58 | for (auto& p : children_) |
| 59 | delete p.second; |
| 60 | } |
| 61 | |
| 62 | void Add(StringPiece name, shared_ptr<Rule> rule) { |
| 63 | if (name.empty() || name[0] == '%') { |
| 64 | rules_.push_back(Entry(rule, name)); |
| 65 | return; |
| 66 | } |
| 67 | const char c = name[0]; |
| 68 | auto p = children_.emplace(c, nullptr); |
| 69 | if (p.second) { |
| 70 | p.first->second = new RuleTrie(); |
| 71 | } |
| 72 | p.first->second->Add(name.substr(1), rule); |
| 73 | } |
| 74 | |
Shinichiro Hamaji | f772b17 | 2015-06-29 16:05:44 +0900 | [diff] [blame] | 75 | void Get(StringPiece name, vector<shared_ptr<Rule>>* rules) const { |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 76 | for (const Entry& ent : rules_) { |
| 77 | if ((ent.suffix.empty() && name.empty()) || |
| 78 | HasSuffix(name, ent.suffix.substr(1))) { |
| 79 | rules->push_back(ent.rule); |
| 80 | } |
| 81 | } |
Shinichiro Hamaji | f772b17 | 2015-06-29 16:05:44 +0900 | [diff] [blame] | 82 | if (name.empty()) |
| 83 | return; |
| 84 | auto found = children_.find(name[0]); |
| 85 | if (found != children_.end()) { |
| 86 | found->second->Get(name.substr(1), rules); |
| 87 | } |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | size_t size() const { |
| 91 | size_t r = rules_.size(); |
| 92 | for (const auto& c : children_) |
| 93 | r += c.second->size(); |
| 94 | return r; |
| 95 | } |
| 96 | |
| 97 | private: |
| 98 | vector<Entry> rules_; |
| 99 | unordered_map<char, RuleTrie*> children_; |
| 100 | }; |
| 101 | |
| 102 | } // namespace |
| 103 | |
Shinichiro Hamaji | 3ac2a09 | 2015-10-01 18:38:02 +0900 | [diff] [blame] | 104 | DepNode::DepNode(Symbol o, bool p, bool r) |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 105 | : output(o), |
| 106 | has_rule(false), |
Colin Cross | 5b26db3 | 2015-09-29 16:51:02 -0700 | [diff] [blame] | 107 | is_default_target(false), |
Shinichiro Hamaji | 3ac2a09 | 2015-10-01 18:38:02 +0900 | [diff] [blame] | 108 | is_phony(p), |
| 109 | is_restat(r), |
Shinichiro Hamaji | a7984ad | 2015-09-11 16:33:16 +0900 | [diff] [blame] | 110 | rule_vars(NULL), |
| 111 | output_pattern(Symbol::IsUninitialized()) { |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 112 | g_dep_node_pool->push_back(this); |
| 113 | } |
| 114 | |
| 115 | class DepBuilder { |
| 116 | public: |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 117 | DepBuilder(Evaluator* ev, |
| 118 | const vector<shared_ptr<Rule>>& rules, |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 119 | const unordered_map<Symbol, Vars*>& rule_vars) |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 120 | : ev_(ev), |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 121 | rule_vars_(rule_vars), |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 122 | implicit_rules_(new RuleTrie()), |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 123 | first_rule_(NULL) { |
| 124 | PopulateRules(rules); |
Shinichiro Hamaji | b4969af | 2015-06-28 02:06:54 +0900 | [diff] [blame] | 125 | LOG_STAT("%zu variables", ev->mutable_vars()->size()); |
| 126 | LOG_STAT("%zu explicit rules", rules_.size()); |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 127 | LOG_STAT("%zu implicit rules", implicit_rules_->size()); |
Shinichiro Hamaji | b4969af | 2015-06-28 02:06:54 +0900 | [diff] [blame] | 128 | LOG_STAT("%zu suffix rules", suffix_rules_.size()); |
Shinichiro Hamaji | d40b6fe | 2015-06-29 17:08:42 +0900 | [diff] [blame] | 129 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 130 | auto found = rules_.find(Intern(".PHONY")); |
Shinichiro Hamaji | d40b6fe | 2015-06-29 17:08:42 +0900 | [diff] [blame] | 131 | if (found != rules_.end()) { |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 132 | for (Symbol input : found->second->inputs) { |
Shinichiro Hamaji | d40b6fe | 2015-06-29 17:08:42 +0900 | [diff] [blame] | 133 | phony_.insert(input); |
| 134 | } |
| 135 | } |
Shinichiro Hamaji | 3ac2a09 | 2015-10-01 18:38:02 +0900 | [diff] [blame] | 136 | found = rules_.find(Intern(".KATI_RESTAT")); |
| 137 | if (found != rules_.end()) { |
| 138 | for (Symbol input : found->second->inputs) { |
| 139 | restat_.insert(input); |
| 140 | } |
| 141 | } |
Shinichiro Hamaji | cbe9f49 | 2015-11-30 16:39:35 +0900 | [diff] [blame^] | 142 | found = rules_.find(Intern(".SUFFIXES")); |
| 143 | if (found != rules_.end()) { |
| 144 | if (found->second->inputs.empty()) { |
| 145 | suffix_rules_.clear(); |
| 146 | } else { |
| 147 | WARN("%s:%d: kati doesn't support .SUFFIXES with prerequisites", |
| 148 | LOCF(found->second->loc)); |
| 149 | } |
| 150 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 151 | } |
| 152 | |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 153 | ~DepBuilder() { |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 154 | } |
| 155 | |
Shinichiro Hamaji | a62b02a | 2015-10-01 14:21:40 +0900 | [diff] [blame] | 156 | void Build(vector<Symbol> targets, vector<DepNode*>* nodes) { |
Colin Cross | 5b26db3 | 2015-09-29 16:51:02 -0700 | [diff] [blame] | 157 | if (!first_rule_) { |
| 158 | ERROR("*** No targets."); |
| 159 | } |
| 160 | CHECK(!first_rule_->outputs.empty()); |
Shinichiro Hamaji | 43defe0 | 2015-07-11 07:06:43 +0900 | [diff] [blame] | 161 | |
Shinichiro Hamaji | 6ff74ce | 2015-10-03 11:58:35 +0900 | [diff] [blame] | 162 | if (!g_flags.gen_all_targets && targets.empty()) { |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 163 | targets.push_back(first_rule_->outputs[0]); |
Shinichiro Hamaji | 319b649 | 2015-09-24 14:23:55 +0900 | [diff] [blame] | 164 | } |
Shinichiro Hamaji | 7223e7b | 2015-09-28 15:17:27 +0900 | [diff] [blame] | 165 | if (g_flags.gen_all_targets) { |
Shinichiro Hamaji | 6ff74ce | 2015-10-03 11:58:35 +0900 | [diff] [blame] | 166 | unordered_set<Symbol> non_root_targets; |
| 167 | for (const auto& p : rules_) { |
| 168 | for (Symbol t : p.second->inputs) |
| 169 | non_root_targets.insert(t); |
| 170 | for (Symbol t : p.second->order_only_inputs) |
| 171 | non_root_targets.insert(t); |
| 172 | } |
| 173 | |
| 174 | for (const auto& p : rules_) { |
| 175 | Symbol t = p.first; |
| 176 | if (!non_root_targets.count(t)) { |
| 177 | targets.push_back(p.first); |
| 178 | } |
| 179 | } |
Shinichiro Hamaji | 7223e7b | 2015-09-28 15:17:27 +0900 | [diff] [blame] | 180 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 181 | |
| 182 | // TODO: LogStats? |
| 183 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 184 | for (Symbol target : targets) { |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 185 | cur_rule_vars_.reset(new Vars); |
| 186 | ev_->set_current_scope(cur_rule_vars_.get()); |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 187 | DepNode* n = BuildPlan(target, Intern("")); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 188 | nodes->push_back(n); |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 189 | ev_->set_current_scope(NULL); |
| 190 | cur_rule_vars_.reset(NULL); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
| 194 | private: |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 195 | bool Exists(Symbol target) { |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 196 | auto found = rules_.find(target); |
| 197 | if (found != rules_.end()) |
| 198 | return true; |
| 199 | if (phony_.count(target)) |
| 200 | return true; |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 201 | return ::Exists(target.str()); |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 202 | } |
| 203 | |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 204 | void PopulateRules(const vector<shared_ptr<Rule>>& rules) { |
| 205 | for (shared_ptr<Rule> rule : rules) { |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 206 | if (rule->outputs.empty()) { |
| 207 | PopulateImplicitRule(rule); |
| 208 | } else { |
| 209 | PopulateExplicitRule(rule); |
| 210 | } |
| 211 | } |
Shinichiro Hamaji | 65657d9 | 2015-06-24 17:05:50 +0900 | [diff] [blame] | 212 | for (auto& p : suffix_rules_) { |
| 213 | reverse(p.second.begin(), p.second.end()); |
| 214 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 215 | } |
| 216 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 217 | bool PopulateSuffixRule(shared_ptr<Rule> rule, Symbol output) { |
| 218 | if (output.empty() || output.str()[0] != '.') |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 219 | return false; |
| 220 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 221 | const StringPiece rest = StringPiece(output.str()).substr(1); |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 222 | size_t dot_index = rest.find('.'); |
| 223 | // If there is only a single dot or the third dot, this is not a |
| 224 | // suffix rule. |
| 225 | if (dot_index == string::npos || |
| 226 | rest.substr(dot_index+1).find('.') != string::npos) { |
| 227 | return false; |
| 228 | } |
| 229 | |
| 230 | StringPiece input_suffix = rest.substr(0, dot_index); |
| 231 | StringPiece output_suffix = rest.substr(dot_index+1); |
| 232 | shared_ptr<Rule> r = make_shared<Rule>(*rule); |
| 233 | r->inputs.clear(); |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 234 | r->inputs.push_back(Intern(input_suffix)); |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 235 | r->is_suffix_rule = true; |
| 236 | suffix_rules_[output_suffix].push_back(r); |
| 237 | return true; |
| 238 | } |
| 239 | |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 240 | void ApplyOutputPattern(const Rule& r, |
| 241 | Symbol output, |
| 242 | const vector<Symbol>& inputs, |
| 243 | vector<Symbol>* out_inputs) { |
| 244 | if (inputs.empty()) |
| 245 | return; |
| 246 | if (r.is_suffix_rule) { |
| 247 | for (Symbol input : inputs) { |
| 248 | out_inputs->push_back(ReplaceSuffix(output, input)); |
| 249 | } |
| 250 | return; |
| 251 | } |
| 252 | if (r.output_patterns.empty()) { |
| 253 | copy(inputs.begin(), inputs.end(), back_inserter(*out_inputs)); |
| 254 | return; |
| 255 | } |
| 256 | CHECK(r.output_patterns.size() == 1); |
| 257 | Pattern pat(r.output_patterns[0].str()); |
| 258 | for (Symbol input : inputs) { |
| 259 | string buf; |
| 260 | pat.AppendSubst(output.str(), input.str(), &buf); |
| 261 | out_inputs->push_back(Intern(buf)); |
| 262 | } |
| 263 | } |
| 264 | |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 265 | shared_ptr<Rule> MergeRules(const Rule& old_rule, |
| 266 | const Rule& rule, |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 267 | Symbol output, |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 268 | bool is_suffix_rule) { |
| 269 | if (old_rule.is_double_colon != rule.is_double_colon) { |
| 270 | ERROR("%s:%d: *** target file `%s' has both : and :: entries.", |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 271 | LOCF(rule.loc), output.str().c_str()); |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 272 | } |
| 273 | if (!old_rule.cmds.empty() && !rule.cmds.empty() && |
| 274 | !is_suffix_rule && !rule.is_double_colon) { |
Shinichiro Hamaji | ff4584d | 2015-06-24 17:45:14 +0900 | [diff] [blame] | 275 | WARN("%s:%d: warning: overriding commands for target `%s'", |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 276 | LOCF(rule.cmd_loc()), output.str().c_str()); |
Shinichiro Hamaji | ff4584d | 2015-06-24 17:45:14 +0900 | [diff] [blame] | 277 | WARN("%s:%d: warning: ignoring old commands for target `%s'", |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 278 | LOCF(old_rule.cmd_loc()), output.str().c_str()); |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | shared_ptr<Rule> r = make_shared<Rule>(rule); |
| 282 | if (rule.is_double_colon) { |
| 283 | r->cmds.clear(); |
| 284 | for (Value* c : old_rule.cmds) |
| 285 | r->cmds.push_back(c); |
| 286 | for (Value* c : rule.cmds) |
| 287 | r->cmds.push_back(c); |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 288 | if (!rule.output_patterns.empty() && !old_rule.output_patterns.empty() && |
| 289 | rule.output_patterns != old_rule.output_patterns) { |
| 290 | ERROR("%s:%d: TODO: merging two double rules with output patterns " |
| 291 | "is not supported", LOCF(rule.loc)); |
| 292 | } |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 293 | } else if (!old_rule.cmds.empty() && rule.cmds.empty()) { |
| 294 | r->cmds = old_rule.cmds; |
| 295 | } |
Shinichiro Hamaji | 485f912 | 2015-06-26 07:06:14 +0900 | [diff] [blame] | 296 | |
Shinichiro Hamaji | 2e23e4a | 2015-06-26 07:33:16 +0900 | [diff] [blame] | 297 | // If the latter rule has a command (regardless of the commands in |
| 298 | // |old_rule|), inputs in the latter rule has a priority. |
Shinichiro Hamaji | 485f912 | 2015-06-26 07:06:14 +0900 | [diff] [blame] | 299 | if (rule.cmds.empty()) { |
| 300 | r->inputs = old_rule.inputs; |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 301 | ApplyOutputPattern(rule, output, rule.inputs, &r->inputs); |
Shinichiro Hamaji | 485f912 | 2015-06-26 07:06:14 +0900 | [diff] [blame] | 302 | r->order_only_inputs = old_rule.order_only_inputs; |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 303 | ApplyOutputPattern(rule, output, rule.order_only_inputs, |
| 304 | &r->order_only_inputs); |
| 305 | r->output_patterns = old_rule.output_patterns; |
Shinichiro Hamaji | 485f912 | 2015-06-26 07:06:14 +0900 | [diff] [blame] | 306 | } else { |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 307 | ApplyOutputPattern(old_rule, output, old_rule.inputs, &r->inputs); |
| 308 | ApplyOutputPattern(old_rule, output, old_rule.order_only_inputs, |
| 309 | &r->order_only_inputs); |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 310 | } |
Shinichiro Hamaji | af2b7c6 | 2015-10-03 11:24:39 +0900 | [diff] [blame] | 311 | r->is_default_target |= old_rule.is_default_target; |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 312 | return r; |
| 313 | } |
| 314 | |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 315 | void PopulateExplicitRule(shared_ptr<Rule> orig_rule) { |
| 316 | for (Symbol output : orig_rule->outputs) { |
| 317 | const bool is_suffix_rule = PopulateSuffixRule(orig_rule, output); |
Shinichiro Hamaji | e36dd56 | 2015-06-27 16:34:48 +0900 | [diff] [blame] | 318 | |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 319 | shared_ptr<Rule> rule = make_shared<Rule>(*orig_rule); |
Shinichiro Hamaji | e36dd56 | 2015-06-27 16:34:48 +0900 | [diff] [blame] | 320 | rule->outputs.clear(); |
| 321 | rule->outputs.push_back(output); |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 322 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 323 | auto p = rules_.insert(make_pair(output, rule)); |
| 324 | if (p.second) { |
| 325 | if (!first_rule_ && output.get(0) != '.') { |
Shinichiro Hamaji | af2b7c6 | 2015-10-03 11:24:39 +0900 | [diff] [blame] | 326 | rule->is_default_target = true; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 327 | first_rule_ = rule; |
| 328 | } |
| 329 | } else { |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 330 | p.first->second = |
| 331 | MergeRules(*p.first->second, *rule, output, is_suffix_rule); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 336 | void PopulateImplicitRule(shared_ptr<Rule> rule) { |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 337 | for (Symbol output_pattern : rule->output_patterns) { |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 338 | shared_ptr<Rule> r = make_shared<Rule>(*rule); |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 339 | r->output_patterns.clear(); |
| 340 | r->output_patterns.push_back(output_pattern); |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 341 | implicit_rules_->Add(output_pattern.str(), r); |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 342 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 343 | } |
| 344 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 345 | shared_ptr<Rule> LookupRule(Symbol o) { |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 346 | auto found = rules_.find(o); |
| 347 | if (found != rules_.end()) |
| 348 | return found->second; |
| 349 | return NULL; |
| 350 | } |
| 351 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 352 | Vars* LookupRuleVars(Symbol o) { |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 353 | auto found = rule_vars_.find(o); |
| 354 | if (found != rule_vars_.end()) |
| 355 | return found->second; |
| 356 | return NULL; |
| 357 | } |
| 358 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 359 | bool CanPickImplicitRule(shared_ptr<Rule> rule, Symbol output) { |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 360 | CHECK(rule->output_patterns.size() == 1); |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 361 | Pattern pat(rule->output_patterns[0].str()); |
| 362 | if (!pat.Match(output.str())) { |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 363 | return false; |
| 364 | } |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 365 | for (Symbol input : rule->inputs) { |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 366 | string buf; |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 367 | pat.AppendSubst(output.str(), input.str(), &buf); |
| 368 | if (!Exists(Intern(buf))) |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 369 | return false; |
| 370 | } |
| 371 | return true; |
| 372 | } |
| 373 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 374 | Vars* MergeImplicitRuleVars(Symbol output, Vars* vars) { |
Shinichiro Hamaji | dca79a3 | 2015-06-24 15:27:33 +0900 | [diff] [blame] | 375 | auto found = rule_vars_.find(output); |
| 376 | if (found == rule_vars_.end()) |
| 377 | return vars; |
| 378 | if (vars == NULL) |
| 379 | return found->second; |
| 380 | // TODO: leak. |
| 381 | Vars* r = new Vars(*found->second); |
| 382 | for (auto p : *vars) { |
| 383 | (*r)[p.first] = p.second; |
| 384 | } |
| 385 | return r; |
| 386 | } |
| 387 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 388 | bool PickRule(Symbol output, |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 389 | shared_ptr<Rule>* out_rule, Vars** out_var) { |
| 390 | shared_ptr<Rule> rule = LookupRule(output); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 391 | Vars* vars = LookupRuleVars(output); |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 392 | *out_rule = rule; |
| 393 | *out_var = vars; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 394 | if (rule) { |
| 395 | if (!rule->cmds.empty()) { |
| 396 | return true; |
| 397 | } |
| 398 | } |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 399 | |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 400 | vector<shared_ptr<Rule>> irules; |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 401 | implicit_rules_->Get(output.str(), &irules); |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 402 | for (auto iter = irules.rbegin(); iter != irules.rend(); ++iter) { |
| 403 | shared_ptr<Rule> irule = *iter; |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 404 | if (!CanPickImplicitRule(irule, output)) |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 405 | continue; |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 406 | if (rule) { |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 407 | shared_ptr<Rule> r = make_shared<Rule>(*rule); |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 408 | r->output_patterns = irule->output_patterns; |
Shinichiro Hamaji | d2c0fe1 | 2015-06-26 07:42:53 +0900 | [diff] [blame] | 409 | r->inputs.clear(); |
| 410 | r->inputs = irule->inputs; |
| 411 | copy(rule->inputs.begin(), rule->inputs.end(), |
| 412 | back_inserter(r->inputs)); |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 413 | r->cmds = irule->cmds; |
Shinichiro Hamaji | af2b7c6 | 2015-10-03 11:24:39 +0900 | [diff] [blame] | 414 | r->is_default_target |= irule->is_default_target; |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 415 | r->loc = irule->loc; |
| 416 | r->cmd_lineno = irule->cmd_lineno; |
| 417 | *out_rule = r; |
| 418 | return true; |
| 419 | } |
| 420 | if (vars) { |
Shinichiro Hamaji | dca79a3 | 2015-06-24 15:27:33 +0900 | [diff] [blame] | 421 | CHECK(irule->output_patterns.size() == 1); |
| 422 | vars = MergeImplicitRuleVars(irule->output_patterns[0], vars); |
| 423 | *out_var = vars; |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 424 | } |
| 425 | *out_rule = irule; |
| 426 | return true; |
| 427 | } |
| 428 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 429 | StringPiece output_suffix = GetExt(output.str()); |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 430 | if (output_suffix.get(0) != '.') |
| 431 | return rule.get(); |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 432 | output_suffix = output_suffix.substr(1); |
Shinichiro Hamaji | 4a71131 | 2015-06-19 14:44:20 +0900 | [diff] [blame] | 433 | |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 434 | SuffixRuleMap::const_iterator found = suffix_rules_.find(output_suffix); |
| 435 | if (found == suffix_rules_.end()) |
| 436 | return rule.get(); |
| 437 | |
| 438 | for (shared_ptr<Rule> irule : found->second) { |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 439 | CHECK(irule->inputs.size() == 1); |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 440 | Symbol input = ReplaceSuffix(output, irule->inputs[0]); |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 441 | if (!Exists(input)) |
| 442 | continue; |
| 443 | |
| 444 | if (rule) { |
| 445 | shared_ptr<Rule> r = make_shared<Rule>(*rule); |
| 446 | r->inputs.insert(r->inputs.begin(), input); |
| 447 | r->cmds = irule->cmds; |
Shinichiro Hamaji | af2b7c6 | 2015-10-03 11:24:39 +0900 | [diff] [blame] | 448 | r->is_default_target |= irule->is_default_target; |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 449 | r->loc = irule->loc; |
| 450 | r->cmd_lineno = irule->cmd_lineno; |
| 451 | *out_rule = r; |
| 452 | return true; |
| 453 | } |
| 454 | if (vars) { |
Shinichiro Hamaji | dca79a3 | 2015-06-24 15:27:33 +0900 | [diff] [blame] | 455 | CHECK(irule->outputs.size() == 1); |
| 456 | vars = MergeImplicitRuleVars(irule->outputs[0], vars); |
| 457 | *out_var = vars; |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 458 | } |
Shinichiro Hamaji | 52dbb60 | 2015-06-19 15:57:07 +0900 | [diff] [blame] | 459 | *out_rule = irule; |
| 460 | return true; |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | return rule.get(); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 464 | } |
| 465 | |
Shinichiro Hamaji | 8d50301 | 2015-07-03 16:26:15 +0900 | [diff] [blame] | 466 | DepNode* BuildPlan(Symbol output, Symbol needed_by UNUSED) { |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 467 | LOG("BuildPlan: %s for %s", |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 468 | output.c_str(), |
| 469 | needed_by.c_str()); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 470 | |
| 471 | auto found = done_.find(output); |
| 472 | if (found != done_.end()) { |
| 473 | return found->second; |
| 474 | } |
| 475 | |
Shinichiro Hamaji | 3ac2a09 | 2015-10-01 18:38:02 +0900 | [diff] [blame] | 476 | DepNode* n = new DepNode(output, |
| 477 | phony_.count(output), |
| 478 | restat_.count(output)); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 479 | done_[output] = n; |
| 480 | |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 481 | shared_ptr<Rule> rule; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 482 | Vars* vars; |
| 483 | if (!PickRule(output, &rule, &vars)) { |
| 484 | return n; |
| 485 | } |
| 486 | |
Shinichiro Hamaji | a7984ad | 2015-09-11 16:33:16 +0900 | [diff] [blame] | 487 | if (rule->output_patterns.size() >= 1) { |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 488 | if (rule->output_patterns.size() != 1) { |
| 489 | fprintf(stderr, "hmm %s\n", rule->DebugString().c_str()); |
| 490 | } |
Shinichiro Hamaji | a7984ad | 2015-09-11 16:33:16 +0900 | [diff] [blame] | 491 | CHECK(rule->output_patterns.size() == 1); |
| 492 | n->output_pattern = rule->output_patterns[0]; |
| 493 | } |
| 494 | |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 495 | vector<unique_ptr<ScopedVar>> sv; |
| 496 | if (vars) { |
| 497 | for (const auto& p : *vars) { |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 498 | Symbol name = p.first; |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 499 | RuleVar* var = reinterpret_cast<RuleVar*>(p.second); |
| 500 | CHECK(var); |
| 501 | Var* new_var = var->v(); |
| 502 | if (var->op() == AssignOp::PLUS_EQ) { |
| 503 | Var* old_var = ev_->LookupVar(name); |
| 504 | if (old_var->IsDefined()) { |
| 505 | // TODO: This would be incorrect and has a leak. |
| 506 | shared_ptr<string> s = make_shared<string>(); |
| 507 | old_var->Eval(ev_, s.get()); |
Shinichiro Hamaji | 3c785c7 | 2015-06-23 19:22:34 +0900 | [diff] [blame] | 508 | if (!s->empty()) |
| 509 | *s += ' '; |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 510 | new_var->Eval(ev_, s.get()); |
Shinichiro Hamaji | 5081c71 | 2015-08-14 16:49:20 +0900 | [diff] [blame] | 511 | new_var = new SimpleVar(*s, old_var->Origin()); |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 512 | } |
| 513 | } else if (var->op() == AssignOp::QUESTION_EQ) { |
| 514 | Var* old_var = ev_->LookupVar(name); |
| 515 | if (old_var->IsDefined()) { |
| 516 | continue; |
| 517 | } |
| 518 | } |
Shinichiro Hamaji | e978a89 | 2015-08-17 16:53:40 +0900 | [diff] [blame] | 519 | sv.emplace_back(new ScopedVar(cur_rule_vars_.get(), name, new_var)); |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 520 | } |
| 521 | } |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 522 | |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 523 | ApplyOutputPattern(*rule, output, rule->inputs, &n->actual_inputs); |
| 524 | for (Symbol input : n->actual_inputs) { |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 525 | DepNode* c = BuildPlan(input, output); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 526 | n->deps.push_back(c); |
| 527 | } |
| 528 | |
Shinichiro Hamaji | 53ffb07 | 2015-09-26 12:07:22 +0900 | [diff] [blame] | 529 | vector<Symbol> order_only_inputs; |
| 530 | ApplyOutputPattern(*rule, output, rule->order_only_inputs, |
| 531 | &order_only_inputs); |
| 532 | for (Symbol input : order_only_inputs) { |
Shinichiro Hamaji | 704e4fe | 2015-06-24 17:37:47 +0900 | [diff] [blame] | 533 | DepNode* c = BuildPlan(input, output); |
Shinichiro Hamaji | 183dbb9 | 2015-07-06 17:21:39 +0900 | [diff] [blame] | 534 | n->order_onlys.push_back(c); |
Shinichiro Hamaji | 704e4fe | 2015-06-24 17:37:47 +0900 | [diff] [blame] | 535 | } |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 536 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 537 | n->has_rule = true; |
| 538 | n->cmds = rule->cmds; |
Colin Cross | 5b26db3 | 2015-09-29 16:51:02 -0700 | [diff] [blame] | 539 | n->is_default_target = rule->is_default_target; |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 540 | if (cur_rule_vars_->empty()) { |
| 541 | n->rule_vars = NULL; |
| 542 | } else { |
| 543 | n->rule_vars = new Vars; |
| 544 | for (auto p : *cur_rule_vars_) { |
| 545 | n->rule_vars->insert(p); |
| 546 | } |
| 547 | } |
| 548 | n->loc = rule->loc; |
| 549 | if (!rule->cmds.empty() && rule->cmd_lineno) |
| 550 | n->loc.lineno = rule->cmd_lineno; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 551 | |
| 552 | return n; |
| 553 | } |
| 554 | |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 555 | Evaluator* ev_; |
Dan Willemsen | b248caa | 2015-10-01 16:07:48 -0700 | [diff] [blame] | 556 | map<Symbol, shared_ptr<Rule>> rules_; |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 557 | const unordered_map<Symbol, Vars*>& rule_vars_; |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 558 | unique_ptr<Vars> cur_rule_vars_; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 559 | |
Shinichiro Hamaji | 2a04789 | 2015-06-29 13:56:41 +0900 | [diff] [blame] | 560 | unique_ptr<RuleTrie> implicit_rules_; |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 561 | typedef unordered_map<StringPiece, vector<shared_ptr<Rule>>> SuffixRuleMap; |
| 562 | SuffixRuleMap suffix_rules_; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 563 | |
Shinichiro Hamaji | 0562c30 | 2015-06-19 15:30:49 +0900 | [diff] [blame] | 564 | shared_ptr<Rule> first_rule_; |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 565 | unordered_map<Symbol, DepNode*> done_; |
| 566 | unordered_set<Symbol> phony_; |
Shinichiro Hamaji | 3ac2a09 | 2015-10-01 18:38:02 +0900 | [diff] [blame] | 567 | unordered_set<Symbol> restat_; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 568 | }; |
| 569 | |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 570 | void MakeDep(Evaluator* ev, |
| 571 | const vector<shared_ptr<Rule>>& rules, |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 572 | const unordered_map<Symbol, Vars*>& rule_vars, |
| 573 | const vector<Symbol>& targets, |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 574 | vector<DepNode*>* nodes) { |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 575 | DepBuilder db(ev, rules, rule_vars); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 576 | db.Build(targets, nodes); |
| 577 | } |
| 578 | |
| 579 | void InitDepNodePool() { |
| 580 | g_dep_node_pool = new vector<DepNode*>; |
| 581 | } |
| 582 | |
| 583 | void QuitDepNodePool() { |
| 584 | for (DepNode* n : *g_dep_node_pool) |
| 585 | delete n; |
| 586 | delete g_dep_node_pool; |
| 587 | } |