OSDN Git Service

* Makefile.in (c-common.o): Don't depend on c-tree.h or c-lex.h.
[pf3gnuchains/gcc-fork.git] / gcc / c-common.h
1 /* Definitions for c-common.c.
2    Copyright (C) 1987, 1993, 1994, 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 /* Reserved identifiers.  */
23
24 enum rid
25 {
26   RID_UNUSED,
27   RID_INT,
28   RID_CHAR,
29   RID_FLOAT,
30   RID_DOUBLE,
31   RID_VOID,
32   RID_UNUSED1,
33
34   /* The first seven are in the order of most frequently used,
35      as emiprically determined.  */
36   RID_FIRST_MODIFIER,
37   RID_EXTERN = RID_FIRST_MODIFIER,
38   RID_CONST,
39   RID_LONG,
40   RID_TYPEDEF,
41   RID_UNSIGNED,
42   RID_SHORT,
43   RID_INLINE,
44   RID_AUTO,
45   RID_STATIC,
46   RID_REGISTER,
47   RID_SIGNED,
48   RID_RESTRICT,
49   RID_VOLATILE,
50   RID_BOUNDED,
51   RID_UNBOUNDED,
52   RID_NOALIAS,
53   RID_ITERATOR,
54   RID_COMPLEX,
55
56   RID_IN,
57   RID_OUT,
58   RID_INOUT,
59   RID_BYCOPY,
60   RID_BYREF,
61   RID_ONEWAY,
62   RID_ID,
63
64   RID_MAX
65 };
66
67 #define NORID RID_UNUSED
68
69 /* The elements of `ridpointers' are identifier nodes for the reserved
70    type names and storage classes.  It is indexed by a RID_... value.  */
71 extern tree *ridpointers;
72
73 /* Standard named or nameless data types of the C compiler.  */
74
75 enum c_tree_index
76 {
77     CTI_WCHAR_TYPE,
78     CTI_SIGNED_WCHAR_TYPE,
79     CTI_UNSIGNED_WCHAR_TYPE,
80     CTI_WIDEST_INT_LIT_TYPE,
81     CTI_WIDEST_UINT_LIT_TYPE,
82
83     CTI_CHAR_ARRAY_TYPE,
84     CTI_WCHAR_ARRAY_TYPE,
85     CTI_INT_ARRAY_TYPE,
86     CTI_STRING_TYPE,
87     CTI_CONST_STRING_TYPE,
88
89     CTI_BOOLEAN_TYPE,
90     CTI_BOOLEAN_TRUE,
91     CTI_BOOLEAN_FALSE,
92     CTI_DEFAULT_FUNCTION_TYPE,
93     CTI_VOID_LIST,
94
95     CTI_VOID_FTYPE,
96     CTI_VOID_FTYPE_PTR,
97     CTI_INT_FTYPE_INT,
98     CTI_PTR_FTYPE_SIZETYPE,
99
100     CTI_G77_INTEGER_TYPE,
101     CTI_G77_UINTEGER_TYPE,
102     CTI_G77_LONGINT_TYPE,
103     CTI_G77_ULONGINT_TYPE,
104
105     CTI_MAX
106 };
107
108 #define wchar_type_node                 c_global_trees[CTI_WCHAR_TYPE]
109 #define signed_wchar_type_node          c_global_trees[CTI_SIGNED_WCHAR_TYPE]
110 #define unsigned_wchar_type_node        c_global_trees[CTI_UNSIGNED_WCHAR_TYPE]
111 #define widest_integer_literal_type_node c_global_trees[CTI_WIDEST_INT_LIT_TYPE]
112 #define widest_unsigned_literal_type_node c_global_trees[CTI_WIDEST_UINT_LIT_TYPE]
113
114 #define boolean_type_node               c_global_trees[CTI_BOOLEAN_TYPE]
115 #define boolean_true_node               c_global_trees[CTI_BOOLEAN_TRUE]
116 #define boolean_false_node              c_global_trees[CTI_BOOLEAN_FALSE]
117
118 #define char_array_type_node            c_global_trees[CTI_CHAR_ARRAY_TYPE]
119 #define wchar_array_type_node           c_global_trees[CTI_WCHAR_ARRAY_TYPE]
120 #define int_array_type_node             c_global_trees[CTI_INT_ARRAY_TYPE]
121 #define string_type_node                c_global_trees[CTI_STRING_TYPE]
122 #define const_string_type_node          c_global_trees[CTI_CONST_STRING_TYPE]
123
124 #define default_function_type           c_global_trees[CTI_DEFAULT_FUNCTION_TYPE]
125 #define void_list_node                  c_global_trees[CTI_VOID_LIST]
126 #define void_ftype                      c_global_trees[CTI_VOID_FTYPE]
127 #define void_ftype_ptr                  c_global_trees[CTI_VOID_FTYPE_PTR]
128 #define int_ftype_int                   c_global_trees[CTI_INT_FTYPE_INT]
129 #define ptr_ftype_sizetype              c_global_trees[CTI_PTR_FTYPE_SIZETYPE]
130
131 /* g77 integer types, which which must be kept in sync with f/com.h */
132 #define g77_integer_type_node           c_global_trees[CTI_G77_INTEGER_TYPE]
133 #define g77_uinteger_type_node          c_global_trees[CTI_G77_UINTEGER_TYPE]
134 #define g77_longint_type_node           c_global_trees[CTI_G77_LONGINT_TYPE]
135 #define g77_ulongint_type_node          c_global_trees[CTI_G77_ULONGINT_TYPE]
136
137 extern tree c_global_trees[CTI_MAX];
138
139 typedef enum c_language_kind
140 {
141   clk_c,           /* A dialect of C: K&R C, ANSI/ISO C89, C2000,
142                        etc. */
143   clk_cplusplus,   /* ANSI/ISO C++ */
144   clk_objective_c  /* Objective C */
145
146 c_language_kind;
147
148 /* The variant of the C language being processed.  Each C language
149    front-end defines this variable.  */
150
151 extern c_language_kind c_language;
152
153 /* Nonzero means give string constants the type `const char *', rather
154    than `char *'.  */
155
156 extern int flag_const_strings;
157
158 /* Warn about *printf or *scanf format/argument anomalies. */
159
160 extern int warn_format;
161
162 /* Nonzero means do some things the same way PCC does.  */
163
164 extern int flag_traditional;
165
166 /* Nonzero means use the ISO C99 dialect of C.  */
167
168 extern int flag_isoc99;
169
170 /* Nonzero means warn about suggesting putting in ()'s.  */
171
172 extern int warn_parentheses;
173
174 /* Warn if a type conversion is done that might have confusing results.  */
175
176 extern int warn_conversion;
177
178 /* C types are partitioned into three subsets: object, function, and
179    incomplete types.  */
180 #define C_TYPE_OBJECT_P(type) \
181   (TREE_CODE (type) != FUNCTION_TYPE && TYPE_SIZE (type))
182
183 #define C_TYPE_INCOMPLETE_P(type) \
184   (TREE_CODE (type) != FUNCTION_TYPE && TYPE_SIZE (type) == 0)
185
186 #define C_TYPE_FUNCTION_P(type) \
187   (TREE_CODE (type) == FUNCTION_TYPE)
188
189 /* For convenience we define a single macro to identify the class of
190    object or incomplete types.  */
191 #define C_TYPE_OBJECT_OR_INCOMPLETE_P(type) \
192   (!C_TYPE_FUNCTION_P (type))
193
194 /* Record in each node resulting from a binary operator
195    what operator was specified for it.  */
196 #define C_EXP_ORIGINAL_CODE(exp) ((enum tree_code) TREE_COMPLEXITY (exp))
197
198 /* Pointer to function to generate the VAR_DECL for __FUNCTION__ etc.
199    ID is the identifier to use, NAME is the string.
200    TYPE_DEP indicates whether it depends on type of the function or not
201    (i.e. __PRETTY_FUNCTION__).  */
202
203 extern tree (*make_fname_decl)                  PARAMS ((tree, const char *, int));
204
205 extern void declare_function_name               PARAMS ((void));
206 extern void decl_attributes                     PARAMS ((tree, tree, tree));
207 extern void init_function_format_info           PARAMS ((void));
208 extern void check_function_format               PARAMS ((tree, tree, tree));
209 extern void c_apply_type_quals_to_decl          PARAMS ((int, tree));
210 /* Print an error message for invalid operands to arith operation CODE.
211    NOP_EXPR is used as a special case (see truthvalue_conversion).  */
212 extern void binary_op_error                     PARAMS ((enum tree_code));
213 extern void c_expand_expr_stmt                  PARAMS ((tree));
214 extern void c_expand_start_cond                 PARAMS ((tree, int, int));
215 extern void c_expand_start_else                 PARAMS ((void));
216 extern void c_expand_end_cond                   PARAMS ((void));
217 /* Validate the expression after `case' and apply default promotions.  */
218 extern tree check_case_value                    PARAMS ((tree));
219 /* Concatenate a list of STRING_CST nodes into one STRING_CST.  */
220 extern tree combine_strings                     PARAMS ((tree));
221 extern void constant_expression_warning         PARAMS ((tree));
222 extern tree convert_and_check                   PARAMS ((tree, tree));
223 extern void overflow_warning                    PARAMS ((tree));
224 extern void unsigned_conversion_warning         PARAMS ((tree, tree));
225
226 /* Read the rest of the current #-directive line.  */
227 #if USE_CPPLIB
228 extern char *get_directive_line                 PARAMS ((void));
229 #define GET_DIRECTIVE_LINE() get_directive_line ()
230 #else
231 extern char *get_directive_line                 PARAMS ((FILE *));
232 #define GET_DIRECTIVE_LINE() get_directive_line (finput)
233 #endif
234
235 /* Subroutine of build_binary_op, used for comparison operations.
236    See if the operands have both been converted from subword integer types
237    and, if so, perhaps change them both back to their original type.  */
238 extern tree shorten_compare                     PARAMS ((tree *, tree *, tree *, enum tree_code *));
239 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
240    or validate its data type for an `if' or `while' statement or ?..: exp. */
241 extern tree truthvalue_conversion               PARAMS ((tree));
242 extern tree type_for_mode                       PARAMS ((enum machine_mode, int));
243 extern tree type_for_size                       PARAMS ((unsigned, int));
244
245 /* Build tree nodes and builtin functions common to both C and C++ language
246    frontends.  */
247 extern void c_common_nodes_and_builtins         PARAMS ((int, int, int));
248
249 extern tree build_va_arg                        PARAMS ((tree, tree));
250
251 /* Nonzero if the type T promotes to itself.
252    ANSI C states explicitly the list of types that promote;
253    in particular, short promotes to int even if they have the same width.  */
254 #define C_PROMOTING_INTEGER_TYPE_P(t)                           \
255   (TREE_CODE ((t)) == INTEGER_TYPE                              \
256    && (TYPE_MAIN_VARIANT (t) == char_type_node                  \
257        || TYPE_MAIN_VARIANT (t) == signed_char_type_node        \
258        || TYPE_MAIN_VARIANT (t) == unsigned_char_type_node      \
259        || TYPE_MAIN_VARIANT (t) == short_integer_type_node      \
260        || TYPE_MAIN_VARIANT (t) == short_unsigned_type_node))
261
262 extern int self_promoting_args_p                PARAMS ((tree));
263 extern tree simple_type_promotes_to             PARAMS ((tree));
264
265 \f
266 /* These macros provide convenient access to the various _STMT nodes
267    created when parsing template declarations.  */
268
269 /* IF_STMT accessors. These give access to the condtion of the if
270    statement, the then block of the if statement, and the else block
271    of the if stsatement if it exists. */
272 #define IF_COND(NODE)           TREE_OPERAND (IF_STMT_CHECK (NODE), 0)
273 #define THEN_CLAUSE(NODE)       TREE_OPERAND (IF_STMT_CHECK (NODE), 1)
274 #define ELSE_CLAUSE(NODE)       TREE_OPERAND (IF_STMT_CHECK (NODE), 2)
275
276 /* WHILE_STMT accessors. These give access to the condtion of the
277    while statement and the body of the while statement, respectively. */
278 #define WHILE_COND(NODE)        TREE_OPERAND (WHILE_STMT_CHECK (NODE), 0)
279 #define WHILE_BODY(NODE)        TREE_OPERAND (WHILE_STMT_CHECK (NODE), 1)
280
281 /* DO_STMT accessors. These give access to the condition of the do
282    statement and the body of the do statement, respectively. */
283 #define DO_COND(NODE)           TREE_OPERAND (DO_STMT_CHECK (NODE), 0)
284 #define DO_BODY(NODE)           TREE_OPERAND (DO_STMT_CHECK (NODE), 1)
285
286 /* RETURN_STMT accessor. This gives the expression associated with a
287    return statement. */
288 #define RETURN_EXPR(NODE)       TREE_OPERAND (RETURN_STMT_CHECK (NODE), 0)
289
290 /* EXPR_STMT accessor. This gives the expression associated with an
291    expression statement. */
292 #define EXPR_STMT_EXPR(NODE)    TREE_OPERAND (EXPR_STMT_CHECK (NODE), 0)
293
294 /* FOR_STMT accessors. These give access to the init statement,
295    condition, update expression, and body of the for statement,
296    respectively. */
297 #define FOR_INIT_STMT(NODE)     TREE_OPERAND (FOR_STMT_CHECK (NODE), 0)
298 #define FOR_COND(NODE)          TREE_OPERAND (FOR_STMT_CHECK (NODE), 1)
299 #define FOR_EXPR(NODE)          TREE_OPERAND (FOR_STMT_CHECK (NODE), 2)
300 #define FOR_BODY(NODE)          TREE_OPERAND (FOR_STMT_CHECK (NODE), 3)
301
302 /* SWITCH_STMT accessors. These give access to the condition and body
303    of the switch statement, respectively. */
304 #define SWITCH_COND(NODE)       TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 0)
305 #define SWITCH_BODY(NODE)       TREE_OPERAND (SWITCH_STMT_CHECK (NODE), 1)
306
307 /* CASE_LABEL accessors. These give access to the high and low values
308    of a case label, respectively. */
309 #define CASE_LOW(NODE)          TREE_OPERAND (CASE_LABEL_CHECK (NODE), 0)
310 #define CASE_HIGH(NODE)         TREE_OPERAND (CASE_LABEL_CHECK (NODE), 1)
311
312 /* GOTO_STMT accessor. This gives access to the label associated with
313    a goto statement. */
314 #define GOTO_DESTINATION(NODE)  TREE_OPERAND (GOTO_STMT_CHECK (NODE), 0)
315
316 /* COMPOUND_STMT accessor. This gives access to the TREE_LIST of
317    statements assocated with a compound statement. The result is the
318    first statement in the list. Succeeding nodes can be acccessed by
319    calling TREE_CHAIN on a node in the list. */
320 #define COMPOUND_BODY(NODE)     TREE_OPERAND (COMPOUND_STMT_CHECK (NODE), 0)
321
322 /* ASM_STMT accessors. ASM_STRING returns a STRING_CST for the
323    instruction (e.g., "mov x, y"). ASM_OUTPUTS, ASM_INPUTS, and
324    ASM_CLOBBERS represent the outputs, inputs, and clobbers for the
325    statement. */
326 #define ASM_CV_QUAL(NODE)       TREE_OPERAND (ASM_STMT_CHECK (NODE), 0)
327 #define ASM_STRING(NODE)        TREE_OPERAND (ASM_STMT_CHECK (NODE), 1)
328 #define ASM_OUTPUTS(NODE)       TREE_OPERAND (ASM_STMT_CHECK (NODE), 2)
329 #define ASM_INPUTS(NODE)        TREE_OPERAND (ASM_STMT_CHECK (NODE), 3)
330 #define ASM_CLOBBERS(NODE)      TREE_OPERAND (ASM_STMT_CHECK (NODE), 4)
331
332 /* DECL_STMT accessor. This gives access to the DECL associated with
333    the given declaration statement. */ 
334 #define DECL_STMT_DECL(NODE)    TREE_OPERAND (DECL_STMT_CHECK (NODE), 0)
335
336 /* STMT_EXPR accessor. */
337 #define STMT_EXPR_STMT(NODE)    TREE_OPERAND (STMT_EXPR_CHECK (NODE), 0)
338
339 /* LABEL_STMT accessor. This gives access to the label associated with
340    the given label statement. */
341 #define LABEL_STMT_LABEL(NODE)  TREE_OPERAND (LABEL_STMT_CHECK (NODE), 0)
342
343 /* Nonzero if this SCOPE_STMT is for the beginning of a scope.  */
344 #define SCOPE_BEGIN_P(NODE) \
345   (TREE_LANG_FLAG_0 (SCOPE_STMT_CHECK (NODE))) 
346
347 /* Nonzero if this SCOPE_STMT is for the end of a scope.  */
348 #define SCOPE_END_P(NODE) \
349   (!SCOPE_BEGIN_P (SCOPE_STMT_CHECK (NODE)))
350
351 /* The BLOCK containing the declarations contained in this scope.  */
352 #define SCOPE_STMT_BLOCK(NODE) \
353   (TREE_OPERAND (SCOPE_STMT_CHECK (NODE), 0))
354
355 /* Nonzero for a SCOPE_STMT if there were no variables in this scope.  */
356 #define SCOPE_NULLIFIED_P(NODE) \
357   (SCOPE_STMT_BLOCK ((NODE)) == NULL_TREE)
358
359 /* Nonzero for a SCOPE_STMT which represents a lexical scope, but
360    which should be treated as non-existant from the point of view of
361    running cleanup actions.  */
362 #define SCOPE_NO_CLEANUPS_P(NODE) \
363   (TREE_LANG_FLAG_3 (SCOPE_STMT_CHECK (NODE)))
364
365 /* Nonzero for a SCOPE_STMT if this statement is for a partial scope.
366    For example, in:
367   
368      S s;
369      l:
370      S s2;
371      goto l;
372
373    there is (implicitly) a new scope after `l', even though there are
374    no curly braces.  In particular, when we hit the goto, we must
375    destroy s2 and then re-construct it.  For the implicit scope,
376    SCOPE_PARTIAL_P will be set.  */
377 #define SCOPE_PARTIAL_P(NODE) \
378   (TREE_LANG_FLAG_4 (SCOPE_STMT_CHECK (NODE)))
379
380 /* Nonzero for an ASM_STMT if the assembly statement is volatile.  */
381 #define ASM_VOLATILE_P(NODE)                    \
382   (ASM_CV_QUAL (ASM_STMT_CHECK (NODE)) != NULL_TREE)
383
384 /* The line-number at which a statement began.  But if
385    STMT_LINENO_FOR_FN_P does holds, then this macro gives the
386    line number for the end of the current function instead.  */
387 #define STMT_LINENO(NODE)                       \
388   (TREE_COMPLEXITY ((NODE)))
389
390 /* If non-zero, the STMT_LINENO for NODE is the line at which the
391    function ended.  */
392 #define STMT_LINENO_FOR_FN_P(NODE)              \
393   (TREE_LANG_FLAG_2 ((NODE)))
394
395
396 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) SYM,
397
398 enum c_tree_code {
399   C_DUMMY_TREE_CODE = LAST_AND_UNUSED_TREE_CODE,
400 #include "c-common.def"
401   LAST_C_TREE_CODE
402 };
403
404 #undef DEFTREECODE
405
406 extern void add_c_tree_codes                    PARAMS ((void));
407 \f
408
409 /* These functions must be defined by each front-end which implements
410    a variant of the C language.  They are used in c-common.c.  */
411
412 extern tree build_unary_op                      PARAMS ((enum tree_code,
413                                                          tree, int));
414 extern tree build_binary_op                     PARAMS ((enum tree_code,
415                                                          tree, tree, int));
416 extern int lvalue_p                             PARAMS ((tree));
417 extern tree default_conversion                  PARAMS ((tree));
418
419 /* Given two integer or real types, return the type for their sum.
420    Given two compatible ANSI C types, returns the merged type.  */
421
422 extern tree common_type                         PARAMS ((tree, tree));
423