| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 for (RecordMap::const_iterator i = values_.begin(); i != values_.end(); ++i) | 173 for (RecordMap::const_iterator i = values_.begin(); i != values_.end(); ++i) |
| 174 (*output)[i->first] = i->second.value; | 174 (*output)[i->first] = i->second.value; |
| 175 } | 175 } |
| 176 | 176 |
| 177 bool Scope::NonRecursiveMergeTo(Scope* dest, | 177 bool Scope::NonRecursiveMergeTo(Scope* dest, |
| 178 const ParseNode* node_for_err, | 178 const ParseNode* node_for_err, |
| 179 const char* desc_for_err, | 179 const char* desc_for_err, |
| 180 Err* err) const { | 180 Err* err) const { |
| 181 // Values. | 181 // Values. |
| 182 for (RecordMap::const_iterator i = values_.begin(); i != values_.end(); ++i) { | 182 for (RecordMap::const_iterator i = values_.begin(); i != values_.end(); ++i) { |
| 183 const Value& new_value = i->second.value; |
| 183 const Value* existing_value = dest->GetValue(i->first); | 184 const Value* existing_value = dest->GetValue(i->first); |
| 184 if (existing_value) { | 185 if (existing_value && new_value != *existing_value) { |
| 185 // Value present in both the source and the dest. | 186 // Value present in both the source and the dest. |
| 186 std::string desc_string(desc_for_err); | 187 std::string desc_string(desc_for_err); |
| 187 *err = Err(node_for_err, "Value collision.", | 188 *err = Err(node_for_err, "Value collision.", |
| 188 "This " + desc_string + " contains \"" + i->first.as_string() + "\""); | 189 "This " + desc_string + " contains \"" + i->first.as_string() + "\""); |
| 189 err->AppendSubErr(Err(i->second.value, "defined here.", | 190 err->AppendSubErr(Err(i->second.value, "defined here.", |
| 190 "Which would clobber the one in your current scope")); | 191 "Which would clobber the one in your current scope")); |
| 191 err->AppendSubErr(Err(*existing_value, "defined here.", | 192 err->AppendSubErr(Err(*existing_value, "defined here.", |
| 192 "Executing " + desc_string + " should not conflict with anything " | 193 "Executing " + desc_string + " should not conflict with anything " |
| 193 "in the current\nscope.")); | 194 "in the current\nscope unless the values are identical.")); |
| 194 return false; | 195 return false; |
| 195 } | 196 } |
| 196 dest->values_[i->first] = i->second; | 197 dest->values_[i->first] = i->second; |
| 197 } | 198 } |
| 198 | 199 |
| 199 // Target defaults are owning pointers. | 200 // Target defaults are owning pointers. |
| 200 for (NamedScopeMap::const_iterator i = target_defaults_.begin(); | 201 for (NamedScopeMap::const_iterator i = target_defaults_.begin(); |
| 201 i != target_defaults_.end(); ++i) { | 202 i != target_defaults_.end(); ++i) { |
| 202 if (dest->GetTargetDefaults(i->first)) { | 203 if (dest->GetTargetDefaults(i->first)) { |
| 203 // TODO(brettw) it would be nice to know the origin of a | 204 // TODO(brettw) it would be nice to know the origin of a |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 351 } |
| 351 | 352 |
| 352 void Scope::AddProvider(ProgrammaticProvider* p) { | 353 void Scope::AddProvider(ProgrammaticProvider* p) { |
| 353 programmatic_providers_.insert(p); | 354 programmatic_providers_.insert(p); |
| 354 } | 355 } |
| 355 | 356 |
| 356 void Scope::RemoveProvider(ProgrammaticProvider* p) { | 357 void Scope::RemoveProvider(ProgrammaticProvider* p) { |
| 357 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); | 358 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); |
| 358 programmatic_providers_.erase(p); | 359 programmatic_providers_.erase(p); |
| 359 } | 360 } |
| OLD | NEW |