LCOV - code coverage report
Current view: top level - gcc - diagnostic.h (source / functions) Hit Total Coverage
Test: gcc.info Lines: 8 8 100.0 %
Date: 2023-07-19 08:18:47 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Various declarations for language-independent diagnostics subroutines.
       2             :    Copyright (C) 2000-2023 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             : #include "pretty-print.h"
      25             : #include "diagnostic-core.h"
      26             : 
      27             : namespace text_art
      28             : {
      29             :   class theme;
      30             : } // namespace text_art
      31             : 
      32             : /* An enum for controlling what units to use for the column number
      33             :    when diagnostics are output, used by the -fdiagnostics-column-unit option.
      34             :    Tabs will be expanded or not according to the value of -ftabstop.  The origin
      35             :    (default 1) is controlled by -fdiagnostics-column-origin.  */
      36             : 
      37             : enum diagnostics_column_unit
      38             : {
      39             :   /* The default from GCC 11 onwards: display columns.  */
      40             :   DIAGNOSTICS_COLUMN_UNIT_DISPLAY,
      41             : 
      42             :   /* The behavior in GCC 10 and earlier: simple bytes.  */
      43             :   DIAGNOSTICS_COLUMN_UNIT_BYTE
      44             : };
      45             : 
      46             : /* An enum for controlling how to print non-ASCII characters/bytes when
      47             :    a diagnostic suggests escaping the source code on output.  */
      48             : 
      49             : enum diagnostics_escape_format
      50             : {
      51             :   /* Escape non-ASCII Unicode characters in the form <U+XXXX> and
      52             :      non-UTF-8 bytes in the form <XX>.  */
      53             :   DIAGNOSTICS_ESCAPE_FORMAT_UNICODE,
      54             : 
      55             :   /* Escape non-ASCII bytes in the form <XX> (thus showing the underlying
      56             :      encoding of non-ASCII Unicode characters).  */
      57             :   DIAGNOSTICS_ESCAPE_FORMAT_BYTES
      58             : };
      59             : 
      60             : /* Enum for overriding the standard output format.  */
      61             : 
      62             : enum diagnostics_output_format
      63             : {
      64             :   /* The default: textual output.  */
      65             :   DIAGNOSTICS_OUTPUT_FORMAT_TEXT,
      66             : 
      67             :   /* JSON-based output, to stderr.  */
      68             :   DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR,
      69             : 
      70             :   /* JSON-based output, to a file.  */
      71             :   DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE,
      72             : 
      73             :   /* SARIF-based output, to stderr.  */
      74             :   DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR,
      75             : 
      76             :   /* SARIF-based output, to a file.  */
      77             :   DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE
      78             : };
      79             : 
      80             : /* An enum for controlling how diagnostic_paths should be printed.  */
      81             : enum diagnostic_path_format
      82             : {
      83             :   /* Don't print diagnostic_paths.  */
      84             :   DPF_NONE,
      85             : 
      86             :   /* Print diagnostic_paths by emitting a separate "note" for every event
      87             :      in the path.  */
      88             :   DPF_SEPARATE_EVENTS,
      89             : 
      90             :   /* Print diagnostic_paths by consolidating events together where they
      91             :      are close enough, and printing such runs of events with multiple
      92             :      calls to diagnostic_show_locus, showing the individual events in
      93             :      each run via labels in the source.  */
      94             :   DPF_INLINE_EVENTS
      95             : };
      96             : 
      97             : /* An enum for capturing values of GCC_EXTRA_DIAGNOSTIC_OUTPUT,
      98             :    and for -fdiagnostics-parseable-fixits.  */
      99             : 
     100             : enum diagnostics_extra_output_kind
     101             : {
     102             :   /* No extra output, or an unrecognized value.  */
     103             :   EXTRA_DIAGNOSTIC_OUTPUT_none,
     104             : 
     105             :   /* Emit fix-it hints using the "fixits-v1" format, equivalent to
     106             :      -fdiagnostics-parseable-fixits.  */
     107             :   EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1,
     108             : 
     109             :   /* Emit fix-it hints using the "fixits-v2" format.  */
     110             :   EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2
     111             : };
     112             : 
     113             : /* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
     114             :    its context and its KIND (ice, error, warning, note, ...)  See complete
     115             :    list in diagnostic.def.  */
     116     4390180 : struct diagnostic_info
     117             : {
     118     2195090 :   diagnostic_info ()
     119     2195090 :     : message (), richloc (), metadata (), x_data (), kind (), option_index (),
     120     2195090 :       m_iinfo ()
     121     2195090 :   { }
     122             : 
     123             :   /* Text to be formatted.  */
     124             :   text_info message;
     125             : 
     126             :   /* The location at which the diagnostic is to be reported.  */
     127             :   rich_location *richloc;
     128             : 
     129             :   /* An optional bundle of metadata associated with the diagnostic
     130             :      (or NULL).  */
     131             :   const diagnostic_metadata *metadata;
     132             : 
     133             :   /* Auxiliary data for client.  */
     134             :   void *x_data;
     135             :   /* The kind of diagnostic it is about.  */
     136             :   diagnostic_t kind;
     137             :   /* Which OPT_* directly controls this diagnostic.  */
     138             :   int option_index;
     139             : 
     140             :   /* Inlining context containing locations for each call site along
     141             :      the inlining stack.  */
     142     2195090 :   struct inlining_info
     143             :   {
     144             :     /* Locations along the inlining stack.  */
     145             :     auto_vec<location_t, 8> m_ilocs;
     146             :     /* The abstract origin of the location.  */
     147             :     void *m_ao;
     148             :     /* Set if every M_ILOCS element is in a system header.  */
     149             :     bool m_allsyslocs;
     150             :   } m_iinfo;
     151             : };
     152             : 
     153             : /* Each time a diagnostic's classification is changed with a pragma,
     154             :    we record the change and the location of the change in an array of
     155             :    these structs.  */
     156             : struct diagnostic_classification_change_t
     157             : {
     158             :   location_t location;
     159             :   int option;
     160             :   diagnostic_t kind;
     161             : };
     162             : 
     163             : /*  Forward declarations.  */
     164             : typedef void (*diagnostic_starter_fn) (diagnostic_context *,
     165             :                                        diagnostic_info *);
     166             : 
     167             : typedef void (*diagnostic_start_span_fn) (diagnostic_context *,
     168             :                                           expanded_location);
     169             : 
     170             : typedef void (*diagnostic_finalizer_fn) (diagnostic_context *,
     171             :                                          diagnostic_info *,
     172             :                                          diagnostic_t);
     173             : 
     174             : class edit_context;
     175             : namespace json { class value; }
     176             : class diagnostic_client_data_hooks;
     177             : class logical_location;
     178             : class diagnostic_diagram;
     179             : 
     180             : /* This data structure bundles altogether any information relevant to
     181             :    the context of a diagnostic message.  */
     182             : struct diagnostic_context
     183             : {
     184             :   /* Where most of the diagnostic formatting work is done.  */
     185             :   pretty_printer *printer;
     186             : 
     187             :   /* Cache of source code.  */
     188             :   file_cache *m_file_cache;
     189             : 
     190             :   /* The number of times we have issued diagnostics.  */
     191             :   int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
     192             : 
     193             :   /* True if it has been requested that warnings be treated as errors.  */
     194             :   bool warning_as_error_requested;
     195             : 
     196             :   /* The number of option indexes that can be passed to warning() et
     197             :      al.  */
     198             :   int n_opts;
     199             : 
     200             :   /* For each option index that can be passed to warning() et al
     201             :      (OPT_* from options.h when using this code with the core GCC
     202             :      options), this array may contain a new kind that the diagnostic
     203             :      should be changed to before reporting, or DK_UNSPECIFIED to leave
     204             :      it as the reported kind, or DK_IGNORED to not report it at
     205             :      all.  */
     206             :   diagnostic_t *classify_diagnostic;
     207             : 
     208             :   /* History of all changes to the classifications above.  This list
     209             :      is stored in location-order, so we can search it, either
     210             :      binary-wise or end-to-front, to find the most recent
     211             :      classification for a given diagnostic, given the location of the
     212             :      diagnostic.  */
     213             :   diagnostic_classification_change_t *classification_history;
     214             : 
     215             :   /* The size of the above array.  */
     216             :   int n_classification_history;
     217             : 
     218             :   /* For pragma push/pop.  */
     219             :   int *push_list;
     220             :   int n_push;
     221             : 
     222             :   /* True if we should print the source line with a caret indicating
     223             :      the location.  */
     224             :   bool show_caret;
     225             : 
     226             :   /* Maximum width of the source line printed.  */
     227             :   int caret_max_width;
     228             : 
     229             :   /* Character used for caret diagnostics.  */
     230             :   char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
     231             : 
     232             :   /* True if we should print any CWE identifiers associated with
     233             :      diagnostics.  */
     234             :   bool show_cwe;
     235             : 
     236             :   /* True if we should print any rules associated with diagnostics.  */
     237             :   bool show_rules;
     238             : 
     239             :   /* How should diagnostic_path objects be printed.  */
     240             :   enum diagnostic_path_format path_format;
     241             : 
     242             :   /* True if we should print stack depths when printing diagnostic paths.  */
     243             :   bool show_path_depths;
     244             : 
     245             :   /* True if we should print the command line option which controls
     246             :      each diagnostic, if known.  */
     247             :   bool show_option_requested;
     248             : 
     249             :   /* True if we should raise a SIGABRT on errors.  */
     250             :   bool abort_on_error;
     251             : 
     252             :   /* True if we should show the column number on diagnostics.  */
     253             :   bool show_column;
     254             : 
     255             :   /* True if pedwarns are errors.  */
     256             :   bool pedantic_errors;
     257             : 
     258             :   /* True if permerrors are warnings.  */
     259             :   bool permissive;
     260             : 
     261             :   /* The index of the option to associate with turning permerrors into
     262             :      warnings.  */
     263             :   int opt_permissive;
     264             : 
     265             :   /* True if errors are fatal.  */
     266             :   bool fatal_errors;
     267             : 
     268             :   /* True if all warnings should be disabled.  */
     269             :   bool dc_inhibit_warnings;
     270             : 
     271             :   /* True if warnings should be given in system headers.  */
     272             :   bool dc_warn_system_headers;
     273             : 
     274             :   /* Maximum number of errors to report.  */
     275             :   int max_errors;
     276             : 
     277             :   /* This function is called before any message is printed out.  It is
     278             :      responsible for preparing message prefix and such.  For example, it
     279             :      might say:
     280             :      In file included from "/usr/local/include/curses.h:5:
     281             :                       from "/home/gdr/src/nifty_printer.h:56:
     282             :                       ...
     283             :   */
     284             :   diagnostic_starter_fn begin_diagnostic;
     285             : 
     286             :   /* This function is called by diagnostic_show_locus in between
     287             :      disjoint spans of source code, so that the context can print
     288             :      something to indicate that a new span of source code has begun.  */
     289             :   diagnostic_start_span_fn start_span;
     290             : 
     291             :   /* This function is called after the diagnostic message is printed.  */
     292             :   diagnostic_finalizer_fn end_diagnostic;
     293             : 
     294             :   /* Client hook to report an internal error.  */
     295             :   void (*internal_error) (diagnostic_context *, const char *, va_list *);
     296             : 
     297             :   /* Client hook to say whether the option controlling a diagnostic is
     298             :      enabled.  Returns nonzero if enabled, zero if disabled.  */
     299             :   int (*option_enabled) (int, unsigned, void *);
     300             : 
     301             :   /* Client information to pass as second argument to
     302             :      option_enabled.  */
     303             :   void *option_state;
     304             : 
     305             :   /* Client hook to return the name of an option that controls a
     306             :      diagnostic.  Returns malloced memory.  The first diagnostic_t
     307             :      argument is the kind of diagnostic before any reclassification
     308             :      (of warnings as errors, etc.); the second is the kind after any
     309             :      reclassification.  May return NULL if no name is to be printed.
     310             :      May be passed 0 as well as the index of a particular option.  */
     311             :   char *(*option_name) (diagnostic_context *, int, diagnostic_t, diagnostic_t);
     312             : 
     313             :   /* Client hook to return a URL describing the option that controls
     314             :      a diagnostic.  Returns malloced memory.  May return NULL if no URL
     315             :      is available.  May be passed 0 as well as the index of a
     316             :      particular option.  */
     317             :   char *(*get_option_url) (diagnostic_context *, int);
     318             : 
     319             :   void (*print_path) (diagnostic_context *, const diagnostic_path *);
     320             :   json::value *(*make_json_for_path) (diagnostic_context *, const diagnostic_path *);
     321             : 
     322             :   /* Auxiliary data for client.  */
     323             :   void *x_data;
     324             : 
     325             :   /* Used to detect that the last caret was printed at the same location.  */
     326             :   location_t last_location;
     327             : 
     328             :   /* Used to detect when the input file stack has changed since last
     329             :      described.  */
     330             :   const line_map_ordinary *last_module;
     331             : 
     332             :   int lock;
     333             : 
     334             :   /* A copy of lang_hooks.option_lang_mask ().  */
     335             :   unsigned lang_mask;
     336             : 
     337             :   bool inhibit_notes_p;
     338             : 
     339             :   /* When printing source code, should the characters at carets and ranges
     340             :      be colorized? (assuming colorization is on at all).
     341             :      This should be true for frontends that generate range information
     342             :      (so that the ranges of code are colorized),
     343             :      and false for frontends that merely specify points within the
     344             :      source code (to avoid e.g. colorizing just the first character in
     345             :      a token, which would look strange).  */
     346             :   bool colorize_source_p;
     347             : 
     348             :   /* When printing source code, should labelled ranges be printed?  */
     349             :   bool show_labels_p;
     350             : 
     351             :   /* When printing source code, should there be a left-hand margin
     352             :      showing line numbers?  */
     353             :   bool show_line_numbers_p;
     354             : 
     355             :   /* If printing source code, what should the minimum width of the margin
     356             :      be?  Line numbers will be right-aligned, and padded to this width.  */
     357             :   int min_margin_width;
     358             : 
     359             :   /* Usable by plugins; if true, print a debugging ruler above the
     360             :      source output.  */
     361             :   bool show_ruler_p;
     362             : 
     363             :   /* True if -freport-bug option is used.  */
     364             :   bool report_bug;
     365             : 
     366             :   /* Used to specify additional diagnostic output to be emitted after the
     367             :      rest of the diagnostic.  This is for implementing
     368             :      -fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT.  */
     369             :   enum diagnostics_extra_output_kind extra_output_kind;
     370             : 
     371             :   /* What units to use when outputting the column number.  */
     372             :   enum diagnostics_column_unit column_unit;
     373             : 
     374             :   /* The origin for the column number (1-based or 0-based typically).  */
     375             :   int column_origin;
     376             : 
     377             :   /* The size of the tabstop for tab expansion.  */
     378             :   int tabstop;
     379             : 
     380             :   /* How should non-ASCII/non-printable bytes be escaped when
     381             :      a diagnostic suggests escaping the source code on output.  */
     382             :   enum diagnostics_escape_format escape_format;
     383             : 
     384             :   /* If non-NULL, an edit_context to which fix-it hints should be
     385             :      applied, for generating patches.  */
     386             :   edit_context *edit_context_ptr;
     387             : 
     388             :   /* How many diagnostic_group instances are currently alive.  */
     389             :   int diagnostic_group_nesting_depth;
     390             : 
     391             :   /* How many diagnostics have been emitted since the bottommost
     392             :      diagnostic_group was pushed.  */
     393             :   int diagnostic_group_emission_count;
     394             : 
     395             :   /* Optional callbacks for handling diagnostic groups.  */
     396             : 
     397             :   /* If non-NULL, this will be called immediately before the first
     398             :      time a diagnostic is emitted within a stack of groups.  */
     399             :   void (*begin_group_cb) (diagnostic_context * context);
     400             : 
     401             :   /* If non-NULL, this will be called when a stack of groups is
     402             :      popped if any diagnostics were emitted within that group.  */
     403             :   void (*end_group_cb) (diagnostic_context * context);
     404             : 
     405             :   /* Callback for final cleanup.  */
     406             :   void (*final_cb) (diagnostic_context *context);
     407             : 
     408             :   /* Callback to set the locations of call sites along the inlining
     409             :      stack corresponding to a diagnostic location.  Needed to traverse
     410             :      the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK()
     411             :      of a diagnostic's location.  */
     412             :   void (*set_locations_cb)(diagnostic_context *, diagnostic_info *);
     413             : 
     414             :   /* Optional callback for attempting to handle ICEs gracefully.  */
     415             :   void (*ice_handler_cb) (diagnostic_context *context);
     416             : 
     417             :   /* Include files that diagnostic_report_current_module has already listed the
     418             :      include path for.  */
     419             :   hash_set<location_t, false, location_hash> *includes_seen;
     420             : 
     421             :   /* A bundle of hooks for providing data to the context about its client
     422             :      e.g. version information, plugins, etc.
     423             :      Used by SARIF output to give metadata about the client that's
     424             :      producing diagnostics.  */
     425             :   diagnostic_client_data_hooks *m_client_data_hooks;
     426             : 
     427             :   /* Support for diagrams.  */
     428             :   struct
     429             :   {
     430             :     /* Theme to use when generating diagrams.
     431             :        Can be NULL (if text art is disabled).  */
     432             :     text_art::theme *m_theme;
     433             : 
     434             :     /* Callback for emitting diagrams.  */
     435             :     void (*m_emission_cb) (diagnostic_context *context,
     436             :                            const diagnostic_diagram &diagram);
     437             :   } m_diagrams;
     438             : };
     439             : 
     440             : inline void
     441             : diagnostic_inhibit_notes (diagnostic_context * context)
     442             : {
     443             :   context->inhibit_notes_p = true;
     444             : }
     445             : 
     446             : 
     447             : /* Client supplied function to announce a diagnostic.  */
     448             : #define diagnostic_starter(DC) (DC)->begin_diagnostic
     449             : 
     450             : /* Client supplied function called after a diagnostic message is
     451             :    displayed.  */
     452             : #define diagnostic_finalizer(DC) (DC)->end_diagnostic
     453             : 
     454             : /* Extension hooks for client.  */
     455             : #define diagnostic_context_auxiliary_data(DC) (DC)->x_data
     456             : #define diagnostic_info_auxiliary_data(DI) (DI)->x_data
     457             : 
     458             : /* Same as pp_format_decoder.  Works on 'diagnostic_context *'.  */
     459             : #define diagnostic_format_decoder(DC) ((DC)->printer->format_decoder)
     460             : 
     461             : /* Same as output_prefixing_rule.  Works on 'diagnostic_context *'.  */
     462             : #define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule)
     463             : 
     464             : /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher.  */
     465             : #define diagnostic_abort_on_error(DC) \
     466             :   (DC)->abort_on_error = true
     467             : 
     468             : /* This diagnostic_context is used by front-ends that directly output
     469             :    diagnostic messages without going through `error', `warning',
     470             :    and similar functions.  */
     471             : extern diagnostic_context *global_dc;
     472             : 
     473             : /* Returns whether the diagnostic framework has been intialized already and is
     474             :    ready for use.  */
     475             : #define diagnostic_ready_p() (global_dc->printer != NULL)
     476             : 
     477             : /* The total count of a KIND of diagnostics emitted so far.  */
     478             : #define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)]
     479             : 
     480             : /* The number of errors that have been issued so far.  Ideally, these
     481             :    would take a diagnostic_context as an argument.  */
     482             : #define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
     483             : /* Similarly, but for warnings.  */
     484             : #define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
     485             : /* Similarly, but for warnings promoted to errors.  */
     486             : #define werrorcount diagnostic_kind_count (global_dc, DK_WERROR)
     487             : /* Similarly, but for sorrys.  */
     488             : #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
     489             : 
     490             : /* Returns nonzero if warnings should be emitted.  */
     491             : #define diagnostic_report_warnings_p(DC, LOC)                           \
     492             :   (!(DC)->dc_inhibit_warnings                                                \
     493             :    && !(in_system_header_at (LOC) && !(DC)->dc_warn_system_headers))
     494             : 
     495             : /* Override the option index to be used for reporting a
     496             :    diagnostic.  */
     497             : 
     498             : inline void
     499             : diagnostic_override_option_index (diagnostic_info *info, int optidx)
     500             : {
     501             :   info->option_index = optidx;
     502             : }
     503             : 
     504             : /* Diagnostic related functions.  */
     505             : extern void diagnostic_initialize (diagnostic_context *, int);
     506             : extern void diagnostic_color_init (diagnostic_context *, int value = -1);
     507             : extern void diagnostic_urls_init (diagnostic_context *, int value = -1);
     508             : extern void diagnostic_finish (diagnostic_context *);
     509             : extern void diagnostic_report_current_module (diagnostic_context *, location_t);
     510             : extern void diagnostic_show_locus (diagnostic_context *,
     511             :                                    rich_location *richloc,
     512             :                                    diagnostic_t diagnostic_kind);
     513             : extern void diagnostic_show_any_path (diagnostic_context *, diagnostic_info *);
     514             : 
     515             : /* Because we read source files a second time after the frontend did it the
     516             :    first time, we need to know how the frontend handled things like character
     517             :    set conversion and UTF-8 BOM stripping, in order to make everything
     518             :    consistent.  This function needs to be called by each frontend that requires
     519             :    non-default behavior, to inform the diagnostics infrastructure how input is
     520             :    to be processed.  The default behavior is to do no conversion and not to
     521             :    strip a UTF-8 BOM.
     522             : 
     523             :    The callback should return the input charset to be used to convert the given
     524             :    file's contents to UTF-8, or it should return NULL if no conversion is needed
     525             :    for this file.  SHOULD_SKIP_BOM only applies in case no conversion was
     526             :    performed, and if true, it will cause a UTF-8 BOM to be skipped at the
     527             :    beginning of the file.  (In case a conversion was performed, the BOM is
     528             :    rather skipped as part of the conversion process.)  */
     529             : 
     530             : void diagnostic_initialize_input_context (diagnostic_context *context,
     531             :                                           diagnostic_input_charset_callback ccb,
     532             :                                           bool should_skip_bom);
     533             : 
     534             : /* Force diagnostics controlled by OPTIDX to be kind KIND.  */
     535             : extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
     536             :                                                     int /* optidx */,
     537             :                                                     diagnostic_t /* kind */,
     538             :                                                     location_t);
     539             : extern void diagnostic_push_diagnostics (diagnostic_context *, location_t);
     540             : extern void diagnostic_pop_diagnostics (diagnostic_context *, location_t);
     541             : extern bool diagnostic_report_diagnostic (diagnostic_context *,
     542             :                                           diagnostic_info *);
     543             : #ifdef ATTRIBUTE_GCC_DIAG
     544             : extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
     545             :                                  rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
     546             : extern void diagnostic_set_info_translated (diagnostic_info *, const char *,
     547             :                                             va_list *, rich_location *,
     548             :                                             diagnostic_t)
     549             :      ATTRIBUTE_GCC_DIAG(2,0);
     550             : extern void diagnostic_append_note (diagnostic_context *, location_t,
     551             :                                     const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
     552             : #endif
     553             : extern char *diagnostic_build_prefix (diagnostic_context *, const diagnostic_info *);
     554             : void default_diagnostic_starter (diagnostic_context *, diagnostic_info *);
     555             : void default_diagnostic_start_span_fn (diagnostic_context *,
     556             :                                        expanded_location);
     557             : void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *,
     558             :                                    diagnostic_t);
     559             : void diagnostic_set_caret_max_width (diagnostic_context *context, int value);
     560             : void diagnostic_action_after_output (diagnostic_context *, diagnostic_t);
     561             : void diagnostic_check_max_errors (diagnostic_context *, bool flush = false);
     562             : 
     563             : void diagnostic_file_cache_fini (void);
     564             : 
     565             : int get_terminal_width (void);
     566             : 
     567             : /* Return the location associated to this diagnostic. Parameter WHICH
     568             :    specifies which location. By default, expand the first one.  */
     569             : 
     570             : inline location_t
     571      199835 : diagnostic_location (const diagnostic_info * diagnostic, int which = 0)
     572             : {
     573      199835 :   return diagnostic->message.get_location (which);
     574             : }
     575             : 
     576             : /* Return the number of locations to be printed in DIAGNOSTIC.  */
     577             : 
     578             : inline unsigned int
     579             : diagnostic_num_locations (const diagnostic_info * diagnostic)
     580             : {
     581             :   return diagnostic->message.m_richloc->get_num_locations ();
     582             : }
     583             : 
     584             : /* Expand the location of this diagnostic. Use this function for
     585             :    consistency.  Parameter WHICH specifies which location. By default,
     586             :    expand the first one.  */
     587             : 
     588             : inline expanded_location
     589             : diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0)
     590             : {
     591             :   return diagnostic->richloc->get_expanded_location (which);
     592             : }
     593             : 
     594             : /* This is somehow the right-side margin of a caret line, that is, we
     595             :    print at least these many characters after the position pointed at
     596             :    by the caret.  */
     597             : const int CARET_LINE_MARGIN = 10;
     598             : 
     599             : /* Return true if the two locations can be represented within the same
     600             :    caret line.  This is used to build a prefix and also to determine
     601             :    whether to print one or two caret lines.  */
     602             : 
     603             : inline bool
     604             : diagnostic_same_line (const diagnostic_context *context,
     605             :                        expanded_location s1, expanded_location s2)
     606             : {
     607             :   return s2.column && s1.line == s2.line 
     608             :     && context->caret_max_width - CARET_LINE_MARGIN > abs (s1.column - s2.column);
     609             : }
     610             : 
     611             : extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
     612             : extern int diagnostic_converted_column (diagnostic_context *context,
     613             :                                         expanded_location s);
     614             : 
     615             : /* Pure text formatting support functions.  */
     616             : extern char *file_name_as_prefix (diagnostic_context *, const char *);
     617             : 
     618             : extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
     619             : 
     620             : extern void diagnostic_output_format_init (diagnostic_context *,
     621             :                                            const char *base_file_name,
     622             :                                            enum diagnostics_output_format);
     623             : extern void diagnostic_output_format_init_json_stderr (diagnostic_context *context);
     624             : extern void diagnostic_output_format_init_json_file (diagnostic_context *context,
     625             :                                                      const char *base_file_name);
     626             : extern void diagnostic_output_format_init_sarif_stderr (diagnostic_context *context);
     627             : extern void diagnostic_output_format_init_sarif_file (diagnostic_context *context,
     628             :                                                       const char *base_file_name);
     629             : 
     630             : /* Compute the number of digits in the decimal representation of an integer.  */
     631             : extern int num_digits (int);
     632             : 
     633             : extern json::value *json_from_expanded_location (diagnostic_context *context,
     634             :                                                  location_t loc);
     635             : 
     636             : extern bool warning_enabled_at (location_t, int);
     637             : 
     638             : extern char *get_cwe_url (int cwe);
     639             : 
     640             : extern void diagnostic_emit_diagram (diagnostic_context *context,
     641             :                                      const diagnostic_diagram &diagram);
     642             : 
     643             : #endif /* ! GCC_DIAGNOSTIC_H */

Generated by: LCOV version 1.16