GCC Middle and Back End API Reference
pretty-print-markup.h
Go to the documentation of this file.
1/* Copyright (C) 2024-2025 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 "diagnostics/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 begin_url (const char *url);
49 void end_url ();
50
51 void add_event_id (diagnostic_event_id_t event_id);
52
53 void push_back_any_text ();
54
57 bool &m_quoted;
59};
60
61/* Abstract base class for use in pp_format for handling "%e".
62 This can add arbitrary content to the buffer being constructed, and
63 isolates the non-typesafe part of the formatting call in one place. */
64
66{
67public:
68 virtual ~element () {}
69 virtual void add_to_phase_2 (context &ctxt) = 0;
70
71protected:
72 element () {}
73
74private:
76};
77
78/* Concrete subclass: handle "%e" by printing a comma-separated list
79 of quoted strings. */
80
82{
83public:
85 : m_strings (strings)
86 {
87 }
88
89 void add_to_phase_2 (context &ctxt) final override;
90
91private:
93};
94
95} // namespace pp_markup
96
98{
99public:
100 pp_element_quoted_string (const char *text,
101 const char *highlight_color = nullptr)
102 : m_text (text),
103 m_highlight_color (highlight_color)
104 {}
105
106 void add_to_phase_2 (pp_markup::context &ctxt) final override
107 {
108 ctxt.begin_quote ();
110 ctxt.begin_highlight_color (m_highlight_color);
111 pp_string (&ctxt.m_pp, m_text);
113 ctxt.end_highlight_color ();
114 ctxt.end_quote ();
115 }
116
117private:
118 const char *m_text;
119 const char *m_highlight_color;
120};
121
122#endif /* GCC_PRETTY_PRINT_MARKUP_H */
Definition vec.h:1667
Definition event-id.h:39
Definition pretty-print.h:84
pp_element_quoted_string(const char *text, const char *highlight_color=nullptr)
Definition pretty-print-markup.h:100
const char * m_highlight_color
Definition pretty-print-markup.h:119
const char * m_text
Definition pretty-print-markup.h:118
void add_to_phase_2(pp_markup::context &ctxt) final override
Definition pretty-print-markup.h:106
void add_to_phase_2(context &ctxt) final override
Definition pretty-print.cc:3218
comma_separated_quoted_strings(const auto_vec< const char * > &strings)
Definition pretty-print-markup.h:84
const auto_vec< const char * > & m_strings
Definition pretty-print-markup.h:92
Definition pretty-print-markup.h:30
void end_highlight_color()
Definition pretty-print.cc:3175
pretty_printer & m_pp
Definition pretty-print-markup.h:55
bool & m_quoted
Definition pretty-print-markup.h:57
void begin_highlight_color(const char *color_name)
Definition pretty-print.cc:3164
void add_event_id(diagnostic_event_id_t event_id)
Definition pretty-print.cc:3200
pp_token_list * m_formatted_token_list
Definition pretty-print-markup.h:58
void end_quote()
Definition pretty-print.cc:3151
context(pretty_printer &pp, bool &quoted, pp_token_list *formatted_token_list)
Definition pretty-print-markup.h:32
void begin_url(const char *url)
Definition pretty-print.cc:3185
output_buffer & m_buf
Definition pretty-print-markup.h:56
void begin_quote()
Definition pretty-print.cc:3141
void end_url()
Definition pretty-print.cc:3193
void push_back_any_text()
Definition pretty-print.cc:3208
virtual ~element()
Definition pretty-print-markup.h:68
DISABLE_COPY_AND_ASSIGN(element)
element()
Definition pretty-print-markup.h:72
virtual void add_to_phase_2(context &ctxt)=0
Definition pretty-print-format-impl.h:300
Definition pretty-print.h:241
pp_markup::element pp_element
Definition coretypes.h:175
Definition coretypes.h:174
void pp_string(pretty_printer *pp, const char *str)
Definition pretty-print.cc:2638
output_buffer *& pp_buffer(pretty_printer *pp)
Definition pretty-print.h:398