1 /* Subclasses of logical_location with knowledge of "tree".
2 Copyright (C) 2022-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
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
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
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/>. */
23 #include "coretypes.h"
25 #include "pretty-print.h"
26 #include "tree-logical-location.h"
27 #include "langhooks.h"
30 /* class compiler_logical_location : public logical_location. */
32 /* Get a string for DECL suitable for use by the SARIF logicalLocation
33 "name" property (SARIF v2.1.0 section 3.33.4). */
36 compiler_logical_location::get_short_name_for_tree (tree decl
)
39 return identifier_to_locale (lang_hooks
.decl_printable_name (decl
, 0));
42 /* Get a string for DECL suitable for use by the SARIF logicalLocation
43 "fullyQualifiedName" property (SARIF v2.1.0 section 3.33.5). */
46 compiler_logical_location::get_name_with_scope_for_tree (tree decl
)
49 return identifier_to_locale (lang_hooks
.decl_printable_name (decl
, 1));
52 /* Get a string for DECL suitable for use by the SARIF logicalLocation
53 "decoratedName" property (SARIF v2.1.0 section 3.33.6). */
56 compiler_logical_location::get_internal_name_for_tree (tree decl
)
59 if (HAS_DECL_ASSEMBLER_NAME_P (decl
))
60 if (tree id
= DECL_ASSEMBLER_NAME (decl
))
61 return IDENTIFIER_POINTER (id
);
65 /* Get what kind of SARIF logicalLocation DECL is (if any). */
67 enum logical_location_kind
68 compiler_logical_location::get_kind_for_tree (tree decl
)
71 return LOGICAL_LOCATION_KIND_UNKNOWN
;
73 switch (TREE_CODE (decl
))
76 return LOGICAL_LOCATION_KIND_UNKNOWN
;
78 return LOGICAL_LOCATION_KIND_FUNCTION
;
80 return LOGICAL_LOCATION_KIND_PARAMETER
;
82 return LOGICAL_LOCATION_KIND_VARIABLE
;
87 compiler_logical_location::get_name_for_tree_for_path_output (tree decl
)
90 const char *n
= DECL_NAME (decl
)
91 ? identifier_to_locale (lang_hooks
.decl_printable_name (decl
, 2))
93 return label_text::borrow (n
);
96 /* class tree_logical_location : public compiler_logical_location. */
98 /* Implementation of the logical_location vfuncs, using m_decl. */
101 tree_logical_location::get_short_name () const
104 return get_short_name_for_tree (m_decl
);
108 tree_logical_location::get_name_with_scope () const
111 return get_name_with_scope_for_tree (m_decl
);
115 tree_logical_location::get_internal_name () const
118 return get_internal_name_for_tree (m_decl
);
121 enum logical_location_kind
122 tree_logical_location::get_kind () const
125 return get_kind_for_tree (m_decl
);
129 tree_logical_location::get_name_for_path_output () const
132 return get_name_for_tree_for_path_output (m_decl
);
135 /* class current_fndecl_logical_location : public compiler_logical_location. */
137 /* Implementation of the logical_location vfuncs, using
138 current_function_decl. */
141 current_fndecl_logical_location::get_short_name () const
143 gcc_assert (current_function_decl
);
144 return get_short_name_for_tree (current_function_decl
);
148 current_fndecl_logical_location::get_name_with_scope () const
150 gcc_assert (current_function_decl
);
151 return get_name_with_scope_for_tree (current_function_decl
);
155 current_fndecl_logical_location::get_internal_name () const
157 gcc_assert (current_function_decl
);
158 return get_internal_name_for_tree (current_function_decl
);
161 enum logical_location_kind
162 current_fndecl_logical_location::get_kind () const
164 gcc_assert (current_function_decl
);
165 return get_kind_for_tree (current_function_decl
);
169 current_fndecl_logical_location::get_name_for_path_output () const
171 gcc_assert (current_function_decl
);
172 return get_name_for_tree_for_path_output (current_function_decl
);