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