GCC Middle and Back End API Reference
diagnostic-buffer.h
Go to the documentation of this file.
1/* Support for buffering diagnostics before flushing them to output format.
2 Copyright (C) 2024-2025 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_DIAGNOSTIC_BUFFER_H
22#define GCC_DIAGNOSTIC_BUFFER_H
23
24#include "diagnostic.h"
25
29
30/* Class representing a buffer of zero or more diagnostics that
31 have been reported to a diagnostic_context, but which haven't
32 yet been flushed.
33
34 A diagnostic_buffer can be:
35
36 * flushed to the diagnostic_context, which issues
37 the diagnostics within the buffer to the output format
38 and checks for limits such as -fmax-errors=, or
39
40 * moved to another diagnostic_buffer, which moves the diagnostics
41 within the first buffer to the other buffer, appending them after any
42 existing diagnostics within the destination buffer, emptying the
43 source buffer, or
44
45 * cleared, which discards any diagnostics within the buffer
46 without issuing them to the output format.
47
48 Since a buffer needs to contain output-format-specific data,
49 it's not possible to change the output format of the
50 diagnostic_context once any buffers are non-empty.
51
52 To simplify implementing output formats, it's not possible
53 to change buffering on a diagnostic_context whilst within a
54 diagnostic group. */
55
57{
58 public:
59 friend class diagnostic_context;
60
63
64 void dump (FILE *out, int indent) const;
65 void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
66
68 {
69 return m_diagnostic_counters.get_count (kind);
70 }
71
72 bool empty_p () const;
73
74 void move_to (diagnostic_buffer &dest);
75
76 private:
78
81
82 /* The number of buffered diagnostics of each kind. */
84};
85
86/* Implementation detail of diagnostic_buffer.
87
88 Abstract base class describing how to represent zero of more
89 buffered diagnostics for a particular diagnostic_output_format
90 (e.g. text vs SARIF).
91
92 Each diagnostic_output_format subclass should implement its own
93 subclass for handling diagnostic_buffer. */
94
96{
97public:
99
100 virtual void dump (FILE *out, int indent) const = 0;
101 void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
102
103 virtual bool empty_p () const = 0;
104 virtual void move_to (diagnostic_per_format_buffer &dest) = 0;
105 virtual void clear () = 0;
106 virtual void flush () = 0;
107};
108
109#endif /* ! GCC_DIAGNOSTIC_BUFFER_H */
Definition vec.h:1656
Definition diagnostic-buffer.h:57
void DEBUG_FUNCTION dump() const
Definition diagnostic-buffer.h:65
bool empty_p() const
Definition diagnostic.cc:1994
~diagnostic_buffer()
Definition diagnostic.cc:1971
void move_to(diagnostic_buffer &dest)
Definition diagnostic.cc:2004
diagnostic_context & m_ctxt
Definition diagnostic-buffer.h:79
auto_vec< diagnostic_per_format_buffer * > * m_per_format_buffers
Definition diagnostic-buffer.h:80
diagnostic_buffer(diagnostic_context &ctxt)
Definition diagnostic.cc:1965
int diagnostic_count(diagnostic_t kind) const
Definition diagnostic-buffer.h:67
void ensure_per_format_buffers()
Definition diagnostic.cc:2042
diagnostic_counters m_diagnostic_counters
Definition diagnostic-buffer.h:83
Definition diagnostic.h:506
Definition diagnostic-format.h:33
Definition diagnostic-buffer.h:96
virtual void move_to(diagnostic_per_format_buffer &dest)=0
virtual ~diagnostic_per_format_buffer()
Definition diagnostic-buffer.h:98
virtual void dump(FILE *out, int indent) const =0
virtual bool empty_p() const =0
void DEBUG_FUNCTION dump() const
Definition diagnostic-buffer.h:101
Definition diagnostic-format-text.h:33
diagnostic_t
Definition diagnostic-core.h:29
Definition diagnostic.h:458
int get_count(diagnostic_t kind) const
Definition diagnostic.h:464
#define DEBUG_FUNCTION
Definition system.h:1236