GCC Middle and Back End API Reference
pretty-print-markup.h
Go to the documentation of this file.
1/* Copyright (C) 2024 Free Software Foundation, Inc.
2 Contributed by David Malcolm <dmalcolm@redhat.com>
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_PRETTY_PRINT_MARKUP_H
21#define GCC_PRETTY_PRINT_MARKUP_H
22
23#include "diagnostic-color.h"
24
25class pp_token_list;
26
27namespace pp_markup {
28
30{
31public:
33 bool &quoted,
34 pp_token_list *formatted_token_list)
35 : m_pp (pp),
36 m_buf (*pp_buffer (&pp)),
37 m_quoted (quoted),
38 m_formatted_token_list (formatted_token_list)
39 {
40 }
41
42 void begin_quote ();
43 void end_quote ();
44
45 void begin_highlight_color (const char *color_name);
46 void end_highlight_color ();
47
48 void push_back_any_text ();
49
52 bool &m_quoted;
54};
55
56/* Abstract base class for use in pp_format for handling "%e".
57 This can add arbitrary content to the buffer being constructed, and
58 isolates the non-typesafe part of the formatting call in one place. */
59
61{
62public:
63 virtual ~element () {}
64 virtual void add_to_phase_2 (context &ctxt) = 0;
65
66protected:
67 element () {}
68
69private:
71};
72
73/* Concrete subclass: handle "%e" by printing a comma-separated list
74 of quoted strings. */
75
77{
78public:
80 : m_strings (strings)
81 {
82 }
83
84 void add_to_phase_2 (context &ctxt) final override;
85
86private:
88};
89
90} // namespace pp_markup
91
93{
94public:
95 pp_element_quoted_string (const char *text,
96 const char *highlight_color = nullptr)
97 : m_text (text),
98 m_highlight_color (highlight_color)
99 {}
100
101 void add_to_phase_2 (pp_markup::context &ctxt) final override
102 {
103 ctxt.begin_quote ();
105 ctxt.begin_highlight_color (m_highlight_color);
106 pp_string (&ctxt.m_pp, m_text);
108 ctxt.end_highlight_color ();
109 ctxt.end_quote ();
110 }
111
112private:
113 const char *m_text;
114 const char *m_highlight_color;
115};
116
117#endif /* GCC_PRETTY_PRINT_MARKUP_H */
Definition vec.h:1656
Definition pretty-print.h:84
Definition pretty-print-markup.h:93
pp_element_quoted_string(const char *text, const char *highlight_color=nullptr)
Definition pretty-print-markup.h:95
const char * m_highlight_color
Definition pretty-print-markup.h:114
const char * m_text
Definition pretty-print-markup.h:113
void add_to_phase_2(pp_markup::context &ctxt) final override
Definition pretty-print-markup.h:101
Definition pretty-print-markup.h:77
void add_to_phase_2(context &ctxt) final override
Definition pretty-print.cc:3205
comma_separated_quoted_strings(const auto_vec< const char * > &strings)
Definition pretty-print-markup.h:79
const auto_vec< const char * > & m_strings
Definition pretty-print-markup.h:87
Definition pretty-print-markup.h:30
void end_highlight_color()
Definition pretty-print.cc:3185
pretty_printer & m_pp
Definition pretty-print-markup.h:50
bool & m_quoted
Definition pretty-print-markup.h:52
void begin_highlight_color(const char *color_name)
Definition pretty-print.cc:3174
pp_token_list * m_formatted_token_list
Definition pretty-print-markup.h:53
void end_quote()
Definition pretty-print.cc:3161
context(pretty_printer &pp, bool &quoted, pp_token_list *formatted_token_list)
Definition pretty-print-markup.h:32
output_buffer & m_buf
Definition pretty-print-markup.h:51
void begin_quote()
Definition pretty-print.cc:3151
void push_back_any_text()
Definition pretty-print.cc:3195
Definition pretty-print-markup.h:61
virtual ~element()
Definition pretty-print-markup.h:63
DISABLE_COPY_AND_ASSIGN(element)
element()
Definition pretty-print-markup.h:67
virtual void add_to_phase_2(context &ctxt)=0
Definition pretty-print-format-impl.h:300
Definition pretty-print.h:241
Definition coretypes.h:172
void pp_string(pretty_printer *pp, const char *str)
Definition pretty-print.cc:2653
output_buffer *& pp_buffer(pretty_printer *pp)
Definition pretty-print.h:393