• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "tools/gn/builder_record.h"
6 
7 #include "tools/gn/item.h"
8 
BuilderRecord(ItemType type,const Label & label)9 BuilderRecord::BuilderRecord(ItemType type, const Label& label)
10     : type_(type),
11       label_(label),
12       originally_referenced_from_(NULL),
13       should_generate_(false),
14       resolved_(false) {
15 }
16 
~BuilderRecord()17 BuilderRecord::~BuilderRecord() {
18 }
19 
20 // static
GetNameForType(ItemType type)21 const 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";
29     case ITEM_UNKNOWN:
30     default:
31       return "unknown";
32   }
33 }
34 
35 // static
IsItemOfType(const Item * item,ItemType type)36 bool BuilderRecord::IsItemOfType(const Item* item, ItemType type) {
37   switch (type) {
38     case ITEM_TARGET:
39       return !!item->AsTarget();
40     case ITEM_CONFIG:
41       return !!item->AsConfig();
42     case ITEM_TOOLCHAIN:
43       return !!item->AsToolchain();
44     case ITEM_UNKNOWN:
45     default:
46       return false;
47   }
48 }
49 
50 // static
TypeOfItem(const Item * item)51 BuilderRecord::ItemType BuilderRecord::TypeOfItem(const Item* item) {
52   if (item->AsTarget())
53     return ITEM_TARGET;
54   if (item->AsConfig())
55     return ITEM_CONFIG;
56   if (item->AsToolchain())
57     return ITEM_TOOLCHAIN;
58 
59   NOTREACHED();
60   return ITEM_UNKNOWN;
61 }
62 
AddDep(BuilderRecord * record)63 void BuilderRecord::AddDep(BuilderRecord* record) {
64   all_deps_.insert(record);
65   if (!record->resolved()) {
66     unresolved_deps_.insert(record);
67     record->waiting_on_resolution_.insert(this);
68   }
69 }
70