Line data Source code
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 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along 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 :
24 : #include "pretty-print-format-impl.h"
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 :
31 : class pretty_print_token_buffer
32 : {
33 : public:
34 : pretty_print_token_buffer ();
35 : pretty_print_token_buffer (const char *gmsgid,
36 : va_list *args);
37 :
38 : pretty_print_token_buffer (const pretty_print_token_buffer &) = delete;
39 : pretty_print_token_buffer (pretty_print_token_buffer &&);
40 :
41 164 : ~pretty_print_token_buffer () = default;
42 :
43 : std::string to_string () const;
44 :
45 0 : void dump (FILE *out) const { m_tokens.dump (out); }
46 0 : void DEBUG_FUNCTION dump () const { dump (stderr); }
47 :
48 : std::unique_ptr<auto_obstack> m_obstack;
49 : pp_token_list m_tokens;
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 :
55 8 : class pp_token_buffer_element : public pp_element
56 : {
57 : public:
58 8 : pp_token_buffer_element (const pretty_print_token_buffer &token_buf)
59 8 : : m_token_buf (token_buf)
60 : {
61 : }
62 :
63 : void
64 : add_to_phase_2 (pp_markup::context &ctxt) final override;
65 :
66 : private:
67 : const pretty_print_token_buffer &m_token_buf;
68 : };
69 :
70 : #endif /* GCC_PRETTY_PRINT_TOKEN_BUFFER_H */
|