LCOV - code coverage report
Current view: top level - gcc - tree-logical-location.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 84.2 % 57 48
Test Date: 2025-09-20 13:40:47 Functions: 87.5 % 8 7
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Subclass of logical_location_manager with knowledge of "tree".
       2                 :             :    Copyright (C) 2022-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by David Malcolm <dmalcolm@redhat.com>.
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             : for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : #include "config.h"
      22                 :             : #include "system.h"
      23                 :             : #include "coretypes.h"
      24                 :             : #include "tree.h"
      25                 :             : #include "pretty-print.h"
      26                 :             : #include "tree-logical-location.h"
      27                 :             : #include "langhooks.h"
      28                 :             : #include "intl.h"
      29                 :             : #include "diagnostics/dumping.h"
      30                 :             : 
      31                 :             : using namespace diagnostics::logical_locations;
      32                 :             : 
      33                 :             : static void
      34                 :        7137 : assert_valid_tree (const_tree node)
      35                 :             : {
      36                 :        7137 :   gcc_assert (node);
      37                 :        7137 :   gcc_assert (DECL_P (node) || TYPE_P (node));
      38                 :        7137 :   gcc_assert (TREE_CODE (node) != TRANSLATION_UNIT_DECL);
      39                 :        7137 : }
      40                 :             : 
      41                 :             : /* class tree_logical_location_manager
      42                 :             :    : public diagnostics::logical_locations::manager.  */
      43                 :             : 
      44                 :             : void
      45                 :           0 : tree_logical_location_manager::dump (FILE *outfile, int indent) const
      46                 :             : {
      47                 :           0 :   diagnostics::dumping::emit_heading (outfile, indent,
      48                 :             :                                       "tree_logical_location_manager");
      49                 :           0 : }
      50                 :             : 
      51                 :             : const char *
      52                 :         413 : tree_logical_location_manager::get_short_name (key k) const
      53                 :             : {
      54                 :         413 :   tree node = tree_from_key (k);
      55                 :         413 :   assert_valid_tree (node);
      56                 :             : 
      57                 :         413 :   if (DECL_P (node))
      58                 :         404 :     return identifier_to_locale (lang_hooks.decl_printable_name (node, 0));
      59                 :           9 :   if (TYPE_P (node))
      60                 :          18 :     return IDENTIFIER_POINTER (TYPE_IDENTIFIER (node));
      61                 :             :   return nullptr;
      62                 :             : }
      63                 :             : 
      64                 :             : const char *
      65                 :         668 : tree_logical_location_manager::get_name_with_scope (key k) const
      66                 :             : {
      67                 :         668 :   tree node = tree_from_key (k);
      68                 :         668 :   assert_valid_tree (node);
      69                 :             : 
      70                 :         668 :   if (DECL_P (node))
      71                 :         659 :     return identifier_to_locale (lang_hooks.decl_printable_name (node, 1));
      72                 :             :   if (TYPE_P (node))
      73                 :             :     return nullptr;
      74                 :             :   return nullptr;
      75                 :             : }
      76                 :             : 
      77                 :             : const char *
      78                 :         412 : tree_logical_location_manager::get_internal_name (key k) const
      79                 :             : {
      80                 :         412 :   tree node = tree_from_key (k);
      81                 :         412 :   assert_valid_tree (node);
      82                 :             : 
      83                 :         412 :   if (DECL_P (node))
      84                 :             :     {
      85                 :         403 :       if (HAS_DECL_ASSEMBLER_NAME_P (node)
      86                 :         403 :           && TREE_CODE (node) != NAMESPACE_DECL) // FIXME
      87                 :         186 :         if (tree id = DECL_ASSEMBLER_NAME (node))
      88                 :         186 :           return IDENTIFIER_POINTER (id);
      89                 :             :     }
      90                 :             :   else if (TYPE_P (node))
      91                 :             :     return nullptr;
      92                 :             :   return NULL;
      93                 :             : }
      94                 :             : 
      95                 :             : enum kind
      96                 :        4459 : tree_logical_location_manager::get_kind (key k) const
      97                 :             : {
      98                 :        4459 :   tree node = tree_from_key (k);
      99                 :        4459 :   assert_valid_tree (node);
     100                 :             : 
     101                 :        4459 :   switch (TREE_CODE (node))
     102                 :             :     {
     103                 :             :     default:
     104                 :             :       return kind::unknown;
     105                 :             :     case FUNCTION_DECL:
     106                 :             :       return kind::function;
     107                 :             :     case PARM_DECL:
     108                 :             :       return kind::parameter;
     109                 :             :     case VAR_DECL:
     110                 :             :       return kind::variable;
     111                 :             :     case NAMESPACE_DECL:
     112                 :             :       return kind::namespace_;
     113                 :             : 
     114                 :             :     case RECORD_TYPE:
     115                 :             :       return kind::type;
     116                 :             :     }
     117                 :             : }
     118                 :             : 
     119                 :             : label_text
     120                 :         773 : tree_logical_location_manager::get_name_for_path_output (key k) const
     121                 :             : {
     122                 :         773 :   tree node = tree_from_key (k);
     123                 :         773 :   assert_valid_tree (node);
     124                 :             : 
     125                 :         773 :   if (DECL_P (node))
     126                 :             :     {
     127                 :         773 :       const char *n = DECL_NAME (node)
     128                 :         773 :         ? identifier_to_locale (lang_hooks.decl_printable_name (node, 2))
     129                 :           0 :         : _("<anonymous>");
     130                 :         773 :       return label_text::borrow (n);
     131                 :             :     }
     132                 :           0 :   else if (TYPE_P (node))
     133                 :           0 :     return label_text ();
     134                 :           0 :   return label_text ();
     135                 :             : }
     136                 :             : 
     137                 :             : key
     138                 :         412 : tree_logical_location_manager::get_parent (key k) const
     139                 :             : {
     140                 :         412 :   tree node = tree_from_key (k);
     141                 :         412 :   assert_valid_tree (node);
     142                 :             : 
     143                 :         412 :   if (DECL_P (node))
     144                 :             :     {
     145                 :         403 :       if (!DECL_CONTEXT (node))
     146                 :          10 :         return key ();
     147                 :         393 :       if (TREE_CODE (DECL_CONTEXT (node)) == TRANSLATION_UNIT_DECL)
     148                 :         176 :         return key ();
     149                 :         217 :       return key_from_tree (DECL_CONTEXT (node));
     150                 :             :     }
     151                 :           9 :   else if (TYPE_P (node))
     152                 :             :     {
     153                 :           9 :       if (!TYPE_CONTEXT (node))
     154                 :           0 :         return key ();
     155                 :           9 :       return key_from_tree (TYPE_CONTEXT (node));
     156                 :             :     }
     157                 :           0 :   return key ();
     158                 :             : }
        

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.