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 } // namespace | 19 } // namespace |
20 | 20 |
21 Scope::Scope(const Settings* settings) | 21 Scope::Scope(const Settings* settings) |
22 : const_containing_(NULL), | 22 : const_containing_(NULL), |
23 mutable_containing_(NULL), | 23 mutable_containing_(NULL), |
24 settings_(settings), | 24 settings_(settings), |
25 mode_flags_(0) { | 25 mode_flags_(0), |
| 26 item_collector_(NULL) { |
26 } | 27 } |
27 | 28 |
28 Scope::Scope(Scope* parent) | 29 Scope::Scope(Scope* parent) |
29 : const_containing_(NULL), | 30 : const_containing_(NULL), |
30 mutable_containing_(parent), | 31 mutable_containing_(parent), |
31 settings_(parent->settings()), | 32 settings_(parent->settings()), |
32 mode_flags_(0) { | 33 mode_flags_(0), |
| 34 item_collector_(NULL) { |
33 } | 35 } |
34 | 36 |
35 Scope::Scope(const Scope* parent) | 37 Scope::Scope(const Scope* parent) |
36 : const_containing_(parent), | 38 : const_containing_(parent), |
37 mutable_containing_(NULL), | 39 mutable_containing_(NULL), |
38 settings_(parent->settings()), | 40 settings_(parent->settings()), |
39 mode_flags_(0) { | 41 mode_flags_(0), |
| 42 item_collector_(NULL) { |
40 } | 43 } |
41 | 44 |
42 Scope::~Scope() { | 45 Scope::~Scope() { |
43 STLDeleteContainerPairSecondPointers(target_defaults_.begin(), | 46 STLDeleteContainerPairSecondPointers(target_defaults_.begin(), |
44 target_defaults_.end()); | 47 target_defaults_.end()); |
45 STLDeleteContainerPairSecondPointers(templates_.begin(), templates_.end()); | 48 STLDeleteContainerPairSecondPointers(templates_.begin(), templates_.end()); |
46 } | 49 } |
47 | 50 |
48 const Value* Scope::GetValue(const base::StringPiece& ident, | 51 const Value* Scope::GetValue(const base::StringPiece& ident, |
49 bool counts_as_used) { | 52 bool counts_as_used) { |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 } | 386 } |
384 | 387 |
385 const SourceDir& Scope::GetSourceDir() const { | 388 const SourceDir& Scope::GetSourceDir() const { |
386 if (!source_dir_.is_null()) | 389 if (!source_dir_.is_null()) |
387 return source_dir_; | 390 return source_dir_; |
388 if (containing()) | 391 if (containing()) |
389 return containing()->GetSourceDir(); | 392 return containing()->GetSourceDir(); |
390 return source_dir_; | 393 return source_dir_; |
391 } | 394 } |
392 | 395 |
| 396 Scope::ItemVector* Scope::GetItemCollector() { |
| 397 if (item_collector_) |
| 398 return item_collector_; |
| 399 if (mutable_containing()) |
| 400 return mutable_containing()->GetItemCollector(); |
| 401 return NULL; |
| 402 } |
| 403 |
393 void Scope::SetProperty(const void* key, void* value) { | 404 void Scope::SetProperty(const void* key, void* value) { |
394 if (!value) { | 405 if (!value) { |
395 DCHECK(properties_.find(key) != properties_.end()); | 406 DCHECK(properties_.find(key) != properties_.end()); |
396 properties_.erase(key); | 407 properties_.erase(key); |
397 } else { | 408 } else { |
398 properties_[key] = value; | 409 properties_[key] = value; |
399 } | 410 } |
400 } | 411 } |
401 | 412 |
402 void* Scope::GetProperty(const void* key, const Scope** found_on_scope) const { | 413 void* Scope::GetProperty(const void* key, const Scope** found_on_scope) const { |
403 PropertyMap::const_iterator found = properties_.find(key); | 414 PropertyMap::const_iterator found = properties_.find(key); |
404 if (found != properties_.end()) { | 415 if (found != properties_.end()) { |
405 if (found_on_scope) | 416 if (found_on_scope) |
406 *found_on_scope = this; | 417 *found_on_scope = this; |
407 return found->second; | 418 return found->second; |
408 } | 419 } |
409 if (containing()) | 420 if (containing()) |
410 return containing()->GetProperty(key, found_on_scope); | 421 return containing()->GetProperty(key, found_on_scope); |
411 return NULL; | 422 return NULL; |
412 } | 423 } |
413 | 424 |
414 void Scope::AddProvider(ProgrammaticProvider* p) { | 425 void Scope::AddProvider(ProgrammaticProvider* p) { |
415 programmatic_providers_.insert(p); | 426 programmatic_providers_.insert(p); |
416 } | 427 } |
417 | 428 |
418 void Scope::RemoveProvider(ProgrammaticProvider* p) { | 429 void Scope::RemoveProvider(ProgrammaticProvider* p) { |
419 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); | 430 DCHECK(programmatic_providers_.find(p) != programmatic_providers_.end()); |
420 programmatic_providers_.erase(p); | 431 programmatic_providers_.erase(p); |
421 } | 432 } |
OLD | NEW |