1 /* Subclasses of logical_location with knowledge of "tree".
2 Copyright (C) 2022 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"
29 /* class compiler_logical_location : public logical_location. */
31 /* Get a string for DECL suitable for use by the SARIF logicalLocation
32 "name" property (SARIF v2.1.0 section 3.33.4). */
35 compiler_logical_location::get_short_name_for_tree (tree decl
)
38 return identifier_to_locale (lang_hooks
.decl_printable_name (decl
, 0));
41 /* Get a string for DECL suitable for use by the SARIF logicalLocation
42 "fullyQualifiedName" property (SARIF v2.1.0 section 3.33.5). */
45 compiler_logical_location::get_name_with_scope_for_tree (tree decl
)
48 return identifier_to_locale (lang_hooks
.decl_printable_name (decl
, 1));
51 /* Get a string for DECL suitable for use by the SARIF logicalLocation
52 "decoratedName" property (SARIF v2.1.0 section 3.33.6). */
55 compiler_logical_location::get_internal_name_for_tree (tree decl
)
58 if (HAS_DECL_ASSEMBLER_NAME_P (decl
))
59 if (tree id
= DECL_ASSEMBLER_NAME (decl
))
60 return IDENTIFIER_POINTER (id
);
64 /* Get what kind of SARIF logicalLocation DECL is (if any). */
66 enum logical_location_kind
67 compiler_logical_location::get_kind_for_tree (tree decl
)
70 return LOGICAL_LOCATION_KIND_UNKNOWN
;
72 switch (TREE_CODE (decl
))
75 return LOGICAL_LOCATION_KIND_UNKNOWN
;
77 return LOGICAL_LOCATION_KIND_FUNCTION
;
79 return LOGICAL_LOCATION_KIND_PARAMETER
;
81 return LOGICAL_LOCATION_KIND_VARIABLE
;
85 /* class tree_logical_location : public compiler_logical_location. */
87 /* Implementation of the logical_location vfuncs, using m_decl. */
90 tree_logical_location::get_short_name () const
93 return get_short_name_for_tree (m_decl
);
97 tree_logical_location::get_name_with_scope () const
100 return get_name_with_scope_for_tree (m_decl
);
104 tree_logical_location::get_internal_name () const
107 return get_internal_name_for_tree (m_decl
);
110 enum logical_location_kind
111 tree_logical_location::get_kind () const
114 return get_kind_for_tree (m_decl
);
117 /* class current_fndecl_logical_location : public compiler_logical_location. */
119 /* Implementation of the logical_location vfuncs, using
120 current_function_decl. */
123 current_fndecl_logical_location::get_short_name () const
125 gcc_assert (current_function_decl
);
126 return get_short_name_for_tree (current_function_decl
);
130 current_fndecl_logical_location::get_name_with_scope () const
132 gcc_assert (current_function_decl
);
133 return get_name_with_scope_for_tree (current_function_decl
);
137 current_fndecl_logical_location::get_internal_name () const
139 gcc_assert (current_function_decl
);
140 return get_internal_name_for_tree (current_function_decl
);
143 enum logical_location_kind
144 current_fndecl_logical_location::get_kind () const
146 gcc_assert (current_function_decl
);
147 return get_kind_for_tree (current_function_decl
);