]>
Commit | Line | Data |
---|---|---|
6cf276dd | 1 | /* Subclasses of logical_location with knowledge of "tree". |
a945c346 | 2 | Copyright (C) 2022-2024 Free Software Foundation, Inc. |
6cf276dd DM |
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 | compiler_logical_location::get_short_name_for_tree (tree decl) | |
36 | { | |
37 | gcc_assert (decl); | |
38 | 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 | compiler_logical_location::get_name_with_scope_for_tree (tree decl) | |
46 | { | |
47 | gcc_assert (decl); | |
48 | 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 | compiler_logical_location::get_internal_name_for_tree (tree decl) | |
56 | { | |
57 | gcc_assert (decl); | |
58 | if (HAS_DECL_ASSEMBLER_NAME_P (decl)) | |
59 | if (tree id = DECL_ASSEMBLER_NAME (decl)) | |
60 | 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 | compiler_logical_location::get_kind_for_tree (tree decl) | |
68 | { | |
69 | if (!decl) | |
70 | return LOGICAL_LOCATION_KIND_UNKNOWN; | |
71 | ||
72 | switch (TREE_CODE (decl)) | |
73 | { | |
74 | default: | |
75 | return LOGICAL_LOCATION_KIND_UNKNOWN; | |
76 | case FUNCTION_DECL: | |
77 | return LOGICAL_LOCATION_KIND_FUNCTION; | |
78 | case PARM_DECL: | |
79 | return LOGICAL_LOCATION_KIND_PARAMETER; | |
80 | case VAR_DECL: | |
81 | 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 | tree_logical_location::get_short_name () const | |
91 | { | |
92 | gcc_assert (m_decl); | |
93 | return get_short_name_for_tree (m_decl); | |
94 | } | |
95 | ||
96 | const char * | |
97 | tree_logical_location::get_name_with_scope () const | |
98 | { | |
99 | gcc_assert (m_decl); | |
100 | return get_name_with_scope_for_tree (m_decl); | |
101 | } | |
102 | ||
103 | const char * | |
104 | tree_logical_location::get_internal_name () const | |
105 | { | |
106 | gcc_assert (m_decl); | |
107 | return get_internal_name_for_tree (m_decl); | |
108 | } | |
109 | ||
110 | enum logical_location_kind | |
111 | tree_logical_location::get_kind () const | |
112 | { | |
113 | gcc_assert (m_decl); | |
114 | 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 | current_fndecl_logical_location::get_short_name () const | |
124 | { | |
125 | gcc_assert (current_function_decl); | |
126 | return get_short_name_for_tree (current_function_decl); | |
127 | } | |
128 | ||
129 | const char * | |
130 | current_fndecl_logical_location::get_name_with_scope () const | |
131 | { | |
132 | gcc_assert (current_function_decl); | |
133 | return get_name_with_scope_for_tree (current_function_decl); | |
134 | } | |
135 | ||
136 | const char * | |
137 | current_fndecl_logical_location::get_internal_name () const | |
138 | { | |
139 | gcc_assert (current_function_decl); | |
140 | return get_internal_name_for_tree (current_function_decl); | |
141 | } | |
142 | ||
143 | enum logical_location_kind | |
144 | current_fndecl_logical_location::get_kind () const | |
145 | { | |
146 | gcc_assert (current_function_decl); | |
147 | return get_kind_for_tree (current_function_decl); | |
148 | } |