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

Unified Diff: tools/gn/scope.cc

Issue 2187523003: Allow creation and modification of scopes in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 4 months 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
« no previous file with comments | « tools/gn/scope.h ('k') | tools/gn/scope_unittest.cc » ('j') | 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 8e9230d84111d66ee358a20befabe822f7df2894..7e7c201bbef918100225206b6ae107a6adc67f36 100644
--- a/tools/gn/scope.cc
+++ b/tools/gn/scope.cc
@@ -66,6 +66,11 @@ Scope::Scope(const Scope* parent)
Scope::~Scope() {
}
+void Scope::DetachFromContaining() {
+ const_containing_ = nullptr;
+ mutable_containing_ = nullptr;
+}
+
const Value* Scope::GetValue(const base::StringPiece& ident,
bool counts_as_used) {
// First check for programmatically-provided values.
@@ -91,6 +96,7 @@ const Value* Scope::GetValue(const base::StringPiece& ident,
}
Value* Scope::GetMutableValue(const base::StringPiece& ident,
+ SearchNested search_mode,
bool counts_as_used) {
// Don't do programmatic values, which are not mutable.
RecordMap::iterator found = values_.find(ident);
@@ -100,25 +106,10 @@ Value* Scope::GetMutableValue(const base::StringPiece& ident,
return &found->second.value;
}
- // Search in the parent mutable scope, but not const one.
- if (mutable_containing_)
- return mutable_containing_->GetMutableValue(ident, counts_as_used);
- return nullptr;
-}
-
-Value* Scope::GetValueForcedToCurrentScope(const base::StringPiece& ident,
- const ParseNode* set_node) {
- RecordMap::iterator found = values_.find(ident);
- if (found != values_.end())
- return &found->second.value; // Already have in the current scope.
-
- // Search in the parent scope.
- if (containing()) {
- const Value* in_containing = containing()->GetValue(ident);
- if (in_containing) {
- // Promote to current scope.
- return SetValue(ident, *in_containing, set_node);
- }
+ // Search in the parent mutable scope if requested, but not const one.
+ if (search_mode == SEARCH_NESTED && mutable_containing_) {
+ return mutable_containing_->GetMutableValue(
+ ident, Scope::SEARCH_NESTED, counts_as_used);
}
return nullptr;
}
@@ -144,10 +135,10 @@ const Value* Scope::GetValue(const base::StringPiece& ident) const {
}
Value* Scope::SetValue(const base::StringPiece& ident,
- const Value& v,
+ Value v,
const ParseNode* set_node) {
Record& r = values_[ident]; // Clears any existing value.
- r.value = v;
+ r.value = std::move(v);
r.value.set_origin(set_node);
return &r.value;
}
« no previous file with comments | « tools/gn/scope.h ('k') | tools/gn/scope_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698