LCOV - code coverage report
Current view: top level - gcc/diagnostics - sink.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.9 % 18 16
Test Date: 2026-02-28 14:20:25 Functions: 57.1 % 7 4
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Declarations for managing different output formats for diagnostics.
       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_DIAGNOSTICS_SINK_H
      22              : #define GCC_DIAGNOSTICS_SINK_H
      23              : 
      24              : #include "diagnostic.h"
      25              : #include "diagnostics/logical-locations.h"
      26              : 
      27              : namespace diagnostics {
      28              : 
      29              : class per_sink_buffer;
      30              : 
      31              : /* Abstract base class for a particular output format for diagnostics;
      32              :    each value of -fdiagnostics-output-format= will have its own
      33              :    implementation.  */
      34              : 
      35              : class sink
      36              : {
      37              : public:
      38              :   /* Abstract base class for adding additional functionality to a sink
      39              :      (e.g. via a plugin).  */
      40              :   class extension
      41              :   {
      42              :   public:
      43              :     virtual ~extension () {}
      44              :     virtual void dump (FILE *out, int indent) const = 0;
      45            2 :     virtual void finalize () {}
      46              : 
      47              :     sink &get_sink () const { return m_sink; }
      48              : 
      49              :   protected:
      50            2 :     extension (sink &sink_)
      51            2 :     : m_sink (sink_)
      52              :     {
      53              :     }
      54              : 
      55              :   private:
      56              :     sink &m_sink;
      57              :   };
      58              : 
      59       308180 :   virtual ~sink () {}
      60              : 
      61            0 :   virtual text_sink *dyn_cast_text_sink () { return nullptr; }
      62              : 
      63              :   virtual void dump_kind (FILE *out) const = 0;
      64              :   virtual void dump (FILE *out, int indent) const;
      65              : 
      66              :   /* Vfunc for notifying this format what the primary input file is,
      67              :      e.g. for titles of HTML, for SARIF's artifact metadata.  */
      68           12 :   virtual void set_main_input_filename (const char *) {}
      69              : 
      70              :   /* Vfunc for making an appropriate per_sink_buffer
      71              :      subclass for this format.  */
      72              :   virtual std::unique_ptr<per_sink_buffer>
      73              :   make_per_sink_buffer () = 0;
      74              : 
      75              :   /* Vfunc to be called when call a diagnostics::buffer is set on
      76              :      a diagnostics::context, to update this format.  The per_sink_buffer
      77              :      will be one created by make_per_sink_buffer above and thus be
      78              :      of the correct subclass.  */
      79              :   virtual void set_buffer (per_sink_buffer *) = 0;
      80              : 
      81              :   virtual void on_begin_group () = 0;
      82              :   virtual void on_end_group () = 0;
      83              : 
      84              :   /* Vfunc with responsibility for phase 3 of formatting the message
      85              :      and "printing" the result.  */
      86              :   virtual void on_report_diagnostic (const diagnostic_info &,
      87              :                                      enum kind orig_diag_kind) = 0;
      88              : 
      89              :   virtual void on_report_verbatim (text_info &);
      90              : 
      91              :   virtual void on_diagram (const diagram &diag) = 0;
      92              :   virtual void after_diagnostic (const diagnostic_info &) = 0;
      93              :   virtual bool machine_readable_stderr_p () const = 0;
      94              :   virtual bool follows_reference_printer_p () const = 0;
      95              : 
      96              :   /* Vfunc called when the diagnostics::context changes its
      97              :      reference printer (either to a new subclass of pretty_printer
      98              :      or when color/url options change).
      99              :      Subclasses should update their m_printer accordingly.  */
     100              :   virtual void update_printer () = 0;
     101              : 
     102              :   virtual void
     103              :   report_global_digraph (const lazily_created<digraphs::digraph> &) = 0;
     104              : 
     105              :   virtual void
     106              :   report_digraph_for_logical_location (const lazily_created<digraphs::digraph> &,
     107              :                                        logical_locations::key) = 0;
     108              : 
     109      4412638 :   context &get_context () const { return m_context; }
     110     19278238 :   pretty_printer *get_printer () const { return m_printer.get (); }
     111              : 
     112         2644 :   text_art::theme *get_diagram_theme () const
     113              :   {
     114         2644 :     return m_context.get_diagram_theme ();
     115              :   }
     116              : 
     117            0 :   void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
     118              : 
     119      1561222 :   logging::logger *get_logger () { return m_context.get_logger (); }
     120              : 
     121              :   void
     122            2 :   add_extension (std::unique_ptr<extension> sink_ext)
     123              :   {
     124            2 :     m_extensions.push_back (std::move (sink_ext));
     125              :   }
     126              : 
     127              :   void
     128              :   finalize_extensions ();
     129              : 
     130              : protected:
     131       708520 :   sink (context &dc)
     132       708520 :   : m_context (dc),
     133       708520 :     m_printer (dc.clone_printer ())
     134       708520 :   {}
     135              : 
     136              : protected:
     137              :   context &m_context;
     138              :   std::unique_ptr<pretty_printer> m_printer;
     139              : 
     140              : private:
     141              :   std::vector<std::unique_ptr<extension>> m_extensions;
     142              : };
     143              : 
     144              : extern void
     145              : output_format_init (context &,
     146              :                     const char *main_input_filename_,
     147              :                     const char *base_file_name,
     148              :                     enum diagnostics_output_format,
     149              :                     bool json_formatting);
     150              : 
     151              : } // namespace diagnostics
     152              : 
     153              : #endif /* ! GCC_DIAGNOSTICS_SINK_H */
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.