52173917448b2321b6aed0c4f0d2afb4d0db2932
[gcc.git] / gcc / c-lang.c
1 /* Language-specific hook definitions for C front end.
2 Copyright (C) 1991, 1995, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
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
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "function.h"
27 #include "input.h"
28 #include "toplev.h"
29 #include "diagnostic.h"
30 #include "output.h"
31 #include "flags.h"
32 #include "ggc.h"
33 #include "rtl.h"
34 #include "expr.h"
35 #include "c-tree.h"
36 #include "c-lex.h"
37 #include "cpplib.h"
38
39 static int c_tree_printer PARAMS ((output_buffer *));
40 static int c_missing_noreturn_ok_p PARAMS ((tree));
41
42 /* Each of the functions defined here
43 is an alternative to a function in objc-actions.c. */
44
45 int
46 lang_decode_option (argc, argv)
47 int argc;
48 char **argv;
49 {
50 return c_decode_option (argc, argv);
51 }
52
53 void
54 lang_init_options ()
55 {
56 parse_in = cpp_create_reader (CLK_GNUC89);
57
58 /* Mark as "unspecified". */
59 flag_bounds_check = -1;
60 }
61
62 void
63 lang_init ()
64 {
65 /* If still "unspecified", make it match -fbounded-pointers. */
66 if (flag_bounds_check < 0)
67 flag_bounds_check = flag_bounded_pointers;
68
69 /* If still unspecified, make it match pedantic && -std=c99. */
70 if (mesg_implicit_function_declaration < 0)
71 {
72 if (pedantic && flag_isoc99)
73 mesg_implicit_function_declaration = flag_pedantic_errors ? 2 : 1;
74 else
75 mesg_implicit_function_declaration = 0;
76 }
77
78 save_lang_status = &push_c_function_context;
79 restore_lang_status = &pop_c_function_context;
80 mark_lang_status = &mark_c_function_context;
81 lang_expand_expr = &c_expand_expr;
82 lang_safe_from_p = &c_safe_from_p;
83 lang_printer = &c_tree_printer;
84 lang_expand_decl_stmt = &c_expand_decl_stmt;
85 lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p;
86
87 c_parse_init ();
88 }
89
90 void
91 lang_finish ()
92 {
93 }
94
95 const char *
96 lang_identify ()
97 {
98 return "c";
99 }
100
101 void
102 print_lang_statistics ()
103 {
104 }
105
106 /* used by print-tree.c */
107
108 void
109 lang_print_xnode (file, node, indent)
110 FILE *file ATTRIBUTE_UNUSED;
111 tree node ATTRIBUTE_UNUSED;
112 int indent ATTRIBUTE_UNUSED;
113 {
114 }
115
116 /* Used by c-lex.c, but only for objc. */
117
118 tree
119 lookup_interface (arg)
120 tree arg ATTRIBUTE_UNUSED;
121 {
122 return 0;
123 }
124
125 tree
126 is_class_name (arg)
127 tree arg ATTRIBUTE_UNUSED;
128 {
129 return 0;
130 }
131
132 void
133 maybe_objc_check_decl (decl)
134 tree decl ATTRIBUTE_UNUSED;
135 {
136 }
137
138 int
139 maybe_objc_comptypes (lhs, rhs, reflexive)
140 tree lhs ATTRIBUTE_UNUSED;
141 tree rhs ATTRIBUTE_UNUSED;
142 int reflexive ATTRIBUTE_UNUSED;
143 {
144 return -1;
145 }
146
147 tree
148 maybe_objc_method_name (decl)
149 tree decl ATTRIBUTE_UNUSED;
150 {
151 return 0;
152 }
153
154 tree
155 maybe_building_objc_message_expr ()
156 {
157 return 0;
158 }
159
160 int
161 recognize_objc_keyword ()
162 {
163 return 0;
164 }
165
166 /* Used by c-typeck.c (build_external_ref), but only for objc. */
167
168 tree
169 lookup_objc_ivar (id)
170 tree id ATTRIBUTE_UNUSED;
171 {
172 return 0;
173 }
174
175 #if !defined(ASM_OUTPUT_CONSTRUCTOR) || !defined(ASM_OUTPUT_DESTRUCTOR)
176 extern tree static_ctors;
177 extern tree static_dtors;
178
179 static tree start_cdtor PARAMS ((int));
180 static void finish_cdtor PARAMS ((tree));
181
182 static tree
183 start_cdtor (method_type)
184 int method_type;
185 {
186 tree fnname = get_file_function_name (method_type);
187 tree void_list_node_1 = build_tree_list (NULL_TREE, void_type_node);
188 tree body;
189
190 start_function (void_list_node_1,
191 build_parse_node (CALL_EXPR, fnname,
192 tree_cons (NULL_TREE, NULL_TREE,
193 void_list_node_1),
194 NULL_TREE),
195 NULL_TREE, NULL_TREE);
196 store_parm_decls ();
197
198 current_function_cannot_inline
199 = "static constructors and destructors cannot be inlined";
200
201 body = c_begin_compound_stmt ();
202
203 pushlevel (0);
204 clear_last_expr ();
205 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
206
207 return body;
208 }
209
210 static void
211 finish_cdtor (body)
212 tree body;
213 {
214 tree scope;
215 tree block;
216
217 scope = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
218 block = poplevel (0, 0, 0);
219 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope)) = block;
220 SCOPE_STMT_BLOCK (TREE_VALUE (scope)) = block;
221
222 RECHAIN_STMTS (body, COMPOUND_BODY (body));
223
224 finish_function (0);
225 }
226 #endif
227
228 /* Called at end of parsing, but before end-of-file processing. */
229
230 void
231 finish_file ()
232 {
233 #ifndef ASM_OUTPUT_CONSTRUCTOR
234 if (static_ctors)
235 {
236 tree body = start_cdtor ('I');
237
238 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
239 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
240 NULL_TREE));
241
242 finish_cdtor (body);
243 }
244 #endif
245 #ifndef ASM_OUTPUT_DESTRUCTOR
246 if (static_dtors)
247 {
248 tree body = start_cdtor ('D');
249
250 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
251 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
252 NULL_TREE));
253
254 finish_cdtor (body);
255 }
256 #endif
257
258 if (back_end_hook)
259 (*back_end_hook) (getdecls ());
260
261 if (flag_dump_translation_unit)
262 dump_node_to_file (getdecls (), flag_dump_translation_unit);
263 }
264
265 /* Called during diagnostic message formatting process to print a
266 source-level entity onto BUFFER. The meaning of the format specifiers
267 is as follows:
268 %D: a general decl,
269 %F: a function declaration,
270 %T: a type.
271
272 These format specifiers form a subset of the format specifiers set used
273 by the C++ front-end.
274 Please notice when called, the `%' part was already skipped by the
275 diagnostic machinery. */
276 static int
277 c_tree_printer (buffer)
278 output_buffer *buffer;
279 {
280 tree t = va_arg (output_buffer_format_args (buffer), tree);
281
282 switch (*output_buffer_text_cursor (buffer))
283 {
284 case 'D':
285 case 'F':
286 case 'T':
287 {
288 const char *n = DECL_NAME (t)
289 ? (*decl_printable_name) (t, 2)
290 : "({anonymous})";
291 output_add_string (buffer, n);
292 }
293 return 1;
294
295 default:
296 return 0;
297 }
298 }
299
300 static int
301 c_missing_noreturn_ok_p (decl)
302 tree decl;
303 {
304 /* A missing noreturn is not ok for freestanding implementations and
305 ok for the `main' function in hosted implementations. */
306 return flag_hosted && MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl));
307 }