]>
Commit | Line | Data |
---|---|---|
51e29401 | 1 | /* Process declarations and variables for C compiler. |
11433f42 | 2 | Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc. |
51e29401 RS |
3 | |
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | ||
21 | /* Process declarations and symbol lookup for C front end. | |
22 | Also constructs types; the standard scalar types at initialization, | |
23 | and structure, union, array and enum types when they are declared. */ | |
24 | ||
25 | /* ??? not all decl nodes are given the most useful possible | |
26 | line numbers. For example, the CONST_DECLs for enum values. */ | |
27 | ||
28 | #include "config.h" | |
29 | #include "tree.h" | |
30 | #include "flags.h" | |
e14417fa | 31 | #include "output.h" |
51e29401 RS |
32 | #include "c-tree.h" |
33 | #include "c-lex.h" | |
34 | #include <stdio.h> | |
35 | ||
36 | /* In grokdeclarator, distinguish syntactic contexts of declarators. */ | |
37 | enum decl_context | |
38 | { NORMAL, /* Ordinary declaration */ | |
39 | FUNCDEF, /* Function definition */ | |
40 | PARM, /* Declaration of parm before function body */ | |
41 | FIELD, /* Declaration inside struct or union */ | |
42 | BITFIELD, /* Likewise but with specified width */ | |
43 | TYPENAME}; /* Typename (inside cast or sizeof) */ | |
44 | ||
51e29401 RS |
45 | #ifndef CHAR_TYPE_SIZE |
46 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
47 | #endif | |
48 | ||
49 | #ifndef SHORT_TYPE_SIZE | |
50 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) | |
51 | #endif | |
52 | ||
53 | #ifndef INT_TYPE_SIZE | |
54 | #define INT_TYPE_SIZE BITS_PER_WORD | |
55 | #endif | |
56 | ||
57 | #ifndef LONG_TYPE_SIZE | |
58 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
59 | #endif | |
60 | ||
61 | #ifndef LONG_LONG_TYPE_SIZE | |
62 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
63 | #endif | |
64 | ||
65 | #ifndef WCHAR_UNSIGNED | |
66 | #define WCHAR_UNSIGNED 0 | |
67 | #endif | |
68 | ||
69 | #ifndef FLOAT_TYPE_SIZE | |
70 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
71 | #endif | |
72 | ||
73 | #ifndef DOUBLE_TYPE_SIZE | |
74 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
75 | #endif | |
76 | ||
77 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
78 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
79 | #endif | |
80 | ||
81 | /* We let tm.h override the types used here, to handle trivial differences | |
82 | such as the choice of unsigned int or long unsigned int for size_t. | |
83 | When machines start needing nontrivial differences in the size type, | |
84 | it would be best to do something here to figure out automatically | |
85 | from other information what type to use. */ | |
86 | ||
87 | #ifndef SIZE_TYPE | |
88 | #define SIZE_TYPE "long unsigned int" | |
89 | #endif | |
90 | ||
91 | #ifndef PTRDIFF_TYPE | |
92 | #define PTRDIFF_TYPE "long int" | |
93 | #endif | |
94 | ||
95 | #ifndef WCHAR_TYPE | |
96 | #define WCHAR_TYPE "int" | |
97 | #endif | |
98 | \f | |
99 | /* a node which has tree code ERROR_MARK, and whose type is itself. | |
100 | All erroneous expressions are replaced with this node. All functions | |
101 | that accept nodes as arguments should avoid generating error messages | |
102 | if this node is one of the arguments, since it is undesirable to get | |
103 | multiple error messages from one error in the input. */ | |
104 | ||
105 | tree error_mark_node; | |
106 | ||
107 | /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ | |
108 | ||
109 | tree short_integer_type_node; | |
110 | tree integer_type_node; | |
111 | tree long_integer_type_node; | |
112 | tree long_long_integer_type_node; | |
113 | ||
114 | tree short_unsigned_type_node; | |
115 | tree unsigned_type_node; | |
116 | tree long_unsigned_type_node; | |
117 | tree long_long_unsigned_type_node; | |
118 | ||
f444e553 JM |
119 | tree boolean_type_node; |
120 | tree boolean_false_node; | |
121 | tree boolean_true_node; | |
122 | ||
51e29401 RS |
123 | tree ptrdiff_type_node; |
124 | ||
125 | tree unsigned_char_type_node; | |
126 | tree signed_char_type_node; | |
127 | tree char_type_node; | |
128 | tree wchar_type_node; | |
129 | tree signed_wchar_type_node; | |
130 | tree unsigned_wchar_type_node; | |
131 | ||
132 | tree float_type_node; | |
133 | tree double_type_node; | |
134 | tree long_double_type_node; | |
135 | ||
5ab10c42 RS |
136 | tree complex_integer_type_node; |
137 | tree complex_float_type_node; | |
138 | tree complex_double_type_node; | |
139 | tree complex_long_double_type_node; | |
140 | ||
ac4f24e7 RS |
141 | tree intQI_type_node; |
142 | tree intHI_type_node; | |
143 | tree intSI_type_node; | |
144 | tree intDI_type_node; | |
145 | ||
146 | tree unsigned_intQI_type_node; | |
147 | tree unsigned_intHI_type_node; | |
148 | tree unsigned_intSI_type_node; | |
149 | tree unsigned_intDI_type_node; | |
150 | ||
51e29401 RS |
151 | /* a VOID_TYPE node. */ |
152 | ||
153 | tree void_type_node; | |
154 | ||
155 | /* Nodes for types `void *' and `const void *'. */ | |
156 | ||
157 | tree ptr_type_node, const_ptr_type_node; | |
158 | ||
159 | /* Nodes for types `char *' and `const char *'. */ | |
160 | ||
161 | tree string_type_node, const_string_type_node; | |
162 | ||
fba9adc6 | 163 | /* Type `char[SOMENUMBER]'. |
51e29401 RS |
164 | Used when an array of char is needed and the size is irrelevant. */ |
165 | ||
166 | tree char_array_type_node; | |
167 | ||
fba9adc6 | 168 | /* Type `int[SOMENUMBER]' or something like it. |
51e29401 RS |
169 | Used when an array of int needed and the size is irrelevant. */ |
170 | ||
171 | tree int_array_type_node; | |
172 | ||
fba9adc6 | 173 | /* Type `wchar_t[SOMENUMBER]' or something like it. |
51e29401 RS |
174 | Used when a wide string literal is created. */ |
175 | ||
176 | tree wchar_array_type_node; | |
177 | ||
178 | /* type `int ()' -- used for implicit declaration of functions. */ | |
179 | ||
180 | tree default_function_type; | |
181 | ||
182 | /* function types `double (double)' and `double (double, double)', etc. */ | |
183 | ||
184 | tree double_ftype_double, double_ftype_double_double; | |
185 | tree int_ftype_int, long_ftype_long; | |
732149f9 RK |
186 | tree float_ftype_float; |
187 | tree ldouble_ftype_ldouble; | |
51e29401 RS |
188 | |
189 | /* Function type `void (void *, void *, int)' and similar ones */ | |
190 | ||
191 | tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int; | |
192 | ||
193 | /* Function type `char *(char *, char *)' and similar ones */ | |
194 | tree string_ftype_ptr_ptr, int_ftype_string_string; | |
195 | ||
51e29401 RS |
196 | /* Function type `int (const void *, const void *, size_t)' */ |
197 | tree int_ftype_cptr_cptr_sizet; | |
198 | ||
199 | /* Two expressions that are constants with value zero. | |
200 | The first is of type `int', the second of type `void *'. */ | |
201 | ||
202 | tree integer_zero_node; | |
203 | tree null_pointer_node; | |
204 | ||
205 | /* A node for the integer constant 1. */ | |
206 | ||
207 | tree integer_one_node; | |
208 | ||
209 | /* Nonzero if we have seen an invalid cross reference | |
210 | to a struct, union, or enum, but not yet printed the message. */ | |
211 | ||
212 | tree pending_invalid_xref; | |
213 | /* File and line to appear in the eventual error message. */ | |
214 | char *pending_invalid_xref_file; | |
215 | int pending_invalid_xref_line; | |
216 | ||
217 | /* While defining an enum type, this is 1 plus the last enumerator | |
18192b41 RK |
218 | constant value. Note that will do not have to save this or `enum_overflow' |
219 | around nested function definition since such a definition could only | |
220 | occur in an enum value expression and we don't use these variables in | |
221 | that case. */ | |
51e29401 RS |
222 | |
223 | static tree enum_next_value; | |
224 | ||
93e3ba4f RS |
225 | /* Nonzero means that there was overflow computing enum_next_value. */ |
226 | ||
227 | static int enum_overflow; | |
228 | ||
51e29401 RS |
229 | /* Parsing a function declarator leaves a list of parameter names |
230 | or a chain or parameter decls here. */ | |
231 | ||
232 | static tree last_function_parms; | |
233 | ||
234 | /* Parsing a function declarator leaves here a chain of structure | |
235 | and enum types declared in the parmlist. */ | |
236 | ||
237 | static tree last_function_parm_tags; | |
238 | ||
239 | /* After parsing the declarator that starts a function definition, | |
240 | `start_function' puts here the list of parameter names or chain of decls. | |
241 | `store_parm_decls' finds it here. */ | |
242 | ||
243 | static tree current_function_parms; | |
244 | ||
245 | /* Similar, for last_function_parm_tags. */ | |
246 | static tree current_function_parm_tags; | |
247 | ||
50a9145c JW |
248 | /* Similar, for the file and line that the prototype came from if this is |
249 | an old-style definition. */ | |
250 | static char *current_function_prototype_file; | |
251 | static int current_function_prototype_line; | |
252 | ||
51e29401 RS |
253 | /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function |
254 | that have names. Here so we can clear out their names' definitions | |
255 | at the end of the function. */ | |
256 | ||
c9c30903 | 257 | static tree named_labels; |
51e29401 RS |
258 | |
259 | /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ | |
260 | ||
261 | static tree shadowed_labels; | |
262 | ||
263 | /* Nonzero when store_parm_decls is called indicates a varargs function. | |
264 | Value not meaningful after store_parm_decls. */ | |
265 | ||
266 | static int c_function_varargs; | |
267 | ||
268 | /* The FUNCTION_DECL for the function currently being compiled, | |
269 | or 0 if between functions. */ | |
270 | tree current_function_decl; | |
271 | ||
272 | /* Set to 0 at beginning of a function definition, set to 1 if | |
273 | a return statement that specifies a return value is seen. */ | |
274 | ||
275 | int current_function_returns_value; | |
276 | ||
277 | /* Set to 0 at beginning of a function definition, set to 1 if | |
278 | a return statement with no argument is seen. */ | |
279 | ||
280 | int current_function_returns_null; | |
281 | ||
282 | /* Set to nonzero by `grokdeclarator' for a function | |
283 | whose return type is defaulted, if warnings for this are desired. */ | |
284 | ||
285 | static int warn_about_return_type; | |
286 | ||
929f3671 | 287 | /* Nonzero when starting a function declared `extern inline'. */ |
51e29401 RS |
288 | |
289 | static int current_extern_inline; | |
290 | \f | |
291 | /* For each binding contour we allocate a binding_level structure | |
292 | * which records the names defined in that contour. | |
293 | * Contours include: | |
294 | * 0) the global one | |
295 | * 1) one for each function definition, | |
296 | * where internal declarations of the parameters appear. | |
297 | * 2) one for each compound statement, | |
298 | * to record its declarations. | |
299 | * | |
300 | * The current meaning of a name can be found by searching the levels from | |
301 | * the current one out to the global one. | |
302 | */ | |
303 | ||
304 | /* Note that the information in the `names' component of the global contour | |
305 | is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ | |
306 | ||
307 | struct binding_level | |
308 | { | |
309 | /* A chain of _DECL nodes for all variables, constants, functions, | |
310 | and typedef types. These are in the reverse of the order supplied. | |
311 | */ | |
312 | tree names; | |
313 | ||
314 | /* A list of structure, union and enum definitions, | |
315 | * for looking up tag names. | |
316 | * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, | |
317 | * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, | |
318 | * or ENUMERAL_TYPE node. | |
319 | */ | |
320 | tree tags; | |
321 | ||
322 | /* For each level, a list of shadowed outer-level local definitions | |
323 | to be restored when this level is popped. | |
324 | Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and | |
325 | whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ | |
326 | tree shadowed; | |
327 | ||
328 | /* For each level (except not the global one), | |
329 | a chain of BLOCK nodes for all the levels | |
330 | that were entered and exited one level down. */ | |
331 | tree blocks; | |
332 | ||
3bf40d18 RS |
333 | /* The BLOCK node for this level, if one has been preallocated. |
334 | If 0, the BLOCK is allocated (if needed) when the level is popped. */ | |
335 | tree this_block; | |
336 | ||
51e29401 RS |
337 | /* The binding level which this one is contained in (inherits from). */ |
338 | struct binding_level *level_chain; | |
339 | ||
340 | /* Nonzero for the level that holds the parameters of a function. */ | |
51e29401 RS |
341 | char parm_flag; |
342 | ||
343 | /* Nonzero if this level "doesn't exist" for tags. */ | |
344 | char tag_transparent; | |
345 | ||
346 | /* Nonzero if sublevels of this level "don't exist" for tags. | |
347 | This is set in the parm level of a function definition | |
348 | while reading the function body, so that the outermost block | |
349 | of the function body will be tag-transparent. */ | |
350 | char subblocks_tag_transparent; | |
351 | ||
352 | /* Nonzero means make a BLOCK for this level regardless of all else. */ | |
353 | char keep; | |
354 | ||
355 | /* Nonzero means make a BLOCK if this level has any subblocks. */ | |
356 | char keep_if_subblocks; | |
357 | ||
358 | /* Number of decls in `names' that have incomplete | |
359 | structure or union types. */ | |
360 | int n_incomplete; | |
361 | ||
362 | /* A list of decls giving the (reversed) specified order of parms, | |
363 | not including any forward-decls in the parmlist. | |
364 | This is so we can put the parms in proper order for assign_parms. */ | |
365 | tree parm_order; | |
366 | }; | |
367 | ||
368 | #define NULL_BINDING_LEVEL (struct binding_level *) NULL | |
369 | ||
370 | /* The binding level currently in effect. */ | |
371 | ||
372 | static struct binding_level *current_binding_level; | |
373 | ||
374 | /* A chain of binding_level structures awaiting reuse. */ | |
375 | ||
376 | static struct binding_level *free_binding_level; | |
377 | ||
378 | /* The outermost binding level, for names of file scope. | |
379 | This is created when the compiler is started and exists | |
380 | through the entire run. */ | |
381 | ||
382 | static struct binding_level *global_binding_level; | |
383 | ||
384 | /* Binding level structures are initialized by copying this one. */ | |
385 | ||
386 | static struct binding_level clear_binding_level | |
014aa47e RK |
387 | = {NULL, NULL, NULL, NULL, NULL, NULL_BINDING_LEVEL, 0, 0, 0, 0, 0, 0, |
388 | NULL}; | |
51e29401 RS |
389 | |
390 | /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ | |
391 | ||
392 | static int keep_next_level_flag; | |
393 | ||
394 | /* Nonzero means make a BLOCK for the next level pushed | |
395 | if it has subblocks. */ | |
396 | ||
397 | static int keep_next_if_subblocks; | |
398 | ||
399 | /* The chain of outer levels of label scopes. | |
400 | This uses the same data structure used for binding levels, | |
401 | but it works differently: each link in the chain records | |
402 | saved values of named_labels and shadowed_labels for | |
403 | a label binding level outside the current one. */ | |
404 | ||
405 | static struct binding_level *label_level_chain; | |
406 | ||
2c5f4139 JM |
407 | /* Functions called automatically at the beginning and end of execution. */ |
408 | ||
409 | tree static_ctors, static_dtors; | |
410 | ||
51e29401 RS |
411 | /* Forward declarations. */ |
412 | ||
413 | static tree grokparms (), grokdeclarator (); | |
414 | tree pushdecl (); | |
929f3671 | 415 | tree builtin_function (); |
9282f2f9 | 416 | void shadow_tag_warned (); |
51e29401 RS |
417 | |
418 | static tree lookup_tag (); | |
419 | static tree lookup_tag_reverse (); | |
f062da04 | 420 | tree lookup_name_current_level (); |
51e29401 RS |
421 | static char *redeclaration_error_message (); |
422 | static void layout_array_type (); | |
423 | \f | |
424 | /* C-specific option variables. */ | |
425 | ||
426 | /* Nonzero means allow type mismatches in conditional expressions; | |
427 | just make their values `void'. */ | |
428 | ||
429 | int flag_cond_mismatch; | |
430 | ||
431 | /* Nonzero means give `double' the same size as `float'. */ | |
432 | ||
433 | int flag_short_double; | |
434 | ||
435 | /* Nonzero means don't recognize the keyword `asm'. */ | |
436 | ||
437 | int flag_no_asm; | |
438 | ||
fc3ffe83 | 439 | /* Nonzero means don't recognize any builtin functions. */ |
51e29401 RS |
440 | |
441 | int flag_no_builtin; | |
442 | ||
fc3ffe83 RK |
443 | /* Nonzero means don't recognize the non-ANSI builtin functions. |
444 | -ansi sets this. */ | |
445 | ||
446 | int flag_no_nonansi_builtin; | |
447 | ||
51e29401 RS |
448 | /* Nonzero means do some things the same way PCC does. */ |
449 | ||
450 | int flag_traditional; | |
451 | ||
55b4742b RS |
452 | /* Nonzero means to allow single precision math even if we're generally |
453 | being traditional. */ | |
454 | int flag_allow_single_precision = 0; | |
455 | ||
51e29401 RS |
456 | /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */ |
457 | ||
458 | int flag_signed_bitfields = 1; | |
7a0347ff | 459 | int explicit_flag_signed_bitfields = 0; |
51e29401 RS |
460 | |
461 | /* Nonzero means handle `#ident' directives. 0 means ignore them. */ | |
462 | ||
463 | int flag_no_ident = 0; | |
464 | ||
465 | /* Nonzero means warn about implicit declarations. */ | |
466 | ||
467 | int warn_implicit; | |
468 | ||
469 | /* Nonzero means give string constants the type `const char *' | |
470 | to get extra warnings from them. These warnings will be too numerous | |
471 | to be useful, except in thoroughly ANSIfied programs. */ | |
472 | ||
473 | int warn_write_strings; | |
474 | ||
475 | /* Nonzero means warn about pointer casts that can drop a type qualifier | |
476 | from the pointer target type. */ | |
477 | ||
478 | int warn_cast_qual; | |
479 | ||
5c8902bb RK |
480 | /* Nonzero means warn when casting a function call to a type that does |
481 | not match the return type (e.g. (float)sqrt() or (anything*)malloc() | |
482 | when there is no previous declaration of sqrt or malloc. */ | |
483 | ||
484 | int warn_bad_function_cast; | |
485 | ||
51e29401 RS |
486 | /* Warn about traditional constructs whose meanings changed in ANSI C. */ |
487 | ||
488 | int warn_traditional; | |
489 | ||
490 | /* Nonzero means warn about sizeof(function) or addition/subtraction | |
491 | of function pointers. */ | |
492 | ||
493 | int warn_pointer_arith; | |
494 | ||
495 | /* Nonzero means warn for non-prototype function decls | |
496 | or non-prototyped defs without previous prototype. */ | |
497 | ||
498 | int warn_strict_prototypes; | |
499 | ||
500 | /* Nonzero means warn for any global function def | |
501 | without separate previous prototype decl. */ | |
502 | ||
503 | int warn_missing_prototypes; | |
504 | ||
1474fe46 RK |
505 | /* Nonzero means warn for any global function def |
506 | without separate previous decl. */ | |
507 | ||
508 | int warn_missing_declarations; | |
509 | ||
51e29401 RS |
510 | /* Nonzero means warn about multiple (redundant) decls for the same single |
511 | variable or function. */ | |
512 | ||
513 | int warn_redundant_decls = 0; | |
514 | ||
515 | /* Nonzero means warn about extern declarations of objects not at | |
516 | file-scope level and about *all* declarations of functions (whether | |
517 | extern or static) not at file-scope level. Note that we exclude | |
518 | implicit function declarations. To get warnings about those, use | |
519 | -Wimplicit. */ | |
520 | ||
521 | int warn_nested_externs = 0; | |
522 | ||
523 | /* Warn about *printf or *scanf format/argument anomalies. */ | |
524 | ||
525 | int warn_format; | |
526 | ||
527 | /* Warn about a subscript that has type char. */ | |
528 | ||
529 | int warn_char_subscripts = 0; | |
530 | ||
531 | /* Warn if a type conversion is done that might have confusing results. */ | |
532 | ||
533 | int warn_conversion; | |
534 | ||
535 | /* Warn if adding () is suggested. */ | |
536 | ||
929f3671 | 537 | int warn_parentheses; |
51e29401 | 538 | |
36e6fa69 RS |
539 | /* Warn if initializer is not completely bracketed. */ |
540 | ||
541 | int warn_missing_braces; | |
542 | ||
51e29401 RS |
543 | /* Nonzero means `$' can be in an identifier. |
544 | See cccp.c for reasons why this breaks some obscure ANSI C programs. */ | |
545 | ||
546 | #ifndef DOLLARS_IN_IDENTIFIERS | |
547 | #define DOLLARS_IN_IDENTIFIERS 1 | |
548 | #endif | |
549 | int dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1; | |
550 | ||
51e29401 RS |
551 | /* Decode the string P as a language-specific option for C. |
552 | Return 1 if it is recognized (and handle it); | |
553 | return 0 if not recognized. */ | |
554 | ||
555 | int | |
556 | c_decode_option (p) | |
557 | char *p; | |
558 | { | |
559 | if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) | |
560 | { | |
561 | flag_traditional = 1; | |
562 | flag_writable_strings = 1; | |
563 | #if DOLLARS_IN_IDENTIFIERS > 0 | |
564 | dollars_in_ident = 1; | |
565 | #endif | |
566 | } | |
55b4742b RS |
567 | else if (!strcmp (p, "-fallow-single-precision")) |
568 | flag_allow_single_precision = 1; | |
4ecc65ac RS |
569 | else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional")) |
570 | { | |
571 | flag_traditional = 0; | |
572 | flag_writable_strings = 0; | |
573 | dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1; | |
574 | } | |
a419ff54 RS |
575 | else if (!strcmp (p, "-fdollars-in-identifiers")) |
576 | { | |
577 | #if DOLLARS_IN_IDENTIFIERS > 0 | |
578 | dollars_in_ident = 1; | |
579 | #endif | |
580 | } | |
014aa47e | 581 | else if (!strcmp (p, "-fno-dollars-in-identifiers")) |
a419ff54 | 582 | dollars_in_ident = 0; |
51e29401 RS |
583 | else if (!strcmp (p, "-fsigned-char")) |
584 | flag_signed_char = 1; | |
585 | else if (!strcmp (p, "-funsigned-char")) | |
586 | flag_signed_char = 0; | |
587 | else if (!strcmp (p, "-fno-signed-char")) | |
588 | flag_signed_char = 0; | |
589 | else if (!strcmp (p, "-fno-unsigned-char")) | |
590 | flag_signed_char = 1; | |
7a0347ff RS |
591 | else if (!strcmp (p, "-fsigned-bitfields") |
592 | || !strcmp (p, "-fno-unsigned-bitfields")) | |
593 | { | |
594 | flag_signed_bitfields = 1; | |
595 | explicit_flag_signed_bitfields = 1; | |
596 | } | |
597 | else if (!strcmp (p, "-funsigned-bitfields") | |
598 | || !strcmp (p, "-fno-signed-bitfields")) | |
599 | { | |
600 | flag_signed_bitfields = 0; | |
601 | explicit_flag_signed_bitfields = 1; | |
602 | } | |
51e29401 RS |
603 | else if (!strcmp (p, "-fshort-enums")) |
604 | flag_short_enums = 1; | |
605 | else if (!strcmp (p, "-fno-short-enums")) | |
606 | flag_short_enums = 0; | |
607 | else if (!strcmp (p, "-fcond-mismatch")) | |
608 | flag_cond_mismatch = 1; | |
609 | else if (!strcmp (p, "-fno-cond-mismatch")) | |
610 | flag_cond_mismatch = 0; | |
611 | else if (!strcmp (p, "-fshort-double")) | |
612 | flag_short_double = 1; | |
613 | else if (!strcmp (p, "-fno-short-double")) | |
614 | flag_short_double = 0; | |
615 | else if (!strcmp (p, "-fasm")) | |
616 | flag_no_asm = 0; | |
617 | else if (!strcmp (p, "-fno-asm")) | |
618 | flag_no_asm = 1; | |
619 | else if (!strcmp (p, "-fbuiltin")) | |
620 | flag_no_builtin = 0; | |
621 | else if (!strcmp (p, "-fno-builtin")) | |
622 | flag_no_builtin = 1; | |
623 | else if (!strcmp (p, "-fno-ident")) | |
624 | flag_no_ident = 1; | |
625 | else if (!strcmp (p, "-fident")) | |
626 | flag_no_ident = 0; | |
627 | else if (!strcmp (p, "-ansi")) | |
fc3ffe83 | 628 | flag_no_asm = 1, flag_no_nonansi_builtin = 1, dollars_in_ident = 0; |
51e29401 RS |
629 | else if (!strcmp (p, "-Wimplicit")) |
630 | warn_implicit = 1; | |
631 | else if (!strcmp (p, "-Wno-implicit")) | |
632 | warn_implicit = 0; | |
633 | else if (!strcmp (p, "-Wwrite-strings")) | |
634 | warn_write_strings = 1; | |
635 | else if (!strcmp (p, "-Wno-write-strings")) | |
636 | warn_write_strings = 0; | |
637 | else if (!strcmp (p, "-Wcast-qual")) | |
638 | warn_cast_qual = 1; | |
639 | else if (!strcmp (p, "-Wno-cast-qual")) | |
640 | warn_cast_qual = 0; | |
5c8902bb RK |
641 | else if (!strcmp (p, "-Wbad-function-cast")) |
642 | warn_bad_function_cast = 1; | |
643 | else if (!strcmp (p, "-Wno-bad-function-cast")) | |
644 | warn_bad_function_cast = 0; | |
51e29401 RS |
645 | else if (!strcmp (p, "-Wpointer-arith")) |
646 | warn_pointer_arith = 1; | |
647 | else if (!strcmp (p, "-Wno-pointer-arith")) | |
648 | warn_pointer_arith = 0; | |
649 | else if (!strcmp (p, "-Wstrict-prototypes")) | |
650 | warn_strict_prototypes = 1; | |
651 | else if (!strcmp (p, "-Wno-strict-prototypes")) | |
652 | warn_strict_prototypes = 0; | |
653 | else if (!strcmp (p, "-Wmissing-prototypes")) | |
654 | warn_missing_prototypes = 1; | |
655 | else if (!strcmp (p, "-Wno-missing-prototypes")) | |
656 | warn_missing_prototypes = 0; | |
1474fe46 RK |
657 | else if (!strcmp (p, "-Wmissing-declarations")) |
658 | warn_missing_declarations = 1; | |
659 | else if (!strcmp (p, "-Wno-missing-declarations")) | |
660 | warn_missing_declarations = 0; | |
51e29401 RS |
661 | else if (!strcmp (p, "-Wredundant-decls")) |
662 | warn_redundant_decls = 1; | |
ec2343c4 | 663 | else if (!strcmp (p, "-Wno-redundant-decls")) |
51e29401 RS |
664 | warn_redundant_decls = 0; |
665 | else if (!strcmp (p, "-Wnested-externs")) | |
666 | warn_nested_externs = 1; | |
667 | else if (!strcmp (p, "-Wno-nested-externs")) | |
668 | warn_nested_externs = 0; | |
669 | else if (!strcmp (p, "-Wtraditional")) | |
670 | warn_traditional = 1; | |
671 | else if (!strcmp (p, "-Wno-traditional")) | |
672 | warn_traditional = 0; | |
673 | else if (!strcmp (p, "-Wformat")) | |
674 | warn_format = 1; | |
675 | else if (!strcmp (p, "-Wno-format")) | |
676 | warn_format = 0; | |
677 | else if (!strcmp (p, "-Wchar-subscripts")) | |
678 | warn_char_subscripts = 1; | |
679 | else if (!strcmp (p, "-Wno-char-subscripts")) | |
680 | warn_char_subscripts = 0; | |
681 | else if (!strcmp (p, "-Wconversion")) | |
682 | warn_conversion = 1; | |
683 | else if (!strcmp (p, "-Wno-conversion")) | |
684 | warn_conversion = 0; | |
685 | else if (!strcmp (p, "-Wparentheses")) | |
686 | warn_parentheses = 1; | |
687 | else if (!strcmp (p, "-Wno-parentheses")) | |
688 | warn_parentheses = 0; | |
57916f61 RS |
689 | else if (!strcmp (p, "-Wreturn-type")) |
690 | warn_return_type = 1; | |
691 | else if (!strcmp (p, "-Wno-return-type")) | |
692 | warn_return_type = 0; | |
51e29401 RS |
693 | else if (!strcmp (p, "-Wcomment")) |
694 | ; /* cpp handles this one. */ | |
695 | else if (!strcmp (p, "-Wno-comment")) | |
696 | ; /* cpp handles this one. */ | |
697 | else if (!strcmp (p, "-Wcomments")) | |
698 | ; /* cpp handles this one. */ | |
699 | else if (!strcmp (p, "-Wno-comments")) | |
700 | ; /* cpp handles this one. */ | |
701 | else if (!strcmp (p, "-Wtrigraphs")) | |
702 | ; /* cpp handles this one. */ | |
703 | else if (!strcmp (p, "-Wno-trigraphs")) | |
704 | ; /* cpp handles this one. */ | |
fc3ffe83 RK |
705 | else if (!strcmp (p, "-Wimport")) |
706 | ; /* cpp handles this one. */ | |
707 | else if (!strcmp (p, "-Wno-import")) | |
708 | ; /* cpp handles this one. */ | |
36e6fa69 RS |
709 | else if (!strcmp (p, "-Wmissing-braces")) |
710 | warn_missing_braces = 1; | |
711 | else if (!strcmp (p, "-Wno-missing-braces")) | |
712 | warn_missing_braces = 0; | |
51e29401 RS |
713 | else if (!strcmp (p, "-Wall")) |
714 | { | |
715 | extra_warnings = 1; | |
a2468e45 BK |
716 | /* We save the value of warn_uninitialized, since if they put |
717 | -Wuninitialized on the command line, we need to generate a | |
718 | warning about not using it without also specifying -O. */ | |
719 | if (warn_uninitialized != 1) | |
720 | warn_uninitialized = 2; | |
51e29401 RS |
721 | warn_implicit = 1; |
722 | warn_return_type = 1; | |
723 | warn_unused = 1; | |
724 | warn_switch = 1; | |
725 | warn_format = 1; | |
726 | warn_char_subscripts = 1; | |
929f3671 | 727 | warn_parentheses = 1; |
36e6fa69 | 728 | warn_missing_braces = 1; |
51e29401 RS |
729 | } |
730 | else | |
731 | return 0; | |
732 | ||
733 | return 1; | |
734 | } | |
735 | ||
736 | /* Hooks for print_node. */ | |
737 | ||
738 | void | |
27d433a2 BC |
739 | print_lang_decl (file, node, indent) |
740 | FILE *file; | |
741 | tree node; | |
742 | int indent; | |
51e29401 RS |
743 | { |
744 | } | |
745 | ||
746 | void | |
27d433a2 BC |
747 | print_lang_type (file, node, indent) |
748 | FILE *file; | |
749 | tree node; | |
750 | int indent; | |
51e29401 RS |
751 | { |
752 | } | |
753 | ||
754 | void | |
755 | print_lang_identifier (file, node, indent) | |
756 | FILE *file; | |
757 | tree node; | |
758 | int indent; | |
759 | { | |
760 | print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4); | |
761 | print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4); | |
762 | print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4); | |
763 | print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4); | |
764 | print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4); | |
fd0b8fce | 765 | print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4); |
51e29401 RS |
766 | } |
767 | \f | |
b4892310 RS |
768 | /* Hook called at end of compilation to assume 1 elt |
769 | for a top-level array decl that wasn't complete before. */ | |
770 | ||
771 | void | |
772 | finish_incomplete_decl (decl) | |
773 | tree decl; | |
774 | { | |
775 | if (TREE_CODE (decl) == VAR_DECL && TREE_TYPE (decl) != error_mark_node) | |
776 | { | |
777 | tree type = TREE_TYPE (decl); | |
778 | if (TREE_CODE (type) == ARRAY_TYPE | |
779 | && TYPE_DOMAIN (type) == 0 | |
780 | && TREE_CODE (decl) != TYPE_DECL) | |
781 | { | |
782 | complete_array_type (type, NULL_TREE, 1); | |
783 | ||
784 | layout_decl (decl, 0); | |
785 | } | |
786 | } | |
787 | } | |
788 | \f | |
51e29401 RS |
789 | /* Create a new `struct binding_level'. */ |
790 | ||
791 | static | |
792 | struct binding_level * | |
793 | make_binding_level () | |
794 | { | |
795 | /* NOSTRICT */ | |
796 | return (struct binding_level *) xmalloc (sizeof (struct binding_level)); | |
797 | } | |
798 | ||
799 | /* Nonzero if we are currently in the global binding level. */ | |
800 | ||
801 | int | |
802 | global_bindings_p () | |
803 | { | |
804 | return current_binding_level == global_binding_level; | |
805 | } | |
806 | ||
807 | void | |
808 | keep_next_level () | |
809 | { | |
810 | keep_next_level_flag = 1; | |
811 | } | |
812 | ||
813 | /* Nonzero if the current level needs to have a BLOCK made. */ | |
814 | ||
815 | int | |
816 | kept_level_p () | |
817 | { | |
818 | return ((current_binding_level->keep_if_subblocks | |
819 | && current_binding_level->blocks != 0) | |
820 | || current_binding_level->keep | |
821 | || current_binding_level->names != 0 | |
822 | || (current_binding_level->tags != 0 | |
823 | && !current_binding_level->tag_transparent)); | |
824 | } | |
825 | ||
826 | /* Identify this binding level as a level of parameters. | |
89d7540d RS |
827 | DEFINITION_FLAG is 1 for a definition, 0 for a declaration. |
828 | But it turns out there is no way to pass the right value for | |
829 | DEFINITION_FLAG, so we ignore it. */ | |
51e29401 RS |
830 | |
831 | void | |
832 | declare_parm_level (definition_flag) | |
833 | int definition_flag; | |
834 | { | |
89d7540d | 835 | current_binding_level->parm_flag = 1; |
51e29401 RS |
836 | } |
837 | ||
838 | /* Nonzero if currently making parm declarations. */ | |
839 | ||
840 | int | |
841 | in_parm_level_p () | |
842 | { | |
843 | return current_binding_level->parm_flag; | |
844 | } | |
845 | ||
846 | /* Enter a new binding level. | |
847 | If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, | |
848 | not for that of tags. */ | |
849 | ||
850 | void | |
851 | pushlevel (tag_transparent) | |
852 | int tag_transparent; | |
853 | { | |
854 | register struct binding_level *newlevel = NULL_BINDING_LEVEL; | |
855 | ||
856 | /* If this is the top level of a function, | |
857 | just make sure that NAMED_LABELS is 0. */ | |
858 | ||
859 | if (current_binding_level == global_binding_level) | |
860 | { | |
861 | named_labels = 0; | |
862 | } | |
863 | ||
864 | /* Reuse or create a struct for this binding level. */ | |
865 | ||
866 | if (free_binding_level) | |
867 | { | |
868 | newlevel = free_binding_level; | |
869 | free_binding_level = free_binding_level->level_chain; | |
870 | } | |
871 | else | |
872 | { | |
873 | newlevel = make_binding_level (); | |
874 | } | |
875 | ||
876 | /* Add this level to the front of the chain (stack) of levels that | |
877 | are active. */ | |
878 | ||
879 | *newlevel = clear_binding_level; | |
880 | newlevel->tag_transparent | |
881 | = (tag_transparent | |
882 | || (current_binding_level | |
883 | ? current_binding_level->subblocks_tag_transparent | |
884 | : 0)); | |
885 | newlevel->level_chain = current_binding_level; | |
886 | current_binding_level = newlevel; | |
887 | newlevel->keep = keep_next_level_flag; | |
888 | keep_next_level_flag = 0; | |
889 | newlevel->keep_if_subblocks = keep_next_if_subblocks; | |
890 | keep_next_if_subblocks = 0; | |
891 | } | |
892 | ||
893 | /* Exit a binding level. | |
894 | Pop the level off, and restore the state of the identifier-decl mappings | |
895 | that were in effect when this level was entered. | |
896 | ||
897 | If KEEP is nonzero, this level had explicit declarations, so | |
898 | and create a "block" (a BLOCK node) for the level | |
899 | to record its declarations and subblocks for symbol table output. | |
900 | ||
901 | If FUNCTIONBODY is nonzero, this level is the body of a function, | |
902 | so create a block as if KEEP were set and also clear out all | |
903 | label names. | |
904 | ||
905 | If REVERSE is nonzero, reverse the order of decls before putting | |
906 | them into the BLOCK. */ | |
907 | ||
908 | tree | |
909 | poplevel (keep, reverse, functionbody) | |
910 | int keep; | |
911 | int reverse; | |
912 | int functionbody; | |
913 | { | |
914 | register tree link; | |
915 | /* The chain of decls was accumulated in reverse order. | |
916 | Put it into forward order, just for cleanliness. */ | |
917 | tree decls; | |
918 | tree tags = current_binding_level->tags; | |
919 | tree subblocks = current_binding_level->blocks; | |
920 | tree block = 0; | |
921 | tree decl; | |
968e5643 | 922 | int block_previously_created; |
51e29401 RS |
923 | |
924 | keep |= current_binding_level->keep; | |
925 | ||
926 | /* This warning is turned off because it causes warnings for | |
927 | declarations like `extern struct foo *x'. */ | |
928 | #if 0 | |
929 | /* Warn about incomplete structure types in this level. */ | |
930 | for (link = tags; link; link = TREE_CHAIN (link)) | |
931 | if (TYPE_SIZE (TREE_VALUE (link)) == 0) | |
932 | { | |
933 | tree type = TREE_VALUE (link); | |
934 | char *errmsg; | |
935 | switch (TREE_CODE (type)) | |
936 | { | |
937 | case RECORD_TYPE: | |
938 | errmsg = "`struct %s' incomplete in scope ending here"; | |
939 | break; | |
940 | case UNION_TYPE: | |
941 | errmsg = "`union %s' incomplete in scope ending here"; | |
942 | break; | |
943 | case ENUMERAL_TYPE: | |
944 | errmsg = "`enum %s' incomplete in scope ending here"; | |
945 | break; | |
946 | } | |
947 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
948 | error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type))); | |
949 | else | |
950 | /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ | |
951 | error (errmsg, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)))); | |
952 | } | |
953 | #endif /* 0 */ | |
954 | ||
955 | /* Get the decls in the order they were written. | |
956 | Usually current_binding_level->names is in reverse order. | |
957 | But parameter decls were previously put in forward order. */ | |
958 | ||
959 | if (reverse) | |
960 | current_binding_level->names | |
961 | = decls = nreverse (current_binding_level->names); | |
962 | else | |
963 | decls = current_binding_level->names; | |
964 | ||
965 | /* Output any nested inline functions within this block | |
966 | if they weren't already output. */ | |
967 | ||
968 | for (decl = decls; decl; decl = TREE_CHAIN (decl)) | |
969 | if (TREE_CODE (decl) == FUNCTION_DECL | |
970 | && ! TREE_ASM_WRITTEN (decl) | |
971 | && DECL_INITIAL (decl) != 0 | |
972 | && TREE_ADDRESSABLE (decl)) | |
42dfa47f RS |
973 | { |
974 | /* If this decl was copied from a file-scope decl | |
975 | on account of a block-scope extern decl, | |
976 | propagate TREE_ADDRESSABLE to the file-scope decl. */ | |
977 | if (DECL_ABSTRACT_ORIGIN (decl) != 0) | |
978 | TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; | |
979 | else | |
47df0262 RK |
980 | { |
981 | push_function_context (); | |
982 | output_inline_function (decl); | |
983 | pop_function_context (); | |
984 | } | |
42dfa47f | 985 | } |
51e29401 RS |
986 | |
987 | /* If there were any declarations or structure tags in that level, | |
988 | or if this level is a function body, | |
989 | create a BLOCK to record them for the life of this function. */ | |
990 | ||
3bf40d18 | 991 | block = 0; |
968e5643 RS |
992 | block_previously_created = (current_binding_level->this_block != 0); |
993 | if (block_previously_created) | |
3bf40d18 RS |
994 | block = current_binding_level->this_block; |
995 | else if (keep || functionbody | |
996 | || (current_binding_level->keep_if_subblocks && subblocks != 0)) | |
997 | block = make_node (BLOCK); | |
998 | if (block != 0) | |
999 | { | |
1000 | BLOCK_VARS (block) = decls; | |
1001 | BLOCK_TYPE_TAGS (block) = tags; | |
1002 | BLOCK_SUBBLOCKS (block) = subblocks; | |
4ecc65ac | 1003 | remember_end_note (block); |
3bf40d18 | 1004 | } |
51e29401 RS |
1005 | |
1006 | /* In each subblock, record that this is its superior. */ | |
1007 | ||
1008 | for (link = subblocks; link; link = TREE_CHAIN (link)) | |
1009 | BLOCK_SUPERCONTEXT (link) = block; | |
1010 | ||
1011 | /* Clear out the meanings of the local variables of this level. */ | |
1012 | ||
1013 | for (link = decls; link; link = TREE_CHAIN (link)) | |
1014 | { | |
1015 | if (DECL_NAME (link) != 0) | |
1016 | { | |
1017 | /* If the ident. was used or addressed via a local extern decl, | |
1018 | don't forget that fact. */ | |
1394aabd | 1019 | if (DECL_EXTERNAL (link)) |
51e29401 RS |
1020 | { |
1021 | if (TREE_USED (link)) | |
1022 | TREE_USED (DECL_NAME (link)) = 1; | |
1023 | if (TREE_ADDRESSABLE (link)) | |
1024 | TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; | |
1025 | } | |
1026 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | /* Restore all name-meanings of the outer levels | |
1031 | that were shadowed by this level. */ | |
1032 | ||
1033 | for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) | |
1034 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
1035 | ||
1036 | /* If the level being exited is the top level of a function, | |
1037 | check over all the labels, and clear out the current | |
1038 | (function local) meanings of their names. */ | |
1039 | ||
1040 | if (functionbody) | |
1041 | { | |
1042 | /* If this is the top level block of a function, | |
1043 | the vars are the function's parameters. | |
1044 | Don't leave them in the BLOCK because they are | |
1045 | found in the FUNCTION_DECL instead. */ | |
1046 | ||
1047 | BLOCK_VARS (block) = 0; | |
1048 | ||
1049 | /* Clear out the definitions of all label names, | |
1050 | since their scopes end here, | |
1051 | and add them to BLOCK_VARS. */ | |
1052 | ||
1053 | for (link = named_labels; link; link = TREE_CHAIN (link)) | |
1054 | { | |
1055 | register tree label = TREE_VALUE (link); | |
1056 | ||
1057 | if (DECL_INITIAL (label) == 0) | |
1058 | { | |
1059 | error_with_decl (label, "label `%s' used but not defined"); | |
1060 | /* Avoid crashing later. */ | |
1061 | define_label (input_filename, lineno, | |
1062 | DECL_NAME (label)); | |
1063 | } | |
1064 | else if (warn_unused && !TREE_USED (label)) | |
1065 | warning_with_decl (label, "label `%s' defined but not used"); | |
1066 | IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0; | |
1067 | ||
1068 | /* Put the labels into the "variables" of the | |
1069 | top-level block, so debugger can see them. */ | |
1070 | TREE_CHAIN (label) = BLOCK_VARS (block); | |
1071 | BLOCK_VARS (block) = label; | |
1072 | } | |
1073 | } | |
1074 | ||
1075 | /* Pop the current level, and free the structure for reuse. */ | |
1076 | ||
1077 | { | |
1078 | register struct binding_level *level = current_binding_level; | |
1079 | current_binding_level = current_binding_level->level_chain; | |
1080 | ||
1081 | level->level_chain = free_binding_level; | |
1082 | free_binding_level = level; | |
1083 | } | |
1084 | ||
1085 | /* Dispose of the block that we just made inside some higher level. */ | |
1086 | if (functionbody) | |
1087 | DECL_INITIAL (current_function_decl) = block; | |
1088 | else if (block) | |
968e5643 RS |
1089 | { |
1090 | if (!block_previously_created) | |
1091 | current_binding_level->blocks | |
1092 | = chainon (current_binding_level->blocks, block); | |
1093 | } | |
51e29401 RS |
1094 | /* If we did not make a block for the level just exited, |
1095 | any blocks made for inner levels | |
1096 | (since they cannot be recorded as subblocks in that level) | |
1097 | must be carried forward so they will later become subblocks | |
1098 | of something else. */ | |
1099 | else if (subblocks) | |
1100 | current_binding_level->blocks | |
1101 | = chainon (current_binding_level->blocks, subblocks); | |
1102 | ||
1103 | /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this | |
1104 | binding contour so that they point to the appropriate construct, i.e. | |
1105 | either to the current FUNCTION_DECL node, or else to the BLOCK node | |
1106 | we just constructed. | |
1107 | ||
1108 | Note that for tagged types whose scope is just the formal parameter | |
1109 | list for some function type specification, we can't properly set | |
1110 | their TYPE_CONTEXTs here, because we don't have a pointer to the | |
1111 | appropriate FUNCTION_TYPE node readily available to us. For those | |
1112 | cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set | |
1113 | in `grokdeclarator' as soon as we have created the FUNCTION_TYPE | |
1114 | node which will represent the "scope" for these "parameter list local" | |
1115 | tagged types. | |
1116 | */ | |
1117 | ||
1118 | if (functionbody) | |
1119 | for (link = tags; link; link = TREE_CHAIN (link)) | |
1120 | TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl; | |
1121 | else if (block) | |
1122 | for (link = tags; link; link = TREE_CHAIN (link)) | |
1123 | TYPE_CONTEXT (TREE_VALUE (link)) = block; | |
1124 | ||
1125 | if (block) | |
1126 | TREE_USED (block) = 1; | |
1127 | return block; | |
1128 | } | |
3bf40d18 RS |
1129 | |
1130 | /* Delete the node BLOCK from the current binding level. | |
1131 | This is used for the block inside a stmt expr ({...}) | |
1132 | so that the block can be reinserted where appropriate. */ | |
1133 | ||
1134 | void | |
1135 | delete_block (block) | |
1136 | tree block; | |
1137 | { | |
1138 | tree t; | |
1139 | if (current_binding_level->blocks == block) | |
1140 | current_binding_level->blocks = TREE_CHAIN (block); | |
1141 | for (t = current_binding_level->blocks; t;) | |
1142 | { | |
1143 | if (TREE_CHAIN (t) == block) | |
1144 | TREE_CHAIN (t) = TREE_CHAIN (block); | |
1145 | else | |
1146 | t = TREE_CHAIN (t); | |
1147 | } | |
1148 | TREE_CHAIN (block) = NULL; | |
1149 | /* Clear TREE_USED which is always set by poplevel. | |
1150 | The flag is set again if insert_block is called. */ | |
1151 | TREE_USED (block) = 0; | |
1152 | } | |
1153 | ||
1154 | /* Insert BLOCK at the end of the list of subblocks of the | |
1155 | current binding level. This is used when a BIND_EXPR is expanded, | |
6f65afb0 | 1156 | to handle the BLOCK node inside the BIND_EXPR. */ |
3bf40d18 RS |
1157 | |
1158 | void | |
1159 | insert_block (block) | |
1160 | tree block; | |
1161 | { | |
1162 | TREE_USED (block) = 1; | |
1163 | current_binding_level->blocks | |
1164 | = chainon (current_binding_level->blocks, block); | |
1165 | } | |
1166 | ||
968e5643 | 1167 | /* Set the BLOCK node for the innermost scope |
3bf40d18 RS |
1168 | (the one we are currently in). */ |
1169 | ||
968e5643 RS |
1170 | void |
1171 | set_block (block) | |
1172 | register tree block; | |
3bf40d18 | 1173 | { |
968e5643 | 1174 | current_binding_level->this_block = block; |
3bf40d18 | 1175 | } |
51e29401 RS |
1176 | \f |
1177 | void | |
1178 | push_label_level () | |
1179 | { | |
1180 | register struct binding_level *newlevel; | |
1181 | ||
1182 | /* Reuse or create a struct for this binding level. */ | |
1183 | ||
1184 | if (free_binding_level) | |
1185 | { | |
1186 | newlevel = free_binding_level; | |
1187 | free_binding_level = free_binding_level->level_chain; | |
1188 | } | |
1189 | else | |
1190 | { | |
1191 | newlevel = make_binding_level (); | |
1192 | } | |
1193 | ||
1194 | /* Add this level to the front of the chain (stack) of label levels. */ | |
1195 | ||
1196 | newlevel->level_chain = label_level_chain; | |
1197 | label_level_chain = newlevel; | |
1198 | ||
1199 | newlevel->names = named_labels; | |
1200 | newlevel->shadowed = shadowed_labels; | |
1201 | named_labels = 0; | |
1202 | shadowed_labels = 0; | |
1203 | } | |
1204 | ||
1205 | void | |
1206 | pop_label_level () | |
1207 | { | |
1208 | register struct binding_level *level = label_level_chain; | |
1209 | tree link, prev; | |
1210 | ||
1211 | /* Clear out the definitions of the declared labels in this level. | |
1212 | Leave in the list any ordinary, non-declared labels. */ | |
1213 | for (link = named_labels, prev = 0; link;) | |
1214 | { | |
1215 | if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link))) | |
1216 | { | |
1217 | if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0) | |
1218 | { | |
6b2a374b RK |
1219 | error_with_decl (TREE_VALUE (link), |
1220 | "label `%s' used but not defined"); | |
51e29401 RS |
1221 | /* Avoid crashing later. */ |
1222 | define_label (input_filename, lineno, | |
1223 | DECL_NAME (TREE_VALUE (link))); | |
1224 | } | |
1225 | else if (warn_unused && !TREE_USED (TREE_VALUE (link))) | |
1226 | warning_with_decl (TREE_VALUE (link), | |
1227 | "label `%s' defined but not used"); | |
1228 | IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0; | |
1229 | ||
1230 | /* Delete this element from the list. */ | |
1231 | link = TREE_CHAIN (link); | |
1232 | if (prev) | |
1233 | TREE_CHAIN (prev) = link; | |
1234 | else | |
1235 | named_labels = link; | |
1236 | } | |
1237 | else | |
1238 | { | |
1239 | prev = link; | |
1240 | link = TREE_CHAIN (link); | |
1241 | } | |
1242 | } | |
1243 | ||
1244 | /* Bring back all the labels that were shadowed. */ | |
1245 | for (link = shadowed_labels; link; link = TREE_CHAIN (link)) | |
1246 | if (DECL_NAME (TREE_VALUE (link)) != 0) | |
1247 | IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) | |
1248 | = TREE_VALUE (link); | |
1249 | ||
1250 | named_labels = chainon (named_labels, level->names); | |
1251 | shadowed_labels = level->shadowed; | |
1252 | ||
1253 | /* Pop the current level, and free the structure for reuse. */ | |
1254 | label_level_chain = label_level_chain->level_chain; | |
1255 | level->level_chain = free_binding_level; | |
1256 | free_binding_level = level; | |
1257 | } | |
1258 | \f | |
1259 | /* Push a definition or a declaration of struct, union or enum tag "name". | |
1260 | "type" should be the type node. | |
1261 | We assume that the tag "name" is not already defined. | |
1262 | ||
1263 | Note that the definition may really be just a forward reference. | |
1264 | In that case, the TYPE_SIZE will be zero. */ | |
1265 | ||
1266 | void | |
1267 | pushtag (name, type) | |
1268 | tree name, type; | |
1269 | { | |
1270 | register struct binding_level *b; | |
1271 | ||
1272 | /* Find the proper binding level for this type tag. */ | |
1273 | ||
1274 | for (b = current_binding_level; b->tag_transparent; b = b->level_chain) | |
1275 | continue; | |
1276 | ||
1277 | if (name) | |
1278 | { | |
1279 | /* Record the identifier as the type's name if it has none. */ | |
1280 | ||
1281 | if (TYPE_NAME (type) == 0) | |
1282 | TYPE_NAME (type) = name; | |
51e29401 RS |
1283 | } |
1284 | ||
c138f328 RS |
1285 | if (b == global_binding_level) |
1286 | b->tags = perm_tree_cons (name, type, b->tags); | |
1287 | else | |
1288 | b->tags = saveable_tree_cons (name, type, b->tags); | |
1289 | ||
51e29401 RS |
1290 | /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the |
1291 | tagged type we just added to the current binding level. This fake | |
1292 | NULL-named TYPE_DECL node helps dwarfout.c to know when it needs | |
858a47b1 | 1293 | to output a representation of a tagged type, and it also gives |
51e29401 RS |
1294 | us a convenient place to record the "scope start" address for the |
1295 | tagged type. */ | |
1296 | ||
8d9bfdc5 | 1297 | TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); |
51e29401 RS |
1298 | } |
1299 | \f | |
1300 | /* Handle when a new declaration NEWDECL | |
1301 | has the same name as an old one OLDDECL | |
1302 | in the same binding contour. | |
1303 | Prints an error message if appropriate. | |
1304 | ||
1305 | If safely possible, alter OLDDECL to look like NEWDECL, and return 1. | |
1306 | Otherwise, return 0. */ | |
1307 | ||
1308 | static int | |
1309 | duplicate_decls (newdecl, olddecl) | |
1310 | register tree newdecl, olddecl; | |
1311 | { | |
1312 | int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); | |
1313 | int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL | |
1314 | && DECL_INITIAL (newdecl) != 0); | |
664b4b1e RS |
1315 | tree oldtype = TREE_TYPE (olddecl); |
1316 | tree newtype = TREE_TYPE (newdecl); | |
8e5e53da | 1317 | char *errmsg = 0; |
51e29401 | 1318 | |
664b4b1e RS |
1319 | if (TREE_CODE (newtype) == ERROR_MARK |
1320 | || TREE_CODE (oldtype) == ERROR_MARK) | |
51e29401 RS |
1321 | types_match = 0; |
1322 | ||
1323 | /* New decl is completely inconsistent with the old one => | |
1324 | tell caller to replace the old one. | |
1325 | This is always an error except in the case of shadowing a builtin. */ | |
1326 | if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) | |
1327 | { | |
1328 | if (TREE_CODE (olddecl) == FUNCTION_DECL | |
70efc776 RS |
1329 | && (DECL_BUILT_IN (olddecl) |
1330 | || DECL_BUILT_IN_NONANSI (olddecl))) | |
51e29401 | 1331 | { |
70efc776 RS |
1332 | /* If you declare a built-in or predefined function name as static, |
1333 | the old definition is overridden, | |
51e29401 RS |
1334 | but optionally warn this was a bad choice of name. */ |
1335 | if (!TREE_PUBLIC (newdecl)) | |
1336 | { | |
70efc776 RS |
1337 | if (!warn_shadow) |
1338 | ; | |
1339 | else if (DECL_BUILT_IN (olddecl)) | |
51e29401 | 1340 | warning_with_decl (newdecl, "shadowing built-in function `%s'"); |
70efc776 RS |
1341 | else |
1342 | warning_with_decl (newdecl, "shadowing library function `%s'"); | |
51e29401 RS |
1343 | } |
1344 | /* Likewise, if the built-in is not ansi, then programs can | |
929f3671 | 1345 | override it even globally without an error. */ |
70efc776 RS |
1346 | else if (! DECL_BUILT_IN (olddecl)) |
1347 | warning_with_decl (newdecl, | |
1348 | "library function `%s' declared as non-function"); | |
1349 | ||
51e29401 RS |
1350 | else if (DECL_BUILT_IN_NONANSI (olddecl)) |
1351 | warning_with_decl (newdecl, | |
1352 | "built-in function `%s' declared as non-function"); | |
51e29401 RS |
1353 | else |
1354 | warning_with_decl (newdecl, | |
70efc776 | 1355 | "built-in function `%s' declared as non-function"); |
51e29401 RS |
1356 | } |
1357 | else | |
1358 | { | |
1359 | error_with_decl (newdecl, "`%s' redeclared as different kind of symbol"); | |
1360 | error_with_decl (olddecl, "previous declaration of `%s'"); | |
1361 | } | |
1362 | ||
1363 | return 0; | |
1364 | } | |
1365 | ||
1366 | /* For real parm decl following a forward decl, | |
1367 | return 1 so old decl will be reused. */ | |
1368 | if (types_match && TREE_CODE (newdecl) == PARM_DECL | |
1369 | && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl)) | |
1370 | return 1; | |
1371 | ||
1372 | /* The new declaration is the same kind of object as the old one. | |
1373 | The declarations may partially match. Print warnings if they don't | |
1374 | match enough. Ultimately, copy most of the information from the new | |
1375 | decl to the old one, and keep using the old one. */ | |
1376 | ||
1377 | if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL | |
1378 | && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl | |
1379 | && DECL_INITIAL (olddecl) == 0) | |
1380 | /* If -traditional, avoid error for redeclaring fcn | |
1381 | after implicit decl. */ | |
1382 | ; | |
1383 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
1384 | && DECL_BUILT_IN (olddecl)) | |
1385 | { | |
e841f997 | 1386 | /* A function declaration for a built-in function. */ |
51e29401 RS |
1387 | if (!TREE_PUBLIC (newdecl)) |
1388 | { | |
1389 | /* If you declare a built-in function name as static, the | |
1390 | built-in definition is overridden, | |
1391 | but optionally warn this was a bad choice of name. */ | |
1392 | if (warn_shadow) | |
1393 | warning_with_decl (newdecl, "shadowing built-in function `%s'"); | |
1394 | /* Discard the old built-in function. */ | |
1395 | return 0; | |
1396 | } | |
1397 | else if (!types_match) | |
4c41bbfa RS |
1398 | { |
1399 | /* Accept the return type of the new declaration if same modes. */ | |
1400 | tree oldreturntype = TREE_TYPE (TREE_TYPE (olddecl)); | |
1401 | tree newreturntype = TREE_TYPE (TREE_TYPE (newdecl)); | |
4fc7cf69 JW |
1402 | |
1403 | /* Make sure we put the new type in the same obstack as the old ones. | |
1404 | If the old types are not both in the same obstack, use the | |
1405 | permanent one. */ | |
1406 | if (TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype)) | |
1407 | push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); | |
1408 | else | |
1409 | { | |
1410 | push_obstacks_nochange (); | |
1411 | end_temporary_allocation (); | |
1412 | } | |
1413 | ||
4c41bbfa RS |
1414 | if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype)) |
1415 | { | |
32436219 RS |
1416 | /* Function types may be shared, so we can't just modify |
1417 | the return type of olddecl's function type. */ | |
1418 | tree newtype | |
1419 | = build_function_type (newreturntype, | |
1420 | TYPE_ARG_TYPES (TREE_TYPE (olddecl))); | |
1421 | ||
1f7586c1 RS |
1422 | types_match = comptypes (TREE_TYPE (newdecl), newtype); |
1423 | if (types_match) | |
1424 | TREE_TYPE (olddecl) = newtype; | |
1425 | } | |
1426 | /* Accept harmless mismatch in first argument type also. | |
1427 | This is for ffs. */ | |
1428 | if (TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0 | |
1429 | && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) != 0 | |
1430 | && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (newdecl))) != 0 | |
1431 | && TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (olddecl))) != 0 | |
1432 | && (TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (newdecl)))) | |
1433 | == | |
1434 | TYPE_MODE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (olddecl)))))) | |
1435 | { | |
1436 | /* Function types may be shared, so we can't just modify | |
1437 | the return type of olddecl's function type. */ | |
1438 | tree newtype | |
1439 | = build_function_type (TREE_TYPE (TREE_TYPE (olddecl)), | |
1440 | tree_cons (NULL_TREE, | |
1441 | TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (newdecl))), | |
1442 | TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (olddecl))))); | |
1443 | ||
32436219 RS |
1444 | types_match = comptypes (TREE_TYPE (newdecl), newtype); |
1445 | if (types_match) | |
1446 | TREE_TYPE (olddecl) = newtype; | |
4c41bbfa | 1447 | } |
4fc7cf69 JW |
1448 | |
1449 | pop_obstacks (); | |
4c41bbfa RS |
1450 | } |
1451 | if (!types_match) | |
52b6a22f RS |
1452 | { |
1453 | /* If types don't match for a built-in, throw away the built-in. */ | |
1454 | warning_with_decl (newdecl, "conflicting types for built-in function `%s'"); | |
1455 | return 0; | |
1456 | } | |
51e29401 RS |
1457 | } |
1458 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
e841f997 | 1459 | && DECL_SOURCE_LINE (olddecl) == 0) |
51e29401 | 1460 | { |
e841f997 RS |
1461 | /* A function declaration for a predeclared function |
1462 | that isn't actually built in. */ | |
51e29401 RS |
1463 | if (!TREE_PUBLIC (newdecl)) |
1464 | { | |
858a47b1 | 1465 | /* If you declare it as static, the |
e841f997 | 1466 | default definition is overridden. */ |
51e29401 RS |
1467 | return 0; |
1468 | } | |
1469 | else if (!types_match) | |
e841f997 | 1470 | { |
4d06f145 RS |
1471 | /* If the types don't match, preserve volatility indication. |
1472 | Later on, we will discard everything else about the | |
1473 | default declaration. */ | |
e841f997 | 1474 | TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl); |
e841f997 | 1475 | } |
51e29401 | 1476 | } |
592252ad RS |
1477 | /* Permit char *foo () to match void *foo (...) if not pedantic, |
1478 | if one of them came from a system header file. */ | |
a4219ac7 RS |
1479 | else if (!types_match |
1480 | && TREE_CODE (olddecl) == FUNCTION_DECL | |
1481 | && TREE_CODE (newdecl) == FUNCTION_DECL | |
664b4b1e RS |
1482 | && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE |
1483 | && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE | |
592252ad RS |
1484 | && (DECL_IN_SYSTEM_HEADER (olddecl) |
1485 | || DECL_IN_SYSTEM_HEADER (newdecl)) | |
5fe86b8b | 1486 | && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node |
664b4b1e RS |
1487 | && TYPE_ARG_TYPES (oldtype) == 0 |
1488 | && self_promoting_args_p (TYPE_ARG_TYPES (newtype)) | |
1489 | && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node) | |
a4219ac7 | 1490 | || |
664b4b1e RS |
1491 | (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node |
1492 | && TYPE_ARG_TYPES (newtype) == 0 | |
1493 | && self_promoting_args_p (TYPE_ARG_TYPES (oldtype)) | |
5fe86b8b | 1494 | && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node))) |
a4219ac7 RS |
1495 | { |
1496 | if (pedantic) | |
1497 | pedwarn_with_decl (newdecl, "conflicting types for `%s'"); | |
664b4b1e | 1498 | /* Make sure we keep void * as ret type, not char *. */ |
5fe86b8b | 1499 | if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node) |
664b4b1e | 1500 | TREE_TYPE (newdecl) = newtype = oldtype; |
1d00bef8 JW |
1501 | |
1502 | /* Set DECL_IN_SYSTEM_HEADER, so that if we see another declaration | |
1503 | we will come back here again. */ | |
1504 | DECL_IN_SYSTEM_HEADER (newdecl) = 1; | |
a4219ac7 | 1505 | } |
51e29401 RS |
1506 | else if (!types_match |
1507 | /* Permit char *foo (int, ...); followed by char *foo (); | |
1508 | if not pedantic. */ | |
1509 | && ! (TREE_CODE (olddecl) == FUNCTION_DECL | |
1510 | && ! pedantic | |
1511 | /* Return types must still match. */ | |
664b4b1e RS |
1512 | && comptypes (TREE_TYPE (oldtype), |
1513 | TREE_TYPE (newtype)) | |
1514 | && TYPE_ARG_TYPES (newtype) == 0)) | |
51e29401 RS |
1515 | { |
1516 | error_with_decl (newdecl, "conflicting types for `%s'"); | |
1517 | /* Check for function type mismatch | |
1518 | involving an empty arglist vs a nonempty one. */ | |
1519 | if (TREE_CODE (olddecl) == FUNCTION_DECL | |
664b4b1e RS |
1520 | && comptypes (TREE_TYPE (oldtype), |
1521 | TREE_TYPE (newtype)) | |
1522 | && ((TYPE_ARG_TYPES (oldtype) == 0 | |
51e29401 RS |
1523 | && DECL_INITIAL (olddecl) == 0) |
1524 | || | |
664b4b1e | 1525 | (TYPE_ARG_TYPES (newtype) == 0 |
51e29401 RS |
1526 | && DECL_INITIAL (newdecl) == 0))) |
1527 | { | |
1528 | /* Classify the problem further. */ | |
664b4b1e | 1529 | register tree t = TYPE_ARG_TYPES (oldtype); |
51e29401 | 1530 | if (t == 0) |
664b4b1e | 1531 | t = TYPE_ARG_TYPES (newtype); |
51e29401 RS |
1532 | for (; t; t = TREE_CHAIN (t)) |
1533 | { | |
1534 | register tree type = TREE_VALUE (t); | |
1535 | ||
5fe86b8b RS |
1536 | if (TREE_CHAIN (t) == 0 |
1537 | && TYPE_MAIN_VARIANT (type) != void_type_node) | |
51e29401 RS |
1538 | { |
1539 | error ("A parameter list with an ellipsis can't match"); | |
1540 | error ("an empty parameter name list declaration."); | |
1541 | break; | |
1542 | } | |
1543 | ||
90d56da8 | 1544 | if (TYPE_MAIN_VARIANT (type) == float_type_node |
24bc4c7f | 1545 | || C_PROMOTING_INTEGER_TYPE_P (type)) |
51e29401 RS |
1546 | { |
1547 | error ("An argument type that has a default promotion"); | |
1548 | error ("can't match an empty parameter name list declaration."); | |
1549 | break; | |
1550 | } | |
1551 | } | |
1552 | } | |
1553 | error_with_decl (olddecl, "previous declaration of `%s'"); | |
1554 | } | |
1555 | else | |
1556 | { | |
8e5e53da | 1557 | errmsg = redeclaration_error_message (newdecl, olddecl); |
51e29401 RS |
1558 | if (errmsg) |
1559 | { | |
1560 | error_with_decl (newdecl, errmsg); | |
1561 | error_with_decl (olddecl, | |
d847e6a7 RS |
1562 | ((DECL_INITIAL (olddecl) |
1563 | && current_binding_level == global_binding_level) | |
1564 | ? "`%s' previously defined here" | |
1565 | : "`%s' previously declared here")); | |
51e29401 RS |
1566 | } |
1567 | else if (TREE_CODE (olddecl) == FUNCTION_DECL | |
1568 | && DECL_INITIAL (olddecl) != 0 | |
664b4b1e RS |
1569 | && TYPE_ARG_TYPES (oldtype) == 0 |
1570 | && TYPE_ARG_TYPES (newtype) != 0) | |
51e29401 RS |
1571 | { |
1572 | register tree type, parm; | |
1573 | register int nargs; | |
1574 | /* Prototype decl follows defn w/o prototype. */ | |
1575 | ||
664b4b1e RS |
1576 | for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype), |
1577 | type = TYPE_ARG_TYPES (newtype), | |
51e29401 | 1578 | nargs = 1; |
5fe86b8b RS |
1579 | (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) != void_type_node |
1580 | || TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node); | |
51e29401 RS |
1581 | parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++) |
1582 | { | |
5fe86b8b RS |
1583 | if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node |
1584 | || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) | |
51e29401 RS |
1585 | { |
1586 | errmsg = "prototype for `%s' follows and number of arguments"; | |
1587 | break; | |
1588 | } | |
1589 | /* Type for passing arg must be consistent | |
1590 | with that declared for the arg. */ | |
1591 | if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type)) | |
1592 | /* If -traditional, allow `unsigned int' instead of `int' | |
1593 | in the prototype. */ | |
1594 | && (! (flag_traditional | |
90d56da8 RS |
1595 | && TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == integer_type_node |
1596 | && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node))) | |
51e29401 RS |
1597 | { |
1598 | errmsg = "prototype for `%s' follows and argument %d"; | |
1599 | break; | |
1600 | } | |
1601 | } | |
1602 | if (errmsg) | |
1603 | { | |
1604 | error_with_decl (newdecl, errmsg, nargs); | |
1605 | error_with_decl (olddecl, | |
1606 | "doesn't match non-prototype definition here"); | |
1607 | } | |
1608 | else | |
1609 | { | |
1610 | warning_with_decl (newdecl, "prototype for `%s' follows"); | |
1611 | warning_with_decl (olddecl, "non-prototype definition here"); | |
1612 | } | |
1613 | } | |
8eebb258 | 1614 | /* Warn about mismatches in various flags. */ |
51e29401 RS |
1615 | else |
1616 | { | |
8eebb258 RS |
1617 | /* Warn if function is now inline |
1618 | but was previously declared not inline and has been called. */ | |
51e29401 | 1619 | if (TREE_CODE (olddecl) == FUNCTION_DECL |
1394aabd | 1620 | && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl) |
51e29401 RS |
1621 | && TREE_USED (olddecl)) |
1622 | warning_with_decl (newdecl, | |
1623 | "`%s' declared inline after being called"); | |
1624 | if (TREE_CODE (olddecl) == FUNCTION_DECL | |
1394aabd | 1625 | && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl) |
960a2eb1 | 1626 | && DECL_INITIAL (olddecl) != 0) |
51e29401 | 1627 | warning_with_decl (newdecl, |
960a2eb1 | 1628 | "`%s' declared inline after its definition"); |
a1a77352 JW |
1629 | |
1630 | /* If pedantic, warn when static declaration follows a non-static | |
1631 | declaration. Otherwise, do so only for functions. */ | |
1632 | if ((pedantic || TREE_CODE (olddecl) == FUNCTION_DECL) | |
51e29401 RS |
1633 | && TREE_PUBLIC (olddecl) |
1634 | && !TREE_PUBLIC (newdecl)) | |
1635 | warning_with_decl (newdecl, "static declaration for `%s' follows non-static"); | |
1636 | ||
2af6a433 RK |
1637 | /* Warn when const declaration follows a non-const |
1638 | declaration, but not for functions. */ | |
1639 | if (TREE_CODE (olddecl) != FUNCTION_DECL | |
1640 | && !TREE_READONLY (olddecl) | |
1641 | && TREE_READONLY (newdecl)) | |
1642 | warning_with_decl (newdecl, "const declaration for `%s' follows non-const"); | |
8eebb258 RS |
1643 | /* These bits are logically part of the type, for variables. |
1644 | But not for functions | |
1645 | (where qualifiers are not valid ANSI anyway). */ | |
2af6a433 | 1646 | else if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL |
51e29401 RS |
1647 | && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) |
1648 | || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))) | |
1649 | pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl"); | |
1650 | } | |
1651 | } | |
1652 | ||
27f427f8 | 1653 | /* Optionally warn about more than one declaration for the same name. */ |
5ce574f2 | 1654 | if (errmsg == 0 && warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0 |
27f427f8 RS |
1655 | /* Dont warn about a function declaration |
1656 | followed by a definition. */ | |
1657 | && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0 | |
ec820a12 RS |
1658 | && DECL_INITIAL (olddecl) == 0) |
1659 | /* Don't warn about extern decl followed by (tentative) definition. */ | |
1660 | && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) | |
27f427f8 RS |
1661 | { |
1662 | warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope"); | |
1663 | warning_with_decl (olddecl, "previous declaration of `%s'"); | |
1664 | } | |
1665 | ||
51e29401 | 1666 | /* Copy all the DECL_... slots specified in the new decl |
664b4b1e RS |
1667 | except for any that we copy here from the old type. |
1668 | ||
1669 | Past this point, we don't change OLDTYPE and NEWTYPE | |
1670 | even if we change the types of NEWDECL and OLDDECL. */ | |
51e29401 RS |
1671 | |
1672 | if (types_match) | |
1673 | { | |
46b1c393 RK |
1674 | /* Make sure we put the new type in the same obstack as the old ones. |
1675 | If the old types are not both in the same obstack, use the permanent | |
1676 | one. */ | |
1677 | if (TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype)) | |
1678 | push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); | |
1679 | else | |
1680 | { | |
1681 | push_obstacks_nochange (); | |
1682 | end_temporary_allocation (); | |
1683 | } | |
1684 | ||
51e29401 RS |
1685 | /* Merge the data types specified in the two decls. */ |
1686 | if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl)) | |
1687 | TREE_TYPE (newdecl) | |
1688 | = TREE_TYPE (olddecl) | |
664b4b1e | 1689 | = common_type (newtype, oldtype); |
51e29401 RS |
1690 | |
1691 | /* Lay the type out, unless already done. */ | |
1692 | if (oldtype != TREE_TYPE (newdecl)) | |
1693 | { | |
1694 | if (TREE_TYPE (newdecl) != error_mark_node) | |
1695 | layout_type (TREE_TYPE (newdecl)); | |
1696 | if (TREE_CODE (newdecl) != FUNCTION_DECL | |
1697 | && TREE_CODE (newdecl) != TYPE_DECL | |
1698 | && TREE_CODE (newdecl) != CONST_DECL) | |
1699 | layout_decl (newdecl, 0); | |
1700 | } | |
1701 | else | |
1702 | { | |
1703 | /* Since the type is OLDDECL's, make OLDDECL's size go with. */ | |
1704 | DECL_SIZE (newdecl) = DECL_SIZE (olddecl); | |
ec2343c4 MM |
1705 | if (TREE_CODE (olddecl) != FUNCTION_DECL) |
1706 | if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl)) | |
1707 | DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); | |
51e29401 RS |
1708 | } |
1709 | ||
fc542d3c RS |
1710 | /* Keep the old rtl since we can safely use it. */ |
1711 | DECL_RTL (newdecl) = DECL_RTL (olddecl); | |
1712 | ||
51e29401 RS |
1713 | /* Merge the type qualifiers. */ |
1714 | if (DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl) | |
1715 | && !TREE_THIS_VOLATILE (newdecl)) | |
1716 | TREE_THIS_VOLATILE (olddecl) = 0; | |
1717 | if (TREE_READONLY (newdecl)) | |
1718 | TREE_READONLY (olddecl) = 1; | |
1719 | if (TREE_THIS_VOLATILE (newdecl)) | |
e2f6a3cf RS |
1720 | { |
1721 | TREE_THIS_VOLATILE (olddecl) = 1; | |
1722 | if (TREE_CODE (newdecl) == VAR_DECL) | |
1723 | make_var_volatile (newdecl); | |
1724 | } | |
51e29401 | 1725 | |
e3c56d1b RK |
1726 | /* Keep source location of definition rather than declaration. |
1727 | Likewise, keep decl at outer scope. */ | |
1728 | if ((DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0) | |
1729 | || (DECL_CONTEXT (newdecl) != 0 && DECL_CONTEXT (olddecl) == 0)) | |
51e29401 RS |
1730 | { |
1731 | DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); | |
1732 | DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); | |
e3c56d1b RK |
1733 | |
1734 | if (DECL_CONTEXT (olddecl) == 0) | |
1735 | DECL_CONTEXT (newdecl) = 0; | |
51e29401 RS |
1736 | } |
1737 | ||
e2f6a3cf RS |
1738 | /* Merge the unused-warning information. */ |
1739 | if (DECL_IN_SYSTEM_HEADER (olddecl)) | |
1740 | DECL_IN_SYSTEM_HEADER (newdecl) = 1; | |
1741 | else if (DECL_IN_SYSTEM_HEADER (newdecl)) | |
1742 | DECL_IN_SYSTEM_HEADER (olddecl) = 1; | |
1743 | ||
51e29401 RS |
1744 | /* Merge the initialization information. */ |
1745 | if (DECL_INITIAL (newdecl) == 0) | |
1746 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
1e50b042 DE |
1747 | |
1748 | /* Merge the section attribute. | |
1749 | We want to issue an error if the sections conflict but that must be | |
1750 | done later in decl_attributes since we are called before attributes | |
1751 | are assigned. */ | |
1752 | if (DECL_SECTION_NAME (newdecl) == NULL_TREE) | |
1753 | DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); | |
46b1c393 | 1754 | |
2c5f4139 JM |
1755 | if (TREE_CODE (newdecl) == FUNCTION_DECL) |
1756 | { | |
1757 | DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl); | |
1758 | DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); | |
1759 | } | |
1760 | ||
46b1c393 | 1761 | pop_obstacks (); |
51e29401 RS |
1762 | } |
1763 | /* If cannot merge, then use the new type and qualifiers, | |
1764 | and don't preserve the old rtl. */ | |
1765 | else | |
1766 | { | |
1767 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
1768 | TREE_READONLY (olddecl) = TREE_READONLY (newdecl); | |
1769 | TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); | |
1770 | TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); | |
1771 | } | |
1772 | ||
1773 | /* Merge the storage class information. */ | |
1774 | /* For functions, static overrides non-static. */ | |
1775 | if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
1776 | { | |
1777 | TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); | |
1778 | /* This is since we don't automatically | |
1779 | copy the attributes of NEWDECL into OLDDECL. */ | |
1780 | TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); | |
1781 | /* If this clears `static', clear it in the identifier too. */ | |
1782 | if (! TREE_PUBLIC (olddecl)) | |
1783 | TREE_PUBLIC (DECL_NAME (olddecl)) = 0; | |
1784 | } | |
1394aabd | 1785 | if (DECL_EXTERNAL (newdecl)) |
51e29401 RS |
1786 | { |
1787 | TREE_STATIC (newdecl) = TREE_STATIC (olddecl); | |
1394aabd | 1788 | DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl); |
51e29401 RS |
1789 | /* An extern decl does not override previous storage class. */ |
1790 | TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); | |
1791 | } | |
1792 | else | |
1793 | { | |
1794 | TREE_STATIC (olddecl) = TREE_STATIC (newdecl); | |
51e29401 RS |
1795 | TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); |
1796 | } | |
850cba29 | 1797 | |
51e29401 RS |
1798 | /* If either decl says `inline', this fn is inline, |
1799 | unless its definition was passed already. */ | |
1394aabd RS |
1800 | if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == 0) |
1801 | DECL_INLINE (olddecl) = 1; | |
850cba29 | 1802 | DECL_INLINE (newdecl) = DECL_INLINE (olddecl); |
51e29401 RS |
1803 | |
1804 | /* Get rid of any built-in function if new arg types don't match it | |
1805 | or if we have a function definition. */ | |
1806 | if (TREE_CODE (newdecl) == FUNCTION_DECL | |
1807 | && DECL_BUILT_IN (olddecl) | |
1808 | && (!types_match || new_is_definition)) | |
1809 | { | |
1810 | TREE_TYPE (olddecl) = TREE_TYPE (newdecl); | |
1811 | DECL_BUILT_IN (olddecl) = 0; | |
1812 | } | |
1813 | ||
1814 | /* If redeclaring a builtin function, and not a definition, | |
1815 | it stays built in. | |
1816 | Also preserve various other info from the definition. */ | |
1817 | if (TREE_CODE (newdecl) == FUNCTION_DECL && !new_is_definition) | |
1818 | { | |
1819 | if (DECL_BUILT_IN (olddecl)) | |
1820 | { | |
1821 | DECL_BUILT_IN (newdecl) = 1; | |
678566a5 | 1822 | DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); |
51e29401 RS |
1823 | } |
1824 | else | |
1825 | DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); | |
1826 | ||
1827 | DECL_RESULT (newdecl) = DECL_RESULT (olddecl); | |
1828 | DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); | |
1829 | DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl); | |
1830 | DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); | |
1831 | } | |
1832 | ||
850cba29 RS |
1833 | /* Copy most of the decl-specific fields of NEWDECL into OLDDECL. |
1834 | But preserve OLDdECL's DECL_UID. */ | |
1835 | { | |
1836 | register unsigned olddecl_uid = DECL_UID (olddecl); | |
1837 | ||
1838 | bcopy ((char *) newdecl + sizeof (struct tree_common), | |
1839 | (char *) olddecl + sizeof (struct tree_common), | |
1840 | sizeof (struct tree_decl) - sizeof (struct tree_common)); | |
1841 | DECL_UID (olddecl) = olddecl_uid; | |
1842 | } | |
51e29401 RS |
1843 | |
1844 | return 1; | |
1845 | } | |
1846 | ||
1847 | /* Record a decl-node X as belonging to the current lexical scope. | |
1848 | Check for errors (such as an incompatible declaration for the same | |
1849 | name already seen in the same scope). | |
1850 | ||
1851 | Returns either X or an old decl for the same name. | |
1852 | If an old decl is returned, it may have been smashed | |
1853 | to agree with what X says. */ | |
1854 | ||
1855 | tree | |
1856 | pushdecl (x) | |
1857 | tree x; | |
1858 | { | |
1859 | register tree t; | |
1860 | register tree name = DECL_NAME (x); | |
1861 | register struct binding_level *b = current_binding_level; | |
1862 | ||
1863 | DECL_CONTEXT (x) = current_function_decl; | |
89d7540d RS |
1864 | /* A local extern declaration for a function doesn't constitute nesting. |
1865 | A local auto declaration does, since it's a forward decl | |
1866 | for a nested function coming later. */ | |
1867 | if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0 | |
1868 | && DECL_EXTERNAL (x)) | |
51e29401 RS |
1869 | DECL_CONTEXT (x) = 0; |
1870 | ||
1394aabd | 1871 | if (warn_nested_externs && DECL_EXTERNAL (x) && b != global_binding_level |
6e026f48 MM |
1872 | && x != IDENTIFIER_IMPLICIT_DECL (name) |
1873 | /* Don't print error messages for __FUNCTION__ and __PRETTY_FUNCTION__ */ | |
1874 | && !DECL_IN_SYSTEM_HEADER (x)) | |
51e29401 RS |
1875 | warning ("nested extern declaration of `%s'", IDENTIFIER_POINTER (name)); |
1876 | ||
1877 | if (name) | |
1878 | { | |
1879 | char *file; | |
1880 | int line; | |
1881 | ||
93f623fa JW |
1882 | /* Don't type check externs here when -traditional. This is so that |
1883 | code with conflicting declarations inside blocks will get warnings | |
1884 | not errors. X11 for instance depends on this. */ | |
1885 | if (DECL_EXTERNAL (x) && TREE_PUBLIC (x) && ! flag_traditional) | |
e32fe224 | 1886 | t = lookup_name_current_level_global (name); |
7dcf01c2 JW |
1887 | else |
1888 | t = lookup_name_current_level (name); | |
51e29401 RS |
1889 | if (t != 0 && t == error_mark_node) |
1890 | /* error_mark_node is 0 for a while during initialization! */ | |
1891 | { | |
1892 | t = 0; | |
1893 | error_with_decl (x, "`%s' used prior to declaration"); | |
1894 | } | |
1895 | ||
1896 | if (t != 0) | |
1897 | { | |
1898 | file = DECL_SOURCE_FILE (t); | |
1899 | line = DECL_SOURCE_LINE (t); | |
1900 | } | |
1901 | ||
1902 | if (t != 0 && duplicate_decls (x, t)) | |
1903 | { | |
1904 | if (TREE_CODE (t) == PARM_DECL) | |
1905 | { | |
1906 | /* Don't allow more than one "real" duplicate | |
1907 | of a forward parm decl. */ | |
1908 | TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x); | |
1909 | return t; | |
1910 | } | |
1911 | /* If this decl is `static' and an implicit decl was seen previously, | |
1912 | warn. But don't complain if -traditional, | |
1913 | since traditional compilers don't complain. */ | |
1914 | if (!flag_traditional && TREE_PUBLIC (name) | |
1394aabd | 1915 | && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x) |
51e29401 RS |
1916 | /* We used to warn also for explicit extern followed by static, |
1917 | but sometimes you need to do it that way. */ | |
1918 | && IDENTIFIER_IMPLICIT_DECL (name) != 0) | |
1919 | { | |
1920 | pedwarn ("`%s' was declared implicitly `extern' and later `static'", | |
1921 | IDENTIFIER_POINTER (name)); | |
1922 | pedwarn_with_file_and_line (file, line, | |
1923 | "previous declaration of `%s'", | |
1924 | IDENTIFIER_POINTER (name)); | |
1925 | } | |
27f427f8 | 1926 | |
e32fe224 JW |
1927 | /* If this is a global decl, and there exists a conflicting local |
1928 | decl in a parent block, then we can't return as yet, because we | |
1929 | need to register this decl in the current binding block. */ | |
1930 | if (! DECL_EXTERNAL (x) || ! TREE_PUBLIC (x) | |
1931 | || lookup_name (name) == t) | |
1932 | return t; | |
51e29401 RS |
1933 | } |
1934 | ||
1ce634c3 RS |
1935 | /* If we are processing a typedef statement, generate a whole new |
1936 | ..._TYPE node (which will be just an variant of the existing | |
1937 | ..._TYPE node with identical properties) and then install the | |
1938 | TYPE_DECL node generated to represent the typedef name as the | |
1939 | TYPE_NAME of this brand new (duplicate) ..._TYPE node. | |
1940 | ||
1941 | The whole point here is to end up with a situation where each | |
1942 | and every ..._TYPE node the compiler creates will be uniquely | |
1943 | associated with AT MOST one node representing a typedef name. | |
1944 | This way, even though the compiler substitutes corresponding | |
1945 | ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very | |
1946 | early on, later parts of the compiler can always do the reverse | |
1947 | translation and get back the corresponding typedef name. For | |
1948 | example, given: | |
1949 | ||
1950 | typedef struct S MY_TYPE; | |
1951 | MY_TYPE object; | |
1952 | ||
1953 | Later parts of the compiler might only know that `object' was of | |
1954 | type `struct S' if if were not for code just below. With this | |
1955 | code however, later parts of the compiler see something like: | |
1956 | ||
1957 | struct S' == struct S | |
1958 | typedef struct S' MY_TYPE; | |
1959 | struct S' object; | |
1960 | ||
1961 | And they can then deduce (from the node for type struct S') that | |
1962 | the original object declaration was: | |
1963 | ||
1964 | MY_TYPE object; | |
1965 | ||
1966 | Being able to do this is important for proper support of protoize, | |
1967 | and also for generating precise symbolic debugging information | |
1968 | which takes full account of the programmer's (typedef) vocabulary. | |
1969 | ||
1970 | Obviously, we don't want to generate a duplicate ..._TYPE node if | |
1971 | the TYPE_DECL node that we are now processing really represents a | |
1972 | standard built-in type. | |
1973 | ||
51e29401 RS |
1974 | Since all standard types are effectively declared at line zero |
1975 | in the source file, we can easily check to see if we are working | |
1976 | on a standard type by checking the current value of lineno. */ | |
1977 | ||
1978 | if (TREE_CODE (x) == TYPE_DECL) | |
1979 | { | |
1600ec67 | 1980 | if (DECL_SOURCE_LINE (x) == 0) |
51e29401 RS |
1981 | { |
1982 | if (TYPE_NAME (TREE_TYPE (x)) == 0) | |
1983 | TYPE_NAME (TREE_TYPE (x)) = x; | |
1984 | } | |
32831d4b | 1985 | else if (TREE_TYPE (x) != error_mark_node) |
51e29401 RS |
1986 | { |
1987 | tree tt = TREE_TYPE (x); | |
1988 | ||
1ce634c3 | 1989 | tt = build_type_copy (tt); |
51e29401 RS |
1990 | TYPE_NAME (tt) = x; |
1991 | TREE_TYPE (x) = tt; | |
1992 | } | |
1993 | } | |
1994 | ||
fd0b8fce | 1995 | /* Multiple external decls of the same identifier ought to match. |
93f623fa JW |
1996 | Check against both global declarations (when traditional) and out of |
1997 | scope (limbo) block level declarations. | |
51e29401 | 1998 | |
fd0b8fce JW |
1999 | We get warnings about inline functions where they are defined. |
2000 | Avoid duplicate warnings where they are used. */ | |
93f623fa | 2001 | if (TREE_PUBLIC (x) && ! DECL_INLINE (x)) |
51e29401 | 2002 | { |
93f623fa JW |
2003 | tree decl; |
2004 | ||
2005 | if (flag_traditional && IDENTIFIER_GLOBAL_VALUE (name) != 0 | |
2006 | && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) | |
2007 | || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))) | |
2008 | decl = IDENTIFIER_GLOBAL_VALUE (name); | |
2009 | else if (IDENTIFIER_LIMBO_VALUE (name) != 0) | |
2010 | /* Decls in limbo are always extern, so no need to check that. */ | |
2011 | decl = IDENTIFIER_LIMBO_VALUE (name); | |
2012 | else | |
2013 | decl = 0; | |
fd0b8fce | 2014 | |
93f623fa | 2015 | if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl)) |
58811315 RS |
2016 | /* If old decl is built-in, we already warned if we should. */ |
2017 | && !DECL_BUILT_IN (decl)) | |
51e29401 RS |
2018 | { |
2019 | pedwarn_with_decl (x, | |
2020 | "type mismatch with previous external decl"); | |
fd0b8fce | 2021 | pedwarn_with_decl (decl, "previous external decl of `%s'"); |
51e29401 RS |
2022 | } |
2023 | } | |
2024 | ||
2025 | /* If a function has had an implicit declaration, and then is defined, | |
2026 | make sure they are compatible. */ | |
2027 | ||
2028 | if (IDENTIFIER_IMPLICIT_DECL (name) != 0 | |
2029 | && IDENTIFIER_GLOBAL_VALUE (name) == 0 | |
2030 | && TREE_CODE (x) == FUNCTION_DECL | |
2031 | && ! comptypes (TREE_TYPE (x), | |
2032 | TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name)))) | |
2033 | { | |
2034 | warning_with_decl (x, "type mismatch with previous implicit declaration"); | |
929f3671 RS |
2035 | warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name), |
2036 | "previous implicit declaration of `%s'"); | |
51e29401 RS |
2037 | } |
2038 | ||
2039 | /* In PCC-compatibility mode, extern decls of vars with no current decl | |
2040 | take effect at top level no matter where they are. */ | |
1394aabd | 2041 | if (flag_traditional && DECL_EXTERNAL (x) |
51e29401 RS |
2042 | && lookup_name (name) == 0) |
2043 | { | |
2044 | tree type = TREE_TYPE (x); | |
2045 | ||
2046 | /* But don't do this if the type contains temporary nodes. */ | |
2047 | while (type) | |
2048 | { | |
2049 | if (type == error_mark_node) | |
2050 | break; | |
2051 | if (! TREE_PERMANENT (type)) | |
2052 | { | |
2053 | warning_with_decl (x, "type of external `%s' is not global"); | |
2054 | /* By exiting the loop early, we leave TYPE nonzero, | |
2055 | and thus prevent globalization of the decl. */ | |
2056 | break; | |
2057 | } | |
2058 | else if (TREE_CODE (type) == FUNCTION_TYPE | |
2059 | && TYPE_ARG_TYPES (type) != 0) | |
2060 | /* The types might not be truly local, | |
2061 | but the list of arg types certainly is temporary. | |
2062 | Since prototypes are nontraditional, | |
2063 | ok not to do the traditional thing. */ | |
2064 | break; | |
2065 | type = TREE_TYPE (type); | |
2066 | } | |
2067 | ||
2068 | if (type == 0) | |
2069 | b = global_binding_level; | |
2070 | } | |
2071 | ||
2072 | /* This name is new in its binding level. | |
2073 | Install the new declaration and return it. */ | |
2074 | if (b == global_binding_level) | |
2075 | { | |
2076 | /* Install a global value. */ | |
2077 | ||
2078 | /* If the first global decl has external linkage, | |
2079 | warn if we later see static one. */ | |
2080 | if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x)) | |
2081 | TREE_PUBLIC (name) = 1; | |
2082 | ||
2083 | IDENTIFIER_GLOBAL_VALUE (name) = x; | |
2084 | ||
fd0b8fce JW |
2085 | /* We no longer care about any previous block level declarations. */ |
2086 | IDENTIFIER_LIMBO_VALUE (name) = 0; | |
2087 | ||
51e29401 RS |
2088 | /* Don't forget if the function was used via an implicit decl. */ |
2089 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
2090 | && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) | |
2091 | TREE_USED (x) = 1, TREE_USED (name) = 1; | |
2092 | ||
2093 | /* Don't forget if its address was taken in that way. */ | |
2094 | if (IDENTIFIER_IMPLICIT_DECL (name) | |
2095 | && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) | |
2096 | TREE_ADDRESSABLE (x) = 1; | |
2097 | ||
2098 | /* Warn about mismatches against previous implicit decl. */ | |
2099 | if (IDENTIFIER_IMPLICIT_DECL (name) != 0 | |
2100 | /* If this real decl matches the implicit, don't complain. */ | |
2101 | && ! (TREE_CODE (x) == FUNCTION_DECL | |
90d56da8 RS |
2102 | && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x))) |
2103 | == integer_type_node))) | |
51e29401 RS |
2104 | pedwarn ("`%s' was previously implicitly declared to return `int'", |
2105 | IDENTIFIER_POINTER (name)); | |
2106 | ||
2107 | /* If this decl is `static' and an `extern' was seen previously, | |
2108 | that is erroneous. */ | |
2109 | if (TREE_PUBLIC (name) | |
1394aabd | 2110 | && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x)) |
51e29401 | 2111 | { |
b0e919de RS |
2112 | /* Okay to redeclare an ANSI built-in as static. */ |
2113 | if (t != 0 && DECL_BUILT_IN (t)) | |
929f3671 RS |
2114 | ; |
2115 | /* Okay to declare a non-ANSI built-in as anything. */ | |
2116 | else if (t != 0 && DECL_BUILT_IN_NONANSI (t)) | |
2117 | ; | |
2118 | else if (IDENTIFIER_IMPLICIT_DECL (name)) | |
51e29401 RS |
2119 | pedwarn ("`%s' was declared implicitly `extern' and later `static'", |
2120 | IDENTIFIER_POINTER (name)); | |
2121 | else | |
2122 | pedwarn ("`%s' was declared `extern' and later `static'", | |
2123 | IDENTIFIER_POINTER (name)); | |
2124 | } | |
2125 | } | |
2126 | else | |
2127 | { | |
2128 | /* Here to install a non-global value. */ | |
2129 | tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); | |
2130 | tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); | |
2131 | IDENTIFIER_LOCAL_VALUE (name) = x; | |
2132 | ||
2133 | /* If this is an extern function declaration, see if we | |
fc542d3c | 2134 | have a global definition or declaration for the function. */ |
51e29401 | 2135 | if (oldlocal == 0 |
1394aabd | 2136 | && DECL_EXTERNAL (x) && !DECL_INLINE (x) |
51e29401 RS |
2137 | && oldglobal != 0 |
2138 | && TREE_CODE (x) == FUNCTION_DECL | |
2139 | && TREE_CODE (oldglobal) == FUNCTION_DECL) | |
2140 | { | |
2141 | /* We have one. Their types must agree. */ | |
2142 | if (! comptypes (TREE_TYPE (x), | |
2143 | TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)))) | |
fc542d3c RS |
2144 | pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one"); |
2145 | else | |
2146 | { | |
2147 | /* Inner extern decl is inline if global one is. | |
2148 | Copy enough to really inline it. */ | |
2149 | if (DECL_INLINE (oldglobal)) | |
2150 | { | |
2151 | DECL_INLINE (x) = DECL_INLINE (oldglobal); | |
4135e766 RS |
2152 | DECL_INITIAL (x) = (current_function_decl == oldglobal |
2153 | ? 0 : DECL_INITIAL (oldglobal)); | |
fc542d3c | 2154 | DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal); |
a2469305 | 2155 | DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal); |
fc542d3c | 2156 | DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal); |
42dfa47f RS |
2157 | DECL_RESULT (x) = DECL_RESULT (oldglobal); |
2158 | TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal); | |
2159 | DECL_ABSTRACT_ORIGIN (x) = oldglobal; | |
fc542d3c RS |
2160 | } |
2161 | /* Inner extern decl is built-in if global one is. */ | |
2162 | if (DECL_BUILT_IN (oldglobal)) | |
2163 | { | |
2164 | DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal); | |
678566a5 | 2165 | DECL_FUNCTION_CODE (x) = DECL_FUNCTION_CODE (oldglobal); |
fc542d3c RS |
2166 | } |
2167 | /* Keep the arg types from a file-scope fcn defn. */ | |
2168 | if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0 | |
2169 | && DECL_INITIAL (oldglobal) | |
2170 | && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0) | |
2171 | TREE_TYPE (x) = TREE_TYPE (oldglobal); | |
2172 | } | |
51e29401 RS |
2173 | } |
2174 | ||
2175 | #if 0 /* This case is probably sometimes the right thing to do. */ | |
2176 | /* If we have a local external declaration, | |
2177 | then any file-scope declaration should not | |
2178 | have been static. */ | |
2179 | if (oldlocal == 0 && oldglobal != 0 | |
2180 | && !TREE_PUBLIC (oldglobal) | |
1394aabd | 2181 | && DECL_EXTERNAL (x) && TREE_PUBLIC (x)) |
51e29401 RS |
2182 | warning ("`%s' locally external but globally static", |
2183 | IDENTIFIER_POINTER (name)); | |
2184 | #endif | |
2185 | ||
2186 | /* If we have a local external declaration, | |
2187 | and no file-scope declaration has yet been seen, | |
2188 | then if we later have a file-scope decl it must not be static. */ | |
2189 | if (oldlocal == 0 | |
2190 | && oldglobal == 0 | |
1394aabd | 2191 | && DECL_EXTERNAL (x) |
51e29401 RS |
2192 | && TREE_PUBLIC (x)) |
2193 | { | |
2194 | TREE_PUBLIC (name) = 1; | |
fd0b8fce JW |
2195 | |
2196 | /* Save this decl, so that we can do type checking against | |
2197 | other decls after it falls out of scope. | |
2198 | ||
2199 | Only save it once. This prevents temporary decls created in | |
2200 | expand_inline_function from being used here, since this | |
2201 | will have been set when the inline function was parsed. | |
2202 | It also helps give slightly better warnings. */ | |
2203 | if (IDENTIFIER_LIMBO_VALUE (name) == 0) | |
2204 | IDENTIFIER_LIMBO_VALUE (name) = x; | |
51e29401 RS |
2205 | } |
2206 | ||
2207 | /* Warn if shadowing an argument at the top level of the body. */ | |
1394aabd | 2208 | if (oldlocal != 0 && !DECL_EXTERNAL (x) |
51e29401 RS |
2209 | /* This warning doesn't apply to the parms of a nested fcn. */ |
2210 | && ! current_binding_level->parm_flag | |
2211 | /* Check that this is one level down from the parms. */ | |
2212 | && current_binding_level->level_chain->parm_flag | |
2213 | /* Check that the decl being shadowed | |
2214 | comes from the parm level, one level up. */ | |
2215 | && chain_member (oldlocal, current_binding_level->level_chain->names)) | |
2216 | { | |
2217 | if (TREE_CODE (oldlocal) == PARM_DECL) | |
2218 | pedwarn ("declaration of `%s' shadows a parameter", | |
2219 | IDENTIFIER_POINTER (name)); | |
2220 | else | |
2221 | pedwarn ("declaration of `%s' shadows a symbol from the parameter list", | |
2222 | IDENTIFIER_POINTER (name)); | |
2223 | } | |
2224 | ||
2225 | /* Maybe warn if shadowing something else. */ | |
1394aabd | 2226 | else if (warn_shadow && !DECL_EXTERNAL (x) |
2bae939e | 2227 | /* No shadow warnings for internally generated vars. */ |
7a0347ff | 2228 | && DECL_SOURCE_LINE (x) != 0 |
51e29401 | 2229 | /* No shadow warnings for vars made for inlining. */ |
b032c74c | 2230 | && ! DECL_FROM_INLINE (x)) |
51e29401 RS |
2231 | { |
2232 | char *warnstring = 0; | |
2233 | ||
2234 | if (TREE_CODE (x) == PARM_DECL | |
89d7540d RS |
2235 | && current_binding_level->level_chain->parm_flag) |
2236 | /* Don't warn about the parm names in function declarator | |
2237 | within a function declarator. | |
2238 | It would be nice to avoid warning in any function | |
2239 | declarator in a declaration, as opposed to a definition, | |
2240 | but there is no way to tell it's not a definition. */ | |
51e29401 RS |
2241 | ; |
2242 | else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL) | |
2243 | warnstring = "declaration of `%s' shadows a parameter"; | |
2244 | else if (oldlocal != 0) | |
2245 | warnstring = "declaration of `%s' shadows previous local"; | |
2246 | else if (IDENTIFIER_GLOBAL_VALUE (name) != 0 | |
2247 | && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node) | |
2248 | warnstring = "declaration of `%s' shadows global declaration"; | |
2249 | ||
2250 | if (warnstring) | |
2251 | warning (warnstring, IDENTIFIER_POINTER (name)); | |
2252 | } | |
2253 | ||
2254 | /* If storing a local value, there may already be one (inherited). | |
2255 | If so, record it for restoration when this binding level ends. */ | |
2256 | if (oldlocal != 0) | |
2257 | b->shadowed = tree_cons (name, oldlocal, b->shadowed); | |
2258 | } | |
2259 | ||
2260 | /* Keep count of variables in this level with incomplete type. */ | |
2261 | if (TYPE_SIZE (TREE_TYPE (x)) == 0) | |
2262 | ++b->n_incomplete; | |
2263 | } | |
2264 | ||
2265 | /* Put decls on list in reverse order. | |
2266 | We will reverse them later if necessary. */ | |
2267 | TREE_CHAIN (x) = b->names; | |
2268 | b->names = x; | |
2269 | ||
2270 | return x; | |
2271 | } | |
2272 | ||
2273 | /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */ | |
2274 | ||
2275 | tree | |
2276 | pushdecl_top_level (x) | |
2277 | tree x; | |
2278 | { | |
2279 | register tree t; | |
2280 | register struct binding_level *b = current_binding_level; | |
2281 | ||
2282 | current_binding_level = global_binding_level; | |
2283 | t = pushdecl (x); | |
2284 | current_binding_level = b; | |
2285 | return t; | |
2286 | } | |
2287 | \f | |
2288 | /* Generate an implicit declaration for identifier FUNCTIONID | |
2289 | as a function of type int (). Print a warning if appropriate. */ | |
2290 | ||
2291 | tree | |
2292 | implicitly_declare (functionid) | |
2293 | tree functionid; | |
2294 | { | |
2295 | register tree decl; | |
2296 | int traditional_warning = 0; | |
2297 | /* Only one "implicit declaration" warning per identifier. */ | |
2298 | int implicit_warning; | |
2299 | ||
2300 | /* Save the decl permanently so we can warn if definition follows. */ | |
2301 | push_obstacks_nochange (); | |
2302 | end_temporary_allocation (); | |
2303 | ||
2304 | /* We used to reuse an old implicit decl here, | |
2305 | but this loses with inline functions because it can clobber | |
2306 | the saved decl chains. */ | |
2307 | /* if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0) | |
2308 | decl = IDENTIFIER_IMPLICIT_DECL (functionid); | |
2309 | else */ | |
2310 | decl = build_decl (FUNCTION_DECL, functionid, default_function_type); | |
2311 | ||
2312 | /* Warn of implicit decl following explicit local extern decl. | |
2313 | This is probably a program designed for traditional C. */ | |
2314 | if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0) | |
2315 | traditional_warning = 1; | |
2316 | ||
2317 | /* Warn once of an implicit declaration. */ | |
2318 | implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0); | |
2319 | ||
1394aabd | 2320 | DECL_EXTERNAL (decl) = 1; |
51e29401 RS |
2321 | TREE_PUBLIC (decl) = 1; |
2322 | ||
2323 | /* Record that we have an implicit decl and this is it. */ | |
2324 | IDENTIFIER_IMPLICIT_DECL (functionid) = decl; | |
2325 | ||
2326 | /* ANSI standard says implicit declarations are in the innermost block. | |
2327 | So we record the decl in the standard fashion. | |
2328 | If flag_traditional is set, pushdecl does it top-level. */ | |
2329 | pushdecl (decl); | |
2330 | ||
2331 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ | |
2332 | maybe_objc_check_decl (decl); | |
2333 | ||
8d9bfdc5 | 2334 | rest_of_decl_compilation (decl, NULL_PTR, 0, 0); |
51e29401 RS |
2335 | |
2336 | if (warn_implicit && implicit_warning) | |
2337 | warning ("implicit declaration of function `%s'", | |
2338 | IDENTIFIER_POINTER (functionid)); | |
2339 | else if (warn_traditional && traditional_warning) | |
2340 | warning ("function `%s' was previously declared within a block", | |
2341 | IDENTIFIER_POINTER (functionid)); | |
2342 | ||
2343 | /* Write a record describing this implicit function declaration to the | |
2344 | prototypes file (if requested). */ | |
2345 | ||
2346 | gen_aux_info_record (decl, 0, 1, 0); | |
2347 | ||
2348 | pop_obstacks (); | |
2349 | ||
2350 | return decl; | |
2351 | } | |
2352 | ||
2353 | /* Return zero if the declaration NEWDECL is valid | |
2354 | when the declaration OLDDECL (assumed to be for the same name) | |
2355 | has already been seen. | |
2356 | Otherwise return an error message format string with a %s | |
2357 | where the identifier should go. */ | |
2358 | ||
2359 | static char * | |
2360 | redeclaration_error_message (newdecl, olddecl) | |
2361 | tree newdecl, olddecl; | |
2362 | { | |
2363 | if (TREE_CODE (newdecl) == TYPE_DECL) | |
2364 | { | |
2365 | if (flag_traditional && TREE_TYPE (newdecl) == TREE_TYPE (olddecl)) | |
2366 | return 0; | |
2367 | return "redefinition of `%s'"; | |
2368 | } | |
2369 | else if (TREE_CODE (newdecl) == FUNCTION_DECL) | |
2370 | { | |
2371 | /* Declarations of functions can insist on internal linkage | |
2372 | but they can't be inconsistent with internal linkage, | |
2373 | so there can be no error on that account. | |
2374 | However defining the same name twice is no good. */ | |
2375 | if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0 | |
2376 | /* However, defining once as extern inline and a second | |
2377 | time in another way is ok. */ | |
1394aabd RS |
2378 | && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl) |
2379 | && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl)))) | |
51e29401 RS |
2380 | return "redefinition of `%s'"; |
2381 | return 0; | |
2382 | } | |
2383 | else if (current_binding_level == global_binding_level) | |
2384 | { | |
2385 | /* Objects declared at top level: */ | |
2386 | /* If at least one is a reference, it's ok. */ | |
1394aabd | 2387 | if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) |
51e29401 RS |
2388 | return 0; |
2389 | /* Reject two definitions. */ | |
2390 | if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0) | |
2391 | return "redefinition of `%s'"; | |
2392 | /* Now we have two tentative defs, or one tentative and one real def. */ | |
2393 | /* Insist that the linkage match. */ | |
2394 | if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl)) | |
2395 | return "conflicting declarations of `%s'"; | |
2396 | return 0; | |
2397 | } | |
2398 | else if (current_binding_level->parm_flag | |
2399 | && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) | |
2400 | return 0; | |
2401 | else | |
2402 | { | |
7dcf01c2 JW |
2403 | /* Newdecl has block scope. If olddecl has block scope also, then |
2404 | reject two definitions, and reject a definition together with an | |
2405 | external reference. Otherwise, it is OK, because newdecl must | |
2406 | be an extern reference to olddecl. */ | |
2407 | if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)) | |
2408 | && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)) | |
51e29401 RS |
2409 | return "redeclaration of `%s'"; |
2410 | return 0; | |
2411 | } | |
2412 | } | |
2413 | \f | |
2414 | /* Get the LABEL_DECL corresponding to identifier ID as a label. | |
2415 | Create one if none exists so far for the current function. | |
2416 | This function is called for both label definitions and label references. */ | |
2417 | ||
2418 | tree | |
2419 | lookup_label (id) | |
2420 | tree id; | |
2421 | { | |
2422 | register tree decl = IDENTIFIER_LABEL_VALUE (id); | |
2423 | ||
7d9795e5 RS |
2424 | if (current_function_decl == 0) |
2425 | { | |
2426 | error ("label %s referenced outside of any function", | |
2427 | IDENTIFIER_POINTER (id)); | |
2428 | return 0; | |
2429 | } | |
2430 | ||
51e29401 RS |
2431 | /* Use a label already defined or ref'd with this name. */ |
2432 | if (decl != 0) | |
2433 | { | |
2434 | /* But not if it is inherited and wasn't declared to be inheritable. */ | |
2435 | if (DECL_CONTEXT (decl) != current_function_decl | |
2436 | && ! C_DECLARED_LABEL_FLAG (decl)) | |
2437 | return shadow_label (id); | |
2438 | return decl; | |
2439 | } | |
2440 | ||
2441 | decl = build_decl (LABEL_DECL, id, void_type_node); | |
2442 | ||
8fcd361e RS |
2443 | /* Make sure every label has an rtx. */ |
2444 | label_rtx (decl); | |
2445 | ||
51e29401 RS |
2446 | /* A label not explicitly declared must be local to where it's ref'd. */ |
2447 | DECL_CONTEXT (decl) = current_function_decl; | |
2448 | ||
2449 | DECL_MODE (decl) = VOIDmode; | |
2450 | ||
2451 | /* Say where one reference is to the label, | |
2452 | for the sake of the error if it is not defined. */ | |
2453 | DECL_SOURCE_LINE (decl) = lineno; | |
2454 | DECL_SOURCE_FILE (decl) = input_filename; | |
2455 | ||
2456 | IDENTIFIER_LABEL_VALUE (id) = decl; | |
2457 | ||
2458 | named_labels = tree_cons (NULL_TREE, decl, named_labels); | |
2459 | ||
2460 | return decl; | |
2461 | } | |
2462 | ||
2463 | /* Make a label named NAME in the current function, | |
2464 | shadowing silently any that may be inherited from containing functions | |
2465 | or containing scopes. | |
2466 | ||
2467 | Note that valid use, if the label being shadowed | |
2468 | comes from another scope in the same function, | |
2469 | requires calling declare_nonlocal_label right away. */ | |
2470 | ||
2471 | tree | |
2472 | shadow_label (name) | |
2473 | tree name; | |
2474 | { | |
2475 | register tree decl = IDENTIFIER_LABEL_VALUE (name); | |
2476 | ||
2477 | if (decl != 0) | |
2478 | { | |
a784882b RE |
2479 | register tree dup; |
2480 | ||
2481 | /* Check to make sure that the label hasn't already been declared | |
2482 | at this label scope */ | |
2483 | for (dup = named_labels; dup; dup = TREE_CHAIN (dup)) | |
2484 | if (TREE_VALUE (dup) == decl) | |
2485 | { | |
2486 | error ("duplicate label declaration `%s'", | |
2487 | IDENTIFIER_POINTER (name)); | |
2488 | error_with_decl (TREE_VALUE (dup), | |
2489 | "this is a previous declaration"); | |
2490 | /* Just use the previous declaration. */ | |
2491 | return lookup_label (name); | |
2492 | } | |
2493 | ||
51e29401 RS |
2494 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); |
2495 | IDENTIFIER_LABEL_VALUE (name) = decl = 0; | |
2496 | } | |
2497 | ||
2498 | return lookup_label (name); | |
2499 | } | |
2500 | ||
2501 | /* Define a label, specifying the location in the source file. | |
2502 | Return the LABEL_DECL node for the label, if the definition is valid. | |
2503 | Otherwise return 0. */ | |
2504 | ||
2505 | tree | |
2506 | define_label (filename, line, name) | |
2507 | char *filename; | |
2508 | int line; | |
2509 | tree name; | |
2510 | { | |
2511 | tree decl = lookup_label (name); | |
2512 | ||
2513 | /* If label with this name is known from an outer context, shadow it. */ | |
2514 | if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl) | |
2515 | { | |
2516 | shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); | |
2517 | IDENTIFIER_LABEL_VALUE (name) = 0; | |
2518 | decl = lookup_label (name); | |
2519 | } | |
2520 | ||
2521 | if (DECL_INITIAL (decl) != 0) | |
2522 | { | |
db2e669b | 2523 | error ("duplicate label `%s'", IDENTIFIER_POINTER (name)); |
51e29401 RS |
2524 | return 0; |
2525 | } | |
2526 | else | |
2527 | { | |
2528 | /* Mark label as having been defined. */ | |
2529 | DECL_INITIAL (decl) = error_mark_node; | |
2530 | /* Say where in the source. */ | |
2531 | DECL_SOURCE_FILE (decl) = filename; | |
2532 | DECL_SOURCE_LINE (decl) = line; | |
2533 | return decl; | |
2534 | } | |
2535 | } | |
2536 | \f | |
2537 | /* Return the list of declarations of the current level. | |
2538 | Note that this list is in reverse order unless/until | |
2539 | you nreverse it; and when you do nreverse it, you must | |
2540 | store the result back using `storedecls' or you will lose. */ | |
2541 | ||
2542 | tree | |
2543 | getdecls () | |
2544 | { | |
2545 | return current_binding_level->names; | |
2546 | } | |
2547 | ||
2548 | /* Return the list of type-tags (for structs, etc) of the current level. */ | |
2549 | ||
2550 | tree | |
2551 | gettags () | |
2552 | { | |
2553 | return current_binding_level->tags; | |
2554 | } | |
2555 | ||
2556 | /* Store the list of declarations of the current level. | |
2557 | This is done for the parameter declarations of a function being defined, | |
2558 | after they are modified in the light of any missing parameters. */ | |
2559 | ||
2560 | static void | |
2561 | storedecls (decls) | |
2562 | tree decls; | |
2563 | { | |
2564 | current_binding_level->names = decls; | |
2565 | } | |
2566 | ||
2567 | /* Similarly, store the list of tags of the current level. */ | |
2568 | ||
2569 | static void | |
2570 | storetags (tags) | |
2571 | tree tags; | |
2572 | { | |
2573 | current_binding_level->tags = tags; | |
2574 | } | |
2575 | \f | |
2576 | /* Given NAME, an IDENTIFIER_NODE, | |
2577 | return the structure (or union or enum) definition for that name. | |
2578 | Searches binding levels from BINDING_LEVEL up to the global level. | |
2579 | If THISLEVEL_ONLY is nonzero, searches only the specified context | |
2580 | (but skips any tag-transparent contexts to find one that is | |
2581 | meaningful for tags). | |
2582 | CODE says which kind of type the caller wants; | |
2583 | it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. | |
2584 | If the wrong kind of type is found, an error is reported. */ | |
2585 | ||
2586 | static tree | |
2587 | lookup_tag (code, name, binding_level, thislevel_only) | |
2588 | enum tree_code code; | |
2589 | struct binding_level *binding_level; | |
2590 | tree name; | |
2591 | int thislevel_only; | |
2592 | { | |
2593 | register struct binding_level *level; | |
2594 | ||
2595 | for (level = binding_level; level; level = level->level_chain) | |
2596 | { | |
2597 | register tree tail; | |
2598 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
2599 | { | |
2600 | if (TREE_PURPOSE (tail) == name) | |
2601 | { | |
2602 | if (TREE_CODE (TREE_VALUE (tail)) != code) | |
2603 | { | |
2604 | /* Definition isn't the kind we were looking for. */ | |
2605 | pending_invalid_xref = name; | |
2606 | pending_invalid_xref_file = input_filename; | |
2607 | pending_invalid_xref_line = lineno; | |
2608 | } | |
2609 | return TREE_VALUE (tail); | |
2610 | } | |
2611 | } | |
2612 | if (thislevel_only && ! level->tag_transparent) | |
2613 | return NULL_TREE; | |
2614 | } | |
2615 | return NULL_TREE; | |
2616 | } | |
2617 | ||
2618 | /* Print an error message now | |
2619 | for a recent invalid struct, union or enum cross reference. | |
2620 | We don't print them immediately because they are not invalid | |
2621 | when used in the `struct foo;' construct for shadowing. */ | |
2622 | ||
2623 | void | |
2624 | pending_xref_error () | |
2625 | { | |
2626 | if (pending_invalid_xref != 0) | |
2627 | error_with_file_and_line (pending_invalid_xref_file, | |
2628 | pending_invalid_xref_line, | |
2629 | "`%s' defined as wrong kind of tag", | |
2630 | IDENTIFIER_POINTER (pending_invalid_xref)); | |
2631 | pending_invalid_xref = 0; | |
2632 | } | |
2633 | ||
2634 | /* Given a type, find the tag that was defined for it and return the tag name. | |
2635 | Otherwise return 0. */ | |
2636 | ||
2637 | static tree | |
2638 | lookup_tag_reverse (type) | |
2639 | tree type; | |
2640 | { | |
2641 | register struct binding_level *level; | |
2642 | ||
2643 | for (level = current_binding_level; level; level = level->level_chain) | |
2644 | { | |
2645 | register tree tail; | |
2646 | for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) | |
2647 | { | |
2648 | if (TREE_VALUE (tail) == type) | |
2649 | return TREE_PURPOSE (tail); | |
2650 | } | |
2651 | } | |
2652 | return NULL_TREE; | |
2653 | } | |
2654 | \f | |
2655 | /* Look up NAME in the current binding level and its superiors | |
2656 | in the namespace of variables, functions and typedefs. | |
2657 | Return a ..._DECL node of some kind representing its definition, | |
2658 | or return 0 if it is undefined. */ | |
2659 | ||
2660 | tree | |
2661 | lookup_name (name) | |
2662 | tree name; | |
2663 | { | |
2664 | register tree val; | |
2665 | if (current_binding_level != global_binding_level | |
2666 | && IDENTIFIER_LOCAL_VALUE (name)) | |
2667 | val = IDENTIFIER_LOCAL_VALUE (name); | |
2668 | else | |
2669 | val = IDENTIFIER_GLOBAL_VALUE (name); | |
2670 | return val; | |
2671 | } | |
2672 | ||
2673 | /* Similar to `lookup_name' but look only at current binding level. */ | |
2674 | ||
f062da04 | 2675 | tree |
51e29401 RS |
2676 | lookup_name_current_level (name) |
2677 | tree name; | |
2678 | { | |
2679 | register tree t; | |
2680 | ||
2681 | if (current_binding_level == global_binding_level) | |
2682 | return IDENTIFIER_GLOBAL_VALUE (name); | |
2683 | ||
2684 | if (IDENTIFIER_LOCAL_VALUE (name) == 0) | |
2685 | return 0; | |
2686 | ||
2687 | for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) | |
2688 | if (DECL_NAME (t) == name) | |
2689 | break; | |
2690 | ||
2691 | return t; | |
2692 | } | |
e32fe224 JW |
2693 | |
2694 | /* Similar to `lookup_name_current_level' but also look at the global binding | |
2695 | level. */ | |
2696 | ||
2697 | tree | |
2698 | lookup_name_current_level_global (name) | |
2699 | tree name; | |
2700 | { | |
2701 | register tree t = 0; | |
2702 | ||
2703 | if (current_binding_level == global_binding_level) | |
2704 | return IDENTIFIER_GLOBAL_VALUE (name); | |
2705 | ||
2706 | if (IDENTIFIER_LOCAL_VALUE (name) != 0) | |
2707 | for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) | |
2708 | if (DECL_NAME (t) == name) | |
2709 | break; | |
2710 | ||
2711 | if (t == 0) | |
2712 | t = IDENTIFIER_GLOBAL_VALUE (name); | |
2713 | ||
2714 | return t; | |
2715 | } | |
51e29401 RS |
2716 | \f |
2717 | /* Create the predefined scalar types of C, | |
2718 | and some nodes representing standard constants (0, 1, (void *)0). | |
2719 | Initialize the global binding level. | |
2720 | Make definitions for built-in primitive functions. */ | |
2721 | ||
2722 | void | |
2723 | init_decl_processing () | |
2724 | { | |
2725 | register tree endlink; | |
2726 | /* Either char* or void*. */ | |
2727 | tree traditional_ptr_type_node; | |
f0a45d37 RS |
2728 | /* Data types of memcpy and strlen. */ |
2729 | tree memcpy_ftype, strlen_ftype; | |
9c4614c3 | 2730 | tree void_ftype_any; |
51e29401 RS |
2731 | int wchar_type_size; |
2732 | tree temp; | |
fba9adc6 | 2733 | tree array_domain_type; |
51e29401 RS |
2734 | |
2735 | current_function_decl = NULL; | |
2736 | named_labels = NULL; | |
2737 | current_binding_level = NULL_BINDING_LEVEL; | |
2738 | free_binding_level = NULL_BINDING_LEVEL; | |
2739 | pushlevel (0); /* make the binding_level structure for global names */ | |
2740 | global_binding_level = current_binding_level; | |
2741 | ||
2742 | /* Define `int' and `char' first so that dbx will output them first. */ | |
2743 | ||
2744 | integer_type_node = make_signed_type (INT_TYPE_SIZE); | |
2745 | pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT], | |
2746 | integer_type_node)); | |
2747 | ||
2748 | /* Define `char', which is like either `signed char' or `unsigned char' | |
2749 | but not the same as either. */ | |
2750 | ||
7a0347ff RS |
2751 | char_type_node |
2752 | = (flag_signed_char | |
2753 | ? make_signed_type (CHAR_TYPE_SIZE) | |
2754 | : make_unsigned_type (CHAR_TYPE_SIZE)); | |
51e29401 RS |
2755 | pushdecl (build_decl (TYPE_DECL, get_identifier ("char"), |
2756 | char_type_node)); | |
2757 | ||
2758 | long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); | |
2759 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"), | |
2760 | long_integer_type_node)); | |
2761 | ||
2762 | unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); | |
2763 | pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"), | |
2764 | unsigned_type_node)); | |
2765 | ||
2766 | long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); | |
2767 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"), | |
2768 | long_unsigned_type_node)); | |
2769 | ||
6706083e DE |
2770 | long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); |
2771 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"), | |
2772 | long_long_integer_type_node)); | |
2773 | ||
2774 | long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); | |
2775 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"), | |
2776 | long_long_unsigned_type_node)); | |
2777 | ||
51e29401 RS |
2778 | /* `unsigned long' is the standard type for sizeof. |
2779 | Traditionally, use a signed type. | |
2780 | Note that stddef.h uses `unsigned long', | |
2781 | and this must agree, even of long and int are the same size. */ | |
a34731a6 RK |
2782 | sizetype |
2783 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); | |
2784 | if (flag_traditional && TREE_UNSIGNED (sizetype)) | |
2785 | sizetype = signed_type (sizetype); | |
51e29401 RS |
2786 | |
2787 | ptrdiff_type_node | |
2788 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); | |
2789 | ||
2790 | TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype; | |
2791 | TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype; | |
2792 | TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype; | |
2793 | TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype; | |
2794 | TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype; | |
6706083e DE |
2795 | TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype; |
2796 | TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype; | |
51e29401 RS |
2797 | |
2798 | error_mark_node = make_node (ERROR_MARK); | |
2799 | TREE_TYPE (error_mark_node) = error_mark_node; | |
2800 | ||
2801 | short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); | |
2802 | pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"), | |
2803 | short_integer_type_node)); | |
2804 | ||
51e29401 RS |
2805 | short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); |
2806 | pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"), | |
2807 | short_unsigned_type_node)); | |
2808 | ||
51e29401 RS |
2809 | /* Define both `signed char' and `unsigned char'. */ |
2810 | signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); | |
2811 | pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"), | |
2812 | signed_char_type_node)); | |
2813 | ||
2814 | unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); | |
2815 | pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"), | |
2816 | unsigned_char_type_node)); | |
2817 | ||
fa7d8b92 | 2818 | intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); |
ac4f24e7 RS |
2819 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); |
2820 | ||
fa7d8b92 | 2821 | intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); |
ac4f24e7 RS |
2822 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); |
2823 | ||
fa7d8b92 | 2824 | intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); |
ac4f24e7 RS |
2825 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); |
2826 | ||
fa7d8b92 | 2827 | intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); |
ac4f24e7 RS |
2828 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); |
2829 | ||
fa7d8b92 | 2830 | unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); |
ac4f24e7 RS |
2831 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); |
2832 | ||
fa7d8b92 | 2833 | unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); |
ac4f24e7 RS |
2834 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); |
2835 | ||
fa7d8b92 | 2836 | unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); |
ac4f24e7 RS |
2837 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); |
2838 | ||
fa7d8b92 | 2839 | unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); |
ac4f24e7 RS |
2840 | pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); |
2841 | ||
51e29401 RS |
2842 | float_type_node = make_node (REAL_TYPE); |
2843 | TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; | |
2844 | pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT], | |
2845 | float_type_node)); | |
2846 | layout_type (float_type_node); | |
2847 | ||
2848 | double_type_node = make_node (REAL_TYPE); | |
2849 | if (flag_short_double) | |
2850 | TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; | |
2851 | else | |
2852 | TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; | |
2853 | pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE], | |
2854 | double_type_node)); | |
2855 | layout_type (double_type_node); | |
2856 | ||
2857 | long_double_type_node = make_node (REAL_TYPE); | |
2858 | TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; | |
2859 | pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"), | |
2860 | long_double_type_node)); | |
2861 | layout_type (long_double_type_node); | |
2862 | ||
5ab10c42 RS |
2863 | complex_integer_type_node = make_node (COMPLEX_TYPE); |
2864 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), | |
2865 | complex_integer_type_node)); | |
2866 | TREE_TYPE (complex_integer_type_node) = integer_type_node; | |
2867 | layout_type (complex_integer_type_node); | |
2868 | ||
2869 | complex_float_type_node = make_node (COMPLEX_TYPE); | |
2870 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), | |
2871 | complex_float_type_node)); | |
2872 | TREE_TYPE (complex_float_type_node) = float_type_node; | |
2873 | layout_type (complex_float_type_node); | |
2874 | ||
2875 | complex_double_type_node = make_node (COMPLEX_TYPE); | |
2876 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), | |
2877 | complex_double_type_node)); | |
2878 | TREE_TYPE (complex_double_type_node) = double_type_node; | |
2879 | layout_type (complex_double_type_node); | |
2880 | ||
2881 | complex_long_double_type_node = make_node (COMPLEX_TYPE); | |
2882 | pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), | |
2883 | complex_long_double_type_node)); | |
2884 | TREE_TYPE (complex_long_double_type_node) = long_double_type_node; | |
2885 | layout_type (complex_long_double_type_node); | |
2886 | ||
51e29401 RS |
2887 | wchar_type_node |
2888 | = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); | |
2889 | wchar_type_size = TYPE_PRECISION (wchar_type_node); | |
7e4849da RS |
2890 | signed_wchar_type_node = signed_type (wchar_type_node); |
2891 | unsigned_wchar_type_node = unsigned_type (wchar_type_node); | |
51e29401 RS |
2892 | |
2893 | integer_zero_node = build_int_2 (0, 0); | |
2894 | TREE_TYPE (integer_zero_node) = integer_type_node; | |
2895 | integer_one_node = build_int_2 (1, 0); | |
2896 | TREE_TYPE (integer_one_node) = integer_type_node; | |
2897 | ||
f444e553 JM |
2898 | boolean_type_node = integer_type_node; |
2899 | boolean_true_node = integer_one_node; | |
2900 | boolean_false_node = integer_zero_node; | |
2901 | ||
51e29401 RS |
2902 | size_zero_node = build_int_2 (0, 0); |
2903 | TREE_TYPE (size_zero_node) = sizetype; | |
2904 | size_one_node = build_int_2 (1, 0); | |
2905 | TREE_TYPE (size_one_node) = sizetype; | |
2906 | ||
2907 | void_type_node = make_node (VOID_TYPE); | |
2908 | pushdecl (build_decl (TYPE_DECL, | |
2909 | ridpointers[(int) RID_VOID], void_type_node)); | |
2910 | layout_type (void_type_node); /* Uses integer_zero_node */ | |
2911 | /* We are not going to have real types in C with less than byte alignment, | |
2912 | so we might as well not have any types that claim to have it. */ | |
2913 | TYPE_ALIGN (void_type_node) = BITS_PER_UNIT; | |
2914 | ||
2915 | null_pointer_node = build_int_2 (0, 0); | |
2916 | TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); | |
2917 | layout_type (TREE_TYPE (null_pointer_node)); | |
2918 | ||
2919 | string_type_node = build_pointer_type (char_type_node); | |
2920 | const_string_type_node | |
2921 | = build_pointer_type (build_type_variant (char_type_node, 1, 0)); | |
2922 | ||
fba9adc6 | 2923 | /* Make a type to be the domain of a few array types |
c81fe25d RK |
2924 | whose domains don't really matter. |
2925 | 200 is small enough that it always fits in size_t | |
2926 | and large enough that it can hold most function names for the | |
2927 | initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ | |
2928 | array_domain_type = build_index_type (build_int_2 (200, 0)); | |
fba9adc6 RS |
2929 | |
2930 | /* make a type for arrays of characters. | |
51e29401 RS |
2931 | With luck nothing will ever really depend on the length of this |
2932 | array type. */ | |
2933 | char_array_type_node | |
fba9adc6 | 2934 | = build_array_type (char_type_node, array_domain_type); |
51e29401 RS |
2935 | /* Likewise for arrays of ints. */ |
2936 | int_array_type_node | |
fba9adc6 | 2937 | = build_array_type (integer_type_node, array_domain_type); |
51e29401 RS |
2938 | /* This is for wide string constants. */ |
2939 | wchar_array_type_node | |
fba9adc6 | 2940 | = build_array_type (wchar_type_node, array_domain_type); |
51e29401 RS |
2941 | |
2942 | default_function_type | |
2943 | = build_function_type (integer_type_node, NULL_TREE); | |
2944 | ||
2945 | ptr_type_node = build_pointer_type (void_type_node); | |
2946 | const_ptr_type_node | |
2947 | = build_pointer_type (build_type_variant (void_type_node, 1, 0)); | |
2948 | ||
2949 | endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE); | |
2950 | ||
9c4614c3 | 2951 | void_ftype_any |
8d9bfdc5 | 2952 | = build_function_type (void_type_node, NULL_TREE); |
9c4614c3 | 2953 | |
732149f9 RK |
2954 | float_ftype_float |
2955 | = build_function_type (float_type_node, | |
2956 | tree_cons (NULL_TREE, float_type_node, endlink)); | |
2957 | ||
51e29401 RS |
2958 | double_ftype_double |
2959 | = build_function_type (double_type_node, | |
2960 | tree_cons (NULL_TREE, double_type_node, endlink)); | |
2961 | ||
732149f9 RK |
2962 | ldouble_ftype_ldouble |
2963 | = build_function_type (long_double_type_node, | |
2964 | tree_cons (NULL_TREE, long_double_type_node, | |
2965 | endlink)); | |
2966 | ||
51e29401 RS |
2967 | double_ftype_double_double |
2968 | = build_function_type (double_type_node, | |
2969 | tree_cons (NULL_TREE, double_type_node, | |
2970 | tree_cons (NULL_TREE, | |
2971 | double_type_node, endlink))); | |
2972 | ||
2973 | int_ftype_int | |
2974 | = build_function_type (integer_type_node, | |
2975 | tree_cons (NULL_TREE, integer_type_node, endlink)); | |
2976 | ||
2977 | long_ftype_long | |
2978 | = build_function_type (long_integer_type_node, | |
2979 | tree_cons (NULL_TREE, | |
2980 | long_integer_type_node, endlink)); | |
2981 | ||
2982 | void_ftype_ptr_ptr_int | |
2983 | = build_function_type (void_type_node, | |
2984 | tree_cons (NULL_TREE, ptr_type_node, | |
2985 | tree_cons (NULL_TREE, ptr_type_node, | |
2986 | tree_cons (NULL_TREE, | |
2987 | integer_type_node, | |
2988 | endlink)))); | |
2989 | ||
2990 | int_ftype_cptr_cptr_sizet | |
2991 | = build_function_type (integer_type_node, | |
2992 | tree_cons (NULL_TREE, const_ptr_type_node, | |
2993 | tree_cons (NULL_TREE, const_ptr_type_node, | |
2994 | tree_cons (NULL_TREE, | |
2995 | sizetype, | |
2996 | endlink)))); | |
2997 | ||
2998 | void_ftype_ptr_int_int | |
2999 | = build_function_type (void_type_node, | |
3000 | tree_cons (NULL_TREE, ptr_type_node, | |
3001 | tree_cons (NULL_TREE, integer_type_node, | |
3002 | tree_cons (NULL_TREE, | |
3003 | integer_type_node, | |
3004 | endlink)))); | |
3005 | ||
3006 | string_ftype_ptr_ptr /* strcpy prototype */ | |
3007 | = build_function_type (string_type_node, | |
3008 | tree_cons (NULL_TREE, string_type_node, | |
3009 | tree_cons (NULL_TREE, | |
3010 | const_string_type_node, | |
3011 | endlink))); | |
3012 | ||
3013 | int_ftype_string_string /* strcmp prototype */ | |
3014 | = build_function_type (integer_type_node, | |
3015 | tree_cons (NULL_TREE, const_string_type_node, | |
3016 | tree_cons (NULL_TREE, | |
3017 | const_string_type_node, | |
3018 | endlink))); | |
3019 | ||
f0a45d37 RS |
3020 | strlen_ftype /* strlen prototype */ |
3021 | = build_function_type (flag_traditional ? integer_type_node : sizetype, | |
51e29401 RS |
3022 | tree_cons (NULL_TREE, const_string_type_node, |
3023 | endlink)); | |
3024 | ||
3025 | traditional_ptr_type_node | |
3026 | = (flag_traditional ? string_type_node : ptr_type_node); | |
3027 | ||
3028 | memcpy_ftype /* memcpy prototype */ | |
3029 | = build_function_type (traditional_ptr_type_node, | |
3030 | tree_cons (NULL_TREE, ptr_type_node, | |
3031 | tree_cons (NULL_TREE, const_ptr_type_node, | |
3032 | tree_cons (NULL_TREE, | |
3033 | sizetype, | |
3034 | endlink)))); | |
3035 | ||
5fe5c210 | 3036 | builtin_function ("__builtin_constant_p", int_ftype_int, |
8d9bfdc5 | 3037 | BUILT_IN_CONSTANT_P, NULL_PTR); |
51e29401 RS |
3038 | |
3039 | builtin_function ("__builtin_return_address", | |
530fb43c | 3040 | build_function_type (ptr_type_node, |
51e29401 RS |
3041 | tree_cons (NULL_TREE, |
3042 | unsigned_type_node, | |
3043 | endlink)), | |
8d9bfdc5 | 3044 | BUILT_IN_RETURN_ADDRESS, NULL_PTR); |
51e29401 RS |
3045 | |
3046 | builtin_function ("__builtin_frame_address", | |
530fb43c | 3047 | build_function_type (ptr_type_node, |
51e29401 RS |
3048 | tree_cons (NULL_TREE, |
3049 | unsigned_type_node, | |
3050 | endlink)), | |
8d9bfdc5 | 3051 | BUILT_IN_FRAME_ADDRESS, NULL_PTR); |
51e29401 RS |
3052 | |
3053 | builtin_function ("__builtin_alloca", | |
3054 | build_function_type (ptr_type_node, | |
3055 | tree_cons (NULL_TREE, | |
3056 | sizetype, | |
3057 | endlink)), | |
3058 | BUILT_IN_ALLOCA, "alloca"); | |
1f53ee05 RS |
3059 | builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); |
3060 | /* Define alloca, ffs as builtins. | |
3061 | Declare _exit just to mark it as volatile. */ | |
fc3ffe83 | 3062 | if (! flag_no_builtin && !flag_no_nonansi_builtin) |
51e29401 | 3063 | { |
51e29401 RS |
3064 | temp = builtin_function ("alloca", |
3065 | build_function_type (ptr_type_node, | |
3066 | tree_cons (NULL_TREE, | |
3067 | sizetype, | |
3068 | endlink)), | |
8d9bfdc5 | 3069 | BUILT_IN_ALLOCA, NULL_PTR); |
51e29401 RS |
3070 | /* Suppress error if redefined as a non-function. */ |
3071 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
1f53ee05 RS |
3072 | temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); |
3073 | /* Suppress error if redefined as a non-function. */ | |
3074 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
8d9bfdc5 RK |
3075 | temp = builtin_function ("_exit", void_ftype_any, NOT_BUILT_IN, |
3076 | NULL_PTR); | |
51e29401 RS |
3077 | TREE_THIS_VOLATILE (temp) = 1; |
3078 | TREE_SIDE_EFFECTS (temp) = 1; | |
3079 | /* Suppress error if redefined as a non-function. */ | |
3080 | DECL_BUILT_IN_NONANSI (temp) = 1; | |
3081 | } | |
3082 | ||
8d9bfdc5 | 3083 | builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); |
732149f9 RK |
3084 | builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS, |
3085 | NULL_PTR); | |
8d9bfdc5 RK |
3086 | builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, |
3087 | NULL_PTR); | |
732149f9 RK |
3088 | builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, |
3089 | NULL_PTR); | |
8d9bfdc5 RK |
3090 | builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS, |
3091 | NULL_PTR); | |
530fb43c RK |
3092 | builtin_function ("__builtin_saveregs", |
3093 | build_function_type (ptr_type_node, NULL_TREE), | |
8d9bfdc5 | 3094 | BUILT_IN_SAVEREGS, NULL_PTR); |
51e29401 RS |
3095 | /* EXPAND_BUILTIN_VARARGS is obsolete. */ |
3096 | #if 0 | |
3097 | builtin_function ("__builtin_varargs", | |
3098 | build_function_type (ptr_type_node, | |
3099 | tree_cons (NULL_TREE, | |
3100 | integer_type_node, | |
3101 | endlink)), | |
8d9bfdc5 | 3102 | BUILT_IN_VARARGS, NULL_PTR); |
51e29401 RS |
3103 | #endif |
3104 | builtin_function ("__builtin_classify_type", default_function_type, | |
8d9bfdc5 | 3105 | BUILT_IN_CLASSIFY_TYPE, NULL_PTR); |
51e29401 | 3106 | builtin_function ("__builtin_next_arg", |
8d0aed47 | 3107 | build_function_type (ptr_type_node, NULL_TREE), |
8d9bfdc5 | 3108 | BUILT_IN_NEXT_ARG, NULL_PTR); |
51e29401 RS |
3109 | builtin_function ("__builtin_args_info", |
3110 | build_function_type (integer_type_node, | |
3111 | tree_cons (NULL_TREE, | |
3112 | integer_type_node, | |
3113 | endlink)), | |
8d9bfdc5 | 3114 | BUILT_IN_ARGS_INFO, NULL_PTR); |
51e29401 | 3115 | |
efb99317 TW |
3116 | /* Untyped call and return. */ |
3117 | builtin_function ("__builtin_apply_args", | |
3118 | build_function_type (ptr_type_node, NULL_TREE), | |
3119 | BUILT_IN_APPLY_ARGS, NULL_PTR); | |
3120 | ||
3121 | temp = tree_cons (NULL_TREE, | |
3122 | build_pointer_type (build_function_type (void_type_node, | |
3123 | NULL_TREE)), | |
3124 | tree_cons (NULL_TREE, | |
3125 | ptr_type_node, | |
3126 | tree_cons (NULL_TREE, | |
e09d75bd | 3127 | sizetype, |
efb99317 TW |
3128 | endlink))); |
3129 | builtin_function ("__builtin_apply", | |
3130 | build_function_type (ptr_type_node, temp), | |
3131 | BUILT_IN_APPLY, NULL_PTR); | |
3132 | builtin_function ("__builtin_return", | |
3133 | build_function_type (void_type_node, | |
3134 | tree_cons (NULL_TREE, | |
3135 | ptr_type_node, | |
3136 | endlink)), | |
3137 | BUILT_IN_RETURN, NULL_PTR); | |
3138 | ||
51e29401 RS |
3139 | /* Currently under experimentation. */ |
3140 | builtin_function ("__builtin_memcpy", memcpy_ftype, | |
3141 | BUILT_IN_MEMCPY, "memcpy"); | |
3142 | builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, | |
3143 | BUILT_IN_MEMCMP, "memcmp"); | |
3144 | builtin_function ("__builtin_strcmp", int_ftype_string_string, | |
3145 | BUILT_IN_STRCMP, "strcmp"); | |
3146 | builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, | |
3147 | BUILT_IN_STRCPY, "strcpy"); | |
f0a45d37 | 3148 | builtin_function ("__builtin_strlen", strlen_ftype, |
51e29401 | 3149 | BUILT_IN_STRLEN, "strlen"); |
732149f9 RK |
3150 | builtin_function ("__builtin_sqrtf", float_ftype_float, |
3151 | BUILT_IN_FSQRT, "sqrtf"); | |
929f3671 RS |
3152 | builtin_function ("__builtin_fsqrt", double_ftype_double, |
3153 | BUILT_IN_FSQRT, "sqrt"); | |
732149f9 RK |
3154 | builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble, |
3155 | BUILT_IN_FSQRT, "sqrtl"); | |
3156 | builtin_function ("__builtin_sinf", float_ftype_float, | |
3157 | BUILT_IN_SIN, "sinf"); | |
96a1b3af JVA |
3158 | builtin_function ("__builtin_sin", double_ftype_double, |
3159 | BUILT_IN_SIN, "sin"); | |
732149f9 RK |
3160 | builtin_function ("__builtin_sinl", ldouble_ftype_ldouble, |
3161 | BUILT_IN_SIN, "sinl"); | |
3162 | builtin_function ("__builtin_cosf", float_ftype_float, | |
3163 | BUILT_IN_COS, "cosf"); | |
96a1b3af JVA |
3164 | builtin_function ("__builtin_cos", double_ftype_double, |
3165 | BUILT_IN_COS, "cos"); | |
732149f9 RK |
3166 | builtin_function ("__builtin_cosl", ldouble_ftype_ldouble, |
3167 | BUILT_IN_COS, "cosl"); | |
96a1b3af | 3168 | |
51e29401 RS |
3169 | /* In an ANSI C program, it is okay to supply built-in meanings |
3170 | for these functions, since applications cannot validly use them | |
3171 | with any other meaning. | |
9e3c9e1b RS |
3172 | However, honor the -fno-builtin option. */ |
3173 | if (!flag_no_builtin) | |
51e29401 | 3174 | { |
8d9bfdc5 | 3175 | builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); |
732149f9 | 3176 | builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); |
8d9bfdc5 | 3177 | builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); |
732149f9 RK |
3178 | builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, |
3179 | NULL_PTR); | |
8d9bfdc5 RK |
3180 | builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); |
3181 | builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); | |
3182 | builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, | |
3183 | NULL_PTR); | |
3184 | builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, | |
3185 | NULL_PTR); | |
3186 | builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, | |
3187 | NULL_PTR); | |
3188 | builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR); | |
732149f9 | 3189 | builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR); |
8d9bfdc5 | 3190 | builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); |
732149f9 RK |
3191 | builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, |
3192 | NULL_PTR); | |
3193 | builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR); | |
96a1b3af | 3194 | builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); |
732149f9 RK |
3195 | builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR); |
3196 | builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR); | |
96a1b3af | 3197 | builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); |
732149f9 | 3198 | builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR); |
9e3c9e1b RS |
3199 | |
3200 | /* Declare these functions volatile | |
3201 | to avoid spurious "control drops through" warnings. */ | |
3202 | /* Don't specify the argument types, to avoid errors | |
3203 | from certain code which isn't valid in ANSI but which exists. */ | |
8d9bfdc5 RK |
3204 | temp = builtin_function ("abort", void_ftype_any, NOT_BUILT_IN, |
3205 | NULL_PTR); | |
9e3c9e1b RS |
3206 | TREE_THIS_VOLATILE (temp) = 1; |
3207 | TREE_SIDE_EFFECTS (temp) = 1; | |
8d9bfdc5 | 3208 | temp = builtin_function ("exit", void_ftype_any, NOT_BUILT_IN, NULL_PTR); |
9e3c9e1b RS |
3209 | TREE_THIS_VOLATILE (temp) = 1; |
3210 | TREE_SIDE_EFFECTS (temp) = 1; | |
51e29401 RS |
3211 | } |
3212 | ||
3213 | #if 0 | |
3214 | /* Support for these has not been written in either expand_builtin | |
3215 | or build_function_call. */ | |
8d9bfdc5 RK |
3216 | builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR); |
3217 | builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR); | |
3218 | builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, | |
3219 | NULL_PTR); | |
3220 | builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, | |
3221 | NULL_PTR); | |
3222 | builtin_function ("__builtin_fmod", double_ftype_double_double, | |
3223 | BUILT_IN_FMOD, NULL_PTR); | |
3224 | builtin_function ("__builtin_frem", double_ftype_double_double, | |
3225 | BUILT_IN_FREM, NULL_PTR); | |
3226 | builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, | |
3227 | BUILT_IN_MEMSET, NULL_PTR); | |
3228 | builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, | |
3229 | NULL_PTR); | |
3230 | builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, | |
3231 | NULL_PTR); | |
51e29401 RS |
3232 | #endif |
3233 | ||
f444e553 JM |
3234 | pedantic_lvalues = pedantic; |
3235 | ||
b032c74c | 3236 | /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ |
7da551a2 | 3237 | declare_function_name (); |
64309441 | 3238 | |
51e29401 RS |
3239 | start_identifier_warnings (); |
3240 | ||
561d994f RK |
3241 | /* Prepare to check format strings against argument lists. */ |
3242 | init_function_format_info (); | |
75621238 RS |
3243 | |
3244 | init_iterators (); | |
b4892310 RS |
3245 | |
3246 | incomplete_decl_finalize_hook = finish_incomplete_decl; | |
51e29401 RS |
3247 | } |
3248 | ||
3249 | /* Return a definition for a builtin function named NAME and whose data type | |
3250 | is TYPE. TYPE should be a function type with argument types. | |
3251 | FUNCTION_CODE tells later passes how to compile calls to this function. | |
3252 | See tree.h for its possible values. | |
3253 | ||
3254 | If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, | |
3255 | the name to be called if we can't opencode the function. */ | |
3256 | ||
929f3671 | 3257 | tree |
51e29401 RS |
3258 | builtin_function (name, type, function_code, library_name) |
3259 | char *name; | |
3260 | tree type; | |
3261 | enum built_in_function function_code; | |
3262 | char *library_name; | |
3263 | { | |
3264 | tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type); | |
1394aabd | 3265 | DECL_EXTERNAL (decl) = 1; |
51e29401 | 3266 | TREE_PUBLIC (decl) = 1; |
9a509bfe RS |
3267 | /* If -traditional, permit redefining a builtin function any way you like. |
3268 | (Though really, if the program redefines these functions, | |
3269 | it probably won't work right unless compiled with -fno-builtin.) */ | |
3270 | if (flag_traditional && name[0] != '_') | |
3271 | DECL_BUILT_IN_NONANSI (decl) = 1; | |
51e29401 RS |
3272 | if (library_name) |
3273 | DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); | |
8d9bfdc5 | 3274 | make_decl_rtl (decl, NULL_PTR, 1); |
51e29401 RS |
3275 | pushdecl (decl); |
3276 | if (function_code != NOT_BUILT_IN) | |
3277 | { | |
3278 | DECL_BUILT_IN (decl) = 1; | |
678566a5 | 3279 | DECL_FUNCTION_CODE (decl) = function_code; |
51e29401 | 3280 | } |
6b19af32 RS |
3281 | /* Warn if a function in the namespace for users |
3282 | is used without an occasion to consider it declared. */ | |
3283 | if (name[0] != '_' || name[1] != '_') | |
3284 | C_DECL_ANTICIPATED (decl) = 1; | |
51e29401 RS |
3285 | |
3286 | return decl; | |
3287 | } | |
3288 | \f | |
3289 | /* Called when a declaration is seen that contains no names to declare. | |
3290 | If its type is a reference to a structure, union or enum inherited | |
3291 | from a containing scope, shadow that tag name for the current scope | |
3292 | with a forward reference. | |
3293 | If its type defines a new named structure or union | |
3294 | or defines an enum, it is valid but we need not do anything here. | |
3295 | Otherwise, it is an error. */ | |
3296 | ||
3297 | void | |
3298 | shadow_tag (declspecs) | |
3299 | tree declspecs; | |
9282f2f9 RS |
3300 | { |
3301 | shadow_tag_warned (declspecs, 0); | |
3302 | } | |
3303 | ||
3304 | void | |
3305 | shadow_tag_warned (declspecs, warned) | |
3306 | tree declspecs; | |
3307 | int warned; | |
773edaef RK |
3308 | /* 1 => we have done a pedwarn. 2 => we have done a warning, but |
3309 | no pedwarn. */ | |
51e29401 RS |
3310 | { |
3311 | int found_tag = 0; | |
51e29401 RS |
3312 | register tree link; |
3313 | ||
3314 | pending_invalid_xref = 0; | |
3315 | ||
3316 | for (link = declspecs; link; link = TREE_CHAIN (link)) | |
3317 | { | |
3318 | register tree value = TREE_VALUE (link); | |
3319 | register enum tree_code code = TREE_CODE (value); | |
3320 | ||
3321 | if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE) | |
3322 | /* Used to test also that TYPE_SIZE (value) != 0. | |
3323 | That caused warning for `struct foo;' at top level in the file. */ | |
3324 | { | |
3325 | register tree name = lookup_tag_reverse (value); | |
3326 | register tree t; | |
3327 | ||
3328 | found_tag++; | |
3329 | ||
3330 | if (name == 0) | |
3331 | { | |
773edaef RK |
3332 | if (warned != 1 && code != ENUMERAL_TYPE) |
3333 | /* Empty unnamed enum OK */ | |
51e29401 RS |
3334 | { |
3335 | pedwarn ("unnamed struct/union that defines no instances"); | |
3336 | warned = 1; | |
3337 | } | |
3338 | } | |
3339 | else | |
3340 | { | |
3341 | t = lookup_tag (code, name, current_binding_level, 1); | |
3342 | ||
3343 | if (t == 0) | |
3344 | { | |
3345 | t = make_node (code); | |
3346 | pushtag (name, t); | |
3347 | } | |
3348 | } | |
3349 | } | |
3350 | else | |
3351 | { | |
3352 | if (!warned) | |
773edaef RK |
3353 | { |
3354 | warning ("useless keyword or type name in empty declaration"); | |
3355 | warned = 2; | |
3356 | } | |
51e29401 RS |
3357 | } |
3358 | } | |
3359 | ||
773edaef RK |
3360 | if (found_tag > 1) |
3361 | error ("two types specified in one empty declaration"); | |
3362 | ||
3363 | if (warned != 1) | |
51e29401 | 3364 | { |
51e29401 RS |
3365 | if (found_tag == 0) |
3366 | pedwarn ("empty declaration"); | |
3367 | } | |
3368 | } | |
3369 | \f | |
3370 | /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ | |
3371 | ||
3372 | tree | |
3373 | groktypename (typename) | |
3374 | tree typename; | |
3375 | { | |
3376 | if (TREE_CODE (typename) != TREE_LIST) | |
3377 | return typename; | |
3378 | return grokdeclarator (TREE_VALUE (typename), | |
3379 | TREE_PURPOSE (typename), | |
3380 | TYPENAME, 0); | |
3381 | } | |
3382 | ||
3383 | /* Return a PARM_DECL node for a given pair of specs and declarator. */ | |
3384 | ||
3385 | tree | |
3386 | groktypename_in_parm_context (typename) | |
3387 | tree typename; | |
3388 | { | |
3389 | if (TREE_CODE (typename) != TREE_LIST) | |
3390 | return typename; | |
3391 | return grokdeclarator (TREE_VALUE (typename), | |
3392 | TREE_PURPOSE (typename), | |
3393 | PARM, 0); | |
3394 | } | |
3395 | ||
3396 | /* Decode a declarator in an ordinary declaration or data definition. | |
3397 | This is called as soon as the type information and variable name | |
3398 | have been parsed, before parsing the initializer if any. | |
3399 | Here we create the ..._DECL node, fill in its type, | |
3400 | and put it on the list of decls for the current context. | |
3401 | The ..._DECL node is returned as the value. | |
3402 | ||
3403 | Exception: for arrays where the length is not specified, | |
3404 | the type is left null, to be filled in by `finish_decl'. | |
3405 | ||
3406 | Function definitions do not come here; they go to start_function | |
3407 | instead. However, external and forward declarations of functions | |
3408 | do go through here. Structure field declarations are done by | |
3409 | grokfield and not through here. */ | |
3410 | ||
3411 | /* Set this to zero to debug not using the temporary obstack | |
3412 | to parse initializers. */ | |
3413 | int debug_temp_inits = 1; | |
3414 | ||
3415 | tree | |
3416 | start_decl (declarator, declspecs, initialized) | |
eaa81144 | 3417 | tree declarator, declspecs; |
51e29401 RS |
3418 | int initialized; |
3419 | { | |
3420 | register tree decl = grokdeclarator (declarator, declspecs, | |
3421 | NORMAL, initialized); | |
3422 | register tree tem; | |
3423 | int init_written = initialized; | |
3424 | ||
3425 | /* The corresponding pop_obstacks is in finish_decl. */ | |
3426 | push_obstacks_nochange (); | |
3427 | ||
3428 | if (initialized) | |
3429 | /* Is it valid for this decl to have an initializer at all? | |
3430 | If not, set INITIALIZED to zero, which will indirectly | |
3431 | tell `finish_decl' to ignore the initializer once it is parsed. */ | |
3432 | switch (TREE_CODE (decl)) | |
3433 | { | |
3434 | case TYPE_DECL: | |
3435 | /* typedef foo = bar means give foo the same type as bar. | |
3436 | We haven't parsed bar yet, so `finish_decl' will fix that up. | |
3437 | Any other case of an initialization in a TYPE_DECL is an error. */ | |
3438 | if (pedantic || list_length (declspecs) > 1) | |
3439 | { | |
3440 | error ("typedef `%s' is initialized", | |
3441 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3442 | initialized = 0; | |
3443 | } | |
3444 | break; | |
3445 | ||
3446 | case FUNCTION_DECL: | |
3447 | error ("function `%s' is initialized like a variable", | |
3448 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3449 | initialized = 0; | |
3450 | break; | |
3451 | ||
3452 | case PARM_DECL: | |
3453 | /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE. */ | |
3454 | error ("parameter `%s' is initialized", | |
3455 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3456 | initialized = 0; | |
3457 | break; | |
3458 | ||
3459 | default: | |
3460 | /* Don't allow initializations for incomplete types | |
3461 | except for arrays which might be completed by the initialization. */ | |
3462 | if (TYPE_SIZE (TREE_TYPE (decl)) != 0) | |
3463 | { | |
3464 | /* A complete type is ok if size is fixed. */ | |
3465 | ||
3466 | if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST | |
3467 | || C_DECL_VARIABLE_SIZE (decl)) | |
3468 | { | |
3469 | error ("variable-sized object may not be initialized"); | |
3470 | initialized = 0; | |
3471 | } | |
3472 | } | |
3473 | else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) | |
3474 | { | |
3475 | error ("variable `%s' has initializer but incomplete type", | |
3476 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3477 | initialized = 0; | |
3478 | } | |
3479 | else if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))) == 0) | |
3480 | { | |
3481 | error ("elements of array `%s' have incomplete type", | |
3482 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3483 | initialized = 0; | |
3484 | } | |
3485 | } | |
3486 | ||
3487 | if (initialized) | |
3488 | { | |
3489 | #if 0 /* Seems redundant with grokdeclarator. */ | |
3490 | if (current_binding_level != global_binding_level | |
1394aabd | 3491 | && DECL_EXTERNAL (decl) |
51e29401 RS |
3492 | && TREE_CODE (decl) != FUNCTION_DECL) |
3493 | warning ("declaration of `%s' has `extern' and is initialized", | |
3494 | IDENTIFIER_POINTER (DECL_NAME (decl))); | |
3495 | #endif | |
1394aabd | 3496 | DECL_EXTERNAL (decl) = 0; |
51e29401 RS |
3497 | if (current_binding_level == global_binding_level) |
3498 | TREE_STATIC (decl) = 1; | |
3499 | ||
3500 | /* Tell `pushdecl' this is an initialized decl | |
3501 | even though we don't yet have the initializer expression. | |
3502 | Also tell `finish_decl' it may store the real initializer. */ | |
3503 | DECL_INITIAL (decl) = error_mark_node; | |
3504 | } | |
3505 | ||
3506 | /* If this is a function declaration, write a record describing it to the | |
3507 | prototypes file (if requested). */ | |
3508 | ||
3509 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
3510 | gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0); | |
3511 | ||
3512 | /* Add this decl to the current binding level. | |
3513 | TEM may equal DECL or it may be a previous decl of the same name. */ | |
3514 | tem = pushdecl (decl); | |
3515 | ||
2c0d84d6 MS |
3516 | /* For C and Obective-C, we by default put things in .common when |
3517 | possible. */ | |
3518 | DECL_COMMON (tem) = 1; | |
3519 | ||
51e29401 RS |
3520 | /* For a local variable, define the RTL now. */ |
3521 | if (current_binding_level != global_binding_level | |
3522 | /* But not if this is a duplicate decl | |
3523 | and we preserved the rtl from the previous one | |
3524 | (which may or may not happen). */ | |
3525 | && DECL_RTL (tem) == 0) | |
3526 | { | |
3527 | if (TYPE_SIZE (TREE_TYPE (tem)) != 0) | |
3528 | expand_decl (tem); | |
3529 | else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE | |
3530 | && DECL_INITIAL (tem) != 0) | |
3531 | expand_decl (tem); | |
3532 | } | |
3533 | ||
3534 | if (init_written) | |
3535 | { | |
3536 | /* When parsing and digesting the initializer, | |
3537 | use temporary storage. Do this even if we will ignore the value. */ | |
3538 | if (current_binding_level == global_binding_level && debug_temp_inits) | |
3539 | temporary_allocation (); | |
3540 | } | |
3541 | ||
3542 | return tem; | |
3543 | } | |
3544 | ||
3545 | /* Finish processing of a declaration; | |
3546 | install its initial value. | |
3547 | If the length of an array type is not known before, | |
3548 | it must be determined now, from the initial value, or it is an error. */ | |
3549 | ||
3550 | void | |
3551 | finish_decl (decl, init, asmspec_tree) | |
3552 | tree decl, init; | |
3553 | tree asmspec_tree; | |
3554 | { | |
3555 | register tree type = TREE_TYPE (decl); | |
3556 | int was_incomplete = (DECL_SIZE (decl) == 0); | |
3557 | int temporary = allocation_temporary_p (); | |
3558 | char *asmspec = 0; | |
3559 | ||
72f5a12b | 3560 | /* If a name was specified, get the string. */ |
51e29401 | 3561 | if (asmspec_tree) |
72f5a12b | 3562 | asmspec = TREE_STRING_POINTER (asmspec_tree); |
51e29401 RS |
3563 | |
3564 | /* If `start_decl' didn't like having an initialization, ignore it now. */ | |
3565 | ||
3566 | if (init != 0 && DECL_INITIAL (decl) == 0) | |
3567 | init = 0; | |
3568 | /* Don't crash if parm is initialized. */ | |
3569 | if (TREE_CODE (decl) == PARM_DECL) | |
3570 | init = 0; | |
3571 | ||
519d591f RS |
3572 | if (ITERATOR_P (decl)) |
3573 | { | |
3574 | if (init == 0) | |
3575 | error_with_decl (decl, "iterator has no initial value"); | |
3576 | else | |
3577 | init = save_expr (init); | |
3578 | } | |
3579 | ||
51e29401 RS |
3580 | if (init) |
3581 | { | |
3582 | if (TREE_CODE (decl) != TYPE_DECL) | |
3583 | store_init_value (decl, init); | |
3584 | else | |
3585 | { | |
3586 | /* typedef foo = bar; store the type of bar as the type of foo. */ | |
3587 | TREE_TYPE (decl) = TREE_TYPE (init); | |
3588 | DECL_INITIAL (decl) = init = 0; | |
3589 | } | |
3590 | } | |
3591 | ||
7a0347ff RS |
3592 | /* Pop back to the obstack that is current for this binding level. |
3593 | This is because MAXINDEX, rtl, etc. to be made below | |
3594 | must go in the permanent obstack. But don't discard the | |
51e29401 | 3595 | temporary data yet. */ |
7a0347ff RS |
3596 | pop_obstacks (); |
3597 | #if 0 /* pop_obstacks was near the end; this is what was here. */ | |
51e29401 RS |
3598 | if (current_binding_level == global_binding_level && temporary) |
3599 | end_temporary_allocation (); | |
7a0347ff | 3600 | #endif |
51e29401 RS |
3601 | |
3602 | /* Deduce size of array from initialization, if not already known */ | |
3603 | ||
3604 | if (TREE_CODE (type) == ARRAY_TYPE | |
3605 | && TYPE_DOMAIN (type) == 0 | |
3606 | && TREE_CODE (decl) != TYPE_DECL) | |
3607 | { | |
3608 | int do_default | |
3609 | = (TREE_STATIC (decl) | |
3610 | /* Even if pedantic, an external linkage array | |
3611 | may have incomplete type at first. */ | |
3612 | ? pedantic && !TREE_PUBLIC (decl) | |
1394aabd | 3613 | : !DECL_EXTERNAL (decl)); |
51e29401 RS |
3614 | int failure |
3615 | = complete_array_type (type, DECL_INITIAL (decl), do_default); | |
3616 | ||
3617 | /* Get the completed type made by complete_array_type. */ | |
3618 | type = TREE_TYPE (decl); | |
3619 | ||
3620 | if (failure == 1) | |
3621 | error_with_decl (decl, "initializer fails to determine size of `%s'"); | |
3622 | ||
3623 | if (failure == 2) | |
3624 | { | |
3625 | if (do_default) | |
3626 | error_with_decl (decl, "array size missing in `%s'"); | |
b4892310 RS |
3627 | /* If a `static' var's size isn't known, |
3628 | make it extern as well as static, so it does not get | |
3629 | allocated. | |
3630 | If it is not `static', then do not mark extern; | |
3631 | finish_incomplete_decl will give it a default size | |
3632 | and it will get allocated. */ | |
3633 | else if (!pedantic && TREE_STATIC (decl) && ! TREE_PUBLIC (decl)) | |
1394aabd | 3634 | DECL_EXTERNAL (decl) = 1; |
51e29401 RS |
3635 | } |
3636 | ||
7e44eda6 JW |
3637 | /* TYPE_MAX_VALUE is always one less than the number of elements |
3638 | in the array, because we start counting at zero. Therefore, | |
3639 | warn only if the value is less than zero. */ | |
51e29401 | 3640 | if (pedantic && TYPE_DOMAIN (type) != 0 |
7e44eda6 | 3641 | && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0) |
6aa10371 | 3642 | error_with_decl (decl, "zero or negative size array `%s'"); |
51e29401 RS |
3643 | |
3644 | layout_decl (decl, 0); | |
3645 | } | |
3646 | ||
3647 | if (TREE_CODE (decl) == VAR_DECL) | |
3648 | { | |
d575f110 RS |
3649 | if (DECL_SIZE (decl) == 0 |
3650 | && TYPE_SIZE (TREE_TYPE (decl)) != 0) | |
3651 | layout_decl (decl, 0); | |
3652 | ||
a7f64d52 RS |
3653 | if (DECL_SIZE (decl) == 0 |
3654 | && (TREE_STATIC (decl) | |
3655 | ? | |
3656 | /* A static variable with an incomplete type | |
f3b4fb6e | 3657 | is an error if it is initialized. |
70efc776 | 3658 | Also if it is not file scope. |
a7f64d52 RS |
3659 | Otherwise, let it through, but if it is not `extern' |
3660 | then it may cause an error message later. */ | |
15317f89 JW |
3661 | /* We must use DECL_CONTEXT instead of current_binding_level, |
3662 | because a duplicate_decls call could have changed the binding | |
3663 | level of this decl. */ | |
3664 | (DECL_INITIAL (decl) != 0 || DECL_CONTEXT (decl) != 0) | |
a7f64d52 RS |
3665 | : |
3666 | /* An automatic variable with an incomplete type | |
3667 | is an error. */ | |
70038ec9 | 3668 | !DECL_EXTERNAL (decl))) |
51e29401 | 3669 | { |
51e29401 RS |
3670 | error_with_decl (decl, "storage size of `%s' isn't known"); |
3671 | TREE_TYPE (decl) = error_mark_node; | |
3672 | } | |
3673 | ||
1394aabd | 3674 | if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) |
90374cc2 | 3675 | && DECL_SIZE (decl) != 0) |
e681c5a1 RS |
3676 | { |
3677 | if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) | |
3678 | constant_expression_warning (DECL_SIZE (decl)); | |
3679 | else | |
3680 | error_with_decl (decl, "storage size of `%s' isn't constant"); | |
3681 | } | |
51e29401 RS |
3682 | } |
3683 | ||
3c4afaa5 | 3684 | /* If this is a function and an assembler name is specified, it isn't |
72f5a12b RK |
3685 | builtin any more. Also reset DECL_RTL so we can give it its new |
3686 | name. */ | |
3c4afaa5 | 3687 | if (TREE_CODE (decl) == FUNCTION_DECL && asmspec) |
72f5a12b RK |
3688 | { |
3689 | DECL_BUILT_IN (decl) = 0; | |
3690 | DECL_RTL (decl) = 0; | |
3691 | } | |
3c4afaa5 | 3692 | |
51e29401 RS |
3693 | /* Output the assembler code and/or RTL code for variables and functions, |
3694 | unless the type is an undefined structure or union. | |
3695 | If not, it will get done when the type is completed. */ | |
3696 | ||
3697 | if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL) | |
3698 | { | |
a98b1078 RK |
3699 | if ((flag_traditional || TREE_PERMANENT (decl)) |
3700 | && allocation_temporary_p ()) | |
51e29401 RS |
3701 | { |
3702 | push_obstacks_nochange (); | |
3703 | end_temporary_allocation (); | |
3704 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ | |
3705 | maybe_objc_check_decl (decl); | |
15317f89 | 3706 | rest_of_decl_compilation (decl, asmspec, DECL_CONTEXT (decl) == 0, |
51e29401 RS |
3707 | 0); |
3708 | pop_obstacks (); | |
3709 | } | |
3710 | else | |
3711 | { | |
3712 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ | |
3713 | maybe_objc_check_decl (decl); | |
15317f89 | 3714 | rest_of_decl_compilation (decl, asmspec, DECL_CONTEXT (decl) == 0, |
51e29401 RS |
3715 | 0); |
3716 | } | |
15317f89 | 3717 | if (DECL_CONTEXT (decl) != 0) |
51e29401 RS |
3718 | { |
3719 | /* Recompute the RTL of a local array now | |
3720 | if it used to be an incomplete type. */ | |
3721 | if (was_incomplete | |
1394aabd | 3722 | && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl)) |
51e29401 RS |
3723 | { |
3724 | /* If we used it already as memory, it must stay in memory. */ | |
3725 | TREE_ADDRESSABLE (decl) = TREE_USED (decl); | |
3726 | /* If it's still incomplete now, no init will save it. */ | |
3727 | if (DECL_SIZE (decl) == 0) | |
3728 | DECL_INITIAL (decl) = 0; | |
3729 | expand_decl (decl); | |
3730 | } | |
3731 | /* Compute and store the initial value. */ | |
42dfa47f RS |
3732 | if (TREE_CODE (decl) != FUNCTION_DECL) |
3733 | expand_decl_init (decl); | |
51e29401 RS |
3734 | } |
3735 | } | |
3736 | ||
3737 | if (TREE_CODE (decl) == TYPE_DECL) | |
3738 | { | |
3739 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ | |
3740 | maybe_objc_check_decl (decl); | |
15317f89 | 3741 | rest_of_decl_compilation (decl, NULL_PTR, DECL_CONTEXT (decl) == 0, |
51e29401 RS |
3742 | 0); |
3743 | } | |
3744 | ||
14f3e886 | 3745 | /* ??? After 2.3, test (init != 0) instead of TREE_CODE. */ |
3e755d23 JW |
3746 | /* This test used to include TREE_PERMANENT, however, we have the same |
3747 | problem with initializers at the function level. Such initializers get | |
3748 | saved until the end of the function on the momentary_obstack. */ | |
14f3e886 | 3749 | if (!(TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl)) |
3e755d23 | 3750 | && temporary |
eda115dd RS |
3751 | /* DECL_INITIAL is not defined in PARM_DECLs, since it shares |
3752 | space with DECL_ARG_TYPE. */ | |
3753 | && TREE_CODE (decl) != PARM_DECL) | |
51e29401 RS |
3754 | { |
3755 | /* We need to remember that this array HAD an initialization, | |
3756 | but discard the actual temporary nodes, | |
3757 | since we can't have a permanent node keep pointing to them. */ | |
14f3e886 RS |
3758 | /* We make an exception for inline functions, since it's |
3759 | normal for a local extern redeclaration of an inline function | |
3760 | to have a copy of the top-level decl's DECL_INLINE. */ | |
db57d413 | 3761 | if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node) |
549a367a | 3762 | { |
3e755d23 | 3763 | /* If this is a const variable, then preserve the |
549a367a JW |
3764 | initializer instead of discarding it so that we can optimize |
3765 | references to it. */ | |
3e755d23 JW |
3766 | /* This test used to include TREE_STATIC, but this won't be set |
3767 | for function level initializers. */ | |
3861b613 | 3768 | if (TREE_READONLY (decl) || ITERATOR_P (decl)) |
b4d4e33d RS |
3769 | { |
3770 | preserve_initializer (); | |
3771 | /* Hack? Set the permanent bit for something that is permanent, | |
3772 | but not on the permenent obstack, so as to convince | |
3773 | output_constant_def to make its rtl on the permanent | |
3774 | obstack. */ | |
3775 | TREE_PERMANENT (DECL_INITIAL (decl)) = 1; | |
7d49f92a RK |
3776 | |
3777 | /* The initializer and DECL must have the same (or equivalent | |
3778 | types), but if the initializer is a STRING_CST, its type | |
3779 | might not be on the right obstack, so copy the type | |
3780 | of DECL. */ | |
3781 | TREE_TYPE (DECL_INITIAL (decl)) = type; | |
b4d4e33d | 3782 | } |
549a367a JW |
3783 | else |
3784 | DECL_INITIAL (decl) = error_mark_node; | |
3785 | } | |
51e29401 RS |
3786 | } |
3787 | ||
739d15ab RK |
3788 | /* If requested, warn about definitions of large data objects. */ |
3789 | ||
3790 | if (warn_larger_than | |
3791 | && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) | |
3792 | && !DECL_EXTERNAL (decl)) | |
3793 | { | |
3794 | register tree decl_size = DECL_SIZE (decl); | |
3795 | ||
3796 | if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) | |
3797 | { | |
3798 | unsigned units = TREE_INT_CST_LOW(decl_size) / BITS_PER_UNIT; | |
3799 | ||
3800 | if (units > larger_than_size) | |
3801 | warning_with_decl (decl, "size of `%s' is %u bytes", units); | |
3802 | } | |
3803 | } | |
3804 | ||
7a0347ff | 3805 | #if 0 |
51e29401 RS |
3806 | /* Resume permanent allocation, if not within a function. */ |
3807 | /* The corresponding push_obstacks_nochange is in start_decl, | |
3808 | and in push_parm_decl and in grokfield. */ | |
3809 | pop_obstacks (); | |
7a0347ff RS |
3810 | #endif |
3811 | ||
3812 | /* If we have gone back from temporary to permanent allocation, | |
3813 | actually free the temporary space that we no longer need. */ | |
3814 | if (temporary && !allocation_temporary_p ()) | |
3e755d23 | 3815 | permanent_allocation (0); |
51e29401 RS |
3816 | |
3817 | /* At the end of a declaration, throw away any variable type sizes | |
3818 | of types defined inside that declaration. There is no use | |
3819 | computing them in the following function definition. */ | |
3820 | if (current_binding_level == global_binding_level) | |
3821 | get_pending_sizes (); | |
3822 | } | |
3823 | ||
3824 | /* If DECL has a cleanup, build and return that cleanup here. | |
3825 | This is a callback called by expand_expr. */ | |
3826 | ||
3827 | tree | |
3828 | maybe_build_cleanup (decl) | |
3829 | tree decl; | |
3830 | { | |
3831 | /* There are no cleanups in C. */ | |
3832 | return NULL_TREE; | |
3833 | } | |
3834 | ||
3835 | /* Given a parsed parameter declaration, | |
3836 | decode it into a PARM_DECL and push that on the current binding level. | |
3837 | Also, for the sake of forward parm decls, | |
3838 | record the given order of parms in `parm_order'. */ | |
3839 | ||
3840 | void | |
3841 | push_parm_decl (parm) | |
3842 | tree parm; | |
3843 | { | |
6cc902a1 | 3844 | tree decl; |
929f3671 RS |
3845 | int old_immediate_size_expand = immediate_size_expand; |
3846 | /* Don't try computing parm sizes now -- wait till fn is called. */ | |
3847 | immediate_size_expand = 0; | |
51e29401 RS |
3848 | |
3849 | /* The corresponding pop_obstacks is in finish_decl. */ | |
3850 | push_obstacks_nochange (); | |
3851 | ||
3852 | decl = grokdeclarator (TREE_VALUE (parm), TREE_PURPOSE (parm), PARM, 0); | |
6a5ed5bf RK |
3853 | |
3854 | #if 0 | |
93e3ba4f RS |
3855 | if (DECL_NAME (decl)) |
3856 | { | |
6cc902a1 | 3857 | tree olddecl; |
93e3ba4f RS |
3858 | olddecl = lookup_name (DECL_NAME (decl)); |
3859 | if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL) | |
3860 | pedwarn_with_decl (decl, "ANSI C forbids parameter `%s' shadowing typedef"); | |
3861 | } | |
6a5ed5bf RK |
3862 | #endif |
3863 | ||
51e29401 RS |
3864 | decl = pushdecl (decl); |
3865 | ||
929f3671 RS |
3866 | immediate_size_expand = old_immediate_size_expand; |
3867 | ||
51e29401 RS |
3868 | current_binding_level->parm_order |
3869 | = tree_cons (NULL_TREE, decl, current_binding_level->parm_order); | |
3870 | ||
3871 | /* Add this decl to the current binding level. */ | |
3872 | finish_decl (decl, NULL_TREE, NULL_TREE); | |
3873 | } | |
3874 | ||
3875 | /* Clear the given order of parms in `parm_order'. | |
3876 | Used at start of parm list, | |
3877 | and also at semicolon terminating forward decls. */ | |
3878 | ||
3879 | void | |
3880 | clear_parm_order () | |
3881 | { | |
3882 | current_binding_level->parm_order = NULL_TREE; | |
3883 | } | |
3884 | \f | |
3885 | /* Make TYPE a complete type based on INITIAL_VALUE. | |
929f3671 | 3886 | Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, |
51e29401 RS |
3887 | 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ |
3888 | ||
3889 | int | |
3890 | complete_array_type (type, initial_value, do_default) | |
3891 | tree type; | |
3892 | tree initial_value; | |
3893 | int do_default; | |
3894 | { | |
3895 | register tree maxindex = NULL_TREE; | |
3896 | int value = 0; | |
3897 | ||
3898 | if (initial_value) | |
3899 | { | |
3900 | /* Note MAXINDEX is really the maximum index, | |
3901 | one less than the size. */ | |
3902 | if (TREE_CODE (initial_value) == STRING_CST) | |
3903 | { | |
3904 | int eltsize | |
3905 | = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); | |
20bf3fac RS |
3906 | maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) |
3907 | / eltsize) - 1, 0); | |
51e29401 RS |
3908 | } |
3909 | else if (TREE_CODE (initial_value) == CONSTRUCTOR) | |
3910 | { | |
ecd4cee0 | 3911 | tree elts = CONSTRUCTOR_ELTS (initial_value); |
20bf3fac | 3912 | maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); |
ecd4cee0 RS |
3913 | for (; elts; elts = TREE_CHAIN (elts)) |
3914 | { | |
3915 | if (TREE_PURPOSE (elts)) | |
3916 | maxindex = TREE_PURPOSE (elts); | |
3917 | else | |
3918 | maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); | |
3919 | } | |
3920 | maxindex = copy_node (maxindex); | |
51e29401 RS |
3921 | } |
3922 | else | |
3923 | { | |
3924 | /* Make an error message unless that happened already. */ | |
3925 | if (initial_value != error_mark_node) | |
3926 | value = 1; | |
3927 | ||
3928 | /* Prevent further error messages. */ | |
b4892310 | 3929 | maxindex = build_int_2 (0, 0); |
51e29401 RS |
3930 | } |
3931 | } | |
3932 | ||
3933 | if (!maxindex) | |
3934 | { | |
3935 | if (do_default) | |
b4892310 | 3936 | maxindex = build_int_2 (0, 0); |
51e29401 RS |
3937 | value = 2; |
3938 | } | |
3939 | ||
3940 | if (maxindex) | |
3941 | { | |
3942 | TYPE_DOMAIN (type) = build_index_type (maxindex); | |
3943 | if (!TREE_TYPE (maxindex)) | |
3944 | TREE_TYPE (maxindex) = TYPE_DOMAIN (type); | |
f4e59008 RS |
3945 | #if 0 /* I took out this change |
3946 | together with the change in build_array_type. --rms */ | |
e1fe03e9 RS |
3947 | change_main_variant (type, |
3948 | build_array_type (TREE_TYPE (type), | |
3949 | TYPE_DOMAIN (type))); | |
f4e59008 | 3950 | #endif |
51e29401 RS |
3951 | } |
3952 | ||
3953 | /* Lay out the type now that we can get the real answer. */ | |
3954 | ||
3955 | layout_type (type); | |
3956 | ||
3957 | return value; | |
3958 | } | |
3959 | \f | |
3960 | /* Given declspecs and a declarator, | |
3961 | determine the name and type of the object declared | |
3962 | and construct a ..._DECL node for it. | |
3963 | (In one case we can return a ..._TYPE node instead. | |
3964 | For invalid input we sometimes return 0.) | |
3965 | ||
3966 | DECLSPECS is a chain of tree_list nodes whose value fields | |
3967 | are the storage classes and type specifiers. | |
3968 | ||
3969 | DECL_CONTEXT says which syntactic context this declaration is in: | |
3970 | NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. | |
3971 | FUNCDEF for a function definition. Like NORMAL but a few different | |
3972 | error messages in each case. Return value may be zero meaning | |
3973 | this definition is too screwy to try to parse. | |
3974 | PARM for a parameter declaration (either within a function prototype | |
3975 | or before a function body). Make a PARM_DECL, or return void_type_node. | |
3976 | TYPENAME if for a typename (in a cast or sizeof). | |
3977 | Don't make a DECL node; just return the ..._TYPE node. | |
3978 | FIELD for a struct or union field; make a FIELD_DECL. | |
3979 | BITFIELD for a field with specified width. | |
3980 | INITIALIZED is 1 if the decl has an initializer. | |
3981 | ||
3982 | In the TYPENAME case, DECLARATOR is really an absolute declarator. | |
3983 | It may also be so in the PARM case, for a prototype where the | |
3984 | argument type is specified but not the name. | |
3985 | ||
3986 | This function is where the complicated C meanings of `static' | |
929f3671 | 3987 | and `extern' are interpreted. */ |
51e29401 RS |
3988 | |
3989 | static tree | |
3990 | grokdeclarator (declarator, declspecs, decl_context, initialized) | |
3991 | tree declspecs; | |
3992 | tree declarator; | |
3993 | enum decl_context decl_context; | |
3994 | int initialized; | |
3995 | { | |
3996 | int specbits = 0; | |
3997 | tree spec; | |
3998 | tree type = NULL_TREE; | |
3999 | int longlong = 0; | |
4000 | int constp; | |
4001 | int volatilep; | |
4002 | int inlinep; | |
4003 | int explicit_int = 0; | |
4004 | int explicit_char = 0; | |
5ab10c42 | 4005 | int defaulted_int = 0; |
51e29401 RS |
4006 | tree typedef_decl = 0; |
4007 | char *name; | |
4008 | tree typedef_type = 0; | |
4009 | int funcdef_flag = 0; | |
4010 | enum tree_code innermost_code = ERROR_MARK; | |
4011 | int bitfield = 0; | |
929f3671 | 4012 | int size_varies = 0; |
51e29401 RS |
4013 | |
4014 | if (decl_context == BITFIELD) | |
4015 | bitfield = 1, decl_context = FIELD; | |
4016 | ||
4017 | if (decl_context == FUNCDEF) | |
4018 | funcdef_flag = 1, decl_context = NORMAL; | |
4019 | ||
4020 | push_obstacks_nochange (); | |
4021 | ||
4022 | if (flag_traditional && allocation_temporary_p ()) | |
4023 | end_temporary_allocation (); | |
4024 | ||
4025 | /* Look inside a declarator for the name being declared | |
4026 | and get it as a string, for an error message. */ | |
4027 | { | |
4028 | register tree decl = declarator; | |
4029 | name = 0; | |
4030 | ||
4031 | while (decl) | |
4032 | switch (TREE_CODE (decl)) | |
4033 | { | |
4034 | case ARRAY_REF: | |
4035 | case INDIRECT_REF: | |
4036 | case CALL_EXPR: | |
4037 | innermost_code = TREE_CODE (decl); | |
4038 | decl = TREE_OPERAND (decl, 0); | |
4039 | break; | |
4040 | ||
4041 | case IDENTIFIER_NODE: | |
4042 | name = IDENTIFIER_POINTER (decl); | |
4043 | decl = 0; | |
4044 | break; | |
4045 | ||
4046 | default: | |
4047 | abort (); | |
4048 | } | |
4049 | if (name == 0) | |
4050 | name = "type name"; | |
4051 | } | |
4052 | ||
4053 | /* A function definition's declarator must have the form of | |
4054 | a function declarator. */ | |
4055 | ||
4056 | if (funcdef_flag && innermost_code != CALL_EXPR) | |
4057 | return 0; | |
4058 | ||
4059 | /* Anything declared one level down from the top level | |
4060 | must be one of the parameters of a function | |
4061 | (because the body is at least two levels down). */ | |
4062 | ||
4063 | /* If this looks like a function definition, make it one, | |
4064 | even if it occurs where parms are expected. | |
4065 | Then store_parm_decls will reject it and not use it as a parm. */ | |
4066 | if (decl_context == NORMAL && !funcdef_flag | |
4067 | && current_binding_level->level_chain == global_binding_level) | |
4068 | decl_context = PARM; | |
4069 | ||
4070 | /* Look through the decl specs and record which ones appear. | |
4071 | Some typespecs are defined as built-in typenames. | |
4072 | Others, the ones that are modifiers of other types, | |
4073 | are represented by bits in SPECBITS: set the bits for | |
4074 | the modifiers that appear. Storage class keywords are also in SPECBITS. | |
4075 | ||
4076 | If there is a typedef name or a type, store the type in TYPE. | |
4077 | This includes builtin typedefs such as `int'. | |
4078 | ||
4079 | Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char' | |
4080 | and did not come from a user typedef. | |
4081 | ||
4082 | Set LONGLONG if `long' is mentioned twice. */ | |
4083 | ||
4084 | for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) | |
4085 | { | |
4086 | register int i; | |
4087 | register tree id = TREE_VALUE (spec); | |
4088 | ||
4089 | if (id == ridpointers[(int) RID_INT]) | |
4090 | explicit_int = 1; | |
4091 | if (id == ridpointers[(int) RID_CHAR]) | |
4092 | explicit_char = 1; | |
4093 | ||
4094 | if (TREE_CODE (id) == IDENTIFIER_NODE) | |
4095 | for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++) | |
4096 | { | |
4097 | if (ridpointers[i] == id) | |
4098 | { | |
4099 | if (i == (int) RID_LONG && specbits & (1<<i)) | |
4100 | { | |
89d7540d | 4101 | if (longlong) |
47429a02 | 4102 | error ("`long long long' is too long for GCC"); |
51e29401 | 4103 | else |
89d7540d | 4104 | { |
5db1a3c4 | 4105 | if (pedantic && ! in_system_header) |
89d7540d RS |
4106 | pedwarn ("ANSI C does not support `long long'"); |
4107 | longlong = 1; | |
4108 | } | |
51e29401 RS |
4109 | } |
4110 | else if (specbits & (1 << i)) | |
93e3ba4f | 4111 | pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); |
51e29401 RS |
4112 | specbits |= 1 << i; |
4113 | goto found; | |
4114 | } | |
4115 | } | |
4116 | if (type) | |
4117 | error ("two or more data types in declaration of `%s'", name); | |
4118 | /* Actual typedefs come to us as TYPE_DECL nodes. */ | |
4119 | else if (TREE_CODE (id) == TYPE_DECL) | |
4120 | { | |
4121 | type = TREE_TYPE (id); | |
4122 | typedef_decl = id; | |
4123 | } | |
4124 | /* Built-in types come as identifiers. */ | |
4125 | else if (TREE_CODE (id) == IDENTIFIER_NODE) | |
4126 | { | |
4127 | register tree t = lookup_name (id); | |
4128 | if (TREE_TYPE (t) == error_mark_node) | |
4129 | ; | |
4130 | else if (!t || TREE_CODE (t) != TYPE_DECL) | |
4131 | error ("`%s' fails to be a typedef or built in type", | |
4132 | IDENTIFIER_POINTER (id)); | |
4133 | else | |
4134 | { | |
4135 | type = TREE_TYPE (t); | |
4136 | typedef_decl = t; | |
4137 | } | |
4138 | } | |
4139 | else if (TREE_CODE (id) != ERROR_MARK) | |
4140 | type = id; | |
4141 | ||
4142 | found: {} | |
4143 | } | |
4144 | ||
4145 | typedef_type = type; | |
4146 | if (type) | |
929f3671 | 4147 | size_varies = C_TYPE_VARIABLE_SIZE (type); |
51e29401 | 4148 | |
5ab10c42 | 4149 | /* No type at all: default to `int', and set DEFAULTED_INT |
51e29401 RS |
4150 | because it was not a user-defined typedef. */ |
4151 | ||
4152 | if (type == 0) | |
4153 | { | |
4154 | if (funcdef_flag && warn_return_type | |
4155 | && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) | |
4156 | | (1 << (int) RID_SIGNED) | (1 << (int) RID_UNSIGNED)))) | |
4157 | warn_about_return_type = 1; | |
5ab10c42 | 4158 | defaulted_int = 1; |
51e29401 RS |
4159 | type = integer_type_node; |
4160 | } | |
4161 | ||
4162 | /* Now process the modifiers that were specified | |
4163 | and check for invalid combinations. */ | |
4164 | ||
4165 | /* Long double is a special combination. */ | |
4166 | ||
90d56da8 RS |
4167 | if ((specbits & 1 << (int) RID_LONG) |
4168 | && TYPE_MAIN_VARIANT (type) == double_type_node) | |
51e29401 RS |
4169 | { |
4170 | specbits &= ~ (1 << (int) RID_LONG); | |
4171 | type = long_double_type_node; | |
4172 | } | |
4173 | ||
4174 | /* Check all other uses of type modifiers. */ | |
4175 | ||
4176 | if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) | |
4177 | | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED))) | |
4178 | { | |
4179 | int ok = 0; | |
4180 | ||
4181 | if (TREE_CODE (type) != INTEGER_TYPE) | |
4182 | error ("long, short, signed or unsigned invalid for `%s'", name); | |
4183 | else if ((specbits & 1 << (int) RID_LONG) | |
4184 | && (specbits & 1 << (int) RID_SHORT)) | |
4185 | error ("long and short specified together for `%s'", name); | |
4186 | else if (((specbits & 1 << (int) RID_LONG) | |
4187 | || (specbits & 1 << (int) RID_SHORT)) | |
4188 | && explicit_char) | |
4189 | error ("long or short specified with char for `%s'", name); | |
4190 | else if (((specbits & 1 << (int) RID_LONG) | |
4191 | || (specbits & 1 << (int) RID_SHORT)) | |
4192 | && TREE_CODE (type) == REAL_TYPE) | |
4193 | error ("long or short specified with floating type for `%s'", name); | |
4194 | else if ((specbits & 1 << (int) RID_SIGNED) | |
4195 | && (specbits & 1 << (int) RID_UNSIGNED)) | |
4196 | error ("signed and unsigned given together for `%s'", name); | |
4197 | else | |
4198 | { | |
4199 | ok = 1; | |
5ab10c42 | 4200 | if (!explicit_int && !defaulted_int && !explicit_char && pedantic) |
51e29401 RS |
4201 | { |
4202 | pedwarn ("long, short, signed or unsigned used invalidly for `%s'", | |
4203 | name); | |
4204 | if (flag_pedantic_errors) | |
4205 | ok = 0; | |
4206 | } | |
4207 | } | |
4208 | ||
4209 | /* Discard the type modifiers if they are invalid. */ | |
4210 | if (! ok) | |
4211 | { | |
4212 | specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) | |
4213 | | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)); | |
4214 | longlong = 0; | |
4215 | } | |
4216 | } | |
4217 | ||
c470260b RK |
4218 | if ((specbits & (1 << (int) RID_COMPLEX)) |
4219 | && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) | |
4220 | { | |
4221 | error ("complex invalid for `%s'", name); | |
4222 | specbits &= ~ (1 << (int) RID_COMPLEX); | |
4223 | } | |
4224 | ||
51e29401 RS |
4225 | /* Decide whether an integer type is signed or not. |
4226 | Optionally treat bitfields as signed by default. */ | |
4227 | if (specbits & 1 << (int) RID_UNSIGNED | |
4228 | /* Traditionally, all bitfields are unsigned. */ | |
7a0347ff RS |
4229 | || (bitfield && flag_traditional |
4230 | && (! explicit_flag_signed_bitfields || !flag_signed_bitfields)) | |
51e29401 | 4231 | || (bitfield && ! flag_signed_bitfields |
5ab10c42 | 4232 | && (explicit_int || defaulted_int || explicit_char |
51e29401 RS |
4233 | /* A typedef for plain `int' without `signed' |
4234 | can be controlled just like plain `int'. */ | |
4235 | || ! (typedef_decl != 0 | |
4236 | && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
4237 | && TREE_CODE (type) != ENUMERAL_TYPE | |
4238 | && !(specbits & 1 << (int) RID_SIGNED))) | |
4239 | { | |
4240 | if (longlong) | |
4241 | type = long_long_unsigned_type_node; | |
4242 | else if (specbits & 1 << (int) RID_LONG) | |
4243 | type = long_unsigned_type_node; | |
4244 | else if (specbits & 1 << (int) RID_SHORT) | |
4245 | type = short_unsigned_type_node; | |
4246 | else if (type == char_type_node) | |
4247 | type = unsigned_char_type_node; | |
4248 | else if (typedef_decl) | |
4249 | type = unsigned_type (type); | |
4250 | else | |
4251 | type = unsigned_type_node; | |
4252 | } | |
4253 | else if ((specbits & 1 << (int) RID_SIGNED) | |
4254 | && type == char_type_node) | |
4255 | type = signed_char_type_node; | |
4256 | else if (longlong) | |
4257 | type = long_long_integer_type_node; | |
4258 | else if (specbits & 1 << (int) RID_LONG) | |
4259 | type = long_integer_type_node; | |
4260 | else if (specbits & 1 << (int) RID_SHORT) | |
4261 | type = short_integer_type_node; | |
c470260b RK |
4262 | |
4263 | if (specbits & 1 << (int) RID_COMPLEX) | |
5ab10c42 | 4264 | { |
c470260b RK |
4265 | /* If we just have "complex", it is equivalent to |
4266 | "complex double", but if any modifiers at all are specified it is | |
4267 | the complex form of TYPE. E.g, "complex short" is | |
4268 | "complex short int". */ | |
4269 | ||
4270 | if (defaulted_int && ! longlong | |
4271 | && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT) | |
4272 | | (1 << (int) RID_SIGNED) | |
4273 | | (1 << (int) RID_UNSIGNED)))) | |
5ab10c42 RS |
4274 | type = complex_double_type_node; |
4275 | else if (type == integer_type_node) | |
4276 | type = complex_integer_type_node; | |
4277 | else if (type == float_type_node) | |
4278 | type = complex_float_type_node; | |
4279 | else if (type == double_type_node) | |
4280 | type = complex_double_type_node; | |
4281 | else if (type == long_double_type_node) | |
4282 | type = complex_long_double_type_node; | |
4283 | else | |
c470260b | 4284 | type = build_complex_type (type); |
5ab10c42 | 4285 | } |
51e29401 RS |
4286 | |
4287 | /* Set CONSTP if this declaration is `const', whether by | |
4288 | explicit specification or via a typedef. | |
4289 | Likewise for VOLATILEP. */ | |
4290 | ||
4291 | constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type); | |
4292 | volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type); | |
4293 | inlinep = !! (specbits & (1 << (int) RID_INLINE)); | |
4294 | if (constp > 1) | |
93e3ba4f | 4295 | pedwarn ("duplicate `const'"); |
51e29401 | 4296 | if (volatilep > 1) |
93e3ba4f | 4297 | pedwarn ("duplicate `volatile'"); |
51e29401 RS |
4298 | if (! flag_gen_aux_info && (TYPE_READONLY (type) || TYPE_VOLATILE (type))) |
4299 | type = TYPE_MAIN_VARIANT (type); | |
4300 | ||
4301 | /* Warn if two storage classes are given. Default to `auto'. */ | |
4302 | ||
4303 | { | |
4304 | int nclasses = 0; | |
4305 | ||
4306 | if (specbits & 1 << (int) RID_AUTO) nclasses++; | |
4307 | if (specbits & 1 << (int) RID_STATIC) nclasses++; | |
4308 | if (specbits & 1 << (int) RID_EXTERN) nclasses++; | |
4309 | if (specbits & 1 << (int) RID_REGISTER) nclasses++; | |
4310 | if (specbits & 1 << (int) RID_TYPEDEF) nclasses++; | |
519d591f | 4311 | if (specbits & 1 << (int) RID_ITERATOR) nclasses++; |
51e29401 RS |
4312 | |
4313 | /* Warn about storage classes that are invalid for certain | |
4314 | kinds of declarations (parameters, typenames, etc.). */ | |
4315 | ||
4316 | if (nclasses > 1) | |
4317 | error ("multiple storage classes in declaration of `%s'", name); | |
4318 | else if (funcdef_flag | |
4319 | && (specbits | |
4320 | & ((1 << (int) RID_REGISTER) | |
4321 | | (1 << (int) RID_AUTO) | |
4322 | | (1 << (int) RID_TYPEDEF)))) | |
4323 | { | |
4324 | if (specbits & 1 << (int) RID_AUTO | |
4325 | && (pedantic || current_binding_level == global_binding_level)) | |
4326 | pedwarn ("function definition declared `auto'"); | |
4327 | if (specbits & 1 << (int) RID_REGISTER) | |
4328 | error ("function definition declared `register'"); | |
4329 | if (specbits & 1 << (int) RID_TYPEDEF) | |
4330 | error ("function definition declared `typedef'"); | |
4331 | specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER) | |
4332 | | (1 << (int) RID_AUTO)); | |
4333 | } | |
4334 | else if (decl_context != NORMAL && nclasses > 0) | |
4335 | { | |
4336 | if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER) | |
4337 | ; | |
4338 | else | |
4339 | { | |
4340 | error ((decl_context == FIELD | |
4341 | ? "storage class specified for structure field `%s'" | |
4342 | : (decl_context == PARM | |
4343 | ? "storage class specified for parameter `%s'" | |
4344 | : "storage class specified for typename")), | |
4345 | name); | |
4346 | specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER) | |
4347 | | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC) | |
4348 | | (1 << (int) RID_EXTERN)); | |
4349 | } | |
4350 | } | |
4351 | else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag) | |
4352 | { | |
4353 | /* `extern' with initialization is invalid if not at top level. */ | |
4354 | if (current_binding_level == global_binding_level) | |
4355 | warning ("`%s' initialized and declared `extern'", name); | |
4356 | else | |
4357 | error ("`%s' has both `extern' and initializer", name); | |
4358 | } | |
4359 | else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag | |
4360 | && current_binding_level != global_binding_level) | |
4361 | error ("nested function `%s' declared `extern'", name); | |
4362 | else if (current_binding_level == global_binding_level | |
4363 | && specbits & (1 << (int) RID_AUTO)) | |
4364 | error ("top-level declaration of `%s' specifies `auto'", name); | |
519d591f RS |
4365 | else if ((specbits & 1 << (int) RID_ITERATOR) |
4366 | && TREE_CODE (declarator) != IDENTIFIER_NODE) | |
4367 | { | |
4368 | error ("iterator `%s' has derived type", name); | |
4369 | type = error_mark_node; | |
4370 | } | |
4371 | else if ((specbits & 1 << (int) RID_ITERATOR) | |
4372 | && TREE_CODE (type) != INTEGER_TYPE) | |
4373 | { | |
4374 | error ("iterator `%s' has noninteger type", name); | |
4375 | type = error_mark_node; | |
4376 | } | |
51e29401 RS |
4377 | } |
4378 | ||
4379 | /* Now figure out the structure of the declarator proper. | |
4380 | Descend through it, creating more complex types, until we reach | |
4381 | the declared identifier (or NULL_TREE, in an absolute declarator). */ | |
4382 | ||
4383 | while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) | |
4384 | { | |
4385 | if (type == error_mark_node) | |
4386 | { | |
4387 | declarator = TREE_OPERAND (declarator, 0); | |
4388 | continue; | |
4389 | } | |
4390 | ||
4391 | /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), | |
4392 | an INDIRECT_REF (for *...), | |
4393 | a CALL_EXPR (for ...(...)), | |
4394 | an identifier (for the name being declared) | |
4395 | or a null pointer (for the place in an absolute declarator | |
4396 | where the name was omitted). | |
4397 | For the last two cases, we have just exited the loop. | |
4398 | ||
4399 | At this point, TYPE is the type of elements of an array, | |
4400 | or for a function to return, or for a pointer to point to. | |
4401 | After this sequence of ifs, TYPE is the type of the | |
4402 | array or function or pointer, and DECLARATOR has had its | |
4403 | outermost layer removed. */ | |
4404 | ||
4405 | if (TREE_CODE (declarator) == ARRAY_REF) | |
4406 | { | |
4407 | register tree itype = NULL_TREE; | |
4408 | register tree size = TREE_OPERAND (declarator, 1); | |
e0e2f469 JW |
4409 | /* An uninitialized decl with `extern' is a reference. */ |
4410 | int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN)); | |
1ff1a2d2 RK |
4411 | /* The index is a signed object `sizetype' bits wide. */ |
4412 | tree index_type = signed_type (sizetype); | |
51e29401 RS |
4413 | |
4414 | declarator = TREE_OPERAND (declarator, 0); | |
4415 | ||
4416 | /* Check for some types that there cannot be arrays of. */ | |
4417 | ||
5fe86b8b | 4418 | if (TYPE_MAIN_VARIANT (type) == void_type_node) |
51e29401 RS |
4419 | { |
4420 | error ("declaration of `%s' as array of voids", name); | |
4421 | type = error_mark_node; | |
4422 | } | |
4423 | ||
4424 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
4425 | { | |
4426 | error ("declaration of `%s' as array of functions", name); | |
4427 | type = error_mark_node; | |
4428 | } | |
4429 | ||
4430 | if (size == error_mark_node) | |
4431 | type = error_mark_node; | |
4432 | ||
4433 | if (type == error_mark_node) | |
4434 | continue; | |
4435 | ||
e0e2f469 JW |
4436 | /* If this is a block level extern, it must live past the end |
4437 | of the function so that we can check it against other extern | |
4438 | declarations (IDENTIFIER_LIMBO_VALUE). */ | |
4439 | if (extern_ref && allocation_temporary_p ()) | |
4440 | end_temporary_allocation (); | |
4441 | ||
51e29401 RS |
4442 | /* If size was specified, set ITYPE to a range-type for that size. |
4443 | Otherwise, ITYPE remains null. finish_decl may figure it out | |
4444 | from an initial value. */ | |
4445 | ||
4446 | if (size) | |
4447 | { | |
4448 | /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ | |
874a7be1 | 4449 | STRIP_TYPE_NOPS (size); |
51e29401 RS |
4450 | |
4451 | if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE | |
4452 | && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) | |
4453 | { | |
4454 | error ("size of array `%s' has non-integer type", name); | |
4455 | size = integer_one_node; | |
4456 | } | |
0a43d680 | 4457 | |
51e29401 RS |
4458 | if (pedantic && integer_zerop (size)) |
4459 | pedwarn ("ANSI C forbids zero-size array `%s'", name); | |
0a43d680 | 4460 | |
51e29401 RS |
4461 | if (TREE_CODE (size) == INTEGER_CST) |
4462 | { | |
90374cc2 | 4463 | constant_expression_warning (size); |
0a43d680 | 4464 | if (tree_int_cst_sgn (size) < 0) |
51e29401 RS |
4465 | { |
4466 | error ("size of array `%s' is negative", name); | |
4467 | size = integer_one_node; | |
4468 | } | |
51e29401 RS |
4469 | } |
4470 | else | |
4471 | { | |
0a43d680 RK |
4472 | /* Make sure the array size remains visibly nonconstant |
4473 | even if it is (eg) a const variable with known value. */ | |
4474 | size_varies = 1; | |
4475 | ||
51e29401 | 4476 | if (pedantic) |
1a6603da RS |
4477 | { |
4478 | if (TREE_CONSTANT (size)) | |
4479 | pedwarn ("ANSI C forbids array `%s' whose size can't be evaluated", name); | |
4480 | else | |
4481 | pedwarn ("ANSI C forbids variable-size array `%s'", name); | |
4482 | } | |
51e29401 | 4483 | } |
0a43d680 | 4484 | |
1ff1a2d2 | 4485 | /* Convert size to index_type, so that if it is a variable |
0a43d680 | 4486 | the computations will be done in the proper mode. */ |
1ff1a2d2 RK |
4487 | itype = fold (build (MINUS_EXPR, index_type, |
4488 | convert (index_type, size), | |
4489 | convert (index_type, size_one_node))); | |
0a43d680 RK |
4490 | |
4491 | if (size_varies) | |
4492 | itype = variable_size (itype); | |
4493 | itype = build_index_type (itype); | |
51e29401 RS |
4494 | } |
4495 | ||
4496 | #if 0 /* This had bad results for pointers to arrays, as in | |
4497 | union incomplete (*foo)[4]; */ | |
4498 | /* Complain about arrays of incomplete types, except in typedefs. */ | |
4499 | ||
4500 | if (TYPE_SIZE (type) == 0 | |
4501 | /* Avoid multiple warnings for nested array types. */ | |
4502 | && TREE_CODE (type) != ARRAY_TYPE | |
4503 | && !(specbits & (1 << (int) RID_TYPEDEF)) | |
4504 | && !C_TYPE_BEING_DEFINED (type)) | |
4505 | warning ("array type has incomplete element type"); | |
4506 | #endif | |
4507 | ||
51e29401 RS |
4508 | #if 0 /* We shouldn't have a function type here at all! |
4509 | Functions aren't allowed as array elements. */ | |
4510 | if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | |
4511 | && (constp || volatilep)) | |
4512 | pedwarn ("ANSI C forbids const or volatile function types"); | |
4513 | #endif | |
50e65854 JW |
4514 | |
4515 | /* Build the array type itself, then merge any constancy or | |
4516 | volatility into the target type. We must do it in this order | |
4517 | to ensure that the TYPE_MAIN_VARIANT field of the array type | |
4518 | is set correctly. */ | |
4519 | ||
4520 | type = build_array_type (type, itype); | |
51e29401 RS |
4521 | if (constp || volatilep) |
4522 | type = c_build_type_variant (type, constp, volatilep); | |
4523 | ||
4524 | #if 0 /* don't clear these; leave them set so that the array type | |
4525 | or the variable is itself const or volatile. */ | |
4526 | constp = 0; | |
4527 | volatilep = 0; | |
4528 | #endif | |
4529 | ||
929f3671 | 4530 | if (size_varies) |
51e29401 RS |
4531 | C_TYPE_VARIABLE_SIZE (type) = 1; |
4532 | } | |
4533 | else if (TREE_CODE (declarator) == CALL_EXPR) | |
4534 | { | |
fd0b8fce JW |
4535 | int extern_ref = (!(specbits & (1 << (int) RID_AUTO)) |
4536 | || current_binding_level == global_binding_level); | |
51e29401 RS |
4537 | tree arg_types; |
4538 | ||
4539 | /* Declaring a function type. | |
4540 | Make sure we have a valid type for the function to return. */ | |
4541 | if (type == error_mark_node) | |
4542 | continue; | |
4543 | ||
929f3671 | 4544 | size_varies = 0; |
51e29401 RS |
4545 | |
4546 | /* Warn about some types functions can't return. */ | |
4547 | ||
4548 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
4549 | { | |
4550 | error ("`%s' declared as function returning a function", name); | |
4551 | type = integer_type_node; | |
4552 | } | |
4553 | if (TREE_CODE (type) == ARRAY_TYPE) | |
4554 | { | |
4555 | error ("`%s' declared as function returning an array", name); | |
4556 | type = integer_type_node; | |
4557 | } | |
4558 | ||
4559 | #ifndef TRADITIONAL_RETURN_FLOAT | |
4560 | /* Traditionally, declaring return type float means double. */ | |
4561 | ||
90d56da8 | 4562 | if (flag_traditional && TYPE_MAIN_VARIANT (type) == float_type_node) |
51e29401 RS |
4563 | type = double_type_node; |
4564 | #endif /* TRADITIONAL_RETURN_FLOAT */ | |
4565 | ||
fd0b8fce JW |
4566 | /* If this is a block level extern, it must live past the end |
4567 | of the function so that we can check it against other extern | |
4568 | declarations (IDENTIFIER_LIMBO_VALUE). */ | |
4569 | if (extern_ref && allocation_temporary_p ()) | |
4570 | end_temporary_allocation (); | |
4571 | ||
51e29401 RS |
4572 | /* Construct the function type and go to the next |
4573 | inner layer of declarator. */ | |
4574 | ||
4575 | arg_types = grokparms (TREE_OPERAND (declarator, 1), | |
4576 | funcdef_flag | |
4577 | /* Say it's a definition | |
4578 | only for the CALL_EXPR | |
4579 | closest to the identifier. */ | |
4580 | && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE); | |
4581 | #if 0 /* This seems to be false. We turn off temporary allocation | |
4582 | above in this function if -traditional. | |
4583 | And this code caused inconsistent results with prototypes: | |
4584 | callers would ignore them, and pass arguments wrong. */ | |
4585 | ||
4586 | /* Omit the arg types if -traditional, since the arg types | |
4587 | and the list links might not be permanent. */ | |
8d9bfdc5 RK |
4588 | type = build_function_type (type, |
4589 | flag_traditional | |
4590 | ? NULL_TREE : arg_types); | |
51e29401 | 4591 | #endif |
61df2ee2 RS |
4592 | /* ANSI seems to say that `const int foo ();' |
4593 | does not make the function foo const. */ | |
4594 | if (constp || volatilep) | |
4595 | type = c_build_type_variant (type, constp, volatilep); | |
4596 | constp = 0; | |
4597 | volatilep = 0; | |
4598 | ||
51e29401 RS |
4599 | type = build_function_type (type, arg_types); |
4600 | declarator = TREE_OPERAND (declarator, 0); | |
4601 | ||
4602 | /* Set the TYPE_CONTEXTs for each tagged type which is local to | |
4603 | the formal parameter list of this FUNCTION_TYPE to point to | |
4604 | the FUNCTION_TYPE node itself. */ | |
4605 | ||
4606 | { | |
4607 | register tree link; | |
4608 | ||
4609 | for (link = current_function_parm_tags; | |
4610 | link; | |
4611 | link = TREE_CHAIN (link)) | |
4612 | TYPE_CONTEXT (TREE_VALUE (link)) = type; | |
4613 | } | |
4614 | } | |
4615 | else if (TREE_CODE (declarator) == INDIRECT_REF) | |
4616 | { | |
4617 | /* Merge any constancy or volatility into the target type | |
4618 | for the pointer. */ | |
4619 | ||
4620 | if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | |
4621 | && (constp || volatilep)) | |
4622 | pedwarn ("ANSI C forbids const or volatile function types"); | |
4623 | if (constp || volatilep) | |
4624 | type = c_build_type_variant (type, constp, volatilep); | |
4625 | constp = 0; | |
4626 | volatilep = 0; | |
929f3671 | 4627 | size_varies = 0; |
51e29401 RS |
4628 | |
4629 | type = build_pointer_type (type); | |
4630 | ||
4631 | /* Process a list of type modifier keywords | |
4632 | (such as const or volatile) that were given inside the `*'. */ | |
4633 | ||
4634 | if (TREE_TYPE (declarator)) | |
4635 | { | |
4636 | register tree typemodlist; | |
4637 | int erred = 0; | |
4638 | for (typemodlist = TREE_TYPE (declarator); typemodlist; | |
4639 | typemodlist = TREE_CHAIN (typemodlist)) | |
4640 | { | |
4641 | if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) | |
4642 | constp++; | |
4643 | else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) | |
4644 | volatilep++; | |
4645 | else if (!erred) | |
4646 | { | |
4647 | erred = 1; | |
4648 | error ("invalid type modifier within pointer declarator"); | |
4649 | } | |
4650 | } | |
4651 | if (constp > 1) | |
47429a02 | 4652 | pedwarn ("duplicate `const'"); |
51e29401 | 4653 | if (volatilep > 1) |
47429a02 | 4654 | pedwarn ("duplicate `volatile'"); |
51e29401 RS |
4655 | } |
4656 | ||
4657 | declarator = TREE_OPERAND (declarator, 0); | |
4658 | } | |
4659 | else | |
4660 | abort (); | |
4661 | ||
4662 | } | |
4663 | ||
4664 | /* Now TYPE has the actual type. */ | |
4665 | ||
4666 | /* If this is declaring a typedef name, return a TYPE_DECL. */ | |
4667 | ||
4668 | if (specbits & (1 << (int) RID_TYPEDEF)) | |
4669 | { | |
4670 | tree decl; | |
4671 | /* Note that the grammar rejects storage classes | |
4672 | in typenames, fields or parameters */ | |
4673 | if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | |
4674 | && (constp || volatilep)) | |
4675 | pedwarn ("ANSI C forbids const or volatile function types"); | |
4676 | if (constp || volatilep) | |
4677 | type = c_build_type_variant (type, constp, volatilep); | |
4678 | pop_obstacks (); | |
4679 | decl = build_decl (TYPE_DECL, declarator, type); | |
4680 | if ((specbits & (1 << (int) RID_SIGNED)) | |
4681 | || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) | |
4682 | C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; | |
4683 | return decl; | |
4684 | } | |
4685 | ||
4686 | /* Detect the case of an array type of unspecified size | |
4687 | which came, as such, direct from a typedef name. | |
4688 | We must copy the type, so that each identifier gets | |
4689 | a distinct type, so that each identifier's size can be | |
4690 | controlled separately by its own initializer. */ | |
4691 | ||
4692 | if (type != 0 && typedef_type != 0 | |
4693 | && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type) | |
4694 | && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0) | |
4695 | { | |
4696 | type = build_array_type (TREE_TYPE (type), 0); | |
929f3671 | 4697 | if (size_varies) |
51e29401 RS |
4698 | C_TYPE_VARIABLE_SIZE (type) = 1; |
4699 | } | |
4700 | ||
4701 | /* If this is a type name (such as, in a cast or sizeof), | |
4702 | compute the type and return it now. */ | |
4703 | ||
4704 | if (decl_context == TYPENAME) | |
4705 | { | |
4706 | /* Note that the grammar rejects storage classes | |
4707 | in typenames, fields or parameters */ | |
4708 | if (pedantic && TREE_CODE (type) == FUNCTION_TYPE | |
4709 | && (constp || volatilep)) | |
4710 | pedwarn ("ANSI C forbids const or volatile function types"); | |
4711 | if (constp || volatilep) | |
4712 | type = c_build_type_variant (type, constp, volatilep); | |
4713 | pop_obstacks (); | |
4714 | return type; | |
4715 | } | |
4716 | ||
61df2ee2 RS |
4717 | /* Aside from typedefs and type names (handle above), |
4718 | `void' at top level (not within pointer) | |
4719 | is allowed only in public variables. | |
51e29401 RS |
4720 | We don't complain about parms either, but that is because |
4721 | a better error message can be made later. */ | |
4722 | ||
61df2ee2 RS |
4723 | if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM |
4724 | && ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE) | |
4725 | && ((specbits & (1 << (int) RID_EXTERN)) | |
4726 | || (current_binding_level == global_binding_level | |
4727 | && !(specbits | |
4728 | & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER))))))) | |
51e29401 RS |
4729 | { |
4730 | error ("variable or field `%s' declared void", | |
4731 | IDENTIFIER_POINTER (declarator)); | |
4732 | type = integer_type_node; | |
4733 | } | |
4734 | ||
4735 | /* Now create the decl, which may be a VAR_DECL, a PARM_DECL | |
4736 | or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ | |
4737 | ||
4738 | { | |
4739 | register tree decl; | |
4740 | ||
4741 | if (decl_context == PARM) | |
4742 | { | |
4743 | tree type_as_written = type; | |
90d56da8 | 4744 | tree main_type; |
51e29401 RS |
4745 | |
4746 | /* A parameter declared as an array of T is really a pointer to T. | |
4747 | One declared as a function is really a pointer to a function. */ | |
4748 | ||
4749 | if (TREE_CODE (type) == ARRAY_TYPE) | |
4750 | { | |
4751 | /* Transfer const-ness of array into that of type pointed to. */ | |
eaf2e788 RS |
4752 | type = TREE_TYPE (type); |
4753 | if (constp || volatilep) | |
4754 | type = c_build_type_variant (type, constp, volatilep); | |
4755 | type = build_pointer_type (type); | |
51e29401 | 4756 | volatilep = constp = 0; |
929f3671 | 4757 | size_varies = 0; |
51e29401 RS |
4758 | } |
4759 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
4760 | { | |
4761 | if (pedantic && (constp || volatilep)) | |
4762 | pedwarn ("ANSI C forbids const or volatile function types"); | |
eaf2e788 RS |
4763 | if (constp || volatilep) |
4764 | type = c_build_type_variant (type, constp, volatilep); | |
4765 | type = build_pointer_type (type); | |
51e29401 RS |
4766 | volatilep = constp = 0; |
4767 | } | |
4768 | ||
51e29401 | 4769 | decl = build_decl (PARM_DECL, declarator, type); |
929f3671 | 4770 | if (size_varies) |
51e29401 RS |
4771 | C_DECL_VARIABLE_SIZE (decl) = 1; |
4772 | ||
4773 | /* Compute the type actually passed in the parmlist, | |
4774 | for the case where there is no prototype. | |
4775 | (For example, shorts and chars are passed as ints.) | |
4776 | When there is a prototype, this is overridden later. */ | |
4777 | ||
4778 | DECL_ARG_TYPE (decl) = type; | |
f537a5c5 RS |
4779 | main_type = (type == error_mark_node |
4780 | ? error_mark_node | |
4781 | : TYPE_MAIN_VARIANT (type)); | |
90d56da8 | 4782 | if (main_type == float_type_node) |
51e29401 | 4783 | DECL_ARG_TYPE (decl) = double_type_node; |
13d39dbc | 4784 | /* Don't use TYPE_PRECISION to decide whether to promote, |
8eebb258 RS |
4785 | because we should convert short if it's the same size as int, |
4786 | but we should not convert long if it's the same size as int. */ | |
f537a5c5 RS |
4787 | else if (TREE_CODE (main_type) != ERROR_MARK |
4788 | && C_PROMOTING_INTEGER_TYPE_P (main_type)) | |
8eebb258 RS |
4789 | { |
4790 | if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node) | |
4791 | && TREE_UNSIGNED (type)) | |
4792 | DECL_ARG_TYPE (decl) = unsigned_type_node; | |
4793 | else | |
4794 | DECL_ARG_TYPE (decl) = integer_type_node; | |
4795 | } | |
51e29401 RS |
4796 | |
4797 | DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written; | |
4798 | } | |
4799 | else if (decl_context == FIELD) | |
4800 | { | |
4801 | /* Structure field. It may not be a function. */ | |
4802 | ||
4803 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
4804 | { | |
4805 | error ("field `%s' declared as a function", | |
4806 | IDENTIFIER_POINTER (declarator)); | |
4807 | type = build_pointer_type (type); | |
4808 | } | |
4809 | else if (TREE_CODE (type) != ERROR_MARK && TYPE_SIZE (type) == 0) | |
4810 | { | |
4811 | error ("field `%s' has incomplete type", | |
4812 | IDENTIFIER_POINTER (declarator)); | |
4813 | type = error_mark_node; | |
4814 | } | |
4815 | /* Move type qualifiers down to element of an array. */ | |
4816 | if (TREE_CODE (type) == ARRAY_TYPE && (constp || volatilep)) | |
4817 | { | |
4818 | type = build_array_type (c_build_type_variant (TREE_TYPE (type), | |
4819 | constp, volatilep), | |
4820 | TYPE_DOMAIN (type)); | |
4821 | #if 0 /* Leave the field const or volatile as well. */ | |
4822 | constp = volatilep = 0; | |
4823 | #endif | |
4824 | } | |
4825 | decl = build_decl (FIELD_DECL, declarator, type); | |
929f3671 | 4826 | if (size_varies) |
51e29401 RS |
4827 | C_DECL_VARIABLE_SIZE (decl) = 1; |
4828 | } | |
4829 | else if (TREE_CODE (type) == FUNCTION_TYPE) | |
4830 | { | |
fd0b8fce JW |
4831 | /* Every function declaration is "external" |
4832 | except for those which are inside a function body | |
4833 | in which `auto' is used. | |
4834 | That is a case not specified by ANSI C, | |
4835 | and we use it for forward declarations for nested functions. */ | |
4836 | int extern_ref = (!(specbits & (1 << (int) RID_AUTO)) | |
4837 | || current_binding_level == global_binding_level); | |
4838 | ||
51e29401 RS |
4839 | if (specbits & (1 << (int) RID_AUTO) |
4840 | && (pedantic || current_binding_level == global_binding_level)) | |
4841 | pedwarn ("invalid storage class for function `%s'", | |
4842 | IDENTIFIER_POINTER (declarator)); | |
4843 | if (specbits & (1 << (int) RID_REGISTER)) | |
4844 | error ("invalid storage class for function `%s'", | |
4845 | IDENTIFIER_POINTER (declarator)); | |
4846 | /* Function declaration not at top level. | |
4847 | Storage classes other than `extern' are not allowed | |
4848 | and `extern' makes no difference. */ | |
4849 | if (current_binding_level != global_binding_level | |
4850 | && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE))) | |
4851 | && pedantic) | |
4852 | pedwarn ("invalid storage class for function `%s'", | |
4853 | IDENTIFIER_POINTER (declarator)); | |
fd0b8fce JW |
4854 | |
4855 | /* If this is a block level extern, it must live past the end | |
4856 | of the function so that we can check it against other | |
4857 | extern declarations (IDENTIFIER_LIMBO_VALUE). */ | |
4858 | if (extern_ref && allocation_temporary_p ()) | |
4859 | end_temporary_allocation (); | |
4860 | ||
51e29401 RS |
4861 | decl = build_decl (FUNCTION_DECL, declarator, type); |
4862 | ||
7a0347ff RS |
4863 | if (pedantic && (constp || volatilep) |
4864 | && ! DECL_IN_SYSTEM_HEADER (decl)) | |
51e29401 RS |
4865 | pedwarn ("ANSI C forbids const or volatile functions"); |
4866 | ||
61df2ee2 RS |
4867 | if (volatilep |
4868 | && TREE_TYPE (TREE_TYPE (decl)) != void_type_node) | |
11433f42 | 4869 | warning ("`noreturn' function returns non-void value"); |
61df2ee2 | 4870 | |
fd0b8fce | 4871 | if (extern_ref) |
1394aabd | 4872 | DECL_EXTERNAL (decl) = 1; |
51e29401 RS |
4873 | /* Record absence of global scope for `static' or `auto'. */ |
4874 | TREE_PUBLIC (decl) | |
4875 | = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO))); | |
4876 | /* Record presence of `inline', if it is reasonable. */ | |
4877 | if (inlinep) | |
4878 | { | |
4879 | tree last = tree_last (TYPE_ARG_TYPES (type)); | |
4880 | ||
4881 | if (! strcmp (IDENTIFIER_POINTER (declarator), "main")) | |
4882 | warning ("cannot inline function `main'"); | |
5fe86b8b RS |
4883 | else if (last && (TYPE_MAIN_VARIANT (TREE_VALUE (last)) |
4884 | != void_type_node)) | |
51e29401 RS |
4885 | warning ("inline declaration ignored for function with `...'"); |
4886 | else | |
4887 | /* Assume that otherwise the function can be inlined. */ | |
1394aabd | 4888 | DECL_INLINE (decl) = 1; |
51e29401 RS |
4889 | |
4890 | if (specbits & (1 << (int) RID_EXTERN)) | |
4891 | current_extern_inline = 1; | |
4892 | } | |
4893 | } | |
4894 | else | |
4895 | { | |
4896 | /* It's a variable. */ | |
fd0b8fce JW |
4897 | /* An uninitialized decl with `extern' is a reference. */ |
4898 | int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN)); | |
51e29401 RS |
4899 | |
4900 | /* Move type qualifiers down to element of an array. */ | |
4901 | if (TREE_CODE (type) == ARRAY_TYPE && (constp || volatilep)) | |
4902 | { | |
4903 | type = build_array_type (c_build_type_variant (TREE_TYPE (type), | |
4904 | constp, volatilep), | |
4905 | TYPE_DOMAIN (type)); | |
4906 | #if 0 /* Leave the variable const or volatile as well. */ | |
4907 | constp = volatilep = 0; | |
4908 | #endif | |
4909 | } | |
4910 | ||
fd0b8fce JW |
4911 | /* If this is a block level extern, it must live past the end |
4912 | of the function so that we can check it against other | |
4913 | extern declarations (IDENTIFIER_LIMBO_VALUE). */ | |
4914 | if (extern_ref && allocation_temporary_p ()) | |
4915 | end_temporary_allocation (); | |
4916 | ||
51e29401 | 4917 | decl = build_decl (VAR_DECL, declarator, type); |
929f3671 | 4918 | if (size_varies) |
51e29401 RS |
4919 | C_DECL_VARIABLE_SIZE (decl) = 1; |
4920 | ||
4921 | if (inlinep) | |
4922 | pedwarn_with_decl (decl, "variable `%s' declared `inline'"); | |
4923 | ||
fd0b8fce | 4924 | DECL_EXTERNAL (decl) = extern_ref; |
ee534ebf RS |
4925 | /* At top level, the presence of a `static' or `register' storage |
4926 | class specifier, or the absence of all storage class specifiers | |
4927 | makes this declaration a definition (perhaps tentative). Also, | |
4928 | the absence of both `static' and `register' makes it public. */ | |
51e29401 RS |
4929 | if (current_binding_level == global_binding_level) |
4930 | { | |
ee534ebf RS |
4931 | TREE_PUBLIC (decl) |
4932 | = !(specbits | |
4933 | & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER))); | |
1394aabd | 4934 | TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); |
51e29401 RS |
4935 | } |
4936 | /* Not at top level, only `static' makes a static definition. */ | |
4937 | else | |
4938 | { | |
4939 | TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0; | |
1394aabd | 4940 | TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); |
51e29401 | 4941 | } |
519d591f RS |
4942 | |
4943 | if (specbits & 1 << (int) RID_ITERATOR) | |
4944 | ITERATOR_P (decl) = 1; | |
51e29401 RS |
4945 | } |
4946 | ||
4947 | /* Record `register' declaration for warnings on & | |
4948 | and in case doing stupid register allocation. */ | |
4949 | ||
4950 | if (specbits & (1 << (int) RID_REGISTER)) | |
1394aabd | 4951 | DECL_REGISTER (decl) = 1; |
51e29401 RS |
4952 | |
4953 | /* Record constancy and volatility. */ | |
4954 | ||
4955 | if (constp) | |
4956 | TREE_READONLY (decl) = 1; | |
4957 | if (volatilep) | |
4958 | { | |
4959 | TREE_SIDE_EFFECTS (decl) = 1; | |
4960 | TREE_THIS_VOLATILE (decl) = 1; | |
4961 | } | |
4962 | /* If a type has volatile components, it should be stored in memory. | |
4963 | Otherwise, the fact that those components are volatile | |
4964 | will be ignored, and would even crash the compiler. */ | |
4965 | if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))) | |
4966 | mark_addressable (decl); | |
4967 | ||
4968 | pop_obstacks (); | |
4969 | ||
4970 | return decl; | |
4971 | } | |
4972 | } | |
4973 | \f | |
51e29401 RS |
4974 | /* Decode the parameter-list info for a function type or function definition. |
4975 | The argument is the value returned by `get_parm_info' (or made in parse.y | |
4976 | if there is an identifier list instead of a parameter decl list). | |
4977 | These two functions are separate because when a function returns | |
4978 | or receives functions then each is called multiple times but the order | |
4979 | of calls is different. The last call to `grokparms' is always the one | |
4980 | that contains the formal parameter names of a function definition. | |
4981 | ||
4982 | Store in `last_function_parms' a chain of the decls of parms. | |
4983 | Also store in `last_function_parm_tags' a chain of the struct, union, | |
4984 | and enum tags declared among the parms. | |
4985 | ||
4986 | Return a list of arg types to use in the FUNCTION_TYPE for this function. | |
4987 | ||
4988 | FUNCDEF_FLAG is nonzero for a function definition, 0 for | |
4989 | a mere declaration. A nonempty identifier-list gets an error message | |
4990 | when FUNCDEF_FLAG is zero. */ | |
4991 | ||
4992 | static tree | |
4993 | grokparms (parms_info, funcdef_flag) | |
4994 | tree parms_info; | |
4995 | int funcdef_flag; | |
4996 | { | |
4997 | tree first_parm = TREE_CHAIN (parms_info); | |
4998 | ||
4999 | last_function_parms = TREE_PURPOSE (parms_info); | |
5000 | last_function_parm_tags = TREE_VALUE (parms_info); | |
5001 | ||
27f427f8 RS |
5002 | if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag |
5003 | && !in_system_header) | |
51e29401 RS |
5004 | warning ("function declaration isn't a prototype"); |
5005 | ||
5006 | if (first_parm != 0 | |
5007 | && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) | |
5008 | { | |
5009 | if (! funcdef_flag) | |
5010 | pedwarn ("parameter names (without types) in function declaration"); | |
5011 | ||
5012 | last_function_parms = first_parm; | |
5013 | return 0; | |
5014 | } | |
5015 | else | |
5016 | { | |
5017 | tree parm; | |
5018 | tree typelt; | |
5019 | /* We no longer test FUNCDEF_FLAG. | |
5020 | If the arg types are incomplete in a declaration, | |
5021 | they must include undefined tags. | |
5022 | These tags can never be defined in the scope of the declaration, | |
5023 | so the types can never be completed, | |
5024 | and no call can be compiled successfully. */ | |
5025 | #if 0 | |
5026 | /* In a fcn definition, arg types must be complete. */ | |
5027 | if (funcdef_flag) | |
5028 | #endif | |
5029 | for (parm = last_function_parms, typelt = first_parm; | |
5030 | parm; | |
5031 | parm = TREE_CHAIN (parm)) | |
5032 | /* Skip over any enumeration constants declared here. */ | |
5033 | if (TREE_CODE (parm) == PARM_DECL) | |
5034 | { | |
5035 | /* Barf if the parameter itself has an incomplete type. */ | |
5036 | tree type = TREE_VALUE (typelt); | |
5037 | if (TYPE_SIZE (type) == 0) | |
5038 | { | |
5039 | if (funcdef_flag && DECL_NAME (parm) != 0) | |
5040 | error ("parameter `%s' has incomplete type", | |
5041 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
5042 | else | |
5043 | warning ("parameter has incomplete type"); | |
5044 | if (funcdef_flag) | |
5045 | { | |
5046 | TREE_VALUE (typelt) = error_mark_node; | |
5047 | TREE_TYPE (parm) = error_mark_node; | |
5048 | } | |
5049 | } | |
5050 | #if 0 /* This has been replaced by parm_tags_warning | |
5051 | which uses a more accurate criterion for what to warn about. */ | |
5052 | else | |
5053 | { | |
5054 | /* Now warn if is a pointer to an incomplete type. */ | |
5055 | while (TREE_CODE (type) == POINTER_TYPE | |
5056 | || TREE_CODE (type) == REFERENCE_TYPE) | |
5057 | type = TREE_TYPE (type); | |
5058 | type = TYPE_MAIN_VARIANT (type); | |
5059 | if (TYPE_SIZE (type) == 0) | |
5060 | { | |
5061 | if (DECL_NAME (parm) != 0) | |
5062 | warning ("parameter `%s' points to incomplete type", | |
5063 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
5064 | else | |
5065 | warning ("parameter points to incomplete type"); | |
5066 | } | |
5067 | } | |
5068 | #endif | |
5069 | typelt = TREE_CHAIN (typelt); | |
5070 | } | |
5071 | ||
023de292 | 5072 | /* Allocate the list of types the way we allocate a type. */ |
c47851dd | 5073 | if (first_parm && ! TREE_PERMANENT (first_parm)) |
023de292 RS |
5074 | { |
5075 | /* Construct a copy of the list of types | |
5076 | on the saveable obstack. */ | |
5077 | tree result = NULL; | |
5078 | for (typelt = first_parm; typelt; typelt = TREE_CHAIN (typelt)) | |
5079 | result = saveable_tree_cons (NULL_TREE, TREE_VALUE (typelt), | |
5080 | result); | |
5081 | return nreverse (result); | |
5082 | } | |
5083 | else | |
5084 | /* The list we have is permanent already. */ | |
5085 | return first_parm; | |
51e29401 RS |
5086 | } |
5087 | } | |
5088 | ||
5089 | ||
5090 | /* Return a tree_list node with info on a parameter list just parsed. | |
5091 | The TREE_PURPOSE is a chain of decls of those parms. | |
5092 | The TREE_VALUE is a list of structure, union and enum tags defined. | |
5093 | The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE. | |
5094 | This tree_list node is later fed to `grokparms'. | |
5095 | ||
5096 | VOID_AT_END nonzero means append `void' to the end of the type-list. | |
5097 | Zero means the parmlist ended with an ellipsis so don't append `void'. */ | |
5098 | ||
5099 | tree | |
5100 | get_parm_info (void_at_end) | |
5101 | int void_at_end; | |
5102 | { | |
5103 | register tree decl, t; | |
5104 | register tree types = 0; | |
5105 | int erred = 0; | |
5106 | tree tags = gettags (); | |
5107 | tree parms = getdecls (); | |
5108 | tree new_parms = 0; | |
5109 | tree order = current_binding_level->parm_order; | |
5110 | ||
5111 | /* Just `void' (and no ellipsis) is special. There are really no parms. */ | |
5112 | if (void_at_end && parms != 0 | |
5113 | && TREE_CHAIN (parms) == 0 | |
5fe86b8b | 5114 | && TYPE_MAIN_VARIANT (TREE_TYPE (parms)) == void_type_node |
51e29401 RS |
5115 | && DECL_NAME (parms) == 0) |
5116 | { | |
5117 | parms = NULL_TREE; | |
5118 | storedecls (NULL_TREE); | |
5119 | return saveable_tree_cons (NULL_TREE, NULL_TREE, | |
5120 | saveable_tree_cons (NULL_TREE, void_type_node, NULL_TREE)); | |
5121 | } | |
5122 | ||
fc3ffe83 RK |
5123 | /* Extract enumerator values and other non-parms declared with the parms. |
5124 | Likewise any forward parm decls that didn't have real parm decls. */ | |
51e29401 RS |
5125 | for (decl = parms; decl; ) |
5126 | { | |
5127 | tree next = TREE_CHAIN (decl); | |
5128 | ||
e38e5ba8 | 5129 | if (TREE_CODE (decl) != PARM_DECL) |
fc3ffe83 | 5130 | { |
fc3ffe83 RK |
5131 | TREE_CHAIN (decl) = new_parms; |
5132 | new_parms = decl; | |
5133 | } | |
e38e5ba8 | 5134 | else if (TREE_ASM_WRITTEN (decl)) |
51e29401 | 5135 | { |
e38e5ba8 | 5136 | error_with_decl (decl, "parameter `%s' has just a forward declaration"); |
51e29401 RS |
5137 | TREE_CHAIN (decl) = new_parms; |
5138 | new_parms = decl; | |
5139 | } | |
5140 | decl = next; | |
5141 | } | |
5142 | ||
5143 | /* Put the parm decls back in the order they were in in the parm list. */ | |
5144 | for (t = order; t; t = TREE_CHAIN (t)) | |
5145 | { | |
5146 | if (TREE_CHAIN (t)) | |
5147 | TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t)); | |
5148 | else | |
5149 | TREE_CHAIN (TREE_VALUE (t)) = 0; | |
5150 | } | |
5151 | ||
5152 | new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0, | |
5153 | new_parms); | |
5154 | ||
5155 | /* Store the parmlist in the binding level since the old one | |
5156 | is no longer a valid list. (We have changed the chain pointers.) */ | |
5157 | storedecls (new_parms); | |
5158 | ||
5159 | for (decl = new_parms; decl; decl = TREE_CHAIN (decl)) | |
5160 | /* There may also be declarations for enumerators if an enumeration | |
5161 | type is declared among the parms. Ignore them here. */ | |
5162 | if (TREE_CODE (decl) == PARM_DECL) | |
5163 | { | |
5164 | /* Since there is a prototype, | |
5165 | args are passed in their declared types. */ | |
5166 | tree type = TREE_TYPE (decl); | |
5167 | DECL_ARG_TYPE (decl) = type; | |
5168 | #ifdef PROMOTE_PROTOTYPES | |
fd48df3e RK |
5169 | if ((TREE_CODE (type) == INTEGER_TYPE |
5170 | || TREE_CODE (type) == ENUMERAL_TYPE) | |
51e29401 RS |
5171 | && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) |
5172 | DECL_ARG_TYPE (decl) = integer_type_node; | |
5173 | #endif | |
5174 | ||
5175 | types = saveable_tree_cons (NULL_TREE, TREE_TYPE (decl), types); | |
5fe86b8b | 5176 | if (TYPE_MAIN_VARIANT (TREE_VALUE (types)) == void_type_node && ! erred |
51e29401 RS |
5177 | && DECL_NAME (decl) == 0) |
5178 | { | |
5179 | error ("`void' in parameter list must be the entire list"); | |
5180 | erred = 1; | |
5181 | } | |
5182 | } | |
5183 | ||
5184 | if (void_at_end) | |
5185 | return saveable_tree_cons (new_parms, tags, | |
5186 | nreverse (saveable_tree_cons (NULL_TREE, void_type_node, types))); | |
5187 | ||
5188 | return saveable_tree_cons (new_parms, tags, nreverse (types)); | |
5189 | } | |
5190 | ||
5191 | /* At end of parameter list, warn about any struct, union or enum tags | |
5192 | defined within. Do so because these types cannot ever become complete. */ | |
5193 | ||
5194 | void | |
5195 | parmlist_tags_warning () | |
5196 | { | |
5197 | tree elt; | |
5198 | static int already; | |
5199 | ||
5200 | for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt)) | |
5201 | { | |
5202 | enum tree_code code = TREE_CODE (TREE_VALUE (elt)); | |
27301b30 RS |
5203 | /* An anonymous union parm type is meaningful as a GNU extension. |
5204 | So don't warn for that. */ | |
5205 | if (code == UNION_TYPE && !pedantic) | |
5206 | continue; | |
c138f328 RS |
5207 | if (TREE_PURPOSE (elt) != 0) |
5208 | warning ("`%s %s' declared inside parameter list", | |
5209 | (code == RECORD_TYPE ? "struct" | |
5210 | : code == UNION_TYPE ? "union" | |
5211 | : "enum"), | |
5212 | IDENTIFIER_POINTER (TREE_PURPOSE (elt))); | |
5213 | else | |
5214 | warning ("anonymous %s declared inside parameter list", | |
5215 | (code == RECORD_TYPE ? "struct" | |
5216 | : code == UNION_TYPE ? "union" | |
5217 | : "enum")); | |
5218 | ||
51e29401 RS |
5219 | if (! already) |
5220 | { | |
5221 | warning ("its scope is only this definition or declaration,"); | |
5222 | warning ("which is probably not what you want."); | |
5223 | already = 1; | |
5224 | } | |
5225 | } | |
5226 | } | |
5227 | \f | |
5228 | /* Get the struct, enum or union (CODE says which) with tag NAME. | |
5229 | Define the tag as a forward-reference if it is not defined. */ | |
5230 | ||
5231 | tree | |
5232 | xref_tag (code, name) | |
5233 | enum tree_code code; | |
5234 | tree name; | |
5235 | { | |
5236 | int temporary = allocation_temporary_p (); | |
5237 | ||
5238 | /* If a cross reference is requested, look up the type | |
5239 | already defined for this tag and return it. */ | |
5240 | ||
5241 | register tree ref = lookup_tag (code, name, current_binding_level, 0); | |
5242 | /* Even if this is the wrong type of tag, return what we found. | |
5243 | There will be an error message anyway, from pending_xref_error. | |
5244 | If we create an empty xref just for an invalid use of the type, | |
929f3671 | 5245 | the main result is to create lots of superfluous error messages. */ |
51e29401 RS |
5246 | if (ref) |
5247 | return ref; | |
5248 | ||
5249 | push_obstacks_nochange (); | |
5250 | ||
5251 | if (current_binding_level == global_binding_level && temporary) | |
5252 | end_temporary_allocation (); | |
5253 | ||
5254 | /* If no such tag is yet defined, create a forward-reference node | |
5255 | and record it as the "definition". | |
5256 | When a real declaration of this type is found, | |
5257 | the forward-reference will be altered into a real type. */ | |
5258 | ||
5259 | ref = make_node (code); | |
5260 | if (code == ENUMERAL_TYPE) | |
5261 | { | |
5262 | /* (In ANSI, Enums can be referred to only if already defined.) */ | |
5263 | if (pedantic) | |
5264 | pedwarn ("ANSI C forbids forward references to `enum' types"); | |
5265 | /* Give the type a default layout like unsigned int | |
5266 | to avoid crashing if it does not get defined. */ | |
5267 | TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); | |
5268 | TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); | |
5269 | TREE_UNSIGNED (ref) = 1; | |
5270 | TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); | |
5271 | TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); | |
5272 | TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); | |
5273 | } | |
5274 | ||
5275 | pushtag (name, ref); | |
5276 | ||
5277 | pop_obstacks (); | |
5278 | ||
5279 | return ref; | |
5280 | } | |
5281 | \f | |
5282 | /* Make sure that the tag NAME is defined *in the current binding level* | |
5283 | at least as a forward reference. | |
7a0347ff RS |
5284 | CODE says which kind of tag NAME ought to be. |
5285 | ||
5286 | We also do a push_obstacks_nochange | |
5287 | whose matching pop is in finish_struct. */ | |
51e29401 RS |
5288 | |
5289 | tree | |
5290 | start_struct (code, name) | |
5291 | enum tree_code code; | |
5292 | tree name; | |
5293 | { | |
5294 | /* If there is already a tag defined at this binding level | |
5295 | (as a forward reference), just return it. */ | |
5296 | ||
5297 | register tree ref = 0; | |
5298 | ||
7a0347ff RS |
5299 | push_obstacks_nochange (); |
5300 | if (current_binding_level == global_binding_level) | |
5301 | end_temporary_allocation (); | |
5302 | ||
51e29401 RS |
5303 | if (name != 0) |
5304 | ref = lookup_tag (code, name, current_binding_level, 1); | |
5305 | if (ref && TREE_CODE (ref) == code) | |
5306 | { | |
5307 | C_TYPE_BEING_DEFINED (ref) = 1; | |
5308 | if (TYPE_FIELDS (ref)) | |
5309 | error ((code == UNION_TYPE ? "redefinition of `union %s'" | |
5310 | : "redefinition of `struct %s'"), | |
5311 | IDENTIFIER_POINTER (name)); | |
5312 | ||
5313 | return ref; | |
5314 | } | |
5315 | ||
5316 | /* Otherwise create a forward-reference just so the tag is in scope. */ | |
5317 | ||
5318 | ref = make_node (code); | |
5319 | pushtag (name, ref); | |
5320 | C_TYPE_BEING_DEFINED (ref) = 1; | |
5321 | return ref; | |
5322 | } | |
5323 | ||
5324 | /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted) | |
5325 | of a structure component, returning a FIELD_DECL node. | |
5326 | WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. | |
5327 | ||
5328 | This is done during the parsing of the struct declaration. | |
5329 | The FIELD_DECL nodes are chained together and the lot of them | |
5330 | are ultimately passed to `build_struct' to make the RECORD_TYPE node. */ | |
5331 | ||
5332 | tree | |
5333 | grokfield (filename, line, declarator, declspecs, width) | |
5334 | char *filename; | |
5335 | int line; | |
5336 | tree declarator, declspecs, width; | |
5337 | { | |
5338 | tree value; | |
5339 | ||
5340 | /* The corresponding pop_obstacks is in finish_decl. */ | |
5341 | push_obstacks_nochange (); | |
5342 | ||
5343 | value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0); | |
5344 | ||
8d9bfdc5 | 5345 | finish_decl (value, NULL_TREE, NULL_TREE); |
51e29401 RS |
5346 | DECL_INITIAL (value) = width; |
5347 | ||
abe31bf8 | 5348 | maybe_objc_check_decl (value); |
51e29401 RS |
5349 | return value; |
5350 | } | |
5351 | \f | |
5352 | /* Function to help qsort sort FIELD_DECLs by name order. */ | |
5353 | ||
5354 | static int | |
5355 | field_decl_cmp (x, y) | |
5356 | tree *x, *y; | |
5357 | { | |
5358 | return (long)DECL_NAME (*x) - (long)DECL_NAME (*y); | |
5359 | } | |
5360 | ||
5361 | /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. | |
7a0347ff RS |
5362 | FIELDLIST is a chain of FIELD_DECL nodes for the fields. |
5363 | ||
5364 | We also do a pop_obstacks to match the push in start_struct. */ | |
51e29401 RS |
5365 | |
5366 | tree | |
5367 | finish_struct (t, fieldlist) | |
5368 | register tree t, fieldlist; | |
5369 | { | |
5370 | register tree x; | |
5371 | int old_momentary; | |
5372 | int toplevel = global_binding_level == current_binding_level; | |
5373 | ||
5374 | /* If this type was previously laid out as a forward reference, | |
5375 | make sure we lay it out again. */ | |
5376 | ||
5377 | TYPE_SIZE (t) = 0; | |
5378 | ||
5379 | /* Nameless union parm types are useful as GCC extension. */ | |
5380 | if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic) | |
5381 | /* Otherwise, warn about any struct or union def. in parmlist. */ | |
5382 | if (in_parm_level_p ()) | |
5383 | { | |
5384 | if (pedantic) | |
5385 | pedwarn ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms" | |
5386 | : "structure defined inside parms")); | |
f3c2c111 | 5387 | else if (! flag_traditional) |
51e29401 RS |
5388 | warning ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms" |
5389 | : "structure defined inside parms")); | |
5390 | } | |
5391 | ||
5392 | old_momentary = suspend_momentary (); | |
5393 | ||
5394 | if (fieldlist == 0 && pedantic) | |
5395 | pedwarn ((TREE_CODE (t) == UNION_TYPE ? "union has no members" | |
5396 | : "structure has no members")); | |
5397 | ||
5398 | /* Install struct as DECL_CONTEXT of each field decl. | |
5399 | Also process specified field sizes. | |
77f934bb | 5400 | Set DECL_FIELD_SIZE to the specified size, or 0 if none specified. |
51e29401 RS |
5401 | The specified size is found in the DECL_INITIAL. |
5402 | Store 0 there, except for ": 0" fields (so we can find them | |
5403 | and delete them, below). */ | |
5404 | ||
5405 | for (x = fieldlist; x; x = TREE_CHAIN (x)) | |
5406 | { | |
5407 | DECL_CONTEXT (x) = t; | |
77f934bb | 5408 | DECL_FIELD_SIZE (x) = 0; |
51e29401 RS |
5409 | |
5410 | /* If any field is const, the structure type is pseudo-const. */ | |
5411 | if (TREE_READONLY (x)) | |
5412 | C_TYPE_FIELDS_READONLY (t) = 1; | |
5413 | else | |
5414 | { | |
5415 | /* A field that is pseudo-const makes the structure likewise. */ | |
5416 | tree t1 = TREE_TYPE (x); | |
5417 | while (TREE_CODE (t1) == ARRAY_TYPE) | |
5418 | t1 = TREE_TYPE (t1); | |
5419 | if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) | |
5420 | && C_TYPE_FIELDS_READONLY (t1)) | |
5421 | C_TYPE_FIELDS_READONLY (t) = 1; | |
5422 | } | |
5423 | ||
5424 | /* Any field that is volatile means variables of this type must be | |
5425 | treated in some ways as volatile. */ | |
5426 | if (TREE_THIS_VOLATILE (x)) | |
5427 | C_TYPE_FIELDS_VOLATILE (t) = 1; | |
5428 | ||
5429 | /* Any field of nominal variable size implies structure is too. */ | |
5430 | if (C_DECL_VARIABLE_SIZE (x)) | |
5431 | C_TYPE_VARIABLE_SIZE (t) = 1; | |
5432 | ||
8d7bbe5f RS |
5433 | /* Detect invalid nested redefinition. */ |
5434 | if (TREE_TYPE (x) == t) | |
5435 | error ("nested redefinition of `%s'", | |
5436 | IDENTIFIER_POINTER (TYPE_NAME (t))); | |
5437 | ||
51e29401 | 5438 | /* Detect invalid bit-field size. */ |
07c5ab55 RS |
5439 | if (DECL_INITIAL (x)) |
5440 | STRIP_NOPS (DECL_INITIAL (x)); | |
90374cc2 | 5441 | if (DECL_INITIAL (x)) |
e681c5a1 RS |
5442 | { |
5443 | if (TREE_CODE (DECL_INITIAL (x)) == INTEGER_CST) | |
5444 | constant_expression_warning (DECL_INITIAL (x)); | |
5445 | else | |
5446 | { | |
5447 | error_with_decl (x, "bit-field `%s' width not an integer constant"); | |
5448 | DECL_INITIAL (x) = NULL; | |
5449 | } | |
5450 | } | |
51e29401 RS |
5451 | |
5452 | /* Detect invalid bit-field type. */ | |
5453 | if (DECL_INITIAL (x) | |
5454 | && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE | |
5455 | && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE) | |
5456 | { | |
5457 | error_with_decl (x, "bit-field `%s' has invalid type"); | |
5458 | DECL_INITIAL (x) = NULL; | |
5459 | } | |
5460 | if (DECL_INITIAL (x) && pedantic | |
5461 | && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node | |
61df2ee2 RS |
5462 | && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node |
5463 | /* Accept an enum that's equivalent to int or unsigned int. */ | |
5464 | && !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE | |
5465 | && (TYPE_PRECISION (TREE_TYPE (x)) | |
5466 | == TYPE_PRECISION (integer_type_node)))) | |
51e29401 RS |
5467 | pedwarn_with_decl (x, "bit-field `%s' type invalid in ANSI C"); |
5468 | ||
5469 | /* Detect and ignore out of range field width. */ | |
5470 | if (DECL_INITIAL (x)) | |
5471 | { | |
2d724389 | 5472 | unsigned HOST_WIDE_INT width = TREE_INT_CST_LOW (DECL_INITIAL (x)); |
51e29401 | 5473 | |
6aa10371 | 5474 | if (tree_int_cst_sgn (DECL_INITIAL (x)) < 0) |
51e29401 RS |
5475 | { |
5476 | DECL_INITIAL (x) = NULL; | |
5477 | error_with_decl (x, "negative width in bit-field `%s'"); | |
5478 | } | |
2d724389 RS |
5479 | else if (TREE_INT_CST_HIGH (DECL_INITIAL (x)) != 0 |
5480 | || width > TYPE_PRECISION (TREE_TYPE (x))) | |
51e29401 | 5481 | { |
51e29401 | 5482 | DECL_INITIAL (x) = NULL; |
2d724389 | 5483 | pedwarn_with_decl (x, "width of `%s' exceeds its type"); |
51e29401 | 5484 | } |
2d724389 | 5485 | else if (width == 0 && DECL_NAME (x) != 0) |
51e29401 | 5486 | { |
2d724389 | 5487 | error_with_decl (x, "zero width for bit-field `%s'"); |
51e29401 | 5488 | DECL_INITIAL (x) = NULL; |
51e29401 RS |
5489 | } |
5490 | } | |
5491 | ||
5492 | /* Process valid field width. */ | |
5493 | if (DECL_INITIAL (x)) | |
5494 | { | |
5495 | register int width = TREE_INT_CST_LOW (DECL_INITIAL (x)); | |
5496 | ||
77f934bb | 5497 | DECL_FIELD_SIZE (x) = width; |
51e29401 RS |
5498 | DECL_BIT_FIELD (x) = 1; |
5499 | DECL_INITIAL (x) = NULL; | |
5500 | ||
5501 | if (width == 0) | |
5502 | { | |
5503 | /* field size 0 => force desired amount of alignment. */ | |
5504 | #ifdef EMPTY_FIELD_BOUNDARY | |
5505 | DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY); | |
5506 | #endif | |
5507 | #ifdef PCC_BITFIELD_TYPE_MATTERS | |
5508 | DECL_ALIGN (x) = MAX (DECL_ALIGN (x), | |
5509 | TYPE_ALIGN (TREE_TYPE (x))); | |
5510 | #endif | |
5511 | } | |
5512 | } | |
34322499 | 5513 | else if (TREE_TYPE (x) != error_mark_node) |
ec2343c4 MM |
5514 | { |
5515 | int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT | |
5516 | : TYPE_ALIGN (TREE_TYPE (x))); | |
5517 | /* Non-bit-fields are aligned for their type, except packed | |
5518 | fields which require only BITS_PER_UNIT alignment. */ | |
5519 | DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align); | |
5520 | } | |
51e29401 RS |
5521 | } |
5522 | ||
5523 | /* Now DECL_INITIAL is null on all members. */ | |
5524 | ||
5525 | /* Delete all duplicate fields from the fieldlist */ | |
5526 | for (x = fieldlist; x && TREE_CHAIN (x);) | |
5527 | /* Anonymous fields aren't duplicates. */ | |
5528 | if (DECL_NAME (TREE_CHAIN (x)) == 0) | |
5529 | x = TREE_CHAIN (x); | |
5530 | else | |
5531 | { | |
5532 | register tree y = fieldlist; | |
5533 | ||
5534 | while (1) | |
5535 | { | |
5536 | if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x))) | |
5537 | break; | |
5538 | if (y == x) | |
5539 | break; | |
5540 | y = TREE_CHAIN (y); | |
5541 | } | |
5542 | if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x))) | |
5543 | { | |
5544 | error_with_decl (TREE_CHAIN (x), "duplicate member `%s'"); | |
5545 | TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x)); | |
5546 | } | |
5547 | else x = TREE_CHAIN (x); | |
5548 | } | |
5549 | ||
5550 | /* Now we have the nearly final fieldlist. Record it, | |
5551 | then lay out the structure or union (including the fields). */ | |
5552 | ||
5553 | TYPE_FIELDS (t) = fieldlist; | |
5554 | ||
5555 | layout_type (t); | |
5556 | ||
5557 | /* Delete all zero-width bit-fields from the front of the fieldlist */ | |
5558 | while (fieldlist | |
5559 | && DECL_INITIAL (fieldlist)) | |
5560 | fieldlist = TREE_CHAIN (fieldlist); | |
5561 | /* Delete all such members from the rest of the fieldlist */ | |
5562 | for (x = fieldlist; x;) | |
5563 | { | |
5564 | if (TREE_CHAIN (x) && DECL_INITIAL (TREE_CHAIN (x))) | |
5565 | TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x)); | |
5566 | else x = TREE_CHAIN (x); | |
5567 | } | |
5568 | ||
5569 | /* Now we have the truly final field list. | |
5570 | Store it in this type and in the variants. */ | |
5571 | ||
5572 | TYPE_FIELDS (t) = fieldlist; | |
5573 | ||
5574 | /* If there are lots of fields, sort so we can look through them fast. | |
5575 | We arbitrarily consider 16 or more elts to be "a lot". */ | |
5576 | { | |
5577 | int len = 0; | |
5578 | ||
5579 | for (x = fieldlist; x; x = TREE_CHAIN (x)) | |
5580 | { | |
5581 | if (len > 15) | |
5582 | break; | |
5583 | len += 1; | |
5584 | } | |
5585 | if (len > 15) | |
5586 | { | |
5587 | tree *field_array; | |
5588 | char *space; | |
5589 | ||
5590 | len += list_length (x); | |
5591 | /* Use the same allocation policy here that make_node uses, to | |
5592 | ensure that this lives as long as the rest of the struct decl. | |
5593 | All decls in an inline function need to be saved. */ | |
5594 | if (allocation_temporary_p ()) | |
5595 | space = savealloc (sizeof (struct lang_type) + len * sizeof (tree)); | |
5596 | else | |
5597 | space = oballoc (sizeof (struct lang_type) + len * sizeof (tree)); | |
5598 | ||
5599 | TYPE_LANG_SPECIFIC (t) = (struct lang_type *) space; | |
5600 | TYPE_LANG_SPECIFIC (t)->len = len; | |
5601 | ||
5602 | field_array = &TYPE_LANG_SPECIFIC (t)->elts[0]; | |
5603 | len = 0; | |
5604 | for (x = fieldlist; x; x = TREE_CHAIN (x)) | |
5605 | field_array[len++] = x; | |
5606 | ||
5607 | qsort (field_array, len, sizeof (tree), field_decl_cmp); | |
5608 | } | |
5609 | } | |
5610 | ||
5611 | for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) | |
5612 | { | |
5613 | TYPE_FIELDS (x) = TYPE_FIELDS (t); | |
5614 | TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t); | |
5615 | TYPE_ALIGN (x) = TYPE_ALIGN (t); | |
5616 | } | |
5617 | ||
5618 | /* Promote each bit-field's type to int if it is narrower than that. */ | |
5619 | for (x = fieldlist; x; x = TREE_CHAIN (x)) | |
5620 | if (DECL_BIT_FIELD (x) | |
06038f12 RS |
5621 | && (C_PROMOTING_INTEGER_TYPE_P (TREE_TYPE (x)) |
5622 | || DECL_FIELD_SIZE (x) < TYPE_PRECISION (integer_type_node))) | |
5623 | { | |
5624 | tree type = TREE_TYPE (x); | |
5625 | ||
5626 | /* Preserve unsignedness if traditional | |
5627 | or if not really getting any wider. */ | |
5628 | if (TREE_UNSIGNED (type) | |
5629 | && (flag_traditional | |
5630 | || | |
5631 | (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node) | |
5632 | && | |
5633 | DECL_FIELD_SIZE (x) == TYPE_PRECISION (integer_type_node)))) | |
5634 | TREE_TYPE (x) = unsigned_type_node; | |
5635 | else | |
5636 | TREE_TYPE (x) = integer_type_node; | |
5637 | } | |
51e29401 RS |
5638 | |
5639 | /* If this structure or union completes the type of any previous | |
5640 | variable declaration, lay it out and output its rtl. */ | |
5641 | ||
5642 | if (current_binding_level->n_incomplete != 0) | |
5643 | { | |
5644 | tree decl; | |
5645 | for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl)) | |
5646 | { | |
5647 | if (TREE_TYPE (decl) == t | |
5648 | && TREE_CODE (decl) != TYPE_DECL) | |
5649 | { | |
5650 | layout_decl (decl, 0); | |
5651 | /* This is a no-op in c-lang.c or something real in objc-actions.c. */ | |
5652 | maybe_objc_check_decl (decl); | |
8d9bfdc5 | 5653 | rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); |
51e29401 RS |
5654 | if (! toplevel) |
5655 | expand_decl (decl); | |
5656 | --current_binding_level->n_incomplete; | |
5657 | } | |
5658 | else if (TYPE_SIZE (TREE_TYPE (decl)) == 0 | |
5659 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
5660 | { | |
5661 | tree element = TREE_TYPE (decl); | |
5662 | while (TREE_CODE (element) == ARRAY_TYPE) | |
5663 | element = TREE_TYPE (element); | |
5664 | if (element == t) | |
5665 | layout_array_type (TREE_TYPE (decl)); | |
5666 | } | |
5667 | } | |
5668 | } | |
5669 | ||
5670 | resume_momentary (old_momentary); | |
5671 | ||
5672 | /* Finish debugging output for this type. */ | |
5673 | rest_of_type_compilation (t, toplevel); | |
5674 | ||
7a0347ff RS |
5675 | /* The matching push is in start_struct. */ |
5676 | pop_obstacks (); | |
5677 | ||
51e29401 RS |
5678 | return t; |
5679 | } | |
5680 | ||
5681 | /* Lay out the type T, and its element type, and so on. */ | |
5682 | ||
5683 | static void | |
5684 | layout_array_type (t) | |
5685 | tree t; | |
5686 | { | |
5687 | if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) | |
5688 | layout_array_type (TREE_TYPE (t)); | |
5689 | layout_type (t); | |
5690 | } | |
5691 | \f | |
5692 | /* Begin compiling the definition of an enumeration type. | |
5693 | NAME is its name (or null if anonymous). | |
5694 | Returns the type object, as yet incomplete. | |
5695 | Also records info about it so that build_enumerator | |
5696 | may be used to declare the individual values as they are read. */ | |
5697 | ||
5698 | tree | |
5699 | start_enum (name) | |
5700 | tree name; | |
5701 | { | |
5702 | register tree enumtype = 0; | |
5703 | ||
5704 | /* If this is the real definition for a previous forward reference, | |
5705 | fill in the contents in the same object that used to be the | |
5706 | forward reference. */ | |
5707 | ||
5708 | if (name != 0) | |
5709 | enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1); | |
5710 | ||
7a0347ff RS |
5711 | /* The corresponding pop_obstacks is in finish_enum. */ |
5712 | push_obstacks_nochange (); | |
5713 | /* If these symbols and types are global, make them permanent. */ | |
5714 | if (current_binding_level == global_binding_level) | |
5715 | end_temporary_allocation (); | |
5716 | ||
51e29401 RS |
5717 | if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE) |
5718 | { | |
5719 | enumtype = make_node (ENUMERAL_TYPE); | |
5720 | pushtag (name, enumtype); | |
5721 | } | |
5722 | ||
5723 | C_TYPE_BEING_DEFINED (enumtype) = 1; | |
5724 | ||
5725 | if (TYPE_VALUES (enumtype) != 0) | |
5726 | { | |
5727 | /* This enum is a named one that has been declared already. */ | |
5728 | error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name)); | |
5729 | ||
5730 | /* Completely replace its old definition. | |
5731 | The old enumerators remain defined, however. */ | |
5732 | TYPE_VALUES (enumtype) = 0; | |
5733 | } | |
5734 | ||
5735 | enum_next_value = integer_zero_node; | |
93e3ba4f | 5736 | enum_overflow = 0; |
51e29401 RS |
5737 | |
5738 | return enumtype; | |
5739 | } | |
5740 | ||
5741 | /* After processing and defining all the values of an enumeration type, | |
5742 | install their decls in the enumeration type and finish it off. | |
5743 | ENUMTYPE is the type object and VALUES a list of decl-value pairs. | |
5744 | Returns ENUMTYPE. */ | |
5745 | ||
5746 | tree | |
5747 | finish_enum (enumtype, values) | |
5748 | register tree enumtype, values; | |
5749 | { | |
fbe23ee7 | 5750 | register tree pair, tem; |
51e29401 | 5751 | tree minnode = 0, maxnode = 0; |
de953b38 | 5752 | int lowprec, highprec, precision; |
51e29401 RS |
5753 | int toplevel = global_binding_level == current_binding_level; |
5754 | ||
5755 | if (in_parm_level_p ()) | |
5756 | warning ("enum defined inside parms"); | |
5757 | ||
5758 | /* Calculate the maximum value of any enumerator in this type. */ | |
5759 | ||
59116212 RK |
5760 | if (values == error_mark_node) |
5761 | minnode = maxnode = integer_zero_node; | |
5762 | else | |
5763 | for (pair = values; pair; pair = TREE_CHAIN (pair)) | |
5764 | { | |
5765 | tree value = TREE_VALUE (pair); | |
5766 | if (pair == values) | |
5767 | minnode = maxnode = TREE_VALUE (pair); | |
5768 | else | |
5769 | { | |
5770 | if (tree_int_cst_lt (maxnode, value)) | |
5771 | maxnode = value; | |
5772 | if (tree_int_cst_lt (value, minnode)) | |
5773 | minnode = value; | |
5774 | } | |
5775 | } | |
51e29401 RS |
5776 | |
5777 | TYPE_MIN_VALUE (enumtype) = minnode; | |
5778 | TYPE_MAX_VALUE (enumtype) = maxnode; | |
5779 | ||
de953b38 RK |
5780 | /* An enum can have some negative values; then it is signed. */ |
5781 | TREE_UNSIGNED (enumtype) = tree_int_cst_sgn (minnode) >= 0; | |
51e29401 | 5782 | |
de953b38 | 5783 | /* Determine the precision this type needs. */ |
51e29401 | 5784 | |
de953b38 RK |
5785 | lowprec = min_precision (minnode, TREE_UNSIGNED (enumtype)); |
5786 | highprec = min_precision (maxnode, TREE_UNSIGNED (enumtype)); | |
5787 | precision = MAX (lowprec, highprec); | |
51e29401 RS |
5788 | |
5789 | if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node)) | |
5790 | /* Use the width of the narrowest normal C type which is wide enough. */ | |
5791 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size (precision, 1)); | |
5792 | else | |
5793 | TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); | |
5794 | ||
5795 | TYPE_SIZE (enumtype) = 0; | |
5796 | layout_type (enumtype); | |
5797 | ||
59116212 | 5798 | if (values != error_mark_node) |
75b46437 | 5799 | { |
59116212 RK |
5800 | /* Change the type of the enumerators to be the enum type. |
5801 | Formerly this was done only for enums that fit in an int, | |
5802 | but the comment said it was done only for enums wider than int. | |
5803 | It seems necessary to do this for wide enums, | |
5804 | and best not to change what's done for ordinary narrower ones. */ | |
5805 | for (pair = values; pair; pair = TREE_CHAIN (pair)) | |
5806 | { | |
5807 | TREE_TYPE (TREE_PURPOSE (pair)) = enumtype; | |
5808 | DECL_SIZE (TREE_PURPOSE (pair)) = TYPE_SIZE (enumtype); | |
5809 | if (TREE_CODE (TREE_PURPOSE (pair)) != FUNCTION_DECL) | |
5810 | DECL_ALIGN (TREE_PURPOSE (pair)) = TYPE_ALIGN (enumtype); | |
5811 | } | |
51e29401 | 5812 | |
59116212 RK |
5813 | /* Replace the decl nodes in VALUES with their names. */ |
5814 | for (pair = values; pair; pair = TREE_CHAIN (pair)) | |
5815 | TREE_PURPOSE (pair) = DECL_NAME (TREE_PURPOSE (pair)); | |
51e29401 | 5816 | |
59116212 RK |
5817 | TYPE_VALUES (enumtype) = values; |
5818 | } | |
51e29401 | 5819 | |
fbe23ee7 RS |
5820 | /* Fix up all variant types of this enum type. */ |
5821 | for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem)) | |
5822 | { | |
5823 | TYPE_VALUES (tem) = TYPE_VALUES (enumtype); | |
5824 | TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); | |
5825 | TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); | |
5826 | TYPE_SIZE (tem) = TYPE_SIZE (enumtype); | |
5827 | TYPE_MODE (tem) = TYPE_MODE (enumtype); | |
5828 | TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); | |
5829 | TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); | |
5830 | TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); | |
5831 | } | |
5832 | ||
51e29401 RS |
5833 | /* Finish debugging output for this type. */ |
5834 | rest_of_type_compilation (enumtype, toplevel); | |
5835 | ||
7a0347ff RS |
5836 | /* This matches a push in start_enum. */ |
5837 | pop_obstacks (); | |
5838 | ||
51e29401 RS |
5839 | return enumtype; |
5840 | } | |
5841 | ||
5842 | /* Build and install a CONST_DECL for one value of the | |
5843 | current enumeration type (one that was begun with start_enum). | |
5844 | Return a tree-list containing the CONST_DECL and its value. | |
5845 | Assignment of sequential values by default is handled here. */ | |
5846 | ||
5847 | tree | |
5848 | build_enumerator (name, value) | |
5849 | tree name, value; | |
5850 | { | |
75b46437 | 5851 | register tree decl, type; |
51e29401 RS |
5852 | |
5853 | /* Validate and default VALUE. */ | |
5854 | ||
5855 | /* Remove no-op casts from the value. */ | |
cd7a1451 | 5856 | if (value) |
874a7be1 | 5857 | STRIP_TYPE_NOPS (value); |
51e29401 | 5858 | |
90374cc2 | 5859 | if (value != 0) |
e681c5a1 RS |
5860 | { |
5861 | if (TREE_CODE (value) == INTEGER_CST) | |
25a1019f RK |
5862 | { |
5863 | value = default_conversion (value); | |
5864 | constant_expression_warning (value); | |
5865 | } | |
e681c5a1 RS |
5866 | else |
5867 | { | |
5868 | error ("enumerator value for `%s' not integer constant", | |
5869 | IDENTIFIER_POINTER (name)); | |
5870 | value = 0; | |
5871 | } | |
5872 | } | |
51e29401 RS |
5873 | |
5874 | /* Default based on previous value. */ | |
5875 | /* It should no longer be possible to have NON_LVALUE_EXPR | |
5876 | in the default. */ | |
5877 | if (value == 0) | |
93e3ba4f RS |
5878 | { |
5879 | value = enum_next_value; | |
5880 | if (enum_overflow) | |
5881 | error ("overflow in enumeration values"); | |
5882 | } | |
51e29401 RS |
5883 | |
5884 | if (pedantic && ! int_fits_type_p (value, integer_type_node)) | |
5885 | { | |
5886 | pedwarn ("ANSI C restricts enumerator values to range of `int'"); | |
5887 | value = integer_zero_node; | |
5888 | } | |
5889 | ||
5890 | /* Set basis for default for next value. */ | |
5891 | enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0); | |
93e3ba4f | 5892 | enum_overflow = tree_int_cst_lt (enum_next_value, value); |
51e29401 RS |
5893 | |
5894 | /* Now create a declaration for the enum value name. */ | |
5895 | ||
75b46437 RS |
5896 | type = TREE_TYPE (value); |
5897 | type = type_for_size (MAX (TYPE_PRECISION (type), | |
5898 | TYPE_PRECISION (integer_type_node)), | |
5899 | ((flag_traditional | |
5900 | || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node)) | |
5901 | && TREE_UNSIGNED (type))); | |
5902 | ||
5903 | decl = build_decl (CONST_DECL, name, type); | |
51e29401 | 5904 | DECL_INITIAL (decl) = value; |
75b46437 | 5905 | TREE_TYPE (value) = type; |
51e29401 RS |
5906 | pushdecl (decl); |
5907 | ||
8d9bfdc5 | 5908 | return saveable_tree_cons (decl, value, NULL_TREE); |
51e29401 RS |
5909 | } |
5910 | \f | |
5911 | /* Create the FUNCTION_DECL for a function definition. | |
5912 | DECLSPECS and DECLARATOR are the parts of the declaration; | |
5913 | they describe the function's name and the type it returns, | |
5914 | but twisted together in a fashion that parallels the syntax of C. | |
5915 | ||
5916 | This function creates a binding context for the function body | |
5917 | as well as setting up the FUNCTION_DECL in current_function_decl. | |
5918 | ||
5919 | Returns 1 on success. If the DECLARATOR is not suitable for a function | |
5920 | (it defines a datum instead), we return 0, which tells | |
5921 | yyparse to report a parse error. | |
5922 | ||
5923 | NESTED is nonzero for a function nested within another function. */ | |
5924 | ||
5925 | int | |
5926 | start_function (declspecs, declarator, nested) | |
5927 | tree declarator, declspecs; | |
5928 | int nested; | |
5929 | { | |
5930 | tree decl1, old_decl; | |
5931 | tree restype; | |
5415b705 | 5932 | int old_immediate_size_expand = immediate_size_expand; |
51e29401 RS |
5933 | |
5934 | current_function_returns_value = 0; /* Assume, until we see it does. */ | |
5935 | current_function_returns_null = 0; | |
5936 | warn_about_return_type = 0; | |
5937 | current_extern_inline = 0; | |
5938 | c_function_varargs = 0; | |
5939 | named_labels = 0; | |
5940 | shadowed_labels = 0; | |
5941 | ||
5415b705 RK |
5942 | /* Don't expand any sizes in the return type of the function. */ |
5943 | immediate_size_expand = 0; | |
5944 | ||
51e29401 RS |
5945 | decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1); |
5946 | ||
5947 | /* If the declarator is not suitable for a function definition, | |
5948 | cause a syntax error. */ | |
5949 | if (decl1 == 0) | |
5950 | return 0; | |
5951 | ||
5952 | announce_function (decl1); | |
5953 | ||
5954 | if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0) | |
5955 | { | |
5956 | error ("return-type is an incomplete type"); | |
5957 | /* Make it return void instead. */ | |
5958 | TREE_TYPE (decl1) | |
5959 | = build_function_type (void_type_node, | |
5960 | TYPE_ARG_TYPES (TREE_TYPE (decl1))); | |
5961 | } | |
5962 | ||
5963 | if (warn_about_return_type) | |
5964 | warning ("return-type defaults to `int'"); | |
5965 | ||
5966 | /* Save the parm names or decls from this function's declarator | |
5967 | where store_parm_decls will find them. */ | |
5968 | current_function_parms = last_function_parms; | |
5969 | current_function_parm_tags = last_function_parm_tags; | |
5970 | ||
5971 | /* Make the init_value nonzero so pushdecl knows this is not tentative. | |
5972 | error_mark_node is replaced below (in poplevel) with the BLOCK. */ | |
5973 | DECL_INITIAL (decl1) = error_mark_node; | |
5974 | ||
5975 | /* If this definition isn't a prototype and we had a prototype declaration | |
5976 | before, copy the arg type info from that prototype. | |
5977 | But not if what we had before was a builtin function. */ | |
5978 | old_decl = lookup_name_current_level (DECL_NAME (decl1)); | |
5979 | if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE | |
5980 | && !DECL_BUILT_IN (old_decl) | |
fa7d8b92 RK |
5981 | && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) |
5982 | == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl)))) | |
51e29401 | 5983 | && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) |
50a9145c JW |
5984 | { |
5985 | TREE_TYPE (decl1) = TREE_TYPE (old_decl); | |
5986 | current_function_prototype_file = DECL_SOURCE_FILE (old_decl); | |
5987 | current_function_prototype_line = DECL_SOURCE_LINE (old_decl); | |
5988 | } | |
51e29401 | 5989 | |
6fc7c517 JW |
5990 | /* If there is no explicit declaration, look for any out-of-scope implicit |
5991 | declarations. */ | |
5992 | if (old_decl == 0) | |
5993 | old_decl = IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)); | |
5994 | ||
51e29401 RS |
5995 | /* Optionally warn of old-fashioned def with no previous prototype. */ |
5996 | if (warn_strict_prototypes | |
5997 | && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0 | |
5998 | && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0)) | |
5999 | warning ("function declaration isn't a prototype"); | |
6000 | /* Optionally warn of any global def with no previous prototype. */ | |
6001 | else if (warn_missing_prototypes | |
6002 | && TREE_PUBLIC (decl1) | |
39ab948e RS |
6003 | && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0) |
6004 | && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1)))) | |
51e29401 RS |
6005 | warning_with_decl (decl1, "no previous prototype for `%s'"); |
6006 | /* Optionally warn of any def with no previous prototype | |
6007 | if the function has already been used. */ | |
6008 | else if (warn_missing_prototypes | |
6009 | && old_decl != 0 && TREE_USED (old_decl) | |
6fc7c517 | 6010 | && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) == 0) |
1474fe46 RK |
6011 | warning_with_decl (decl1, |
6012 | "`%s' was used with no prototype before its definition"); | |
6013 | /* Optionally warn of any global def with no previous declaration. */ | |
6014 | else if (warn_missing_declarations | |
6015 | && TREE_PUBLIC (decl1) | |
6016 | && old_decl == 0 | |
6017 | && strcmp ("main", IDENTIFIER_POINTER (DECL_NAME (decl1)))) | |
6018 | warning_with_decl (decl1, "no previous declaration for `%s'"); | |
6019 | /* Optionally warn of any def with no previous declaration | |
6020 | if the function has already been used. */ | |
6021 | else if (warn_missing_declarations | |
6fc7c517 JW |
6022 | && old_decl != 0 && TREE_USED (old_decl) |
6023 | && old_decl == IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))) | |
1474fe46 RK |
6024 | warning_with_decl (decl1, |
6025 | "`%s' was used with no declaration before its definition"); | |
51e29401 RS |
6026 | |
6027 | /* This is a definition, not a reference. | |
1394aabd | 6028 | So normally clear DECL_EXTERNAL. |
51e29401 | 6029 | However, `extern inline' acts like a declaration |
1394aabd RS |
6030 | except for defining how to inline. So set DECL_EXTERNAL in that case. */ |
6031 | DECL_EXTERNAL (decl1) = current_extern_inline; | |
51e29401 RS |
6032 | |
6033 | /* This function exists in static storage. | |
6034 | (This does not mean `static' in the C sense!) */ | |
6035 | TREE_STATIC (decl1) = 1; | |
6036 | ||
6037 | /* A nested function is not global. */ | |
6038 | if (current_function_decl != 0) | |
6039 | TREE_PUBLIC (decl1) = 0; | |
6040 | ||
6041 | /* Record the decl so that the function name is defined. | |
6042 | If we already have a decl for this name, and it is a FUNCTION_DECL, | |
6043 | use the old decl. */ | |
6044 | ||
6045 | current_function_decl = pushdecl (decl1); | |
6046 | ||
6047 | pushlevel (0); | |
6048 | declare_parm_level (1); | |
6049 | current_binding_level->subblocks_tag_transparent = 1; | |
6050 | ||
6051 | make_function_rtl (current_function_decl); | |
6052 | ||
6053 | restype = TREE_TYPE (TREE_TYPE (current_function_decl)); | |
6054 | /* Promote the value to int before returning it. */ | |
24bc4c7f | 6055 | if (C_PROMOTING_INTEGER_TYPE_P (restype)) |
42dfa47f RS |
6056 | { |
6057 | /* It retains unsignedness if traditional | |
6058 | or if not really getting wider. */ | |
6059 | if (TREE_UNSIGNED (restype) | |
6060 | && (flag_traditional | |
6061 | || (TYPE_PRECISION (restype) | |
6062 | == TYPE_PRECISION (integer_type_node)))) | |
6063 | restype = unsigned_type_node; | |
6064 | else | |
6065 | restype = integer_type_node; | |
6066 | } | |
8d9bfdc5 RK |
6067 | DECL_RESULT (current_function_decl) |
6068 | = build_decl (RESULT_DECL, NULL_TREE, restype); | |
51e29401 RS |
6069 | |
6070 | if (!nested) | |
6071 | /* Allocate further tree nodes temporarily during compilation | |
6072 | of this function only. */ | |
6073 | temporary_allocation (); | |
6074 | ||
6075 | /* If this fcn was already referenced via a block-scope `extern' decl | |
6076 | (or an implicit decl), propagate certain information about the usage. */ | |
6077 | if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl))) | |
6078 | TREE_ADDRESSABLE (current_function_decl) = 1; | |
6079 | ||
5415b705 RK |
6080 | immediate_size_expand = old_immediate_size_expand; |
6081 | ||
51e29401 RS |
6082 | return 1; |
6083 | } | |
6084 | ||
6085 | /* Record that this function is going to be a varargs function. | |
6086 | This is called before store_parm_decls, which is too early | |
6087 | to call mark_varargs directly. */ | |
6088 | ||
6089 | void | |
6090 | c_mark_varargs () | |
6091 | { | |
6092 | c_function_varargs = 1; | |
6093 | } | |
6094 | \f | |
6095 | /* Store the parameter declarations into the current function declaration. | |
6096 | This is called after parsing the parameter declarations, before | |
6097 | digesting the body of the function. | |
6098 | ||
6099 | For an old-style definition, modify the function's type | |
6100 | to specify at least the number of arguments. */ | |
6101 | ||
6102 | void | |
6103 | store_parm_decls () | |
6104 | { | |
6105 | register tree fndecl = current_function_decl; | |
6106 | register tree parm; | |
6107 | ||
6108 | /* This is either a chain of PARM_DECLs (if a prototype was used) | |
6109 | or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */ | |
6110 | tree specparms = current_function_parms; | |
6111 | ||
6112 | /* This is a list of types declared among parms in a prototype. */ | |
6113 | tree parmtags = current_function_parm_tags; | |
6114 | ||
6115 | /* This is a chain of PARM_DECLs from old-style parm declarations. */ | |
6116 | register tree parmdecls = getdecls (); | |
6117 | ||
6118 | /* This is a chain of any other decls that came in among the parm | |
6119 | declarations. If a parm is declared with enum {foo, bar} x; | |
6120 | then CONST_DECLs for foo and bar are put here. */ | |
6121 | tree nonparms = 0; | |
6122 | ||
6123 | /* Nonzero if this definition is written with a prototype. */ | |
6124 | int prototype = 0; | |
6125 | ||
6126 | if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST) | |
6127 | { | |
6128 | /* This case is when the function was defined with an ANSI prototype. | |
6129 | The parms already have decls, so we need not do anything here | |
6130 | except record them as in effect | |
6131 | and complain if any redundant old-style parm decls were written. */ | |
6132 | ||
6133 | register tree next; | |
6134 | tree others = 0; | |
6135 | ||
6136 | prototype = 1; | |
6137 | ||
6138 | if (parmdecls != 0) | |
7a0347ff RS |
6139 | { |
6140 | tree decl, link; | |
6141 | ||
6142 | error_with_decl (fndecl, | |
6143 | "parm types given both in parmlist and separately"); | |
6144 | /* Get rid of the erroneous decls; don't keep them on | |
6145 | the list of parms, since they might not be PARM_DECLs. */ | |
6146 | for (decl = current_binding_level->names; | |
6147 | decl; decl = TREE_CHAIN (decl)) | |
6148 | if (DECL_NAME (decl)) | |
6149 | IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0; | |
6150 | for (link = current_binding_level->shadowed; | |
6151 | link; link = TREE_CHAIN (link)) | |
6152 | IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); | |
6153 | current_binding_level->names = 0; | |
6154 | current_binding_level->shadowed = 0; | |
6155 | } | |
51e29401 RS |
6156 | |
6157 | specparms = nreverse (specparms); | |
6158 | for (parm = specparms; parm; parm = next) | |
6159 | { | |
6160 | next = TREE_CHAIN (parm); | |
6161 | if (TREE_CODE (parm) == PARM_DECL) | |
6162 | { | |
6163 | if (DECL_NAME (parm) == 0) | |
6164 | error_with_decl (parm, "parameter name omitted"); | |
5fe86b8b | 6165 | else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) |
a4faa7cc JW |
6166 | { |
6167 | error_with_decl (parm, "parameter `%s' declared void"); | |
6168 | /* Change the type to error_mark_node so this parameter | |
6169 | will be ignored by assign_parms. */ | |
6170 | TREE_TYPE (parm) = error_mark_node; | |
6171 | } | |
51e29401 RS |
6172 | pushdecl (parm); |
6173 | } | |
6174 | else | |
6175 | { | |
6176 | /* If we find an enum constant or a type tag, | |
6177 | put it aside for the moment. */ | |
6178 | TREE_CHAIN (parm) = 0; | |
6179 | others = chainon (others, parm); | |
6180 | } | |
6181 | } | |
6182 | ||
6183 | /* Get the decls in their original chain order | |
6184 | and record in the function. */ | |
6185 | DECL_ARGUMENTS (fndecl) = getdecls (); | |
6186 | ||
6187 | #if 0 | |
6188 | /* If this function takes a variable number of arguments, | |
6189 | add a phony parameter to the end of the parm list, | |
6190 | to represent the position of the first unnamed argument. */ | |
6191 | if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))) | |
6192 | != void_type_node) | |
6193 | { | |
6194 | tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node); | |
6195 | /* Let's hope the address of the unnamed parm | |
6196 | won't depend on its type. */ | |
6197 | TREE_TYPE (dummy) = integer_type_node; | |
6198 | DECL_ARG_TYPE (dummy) = integer_type_node; | |
6199 | DECL_ARGUMENTS (fndecl) | |
6200 | = chainon (DECL_ARGUMENTS (fndecl), dummy); | |
6201 | } | |
6202 | #endif | |
6203 | ||
6204 | /* Now pushdecl the enum constants. */ | |
6205 | for (parm = others; parm; parm = next) | |
6206 | { | |
6207 | next = TREE_CHAIN (parm); | |
6208 | if (DECL_NAME (parm) == 0) | |
6209 | ; | |
5fe86b8b | 6210 | else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) |
51e29401 RS |
6211 | ; |
6212 | else if (TREE_CODE (parm) != PARM_DECL) | |
6213 | pushdecl (parm); | |
6214 | } | |
6215 | ||
6216 | storetags (chainon (parmtags, gettags ())); | |
6217 | } | |
6218 | else | |
6219 | { | |
6220 | /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes | |
6221 | each with a parm name as the TREE_VALUE. | |
6222 | ||
6223 | PARMDECLS is a chain of declarations for parameters. | |
6224 | Warning! It can also contain CONST_DECLs which are not parameters | |
6225 | but are names of enumerators of any enum types | |
6226 | declared among the parameters. | |
6227 | ||
6228 | First match each formal parameter name with its declaration. | |
6229 | Associate decls with the names and store the decls | |
6230 | into the TREE_PURPOSE slots. */ | |
6231 | ||
6232 | for (parm = parmdecls; parm; parm = TREE_CHAIN (parm)) | |
6233 | DECL_RESULT (parm) = 0; | |
6234 | ||
6235 | for (parm = specparms; parm; parm = TREE_CHAIN (parm)) | |
6236 | { | |
6237 | register tree tail, found = NULL; | |
6238 | ||
6239 | if (TREE_VALUE (parm) == 0) | |
6240 | { | |
6241 | error_with_decl (fndecl, "parameter name missing from parameter list"); | |
6242 | TREE_PURPOSE (parm) = 0; | |
6243 | continue; | |
6244 | } | |
6245 | ||
6246 | /* See if any of the parmdecls specifies this parm by name. | |
6247 | Ignore any enumerator decls. */ | |
6248 | for (tail = parmdecls; tail; tail = TREE_CHAIN (tail)) | |
6249 | if (DECL_NAME (tail) == TREE_VALUE (parm) | |
6250 | && TREE_CODE (tail) == PARM_DECL) | |
6251 | { | |
6252 | found = tail; | |
6253 | break; | |
6254 | } | |
6255 | ||
6256 | /* If declaration already marked, we have a duplicate name. | |
6257 | Complain, and don't use this decl twice. */ | |
6258 | if (found && DECL_RESULT (found) != 0) | |
6259 | { | |
6260 | error_with_decl (found, "multiple parameters named `%s'"); | |
6261 | found = 0; | |
6262 | } | |
6263 | ||
6264 | /* If the declaration says "void", complain and ignore it. */ | |
5fe86b8b | 6265 | if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node) |
51e29401 RS |
6266 | { |
6267 | error_with_decl (found, "parameter `%s' declared void"); | |
6268 | TREE_TYPE (found) = integer_type_node; | |
6269 | DECL_ARG_TYPE (found) = integer_type_node; | |
6270 | layout_decl (found, 0); | |
6271 | } | |
6272 | ||
6273 | /* Traditionally, a parm declared float is actually a double. */ | |
6274 | if (found && flag_traditional | |
90d56da8 | 6275 | && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node) |
6d142a10 RS |
6276 | { |
6277 | TREE_TYPE (found) = double_type_node; | |
6278 | DECL_ARG_TYPE (found) = double_type_node; | |
6279 | layout_decl (found, 0); | |
6280 | } | |
51e29401 RS |
6281 | |
6282 | /* If no declaration found, default to int. */ | |
6283 | if (!found) | |
6284 | { | |
6285 | found = build_decl (PARM_DECL, TREE_VALUE (parm), | |
6286 | integer_type_node); | |
6287 | DECL_ARG_TYPE (found) = TREE_TYPE (found); | |
6288 | DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl); | |
6289 | DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl); | |
6290 | if (extra_warnings) | |
6291 | warning_with_decl (found, "type of `%s' defaults to `int'"); | |
6292 | pushdecl (found); | |
6293 | } | |
6294 | ||
6295 | TREE_PURPOSE (parm) = found; | |
6296 | ||
6297 | /* Mark this decl as "already found" -- see test, above. | |
6298 | It is safe to use DECL_RESULT for this | |
6299 | since it is not used in PARM_DECLs or CONST_DECLs. */ | |
6300 | DECL_RESULT (found) = error_mark_node; | |
6301 | } | |
6302 | ||
6303 | /* Put anything which is on the parmdecls chain and which is | |
6304 | not a PARM_DECL onto the list NONPARMS. (The types of | |
6305 | non-parm things which might appear on the list include | |
6306 | enumerators and NULL-named TYPE_DECL nodes.) Complain about | |
6307 | any actual PARM_DECLs not matched with any names. */ | |
6308 | ||
6309 | nonparms = 0; | |
6310 | for (parm = parmdecls; parm; ) | |
6311 | { | |
6312 | tree next = TREE_CHAIN (parm); | |
6313 | TREE_CHAIN (parm) = 0; | |
6314 | ||
6315 | if (TREE_CODE (parm) != PARM_DECL) | |
6316 | nonparms = chainon (nonparms, parm); | |
6317 | else | |
6318 | { | |
6319 | /* Complain about args with incomplete types. */ | |
6320 | if (TYPE_SIZE (TREE_TYPE (parm)) == 0) | |
6321 | { | |
6322 | error_with_decl (parm, "parameter `%s' has incomplete type"); | |
6323 | TREE_TYPE (parm) = error_mark_node; | |
6324 | } | |
6325 | ||
6326 | if (DECL_RESULT (parm) == 0) | |
6327 | { | |
6328 | error_with_decl (parm, | |
6329 | "declaration for parameter `%s' but no such parameter"); | |
6330 | /* Pretend the parameter was not missing. | |
6331 | This gets us to a standard state and minimizes | |
6332 | further error messages. */ | |
6333 | specparms | |
6334 | = chainon (specparms, | |
6335 | tree_cons (parm, NULL_TREE, NULL_TREE)); | |
6336 | } | |
6337 | } | |
6338 | ||
6339 | parm = next; | |
6340 | } | |
6341 | ||
6342 | /* Chain the declarations together in the order of the list of names. */ | |
6343 | /* Store that chain in the function decl, replacing the list of names. */ | |
6344 | parm = specparms; | |
6345 | DECL_ARGUMENTS (fndecl) = 0; | |
6346 | { | |
6347 | register tree last; | |
6348 | for (last = 0; parm; parm = TREE_CHAIN (parm)) | |
6349 | if (TREE_PURPOSE (parm)) | |
6350 | { | |
6351 | if (last == 0) | |
6352 | DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm); | |
6353 | else | |
6354 | TREE_CHAIN (last) = TREE_PURPOSE (parm); | |
6355 | last = TREE_PURPOSE (parm); | |
6356 | TREE_CHAIN (last) = 0; | |
6357 | } | |
6358 | } | |
6359 | ||
6360 | /* If there was a previous prototype, | |
6361 | set the DECL_ARG_TYPE of each argument according to | |
6362 | the type previously specified, and report any mismatches. */ | |
6363 | ||
6364 | if (TYPE_ARG_TYPES (TREE_TYPE (fndecl))) | |
6365 | { | |
6366 | register tree type; | |
6367 | for (parm = DECL_ARGUMENTS (fndecl), | |
6368 | type = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); | |
5fe86b8b RS |
6369 | parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) |
6370 | != void_type_node)); | |
51e29401 RS |
6371 | parm = TREE_CHAIN (parm), type = TREE_CHAIN (type)) |
6372 | { | |
6373 | if (parm == 0 || type == 0 | |
5fe86b8b | 6374 | || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node) |
51e29401 RS |
6375 | { |
6376 | error ("number of arguments doesn't match prototype"); | |
50a9145c JW |
6377 | error_with_file_and_line (current_function_prototype_file, |
6378 | current_function_prototype_line, | |
6379 | "prototype declaration"); | |
51e29401 RS |
6380 | break; |
6381 | } | |
6382 | /* Type for passing arg must be consistent | |
6383 | with that declared for the arg. */ | |
ec2343c4 | 6384 | if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type))) |
51e29401 | 6385 | { |
b3fc0c98 RS |
6386 | if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) |
6387 | == TYPE_MAIN_VARIANT (TREE_VALUE (type))) | |
51e29401 | 6388 | { |
ec2343c4 MM |
6389 | /* Adjust argument to match prototype. E.g. a previous |
6390 | `int foo(float);' prototype causes | |
6391 | `int foo(x) float x; {...}' to be treated like | |
6392 | `int foo(float x) {...}'. This is particularly | |
6393 | useful for argument types like uid_t. */ | |
6394 | DECL_ARG_TYPE (parm) = TREE_TYPE (parm); | |
6395 | #ifdef PROMOTE_PROTOTYPES | |
fd48df3e RK |
6396 | if ((TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE |
6397 | || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE) | |
ec2343c4 MM |
6398 | && TYPE_PRECISION (TREE_TYPE (parm)) |
6399 | < TYPE_PRECISION (integer_type_node)) | |
6400 | DECL_ARG_TYPE (parm) = integer_type_node; | |
6401 | #endif | |
6402 | if (pedantic) | |
50a9145c | 6403 | { |
42f00318 | 6404 | pedwarn ("promoted argument `%s' doesn't match prototype", |
50a9145c JW |
6405 | IDENTIFIER_POINTER (DECL_NAME (parm))); |
6406 | warning_with_file_and_line | |
6407 | (current_function_prototype_file, | |
6408 | current_function_prototype_line, | |
6409 | "prototype declaration"); | |
6410 | } | |
51e29401 | 6411 | } |
ec2343c4 MM |
6412 | /* If -traditional, allow `int' argument to match |
6413 | `unsigned' prototype. */ | |
6414 | else if (! (flag_traditional | |
90d56da8 RS |
6415 | && TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == integer_type_node |
6416 | && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node)) | |
50a9145c JW |
6417 | { |
6418 | error ("argument `%s' doesn't match prototype", | |
6419 | IDENTIFIER_POINTER (DECL_NAME (parm))); | |
6420 | error_with_file_and_line (current_function_prototype_file, | |
6421 | current_function_prototype_line, | |
6422 | "prototype declaration"); | |
6423 | } | |
51e29401 RS |
6424 | } |
6425 | } | |
6426 | TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0; | |
6427 | } | |
6428 | ||
6429 | /* Otherwise, create a prototype that would match. */ | |
6430 | ||
6431 | else | |
6432 | { | |
b8e605ab | 6433 | tree actual = 0, last = 0, type; |
51e29401 RS |
6434 | |
6435 | for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm)) | |
6436 | { | |
8d9bfdc5 RK |
6437 | type = perm_tree_cons (NULL_TREE, DECL_ARG_TYPE (parm), |
6438 | NULL_TREE); | |
51e29401 RS |
6439 | if (last) |
6440 | TREE_CHAIN (last) = type; | |
6441 | else | |
6442 | actual = type; | |
6443 | last = type; | |
6444 | } | |
8d9bfdc5 | 6445 | type = perm_tree_cons (NULL_TREE, void_type_node, NULL_TREE); |
51e29401 RS |
6446 | if (last) |
6447 | TREE_CHAIN (last) = type; | |
6448 | else | |
6449 | actual = type; | |
6450 | ||
c138f328 RS |
6451 | /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES |
6452 | of the type of this function, but we need to avoid having this | |
6453 | affect the types of other similarly-typed functions, so we must | |
6454 | first force the generation of an identical (but separate) type | |
6455 | node for the relevant function type. The new node we create | |
6456 | will be a variant of the main variant of the original function | |
6457 | type. */ | |
6458 | ||
929f3671 | 6459 | TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl)); |
c138f328 | 6460 | |
51e29401 RS |
6461 | TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual; |
6462 | } | |
6463 | ||
6464 | /* Now store the final chain of decls for the arguments | |
6465 | as the decl-chain of the current lexical scope. | |
6466 | Put the enumerators in as well, at the front so that | |
6467 | DECL_ARGUMENTS is not modified. */ | |
6468 | ||
6469 | storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); | |
6470 | } | |
6471 | ||
6472 | /* Make sure the binding level for the top of the function body | |
6473 | gets a BLOCK if there are any in the function. | |
6474 | Otherwise, the dbx output is wrong. */ | |
6475 | ||
6476 | keep_next_if_subblocks = 1; | |
6477 | ||
6478 | /* ??? This might be an improvement, | |
6479 | but needs to be thought about some more. */ | |
6480 | #if 0 | |
6481 | keep_next_level_flag = 1; | |
6482 | #endif | |
6483 | ||
6484 | /* Write a record describing this function definition to the prototypes | |
6485 | file (if requested). */ | |
6486 | ||
6487 | gen_aux_info_record (fndecl, 1, 0, prototype); | |
6488 | ||
6489 | /* Initialize the RTL code for the function. */ | |
6490 | ||
6491 | init_function_start (fndecl, input_filename, lineno); | |
6492 | ||
6493 | /* If this is a varargs function, inform function.c. */ | |
6494 | ||
6495 | if (c_function_varargs) | |
6496 | mark_varargs (); | |
6497 | ||
b032c74c | 6498 | /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ |
7da551a2 RS |
6499 | |
6500 | declare_function_name (); | |
93e3ba4f | 6501 | |
51e29401 RS |
6502 | /* Set up parameters and prepare for return, for the function. */ |
6503 | ||
6504 | expand_function_start (fndecl, 0); | |
6505 | ||
6506 | /* If this function is `main', emit a call to `__main' | |
6507 | to run global initializers, etc. */ | |
6508 | if (DECL_NAME (fndecl) | |
6509 | && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 | |
6510 | && DECL_CONTEXT (fndecl) == NULL_TREE) | |
6511 | expand_main_function (); | |
6512 | } | |
6513 | \f | |
6514 | /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes | |
6515 | each with a parm name as the TREE_VALUE. A null pointer as TREE_VALUE | |
6516 | stands for an ellipsis in the identifier list. | |
6517 | ||
6518 | PARMLIST is the data returned by get_parm_info for the | |
6519 | parmlist that follows the semicolon. | |
6520 | ||
6521 | We return a value of the same sort that get_parm_info returns, | |
6522 | except that it describes the combination of identifiers and parmlist. */ | |
6523 | ||
6524 | tree | |
6525 | combine_parm_decls (specparms, parmlist, void_at_end) | |
6526 | tree specparms, parmlist; | |
6527 | int void_at_end; | |
6528 | { | |
6529 | register tree fndecl = current_function_decl; | |
6530 | register tree parm; | |
6531 | ||
6532 | tree parmdecls = TREE_PURPOSE (parmlist); | |
6533 | ||
6534 | /* This is a chain of any other decls that came in among the parm | |
6535 | declarations. They were separated already by get_parm_info, | |
6536 | so we just need to keep them separate. */ | |
6537 | tree nonparms = TREE_VALUE (parmlist); | |
6538 | ||
6539 | tree types = 0; | |
6540 | ||
6541 | for (parm = parmdecls; parm; parm = TREE_CHAIN (parm)) | |
6542 | DECL_RESULT (parm) = 0; | |
6543 | ||
6544 | for (parm = specparms; parm; parm = TREE_CHAIN (parm)) | |
6545 | { | |
6546 | register tree tail, found = NULL; | |
6547 | ||
6548 | /* See if any of the parmdecls specifies this parm by name. */ | |
6549 | for (tail = parmdecls; tail; tail = TREE_CHAIN (tail)) | |
6550 | if (DECL_NAME (tail) == TREE_VALUE (parm)) | |
6551 | { | |
6552 | found = tail; | |
6553 | break; | |
6554 | } | |
6555 | ||
6556 | /* If declaration already marked, we have a duplicate name. | |
6557 | Complain, and don't use this decl twice. */ | |
6558 | if (found && DECL_RESULT (found) != 0) | |
6559 | { | |
6560 | error_with_decl (found, "multiple parameters named `%s'"); | |
6561 | found = 0; | |
6562 | } | |
6563 | ||
6564 | /* If the declaration says "void", complain and ignore it. */ | |
5fe86b8b | 6565 | if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node) |
51e29401 RS |
6566 | { |
6567 | error_with_decl (found, "parameter `%s' declared void"); | |
6568 | TREE_TYPE (found) = integer_type_node; | |
6569 | DECL_ARG_TYPE (found) = integer_type_node; | |
6570 | layout_decl (found, 0); | |
6571 | } | |
6572 | ||
6573 | /* Traditionally, a parm declared float is actually a double. */ | |
6574 | if (found && flag_traditional | |
90d56da8 | 6575 | && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node) |
6d142a10 RS |
6576 | { |
6577 | TREE_TYPE (found) = double_type_node; | |
6578 | DECL_ARG_TYPE (found) = double_type_node; | |
6579 | layout_decl (found, 0); | |
6580 | } | |
51e29401 RS |
6581 | |
6582 | /* If no declaration found, default to int. */ | |
6583 | if (!found) | |
6584 | { | |
6585 | found = build_decl (PARM_DECL, TREE_VALUE (parm), | |
6586 | integer_type_node); | |
6587 | DECL_ARG_TYPE (found) = TREE_TYPE (found); | |
6588 | DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl); | |
6589 | DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl); | |
6b2a374b | 6590 | error_with_decl (found, "type of parameter `%s' is not declared"); |
51e29401 RS |
6591 | pushdecl (found); |
6592 | } | |
6593 | ||
6594 | TREE_PURPOSE (parm) = found; | |
6595 | ||
6596 | /* Mark this decl as "already found" -- see test, above. | |
6597 | It is safe to use DECL_RESULT for this | |
6598 | since it is not used in PARM_DECLs or CONST_DECLs. */ | |
6599 | DECL_RESULT (found) = error_mark_node; | |
6600 | } | |
6601 | ||
6602 | /* Complain about any actual PARM_DECLs not matched with any names. */ | |
6603 | ||
6604 | for (parm = parmdecls; parm; ) | |
6605 | { | |
6606 | tree next = TREE_CHAIN (parm); | |
6607 | TREE_CHAIN (parm) = 0; | |
6608 | ||
6609 | /* Complain about args with incomplete types. */ | |
6610 | if (TYPE_SIZE (TREE_TYPE (parm)) == 0) | |
6611 | { | |
6612 | error_with_decl (parm, "parameter `%s' has incomplete type"); | |
6613 | TREE_TYPE (parm) = error_mark_node; | |
6614 | } | |
6615 | ||
6616 | if (DECL_RESULT (parm) == 0) | |
6617 | { | |
6618 | error_with_decl (parm, | |
6619 | "declaration for parameter `%s' but no such parameter"); | |
6620 | /* Pretend the parameter was not missing. | |
6621 | This gets us to a standard state and minimizes | |
6622 | further error messages. */ | |
6623 | specparms | |
6624 | = chainon (specparms, | |
6625 | tree_cons (parm, NULL_TREE, NULL_TREE)); | |
6626 | } | |
6627 | ||
6628 | parm = next; | |
6629 | } | |
6630 | ||
6631 | /* Chain the declarations together in the order of the list of names. | |
6632 | At the same time, build up a list of their types, in reverse order. */ | |
6633 | ||
6634 | parm = specparms; | |
6635 | parmdecls = 0; | |
6636 | { | |
6637 | register tree last; | |
6638 | for (last = 0; parm; parm = TREE_CHAIN (parm)) | |
6639 | if (TREE_PURPOSE (parm)) | |
6640 | { | |
6641 | if (last == 0) | |
6642 | parmdecls = TREE_PURPOSE (parm); | |
6643 | else | |
6644 | TREE_CHAIN (last) = TREE_PURPOSE (parm); | |
6645 | last = TREE_PURPOSE (parm); | |
6646 | TREE_CHAIN (last) = 0; | |
6647 | ||
6648 | types = saveable_tree_cons (NULL_TREE, TREE_TYPE (parm), types); | |
6649 | } | |
6650 | } | |
6651 | ||
6652 | if (void_at_end) | |
6653 | return saveable_tree_cons (parmdecls, nonparms, | |
6654 | nreverse (saveable_tree_cons (NULL_TREE, void_type_node, types))); | |
6655 | ||
6656 | return saveable_tree_cons (parmdecls, nonparms, nreverse (types)); | |
6657 | } | |
6658 | \f | |
6659 | /* Finish up a function declaration and compile that function | |
6660 | all the way to assembler language output. The free the storage | |
6661 | for the function definition. | |
6662 | ||
6663 | This is called after parsing the body of the function definition. | |
6664 | ||
6665 | NESTED is nonzero if the function being finished is nested in another. */ | |
6666 | ||
6667 | void | |
6668 | finish_function (nested) | |
6669 | int nested; | |
6670 | { | |
6671 | register tree fndecl = current_function_decl; | |
6672 | ||
6673 | /* TREE_READONLY (fndecl) = 1; | |
6674 | This caused &foo to be of type ptr-to-const-function | |
6675 | which then got a warning when stored in a ptr-to-function variable. */ | |
6676 | ||
6677 | poplevel (1, 0, 1); | |
960a2eb1 | 6678 | BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; |
51e29401 RS |
6679 | |
6680 | /* Must mark the RESULT_DECL as being in this function. */ | |
6681 | ||
6682 | DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; | |
6683 | ||
6684 | /* Obey `register' declarations if `setjmp' is called in this fn. */ | |
6685 | if (flag_traditional && current_function_calls_setjmp) | |
6686 | { | |
6687 | setjmp_protect (DECL_INITIAL (fndecl)); | |
6688 | setjmp_protect_args (); | |
6689 | } | |
6690 | ||
6691 | #ifdef DEFAULT_MAIN_RETURN | |
6692 | if (! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")) | |
6693 | { | |
90d56da8 RS |
6694 | if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) |
6695 | != integer_type_node) | |
8e077183 RS |
6696 | warning_with_decl (fndecl, "return type of `%s' is not `int'"); |
6697 | else | |
6698 | { | |
6699 | /* Make it so that `main' always returns success by default. */ | |
6700 | DEFAULT_MAIN_RETURN; | |
6701 | } | |
51e29401 RS |
6702 | } |
6703 | #endif | |
6704 | ||
6705 | /* Generate rtl for function exit. */ | |
0e5eedfe | 6706 | expand_function_end (input_filename, lineno, 0); |
51e29401 RS |
6707 | |
6708 | /* So we can tell if jump_optimize sets it to 1. */ | |
6709 | can_reach_end = 0; | |
6710 | ||
6711 | /* Run the optimizers and output the assembler code for this function. */ | |
6712 | rest_of_compilation (fndecl); | |
6713 | ||
6714 | current_function_returns_null |= can_reach_end; | |
6715 | ||
6716 | if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) | |
11433f42 | 6717 | warning ("`noreturn' function does return"); |
42dfa47f | 6718 | else if (warn_return_type && can_reach_end |
51e29401 RS |
6719 | && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) != void_type_node) |
6720 | /* If this function returns non-void and control can drop through, | |
6721 | complain. */ | |
6722 | warning ("control reaches end of non-void function"); | |
6723 | /* With just -W, complain only if function returns both with | |
6724 | and without a value. */ | |
6725 | else if (extra_warnings | |
6726 | && current_function_returns_value && current_function_returns_null) | |
6727 | warning ("this function may return with or without a value"); | |
6728 | ||
739d15ab RK |
6729 | /* If requested, warn about function definitions where the function will |
6730 | return a value (usually of some struct or union type) which itself will | |
6731 | take up a lot of stack space. */ | |
6732 | ||
6733 | if (warn_larger_than && !DECL_EXTERNAL (fndecl) && TREE_TYPE (fndecl)) | |
6734 | { | |
6735 | register tree ret_type = TREE_TYPE (TREE_TYPE (fndecl)); | |
6736 | ||
6737 | if (ret_type) | |
6738 | { | |
6739 | register tree ret_type_size = TYPE_SIZE (ret_type); | |
6740 | ||
6741 | if (TREE_CODE (ret_type_size) == INTEGER_CST) | |
6742 | { | |
6743 | unsigned units | |
6744 | = TREE_INT_CST_LOW (ret_type_size) / BITS_PER_UNIT; | |
6745 | ||
6746 | if (units > larger_than_size) | |
6747 | warning_with_decl (fndecl, | |
6748 | "size of return value of `%s' is %u bytes", | |
6749 | units); | |
6750 | } | |
6751 | } | |
6752 | } | |
6753 | ||
51e29401 RS |
6754 | /* Free all the tree nodes making up this function. */ |
6755 | /* Switch back to allocating nodes permanently | |
6756 | until we start another function. */ | |
6757 | if (! nested) | |
3e755d23 | 6758 | permanent_allocation (1); |
51e29401 RS |
6759 | |
6760 | if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested) | |
6761 | { | |
6762 | /* Stop pointing to the local nodes about to be freed. */ | |
6763 | /* But DECL_INITIAL must remain nonzero so we know this | |
6764 | was an actual function definition. */ | |
6765 | /* For a nested function, this is done in pop_c_function_context. */ | |
708e813b RS |
6766 | /* If rest_of_compilation set this to 0, leave it 0. */ |
6767 | if (DECL_INITIAL (fndecl) != 0) | |
6768 | DECL_INITIAL (fndecl) = error_mark_node; | |
51e29401 RS |
6769 | DECL_ARGUMENTS (fndecl) = 0; |
6770 | } | |
6771 | ||
2c5f4139 JM |
6772 | if (DECL_STATIC_CONSTRUCTOR (fndecl)) |
6773 | { | |
6774 | #ifndef ASM_OUTPUT_CONSTRUCTOR | |
6775 | if (! flag_gnu_linker) | |
6776 | static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); | |
6777 | else | |
6778 | #endif | |
6779 | assemble_constructor (IDENTIFIER_POINTER (DECL_NAME (fndecl))); | |
6780 | } | |
6781 | if (DECL_STATIC_DESTRUCTOR (fndecl)) | |
6782 | { | |
6783 | #ifndef ASM_OUTPUT_DESTRUCTOR | |
6784 | if (! flag_gnu_linker) | |
6785 | static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); | |
6786 | else | |
6787 | #endif | |
6788 | assemble_destructor (IDENTIFIER_POINTER (DECL_NAME (fndecl))); | |
6789 | } | |
6790 | ||
51e29401 RS |
6791 | if (! nested) |
6792 | { | |
6793 | /* Let the error reporting routines know that we're outside a | |
6794 | function. For a nested function, this value is used in | |
6795 | pop_c_function_context and then reset via pop_function_context. */ | |
6796 | current_function_decl = NULL; | |
6797 | } | |
6798 | } | |
6799 | \f | |
6800 | /* Save and restore the variables in this file and elsewhere | |
6801 | that keep track of the progress of compilation of the current function. | |
6802 | Used for nested functions. */ | |
6803 | ||
6804 | struct c_function | |
6805 | { | |
6806 | struct c_function *next; | |
51e29401 RS |
6807 | tree named_labels; |
6808 | tree shadowed_labels; | |
6809 | int returns_value; | |
6810 | int returns_null; | |
6811 | int warn_about_return_type; | |
6812 | int extern_inline; | |
6813 | struct binding_level *binding_level; | |
6814 | }; | |
6815 | ||
6816 | struct c_function *c_function_chain; | |
6817 | ||
6818 | /* Save and reinitialize the variables | |
6819 | used during compilation of a C function. */ | |
6820 | ||
6821 | void | |
6822 | push_c_function_context () | |
6823 | { | |
6824 | struct c_function *p | |
6825 | = (struct c_function *) xmalloc (sizeof (struct c_function)); | |
6826 | ||
ec2343c4 MM |
6827 | if (pedantic) |
6828 | pedwarn ("ANSI C forbids nested functions"); | |
6829 | ||
51e29401 RS |
6830 | push_function_context (); |
6831 | ||
6832 | p->next = c_function_chain; | |
6833 | c_function_chain = p; | |
6834 | ||
51e29401 RS |
6835 | p->named_labels = named_labels; |
6836 | p->shadowed_labels = shadowed_labels; | |
6837 | p->returns_value = current_function_returns_value; | |
6838 | p->returns_null = current_function_returns_null; | |
6839 | p->warn_about_return_type = warn_about_return_type; | |
6840 | p->extern_inline = current_extern_inline; | |
6841 | p->binding_level = current_binding_level; | |
6842 | } | |
6843 | ||
6844 | /* Restore the variables used during compilation of a C function. */ | |
6845 | ||
6846 | void | |
6847 | pop_c_function_context () | |
6848 | { | |
6849 | struct c_function *p = c_function_chain; | |
6850 | tree link; | |
6851 | ||
6852 | /* Bring back all the labels that were shadowed. */ | |
6853 | for (link = shadowed_labels; link; link = TREE_CHAIN (link)) | |
6854 | if (DECL_NAME (TREE_VALUE (link)) != 0) | |
6855 | IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) | |
6856 | = TREE_VALUE (link); | |
6857 | ||
6858 | if (DECL_SAVED_INSNS (current_function_decl) == 0) | |
6859 | { | |
6860 | /* Stop pointing to the local nodes about to be freed. */ | |
6861 | /* But DECL_INITIAL must remain nonzero so we know this | |
6862 | was an actual function definition. */ | |
6863 | DECL_INITIAL (current_function_decl) = error_mark_node; | |
6864 | DECL_ARGUMENTS (current_function_decl) = 0; | |
6865 | } | |
6866 | ||
6867 | pop_function_context (); | |
6868 | ||
6869 | c_function_chain = p->next; | |
6870 | ||
51e29401 RS |
6871 | named_labels = p->named_labels; |
6872 | shadowed_labels = p->shadowed_labels; | |
6873 | current_function_returns_value = p->returns_value; | |
6874 | current_function_returns_null = p->returns_null; | |
6875 | warn_about_return_type = p->warn_about_return_type; | |
6876 | current_extern_inline = p->extern_inline; | |
6877 | current_binding_level = p->binding_level; | |
6878 | ||
6879 | free (p); | |
6880 | } | |
37105beb JM |
6881 | |
6882 | /* integrate_decl_tree calls this function, but since we don't use the | |
6883 | DECL_LANG_SPECIFIC field, this is a no-op. */ | |
6884 | ||
6885 | void | |
6886 | copy_lang_decl (node) | |
6887 | tree node; | |
6888 | { | |
6889 | } |