1/* Subclass of logical_location_manager with knowledge of "tree".
2 Copyright (C) 2022-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along 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#include "intl.h"
29
30static void
31assert_valid_tree (const_tree node)
32{
33 gcc_assert (node);
34 gcc_assert (DECL_P (node) || TYPE_P (node));
35 gcc_assert (TREE_CODE (node) != TRANSLATION_UNIT_DECL);
36}
37
38/* class tree_logical_location_manager : public logical_location_manager. */
39
40const char *
41tree_logical_location_manager::get_short_name (key k) const
42{
43 tree node = tree_from_key (k);
44 assert_valid_tree (node);
45
46 if (DECL_P (node))
47 return identifier_to_locale (lang_hooks.decl_printable_name (node, 0));
48 if (TYPE_P (node))
49 return IDENTIFIER_POINTER (TYPE_IDENTIFIER (node));
50 return nullptr;
51}
52
53const char *
54tree_logical_location_manager::get_name_with_scope (key k) const
55{
56 tree node = tree_from_key (k);
57 assert_valid_tree (node);
58
59 if (DECL_P (node))
60 return identifier_to_locale (lang_hooks.decl_printable_name (node, 1));
61 if (TYPE_P (node))
62 return nullptr;
63 return nullptr;
64}
65
66const char *
67tree_logical_location_manager::get_internal_name (key k) const
68{
69 tree node = tree_from_key (k);
70 assert_valid_tree (node);
71
72 if (DECL_P (node))
73 {
74 if (HAS_DECL_ASSEMBLER_NAME_P (node)
75 && TREE_CODE (node) != NAMESPACE_DECL) // FIXME
76 if (tree id = DECL_ASSEMBLER_NAME (node))
77 return IDENTIFIER_POINTER (id);
78 }
79 else if (TYPE_P (node))
80 return nullptr;
81 return NULL;
82}
83
84enum logical_location_kind
85tree_logical_location_manager::get_kind (key k) const
86{
87 tree node = tree_from_key (k);
88 assert_valid_tree (node);
89
90 switch (TREE_CODE (node))
91 {
92 default:
93 return logical_location_kind::unknown;
94 case FUNCTION_DECL:
95 return logical_location_kind::function;
96 case PARM_DECL:
97 return logical_location_kind::parameter;
98 case VAR_DECL:
99 return logical_location_kind::variable;
100 case NAMESPACE_DECL:
101 return logical_location_kind::namespace_;
102
103 case RECORD_TYPE:
104 return logical_location_kind::type;
105 }
106}
107
108label_text
109tree_logical_location_manager::get_name_for_path_output (key k) const
110{
111 tree node = tree_from_key (k);
112 assert_valid_tree (node);
113
114 if (DECL_P (node))
115 {
116 const char *n = DECL_NAME (node)
117 ? identifier_to_locale (lang_hooks.decl_printable_name (node, 2))
118 : _("<anonymous>");
119 return label_text::borrow (buffer: n);
120 }
121 else if (TYPE_P (node))
122 return label_text ();
123 return label_text ();
124}
125
126logical_location
127tree_logical_location_manager::get_parent (key k) const
128{
129 tree node = tree_from_key (k);
130 assert_valid_tree (node);
131
132 if (DECL_P (node))
133 {
134 if (!DECL_CONTEXT (node))
135 return logical_location ();
136 if (TREE_CODE (DECL_CONTEXT (node)) == TRANSLATION_UNIT_DECL)
137 return logical_location ();
138 return key_from_tree (DECL_CONTEXT (node));
139 }
140 else if (TYPE_P (node))
141 {
142 if (!TYPE_CONTEXT (node))
143 return logical_location ();
144 return key_from_tree (TYPE_CONTEXT (node));
145 }
146 return logical_location ();
147}
148

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of gcc/tree-logical-location.cc