summaryrefslogtreecommitdiffstats
path: root/src/eval_env.h
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2010-12-05 00:09:50 (GMT)
committerEvan Martin <martine@danga.com>2010-12-05 00:09:50 (GMT)
commit42d237e7841679b27cd5dcae82d143d86a87a807 (patch)
tree253b0cf88ecf3b0404146a7c7945dd4c660afa04 /src/eval_env.h
parentd0025e234cf3fc0a13f45d179880578285609b59 (diff)
downloadNinja-42d237e7841679b27cd5dcae82d143d86a87a807.zip
Ninja-42d237e7841679b27cd5dcae82d143d86a87a807.tar.gz
Ninja-42d237e7841679b27cd5dcae82d143d86a87a807.tar.bz2
move src into subdir
Diffstat (limited to 'src/eval_env.h')
-rw-r--r--src/eval_env.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/eval_env.h b/src/eval_env.h
new file mode 100644
index 0000000..a630e7a
--- /dev/null
+++ b/src/eval_env.h
@@ -0,0 +1,43 @@
+#ifndef NINJA_EVAL_ENV_H_
+#define NINJA_EVAL_ENV_H_
+
+// A scope for variable lookups.
+struct Env {
+ virtual string LookupVariable(const string& var) = 0;
+};
+
+// A standard scope, which contains a mapping of variables to values
+// as well as a pointer to a parent scope.
+struct BindingEnv : public Env {
+ virtual string LookupVariable(const string& var) {
+ map<string, string>::iterator i = bindings_.find(var);
+ if (i != bindings_.end())
+ return i->second;
+ if (parent_)
+ return parent_->LookupVariable(var);
+ return "";
+ }
+ void AddBinding(const string& key, const string& val) {
+ bindings_[key] = val;
+ }
+
+ map<string, string> bindings_;
+ Env* parent_;
+};
+
+// A tokenized string that contains variable references.
+// Can be evaluated relative to an Env.
+struct EvalString {
+ bool Parse(const string& input, string* err);
+ string Evaluate(Env* env) const;
+
+ const string& unparsed() const { return unparsed_; }
+ const bool empty() const { return unparsed_.empty(); }
+
+ string unparsed_;
+ enum TokenType { RAW, SPECIAL };
+ typedef vector<pair<string, TokenType> > TokenList;
+ TokenList parsed_;
+};
+
+#endif // NINJA_EVAL_ENV_H_