2001-03-22 Alexandre Petit-Bianco <apbianco@redhat.com>
[official-gcc.git] / gcc / c-lang.c
blob22c98100ee14b91c70f93f009e83aec656c7eb5d
1 /* Language-specific hook definitions for C front end.
2 Copyright (C) 1991, 1995, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU CC.
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.
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.
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. */
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"
39 static int c_tree_printer PARAMS ((output_buffer *));
40 static int c_missing_noreturn_ok_p PARAMS ((tree));
41 static void c_init PARAMS ((void));
42 static void c_init_options PARAMS ((void));
43 static void c_post_options PARAMS ((void));
45 /* Each front end provides its own. */
46 struct lang_hooks lang_hooks = {c_init,
47 NULL, /* c_finish */
48 c_init_options,
49 c_decode_option,
50 c_post_options};
52 /* Post-switch processing. */
53 static void
54 c_post_options ()
56 cpp_post_options (parse_in);
59 static void
60 c_init_options ()
62 parse_in = cpp_create_reader (CLK_GNUC89);
64 /* Mark as "unspecified". */
65 flag_bounds_check = -1;
68 static void
69 c_init ()
71 c_common_lang_init ();
73 /* If still unspecified, make it match -std=c99
74 (allowing for -pedantic-errors). */
75 if (mesg_implicit_function_declaration < 0)
77 if (flag_isoc99)
78 mesg_implicit_function_declaration = flag_pedantic_errors ? 2 : 1;
79 else
80 mesg_implicit_function_declaration = 0;
83 save_lang_status = &push_c_function_context;
84 restore_lang_status = &pop_c_function_context;
85 mark_lang_status = &mark_c_function_context;
86 lang_expand_expr = &c_expand_expr;
87 lang_safe_from_p = &c_safe_from_p;
88 lang_printer = &c_tree_printer;
89 lang_expand_decl_stmt = &c_expand_decl_stmt;
90 lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p;
92 c_parse_init ();
95 const char *
96 lang_identify ()
98 return "c";
101 void
102 print_lang_statistics ()
106 /* used by print-tree.c */
108 void
109 lang_print_xnode (file, node, indent)
110 FILE *file ATTRIBUTE_UNUSED;
111 tree node ATTRIBUTE_UNUSED;
112 int indent ATTRIBUTE_UNUSED;
116 /* Used by c-lex.c, but only for objc. */
118 tree
119 lookup_interface (arg)
120 tree arg ATTRIBUTE_UNUSED;
122 return 0;
125 tree
126 is_class_name (arg)
127 tree arg ATTRIBUTE_UNUSED;
129 return 0;
132 void
133 maybe_objc_check_decl (decl)
134 tree decl ATTRIBUTE_UNUSED;
139 maybe_objc_comptypes (lhs, rhs, reflexive)
140 tree lhs ATTRIBUTE_UNUSED;
141 tree rhs ATTRIBUTE_UNUSED;
142 int reflexive ATTRIBUTE_UNUSED;
144 return -1;
147 tree
148 maybe_building_objc_message_expr ()
150 return 0;
154 recognize_objc_keyword ()
156 return 0;
159 /* Used by c-typeck.c (build_external_ref), but only for objc. */
161 tree
162 lookup_objc_ivar (id)
163 tree id ATTRIBUTE_UNUSED;
165 return 0;
168 #if !defined(ASM_OUTPUT_CONSTRUCTOR) || !defined(ASM_OUTPUT_DESTRUCTOR)
169 extern tree static_ctors;
170 extern tree static_dtors;
172 static tree start_cdtor PARAMS ((int));
173 static void finish_cdtor PARAMS ((tree));
175 static tree
176 start_cdtor (method_type)
177 int method_type;
179 tree fnname = get_file_function_name (method_type);
180 tree void_list_node_1 = build_tree_list (NULL_TREE, void_type_node);
181 tree body;
183 start_function (void_list_node_1,
184 build_nt (CALL_EXPR, fnname,
185 tree_cons (NULL_TREE, NULL_TREE, void_list_node_1),
186 NULL_TREE),
187 NULL_TREE, NULL_TREE);
188 store_parm_decls ();
190 current_function_cannot_inline
191 = "static constructors and destructors cannot be inlined";
193 body = c_begin_compound_stmt ();
195 pushlevel (0);
196 clear_last_expr ();
197 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
199 return body;
202 static void
203 finish_cdtor (body)
204 tree body;
206 tree scope;
207 tree block;
209 scope = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
210 block = poplevel (0, 0, 0);
211 SCOPE_STMT_BLOCK (TREE_PURPOSE (scope)) = block;
212 SCOPE_STMT_BLOCK (TREE_VALUE (scope)) = block;
214 RECHAIN_STMTS (body, COMPOUND_BODY (body));
216 finish_function (0);
218 #endif
220 /* Called at end of parsing, but before end-of-file processing. */
222 void
223 finish_file ()
225 #ifndef ASM_OUTPUT_CONSTRUCTOR
226 if (static_ctors)
228 tree body = start_cdtor ('I');
230 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
231 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
232 NULL_TREE));
234 finish_cdtor (body);
236 #endif
237 #ifndef ASM_OUTPUT_DESTRUCTOR
238 if (static_dtors)
240 tree body = start_cdtor ('D');
242 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
243 c_expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
244 NULL_TREE));
246 finish_cdtor (body);
248 #endif
250 if (back_end_hook)
251 (*back_end_hook) (getdecls ());
253 if (flag_dump_translation_unit)
254 dump_node_to_file (getdecls (), flag_dump_translation_unit);
257 /* Called during diagnostic message formatting process to print a
258 source-level entity onto BUFFER. The meaning of the format specifiers
259 is as follows:
260 %D: a general decl,
261 %F: a function declaration,
262 %T: a type.
264 These format specifiers form a subset of the format specifiers set used
265 by the C++ front-end.
266 Please notice when called, the `%' part was already skipped by the
267 diagnostic machinery. */
268 static int
269 c_tree_printer (buffer)
270 output_buffer *buffer;
272 tree t = va_arg (output_buffer_format_args (buffer), tree);
274 switch (*output_buffer_text_cursor (buffer))
276 case 'D':
277 case 'F':
278 case 'T':
280 const char *n = DECL_NAME (t)
281 ? (*decl_printable_name) (t, 2)
282 : "({anonymous})";
283 output_add_string (buffer, n);
285 return 1;
287 default:
288 return 0;
292 static int
293 c_missing_noreturn_ok_p (decl)
294 tree decl;
296 /* A missing noreturn is not ok for freestanding implementations and
297 ok for the `main' function in hosted implementations. */
298 return flag_hosted && MAIN_NAME_P (DECL_ASSEMBLER_NAME (decl));