OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/scope.h" | 5 #include "tools/gn/scope.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "tools/gn/parse_tree.h" | 9 #include "tools/gn/parse_tree.h" |
10 #include "tools/gn/template.h" | 10 #include "tools/gn/template.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (containing()) { | 109 if (containing()) { |
110 const Value* in_containing = containing()->GetValue(ident); | 110 const Value* in_containing = containing()->GetValue(ident); |
111 if (in_containing) { | 111 if (in_containing) { |
112 // Promote to current scope. | 112 // Promote to current scope. |
113 return SetValue(ident, *in_containing, set_node); | 113 return SetValue(ident, *in_containing, set_node); |
114 } | 114 } |
115 } | 115 } |
116 return nullptr; | 116 return nullptr; |
117 } | 117 } |
118 | 118 |
| 119 base::StringPiece Scope::GetStorageKey(const base::StringPiece& ident) const { |
| 120 RecordMap::const_iterator found = values_.find(ident); |
| 121 if (found != values_.end()) |
| 122 return found->first; |
| 123 |
| 124 // Search in parent scope. |
| 125 if (containing()) |
| 126 return containing()->GetStorageKey(ident); |
| 127 return base::StringPiece(); |
| 128 } |
| 129 |
119 const Value* Scope::GetValue(const base::StringPiece& ident) const { | 130 const Value* Scope::GetValue(const base::StringPiece& ident) const { |
120 RecordMap::const_iterator found = values_.find(ident); | 131 RecordMap::const_iterator found = values_.find(ident); |
121 if (found != values_.end()) | 132 if (found != values_.end()) |
122 return &found->second.value; | 133 return &found->second.value; |
123 if (containing()) | 134 if (containing()) |
124 return containing()->GetValue(ident); | 135 return containing()->GetValue(ident); |
125 return nullptr; | 136 return nullptr; |
126 } | 137 } |
127 | 138 |
128 Value* Scope::SetValue(const base::StringPiece& ident, | 139 Value* Scope::SetValue(const base::StringPiece& ident, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 184 |
174 void Scope::MarkUsed(const base::StringPiece& ident) { | 185 void Scope::MarkUsed(const base::StringPiece& ident) { |
175 RecordMap::iterator found = values_.find(ident); | 186 RecordMap::iterator found = values_.find(ident); |
176 if (found == values_.end()) { | 187 if (found == values_.end()) { |
177 NOTREACHED(); | 188 NOTREACHED(); |
178 return; | 189 return; |
179 } | 190 } |
180 found->second.used = true; | 191 found->second.used = true; |
181 } | 192 } |
182 | 193 |
| 194 void Scope::MarkAllUsed() { |
| 195 for (auto& cur : values_) |
| 196 cur.second.used = true; |
| 197 } |
| 198 |
183 void Scope::MarkUnused(const base::StringPiece& ident) { | 199 void Scope::MarkUnused(const base::StringPiece& ident) { |
184 RecordMap::iterator found = values_.find(ident); | 200 RecordMap::iterator found = values_.find(ident); |
185 if (found == values_.end()) { | 201 if (found == values_.end()) { |
186 NOTREACHED(); | 202 NOTREACHED(); |
187 return; | 203 return; |
188 } | 204 } |
189 found->second.used = false; | 205 found->second.used = false; |
190 } | 206 } |
191 | 207 |
192 bool Scope::IsSetButUnused(const base::StringPiece& ident) const { | 208 bool Scope::IsSetButUnused(const base::StringPiece& ident) const { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 err->AppendSubErr(Err(pair.second.value, "defined here.", | 264 err->AppendSubErr(Err(pair.second.value, "defined here.", |
249 "Which would clobber the one in your current scope")); | 265 "Which would clobber the one in your current scope")); |
250 err->AppendSubErr(Err(*existing_value, "defined here.", | 266 err->AppendSubErr(Err(*existing_value, "defined here.", |
251 "Executing " + desc_string + " should not conflict with anything " | 267 "Executing " + desc_string + " should not conflict with anything " |
252 "in the current\nscope unless the values are identical.")); | 268 "in the current\nscope unless the values are identical.")); |
253 return false; | 269 return false; |
254 } | 270 } |
255 } | 271 } |
256 dest->values_[pair.first] = pair.second; | 272 dest->values_[pair.first] = pair.second; |
257 | 273 |
258 if (options.mark_used) | 274 if (options.mark_dest_used) |
259 dest->MarkUsed(pair.first); | 275 dest->MarkUsed(pair.first); |
260 } | 276 } |
261 | 277 |
262 // Target defaults are owning pointers. | 278 // Target defaults are owning pointers. |
263 for (const auto& pair : target_defaults_) { | 279 for (const auto& pair : target_defaults_) { |
264 if (!options.clobber_existing) { | 280 if (!options.clobber_existing) { |
265 if (dest->GetTargetDefaults(pair.first)) { | 281 if (dest->GetTargetDefaults(pair.first)) { |
266 // TODO(brettw) it would be nice to know the origin of a | 282 // TODO(brettw) it would be nice to know the origin of a |
267 // set_target_defaults so we can give locations for the colliding target | 283 // set_target_defaults so we can give locations for the colliding target |
268 // defaults. | 284 // defaults. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 484 } |
469 | 485 |
470 void Scope::AddProvider(ProgrammaticProvider* p) { | 486 void Scope::AddProvider(ProgrammaticProvider* p) { |
471 programmatic_providers_.insert(p); | 487 programmatic_providers_.insert(p); |
472 } | 488 } |
473 | 489 |
474 void Scope::RemoveProvider(ProgrammaticProvider* p) { | 490 void Scope::RemoveProvider(ProgrammaticProvider* p) { |
475 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); | 491 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); |
476 programmatic_providers_.erase(p); | 492 programmatic_providers_.erase(p); |
477 } | 493 } |
OLD | NEW |