LCOV - code coverage report
Current view: top level - gcc - tree-logical-location.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.2 % 54 46
Test Date: 2024-12-21 13:15:12 Functions: 93.3 % 15 14
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Subclasses of logical_location with knowledge of "tree".
       2                 :             :    Copyright (C) 2022-2024 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                 :             : /* class compiler_logical_location : public logical_location.  */
      31                 :             : 
      32                 :             : /* Get a string for DECL suitable for use by the SARIF logicalLocation
      33                 :             :    "name" property (SARIF v2.1.0 section 3.33.4).  */
      34                 :             : 
      35                 :             : const char *
      36                 :         104 : compiler_logical_location::get_short_name_for_tree (tree decl)
      37                 :             : {
      38                 :         104 :   gcc_assert (decl);
      39                 :         104 :   return identifier_to_locale (lang_hooks.decl_printable_name (decl, 0));
      40                 :             : }
      41                 :             : 
      42                 :             : /* Get a string for DECL suitable for use by the SARIF logicalLocation
      43                 :             :    "fullyQualifiedName" property (SARIF v2.1.0 section 3.33.5).  */
      44                 :             : 
      45                 :             : const char *
      46                 :         104 : compiler_logical_location::get_name_with_scope_for_tree (tree decl)
      47                 :             : {
      48                 :         104 :   gcc_assert (decl);
      49                 :         104 :   return identifier_to_locale (lang_hooks.decl_printable_name (decl, 1));
      50                 :             : }
      51                 :             : 
      52                 :             : /* Get a string for DECL suitable for use by the SARIF logicalLocation
      53                 :             :    "decoratedName" property (SARIF v2.1.0 section 3.33.6).  */
      54                 :             : 
      55                 :             : const char *
      56                 :         104 : compiler_logical_location::get_internal_name_for_tree (tree decl)
      57                 :             : {
      58                 :         104 :   gcc_assert (decl);
      59                 :         104 :   if (HAS_DECL_ASSEMBLER_NAME_P (decl))
      60                 :         104 :     if (tree id = DECL_ASSEMBLER_NAME (decl))
      61                 :         104 :       return IDENTIFIER_POINTER (id);
      62                 :             :   return NULL;
      63                 :             : }
      64                 :             : 
      65                 :             : /* Get what kind of SARIF logicalLocation DECL is (if any).  */
      66                 :             : 
      67                 :             : enum logical_location_kind
      68                 :        3960 : compiler_logical_location::get_kind_for_tree (tree decl)
      69                 :             : {
      70                 :        3960 :   if (!decl)
      71                 :             :     return LOGICAL_LOCATION_KIND_UNKNOWN;
      72                 :             : 
      73                 :        3960 :   switch (TREE_CODE (decl))
      74                 :             :     {
      75                 :             :     default:
      76                 :             :       return LOGICAL_LOCATION_KIND_UNKNOWN;
      77                 :             :     case FUNCTION_DECL:
      78                 :             :       return LOGICAL_LOCATION_KIND_FUNCTION;
      79                 :           0 :     case PARM_DECL:
      80                 :           0 :       return LOGICAL_LOCATION_KIND_PARAMETER;
      81                 :           0 :     case VAR_DECL:
      82                 :           0 :       return LOGICAL_LOCATION_KIND_VARIABLE;
      83                 :             :     }
      84                 :             : }
      85                 :             : 
      86                 :             : label_text
      87                 :         761 : compiler_logical_location::get_name_for_tree_for_path_output (tree decl)
      88                 :             : {
      89                 :         761 :   gcc_assert (decl);
      90                 :         761 :   const char *n = DECL_NAME (decl)
      91                 :         761 :     ? identifier_to_locale (lang_hooks.decl_printable_name (decl, 2))
      92                 :           0 :     : _("<anonymous>");
      93                 :         761 :   return label_text::borrow (n);
      94                 :             : }
      95                 :             : 
      96                 :             : /* class tree_logical_location : public compiler_logical_location.  */
      97                 :             : 
      98                 :             : /* Implementation of the logical_location vfuncs, using m_decl.  */
      99                 :             : 
     100                 :             : const char *
     101                 :          59 : tree_logical_location::get_short_name () const
     102                 :             : {
     103                 :          59 :   gcc_assert (m_decl);
     104                 :          59 :   return get_short_name_for_tree (m_decl);
     105                 :             : }
     106                 :             : 
     107                 :             : const char *
     108                 :          59 : tree_logical_location::get_name_with_scope () const
     109                 :             : {
     110                 :          59 :   gcc_assert (m_decl);
     111                 :          59 :   return get_name_with_scope_for_tree (m_decl);
     112                 :             : }
     113                 :             : 
     114                 :             : const char *
     115                 :          59 : tree_logical_location::get_internal_name () const
     116                 :             : {
     117                 :          59 :   gcc_assert (m_decl);
     118                 :          59 :   return get_internal_name_for_tree (m_decl);
     119                 :             : }
     120                 :             : 
     121                 :             : enum logical_location_kind
     122                 :        3915 : tree_logical_location::get_kind () const
     123                 :             : {
     124                 :        3915 :   gcc_assert (m_decl);
     125                 :        3915 :   return get_kind_for_tree (m_decl);
     126                 :             : }
     127                 :             : 
     128                 :             : label_text
     129                 :         761 : tree_logical_location::get_name_for_path_output () const
     130                 :             : {
     131                 :         761 :   gcc_assert (m_decl);
     132                 :         761 :   return get_name_for_tree_for_path_output (m_decl);
     133                 :             : }
     134                 :             : 
     135                 :             : /* class current_fndecl_logical_location : public compiler_logical_location.  */
     136                 :             : 
     137                 :             : /* Implementation of the logical_location vfuncs, using
     138                 :             :    current_function_decl.  */
     139                 :             : 
     140                 :             : const char *
     141                 :          45 : current_fndecl_logical_location::get_short_name () const
     142                 :             : {
     143                 :          45 :   gcc_assert (current_function_decl);
     144                 :          45 :   return get_short_name_for_tree (current_function_decl);
     145                 :             : }
     146                 :             : 
     147                 :             : const char *
     148                 :          45 : current_fndecl_logical_location::get_name_with_scope () const
     149                 :             : {
     150                 :          45 :   gcc_assert (current_function_decl);
     151                 :          45 :   return get_name_with_scope_for_tree (current_function_decl);
     152                 :             : }
     153                 :             : 
     154                 :             : const char *
     155                 :          45 : current_fndecl_logical_location::get_internal_name () const
     156                 :             : {
     157                 :          45 :   gcc_assert (current_function_decl);
     158                 :          45 :   return get_internal_name_for_tree (current_function_decl);
     159                 :             : }
     160                 :             : 
     161                 :             : enum logical_location_kind
     162                 :          45 : current_fndecl_logical_location::get_kind () const
     163                 :             : {
     164                 :          45 :   gcc_assert (current_function_decl);
     165                 :          45 :   return get_kind_for_tree (current_function_decl);
     166                 :             : }
     167                 :             : 
     168                 :             : label_text
     169                 :           0 : current_fndecl_logical_location::get_name_for_path_output () const
     170                 :             : {
     171                 :           0 :   gcc_assert (current_function_decl);
     172                 :           0 :   return get_name_for_tree_for_path_output (current_function_decl);
     173                 :             : }
        

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.