summaryrefslogtreecommitdiffstats
path: root/src/eval_env.h
diff options
context:
space:
mode:
authorMohamed Bamakhrama <mohamed.bamakhrama@intel.com>2015-03-01 23:57:33 (GMT)
committerMohamed Bamakhrama <mohamed.bamakhrama@intel.com>2015-03-01 23:57:33 (GMT)
commitf8f293730de2e12f6575c5d890a16504340f75fe (patch)
treef4544bb3ab1fea478c57a2892616a5761c5769f6 /src/eval_env.h
parentc406d1c8adfedc1982e2c08ab95d581f65eb65de (diff)
downloadNinja-f8f293730de2e12f6575c5d890a16504340f75fe.zip
Ninja-f8f293730de2e12f6575c5d890a16504340f75fe.tar.gz
Ninja-f8f293730de2e12f6575c5d890a16504340f75fe.tar.bz2
Allow scoping rules through subninja
Ninja didn't support scoping rules through subninja and assumed a unique rule name in the whole namespace. With this change, this behavior is changed to allow scoping rules. Two rules can have the same name if they belong to two different scopes. However, two rules can NOT have the same name in the same scope.
Diffstat (limited to 'src/eval_env.h')
-rw-r--r--src/eval_env.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/eval_env.h b/src/eval_env.h
index f3c959a..46ea131 100644
--- a/src/eval_env.h
+++ b/src/eval_env.h
@@ -24,10 +24,32 @@ using namespace std;
struct EvalString;
+/// An invokable build command and associated metadata (description, etc.).
+struct Rule {
+ explicit Rule(const string& name) : name_(name) {}
+
+ const string& name() const { return name_; }
+
+ typedef map<string, EvalString> Bindings;
+ void AddBinding(const string& key, const EvalString& val);
+
+ static bool IsReservedBinding(const string& var);
+
+ const EvalString* GetBinding(const string& key) const;
+
+ private:
+ // Allow the parsers to reach into this object and fill out its fields.
+ friend struct ManifestParser;
+
+ string name_;
+ map<string, EvalString> bindings_;
+};
+
/// An interface for a scope for variable (e.g. "$foo") lookups.
struct Env {
virtual ~Env() {}
virtual string LookupVariable(const string& var) = 0;
+ virtual const Rule* LookupRule(const string& rule_name) = 0;
};
/// An Env which contains a mapping of variables to values
@@ -39,6 +61,11 @@ struct BindingEnv : public Env {
virtual ~BindingEnv() {}
virtual string LookupVariable(const string& var);
+ void AddRule(const Rule* rule);
+ const Rule* LookupRule(const string& rule_name);
+ const Rule* LookupRuleCurrentScope(const string& rule_name);
+ const map<string, const Rule*> GetRules() const;
+
void AddBinding(const string& key, const string& val);
/// This is tricky. Edges want lookup scope to go in this order:
@@ -51,6 +78,7 @@ struct BindingEnv : public Env {
private:
map<string, string> bindings_;
+ map<string, const Rule*> rules_;
Env* parent_;
};