OSDN Git Service

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