]>
Commit | Line | Data |
---|---|---|
ca58dfe1 | 1 | /* Language-dependent hooks for C++. |
d353bf18 | 2 | Copyright (C) 2001-2015 Free Software Foundation, Inc. |
ca58dfe1 | 3 | Contributed by Alexandre Oliva <aoliva@redhat.com> |
4 | ||
6f0d25a6 | 5 | This file is part of GCC. |
ca58dfe1 | 6 | |
6f0d25a6 | 7 | GCC is free software; you can redistribute it and/or modify |
ca58dfe1 | 8 | it under the terms of the GNU General Public License as published by |
aa139c3f | 9 | the Free Software Foundation; either version 3, or (at your option) |
ca58dfe1 | 10 | any later version. |
11 | ||
6f0d25a6 | 12 | GCC is distributed in the hope that it will be useful, |
ca58dfe1 | 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 | |
aa139c3f | 18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
ca58dfe1 | 20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
805e22b2 | 23 | #include "coretypes.h" |
24 | #include "tm.h" | |
b20a8bb4 | 25 | #include "alias.h" |
26 | #include "symtab.h" | |
ca58dfe1 | 27 | #include "tree.h" |
1b006e46 | 28 | #include "stor-layout.h" |
ca58dfe1 | 29 | #include "cp-tree.h" |
7bedc3a0 | 30 | #include "c-family/c-common.h" |
ca58dfe1 | 31 | #include "langhooks.h" |
b0278d39 | 32 | #include "langhooks-def.h" |
5dd72fac | 33 | #include "debug.h" |
34 | #include "cp-objcp-common.h" | |
cc7d6aed | 35 | #include "target.h" |
b3145af5 | 36 | #include "parser.h" |
ca58dfe1 | 37 | |
c0f19401 | 38 | enum c_language_kind c_language = clk_cxx; |
5ded8c6f | 39 | static void cp_init_ts (void); |
facb12b2 | 40 | static const char * cxx_dwarf_name (tree t, int verbosity); |
03a61d93 | 41 | static enum classify_record cp_classify_record (tree type); |
58d82cd0 | 42 | static tree cp_eh_personality (void); |
05b89780 | 43 | static tree get_template_innermost_arguments_folded (const_tree); |
44 | static tree get_template_argument_pack_elems_folded (const_tree); | |
1b006e46 | 45 | static tree cxx_enum_underlying_base_type (const_tree); |
c0f19401 | 46 | |
5dd72fac | 47 | /* Lang hooks common to C++ and ObjC++ are declared in cp/cp-objcp-common.h; |
48 | consequently, there should be very few hooks below. */ | |
49 | ||
d19bd1f0 | 50 | #undef LANG_HOOKS_NAME |
51 | #define LANG_HOOKS_NAME "GNU C++" | |
ca58dfe1 | 52 | #undef LANG_HOOKS_INIT |
53 | #define LANG_HOOKS_INIT cxx_init | |
03a61d93 | 54 | #undef LANG_HOOKS_CLASSIFY_RECORD |
55 | #define LANG_HOOKS_CLASSIFY_RECORD cp_classify_record | |
0e4744ac | 56 | #undef LANG_HOOKS_GENERIC_TYPE_P |
57 | #define LANG_HOOKS_GENERIC_TYPE_P class_tmpl_impl_spec_p | |
7c48f38c | 58 | |
59 | #undef LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS | |
60 | #define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS \ | |
61 | get_primary_template_innermost_parameters | |
62 | #undef LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS | |
63 | #define LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS \ | |
05b89780 | 64 | get_template_innermost_arguments_folded |
5d1e31fa | 65 | #undef LANG_HOOKS_FUNCTION_PARAMETER_PACK_P |
66 | #define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P \ | |
67 | function_parameter_pack_p | |
7c48f38c | 68 | #undef LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS |
69 | #define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS \ | |
05b89780 | 70 | get_template_argument_pack_elems_folded |
7c48f38c | 71 | #undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P |
72 | #define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \ | |
73 | template_template_parameter_p | |
5d1e31fa | 74 | #undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P |
75 | #define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \ | |
76 | function_parameter_expanded_from_pack_p | |
77 | #undef LANG_HOOKS_GET_GENERIC_FUNCTION_DECL | |
78 | #define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL get_function_template_decl | |
facb12b2 | 79 | #undef LANG_HOOKS_DWARF_NAME |
80 | #define LANG_HOOKS_DWARF_NAME cxx_dwarf_name | |
5ded8c6f | 81 | #undef LANG_HOOKS_INIT_TS |
82 | #define LANG_HOOKS_INIT_TS cp_init_ts | |
58d82cd0 | 83 | #undef LANG_HOOKS_EH_PERSONALITY |
84 | #define LANG_HOOKS_EH_PERSONALITY cp_eh_personality | |
85 | #undef LANG_HOOKS_EH_RUNTIME_TYPE | |
86 | #define LANG_HOOKS_EH_RUNTIME_TYPE build_eh_type_type | |
1b006e46 | 87 | #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE |
88 | #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE cxx_enum_underlying_base_type | |
a1f71e15 | 89 | |
5dd72fac | 90 | /* Each front end provides its own lang hook initializer. */ |
34e5cced | 91 | struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; |
2a631e19 | 92 | |
5dd72fac | 93 | /* Lang hook routines common to C++ and ObjC++ appear in cp/cp-objcp-common.c; |
94 | there should be very few routines below. */ | |
21ac3a84 | 95 | |
5dd72fac | 96 | /* The following function does something real, but only in Objective-C++. */ |
0de2b732 | 97 | |
5dd72fac | 98 | tree |
a49c5913 | 99 | objcp_tsubst_copy_and_build (tree /*t*/, |
100 | tree /*args*/, | |
101 | tsubst_flags_t /*complain*/, | |
102 | tree /*in_decl*/, | |
103 | bool /*function_p*/) | |
393b349a | 104 | { |
5dd72fac | 105 | return NULL_TREE; |
393b349a | 106 | } |
107 | ||
5ded8c6f | 108 | static void |
109 | cp_init_ts (void) | |
110 | { | |
9b88d08d | 111 | cp_common_init_ts (); |
5ded8c6f | 112 | |
4dd41a12 | 113 | init_shadowed_var_for_decl (); |
5ded8c6f | 114 | } |
115 | ||
facb12b2 | 116 | static const char * |
117 | cxx_dwarf_name (tree t, int verbosity) | |
118 | { | |
119 | gcc_assert (DECL_P (t)); | |
120 | ||
709be7ff | 121 | if (DECL_NAME (t) |
3910cc8d | 122 | && (ANON_AGGRNAME_P (DECL_NAME (t)) || LAMBDA_TYPE_P (t))) |
709be7ff | 123 | return NULL; |
facb12b2 | 124 | if (verbosity >= 2) |
8a47db47 | 125 | return decl_as_dwarf_string (t, |
126 | TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME | |
127 | | TFF_NO_OMIT_DEFAULT_TEMPLATE_ARGUMENTS); | |
facb12b2 | 128 | |
8a47db47 | 129 | return lang_decl_dwarf_name (t, verbosity, false); |
facb12b2 | 130 | } |
131 | ||
03a61d93 | 132 | static enum classify_record |
133 | cp_classify_record (tree type) | |
134 | { | |
d544dcee | 135 | if (TYPE_LANG_SPECIFIC (type) |
136 | && CLASSTYPE_DECLARED_CLASS (type)) | |
03a61d93 | 137 | return RECORD_IS_CLASS; |
138 | ||
139 | return RECORD_IS_STRUCT; | |
140 | } | |
141 | ||
58d82cd0 | 142 | static GTY(()) tree cp_eh_personality_decl; |
143 | ||
144 | static tree | |
145 | cp_eh_personality (void) | |
146 | { | |
147 | if (!cp_eh_personality_decl) | |
148 | { | |
382597e4 | 149 | const char *lang = (pragma_java_exceptions ? "gcj" : "gxx"); |
150 | cp_eh_personality_decl = build_personality_function (lang); | |
58d82cd0 | 151 | } |
152 | ||
153 | return cp_eh_personality_decl; | |
154 | } | |
155 | ||
05b89780 | 156 | /* This is a subroutine of fold_cplus_constants. It returns TRUE if T |
157 | is a C++ specific constant that needs to be folded further before | |
158 | being passed to the debug info emitter. */ | |
159 | ||
160 | static bool | |
161 | template_arg_needs_folding (const_tree t) | |
162 | { | |
163 | /* For now only PTRMEM_CST nodes are to be folded further. */ | |
164 | if (TREE_CODE (t) == PTRMEM_CST) | |
165 | return true; | |
166 | return false; | |
167 | } | |
168 | ||
169 | /* Fold the elements of the TREE_VEC C which are C++ specific nodes | |
170 | that would need folding so that they can be processed by the debug | |
171 | info emitter. This is a subroutine of | |
172 | get_template_innermost_arguments_folded and | |
173 | get_template_argument_pack_elems_folded. */ | |
174 | ||
175 | static tree | |
176 | fold_cplus_constants (const_tree c) | |
177 | { | |
178 | tree folded_elems, elems = CONST_CAST_TREE (c); | |
179 | int vec_len, i; | |
180 | ||
181 | if (elems == NULL_TREE || elems == error_mark_node) | |
182 | return elems; | |
183 | ||
184 | vec_len = TREE_VEC_LENGTH (elems); | |
185 | ||
186 | /* First check if there is at least one element that needs | |
187 | folding. If there is none, we just return ELEMS. Otherwise create | |
188 | and return a new tree vector that contains the folded versions of | |
189 | ELEMS. This is to avoid allocating memory if we don't need | |
190 | to. */ | |
191 | for (i = 0; i < vec_len; ++i) | |
192 | { | |
193 | if (template_arg_needs_folding (TREE_VEC_ELT (elems, i))) | |
194 | break; | |
195 | } | |
196 | if (i == vec_len) | |
197 | return elems; | |
198 | ||
199 | folded_elems = make_tree_vec (vec_len); | |
200 | for (i = 0; i < vec_len; ++i) | |
201 | { | |
202 | tree elem = TREE_VEC_ELT (elems, i); | |
203 | TREE_VEC_ELT (folded_elems, i) = | |
204 | (elem && !TYPE_P (elem)) ? cplus_expand_constant (elem) : elem; | |
205 | ||
206 | } | |
207 | return folded_elems; | |
208 | } | |
209 | ||
210 | /* The C++ implementation of the LANG_HOOKS_GET_INNERMOST_GENERIC_ARGS | |
211 | hook. It returns the innermost template arguments of type T, and | |
212 | makes sure those arguments are folded enough for the debug info | |
213 | emitter. */ | |
214 | ||
215 | static tree | |
216 | get_template_innermost_arguments_folded (const_tree t) | |
217 | { | |
218 | return fold_cplus_constants (get_template_innermost_arguments (t)); | |
219 | } | |
220 | ||
221 | static tree | |
222 | get_template_argument_pack_elems_folded (const_tree t) | |
223 | { | |
224 | return fold_cplus_constants (get_template_argument_pack_elems (t)); | |
225 | } | |
226 | ||
1b006e46 | 227 | /* The C++ version of the enum_underlying_base_type langhook. |
228 | See also cp/semantics.c (finish_underlying_type). */ | |
229 | ||
230 | static | |
231 | tree cxx_enum_underlying_base_type (const_tree type) | |
232 | { | |
233 | tree underlying_type = ENUM_UNDERLYING_TYPE (type); | |
234 | ||
235 | if (! ENUM_FIXED_UNDERLYING_TYPE_P (type)) | |
236 | underlying_type | |
237 | = c_common_type_for_mode (TYPE_MODE (underlying_type), | |
238 | TYPE_UNSIGNED (underlying_type)); | |
239 | ||
240 | return underlying_type; | |
241 | } | |
242 | ||
bb87f728 | 243 | #include "gt-cp-cp-lang.h" |
5dd72fac | 244 | #include "gtype-cp.h" |