cpp

Coverage Report

Created: 2022-11-10 11:34

/home/andy/git/oilshell/oil/mycpp/gc_list.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef MYCPP_GC_LIST_H
2
#define MYCPP_GC_LIST_H
3
4
#include <algorithm>  // sort() is templated
5
6
#include "mycpp/comparators.h"
7
8
class ValueError;
9
10
// Type that is layout-compatible with List (unit tests assert this).  Two
11
// purposes:
12
// - To make globals of "plain old data" at compile-time, not at startup time.
13
//   This can't be done with subclasses of Obj.
14
// - To avoid invalid-offsetof warnings when computing GC masks.
15
16
template <typename T, int N>
17
class GlobalList {
18
 public:
19
  OBJ_HEADER()
20
  int len_;
21
  int capacity_;
22
  GlobalSlab<T, N>* slab_;
23
};
24
25
// A list has one Slab pointer which we need to follow.
26
506
constexpr uint16_t maskof_List() {
27
506
  return maskbit(offsetof(GlobalList<int COMMA 1>, slab_));
28
506
}
29
30
template <typename T>
31
class List : public Obj {
32
  // TODO: Move methods that don't allocate or resize: out of gc_heap?
33
  // - allocate: append(), extend()
34
  // - resize: pop(), clear()
35
  // - neither: reverse(), sort() -- these are more like functions.  Except
36
  //   sort() is a templated method that depends on type param T.
37
  // - neither: index(), slice()
38
39
  // 8 / 4 = 2 items, or 8 / 8 = 1 item
40
  static const int kCapacityAdjust = kSlabHeaderSize / sizeof(T);
41
  static_assert(kSlabHeaderSize % sizeof(T) == 0,
42
                "Slab header size should be multiple of item size");
43
44
 public:
45
506
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
506
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
506
  }
_ZN4ListIP3StrEC2Ev
Line
Count
Source
45
98
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
98
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
98
  }
_ZN4ListIiEC2Ev
Line
Count
Source
45
332
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
332
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
332
  }
_ZN4ListIbEC2Ev
Line
Count
Source
45
3
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
3
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
3
  }
_ZN4ListIdEC2Ev
Line
Count
Source
45
2
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
2
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
2
  }
_ZN4ListIP6Tuple2IP3StriEEC2Ev
Line
Count
Source
45
1
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
1
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
1
  }
_ZN4ListIP6Tuple2IiP3StrEEC2Ev
Line
Count
Source
45
2
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
2
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
2
  }
_ZN4ListIPN10hnode_asdl5fieldEEC2Ev
Line
Count
Source
45
34
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
34
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
34
  }
_ZN4ListIPN10hnode_asdl7hnode_tEEC2Ev
Line
Count
Source
45
34
  List() : Obj(Tag::FixedSize, maskof_List(), sizeof(List<T>)) {
46
    // Ensured by heap zeroing.  It's never directly on the stack.
47
34
    assert(len_ == 0);
48
0
    assert(capacity_ == 0);
49
0
    assert(slab_ == nullptr);
50
34
  }
51
52
  // Implements L[i]
53
  T index_(int i);
54
55
  // returns index of the element
56
  int index(T element);
57
58
  // Implements L[i] = item
59
  // Note: Unlike Dict::set(), we don't need to specialize List::set() on T for
60
  // StackRoots because it doesn't allocate.
61
  void set(int i, T item);
62
63
  // L[begin:]
64
  List* slice(int begin);
65
66
  // L[begin:end]
67
  // TODO: Can this be optimized?
68
  List* slice(int begin, int end);
69
70
  // Should we have a separate API that doesn't return it?
71
  // https://stackoverflow.com/questions/12600330/pop-back-return-value
72
  T pop();
73
74
  // Used in osh/word_parse.py to remove from front
75
  // TODO: Don't accept an arbitrary index?
76
  T pop(int i);
77
78
  void clear();
79
80
  // Used in osh/string_ops.py
81
  void reverse();
82
83
  // Templated function
84
  void sort();
85
86
  // Ensure that there's space for a number of items
87
  void reserve(int n);
88
89
  // Append a single element to this list.  Calls free function list_append(),
90
  // which has pointer and non-pointer specializations.
91
  void append(T item);
92
93
  // Extend this list with multiple elements.
94
  void extend(List<T>* other);
95
96
  int len_;       // number of entries
97
  int capacity_;  // max entries before resizing
98
99
  // The container may be resized, so this field isn't in-line.
100
  Slab<T>* slab_;
101
102
  DISALLOW_COPY_AND_ASSIGN(List)
