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_NODE_H_ | |
6 #define TOOLS_GN_ITEM_NODE_H_ | |
7 | |
8 #include <set> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/callback.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "tools/gn/location.h" | |
15 | |
16 class Item; | |
17 | |
18 // Represents a node in the depdency tree. It references an Item which is | |
19 // the actual thing. | |
20 // | |
21 // The items and nodes are split apart so that the ItemTree can manipulate | |
22 // the dependencies one one thread while the Item itself is been modified on | |
23 // another. | |
24 class ItemNode { | |
25 public: | |
26 enum State { | |
27 // Another item has referenced this one by name, but we have not yet | |
28 // encountered this item to know what it is. | |
29 REFERENCED, | |
30 | |
31 // This item has been defined but some of the dependencies it references | |
32 // have not been. | |
33 GENERATED, | |
34 | |
35 // All of this item's transitive dependencies have been found and | |
36 // resolved. | |
37 RESOLVED, | |
38 }; | |
39 | |
40 typedef std::set<ItemNode*> ItemNodeSet; | |
41 | |
42 // Takes ownership of the pointer. | |
43 // Initial state will be REFERENCED. | |
44 ItemNode(Item* i); | |
45 ~ItemNode(); | |
46 | |
47 State state() const { return state_; } | |
48 | |
49 // This closure will be executed when the item is resolved. | |
50 void set_resolved_closure(const base::Closure& closure) { | |
51 resolved_closure_ = closure; | |
52 } | |
53 | |
54 const Item* item() const { return item_.get(); } | |
55 Item* item() { return item_.get(); } | |
56 | |
57 // Where this was created from, which might be when it was generated or | |
58 // when it was first referenced from another target. | |
59 const LocationRange& originally_referenced_from_here() const { | |
60 return originally_referenced_from_here_; | |
61 } | |
62 void set_originally_referenced_from_here(const LocationRange& r) { | |
63 originally_referenced_from_here_ = r; | |
64 } | |
65 | |
66 // Where this was generated from. This will be empty for items that have | |
67 // been referenced but not generated. Note that this has to be one the | |
68 // ItemNode because it can be changing from multiple threads and we need | |
69 // to be sure that access is serialized. | |
70 const LocationRange& generated_from_here() const { | |
71 return generated_from_here_; | |
72 } | |
73 void set_generated_from_here(const LocationRange& r) { | |
74 generated_from_here_ = r; | |
75 } | |
76 | |
77 const ItemNodeSet& direct_dependencies() const { | |
78 return direct_dependencies_; | |
79 } | |
80 const ItemNodeSet& unresolved_dependencies() const { | |
81 return unresolved_dependencies_; | |
82 } | |
83 | |
84 void AddDependency(ItemNode* node); | |
85 | |
86 // Removes the given dependency from the unresolved list. Does not do | |
87 // anything else to update waiters. | |
88 void MarkDirectDependencyResolved(ItemNode* node); | |
89 | |
90 // Destructively retrieve the set of waiting nodes. | |
91 void SwapOutWaitingDependencySet(ItemNodeSet* out_set); | |
92 | |
93 void SetGenerated(); | |
94 void SetResolved(); | |
95 | |
96 private: | |
97 State state_; | |
98 scoped_ptr<Item> item_; | |
99 | |
100 LocationRange originally_referenced_from_here_; | |
101 LocationRange generated_from_here_; | |
102 | |
103 // What to run when this item is resolved. | |
104 base::Closure resolved_closure_; | |
105 | |
106 // Everything this item directly depends on. | |
107 ItemNodeSet direct_dependencies_; | |
108 | |
109 // Unresolved things this item directly depends on. | |
110 ItemNodeSet unresolved_dependencies_; | |
111 | |
112 // These items are waiting on us to be resolved before they can be | |
113 // resolved. This is the backpointer for unresolved_dependencies_. | |
114 ItemNodeSet waiting_on_resolution_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(ItemNode); | |
117 }; | |
118 | |
119 #endif // TOOLS_GN_ITEM_NODE_H_ | |
OLD | NEW |