blob: 107e44187c401647a0ff1f2b39691d6d2590b7f0 [file] [log] [blame]
[email protected]26542b02013-11-08 23:25:041// 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#include "tools/gn/builder_record.h"
6
7#include "tools/gn/item.h"
8
9BuilderRecord::BuilderRecord(ItemType type, const Label& label)
10 : type_(type),
11 label_(label),
tfarina9b636af2014-12-23 00:52:0712 originally_referenced_from_(nullptr),
[email protected]26542b02013-11-08 23:25:0413 should_generate_(false),
14 resolved_(false) {
15}
16
17BuilderRecord::~BuilderRecord() {
18}
19
20// static
21const char* BuilderRecord::GetNameForType(ItemType type) {
22 switch (type) {
23 case ITEM_TARGET:
24 return "target";
25 case ITEM_CONFIG:
26 return "config";
27 case ITEM_TOOLCHAIN:
28 return "toolchain";
sdefresne40451c52016-06-04 12:37:2929 case ITEM_POOL:
30 return "pool";
[email protected]26542b02013-11-08 23:25:0431 case ITEM_UNKNOWN:
32 default:
33 return "unknown";
34 }
35}
36
37// static
38bool BuilderRecord::IsItemOfType(const Item* item, ItemType type) {
39 switch (type) {
40 case ITEM_TARGET:
41 return !!item->AsTarget();
42 case ITEM_CONFIG:
43 return !!item->AsConfig();
44 case ITEM_TOOLCHAIN:
45 return !!item->AsToolchain();
sdefresne40451c52016-06-04 12:37:2946 case ITEM_POOL:
47 return !!item->AsPool();
[email protected]26542b02013-11-08 23:25:0448 case ITEM_UNKNOWN:
49 default:
50 return false;
51 }
52}
53
54// static
55BuilderRecord::ItemType BuilderRecord::TypeOfItem(const Item* item) {
56 if (item->AsTarget())
57 return ITEM_TARGET;
58 if (item->AsConfig())
59 return ITEM_CONFIG;
60 if (item->AsToolchain())
61 return ITEM_TOOLCHAIN;
sdefresne40451c52016-06-04 12:37:2962 if (item->AsPool())
63 return ITEM_POOL;
[email protected]26542b02013-11-08 23:25:0464
65 NOTREACHED();
66 return ITEM_UNKNOWN;
67}
68
69void BuilderRecord::AddDep(BuilderRecord* record) {
70 all_deps_.insert(record);
71 if (!record->resolved()) {
72 unresolved_deps_.insert(record);
73 record->waiting_on_resolution_.insert(this);
74 }
75}