103
};
104
105
// "Constructors" as free functions since we can't allocate within a
106
// constructor.  Allocation may cause garbage collection, which interferes with
107
// placement new.
108
109
template <typename T>
110
321
List<T>* NewList() {
111
321
  return Alloc<List<T>>();
112
321
}
_Z7NewListIiEP4ListIT_Ev
Line
Count
Source
110
308
List<T>* NewList() {
111
308
  return Alloc<List<T>>();
112
308
}
_Z7NewListIP3StrEP4ListIT_Ev
Line
Count
Source
110
13
List<T>* NewList() {
111
13
  return Alloc<List<T>>();
112
13
}
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl5fieldEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl7hnode_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN12runtime_asdl10assign_argEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN12runtime_asdl12part_value_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN12runtime_asdl7value_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl13compound_wordEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl11word_part_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl9command_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl6word_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl5redirEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl8env_pairEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl11assign_pairEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl6if_armEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl8case_armEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl9name_typeEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl12place_expr_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl5paramEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl11type_expr_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl7variantEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl12class_item_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl11import_nameEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl12UntypedParamEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl10TypedParamEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl5TokenEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl5speckEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl6expr_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl13comprehensionEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl20class_literal_term_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl17char_class_term_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl4re_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl9named_argEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl11string_lineEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIP6Tuple2IiP3StrEEP4ListIT_Ev
113
114
// Literal ['foo', 'bar']
115
template <typename T>
116
49
List<T>* NewList(std::initializer_list<T> init) {
117
49
  auto self = Alloc<List<T>>();
118
49
  StackRoots _roots({&self});
119
120
49
  int n = init.size();
121
49
  self->reserve(n);
122
123
49
  int i = 0;
124
110
  for (auto item : init) {
125
110
    self->set(i, item);
126
110
    ++i;
127
110
  }
128
49
  self->len_ = n;
129
49
  return self;
130
49
}
_Z7NewListIP3StrEP4ListIT_ESt16initializer_listIS3_E
Line
Count
Source
116
27
List<T>* NewList(std::initializer_list<T> init) {
117
27
  auto self = Alloc<List<T>>();
118
27
  StackRoots _roots({&self});
119
120
27
  int n = init.size();
121
27
  self->reserve(n);
122
123
27
  int i = 0;
124
45
  for (auto item : init) {
125
45
    self->set(i, item);
126
45
    ++i;
127
45
  }
128
27
  self->len_ = n;
129
27
  return self;
130
27
}
_Z7NewListIiEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
116
17
List<T>* NewList(std::initializer_list<T> init) {
117
17
  auto self = Alloc<List<T>>();
118
17
  StackRoots _roots({&self});
119
120
17
  int n = init.size();
121
17
  self->reserve(n);
122
123
17
  int i = 0;
124
53
  for (auto item : init) {
125
53
    self->set(i, item);
126
53
    ++i;
127
53
  }
128
17
  self->len_ = n;
129
17
  return self;
130
17
}
_Z7NewListIdEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
116
2
List<T>* NewList(std::initializer_list<T> init) {
117
2
  auto self = Alloc<List<T>>();
118
2
  StackRoots _roots({&self});
119
120
2
  int n = init.size();
121
2
  self->reserve(n);
122
123
2
  int i = 0;
124
6
  for (auto item : init) {
125
6
    self->set(i, item);
126
6
    ++i;
127
6
  }
128
2
  self->len_ = n;
129
2
  return self;
130
2
}
_Z7NewListIP6Tuple2IP3StriEEP4ListIT_ESt16initializer_listIS6_E
Line
Count
Source
116
1
List<T>* NewList(std::initializer_list<T> init) {
117
1
  auto self = Alloc<List<T>>();
118
1
  StackRoots _roots({&self});
119
120
1
  int n = init.size();
121
1
  self->reserve(n);
122
123
1
  int i = 0;
124
2
  for (auto item : init) {
125
2
    self->set(i, item);
126
2
    ++i;
127
2
  }
128
1
  self->len_ = n;
129
1
  return self;
130
1
}
_Z7NewListIP6Tuple2IiP3StrEEP4ListIT_ESt16initializer_listIS6_E
Line
Count
Source
116
1
List<T>* NewList(std::initializer_list<T> init) {
117
1
  auto self = Alloc<List<T>>();
118
1
  StackRoots _roots({&self});
119
120
1
  int n = init.size();
121
1
  self->reserve(n);
122
123
1
  int i = 0;
124
2
  for (auto item : init) {
125
2
    self->set(i, item);
126
2
    ++i;
127
2
  }
128
1
  self->len_ = n;
129
1
  return self;
130
1
}
_Z7NewListIbEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
116
1
List<T>* NewList(std::initializer_list<T> init) {
117
1
  auto self = Alloc<List<T>>();
118
1
  StackRoots _roots({&self});
119
120
1
  int n = init.size();
121
1
  self->reserve(n);
122
123
1
  int i = 0;
124
2
  for (auto item : init) {
125
2
    self->set(i, item);
126
2
    ++i;
127
2
  }
128
1
  self->len_ = n;
129
1
  return self;
130
1
}
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl7hnode_tEEP4ListIT_ESt16initializer_listIS4_E
131
132
// ['foo'] * 3
133
template <typename T>
134
7
List<T>* NewList(T item, int times) {
135
7
  auto self = Alloc<List<T>>();
136
7
  StackRoots _roots({&self});
137
138
7
  self->reserve(times);
139
7
  self->len_ = times;
140
28
  for (int i = 0; i < times; ++i) {
141
21
    self->set(i, item);
142
21
  }
143
7
  return self;
144
7
}
_Z7NewListIP3StrEP4ListIT_ES3_i
Line
Count
Source
134
3
List<T>* NewList(T item, int times) {
135
3
  auto self = Alloc<List<T>>();
136
3
  StackRoots _roots({&self});
137
138
3
  self->reserve(times);
139
3
  self->len_ = times;
140
12
  for (int i = 0; i < times; ++i) {
141
9
    self->set(i, item);
142
9
  }
143
3
  return self;
144
3
}
_Z7NewListIbEP4ListIT_ES1_i
Line
Count
Source
134
2
List<T>* NewList(T item, int times) {
135
2
  auto self = Alloc<List<T>>();
136
2
  StackRoots _roots({&self});
137
138
2
  self->reserve(times);
139
2
  self->len_ = times;
140
8
  for (int i = 0; i < times; ++i) {
141
6
    self->set(i, item);
142
6
  }
143
2
  return self;
144
2
}
_Z7NewListIiEP4ListIT_ES1_i
Line
Count
Source
134
2
List<T>* NewList(T item, int times) {
135
2
  auto self = Alloc<List<T>>();
136
2
  StackRoots _roots({&self});
137
138
2
  self->reserve(times);
139
2
  self->len_ = times;
140
8
  for (int i = 0; i < times; ++i) {
141
6
    self->set(i, item);
142
6
  }
143
2
  return self;
144
2
}
145
146
// e.g. List<int>
147
template <typename T>
148
2.52k
void list_append(List<T>* self, T item) {
149
2.52k
  StackRoots _roots({&self});
150
151
2.52k
  self->reserve(self->len_ + 1);
152
2.52k
  self->set(self->len_, item);
153
2.52k
  ++self->len_;
154
2.52k
}
155
156
// e.g. List<Str*>
157
template <typename T>
158
305
void list_append(List<T*>* self, T* item) {
159
305
  StackRoots _roots({&self, &item});
160
161
305
  self->reserve(self->len_ + 1);
162
305
  self->set(self->len_, item);
163
305
  ++self->len_;
164
305
}
_Z11list_appendI3StrEvP4ListIPT_ES3_
Line
Count
Source
158
244
void list_append(List<T*>* self, T* item) {
159
244
  StackRoots _roots({&self, &item});
160
161
244
  self->reserve(self->len_ + 1);
162
244
  self->set(self->len_, item);
163
244
  ++self->len_;
164
244
}
Unexecuted instantiation: _Z11list_appendI6Tuple2IP3StriEEvP4ListIPT_ES6_
_Z11list_appendIN10hnode_asdl5fieldEEvP4ListIPT_ES4_
Line
Count
Source
158
60
void list_append(List<T*>* self, T* item) {
159
60
  StackRoots _roots({&self, &item});
160
161
60
  self->reserve(self->len_ + 1);
162
60
  self->set(self->len_, item);
163
60
  ++self->len_;
164
60
}
_Z11list_appendI6Tuple2IiP3StrEEvP4ListIPT_ES6_
Line
Count
Source
158
1
void list_append(List<T*>* self, T* item) {
159
1
  StackRoots _roots({&self, &item});
160
161
1
  self->reserve(self->len_ + 1);
162
1
  self->set(self->len_, item);
163
1
  ++self->len_;
164
1
}
Unexecuted instantiation: _Z11list_appendIN10hnode_asdl7hnode_tEEvP4ListIPT_ES4_
165
166
template <typename T>
167
2.82k
void List<T>::append(T item) {
168
2.82k
  list_append(this, item);
169
2.82k
}
_ZN4ListIiE6appendEi
Line
Count
Source
167
2.52k
void List<T>::append(T item) {
168
2.52k
  list_append(this, item);
169
2.52k
}
_ZN4ListIP3StrE6appendES1_
Line
Count
Source
167
244
void List<T>::append(T item) {
168
244
  list_append(this, item);
169
244
}
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StriEE6appendES4_
_ZN4ListIPN10hnode_asdl5fieldEE6appendES2_
Line
Count
Source
167
60
void List<T>::append(T item) {
168
60
  list_append(this, item);
169
60
}
_ZN4ListIP6Tuple2IiP3StrEE6appendES4_
Line
Count
Source
167
1
void List<T>::append(T item) {
168
1
  list_append(this, item);
169
1
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE6appendES2_
170
171
template <typename T>
172
2.09k
int len(const List<T>* L) {
173
2.09k
  return L->len_;
174
2.09k
}
_Z3lenIiEiPK4ListIT_E
Line
Count
Source
172
1.95k
int len(const List<T>* L) {
173
1.95k
  return L->len_;
174
1.95k
}
_Z3lenIbEiPK4ListIT_E
Line
Count
Source
172
2
int len(const List<T>* L) {
173
2
  return L->len_;
174
2
}
_Z3lenIdEiPK4ListIT_E
Line
Count
Source
172
4
int len(const List<T>* L) {
173
4
  return L->len_;
174
4
}
_Z3lenIP3StrEiPK4ListIT_E
Line
Count
Source
172
140
int len(const List<T>* L) {
173
140
  return L->len_;
174
140
}
_Z3lenIP6Tuple2IiP3StrEEiPK4ListIT_E
Line
Count
Source
172
1
int len(const List<T>* L) {
173
1
  return L->len_;
174
1
}
Unexecuted instantiation: _Z3lenIPN12runtime_asdl10assign_argEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN12runtime_asdl12part_value_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN12runtime_asdl7value_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl11word_part_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl5TokenEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl6word_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl6expr_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl9named_argEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl13compound_wordEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl11string_lineEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl9command_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl5redirEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl8env_pairEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl11assign_pairEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl6if_armEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl8case_armEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl9name_typeEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl12place_expr_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl5paramEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl11type_expr_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl7variantEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl12class_item_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl11import_nameEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl12UntypedParamEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl10TypedParamEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl5speckEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl13comprehensionEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl20class_literal_term_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl17char_class_term_tEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN11syntax_asdl4re_tEEiPK4ListIT_E
175
176
template <typename T>
177
List<T>* list_repeat(T item, int times);
178
179
template <typename T>
180
inline bool list_contains(List<T>* haystack, T needle);
181
182
18
inline int int_cmp(int a, int b) {
183
18
  if (a == b) {
184
4
    return 0;
185
4
  }
186
14
  return a < b ? -1 : 1;
187
18
}
188
189
inline int str_cmp(Str* a, Str* b);
190
inline bool _cmp(Str* a, Str* b);
191
192
template <typename K, typename V>
193
class Dict;  // forward decl
194
195
template <typename V>
196
List<Str*>* sorted(Dict<Str*, V>* d);
197
198
/* template <typename T> */
199
/* void List<T>::sort(); */
200
201
// L[begin:]
202
template <typename T>
203
305
List<T>* List<T>::slice(int begin) {
204
305
  if (begin < 0) {
205
0
    begin = len_ + begin;
206
0
  }
207
208
305
  assert(begin >= 0);
209
210
0
  auto self = this;
211
305
  List<T>* result = nullptr;
212
305
  StackRoots _roots({&self, &result});
213
214
305
  result = NewList<T>();
215
216
1.51k
  for (int i = begin; i < self->len_; i++) {
217
1.21k
    result->append(self->slab_->items_[i]);
218
1.21k
  }
219
220
305
  return result;
221
305
}
_ZN4ListIiE5sliceEi
Line
Count
Source
203
302
List<T>* List<T>::slice(int begin) {
204
302
  if (begin < 0) {
205
0
    begin = len_ + begin;
206
0
  }
207
208
302
  assert(begin >= 0);
209
210
0
  auto self = this;
211
302
  List<T>* result = nullptr;
212
302
  StackRoots _roots({&self, &result});
213
214
302
  result = NewList<T>();
215
216
1.50k
  for (int i = begin; i < self->len_; i++) {
217
1.20k
    result->append(self->slab_->items_[i]);
218
1.20k
  }
219
220
302
  return result;
221
302
}
_ZN4ListIP3StrE5sliceEi
Line
Count
Source
203
3
List<T>* List<T>::slice(int begin) {
204
3
  if (begin < 0) {
205
0
    begin = len_ + begin;
206
0
  }
207
208
3
  assert(begin >= 0);
209
210
0
  auto self = this;
211
3
  List<T>* result = nullptr;
212
3
  StackRoots _roots({&self, &result});
213
214
3
  result = NewList<T>();
215
216
9
  for (int i = begin; i < self->len_; i++) {
217
6
    result->append(self->slab_->items_[i]);
218
6
  }
219
220
3
  return result;
221
3
}
222
223
// L[begin:end]
224
// TODO: Can this be optimized?
225
template <typename T>
226
2
List<T>* List<T>::slice(int begin, int end) {
227
2
  if (begin < 0) {
228
1
    begin = len_ + begin;
229
1
  }
230
2
  if (end < 0) {
231
2
    end = len_ + end;
232
2
  }
233
234
2
  assert(end <= len_);
235
0
  assert(begin >= 0);
236
0
  assert(end >= 0);
237
238
0
  auto self = this;
239
2
  List<T>* result = nullptr;
240
2
  StackRoots _roots({&self, &result});
241
242
2
  result = NewList<T>();
243
6
  for (int i = begin; i < end; i++) {
244
4
    result->append(self->slab_->items_[i]);
245
4
  }
246
247
2
  return result;
248
2
}
249
250
// Ensure that there's space for a number of items
251
template <typename T>
252
2.88k
void List<T>::reserve(int n) {
253
  // log("reserve capacity = %d, n = %d", capacity_, n);
254
2.88k
  auto self = this;
255
2.88k
  StackRoots _roots({&self});
256
257
  // Don't do anything if there's already enough space.
258
2.88k
  if (self->capacity_ >= n) return;
259
260
  // Example: The user asks for space for 7 integers.  Account for the
261
  // header, and say we need 9 to determine the obj length.  9 is
262
  // rounded up to 16, for a 64-byte obj.  Then we actually have space
263
  // for 14 items.
264
478
  self->capacity_ = RoundUp(n + kCapacityAdjust) - kCapacityAdjust;
265
478
  auto new_slab = NewSlab<T>(self->capacity_);
266
267
478
  if (self->len_ > 0) {
268
    // log("Copying %d bytes", len_ * sizeof(T));
269
13
    memcpy(new_slab->items_, self->slab_->items_, self->len_ * sizeof(T));
270
13
  }
271
478
  self->slab_ = new_slab;
272
478
}
_ZN4ListIP3StrE7reserveEi
Line
Count
Source
252
274
void List<T>::reserve(int n) {
253
  // log("reserve capacity = %d, n = %d", capacity_, n);
254
274
  auto self = this;
255
274
  StackRoots _roots({&self});
256
257
  // Don't do anything if there's already enough space.
258
274
  if (self->capacity_ >= n) return;
259
260
  // Example: The user asks for space for 7 integers.  Account for the
261
  // header, and say we need 9 to determine the obj length.  9 is
262
  // rounded up to 16, for a 64-byte obj.  Then we actually have space
263
  // for 14 items.
264
98
  self->capacity_ = RoundUp(n + kCapacityAdjust) - kCapacityAdjust;
265
98
  auto new_slab = NewSlab<T>(self->capacity_);
266
267
98
  if (self->len_ > 0) {
268
    // log("Copying %d bytes", len_ * sizeof(T));
269
5
    memcpy(new_slab->items_, self->slab_->items_, self->len_ * sizeof(T));
270
5
  }
271
98
  self->slab_ = new_slab;
272
98
}
_ZN4ListIiE7reserveEi
Line
Count
Source
252
2.54k
void List<T>::reserve(int n) {
253
  // log("reserve capacity = %d, n = %d", capacity_, n);
254
2.54k
  auto self = this;
255
2.54k
  StackRoots _roots({&self});
256
257
  // Don't do anything if there's already enough space.
258
2.54k
  if (self->capacity_ >= n) return;
259
260
  // Example: The user asks for space for 7 integers.  Account for the
261
  // header, and say we need 9 to determine the obj length.  9 is
262
  // rounded up to 16, for a 64-byte obj.  Then we actually have space
263
  // for 14 items.
264
338
  self->capacity_ = RoundUp(n + kCapacityAdjust) - kCapacityAdjust;
265
338
  auto new_slab = NewSlab<T>(self->capacity_);
266
267
338
  if (self->len_ > 0) {
268
    // log("Copying %d bytes", len_ * sizeof(T));
269
8
    memcpy(new_slab->items_, self->slab_->items_, self->len_ * sizeof(T));
270
8
  }
271
338
  self->slab_ = new_slab;
272
338
}
_ZN4ListIbE7reserveEi
Line
Count
Source
252
3
void List<T>::reserve(int n) {
253
  // log("reserve capacity = %d, n = %d", capacity_, n);
254
3
  auto self = this;
255
3
  StackRoots _roots({&self});
256
257
  // Don't do anything if there's already enough space.
258
3
  if (self->capacity_ >= n) return;
259
260
  // Example: The user asks for space for 7 integers.  Account for the
261
  // header, and say we need 9 to determine the obj length.  9 is
262
  // rounded up to 16, for a 64-byte obj.  Then we actually have space
263
  // for 14 items.
264
3
  self->capacity_ = RoundUp(n + kCapacityAdjust) - kCapacityAdjust;
265
3
  auto new_slab = NewSlab<T>(self->capacity_);
266
267
3
  if (self->len_ > 0) {
268
    // log("Copying %d bytes", len_ * sizeof(T));
269
0
    memcpy(new_slab->items_, self->slab_->items_, self->len_ * sizeof(T));
270
0
  }
271
3
  self->slab_ = new_slab;
272
3
}
_ZN4ListIdE7reserveEi
Line
Count
Source
252
2
void List<T>::reserve(int n) {
253
  // log("reserve capacity = %d, n = %d", capacity_, n);
254
2
  auto self = this;
255
2
  StackRoots _roots({&self});
256
257
  // Don't do anything if there's already enough space.
258
2
  if (self->capacity_ >= n) return;
259
260
  // Example: The user asks for space for 7 integers.  Account for the
261
  // header, and say we need 9 to determine the obj length.  9 is
262
  // rounded up to 16, for a 64-byte obj.  Then we actually have space
263
  // for 14 items.
264
2
  self->capacity_ = RoundUp(n + kCapacityAdjust) - kCapacityAdjust;
265
2
  auto new_slab = NewSlab<T>(self->capacity_);
266
267
2
  if (self->len_ > 0) {
268
    // log("Copying %d bytes", len_ * sizeof(T));
269
0
    memcpy(new_slab->items_, self->slab_->items_, self->len_ * sizeof(T));
270
0
  }
271
2
  self->slab_ = new_slab;
272
2
}
_ZN4ListIP6Tuple2IP3StriEE7reserveEi
Line
Count
Source
252
1
void List<T>::reserve(int n) {
253
  // log("reserve capacity = %d, n = %d", capacity_, n);
254
1
  auto self = this;
255
1
  StackRoots _roots({&self});
256
257
  // Don't do anything if there's already enough space.
258
1
  if (self->capacity_ >= n) return;
259
260
  // Example: The user asks for space for 7 integers.  Account for the
261
  // header, and say we need 9 to determine the obj length.  9 is
262
  // rounded up to 16, for a 64-byte obj.  Then we actually have space
263
  // for 14 items.
264
1
  self->capacity_ = RoundUp(n + kCapacityAdjust) - kCapacityAdjust;
265
1
  auto new_slab = NewSlab<T>(self->capacity_);
266
267
1
  if (self->len_ > 0) {
268
    // log("Copying %d bytes", len_ * sizeof(T));
269
0
    memcpy(new_slab->items_, self->slab_->items_, self->len_ * sizeof(T));
270
0
  }
271
1
  self->slab_ = new_slab;
272
1
}
_ZN4ListIP6Tuple2IiP3StrEE7reserveEi
Line
Count
Source
252
2
void List<T>::reserve(int n) {
253
  // log("reserve capacity = %d, n = %d", capacity_, n);
254
2
  auto self = this;
255
2
  StackRoots _roots({&self});
256
257
  // Don't do anything if there's already enough space.
258
2
  if (self->capacity_ >= n) return;
259
260
  // Example: The user asks for space for 7 integers.  Account for the
261
  // header, and say we need 9 to determine the obj length.  9 is
262
  // rounded up to 16, for a 64-byte obj.  Then we actually have space
263
  // for 14 items.
264
2
  self->capacity_ = RoundUp(n + kCapacityAdjust) - kCapacityAdjust;
265
2
  auto new_slab = NewSlab<T>(self->capacity_);
266
267
2
  if (self->len_ > 0) {
268
    // log("Copying %d bytes", len_ * sizeof(T));
269
0
    memcpy(new_slab->items_, self->slab_->items_, self->len_ * sizeof(T));
270
0
  }
271
2
  self->slab_ = new_slab;
272
2
}
_ZN4ListIPN10hnode_asdl5fieldEE7reserveEi
Line
Count
Source
252
60
void List<T>::reserve(int n) {
253
  // log("reserve capacity = %d, n = %d", capacity_, n);
254
60
  auto self = this;
255
60
  StackRoots _roots({&self});
256
257
  // Don't do anything if there's already enough space.
258
60
  if (self->capacity_ >= n) return;
259
260
  // Example: The user asks for space for 7 integers.  Account for the
261
  // header, and say we need 9 to determine the obj length.  9 is
262
  // rounded up to 16, for a 64-byte obj.  Then we actually have space
263
  // for 14 items.
264
34
  self->capacity_ = RoundUp(n + kCapacityAdjust) - kCapacityAdjust;
265
34
  auto new_slab = NewSlab<T>(self->capacity_);
266
267
34
  if (self->len_ > 0) {
268
    // log("Copying %d bytes", len_ * sizeof(T));
269
0
    memcpy(new_slab->items_, self->slab_->items_, self->len_ * sizeof(T));
270
0
  }
271
34
  self->slab_ = new_slab;
272
34
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE7reserveEi
273
274
// Implements L[i] = item
275
// Note: Unlike Dict::set(), we don't need to specialize List::set() on T for
276
// StackRoots because it doesn't allocate.
277
template <typename T>
278
2.97k
void List<T>::set(int i, T item) {
279
2.97k
  if (i < 0) {
280
0
    i = len_ + i;
281
0
  }
282
283
2.97k
  assert(i >= 0);
284
0
  assert(i < capacity_);
285
286
0
  slab_->items_[i] = item;
287
2.97k
}
_ZN4ListIP3StrE3setEiS1_
Line
Count
Source
278
301
void List<T>::set(int i, T item) {
279
301
  if (i < 0) {
280
0
    i = len_ + i;
281
0
  }
282
283
301
  assert(i >= 0);
284
0
  assert(i < capacity_);
285
286
0
  slab_->items_[i] = item;
287
301
}
_ZN4ListIiE3setEii
Line
Count
Source
278
2.59k
void List<T>::set(int i, T item) {
279
2.59k
  if (i < 0) {
280
0
    i = len_ + i;
281
0
  }
282
283
2.59k
  assert(i >= 0);
284
0
  assert(i < capacity_);
285
286
0
  slab_->items_[i] = item;
287
2.59k
}
_ZN4ListIbE3setEib
Line
Count
Source
278
8
void List<T>::set(int i, T item) {
279
8
  if (i < 0) {
280
0
    i = len_ + i;
281
0
  }
282
283
8
  assert(i >= 0);
284
0
  assert(i < capacity_);
285
286
0
  slab_->items_[i] = item;
287
8
}
_ZN4ListIdE3setEid
Line
Count
Source
278
6
void List<T>::set(int i, T item) {
279
6
  if (i < 0) {
280
0
    i = len_ + i;
281
0
  }
282
283
6
  assert(i >= 0);
284
0
  assert(i < capacity_);
285
286
0
  slab_->items_[i] = item;
287
6
}
_ZN4ListIP6Tuple2IP3StriEE3setEiS4_
Line
Count
Source
278
2
void List<T>::set(int i, T item) {
279
2
  if (i < 0) {
280
0
    i = len_ + i;
281
0
  }
282
283
2
  assert(i >= 0);
284
0
  assert(i < capacity_);
285
286
0
  slab_->items_[i] = item;
287
2
}
_ZN4ListIP6Tuple2IiP3StrEE3setEiS4_
Line
Count
Source
278
3
void List<T>::set(int i, T item) {
279
3
  if (i < 0) {
280
0
    i = len_ + i;
281
0
  }
282
283
3
  assert(i >= 0);
284
0
  assert(i < capacity_);
285
286
0
  slab_->items_[i] = item;
287
3
}
_ZN4ListIPN10hnode_asdl5fieldEE3setEiS2_
Line
Count
Source
278
60
void List<T>::set(int i, T item) {
279
60
  if (i < 0) {
280
0
    i = len_ + i;
281
0
  }
282
283
60
  assert(i >= 0);
284
0
  assert(i < capacity_);
285
286
0
  slab_->items_[i] = item;
287
60
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE3setEiS2_
288
289
// Implements L[i]
290
template <typename T>
291
599
T List<T>::index_(int i) {
292
599
  if (i < 0) {
293
4
    int j = len_ + i;
294
4
    assert(j < len_);
295
0
    assert(j >= 0);
296
0
    return slab_->items_[j];
297
4
  }
298
299
595
  assert(i < len_);
300
0
  assert(i >= 0);
301
0
  return slab_->items_[i];
302
599
}
_ZN4ListIiE6index_Ei
Line
Count
Source
291
78
T List<T>::index_(int i) {
292
78
  if (i < 0) {
293
1
    int j = len_ + i;
294
1
    assert(j < len_);
295
0
    assert(j >= 0);
296
0
    return slab_->items_[j];
297
1
  }
298
299
77
  assert(i < len_);
300
0
  assert(i >= 0);
301
0
  return slab_->items_[i];
302
78
}
_ZN4ListIbE6index_Ei
Line
Count
Source
291
4
T List<T>::index_(int i) {
292
4
  if (i < 0) {
293
0
    int j = len_ + i;
294
0
    assert(j < len_);
295
0
    assert(j >= 0);
296
0
    return slab_->items_[j];
297
0
  }
298
299
4
  assert(i < len_);
300
0
  assert(i >= 0);
301
0
  return slab_->items_[i];
302
4
}
_ZN4ListIdE6index_Ei
Line
Count
Source
291
8
T List<T>::index_(int i) {
292
8
  if (i < 0) {
293
0
    int j = len_ + i;
294
0
    assert(j < len_);
295
0
    assert(j >= 0);
296
0
    return slab_->items_[j];
297
0
  }
298
299
8
  assert(i < len_);
300
0
  assert(i >= 0);
301
0
  return slab_->items_[i];
302
8
}
_ZN4ListIP3StrE6index_Ei
Line
Count
Source
291
509
T List<T>::index_(int i) {
292
509
  if (i < 0) {
293
3
    int j = len_ + i;
294
3
    assert(j < len_);
295
0
    assert(j >= 0);
296
0
    return slab_->items_[j];
297
3
  }
298
299
506
  assert(i < len_);
300
0
  assert(i >= 0);
301
0
  return slab_->items_[i];
302
509
}
303
304
// L.index(i) -- Python method
305
template <typename T>
306
int List<T>::index(T value) {
307
  int element_count = len(this);
308
  for (int i = 0; i < element_count; i++) {
309
    if (are_equal(slab_->items_[i], value)) {
310
      return i;
311
    }
312
  }
313
  throw Alloc<ValueError>();
314
}
315
316
// Should we have a separate API that doesn't return it?
317
// https://stackoverflow.com/questions/12600330/pop-back-return-value
318
template <typename T>
319
5
T List<T>::pop() {
320
5
  assert(len_ > 0);
321
0
  len_--;
322
5
  T result = slab_->items_[len_];
323
5
  slab_->items_[len_] = 0;  // zero for GC scan
324
5
  return result;
325
5
}
_ZN4ListIiE3popEv
Line
Count
Source
319
1
T List<T>::pop() {
320
1
  assert(len_ > 0);
321
0
  len_--;
322
1
  T result = slab_->items_[len_];
323
1
  slab_->items_[len_] = 0;  // zero for GC scan
324
1
  return result;
325
1
}
_ZN4ListIP3StrE3popEv
Line
Count
Source
319
4
T List<T>::pop() {
320
4
  assert(len_ > 0);
321
0
  len_--;
322
4
  T result = slab_->items_[len_];
323
4
  slab_->items_[len_] = 0;  // zero for GC scan
324
4
  return result;
325
4
}
326
327
// Used in osh/word_parse.py to remove from front
328
// TODO: Don't accept an arbitrary index?
329
template <typename T>
330
2
T List<T>::pop(int i) {
331
2
  assert(len_ > 0);
332
0
  assert(i == 0);  // only support popping the first item
333
334
0
  T result = index_(0);
335
2
  len_--;
336
337
  // Shift everything by one
338
2
  memmove(slab_->items_, slab_->items_ + 1, len_ * sizeof(T));
339
340
  /*
341
  for (int j = 0; j < len_; j++) {
342
    slab_->items_[j] = slab_->items_[j+1];
343
  }
344
  */
345
346
2
  slab_->items_[len_] = 0;  // zero for GC scan
347
2
  return result;
348
2
}
349
350
template <typename T>
351
3
void List<T>::clear() {
352
3
  memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
353
3
  len_ = 0;
354
3
}
_ZN4ListIiE5clearEv
Line
Count
Source
351
2
void List<T>::clear() {
352
2
  memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
353
2
  len_ = 0;
354
2
}
_ZN4ListIP3StrE5clearEv
Line
Count
Source
351
1
void List<T>::clear() {
352
1
  memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
353
1
  len_ = 0;
354
1
}
355
356
// Used in osh/string_ops.py
357
template <typename T>
358
4
void List<T>::reverse() {
359
8
  for (int i = 0; i < len_ / 2; ++i) {
360
    // log("swapping %d and %d", i, n-i);
361
4
    T tmp = slab_->items_[i];
362
4
    int j = len_ - 1 - i;
363
4
    slab_->items_[i] = slab_->items_[j];
364
4
    slab_->items_[j] = tmp;
365
4
  }
366
4
}
_ZN4ListIiE7reverseEv
Line
Count
Source
358
4
void List<T>::reverse() {
359
8
  for (int i = 0; i < len_ / 2; ++i) {
360
    // log("swapping %d and %d", i, n-i);
361
4
    T tmp = slab_->items_[i];
362
4
    int j = len_ - 1 - i;
363
4
    slab_->items_[i] = slab_->items_[j];
364
4
    slab_->items_[j] = tmp;
365
4
  }
366
4
}
Unexecuted instantiation: _ZN4ListIP3StrE7reverseEv
367
368
// Extend this list with multiple elements.
369
template <typename T>
370
4
void List<T>::extend(List<T>* other) {
371
4
  auto self = this;
372
4
  StackRoots _roots({&self, &other});
373
374
4
  int n = other->len_;
375
4
  int new_len = self->len_ + n;
376
4
  self->reserve(new_len);
377
378
16
  for (int i = 0; i < n; ++i) {
379
12
    self->set(self->len_ + i, other->slab_->items_[i]);
380
12
  }
381
4
  self->len_ = new_len;
382
4
}
_ZN4ListIiE6extendEPS0_
Line
Count
Source
370
4
void List<T>::extend(List<T>* other) {
371
4
  auto self = this;
372
4
  StackRoots _roots({&self, &other});
373
374
4
  int n = other->len_;
375
4
  int new_len = self->len_ + n;
376
4
  self->reserve(new_len);
377
378
16
  for (int i = 0; i < n; ++i) {
379
12
    self->set(self->len_ + i, other->slab_->items_[i]);
380
12
  }
381
4
  self->len_ = new_len;
382
4
}
Unexecuted instantiation: _ZN4ListIP3StrE6extendEPS2_
383
384
// Used by [[ a > b ]] and so forth
385
25
inline int str_cmp(Str* a, Str* b) {
386
25
  int len_a = len(a);
387
25
  int len_b = len(b);
388
389
25
  int min = std::min(len_a, len_b);
390
25
  if (min == 0) {
391
8
    return int_cmp(len_a, len_b);
392
8
  }
393
17
  int comp = memcmp(a->data_, b->data_, min);
394
17
  if (comp == 0) {
395
4
    return int_cmp(len_a, len_b);  // tiebreaker
396
4
  }
397
13
  return comp;
398
17
}
399
400
13
inline bool _cmp(Str* a, Str* b) {
401
13
  return str_cmp(a, b) < 0;
402
13
}
403
404
template <typename T>
405
3
void List<T>::sort() {
406
3
  std::sort(slab_->items_, slab_->items_ + len_, _cmp);
407
3
}
408
409
/* template <typename T> */
410
/* int len(const List<T>* L) { */
411
/*   return L->len_; */
412
/* } */
413
414
// TODO: mycpp can just generate the constructor instead?
415
// e.g. [None] * 3
416
template <typename T>
417
5
List<T>* list_repeat(T item, int times) {
418
5
  return NewList<T>(item, times);
419
5
}
_Z11list_repeatIP3StrEP4ListIT_ES3_i
Line
Count
Source
417
3
List<T>* list_repeat(T item, int times) {
418
3
  return NewList<T>(item, times);
419
3
}
_Z11list_repeatIbEP4ListIT_ES1_i
Line
Count
Source
417
2
List<T>* list_repeat(T item, int times) {
418
2
  return NewList<T>(item, times);
419
2
}
420
421
#if 0
422
template <typename T>
423
List<T>* NewList() {
424
  return Alloc<List<T>>();
425
}
426
427
// Literal ['foo', 'bar']
428
template <typename T>
429
List<T>* NewList(std::initializer_list<T> init) {
430
  auto self = Alloc<List<T>>();
431
  StackRoots _roots({&self});
432
433
  int n = init.size();
434
  self->reserve(n);
435
436
  int i = 0;
437
  for (auto item : init) {
438
    self->set(i, item);
439
    ++i;
440
  }
441
  self->len_ = n;
442
  return self;
443
}
444
445
// ['foo'] * 3
446
template <typename T>
447
List<T>* NewList(T item, int times) {
448
  auto self = Alloc<List<T>>();
449
  StackRoots _roots({&self});
450
451
  self->reserve(times);
452
  self->len_ = times;
453
  for (int i = 0; i < times; ++i) {
454
    self->set(i, item);
455
  }
456
  return self;
457
}
458
#endif
459
460
// e.g. 'a' in ['a', 'b', 'c']
461
template <typename T>
462
19
inline bool list_contains(List<T>* haystack, T needle) {
463
  // StackRoots _roots({&haystack, &needle});  // doesn't allocate
464
465
19
  int n = len(haystack);
466
43
  for (int i = 0; i < n; ++i) {
467
35
    if (are_equal(haystack->index_(i), needle)) {
468
11
      return true;
469
11
    }
470
35
  }
471
8
  return false;
472
19
}
_Z13list_containsIP3StrEbP4ListIT_ES3_
Line
Count
Source
462
9
inline bool list_contains(List<T>* haystack, T needle) {
463
  // StackRoots _roots({&haystack, &needle});  // doesn't allocate
464
465
9
  int n = len(haystack);
466
20
  for (int i = 0; i < n; ++i) {
467
16
    if (are_equal(haystack->index_(i), needle)) {
468
5
      return true;
469
5
    }
470
16
  }
471
4
  return false;
472
9
}
_Z13list_containsIiEbP4ListIT_ES1_
Line
Count
Source
462
6
inline bool list_contains(List<T>* haystack, T needle) {
463
  // StackRoots _roots({&haystack, &needle});  // doesn't allocate
464
465
6
  int n = len(haystack);
466
13
  for (int i = 0; i < n; ++i) {
467
11
    if (are_equal(haystack->index_(i), needle)) {
468
4
      return true;
469
4
    }
470
11
  }
471
2
  return false;
472
6
}
_Z13list_containsIdEbP4ListIT_ES1_
Line
Count
Source
462
4
inline bool list_contains(List<T>* haystack, T needle) {
463
  // StackRoots _roots({&haystack, &needle});  // doesn't allocate
464
465
4
  int n = len(haystack);
466
10
  for (int i = 0; i < n; ++i) {
467
8
    if (are_equal(haystack->index_(i), needle)) {
468
2
      return true;
469
2
    }
470
8
  }
471
2
  return false;
472
4
}
473
474
template <typename V>
475
1
List<Str*>* sorted(Dict<Str*, V>* d) {
476
1
  auto keys = d->keys();
477
1
  keys->sort();
478
1
  return keys;
479
1
}
480
481
// list(L) copies the list
482
template <typename T>
483
1
List<T>* list(List<T>* other) {
484
1
  auto result = NewList<T>();
485
1
  result->extend(other);
486
1
  return result;
487
1
}
488
489
#define GLOBAL_LIST(T, N, name, array)                                      \
490
  GlobalSlab<T, N> _slab_##name = {Tag::Global, 0, kZeroMask, kNoObjLen,    \
491
                                   array};                                  \
492
  GlobalList<T, N> _list_##name = {Tag::Global, 0, kZeroMask,    kNoObjLen, \
493
                                   N,           N, &_slab_##name};          \
494
  List<T>* name = reinterpret_cast<List<T>*>(&_list_##name);
495
496
template <class T>
497
class ListIter {
498
 public:
499
112
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
500
    // We need this because ListIter is directly on the stack, and L_ could be
501
    // moved during iteration.
502
112
    gHeap.PushRoot(reinterpret_cast<Obj**>(&L_));
503
112
  }
_ZN8ListIterIiEC2EP4ListIiE
Line
Count
Source
499
6
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
500
    // We need this because ListIter is directly on the stack, and L_ could be
501
    // moved during iteration.
502
6
    gHeap.PushRoot(reinterpret_cast<Obj**>(&L_));
503
6
  }
_ZN8ListIterIP3StrEC2EP4ListIS1_E
Line
Count
Source
499
23
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
500
    // We need this because ListIter is directly on the stack, and L_ could be
501
    // moved during iteration.
502
23
    gHeap.PushRoot(reinterpret_cast<Obj**>(&L_));
503
23
  }
_ZN8ListIterIP6Tuple2IP3StriEEC2EP4ListIS4_E
Line
Count
Source
499
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
500
    // We need this because ListIter is directly on the stack, and L_ could be
501
    // moved during iteration.
502
1
    gHeap.PushRoot(reinterpret_cast<Obj**>(&L_));
503
1
  }
