rs6000, change altivec*-runnable.c test file names
[official-gcc.git] / gcc / tree-logical-location.cc
blobca8b34a42d36bcd6a14ac0f4f06457ef47b9bc0c
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>.
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
10 version.
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.
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/>. */
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"
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). */
35 const char *
36 compiler_logical_location::get_short_name_for_tree (tree decl)
38 gcc_assert (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). */
45 const char *
46 compiler_logical_location::get_name_with_scope_for_tree (tree decl)
48 gcc_assert (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). */
55 const char *
56 compiler_logical_location::get_internal_name_for_tree (tree decl)
58 gcc_assert (decl);
59 if (HAS_DECL_ASSEMBLER_NAME_P (decl))
60 if (tree id = DECL_ASSEMBLER_NAME (decl))
61 return IDENTIFIER_POINTER (id);
62 return NULL;
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)
70 if (!decl)
71 return LOGICAL_LOCATION_KIND_UNKNOWN;
73 switch (TREE_CODE (decl))
75 default:
76 return LOGICAL_LOCATION_KIND_UNKNOWN;
77 case FUNCTION_DECL:
78 return LOGICAL_LOCATION_KIND_FUNCTION;
79 case PARM_DECL:
80 return LOGICAL_LOCATION_KIND_PARAMETER;
81 case VAR_DECL:
82 return LOGICAL_LOCATION_KIND_VARIABLE;
86 label_text
87 compiler_logical_location::get_name_for_tree_for_path_output (tree decl)
89 gcc_assert (decl);
90 const char *n = DECL_NAME (decl)
91 ? identifier_to_locale (lang_hooks.decl_printable_name (decl, 2))
92 : _("<anonymous>");
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. */
100 const char *
101 tree_logical_location::get_short_name () const
103 gcc_assert (m_decl);
104 return get_short_name_for_tree (m_decl);
107 const char *
108 tree_logical_location::get_name_with_scope () const
110 gcc_assert (m_decl);
111 return get_name_with_scope_for_tree (m_decl);
114 const char *
115 tree_logical_location::get_internal_name () const
117 gcc_assert (m_decl);
118 return get_internal_name_for_tree (m_decl);
121 enum logical_location_kind
122 tree_logical_location::get_kind () const
124 gcc_assert (m_decl);
125 return get_kind_for_tree (m_decl);
128 label_text
129 tree_logical_location::get_name_for_path_output () const
131 gcc_assert (m_decl);
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. */
140 const char *
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);
147 const char *
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);
154 const char *
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);
168 label_text
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);