annotate gcc/cp/cp-lang.c @ 111:04ced10e8804

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