| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef TOOLS_GN_ITEM_TREE_H_ | |
| 6 #define TOOLS_GN_ITEM_TREE_H_ | |
| 7 | |
| 8 #include "base/containers/hash_tables.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/synchronization/lock.h" | |
| 11 #include "tools/gn/label.h" | |
| 12 | |
| 13 class Err; | |
| 14 class Item; | |
| 15 class ItemNode; | |
| 16 | |
| 17 // Represents the full dependency tree if labeled items in the system. | |
| 18 // Generally you will interact with this through the target manager, etc. | |
| 19 class ItemTree { | |
| 20 public: | |
| 21 ItemTree(); | |
| 22 ~ItemTree(); | |
| 23 | |
| 24 // This lock must be held when calling the "Locked" functions below. | |
| 25 base::Lock& lock() { return lock_; } | |
| 26 | |
| 27 // Returns NULL if the item is not found. | |
| 28 // | |
| 29 // The lock must be held. | |
| 30 ItemNode* GetExistingNodeLocked(const Label& label); | |
| 31 | |
| 32 // There must not be an item with this label in the tree already. Takes | |
| 33 // ownership of the pointer. | |
| 34 // | |
| 35 // The lock must be held. | |
| 36 void AddNodeLocked(ItemNode* node); | |
| 37 | |
| 38 // Mark the given item as being generated. If it has no unresolved | |
| 39 // dependencies, it will be marked resolved, and the resolved state will be | |
| 40 // recursively pushed into the dependency tree. Returns an error if there was | |
| 41 // an error. | |
| 42 Err MarkItemGeneratedLocked(const Label& label); | |
| 43 | |
| 44 // Fills the given vector with all known items. | |
| 45 void GetAllItemsLocked(std::vector<const Item*>* dest) const; | |
| 46 | |
| 47 // Returns an error if there are unresolved dependencies, or no error if | |
| 48 // there aren't. | |
| 49 // | |
| 50 // The lock should not be held. | |
| 51 Err CheckForBadItems() const; | |
| 52 | |
| 53 private: | |
| 54 Err MarkItemResolvedLocked(ItemNode* node); | |
| 55 | |
| 56 // Given a set of unresolved nodes, looks for cycles and returns the error | |
| 57 // message describing any cycles it found. | |
| 58 std::string CheckForCircularDependenciesLocked( | |
| 59 const std::vector<const ItemNode*>& bad_nodes) const; | |
| 60 | |
| 61 mutable base::Lock lock_; | |
| 62 | |
| 63 typedef base::hash_map<Label, ItemNode*> StringToNodeHash; | |
| 64 StringToNodeHash items_; // Owning pointer. | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(ItemTree); | |
| 67 }; | |
| 68 | |
| 69 #endif // TOOLS_GN_ITEM_TREE_H_ | |
| OLD | NEW |