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 #include "tools/gn/scope.h" | 5 #include "tools/gn/scope.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "tools/gn/parse_tree.h" | 9 #include "tools/gn/parse_tree.h" |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 // Search in the parent scope. | 63 // Search in the parent scope. |
64 if (const_containing_) | 64 if (const_containing_) |
65 return const_containing_->GetValue(ident); | 65 return const_containing_->GetValue(ident); |
66 if (mutable_containing_) | 66 if (mutable_containing_) |
67 return mutable_containing_->GetValue(ident, counts_as_used); | 67 return mutable_containing_->GetValue(ident, counts_as_used); |
68 return NULL; | 68 return NULL; |
69 } | 69 } |
70 | 70 |
| 71 Value* Scope::GetMutableValue(const base::StringPiece& ident, |
| 72 bool counts_as_used) { |
| 73 // Don't do programatic values, which are not mutable. |
| 74 RecordMap::iterator found = values_.find(ident); |
| 75 if (found != values_.end()) { |
| 76 if (counts_as_used) |
| 77 found->second.used = true; |
| 78 return &found->second.value; |
| 79 } |
| 80 |
| 81 // Search in the parent mutable scope, but not const one. |
| 82 if (mutable_containing_) |
| 83 return mutable_containing_->GetMutableValue(ident, counts_as_used); |
| 84 return NULL; |
| 85 } |
| 86 |
71 Value* Scope::GetValueForcedToCurrentScope(const base::StringPiece& ident, | 87 Value* Scope::GetValueForcedToCurrentScope(const base::StringPiece& ident, |
72 const ParseNode* set_node) { | 88 const ParseNode* set_node) { |
73 RecordMap::iterator found = values_.find(ident); | 89 RecordMap::iterator found = values_.find(ident); |
74 if (found != values_.end()) | 90 if (found != values_.end()) |
75 return &found->second.value; // Already have in the current scope. | 91 return &found->second.value; // Already have in the current scope. |
76 | 92 |
77 // Search in the parent scope. | 93 // Search in the parent scope. |
78 if (containing()) { | 94 if (containing()) { |
79 const Value* in_containing = containing()->GetValue(ident); | 95 const Value* in_containing = containing()->GetValue(ident); |
80 if (in_containing) { | 96 if (in_containing) { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 367 } |
352 | 368 |
353 void Scope::AddProvider(ProgrammaticProvider* p) { | 369 void Scope::AddProvider(ProgrammaticProvider* p) { |
354 programmatic_providers_.insert(p); | 370 programmatic_providers_.insert(p); |
355 } | 371 } |
356 | 372 |
357 void Scope::RemoveProvider(ProgrammaticProvider* p) { | 373 void Scope::RemoveProvider(ProgrammaticProvider* p) { |
358 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); | 374 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); |
359 programmatic_providers_.erase(p); | 375 programmatic_providers_.erase(p); |
360 } | 376 } |
OLD | NEW |