LCOV - code coverage report
Current view: top level - gcc - tree-logical-location.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 88.9 % 54 48
Test Date: 2025-07-05 13:26:22 Functions: 100.0 % 7 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                 :             : 
      30                 :             : static void
      31                 :        6876 : assert_valid_tree (const_tree node)
      32                 :             : {
      33                 :        6876 :   gcc_assert (node);
      34                 :        6876 :   gcc_assert (DECL_P (node) || TYPE_P (node));
      35                 :        6876 :   gcc_assert (TREE_CODE (node) != TRANSLATION_UNIT_DECL);
      36                 :        6876 : }
      37                 :             : 
      38                 :             : /* class tree_logical_location_manager : public logical_location_manager.  */
      39                 :             : 
      40                 :             : const char *
      41                 :         369 : tree_logical_location_manager::get_short_name (key k) const
      42                 :             : {
      43                 :         369 :   tree node = tree_from_key (k);
      44                 :         369 :   assert_valid_tree (node);
      45                 :             : 
      46                 :         369 :   if (DECL_P (node))
      47                 :         360 :     return identifier_to_locale (lang_hooks.decl_printable_name (node, 0));
      48                 :           9 :   if (TYPE_P (node))
      49                 :          18 :     return IDENTIFIER_POINTER (TYPE_IDENTIFIER (node));
      50                 :             :   return nullptr;
      51                 :             : }
      52                 :             : 
      53                 :             : const char *
      54                 :         578 : tree_logical_location_manager::get_name_with_scope (key k) const
      55                 :             : {
      56                 :         578 :   tree node = tree_from_key (k);
      57                 :         578 :   assert_valid_tree (node);
      58                 :             : 
      59                 :         578 :   if (DECL_P (node))
      60                 :         569 :     return identifier_to_locale (lang_hooks.decl_printable_name (node, 1));
      61                 :             :   if (TYPE_P (node))
      62                 :             :     return nullptr;
      63                 :             :   return nullptr;
      64                 :             : }
      65                 :             : 
      66                 :             : const char *
      67                 :         369 : tree_logical_location_manager::get_internal_name (key k) const
      68                 :             : {
      69                 :         369 :   tree node = tree_from_key (k);
      70                 :         369 :   assert_valid_tree (node);
      71                 :             : 
      72                 :         369 :   if (DECL_P (node))
      73                 :             :     {
      74                 :         360 :       if (HAS_DECL_ASSEMBLER_NAME_P (node)
      75                 :         360 :           && TREE_CODE (node) != NAMESPACE_DECL) // FIXME
      76                 :         143 :         if (tree id = DECL_ASSEMBLER_NAME (node))
      77                 :         143 :           return IDENTIFIER_POINTER (id);
      78                 :             :     }
      79                 :             :   else if (TYPE_P (node))
      80                 :             :     return nullptr;
      81                 :             :   return NULL;
      82                 :             : }
      83                 :             : 
      84                 :             : enum logical_location_kind
      85                 :        4425 : tree_logical_location_manager::get_kind (key k) const
      86                 :             : {
      87                 :        4425 :   tree node = tree_from_key (k);
      88                 :        4425 :   assert_valid_tree (node);
      89                 :             : 
      90                 :        4425 :   switch (TREE_CODE (node))
      91                 :             :     {
      92                 :             :     default:
      93                 :             :       return logical_location_kind::unknown;
      94                 :             :     case FUNCTION_DECL:
      95                 :             :       return logical_location_kind::function;
      96                 :             :     case PARM_DECL:
      97                 :             :       return logical_location_kind::parameter;
      98                 :             :     case VAR_DECL:
      99                 :             :       return logical_location_kind::variable;
     100                 :             :     case NAMESPACE_DECL:
     101                 :             :       return logical_location_kind::namespace_;
     102                 :             : 
     103                 :             :     case RECORD_TYPE:
     104                 :             :       return logical_location_kind::type;
     105                 :             :     }
     106                 :             : }
     107                 :             : 
     108                 :             : label_text
     109                 :         766 : tree_logical_location_manager::get_name_for_path_output (key k) const
     110                 :             : {
     111                 :         766 :   tree node = tree_from_key (k);
     112                 :         766 :   assert_valid_tree (node);
     113                 :             : 
     114                 :         766 :   if (DECL_P (node))
     115                 :             :     {
     116                 :         766 :       const char *n = DECL_NAME (node)
     117                 :         766 :         ? identifier_to_locale (lang_hooks.decl_printable_name (node, 2))
     118                 :           0 :         : _("<anonymous>");
     119                 :         766 :       return label_text::borrow (n);
     120                 :             :     }
     121                 :           0 :   else if (TYPE_P (node))
     122                 :           0 :     return label_text ();
     123                 :           0 :   return label_text ();
     124                 :             : }
     125                 :             : 
     126                 :             : logical_location
     127                 :         369 : tree_logical_location_manager::get_parent (key k) const
     128                 :             : {
     129                 :         369 :   tree node = tree_from_key (k);
     130                 :         369 :   assert_valid_tree (node);
     131                 :             : 
     132                 :         369 :   if (DECL_P (node))
     133                 :             :     {
     134                 :         360 :       if (!DECL_CONTEXT (node))
     135                 :          10 :         return logical_location ();
     136                 :         350 :       if (TREE_CODE (DECL_CONTEXT (node)) == TRANSLATION_UNIT_DECL)
     137                 :         133 :         return logical_location ();
     138                 :         217 :       return key_from_tree (DECL_CONTEXT (node));
     139                 :             :     }
     140                 :           9 :   else if (TYPE_P (node))
     141                 :             :     {
     142                 :           9 :       if (!TYPE_CONTEXT (node))
     143                 :           0 :         return logical_location ();
     144                 :           9 :       return key_from_tree (TYPE_CONTEXT (node));
     145                 :             :     }
     146                 :           0 :   return logical_location ();
     147                 :             : }
        

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.