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