|
14 | 14 | #include <quick-lint-js/location.h> |
15 | 15 | #include <quick-lint-js/monotonic-allocator.h> |
16 | 16 | #include <quick-lint-js/narrow-cast.h> |
| 17 | +#include <quick-lint-js/optional.h> |
17 | 18 | #include <quick-lint-js/padded-string.h> |
18 | 19 | #include <quick-lint-js/token.h> |
19 | 20 | #include <quick-lint-js/utf-8.h> |
@@ -316,27 +317,28 @@ struct lexer_transaction { |
316 | 317 | const char8* old_input, |
317 | 318 | diag_reporter** diag_reporter_pointer, |
318 | 319 | allocator_type* allocator) |
319 | | - : allocator_rewind(allocator), |
| 320 | + : allocator_rewind(allocator->prepare_for_rewind()), |
320 | 321 | old_last_token(old_last_token), |
321 | 322 | old_last_last_token_end(old_last_last_token_end), |
322 | 323 | old_input(old_input), |
323 | | - reporter(allocator), |
| 324 | + reporter(std::in_place, allocator), |
324 | 325 | old_diag_reporter( |
325 | | - std::exchange(*diag_reporter_pointer, &this->reporter)) {} |
| 326 | + std::exchange(*diag_reporter_pointer, get(this->reporter))) {} |
326 | 327 |
|
327 | 328 | // Don't allow copying a transaction. lexer::diag_reporter_ might point to |
328 | 329 | // lexer_transaction::diag_reporter. |
329 | 330 | lexer_transaction(const lexer_transaction&) = delete; |
330 | 331 | lexer_transaction& operator=(const lexer_transaction&) = delete; |
331 | 332 |
|
332 | 333 | // Rewinds memory allocated by 'reporter'. Must be constructed before |
333 | | - // 'reporter' (thus destructed after 'reporter'). |
334 | | - allocator_type::conditional_rewind_guard allocator_rewind; |
| 334 | + // 'reporter' is constructed. 'allocator_type::rewind' must be called before |
| 335 | + // 'reporter' is destructed. |
| 336 | + allocator_type::rewind_state allocator_rewind; |
335 | 337 |
|
336 | 338 | token old_last_token; |
337 | 339 | const char8* old_last_last_token_end; |
338 | 340 | const char8* old_input; |
339 | | - buffering_diag_reporter reporter; |
| 341 | + std::optional<buffering_diag_reporter> reporter; |
340 | 342 | diag_reporter* old_diag_reporter; |
341 | 343 | }; |
342 | 344 | } |
|
0 commit comments