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

Side by Side Diff: tools/gn/scope.h

Issue 2224343003: GN: Throw an error overwriting a nonempty scope. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment 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 unified diff | Download patch
OLDNEW
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 #ifndef TOOLS_GN_SCOPE_H_ 5 #ifndef TOOLS_GN_SCOPE_H_
6 #define TOOLS_GN_SCOPE_H_ 6 #define TOOLS_GN_SCOPE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 const Scope* mutable_containing() const { return mutable_containing_; } 118 const Scope* mutable_containing() const { return mutable_containing_; }
119 const Scope* const_containing() const { return const_containing_; } 119 const Scope* const_containing() const { return const_containing_; }
120 const Scope* containing() const { 120 const Scope* containing() const {
121 return mutable_containing_ ? mutable_containing_ : const_containing_; 121 return mutable_containing_ ? mutable_containing_ : const_containing_;
122 } 122 }
123 123
124 // Clears any references to containing scopes. This scope will now be 124 // Clears any references to containing scopes. This scope will now be
125 // self-sufficient. 125 // self-sufficient.
126 void DetachFromContaining(); 126 void DetachFromContaining();
127 127
128 // Returns true if the scope has any values set. This does not check other
129 // things that may be set like templates or defaults.
130 //
131 // Currently this does not search nested scopes and this will assert if you
132 // want to search nested scopes. The enum is passed so the callers are
133 // unambiguous about nested scope handling. This can be added if needed.
134 bool HasValues(SearchNested search_nested) const;
135
128 // Returns NULL if there's no such value. 136 // Returns NULL if there's no such value.
129 // 137 //
130 // counts_as_used should be set if the variable is being read in a way that 138 // counts_as_used should be set if the variable is being read in a way that
131 // should count for unused variable checking. 139 // should count for unused variable checking.
132 const Value* GetValue(const base::StringPiece& ident, 140 const Value* GetValue(const base::StringPiece& ident,
133 bool counts_as_used); 141 bool counts_as_used);
134 const Value* GetValue(const base::StringPiece& ident) const; 142 const Value* GetValue(const base::StringPiece& ident) const;
135 143
136 // If the value exists in the current scope, destrictively moves it into the
137 // return value. If it exists in a containing scope, copies it.
138 //
139 // This is for implementing modify-write operations where we want to read
140 // the existing value and plan to immediately overwrite it. If the value is
141 // in a containing scope, we never want to touch it (all writes go to the
142 // current scope), but if it's in the current scope, avoid the copy since it
143 // will be overwritten anyway.
144 //Value DestructiveMoveOut(const base::StringPiece& ident);
145
146 // Returns the requested value as a mutable one if possible. If the value 144 // Returns the requested value as a mutable one if possible. If the value
147 // is not found in a mutable scope, then returns null. Note that the value 145 // is not found in a mutable scope, then returns null. Note that the value
148 // could still exist in a const scope, so GetValue() could still return 146 // could still exist in a const scope, so GetValue() could still return
149 // non-null in this case. 147 // non-null in this case.
150 // 148 //
151 // Say you have a local scope that then refers to the const root scope from 149 // Say you have a local scope that then refers to the const root scope from
152 // the master build config. You can't change the values from the master 150 // the master build config. You can't change the values from the master
153 // build config (it's read-only so it can be read from multiple threads 151 // build config (it's read-only so it can be read from multiple threads
154 // without locking). Read-only operations would work on values from the root 152 // without locking). Read-only operations would work on values from the root
155 // scope, but write operations would only work on values in the derived 153 // scope, but write operations would only work on values in the derived
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 369
372 typedef std::set<ProgrammaticProvider*> ProviderSet; 370 typedef std::set<ProgrammaticProvider*> ProviderSet;
373 ProviderSet programmatic_providers_; 371 ProviderSet programmatic_providers_;
374 372
375 SourceDir source_dir_; 373 SourceDir source_dir_;
376 374
377 DISALLOW_COPY_AND_ASSIGN(Scope); 375 DISALLOW_COPY_AND_ASSIGN(Scope);
378 }; 376 };
379 377
380 #endif // TOOLS_GN_SCOPE_H_ 378 #endif // TOOLS_GN_SCOPE_H_
OLDNEW
« tools/gn/operators.cc ('K') | « tools/gn/operators_unittest.cc ('k') | tools/gn/scope.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698