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 #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 <set> | 9 #include <set> |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 // Returns NULL if there's no such value. | 81 // Returns NULL if there's no such value. |
82 // | 82 // |
83 // counts_as_used should be set if the variable is being read in a way that | 83 // counts_as_used should be set if the variable is being read in a way that |
84 // should count for unused variable checking. | 84 // should count for unused variable checking. |
85 const Value* GetValue(const base::StringPiece& ident, | 85 const Value* GetValue(const base::StringPiece& ident, |
86 bool counts_as_used); | 86 bool counts_as_used); |
87 const Value* GetValue(const base::StringPiece& ident) const; | 87 const Value* GetValue(const base::StringPiece& ident) const; |
88 | 88 |
| 89 // Returns the requested value as a mutable one if possible. If the value |
| 90 // is not found in a mutable scope, then returns null. Note that the value |
| 91 // could still exist in a const scope, so GetValue() could still return |
| 92 // non-null in this case. |
| 93 // |
| 94 // Say you have a local scope that then refers to the const root scope from |
| 95 // the master build config. You can't change the values from the master |
| 96 // build config (it's read-only so it can be read from multiple threads |
| 97 // without locking). Read-only operations would work on values from the root |
| 98 // scope, but write operations would only work on values in the derived |
| 99 // scope(s). |
| 100 // |
| 101 // Be careful when calling this. It's not normally correct to modify values, |
| 102 // but you should instead do a new Set each time. |
| 103 // |
| 104 // Consider this code: |
| 105 // a = 5 |
| 106 // { |
| 107 // a = 6 |
| 108 // } |
| 109 // The 6 should get set on the nested scope rather than modify the value |
| 110 // in the outer one. |
| 111 Value* GetMutableValue(const base::StringPiece& ident, bool counts_as_used); |
| 112 |
89 // Same as GetValue, but if the value exists in a parent scope, we'll copy | 113 // Same as GetValue, but if the value exists in a parent scope, we'll copy |
90 // it to the current scope. If the return value is non-null, the value is | 114 // it to the current scope. If the return value is non-null, the value is |
91 // guaranteed to be set in the current scope. Generatlly this will be used | 115 // guaranteed to be set in the current scope. Generatlly this will be used |
92 // if the calling code is planning on modifying the value in-place. | 116 // if the calling code is planning on modifying the value in-place. |
93 // | 117 // |
94 // Since this is used when doing read-modifies, we never count this access | 118 // Since this is used when doing read-modifies, we never count this access |
95 // as reading the variable, since we assume it will be written to. | 119 // as reading the variable, since we assume it will be written to. |
96 Value* GetValueForcedToCurrentScope(const base::StringPiece& ident, | 120 Value* GetValueForcedToCurrentScope(const base::StringPiece& ident, |
97 const ParseNode* set_node); | 121 const ParseNode* set_node); |
98 | 122 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 278 |
255 typedef std::set<ProgrammaticProvider*> ProviderSet; | 279 typedef std::set<ProgrammaticProvider*> ProviderSet; |
256 ProviderSet programmatic_providers_; | 280 ProviderSet programmatic_providers_; |
257 | 281 |
258 SourceDir source_dir_; | 282 SourceDir source_dir_; |
259 | 283 |
260 DISALLOW_COPY_AND_ASSIGN(Scope); | 284 DISALLOW_COPY_AND_ASSIGN(Scope); |
261 }; | 285 }; |
262 | 286 |
263 #endif // TOOLS_GN_SCOPE_H_ | 287 #endif // TOOLS_GN_SCOPE_H_ |
OLD | NEW |