_ZN8ListIterIP6Tuple2IiP3StrEEC2EP4ListIS4_E
Line
Count
Source
499
2
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
500
    // We need this because ListIter is directly on the stack, and L_ could be
501
    // moved during iteration.
502
2
    gHeap.PushRoot(reinterpret_cast<Obj**>(&L_));
503
2
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEEC2EP4ListIS2_E
_ZN8ListIterIPN10hnode_asdl5fieldEEC2EP4ListIS2_E
Line
Count
Source
499
79
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
500
    // We need this because ListIter is directly on the stack, and L_ could be
501
    // moved during iteration.
502
79
    gHeap.PushRoot(reinterpret_cast<Obj**>(&L_));
503
79
  }
_ZN8ListIterIbEC2EP4ListIbE
Line
Count
Source
499
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
500
    // We need this because ListIter is directly on the stack, and L_ could be
501
    // moved during iteration.
502
1
    gHeap.PushRoot(reinterpret_cast<Obj**>(&L_));
503
1
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5speckEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEEC2EP4ListIS2_E
504
112
  ~ListIter() {
505
112
    gHeap.PopRoot();
506
112
  }
_ZN8ListIterIiED2Ev
Line
Count
Source
504
6
  ~ListIter() {
505
6
    gHeap.PopRoot();
506
6
  }
