18
18
#include < quick-lint-js/fe/source-code-span.h>
19
19
#include < quick-lint-js/fe/token.h>
20
20
#include < quick-lint-js/port/char8.h>
21
+ #include < quick-lint-js/port/span.h>
21
22
#include < quick-lint-js/port/unreachable.h>
22
23
#include < quick-lint-js/port/warning.h>
23
24
#include < quick-lint-js/util/narrow-cast.h>
@@ -153,8 +154,9 @@ struct object_property_value_pair {
153
154
154
155
class expression_arena {
155
156
public:
156
- template <class >
157
- class array_ptr ;
157
+ // TODO(strager): Inline.
158
+ template <class T >
159
+ using array_ptr = span<const T>;
158
160
159
161
using buffering_visitor_ptr = buffering_visitor *;
160
162
@@ -301,41 +303,6 @@ Derived *expression_cast(expression *p) noexcept {
301
303
template <class Derived , class Expression >
302
304
Derived *expression_cast (Expression *) noexcept = delete ;
303
305
304
- template <class T >
305
- class expression_arena ::array_ptr {
306
- public:
307
- explicit array_ptr () noexcept : data_(nullptr ), size_(0 ) {}
308
-
309
- explicit array_ptr (const T *data, int size) noexcept
310
- : data_(data), size_(size) {}
311
-
312
- explicit array_ptr (const T *begin, const T *end) noexcept
313
- : data_(begin), size_(narrow_cast<int >(end - begin)) {}
314
-
315
- T operator [](int index) const noexcept {
316
- QLJS_ASSERT (index >= 0 );
317
- QLJS_ASSERT (index < this ->size ());
318
- return this ->data_ [index];
319
- }
320
-
321
- T front () const noexcept { return (*this )[0 ]; }
322
-
323
- T back () const noexcept { return (*this )[this ->size () - 1 ]; }
324
-
325
- const T *data () const noexcept { return this ->data_ ; }
326
-
327
- int size () const noexcept { return this ->size_ ; }
328
-
329
- const T *begin () const noexcept { return this ->data_ ; }
330
- const T *end () const noexcept { return this ->data_ + this ->size_ ; }
331
-
332
- bool empty () const noexcept { return this ->size () == 0 ; }
333
-
334
- private:
335
- const T *data_;
336
- int size_;
337
- };
338
-
339
306
template <class Expression , class ... Args>
340
307
expression *expression_arena::make_expression (Args &&... args) {
341
308
expression *result (this ->allocate <Expression>(std::forward<Args>(args)...));
@@ -348,7 +315,7 @@ inline expression_arena::array_ptr<T> expression_arena::make_array(
348
315
bump_vector<T, monotonic_allocator> &&elements) {
349
316
QLJS_ASSERT (elements.get_allocator () == &this ->allocator_ );
350
317
// NOTE(strager): Adopt the pointer instead of copying.
351
- array_ptr<T> result (elements.data (), narrow_cast< int >( elements.size () ));
318
+ array_ptr<T> result (elements.data (), elements.size ());
352
319
elements.release ();
353
320
return result;
354
321
}
@@ -357,7 +324,7 @@ template <class T>
357
324
inline expression_arena::array_ptr<T> expression_arena::make_array (T *begin,
358
325
T *end) {
359
326
T *result_begin = this ->allocate_array_move (begin, end);
360
- int size = narrow_cast<int >(end - begin);
327
+ span_size size = narrow_cast<span_size >(end - begin);
361
328
return array_ptr<T>(result_begin, size);
362
329
}
363
330
@@ -1161,7 +1128,8 @@ inline token_type expression::variable_identifier_token_type() const noexcept {
1161
1128
}
1162
1129
1163
1130
inline int expression::child_count () const noexcept {
1164
- return this ->children ().size ();
1131
+ // TODO(strager): Remove this cast.
1132
+ return narrow_cast<int >(this ->children ().size ());
1165
1133
}
1166
1134
1167
1135
inline expression *expression::child (int index) const noexcept {
@@ -1286,7 +1254,8 @@ inline expression *expression::without_paren() const noexcept {
1286
1254
inline int expression::object_entry_count () const noexcept {
1287
1255
switch (this ->kind_ ) {
1288
1256
case expression_kind::object:
1289
- return static_cast <const expression::object *>(this )->entries_ .size ();
1257
+ // TODO(strager): Remove this cast.
1258
+ return narrow_cast<int >(static_cast <const expression::object *>(this )->entries_ .size ());
1290
1259
1291
1260
default :
1292
1261
QLJS_UNEXPECTED_EXPRESSION_KIND ();
0 commit comments