]>
Commit | Line | Data |
---|---|---|
ca58dfe1 | 1 | /* Language-dependent hooks for C++. |
dd436eaf | 2 | Copyright 2001, 2002 Free Software Foundation, Inc. |
ca58dfe1 | 3 | Contributed by Alexandre Oliva <aoliva@redhat.com> |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
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 | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
805e22b2 | 24 | #include "coretypes.h" |
25 | #include "tm.h" | |
ca58dfe1 | 26 | #include "tree.h" |
27 | #include "cp-tree.h" | |
b3187c7c | 28 | #include "c-common.h" |
ca58dfe1 | 29 | #include "toplev.h" |
30 | #include "langhooks.h" | |
b0278d39 | 31 | #include "langhooks-def.h" |
ca58dfe1 | 32 | |
2a631e19 | 33 | static HOST_WIDE_INT cxx_get_alias_set PARAMS ((tree)); |
c5d44e2f | 34 | static bool ok_to_generate_alias_set_for_type PARAMS ((tree)); |
8d58a5a7 | 35 | static bool cxx_warn_unused_global_decl PARAMS ((tree)); |
c3f16ae3 | 36 | static tree cp_expr_size PARAMS ((tree)); |
21ac3a84 | 37 | static bool cp_var_mod_type_p PARAMS ((tree)); |
2a631e19 | 38 | |
d19bd1f0 | 39 | #undef LANG_HOOKS_NAME |
40 | #define LANG_HOOKS_NAME "GNU C++" | |
ca58dfe1 | 41 | #undef LANG_HOOKS_INIT |
42 | #define LANG_HOOKS_INIT cxx_init | |
43 | #undef LANG_HOOKS_FINISH | |
44 | #define LANG_HOOKS_FINISH cxx_finish | |
df2114d0 | 45 | #undef LANG_HOOKS_CLEAR_BINDING_STACK |
46 | #define LANG_HOOKS_CLEAR_BINDING_STACK pop_everything | |
ca58dfe1 | 47 | #undef LANG_HOOKS_INIT_OPTIONS |
48 | #define LANG_HOOKS_INIT_OPTIONS cxx_init_options | |
49 | #undef LANG_HOOKS_DECODE_OPTION | |
428a5a4e | 50 | #define LANG_HOOKS_DECODE_OPTION c_common_decode_option |
ca58dfe1 | 51 | #undef LANG_HOOKS_POST_OPTIONS |
dd436eaf | 52 | #define LANG_HOOKS_POST_OPTIONS c_common_post_options |
2a631e19 | 53 | #undef LANG_HOOKS_GET_ALIAS_SET |
54 | #define LANG_HOOKS_GET_ALIAS_SET cxx_get_alias_set | |
b3187c7c | 55 | #undef LANG_HOOKS_EXPAND_CONSTANT |
56 | #define LANG_HOOKS_EXPAND_CONSTANT cplus_expand_constant | |
b467ecc1 | 57 | #undef LANG_HOOKS_EXPAND_EXPR |
58 | #define LANG_HOOKS_EXPAND_EXPR cxx_expand_expr | |
b3187c7c | 59 | #undef LANG_HOOKS_SAFE_FROM_P |
60 | #define LANG_HOOKS_SAFE_FROM_P c_safe_from_p | |
b78207a0 | 61 | #undef LANG_HOOKS_PARSE_FILE |
62 | #define LANG_HOOKS_PARSE_FILE c_common_parse_file | |
dbc42b78 | 63 | #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL |
64 | #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL cxx_dup_lang_specific_decl | |
1d347c23 | 65 | #undef LANG_HOOKS_UNSAVE_EXPR_NOW |
66 | #define LANG_HOOKS_UNSAVE_EXPR_NOW cxx_unsave_expr_now | |
2154e08e | 67 | #undef LANG_HOOKS_MAYBE_BUILD_CLEANUP |
68 | #define LANG_HOOKS_MAYBE_BUILD_CLEANUP cxx_maybe_build_cleanup | |
aff9e656 | 69 | #undef LANG_HOOKS_TRUTHVALUE_CONVERSION |
70 | #define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion | |
26ca6c20 | 71 | #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES |
72 | #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES cxx_insert_default_attributes | |
ee23fd7b | 73 | #undef LANG_HOOKS_UNSAFE_FOR_REEVAL |
74 | #define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval | |
d1f6c8f2 | 75 | #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME |
76 | #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME mangle_decl | |
9b86eec0 | 77 | #undef LANG_HOOKS_MARK_ADDRESSABLE |
78 | #define LANG_HOOKS_MARK_ADDRESSABLE cxx_mark_addressable | |
b7fced5e | 79 | #undef LANG_HOOKS_PRINT_STATISTICS |
80 | #define LANG_HOOKS_PRINT_STATISTICS cxx_print_statistics | |
81 | #undef LANG_HOOKS_PRINT_XNODE | |
82 | #define LANG_HOOKS_PRINT_XNODE cxx_print_xnode | |
83 | #undef LANG_HOOKS_PRINT_DECL | |
84 | #define LANG_HOOKS_PRINT_DECL cxx_print_decl | |
85 | #undef LANG_HOOKS_PRINT_TYPE | |
86 | #define LANG_HOOKS_PRINT_TYPE cxx_print_type | |
87 | #undef LANG_HOOKS_PRINT_IDENTIFIER | |
88 | #define LANG_HOOKS_PRINT_IDENTIFIER cxx_print_identifier | |
96554925 | 89 | #undef LANG_HOOKS_DECL_PRINTABLE_NAME |
90 | #define LANG_HOOKS_DECL_PRINTABLE_NAME cxx_printable_name | |
6c7ff025 | 91 | #undef LANG_HOOKS_PRINT_ERROR_FUNCTION |
92 | #define LANG_HOOKS_PRINT_ERROR_FUNCTION cxx_print_error_function | |
8d58a5a7 | 93 | #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL |
94 | #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL cxx_warn_unused_global_decl | |
ca58dfe1 | 95 | |
c80c4f22 | 96 | #undef LANG_HOOKS_FUNCTION_INIT |
97 | #define LANG_HOOKS_FUNCTION_INIT cxx_push_function_context | |
1f3233d1 | 98 | #undef LANG_HOOKS_FUNCTION_FINAL |
99 | #define LANG_HOOKS_FUNCTION_FINAL cxx_pop_function_context | |
c80c4f22 | 100 | |
f8e93a2e | 101 | /* Attribute hooks. */ |
102 | #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE | |
103 | #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE c_common_attribute_table | |
104 | #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE | |
105 | #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE c_common_format_attribute_table | |
106 | #undef LANG_HOOKS_ATTRIBUTE_TABLE | |
107 | #define LANG_HOOKS_ATTRIBUTE_TABLE cxx_attribute_table | |
108 | ||
ca58dfe1 | 109 | #undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES |
110 | #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \ | |
111 | cp_walk_subtrees | |
112 | #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN | |
113 | #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \ | |
114 | cp_cannot_inline_tree_fn | |
115 | #undef LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS | |
116 | #define LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS \ | |
117 | cp_add_pending_fn_decls | |
118 | #undef LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P | |
119 | #define LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P \ | |
120 | cp_is_overload_p | |
121 | #undef LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P | |
122 | #define LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P \ | |
123 | cp_auto_var_in_fn_p | |
124 | #undef LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING | |
125 | #define LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING \ | |
126 | cp_copy_res_decl_for_inlining | |
127 | #undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P | |
128 | #define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P anon_aggr_type_p | |
21ac3a84 | 129 | #undef LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P |
130 | #define LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P cp_var_mod_type_p | |
054e01a7 | 131 | #undef LANG_HOOKS_TREE_INLINING_START_INLINING |
132 | #define LANG_HOOKS_TREE_INLINING_START_INLINING cp_start_inlining | |
133 | #undef LANG_HOOKS_TREE_INLINING_END_INLINING | |
134 | #define LANG_HOOKS_TREE_INLINING_END_INLINING cp_end_inlining | |
3119c950 | 135 | #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN |
136 | #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN cp_dump_tree | |
137 | #undef LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN | |
138 | #define LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN cp_type_quals | |
c3f16ae3 | 139 | #undef LANG_HOOKS_EXPR_SIZE |
140 | #define LANG_HOOKS_EXPR_SIZE cp_expr_size | |
ca58dfe1 | 141 | |
a1f71e15 | 142 | #undef LANG_HOOKS_MAKE_TYPE |
143 | #define LANG_HOOKS_MAKE_TYPE cxx_make_type | |
771d21fa | 144 | #undef LANG_HOOKS_TYPE_FOR_MODE |
145 | #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode | |
146 | #undef LANG_HOOKS_TYPE_FOR_SIZE | |
147 | #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size | |
4070745f | 148 | #undef LANG_HOOKS_SIGNED_TYPE |
149 | #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type | |
150 | #undef LANG_HOOKS_UNSIGNED_TYPE | |
151 | #define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type | |
152 | #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE | |
153 | #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type | |
1dd25100 | 154 | #undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR |
155 | #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR cxx_incomplete_type_error | |
63c62881 | 156 | #undef LANG_HOOKS_TYPE_PROMOTES_TO |
157 | #define LANG_HOOKS_TYPE_PROMOTES_TO cxx_type_promotes_to | |
a1f71e15 | 158 | |
ca58dfe1 | 159 | /* Each front end provides its own hooks, for toplev.c. */ |
d19bd1f0 | 160 | const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; |
2a631e19 | 161 | |
c0af329c | 162 | /* Tree code classes. */ |
8d58a5a7 | 163 | |
164 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, | |
165 | ||
166 | const char tree_code_type[] = { | |
167 | #include "tree.def" | |
168 | 'x', | |
169 | #include "c-common.def" | |
170 | 'x', | |
171 | #include "cp-tree.def" | |
172 | }; | |
173 | #undef DEFTREECODE | |
174 | ||
175 | /* Table indexed by tree code giving number of expression | |
176 | operands beyond the fixed part of the node structure. | |
177 | Not used for types or decls. */ | |
178 | ||
179 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, | |
180 | ||
181 | const unsigned char tree_code_length[] = { | |
182 | #include "tree.def" | |
183 | 0, | |
184 | #include "c-common.def" | |
185 | 0, | |
186 | #include "cp-tree.def" | |
187 | }; | |
188 | #undef DEFTREECODE | |
189 | ||
190 | /* Names of tree components. | |
191 | Used for printing out the tree and error messages. */ | |
192 | #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, | |
193 | ||
194 | const char *const tree_code_name[] = { | |
195 | #include "tree.def" | |
196 | "@@dummy", | |
197 | #include "c-common.def" | |
198 | "@@dummy", | |
199 | #include "cp-tree.def" | |
200 | }; | |
201 | #undef DEFTREECODE | |
202 | ||
c5d44e2f | 203 | /* Check if a C++ type is safe for aliasing. |
204 | Return TRUE if T safe for aliasing FALSE otherwise. */ | |
205 | ||
206 | static bool | |
207 | ok_to_generate_alias_set_for_type (t) | |
208 | tree t; | |
209 | { | |
210 | if (TYPE_PTRMEMFUNC_P (t)) | |
211 | return true; | |
212 | if (AGGREGATE_TYPE_P (t)) | |
213 | { | |
214 | if ((TREE_CODE (t) == RECORD_TYPE) || (TREE_CODE (t) == UNION_TYPE)) | |
215 | { | |
216 | tree fields; | |
0ef91174 | 217 | /* Backend-created structs are safe. */ |
218 | if (! CLASS_TYPE_P (t)) | |
219 | return true; | |
c5d44e2f | 220 | /* PODs are safe. */ |
221 | if (! CLASSTYPE_NON_POD_P(t)) | |
222 | return true; | |
223 | /* Classes with virtual baseclasses are not. */ | |
224 | if (TYPE_USES_VIRTUAL_BASECLASSES (t)) | |
225 | return false; | |
226 | /* Recursively check the base classes. */ | |
227 | if (TYPE_BINFO (t) != NULL && TYPE_BINFO_BASETYPES (t) != NULL) | |
228 | { | |
229 | int i; | |
230 | for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t)); i++) | |
231 | { | |
232 | tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), i); | |
233 | if (!ok_to_generate_alias_set_for_type (BINFO_TYPE (binfo))) | |
234 | return false; | |
235 | } | |
236 | } | |
237 | /* Check all the fields. */ | |
238 | for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields)) | |
239 | { | |
240 | if (TREE_CODE (fields) != FIELD_DECL) | |
241 | continue; | |
242 | if (! ok_to_generate_alias_set_for_type (TREE_TYPE (fields))) | |
243 | return false; | |
244 | } | |
245 | return true; | |
246 | } | |
247 | else if (TREE_CODE (t) == ARRAY_TYPE) | |
248 | return ok_to_generate_alias_set_for_type (TREE_TYPE (t)); | |
249 | else | |
250 | /* This should never happen, we dealt with all the aggregate | |
251 | types that can appear in C++ above. */ | |
252 | abort (); | |
253 | } | |
254 | else | |
255 | return true; | |
256 | } | |
257 | ||
2a631e19 | 258 | /* Special routine to get the alias set for C++. */ |
259 | ||
260 | static HOST_WIDE_INT | |
261 | cxx_get_alias_set (t) | |
262 | tree t; | |
263 | { | |
c5d44e2f | 264 | /* It's not yet safe to use alias sets for classes in C++. */ |
265 | if (!ok_to_generate_alias_set_for_type(t)) | |
2a631e19 | 266 | return 0; |
267 | ||
268 | return c_common_get_alias_set (t); | |
269 | } | |
8d58a5a7 | 270 | |
271 | /* Called from check_global_declarations. */ | |
272 | ||
273 | static bool | |
274 | cxx_warn_unused_global_decl (decl) | |
275 | tree decl; | |
276 | { | |
277 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl)) | |
278 | return false; | |
279 | if (DECL_IN_SYSTEM_HEADER (decl)) | |
280 | return false; | |
281 | ||
282 | /* Const variables take the place of #defines in C++. */ | |
283 | if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl)) | |
284 | return false; | |
285 | ||
286 | return true; | |
287 | } | |
c3f16ae3 | 288 | |
289 | /* Langhook for expr_size: Tell the backend that the value of an expression | |
290 | of non-POD class type does not include any tail padding; a derived class | |
291 | might have allocated something there. */ | |
292 | ||
293 | static tree | |
294 | cp_expr_size (exp) | |
295 | tree exp; | |
296 | { | |
297 | if (CLASS_TYPE_P (TREE_TYPE (exp))) | |
298 | { | |
299 | /* The backend should not be interested in the size of an expression | |
300 | of a type with both of these set; all copies of such types must go | |
301 | through a constructor or assignment op. */ | |
302 | if (TYPE_HAS_COMPLEX_INIT_REF (TREE_TYPE (exp)) | |
900b9bc3 | 303 | && TYPE_HAS_COMPLEX_ASSIGN_REF (TREE_TYPE (exp)) |
304 | /* But storing a CONSTRUCTOR isn't a copy. */ | |
305 | && TREE_CODE (exp) != CONSTRUCTOR) | |
c3f16ae3 | 306 | abort (); |
307 | /* This would be wrong for a type with virtual bases, but they are | |
308 | caught by the abort above. */ | |
309 | return CLASSTYPE_SIZE_UNIT (TREE_TYPE (exp)); | |
310 | } | |
311 | else | |
312 | /* Use the default code. */ | |
313 | return lhd_expr_size (exp); | |
314 | } | |
21ac3a84 | 315 | |
316 | /* Returns true if T is a variably modified type, in the sense of C99. | |
317 | This routine needs only check cases that cannot be handled by the | |
318 | language-independent logic in tree-inline.c. */ | |
319 | ||
320 | static bool | |
321 | cp_var_mod_type_p (tree type) | |
322 | { | |
323 | /* If TYPE is a pointer-to-member, it is variably modified if either | |
324 | the class or the member are variably modified. */ | |
325 | if (TYPE_PTRMEM_P (type) || TYPE_PTRMEMFUNC_P (type)) | |
326 | return (variably_modified_type_p (TYPE_PTRMEM_CLASS_TYPE (type)) | |
327 | || variably_modified_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type))); | |
328 | ||
329 | /* All other types are not variably modified. */ | |
330 | return false; | |
331 | } | |
332 |