LCOV - code coverage report
Current view: top level - gcc - diagnostic.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 98.7 % 151 149
Test Date: 2024-11-02 13:25:42 Functions: 83.3 % 12 10
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Various declarations for language-independent diagnostics subroutines.
       2                 :             :    Copyright (C) 2000-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Gabriel Dos Reis <gdr@codesourcery.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_DIAGNOSTIC_H
      22                 :             : #define GCC_DIAGNOSTIC_H
      23                 :             : 
      24                 :             : /* This header uses std::unique_ptr, but <memory> can't be directly
      25                 :             :    included due to issues with macros.  Hence it must be included from
      26                 :             :    system.h by defining INCLUDE_MEMORY in any source file using it.  */
      27                 :             : 
      28                 :             : #ifndef INCLUDE_MEMORY
      29                 :             : # error "You must define INCLUDE_MEMORY before including system.h to use diagnostic.h"
      30                 :             : #endif
      31                 :             : 
      32                 :             : #include "unique-argv.h"
      33                 :             : #include "rich-location.h"
      34                 :             : #include "pretty-print.h"
      35                 :             : #include "diagnostic-core.h"
      36                 :             : 
      37                 :             : namespace text_art
      38                 :             : {
      39                 :             :   class theme;
      40                 :             : } // namespace text_art
      41                 :             : 
      42                 :             : /* An enum for controlling what units to use for the column number
      43                 :             :    when diagnostics are output, used by the -fdiagnostics-column-unit option.
      44                 :             :    Tabs will be expanded or not according to the value of -ftabstop.  The origin
      45                 :             :    (default 1) is controlled by -fdiagnostics-column-origin.  */
      46                 :             : 
      47                 :             : enum diagnostics_column_unit
      48                 :             : {
      49                 :             :   /* The default from GCC 11 onwards: display columns.  */
      50                 :             :   DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
      51                 :             : 
      52                 :             :   /* The behavior in GCC 10 and earlier: simple bytes.  */
      53                 :             :   DIAGNOSTICS_COLUMN_UNIT_BYTE
      54                 :             : };
      55                 :             : 
      56                 :             : /* An enum for controlling how to print non-ASCII characters/bytes when
      57                 :             :    a diagnostic suggests escaping the source code on output.  */
      58                 :             : 
      59                 :             : enum diagnostics_escape_format
      60                 :             : {
      61                 :             :   /* Escape non-ASCII Unicode characters in the form <U+XXXX> and
      62                 :             :      non-UTF-8 bytes in the form <XX>.  */
      63                 :             :   DIAGNOSTICS_ESCAPE_FORMAT_UNICODE,
      64                 :             : 
      65                 :             :   /* Escape non-ASCII bytes in the form <XX> (thus showing the underlying
      66                 :             :      encoding of non-ASCII Unicode characters).  */
      67                 :             :   DIAGNOSTICS_ESCAPE_FORMAT_BYTES
      68                 :             : };
      69                 :             : 
      70                 :             : /* Enum for overriding the standard output format.  */
      71                 :             : 
      72                 :             : enum diagnostics_output_format
      73                 :             : {
      74                 :             :   /* The default: textual output.  */
      75                 :             :   DIAGNOSTICS_OUTPUT_FORMAT_TEXT,
      76                 :             : 
      77                 :             :   /* JSON-based output, to stderr.  */
      78                 :             :   DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR,
      79                 :             : 
      80                 :             :   /* JSON-based output, to a file.  */
      81                 :             :   DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE,
      82                 :             : 
      83                 :             :   /* SARIF-based output, to stderr.  */
      84                 :             :   DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR,
      85                 :             : 
      86                 :             :   /* SARIF-based output, to a file.  */
      87                 :             :   DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE
      88                 :             : };
      89                 :             : 
      90                 :             : /* An enum for controlling how diagnostic_paths should be printed.  */
      91                 :             : enum diagnostic_path_format
      92                 :             : {
      93                 :             :   /* Don't print diagnostic_paths.  */
      94                 :             :   DPF_NONE,
      95                 :             : 
      96                 :             :   /* Print diagnostic_paths by emitting a separate "note" for every event
      97                 :             :      in the path.  */
      98                 :             :   DPF_SEPARATE_EVENTS,
      99                 :             : 
     100                 :             :   /* Print diagnostic_paths by consolidating events together where they
     101                 :             :      are close enough, and printing such runs of events with multiple
     102                 :             :      calls to diagnostic_show_locus, showing the individual events in
     103                 :             :      each run via labels in the source.  */
     104                 :             :   DPF_INLINE_EVENTS
     105                 :             : };
     106                 :             : 
     107                 :             : /* An enum for capturing values of GCC_EXTRA_DIAGNOSTIC_OUTPUT,
     108                 :             :    and for -fdiagnostics-parseable-fixits.  */
     109                 :             : 
     110                 :             : enum diagnostics_extra_output_kind
     111                 :             : {
     112                 :             :   /* No extra output, or an unrecognized value.  */
     113                 :             :   EXTRA_DIAGNOSTIC_OUTPUT_none,
     114                 :             : 
     115                 :             :   /* Emit fix-it hints using the "fixits-v1" format, equivalent to
     116                 :             :      -fdiagnostics-parseable-fixits.  */
     117                 :             :   EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1,
     118                 :             : 
     119                 :             :   /* Emit fix-it hints using the "fixits-v2" format.  */
     120                 :             :   EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2
     121                 :             : };
     122                 :             : 
     123                 :             : /* Values for -fdiagnostics-text-art-charset=.  */
     124                 :             : 
     125                 :             : enum diagnostic_text_art_charset
     126                 :             : {
     127                 :             :   /* No text art diagrams shall be emitted.  */
     128                 :             :   DIAGNOSTICS_TEXT_ART_CHARSET_NONE,
     129                 :             : 
     130                 :             :   /* Use pure ASCII for text art diagrams.  */
     131                 :             :   DIAGNOSTICS_TEXT_ART_CHARSET_ASCII,
     132                 :             : 
     133                 :             :   /* Use ASCII + conservative use of other unicode characters
     134                 :             :      in text art diagrams.  */
     135                 :             :   DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE,
     136                 :             : 
     137                 :             :   /* Use Emoji.  */
     138                 :             :   DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI
     139                 :             : };
     140                 :             : 
     141                 :             : /* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
     142                 :             :    its context and its KIND (ice, error, warning, note, ...)  See complete
     143                 :             :    list in diagnostic.def.  */
     144                 :   210166592 : struct diagnostic_info
     145                 :             : {
     146                 :   105083993 :   diagnostic_info ()
     147                 :   105083993 :     : message (), richloc (), metadata (), x_data (), kind (), option_id (),
     148                 :   105083993 :       m_iinfo ()
     149                 :   105083993 :   { }
     150                 :             : 
     151                 :             :   /* Text to be formatted.  */
     152                 :             :   text_info message;
     153                 :             : 
     154                 :             :   /* The location at which the diagnostic is to be reported.  */
     155                 :             :   rich_location *richloc;
     156                 :             : 
     157                 :             :   /* An optional bundle of metadata associated with the diagnostic
     158                 :             :      (or NULL).  */
     159                 :             :   const diagnostic_metadata *metadata;
     160                 :             : 
     161                 :             :   /* Auxiliary data for client.  */
     162                 :             :   void *x_data;
     163                 :             :   /* The kind of diagnostic it is about.  */
     164                 :             :   diagnostic_t kind;
     165                 :             :   /* Which OPT_* directly controls this diagnostic.  */
     166                 :             :   diagnostic_option_id option_id;
     167                 :             : 
     168                 :             :   /* Inlining context containing locations for each call site along
     169                 :             :      the inlining stack.  */
     170                 :   105083296 :   struct inlining_info
     171                 :             :   {
     172                 :             :     /* Locations along the inlining stack.  */
     173                 :             :     auto_vec<location_t, 8> m_ilocs;
     174                 :             :     /* The abstract origin of the location.  */
     175                 :             :     void *m_ao;
     176                 :             :     /* Set if every M_ILOCS element is in a system header.  */
     177                 :             :     bool m_allsyslocs;
     178                 :             :   } m_iinfo;
     179                 :             : };
     180                 :             : 
     181                 :             : /*  Forward declarations.  */
     182                 :             : class diagnostic_location_print_policy;
     183                 :             : class diagnostic_source_print_policy;
     184                 :             : 
     185                 :             : typedef void (*diagnostic_text_starter_fn) (diagnostic_text_output_format &,
     186                 :             :                                             const diagnostic_info *);
     187                 :             : 
     188                 :             : typedef void
     189                 :             : (*diagnostic_start_span_fn) (const diagnostic_location_print_policy &,
     190                 :             :                              pretty_printer *,
     191                 :             :                              expanded_location);
     192                 :             : 
     193                 :             : typedef void (*diagnostic_text_finalizer_fn) (diagnostic_text_output_format &,
     194                 :             :                                               const diagnostic_info *,
     195                 :             :                                               diagnostic_t);
     196                 :             : 
     197                 :             : /* Abstract base class for the diagnostic subsystem to make queries
     198                 :             :    about command-line options.  */
     199                 :             : 
     200                 :      282872 : class diagnostic_option_manager
     201                 :             : {
     202                 :             : public:
     203                 :             :   virtual ~diagnostic_option_manager () {}
     204                 :             : 
     205                 :             :   /* Return 1 if option OPTION_ID is enabled, 0 if it is disabled,
     206                 :             :      or -1 if it isn't a simple on-off switch
     207                 :             :      (or if the value is unknown, typically set later in target).  */
     208                 :             :   virtual int option_enabled_p (diagnostic_option_id option_id) const = 0;
     209                 :             : 
     210                 :             :   /* Return malloced memory for the name of the option OPTION_ID
     211                 :             :      which enabled a diagnostic, originally of type ORIG_DIAG_KIND but
     212                 :             :      possibly converted to DIAG_KIND by options such as -Werror.
     213                 :             :      May return NULL if no name is to be printed.
     214                 :             :      May be passed 0 as well as the index of a particular option.  */
     215                 :             :   virtual char *make_option_name (diagnostic_option_id option_id,
     216                 :             :                                   diagnostic_t orig_diag_kind,
     217                 :             :                                   diagnostic_t diag_kind) const = 0;
     218                 :             : 
     219                 :             :   /* Return malloced memory for a URL describing the option that controls
     220                 :             :      a diagnostic.
     221                 :             :      May return NULL if no URL is available.
     222                 :             :      May be passed 0 as well as the index of a particular option.  */
     223                 :             :   virtual char *make_option_url (diagnostic_option_id option_id) const = 0;
     224                 :             : };
     225                 :             : 
     226                 :             : class edit_context;
     227                 :             : class diagnostic_client_data_hooks;
     228                 :             : class logical_location;
     229                 :             : class diagnostic_diagram;
     230                 :             : class diagnostic_source_effect_info;
     231                 :             : class diagnostic_output_format;
     232                 :             :   class diagnostic_text_output_format;
     233                 :             : class diagnostic_buffer;
     234                 :             : 
     235                 :             : /* A stack of sets of classifications: each entry in the stack is
     236                 :             :    a mapping from option index to diagnostic severity that can be changed
     237                 :             :    via pragmas.  The stack can be pushed and popped.  */
     238                 :             : 
     239                 :             : class diagnostic_option_classifier
     240                 :             : {
     241                 :             : public:
     242                 :             :   void init (int n_opts);
     243                 :             :   void fini ();
     244                 :             : 
     245                 :             :   /* Save all diagnostic classifications in a stack.  */
     246                 :             :   void push ();
     247                 :             : 
     248                 :             :   /* Restore the topmost classification set off the stack.  If the stack
     249                 :             :      is empty, revert to the state based on command line parameters.  */
     250                 :             :   void pop (location_t where);
     251                 :             : 
     252                 :     1012266 :   bool option_unspecified_p (diagnostic_option_id option_id) const
     253                 :             :   {
     254                 :     1572880 :     return get_current_override (option_id) == DK_UNSPECIFIED;
     255                 :             :   }
     256                 :             : 
     257                 :     1019157 :   diagnostic_t get_current_override (diagnostic_option_id option_id) const
     258                 :             :   {
     259                 :     1019157 :     gcc_assert (option_id.m_idx < m_n_opts);
     260                 :     1019157 :     return m_classify_diagnostic[option_id.m_idx];
     261                 :             :   }
     262                 :             : 
     263                 :             :   diagnostic_t
     264                 :             :   classify_diagnostic (const diagnostic_context *context,
     265                 :             :                        diagnostic_option_id option_id,
     266                 :             :                        diagnostic_t new_kind,
     267                 :             :                        location_t where);
     268                 :             : 
     269                 :             :   diagnostic_t
     270                 :             :   update_effective_level_from_pragmas (diagnostic_info *diagnostic) const;
     271                 :             : 
     272                 :             :   int pch_save (FILE *);
     273                 :             :   int pch_restore (FILE *);
     274                 :             : 
     275                 :             : private:
     276                 :             :   /* Each time a diagnostic's classification is changed with a pragma,
     277                 :             :      we record the change and the location of the change in an array of
     278                 :             :      these structs.  */
     279                 :             :   struct diagnostic_classification_change_t
     280                 :             :   {
     281                 :             :     location_t location;
     282                 :             : 
     283                 :             :     /* For DK_POP, this is the index of the corresponding push (as stored
     284                 :             :        in m_push_list).
     285                 :             :        Otherwise, this is an option index.  */
     286                 :             :     int option;
     287                 :             : 
     288                 :             :     diagnostic_t kind;
     289                 :             :   };
     290                 :             : 
     291                 :             :   int m_n_opts;
     292                 :             : 
     293                 :             :   /* For each option index that can be passed to warning() et al
     294                 :             :      (OPT_* from options.h when using this code with the core GCC
     295                 :             :      options), this array may contain a new kind that the diagnostic
     296                 :             :      should be changed to before reporting, or DK_UNSPECIFIED to leave
     297                 :             :      it as the reported kind, or DK_IGNORED to not report it at
     298                 :             :      all.  */
     299                 :             :   diagnostic_t *m_classify_diagnostic;
     300                 :             : 
     301                 :             :   /* History of all changes to the classifications above.  This list
     302                 :             :      is stored in location-order, so we can search it, either
     303                 :             :      binary-wise or end-to-front, to find the most recent
     304                 :             :      classification for a given diagnostic, given the location of the
     305                 :             :      diagnostic.  */
     306                 :             :   vec<diagnostic_classification_change_t> m_classification_history;
     307                 :             : 
     308                 :             :   /* For pragma push/pop.  */
     309                 :             :   vec<int> m_push_list;
     310                 :             : };
     311                 :             : 
     312                 :             : /* A bundle of options relating to printing the user's source code
     313                 :             :    (potentially with a margin, underlining, labels, etc).  */
     314                 :             : 
     315                 :             : struct diagnostic_source_printing_options
     316                 :             : {
     317                 :             :   /* True if we should print the source line with a caret indicating
     318                 :             :      the location.
     319                 :             :      Corresponds to -fdiagnostics-show-caret.  */
     320                 :             :   bool enabled;
     321                 :             : 
     322                 :             :   /* Maximum width of the source line printed.  */
     323                 :             :   int max_width;
     324                 :             : 
     325                 :             :   /* Character used at the caret when printing source locations.  */
     326                 :             :   char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
     327                 :             : 
     328                 :             :   /* When printing source code, should the characters at carets and ranges
     329                 :             :      be colorized? (assuming colorization is on at all).
     330                 :             :      This should be true for frontends that generate range information
     331                 :             :      (so that the ranges of code are colorized),
     332                 :             :      and false for frontends that merely specify points within the
     333                 :             :      source code (to avoid e.g. colorizing just the first character in
     334                 :             :      a token, which would look strange).  */
     335                 :             :   bool colorize_source_p;
     336                 :             : 
     337                 :             :   /* When printing source code, should labelled ranges be printed?
     338                 :             :      Corresponds to -fdiagnostics-show-labels.  */
     339                 :             :   bool show_labels_p;
     340                 :             : 
     341                 :             :   /* When printing source code, should there be a left-hand margin
     342                 :             :      showing line numbers?
     343                 :             :      Corresponds to -fdiagnostics-show-line-numbers.  */
     344                 :             :   bool show_line_numbers_p;
     345                 :             : 
     346                 :             :   /* If printing source code, what should the minimum width of the margin
     347                 :             :      be?  Line numbers will be right-aligned, and padded to this width.
     348                 :             :      Corresponds to -fdiagnostics-minimum-margin-width=VALUE.  */
     349                 :             :   int min_margin_width;
     350                 :             : 
     351                 :             :   /* Usable by plugins; if true, print a debugging ruler above the
     352                 :             :      source output.  */
     353                 :             :   bool show_ruler_p;
     354                 :             : 
     355                 :             :   /* When printing events in an inline path, should we print lines
     356                 :             :      visualizing links between related events (e.g. for CFG paths)?
     357                 :             :      Corresponds to -fdiagnostics-show-event-links.  */
     358                 :             :   bool show_event_links_p;
     359                 :             : };
     360                 :             : 
     361                 :             : /* A bundle of state for determining column numbers in diagnostics
     362                 :             :    (tab stops, whether to start at 0 or 1, etc).
     363                 :             :    Uses a file_cache to handle tabs.  */
     364                 :             : 
     365                 :             : class diagnostic_column_policy
     366                 :             : {
     367                 :             : public:
     368                 :             :   diagnostic_column_policy (const diagnostic_context &dc);
     369                 :             : 
     370                 :             :   int converted_column (expanded_location s) const;
     371                 :             : 
     372                 :             :   label_text get_location_text (const expanded_location &s,
     373                 :             :                                 bool show_column,
     374                 :             :                                 bool colorize) const;
     375                 :             : 
     376                 :      111793 :   int get_tabstop () const { return m_tabstop; }
     377                 :             : 
     378                 :             : private:
     379                 :             :   file_cache &m_file_cache;
     380                 :             :   enum diagnostics_column_unit m_column_unit;
     381                 :             :   int m_column_origin;
     382                 :             :   int m_tabstop;
     383                 :             : };
     384                 :             : 
     385                 :             : /* A bundle of state for printing locations within diagnostics
     386                 :             :    (e.g. "FILENAME:LINE:COLUMN"), to isolate the interactions between
     387                 :             :    diagnostic_context and the start_span callbacks.  */
     388                 :             : 
     389                 :             : class diagnostic_location_print_policy
     390                 :             : {
     391                 :             : public:
     392                 :             :   diagnostic_location_print_policy (const diagnostic_context &dc);
     393                 :             :   diagnostic_location_print_policy (const diagnostic_text_output_format &);
     394                 :             : 
     395                 :     1137261 :   bool show_column_p () const { return m_show_column; }
     396                 :             : 
     397                 :             :   const diagnostic_column_policy &
     398                 :        1760 :   get_column_policy () const { return m_column_policy; }
     399                 :             : 
     400                 :             : private:
     401                 :             :   diagnostic_column_policy m_column_policy;
     402                 :             :   bool m_show_column;
     403                 :             : };
     404                 :             : 
     405                 :             : /* A bundle of state for printing source within a diagnostic,
     406                 :             :    to isolate the interactions between diagnostic_context and the
     407                 :             :    implementation of diagnostic_show_locus.  */
     408                 :             : 
     409                 :             : class diagnostic_source_print_policy
     410                 :             : {
     411                 :             : public:
     412                 :             :   diagnostic_source_print_policy (const diagnostic_context &);
     413                 :             : 
     414                 :             :   void
     415                 :             :   print (pretty_printer &pp,
     416                 :             :          const rich_location &richloc,
     417                 :             :          diagnostic_t diagnostic_kind,
     418                 :             :          diagnostic_source_effect_info *effect_info) const;
     419                 :             : 
     420                 :             :   const diagnostic_source_printing_options &
     421                 :      111609 :   get_options () const { return m_options; }
     422                 :             : 
     423                 :             :   diagnostic_start_span_fn
     424                 :         455 :   get_start_span_fn () const { return m_start_span_cb; }
     425                 :             : 
     426                 :             :   file_cache &
     427                 :      111609 :   get_file_cache () const { return m_file_cache; }
     428                 :             : 
     429                 :             :   enum diagnostics_escape_format
     430                 :         554 :   get_escape_format () const
     431                 :             :   {
     432                 :         554 :     return m_escape_format;
     433                 :             :   }
     434                 :             : 
     435                 :             :   text_art::theme *
     436                 :      114194 :   get_diagram_theme () const { return m_diagram_theme; }
     437                 :             : 
     438                 :             :   const diagnostic_column_policy &get_column_policy () const
     439                 :             :   {
     440                 :      111793 :     return m_location_policy.get_column_policy ();
     441                 :             :   }
     442                 :             : 
     443                 :         455 :   const diagnostic_location_print_policy &get_location_policy () const
     444                 :             :   {
     445                 :         455 :     return m_location_policy;
     446                 :             :   }
     447                 :             : 
     448                 :             : private:
     449                 :             :   const diagnostic_source_printing_options &m_options;
     450                 :             :   class diagnostic_location_print_policy m_location_policy;
     451                 :             :   diagnostic_start_span_fn m_start_span_cb;
     452                 :             :   file_cache &m_file_cache;
     453                 :             : 
     454                 :             :   /* Other data copied from diagnostic_context.  */
     455                 :             :   text_art::theme *m_diagram_theme;
     456                 :             :   enum diagnostics_escape_format m_escape_format;
     457                 :             : };
     458                 :             : 
     459                 :             : /* A collection of counters of diagnostics, per-kind
     460                 :             :    (e.g. "3 errors and 1 warning"), for use by both diagnostic_context
     461                 :             :    and by diagnostic_buffer.  */
     462                 :             : 
     463                 :             : struct diagnostic_counters
     464                 :             : {
     465                 :             :   diagnostic_counters ();
     466                 :             : 
     467                 :             :   void dump (FILE *out, int indent) const;
     468                 :           0 :   void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
     469                 :             : 
     470                 :      758592 :   int get_count (diagnostic_t kind) const { return m_count_for_kind[kind]; }
     471                 :             : 
     472                 :             :   void move_to (diagnostic_counters &dest);
     473                 :             :   void clear ();
     474                 :             : 
     475                 :             :   int m_count_for_kind[DK_LAST_DIAGNOSTIC_KIND];
     476                 :             : };
     477                 :             : 
     478                 :             : /* This data structure bundles altogether any information relevant to
     479                 :             :    the context of a diagnostic message.  */
     480                 :      163884 : class diagnostic_context
     481                 :             : {
     482                 :             : public:
     483                 :             :   /* Give access to m_text_callbacks.  */
     484                 :             :   friend diagnostic_text_starter_fn &
     485                 :             :   diagnostic_text_starter (diagnostic_context *context);
     486                 :             :   friend diagnostic_start_span_fn &
     487                 :             :   diagnostic_start_span (diagnostic_context *context);
     488                 :             :   friend diagnostic_text_finalizer_fn &
     489                 :             :   diagnostic_text_finalizer (diagnostic_context *context);
     490                 :             : 
     491                 :             :   friend class diagnostic_source_print_policy;
     492                 :             :   friend class diagnostic_text_output_format;
     493                 :             :   friend class diagnostic_buffer;
     494                 :             : 
     495                 :             :   typedef void (*set_locations_callback_t) (diagnostic_context *,
     496                 :             :                                             diagnostic_info *);
     497                 :             : 
     498                 :             :   void initialize (int n_opts);
     499                 :             :   void color_init (int value);
     500                 :             :   void urls_init (int value);
     501                 :             :   void set_pretty_printer (std::unique_ptr<pretty_printer> pp);
     502                 :             :   void refresh_output_sinks ();
     503                 :             : 
     504                 :             :   void finish ();
     505                 :             : 
     506                 :             :   void dump (FILE *out) const;
     507                 :           0 :   void DEBUG_FUNCTION dump () const { dump (stderr); }
     508                 :             : 
     509                 :             :   bool execution_failed_p () const;
     510                 :             : 
     511                 :             :   void set_original_argv (unique_argv original_argv);
     512                 :         387 :   const char * const *get_original_argv ()
     513                 :             :   {
     514                 :         387 :     return const_cast<const char * const *> (m_original_argv);
     515                 :             :   }
     516                 :             : 
     517                 :      323482 :   void set_set_locations_callback (set_locations_callback_t cb)
     518                 :             :   {
     519                 :      323482 :     m_set_locations_cb = cb;
     520                 :             :   }
     521                 :             : 
     522                 :             :   void
     523                 :             :   initialize_input_context (diagnostic_input_charset_callback ccb,
     524                 :             :                             bool should_skip_bom);
     525                 :             : 
     526                 :             :   void begin_group ();
     527                 :             :   void end_group ();
     528                 :             : 
     529                 :             :   bool warning_enabled_at (location_t loc, diagnostic_option_id option_id);
     530                 :             : 
     531                 :     1012266 :   bool option_unspecified_p (diagnostic_option_id option_id) const
     532                 :             :   {
     533                 :     1572880 :     return m_option_classifier.option_unspecified_p (option_id);
     534                 :             :   }
     535                 :             : 
     536                 :             :   bool emit_diagnostic_with_group (diagnostic_t kind,
     537                 :             :                                    rich_location &richloc,
     538                 :             :                                    const diagnostic_metadata *metadata,
     539                 :             :                                    diagnostic_option_id option_id,
     540                 :             :                                    const char *gmsgid, ...)
     541                 :             :     ATTRIBUTE_GCC_DIAG(6,7);
     542                 :             :   bool emit_diagnostic_with_group_va (diagnostic_t kind,
     543                 :             :                                       rich_location &richloc,
     544                 :             :                                       const diagnostic_metadata *metadata,
     545                 :             :                                       diagnostic_option_id option_id,
     546                 :             :                                       const char *gmsgid, va_list *ap)
     547                 :             :     ATTRIBUTE_GCC_DIAG(6,0);
     548                 :             : 
     549                 :             :   bool report_diagnostic (diagnostic_info *);
     550                 :             :   void report_verbatim (text_info &);
     551                 :             : 
     552                 :             :   diagnostic_t
     553                 :     3413637 :   classify_diagnostic (diagnostic_option_id option_id,
     554                 :             :                        diagnostic_t new_kind,
     555                 :             :                        location_t where)
     556                 :             :   {
     557                 :     3413637 :     return m_option_classifier.classify_diagnostic (this,
     558                 :             :                                                     option_id,
     559                 :             :                                                     new_kind,
     560                 :             :                                                     where);
     561                 :             :   }
     562                 :             : 
     563                 :     2817410 :   void push_diagnostics (location_t where ATTRIBUTE_UNUSED)
     564                 :             :   {
     565                 :     2817410 :     m_option_classifier.push ();
     566                 :             :   }
     567                 :     2816740 :   void pop_diagnostics (location_t where)
     568                 :             :   {
     569                 :     2816740 :     m_option_classifier.pop (where);
     570                 :             :   }
     571                 :             : 
     572                 :             :   void maybe_show_locus (const rich_location &richloc,
     573                 :             :                          diagnostic_t diagnostic_kind,
     574                 :             :                          pretty_printer &pp,
     575                 :             :                          diagnostic_source_effect_info *effect_info);
     576                 :             : 
     577                 :             :   void emit_diagram (const diagnostic_diagram &diagram);
     578                 :             : 
     579                 :             :   /* Various setters for use by option-handling logic.  */
     580                 :             :   void set_output_format (std::unique_ptr<diagnostic_output_format> output_format);
     581                 :             :   void set_text_art_charset (enum diagnostic_text_art_charset charset);
     582                 :             :   void set_client_data_hooks (std::unique_ptr<diagnostic_client_data_hooks> hooks);
     583                 :             :   void set_urlifier (std::unique_ptr<urlifier>);
     584                 :             :   void create_edit_context ();
     585                 :        4304 :   void set_warning_as_error_requested (bool val)
     586                 :             :   {
     587                 :        4304 :     m_warning_as_error_requested = val;
     588                 :        4304 :   }
     589                 :          12 :   void set_report_bug (bool val) { m_report_bug = val; }
     590                 :           4 :   void set_extra_output_kind (enum diagnostics_extra_output_kind kind)
     591                 :             :   {
     592                 :           4 :     m_extra_output_kind = kind;
     593                 :           4 :   }
     594                 :      271146 :   void set_show_cwe (bool val) { m_show_cwe = val;  }
     595                 :      271146 :   void set_show_rules (bool val) { m_show_rules = val; }
     596                 :             :   void set_show_highlight_colors (bool val);
     597                 :      546176 :   void set_path_format (enum diagnostic_path_format val)
     598                 :             :   {
     599                 :      546176 :     m_path_format = val;
     600                 :      275026 :   }
     601                 :      271222 :   void set_show_path_depths (bool val) { m_show_path_depths = val; }
     602                 :      271200 :   void set_show_option_requested (bool val) { m_show_option_requested = val; }
     603                 :          44 :   void set_max_errors (int val) { m_max_errors = val; }
     604                 :         532 :   void set_escape_format (enum diagnostics_escape_format val)
     605                 :             :   {
     606                 :         532 :     m_escape_format = val;
     607                 :           4 :   }
     608                 :             : 
     609                 :             :   void set_format_decoder (printer_fn format_decoder);
     610                 :             :   void set_prefixing_rule (diagnostic_prefixing_rule_t rule);
     611                 :             : 
     612                 :             :   /* Various accessors.  */
     613                 :       28875 :   bool warning_as_error_requested_p () const
     614                 :             :   {
     615                 :       28875 :     return m_warning_as_error_requested;
     616                 :             :   }
     617                 :       14882 :   bool show_path_depths_p () const { return m_show_path_depths; }
     618                 :             :   diagnostic_output_format &get_output_format (size_t idx) const;
     619                 :        3774 :   enum diagnostic_path_format get_path_format () const { return m_path_format; }
     620                 :      111646 :   enum diagnostics_escape_format get_escape_format () const
     621                 :             :   {
     622                 :      111646 :     return m_escape_format;
     623                 :             :   }
     624                 :             : 
     625                 :             :   file_cache &
     626                 :     2655926 :   get_file_cache () const
     627                 :             :   {
     628                 :     2655926 :     gcc_assert (m_file_cache);
     629                 :     2655926 :     return *m_file_cache;
     630                 :             :   }
     631                 :             : 
     632                 :      269361 :   edit_context *get_edit_context () const
     633                 :             :   {
     634                 :      269361 :     return m_edit_context_ptr;
     635                 :             :   }
     636                 :        1729 :   const diagnostic_client_data_hooks *get_client_data_hooks () const
     637                 :             :   {
     638                 :        1729 :     return m_client_data_hooks;
     639                 :             :   }
     640                 :     1426453 :   urlifier *get_urlifier () const { return m_urlifier; }
     641                 :      114192 :   text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; }
     642                 :             : 
     643                 :      355629 :   int &diagnostic_count (diagnostic_t kind)
     644                 :             :   {
     645                 :      355629 :     return m_diagnostic_counters.m_count_for_kind[kind];
     646                 :             :   }
     647                 :      758496 :   int diagnostic_count (diagnostic_t kind) const
     648                 :             :   {
     649                 :      269640 :     return m_diagnostic_counters.get_count (kind);
     650                 :             :   }
     651                 :             : 
     652                 :             :   /* Option-related member functions.  */
     653                 :    86964717 :   inline bool option_enabled_p (diagnostic_option_id option_id) const
     654                 :             :   {
     655                 :    86964717 :     if (!m_option_mgr)
     656                 :             :       return true;
     657                 :    86964717 :     return m_option_mgr->option_enabled_p (option_id);
     658                 :             :   }
     659                 :             : 
     660                 :     1425345 :   inline char *make_option_name (diagnostic_option_id option_id,
     661                 :             :                                  diagnostic_t orig_diag_kind,
     662                 :             :                                  diagnostic_t diag_kind) const
     663                 :             :   {
     664                 :     1425345 :     if (!m_option_mgr)
     665                 :             :       return nullptr;
     666                 :     1425161 :     return m_option_mgr->make_option_name (option_id,
     667                 :             :                                            orig_diag_kind,
     668                 :     1425161 :                                            diag_kind);
     669                 :             :   }
     670                 :             : 
     671                 :         122 :   inline char *make_option_url (diagnostic_option_id option_id) const
     672                 :             :   {
     673                 :         122 :     if (!m_option_mgr)
     674                 :             :       return nullptr;
     675                 :         122 :     return m_option_mgr->make_option_url (option_id);
     676                 :             :   }
     677                 :             : 
     678                 :             :   void
     679                 :             :   set_option_manager (std::unique_ptr<diagnostic_option_manager> mgr,
     680                 :             :                       unsigned lang_mask);
     681                 :             : 
     682                 :      257207 :   unsigned get_lang_mask () const
     683                 :             :   {
     684                 :      257207 :     return m_lang_mask;
     685                 :             :   }
     686                 :             : 
     687                 :             :   bool diagnostic_impl (rich_location *, const diagnostic_metadata *,
     688                 :             :                         diagnostic_option_id, const char *,
     689                 :             :                         va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
     690                 :             :   bool diagnostic_n_impl (rich_location *, const diagnostic_metadata *,
     691                 :             :                           diagnostic_option_id, unsigned HOST_WIDE_INT,
     692                 :             :                           const char *, const char *, va_list *,
     693                 :             :                           diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0);
     694                 :             : 
     695                 :             :   int
     696                 :         441 :   pch_save (FILE *f)
     697                 :             :   {
     698                 :         441 :     return m_option_classifier.pch_save (f);
     699                 :             :   }
     700                 :             : 
     701                 :             :   int
     702                 :         347 :   pch_restore (FILE *f)
     703                 :             :   {
     704                 :         347 :     return m_option_classifier.pch_restore (f);
     705                 :             :   }
     706                 :             : 
     707                 :             : 
     708                 :             :   void set_diagnostic_buffer (diagnostic_buffer *);
     709                 :     1133138 :   diagnostic_buffer *get_diagnostic_buffer () const
     710                 :             :   {
     711                 :     1133138 :     return m_diagnostic_buffer;
     712                 :             :   }
     713                 :             :   void clear_diagnostic_buffer (diagnostic_buffer &);
     714                 :             :   void flush_diagnostic_buffer (diagnostic_buffer &);
     715                 :             : 
     716                 :     1251862 :   std::unique_ptr<pretty_printer> clone_printer () const
     717                 :             :   {
     718                 :     1251796 :     return m_reference_printer->clone ();
     719                 :             :   }
     720                 :             : 
     721                 :     3633755 :   pretty_printer *get_reference_printer () const
     722                 :             :   {
     723                 :     3633563 :     return m_reference_printer;
     724                 :             :   }
     725                 :             : 
     726                 :             :   void
     727                 :             :   add_sink (std::unique_ptr<diagnostic_output_format>);
     728                 :             : 
     729                 :             :   bool supports_fnotice_on_stderr_p () const;
     730                 :             : 
     731                 :             : private:
     732                 :             :   void error_recursion () ATTRIBUTE_NORETURN;
     733                 :             : 
     734                 :             :   bool diagnostic_enabled (diagnostic_info *diagnostic);
     735                 :             : 
     736                 :             :   void get_any_inlining_info (diagnostic_info *diagnostic);
     737                 :             : 
     738                 :             :   void check_max_errors (bool flush);
     739                 :             :   void action_after_output (diagnostic_t diag_kind);
     740                 :             : 
     741                 :             :   /* Data members.
     742                 :             :      Ideally, all of these would be private.  */
     743                 :             : 
     744                 :             : private:
     745                 :             :   /* A reference instance of pretty_printer created by the client
     746                 :             :      and owned by the context.  Used for cloning when creating/adding
     747                 :             :      output formats.
     748                 :             :      Owned by the context; this would be a std::unique_ptr if
     749                 :             :      diagnostic_context had a proper ctor.  */
     750                 :             :   pretty_printer *m_reference_printer;
     751                 :             : 
     752                 :             :   /* Cache of source code.
     753                 :             :      Owned by the context; this would be a std::unique_ptr if
     754                 :             :      diagnostic_context had a proper ctor.  */
     755                 :             :   file_cache *m_file_cache;
     756                 :             : 
     757                 :             :   /* The number of times we have issued diagnostics.  */
     758                 :             :   diagnostic_counters m_diagnostic_counters;
     759                 :             : 
     760                 :             :   /* True if it has been requested that warnings be treated as errors.  */
     761                 :             :   bool m_warning_as_error_requested;
     762                 :             : 
     763                 :             :   /* The number of option indexes that can be passed to warning() et
     764                 :             :      al.  */
     765                 :             :   int m_n_opts;
     766                 :             : 
     767                 :             :   /* The stack of sets of overridden diagnostic option severities.  */
     768                 :             :   diagnostic_option_classifier m_option_classifier;
     769                 :             : 
     770                 :             :   /* True if we should print any CWE identifiers associated with
     771                 :             :      diagnostics.  */
     772                 :             :   bool m_show_cwe;
     773                 :             : 
     774                 :             :   /* True if we should print any rules associated with diagnostics.  */
     775                 :             :   bool m_show_rules;
     776                 :             : 
     777                 :             :   /* How should diagnostic_path objects be printed.  */
     778                 :             :   enum diagnostic_path_format m_path_format;
     779                 :             : 
     780                 :             :   /* True if we should print stack depths when printing diagnostic paths.  */
     781                 :             :   bool m_show_path_depths;
     782                 :             : 
     783                 :             :   /* True if we should print the command line option which controls
     784                 :             :      each diagnostic, if known.  */
     785                 :             :   bool m_show_option_requested;
     786                 :             : 
     787                 :             : public:
     788                 :             :   /* True if we should raise a SIGABRT on errors.  */
     789                 :             :   bool m_abort_on_error;
     790                 :             : 
     791                 :             :   /* True if we should show the column number on diagnostics.  */
     792                 :             :   bool m_show_column;
     793                 :             : 
     794                 :             :   /* True if pedwarns are errors.  */
     795                 :             :   bool m_pedantic_errors;
     796                 :             : 
     797                 :             :   /* True if permerrors are warnings.  */
     798                 :             :   bool m_permissive;
     799                 :             : 
     800                 :             :   /* The index of the option to associate with turning permerrors into
     801                 :             :      warnings.  */
     802                 :             :   int m_opt_permissive;
     803                 :             : 
     804                 :             :   /* True if errors are fatal.  */
     805                 :             :   bool m_fatal_errors;
     806                 :             : 
     807                 :             :   /* True if all warnings should be disabled.  */
     808                 :             :   bool m_inhibit_warnings;
     809                 :             : 
     810                 :             :   /* True if warnings should be given in system headers.  */
     811                 :             :   bool m_warn_system_headers;
     812                 :             : 
     813                 :             : private:
     814                 :             :   /* Maximum number of errors to report.  */
     815                 :             :   int m_max_errors;
     816                 :             : 
     817                 :             :   /* Client-supplied callbacks for use in text output.  */
     818                 :             :   struct {
     819                 :             :     /* This function is called before any message is printed out.  It is
     820                 :             :        responsible for preparing message prefix and such.  For example, it
     821                 :             :        might say:
     822                 :             :        In file included from "/usr/local/include/curses.h:5:
     823                 :             :        from "/home/gdr/src/nifty_printer.h:56:
     824                 :             :        ...
     825                 :             :     */
     826                 :             :     diagnostic_text_starter_fn m_begin_diagnostic;
     827                 :             : 
     828                 :             :     /* This function is called by diagnostic_show_locus in between
     829                 :             :        disjoint spans of source code, so that the context can print
     830                 :             :        something to indicate that a new span of source code has begun.  */
     831                 :             :     diagnostic_start_span_fn m_start_span;
     832                 :             : 
     833                 :             :     /* This function is called after the diagnostic message is printed.  */
     834                 :             :     diagnostic_text_finalizer_fn m_end_diagnostic;
     835                 :             :   } m_text_callbacks;
     836                 :             : 
     837                 :             : public:
     838                 :             :   /* Client hook to report an internal error.  */
     839                 :             :   void (*m_internal_error) (diagnostic_context *, const char *, va_list *);
     840                 :             : 
     841                 :             :   /* Client hook to adjust properties of the given diagnostic that we're
     842                 :             :      about to issue, such as its kind.  */
     843                 :             :   void (*m_adjust_diagnostic_info)(diagnostic_context *, diagnostic_info *);
     844                 :             : 
     845                 :             : private:
     846                 :             :   /* Owned by the context; this would be a std::unique_ptr if
     847                 :             :      diagnostic_context had a proper ctor.  */
     848                 :             :   diagnostic_option_manager *m_option_mgr;
     849                 :             :   unsigned m_lang_mask;
     850                 :             : 
     851                 :             :   /* An optional hook for adding URLs to quoted text strings in
     852                 :             :      diagnostics.  Only used for the main diagnostic message.
     853                 :             :      Owned by the context; this would be a std::unique_ptr if
     854                 :             :      diagnostic_context had a proper ctor.  */
     855                 :             :   urlifier *m_urlifier;
     856                 :             : 
     857                 :             : public:
     858                 :             :   /* Auxiliary data for client.  */
     859                 :             :   void *m_client_aux_data;
     860                 :             : 
     861                 :             :   /* Used to detect that the last caret was printed at the same location.  */
     862                 :             :   location_t m_last_location;
     863                 :             : 
     864                 :             : private:
     865                 :             :   int m_lock;
     866                 :             : 
     867                 :             : public:
     868                 :             :   bool m_inhibit_notes_p;
     869                 :             : 
     870                 :             :   diagnostic_source_printing_options m_source_printing;
     871                 :             : 
     872                 :             : private:
     873                 :             :   /* True if -freport-bug option is used.  */
     874                 :             :   bool m_report_bug;
     875                 :             : 
     876                 :             :   /* Used to specify additional diagnostic output to be emitted after the
     877                 :             :      rest of the diagnostic.  This is for implementing
     878                 :             :      -fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT.  */
     879                 :             :   enum diagnostics_extra_output_kind m_extra_output_kind;
     880                 :             : 
     881                 :             : public:
     882                 :             :   /* What units to use when outputting the column number.  */
     883                 :             :   enum diagnostics_column_unit m_column_unit;
     884                 :             : 
     885                 :             :   /* The origin for the column number (1-based or 0-based typically).  */
     886                 :             :   int m_column_origin;
     887                 :             : 
     888                 :             :   /* The size of the tabstop for tab expansion.  */
     889                 :             :   int m_tabstop;
     890                 :             : 
     891                 :             : private:
     892                 :             :   /* How should non-ASCII/non-printable bytes be escaped when
     893                 :             :      a diagnostic suggests escaping the source code on output.  */
     894                 :             :   enum diagnostics_escape_format m_escape_format;
     895                 :             : 
     896                 :             :   /* If non-NULL, an edit_context to which fix-it hints should be
     897                 :             :      applied, for generating patches.
     898                 :             :      Owned by the context; this would be a std::unique_ptr if
     899                 :             :      diagnostic_context had a proper ctor.  */
     900                 :             :   edit_context *m_edit_context_ptr;
     901                 :             : 
     902                 :             :   /* Fields relating to diagnostic groups.  */
     903                 :             :   struct {
     904                 :             :     /* How many diagnostic_group instances are currently alive.  */
     905                 :             :     int m_nesting_depth;
     906                 :             : 
     907                 :             :     /* How many diagnostics have been emitted since the bottommost
     908                 :             :        diagnostic_group was pushed.  */
     909                 :             :     int m_emission_count;
     910                 :             :   } m_diagnostic_groups;
     911                 :             : 
     912                 :             :   /* The various sinks to which diagnostics are to be outputted
     913                 :             :      (text vs structured formats such as SARIF).
     914                 :             :      The sinks are owned by the context; this would be a
     915                 :             :      std::vector<std::unique_ptr> if diagnostic_context had a
     916                 :             :      proper ctor.  */
     917                 :             :   auto_vec<diagnostic_output_format *> m_output_sinks;
     918                 :             : 
     919                 :             :   /* Callback to set the locations of call sites along the inlining
     920                 :             :      stack corresponding to a diagnostic location.  Needed to traverse
     921                 :             :      the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK()
     922                 :             :      of a diagnostic's location.  */
     923                 :             :   set_locations_callback_t m_set_locations_cb;
     924                 :             : 
     925                 :             :   /* A bundle of hooks for providing data to the context about its client
     926                 :             :      e.g. version information, plugins, etc.
     927                 :             :      Used by SARIF output to give metadata about the client that's
     928                 :             :      producing diagnostics.
     929                 :             :      Owned by the context; this would be a std::unique_ptr if
     930                 :             :      diagnostic_context had a proper ctor.  */
     931                 :             :   diagnostic_client_data_hooks *m_client_data_hooks;
     932                 :             : 
     933                 :             :   /* Support for diagrams.  */
     934                 :             :   struct
     935                 :             :   {
     936                 :             :     /* Theme to use when generating diagrams.
     937                 :             :        Can be NULL (if text art is disabled).
     938                 :             :        Owned by the context; this would be a std::unique_ptr if
     939                 :             :        diagnostic_context had a proper ctor.  */
     940                 :             :     text_art::theme *m_theme;
     941                 :             : 
     942                 :             :   } m_diagrams;
     943                 :             : 
     944                 :             :   /* Owned by the context.  */
     945                 :             :   char **m_original_argv;
     946                 :             : 
     947                 :             :   /* Borrowed pointer to the active diagnostic_buffer, if any.
     948                 :             :      If null (the default), then diagnostics that are reported to the
     949                 :             :      context are immediately issued to the output format.
     950                 :             :      If non-null, then diagnostics that are reported to the context
     951                 :             :      are buffered in the buffer, and may be issued to the output format
     952                 :             :      later (if the buffer is flushed), moved to other buffers, or
     953                 :             :      discarded (if the buffer is cleared).  */
     954                 :             :   diagnostic_buffer *m_diagnostic_buffer;
     955                 :             : };
     956                 :             : 
     957                 :             : inline void
     958                 :         596 : diagnostic_inhibit_notes (diagnostic_context * context)
     959                 :             : {
     960                 :         596 :   context->m_inhibit_notes_p = true;
     961                 :         596 : }
     962                 :             : 
     963                 :             : 
     964                 :             : /* Client supplied function to announce a diagnostic
     965                 :             :    (for text-based diagnostic output).  */
     966                 :             : inline diagnostic_text_starter_fn &
     967                 :             : diagnostic_text_starter (diagnostic_context *context)
     968                 :             : {
     969                 :             :   return context->m_text_callbacks.m_begin_diagnostic;
     970                 :             : }
     971                 :             : 
     972                 :             : /* Client supplied function called between disjoint spans of source code,
     973                 :             :    so that the context can print
     974                 :             :    something to indicate that a new span of source code has begun.  */
     975                 :             : inline diagnostic_start_span_fn &
     976                 :       81466 : diagnostic_start_span (diagnostic_context *context)
     977                 :             : {
     978                 :       81466 :   return context->m_text_callbacks.m_start_span;
     979                 :             : }
     980                 :             : 
     981                 :             : /* Client supplied function called after a diagnostic message is
     982                 :             :    displayed (for text-based diagnostic output).  */
     983                 :             : inline diagnostic_text_finalizer_fn &
     984                 :             : diagnostic_text_finalizer (diagnostic_context *context)
     985                 :             : {
     986                 :             :   return context->m_text_callbacks.m_end_diagnostic;
     987                 :             : }
     988                 :             : 
     989                 :             : /* Extension hooks for client.  */
     990                 :             : #define diagnostic_context_auxiliary_data(DC) (DC)->m_client_aux_data
     991                 :             : #define diagnostic_info_auxiliary_data(DI) (DI)->x_data
     992                 :             : 
     993                 :             : /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher.  */
     994                 :             : inline void
     995                 :          13 : diagnostic_abort_on_error (diagnostic_context *context)
     996                 :             : {
     997                 :          13 :   context->m_abort_on_error = true;
     998                 :             : }
     999                 :             : 
    1000                 :             : /* This diagnostic_context is used by front-ends that directly output
    1001                 :             :    diagnostic messages without going through `error', `warning',
    1002                 :             :    and similar functions.  */
    1003                 :             : extern diagnostic_context *global_dc;
    1004                 :             : 
    1005                 :             : /* The number of errors that have been issued so far.  Ideally, these
    1006                 :             :    would take a diagnostic_context as an argument.  */
    1007                 :             : #define errorcount global_dc->diagnostic_count (DK_ERROR)
    1008                 :             : /* Similarly, but for warnings.  */
    1009                 :             : #define warningcount global_dc->diagnostic_count (DK_WARNING)
    1010                 :             : /* Similarly, but for warnings promoted to errors.  */
    1011                 :             : #define werrorcount global_dc->diagnostic_count (DK_WERROR)
    1012                 :             : /* Similarly, but for sorrys.  */
    1013                 :             : #define sorrycount global_dc->diagnostic_count (DK_SORRY)
    1014                 :             : 
    1015                 :             : /* Returns nonzero if warnings should be emitted.  */
    1016                 :             : #define diagnostic_report_warnings_p(DC, LOC)                           \
    1017                 :             :   (!(DC)->m_inhibit_warnings                                         \
    1018                 :             :    && !(in_system_header_at (LOC) && !(DC)->m_warn_system_headers))
    1019                 :             : 
    1020                 :             : /* Override the option index to be used for reporting a
    1021                 :             :    diagnostic.  */
    1022                 :             : 
    1023                 :             : inline void
    1024                 :      197234 : diagnostic_set_option_id (diagnostic_info *info,
    1025                 :             :                           diagnostic_option_id option_id)
    1026                 :             : {
    1027                 :      197234 :   info->option_id = option_id;
    1028                 :             : }
    1029                 :             : 
    1030                 :             : /* Diagnostic related functions.  */
    1031                 :             : 
    1032                 :             : inline void
    1033                 :      734922 : diagnostic_initialize (diagnostic_context *context, int n_opts)
    1034                 :             : {
    1035                 :      734922 :   context->initialize (n_opts);
    1036                 :             : }
    1037                 :             : 
    1038                 :             : inline void
    1039                 :     1326630 : diagnostic_color_init (diagnostic_context *context, int value = -1)
    1040                 :             : {
    1041                 :     1326630 :   context->color_init (value);
    1042                 :      513311 : }
    1043                 :             : 
    1044                 :             : inline void
    1045                 :     1301135 : diagnostic_urls_init (diagnostic_context *context, int value = -1)
    1046                 :             : {
    1047                 :     1301135 :   context->urls_init (value);
    1048                 :      497004 : }
    1049                 :             : 
    1050                 :             : inline void
    1051                 :      352346 : diagnostic_finish (diagnostic_context *context)
    1052                 :             : {
    1053                 :      352346 :   context->finish ();
    1054                 :             : }
    1055                 :             : 
    1056                 :             : inline void
    1057                 :      321943 : diagnostic_show_locus (diagnostic_context *context,
    1058                 :             :                        rich_location *richloc,
    1059                 :             :                        diagnostic_t diagnostic_kind,
    1060                 :             :                        pretty_printer *pp,
    1061                 :             :                        diagnostic_source_effect_info *effect_info = nullptr)
    1062                 :             : {
    1063                 :      321943 :   gcc_assert (context);
    1064                 :      321943 :   gcc_assert (richloc);
    1065                 :      321943 :   gcc_assert (pp);
    1066                 :      321943 :   context->maybe_show_locus (*richloc, diagnostic_kind, *pp, effect_info);
    1067                 :      321943 : }
    1068                 :             : 
    1069                 :             : /* Because we read source files a second time after the frontend did it the
    1070                 :             :    first time, we need to know how the frontend handled things like character
    1071                 :             :    set conversion and UTF-8 BOM stripping, in order to make everything
    1072                 :             :    consistent.  This function needs to be called by each frontend that requires
    1073                 :             :    non-default behavior, to inform the diagnostics infrastructure how input is
    1074                 :             :    to be processed.  The default behavior is to do no conversion and not to
    1075                 :             :    strip a UTF-8 BOM.
    1076                 :             : 
    1077                 :             :    The callback should return the input charset to be used to convert the given
    1078                 :             :    file's contents to UTF-8, or it should return NULL if no conversion is needed
    1079                 :             :    for this file.  SHOULD_SKIP_BOM only applies in case no conversion was
    1080                 :             :    performed, and if true, it will cause a UTF-8 BOM to be skipped at the
    1081                 :             :    beginning of the file.  (In case a conversion was performed, the BOM is
    1082                 :             :    rather skipped as part of the conversion process.)  */
    1083                 :             : 
    1084                 :             : inline void
    1085                 :      199228 : diagnostic_initialize_input_context (diagnostic_context *context,
    1086                 :             :                                      diagnostic_input_charset_callback ccb,
    1087                 :             :                                      bool should_skip_bom)
    1088                 :             : {
    1089                 :      199228 :   context->initialize_input_context (ccb, should_skip_bom);
    1090                 :             : }
    1091                 :             : 
    1092                 :             : /* Force diagnostics controlled by OPTIDX to be kind KIND.  */
    1093                 :             : inline diagnostic_t
    1094                 :     3413637 : diagnostic_classify_diagnostic (diagnostic_context *context,
    1095                 :             :                                 diagnostic_option_id option_id,
    1096                 :             :                                 diagnostic_t kind,
    1097                 :             :                                 location_t where)
    1098                 :             : {
    1099                 :     3413637 :   return context->classify_diagnostic (option_id, kind, where);
    1100                 :             : }
    1101                 :             : 
    1102                 :             : inline void
    1103                 :     2817410 : diagnostic_push_diagnostics (diagnostic_context *context,
    1104                 :             :                              location_t where)
    1105                 :             : {
    1106                 :     2817410 :   context->push_diagnostics (where);
    1107                 :     2752636 : }
    1108                 :             : inline void
    1109                 :     2816740 : diagnostic_pop_diagnostics (diagnostic_context *context,
    1110                 :             :                             location_t where)
    1111                 :             : {
    1112                 :     2816740 :   context->pop_diagnostics (where);
    1113                 :     2751966 : }
    1114                 :             : 
    1115                 :             : /* Report a diagnostic message (an error or a warning) as specified by
    1116                 :             :    DC.  This function is *the* subroutine in terms of which front-ends
    1117                 :             :    should implement their specific diagnostic handling modules.  The
    1118                 :             :    front-end independent format specifiers are exactly those described
    1119                 :             :    in the documentation of output_format.
    1120                 :             :    Return true if a diagnostic was printed, false otherwise.  */
    1121                 :             : 
    1122                 :             : inline bool
    1123                 :     4475785 : diagnostic_report_diagnostic (diagnostic_context *context,
    1124                 :             :                               diagnostic_info *diagnostic)
    1125                 :             : {
    1126                 :     4475785 :   context->begin_group ();
    1127                 :     4475785 :   bool warned = context->report_diagnostic (diagnostic);
    1128                 :     4475425 :   context->end_group ();
    1129                 :     4475425 :   return warned;
    1130                 :             : }
    1131                 :             : 
    1132                 :             : #ifdef ATTRIBUTE_GCC_DIAG
    1133                 :             : extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
    1134                 :             :                                  rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
    1135                 :             : extern void diagnostic_set_info_translated (diagnostic_info *, const char *,
    1136                 :             :                                             va_list *, rich_location *,
    1137                 :             :                                             diagnostic_t)
    1138                 :             :      ATTRIBUTE_GCC_DIAG(2,0);
    1139                 :             : #endif
    1140                 :             : void default_diagnostic_text_starter (diagnostic_text_output_format &,
    1141                 :             :                                       const diagnostic_info *);
    1142                 :             : void default_diagnostic_start_span_fn (const diagnostic_location_print_policy &,
    1143                 :             :                                        pretty_printer *,
    1144                 :             :                                        expanded_location);
    1145                 :             : void default_diagnostic_text_finalizer (diagnostic_text_output_format &,
    1146                 :             :                                         const diagnostic_info *,
    1147                 :             :                                         diagnostic_t);
    1148                 :             : void diagnostic_set_caret_max_width (diagnostic_context *context, int value);
    1149                 :             : 
    1150                 :             : int get_terminal_width (void);
    1151                 :             : 
    1152                 :             : /* Return the location associated to this diagnostic. Parameter WHICH
    1153                 :             :    specifies which location. By default, expand the first one.  */
    1154                 :             : 
    1155                 :             : inline location_t
    1156                 :    96191919 : diagnostic_location (const diagnostic_info * diagnostic, int which = 0)
    1157                 :             : {
    1158                 :    96191919 :   return diagnostic->message.get_location (which);
    1159                 :             : }
    1160                 :             : 
    1161                 :             : /* Return the number of locations to be printed in DIAGNOSTIC.  */
    1162                 :             : 
    1163                 :             : inline unsigned int
    1164                 :             : diagnostic_num_locations (const diagnostic_info * diagnostic)
    1165                 :             : {
    1166                 :             :   return diagnostic->message.m_richloc->get_num_locations ();
    1167                 :             : }
    1168                 :             : 
    1169                 :             : /* Expand the location of this diagnostic. Use this function for
    1170                 :             :    consistency.  Parameter WHICH specifies which location. By default,
    1171                 :             :    expand the first one.  */
    1172                 :             : 
    1173                 :             : inline expanded_location
    1174                 :     1432731 : diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0)
    1175                 :             : {
    1176                 :     1432731 :   return diagnostic->richloc->get_expanded_location (which);
    1177                 :             : }
    1178                 :             : 
    1179                 :             : /* This is somehow the right-side margin of a caret line, that is, we
    1180                 :             :    print at least these many characters after the position pointed at
    1181                 :             :    by the caret.  */
    1182                 :             : const int CARET_LINE_MARGIN = 10;
    1183                 :             : 
    1184                 :             : /* Return true if the two locations can be represented within the same
    1185                 :             :    caret line.  This is used to build a prefix and also to determine
    1186                 :             :    whether to print one or two caret lines.  */
    1187                 :             : 
    1188                 :             : inline bool
    1189                 :         445 : diagnostic_same_line (const diagnostic_context *context,
    1190                 :             :                        expanded_location s1, expanded_location s2)
    1191                 :             : {
    1192                 :         442 :   return (s2.column && s1.line == s2.line
    1193                 :         445 :           && (context->m_source_printing.max_width - CARET_LINE_MARGIN
    1194                 :         155 :               > abs (s1.column - s2.column)));
    1195                 :             : }
    1196                 :             : 
    1197                 :             : extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
    1198                 :             : 
    1199                 :             : /* Pure text formatting support functions.  */
    1200                 :             : 
    1201                 :             : extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
    1202                 :             : 
    1203                 :             : /* Compute the number of digits in the decimal representation of an integer.  */
    1204                 :             : extern int num_digits (int);
    1205                 :             : 
    1206                 :             : inline bool
    1207                 :      270167 : warning_enabled_at (location_t loc, diagnostic_option_id option_id)
    1208                 :             : {
    1209                 :      270167 :   return global_dc->warning_enabled_at (loc, option_id);
    1210                 :             : }
    1211                 :             : 
    1212                 :             : inline bool
    1213                 :      560614 : option_unspecified_p (diagnostic_option_id option_id)
    1214                 :             : {
    1215                 :      560614 :   return global_dc->option_unspecified_p (option_id);
    1216                 :             : }
    1217                 :             : 
    1218                 :             : extern char *get_cwe_url (int cwe);
    1219                 :             : 
    1220                 :             : extern const char *get_diagnostic_kind_text (diagnostic_t kind);
    1221                 :             : 
    1222                 :             : const char *maybe_line_and_column (int line, int col);
    1223                 :             : 
    1224                 :             : #endif /* ! GCC_DIAGNOSTIC_H */
        

Generated by: LCOV version 2.1-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.