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.
5 #ifndef TOOLS_GN_BUILDER_RECORD_H_
6 #define TOOLS_GN_BUILDER_RECORD_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "tools/gn/item.h"
13 #include "tools/gn/location.h"
17 // This class is used by the builder to manage the loading of the dependency
18 // tree. It holds a reference to an item and links to other records that the
19 // item depends on, both resolved ones, and unresolved ones.
21 // If a target depends on another one that hasn't been defined yet, we'll make
22 // a placeholder BuilderRecord with no item, and try to load the buildfile
23 // associated with the new item. The item will get filled in when we encounter
24 // the declaration for the item (or when we're done and realize there are
27 // You can also have null item pointers when the target is not required for
28 // the current build (should_generate is false).
31 typedef std::set
<BuilderRecord
*> BuilderRecordSet
;
40 BuilderRecord(ItemType type
, const Label
& label
);
43 ItemType
type() const { return type_
; }
44 const Label
& label() const { return label_
; }
46 // Returns a user-ready name for the given type. e.g. "target".
47 static const char* GetNameForType(ItemType type
);
49 // Returns true if the given item is of the given type.
50 static bool IsItemOfType(const Item
* item
, ItemType type
);
52 // Returns the type enum for the given item.
53 static ItemType
TypeOfItem(const Item
* item
);
55 Item
* item() { return item_
.get(); }
56 const Item
* item() const { return item_
.get(); }
57 void set_item(scoped_ptr
<Item
> item
) { item_
= item
.Pass(); }
59 // Indicates from where this item was originally referenced from that caused
60 // it to be loaded. For targets for which we encountered the declaration
61 // before a reference, this will be the empty range.
62 const ParseNode
* originally_referenced_from() const {
63 return originally_referenced_from_
;
65 void set_originally_referenced_from(const ParseNode
* pn
) {
66 originally_referenced_from_
= pn
;
69 bool should_generate() const { return should_generate_
; }
70 void set_should_generate(bool sg
) { should_generate_
= sg
; }
72 bool resolved() const { return resolved_
; }
73 void set_resolved(bool r
) { resolved_
= r
; }
75 bool can_resolve() const {
76 return item_
&& unresolved_deps_
.empty();
79 // All records this one is depending on.
80 BuilderRecordSet
& all_deps() { return all_deps_
; }
81 const BuilderRecordSet
& all_deps() const { return all_deps_
; }
83 // Unresolved records this one is depending on. A subset of all... above.
84 BuilderRecordSet
& unresolved_deps() { return unresolved_deps_
; }
85 const BuilderRecordSet
& unresolved_deps() const { return unresolved_deps_
; }
87 // Records that are waiting on this one to be resolved. This is the other
88 // end of the "unresolved deps" arrow.
89 BuilderRecordSet
& waiting_on_resolution() { return waiting_on_resolution_
; }
90 const BuilderRecordSet
& waiting_on_resolution() const {
91 return waiting_on_resolution_
;
94 void AddDep(BuilderRecord
* record
);
99 scoped_ptr
<Item
> item_
;
100 const ParseNode
* originally_referenced_from_
;
101 bool should_generate_
;
104 BuilderRecordSet all_deps_
;
105 BuilderRecordSet unresolved_deps_
;
106 BuilderRecordSet waiting_on_resolution_
;
108 DISALLOW_COPY_AND_ASSIGN(BuilderRecord
);
111 #endif // TOOLS_GN_BUILDER_RECORD_H_