| 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 #include "tools/gn/template.h" | 10 #include "tools/gn/template.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // FLags set in the mode_flags_ of a scope. If a bit is set, it applies | 14 // FLags set in the mode_flags_ of a scope. If a bit is set, it applies |
| 15 // recursively to all dependent scopes. | 15 // recursively to all dependent scopes. |
| 16 const unsigned kProcessingBuildConfigFlag = 1; | 16 const unsigned kProcessingBuildConfigFlag = 1; |
| 17 const unsigned kProcessingImportFlag = 2; | 17 const unsigned kProcessingImportFlag = 2; |
| 18 | 18 |
| 19 // Returns true if this variable name should be considered private. Private | 19 // Returns true if this variable name should be considered private. Private |
| 20 // values start with an underscore, and are not imported from "gni" files | 20 // values start with an underscore, and are not imported from "gni" files |
| 21 // when processing an import. | 21 // when processing an import. |
| 22 bool IsPrivateVar(const base::StringPiece& name) { | 22 bool IsPrivateVar(const base::StringPiece& name) { |
| 23 return name.empty() || name[0] == '_'; | 23 return name.empty() || name[0] == '_'; |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 // Defaults to all false, which are the things least likely to cause errors. |
| 29 Scope::MergeOptions::MergeOptions() |
| 30 : clobber_existing(false), |
| 31 skip_private_vars(false), |
| 32 mark_dest_used(false) {} |
| 33 |
| 34 Scope::MergeOptions::~MergeOptions() {} |
| 28 | 35 |
| 29 Scope::ProgrammaticProvider::~ProgrammaticProvider() { | 36 Scope::ProgrammaticProvider::~ProgrammaticProvider() { |
| 30 scope_->RemoveProvider(this); | 37 scope_->RemoveProvider(this); |
| 31 } | 38 } |
| 32 | 39 |
| 33 Scope::Scope(const Settings* settings) | 40 Scope::Scope(const Settings* settings) |
| 34 : const_containing_(nullptr), | 41 : const_containing_(nullptr), |
| 35 mutable_containing_(nullptr), | 42 mutable_containing_(nullptr), |
| 36 settings_(settings), | 43 settings_(settings), |
| 37 mode_flags_(0), | 44 mode_flags_(0), |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 251 |
| 245 bool Scope::NonRecursiveMergeTo(Scope* dest, | 252 bool Scope::NonRecursiveMergeTo(Scope* dest, |
| 246 const MergeOptions& options, | 253 const MergeOptions& options, |
| 247 const ParseNode* node_for_err, | 254 const ParseNode* node_for_err, |
| 248 const char* desc_for_err, | 255 const char* desc_for_err, |
| 249 Err* err) const { | 256 Err* err) const { |
| 250 // Values. | 257 // Values. |
| 251 for (const auto& pair : values_) { | 258 for (const auto& pair : values_) { |
| 252 if (options.skip_private_vars && IsPrivateVar(pair.first)) | 259 if (options.skip_private_vars && IsPrivateVar(pair.first)) |
| 253 continue; // Skip this private var. | 260 continue; // Skip this private var. |
| 261 if (!options.excluded_values.empty() && |
| 262 options.excluded_values.find(pair.first.as_string()) != |
| 263 options.excluded_values.end()) { |
| 264 continue; // Skip this excluded value. |
| 265 } |
| 254 | 266 |
| 255 const Value& new_value = pair.second.value; | 267 const Value& new_value = pair.second.value; |
| 256 if (!options.clobber_existing) { | 268 if (!options.clobber_existing) { |
| 257 const Value* existing_value = dest->GetValue(pair.first); | 269 const Value* existing_value = dest->GetValue(pair.first); |
| 258 if (existing_value && new_value != *existing_value) { | 270 if (existing_value && new_value != *existing_value) { |
| 259 // Value present in both the source and the dest. | 271 // Value present in both the source and the dest. |
| 260 std::string desc_string(desc_for_err); | 272 std::string desc_string(desc_for_err); |
| 261 *err = Err(node_for_err, "Value collision.", | 273 *err = Err(node_for_err, "Value collision.", |
| 262 "This " + desc_string + " contains \"" + pair.first.as_string() + | 274 "This " + desc_string + " contains \"" + pair.first.as_string() + |
| 263 "\""); | 275 "\""); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 } | 496 } |
| 485 | 497 |
| 486 void Scope::AddProvider(ProgrammaticProvider* p) { | 498 void Scope::AddProvider(ProgrammaticProvider* p) { |
| 487 programmatic_providers_.insert(p); | 499 programmatic_providers_.insert(p); |
| 488 } | 500 } |
| 489 | 501 |
| 490 void Scope::RemoveProvider(ProgrammaticProvider* p) { | 502 void Scope::RemoveProvider(ProgrammaticProvider* p) { |
| 491 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); | 503 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); |
| 492 programmatic_providers_.erase(p); | 504 programmatic_providers_.erase(p); |
| 493 } | 505 } |
| OLD | NEW |