OSDN Git Service

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