OSDN Git Service

* c-lang.c: #include diagnostic.h
[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 "c-tree.h"
29 #include "c-lex.h"
30 #include "toplev.h"
31 #include "diagnostic.h"
32 #include "output.h"
33 #include "flags.h"
34 #include "ggc.h"
35
36 static int c_tree_printer PARAMS ((output_buffer *));
37
38 #if USE_CPPLIB
39 #include "cpplib.h"
40 extern char *yy_cur;
41 extern cpp_reader  parse_in;
42 extern cpp_options parse_options;
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_reader_init (&parse_in);
61   parse_in.opts = &parse_options;
62   cpp_options_init (&parse_options);
63 #endif
64   /* Mark as "unspecified".  */
65   flag_bounds_check = -1;
66 }
67
68 void
69 lang_init ()
70 {
71   /* If still "unspecified", make it match -fbounded-pointers.  */
72   if (flag_bounds_check < 0)
73     flag_bounds_check = flag_bounded_pointers;
74
75   /* If still unspecified, make it match pedantic && -std=c99.  */
76   if (mesg_implicit_function_declaration < 0)
77     {
78       if (pedantic && flag_isoc99)
79         mesg_implicit_function_declaration = flag_pedantic_errors ? 2 : 1;
80       else
81         mesg_implicit_function_declaration = 0;
82     }
83
84   /* the beginning of the file is a new line; check for # */
85   /* With luck, we discover the real source file's name from that
86      and put it in input_filename.  */
87 #if !USE_CPPLIB
88   ungetc (check_newline (), finput);
89 #else
90   check_newline ();
91   yy_cur--;
92 #endif 
93
94   save_lang_status = &push_c_function_context;
95   restore_lang_status = &pop_c_function_context;
96   mark_lang_status = &mark_c_function_context;
97
98   lang_printer = c_tree_printer;
99
100   c_parse_init ();
101 }
102
103 void
104 lang_finish ()
105 {
106 }
107
108 const char *
109 lang_identify ()
110 {
111   return "c";
112 }
113
114 void
115 print_lang_statistics ()
116 {
117 }
118
119 /* used by print-tree.c */
120
121 void
122 lang_print_xnode (file, node, indent)
123      FILE *file ATTRIBUTE_UNUSED;
124      tree node ATTRIBUTE_UNUSED;
125      int indent ATTRIBUTE_UNUSED;
126 {
127 }
128
129 /* Used by c-lex.c, but only for objc.  */
130
131 tree
132 lookup_interface (arg)
133      tree arg ATTRIBUTE_UNUSED;
134 {
135   return 0;
136 }
137
138 tree
139 is_class_name (arg)
140     tree arg ATTRIBUTE_UNUSED;
141 {
142   return 0;
143 }
144
145 void
146 maybe_objc_check_decl (decl)
147      tree decl ATTRIBUTE_UNUSED;
148 {
149 }
150
151 int
152 maybe_objc_comptypes (lhs, rhs, reflexive)
153      tree lhs ATTRIBUTE_UNUSED;
154      tree rhs ATTRIBUTE_UNUSED;
155      int reflexive ATTRIBUTE_UNUSED;
156 {
157   return -1;
158 }
159
160 tree
161 maybe_objc_method_name (decl)
162     tree decl ATTRIBUTE_UNUSED;
163 {
164   return 0;
165 }
166
167 tree
168 maybe_building_objc_message_expr ()
169 {
170   return 0;
171 }
172
173 int
174 recognize_objc_keyword ()
175 {
176   return 0;
177 }
178
179 /* Used by c-typeck.c (build_external_ref), but only for objc.  */
180
181 tree
182 lookup_objc_ivar (id)
183      tree id ATTRIBUTE_UNUSED;
184 {
185   return 0;
186 }
187
188 /* Called at end of parsing, but before end-of-file processing.  */
189
190 void
191 finish_file ()
192 {
193 #ifndef ASM_OUTPUT_CONSTRUCTOR
194   extern tree static_ctors;
195 #endif
196 #ifndef ASM_OUTPUT_DESTRUCTOR
197   extern tree static_dtors;
198 #endif
199   extern tree build_function_call                 PARAMS ((tree, tree));
200 #if !defined(ASM_OUTPUT_CONSTRUCTOR) || !defined(ASM_OUTPUT_DESTRUCTOR)
201   tree void_list_node_1 = build_tree_list (NULL_TREE, void_type_node);
202 #endif
203 #ifndef ASM_OUTPUT_CONSTRUCTOR
204   if (static_ctors)
205     {
206       tree fnname = get_file_function_name ('I');
207       start_function (void_list_node_1,
208                       build_parse_node (CALL_EXPR, fnname, 
209                                         tree_cons (NULL_TREE, NULL_TREE, 
210                                                    void_list_node_1),
211                                         NULL_TREE),
212                       NULL_TREE, NULL_TREE);
213       fnname = DECL_ASSEMBLER_NAME (current_function_decl);
214       store_parm_decls ();
215
216       for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
217         expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
218                                                NULL_TREE));
219
220       finish_function (0);
221
222       assemble_constructor (IDENTIFIER_POINTER (fnname));
223     }
224 #endif
225 #ifndef ASM_OUTPUT_DESTRUCTOR
226   if (static_dtors)
227     {
228       tree fnname = get_file_function_name ('D');
229       start_function (void_list_node_1,
230                       build_parse_node (CALL_EXPR, fnname, 
231                                         tree_cons (NULL_TREE, NULL_TREE,
232                                                    void_list_node_1),
233                                         NULL_TREE),
234                       NULL_TREE, NULL_TREE);
235       fnname = DECL_ASSEMBLER_NAME (current_function_decl);
236       store_parm_decls ();
237
238       for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
239         expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
240                                                NULL_TREE));
241
242       finish_function (0);
243
244       assemble_destructor (IDENTIFIER_POINTER (fnname));
245     }
246 #endif
247 }
248
249 /* Called during diagnostic message formatting process to print a
250    source-level entity onto BUFFER.  The meaning of the format specifiers
251    is as follows:
252    %D: a general decl,
253    %F: a function declaration,
254    %T: a type.
255
256    These format specifiers form a subset of the format specifiers set used
257    by the C++ front-end.
258    Please notice when called, the `%' part was already skipped by the
259    diagnostic machinery.  */
260 static int
261 c_tree_printer (buffer)
262      output_buffer *buffer;
263 {
264   tree t = va_arg (output_buffer_format_args (buffer), tree);
265
266   switch (*output_buffer_text_cursor (buffer))
267     {
268     case 'D':
269     case 'F':
270     case 'T':
271       {
272         const char *n = DECL_NAME (t)
273           ? (*decl_printable_name) (t, 2)
274           : "({anonymous})";
275         output_add_string (buffer, n);
276       }
277       return 1;
278
279     default:
280       return 0;
281     }
282 }