_ZN8ListIterIP3StrED2Ev
Line
Count
Source
504
23
  ~ListIter() {
505
23
    gHeap.PopRoot();
506
23
  }
_ZN8ListIterIP6Tuple2IP3StriEED2Ev
Line
Count
Source
504
1
  ~ListIter() {
505
1
    gHeap.PopRoot();
506
1
  }
_ZN8ListIterIP6Tuple2IiP3StrEED2Ev
Line
Count
Source
504
2
  ~ListIter() {
505
2
    gHeap.PopRoot();
506
2
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEED2Ev
_ZN8ListIterIPN10hnode_asdl5fieldEED2Ev
Line
Count
Source
504
79
  ~ListIter() {
505
79
    gHeap.PopRoot();
506
79
  }
_ZN8ListIterIbED2Ev
Line
Count
Source
504
1
  ~ListIter() {
505
1
    gHeap.PopRoot();
506
1
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5speckEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEED2Ev
507
242
  void Next() {
508
242
    i_++;
509
242
  }
_ZN8ListIterIiE4NextEv
Line
Count
Source
507
19
  void Next() {
508
19
    i_++;
509
19
  }
_ZN8ListIterIP3StrE4NextEv
Line
Count
Source
507
97
  void Next() {
508
97
    i_++;
509
97
  }
_ZN8ListIterIP6Tuple2IP3StriEE4NextEv
Line
Count
Source
507
2
  void Next() {
508
2
    i_++;
509
2
  }
_ZN8ListIterIP6Tuple2IiP3StrEE4NextEv
Line
Count
Source
507
4
  void Next() {
508
4
    i_++;
509
4
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4NextEv
_ZN8ListIterIPN10hnode_asdl5fieldEE4NextEv
Line
Count
Source
507
118
  void Next() {
508
118
    i_++;
509
118
  }
_ZN8ListIterIbE4NextEv
Line
Count
Source
507
2
  void Next() {
508
2
    i_++;
509
2
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5speckEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE4NextEv
510
354
  bool Done() {
511
    // "unsigned size_t was a mistake"
512
354
    return i_ >= static_cast<int>(L_->len_);
513
354
  }
_ZN8ListIterIiE4DoneEv
Line
Count
Source
510
25
  bool Done() {
511
    // "unsigned size_t was a mistake"
512
25
    return i_ >= static_cast<int>(L_->len_);
513
25
  }
_ZN8ListIterIP3StrE4DoneEv
Line
Count
Source
510
120
  bool Done() {
511
    // "unsigned size_t was a mistake"
512
120
    return i_ >= static_cast<int>(L_->len_);
513
120
  }
_ZN8ListIterIP6Tuple2IP3StriEE4DoneEv
Line
Count
Source
510
3
  bool Done() {
511
    // "unsigned size_t was a mistake"
512
3
    return i_ >= static_cast<int>(L_->len_);
513
3
  }
_ZN8ListIterIP6Tuple2IiP3StrEE4DoneEv
Line
Count
Source
510
6
  bool Done() {
511
    // "unsigned size_t was a mistake"
512
6
    return i_ >= static_cast<int>(L_->len_);
513
6
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4DoneEv
_ZN8ListIterIPN10hnode_asdl5fieldEE4DoneEv
Line
Count
Source
510
197
  bool Done() {
511
    // "unsigned size_t was a mistake"
512
197
    return i_ >= static_cast<int>(L_->len_);
513
197
  }
_ZN8ListIterIbE4DoneEv
Line
Count
Source
510
3
  bool Done() {
511
    // "unsigned size_t was a mistake"
512
3
    return i_ >= static_cast<int>(L_->len_);
513
3
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5speckEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE4DoneEv
514
266
  T Value() {
515
266
    return L_->slab_->items_[i_];
516
266
  }
_ZN8ListIterIiE5ValueEv
Line
Count
Source
514
19
  T Value() {
515
19
    return L_->slab_->items_[i_];
516
19
  }
_ZN8ListIterIP3StrE5ValueEv
Line
Count
Source
514
98
  T Value() {
515
98
    return L_->slab_->items_[i_];
516
98
  }
_ZN8ListIterIP6Tuple2IP3StriEE5ValueEv
Line
Count
Source
514
2
  T Value() {
515
2
    return L_->slab_->items_[i_];
516
2
  }
_ZN8ListIterIP6Tuple2IiP3StrEE5ValueEv
Line
Count
Source
514
4
  T Value() {
515
4
    return L_->slab_->items_[i_];
516
4
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE5ValueEv
_ZN8ListIterIPN10hnode_asdl5fieldEE5ValueEv
Line
Count
Source
514
141
  T Value() {
515
141
    return L_->slab_->items_[i_];
516
141
  }
_ZN8ListIterIbE5ValueEv
Line
Count
Source
514
2
  T Value() {
515
2
    return L_->slab_->items_[i_];
516
2
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5speckEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE5ValueEv
517
518
 private:
519
  List<T>* L_;
520
  int i_;
521
};
522
523
// TODO: Does using pointers rather than indices make this more efficient?
524
template <class T>
525
class ReverseListIter {
526
 public:
527
4
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
528
4
  }
_ZN15ReverseListIterIiEC2EP4ListIiE
Line
Count
Source
527
2
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
528
2
  }
_ZN15ReverseListIterIP3StrEC2EP4ListIS1_E
Line
Count
Source
527
1
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
528
1
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEEC2EP4ListIS4_E
Line
Count
Source
527
1
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
528
1
  }
529
10
  void Next() {
530
10
    i_--;
531
10
  }
_ZN15ReverseListIterIiE4NextEv
Line
Count
Source
529
6
  void Next() {
530
6
    i_--;
531
6
  }
_ZN15ReverseListIterIP3StrE4NextEv
Line
Count
Source
529
2
  void Next() {
530
2
    i_--;
531
2
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE4NextEv
Line
Count
Source
529
2
  void Next() {
530
2
    i_--;
531
2
  }
532
14
  bool Done() {
533
14
    return i_ < 0;
534
14
  }
_ZN15ReverseListIterIiE4DoneEv
Line
Count
Source
532
8
  bool Done() {
533
8
    return i_ < 0;
534
8
  }
_ZN15ReverseListIterIP3StrE4DoneEv
Line
Count
Source
532
3
  bool Done() {
533
3
    return i_ < 0;
534
3
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE4DoneEv
Line
Count
Source
532
3
  bool Done() {
533
3
    return i_ < 0;
534
3
  }
535
10
  T Value() {
536
10
    return L_->slab_->items_[i_];
537
10
  }
_ZN15ReverseListIterIiE5ValueEv
Line
Count
Source
535
6
  T Value() {
536
6
    return L_->slab_->items_[i_];
537
6
  }
_ZN15ReverseListIterIP3StrE5ValueEv
Line
Count
Source
535
2
  T Value() {
536
2
    return L_->slab_->items_[i_];
537
2
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE5ValueEv
Line
Count
Source
535
2
  T Value() {
536
2
    return L_->slab_->items_[i_];
537
2
  }
538
539
 private:
540
  List<T>* L_;
541
  int i_;
542
};
543
544
#endif  // MYCPP_GC_LIST_H