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