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