]>
Commit | Line | Data |
---|---|---|
c0f940ef | 1 | /* Language-specific hook definitions for C front end. |
517cbe13 | 2 | Copyright (C) 1991, 1995, 1997, 1998, |
21c7361e | 3 | 1999, 2000, 2001 Free Software Foundation, Inc. |
c0f940ef | 4 | |
1322177d | 5 | This file is part of GCC. |
c0f940ef | 6 | |
1322177d LB |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 2, or (at your option) any later | |
10 | version. | |
c0f940ef | 11 | |
1322177d LB |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
c0f940ef RS |
16 | |
17 | You should have received a copy of the GNU General Public License | |
1322177d LB |
18 | along with GCC; see the file COPYING. If not, write to the Free |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
c0f940ef RS |
21 | |
22 | ||
23 | #include "config.h" | |
670ee920 | 24 | #include "system.h" |
c0f940ef | 25 | #include "tree.h" |
e2ecd91c | 26 | #include "function.h" |
c0f940ef | 27 | #include "input.h" |
d6f4ec51 | 28 | #include "toplev.h" |
4e1e6a01 | 29 | #include "diagnostic.h" |
cab634f2 | 30 | #include "output.h" |
a8aa7975 | 31 | #include "flags.h" |
1526a060 | 32 | #include "ggc.h" |
8f17b5c5 MM |
33 | #include "rtl.h" |
34 | #include "expr.h" | |
35 | #include "c-tree.h" | |
36 | #include "c-lex.h" | |
5d7da2c6 | 37 | #include "cpplib.h" |
a32f2771 | 38 | |
a32f2771 | 39 | static int c_tree_printer PARAMS ((output_buffer *)); |
21c7361e | 40 | static int c_missing_noreturn_ok_p PARAMS ((tree)); |
13c61421 | 41 | static void c_init PARAMS ((void)); |
ee811cfd | 42 | static void c_init_options PARAMS ((void)); |
cd2a3ba2 NB |
43 | static void c_post_options PARAMS ((void)); |
44 | ||
45 | /* Each front end provides its own. */ | |
13c61421 NB |
46 | struct lang_hooks lang_hooks = {c_init, |
47 | NULL, /* c_finish */ | |
ee811cfd NB |
48 | c_init_options, |
49 | c_decode_option, | |
13c61421 | 50 | c_post_options}; |
cd2a3ba2 NB |
51 | |
52 | /* Post-switch processing. */ | |
53 | static void | |
54 | c_post_options () | |
55 | { | |
96302433 | 56 | cpp_post_options (parse_in); |
cd2a3ba2 | 57 | } |
add7091b | 58 | |
ee811cfd NB |
59 | static void |
60 | c_init_options () | |
b53beeb2 | 61 | { |
2a967f3d NB |
62 | /* Make identifier nodes long enough for the language-specific slots. */ |
63 | set_identifier_size (sizeof (struct lang_identifier)); | |
64 | ||
65 | parse_in = cpp_create_reader (ident_hash, CLK_GNUC89); | |
a32f2771 | 66 | |
a8aa7975 GM |
67 | /* Mark as "unspecified". */ |
68 | flag_bounds_check = -1; | |
b53beeb2 RH |
69 | } |
70 | ||
13c61421 NB |
71 | static void |
72 | c_init () | |
c0f940ef | 73 | { |
03dc0325 | 74 | c_common_lang_init (); |
a8aa7975 | 75 | |
f43b2795 JM |
76 | /* If still unspecified, make it match -std=c99 |
77 | (allowing for -pedantic-errors). */ | |
111458f1 ZW |
78 | if (mesg_implicit_function_declaration < 0) |
79 | { | |
f43b2795 | 80 | if (flag_isoc99) |
111458f1 ZW |
81 | mesg_implicit_function_declaration = flag_pedantic_errors ? 2 : 1; |
82 | else | |
83 | mesg_implicit_function_declaration = 0; | |
84 | } | |
85 | ||
e2ecd91c BS |
86 | save_lang_status = &push_c_function_context; |
87 | restore_lang_status = &pop_c_function_context; | |
1526a060 | 88 | mark_lang_status = &mark_c_function_context; |
8f17b5c5 MM |
89 | lang_expand_expr = &c_expand_expr; |
90 | lang_safe_from_p = &c_safe_from_p; | |
9596ddd6 | 91 | diagnostic_format_decoder (global_dc) = &c_tree_printer; |
8f17b5c5 | 92 | lang_expand_decl_stmt = &c_expand_decl_stmt; |
21c7361e | 93 | lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p; |
4e1e6a01 | 94 | |
1526a060 | 95 | c_parse_init (); |
c0f940ef RS |
96 | } |
97 | ||
c9591059 | 98 | const char * |
d0d4af87 MS |
99 | lang_identify () |
100 | { | |
101 | return "c"; | |
102 | } | |
103 | ||
a604ca26 TW |
104 | void |
105 | print_lang_statistics () | |
106 | { | |
107 | } | |
108 | ||
bc289659 ML |
109 | /* used by print-tree.c */ |
110 | ||
111 | void | |
112 | lang_print_xnode (file, node, indent) | |
d6f4ec51 KG |
113 | FILE *file ATTRIBUTE_UNUSED; |
114 | tree node ATTRIBUTE_UNUSED; | |
115 | int indent ATTRIBUTE_UNUSED; | |
bc289659 ML |
116 | { |
117 | } | |
118 | ||
c0f940ef | 119 | /* Used by c-lex.c, but only for objc. */ |
a604ca26 | 120 | |
c0f940ef RS |
121 | tree |
122 | lookup_interface (arg) | |
d6f4ec51 | 123 | tree arg ATTRIBUTE_UNUSED; |
c0f940ef RS |
124 | { |
125 | return 0; | |
126 | } | |
127 | ||
a604ca26 TW |
128 | tree |
129 | is_class_name (arg) | |
d6f4ec51 | 130 | tree arg ATTRIBUTE_UNUSED; |
a604ca26 TW |
131 | { |
132 | return 0; | |
133 | } | |
134 | ||
c0f940ef RS |
135 | void |
136 | maybe_objc_check_decl (decl) | |
d6f4ec51 | 137 | tree decl ATTRIBUTE_UNUSED; |
c0f940ef RS |
138 | { |
139 | } | |
140 | ||
141 | int | |
a604ca26 | 142 | maybe_objc_comptypes (lhs, rhs, reflexive) |
d6f4ec51 KG |
143 | tree lhs ATTRIBUTE_UNUSED; |
144 | tree rhs ATTRIBUTE_UNUSED; | |
145 | int reflexive ATTRIBUTE_UNUSED; | |
a604ca26 | 146 | { |
a0825a7f | 147 | return -1; |
a604ca26 TW |
148 | } |
149 | ||
c0f940ef RS |
150 | tree |
151 | maybe_building_objc_message_expr () | |
152 | { | |
153 | return 0; | |
154 | } | |
155 | ||
156 | int | |
157 | recognize_objc_keyword () | |
158 | { | |
159 | return 0; | |
160 | } | |
161 | ||
7e585d16 ZW |
162 | /* Used by c-typeck.c (build_external_ref), but only for objc. */ |
163 | ||
164 | tree | |
165 | lookup_objc_ivar (id) | |
166 | tree id ATTRIBUTE_UNUSED; | |
167 | { | |
168 | return 0; | |
169 | } | |
170 | ||
6dbaddf9 RH |
171 | #if !defined(ASM_OUTPUT_CONSTRUCTOR) || !defined(ASM_OUTPUT_DESTRUCTOR) |
172 | extern tree static_ctors; | |
173 | extern tree static_dtors; | |
174 | ||
175 | static tree start_cdtor PARAMS ((int)); | |
176 | static void finish_cdtor PARAMS ((tree)); | |
177 | ||
178 | static tree | |
179 | start_cdtor (method_type) | |
180 | int method_type; | |
181 | { | |
182 | tree fnname = get_file_function_name (method_type); | |
183 | tree void_list_node_1 = build_tree_list (NULL_TREE, void_type_node); | |
184 | tree body; | |
185 | ||
186 | start_function (void_list_node_1, | |
718b8ea5 JM |
187 | build_nt (CALL_EXPR, fnname, |
188 | tree_cons (NULL_TREE, NULL_TREE, void_list_node_1), | |
189 | NULL_TREE), | |
60a97cd4 | 190 | NULL_TREE); |
6dbaddf9 RH |
191 | store_parm_decls (); |
192 | ||
193 | current_function_cannot_inline | |
194 | = "static constructors and destructors cannot be inlined"; | |
195 | ||
196 | body = c_begin_compound_stmt (); | |
197 | ||
198 | pushlevel (0); | |
199 | clear_last_expr (); | |
200 | add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0); | |
201 | ||
202 | return body; | |
203 | } | |
204 | ||
205 | static void | |
206 | finish_cdtor (body) | |
207 | tree body; | |
208 | { | |
209 | tree scope; | |
210 | tree block; | |
211 | ||
212 | scope = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); | |
21c7361e | 213 | block = poplevel (0, 0, 0); |
6dbaddf9 RH |
214 | SCOPE_STMT_BLOCK (TREE_PURPOSE (scope)) = block; |
215 | SCOPE_STMT_BLOCK (TREE_VALUE (scope)) = block; | |
216 | ||
21c7361e | 217 | RECHAIN_STMTS (body, COMPOUND_BODY (body)); |
6dbaddf9 RH |
218 | |
219 | finish_function (0); | |
220 | } | |
221 | #endif | |
222 | ||
0f41302f MS |
223 | /* Called at end of parsing, but before end-of-file processing. */ |
224 | ||
2c5f4139 JM |
225 | void |
226 | finish_file () | |
227 | { | |
2c5f4139 JM |
228 | #ifndef ASM_OUTPUT_CONSTRUCTOR |
229 | if (static_ctors) | |
230 | { | |
6dbaddf9 | 231 | tree body = start_cdtor ('I'); |
2c5f4139 JM |
232 | |
233 | for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors)) | |
6dbaddf9 RH |
234 | c_expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors), |
235 | NULL_TREE)); | |
2c5f4139 | 236 | |
6dbaddf9 | 237 | finish_cdtor (body); |
2c5f4139 JM |
238 | } |
239 | #endif | |
240 | #ifndef ASM_OUTPUT_DESTRUCTOR | |
241 | if (static_dtors) | |
242 | { | |
6dbaddf9 | 243 | tree body = start_cdtor ('D'); |
2c5f4139 JM |
244 | |
245 | for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors)) | |
6dbaddf9 RH |
246 | c_expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors), |
247 | NULL_TREE)); | |
2c5f4139 | 248 | |
6dbaddf9 | 249 | finish_cdtor (body); |
2c5f4139 JM |
250 | } |
251 | #endif | |
21c7361e | 252 | |
67673f5c MM |
253 | if (back_end_hook) |
254 | (*back_end_hook) (getdecls ()); | |
b7442fb5 NS |
255 | |
256 | { | |
257 | int flags; | |
258 | FILE *stream = dump_begin (TDI_all, &flags); | |
259 | ||
260 | if (stream) | |
261 | { | |
262 | dump_node (getdecls (), flags & ~TDF_SLIM, stream); | |
263 | dump_end (TDI_all, stream); | |
264 | } | |
265 | } | |
2c5f4139 | 266 | } |
4e1e6a01 GDR |
267 | |
268 | /* Called during diagnostic message formatting process to print a | |
269 | source-level entity onto BUFFER. The meaning of the format specifiers | |
270 | is as follows: | |
271 | %D: a general decl, | |
272 | %F: a function declaration, | |
273 | %T: a type. | |
274 | ||
275 | These format specifiers form a subset of the format specifiers set used | |
276 | by the C++ front-end. | |
277 | Please notice when called, the `%' part was already skipped by the | |
278 | diagnostic machinery. */ | |
279 | static int | |
280 | c_tree_printer (buffer) | |
281 | output_buffer *buffer; | |
282 | { | |
283 | tree t = va_arg (output_buffer_format_args (buffer), tree); | |
284 | ||
285 | switch (*output_buffer_text_cursor (buffer)) | |
286 | { | |
287 | case 'D': | |
288 | case 'F': | |
289 | case 'T': | |
290 | { | |
291 | const char *n = DECL_NAME (t) | |
292 | ? (*decl_printable_name) (t, 2) | |
293 | : "({anonymous})"; | |
294 | output_add_string (buffer, n); | |
295 | } | |
296 | return 1; | |
297 | ||
298 | default: | |
299 | return 0; | |
300 | } | |
301 | } | |
21c7361e AJ |
302 | |
303 | static int | |
304 | c_missing_noreturn_ok_p (decl) | |
305 | tree decl; | |
306 | { | |
307 | /* A missing noreturn is not ok for freestanding implementations and | |
308 | ok for the `main' function in hosted implementations. */ | |
309 | return flag_hosted && MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl)); | |
310 | } |