GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc

Introduce pretty-print-token-buffer.{cc,h}

Refactors diagnostic message handling by introducing pretty-print-token-buffer, improving token capture during pretty-printing.

This commit introduces pretty-print-token-buffer.{cc,h} to better capture tokens from a pretty-print operation and reimplements diagnostic_message_buffer as a subclass of pretty_print_token_buffer. This refactoring centralizes token handling and provides a mechanism for replaying tokens into another pretty-print, using ‘%e’. The change impacts how diagnostic messages are constructed and formatted.

In Details

This commit introduces pretty-print-token-buffer.{cc,h}, moving the implementation of diagnostic_message_buffer from libdiagnostics to this new location. A new class pp_token_buffer_element replays tokens in a pretty_print_token_buffer into another pretty-print using '%e'. Key files affected include libgdiagnostics.cc and the newly added pretty-print-token-buffer.{cc,h}.

For Context

This commit introduces a new component, pretty-print-token-buffer, to GCC. This component allows capturing the tokens produced during pretty-printing (formatting code for readability). By moving the diagnostic message buffer implementation to this new component, the compiler can more effectively replay these tokens to create richer diagnostic messages. This enhances the compiler's ability to provide detailed and context-aware feedback to developers.

Filed Under: refactoringdiagnosticspretty-printing