summaryrefslogtreecommitdiffstats
path: root/src/eval_env.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval_env.h')
-rw-r--r--src/eval_env.h75
1 files changed, 51 insertions, 24 deletions
diff --git a/src/eval_env.h b/src/eval_env.h
index f3c959a..28c4d16 100644
--- a/src/eval_env.h
+++ b/src/eval_env.h
@@ -22,7 +22,7 @@ using namespace std;
#include "string_piece.h"
-struct EvalString;
+struct Rule;
/// An interface for a scope for variable (e.g. "$foo") lookups.
struct Env {
@@ -30,15 +30,62 @@ struct Env {
virtual string LookupVariable(const string& var) = 0;
};
+/// A tokenized string that contains variable references.
+/// Can be evaluated relative to an Env.
+struct EvalString {
+ string Evaluate(Env* env) const;
+
+ void Clear() { parsed_.clear(); }
+ bool empty() const { return parsed_.empty(); }
+
+ void AddText(StringPiece text);
+ void AddSpecial(StringPiece text);
+
+ /// Construct a human-readable representation of the parsed state,
+ /// for use in tests.
+ string Serialize() const;
+
+private:
+ enum TokenType { RAW, SPECIAL };
+ typedef vector<pair<string, TokenType> > TokenList;
+ TokenList parsed_;
+};
+
+/// 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 Env which contains a mapping of variables to values
/// as well as a pointer to a parent scope.
struct BindingEnv : public Env {
BindingEnv() : parent_(NULL) {}
- explicit BindingEnv(Env* parent) : parent_(parent) {}
+ explicit BindingEnv(BindingEnv* parent) : parent_(parent) {}
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,28 +98,8 @@ struct BindingEnv : public Env {
private:
map<string, string> bindings_;
- Env* parent_;
-};
-
-/// A tokenized string that contains variable references.
-/// Can be evaluated relative to an Env.
-struct EvalString {
- string Evaluate(Env* env) const;
-
- void Clear() { parsed_.clear(); }
- bool empty() const { return parsed_.empty(); }
-
- void AddText(StringPiece text);
- void AddSpecial(StringPiece text);
-
- /// Construct a human-readable representation of the parsed state,
- /// for use in tests.
- string Serialize() const;
-
-private:
- enum TokenType { RAW, SPECIAL };
- typedef vector<pair<string, TokenType> > TokenList;
- TokenList parsed_;
+ map<string, const Rule*> rules_;
+ BindingEnv* parent_;
};
#endif // NINJA_EVAL_ENV_H_