OSDN Git Service

* c-common.def (COMPOUND_LITERAL_EXPR): New.
[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 GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "function.h"
27 #include "toplev.h"
28 #include "flags.h"
29 #include "ggc.h"
30 #include "rtl.h"
31 #include "expr.h"
32 #include "c-tree.h"
33 #include "varray.h"
34 #include "langhooks.h"
35 #include "langhooks-def.h"
36
37 static const char *c_init PARAMS ((const char *));
38 static void c_init_options PARAMS ((void));
39 static void c_post_options PARAMS ((void));
40
41 /* ### When changing hooks, consider if ObjC needs changing too!! ### */
42
43 #undef LANG_HOOKS_NAME
44 #define LANG_HOOKS_NAME "GNU C"
45 #undef LANG_HOOKS_INIT
46 #define LANG_HOOKS_INIT c_init
47 #undef LANG_HOOKS_FINISH
48 #define LANG_HOOKS_FINISH c_common_finish
49 #undef LANG_HOOKS_INIT_OPTIONS
50 #define LANG_HOOKS_INIT_OPTIONS c_init_options
51 #undef LANG_HOOKS_DECODE_OPTION
52 #define LANG_HOOKS_DECODE_OPTION c_decode_option
53 #undef LANG_HOOKS_POST_OPTIONS
54 #define LANG_HOOKS_POST_OPTIONS c_post_options
55 #undef LANG_HOOKS_GET_ALIAS_SET
56 #define LANG_HOOKS_GET_ALIAS_SET c_common_get_alias_set
57 #undef LANG_HOOKS_SAFE_FROM_P
58 #define LANG_HOOKS_SAFE_FROM_P c_safe_from_p
59 #undef LANG_HOOKS_STATICP
60 #define LANG_HOOKS_STATICP c_staticp
61 #undef LANG_HOOKS_PRINT_IDENTIFIER
62 #define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
63 #undef LANG_HOOKS_SET_YYDEBUG
64 #define LANG_HOOKS_SET_YYDEBUG c_set_yydebug
65
66 #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
67 #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \
68   c_cannot_inline_tree_fn
69 #undef LANG_HOOKS_TREE_INLINING_DISREGARD_INLINE_LIMITS
70 #define LANG_HOOKS_TREE_INLINING_DISREGARD_INLINE_LIMITS \
71   c_disregard_inline_limits
72 #undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P
73 #define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P \
74   anon_aggr_type_p
75
76 /* ### When changing hooks, consider if ObjC needs changing too!! ### */
77
78 /* Each front end provides its own.  */
79 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
80
81 static varray_type deferred_fns;
82
83 /* Post-switch processing.  */
84 static void
85 c_post_options ()
86 {
87   c_common_post_options ();
88 }
89
90 static void
91 c_init_options ()
92 {
93   c_common_init_options (clk_c);
94 }
95
96 static const char *
97 c_init (filename)
98      const char *filename;
99 {
100   filename = c_objc_common_init (filename);
101
102   VARRAY_TREE_INIT (deferred_fns, 32, "deferred_fns");
103   ggc_add_tree_varray_root (&deferred_fns, 1);
104
105   return filename;
106 }
107
108 /* Used by c-lex.c, but only for objc.  */
109
110 tree
111 lookup_interface (arg)
112      tree arg ATTRIBUTE_UNUSED;
113 {
114   return 0;
115 }
116
117 tree
118 is_class_name (arg)
119     tree arg ATTRIBUTE_UNUSED;
120 {
121   return 0;
122 }
123
124 void
125 maybe_objc_check_decl (decl)
126      tree decl ATTRIBUTE_UNUSED;
127 {
128 }
129
130 int
131 maybe_objc_comptypes (lhs, rhs, reflexive)
132      tree lhs ATTRIBUTE_UNUSED;
133      tree rhs ATTRIBUTE_UNUSED;
134      int reflexive ATTRIBUTE_UNUSED;
135 {
136   return -1;
137 }
138
139 tree
140 maybe_building_objc_message_expr ()
141 {
142   return 0;
143 }
144
145 int
146 recognize_objc_keyword ()
147 {
148   return 0;
149 }
150
151 /* Used by c-typeck.c (build_external_ref), but only for objc.  */
152
153 tree
154 lookup_objc_ivar (id)
155      tree id ATTRIBUTE_UNUSED;
156 {
157   return 0;
158 }
159
160 extern tree static_ctors;
161 extern tree static_dtors;
162
163 static tree start_cdtor         PARAMS ((int));
164 static void finish_cdtor        PARAMS ((tree));
165
166 static tree
167 start_cdtor (method_type)
168      int method_type;
169 {
170   tree fnname = get_file_function_name (method_type);
171   tree void_list_node_1 = build_tree_list (NULL_TREE, void_type_node);
172   tree body;
173
174   start_function (void_list_node_1,
175                   build_nt (CALL_EXPR, fnname,
176                             tree_cons (NULL_TREE, NULL_TREE, void_list_node_1),
177                             NULL_TREE),
178                   NULL_TREE);
179   store_parm_decls ();
180
181   current_function_cannot_inline
182     = "static constructors and destructors cannot be inlined";
183
184   body = c_begin_compound_stmt ();
185
186   pushlevel (0);
187   clear_last_expr ();
188   add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
189
190   return body;
191 }
192
193 static void
194 finish_cdtor (body)
195      tree body;
196 {
197   tree scope;
198   tree block;
199
200   scope = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
201   block = poplevel (0, 0, 0);
202   SCOPE_STMT_BLOCK (TREE_PURPOSE (scope)) = block;
203   SCOPE_STMT_BLOCK (TREE_VALUE (scope)) = block;
204
205   RECHAIN_STMTS (body, COMPOUND_BODY (body));
206
207   finish_function (0);
208 }
209
210 /* Register a function tree, so that its optimization and conversion
211    to RTL is only done at the end of the compilation.  */
212
213 int
214 defer_fn (fn)
215      tree fn;
216 {
217   VARRAY_PUSH_TREE (deferred_fns, fn);
218
219   return 1;
220 }
221
222 /* Called at end of parsing, but before end-of-file processing.  */
223
224 void
225 finish_file ()
226 {
227   unsigned int i;
228
229   for (i = 0; i < VARRAY_ACTIVE_SIZE (deferred_fns); i++)
230     {
231       tree decl = VARRAY_TREE (deferred_fns, i);
232
233       if (! TREE_ASM_WRITTEN (decl))
234         {
235           /* For static inline functions, delay the decision whether to
236              emit them or not until wrapup_global_declarations.  */
237           if (! TREE_PUBLIC (decl))
238             DECL_DEFER_OUTPUT (decl) = 1;
239           c_expand_deferred_function (decl);
240         }
241     }
242   VARRAY_FREE (deferred_fns);
243
244   if (static_ctors)
245     {
246       tree body = start_cdtor ('I');
247
248       for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
249         c_expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
250                                                  NULL_TREE));
251
252       finish_cdtor (body);
253     }
254   if (static_dtors)
255     {
256       tree body = start_cdtor ('D');
257
258       for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
259         c_expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
260                                                  NULL_TREE));
261
262       finish_cdtor (body);
263     }
264
265   if (back_end_hook)
266     (*back_end_hook) (getdecls ());
267   
268   {
269     int flags;
270     FILE *stream = dump_begin (TDI_all, &flags);
271
272     if (stream)
273       {
274         dump_node (getdecls (), flags & ~TDF_SLIM, stream);
275         dump_end (TDI_all, stream);
276       }
277   }
278 }