|
|
1.1 root 1: /* Process declarations and variables for C compiler.
1.1.1.2 root 2: Copyright (C) 1988 Free Software Foundation, Inc.
1.1 root 3:
4: This file is part of GNU CC.
5:
6: GNU CC is distributed in the hope that it will be useful,
7: but WITHOUT ANY WARRANTY. No author or distributor
8: accepts responsibility to anyone for the consequences of using it
9: or for whether it serves any particular purpose or works at all,
10: unless he says so in writing. Refer to the GNU CC General Public
11: License for full details.
12:
13: Everyone is granted permission to copy, modify and redistribute
14: GNU CC, but only under the conditions described in the
15: GNU CC General Public License. A copy of this license is
16: supposed to have been given to you along with GNU CC so you
17: can know your rights and responsibilities. It should be in a
18: file named COPYING. Among other things, the copyright notice
19: and this notice must be preserved on all copies. */
20:
21:
22: /* Process declarations and symbol lookup for C front end.
23: Also constructs types; the standard scalar types at initialization,
24: and structure, union, array and enum types when they are declared. */
25:
26: /* ??? not all decl nodes are given the most useful possible
27: line numbers. For example, the CONST_DECLs for enum values. */
28:
29: #include "config.h"
30: #include "tree.h"
1.1.1.2 root 31: #include "flags.h"
1.1 root 32: #include "c-tree.h"
1.1.1.2 root 33: #include "parse.h"
1.1 root 34:
35: /* In grokdeclarator, distinguish syntactic contexts of declarators. */
36: enum decl_context
37: { NORMAL, /* Ordinary declaration */
1.1.1.2 root 38: FUNCDEF, /* Function definition */
1.1 root 39: PARM, /* Declaration of parm before function body */
40: FIELD, /* Declaration inside struct or union */
41: TYPENAME}; /* Typename (inside cast or sizeof) */
42:
43: #define NULL 0
1.1.1.3 root 44: #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
45: #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
1.1 root 46:
47: static tree grokparms (), grokdeclarator ();
1.1.1.2 root 48: tree pushdecl ();
49: tree make_index_type ();
1.1 root 50: static void builtin_function ();
51:
52: static tree lookup_tag ();
1.1.1.2 root 53: static tree lookup_tag_reverse ();
1.1 root 54: static tree lookup_name_current_level ();
1.1.1.2 root 55: static char *redeclaration_error_message ();
1.1 root 56:
57: /* a node which has tree code ERROR_MARK, and whose type is itself.
58: All erroneous expressions are replaced with this node. All functions
59: that accept nodes as arguments should avoid generating error messages
60: if this node is one of the arguments, since it is undesirable to get
61: multiple error messages from one error in the input. */
62:
63: tree error_mark_node;
64:
65: /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
66:
67: tree short_integer_type_node;
68: tree integer_type_node;
69: tree long_integer_type_node;
70:
71: tree short_unsigned_type_node;
72: tree unsigned_type_node;
73: tree long_unsigned_type_node;
74:
75: tree unsigned_char_type_node;
1.1.1.2 root 76: tree signed_char_type_node;
1.1 root 77: tree char_type_node;
78:
79: tree float_type_node;
80: tree double_type_node;
81: tree long_double_type_node;
82:
83: /* a VOID_TYPE node. */
84:
85: tree void_type_node;
86:
87: /* A node for type `void *'. */
88:
89: tree ptr_type_node;
90:
91: /* A node for type `char *'. */
92:
93: tree string_type_node;
94:
95: /* Type `char[256]' or something like it.
96: Used when an array of char is needed and the size is irrelevant. */
97:
98: tree char_array_type_node;
99:
1.1.1.2 root 100: /* Type `int[256]' or something like it.
101: Used when an array of int needed and the size is irrelevant. */
102:
103: tree int_array_type_node;
104:
1.1 root 105: /* type `int ()' -- used for implicit declaration of functions. */
106:
107: tree default_function_type;
108:
109: /* function types `double (double)' and `double (double, double)', etc. */
110:
111: tree double_ftype_double, double_ftype_double_double;
112: tree int_ftype_int, long_ftype_long;
113:
114: /* Function type `void (void *, void *, int)' and similar ones */
115:
116: tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
117:
118: /* Two expressions that are constants with value zero.
119: The first is of type `int', the second of type `void *'. */
120:
121: tree integer_zero_node;
122: tree null_pointer_node;
123:
124: /* A node for the integer constant 1. */
125:
126: tree integer_one_node;
127:
128: /* An identifier whose name is <value>. This is used as the "name"
129: of the RESULT_DECLs for values of functions. */
130:
131: tree value_identifier;
132:
1.1.1.2 root 133: /* While defining an enum type, this is 1 plus the last enumerator
134: constant value. */
1.1 root 135:
1.1.1.2 root 136: static tree enum_next_value;
1.1 root 137:
1.1.1.2 root 138: /* Parsing a function declarator leaves a list of parameter names
139: or a chain or parameter decls here. */
1.1 root 140:
1.1.1.2 root 141: static tree last_function_parms;
1.1 root 142:
1.1.1.2 root 143: /* Parsing a function declarator leaves here a chain of structure
144: and enum types declared in the parmlist. */
1.1 root 145:
1.1.1.2 root 146: static tree last_function_parm_tags;
147:
148: /* After parsing the declarator that starts a function definition,
149: `start_function' puts here the list of parameter names or chain of decls.
150: `store_parm_decls' finds it here. */
151:
152: static tree current_function_parms;
153:
154: /* Similar, for last_function_parm_tags. */
155: static tree current_function_parm_tags;
1.1 root 156:
157: /* A list (chain of TREE_LIST nodes) of all LABEL_STMTs in the function
158: that have names. Here so we can clear out their names' definitions
159: at the end of the function. */
160:
161: static tree named_labels;
162:
1.1.1.2 root 163: /* The FUNCTION_DECL for the function currently being compiled,
164: or 0 if between functions. */
165: tree current_function_decl;
1.1 root 166:
167: /* Set to 0 at beginning of a function definition, set to 1 if
168: a return statement that specifies a return value is seen. */
169:
170: int current_function_returns_value;
1.1.1.2 root 171:
172: /* Set to 0 at beginning of a function definition, set to 1 if
173: a return statement with no argument is seen. */
174:
175: int current_function_returns_null;
176:
177: /* Set to nonzero by `grokdeclarator' for a function
178: whose return type is defaulted, if warnings for this are desired. */
179:
180: static int warn_about_return_type;
1.1 root 181:
182: /* For each binding contour we allocate a binding_level structure
183: * which records the names defined in that contour.
184: * Contours include:
185: * 0) the global one
186: * 1) one for each function definition,
187: * where internal declarations of the parameters appear.
188: * 2) one for each compound statement,
189: * to record its declarations.
190: *
191: * The current meaning of a name can be found by searching the levels from
192: * the current one out to the global one.
193: */
194:
195: /* Note that the information in the `names' component of the global contour
196: is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
197:
1.1.1.2 root 198: struct binding_level
1.1 root 199: {
200: /* A chain of _DECL nodes for all variables, constants, functions,
201: and typedef types. These are in the reverse of the order supplied.
202: */
203: tree names;
204:
205: /* A list of structure, union and enum definitions,
206: * for looking up tag names.
207: * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
208: * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
209: * or ENUMERAL_TYPE node.
210: */
211: tree tags;
212:
213: /* For each level, a list of shadowed outer-level local definitions
214: to be restored when this level is popped.
215: Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
216: whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
217: tree shadowed;
218:
1.1.1.2 root 219: /* For each level (except not the global one),
220: a chain of LET_STMT nodes for all the levels
221: that were entered and exited one level down. */
222: tree blocks;
223:
1.1 root 224: /* The binding level which this one is contained in (inherits from). */
225: struct binding_level *level_chain;
1.1.1.2 root 226:
227: /* Nonzero for the level that holds the parameters of a function. */
228: char parm_flag;
229:
230: /* Nonzero if this level "doesn't exist" for tags. */
231: char tag_transparent;
232:
233: /* Number of decls in `names' that have incomplete
234: structure or union types. */
235: int n_incomplete;
1.1 root 236: };
237:
238: #define NULL_BINDING_LEVEL (struct binding_level *) NULL
239:
240: /* The binding level currently in effect. */
241:
242: static struct binding_level *current_binding_level;
243:
244: /* A chain of binding_level structures awaiting reuse. */
245:
246: static struct binding_level *free_binding_level;
247:
248: /* The outermost binding level, for names of file scope.
249: This is created when the compiler is started and exists
250: through the entire run. */
251:
252: static struct binding_level *global_binding_level;
253:
254: /* Binding level structures are initialized by copying this one. */
255:
1.1.1.2 root 256: static struct binding_level clear_binding_level
257: = {NULL, NULL, NULL, NULL, NULL, 0, 0, 0};
1.1 root 258:
259: /* Create a new `struct binding_level'. */
260:
261: static
262: struct binding_level *
263: make_binding_level ()
264: {
265: /* NOSTRICT */
266: return (struct binding_level *) xmalloc (sizeof (struct binding_level));
267: }
268:
1.1.1.4 ! root 269: /* Nonzero if we are currently in the global binding level. */
! 270:
! 271: int
! 272: global_bindings_p ()
! 273: {
! 274: return current_binding_level == global_binding_level;
! 275: }
! 276:
1.1.1.2 root 277: /* Enter a new binding level.
278: If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
279: not for that of tags. */
1.1 root 280:
281: void
1.1.1.2 root 282: pushlevel (tag_transparent)
283: int tag_transparent;
1.1 root 284: {
285: register struct binding_level *newlevel = NULL_BINDING_LEVEL;
286:
287: /* If this is the top level of a function,
1.1.1.2 root 288: just make sure that NAMED_LABELS is 0.
1.1 root 289: They should have been set to 0 at the end of the previous function. */
290:
291: if (current_binding_level == global_binding_level)
292: {
1.1.1.2 root 293: if (named_labels)
1.1 root 294: abort ();
295: }
296:
297: /* Reuse or create a struct for this binding level. */
298:
299: if (free_binding_level)
300: {
301: newlevel = free_binding_level;
302: free_binding_level = free_binding_level->level_chain;
303: }
304: else
305: {
306: newlevel = make_binding_level ();
307: }
308:
309: /* Add this level to the front of the chain (stack) of levels that
310: are active. */
311:
312: *newlevel = clear_binding_level;
313: newlevel->level_chain = current_binding_level;
314: current_binding_level = newlevel;
1.1.1.2 root 315: newlevel->tag_transparent = tag_transparent;
1.1 root 316: }
317:
1.1.1.2 root 318: /* Exit a binding level.
319: Pop the level off, and restore the state of the identifier-decl mappings
320: that were in effect when this level was entered.
321:
322: If KEEP is nonzero, this level had explicit declarations, so
323: and create a "block" (a LET_STMT node) for the level
324: to record its declarations and subblocks for symbol table output.
325:
326: If FUNCTIONBODY is nonzero, this level is the body of a function,
327: so create a block as if KEEP were set and also clear out all
328: label names.
329:
330: If REVERSE is nonzero, reverse the order of decls before putting
331: them into the LET_STMT. */
1.1 root 332:
333: void
1.1.1.2 root 334: poplevel (keep, reverse, functionbody)
335: int keep;
336: int reverse;
337: int functionbody;
1.1 root 338: {
339: register tree link;
1.1.1.2 root 340: /* The chain of decls was accumulated in reverse order.
341: Put it into forward order, just for cleanliness. */
342: tree decls;
343: tree tags = current_binding_level->tags;
344: tree subblocks = current_binding_level->blocks;
345: tree block = 0;
346:
347: /* This warning is turned off because it causes warnings for
348: declarations like `extern struct foo *x'. */
349: #if 0
350: /* Warn about incomplete structure types in this level. */
351: for (link = tags; link; link = TREE_CHAIN (link))
352: if (TYPE_SIZE (TREE_VALUE (link)) == 0)
353: {
354: tree type = TREE_VALUE (link);
355: char *errmsg;
356: switch (TREE_CODE (type))
357: {
358: case RECORD_TYPE:
359: errmsg = "`struct %s' incomplete in scope ending here";
360: break;
361: case UNION_TYPE:
362: errmsg = "`union %s' incomplete in scope ending here";
363: break;
364: case ENUMERAL_TYPE:
365: errmsg = "`enum %s' incomplete in scope ending here";
366: break;
367: }
368: if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
369: error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
370: else
371: /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
372: error (errmsg, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
373: }
374: #endif /* 0 */
375:
376: /* Get the decls in the order they were written.
377: Usually current_binding_level->names is in reverse order.
378: But parameter decls were previously put in forward order. */
379:
380: if (reverse)
381: current_binding_level->names
382: = decls = nreverse (current_binding_level->names);
383: else
384: decls = current_binding_level->names;
385:
386: /* If there were any declarations or structure tags in that level,
387: or if this level is a function body,
388: create a LET_STMT to record them for the life of this function. */
1.1 root 389:
1.1.1.2 root 390: if (keep || functionbody)
391: block = build_let (0, 0, keep ? decls : 0,
392: subblocks, 0, keep ? tags : 0);
1.1 root 393:
1.1.1.2 root 394: /* In each subblock, record that this is its superior. */
395:
396: for (link = subblocks; link; link = TREE_CHAIN (link))
397: STMT_SUPERCONTEXT (link) = block;
398:
399: /* Clear out the meanings of the local variables of this level;
400: also record in each decl which block it belongs to. */
401:
402: for (link = decls; link; link = TREE_CHAIN (link))
403: {
404: if (DECL_NAME (link) != 0)
405: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
406: DECL_CONTEXT (link) = block;
407: }
1.1 root 408:
409: /* Restore all name-meanings of the outer levels
410: that were shadowed by this level. */
411:
412: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
413: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
414:
415: /* If the level being exited is the top level of a function,
1.1.1.2 root 416: check over all the labels. */
1.1 root 417:
1.1.1.2 root 418: if (functionbody)
1.1 root 419: {
1.1.1.2 root 420: /* Clear out the definitions of all label names,
421: since their scopes end here. */
1.1 root 422:
1.1.1.2 root 423: for (link = named_labels; link; link = TREE_CHAIN (link))
1.1 root 424: {
1.1.1.2 root 425: if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
1.1 root 426: {
1.1.1.2 root 427: error ("label `%s' used somewhere above but not defined",
428: IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (link))));
429: /* Avoid crashing later. */
430: define_label (input_filename, 1, DECL_NAME (TREE_VALUE (link)));
1.1 root 431: }
1.1.1.2 root 432: IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
1.1 root 433: }
434:
435: named_labels = 0;
436: }
437:
438: /* Pop the current level, and free the structure for reuse. */
439:
440: {
441: register struct binding_level *level = current_binding_level;
442: current_binding_level = current_binding_level->level_chain;
443:
444: level->level_chain = free_binding_level;
445: free_binding_level = level;
446: }
1.1.1.2 root 447:
448: if (functionbody)
449: {
450: DECL_INITIAL (current_function_decl) = block;
451: /* If this is the top level block of a function,
452: the vars are the function's parameters.
453: Don't leave them in the LET_STMT because they are
454: found in the FUNCTION_DECL instead. */
455: STMT_VARS (block) = 0;
456: }
457: else if (block)
458: current_binding_level->blocks
459: = chainon (current_binding_level->blocks, block);
460: /* If we did not make a block for the level just exited,
461: any blocks made for inner levels
462: (since they cannot be recorded as subblocks in that level)
463: must be carried forward so they will later become subblocks
464: of something else. */
465: else if (subblocks)
466: current_binding_level->blocks
467: = chainon (current_binding_level->blocks, subblocks);
468:
1.1 root 469: }
470:
471: /* Push a definition of struct, union or enum tag "name".
472: "type" should be the type node.
1.1.1.2 root 473: We assume that the tag "name" is not already defined.
474:
1.1 root 475: Note that the definition may really be just a forward reference.
476: In that case, the TYPE_SIZE will be zero. */
477:
478: void
479: pushtag (name, type)
480: tree name, type;
481: {
1.1.1.2 root 482: register struct binding_level *b = current_binding_level;
483: while (b->tag_transparent) b = b->level_chain;
1.1 root 484:
485: if (name)
486: {
487: /* Record the identifier as the type's name if it has none. */
488:
489: if (TYPE_NAME (type) == 0)
490: TYPE_NAME (type) = name;
491:
1.1.1.2 root 492: b->tags = tree_cons (name, type, b->tags);
493: }
1.1 root 494: }
1.1.1.2 root 495:
496: /* Handle when a new declaration NEW has the same name as an old one OLD
497: in the same binding contour. Prints an error message if appropriate.
498:
499: If safely possible, alter OLD to look like NEW, and return 1.
500: Otherwise, return 0. */
501:
502: static int
503: duplicate_decls (new, old)
504: register tree new, old;
505: {
506: int types_match = comptypes (TREE_TYPE (new), TREE_TYPE (old));
507:
508: /* If this decl has linkage, and the old one does too, maybe no error. */
509: if (TREE_CODE (old) != TREE_CODE (new))
1.1.1.4 ! root 510: {
! 511: error_with_decl (new, "`%s' redeclared as different kind of symbol");
! 512: error_with_decl (old, "previous declaration of `%s'");
! 513: }
1.1.1.2 root 514: else
515: {
516: if (!types_match)
1.1.1.4 ! root 517: {
! 518: error_with_decl (new, "conflicting types for `%s'");
! 519: error_with_decl (old, "previous declaration of `%s'");
! 520: }
1.1.1.2 root 521: else
522: {
523: char *errmsg = redeclaration_error_message (new, old);
524: if (errmsg)
1.1.1.4 ! root 525: {
! 526: error_with_decl (new, errmsg);
! 527: error_with_decl (old, "previous declaration of `%s'");
! 528: }
1.1.1.2 root 529: }
530: }
1.1 root 531:
1.1.1.2 root 532: if (TREE_CODE (old) == TREE_CODE (new))
533: {
534: /* Copy all the DECL_... slots specified in the new decl
535: except for any that we copy here from the old type. */
1.1 root 536:
1.1.1.2 root 537: if (types_match)
538: {
539: tree oldtype = TREE_TYPE (old);
540: /* Merge the data types specified in the two decls. */
541: TREE_TYPE (new)
542: = TREE_TYPE (old) = commontype (TREE_TYPE (new), TREE_TYPE (old));
1.1 root 543:
1.1.1.2 root 544: /* Lay the type out, unless already done. */
545: if (oldtype != TREE_TYPE (new))
546: {
547: if (TREE_TYPE (new) != error_mark_node)
548: layout_type (TREE_TYPE (new));
549: if (TREE_CODE (new) != FUNCTION_DECL
550: && TREE_CODE (new) != TYPE_DECL
551: && TREE_CODE (new) != CONST_DECL)
552: layout_decl (new);
553: }
554: else
555: {
556: /* Since the type is OLD's, make OLD's size go with. */
557: DECL_SIZE (new) = DECL_SIZE (old);
558: DECL_SIZE_UNIT (new) = DECL_SIZE_UNIT (old);
559: }
1.1 root 560:
1.1.1.2 root 561: /* Merge the initialization information. */
562: if (DECL_INITIAL (new) == 0)
563: DECL_INITIAL (new) = DECL_INITIAL (old);
564: /* Keep the old rtl since we can safely use it. */
565: DECL_RTL (new) = DECL_RTL (old);
566: }
567: /* If cannot merge, then use the new type
568: and discard the old rtl. */
569: else
570: TREE_TYPE (old) = TREE_TYPE (new);
571:
572: /* Merge the storage class information. */
573: if (TREE_EXTERNAL (new))
574: {
575: TREE_STATIC (new) = TREE_STATIC (old);
576: TREE_PUBLIC (new) = TREE_PUBLIC (old);
577: TREE_EXTERNAL (new) = TREE_EXTERNAL (old);
578: }
579: else
580: {
581: TREE_STATIC (old) = TREE_STATIC (new);
582: TREE_EXTERNAL (old) = 0;
583: TREE_PUBLIC (old) = TREE_PUBLIC (new);
584: }
585: /* If either decl says `inline', this fn is inline,
586: unless its definition was passed already. */
587: if (TREE_INLINE (new) && DECL_INITIAL (old) == 0)
588: TREE_INLINE (old) = 1;
589:
590: bcopy ((char *) new + sizeof (struct tree_common),
591: (char *) old + sizeof (struct tree_common),
592: sizeof (struct tree_decl) - sizeof (struct tree_common));
593: return 1;
1.1 root 594: }
1.1.1.2 root 595:
596: /* New decl is completely inconsistent with the old one =>
597: tell caller to replace the old one. */
598: return 0;
1.1 root 599: }
600:
601: /* Record a decl-node X as belonging to the current lexical scope.
602: Check for errors (such as an incompatible declaration for the same
603: name already seen in the same scope).
604:
605: Returns either X or an old decl for the same name.
1.1.1.2 root 606: If an old decl is returned, it may have been smashed
1.1 root 607: to agree with what X says. */
608:
609: tree
610: pushdecl (x)
611: tree x;
612: {
613: register tree t;
614: register tree name = DECL_NAME (x);
615:
616: if (name)
617: {
618: t = lookup_name_current_level (name);
1.1.1.2 root 619: if (t && duplicate_decls (x, t))
620: return t;
1.1 root 621:
622: /* If declaring a type as a typedef, and the type has no known
623: typedef name, install this TYPE_DECL as its typedef name. */
624: if (TREE_CODE (x) == TYPE_DECL)
1.1.1.3 root 625: if (TYPE_NAME (TREE_TYPE (x)) == 0)
1.1 root 626: TYPE_NAME (TREE_TYPE (x)) = x;
627:
1.1.1.2 root 628: /* This name is new in its binding level.
629: Install the new declaration and return it. */
630: if (current_binding_level == global_binding_level
631: /* In PCC-compatibility mode, extern decls
632: take effect at top level no matter where they are. */
633: || (flag_traditional && TREE_EXTERNAL (x)
634: && lookup_name (name) == 0))
635: {
636: /* Install a global value. */
637:
638: IDENTIFIER_GLOBAL_VALUE (name) = x;
639:
640: if (IDENTIFIER_IMPLICIT_DECL (name) != 0
641: /* If this real decl matches the implicit, don't complain. */
642: && ! (TREE_CODE (x) == FUNCTION_DECL
643: && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
644: warning ("`%s' was previously implicitly declared to return `int'",
645: IDENTIFIER_POINTER (name));
1.1.1.4 ! root 646:
! 647: /* If this decl is `static' and an `extern' was seen previously,
! 648: that is erroneous. */
! 649: if (TREE_PUBLIC (name)
! 650: && ! TREE_PUBLIC (x) && ! TREE_EXTERNAL (x))
! 651: warning ("`%s' was declared `extern' and later `static'",
! 652: IDENTIFIER_POINTER (name));
1.1.1.2 root 653: }
654: else
655: {
1.1.1.3 root 656: /* Here to install a non-global value. */
657: tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
658: IDENTIFIER_LOCAL_VALUE (name) = x;
659:
660: /* If this is an extern function declaration, see if we
661: have a global definition for the function. */
662: if (oldlocal == 0
663: && IDENTIFIER_GLOBAL_VALUE (name)
664: && TREE_CODE (x) == FUNCTION_DECL
665: && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == FUNCTION_DECL
666: && TREE_INLINE (IDENTIFIER_GLOBAL_VALUE (name)))
667: {
668: /* We have one. Their types must agree. */
669: if (! comptypes (TREE_TYPE (x),
670: TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name))))
671: warning_with_decl (x, "local declaration of `%s' doesn't match global one");
672: /* If the global one is inline, make the local one inline. */
673: else if (TREE_INLINE (IDENTIFIER_GLOBAL_VALUE (name)))
674: IDENTIFIER_LOCAL_VALUE (name) = IDENTIFIER_GLOBAL_VALUE (name);
675: }
1.1.1.4 ! root 676: /* If we have a local external declaration,
! 677: and no file-scope declaration has yet been seen,
! 678: then if we later have a file-scope decl it may not be static. */
! 679: if (oldlocal == 0
! 680: && IDENTIFIER_GLOBAL_VALUE (name) == 0
! 681: && TREE_EXTERNAL (x))
! 682: {
! 683: TREE_PUBLIC (name) = 1;
! 684: }
1.1.1.3 root 685: /* Warn if shadowing an argument. */
686: if (oldlocal != 0
687: && TREE_CODE (oldlocal) == PARM_DECL
1.1.1.2 root 688: && current_binding_level->level_chain->parm_flag)
689: warning ("shadowing parameter `%s' with a local variable",
690: IDENTIFIER_POINTER (name));
691: /* If storing a local value, there may already be one (inherited).
692: If so, record it for restoration when this binding level ends. */
1.1.1.3 root 693: if (oldlocal != 0)
1.1.1.2 root 694: current_binding_level->shadowed
1.1.1.3 root 695: = tree_cons (name, oldlocal,
1.1.1.2 root 696: current_binding_level->shadowed);
697: }
698:
699: /* Keep count of variables in this level with incomplete type. */
700: if (TYPE_SIZE (TREE_TYPE (x)) == 0)
701: ++current_binding_level->n_incomplete;
1.1 root 702: }
703:
704: /* Put decls on list in reverse order.
705: We will reverse them later if necessary. */
1.1.1.2 root 706: TREE_CHAIN (x) = current_binding_level->names;
707: current_binding_level->names = x;
1.1 root 708:
709: return x;
710: }
1.1.1.2 root 711:
712: /* Generate an implicit declaration for identifier FUNCTIONID
713: as a function of type int (). Print a warning if appropriate. */
1.1 root 714:
1.1.1.2 root 715: tree
716: implicitly_declare (functionid)
717: tree functionid;
1.1 root 718: {
1.1.1.2 root 719: register tree decl;
1.1 root 720:
1.1.1.4 ! root 721: /* Save the decl permanently so we can warn if definition follows. */
! 722: end_temporary_allocation ();
1.1.1.2 root 723:
1.1.1.4 ! root 724: if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
! 725: decl = IDENTIFIER_IMPLICIT_DECL (functionid);
! 726: else
! 727: decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
1.1.1.2 root 728:
729: TREE_EXTERNAL (decl) = 1;
730: TREE_PUBLIC (decl) = 1;
731:
732: /* ANSI standard says implicit declarations are in the innermost block.
733: So we record the decl in the standard fashion.
734: If flag_traditional is set, pushdecl does it top-level. */
735: pushdecl (decl);
736: rest_of_decl_compilation (decl, 0, 0, 0);
737:
738: if (warn_implicit
739: /* Only one warning per identifier. */
740: && IDENTIFIER_IMPLICIT_DECL (functionid) == 0)
741: warning ("implicit declaration of function `%s'",
742: IDENTIFIER_POINTER (functionid));
743:
744: IDENTIFIER_IMPLICIT_DECL (functionid) = decl;
745:
1.1.1.4 ! root 746: resume_temporary_allocation ();
1.1.1.2 root 747:
748: return decl;
749: }
750:
751: /* Return zero if the declaration NEW is valid
752: when the declaration OLD (assumed to be for the same name)
753: has already been seen.
754: Otherwise return an error message format string with a %s
755: where the identifier should go. */
1.1 root 756:
1.1.1.2 root 757: static char *
758: redeclaration_error_message (new, old)
759: tree new, old;
760: {
761: if (TREE_CODE (new) == TYPE_DECL)
762: return "redefinition of `%s'";
763: else if (TREE_CODE (new) == FUNCTION_DECL)
764: {
765: /* Declarations of functions can insist on internal linkage
766: but they can't be inconsistent with internal linkage,
767: so there can be no error on that account.
768: However defining the same name twice is no good. */
769: if (DECL_INITIAL (old) != 0 && DECL_INITIAL (new) != 0)
770: return "redefinition of `%s'";
771: return 0;
772: }
773: else if (current_binding_level == global_binding_level)
774: {
775: /* Objects declared at top level: */
776: /* If at least one is a reference, it's ok. */
777: if (TREE_EXTERNAL (new) || TREE_EXTERNAL (old))
778: return 0;
779: /* Reject two definitions. */
780: if (DECL_INITIAL (old) != 0 && DECL_INITIAL (new) != 0)
781: return "redefinition of `%s'";
782: /* Now we have two tentative defs, or one tentative and one real def. */
783: /* Insist that the linkage match. */
784: if (TREE_PUBLIC (old) != TREE_PUBLIC (new))
785: return "conflicting declarations of `%s'";
786: return 0;
787: }
1.1 root 788: else
1.1.1.2 root 789: {
790: /* Objects declared with block scope: */
791: /* Reject two definitions, and reject a definition
792: together with an external reference. */
793: if (!(TREE_EXTERNAL (new) && TREE_EXTERNAL (old)))
794: return "redeclaration of `%s'";
795: return 0;
796: }
797: }
798:
799: /* Get the LABEL_DECL corresponding to identifier ID as a label.
800: Create one if none exists so far for the current function.
801: This function is called for both label definitions and label references. */
802:
803: tree
804: lookup_label (id)
805: tree id;
806: {
807: register tree decl = IDENTIFIER_LABEL_VALUE (id);
808:
809: if (decl != 0)
810: return decl;
811:
812: decl = build_decl (LABEL_DECL, id, NULL_TREE);
813: DECL_MODE (decl) = VOIDmode;
814: /* Mark that the label's definition has not been seen. */
815: DECL_SOURCE_LINE (decl) = 0;
816:
817: IDENTIFIER_LABEL_VALUE (id) = decl;
1.1 root 818:
819: named_labels
1.1.1.2 root 820: = tree_cons (NULL_TREE, decl, named_labels);
821:
822: return decl;
1.1 root 823: }
824:
1.1.1.2 root 825: /* Define a label, specifying the location in the source file.
826: Return the LABEL_DECL node for the label, if the definition is valid.
827: Otherwise return 0. */
1.1 root 828:
1.1.1.2 root 829: tree
830: define_label (filename, line, name)
831: char *filename;
832: int line;
833: tree name;
1.1 root 834: {
1.1.1.2 root 835: tree decl = lookup_label (name);
836: if (DECL_SOURCE_LINE (decl) != 0)
837: {
838: error_with_decl (decl, "duplicate label `%s'");
839: return 0;
840: }
841: else
842: {
843: /* Mark label as having been defined. */
844: DECL_SOURCE_FILE (decl) = filename;
845: DECL_SOURCE_LINE (decl) = line;
846: return decl;
847: }
1.1 root 848: }
849:
850: /* Return the list of declarations of the current level.
1.1.1.2 root 851: Note that this list is in reverse order unless/until
852: you nreverse it; and when you do nreverse it, you must
853: store the result back using `storedecls' or you will lose. */
1.1 root 854:
855: tree
856: getdecls ()
857: {
1.1.1.2 root 858: return current_binding_level->names;
1.1 root 859: }
860:
861: /* Return the list of type-tags (for structs, etc) of the current level. */
862:
863: tree
864: gettags ()
865: {
866: return current_binding_level->tags;
867: }
868:
869: /* Store the list of declarations of the current level.
870: This is done for the parameter declarations of a function being defined,
871: after they are modified in the light of any missing parameters. */
872:
1.1.1.2 root 873: static void
1.1 root 874: storedecls (decls)
875: tree decls;
876: {
877: current_binding_level->names = decls;
878: }
1.1.1.2 root 879:
880: /* Similarly, store the list of tags of the current level. */
881:
882: static void
883: storetags (tags)
884: tree tags;
885: {
886: current_binding_level->tags = tags;
887: }
1.1 root 888:
889: /* Given NAME, an IDENTIFIER_NODE,
890: return the structure (or union or enum) definition for that name.
891: Searches binding levels from BINDING_LEVEL up to the global level.
1.1.1.2 root 892: If THISLEVEL_ONLY is nonzero, searches only the specified context
893: (but skips any tag-transparent contexts to find one that is
894: meaningful for tags).
1.1 root 895: FORM says which kind of type the caller wants;
896: it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
897: If the wrong kind of type is found, an error is reported. */
898:
899: static tree
900: lookup_tag (form, name, binding_level, thislevel_only)
901: enum tree_code form;
902: struct binding_level *binding_level;
903: tree name;
904: int thislevel_only;
905: {
906: register struct binding_level *level;
907:
908: for (level = binding_level; level; level = level->level_chain)
909: {
910: register tree tail;
911: for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
912: {
913: if (TREE_PURPOSE (tail) == name)
914: {
915: if (TREE_CODE (TREE_VALUE (tail)) != form)
916: {
917: /* Definition isn't the kind we were looking for. */
1.1.1.2 root 918: error ("`%s' defined as wrong kind of tag",
919: IDENTIFIER_POINTER (name));
1.1 root 920: }
921: return TREE_VALUE (tail);
922: }
923: }
1.1.1.2 root 924: if (thislevel_only && ! level->tag_transparent)
1.1 root 925: return NULL_TREE;
926: }
927: return NULL_TREE;
928: }
929:
1.1.1.2 root 930: /* Given a type, find the tag that was defined for it and return the tag name.
931: Otherwise return 0. However, the value can never be 0
932: in the cases in which this is used. */
933:
934: static tree
935: lookup_tag_reverse (type)
936: tree type;
937: {
938: register struct binding_level *level;
939:
940: for (level = current_binding_level; level; level = level->level_chain)
941: {
942: register tree tail;
943: for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
944: {
945: if (TREE_VALUE (tail) == type)
946: return TREE_PURPOSE (tail);
947: }
948: }
949: return NULL_TREE;
950: }
951:
1.1 root 952: /* Look up NAME in the current binding level and its superiors
953: in the namespace of variables, functions and typedefs.
954: Return a ..._DECL node of some kind representing its definition,
955: or return 0 if it is undefined. */
956:
957: tree
958: lookup_name (name)
959: tree name;
960: {
1.1.1.2 root 961: register tree val;
1.1 root 962: if (current_binding_level != global_binding_level
963: && IDENTIFIER_LOCAL_VALUE (name))
1.1.1.2 root 964: val = IDENTIFIER_LOCAL_VALUE (name);
965: else
966: val = IDENTIFIER_GLOBAL_VALUE (name);
967: if (val && TREE_TYPE (val) == error_mark_node)
968: return error_mark_node;
969: return val;
1.1 root 970: }
971:
972: /* Similar to `lookup_name' but look only at current binding level. */
973:
974: static tree
975: lookup_name_current_level (name)
976: tree name;
977: {
978: register tree t;
979:
980: if (current_binding_level == global_binding_level)
981: return IDENTIFIER_GLOBAL_VALUE (name);
982:
983: if (IDENTIFIER_LOCAL_VALUE (name) == 0)
984: return 0;
985:
986: for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
987: if (DECL_NAME (t) == name)
988: break;
989:
990: return t;
991: }
992:
993: /* Create the predefined scalar types of C,
994: and some nodes representing standard constants (0, 1, (void *)0).
995: Initialize the global binding level.
996: Make definitions for built-in primitive functions. */
997:
998: void
999: init_decl_processing ()
1000: {
1001: register tree endlink;
1002:
1.1.1.2 root 1003: current_function_decl = NULL;
1.1 root 1004: named_labels = NULL;
1005: current_binding_level = NULL_BINDING_LEVEL;
1006: free_binding_level = NULL_BINDING_LEVEL;
1.1.1.2 root 1007: pushlevel (0); /* make the binding_level structure for global names */
1.1 root 1008: global_binding_level = current_binding_level;
1009:
1010: value_identifier = get_identifier ("<value>");
1011:
1.1.1.2 root 1012: /* Define `int' and `char' first so that dbx will output them first. */
1.1 root 1013:
1.1.1.2 root 1014: #ifdef INT_TYPE_SIZE
1015: integer_type_node = make_signed_type (INT_TYPE_SIZE);
1016: #else
1.1 root 1017: integer_type_node = make_signed_type (BITS_PER_WORD);
1.1.1.2 root 1018: #endif
1.1 root 1019: pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT],
1.1.1.2 root 1020: integer_type_node));
1021:
1022: /* Define `char', which is like either `signed char' or `unsigned char'
1023: but not the same as either. */
1024:
1025: char_type_node =
1026: (flag_signed_char
1027: ? make_signed_type (BITS_PER_UNIT)
1028: : make_unsigned_type (BITS_PER_UNIT));
1029: pushdecl (build_decl (TYPE_DECL, get_identifier ("char"),
1030: char_type_node));
1031:
1032: #ifdef INT_TYPE_SIZE
1033: unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
1034: #else
1035: unsigned_type_node = make_unsigned_type (BITS_PER_WORD);
1036: #endif
1037: pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
1038: unsigned_type_node));
1039:
1.1.1.3 root 1040: long_unsigned_type_node = make_unsigned_type (BITS_PER_WORD);
1041: pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"),
1042: long_unsigned_type_node));
1043:
1044: /* `unsigned long' or `unsigned int' is the type for sizeof. */
1045: #ifdef INT_TYPE_SIZE
1046: if (INT_TYPE_SIZE != BITS_PER_WORD)
1047: sizetype = long_unsigned_type_node;
1048: else
1049: sizetype = unsigned_type_node;
1050: #else
1.1.1.2 root 1051: sizetype = unsigned_type_node;
1.1.1.3 root 1052: #endif
1053:
1.1.1.2 root 1054: TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
1055: TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
1056: TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
1.1.1.3 root 1057: TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
1.1 root 1058:
1059: error_mark_node = make_node (ERROR_MARK);
1060: TREE_TYPE (error_mark_node) = error_mark_node;
1061:
1.1.1.3 root 1062: short_integer_type_node = make_signed_type (BITS_PER_UNIT * MIN (UNITS_PER_WORD / 2, 2));
1.1 root 1063: pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"),
1.1.1.2 root 1064: short_integer_type_node));
1.1 root 1065:
1066: long_integer_type_node = make_signed_type (BITS_PER_WORD);
1067: pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"),
1.1.1.2 root 1068: long_integer_type_node));
1.1 root 1069:
1.1.1.3 root 1070: short_unsigned_type_node = make_unsigned_type (BITS_PER_UNIT * MIN (UNITS_PER_WORD / 2, 2));
1.1 root 1071: pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"),
1.1.1.2 root 1072: short_unsigned_type_node));
1.1 root 1073:
1.1.1.2 root 1074: /* Define both `signed char' and `unsigned char'. */
1075: signed_char_type_node = make_signed_type (BITS_PER_UNIT);
1076: pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"),
1077: signed_char_type_node));
1.1 root 1078:
1079: unsigned_char_type_node = make_unsigned_type (BITS_PER_UNIT);
1080: pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"),
1.1.1.2 root 1081: unsigned_char_type_node));
1.1 root 1082:
1083: float_type_node = make_node (REAL_TYPE);
1084: TYPE_PRECISION (float_type_node) = BITS_PER_WORD;
1085: pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],
1.1.1.2 root 1086: float_type_node));
1.1 root 1087: layout_type (float_type_node);
1088:
1089: double_type_node = make_node (REAL_TYPE);
1090: TYPE_PRECISION (double_type_node) = 2 * BITS_PER_WORD;
1091: pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],
1.1.1.2 root 1092: double_type_node));
1.1 root 1093: layout_type (double_type_node);
1094:
1095: long_double_type_node = make_node (REAL_TYPE);
1096: TYPE_PRECISION (long_double_type_node) = 2 * BITS_PER_WORD;
1097: pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"),
1.1.1.2 root 1098: long_double_type_node));
1.1 root 1099: layout_type (long_double_type_node);
1100:
1101: integer_zero_node = build_int_2 (0, 0);
1102: TREE_TYPE (integer_zero_node) = integer_type_node;
1103: integer_one_node = build_int_2 (1, 0);
1104: TREE_TYPE (integer_one_node) = integer_type_node;
1105:
1.1.1.3 root 1106: size_zero_node = build_int_2 (0, 0);
1107: TREE_TYPE (size_zero_node) = sizetype;
1108: size_one_node = build_int_2 (1, 0);
1109: TREE_TYPE (size_one_node) = sizetype;
1110:
1.1 root 1111: void_type_node = make_node (VOID_TYPE);
1112: pushdecl (build_decl (TYPE_DECL,
1.1.1.2 root 1113: ridpointers[(int) RID_VOID], void_type_node));
1.1 root 1114: layout_type (void_type_node); /* Uses integer_zero_node */
1115:
1116: null_pointer_node = build_int_2 (0, 0);
1117: TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
1118: layout_type (TREE_TYPE (null_pointer_node));
1119:
1120: string_type_node = build_pointer_type (char_type_node);
1121:
1122: /* make a type for arrays of 256 characters.
1123: 256 is picked randomly because we have a type for integers from 0 to 255.
1124: With luck nothing will ever really depend on the length of this
1125: array type. */
1126: char_array_type_node
1127: = build_array_type (char_type_node, unsigned_char_type_node);
1.1.1.2 root 1128: /* Likewise for arrays of ints. */
1129: int_array_type_node
1130: = build_array_type (integer_type_node, unsigned_char_type_node);
1.1 root 1131:
1132: default_function_type
1133: = build_function_type (integer_type_node, NULL_TREE);
1134:
1135: ptr_type_node = build_pointer_type (void_type_node);
1136: endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
1137:
1138: double_ftype_double
1139: = build_function_type (double_type_node,
1140: tree_cons (NULL_TREE, double_type_node, endlink));
1141:
1142: double_ftype_double_double
1143: = build_function_type (double_type_node,
1144: tree_cons (NULL_TREE, double_type_node,
1145: tree_cons (NULL_TREE,
1146: double_type_node, endlink)));
1147:
1148: int_ftype_int
1149: = build_function_type (integer_type_node,
1150: tree_cons (NULL_TREE, integer_type_node, endlink));
1151:
1152: long_ftype_long
1153: = build_function_type (long_integer_type_node,
1154: tree_cons (NULL_TREE,
1155: long_integer_type_node, endlink));
1156:
1157: void_ftype_ptr_ptr_int
1158: = build_function_type (void_type_node,
1159: tree_cons (NULL_TREE, ptr_type_node,
1160: tree_cons (NULL_TREE, ptr_type_node,
1161: tree_cons (NULL_TREE,
1162: integer_type_node,
1163: endlink))));
1164:
1165: int_ftype_ptr_ptr_int
1166: = build_function_type (integer_type_node,
1167: tree_cons (NULL_TREE, ptr_type_node,
1168: tree_cons (NULL_TREE, ptr_type_node,
1169: tree_cons (NULL_TREE,
1170: integer_type_node,
1171: endlink))));
1172:
1173: void_ftype_ptr_int_int
1174: = build_function_type (void_type_node,
1175: tree_cons (NULL_TREE, ptr_type_node,
1176: tree_cons (NULL_TREE, integer_type_node,
1177: tree_cons (NULL_TREE,
1178: integer_type_node,
1179: endlink))));
1180:
1.1.1.2 root 1181: builtin_function ("__builtin_alloca",
1.1 root 1182: build_function_type (ptr_type_node,
1183: tree_cons (NULL_TREE,
1184: integer_type_node,
1185: endlink)),
1186: BUILT_IN_ALLOCA);
1187:
1.1.1.2 root 1188: builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS);
1189: builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS);
1190: builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS);
1191: builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS);
1192: /* builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV);
1193: builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV); */
1194: builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR);
1195: builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL);
1196: builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD);
1197: builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM);
1198: builtin_function ("__builtin_memcpy", void_ftype_ptr_ptr_int, BUILT_IN_MEMCPY);
1199: builtin_function ("__builtin_memcmp", int_ftype_ptr_ptr_int, BUILT_IN_MEMCMP);
1200: builtin_function ("__builtin_memset", void_ftype_ptr_int_int, BUILT_IN_MEMSET);
1201: builtin_function ("__builtin_fsqrt", double_ftype_double, BUILT_IN_FSQRT);
1202: builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP);
1203: builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN);
1.1 root 1204: }
1205:
1206: /* Make a definition for a builtin function named NAME and whose data type
1207: is TYPE. TYPE should be a function type with argument types.
1208: FUNCTION_CODE tells later passes how to compile calls to this function.
1209: See tree.h for its possible values. */
1210:
1211: static void
1212: builtin_function (name, type, function_code)
1213: char *name;
1214: tree type;
1215: enum built_in_function function_code;
1216: {
1.1.1.2 root 1217: tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
1218: TREE_EXTERNAL (decl) = 1;
1219: TREE_PUBLIC (decl) = 1;
1.1 root 1220: make_function_rtl (decl);
1221: pushdecl (decl);
1222: DECL_SET_FUNCTION_CODE (decl, function_code);
1223: }
1224:
1225: /* Called when a declaration is seen that contains no names to declare.
1226: If its type is a reference to a structure, union or enum inherited
1227: from a containing scope, shadow that tag name for the current scope
1228: with a forward reference.
1229: If its type defines a new named structure or union
1230: or defines an enum, it is valid but we need not do anything here.
1231: Otherwise, it is an error. */
1232:
1233: void
1234: shadow_tag (declspecs)
1235: tree declspecs;
1236: {
1237: register tree link;
1238:
1239: for (link = declspecs; link; link = TREE_CHAIN (link))
1240: {
1241: register tree value = TREE_VALUE (link);
1242: register enum tree_code code = TREE_CODE (value);
1243: if ((code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
1244: && TYPE_SIZE (value) != 0)
1245: {
1.1.1.2 root 1246: register tree name = lookup_tag_reverse (value);
1.1 root 1247: register tree t = lookup_tag (code, name, current_binding_level, 1);
1248: if (t == 0)
1249: {
1250: t = make_node (code);
1251: pushtag (name, t);
1252: return;
1253: }
1254: if (name != 0 || code == ENUMERAL_TYPE)
1255: return;
1256: }
1257: }
1258: warning ("empty declaration");
1259: }
1260:
1261: /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
1262:
1263: tree
1264: groktypename (typename)
1265: tree typename;
1266: {
1.1.1.2 root 1267: if (TREE_CODE (typename) != TREE_LIST)
1268: return typename;
1.1 root 1269: return grokdeclarator (TREE_VALUE (typename),
1270: TREE_PURPOSE (typename),
1.1.1.2 root 1271: TYPENAME, 0);
1.1 root 1272: }
1273:
1274: /* Decode a declarator in an ordinary declaration or data definition.
1275: This is called as soon as the type information and variable name
1276: have been parsed, before parsing the initializer if any.
1277: Here we create the ..._DECL node, fill in its type,
1278: and put it on the list of decls for the current context.
1279: The ..._DECL node is returned as the value.
1280:
1281: Exception: for arrays where the length is not specified,
1282: the type is left null, to be filled in by `finish_decl'.
1283:
1284: Function definitions do not come here; they go to start_function
1285: instead. However, external and forward declarations of functions
1286: do go through here. Structure field declarations are done by
1287: grokfield and not through here. */
1288:
1.1.1.2 root 1289: /* Set this nonzero to debug not using the temporary obstack
1290: to parse initializers. */
1291: int debug_no_temp_inits = 1;
1292:
1.1 root 1293: tree
1294: start_decl (declarator, declspecs, initialized)
1295: tree declspecs, declarator;
1296: int initialized;
1297: {
1.1.1.2 root 1298: register tree decl = grokdeclarator (declarator, declspecs,
1299: NORMAL, initialized);
1300: register tree tem;
1301: int init_written = initialized;
1302:
1303: if (initialized)
1304: /* Is it valid for this decl to have an initializer at all?
1305: If not, set INITIALIZED to zero, which will indirectly
1306: tell `finish_decl' to ignore the initializer once it is parsed. */
1307: switch (TREE_CODE (decl))
1308: {
1309: case TYPE_DECL:
1310: /* typedef foo = bar means give foo the same type as bar.
1311: We haven't parsed bar yet, so `finish_decl' will fix that up.
1312: Any other case of an initialization in a TYPE_DECL is an error. */
1313: if (pedantic || list_length (declspecs) > 1)
1314: {
1315: error ("typedef `%s' is initialized",
1316: IDENTIFIER_POINTER (DECL_NAME (decl)));
1317: initialized = 0;
1318: }
1319: break;
1320:
1321: case FUNCTION_DECL:
1322: error ("function `%s' is initialized like a variable",
1323: IDENTIFIER_POINTER (DECL_NAME (decl)));
1324: initialized = 0;
1325: break;
1326:
1327: default:
1328: /* Don't allow initializations for incomplete types
1329: except for arrays which might be completed by the initialization. */
1330: if (TYPE_SIZE (TREE_TYPE (decl)) != 0)
1331: ; /* A complete type is ok. */
1332: else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
1333: {
1334: error ("variable `%s' has initializer but incomplete type",
1335: IDENTIFIER_POINTER (DECL_NAME (decl)));
1336: initialized = 0;
1337: }
1338: else if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))) == 0)
1339: {
1340: error ("elements of array `%s' have incomplete type",
1341: IDENTIFIER_POINTER (DECL_NAME (decl)));
1342: initialized = 0;
1343: }
1344: }
1345:
1346: if (initialized)
1347: {
1348: if (current_binding_level != global_binding_level
1349: && TREE_EXTERNAL (decl))
1350: warning ("declaration of `%s' has `extern' and is initialized",
1351: IDENTIFIER_POINTER (DECL_NAME (decl)));
1352: TREE_EXTERNAL (decl) = 0;
1353: if (current_binding_level == global_binding_level)
1354: TREE_STATIC (decl) = 1;
1355:
1356: /* Tell `pushdecl' this is an initialized decl
1357: even though we don't yet have the initializer expression.
1358: Also tell `finish_decl' it may store the real initializer. */
1359: DECL_INITIAL (decl) = error_mark_node;
1360: }
1361:
1362: /* Add this decl to the current binding level. */
1363: tem = pushdecl (decl);
1364:
1365: if (init_written)
1366: {
1367: /* When parsing and digesting the initializer,
1368: use temporary storage. Do this even if we will ignore the value. */
1369: if (current_binding_level == global_binding_level
1370: && debug_no_temp_inits)
1371: temporary_allocation ();
1372: }
1373:
1374: return tem;
1.1 root 1375: }
1376:
1377: /* Finish processing of a declaration;
1378: install its line number and initial value.
1379: If the length of an array type is not known before,
1380: it must be determined now, from the initial value, or it is an error. */
1381:
1382: void
1.1.1.2 root 1383: finish_decl (decl, init, asmspec)
1.1 root 1384: tree decl, init;
1.1.1.2 root 1385: tree asmspec;
1.1 root 1386: {
1387: register tree type = TREE_TYPE (decl);
1.1.1.2 root 1388: int init_written = init != 0;
1.1 root 1389:
1.1.1.2 root 1390: /* If `start_decl' didn't like having an initialization, ignore it now. */
1.1 root 1391:
1.1.1.2 root 1392: if (init != 0 && DECL_INITIAL (decl) == 0)
1393: init = 0;
1394:
1395: if (init)
1396: {
1397: if (TREE_CODE (decl) != TYPE_DECL)
1398: store_init_value (decl, init);
1399: else
1400: {
1401: /* typedef foo = bar; store the type of bar as the type of foo. */
1402: TREE_TYPE (decl) = TREE_TYPE (init);
1403: DECL_INITIAL (decl) = init = 0;
1404: }
1405: }
1406:
1407: /* For top-level declaration, the initial value was read in
1408: the temporary obstack. MAXINDEX, rtl, etc. to be made below
1409: must go in the permanent obstack; but don't discard the
1410: temporary data yet. */
1411:
1412: if (debug_no_temp_inits && init_written
1413: && current_binding_level == global_binding_level)
1414: end_temporary_allocation ();
1415:
1416: /* Deduce size of array from initialization, if not already known */
1.1 root 1417:
1418: if (TREE_CODE (type) == ARRAY_TYPE
1.1.1.2 root 1419: && TYPE_DOMAIN (type) == 0
1420: && TREE_CODE (decl) != TYPE_DECL)
1.1 root 1421: {
1.1.1.2 root 1422: int do_default = ! ((!pedantic && TREE_STATIC (decl))
1423: || TREE_EXTERNAL (decl));
1424: int failure
1425: = complete_array_type (type, DECL_INITIAL (decl), do_default);
1426:
1427: if (failure == 1)
1428: error_with_decl (decl, "initializer fails to determine size of `%s'");
1429:
1430: if (failure == 2)
1431: {
1432: if (do_default)
1433: error_with_decl (decl, "array size missing in `%s'");
1434: else if (!pedantic && TREE_STATIC (decl))
1435: TREE_EXTERNAL (decl) = 1;
1436: }
1437:
1438: if (pedantic && TYPE_DOMAIN (type) != 0
1.1.1.4 ! root 1439: && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
! 1440: integer_zero_node))
1.1.1.2 root 1441: error_with_decl (decl, "zero-size array `%s'");
1.1 root 1442:
1.1.1.2 root 1443: if (TREE_CODE (decl) != TYPE_DECL)
1444: layout_decl (decl, 0);
1445: }
1446:
1447: if (TREE_CODE (decl) == VAR_DECL)
1448: {
1449: if (TREE_STATIC (decl) && DECL_SIZE (decl) == 0)
1.1 root 1450: {
1.1.1.2 root 1451: /* A static variable with an incomplete type:
1452: that is an error if it is initialized or `static'.
1453: Otherwise, let it through, but if it is not `extern'
1454: then it may cause an error message later. */
1455: if (! (TREE_PUBLIC (decl) && DECL_INITIAL (decl) == 0))
1456: error_with_decl (decl, "storage size of `%s' isn't known");
1.1 root 1457: }
1.1.1.2 root 1458: else if (!TREE_EXTERNAL (decl) && DECL_SIZE (decl) == 0)
1.1 root 1459: {
1.1.1.2 root 1460: /* An automatic variable with an incomplete type:
1461: that is an error. */
1462: error_with_decl (decl, "storage size of `%s' isn't known");
1463: TREE_TYPE (decl) = error_mark_node;
1.1 root 1464: }
1465:
1.1.1.2 root 1466: if ((TREE_EXTERNAL (decl) || TREE_STATIC (decl))
1467: && DECL_SIZE (decl) != 0 && ! TREE_LITERAL (DECL_SIZE (decl)))
1468: error_with_decl (decl, "storage size of `%s' isn't constant");
1469: }
1470:
1471: /* Output the assembler code and/or RTL code for variables and functions,
1472: unless the type is an undefined structure or union.
1473: If not, it will get done when the type is completed. */
1474:
1475: if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
1476: {
1477: rest_of_decl_compilation (decl, asmspec,
1478: current_binding_level == global_binding_level,
1479: 0);
1480: if (TYPE_SIZE (TREE_TYPE (decl)) != 0
1481: || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1482: if (current_binding_level != global_binding_level)
1483: expand_decl (decl);
1484: }
1485:
1.1.1.3 root 1486: if (TREE_CODE (decl) == TYPE_DECL)
1487: rest_of_decl_compilation (decl, 0,
1488: current_binding_level == global_binding_level,
1489: 0);
1490:
1.1.1.2 root 1491: /* Resume permanent allocation, if not within a function. */
1492: if (debug_no_temp_inits && init_written
1493: && current_binding_level == global_binding_level)
1494: permanent_allocation ();
1495: }
1496:
1497: /* Given a parsed parameter declaration,
1498: decode it into a PARM_DECL and push that on the current binding level. */
1499:
1500: void
1501: push_parm_decl (parm)
1502: tree parm;
1503: {
1504: register tree decl = grokdeclarator (TREE_VALUE (parm), TREE_PURPOSE (parm),
1505: PARM, 0);
1506:
1507: /* Add this decl to the current binding level. */
1508: finish_decl (pushdecl (decl), NULL_TREE, NULL_TREE);
1509: }
1510:
1511: /* Make TYPE a complete type based on INITIAL_VALUE.
1512: Return 0 if successful, 1 if INITIAL_VALUE can't be decyphered,
1513: 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
1514:
1515: int
1516: complete_array_type (type, initial_value, do_default)
1517: tree type;
1518: tree initial_value;
1519: int do_default;
1520: {
1521: register tree maxindex = NULL_TREE;
1522: int value = 0;
1523:
1524: if (initial_value)
1525: {
1526: /* Note MAXINDEX is really the maximum index,
1527: one less than the size. */
1528: if (TREE_CODE (initial_value) == STRING_CST)
1529: maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
1530: else if (TREE_CODE (initial_value) == CONSTRUCTOR)
1531: {
1532: register int nelts
1533: = list_length (CONSTRUCTOR_ELTS (initial_value));
1534: maxindex = build_int_2 (nelts - 1, 0);
1535: }
1536: else
1.1 root 1537: {
1.1.1.2 root 1538: /* Make an error message unless that happened already. */
1539: if (initial_value != error_mark_node)
1540: value = 1;
1541:
1542: /* Prevent further error messages. */
1543: maxindex = build_int_2 (1, 0);
1.1 root 1544: }
1.1.1.2 root 1545: }
1.1 root 1546:
1.1.1.2 root 1547: if (!maxindex)
1548: {
1549: if (do_default)
1550: maxindex = build_int_2 (1, 0);
1551: value = 2;
1552: }
1.1 root 1553:
1.1.1.2 root 1554: if (maxindex)
1555: {
1556: TYPE_DOMAIN (type) = make_index_type (maxindex);
1557: if (!TREE_TYPE (maxindex))
1558: TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
1.1 root 1559: }
1560:
1.1.1.2 root 1561: /* Lay out the type now that we can get the real answer. */
1562:
1563: layout_type (type);
1.1 root 1564:
1.1.1.2 root 1565: return value;
1.1 root 1566: }
1567:
1568: /* Given declspecs and a declarator,
1569: determine the name and type of the object declared.
1570: DECLSPECS is a chain of tree_list nodes whose value fields
1571: are the storage classes and type specifiers.
1572:
1573: DECL_CONTEXT says which syntactic context this declaration is in:
1.1.1.2 root 1574: NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
1575: FUNCDEF for a function definition. Like NORMAL but a few different
1576: error messages in each case. Return value may be zero meaning
1577: this definition is too screwy to try to parse.
1578: PARM for a parameter declaration (either within a function prototype
1579: or before a function body). Make a PARM_DECL, or return void_type_node.
1580: TYPENAME if for a typename (in a cast or sizeof).
1581: Don't make a DECL node; just return the type.
1582: FIELD for a struct or union field; make a FIELD_DECL.
1583: INITIALIZED is 1 if the decl has an initializer.
1.1 root 1584:
1585: In the TYPENAME case, DECLARATOR is really an absolute declarator.
1586: It may also be so in the PARM case, for a prototype where the
1.1.1.2 root 1587: argument type is specified but not the name.
1588:
1589: This function is where the complicated C meanings of `static'
1590: and `extern' are intrepreted. */
1.1 root 1591:
1592: static tree
1.1.1.2 root 1593: grokdeclarator (declarator, declspecs, decl_context, initialized)
1.1 root 1594: tree declspecs;
1595: tree declarator;
1596: enum decl_context decl_context;
1.1.1.2 root 1597: int initialized;
1.1 root 1598: {
1599: int specbits = 0;
1600: tree spec;
1601: tree type = NULL_TREE;
1602: int longlong = 0;
1603: int constp;
1604: int volatilep;
1.1.1.2 root 1605: int inlinep;
1.1 root 1606: int explicit_int = 0;
1.1.1.2 root 1607: int explicit_char = 0;
1608: char *name;
1609: tree typedef_type = 0;
1610: int funcdef_flag = 0;
1611: enum tree_code innermost_code = ERROR_MARK;
1612:
1613: if (decl_context == FUNCDEF)
1614: funcdef_flag = 1, decl_context = NORMAL;
1615:
1616: /* Look inside a declarator for the name being declared
1617: and get it as a string, for an error message. */
1618: {
1619: register tree decl = declarator;
1620: name = 0;
1621:
1622: while (decl)
1623: switch (TREE_CODE (decl))
1624: {
1625: case ARRAY_REF:
1626: case INDIRECT_REF:
1627: case CALL_EXPR:
1628: innermost_code = TREE_CODE (decl);
1629: decl = TREE_OPERAND (decl, 0);
1630: break;
1631:
1632: case IDENTIFIER_NODE:
1633: name = IDENTIFIER_POINTER (decl);
1634: decl = 0;
1635: break;
1636:
1637: default:
1638: abort ();
1639: }
1640: if (name == 0)
1641: name = "type name";
1642: }
1643:
1644: /* A function definition's declarator must have the form of
1645: a function declarator. */
1646:
1647: if (funcdef_flag && innermost_code != CALL_EXPR)
1648: return 0;
1.1 root 1649:
1650: /* Anything declared one level down from the top level
1651: must be one of the parameters of a function
1652: (because the body is at least two levels down). */
1653:
1654: if (decl_context == NORMAL
1655: && current_binding_level->level_chain == global_binding_level)
1656: decl_context = PARM;
1657:
1658: /* Look through the decl specs and record which ones appear.
1659: Some typespecs are defined as built-in typenames.
1660: Others, the ones that are modifiers of other types,
1661: are represented by bits in SPECBITS: set the bits for
1662: the modifiers that appear. Storage class keywords are also in SPECBITS.
1663:
1664: If there is a typedef name or a type, store the type in TYPE.
1665: This includes builtin typedefs such as `int'.
1666:
1667: Set EXPLICIT_INT if the type is `int' or `char' and did not
1668: come from a user typedef.
1669:
1670: Set LONGLONG if `long' is mentioned twice. */
1671:
1672: for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
1673: {
1674: register int i;
1675: register tree id = TREE_VALUE (spec);
1676:
1.1.1.2 root 1677: if (id == ridpointers[(int) RID_INT])
1.1 root 1678: explicit_int = 1;
1.1.1.2 root 1679: if (id == ridpointers[(int) RID_CHAR])
1680: explicit_char = 1;
1.1 root 1681:
1.1.1.2 root 1682: if (TREE_CODE (id) == IDENTIFIER_NODE)
1683: for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
1684: {
1685: if (ridpointers[i] == id)
1686: {
1687: if (i == (int) RID_LONG && specbits & (1<<i))
1688: longlong = 1;
1689: if (specbits & (1 << i))
1690: warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
1691: specbits |= 1 << i;
1692: goto found;
1693: }
1694: }
1695: if (type)
1696: error ("two or more data types in declaration of `%s'", name);
1697: else if (TREE_CODE (id) == IDENTIFIER_NODE)
1.1 root 1698: {
1699: register tree t = lookup_name (id);
1700: if (!t || TREE_CODE (t) != TYPE_DECL)
1.1.1.2 root 1701: error ("`%s' fails to be a typedef or built in type",
1702: IDENTIFIER_POINTER (id));
1.1 root 1703: else type = TREE_TYPE (t);
1704: }
1.1.1.2 root 1705: else if (TREE_CODE (id) != ERROR_MARK)
1706: type = id;
1.1 root 1707:
1.1.1.2 root 1708: found: {}
1.1 root 1709: }
1710:
1.1.1.2 root 1711: typedef_type = type;
1712:
1.1 root 1713: /* No type at all: default to `int', and set EXPLICIT_INT
1714: because it was not a user-defined typedef. */
1715:
1716: if (type == 0)
1717: {
1.1.1.2 root 1718: if (funcdef_flag && warn_return_type
1719: && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
1720: | (1 << (int) RID_SIGNED) | (1 << (int) RID_UNSIGNED))))
1721: warn_about_return_type = 1;
1.1 root 1722: explicit_int = 1;
1723: type = integer_type_node;
1724: }
1725:
1726: /* Now process the modifiers that were specified
1727: and check for invalid combinations. */
1728:
1729: /* Long double is a special combination. */
1730:
1.1.1.2 root 1731: if ((specbits & 1 << (int) RID_LONG) && type == double_type_node)
1.1 root 1732: {
1.1.1.2 root 1733: specbits &= ~ (1 << (int) RID_LONG);
1.1 root 1734: type = long_double_type_node;
1735: }
1736:
1737: /* Check all other uses of type modifiers. */
1738:
1.1.1.2 root 1739: if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
1740: | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
1.1 root 1741: {
1.1.1.2 root 1742: if (!explicit_int && !explicit_char && !pedantic)
1743: error ("long, short, signed or unsigned used invalidly for `%s'", name);
1744: else if ((specbits & 1 << (int) RID_LONG) && (specbits & 1 << (int) RID_SHORT))
1745: error ("long and short specified together for `%s'", name);
1746: else if (((specbits & 1 << (int) RID_LONG) || (specbits & 1 << (int) RID_SHORT))
1747: && explicit_char)
1748: error ("long or short specified with char for `%s'", name);
1749: else if ((specbits & 1 << (int) RID_SIGNED) && (specbits & 1 << (int) RID_UNSIGNED))
1750: error ("signed and unsigned given together for `%s'", name);
1.1 root 1751: else
1752: {
1.1.1.2 root 1753: if (specbits & 1 << (int) RID_UNSIGNED)
1.1 root 1754: {
1.1.1.2 root 1755: if (specbits & 1 << (int) RID_LONG)
1.1 root 1756: type = long_unsigned_type_node;
1.1.1.2 root 1757: else if (specbits & 1 << (int) RID_SHORT)
1.1 root 1758: type = short_unsigned_type_node;
1759: else if (type == char_type_node)
1760: type = unsigned_char_type_node;
1761: else
1762: type = unsigned_type_node;
1763: }
1.1.1.2 root 1764: else if ((specbits & 1 << (int) RID_SIGNED)
1765: && type == char_type_node)
1766: type = signed_char_type_node;
1767: else if (specbits & 1 << (int) RID_LONG)
1.1 root 1768: type = long_integer_type_node;
1.1.1.2 root 1769: else if (specbits & 1 << (int) RID_SHORT)
1.1 root 1770: type = short_integer_type_node;
1771: }
1772: }
1.1.1.2 root 1773:
1.1 root 1774: /* Set CONSTP if this declaration is `const', whether by
1775: explicit specification or via a typedef.
1776: Likewise for VOLATILEP. */
1777:
1.1.1.2 root 1778: constp = !! (specbits & 1 << (int) RID_CONST) + TREE_READONLY (type);
1779: volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TREE_VOLATILE (type);
1780: inlinep = !! (specbits & (1 << (int) RID_INLINE));
1781: if (constp > 1)
1782: warning ("duplicate `const'");
1783: if (volatilep > 1)
1784: warning ("duplicate `volatile'");
1.1 root 1785: type = TYPE_MAIN_VARIANT (type);
1786:
1787: /* Warn if two storage classes are given. Default to `auto'. */
1788:
1789: {
1790: int nclasses = 0;
1791:
1.1.1.2 root 1792: if (specbits & 1 << (int) RID_AUTO) nclasses++;
1793: if (specbits & 1 << (int) RID_STATIC) nclasses++;
1794: if (specbits & 1 << (int) RID_EXTERN) nclasses++;
1795: if (specbits & 1 << (int) RID_REGISTER) nclasses++;
1796: if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
1.1 root 1797:
1798: /* Warn about storage classes that are invalid for certain
1799: kinds of declarations (parameters, typenames, etc.). */
1800:
1801: if (nclasses > 1)
1.1.1.2 root 1802: error ("multiple storage classes in declaration of `%s'", name);
1.1 root 1803: else if (decl_context != NORMAL && nclasses > 0)
1804: {
1.1.1.2 root 1805: if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
1.1 root 1806: ;
1.1.1.2 root 1807: else
1808: {
1809: error ((decl_context == FIELD
1810: ? "storage class specified for structure field `%s'"
1811: : (decl_context == PARM
1812: ? "storage class specified for parameter `%s'"
1813: : "storage class specified for typename")),
1814: name);
1815: specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
1816: | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
1817: | (1 << (int) RID_EXTERN));
1818: }
1.1 root 1819: }
1.1.1.2 root 1820: else if (current_binding_level == global_binding_level)
1.1 root 1821: {
1.1.1.2 root 1822: if (specbits & (1 << (int) RID_AUTO))
1823: error ("top-level declaration of `%s' specifies `auto'", name);
1824: if (specbits & (1 << (int) RID_REGISTER))
1825: error ("top-level declaration of `%s' specifies `register'", name);
1.1 root 1826: }
1827: }
1.1.1.2 root 1828:
1.1 root 1829: /* Now figure out the structure of the declarator proper.
1830: Descend through it, creating more complex types, until we reach
1831: the declared identifier (or NULL_TREE, in an absolute declarator). */
1832:
1833: while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
1834: {
1.1.1.2 root 1835: if (type == error_mark_node)
1836: {
1837: declarator = TREE_OPERAND (declarator, 0);
1838: continue;
1839: }
1840:
1.1 root 1841: /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
1842: an INDIRECT_REF (for *...),
1843: a CALL_EXPR (for ...(...)),
1844: an identifier (for the name being declared)
1845: or a null pointer (for the place in an absolute declarator
1846: where the name was omitted).
1847: For the last two cases, we have just exited the loop.
1848:
1849: At this point, TYPE is the type of elements of an array,
1850: or for a function to return, or for a pointer to point to.
1851: After this sequence of ifs, TYPE is the type of the
1852: array or function or pointer, and DECLARATOR has had its
1853: outermost layer removed. */
1854:
1855: if (TREE_CODE (declarator) == ARRAY_REF)
1856: {
1857: register tree itype = NULL_TREE;
1858: register tree size = TREE_OPERAND (declarator, 1);
1859:
1.1.1.2 root 1860: declarator = TREE_OPERAND (declarator, 0);
1.1 root 1861:
1862: /* Check for some types that there cannot be arrays of. */
1863:
1864: if (type == void_type_node)
1865: {
1.1.1.2 root 1866: error ("declaration of `%s' as array of voids", name);
1867: type = error_mark_node;
1.1 root 1868: }
1869:
1870: if (TREE_CODE (type) == FUNCTION_TYPE)
1871: {
1.1.1.2 root 1872: error ("declaration of `%s' as array of functions", name);
1873: type = error_mark_node;
1.1 root 1874: }
1875:
1.1.1.2 root 1876: if (size == error_mark_node)
1877: type = error_mark_node;
1878:
1879: if (type == error_mark_node)
1880: continue;
1881:
1.1 root 1882: /* If size was specified, set ITYPE to a range-type for that size.
1883: Otherwise, ITYPE remains null. finish_decl may figure it out
1884: from an initial value. */
1885:
1886: if (size)
1887: {
1.1.1.2 root 1888: if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
1889: && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
1890: {
1891: error ("size of array `%s' has non-integer type", name);
1892: size = integer_one_node;
1893: }
1894: if (pedantic && integer_zerop (size))
1895: warning ("ANSI C forbids zero-size array `%s'", name);
1896: if (INT_CST_LT (size, integer_zero_node))
1897: {
1898: error ("size of array `%s' is negative", name);
1899: size = integer_one_node;
1900: }
1.1 root 1901: if (TREE_LITERAL (size))
1902: itype = make_index_type (build_int_2 (TREE_INT_CST_LOW (size) - 1, 0));
1903: else
1.1.1.2 root 1904: {
1905: if (pedantic)
1906: warning ("ANSI C forbids variable-size array `%s'", name);
1907: itype = build_binary_op (MINUS_EXPR, size, integer_one_node);
1908: itype = make_index_type (itype);
1909: }
1.1 root 1910: }
1911:
1912: /* Build the array type itself. */
1913:
1914: type = build_array_type (type, itype);
1915: }
1916: else if (TREE_CODE (declarator) == CALL_EXPR)
1917: {
1918: /* Declaring a function type.
1919: Make sure we have a valid type for the function to return. */
1.1.1.2 root 1920: if (type == error_mark_node)
1921: continue;
1.1 root 1922:
1923: /* Is this an error? Should they be merged into TYPE here? */
1.1.1.2 root 1924: if (constp || volatilep)
1925: warning ("function declared to return const or volatile result");
1.1 root 1926: constp = 0;
1927: volatilep = 0;
1928:
1929: /* Warn about some types functions can't return. */
1930:
1931: if (TREE_CODE (type) == FUNCTION_TYPE)
1932: {
1.1.1.2 root 1933: error ("`%s' declared as function returning a function", name);
1.1 root 1934: type = integer_type_node;
1935: }
1936: if (TREE_CODE (type) == ARRAY_TYPE)
1937: {
1.1.1.2 root 1938: error ("`%s' declared as function returning an array", name);
1.1 root 1939: type = integer_type_node;
1940: }
1941:
1942: /* Construct the function type and go to the next
1943: inner layer of declarator. */
1944:
1945: type =
1946: build_function_type (type,
1.1.1.2 root 1947: grokparms (TREE_OPERAND (declarator, 1),
1.1.1.3 root 1948: funcdef_flag
1949: /* Say it's a definition
1950: only for the CALL_EXPR
1951: closest to the identifier. */
1952: && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE));
1.1 root 1953: declarator = TREE_OPERAND (declarator, 0);
1954: }
1955: else if (TREE_CODE (declarator) == INDIRECT_REF)
1956: {
1957: /* Merge any constancy or volatility into the target type
1958: for the pointer. */
1959:
1960: if (constp || volatilep)
1961: type = build_type_variant (type, constp, volatilep);
1962: constp = 0;
1963: volatilep = 0;
1964:
1965: type = build_pointer_type (type);
1966:
1967: /* Process a list of type modifier keywords
1968: (such as const or volatile) that were given inside the `*'. */
1969:
1970: if (TREE_TYPE (declarator))
1971: {
1972: register tree typemodlist;
1.1.1.2 root 1973: int erred = 0;
1.1 root 1974: for (typemodlist = TREE_TYPE (declarator); typemodlist;
1975: typemodlist = TREE_CHAIN (typemodlist))
1976: {
1977: if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
1.1.1.2 root 1978: constp++;
1979: else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
1980: volatilep++;
1981: else if (!erred)
1982: {
1983: erred = 1;
1984: error ("invalid type modifier within pointer declarator");
1985: }
1.1 root 1986: }
1.1.1.2 root 1987: if (constp > 1)
1988: warning ("duplicate `const'");
1989: if (volatilep > 1)
1990: warning ("duplicate `volatile'");
1.1 root 1991: }
1992:
1993: declarator = TREE_OPERAND (declarator, 0);
1994: }
1995: else
1996: abort ();
1997:
1.1.1.2 root 1998: /* layout_type (type); */
1.1 root 1999:
2000: /* @@ Should perhaps replace the following code by changes in
2001: * @@ stor_layout.c. */
2002: if (TREE_CODE (type) == FUNCTION_DECL)
2003: {
2004: /* A function variable in C should be Pmode rather than EPmode
2005: because it has just the address of a function, no static chain.*/
2006: TYPE_MODE (type) = Pmode;
2007: }
2008: }
2009:
1.1.1.2 root 2010: /* Now TYPE has the actual type. */
1.1 root 2011:
2012: /* If this is declaring a typedef name, return a TYPE_DECL. */
2013:
1.1.1.2 root 2014: if (specbits & (1 << (int) RID_TYPEDEF))
1.1 root 2015: {
2016: /* Note that the grammar rejects storage classes
2017: in typenames, fields or parameters */
2018: if (constp || volatilep)
2019: type = build_type_variant (type, constp, volatilep);
1.1.1.2 root 2020: return build_decl (TYPE_DECL, declarator, type);
1.1 root 2021: }
2022:
1.1.1.2 root 2023: /* Detect the case of an array type of unspecified size
2024: which came, as such, direct from a typedef name.
2025: We must copy the type, so that each identifier gets
2026: a distinct type, so that each identifier's size can be
2027: controlled separately by its own initializer. */
1.1 root 2028:
1.1.1.2 root 2029: if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
2030: && TYPE_DOMAIN (type) == 0)
2031: {
2032: type = build_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
2033: }
1.1 root 2034:
2035: /* If this is a type name (such as, in a cast or sizeof),
2036: compute the type and return it now. */
2037:
2038: if (decl_context == TYPENAME)
2039: {
2040: /* Note that the grammar rejects storage classes
2041: in typenames, fields or parameters */
2042: if (constp || volatilep)
2043: type = build_type_variant (type, constp, volatilep);
2044: return type;
2045: }
2046:
2047: /* `void' at top level (not within pointer)
1.1.1.2 root 2048: is allowed only in typedefs or type names.
2049: We don't complain about parms either, but that is because
2050: a better error message can be made later. */
1.1 root 2051:
1.1.1.2 root 2052: if (type == void_type_node && decl_context != PARM)
1.1 root 2053: {
1.1.1.2 root 2054: error ("variable or field `%s' declared void",
2055: IDENTIFIER_POINTER (declarator));
1.1 root 2056: type = integer_type_node;
2057: }
2058:
2059: /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
2060: or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
2061:
2062: {
2063: register tree decl;
2064:
2065: if (decl_context == PARM)
2066: {
2067: /* A parameter declared as an array of T is really a pointer to T.
2068: One declared as a function is really a pointer to a function. */
2069:
2070: if (TREE_CODE (type) == ARRAY_TYPE)
2071: {
1.1.1.2 root 2072: /* Transfer const-ness of array into that of type pointed to. */
2073: type = build_pointer_type
2074: (build_type_variant (TREE_TYPE (type), constp, volatilep));
2075: volatilep = constp = 0;
2076: }
2077: else if (TREE_CODE (type) == FUNCTION_TYPE)
2078: type = build_pointer_type (type);
1.1 root 2079:
1.1.1.2 root 2080: decl = build_decl (PARM_DECL, declarator, type);
2081:
2082: /* Compute the type actually passed in the parmlist,
2083: for the case where there is no prototype.
2084: (For example, shorts and chars are passed as ints.)
2085: When there is a prototype, this is overridden later. */
2086:
1.1 root 2087: DECL_ARG_TYPE (decl) = type;
2088: if (type == float_type_node)
2089: DECL_ARG_TYPE (decl) = double_type_node;
2090: else if (TREE_CODE (type) == INTEGER_TYPE
2091: && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
2092: DECL_ARG_TYPE (decl) = integer_type_node;
2093: }
2094: else if (decl_context == FIELD)
2095: {
2096: /* Structure field. It may not be a function. */
2097:
2098: if (TREE_CODE (type) == FUNCTION_TYPE)
2099: {
1.1.1.2 root 2100: error ("field `%s' declared as a function",
2101: IDENTIFIER_POINTER (declarator));
1.1 root 2102: type = build_pointer_type (type);
2103: }
1.1.1.2 root 2104: else if (TYPE_SIZE (type) == 0)
2105: {
2106: error ("field `%s' has incomplete type",
2107: IDENTIFIER_POINTER (declarator));
2108: type = error_mark_node;
2109: }
2110: decl = build_decl (FIELD_DECL, declarator, type);
1.1 root 2111: }
1.1.1.2 root 2112: else if (TREE_CODE (type) == FUNCTION_TYPE)
1.1 root 2113: {
1.1.1.2 root 2114: if (specbits & ((1 << (int) RID_AUTO) | (1 << (int) RID_REGISTER)))
2115: error ("invalid storage class for function `%s'",
2116: IDENTIFIER_POINTER (declarator));
2117: /* Function declaration not at top level.
2118: Storage classes other than `extern' are not allowed
2119: and `extern' makes no difference. */
2120: if (current_binding_level != global_binding_level
2121: && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
2122: && pedantic)
2123: warning ("invalid storage class for function `%s'",
2124: IDENTIFIER_POINTER (declarator));
2125: decl = build_decl (FUNCTION_DECL, declarator, type);
2126: TREE_EXTERNAL (decl) = 1;
2127: /* Record presence of `static'. */
2128: TREE_PUBLIC (decl) = !(specbits & (1 << (int) RID_STATIC));
2129: /* Record presence of `inline', if it is reasonable. */
2130: if (inlinep)
2131: {
2132: tree last = tree_last (TYPE_ARG_TYPES (type));
1.1 root 2133:
1.1.1.2 root 2134: if (! strcmp (IDENTIFIER_POINTER (declarator), "main"))
2135: warning ("cannot inline function `main'");
2136: else if (last && TREE_VALUE (last) != void_type_node)
2137: error ("inline declaration ignored for function with `...'");
2138: else
2139: /* Assume that otherwise the function can be inlined. */
2140: TREE_INLINE (decl) = 1;
2141: }
2142: }
2143: else
2144: {
2145: /* It's a variable. */
1.1 root 2146:
1.1.1.2 root 2147: decl = build_decl (VAR_DECL, declarator, type);
1.1 root 2148:
1.1.1.2 root 2149: if (inlinep)
2150: warning_with_decl (decl, "variable `%s' declared `inline'");
1.1 root 2151:
1.1.1.2 root 2152: /* An uninitialized decl with `extern' is a reference. */
2153: TREE_EXTERNAL (decl)
2154: = !initialized && (specbits & (1 << (int) RID_EXTERN));
2155: /* At top level, either `static' or no s.c. makes a definition
2156: (perhaps tentative), and absence of `static' makes it public. */
2157: if (current_binding_level == global_binding_level)
2158: {
2159: TREE_PUBLIC (decl) = !(specbits & (1 << (int) RID_STATIC));
2160: TREE_STATIC (decl) = ! TREE_EXTERNAL (decl);
2161: }
2162: /* Not at top level, only `static' makes a static definition. */
2163: else
2164: {
2165: TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
2166: /* `extern' with initialization is invalid if not at top level. */
2167: if ((specbits & (1 << (int) RID_EXTERN)) && initialized)
2168: error ("`%s' has both `extern' and initializer", name);
2169: }
1.1 root 2170: }
2171:
2172: /* Record `register' declaration for warnings on &
2173: and in case doing stupid register allocation. */
2174:
1.1.1.2 root 2175: if (specbits & (1 << (int) RID_REGISTER))
1.1 root 2176: TREE_REGDECL (decl) = 1;
2177:
2178: /* Record constancy and volatility. */
2179:
2180: if (constp)
2181: TREE_READONLY (decl) = 1;
2182: if (volatilep)
2183: {
2184: TREE_VOLATILE (decl) = 1;
2185: TREE_THIS_VOLATILE (decl) = 1;
2186: }
2187:
2188: return decl;
2189: }
2190: }
2191:
2192: /* Create a type of integers to be the TYPE_DOMAIN of an ARRAY_TYPE.
2193: MAXVAL should be the maximum value in the domain
2194: (one less than the length of the array). */
2195:
2196: tree
2197: make_index_type (maxval)
2198: tree maxval;
2199: {
2200: register tree itype = make_node (INTEGER_TYPE);
1.1.1.2 root 2201: int maxint = TREE_INT_CST_LOW (maxval);
1.1 root 2202: TYPE_PRECISION (itype) = BITS_PER_WORD;
2203: TYPE_MIN_VALUE (itype) = build_int_2 (0, 0);
2204: TREE_TYPE (TYPE_MIN_VALUE (itype)) = itype;
2205: TYPE_MAX_VALUE (itype) = maxval;
2206: TREE_TYPE (maxval) = itype;
2207: TYPE_MODE (itype) = SImode;
1.1.1.2 root 2208: TYPE_SIZE (itype) = TYPE_SIZE (long_integer_type_node);
2209: TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (long_integer_type_node);
2210: TYPE_ALIGN (itype) = TYPE_ALIGN (long_integer_type_node);
2211: return type_hash_canon (maxint > 0 ? maxint : - maxint, itype);
1.1 root 2212: }
2213:
1.1.1.3 root 2214: /* Decode the parameter-list info for a function type or function definition.
2215: The argument is the value returned by `get_parm_info' (or made in parse.y
2216: if there is an identifier list instead of a parameter decl list).
2217: These two functions are separate because when a function returns
2218: or receives functions then each is called multiple times but the order
2219: of calls is different. The last call to `grokparms' is always the one
2220: that contains the formal parameter names of a function definition.
2221:
2222: Store in `last_function_parms' a chain of the decls of parms.
2223: Also store in `last_function_parm_tags' a chain of the struct and union
2224: tags declared among the parms.
2225:
2226: Return a list of arg types to use in the FUNCTION_TYPE for this function.
1.1.1.2 root 2227:
2228: FUNCDEF_FLAG is nonzero for a function definition, 0 for
2229: a mere declaration. A nonempty identifier-list gets an error message
2230: when FUNCDEF_FLAG is zero. */
1.1 root 2231:
1.1.1.2 root 2232: static tree
1.1.1.3 root 2233: grokparms (parms_info, funcdef_flag)
2234: tree parms_info;
1.1.1.2 root 2235: int funcdef_flag;
1.1 root 2236: {
1.1.1.3 root 2237: tree first_parm = TREE_CHAIN (parms_info);
2238:
2239: last_function_parms = TREE_PURPOSE (parms_info);
2240: last_function_parm_tags = TREE_VALUE (parms_info);
2241:
1.1.1.2 root 2242: if (first_parm != 0
2243: && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
2244: {
2245: if (! funcdef_flag)
2246: warning ("parameter names (without types) in function declaration");
1.1 root 2247:
1.1.1.2 root 2248: last_function_parms = first_parm;
2249: return 0;
2250: }
2251: else
2252: {
1.1.1.3 root 2253: tree t;
2254: /* In a fcn definition, arg types must be complete. */
2255: if (funcdef_flag)
2256: for (t = last_function_parms; t; t = TREE_CHAIN (t))
2257: {
2258: tree type = TREE_TYPE (t);
2259: if (TYPE_SIZE (type) == 0)
2260: {
2261: error ("parameter `%s' has incomplete type",
2262: IDENTIFIER_POINTER (DECL_NAME (t)));
2263: TREE_TYPE (t) = error_mark_node;
2264: }
2265: }
2266:
1.1.1.2 root 2267: return first_parm;
2268: }
2269: }
2270:
2271:
1.1.1.3 root 2272: /* Return a tree_list node with info on a parameter list just parsed.
2273: The TREE_PURPOSE is a chain of decls of those parms.
2274: The TREE_VALUE is a list of structure, union and enum tags defined.
2275: The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
2276: This tree_list node is later fed to `grokparms'.
1.1.1.2 root 2277:
1.1.1.3 root 2278: VOID_AT_END nonzero means append `void' to the end of the type-list.
1.1.1.2 root 2279: Zero means the parmlist ended with an ellipsis so don't append `void'. */
2280:
2281: tree
1.1.1.3 root 2282: get_parm_info (void_at_end)
1.1.1.2 root 2283: int void_at_end;
2284: {
2285: register tree decl;
2286: register tree types = 0;
2287: tree link;
2288: int erred = 0;
1.1.1.3 root 2289: tree tags = gettags ();
2290: tree parms = nreverse (getdecls ());
1.1.1.2 root 2291:
2292: /* Just `void' (and no ellipsis) is special. There are really no parms. */
1.1.1.3 root 2293: if (void_at_end && parms != 0
2294: && TREE_CHAIN (parms) == 0
2295: && TREE_TYPE (parms) == void_type_node)
1.1.1.2 root 2296: {
1.1.1.3 root 2297: parms = NULL_TREE;
1.1.1.2 root 2298: storedecls (NULL_TREE);
1.1.1.3 root 2299: return tree_cons (NULL_TREE, NULL_TREE,
2300: tree_cons (NULL_TREE, void_type_node, NULL_TREE));
1.1.1.2 root 2301: }
2302:
1.1.1.3 root 2303: storedecls (parms);
1.1.1.2 root 2304:
1.1.1.3 root 2305: for (decl = parms; decl; decl = TREE_CHAIN (decl))
1.1.1.2 root 2306: {
2307: /* Since there is a prototype,
2308: args are passed in their declared types. */
2309: DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
2310:
2311: types = tree_cons (NULL_TREE, TREE_TYPE (decl), types);
2312: if (TREE_VALUE (types) == void_type_node && ! erred)
1.1 root 2313: {
1.1.1.2 root 2314: error ("`void' in parameter list must be the entire list");
2315: erred = 1;
1.1 root 2316: }
2317: }
2318:
1.1.1.2 root 2319: if (void_at_end)
1.1.1.3 root 2320: return tree_cons (parms, tags,
2321: nreverse (tree_cons (NULL_TREE, void_type_node, types)));
1.1.1.2 root 2322:
1.1.1.3 root 2323: return tree_cons (parms, tags, nreverse (types));
1.1.1.2 root 2324: }
2325:
2326: /* Get the struct, enum or union (CODE says which) with tag NAME.
2327: Define the tag as a forward-reference if it is not defined. */
2328:
2329: tree
2330: xref_tag (code, name)
2331: tree name;
2332: {
2333: /* If a cross reference is requested, look up the type
2334: already defined for this tag and return it. */
2335:
2336: register tree ref = lookup_tag (code, name, current_binding_level, 0);
2337: if (ref) return ref;
2338:
2339: /* If no such tag is yet defined, create a forward-reference node
2340: and record it as the "definition".
2341: When a real declaration of this type is found,
2342: the forward-reference will be altered into a real type. */
2343:
2344: ref = make_node (code);
2345: pushtag (name, ref);
2346: return ref;
1.1 root 2347: }
2348:
1.1.1.2 root 2349: /* Make sure that the tag NAME is defined *in the current binding level*
2350: at least as a forward reference.
2351: CODE says which kind of tag NAME ought to be. */
2352:
2353: tree
2354: start_struct (code, name)
2355: enum tree_code code;
2356: tree name;
2357: {
2358: /* If there is already a tag defined at this binding level
2359: (as a forward reference), just return it. */
2360:
2361: register tree ref = 0;
2362:
2363: if (name != 0)
2364: ref = lookup_tag (code, name, current_binding_level, 1);
2365: if (ref && TREE_CODE (ref) == code)
2366: {
2367: if (TYPE_FIELDS (ref))
2368: error ((code == UNION_TYPE ? "redefinition of `union %s'"
2369: : "redefinition of `struct %s'"),
2370: IDENTIFIER_POINTER (name));
2371:
2372: return ref;
2373: }
2374:
2375: /* Otherwise create a forward-reference just so the tag is in scope. */
2376:
2377: ref = make_node (code);
2378: pushtag (name, ref);
2379: return ref;
2380: }
2381:
1.1 root 2382: /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
2383: of a structure component, returning a FIELD_DECL node.
2384: WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
2385:
2386: This is done during the parsing of the struct declaration.
2387: The FIELD_DECL nodes are chained together and the lot of them
2388: are ultimately passed to `build_struct' to make the RECORD_TYPE node. */
2389:
2390: tree
2391: grokfield (filename, line, declarator, declspecs, width)
2392: char *filename;
2393: int line;
2394: tree declarator, declspecs, width;
2395: {
1.1.1.2 root 2396: register tree value = grokdeclarator (declarator, declspecs, FIELD, 0);
1.1 root 2397:
1.1.1.2 root 2398: finish_decl (value, NULL, NULL);
1.1 root 2399: DECL_INITIAL (value) = width;
1.1.1.2 root 2400:
1.1 root 2401: return value;
2402: }
2403:
1.1.1.2 root 2404: /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
2405: FIELDLIST is a chain of FIELD_DECL nodes for the fields. */
1.1 root 2406:
2407: tree
1.1.1.2 root 2408: finish_struct (t, fieldlist)
2409: register tree t, fieldlist;
1.1 root 2410: {
2411: register tree x;
1.1.1.2 root 2412: int old;
2413: int round_up_size = 1;
1.1 root 2414:
1.1.1.2 root 2415: /* If this type was previously laid out as a forward reference,
2416: make sure we lay it out again. */
1.1 root 2417:
1.1.1.2 root 2418: TYPE_SIZE (t) = 0;
1.1 root 2419:
1.1.1.2 root 2420: old = suspend_momentary ();
1.1 root 2421:
1.1.1.2 root 2422: if (fieldlist == 0 && pedantic)
2423: warning ((TREE_CODE (t) == UNION_TYPE ? "union has no members"
2424: : "structure has no members"));
1.1 root 2425:
2426: /* Install struct as DECL_CONTEXT of each field decl.
2427: Also process specified field sizes.
2428: Set DECL_SIZE_UNIT to the specified size, or 0 if none specified.
2429: The specified size is found in the DECL_INITIAL.
2430: Store 0 there, except for ": 0" fields (so we can find them
2431: and delete them, below). */
2432:
2433: for (x = fieldlist; x; x = TREE_CHAIN (x))
2434: {
2435: DECL_CONTEXT (x) = t;
2436: DECL_SIZE_UNIT (x) = 0;
1.1.1.2 root 2437:
2438: /* If any field is const, the structure type is pseudo-const. */
2439: if (TREE_READONLY (x))
2440: C_TYPE_FIELDS_READONLY (t) = 1;
2441: else
2442: {
2443: /* A field that is pseudo-const makes the structure likewise. */
2444: tree t1 = TREE_TYPE (x);
2445: while (TREE_CODE (t1) == ARRAY_TYPE)
2446: t1 = TREE_TYPE (t1);
2447: if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
2448: && C_TYPE_FIELDS_READONLY (t1))
2449: C_TYPE_FIELDS_READONLY (t) = 1;
2450: }
2451:
2452: /* Detect invalid bit-field size. */
1.1 root 2453: if (DECL_INITIAL (x) && TREE_CODE (DECL_INITIAL (x)) != INTEGER_CST)
2454: {
1.1.1.2 root 2455: error_with_decl (x, "bit-field `%s' width not an integer constant");
1.1 root 2456: DECL_INITIAL (x) = NULL;
2457: }
1.1.1.2 root 2458:
2459: /* Detect invalid bit-field type. */
2460: if (DECL_INITIAL (x)
2461: && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
2462: && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
2463: {
2464: error_with_decl (x, "bit-field `%s' has invalid type");
2465: DECL_INITIAL (x) = NULL;
2466: }
2467: if (DECL_INITIAL (x) && pedantic
2468: && TREE_TYPE (x) != integer_type_node
2469: && TREE_TYPE (x) != unsigned_type_node)
2470: warning_with_decl (x, "bit-field `%s' type invalid in ANSI C");
2471:
2472: /* Detect and ignore out of range field width. */
1.1 root 2473: if (DECL_INITIAL (x))
2474: {
1.1.1.2 root 2475: register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
1.1 root 2476:
1.1.1.2 root 2477: if (width < 0)
2478: {
2479: DECL_INITIAL (x) = NULL;
2480: warning_with_decl (x, "negative width in bit-field `%s'");
2481: }
2482: else if (width > TYPE_PRECISION (TREE_TYPE (x)))
2483: {
2484: DECL_INITIAL (x) = NULL;
2485: warning_with_decl (x, "width of `%s' exceeds its type");
2486: }
2487: }
2488:
2489: /* Process valid field width. */
2490: if (DECL_INITIAL (x))
2491: {
2492: register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
2493:
2494: if (width == 0)
1.1 root 2495: {
2496: /* field size 0 => mark following field as "aligned" */
2497: if (TREE_CHAIN (x))
1.1.1.3 root 2498: DECL_ALIGN (TREE_CHAIN (x))
2499: = MAX (DECL_ALIGN (TREE_CHAIN (x)), EMPTY_FIELD_BOUNDARY);
1.1.1.2 root 2500: /* field of size 0 at the end => round up the size. */
2501: else
2502: round_up_size = EMPTY_FIELD_BOUNDARY;
1.1 root 2503: }
2504: else
2505: {
2506: DECL_INITIAL (x) = NULL;
1.1.1.2 root 2507: DECL_SIZE_UNIT (x) = width;
1.1 root 2508: TREE_PACKED (x) = 1;
1.1.1.2 root 2509: /* Traditionally a bit field is unsigned
2510: even if declared signed. */
2511: if (flag_traditional
2512: && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE)
2513: TREE_TYPE (x) = unsigned_type_node;
1.1 root 2514: }
2515: }
1.1.1.2 root 2516: else
2517: /* Non-bit-fields are aligned for their type. */
1.1.1.3 root 2518: DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
1.1 root 2519: }
1.1.1.2 root 2520:
2521: /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
2522: And they have already done their work. */
2523:
2524: /* Delete all zero-width bit-fields from the front of the fieldlist */
1.1 root 2525: while (fieldlist
2526: && DECL_INITIAL (fieldlist))
2527: fieldlist = TREE_CHAIN (fieldlist);
1.1.1.2 root 2528: /* Delete all such members from the rest of the fieldlist */
1.1 root 2529: for (x = fieldlist; x;)
2530: {
2531: if (TREE_CHAIN (x) && DECL_INITIAL (TREE_CHAIN (x)))
2532: TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
2533: else x = TREE_CHAIN (x);
2534: }
2535:
1.1.1.2 root 2536: /* Delete all duplicate fields from the fieldlist */
2537: for (x = fieldlist; x && TREE_CHAIN (x);)
2538: /* Anonymous fields aren't duplicates. */
2539: if (DECL_NAME (TREE_CHAIN (x)) == 0)
2540: x = TREE_CHAIN (x);
2541: else
2542: {
2543: register tree y = fieldlist;
2544:
2545: while (1)
2546: {
2547: if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
2548: break;
2549: if (y == x)
2550: break;
2551: y = TREE_CHAIN (y);
2552: }
2553: if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
2554: {
2555: error_with_decl (TREE_CHAIN (x), "duplicate member `%s'");
2556: TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
2557: }
2558: else x = TREE_CHAIN (x);
2559: }
2560:
2561: /* Now we have the final fieldlist. Record it,
2562: then lay out the structure or union (including the fields). */
2563:
1.1 root 2564: TYPE_FIELDS (t) = fieldlist;
1.1.1.2 root 2565:
2566: /* If there's a :0 field at the end, round the size to the
2567: EMPTY_FIELD_BOUNDARY. */
2568: TYPE_ALIGN (t) = round_up_size;
1.1 root 2569:
2570: layout_type (t);
2571:
1.1.1.2 root 2572: /* Promote each bit-field's type to int if it is narrower than that. */
2573: for (x = fieldlist; x; x = TREE_CHAIN (x))
2574: if (TREE_PACKED (x)
2575: && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE
2576: && (TREE_INT_CST_LOW (DECL_SIZE (x)) * DECL_SIZE_UNIT (x)
2577: < TYPE_PRECISION (integer_type_node)))
2578: TREE_TYPE (x) = integer_type_node;
2579:
2580: /* If this structure or union completes the type of any previous
2581: variable declaration, lay it out and output its rtl. */
2582:
2583: if (current_binding_level->n_incomplete != 0)
2584: {
2585: tree decl;
2586: for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
2587: if (TREE_TYPE (decl) == t
2588: && TREE_CODE (decl) != TYPE_DECL)
2589: {
2590: int toplevel = global_binding_level == current_binding_level;
2591: layout_decl (decl);
2592: rest_of_decl_compilation (decl, 0, toplevel, 0);
2593: if (! toplevel)
2594: expand_decl (decl);
2595: --current_binding_level->n_incomplete;
2596: }
2597: }
2598:
2599: resume_momentary (old);
1.1 root 2600:
2601: return t;
2602: }
2603:
2604: /* Begin compiling the definition of an enumeration type.
2605: NAME is its name (or null if anonymous).
2606: Returns the type object, as yet incomplete.
2607: Also records info about it so that build_enumerator
2608: may be used to declare the individual values as they are read. */
2609:
2610: tree
2611: start_enum (name)
2612: tree name;
2613: {
2614: register tree enumtype = 0;
2615:
2616: /* If this is the real definition for a previous forward reference,
2617: fill in the contents in the same object that used to be the
2618: forward reference. */
2619:
2620: if (name != 0)
2621: enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1);
2622:
1.1.1.2 root 2623: if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
1.1 root 2624: {
2625: enumtype = make_node (ENUMERAL_TYPE);
2626: pushtag (name, enumtype);
2627: }
2628:
2629: if (TYPE_VALUES (enumtype) != 0)
2630: {
2631: /* This enum is a named one that has been declared already. */
1.1.1.2 root 2632: error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
1.1 root 2633:
2634: /* Completely replace its old definition.
2635: The old enumerators remain defined, however. */
2636: TYPE_VALUES (enumtype) = 0;
2637: }
2638:
2639: /* Initially, set up this enum as like `int'
2640: so that we can create the enumerators' declarations and values.
2641: Later on, the precision of the type may be changed and
2642: it may be layed out again. */
2643:
2644: TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
2645: TYPE_SIZE (enumtype) = 0;
2646: fixup_unsigned_type (enumtype);
2647:
1.1.1.2 root 2648: enum_next_value = integer_zero_node;
1.1 root 2649:
2650: return enumtype;
2651: }
2652:
2653: /* After processing and defining all the values of an enumeration type,
2654: install their decls in the enumeration type and finish it off.
2655: ENUMTYPE is the type object and VALUES a list of name-value pairs.
2656: Returns ENUMTYPE. */
2657:
2658: tree
2659: finish_enum (enumtype, values)
2660: register tree enumtype, values;
2661: {
2662: register tree pair = values;
2663: register long maxvalue = 0;
1.1.1.4 ! root 2664: register long minvalue = 0;
1.1 root 2665: register int i;
2666:
2667: TYPE_VALUES (enumtype) = values;
2668:
2669: /* Calculate the maximum value of any enumerator in this type. */
1.1.1.2 root 2670:
1.1 root 2671: for (pair = values; pair; pair = TREE_CHAIN (pair))
2672: {
2673: int value = TREE_INT_CST_LOW (TREE_VALUE (pair));
1.1.1.4 ! root 2674: if (pair == values)
! 2675: minvalue = maxvalue = value;
! 2676: else
! 2677: {
! 2678: if (value > maxvalue)
! 2679: maxvalue = value;
! 2680: if (value < minvalue)
! 2681: minvalue = value;
! 2682: }
1.1 root 2683: }
2684:
2685: #if 0
2686: /* Determine the precision this type needs, lay it out, and define it. */
2687:
2688: for (i = maxvalue; i; i >>= 1)
2689: TYPE_PRECISION (enumtype)++;
2690:
2691: if (!TYPE_PRECISION (enumtype))
2692: TYPE_PRECISION (enumtype) = 1;
2693:
2694: /* Cancel the laying out previously done for the enum type,
2695: so that fixup_unsigned_type will do it over. */
2696: TYPE_SIZE (enumtype) = 0;
2697:
2698: fixup_unsigned_type (enumtype);
1.1.1.2 root 2699: #endif
1.1 root 2700:
1.1.1.4 ! root 2701: TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
1.1 root 2702:
1.1.1.4 ! root 2703: /* An enum can have some negative values; then it is signed. */
! 2704: if (minvalue < 0)
! 2705: {
! 2706: TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
! 2707: TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
! 2708: TREE_UNSIGNED (enumtype) = 0;
! 2709: }
1.1 root 2710: return enumtype;
2711: }
2712:
2713: /* Build and install a CONST_DECL for one value of the
2714: current enumeration type (one that was begun with start_enum).
2715: Return a tree-list containing the name and its value.
2716: Assignment of sequential values by default is handled here. */
1.1.1.2 root 2717:
1.1 root 2718: tree
2719: build_enumerator (name, value)
2720: tree name, value;
2721: {
2722: register tree decl;
2723:
2724: /* Validate and default VALUE. */
2725:
2726: if (value != 0 && TREE_CODE (value) != INTEGER_CST)
2727: {
1.1.1.2 root 2728: error ("enumerator value for `%s' not integer constant",
2729: IDENTIFIER_POINTER (name));
1.1 root 2730: value = 0;
2731: }
2732:
1.1.1.2 root 2733: /* Default based on previous value. */
1.1 root 2734: if (value == 0)
1.1.1.2 root 2735: value = enum_next_value;
1.1 root 2736:
1.1.1.2 root 2737: /* Set basis for default for next value. */
2738: enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
2739: integer_one_node);
1.1 root 2740:
2741: /* Now create a declaration for the enum value name. */
2742:
1.1.1.2 root 2743: decl = build_decl (CONST_DECL, name, integer_type_node);
1.1 root 2744: DECL_INITIAL (decl) = value;
1.1.1.2 root 2745: TREE_TYPE (value) = integer_type_node;
1.1 root 2746: pushdecl (decl);
2747:
2748: return build_tree_list (name, value);
2749: }
2750:
2751: /* Create the FUNCTION_DECL for a function definition.
2752: LINE1 is the line number that the definition absolutely begins on.
2753: LINE2 is the line number that the name of the function appears on.
2754: DECLSPECS and DECLARATOR are the parts of the declaration;
2755: they describe the function's name and the type it returns,
2756: but twisted together in a fashion that parallels the syntax of C.
2757:
2758: This function creates a binding context for the function body
2759: as well as setting up the FUNCTION_DECL in current_function_decl.
2760:
2761: Returns 1 on success. If the DECLARATOR is not suitable for a function
2762: (it defines a datum instead), we return 0, which tells
2763: yyparse to report a parse error. */
2764:
2765: int
2766: start_function (declspecs, declarator)
2767: tree declarator, declspecs;
2768: {
1.1.1.2 root 2769: tree decl1, old_decl;
1.1.1.3 root 2770: tree restype;
1.1.1.2 root 2771:
2772: current_function_returns_value = 0; /* Assume, until we see it does. */
2773: current_function_returns_null = 0;
2774: warn_about_return_type = 0;
1.1 root 2775:
1.1.1.2 root 2776: decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
1.1 root 2777:
1.1.1.2 root 2778: /* If the declarator is not suitable for a function definition,
2779: cause a syntax error. */
2780: if (decl1 == 0)
1.1 root 2781: return 0;
2782:
2783: current_function_decl = decl1;
2784:
2785: announce_function (current_function_decl);
2786:
1.1.1.3 root 2787: if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0)
1.1.1.2 root 2788: {
2789: error ("return-type is an incomplete type");
2790: /* Make it return void instead. */
2791: TREE_TYPE (decl1)
2792: = build_function_type (void_type_node,
2793: TYPE_ARG_TYPES (TREE_TYPE (decl1)));
2794: }
2795:
2796: if (warn_about_return_type)
2797: warning ("return-type defaults to `int'");
2798:
2799: /* Save the parm names or decls from this function's declarator
2800: where store_parm_decls will find them. */
2801: current_function_parms = last_function_parms;
2802: current_function_parm_tags = last_function_parm_tags;
2803:
1.1 root 2804: /* Make the init_value nonzero so pushdecl knows this is not tentative.
1.1.1.2 root 2805: error_mark_node is replaced below (in poplevel) with the LET_STMT. */
2806: DECL_INITIAL (current_function_decl) = error_mark_node;
2807:
2808: /* If this definition isn't a prototype and we had a prototype declaration
2809: before, copy the arg type info from that prototype. */
2810: old_decl = lookup_name_current_level (DECL_NAME (current_function_decl));
2811: if (old_decl != 0
2812: && TREE_TYPE (TREE_TYPE (current_function_decl)) == TREE_TYPE (TREE_TYPE (old_decl))
2813: && TYPE_ARG_TYPES (TREE_TYPE (current_function_decl)) == 0)
2814: TREE_TYPE (current_function_decl) = TREE_TYPE (old_decl);
2815:
2816: /* This is a definition, not a reference. */
2817: TREE_EXTERNAL (current_function_decl) = 0;
2818: /* This function exists in static storage.
2819: (This does not mean `static' in the C sense!) */
2820: TREE_STATIC (current_function_decl) = 1;
2821:
2822: /* Record the decl so that the function name is defined.
2823: If we already have a decl for this name, and it is a FUNCTION_DECL,
2824: use the old decl. */
1.1 root 2825:
1.1.1.2 root 2826: current_function_decl = pushdecl (current_function_decl);
1.1 root 2827:
1.1.1.2 root 2828: pushlevel (0);
2829: current_binding_level->parm_flag = 1;
1.1 root 2830:
2831: make_function_rtl (current_function_decl);
2832:
2833: /* Allocate further tree nodes temporarily during compilation
2834: of this function only. */
2835: temporary_allocation ();
2836:
1.1.1.3 root 2837: restype = TREE_TYPE (TREE_TYPE (current_function_decl));
2838: /* Promote the value to int before returning it. */
2839: if (TREE_CODE (restype) == INTEGER_TYPE
2840: && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
2841: restype = integer_type_node;
1.1 root 2842: DECL_RESULT (current_function_decl)
1.1.1.3 root 2843: = build_decl (RESULT_DECL, value_identifier, restype);
1.1 root 2844:
2845: /* Make the FUNCTION_DECL's contents appear in a local tree dump
2846: and make the FUNCTION_DECL itself not appear in the permanent dump. */
2847:
2848: TREE_PERMANENT (current_function_decl) = 0;
2849:
1.1.1.4 ! root 2850: /* If this fcn was already referenced via a block-scope `extern' decl
! 2851: (or an implicit decl), propagate certain information about the usage. */
! 2852: if (TREE_ADDRESSABLE (DECL_NAME (current_function_decl)))
! 2853: TREE_ADDRESSABLE (current_function_decl) = 1;
! 2854:
1.1 root 2855: return 1;
2856: }
2857:
2858: /* Store the parameter declarations into the current function declaration.
2859: This is called after parsing the parameter declarations, before
2860: digesting the body of the function. */
2861:
2862: void
2863: store_parm_decls ()
2864: {
2865: register tree fndecl = current_function_decl;
2866: register tree parm;
2867:
1.1.1.2 root 2868: /* This is either a chain of PARM_DECLs (if a prototype was used)
2869: or a list of IDENTIFIER_NODEs (for an old-fashioned C definition). */
2870: tree specparms = current_function_parms;
1.1 root 2871:
1.1.1.2 root 2872: /* This is a list of types declared among parms in a prototype. */
2873: tree parmtags = current_function_parm_tags;
1.1 root 2874:
1.1.1.2 root 2875: /* This is a chain of PARM_DECLs from old-style parm declarations. */
2876: register tree parmdecls = getdecls ();
1.1 root 2877:
1.1.1.2 root 2878: /* This is a chain of any other decls that came in among the parm
2879: declarations. If a parm is declared with enum {foo, bar} x;
2880: then CONST_DECLs for foo and bar are put here. */
2881: tree nonparms = 0;
2882:
2883: if (specparms != 0 && TREE_CODE (specparms) == PARM_DECL)
2884: {
2885: /* This case is when the function was defined with an ANSI prototype.
2886: The parms already have decls, so we need not do anything here
2887: except record them as in effect
2888: and complain if any redundant old-style parm decls were written. */
2889:
2890: register tree next;
2891:
2892: if (parmdecls != 0)
2893: error_with_decl (fndecl,
2894: "parm types given both in parmlist and separately");
2895:
2896: for (parm = nreverse (specparms); parm; parm = next)
2897: {
2898: next = TREE_CHAIN (parm);
2899: if (DECL_NAME (parm) == 0)
2900: error_with_decl (parm, "parameter name omitted");
2901: else if (TREE_TYPE (parm) == void_type_node)
2902: error_with_decl (parm, "parameter `%s' declared void");
2903: else
2904: pushdecl (parm);
1.1 root 2905: }
2906:
1.1.1.2 root 2907: /* Get the decls in their original chain order
2908: and record in the function. */
2909: DECL_ARGUMENTS (fndecl) = getdecls ();
1.1 root 2910:
1.1.1.2 root 2911: storetags (chainon (parmtags, gettags ()));
2912: }
2913: else
2914: {
2915: /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
2916: each with a parm name as the TREE_VALUE.
2917:
2918: PARMDECLS is a list of declarations for parameters.
2919: Warning! It can also contain CONST_DECLs which are not parameters
2920: but are names of enumerators of any enum types
2921: declared among the parameters.
2922:
2923: First match each formal parameter name with its declaration.
2924: Associate decls with the names and store the decls
2925: into the TREE_PURPOSE slots. */
1.1 root 2926:
1.1.1.2 root 2927: for (parm = specparms; parm; parm = TREE_CHAIN (parm))
1.1 root 2928: {
1.1.1.2 root 2929: register tree tail, found = NULL;
2930:
2931: if (TREE_VALUE (parm) == 0)
2932: {
2933: error_with_decl (fndecl, "parameter name missing from parameter list");
2934: TREE_PURPOSE (parm) = 0;
2935: continue;
2936: }
1.1 root 2937:
1.1.1.2 root 2938: /* See if any of the parmdecls specifies this parm by name.
2939: Ignore any enumerator decls. */
2940: for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
2941: if (DECL_NAME (tail) == TREE_VALUE (parm)
2942: && TREE_CODE (tail) == PARM_DECL)
2943: {
2944: found = tail;
2945: break;
2946: }
2947:
2948: /* If declaration already marked, we have a duplicate name.
2949: Complain, and don't use this decl twice. */
2950: if (found && DECL_CONTEXT (found) != 0)
2951: {
2952: error_with_decl (found, "multiple parameters named `%s'");
2953: found = 0;
2954: }
1.1 root 2955:
1.1.1.2 root 2956: /* If the declaration says "void", complain and ignore it. */
2957: if (found && TREE_TYPE (found) == void_type_node)
2958: {
2959: error_with_decl (found, "parameter `%s' declared void");
2960: TREE_TYPE (found) = integer_type_node;
2961: DECL_ARG_TYPE (found) = integer_type_node;
2962: layout_decl (found, 0);
2963: }
1.1 root 2964:
1.1.1.2 root 2965: /* If no declaration found, default to int. */
2966: if (!found)
2967: {
2968: found = build_decl (PARM_DECL, TREE_VALUE (parm),
2969: integer_type_node);
2970: DECL_ARG_TYPE (found) = TREE_TYPE (found);
2971: DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
2972: DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
2973: pushdecl (found);
2974: }
1.1 root 2975:
1.1.1.2 root 2976: TREE_PURPOSE (parm) = found;
1.1 root 2977:
1.1.1.2 root 2978: /* Mark this decl as "already found" -- see test, above.
2979: It is safe to clobber DECL_CONTEXT temporarily
2980: because the final values are not stored until
2981: the `poplevel' in `finish_function'. */
2982: DECL_CONTEXT (found) = error_mark_node;
2983: }
1.1 root 2984:
1.1.1.2 root 2985: /* Complain about declarations not matched with any names.
2986: Put any enumerator constants onto the list NONPARMS. */
2987:
2988: nonparms = 0;
2989: for (parm = parmdecls; parm; )
1.1 root 2990: {
1.1.1.2 root 2991: tree next = TREE_CHAIN (parm);
2992: TREE_CHAIN (parm) = 0;
2993:
1.1.1.3 root 2994: /* Complain about args with incomplete types. */
2995: if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
2996: {
2997: error_with_decl (parm, "parameter `%s' has incomplete type");
2998: TREE_TYPE (parm) = error_mark_node;
2999: }
3000:
1.1.1.2 root 3001: if (TREE_CODE (parm) != PARM_DECL)
3002: nonparms = chainon (nonparms, parm);
3003:
3004: else if (DECL_CONTEXT (parm) == 0)
3005: {
3006: error_with_decl (parm,
3007: "declaration for parameter `%s' but no such parameter");
3008: /* Pretend the parameter was not missing.
3009: This gets us to a standard state and minimizes
3010: further error messages. */
3011: specparms
3012: = chainon (specparms,
3013: tree_cons (parm, NULL_TREE, NULL_TREE));
3014: }
3015:
3016: parm = next;
1.1 root 3017: }
1.1.1.2 root 3018:
3019: /* Chain the declarations together in the order of the list of names. */
3020: /* Store that chain in the function decl, replacing the list of names. */
3021: parm = specparms;
3022: DECL_ARGUMENTS (fndecl) = 0;
3023: {
3024: register tree last;
3025: for (last = 0; parm; parm = TREE_CHAIN (parm))
3026: if (TREE_PURPOSE (parm))
3027: {
3028: if (last == 0)
3029: DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
3030: else
3031: TREE_CHAIN (last) = TREE_PURPOSE (parm);
3032: last = TREE_PURPOSE (parm);
3033: TREE_CHAIN (last) = 0;
3034: DECL_CONTEXT (last) = 0;
3035: }
3036: }
3037:
3038: /* If there was a previous prototype,
3039: set the DECL_ARG_TYPE of each argument according to
3040: the type previously specified, and report any mismatches. */
3041:
3042: if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
3043: {
3044: register tree type;
3045: for (parm = DECL_ARGUMENTS (fndecl),
3046: type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
3047: parm || (type && TREE_VALUE (type) != void_type_node);
3048: parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
3049: {
3050: if (parm == 0 || type == 0
3051: || TREE_VALUE (type) == void_type_node)
3052: {
3053: error ("argument decls of `%s' don't match prototype",
3054: IDENTIFIER_POINTER (DECL_NAME (fndecl)));
3055: break;
3056: }
3057: /* Type for passing arg must be consistent
3058: with that declared for the arg. */
3059: if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type)))
3060: error ("argument `%s' doesn't match function prototype",
3061: IDENTIFIER_POINTER (DECL_NAME (parm)));
3062: }
3063: }
3064: }
1.1 root 3065:
3066: /* Now store the final chain of decls for the arguments
1.1.1.2 root 3067: as the decl-chain of the current lexical scope.
3068: Put the enumerators in as well, at the front so that
3069: DECL_ARGUMENTS is not modified. */
1.1 root 3070:
1.1.1.2 root 3071: storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
1.1 root 3072:
1.1.1.2 root 3073: /* Initialize the RTL code for the function. */
1.1 root 3074:
1.1.1.2 root 3075: expand_function_start (fndecl);
1.1 root 3076: }
3077:
3078: /* Finish up a function declaration and compile that function
3079: all the way to assembler language output. The free the storage
3080: for the function definition.
3081:
3082: This is called after parsing the body of the function definition.
3083: STMTS is the chain of statements that makes up the function body. */
3084:
3085: void
1.1.1.3 root 3086: finish_function ()
1.1 root 3087: {
3088: register tree fndecl = current_function_decl;
3089:
3090: /* TREE_READONLY (fndecl) = 1;
3091: This caused &foo to be of type ptr-to-const-function
3092: which then got a warning when stored in a ptr-to-function variable. */
3093:
1.1.1.2 root 3094: poplevel (1, 0, 1);
1.1 root 3095:
1.1.1.2 root 3096: /* Must mark the RESULT_DECL as being in this function. */
1.1 root 3097:
1.1.1.2 root 3098: DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
1.1 root 3099:
1.1.1.2 root 3100: /* Generate rtl for function exit. */
3101: expand_function_end ();
1.1 root 3102:
1.1.1.2 root 3103: if (warn_return_type)
3104: /* So we can tell if jump_optimize sets it to 1. */
3105: current_function_returns_null = 0;
3106:
3107: /* Run the optimizers and output the assembler code for this function. */
3108: rest_of_compilation (fndecl);
3109:
3110: if (warn_return_type && current_function_returns_null
3111: && TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node)
3112: /* If this function returns non-void and control can drop through,
3113: complain. */
3114: warning ("control reaches end of non-void function");
3115: /* With just -W, complain only if function returns both with
3116: and without a value. */
3117: else if (extra_warnings
3118: && current_function_returns_value && current_function_returns_null)
3119: warning ("this function may return with or without a value");
1.1 root 3120:
3121: /* Free all the tree nodes making up this function. */
3122: /* Switch back to allocating nodes permanently
3123: until we start another function. */
3124: permanent_allocation ();
3125:
1.1.1.2 root 3126: if (DECL_SAVED_INSNS (fndecl) == 0)
1.1 root 3127: {
1.1.1.2 root 3128: /* Stop pointing to the local nodes about to be freed. */
3129: /* But DECL_INITIAL must remain nonzero so we know this
3130: was an actual function definition. */
3131: DECL_INITIAL (fndecl) = error_mark_node;
3132: DECL_ARGUMENTS (fndecl) = 0;
3133: DECL_RESULT (fndecl) = 0;
1.1 root 3134: }
1.1.1.2 root 3135:
3136: /* Let the error reporting routines know that we're outside a function. */
3137: current_function_decl = NULL;
1.1 root 3138: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.