GCC Middle and Back End API Reference
pretty-print-token-buffer.h
Go to the documentation of this file.
1/* Capturing the results of pretty_print for later playback.
2 Copyright (C) 2023-2026 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_PRETTY_PRINT_TOKEN_BUFFER_H
22#define GCC_PRETTY_PRINT_TOKEN_BUFFER_H
23
25#include "auto-obstack.h"
26#include "pretty-print-markup.h"
27
28/* A class for capturing the results of pretty-printing as tokens,
29 potentially for playback into a different pretty-printer. */
30
32{
33public:
35 pretty_print_token_buffer (const char *gmsgid,
36 va_list *args);
37
40
42
43 std::string to_string () const;
44
45 void dump (FILE *out) const { m_tokens.dump (out); }
46 void DEBUG_FUNCTION dump () const { dump (stderr); }
47
48 std::unique_ptr<auto_obstack> m_obstack;
50};
51
52/* A pp_element subclass for use with "%e" that replays the buffered tokens
53 from TOKEN_BUF in another formatting call. */
54
56{
57public:
59 : m_token_buf (token_buf)
60 {
61 }
62
63 void
64 add_to_phase_2 (pp_markup::context &ctxt) final override;
65
66private:
68};
69
70#endif /* GCC_PRETTY_PRINT_TOKEN_BUFFER_H */
Definition pretty-print-markup.h:30
const pretty_print_token_buffer & m_token_buf
Definition pretty-print-token-buffer.h:67
void add_to_phase_2(pp_markup::context &ctxt) final override
Definition pretty-print-token-buffer.cc:210
pp_token_buffer_element(const pretty_print_token_buffer &token_buf)
Definition pretty-print-token-buffer.h:58
Definition pretty-print-format-impl.h:300
Definition pretty-print-token-buffer.h:32
void DEBUG_FUNCTION dump() const
Definition pretty-print-token-buffer.h:46
std::string to_string() const
Definition pretty-print-token-buffer.cc:153
pretty_print_token_buffer(const pretty_print_token_buffer &)=delete
pp_token_list m_tokens
Definition pretty-print-token-buffer.h:49
pretty_print_token_buffer()
Definition pretty-print-token-buffer.cc:121
std::unique_ptr< auto_obstack > m_obstack
Definition pretty-print-token-buffer.h:48
void dump(FILE *out) const
Definition pretty-print-token-buffer.h:45
~pretty_print_token_buffer()=default
pp_markup::element pp_element
Definition coretypes.h:177
#define DEBUG_FUNCTION
Definition system.h:1191