OSDN Git Service

2004-06-28 Paolo Bonzini <bonzini@gnu.org>
[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, 2003, 2004 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 "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "c-tree.h"
29 #include "c-common.h"
30 #include "ggc.h"
31 #include "langhooks.h"
32 #include "langhooks-def.h"
33 #include "tree-inline.h"
34 #include "diagnostic.h"
35 #include "c-pretty-print.h"
36
37 static void c_initialize_diagnostics (diagnostic_context *);
38
39 enum c_language_kind c_language = clk_c;
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_IDENTIFIER_SIZE
46 #define LANG_HOOKS_IDENTIFIER_SIZE C_SIZEOF_STRUCT_LANG_IDENTIFIER
47 #undef LANG_HOOKS_INIT
48 #define LANG_HOOKS_INIT c_objc_common_init
49 #undef LANG_HOOKS_FINISH
50 #define LANG_HOOKS_FINISH c_common_finish
51 #undef LANG_HOOKS_INIT_OPTIONS
52 #define LANG_HOOKS_INIT_OPTIONS c_common_init_options
53 #undef LANG_HOOKS_INITIALIZE_DIAGNOSTICS
54 #define LANG_HOOKS_INITIALIZE_DIAGNOSTICS c_initialize_diagnostics
55 #undef LANG_HOOKS_HANDLE_OPTION
56 #define LANG_HOOKS_HANDLE_OPTION c_common_handle_option
57 #undef LANG_HOOKS_MISSING_ARGUMENT
58 #define LANG_HOOKS_MISSING_ARGUMENT c_common_missing_argument
59 #undef LANG_HOOKS_POST_OPTIONS
60 #define LANG_HOOKS_POST_OPTIONS c_common_post_options
61 #undef LANG_HOOKS_GET_ALIAS_SET
62 #define LANG_HOOKS_GET_ALIAS_SET c_common_get_alias_set
63 #undef LANG_HOOKS_EXPAND_EXPR
64 #define LANG_HOOKS_EXPAND_EXPR c_expand_expr
65 #undef LANG_HOOKS_EXPAND_DECL
66 #define LANG_HOOKS_EXPAND_DECL c_expand_decl
67 #undef LANG_HOOKS_MARK_ADDRESSABLE
68 #define LANG_HOOKS_MARK_ADDRESSABLE c_mark_addressable
69 #undef LANG_HOOKS_PARSE_FILE
70 #define LANG_HOOKS_PARSE_FILE c_common_parse_file
71 #undef LANG_HOOKS_CLEAR_BINDING_STACK
72 #define LANG_HOOKS_CLEAR_BINDING_STACK lhd_do_nothing
73 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
74 #define LANG_HOOKS_TRUTHVALUE_CONVERSION c_objc_common_truthvalue_conversion
75 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
76 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL c_finish_incomplete_decl
77 #undef LANG_HOOKS_UNSAFE_FOR_REEVAL
78 #define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
79 #undef LANG_HOOKS_STATICP
80 #define LANG_HOOKS_STATICP c_staticp
81 #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
82 #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME c_static_assembler_name
83 #undef LANG_HOOKS_NO_BODY_BLOCKS
84 #define LANG_HOOKS_NO_BODY_BLOCKS true
85 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
86 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL c_warn_unused_global_decl
87 #undef LANG_HOOKS_PRINT_IDENTIFIER
88 #define LANG_HOOKS_PRINT_IDENTIFIER c_print_identifier
89 #undef LANG_HOOKS_FUNCTION_ENTER_NESTED
90 #define LANG_HOOKS_FUNCTION_ENTER_NESTED c_push_function_context
91 #undef LANG_HOOKS_FUNCTION_LEAVE_NESTED
92 #define LANG_HOOKS_FUNCTION_LEAVE_NESTED c_pop_function_context
93 #undef LANG_HOOKS_FUNCTION_MISSING_NORETURN_OK_P
94 #define LANG_HOOKS_FUNCTION_MISSING_NORETURN_OK_P c_missing_noreturn_ok_p
95 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
96 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL c_dup_lang_specific_decl
97
98 /* Attribute hooks.  */
99 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
100 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE c_common_attribute_table
101 #undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
102 #define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE c_common_format_attribute_table
103
104 #undef LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN
105 #define LANG_HOOKS_TREE_INLINING_CANNOT_INLINE_TREE_FN \
106   c_cannot_inline_tree_fn
107 #undef LANG_HOOKS_TREE_INLINING_DISREGARD_INLINE_LIMITS
108 #define LANG_HOOKS_TREE_INLINING_DISREGARD_INLINE_LIMITS \
109   c_disregard_inline_limits
110 #undef LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P
111 #define LANG_HOOKS_TREE_INLINING_ANON_AGGR_TYPE_P \
112   anon_aggr_type_p
113 #undef LANG_HOOKS_TREE_INLINING_CONVERT_PARM_FOR_INLINING
114 #define LANG_HOOKS_TREE_INLINING_CONVERT_PARM_FOR_INLINING \
115   c_convert_parm_for_inlining
116 #undef LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN
117 #define LANG_HOOKS_TREE_DUMP_DUMP_TREE_FN c_dump_tree
118
119 #undef LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION
120 #define LANG_HOOKS_CALLGRAPH_EXPAND_FUNCTION c_expand_body
121
122 #undef LANG_HOOKS_TYPE_FOR_MODE
123 #define LANG_HOOKS_TYPE_FOR_MODE c_common_type_for_mode
124 #undef LANG_HOOKS_TYPE_FOR_SIZE
125 #define LANG_HOOKS_TYPE_FOR_SIZE c_common_type_for_size
126 #undef LANG_HOOKS_SIGNED_TYPE
127 #define LANG_HOOKS_SIGNED_TYPE c_common_signed_type
128 #undef LANG_HOOKS_UNSIGNED_TYPE
129 #define LANG_HOOKS_UNSIGNED_TYPE c_common_unsigned_type
130 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
131 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
132 #undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR
133 #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR c_incomplete_type_error
134 #undef LANG_HOOKS_TYPE_PROMOTES_TO
135 #define LANG_HOOKS_TYPE_PROMOTES_TO c_type_promotes_to
136 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
137 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE c_register_builtin_type
138
139 /* The C front end's scoping structure is very different from
140    that expected by the language-independent code; it is best
141    to disable all of pushlevel, poplevel, set_block, and getdecls.
142    This means it must also provide its own write_globals.  */
143
144 #undef LANG_HOOKS_PUSHLEVEL
145 #define LANG_HOOKS_PUSHLEVEL lhd_do_nothing_i
146 #undef LANG_HOOKS_POPLEVEL
147 #define LANG_HOOKS_POPLEVEL lhd_do_nothing_iii_return_null_tree
148 #undef LANG_HOOKS_SET_BLOCK
149 #define LANG_HOOKS_SET_BLOCK lhd_do_nothing_t
150 #undef LANG_HOOKS_GETDECLS
151 #define LANG_HOOKS_GETDECLS lhd_return_null_tree_v
152 #undef LANG_HOOKS_WRITE_GLOBALS
153 #define LANG_HOOKS_WRITE_GLOBALS c_write_global_declarations
154
155 /* Hooks for tree gimplification.  */
156 #undef LANG_HOOKS_GIMPLIFY_EXPR
157 #define LANG_HOOKS_GIMPLIFY_EXPR c_gimplify_expr
158
159 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
160 #define LANG_HOOKS_TYPES_COMPATIBLE_P c_types_compatible_p
161
162 /* ### When changing hooks, consider if ObjC needs changing too!! ### */
163
164 /* Each front end provides its own.  */
165 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
166
167 /* Tree code classes.  */
168
169 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
170
171 const char tree_code_type[] = {
172 #include "tree.def"
173   'x',
174 #include "c-common.def"
175 };
176 #undef DEFTREECODE
177
178 /* Table indexed by tree code giving number of expression
179    operands beyond the fixed part of the node structure.
180    Not used for types or decls.  */
181
182 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
183
184 const unsigned char tree_code_length[] = {
185 #include "tree.def"
186   0,
187 #include "c-common.def"
188 };
189 #undef DEFTREECODE
190
191 /* Names of tree components.
192    Used for printing out the tree and error messages.  */
193 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
194
195 const char *const tree_code_name[] = {
196 #include "tree.def"
197   "@@dummy",
198 #include "c-common.def"
199 };
200 #undef DEFTREECODE
201
202 void
203 finish_file (void)
204 {
205   c_objc_common_finish_file ();
206 }
207
208 int
209 c_types_compatible_p (tree x, tree y)
210 {
211     return comptypes (TYPE_MAIN_VARIANT (x), TYPE_MAIN_VARIANT (y));
212 }
213 static void
214 c_initialize_diagnostics (diagnostic_context *context)
215 {
216   pretty_printer *base = context->printer;
217   c_pretty_printer *pp = xmalloc (sizeof (c_pretty_printer));
218   memcpy (pp_base (pp), base, sizeof (pretty_printer));
219   pp_c_pretty_printer_init (pp);
220   context->printer = (pretty_printer *) pp;
221
222   /* It is safe to free this object because it was previously malloc()'d.  */
223   free (base);
224 }
225
226 #include "gtype-c.h"