Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: tools/gn/scope.cc

Issue 2509333003: Change GN to disallow reading args defined in the same declare_args() call. (Closed)
Patch Set: update w/ review feedback Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tools/gn/functions.cc ('K') | « tools/gn/scope.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/scope.cc
diff --git a/tools/gn/scope.cc b/tools/gn/scope.cc
index fbe73f448239661b4674537f2440363daf101f15..650c64aacbd82f6c4e18e2ae4be2c344d76c9405 100644
--- a/tools/gn/scope.cc
+++ b/tools/gn/scope.cc
@@ -78,25 +78,37 @@ bool Scope::HasValues(SearchNested search_nested) const {
const Value* Scope::GetValue(const base::StringPiece& ident,
bool counts_as_used) {
+ const Scope* found_in_scope = nullptr;
+ return GetValueWithScope(ident, counts_as_used, &found_in_scope);
+}
+
+const Value* Scope::GetValueWithScope(const base::StringPiece& ident,
+ bool counts_as_used,
+ const Scope** found_in_scope) {
// First check for programmatically-provided values.
for (auto* provider : programmatic_providers_) {
const Value* v = provider->GetProgrammaticValue(ident);
- if (v)
+ if (v) {
+ *found_in_scope = nullptr;
return v;
+ }
}
RecordMap::iterator found = values_.find(ident);
if (found != values_.end()) {
if (counts_as_used)
found->second.used = true;
+ *found_in_scope = this;
return &found->second.value;
}
// Search in the parent scope.
if (const_containing_)
- return const_containing_->GetValue(ident);
- if (mutable_containing_)
- return mutable_containing_->GetValue(ident, counts_as_used);
+ return const_containing_->GetValueWithScope(ident, found_in_scope);
+ if (mutable_containing_) {
+ return mutable_containing_->GetValueWithScope(ident, counts_as_used,
+ found_in_scope);
+ }
return nullptr;
}
@@ -131,11 +143,19 @@ base::StringPiece Scope::GetStorageKey(const base::StringPiece& ident) const {
}
const Value* Scope::GetValue(const base::StringPiece& ident) const {
+ const Scope *found_in_scope = nullptr;
+ return GetValueWithScope(ident, &found_in_scope);
+}
+
+const Value* Scope::GetValueWithScope(const base::StringPiece& ident,
+ const Scope** found_in_scope) const {
RecordMap::const_iterator found = values_.find(ident);
- if (found != values_.end())
+ if (found != values_.end()) {
+ *found_in_scope = this;
return &found->second.value;
+ }
if (containing())
- return containing()->GetValue(ident);
+ return containing()->GetValueWithScope(ident, found_in_scope);
return nullptr;
}
« tools/gn/functions.cc ('K') | « tools/gn/scope.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698