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