22 map<string, string>::iterator i = bindings_.find(var);
23 if (i != bindings_.end())
26 return parent_->LookupVariable(var);
35 assert(LookupRuleCurrentScope(rule->name()) == NULL);
36 rules_[rule->name()] = std::move(rule);
40 auto i = rules_.find(rule_name);
41 if (i == rules_.end())
43 return i->second.get();
47 auto i = rules_.find(rule_name);
48 if (i != rules_.end())
49 return i->second.get();
51 return parent_->LookupRule(rule_name);
60 Bindings::const_iterator i = bindings_.find(key);
61 if (i == bindings_.end())
67 auto rule = std::unique_ptr<Rule>(
new Rule(
"phony"));
78 return var ==
"command" ||
81 var ==
"description" ||
87 var ==
"rspfile_content" ||
88 var ==
"msvc_deps_prefix";
98 map<string, string>::iterator i = bindings_.find(var);
99 if (i != bindings_.end())
106 return parent_->LookupVariable(var);
112 if (parsed_.empty()) {
113 return single_token_;
117 for (TokenList::const_iterator i = parsed_.begin(); i != parsed_.end(); ++i) {
118 if (i->second == RAW)
119 result.append(i->first);
127 if (parsed_.empty()) {
128 single_token_.append(text.
begin(), text.
end());
129 }
else if (!parsed_.empty() && parsed_.back().second == RAW) {
130 parsed_.back().first.append(text.
begin(), text.
end());
132 parsed_.push_back(std::make_pair(text.
AsString(), RAW));
137 if (parsed_.empty() && !single_token_.empty()) {
141 parsed_.push_back(std::make_pair(std::move(single_token_), RAW));
143 parsed_.push_back(std::make_pair(text.
AsString(), SPECIAL));
148 if (parsed_.empty() && !single_token_.empty()) {
150 result.append(single_token_);
153 for (
const auto& pair : parsed_) {
155 if (pair.second == SPECIAL)
157 result.append(pair.first.begin(), pair.first.end());
166 if (parsed_.empty() && !single_token_.empty()) {
167 result.append(single_token_.begin(), single_token_.end());
169 for (TokenList::const_iterator i = parsed_.begin();
170 i != parsed_.end(); ++i) {
171 bool special = (i->second == SPECIAL);
174 result.append(i->first.begin(), i->first.end());
std::string LookupWithFallback(const std::string &var, const EvalString *eval, Env *env)
This is tricky.
void AddBinding(const std::string &key, const std::string &val)
const Rule * LookupRule(const std::string &rule_name)
const std::map< std::string, std::unique_ptr< const Rule > > & GetRules() const
const Rule * LookupRuleCurrentScope(const std::string &rule_name)
virtual std::string LookupVariable(const std::string &var)
void AddRule(std::unique_ptr< const Rule > rule)
An interface for a scope for variable (e.g. "$foo") lookups.
virtual std::string LookupVariable(const std::string &var)=0
A tokenized string that contains variable references.
std::string Evaluate(Env *env) const
std::string Unparse() const
void AddSpecial(StringPiece text)
std::string Serialize() const
Construct a human-readable representation of the parsed state, for use in tests.
void AddText(StringPiece text)
An invocable build command and associated metadata (description, etc.).
const EvalString * GetBinding(const std::string &key) const
void AddBinding(const std::string &key, const EvalString &val)
static std::unique_ptr< Rule > Phony()
static bool IsReservedBinding(const std::string &var)
StringPiece represents a slice of a string whose memory is managed externally.
const_iterator end() const
std::string AsString() const
Convert the slice into a full-fledged std::string, copying the data into a new string.
const_iterator begin() const