LCOV - code coverage report
Current view: top level - gcc - tree-logical-location.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 83.8 % 68 57
Test Date: 2026-02-28 14:20:25 Functions: 87.5 % 8 7
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Subclass of logical_location_manager with knowledge of "tree".
       2              :    Copyright (C) 2022-2026 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         7906 : assert_valid_tree (const_tree node)
      35              : {
      36         7906 :   gcc_assert (node);
      37         7906 :   gcc_assert (DECL_P (node) || TYPE_P (node));
      38         7906 :   gcc_assert (TREE_CODE (node) != TRANSLATION_UNIT_DECL);
      39         7906 : }
      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              : label_text
      52          555 : tree_logical_location_manager::get_short_name (key k) const
      53              : {
      54          555 :   tree node = tree_from_key (k);
      55          555 :   assert_valid_tree (node);
      56              : 
      57          555 :   if (DECL_P (node))
      58          537 :     return label_text::borrow
      59          537 :       (identifier_to_locale (lang_hooks.decl_printable_name (node, 0)));
      60           18 :   if (TYPE_P (node))
      61           36 :     return label_text::borrow (IDENTIFIER_POINTER (TYPE_IDENTIFIER (node)));
      62            0 :   return label_text ();
      63              : }
      64              : 
      65              : label_text
      66          943 : tree_logical_location_manager::get_name_with_scope (key k) const
      67              : {
      68          943 :   tree node = tree_from_key (k);
      69          943 :   assert_valid_tree (node);
      70              : 
      71          943 :   if (DECL_P (node))
      72          925 :     return label_text::borrow
      73          925 :       (identifier_to_locale (lang_hooks.decl_printable_name (node, 1)));
      74           18 :   if (TYPE_P (node))
      75           18 :     return label_text ();
      76            0 :   return label_text ();
      77              : }
      78              : 
      79              : label_text
      80          554 : tree_logical_location_manager::get_internal_name (key k) const
      81              : {
      82          554 :   tree node = tree_from_key (k);
      83          554 :   assert_valid_tree (node);
      84              : 
      85          554 :   if (DECL_P (node))
      86              :     {
      87          536 :       if (HAS_DECL_ASSEMBLER_NAME_P (node)
      88          536 :           && TREE_CODE (node) != NAMESPACE_DECL) // FIXME
      89          319 :         if (tree id = DECL_ASSEMBLER_NAME (node))
      90          319 :           return label_text::borrow (IDENTIFIER_POINTER (id));
      91              :     }
      92           18 :   else if (TYPE_P (node))
      93           18 :     return label_text ();
      94          217 :   return label_text ();
      95              : }
      96              : 
      97              : enum kind
      98         4527 : tree_logical_location_manager::get_kind (key k) const
      99              : {
     100         4527 :   tree node = tree_from_key (k);
     101         4527 :   assert_valid_tree (node);
     102              : 
     103         4527 :   switch (TREE_CODE (node))
     104              :     {
     105              :     default:
     106              :       return kind::unknown;
     107              :     case FUNCTION_DECL:
     108              :       return kind::function;
     109              :     case PARM_DECL:
     110              :       return kind::parameter;
     111              :     case VAR_DECL:
     112              :       return kind::variable;
     113              :     case NAMESPACE_DECL:
     114              :       return kind::namespace_;
     115              : 
     116              :     case RECORD_TYPE:
     117              :       return kind::type;
     118              :     }
     119              : }
     120              : 
     121              : label_text
     122          773 : tree_logical_location_manager::get_name_for_path_output (key k) const
     123              : {
     124          773 :   tree node = tree_from_key (k);
     125          773 :   assert_valid_tree (node);
     126              : 
     127          773 :   if (DECL_P (node))
     128              :     {
     129          773 :       const char *n = DECL_NAME (node)
     130          773 :         ? identifier_to_locale (lang_hooks.decl_printable_name (node, 2))
     131            0 :         : _("<anonymous>");
     132          773 :       return label_text::borrow (n);
     133              :     }
     134            0 :   else if (TYPE_P (node))
     135            0 :     return label_text ();
     136            0 :   return label_text ();
     137              : }
     138              : 
     139              : key
     140          554 : tree_logical_location_manager::get_parent (key k) const
     141              : {
     142          554 :   tree node = tree_from_key (k);
     143          554 :   assert_valid_tree (node);
     144              : 
     145          554 :   if (DECL_P (node))
     146              :     {
     147          536 :       if (!DECL_CONTEXT (node))
     148           10 :         return key ();
     149          526 :       if (TREE_CODE (DECL_CONTEXT (node)) == TRANSLATION_UNIT_DECL)
     150          300 :         return key ();
     151          226 :       return key_from_tree (DECL_CONTEXT (node));
     152              :     }
     153           18 :   else if (TYPE_P (node))
     154              :     {
     155           18 :       if (!TYPE_CONTEXT (node))
     156            0 :         return key ();
     157           18 :       if (TREE_CODE (TYPE_CONTEXT (node)) == TRANSLATION_UNIT_DECL)
     158            9 :         return key ();
     159            9 :       return key_from_tree (TYPE_CONTEXT (node));
     160              :     }
     161            0 :   return key ();
     162              : }
        

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.