LCOV - code coverage report
Current view: top level - gcc - tree-logical-location.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 90.5 % 42 38
Test Date: 2024-03-23 14:05:01 Functions: 100.0 % 12 12
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                 :             : 
      29                 :             : /* class compiler_logical_location : public logical_location.  */
      30                 :             : 
      31                 :             : /* Get a string for DECL suitable for use by the SARIF logicalLocation
      32                 :             :    "name" property (SARIF v2.1.0 section 3.33.4).  */
      33                 :             : 
      34                 :             : const char *
      35                 :          82 : compiler_logical_location::get_short_name_for_tree (tree decl)
      36                 :             : {
      37                 :          82 :   gcc_assert (decl);
      38                 :          82 :   return identifier_to_locale (lang_hooks.decl_printable_name (decl, 0));
      39                 :             : }
      40                 :             : 
      41                 :             : /* Get a string for DECL suitable for use by the SARIF logicalLocation
      42                 :             :    "fullyQualifiedName" property (SARIF v2.1.0 section 3.33.5).  */
      43                 :             : 
      44                 :             : const char *
      45                 :          82 : compiler_logical_location::get_name_with_scope_for_tree (tree decl)
      46                 :             : {
      47                 :          82 :   gcc_assert (decl);
      48                 :          82 :   return identifier_to_locale (lang_hooks.decl_printable_name (decl, 1));
      49                 :             : }
      50                 :             : 
      51                 :             : /* Get a string for DECL suitable for use by the SARIF logicalLocation
      52                 :             :    "decoratedName" property (SARIF v2.1.0 section 3.33.6).  */
      53                 :             : 
      54                 :             : const char *
      55                 :          82 : compiler_logical_location::get_internal_name_for_tree (tree decl)
      56                 :             : {
      57                 :          82 :   gcc_assert (decl);
      58                 :          82 :   if (HAS_DECL_ASSEMBLER_NAME_P (decl))
      59                 :          82 :     if (tree id = DECL_ASSEMBLER_NAME (decl))
      60                 :          82 :       return IDENTIFIER_POINTER (id);
      61                 :             :   return NULL;
      62                 :             : }
      63                 :             : 
      64                 :             : /* Get what kind of SARIF logicalLocation DECL is (if any).  */
      65                 :             : 
      66                 :             : enum logical_location_kind
      67                 :          82 : compiler_logical_location::get_kind_for_tree (tree decl)
      68                 :             : {
      69                 :          82 :   if (!decl)
      70                 :             :     return LOGICAL_LOCATION_KIND_UNKNOWN;
      71                 :             : 
      72                 :          82 :   switch (TREE_CODE (decl))
      73                 :             :     {
      74                 :             :     default:
      75                 :             :       return LOGICAL_LOCATION_KIND_UNKNOWN;
      76                 :             :     case FUNCTION_DECL:
      77                 :             :       return LOGICAL_LOCATION_KIND_FUNCTION;
      78                 :           0 :     case PARM_DECL:
      79                 :           0 :       return LOGICAL_LOCATION_KIND_PARAMETER;
      80                 :           0 :     case VAR_DECL:
      81                 :           0 :       return LOGICAL_LOCATION_KIND_VARIABLE;
      82                 :             :     }
      83                 :             : }
      84                 :             : 
      85                 :             : /* class tree_logical_location : public compiler_logical_location.  */
      86                 :             : 
      87                 :             : /* Implementation of the logical_location vfuncs, using m_decl.  */
      88                 :             : 
      89                 :             : const char *
      90                 :          45 : tree_logical_location::get_short_name () const
      91                 :             : {
      92                 :          45 :   gcc_assert (m_decl);
      93                 :          45 :   return get_short_name_for_tree (m_decl);
      94                 :             : }
      95                 :             : 
      96                 :             : const char *
      97                 :          45 : tree_logical_location::get_name_with_scope () const
      98                 :             : {
      99                 :          45 :   gcc_assert (m_decl);
     100                 :          45 :   return get_name_with_scope_for_tree (m_decl);
     101                 :             : }
     102                 :             : 
     103                 :             : const char *
     104                 :          45 : tree_logical_location::get_internal_name () const
     105                 :             : {
     106                 :          45 :   gcc_assert (m_decl);
     107                 :          45 :   return get_internal_name_for_tree (m_decl);
     108                 :             : }
     109                 :             : 
     110                 :             : enum logical_location_kind
     111                 :          45 : tree_logical_location::get_kind () const
     112                 :             : {
     113                 :          45 :   gcc_assert (m_decl);
     114                 :          45 :   return get_kind_for_tree (m_decl);
     115                 :             : }
     116                 :             : 
     117                 :             : /* class current_fndecl_logical_location : public compiler_logical_location.  */
     118                 :             : 
     119                 :             : /* Implementation of the logical_location vfuncs, using
     120                 :             :    current_function_decl.  */
     121                 :             : 
     122                 :             : const char *
     123                 :          37 : current_fndecl_logical_location::get_short_name () const
     124                 :             : {
     125                 :          37 :   gcc_assert (current_function_decl);
     126                 :          37 :   return get_short_name_for_tree (current_function_decl);
     127                 :             : }
     128                 :             : 
     129                 :             : const char *
     130                 :          37 : current_fndecl_logical_location::get_name_with_scope () const
     131                 :             : {
     132                 :          37 :   gcc_assert (current_function_decl);
     133                 :          37 :   return get_name_with_scope_for_tree (current_function_decl);
     134                 :             : }
     135                 :             : 
     136                 :             : const char *
     137                 :          37 : current_fndecl_logical_location::get_internal_name () const
     138                 :             : {
     139                 :          37 :   gcc_assert (current_function_decl);
     140                 :          37 :   return get_internal_name_for_tree (current_function_decl);
     141                 :             : }
     142                 :             : 
     143                 :             : enum logical_location_kind
     144                 :          37 : current_fndecl_logical_location::get_kind () const
     145                 :             : {
     146                 :          37 :   gcc_assert (current_function_decl);
     147                 :          37 :   return get_kind_for_tree (current_function_decl);
     148                 :             : }
        

Generated by: LCOV version 2.0-1

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.