LCOV - code coverage report
Current view: top level - gcc - gcc-rich-location.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 6 6
Test Date: 2026-02-28 14:20:25 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Declarations relating to class gcc_rich_location
       2              :    Copyright (C) 2014-2026 Free Software Foundation, Inc.
       3              : 
       4              : This file is part of GCC.
       5              : 
       6              : GCC is free software; you can redistribute it and/or modify it under
       7              : the terms of the GNU General Public License as published by the Free
       8              : Software Foundation; either version 3, or (at your option) any later
       9              : version.
      10              : 
      11              : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12              : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13              : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14              : for more details.
      15              : 
      16              : You should have received a copy of the GNU General Public License
      17              : along with GCC; see the file COPYING3.  If not see
      18              : <http://www.gnu.org/licenses/>.  */
      19              : 
      20              : #ifndef GCC_RICH_LOCATION_H
      21              : #define GCC_RICH_LOCATION_H
      22              : 
      23              : #include "rich-location.h"
      24              : 
      25              : namespace diagnostics { class source_print_policy; }
      26              : 
      27              : /* A gcc_rich_location is libcpp's rich_location with additional
      28              :    helper methods for working with gcc's types.  The class is not
      29              :    copyable or assignable because rich_location isn't. */
      30              : 
      31       346369 : class gcc_rich_location : public rich_location
      32              : {
      33              :  public:
      34              :   /* Constructors.  */
      35              : 
      36              :   /* Constructing from a location.  */
      37      1216691 :   explicit gcc_rich_location (location_t loc)
      38      1216691 :     : rich_location (line_table, loc, nullptr, nullptr)
      39              :   {
      40      1216691 :   }
      41              : 
      42              :   /* Constructing from a location with a label and a highlight color.  */
      43        20074 :   explicit gcc_rich_location (location_t loc,
      44              :                               const range_label *label,
      45              :                               const char *highlight_color)
      46        20074 :     : rich_location (line_table, loc, label, highlight_color)
      47              :   {
      48              :   }
      49              : 
      50              :   /* Methods for adding ranges via gcc entities.  */
      51              :   void
      52              :   add_expr (tree expr,
      53              :             range_label *label,
      54              :             const char *highlight_color);
      55              : 
      56              :   void
      57              :   maybe_add_expr (tree t,
      58              :                   range_label *label,
      59              :                   const char *highlight_color);
      60              : 
      61              :   void add_fixit_misspelled_id (location_t misspelled_token_loc,
      62              :                                 tree hint_id);
      63              : 
      64              :   /* If LOC is within the spans of lines that will already be printed for
      65              :      this gcc_rich_location, then add it as a secondary location
      66              :      and return true.
      67              : 
      68              :      Otherwise return false.
      69              : 
      70              :      This allows for a diagnostic to compactly print secondary locations
      71              :      in one diagnostic when these are near enough the primary locations for
      72              :      diagnostics-show-locus.c to cope with them, and to fall back to
      73              :      printing them via a note otherwise e.g.:
      74              : 
      75              :         gcc_rich_location richloc (primary_loc);
      76              :         bool added secondary = richloc.add_location_if_nearby (*global_dc,
      77              :                                                                secondary_loc);
      78              :         error_at (&richloc, "main message");
      79              :         if (!added secondary)
      80              :           inform (secondary_loc, "message for secondary");
      81              : 
      82              :      Implemented in diagnostics/source-printing.cc.  */
      83              : 
      84              :   bool add_location_if_nearby (const diagnostics::source_print_policy &policy,
      85              :                                location_t loc,
      86              :                                bool restrict_to_current_line_spans = true,
      87              :                                const range_label *label = NULL);
      88              : 
      89              :   bool add_location_if_nearby (const diagnostics::context &dc,
      90              :                                location_t loc,
      91              :                                bool restrict_to_current_line_spans = true,
      92              :                                const range_label *label = NULL);
      93              : 
      94              :   /* Add a fix-it hint suggesting the insertion of CONTENT before
      95              :      INSERTION_POINT.
      96              : 
      97              :      Attempt to handle formatting: if INSERTION_POINT is the first thing on
      98              :      its line, and INDENT is sufficiently sane, then add CONTENT on its own
      99              :      line, using the indentation of INDENT.
     100              :      Otherwise, add CONTENT directly before INSERTION_POINT.
     101              : 
     102              :      For example, adding "CONTENT;" with the closing brace as the insertion
     103              :      point and using "INDENT;" for indentation:
     104              : 
     105              :        if ()
     106              :          {
     107              :            INDENT;
     108              :          }
     109              : 
     110              :      would lead to:
     111              : 
     112              :        if ()
     113              :          {
     114              :            INDENT;
     115              :            CONTENT;
     116              :          }
     117              : 
     118              :      but adding it to:
     119              : 
     120              :        if () {INDENT;}
     121              : 
     122              :      would lead to:
     123              : 
     124              :        if () {INDENT;CONTENT;}
     125              :   */
     126              :   void add_fixit_insert_formatted (const char *content,
     127              :                                    location_t insertion_point,
     128              :                                    location_t indent);
     129              : };
     130              : 
     131              : #endif /* GCC_RICH_LOCATION_H */
        

Generated by: LCOV version 2.4-beta

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