OSDN Git Service

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