OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/deps_iterator.h" | 5 #include "tools/gn/deps_iterator.h" |
6 | 6 |
7 #include "tools/gn/target.h" | 7 #include "tools/gn/target.h" |
8 | 8 |
9 DepsIterator::DepsIterator(const Target* t) : current_index_(0) { | 9 DepsIterator::DepsIterator() : current_index_(0) { |
10 vect_stack_[0] = &t->public_deps(); | 10 vect_stack_[0] = nullptr; |
11 vect_stack_[1] = &t->private_deps(); | 11 vect_stack_[1] = nullptr; |
12 vect_stack_[2] = &t->data_deps(); | 12 vect_stack_[2] = nullptr; |
13 | |
14 if (vect_stack_[0]->empty()) | |
15 Advance(); | |
16 } | 13 } |
17 | 14 |
18 // Iterate over the public and private linked deps, but not the data deps. | 15 DepsIterator::DepsIterator(const LabelTargetVector* a, |
19 DepsIterator::DepsIterator(const Target* t, LinkedOnly) : current_index_(0) { | 16 const LabelTargetVector* b, |
20 vect_stack_[0] = &t->public_deps(); | 17 const LabelTargetVector* c) |
21 vect_stack_[1] = &t->private_deps(); | 18 : current_index_(0) { |
22 vect_stack_[2] = NULL; | 19 vect_stack_[0] = a; |
| 20 vect_stack_[1] = b; |
| 21 vect_stack_[2] = c; |
23 | 22 |
24 if (vect_stack_[0]->empty()) | 23 if (vect_stack_[0] && vect_stack_[0]->empty()) |
25 Advance(); | 24 operator++(); |
26 } | 25 } |
27 | 26 |
28 // Advance to the next position. This assumes there are more vectors. | 27 // Advance to the next position. This assumes there are more vectors. |
29 // | 28 // |
30 // For internal use, this function tolerates an initial index equal to the | 29 // For internal use, this function tolerates an initial index equal to the |
31 // length of the current vector. In this case, it will advance to the next | 30 // length of the current vector. In this case, it will advance to the next |
32 // one. | 31 // one. |
33 void DepsIterator::Advance() { | 32 DepsIterator& DepsIterator::operator++() { |
34 DCHECK(vect_stack_[0]); | 33 DCHECK(vect_stack_[0]); |
35 | 34 |
36 current_index_++; | 35 current_index_++; |
37 if (current_index_ >= vect_stack_[0]->size()) { | 36 if (current_index_ >= vect_stack_[0]->size()) { |
38 // Advance to next vect. Shift the elements left by one. | 37 // Advance to next vect. Shift the elements left by one. |
39 vect_stack_[0] = vect_stack_[1]; | 38 vect_stack_[0] = vect_stack_[1]; |
40 vect_stack_[1] = vect_stack_[2]; | 39 vect_stack_[1] = vect_stack_[2]; |
41 vect_stack_[2] = NULL; | 40 vect_stack_[2] = nullptr; |
42 | 41 |
43 current_index_ = 0; | 42 current_index_ = 0; |
44 | 43 |
45 if (vect_stack_[0] && vect_stack_[0]->empty()) | 44 if (vect_stack_[0] && vect_stack_[0]->empty()) |
46 Advance(); | 45 operator++(); |
47 } | 46 } |
| 47 return *this; |
48 } | 48 } |
| 49 |
| 50 DepsIteratorRange::DepsIteratorRange(const DepsIterator& b) |
| 51 : begin_(b), |
| 52 end_() { |
| 53 } |
| 54 |
| 55 DepsIteratorRange::~DepsIteratorRange() { |
| 56 } |
OLD | NEW |