| 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 <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 explicit Scope(const Settings* settings); | 105 explicit Scope(const Settings* settings); |
| 106 | 106 |
| 107 // Creates a dependent scope. | 107 // Creates a dependent scope. |
| 108 explicit Scope(Scope* parent); | 108 explicit Scope(Scope* parent); |
| 109 explicit Scope(const Scope* parent); | 109 explicit Scope(const Scope* parent); |
| 110 | 110 |
| 111 ~Scope(); | 111 ~Scope(); |
| 112 | 112 |
| 113 const Settings* settings() const { return settings_; } | 113 const Settings* settings() const { return settings_; } |
| 114 | 114 |
| 115 // See the const_/mutable_containing_ var declaraions below. Yes, it's a | 115 // See the const_/mutable_containing_ var declarations below. Yes, it's a |
| 116 // bit weird that we can have a const pointer to the "mutable" one. | 116 // bit weird that we can have a const pointer to the "mutable" one. |
| 117 Scope* mutable_containing() { return mutable_containing_; } | 117 Scope* mutable_containing() { return mutable_containing_; } |
| 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 | 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. | 129 // things that may be set like templates or defaults. |
| 130 // | 130 // |
| 131 // Currently this does not search nested scopes and this will assert if you | 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 | 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. | 133 // unambiguous about nested scope handling. This can be added if needed. |
| 134 bool HasValues(SearchNested search_nested) const; | 134 bool HasValues(SearchNested search_nested) const; |
| 135 | 135 |
| 136 // Returns NULL if there's no such value. | 136 // Returns NULL if there's no such value. |
| 137 // | 137 // |
| 138 // 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 |
| 139 // should count for unused variable checking. | 139 // should count for unused variable checking. |
| 140 // |
| 141 // found_in_scope is set to the scope that contains the definition of the |
| 142 // ident. If the value was provided programmatically (like host_cpu), |
| 143 // found_in_scope will be set to null. |
| 140 const Value* GetValue(const base::StringPiece& ident, | 144 const Value* GetValue(const base::StringPiece& ident, |
| 141 bool counts_as_used); | 145 bool counts_as_used); |
| 142 const Value* GetValue(const base::StringPiece& ident) const; | 146 const Value* GetValue(const base::StringPiece& ident) const; |
| 147 const Value* GetValueWithScope(const base::StringPiece& ident, |
| 148 const Scope** found_in_scope) const; |
| 149 const Value* GetValueWithScope(const base::StringPiece& ident, |
| 150 bool counts_as_used, |
| 151 const Scope** found_in_scope); |
| 143 | 152 |
| 144 // Returns the requested value as a mutable one if possible. If the value | 153 // Returns the requested value as a mutable one if possible. If the value |
| 145 // is not found in a mutable scope, then returns null. Note that the value | 154 // is not found in a mutable scope, then returns null. Note that the value |
| 146 // could still exist in a const scope, so GetValue() could still return | 155 // could still exist in a const scope, so GetValue() could still return |
| 147 // non-null in this case. | 156 // non-null in this case. |
| 148 // | 157 // |
| 149 // Say you have a local scope that then refers to the const root scope from | 158 // Say you have a local scope that then refers to the const root scope from |
| 150 // the master build config. You can't change the values from the master | 159 // the master build config. You can't change the values from the master |
| 151 // build config (it's read-only so it can be read from multiple threads | 160 // build config (it's read-only so it can be read from multiple threads |
| 152 // without locking). Read-only operations would work on values from the root | 161 // without locking). Read-only operations would work on values from the root |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 378 |
| 370 typedef std::set<ProgrammaticProvider*> ProviderSet; | 379 typedef std::set<ProgrammaticProvider*> ProviderSet; |
| 371 ProviderSet programmatic_providers_; | 380 ProviderSet programmatic_providers_; |
| 372 | 381 |
| 373 SourceDir source_dir_; | 382 SourceDir source_dir_; |
| 374 | 383 |
| 375 DISALLOW_COPY_AND_ASSIGN(Scope); | 384 DISALLOW_COPY_AND_ASSIGN(Scope); |
| 376 }; | 385 }; |
| 377 | 386 |
| 378 #endif // TOOLS_GN_SCOPE_H_ | 387 #endif // TOOLS_GN_SCOPE_H_ |
| OLD | NEW |