annotate gcc/cp/cp-lang.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Language-dependent hooks for C++.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2001-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Alexandre Oliva <aoliva@redhat.com>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
10 any later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
15 GNU General Public License for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "cp-tree.h"
kono
parents:
diff changeset
25 #include "stor-layout.h"
kono
parents:
diff changeset
26 #include "langhooks.h"
kono
parents:
diff changeset
27 #include "langhooks-def.h"
kono
parents:
diff changeset
28 #include "cp-objcp-common.h"
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 enum c_language_kind c_language = clk_cxx;
kono
parents:
diff changeset
31 static const char * cxx_dwarf_name (tree t, int verbosity);
kono
parents:
diff changeset
32 static enum classify_record cp_classify_record (tree type);
kono
parents:
diff changeset
33 static tree cp_eh_personality (void);
kono
parents:
diff changeset
34 static tree get_template_innermost_arguments_folded (const_tree);
kono
parents:
diff changeset
35 static tree get_template_argument_pack_elems_folded (const_tree);
kono
parents:
diff changeset
36 static tree cxx_enum_underlying_base_type (const_tree);
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h;
kono
parents:
diff changeset
39 consequently, there should be very few hooks below. */
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 #undef LANG_HOOKS_NAME
kono
parents:
diff changeset
42 #define LANG_HOOKS_NAME "GNU C++"
kono
parents:
diff changeset
43 #undef LANG_HOOKS_INIT
kono
parents:
diff changeset
44 #define LANG_HOOKS_INIT cxx_init
kono
parents:
diff changeset
45 #undef LANG_HOOKS_CLASSIFY_RECORD
kono
parents:
diff changeset
46 #define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record
kono
parents:
diff changeset
47 #undef LANG_HOOKS_GENERIC_TYPE_P
kono
parents:
diff changeset
48 #define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS
kono
parents:
diff changeset
51 #define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \
kono
parents:
diff changeset
52 get_primary_template_innermost_parameters
kono
parents:
diff changeset
53 #undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
kono
parents:
diff changeset
54 #define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \
kono
parents:
diff changeset
55 get_template_innermost_arguments_folded
kono
parents:
diff changeset
56 #undef LANG_HOOKS_FUNCTION_PARAMETER_PACK_P
kono
parents:
diff changeset
57 #define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P \
kono
parents:
diff changeset
58 function_parameter_pack_p
kono
parents:
diff changeset
59 #undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS
kono
parents:
diff changeset
60 #define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \
kono
parents:
diff changeset
61 get_template_argument_pack_elems_folded
kono
parents:
diff changeset
62 #undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P
kono
parents:
diff changeset
63 #define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \
kono
parents:
diff changeset
64 template_template_parameter_p
kono
parents:
diff changeset
65 #undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P
kono
parents:
diff changeset
66 #define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \
kono
parents:
diff changeset
67 function_parameter_expanded_from_pack_p
kono
parents:
diff changeset
68 #undef LANG_HOOKS_GET_GENERIC_FUNCTION_DECL
kono
parents:
diff changeset
69 #define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL get_function_template_decl
kono
parents:
diff changeset
70 #undef LANG_HOOKS_DWARF_NAME
kono
parents:
diff changeset
71 #define LANG_HOOKS_DWARF_NAME cxx_dwarf_name
kono
parents:
diff changeset
72 #undef LANG_HOOKS_INIT_TS
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
73 #define LANG_HOOKS_INIT_TS cp_common_init_ts
111
kono
parents:
diff changeset
74 #undef LANG_HOOKS_EH_PERSONALITY
kono
parents:
diff changeset
75 #define LANG_HOOKS_EH_PERSONALITY cp_eh_personality
kono
parents:
diff changeset
76 #undef LANG_HOOKS_EH_RUNTIME_TYPE
kono
parents:
diff changeset
77 #define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type
kono
parents:
diff changeset
78 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
kono
parents:
diff changeset
79 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 #if CHECKING_P
kono
parents:
diff changeset
82 #undef LANG_HOOKS_RUN_LANG_SELFTESTS
kono
parents:
diff changeset
83 #define LANG_HOOKS_RUN_LANG_SELFTESTS selftest::run_cp_tests
kono
parents:
diff changeset
84 #endif /* #if CHECKING_P */
kono
parents:
diff changeset
85
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86 #undef LANG_HOOKS_GET_SUBSTRING_LOCATION
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
87 #define LANG_HOOKS_GET_SUBSTRING_LOCATION c_get_substring_location
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88
111
kono
parents:
diff changeset
89 /* Each front end provides its own lang hook initializer. */
kono
parents:
diff changeset
90 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 /* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c;
kono
parents:
diff changeset
93 there should be very few routines below. */
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 /* The following function does something real, but only in Objective-C++. */
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 tree
kono
parents:
diff changeset
98 objcp_tsubst_copy_and_build (tree /*t*/,
kono
parents:
diff changeset
99 tree /*args*/,
kono
parents:
diff changeset
100 tsubst_flags_t /*complain*/,
kono
parents:
diff changeset
101 tree /*in_decl*/,
kono
parents:
diff changeset
102 bool /*function_p*/)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 return NULL_TREE;
kono
parents:
diff changeset
105 }
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 static const char *
kono
parents:
diff changeset
108 cxx_dwarf_name (tree t, int verbosity)
kono
parents:
diff changeset
109 {
kono
parents:
diff changeset
110 gcc_assert (DECL_P (t));
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 if (DECL_NAME (t)
kono
parents:
diff changeset
113 && (anon_aggrname_p (DECL_NAME (t)) || LAMBDA_TYPE_P (t)))
kono
parents:
diff changeset
114 return NULL;
kono
parents:
diff changeset
115 if (verbosity >= 2)
kono
parents:
diff changeset
116 return decl_as_dwarf_string (t,
kono
parents:
diff changeset
117 TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME
kono
parents:
diff changeset
118 | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS);
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 return lang_decl_dwarf_name (t, verbosity, false);
kono
parents:
diff changeset
121 }
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 static enum classify_record
kono
parents:
diff changeset
124 cp_classify_record (tree type)
kono
parents:
diff changeset
125 {
kono
parents:
diff changeset
126 if (TYPE_LANG_SPECIFIC (type)
kono
parents:
diff changeset
127 && CLASSTYPE_DECLARED_CLASS (type))
kono
parents:
diff changeset
128 return RECORD_IS_CLASS;
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 return RECORD_IS_STRUCT;
kono
parents:
diff changeset
131 }
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 static GTY(()) tree cp_eh_personality_decl;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 static tree
kono
parents:
diff changeset
136 cp_eh_personality (void)
kono
parents:
diff changeset
137 {
kono
parents:
diff changeset
138 if (!cp_eh_personality_decl)
kono
parents:
diff changeset
139 cp_eh_personality_decl = build_personality_function ("gxx");
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 return cp_eh_personality_decl;
kono
parents:
diff changeset
142 }
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 /* This is a subroutine of fold_cplus_constants. It returns TRUE if T
kono
parents:
diff changeset
145 is a C++ specific constant that needs to be folded further before
kono
parents:
diff changeset
146 being passed to the debug info emitter. */
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 static bool
kono
parents:
diff changeset
149 template_arg_needs_folding (const_tree t)
kono
parents:
diff changeset
150 {
kono
parents:
diff changeset
151 /* For now only PTRMEM_CST nodes are to be folded further. */
kono
parents:
diff changeset
152 if (TREE_CODE (t) == PTRMEM_CST)
kono
parents:
diff changeset
153 return true;
kono
parents:
diff changeset
154 return false;
kono
parents:
diff changeset
155 }
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 /* Fold the elements of the TREE_VEC C which are C++ specific nodes
kono
parents:
diff changeset
158 that would need folding so that they can be processed by the debug
kono
parents:
diff changeset
159 info emitter. This is a subroutine of
kono
parents:
diff changeset
160 get_template_innermost_arguments_folded and
kono
parents:
diff changeset
161 get_template_argument_pack_elems_folded. */
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 static tree
kono
parents:
diff changeset
164 fold_cplus_constants (const_tree c)
kono
parents:
diff changeset
165 {
kono
parents:
diff changeset
166 tree folded_elems, elems = CONST_CAST_TREE (c);
kono
parents:
diff changeset
167 int vec_len, i;
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 if (elems == NULL_TREE || elems == error_mark_node)
kono
parents:
diff changeset
170 return elems;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 vec_len = TREE_VEC_LENGTH (elems);
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 /* First check if there is at least one element that needs
kono
parents:
diff changeset
175 folding. If there is none, we just return ELEMS. Otherwise create
kono
parents:
diff changeset
176 and return a new tree vector that contains the folded versions of
kono
parents:
diff changeset
177 ELEMS. This is to avoid allocating memory if we don't need
kono
parents:
diff changeset
178 to. */
kono
parents:
diff changeset
179 for (i = 0; i < vec_len; ++i)
kono
parents:
diff changeset
180 {
kono
parents:
diff changeset
181 if (template_arg_needs_folding (TREE_VEC_ELT (elems, i)))
kono
parents:
diff changeset
182 break;
kono
parents:
diff changeset
183 }
kono
parents:
diff changeset
184 if (i == vec_len)
kono
parents:
diff changeset
185 return elems;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 folded_elems = make_tree_vec (vec_len);
kono
parents:
diff changeset
188 for (i = 0; i < vec_len; ++i)
kono
parents:
diff changeset
189 {
kono
parents:
diff changeset
190 tree elem = TREE_VEC_ELT (elems, i);
kono
parents:
diff changeset
191 TREE_VEC_ELT (folded_elems, i) =
kono
parents:
diff changeset
192 (elem && !TYPE_P (elem)) ? cplus_expand_constant (elem) : elem;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 }
kono
parents:
diff changeset
195 return folded_elems;
kono
parents:
diff changeset
196 }
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 /* The C++ implementation of the LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS
kono
parents:
diff changeset
199 hook. It returns the innermost template arguments of type T, and
kono
parents:
diff changeset
200 makes sure those arguments are folded enough for the debug info
kono
parents:
diff changeset
201 emitter. */
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 static tree
kono
parents:
diff changeset
204 get_template_innermost_arguments_folded (const_tree t)
kono
parents:
diff changeset
205 {
kono
parents:
diff changeset
206 return fold_cplus_constants (get_template_innermost_arguments (t));
kono
parents:
diff changeset
207 }
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 static tree
kono
parents:
diff changeset
210 get_template_argument_pack_elems_folded (const_tree t)
kono
parents:
diff changeset
211 {
kono
parents:
diff changeset
212 return fold_cplus_constants (get_template_argument_pack_elems (t));
kono
parents:
diff changeset
213 }
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 /* The C++ version of the enum_underlying_base_type langhook.
kono
parents:
diff changeset
216 See also cp/semantics.c (finish_underlying_type). */
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 static
kono
parents:
diff changeset
219 tree cxx_enum_underlying_base_type (const_tree type)
kono
parents:
diff changeset
220 {
kono
parents:
diff changeset
221 tree underlying_type = ENUM_UNDERLYING_TYPE (type);
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 if (! ENUM_FIXED_UNDERLYING_TYPE_P (type))
kono
parents:
diff changeset
224 underlying_type
kono
parents:
diff changeset
225 = c_common_type_for_mode (TYPE_MODE (underlying_type),
kono
parents:
diff changeset
226 TYPE_UNSIGNED (underlying_type));
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 return underlying_type;
kono
parents:
diff changeset
229 }
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 #if CHECKING_P
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 namespace selftest {
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* Implementation of LANG_HOOKS_RUN_LANG_SELFTESTS for the C++ frontend. */
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 void
kono
parents:
diff changeset
238 run_cp_tests (void)
kono
parents:
diff changeset
239 {
kono
parents:
diff changeset
240 /* Run selftests shared within the C family. */
kono
parents:
diff changeset
241 c_family_tests ();
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 /* Additional C++-specific tests. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
244 cp_pt_c_tests ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
245 cp_tree_c_tests ();
111
kono
parents:
diff changeset
246 }
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 } // namespace selftest
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 #endif /* #if CHECKING_P */
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 #include "gt-cp-cp-lang.h"
kono
parents:
diff changeset
254 #include "gtype-cp.h"