Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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/inherited_libraries.h" | |
| 6 | |
| 7 #include "tools/gn/target.h" | |
| 8 | |
| 9 InheritedLibraries::InheritedLibraries() { | |
| 10 | |
|
Dirk Pranke
2015/04/15 19:31:38
nit: stray blank line?
| |
| 11 } | |
| 12 | |
| 13 InheritedLibraries::~InheritedLibraries() { | |
| 14 } | |
| 15 | |
| 16 std::vector<const Target*> InheritedLibraries::GetOrdered() const { | |
| 17 std::vector<const Target*> result; | |
| 18 result.resize(map_.size()); | |
| 19 | |
| 20 // The indices in the map should be from 0 to the number of items in the | |
| 21 // map, so insert directly into the result (with some sanity checks). | |
| 22 for (const auto& pair : map_) { | |
| 23 size_t index = pair.second.index; | |
| 24 DCHECK(index < result.size()); | |
| 25 DCHECK(!result[index]); | |
| 26 result[index] = pair.first; | |
| 27 } | |
| 28 | |
| 29 return result; | |
| 30 } | |
| 31 | |
| 32 std::vector<std::pair<const Target*, bool>> | |
| 33 InheritedLibraries::GetOrderedAndPublicFlag() const { | |
| 34 std::vector<std::pair<const Target*, bool>> result; | |
| 35 result.resize(map_.size()); | |
| 36 | |
| 37 for (const auto& pair : map_) { | |
| 38 size_t index = pair.second.index; | |
| 39 DCHECK(index < result.size()); | |
| 40 DCHECK(!result[index].first); | |
| 41 result[index] = std::make_pair(pair.first, pair.second.is_public); | |
| 42 } | |
| 43 | |
| 44 return result; | |
| 45 } | |
| 46 | |
| 47 void InheritedLibraries::Append(const Target* target, bool is_public) { | |
| 48 // Try to insert a new node. | |
| 49 auto insert_result = map_.insert( | |
| 50 std::make_pair(target, Node(map_.size(), is_public))); | |
| 51 | |
| 52 if (!insert_result.second) { | |
| 53 // Element already present, insert failed and insert_result indicates the | |
| 54 // old one. The old one may need to have its public flag updated. | |
| 55 if (is_public) { | |
| 56 Node& existing_node = insert_result.first->second; | |
| 57 existing_node.is_public = true; | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 void InheritedLibraries::AppendInherited(const InheritedLibraries& other, | |
| 63 bool is_public) { | |
| 64 // Append all items in order, mark them public only if the're already public | |
| 65 // and we're adding them publically. | |
| 66 for (const auto& cur : other.GetOrderedAndPublicFlag()) | |
| 67 Append(cur.first, is_public && cur.second); | |
| 68 } | |
| 69 | |
| 70 void InheritedLibraries::AppendPublicSharedLibraries( | |
| 71 const InheritedLibraries& other, | |
| 72 bool is_public) { | |
| 73 for (const auto& cur : other.GetOrderedAndPublicFlag()) { | |
| 74 if (cur.first->output_type() == Target::SHARED_LIBRARY && cur.second) | |
| 75 Append(cur.first, is_public); | |
| 76 } | |
| 77 } | |
| OLD | NEW |