| 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 <[email protected]>. |
| 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_DIAGNOSTIC_BUFFER_H |
| 22 |
#define GCC_DIAGNOSTIC_BUFFER_H |
| 23 |
|
| 24 |
#include "diagnostic.h" |
| 25 |
|
| 26 |
class diagnostic_per_format_buffer; |
| 27 |
class diagnostic_output_format; |
| 28 |
class diagnostic_text_output_format; |
| 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 |
|
| 56 |
class diagnostic_buffer |
| 57 |
{ |
| 58 |
public: |
| 59 |
friend class diagnostic_context; |
| 60 |
|
| 61 |
diagnostic_buffer (diagnostic_context &ctxt); |
| 62 |
~diagnostic_buffer (); |
| 63 |
|
| 64 |
void dump (FILE *out, int indent) const; |
| 65 |
void DEBUG_FUNCTION dump () const { dump (stderr, 0); } |
| 66 |
|
| 67 |
int diagnostic_count (diagnostic_t kind) const |
| 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: |
| 77 |
void ensure_per_format_buffers (); |
| 78 |
|
| 79 |
diagnostic_context &m_ctxt; |
| 80 |
auto_vec<diagnostic_per_format_buffer *> *m_per_format_buffers; |
| 81 |
|
| 82 |
/* The number of buffered diagnostics of each kind. */ |
| 83 |
diagnostic_counters m_diagnostic_counters; |
| 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 |
|
| 95 |
class diagnostic_per_format_buffer |
| 96 |
{ |
| 97 |
public: |
| 98 |
virtual ~diagnostic_per_format_buffer () {} |
| 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 */ |