]>
Commit | Line | Data |
---|---|---|
19551f29 AO |
1 | /* Language-dependent hooks for C++. |
2 | Copyright 2001 Free Software Foundation, Inc. | |
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)); |
8ac61af7 | 34 | |
3ac88239 NB |
35 | #undef LANG_HOOKS_NAME |
36 | #define LANG_HOOKS_NAME "GNU C++" | |
19551f29 AO |
37 | #undef LANG_HOOKS_INIT |
38 | #define LANG_HOOKS_INIT cxx_init | |
39 | #undef LANG_HOOKS_FINISH | |
40 | #define LANG_HOOKS_FINISH cxx_finish | |
37207ee7 ZW |
41 | #undef LANG_HOOKS_CLEAR_BINDING_STACK |
42 | #define LANG_HOOKS_CLEAR_BINDING_STACK pop_everything | |
19551f29 AO |
43 | #undef LANG_HOOKS_INIT_OPTIONS |
44 | #define LANG_HOOKS_INIT_OPTIONS cxx_init_options | |
45 | #undef LANG_HOOKS_DECODE_OPTION | |
46 | #define LANG_HOOKS_DECODE_OPTION cxx_decode_option | |
47 | #undef LANG_HOOKS_POST_OPTIONS | |
48 | #define LANG_HOOKS_POST_OPTIONS cxx_post_options | |
8ac61af7 RK |
49 | #undef LANG_HOOKS_GET_ALIAS_SET |
50 | #define LANG_HOOKS_GET_ALIAS_SET cxx_get_alias_set | |
ac79cd5a RK |
51 | #undef LANG_HOOKS_EXPAND_CONSTANT |
52 | #define LANG_HOOKS_EXPAND_CONSTANT cplus_expand_constant | |
c9d892a8 NB |
53 | #undef LANG_HOOKS_EXPAND_EXPR |
54 | #define LANG_HOOKS_EXPAND_EXPR cxx_expand_expr | |
ac79cd5a RK |
55 | #undef LANG_HOOKS_SAFE_FROM_P |
56 | #define LANG_HOOKS_SAFE_FROM_P c_safe_from_p | |
52dabb6c NB |
57 | #undef LANG_HOOKS_PARSE_FILE |
58 | #define LANG_HOOKS_PARSE_FILE c_common_parse_file | |
63e1b1c4 NB |
59 | #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL |
60 | #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL cxx_dup_lang_specific_decl | |
24965e7a NB |
61 | #undef LANG_HOOKS_UNSAVE_EXPR_NOW |
62 | #define LANG_HOOKS_UNSAVE_EXPR_NOW cxx_unsave_expr_now | |
7b3e5198 NB |
63 | #undef LANG_HOOKS_MAYBE_BUILD_CLEANUP |
64 | #define LANG_HOOKS_MAYBE_BUILD_CLEANUP cxx_maybe_build_cleanup | |
78ef5b89 NB |
65 | #undef LANG_HOOKS_TRUTHVALUE_CONVERSION |
66 | #define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion | |
7ffb4fd2 NB |
67 | #undef LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES |
68 | #define LANG_HOOKS_INSERT_DEFAULT_ATTRIBUTES cxx_insert_default_attributes | |
4f0ade92 NB |
69 | #undef LANG_HOOKS_MARK_TREE |
70 | #define LANG_HOOKS_MARK_TREE cxx_mark_tree | |
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 | |
5d69f816 NB |
91 | #undef LANG_HOOKS_SET_YYDEBUG |
92 | #define LANG_HOOKS_SET_YYDEBUG cxx_set_yydebug | |
ef4f94ac RH |
93 | #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL |
94 | #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL cxx_warn_unused_global_decl | |
19551f29 | 95 | |
b03e38e1 NB |
96 | #undef LANG_HOOKS_FUNCTION_INIT |
97 | #define LANG_HOOKS_FUNCTION_INIT cxx_push_function_context | |
98 | #undef LANG_HOOKS_FUNCTION_FREE | |
99 | #define LANG_HOOKS_FUNCTION_FREE cxx_pop_function_context | |
100 | #undef LANG_HOOKS_FUNCTION_MARK | |
101 | #define LANG_HOOKS_FUNCTION_MARK cxx_mark_function_context | |
102 | ||
19551f29 AO |
103 | #undef LANG_HOOKS_TREE_INLINING_WALK_SUBTREES |
104 | #define LANG_HOOKS_TREE_INLINING_WALK_SUBTREES \ | |
105 | cp_walk_subtrees | |
106 | #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN | |
107 | #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \ | |
108 | cp_cannot_inline_tree_fn | |
109 | #undef LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS | |
110 | #define LANG_HOOKS_TREE_INLINING_ADD_PENDING_FN_DECLS \ | |
111 | cp_add_pending_fn_decls | |
112 | #undef LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P | |
113 | #define LANG_HOOKS_TREE_INLINING_TREE_CHAIN_MATTERS_P \ | |
114 | cp_is_overload_p | |
115 | #undef LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P | |
116 | #define LANG_HOOKS_TREE_INLINING_AUTO_VAR_IN_FN_P \ | |
117 | cp_auto_var_in_fn_p | |
118 | #undef LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING | |
119 | #define LANG_HOOKS_TREE_INLINING_COPY_RES_DECL_FOR_INLINING \ | |
120 | cp_copy_res_decl_for_inlining | |
121 | #undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P | |
122 | #define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P anon_aggr_type_p | |
742a37d5 JM |
123 | #undef LANG_HOOKS_TREE_INLINING_START_INLINING |
124 | #define LANG_HOOKS_TREE_INLINING_START_INLINING cp_start_inlining | |
125 | #undef LANG_HOOKS_TREE_INLINING_END_INLINING | |
126 | #define LANG_HOOKS_TREE_INLINING_END_INLINING cp_end_inlining | |
89d684bb BM |
127 | #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN |
128 | #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN cp_dump_tree | |
129 | #undef LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN | |
130 | #define LANG_HOOKS_TREE_DUMP_TYPE_QUALS_FN cp_type_quals | |
19551f29 | 131 | |
f1e639b1 NB |
132 | #undef LANG_HOOKS_MAKE_TYPE |
133 | #define LANG_HOOKS_MAKE_TYPE cxx_make_type | |
b0c48229 NB |
134 | #undef LANG_HOOKS_TYPE_FOR_MODE |
135 | #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode | |
136 | #undef LANG_HOOKS_TYPE_FOR_SIZE | |
137 | #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size | |
ceef8ce4 NB |
138 | #undef LANG_HOOKS_SIGNED_TYPE |
139 | #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type | |
140 | #undef LANG_HOOKS_UNSIGNED_TYPE | |
141 | #define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type | |
142 | #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE | |
143 | #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type | |
7a228918 NB |
144 | #undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR |
145 | #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR cxx_incomplete_type_error | |
ab393bf1 NB |
146 | #undef LANG_HOOKS_TYPE_PROMOTES_TO |
147 | #define LANG_HOOKS_TYPE_PROMOTES_TO cxx_type_promotes_to | |
f1e639b1 | 148 | |
19551f29 | 149 | /* Each front end provides its own hooks, for toplev.c. */ |
3ac88239 | 150 | const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; |
8ac61af7 | 151 | |
ef4f94ac RH |
152 | /* Tree code classes. */ |
153 | ||
154 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE, | |
155 | ||
156 | const char tree_code_type[] = { | |
157 | #include "tree.def" | |
158 | 'x', | |
159 | #include "c-common.def" | |
160 | 'x', | |
161 | #include "cp-tree.def" | |
162 | }; | |
163 | #undef DEFTREECODE | |
164 | ||
165 | /* Table indexed by tree code giving number of expression | |
166 | operands beyond the fixed part of the node structure. | |
167 | Not used for types or decls. */ | |
168 | ||
169 | #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH, | |
170 | ||
171 | const unsigned char tree_code_length[] = { | |
172 | #include "tree.def" | |
173 | 0, | |
174 | #include "c-common.def" | |
175 | 0, | |
176 | #include "cp-tree.def" | |
177 | }; | |
178 | #undef DEFTREECODE | |
179 | ||
180 | /* Names of tree components. | |
181 | Used for printing out the tree and error messages. */ | |
182 | #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME, | |
183 | ||
184 | const char *const tree_code_name[] = { | |
185 | #include "tree.def" | |
186 | "@@dummy", | |
187 | #include "c-common.def" | |
188 | "@@dummy", | |
189 | #include "cp-tree.def" | |
190 | }; | |
191 | #undef DEFTREECODE | |
192 | ||
61eece67 DN |
193 | /* Check if a C++ type is safe for aliasing. |
194 | Return TRUE if T safe for aliasing FALSE otherwise. */ | |
195 | ||
196 | static bool | |
197 | ok_to_generate_alias_set_for_type (t) | |
198 | tree t; | |
199 | { | |
200 | if (TYPE_PTRMEMFUNC_P (t)) | |
201 | return true; | |
202 | if (AGGREGATE_TYPE_P (t)) | |
203 | { | |
204 | if ((TREE_CODE (t) == RECORD_TYPE) || (TREE_CODE (t) == UNION_TYPE)) | |
205 | { | |
206 | tree fields; | |
207 | /* PODs are safe. */ | |
208 | if (! CLASSTYPE_NON_POD_P(t)) | |
209 | return true; | |
210 | /* Classes with virtual baseclasses are not. */ | |
211 | if (TYPE_USES_VIRTUAL_BASECLASSES (t)) | |
212 | return false; | |
213 | /* Recursively check the base classes. */ | |
214 | if (TYPE_BINFO (t) != NULL && TYPE_BINFO_BASETYPES (t) != NULL) | |
215 | { | |
216 | int i; | |
217 | for (i = 0; i < TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t)); i++) | |
218 | { | |
219 | tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), i); | |
220 | if (!ok_to_generate_alias_set_for_type (BINFO_TYPE (binfo))) | |
221 | return false; | |
222 | } | |
223 | } | |
224 | /* Check all the fields. */ | |
225 | for (fields = TYPE_FIELDS (t); fields; fields = TREE_CHAIN (fields)) | |
226 | { | |
227 | if (TREE_CODE (fields) != FIELD_DECL) | |
228 | continue; | |
229 | if (! ok_to_generate_alias_set_for_type (TREE_TYPE (fields))) | |
230 | return false; | |
231 | } | |
232 | return true; | |
233 | } | |
234 | else if (TREE_CODE (t) == ARRAY_TYPE) | |
235 | return ok_to_generate_alias_set_for_type (TREE_TYPE (t)); | |
236 | else | |
237 | /* This should never happen, we dealt with all the aggregate | |
238 | types that can appear in C++ above. */ | |
239 | abort (); | |
240 | } | |
241 | else | |
242 | return true; | |
243 | } | |
244 | ||
8ac61af7 RK |
245 | /* Special routine to get the alias set for C++. */ |
246 | ||
247 | static HOST_WIDE_INT | |
248 | cxx_get_alias_set (t) | |
249 | tree t; | |
250 | { | |
61eece67 DN |
251 | /* It's not yet safe to use alias sets for classes in C++. */ |
252 | if (!ok_to_generate_alias_set_for_type(t)) | |
8ac61af7 RK |
253 | return 0; |
254 | ||
255 | return c_common_get_alias_set (t); | |
256 | } | |
ef4f94ac RH |
257 | |
258 | /* Called from check_global_declarations. */ | |
259 | ||
260 | static bool | |
261 | cxx_warn_unused_global_decl (decl) | |
262 | tree decl; | |
263 | { | |
264 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl)) | |
265 | return false; | |
266 | if (DECL_IN_SYSTEM_HEADER (decl)) | |
267 | return false; | |
268 | ||
269 | /* Const variables take the place of #defines in C++. */ | |
270 | if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl)) | |
271 | return false; | |
272 | ||
273 | return true; | |
274 | } |