|
|
1.1 root 1: /* Process declarations and variables for C compiler. 1.1.1.2 ! root 2: Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 1.1 root 3: Hacked by Michael Tiemann ([email protected]) 4: 5: This file is part of GNU CC. 6: 7: GNU CC is free software; you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation; either version 2, or (at your option) 10: any later version. 11: 12: GNU CC is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with GNU CC; see the file COPYING. If not, write to 1.1.1.2 ! root 19: the Free Software Foundation, 59 Temple Place - Suite 330, ! 20: Boston, MA 02111-1307, USA. */ 1.1 root 21: 22: 23: /* Process declarations and symbol lookup for C front end. 24: Also constructs types; the standard scalar types at initialization, 25: and structure, union, array and enum types when they are declared. */ 26: 27: /* ??? not all decl nodes are given the most useful possible 28: line numbers. For example, the CONST_DECLs for enum values. */ 29: 30: #include <stdio.h> 31: #include "config.h" 32: #include "tree.h" 33: #include "rtl.h" 34: #include "flags.h" 35: #include "cp-tree.h" 36: #include "decl.h" 37: #include "lex.h" 38: #include <sys/types.h> 39: #include <signal.h> 40: #include "obstack.h" 41: 42: #define obstack_chunk_alloc xmalloc 43: #define obstack_chunk_free free 44: 45: extern tree builtin_return_address_fndecl; 46: 47: extern struct obstack permanent_obstack; 48: 49: extern int current_class_depth; 50: 51: extern tree cleanups_this_call; 52: 1.1.1.2 ! root 53: extern tree static_ctors, static_dtors; ! 54: 1.1 root 55: /* Stack of places to restore the search obstack back to. */ 56: 57: /* Obstack used for remembering local class declarations (like 58: enums and static (const) members. */ 59: #include "stack.h" 60: static struct obstack decl_obstack; 61: static struct stack_level *decl_stack; 62: 63: #ifndef CHAR_TYPE_SIZE 64: #define CHAR_TYPE_SIZE BITS_PER_UNIT 65: #endif 66: 67: #ifndef SHORT_TYPE_SIZE 68: #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) 69: #endif 70: 71: #ifndef INT_TYPE_SIZE 72: #define INT_TYPE_SIZE BITS_PER_WORD 73: #endif 74: 75: #ifndef LONG_TYPE_SIZE 76: #define LONG_TYPE_SIZE BITS_PER_WORD 77: #endif 78: 79: #ifndef LONG_LONG_TYPE_SIZE 80: #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) 81: #endif 82: 83: #ifndef WCHAR_UNSIGNED 84: #define WCHAR_UNSIGNED 0 85: #endif 86: 87: #ifndef FLOAT_TYPE_SIZE 88: #define FLOAT_TYPE_SIZE BITS_PER_WORD 89: #endif 90: 91: #ifndef DOUBLE_TYPE_SIZE 92: #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) 93: #endif 94: 95: #ifndef LONG_DOUBLE_TYPE_SIZE 96: #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) 97: #endif 98: 1.1.1.2 ! root 99: #ifndef BOOL_TYPE_SIZE ! 100: #ifdef SLOW_BYTE_ACCESS ! 101: #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (BITS_PER_WORD) : (BITS_PER_UNIT)) ! 102: #else ! 103: #define BOOL_TYPE_SIZE BITS_PER_UNIT ! 104: #endif ! 105: #endif ! 106: 1.1 root 107: /* We let tm.h override the types used here, to handle trivial differences 108: such as the choice of unsigned int or long unsigned int for size_t. 109: When machines start needing nontrivial differences in the size type, 110: it would be best to do something here to figure out automatically 111: from other information what type to use. */ 112: 113: #ifndef SIZE_TYPE 114: #define SIZE_TYPE "long unsigned int" 115: #endif 116: 117: #ifndef PTRDIFF_TYPE 118: #define PTRDIFF_TYPE "long int" 119: #endif 120: 121: #ifndef WCHAR_TYPE 122: #define WCHAR_TYPE "int" 123: #endif 124: 125: static tree grokparms PROTO((tree, int)); 126: static tree lookup_nested_type PROTO((tree, tree)); 127: static char *redeclaration_error_message PROTO((tree, tree)); 128: static void grok_op_properties PROTO((tree, int, int)); 129: 130: tree define_function 131: PROTO((char *, tree, enum built_in_function, void (*)(), char *)); 132: 133: /* a node which has tree code ERROR_MARK, and whose type is itself. 134: All erroneous expressions are replaced with this node. All functions 135: that accept nodes as arguments should avoid generating error messages 136: if this node is one of the arguments, since it is undesirable to get 137: multiple error messages from one error in the input. */ 138: 139: tree error_mark_node; 140: 141: /* Erroneous argument lists can use this *IFF* they do not modify it. */ 142: tree error_mark_list; 143: 144: /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ 145: 146: tree short_integer_type_node; 147: tree integer_type_node; 148: tree long_integer_type_node; 149: tree long_long_integer_type_node; 150: 151: tree short_unsigned_type_node; 152: tree unsigned_type_node; 153: tree long_unsigned_type_node; 154: tree long_long_unsigned_type_node; 155: 156: tree ptrdiff_type_node; 157: 158: tree unsigned_char_type_node; 159: tree signed_char_type_node; 160: tree char_type_node; 161: tree wchar_type_node; 162: tree signed_wchar_type_node; 163: tree unsigned_wchar_type_node; 164: 165: tree wchar_decl_node; 166: 167: tree float_type_node; 168: tree double_type_node; 169: tree long_double_type_node; 170: 171: tree intQI_type_node; 172: tree intHI_type_node; 173: tree intSI_type_node; 174: tree intDI_type_node; 175: 176: tree unsigned_intQI_type_node; 177: tree unsigned_intHI_type_node; 178: tree unsigned_intSI_type_node; 179: tree unsigned_intDI_type_node; 180: 181: /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */ 182: 183: tree void_type_node, void_list_node; 184: tree void_zero_node; 185: 186: /* Nodes for types `void *' and `const void *'. */ 187: 188: tree ptr_type_node, const_ptr_type_node; 189: 190: /* Nodes for types `char *' and `const char *'. */ 191: 192: tree string_type_node, const_string_type_node; 193: 194: /* Type `char[256]' or something like it. 195: Used when an array of char is needed and the size is irrelevant. */ 196: 197: tree char_array_type_node; 198: 199: /* Type `int[256]' or something like it. 200: Used when an array of int needed and the size is irrelevant. */ 201: 202: tree int_array_type_node; 203: 204: /* Type `wchar_t[256]' or something like it. 205: Used when a wide string literal is created. */ 206: 207: tree wchar_array_type_node; 208: 209: /* The bool data type, and constants */ 1.1.1.2 ! root 210: tree boolean_type_node, boolean_true_node, boolean_false_node; 1.1 root 211: 212: /* type `int ()' -- used for implicit declaration of functions. */ 213: 214: tree default_function_type; 215: 216: /* function types `double (double)' and `double (double, double)', etc. */ 217: 218: tree double_ftype_double, double_ftype_double_double; 219: tree int_ftype_int, long_ftype_long; 220: 221: /* Function type `void (void *, void *, int)' and similar ones. */ 222: 223: tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int; 224: 225: /* Function type `char *(char *, char *)' and similar ones */ 226: tree string_ftype_ptr_ptr, int_ftype_string_string; 227: 228: /* Function type `size_t (const char *)' */ 229: tree sizet_ftype_string; 230: 231: /* Function type `int (const void *, const void *, size_t)' */ 232: tree int_ftype_cptr_cptr_sizet; 233: 234: /* C++ extensions */ 235: tree vtable_entry_type; 236: tree delta_type_node; 1.1.1.2 ! root 237: #if 0 ! 238: /* Old rtti stuff. */ ! 239: tree __baselist_desc_type_node; ! 240: tree __i_desc_type_node, __m_desc_type_node; 1.1 root 241: tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; 1.1.1.2 ! root 242: #endif ! 243: tree __t_desc_type_node, __tp_desc_type_node; ! 244: tree __access_mode_type_node; ! 245: tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node; ! 246: tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node; ! 247: tree __ptmf_desc_type_node, __ptmd_desc_type_node; ! 248: #if 0 ! 249: /* Not needed yet? May be needed one day? */ ! 250: tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type; ! 251: tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type; ! 252: tree __ptmf_desc_array_type, __ptmd_desc_array_type; ! 253: #endif ! 254: 1.1 root 255: tree class_star_type_node; 256: tree class_type_node, record_type_node, union_type_node, enum_type_node; 1.1.1.2 ! root 257: tree unknown_type_node; 1.1 root 258: tree opaque_type_node, signature_type_node; 259: tree sigtable_entry_type; 260: tree maybe_gc_cleanup; 261: 262: /* Array type `vtable_entry_type[]' */ 263: tree vtbl_type_node; 264: 265: /* In a destructor, the point at which all derived class destroying 266: has been done, just before any base class destroying will be done. */ 267: 268: tree dtor_label; 269: 270: /* In a constructor, the point at which we are ready to return 271: the pointer to the initialized object. */ 272: 273: tree ctor_label; 274: 275: /* A FUNCTION_DECL which can call `abort'. Not necessarily the 276: one that the user will declare, but sufficient to be called 277: by routines that want to abort the program. */ 278: 279: tree abort_fndecl; 280: 281: extern rtx cleanup_label, return_label; 282: 283: /* If original DECL_RESULT of current function was a register, 284: but due to being an addressable named return value, would up 285: on the stack, this variable holds the named return value's 286: original location. */ 287: rtx original_result_rtx; 288: 289: /* Sequence of insns which represents base initialization. */ 1.1.1.2 ! root 290: tree base_init_expr; 1.1 root 291: 292: /* C++: Keep these around to reduce calls to `get_identifier'. 293: Identifiers for `this' in member functions and the auto-delete 294: parameter for destructors. */ 295: tree this_identifier, in_charge_identifier; 1.1.1.2 ! root 296: /* Used in pointer to member functions, in vtables, and in sigtables. */ 1.1 root 297: tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; 1.1.1.2 ! root 298: tree pfn_or_delta2_identifier, tag_identifier; ! 299: tree vb_off_identifier, vt_off_identifier; 1.1 root 300: 301: /* A list (chain of TREE_LIST nodes) of named label uses. 302: The TREE_PURPOSE field is the list of variables defined 303: the the label's scope defined at the point of use. 304: The TREE_VALUE field is the LABEL_DECL used. 305: The TREE_TYPE field holds `current_binding_level' at the 306: point of the label's use. 307: 308: Used only for jumps to as-yet undefined labels, since 309: jumps to defined labels can have their validity checked 310: by stmt.c. */ 311: 312: static tree named_label_uses; 313: 314: /* A list of objects which have constructors or destructors 315: which reside in the global scope. The decl is stored in 316: the TREE_VALUE slot and the initializer is stored 317: in the TREE_PURPOSE slot. */ 318: tree static_aggregates; 319: 320: /* -- end of C++ */ 321: 322: /* Two expressions that are constants with value zero. 323: The first is of type `int', the second of type `void *'. */ 324: 325: tree integer_zero_node; 326: tree null_pointer_node; 327: 328: /* A node for the integer constants 1, 2, and 3. */ 329: 330: tree integer_one_node, integer_two_node, integer_three_node; 331: 332: /* Nonzero if we have seen an invalid cross reference 333: to a struct, union, or enum, but not yet printed the message. */ 334: 335: tree pending_invalid_xref; 336: /* File and line to appear in the eventual error message. */ 337: char *pending_invalid_xref_file; 338: int pending_invalid_xref_line; 339: 340: /* While defining an enum type, this is 1 plus the last enumerator 341: constant value. */ 342: 343: static tree enum_next_value; 344: 345: /* Nonzero means that there was overflow computing enum_next_value. */ 346: 347: static int enum_overflow; 348: 349: /* Parsing a function declarator leaves a list of parameter names 350: or a chain or parameter decls here. */ 351: 352: tree last_function_parms; 353: 354: /* Parsing a function declarator leaves here a chain of structure 355: and enum types declared in the parmlist. */ 356: 357: static tree last_function_parm_tags; 358: 359: /* After parsing the declarator that starts a function definition, 360: `start_function' puts here the list of parameter names or chain of decls. 361: `store_parm_decls' finds it here. */ 362: 363: static tree current_function_parms; 364: 365: /* Similar, for last_function_parm_tags. */ 366: static tree current_function_parm_tags; 367: 368: /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function 369: that have names. Here so we can clear out their names' definitions 370: at the end of the function. */ 371: 372: static tree named_labels; 373: 374: /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ 375: 376: static tree shadowed_labels; 377: 378: #if 0 /* Not needed by C++ */ 379: /* Nonzero when store_parm_decls is called indicates a varargs function. 380: Value not meaningful after store_parm_decls. */ 381: 382: static int c_function_varargs; 383: #endif 384: 385: /* The FUNCTION_DECL for the function currently being compiled, 386: or 0 if between functions. */ 387: tree current_function_decl; 388: 389: /* Set to 0 at beginning of a function definition, set to 1 if 390: a return statement that specifies a return value is seen. */ 391: 392: int current_function_returns_value; 393: 394: /* Set to 0 at beginning of a function definition, set to 1 if 395: a return statement with no argument is seen. */ 396: 397: int current_function_returns_null; 398: 399: /* Set to 0 at beginning of a function definition, and whenever 400: a label (case or named) is defined. Set to value of expression 401: returned from function when that value can be transformed into 402: a named return value. */ 403: 404: tree current_function_return_value; 405: 406: /* Set to nonzero by `grokdeclarator' for a function 407: whose return type is defaulted, if warnings for this are desired. */ 408: 409: static int warn_about_return_type; 410: 411: /* Nonzero means give `double' the same size as `float'. */ 412: 413: extern int flag_short_double; 414: 415: /* Nonzero means don't recognize any builtin functions. */ 416: 417: extern int flag_no_builtin; 418: 419: /* Nonzero means don't recognize the non-ANSI builtin functions. 420: -ansi sets this. */ 421: 422: extern int flag_no_nonansi_builtin; 423: 1.1.1.2 ! root 424: /* Nonzero means enable obscure ANSI features and disable GNU extensions ! 425: that might cause ANSI-compliant code to be miscompiled. */ 1.1 root 426: 427: extern int flag_ansi; 428: 429: /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) 430: objects. */ 431: extern int flag_huge_objects; 432: 433: /* Nonzero if we want to conserve space in the .o files. We do this 434: by putting uninitialized data and runtime initialized data into 1.1.1.2 ! root 435: .common instead of .data at the expense of not flagging multiple 1.1 root 436: definitions. */ 437: extern int flag_conserve_space; 438: 439: /* Pointers to the base and current top of the language name stack. */ 440: 441: extern tree *current_lang_base, *current_lang_stack; 442: 443: /* C and C++ flags are in decl2.c. */ 444: 445: /* Set to 0 at beginning of a constructor, set to 1 446: if that function does an allocation before referencing its 447: instance variable. */ 448: int current_function_assigns_this; 449: int current_function_just_assigned_this; 450: 451: /* Set to 0 at beginning of a function. Set non-zero when 452: store_parm_decls is called. Don't call store_parm_decls 453: if this flag is non-zero! */ 454: int current_function_parms_stored; 455: 456: /* Current end of entries in the gc obstack for stack pointer variables. */ 457: 458: int current_function_obstack_index; 459: 460: /* Flag saying whether we have used the obstack in this function or not. */ 461: 462: int current_function_obstack_usage; 463: 464: /* Flag used when debugging spew.c */ 465: 466: extern int spew_debug; 467: 468: /* This is a copy of the class_shadowed list of the previous class binding 469: contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs 470: when entering another class scope (i.e. a cache miss). */ 471: extern tree previous_class_values; 472: 473: 474: /* Allocate a level of searching. */ 475: struct stack_level * 476: push_decl_level (stack, obstack) 477: struct stack_level *stack; 478: struct obstack *obstack; 479: { 480: struct stack_level tem; 481: tem.prev = stack; 482: 483: return push_stack_level (obstack, (char *)&tem, sizeof (tem)); 484: } 485: 486: /* For each binding contour we allocate a binding_level structure 487: * which records the names defined in that contour. 488: * Contours include: 489: * 0) the global one 490: * 1) one for each function definition, 491: * where internal declarations of the parameters appear. 492: * 2) one for each compound statement, 493: * to record its declarations. 494: * 495: * The current meaning of a name can be found by searching the levels from 496: * the current one out to the global one. 497: * 498: * Off to the side, may be the class_binding_level. This exists 499: * only to catch class-local declarations. It is otherwise 500: * nonexistent. 501: * 502: * Also there may be binding levels that catch cleanups that 503: * must be run when exceptions occur. 504: */ 505: 506: /* Note that the information in the `names' component of the global contour 507: is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ 508: 509: struct binding_level 510: { 511: /* A chain of _DECL nodes for all variables, constants, functions, 512: * and typedef types. These are in the reverse of the order supplied. 513: */ 514: tree names; 515: 516: /* A list of structure, union and enum definitions, 517: * for looking up tag names. 518: * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, 519: * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, 520: * or ENUMERAL_TYPE node. 521: * 522: * C++: the TREE_VALUE nodes can be simple types for component_bindings. 523: * 524: */ 525: tree tags; 526: 527: /* For each level, a list of shadowed outer-level local definitions 528: to be restored when this level is popped. 529: Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and 530: whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ 531: tree shadowed; 532: 533: /* Same, for IDENTIFIER_CLASS_VALUE. */ 534: tree class_shadowed; 535: 536: /* Same, for IDENTIFIER_TYPE_VALUE. */ 537: tree type_shadowed; 538: 539: /* For each level (except not the global one), 540: a chain of BLOCK nodes for all the levels 541: that were entered and exited one level down. */ 542: tree blocks; 543: 544: /* The BLOCK node for this level, if one has been preallocated. 545: If 0, the BLOCK is allocated (if needed) when the level is popped. */ 546: tree this_block; 547: 548: /* The binding level which this one is contained in (inherits from). */ 549: struct binding_level *level_chain; 550: 1.1.1.2 ! root 551: /* List of decls in `names' that have incomplete 1.1 root 552: structure or union types. */ 1.1.1.2 ! root 553: tree incomplete; ! 554: ! 555: /* List of VAR_DECLS saved from a previous for statement. ! 556: These would be dead in ANSI-conforming code, but might ! 557: be referenced in traditional code. */ ! 558: tree dead_vars_from_for; 1.1 root 559: 560: /* 1 for the level that holds the parameters of a function. 561: 2 for the level that holds a class declaration. 562: 3 for levels that hold parameter declarations. */ 563: unsigned parm_flag : 4; 564: 565: /* 1 means make a BLOCK for this level regardless of all else. 566: 2 for temporary binding contours created by the compiler. */ 567: unsigned keep : 3; 568: 569: /* Nonzero if this level "doesn't exist" for tags. */ 570: unsigned tag_transparent : 1; 571: 572: /* Nonzero if this level can safely have additional 573: cleanup-needing variables added to it. */ 574: unsigned more_cleanups_ok : 1; 575: unsigned have_cleanups : 1; 576: 577: /* Nonzero if we should accept any name as an identifier in 578: this scope. This happens in some template definitions. */ 579: unsigned accept_any : 1; 580: 581: /* Nonzero if this level is for completing a template class definition 582: inside a binding level that temporarily binds the parameters. This 583: means that definitions here should not be popped off when unwinding 584: this binding level. (Not actually implemented this way, 585: unfortunately.) */ 586: unsigned pseudo_global : 1; 587: 1.1.1.2 ! root 588: /* This is set for a namespace binding level. */ ! 589: unsigned namespace_p : 1; ! 590: ! 591: /* True if this level is that of a for-statement. */ ! 592: unsigned is_for_scope : 1; ! 593: ! 594: /* One bit left for this word. */ 1.1 root 595: 596: #if defined(DEBUG_CP_BINDING_LEVELS) 597: /* Binding depth at which this level began. */ 598: unsigned binding_depth; 599: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 600: }; 601: 602: #define NULL_BINDING_LEVEL ((struct binding_level *) NULL) 603: 604: /* The (non-class) binding level currently in effect. */ 605: 606: static struct binding_level *current_binding_level; 607: 608: /* The binding level of the current class, if any. */ 609: 610: static struct binding_level *class_binding_level; 611: 612: /* The current (class or non-class) binding level currently in effect. */ 613: 614: #define inner_binding_level \ 615: (class_binding_level ? class_binding_level : current_binding_level) 616: 617: /* A chain of binding_level structures awaiting reuse. */ 618: 619: static struct binding_level *free_binding_level; 620: 621: /* The outermost binding level, for names of file scope. 622: This is created when the compiler is started and exists 623: through the entire run. */ 624: 625: static struct binding_level *global_binding_level; 626: 627: /* Binding level structures are initialized by copying this one. */ 628: 629: static struct binding_level clear_binding_level; 630: 631: /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ 632: 633: static int keep_next_level_flag; 634: 635: #if defined(DEBUG_CP_BINDING_LEVELS) 636: static int binding_depth = 0; 637: static int is_class_level = 0; 638: 639: static void 640: indent () 641: { 642: register unsigned i; 643: 644: for (i = 0; i < binding_depth*2; i++) 645: putc (' ', stderr); 646: } 647: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 648: 649: static tree pushdecl_with_scope PROTO((tree, struct binding_level *)); 650: 651: static void 652: push_binding_level (newlevel, tag_transparent, keep) 653: struct binding_level *newlevel; 654: int tag_transparent, keep; 655: { 656: /* Add this level to the front of the chain (stack) of levels that 657: are active. */ 658: *newlevel = clear_binding_level; 659: if (class_binding_level) 660: { 661: newlevel->level_chain = class_binding_level; 662: class_binding_level = (struct binding_level *)0; 663: } 664: else 665: { 666: newlevel->level_chain = current_binding_level; 667: } 668: current_binding_level = newlevel; 669: newlevel->tag_transparent = tag_transparent; 670: newlevel->more_cleanups_ok = 1; 671: newlevel->keep = keep; 672: #if defined(DEBUG_CP_BINDING_LEVELS) 673: newlevel->binding_depth = binding_depth; 674: indent (); 675: fprintf (stderr, "push %s level 0x%08x line %d\n", 676: (is_class_level) ? "class" : "block", newlevel, lineno); 677: is_class_level = 0; 678: binding_depth++; 679: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 680: } 681: 682: static void 683: pop_binding_level () 684: { 685: if (class_binding_level) 686: current_binding_level = class_binding_level; 687: 688: if (global_binding_level) 689: { 690: /* cannot pop a level, if there are none left to pop. */ 691: if (current_binding_level == global_binding_level) 692: my_friendly_abort (123); 693: } 694: /* Pop the current level, and free the structure for reuse. */ 695: #if defined(DEBUG_CP_BINDING_LEVELS) 696: binding_depth--; 697: indent (); 698: fprintf (stderr, "pop %s level 0x%08x line %d\n", 699: (is_class_level) ? "class" : "block", 700: current_binding_level, lineno); 701: if (is_class_level != (current_binding_level == class_binding_level)) 702: #if 0 /* XXX Don't abort when we're watching how things are being managed. */ 703: abort (); 704: #else 705: { 706: indent (); 707: fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); 708: } 709: #endif 710: is_class_level = 0; 711: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 712: { 713: register struct binding_level *level = current_binding_level; 714: current_binding_level = current_binding_level->level_chain; 715: level->level_chain = free_binding_level; 716: #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ 717: if (level->binding_depth != binding_depth) 718: abort (); 719: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 720: free_binding_level = level; 721: 722: class_binding_level = current_binding_level; 723: if (class_binding_level->parm_flag != 2) 724: class_binding_level = 0; 725: while (current_binding_level->parm_flag == 2) 726: current_binding_level = current_binding_level->level_chain; 727: } 728: } 1.1.1.2 ! root 729: ! 730: static void ! 731: suspend_binding_level () ! 732: { ! 733: if (class_binding_level) ! 734: current_binding_level = class_binding_level; ! 735: ! 736: if (global_binding_level) ! 737: { ! 738: /* cannot suspend a level, if there are none left to suspend. */ ! 739: if (current_binding_level == global_binding_level) ! 740: my_friendly_abort (123); ! 741: } ! 742: /* Suspend the current level. */ ! 743: #if defined(DEBUG_CP_BINDING_LEVELS) ! 744: binding_depth--; ! 745: indent (); ! 746: fprintf (stderr, "suspend %s level 0x%08x line %d\n", ! 747: (is_class_level) ? "class" : "block", ! 748: current_binding_level, lineno); ! 749: if (is_class_level != (current_binding_level == class_binding_level)) ! 750: #if 0 /* XXX Don't abort when we're watching how things are being managed. */ ! 751: abort (); ! 752: #else ! 753: { ! 754: indent (); ! 755: fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); ! 756: } ! 757: #endif ! 758: is_class_level = 0; ! 759: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ ! 760: { ! 761: register struct binding_level *level = current_binding_level; ! 762: current_binding_level = current_binding_level->level_chain; ! 763: #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ ! 764: if (level->binding_depth != binding_depth) ! 765: abort (); ! 766: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ ! 767: ! 768: class_binding_level = current_binding_level; ! 769: if (class_binding_level->parm_flag != 2) ! 770: class_binding_level = 0; ! 771: while (current_binding_level->parm_flag == 2) ! 772: current_binding_level = current_binding_level->level_chain; ! 773: } ! 774: } ! 775: ! 776: void ! 777: resume_binding_level (b) ! 778: struct binding_level *b; ! 779: { ! 780: if (class_binding_level) ! 781: { ! 782: #if 1 ! 783: /* These are here because we cannot deal with shadows yet. */ ! 784: sorry ("cannot resume a namespace inside class"); ! 785: return; ! 786: #else ! 787: b->level_chain = class_binding_level; ! 788: class_binding_level = (struct binding_level *)0; ! 789: #endif ! 790: } ! 791: else ! 792: { ! 793: #if 1 ! 794: /* These are here because we cannot deal with shadows yet. */ ! 795: if (b->level_chain != current_binding_level) ! 796: { ! 797: sorry ("cannot resume a namespace inside a different namespace"); ! 798: return; ! 799: } ! 800: #endif ! 801: b->level_chain = current_binding_level; ! 802: } ! 803: current_binding_level = b; ! 804: #if defined(DEBUG_CP_BINDING_LEVELS) ! 805: b->binding_depth = binding_depth; ! 806: indent (); ! 807: fprintf (stderr, "resume %s level 0x%08x line %d\n", ! 808: (is_class_level) ? "class" : "block", b, lineno); ! 809: is_class_level = 0; ! 810: binding_depth++; ! 811: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ ! 812: } 1.1 root 813: 814: /* Nonzero if we are currently in the global binding level. */ 815: 816: int 817: global_bindings_p () 818: { 819: return current_binding_level == global_binding_level; 820: } 821: 1.1.1.2 ! root 822: /* Nonzero if we are currently in a toplevel binding level. This ! 823: means either the global binding level or a namespace in a toplevel ! 824: binding level. */ ! 825: ! 826: int ! 827: toplevel_bindings_p () ! 828: { ! 829: struct binding_level *b = current_binding_level; ! 830: ! 831: while (1) ! 832: { ! 833: if (b == global_binding_level) ! 834: return 1; ! 835: if (! b->namespace_p) ! 836: return 0; ! 837: b=b->level_chain; ! 838: } ! 839: } ! 840: ! 841: /* Nonzero if this is a namespace scope. */ ! 842: ! 843: int ! 844: namespace_bindings_p () ! 845: { ! 846: return current_binding_level->namespace_p; ! 847: } ! 848: 1.1 root 849: void 850: keep_next_level () 851: { 852: keep_next_level_flag = 1; 853: } 854: 855: /* Nonzero if the current level needs to have a BLOCK made. */ 856: 857: int 858: kept_level_p () 859: { 860: return (current_binding_level->blocks != NULL_TREE 861: || current_binding_level->keep 862: || current_binding_level->names != NULL_TREE 863: || (current_binding_level->tags != NULL_TREE 864: && !current_binding_level->tag_transparent)); 865: } 866: 867: /* Identify this binding level as a level of parameters. */ 868: 869: void 870: declare_parm_level () 871: { 872: current_binding_level->parm_flag = 1; 873: } 874: 875: void 876: declare_uninstantiated_type_level () 877: { 878: current_binding_level->accept_any = 1; 879: } 880: 881: int 882: uninstantiated_type_level_p () 883: { 884: return current_binding_level->accept_any; 885: } 886: 887: void 888: declare_pseudo_global_level () 889: { 890: current_binding_level->pseudo_global = 1; 891: } 892: 1.1.1.2 ! root 893: void ! 894: declare_namespace_level () ! 895: { ! 896: current_binding_level->namespace_p = 1; ! 897: } ! 898: 1.1 root 899: int 900: pseudo_global_level_p () 901: { 902: return current_binding_level->pseudo_global; 903: } 904: 905: void 906: set_class_shadows (shadows) 907: tree shadows; 908: { 909: class_binding_level->class_shadowed = shadows; 910: } 911: 912: /* Enter a new binding level. 913: If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, 914: not for that of tags. */ 915: 916: void 917: pushlevel (tag_transparent) 918: int tag_transparent; 919: { 920: register struct binding_level *newlevel = NULL_BINDING_LEVEL; 921: 922: /* If this is the top level of a function, 923: just make sure that NAMED_LABELS is 0. 924: They should have been set to 0 at the end of the previous function. */ 925: 926: if (current_binding_level == global_binding_level) 927: my_friendly_assert (named_labels == NULL_TREE, 134); 928: 929: /* Reuse or create a struct for this binding level. */ 930: 931: #if defined(DEBUG_CP_BINDING_LEVELS) 932: if (0) 933: #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ 934: if (free_binding_level) 935: #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ 936: { 937: newlevel = free_binding_level; 938: free_binding_level = free_binding_level->level_chain; 939: } 940: else 941: { 942: /* Create a new `struct binding_level'. */ 943: newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); 944: } 945: push_binding_level (newlevel, tag_transparent, keep_next_level_flag); 946: GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); 947: keep_next_level_flag = 0; 948: } 949: 1.1.1.2 ! root 950: int ! 951: note_level_for_for () ! 952: { ! 953: current_binding_level->is_for_scope = 1; ! 954: } ! 955: 1.1 root 956: void 957: pushlevel_temporary (tag_transparent) 958: int tag_transparent; 959: { 960: pushlevel (tag_transparent); 961: current_binding_level->keep = 2; 962: clear_last_expr (); 963: 964: /* Note we don't call push_momentary() here. Otherwise, it would cause 965: cleanups to be allocated on the momentary obstack, and they will be 966: overwritten by the next statement. */ 967: 968: expand_start_bindings (0); 969: } 970: 971: /* Exit a binding level. 972: Pop the level off, and restore the state of the identifier-decl mappings 973: that were in effect when this level was entered. 974: 975: If KEEP == 1, this level had explicit declarations, so 976: and create a "block" (a BLOCK node) for the level 977: to record its declarations and subblocks for symbol table output. 978: 979: If KEEP == 2, this level's subblocks go to the front, 980: not the back of the current binding level. This happens, 981: for instance, when code for constructors and destructors 982: need to generate code at the end of a function which must 983: be moved up to the front of the function. 984: 985: If FUNCTIONBODY is nonzero, this level is the body of a function, 986: so create a block as if KEEP were set and also clear out all 987: label names. 988: 989: If REVERSE is nonzero, reverse the order of decls before putting 990: them into the BLOCK. */ 991: 992: tree 993: poplevel (keep, reverse, functionbody) 994: int keep; 995: int reverse; 996: int functionbody; 997: { 998: register tree link; 999: /* The chain of decls was accumulated in reverse order. 1000: Put it into forward order, just for cleanliness. */ 1001: tree decls; 1002: int tmp = functionbody; 1003: int implicit_try_block = current_binding_level->parm_flag == 3; 1004: int real_functionbody = current_binding_level->keep == 2 1005: ? ((functionbody = 0), tmp) : functionbody; 1006: tree tags = functionbody >= 0 ? current_binding_level->tags : 0; 1007: tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; 1008: tree block = NULL_TREE; 1009: tree decl; 1010: int block_previously_created; 1011: 1012: GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, 1013: (HOST_WIDE_INT) current_binding_level->level_chain, 1014: current_binding_level->parm_flag, 1015: current_binding_level->keep, 1016: current_binding_level->tag_transparent); 1017: 1018: if (current_binding_level->keep == 1) 1019: keep = 1; 1020: 1021: /* This warning is turned off because it causes warnings for 1022: declarations like `extern struct foo *x'. */ 1023: #if 0 1024: /* Warn about incomplete structure types in this level. */ 1025: for (link = tags; link; link = TREE_CHAIN (link)) 1026: if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE) 1027: { 1028: tree type = TREE_VALUE (link); 1029: char *errmsg; 1030: switch (TREE_CODE (type)) 1031: { 1032: case RECORD_TYPE: 1033: errmsg = "`struct %s' incomplete in scope ending here"; 1034: break; 1035: case UNION_TYPE: 1036: errmsg = "`union %s' incomplete in scope ending here"; 1037: break; 1038: case ENUMERAL_TYPE: 1039: errmsg = "`enum %s' incomplete in scope ending here"; 1040: break; 1041: } 1042: if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) 1043: error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type))); 1044: else 1045: /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ 1046: error (errmsg, TYPE_NAME_STRING (type)); 1047: } 1048: #endif /* 0 */ 1049: 1050: /* Get the decls in the order they were written. 1051: Usually current_binding_level->names is in reverse order. 1052: But parameter decls were previously put in forward order. */ 1053: 1054: if (reverse) 1055: current_binding_level->names 1056: = decls = nreverse (current_binding_level->names); 1057: else 1058: decls = current_binding_level->names; 1059: 1060: /* Output any nested inline functions within this block 1061: if they weren't already output. */ 1062: 1063: for (decl = decls; decl; decl = TREE_CHAIN (decl)) 1064: if (TREE_CODE (decl) == FUNCTION_DECL 1065: && ! TREE_ASM_WRITTEN (decl) 1066: && DECL_INITIAL (decl) != NULL_TREE 1.1.1.2 ! root 1067: && TREE_ADDRESSABLE (decl) ! 1068: && decl_function_context (decl) == current_function_decl) 1.1 root 1069: { 1070: /* If this decl was copied from a file-scope decl 1071: on account of a block-scope extern decl, 1072: propagate TREE_ADDRESSABLE to the file-scope decl. */ 1073: if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) 1074: TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; 1075: else 1076: { 1077: push_function_context (); 1078: output_inline_function (decl); 1079: pop_function_context (); 1080: } 1081: } 1082: 1083: /* If there were any declarations or structure tags in that level, 1084: or if this level is a function body, 1085: create a BLOCK to record them for the life of this function. */ 1086: 1087: block = NULL_TREE; 1088: block_previously_created = (current_binding_level->this_block != NULL_TREE); 1089: if (block_previously_created) 1090: block = current_binding_level->this_block; 1091: else if (keep == 1 || functionbody) 1092: block = make_node (BLOCK); 1093: if (block != NULL_TREE) 1094: { 1095: BLOCK_VARS (block) = decls; 1096: BLOCK_TYPE_TAGS (block) = tags; 1097: BLOCK_SUBBLOCKS (block) = subblocks; 1098: /* If we created the block earlier on, and we are just diddling it now, 1099: then it already should have a proper BLOCK_END_NOTE value associated 1100: with it, so avoid trashing that. Otherwise, for a new block, install 1101: a new BLOCK_END_NOTE value. */ 1102: if (! block_previously_created) 1103: remember_end_note (block); 1104: } 1105: 1106: /* In each subblock, record that this is its superior. */ 1107: 1108: if (keep >= 0) 1109: for (link = subblocks; link; link = TREE_CHAIN (link)) 1110: BLOCK_SUPERCONTEXT (link) = block; 1111: 1112: /* Clear out the meanings of the local variables of this level. */ 1113: 1.1.1.2 ! root 1114: for (link = current_binding_level->dead_vars_from_for; ! 1115: link != NULL_TREE; link = TREE_CHAIN (link)) 1.1 root 1116: { 1.1.1.2 ! root 1117: if (DECL_DEAD_FOR_LOCAL (link)) 1.1 root 1118: { 1.1.1.2 ! root 1119: tree id = DECL_NAME (link); ! 1120: if (IDENTIFIER_LOCAL_VALUE (id) == link) ! 1121: IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link); ! 1122: } ! 1123: } ! 1124: ! 1125: if (current_binding_level->is_for_scope && flag_new_for_scope == 1) ! 1126: { ! 1127: for (link = decls; link; link = TREE_CHAIN (link)) ! 1128: { ! 1129: if (TREE_CODE (link) == VAR_DECL) ! 1130: DECL_DEAD_FOR_LOCAL (link) = 1; ! 1131: } ! 1132: } ! 1133: else ! 1134: { ! 1135: for (link = decls; link; link = TREE_CHAIN (link)) ! 1136: { ! 1137: if (DECL_NAME (link) != NULL_TREE) 1.1 root 1138: { 1.1.1.2 ! root 1139: /* If the ident. was used or addressed via a local extern decl, ! 1140: don't forget that fact. */ ! 1141: if (DECL_EXTERNAL (link)) ! 1142: { ! 1143: if (TREE_USED (link)) ! 1144: TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; ! 1145: if (TREE_ADDRESSABLE (link)) ! 1146: TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; ! 1147: } ! 1148: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; 1.1 root 1149: } 1150: } 1151: } 1152: 1153: /* Restore all name-meanings of the outer levels 1154: that were shadowed by this level. */ 1155: 1.1.1.2 ! root 1156: if (current_binding_level->is_for_scope && flag_new_for_scope == 1) ! 1157: { ! 1158: struct binding_level *outer = current_binding_level->level_chain; ! 1159: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) ! 1160: { ! 1161: tree id = TREE_PURPOSE (link); ! 1162: tree decl = IDENTIFIER_LOCAL_VALUE (id); ! 1163: if (DECL_DEAD_FOR_LOCAL (decl)) ! 1164: DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link); ! 1165: else ! 1166: IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link); ! 1167: } ! 1168: ! 1169: /* Save declarations made in a 'for' statement so we can support pre-ANSI ! 1170: 'for' scoping semantics. */ ! 1171: ! 1172: /* We append the current names of for-variables to those from previous ! 1173: declarations, so that when we get around to do an poplevel ! 1174: on the OUTER level, we restore the any shadowed readl bindings. ! 1175: Note that the new names are put first on the combined list, ! 1176: so they get to be restored first. This is important if there are ! 1177: two for-loops using the same for-variable in the same block. ! 1178: The binding we really want restored is whatever binding was shadowed ! 1179: by the *first* for-variable, not the binding shadowed by the ! 1180: second for-variable (which would be the first for-variable). */ ! 1181: outer->dead_vars_from_for ! 1182: = chainon (current_binding_level->names, outer->dead_vars_from_for); ! 1183: } ! 1184: else ! 1185: { ! 1186: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) ! 1187: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); ! 1188: } 1.1 root 1189: for (link = current_binding_level->class_shadowed; 1190: link; link = TREE_CHAIN (link)) 1191: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 1192: for (link = current_binding_level->type_shadowed; 1193: link; link = TREE_CHAIN (link)) 1194: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 1195: 1196: /* If the level being exited is the top level of a function, 1197: check over all the labels. */ 1198: 1199: if (functionbody) 1200: { 1201: /* If this is the top level block of a function, 1202: the vars are the function's parameters. 1203: Don't leave them in the BLOCK because they are 1204: found in the FUNCTION_DECL instead. */ 1205: 1206: BLOCK_VARS (block) = 0; 1207: 1208: /* Clear out the definitions of all label names, 1209: since their scopes end here. */ 1210: 1211: for (link = named_labels; link; link = TREE_CHAIN (link)) 1212: { 1213: register tree label = TREE_VALUE (link); 1214: 1215: if (DECL_INITIAL (label) == NULL_TREE) 1216: { 1217: cp_error_at ("label `%D' used but not defined", label); 1218: /* Avoid crashing later. */ 1219: define_label (input_filename, 1, DECL_NAME (label)); 1220: } 1221: else if (warn_unused && !TREE_USED (label)) 1222: cp_warning_at ("label `%D' defined but not used", label); 1223: SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE); 1224: 1225: /* Put the labels into the "variables" of the 1226: top-level block, so debugger can see them. */ 1227: TREE_CHAIN (label) = BLOCK_VARS (block); 1228: BLOCK_VARS (block) = label; 1229: } 1230: 1231: named_labels = NULL_TREE; 1232: } 1233: 1234: /* Any uses of undefined labels now operate under constraints 1235: of next binding contour. */ 1236: { 1237: struct binding_level *level_chain; 1238: level_chain = current_binding_level->level_chain; 1239: if (level_chain) 1240: { 1241: tree labels; 1242: for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels)) 1243: if (TREE_TYPE (labels) == (tree)current_binding_level) 1244: { 1245: TREE_TYPE (labels) = (tree)level_chain; 1246: TREE_PURPOSE (labels) = level_chain->names; 1247: } 1248: } 1249: } 1250: 1251: tmp = current_binding_level->keep; 1252: 1253: pop_binding_level (); 1254: if (functionbody) 1255: DECL_INITIAL (current_function_decl) = block; 1256: else if (block) 1257: { 1258: if (!block_previously_created) 1259: current_binding_level->blocks 1260: = chainon (current_binding_level->blocks, block); 1261: } 1262: /* If we did not make a block for the level just exited, 1263: any blocks made for inner levels 1264: (since they cannot be recorded as subblocks in that level) 1265: must be carried forward so they will later become subblocks 1266: of something else. */ 1267: else if (subblocks) 1268: { 1269: if (keep == 2) 1270: current_binding_level->blocks 1271: = chainon (subblocks, current_binding_level->blocks); 1272: else 1273: current_binding_level->blocks 1274: = chainon (current_binding_level->blocks, subblocks); 1275: } 1276: 1277: /* Take care of compiler's internal binding structures. */ 1278: if (tmp == 2) 1279: { 1280: #if 0 1281: /* We did not call push_momentary for this 1282: binding contour, so there is nothing to pop. */ 1283: pop_momentary (); 1284: #endif 1285: expand_end_bindings (getdecls (), keep, 1); 1286: /* Each and every BLOCK node created here in `poplevel' is important 1287: (e.g. for proper debugging information) so if we created one 1288: earlier, mark it as "used". */ 1289: if (block) 1290: TREE_USED (block) = 1; 1291: block = poplevel (keep, reverse, real_functionbody); 1292: } 1293: 1294: /* Each and every BLOCK node created here in `poplevel' is important 1295: (e.g. for proper debugging information) so if we created one 1296: earlier, mark it as "used". */ 1297: if (block) 1298: TREE_USED (block) = 1; 1299: return block; 1300: } 1301: 1.1.1.2 ! root 1302: /* Resume a binding level for a namespace. */ ! 1303: void ! 1304: resume_level (b) ! 1305: struct binding_level *b; ! 1306: { ! 1307: tree decls, link; ! 1308: ! 1309: resume_binding_level (b); ! 1310: ! 1311: /* Resume the variable caches. */ ! 1312: decls = current_binding_level->names; ! 1313: ! 1314: /* Restore the meanings of the local variables of this level. */ ! 1315: ! 1316: for (link = decls; link; link = TREE_CHAIN (link)) ! 1317: { ! 1318: if (DECL_NAME (link) != NULL_TREE) ! 1319: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link; ! 1320: ! 1321: /* If this is a TYPE_DECL, push it into the type value slot. */ ! 1322: if (TREE_CODE (link) == TYPE_DECL) ! 1323: SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link)); ! 1324: } ! 1325: } ! 1326: 1.1 root 1327: /* Delete the node BLOCK from the current binding level. 1328: This is used for the block inside a stmt expr ({...}) 1329: so that the block can be reinserted where appropriate. */ 1330: 1331: void 1332: delete_block (block) 1333: tree block; 1334: { 1335: tree t; 1336: if (current_binding_level->blocks == block) 1337: current_binding_level->blocks = TREE_CHAIN (block); 1338: for (t = current_binding_level->blocks; t;) 1339: { 1340: if (TREE_CHAIN (t) == block) 1341: TREE_CHAIN (t) = TREE_CHAIN (block); 1342: else 1343: t = TREE_CHAIN (t); 1344: } 1345: TREE_CHAIN (block) = NULL_TREE; 1346: /* Clear TREE_USED which is always set by poplevel. 1347: The flag is set again if insert_block is called. */ 1348: TREE_USED (block) = 0; 1349: } 1350: 1351: /* Insert BLOCK at the end of the list of subblocks of the 1352: current binding level. This is used when a BIND_EXPR is expanded, 1353: to handle the BLOCK node inside the BIND_EXPR. */ 1354: 1355: void 1356: insert_block (block) 1357: tree block; 1358: { 1359: TREE_USED (block) = 1; 1360: current_binding_level->blocks 1361: = chainon (current_binding_level->blocks, block); 1362: } 1363: 1364: /* Add BLOCK to the current list of blocks for this binding contour. */ 1365: void 1366: add_block_current_level (block) 1367: tree block; 1368: { 1369: current_binding_level->blocks 1370: = chainon (current_binding_level->blocks, block); 1371: } 1372: 1373: /* Set the BLOCK node for the innermost scope 1374: (the one we are currently in). */ 1375: 1376: void 1377: set_block (block) 1378: register tree block; 1379: { 1380: current_binding_level->this_block = block; 1381: } 1382: 1383: /* Do a pushlevel for class declarations. */ 1384: void 1385: pushlevel_class () 1386: { 1387: register struct binding_level *newlevel; 1388: 1389: /* Reuse or create a struct for this binding level. */ 1390: #if defined(DEBUG_CP_BINDING_LEVELS) 1391: if (0) 1392: #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ 1393: if (free_binding_level) 1394: #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ 1395: { 1396: newlevel = free_binding_level; 1397: free_binding_level = free_binding_level->level_chain; 1398: } 1399: else 1400: { 1401: /* Create a new `struct binding_level'. */ 1402: newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); 1403: } 1404: 1405: #if defined(DEBUG_CP_BINDING_LEVELS) 1406: is_class_level = 1; 1407: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 1408: 1409: push_binding_level (newlevel, 0, 0); 1410: 1411: decl_stack = push_decl_level (decl_stack, &decl_obstack); 1412: class_binding_level = current_binding_level; 1413: class_binding_level->parm_flag = 2; 1414: /* We have just pushed into a new binding level. Now, fake out the rest 1415: of the compiler. Set the `current_binding_level' back to point to 1416: the most closely containing non-class binding level. */ 1417: do 1418: { 1419: current_binding_level = current_binding_level->level_chain; 1420: } 1421: while (current_binding_level->parm_flag == 2); 1422: } 1423: 1424: /* ...and a poplevel for class declarations. FORCE is used to force 1425: clearing out of CLASS_VALUEs after a class definition. */ 1426: tree 1427: poplevel_class (force) 1428: int force; 1429: { 1430: register struct binding_level *level = class_binding_level; 1431: tree block = NULL_TREE; 1432: tree shadowed; 1433: 1434: my_friendly_assert (level != 0, 354); 1435: 1436: decl_stack = pop_stack_level (decl_stack); 1437: for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) 1438: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); 1439: /* If we're leaving a toplevel class, don't bother to do the setting 1.1.1.2 ! root 1440: of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot 1.1 root 1441: shouldn't even be used when current_class_type isn't set, and second, 1.1.1.2 ! root 1442: if we don't touch it here, we're able to use the cache effect if the 1.1 root 1443: next time we're entering a class scope, it is the same class. */ 1444: if (current_class_depth != 1 || force) 1445: for (shadowed = level->class_shadowed; 1446: shadowed; 1447: shadowed = TREE_CHAIN (shadowed)) 1448: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); 1449: else 1450: /* Remember to save what IDENTIFIER's were bound in this scope so we 1451: can recover from cache misses. */ 1452: previous_class_values = class_binding_level->class_shadowed; 1453: for (shadowed = level->type_shadowed; 1454: shadowed; 1455: shadowed = TREE_CHAIN (shadowed)) 1456: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); 1457: 1458: GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, 1459: (HOST_WIDE_INT) class_binding_level->level_chain, 1460: class_binding_level->parm_flag, 1461: class_binding_level->keep, 1462: class_binding_level->tag_transparent); 1463: 1464: if (class_binding_level->parm_flag != 2) 1465: class_binding_level = (struct binding_level *)0; 1466: 1467: /* Now, pop out of the the binding level which we created up in the 1468: `pushlevel_class' routine. */ 1469: #if defined(DEBUG_CP_BINDING_LEVELS) 1470: is_class_level = 1; 1471: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 1472: 1473: pop_binding_level (); 1474: 1475: return block; 1476: } 1477: 1478: /* For debugging. */ 1479: int no_print_functions = 0; 1480: int no_print_builtins = 0; 1481: 1482: void 1483: print_binding_level (lvl) 1484: struct binding_level *lvl; 1485: { 1486: tree t; 1487: int i = 0, len; 1488: fprintf (stderr, " blocks="); 1489: fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks); 1490: fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d", 1.1.1.2 ! root 1491: list_length (lvl->incomplete), lvl->parm_flag, lvl->keep); 1.1 root 1492: if (lvl->tag_transparent) 1493: fprintf (stderr, " tag-transparent"); 1494: if (lvl->more_cleanups_ok) 1495: fprintf (stderr, " more-cleanups-ok"); 1496: if (lvl->have_cleanups) 1497: fprintf (stderr, " have-cleanups"); 1498: fprintf (stderr, "\n"); 1499: if (lvl->names) 1500: { 1501: fprintf (stderr, " names:\t"); 1502: /* We can probably fit 3 names to a line? */ 1503: for (t = lvl->names; t; t = TREE_CHAIN (t)) 1504: { 1505: if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) 1506: continue; 1507: if (no_print_builtins 1508: && (TREE_CODE(t) == TYPE_DECL) 1509: && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>"))) 1510: continue; 1511: 1512: /* Function decls tend to have longer names. */ 1513: if (TREE_CODE (t) == FUNCTION_DECL) 1514: len = 3; 1515: else 1516: len = 2; 1517: i += len; 1518: if (i > 6) 1519: { 1520: fprintf (stderr, "\n\t"); 1521: i = len; 1522: } 1523: print_node_brief (stderr, "", t, 0); 1524: if (TREE_CODE (t) == ERROR_MARK) 1525: break; 1526: } 1527: if (i) 1528: fprintf (stderr, "\n"); 1529: } 1530: if (lvl->tags) 1531: { 1532: fprintf (stderr, " tags:\t"); 1533: i = 0; 1534: for (t = lvl->tags; t; t = TREE_CHAIN (t)) 1535: { 1536: if (TREE_PURPOSE (t) == NULL_TREE) 1537: len = 3; 1538: else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) 1539: len = 2; 1540: else 1541: len = 4; 1542: i += len; 1543: if (i > 5) 1544: { 1545: fprintf (stderr, "\n\t"); 1546: i = len; 1547: } 1548: if (TREE_PURPOSE (t) == NULL_TREE) 1549: { 1550: print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0); 1551: fprintf (stderr, ">"); 1552: } 1553: else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) 1554: print_node_brief (stderr, "", TREE_VALUE (t), 0); 1555: else 1556: { 1557: print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0); 1558: print_node_brief (stderr, "", TREE_VALUE (t), 0); 1559: fprintf (stderr, ">"); 1560: } 1561: } 1562: if (i) 1563: fprintf (stderr, "\n"); 1564: } 1565: if (lvl->shadowed) 1566: { 1567: fprintf (stderr, " shadowed:"); 1568: for (t = lvl->shadowed; t; t = TREE_CHAIN (t)) 1569: { 1570: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); 1571: } 1572: fprintf (stderr, "\n"); 1573: } 1574: if (lvl->class_shadowed) 1575: { 1576: fprintf (stderr, " class-shadowed:"); 1577: for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t)) 1578: { 1579: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); 1580: } 1581: fprintf (stderr, "\n"); 1582: } 1583: if (lvl->type_shadowed) 1584: { 1585: fprintf (stderr, " type-shadowed:"); 1586: for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) 1587: { 1588: #if 0 1589: fprintf (stderr, "\n\t"); 1590: print_node_brief (stderr, "<", TREE_PURPOSE (t), 0); 1591: if (TREE_VALUE (t)) 1592: print_node_brief (stderr, " ", TREE_VALUE (t), 0); 1593: else 1594: fprintf (stderr, " (none)"); 1595: fprintf (stderr, ">"); 1596: #else 1597: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); 1598: #endif 1599: } 1600: fprintf (stderr, "\n"); 1601: } 1602: } 1603: 1604: void 1605: print_other_binding_stack (stack) 1606: struct binding_level *stack; 1607: { 1608: struct binding_level *level; 1609: for (level = stack; level != global_binding_level; level = level->level_chain) 1610: { 1611: fprintf (stderr, "binding level "); 1612: fprintf (stderr, HOST_PTR_PRINTF, level); 1613: fprintf (stderr, "\n"); 1614: print_binding_level (level); 1615: } 1616: } 1617: 1618: void 1619: print_binding_stack () 1620: { 1621: struct binding_level *b; 1622: fprintf (stderr, "current_binding_level="); 1623: fprintf (stderr, HOST_PTR_PRINTF, current_binding_level); 1624: fprintf (stderr, "\nclass_binding_level="); 1625: fprintf (stderr, HOST_PTR_PRINTF, class_binding_level); 1626: fprintf (stderr, "\nglobal_binding_level="); 1627: fprintf (stderr, HOST_PTR_PRINTF, global_binding_level); 1628: fprintf (stderr, "\n"); 1629: if (class_binding_level) 1630: { 1631: for (b = class_binding_level; b; b = b->level_chain) 1632: if (b == current_binding_level) 1633: break; 1634: if (b) 1635: b = class_binding_level; 1636: else 1637: b = current_binding_level; 1638: } 1639: else 1640: b = current_binding_level; 1641: print_other_binding_stack (b); 1642: fprintf (stderr, "global:\n"); 1643: print_binding_level (global_binding_level); 1644: } 1.1.1.2 ! root 1645: ! 1646: extern char * first_global_object_name; ! 1647: ! 1648: /* Get a unique name for each call to this routine for unnamed namespaces. ! 1649: Mostly copied from get_file_function_name. */ ! 1650: static tree ! 1651: get_unique_name () ! 1652: { ! 1653: static int temp_name_counter = 0; ! 1654: char *buf; ! 1655: register char *p; ! 1656: ! 1657: if (first_global_object_name) ! 1658: p = first_global_object_name; ! 1659: else if (main_input_filename) ! 1660: p = main_input_filename; ! 1661: else ! 1662: p = input_filename; ! 1663: ! 1664: #define UNNAMED_NAMESPACE_FORMAT "__%s_%d" ! 1665: ! 1666: buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p)); ! 1667: ! 1668: sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++); ! 1669: ! 1670: /* Don't need to pull weird characters out of global names. */ ! 1671: if (p != first_global_object_name) ! 1672: { ! 1673: for (p = buf+11; *p; p++) ! 1674: if (! ((*p >= '0' && *p <= '9') ! 1675: #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */ ! 1676: #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */ ! 1677: || *p == '.' ! 1678: #endif ! 1679: #endif ! 1680: #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ ! 1681: || *p == '$' ! 1682: #endif ! 1683: #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ ! 1684: || *p == '.' ! 1685: #endif ! 1686: || (*p >= 'A' && *p <= 'Z') ! 1687: || (*p >= 'a' && *p <= 'z'))) ! 1688: *p = '_'; ! 1689: } ! 1690: ! 1691: return get_identifier (buf); ! 1692: } ! 1693: ! 1694: /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we ! 1695: select a name that is unique to this compilation unit. */ ! 1696: void ! 1697: push_namespace (name) ! 1698: tree name; ! 1699: { ! 1700: extern tree current_namespace; ! 1701: tree old_id = get_namespace_id (); ! 1702: char *buf; ! 1703: tree d = make_node (NAMESPACE_DECL); ! 1704: ! 1705: if (! name) ! 1706: { ! 1707: /* Create a truly ugly name! */ ! 1708: name = get_unique_name (); ! 1709: } ! 1710: ! 1711: DECL_NAME (d) = name; ! 1712: DECL_ASSEMBLER_NAME (d) = name; ! 1713: /* pushdecl wants to check the size of it to see if it is incomplete... */ ! 1714: TREE_TYPE (d) = void_type_node; ! 1715: /* Mark them as external, so redeclaration_error_message doesn't think ! 1716: they are duplicates. */ ! 1717: DECL_EXTERNAL (d) = 1; ! 1718: d = pushdecl (d); ! 1719: ! 1720: if (NAMESPACE_LEVEL (d) == 0) ! 1721: { ! 1722: /* This is new for this compilation unit. */ ! 1723: pushlevel (0); ! 1724: declare_namespace_level (); ! 1725: NAMESPACE_LEVEL (d) = (tree)current_binding_level; ! 1726: } ! 1727: else ! 1728: { ! 1729: resume_level ((struct binding_level*)NAMESPACE_LEVEL (d)); ! 1730: } ! 1731: ! 1732: /* This code is just is bit old now... */ ! 1733: current_namespace = tree_cons (NULL_TREE, name, current_namespace); ! 1734: buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0) ! 1735: + IDENTIFIER_LENGTH (name)); ! 1736: sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "", ! 1737: IDENTIFIER_POINTER (name)); ! 1738: TREE_PURPOSE (current_namespace) = get_identifier (buf); ! 1739: } ! 1740: ! 1741: /* Pop from the scope of the current namespace. */ ! 1742: void ! 1743: pop_namespace () ! 1744: { ! 1745: extern tree current_namespace; ! 1746: tree decls, link; ! 1747: current_namespace = TREE_CHAIN (current_namespace); ! 1748: ! 1749: /* Just in case we get out of sync. */ ! 1750: if (! namespace_bindings_p ()) ! 1751: poplevel (0, 0, 0); ! 1752: ! 1753: decls = current_binding_level->names; ! 1754: ! 1755: /* Clear out the meanings of the local variables of this level. */ ! 1756: ! 1757: for (link = decls; link; link = TREE_CHAIN (link)) ! 1758: { ! 1759: if (DECL_NAME (link) != NULL_TREE) ! 1760: { ! 1761: /* If the ident. was used or addressed via a local extern decl, ! 1762: don't forget that fact. */ ! 1763: if (DECL_EXTERNAL (link)) ! 1764: { ! 1765: if (TREE_USED (link)) ! 1766: TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; ! 1767: if (TREE_ADDRESSABLE (link)) ! 1768: TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; ! 1769: } ! 1770: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; ! 1771: } ! 1772: } ! 1773: ! 1774: /* Restore all name-meanings of the outer levels ! 1775: that were shadowed by this level. */ ! 1776: ! 1777: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) ! 1778: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); ! 1779: for (link = current_binding_level->class_shadowed; ! 1780: link; link = TREE_CHAIN (link)) ! 1781: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); ! 1782: for (link = current_binding_level->type_shadowed; ! 1783: link; link = TREE_CHAIN (link)) ! 1784: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); ! 1785: ! 1786: /* suspend a level. */ ! 1787: suspend_binding_level (); ! 1788: } 1.1 root 1789: 1790: /* Subroutines for reverting temporarily to top-level for instantiation 1791: of templates and such. We actually need to clear out the class- and 1792: local-value slots of all identifiers, so that only the global values 1793: are at all visible. Simply setting current_binding_level to the global 1794: scope isn't enough, because more binding levels may be pushed. */ 1795: struct saved_scope { 1796: struct binding_level *old_binding_level; 1797: tree old_bindings; 1798: struct saved_scope *prev; 1.1.1.2 ! root 1799: tree class_name, class_type, function_decl; ! 1800: tree base_init_list, member_init_list; 1.1 root 1801: struct binding_level *class_bindings; 1802: tree previous_class_type; 1803: tree *lang_base, *lang_stack, lang_name; 1804: int lang_stacksize; 1805: tree named_labels; 1806: }; 1807: static struct saved_scope *current_saved_scope; 1808: extern tree prev_class_type; 1809: 1810: void 1811: push_to_top_level () 1812: { 1813: extern int current_lang_stacksize; 1814: struct saved_scope *s = 1815: (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); 1816: struct binding_level *b = current_binding_level; 1817: tree old_bindings = NULL_TREE; 1818: 1819: /* Have to include global_binding_level, because class-level decls 1820: aren't listed anywhere useful. */ 1821: for (; b; b = b->level_chain) 1822: { 1823: tree t; 1824: 1825: if (b == global_binding_level) 1826: continue; 1827: 1828: for (t = b->names; t; t = TREE_CHAIN (t)) 1829: { 1830: tree binding, t1, t2 = t; 1831: tree id = DECL_ASSEMBLER_NAME (t2); 1832: 1833: if (!id 1834: || (!IDENTIFIER_LOCAL_VALUE (id) 1835: && !IDENTIFIER_CLASS_VALUE (id))) 1836: continue; 1837: 1838: for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) 1839: if (TREE_VEC_ELT (t1, 0) == id) 1840: goto skip_it; 1841: 1842: binding = make_tree_vec (4); 1843: if (id) 1844: { 1845: my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); 1846: TREE_VEC_ELT (binding, 0) = id; 1847: TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id); 1848: TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); 1849: TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); 1850: IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; 1851: IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; 1852: } 1853: TREE_CHAIN (binding) = old_bindings; 1854: old_bindings = binding; 1855: skip_it: 1856: ; 1857: } 1858: /* Unwind type-value slots back to top level. */ 1859: for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) 1860: SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); 1861: } 1862: /* Clear out class-level bindings cache. */ 1863: if (current_binding_level == global_binding_level 1864: && previous_class_type != NULL_TREE) 1865: { 1866: popclass (-1); 1867: previous_class_type = NULL_TREE; 1868: } 1869: 1870: s->old_binding_level = current_binding_level; 1871: current_binding_level = global_binding_level; 1872: 1873: s->class_name = current_class_name; 1874: s->class_type = current_class_type; 1875: s->function_decl = current_function_decl; 1.1.1.2 ! root 1876: s->base_init_list = current_base_init_list; ! 1877: s->member_init_list = current_member_init_list; 1.1 root 1878: s->class_bindings = class_binding_level; 1879: s->previous_class_type = previous_class_type; 1880: s->lang_stack = current_lang_stack; 1881: s->lang_base = current_lang_base; 1882: s->lang_stacksize = current_lang_stacksize; 1883: s->lang_name = current_lang_name; 1884: s->named_labels = named_labels; 1.1.1.2 ! root 1885: current_class_name = current_class_type = NULL_TREE; 1.1 root 1886: current_function_decl = NULL_TREE; 1887: class_binding_level = (struct binding_level *)0; 1888: previous_class_type = NULL_TREE; 1889: current_lang_stacksize = 10; 1890: current_lang_stack = current_lang_base 1891: = (tree *) xmalloc (current_lang_stacksize * sizeof (tree)); 1892: current_lang_name = lang_name_cplusplus; 1893: strict_prototype = strict_prototypes_lang_cplusplus; 1894: named_labels = NULL_TREE; 1895: 1896: s->prev = current_saved_scope; 1897: s->old_bindings = old_bindings; 1898: current_saved_scope = s; 1899: } 1900: 1901: void 1902: pop_from_top_level () 1903: { 1904: extern int current_lang_stacksize; 1905: struct saved_scope *s = current_saved_scope; 1906: tree t; 1907: 1908: if (previous_class_type) 1909: previous_class_type = NULL_TREE; 1910: 1911: current_binding_level = s->old_binding_level; 1912: current_saved_scope = s->prev; 1913: for (t = s->old_bindings; t; t = TREE_CHAIN (t)) 1914: { 1915: tree id = TREE_VEC_ELT (t, 0); 1916: if (id) 1917: { 1918: IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1); 1919: IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2); 1920: IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); 1921: } 1922: } 1923: current_class_name = s->class_name; 1924: current_class_type = s->class_type; 1.1.1.2 ! root 1925: current_base_init_list = s->base_init_list; ! 1926: current_member_init_list = s->member_init_list; 1.1 root 1927: current_function_decl = s->function_decl; 1928: class_binding_level = s->class_bindings; 1929: previous_class_type = s->previous_class_type; 1930: free (current_lang_base); 1931: current_lang_base = s->lang_base; 1932: current_lang_stack = s->lang_stack; 1933: current_lang_name = s->lang_name; 1934: current_lang_stacksize = s->lang_stacksize; 1935: if (current_lang_name == lang_name_cplusplus) 1936: strict_prototype = strict_prototypes_lang_cplusplus; 1937: else if (current_lang_name == lang_name_c) 1938: strict_prototype = strict_prototypes_lang_c; 1939: named_labels = s->named_labels; 1940: 1941: free (s); 1942: } 1943: 1944: /* Push a definition of struct, union or enum tag "name". 1945: into binding_level "b". "type" should be the type node, 1946: We assume that the tag "name" is not already defined. 1947: 1948: Note that the definition may really be just a forward reference. 1949: In that case, the TYPE_SIZE will be a NULL_TREE. 1950: 1951: C++ gratuitously puts all these tags in the name space. */ 1952: 1953: /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, 1954: record the shadowed value for this binding contour. TYPE is 1955: the type that ID maps to. */ 1956: 1957: static void 1958: set_identifier_type_value_with_scope (id, type, b) 1959: tree id; 1960: tree type; 1961: struct binding_level *b; 1962: { 1963: if (b != global_binding_level) 1964: { 1965: tree old_type_value = IDENTIFIER_TYPE_VALUE (id); 1966: b->type_shadowed 1967: = tree_cons (id, old_type_value, b->type_shadowed); 1968: } 1969: SET_IDENTIFIER_TYPE_VALUE (id, type); 1970: } 1971: 1972: /* As set_identifier_type_value_with_scope, but using inner_binding_level. */ 1973: 1974: void 1975: set_identifier_type_value (id, type) 1976: tree id; 1977: tree type; 1978: { 1979: set_identifier_type_value_with_scope (id, type, inner_binding_level); 1980: } 1981: 1982: /* Subroutine "set_nested_typename" builds the nested-typename of 1983: the type decl in question. (Argument CLASSNAME can actually be 1984: a function as well, if that's the smallest containing scope.) */ 1985: 1986: static void 1987: set_nested_typename (decl, classname, name, type) 1988: tree decl, classname, name, type; 1989: { 1.1.1.2 ! root 1990: char *buf; 1.1 root 1991: my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136); 1992: 1.1.1.2 ! root 1993: /* No need to do this for anonymous names, since they're unique. */ ! 1994: if (ANON_AGGRNAME_P (name)) ! 1995: { ! 1996: DECL_NESTED_TYPENAME (decl) = name; ! 1997: return; 1.1 root 1998: } 1.1.1.2 ! root 1999: ! 2000: if (classname == NULL_TREE) ! 2001: classname = get_identifier (""); ! 2002: ! 2003: my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137); ! 2004: my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138); ! 2005: buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname) ! 2006: + IDENTIFIER_LENGTH (name)); ! 2007: sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname), ! 2008: IDENTIFIER_POINTER (name)); ! 2009: DECL_NESTED_TYPENAME (decl) = get_identifier (buf); ! 2010: TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1; ! 2011: ! 2012: /* Create an extra decl so that the nested name will have a type value ! 2013: where appropriate. */ ! 2014: { ! 2015: tree nested, type_decl; ! 2016: nested = DECL_NESTED_TYPENAME (decl); ! 2017: type_decl = build_decl (TYPE_DECL, nested, type); ! 2018: DECL_NESTED_TYPENAME (type_decl) = nested; ! 2019: SET_DECL_ARTIFICIAL (type_decl); ! 2020: /* Mark the TYPE_DECL node created just above as a gratuitous one so that ! 2021: dwarfout.c will know not to generate a TAG_typedef DIE for it, and ! 2022: sdbout.c won't try to output a .def for "::foo". */ ! 2023: DECL_IGNORED_P (type_decl) = 1; ! 2024: ! 2025: /* Remove this when local classes are fixed. */ ! 2026: SET_IDENTIFIER_TYPE_VALUE (nested, type); ! 2027: ! 2028: pushdecl_nonclass_level (type_decl); ! 2029: } 1.1 root 2030: } 2031: 1.1.1.2 ! root 2032: /* Pop off extraneous binding levels left over due to syntax errors. ! 2033: ! 2034: We don't pop past namespaces, as they might be valid. */ 1.1 root 2035: void 2036: pop_everything () 2037: { 2038: #ifdef DEBUG_CP_BINDING_LEVELS 2039: fprintf (stderr, "XXX entering pop_everything ()\n"); 2040: #endif 1.1.1.2 ! root 2041: while (! toplevel_bindings_p () && ! pseudo_global_level_p ()) 1.1 root 2042: { 2043: if (class_binding_level) 2044: pop_nested_class (1); 2045: else 2046: poplevel (0, 0, 0); 2047: } 2048: #ifdef DEBUG_CP_BINDING_LEVELS 2049: fprintf (stderr, "XXX leaving pop_everything ()\n"); 2050: #endif 2051: } 2052: 2053: #if 0 /* not yet, should get fixed properly later */ 2054: /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME. 2055: Other routines shouldn't use build_decl directly; they'll produce 2056: incorrect results with `-g' unless they duplicate this code. 2057: 2058: This is currently needed mainly for dbxout.c, but we can make 2059: use of it in method.c later as well. */ 2060: tree 2061: make_type_decl (name, type) 2062: tree name, type; 2063: { 2064: tree decl, id; 2065: decl = build_decl (TYPE_DECL, name, type); 2066: if (TYPE_NAME (type) == name) 2067: /* Class/union/enum definition, or a redundant typedef for same. */ 2068: { 2069: id = get_identifier (build_overload_name (type, 1, 1)); 2070: DECL_ASSEMBLER_NAME (decl) = id; 2071: } 2072: else if (TYPE_NAME (type) != NULL_TREE) 2073: /* Explicit typedef, or implicit typedef for template expansion. */ 2074: DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type)); 2075: else 2076: { 2077: /* XXX: Typedef for unnamed struct; some other situations. 2078: TYPE_NAME is null; what's right here? */ 2079: } 2080: return decl; 2081: } 2082: #endif 2083: 2084: /* Push a tag name NAME for struct/class/union/enum type TYPE. 1.1.1.2 ! root 2085: Normally put into into the inner-most non-tag-transparent scope, 1.1 root 2086: but if GLOBALIZE is true, put it in the inner-most non-class scope. 2087: The latter is needed for implicit declarations. */ 2088: 2089: void 2090: pushtag (name, type, globalize) 2091: tree name, type; 2092: int globalize; 2093: { 2094: register struct binding_level *b; 2095: tree context = 0; 2096: tree c_decl = 0; 2097: 2098: b = inner_binding_level; 2099: while (b->tag_transparent 2100: || (globalize && b->parm_flag == 2)) 2101: b = b->level_chain; 2102: 1.1.1.2 ! root 2103: if (toplevel_bindings_p ()) 1.1 root 2104: b->tags = perm_tree_cons (name, type, b->tags); 2105: else 2106: b->tags = saveable_tree_cons (name, type, b->tags); 2107: 2108: if (name) 2109: { 2110: context = type ? TYPE_CONTEXT (type) : NULL_TREE; 2111: if (! context && ! globalize) 2112: context = current_scope (); 2113: if (context) 2114: c_decl = TREE_CODE (context) == FUNCTION_DECL 1.1.1.2 ! root 2115: ? context : TYPE_MAIN_DECL (context); 1.1 root 2116: 1.1.1.2 ! root 2117: #if 0 1.1 root 2118: /* Record the identifier as the type's name if it has none. */ 2119: if (TYPE_NAME (type) == NULL_TREE) 2120: TYPE_NAME (type) = name; 1.1.1.2 ! root 2121: #endif 1.1 root 2122: 2123: /* Do C++ gratuitous typedefing. */ 1.1.1.2 ! root 2124: if (IDENTIFIER_TYPE_VALUE (name) != type) 1.1 root 2125: { 2126: register tree d; 2127: int newdecl = 0; 2128: 2129: if (b->parm_flag != 2 2130: || TYPE_SIZE (current_class_type) != NULL_TREE) 2131: { 2132: d = lookup_nested_type (type, c_decl); 2133: 2134: if (d == NULL_TREE) 2135: { 2136: newdecl = 1; 2137: #if 0 /* not yet, should get fixed properly later */ 2138: d = make_type_decl (name, type); 2139: #else 2140: d = build_decl (TYPE_DECL, name, type); 1.1.1.2 ! root 2141: DECL_ASSEMBLER_NAME (d) = current_namespace_id (DECL_ASSEMBLER_NAME (d)); 1.1 root 2142: #endif 2143: SET_DECL_ARTIFICIAL (d); 2144: #ifdef DWARF_DEBUGGING_INFO 2145: if (write_symbols == DWARF_DEBUG) 2146: { 2147: /* Mark the TYPE_DECL node we created just above as an 2148: gratuitous one. We need to do this so that dwarfout.c 2149: will understand that it is not supposed to output a 2150: TAG_typedef DIE for it. */ 2151: DECL_IGNORED_P (d) = 1; 2152: } 2153: #endif /* DWARF_DEBUGGING_INFO */ 2154: set_identifier_type_value_with_scope (name, type, b); 2155: } 2156: else 2157: d = TYPE_NAME (d); 2158: 1.1.1.2 ! root 2159: TYPE_NAME (type) = d; ! 2160: 1.1 root 2161: /* If it is anonymous, then we are called from pushdecl, 1.1.1.2 ! root 2162: and we don't want to infinitely recurse. */ ! 2163: if (! ANON_AGGRNAME_P (name)) 1.1 root 2164: { 2165: if (b->parm_flag == 2) 2166: d = pushdecl_class_level (d); 2167: else 2168: d = pushdecl_with_scope (d, b); 2169: } 2170: } 2171: else 2172: { 2173: /* Make nested declarations go into class-level scope. */ 2174: newdecl = 1; 2175: d = build_decl (TYPE_DECL, name, type); 2176: SET_DECL_ARTIFICIAL (d); 2177: #ifdef DWARF_DEBUGGING_INFO 2178: if (write_symbols == DWARF_DEBUG) 2179: { 2180: /* Mark the TYPE_DECL node we created just above as an 2181: gratuitous one. We need to do this so that dwarfout.c 2182: will understand that it is not supposed to output a 2183: TAG_typedef DIE for it. */ 2184: DECL_IGNORED_P (d) = 1; 2185: } 2186: #endif /* DWARF_DEBUGGING_INFO */ 1.1.1.2 ! root 2187: ! 2188: TYPE_MAIN_DECL (type) = d; ! 2189: 1.1 root 2190: /* Make sure we're in this type's scope when we push the 2191: decl for a template, otherwise class_binding_level will 2192: be NULL and we'll end up dying inside of 2193: push_class_level_binding. */ 2194: if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) 2195: pushclass (type, 0); 2196: d = pushdecl_class_level (d); 2197: if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) 2198: popclass (0); 2199: } 1.1.1.2 ! root 2200: if (newdecl) 1.1 root 2201: { 1.1.1.2 ! root 2202: if (write_symbols != DWARF_DEBUG) ! 2203: { ! 2204: if (ANON_AGGRNAME_P (name)) ! 2205: DECL_IGNORED_P (d) = 1; ! 2206: } ! 2207: ! 2208: if (context == NULL_TREE) ! 2209: /* Non-nested class. */ ! 2210: set_nested_typename (d, NULL_TREE, name, type); ! 2211: else if (context && TREE_CODE (context) == FUNCTION_DECL) ! 2212: /* Function-nested class. */ ! 2213: set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl), ! 2214: name, type); ! 2215: else /* if (context && IS_AGGR_TYPE (context)) */ ! 2216: /* Class-nested class. */ ! 2217: set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl), ! 2218: name, type); 1.1 root 2219: 2220: DECL_CONTEXT (d) = context; 1.1.1.2 ! root 2221: TYPE_CONTEXT (type) = DECL_CONTEXT (d); ! 2222: DECL_ASSEMBLER_NAME (d) ! 2223: = get_identifier (build_overload_name (type, 1, 1)); 1.1 root 2224: } 2225: } 2226: if (b->parm_flag == 2) 2227: { 2228: TREE_NONLOCAL_FLAG (type) = 1; 2229: if (TYPE_SIZE (current_class_type) == NULL_TREE) 2230: CLASSTYPE_TAGS (current_class_type) = b->tags; 2231: } 2232: } 2233: 2234: if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) 2235: /* Use the canonical TYPE_DECL for this node. */ 2236: TYPE_STUB_DECL (type) = TYPE_NAME (type); 2237: else 2238: { 2239: /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE 2240: will be the tagged type we just added to the current 2241: binding level. This fake NULL-named TYPE_DECL node helps 2242: dwarfout.c to know when it needs to output a 2243: representation of a tagged type, and it also gives us a 2244: convenient place to record the "scope start" address for 2245: the tagged type. */ 2246: 2247: #if 0 /* not yet, should get fixed properly later */ 2248: tree d = make_type_decl (NULL_TREE, type); 2249: #else 2250: tree d = build_decl (TYPE_DECL, NULL_TREE, type); 2251: #endif 2252: TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b); 2253: } 2254: } 2255: 2256: /* Counter used to create anonymous type names. */ 2257: static int anon_cnt = 0; 2258: 2259: /* Return an IDENTIFIER which can be used as a name for 2260: anonymous structs and unions. */ 2261: tree 2262: make_anon_name () 2263: { 2264: char buf[32]; 2265: 2266: sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++); 2267: return get_identifier (buf); 2268: } 2269: 2270: /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. 2271: This keeps dbxout from getting confused. */ 2272: void 2273: clear_anon_tags () 2274: { 2275: register struct binding_level *b; 2276: register tree tags; 2277: static int last_cnt = 0; 2278: 2279: /* Fast out if no new anon names were declared. */ 2280: if (last_cnt == anon_cnt) 2281: return; 2282: 2283: b = current_binding_level; 2284: while (b->tag_transparent) 2285: b = b->level_chain; 2286: tags = b->tags; 2287: while (tags) 2288: { 2289: /* A NULL purpose means we have already processed all tags 2290: from here to the end of the list. */ 2291: if (TREE_PURPOSE (tags) == NULL_TREE) 2292: break; 2293: if (ANON_AGGRNAME_P (TREE_PURPOSE (tags))) 2294: TREE_PURPOSE (tags) = NULL_TREE; 2295: tags = TREE_CHAIN (tags); 2296: } 2297: last_cnt = anon_cnt; 2298: } 2299: 2300: /* Subroutine of duplicate_decls: return truthvalue of whether 2301: or not types of these decls match. 2302: 2303: For C++, we must compare the parameter list so that `int' can match 2304: `int&' in a parameter position, but `int&' is not confused with 2305: `const int&'. */ 1.1.1.2 ! root 2306: int 1.1 root 2307: decls_match (newdecl, olddecl) 2308: tree newdecl, olddecl; 2309: { 2310: int types_match; 2311: 2312: if (TREE_CODE (newdecl) == FUNCTION_DECL 2313: && TREE_CODE (olddecl) == FUNCTION_DECL) 2314: { 2315: tree f1 = TREE_TYPE (newdecl); 2316: tree f2 = TREE_TYPE (olddecl); 2317: tree p1 = TYPE_ARG_TYPES (f1); 2318: tree p2 = TYPE_ARG_TYPES (f2); 2319: 2320: /* When we parse a static member function definition, 2321: we put together a FUNCTION_DECL which thinks its type 2322: is METHOD_TYPE. Change that to FUNCTION_TYPE, and 2323: proceed. */ 2324: if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) 2325: revert_static_member_fn (&newdecl, &f1, &p1); 2326: else if (TREE_CODE (f2) == METHOD_TYPE 2327: && DECL_STATIC_FUNCTION_P (newdecl)) 2328: revert_static_member_fn (&olddecl, &f2, &p2); 2329: 2330: /* Here we must take care of the case where new default 2331: parameters are specified. Also, warn if an old 2332: declaration becomes ambiguous because default 2333: parameters may cause the two to be ambiguous. */ 2334: if (TREE_CODE (f1) != TREE_CODE (f2)) 2335: { 2336: if (TREE_CODE (f1) == OFFSET_TYPE) 2337: cp_compiler_error ("`%D' redeclared as member function", newdecl); 2338: else 2339: cp_compiler_error ("`%D' redeclared as non-member function", newdecl); 2340: return 0; 2341: } 2342: 2343: if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1)) 2344: { 2345: if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c 2346: && p2 == NULL_TREE) 2347: { 2348: types_match = self_promoting_args_p (p1); 2349: if (p1 == void_list_node) 2350: TREE_TYPE (newdecl) = TREE_TYPE (olddecl); 2351: } 2352: else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c 2353: && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE) 2354: { 2355: types_match = self_promoting_args_p (p2); 2356: TREE_TYPE (newdecl) = TREE_TYPE (olddecl); 2357: } 2358: else 2359: types_match = compparms (p1, p2, 3); 2360: } 2361: else 2362: types_match = 0; 2363: } 2364: else if (TREE_CODE (newdecl) == TEMPLATE_DECL 2365: && TREE_CODE (olddecl) == TEMPLATE_DECL) 2366: { 2367: tree newargs = DECL_TEMPLATE_PARMS (newdecl); 2368: tree oldargs = DECL_TEMPLATE_PARMS (olddecl); 2369: int i, len = TREE_VEC_LENGTH (newargs); 2370: 2371: if (TREE_VEC_LENGTH (oldargs) != len) 2372: return 0; 2373: 2374: for (i = 0; i < len; i++) 2375: { 2376: tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i)); 2377: tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i)); 2378: if (TREE_CODE (newarg) != TREE_CODE (oldarg)) 2379: return 0; 2380: else if (TREE_CODE (newarg) == TYPE_DECL) 2381: /* continue */; 2382: else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1)) 2383: return 0; 2384: } 2385: 2386: if (DECL_TEMPLATE_IS_CLASS (newdecl) 2387: != DECL_TEMPLATE_IS_CLASS (olddecl)) 2388: types_match = 0; 2389: else if (DECL_TEMPLATE_IS_CLASS (newdecl)) 2390: types_match = 1; 2391: else 2392: types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl), 2393: DECL_TEMPLATE_RESULT (newdecl)); 2394: } 2395: else 2396: { 2397: if (TREE_TYPE (newdecl) == error_mark_node) 2398: types_match = TREE_TYPE (olddecl) == error_mark_node; 2399: else if (TREE_TYPE (olddecl) == NULL_TREE) 2400: types_match = TREE_TYPE (newdecl) == NULL_TREE; 2401: else if (TREE_TYPE (newdecl) == NULL_TREE) 2402: types_match = 0; 2403: else 2404: types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1); 2405: } 2406: 2407: return types_match; 2408: } 2409: 2410: /* If NEWDECL is `static' and an `extern' was seen previously, 2411: warn about it. (OLDDECL may be NULL_TREE; NAME contains 2412: information about previous usage as an `extern'.) 2413: 2414: Note that this does not apply to the C++ case of declaring 2415: a variable `extern const' and then later `const'. 2416: 2417: Don't complain if -traditional, since traditional compilers 2418: don't complain. 2419: 2420: Don't complain about built-in functions, since they are beyond 2421: the user's control. */ 2422: 2423: static void 2424: warn_extern_redeclared_static (newdecl, olddecl) 2425: tree newdecl, olddecl; 2426: { 2427: tree name; 2428: 2429: static char *explicit_extern_static_warning 2430: = "`%D' was declared `extern' and later `static'"; 2431: static char *implicit_extern_static_warning 2432: = "`%D' was declared implicitly `extern' and later `static'"; 2433: 2434: if (flag_traditional 1.1.1.2 ! root 2435: || TREE_CODE (newdecl) == TYPE_DECL) 1.1 root 2436: return; 2437: 2438: name = DECL_ASSEMBLER_NAME (newdecl); 1.1.1.2 ! root 2439: if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl)) 1.1 root 2440: { 2441: /* It's okay to redeclare an ANSI built-in function as static, 2442: or to declare a non-ANSI built-in function as anything. */ 2443: if (! (TREE_CODE (newdecl) == FUNCTION_DECL 2444: && olddecl != NULL_TREE 2445: && TREE_CODE (olddecl) == FUNCTION_DECL 2446: && (DECL_BUILT_IN (olddecl) 2447: || DECL_BUILT_IN_NONANSI (olddecl)))) 2448: { 1.1.1.2 ! root 2449: cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name) 1.1 root 2450: ? implicit_extern_static_warning 2451: : explicit_extern_static_warning, newdecl); 2452: if (olddecl != NULL_TREE) 1.1.1.2 ! root 2453: cp_pedwarn_at ("previous declaration of `%D'", olddecl); 1.1 root 2454: } 2455: } 2456: } 2457: 2458: /* Handle when a new declaration NEWDECL has the same name as an old 2459: one OLDDECL in the same binding contour. Prints an error message 2460: if appropriate. 2461: 2462: If safely possible, alter OLDDECL to look like NEWDECL, and return 1. 2463: Otherwise, return 0. */ 2464: 2465: int 2466: duplicate_decls (newdecl, olddecl) 2467: register tree newdecl, olddecl; 2468: { 2469: extern struct obstack permanent_obstack; 2470: unsigned olddecl_uid = DECL_UID (olddecl); 2471: int olddecl_friend = 0, types_match = 0; 2472: int new_defines_function; 2473: tree previous_c_decl = NULL_TREE; 2474: 1.1.1.2 ! root 2475: if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd') ! 2476: DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl); ! 2477: 1.1 root 2478: types_match = decls_match (newdecl, olddecl); 2479: 2480: if (TREE_CODE (olddecl) != TREE_LIST) 2481: olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl); 2482: 2483: /* If either the type of the new decl or the type of the old decl is an 2484: error_mark_node, then that implies that we have already issued an 2485: error (earlier) for some bogus type specification, and in that case, 2486: it is rather pointless to harass the user with yet more error message 2487: about the same declaration, so well just pretent the types match here. */ 2488: if ((TREE_TYPE (newdecl) 2489: && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK) 2490: || (TREE_TYPE (olddecl) 2491: && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK)) 2492: types_match = 1; 2493: 2494: if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL 2495: && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl) 2496: /* If -traditional, avoid error for redeclaring fcn 2497: after implicit decl. */ 2498: ; 2499: else if (TREE_CODE (olddecl) == FUNCTION_DECL 2500: && DECL_ARTIFICIAL (olddecl) 2501: && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) 2502: { 2503: /* If you declare a built-in or predefined function name as static, 2504: the old definition is overridden, but optionally warn this was a 2505: bad choice of name. Ditto for overloads. */ 1.1.1.2 ! root 2506: if (! DECL_PUBLIC (newdecl) 1.1 root 2507: || (TREE_CODE (newdecl) == FUNCTION_DECL 2508: && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))) 2509: { 2510: if (warn_shadow) 2511: cp_warning ("shadowing %s function `%#D'", 2512: DECL_BUILT_IN (olddecl) ? "built-in" : "library", 2513: olddecl); 2514: /* Discard the old built-in function. */ 2515: return 0; 2516: } 2517: else if (! types_match) 2518: { 2519: if (TREE_CODE (newdecl) != FUNCTION_DECL) 2520: { 2521: /* If the built-in is not ansi, then programs can override 2522: it even globally without an error. */ 2523: if (! DECL_BUILT_IN (olddecl)) 2524: cp_warning ("library function `%#D' redeclared as non-function `%#D'", 2525: olddecl, newdecl); 2526: else 2527: { 2528: cp_error ("declaration of `%#D'", newdecl); 2529: cp_error ("conflicts with built-in declaration `%#D'", 2530: olddecl); 2531: } 2532: return 0; 2533: } 2534: 2535: cp_warning ("declaration of `%#D'", newdecl); 2536: cp_warning ("conflicts with built-in declaration `%#D'", 2537: olddecl); 2538: } 2539: } 2540: else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) 2541: { 2542: if ((TREE_CODE (newdecl) == FUNCTION_DECL 2543: && TREE_CODE (olddecl) == TEMPLATE_DECL 2544: && ! DECL_TEMPLATE_IS_CLASS (olddecl)) 2545: || (TREE_CODE (olddecl) == FUNCTION_DECL 2546: && TREE_CODE (newdecl) == TEMPLATE_DECL 2547: && ! DECL_TEMPLATE_IS_CLASS (newdecl))) 2548: return 0; 2549: 2550: cp_error ("`%#D' redeclared as different kind of symbol", newdecl); 2551: if (TREE_CODE (olddecl) == TREE_LIST) 2552: olddecl = TREE_VALUE (olddecl); 2553: cp_error_at ("previous declaration of `%#D'", olddecl); 2554: 2555: /* New decl is completely inconsistent with the old one => 2556: tell caller to replace the old one. */ 2557: 2558: return 0; 2559: } 2560: else if (!types_match) 2561: { 2562: if (TREE_CODE (newdecl) == TEMPLATE_DECL) 2563: { 2564: /* The name of a class template may not be declared to refer to 2565: any other template, class, function, object, namespace, value, 2566: or type in the same scope. */ 2567: if (DECL_TEMPLATE_IS_CLASS (olddecl) 2568: || DECL_TEMPLATE_IS_CLASS (newdecl)) 2569: { 2570: cp_error ("declaration of template `%#D'", newdecl); 2571: cp_error_at ("conflicts with previous declaration `%#D'", 2572: olddecl); 2573: } 2574: return 0; 2575: } 2576: if (TREE_CODE (newdecl) == FUNCTION_DECL) 2577: { 2578: if (DECL_LANGUAGE (newdecl) == lang_c 2579: && DECL_LANGUAGE (olddecl) == lang_c) 2580: { 2581: cp_error ("declaration of C function `%#D' conflicts with", 2582: newdecl); 2583: cp_error_at ("previous declaration `%#D' here", olddecl); 2584: } 2585: else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), 1.1.1.2 ! root 2586: TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3)) 1.1 root 2587: { 2588: cp_error ("new declaration `%#D'", newdecl); 2589: cp_error_at ("ambiguates old declaration `%#D'", olddecl); 2590: } 2591: else 2592: return 0; 2593: } 2594: 2595: /* Already complained about this, so don't do so again. */ 2596: else if (current_class_type == NULL_TREE 2597: || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) 2598: { 2599: cp_error ("conflicting types for `%#D'", newdecl); 2600: cp_error_at ("previous declaration as `%#D'", olddecl); 2601: } 2602: } 2603: else 2604: { 2605: char *errmsg = redeclaration_error_message (newdecl, olddecl); 2606: if (errmsg) 2607: { 2608: cp_error (errmsg, newdecl); 2609: if (DECL_NAME (olddecl) != NULL_TREE) 2610: cp_error_at ((DECL_INITIAL (olddecl) 2611: && current_binding_level == global_binding_level) 2612: ? "`%#D' previously defined here" 2613: : "`%#D' previously declared here", olddecl); 2614: } 2615: else if (TREE_CODE (olddecl) == FUNCTION_DECL 2616: && DECL_INITIAL (olddecl) != NULL_TREE 2617: && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE 2618: && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE) 2619: { 2620: /* Prototype decl follows defn w/o prototype. */ 2621: cp_warning_at ("prototype for `%#D'", newdecl); 2622: cp_warning_at ("follows non-prototype definition here", olddecl); 2623: } 2624: else if (TREE_CODE (olddecl) == FUNCTION_DECL 2625: && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)) 2626: { 2627: /* extern "C" int foo (); 2628: int foo () { bar (); } 2629: is OK. */ 2630: if (current_lang_stack == current_lang_base) 2631: DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); 2632: else 2633: { 2634: cp_error_at ("previous declaration of `%#D' with %L linkage", 2635: olddecl, DECL_LANGUAGE (olddecl)); 2636: cp_error ("conflicts with new declaration with %L linkage", 2637: DECL_LANGUAGE (newdecl)); 2638: } 2639: } 2640: 1.1.1.2 ! root 2641: if (TREE_CODE (olddecl) == FUNCTION_DECL) ! 2642: { ! 2643: tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl)); ! 2644: tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); ! 2645: int i = 1; ! 2646: ! 2647: if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) ! 2648: t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); ! 2649: ! 2650: for (; t1 && t1 != void_list_node; ! 2651: t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) ! 2652: if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) ! 2653: { ! 2654: if (1 == simple_cst_equal (TREE_PURPOSE (t1), ! 2655: TREE_PURPOSE (t2))) ! 2656: { ! 2657: if (pedantic) ! 2658: { ! 2659: cp_pedwarn ("default argument given for parameter %d of `%#D'", ! 2660: i, newdecl); ! 2661: cp_pedwarn_at ("after previous specification in `%#D'", ! 2662: olddecl); ! 2663: } ! 2664: } ! 2665: else ! 2666: { ! 2667: cp_error ("default argument given for parameter %d of `%#D'", ! 2668: i, newdecl); ! 2669: cp_error_at ("conflicts with previous specification in `%#D'", ! 2670: olddecl); ! 2671: } ! 2672: } ! 2673: ! 2674: if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl)) ! 2675: { ! 2676: #if 0 /* I think this will be correct, but it's really annoying. We should ! 2677: fix the compiler to find vtables by indirection so it isn't ! 2678: necessary. (jason 8/25/95) */ ! 2679: if (DECL_VINDEX (olddecl) && ! DECL_ABSTRACT_VIRTUAL_P (olddecl)) ! 2680: { ! 2681: cp_pedwarn ("virtual function `%#D' redeclared inline", ! 2682: newdecl); ! 2683: cp_pedwarn_at ("previous non-inline declaration here", ! 2684: olddecl); ! 2685: } ! 2686: else ! 2687: #endif ! 2688: if (TREE_ADDRESSABLE (olddecl)) ! 2689: { ! 2690: cp_pedwarn ("`%#D' was used before it was declared inline", ! 2691: newdecl); ! 2692: cp_pedwarn_at ("previous non-inline declaration here", ! 2693: olddecl); ! 2694: } ! 2695: } ! 2696: } ! 2697: /* These bits are logically part of the type for non-functions. */ ! 2698: else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) ! 2699: || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)) ! 2700: { ! 2701: cp_pedwarn ("type qualifiers for `%#D'", newdecl); ! 2702: cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl); ! 2703: } 1.1 root 2704: } 2705: 2706: /* If new decl is `static' and an `extern' was seen previously, 2707: warn about it. */ 2708: warn_extern_redeclared_static (newdecl, olddecl); 2709: 2710: /* We have committed to returning 1 at this point. */ 2711: if (TREE_CODE (newdecl) == FUNCTION_DECL) 2712: { 2713: /* Now that functions must hold information normally held 2714: by field decls, there is extra work to do so that 2715: declaration information does not get destroyed during 2716: definition. */ 2717: if (DECL_VINDEX (olddecl)) 2718: DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); 2719: if (DECL_CONTEXT (olddecl)) 2720: DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); 2721: if (DECL_CLASS_CONTEXT (olddecl)) 2722: DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); 2723: if (DECL_CHAIN (newdecl) == NULL_TREE) 2724: DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); 2725: if (DECL_NEXT_METHOD (newdecl) == NULL_TREE) 2726: DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl); 2727: if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) 2728: DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); 1.1.1.2 ! root 2729: DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl); ! 2730: DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); ! 2731: DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl); 1.1 root 2732: } 2733: 2734: /* Deal with C++: must preserve virtual function table size. */ 2735: if (TREE_CODE (olddecl) == TYPE_DECL) 2736: { 2737: register tree newtype = TREE_TYPE (newdecl); 2738: register tree oldtype = TREE_TYPE (olddecl); 2739: 1.1.1.2 ! root 2740: DECL_NESTED_TYPENAME (newdecl) = DECL_NESTED_TYPENAME (olddecl); ! 2741: 1.1 root 2742: if (newtype != error_mark_node && oldtype != error_mark_node 2743: && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype)) 2744: { 2745: CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype); 2746: CLASSTYPE_FRIEND_CLASSES (newtype) 2747: = CLASSTYPE_FRIEND_CLASSES (oldtype); 2748: } 2749: #if 0 2750: /* why assert here? Just because debugging information is 2751: messed up? (mrs) */ 2752: /* it happens on something like: 2753: typedef struct Thing { 2754: Thing(); 2755: int x; 2756: } Thing; 2757: */ 2758: my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), 2759: 139); 2760: #endif 2761: } 2762: 2763: /* Special handling ensues if new decl is a function definition. */ 2764: new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL 2765: && DECL_INITIAL (newdecl) != NULL_TREE); 2766: 2767: /* Optionally warn about more than one declaration for the same name, 2768: but don't warn about a function declaration followed by a definition. */ 2769: if (warn_redundant_decls 2770: && ! DECL_ARTIFICIAL (olddecl) 2771: && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE) 2772: /* Don't warn about extern decl followed by (tentative) definition. */ 2773: && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) 2774: { 2775: cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); 1.1.1.2 ! root 2776: cp_warning_at ("previous declaration of `%D'", olddecl); 1.1 root 2777: } 2778: 2779: /* Copy all the DECL_... slots specified in the new decl 2780: except for any that we copy here from the old type. */ 2781: 2782: if (types_match) 2783: { 2784: /* Automatically handles default parameters. */ 2785: tree oldtype = TREE_TYPE (olddecl); 1.1.1.2 ! root 2786: tree newtype; 1.1 root 2787: 1.1.1.2 ! root 2788: /* Make sure we put the new type in the same obstack as the old one. */ ! 2789: if (oldtype) 1.1 root 2790: push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); 2791: else 2792: { 2793: push_obstacks_nochange (); 2794: end_temporary_allocation (); 2795: } 2796: 1.1.1.2 ! root 2797: /* Merge the data types specified in the two decls. */ ! 2798: newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); ! 2799: 1.1 root 2800: if (TREE_CODE (newdecl) == VAR_DECL) 2801: DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); 2802: /* Do this after calling `common_type' so that default 2803: parameters don't confuse us. */ 2804: else if (TREE_CODE (newdecl) == FUNCTION_DECL 2805: && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) 2806: != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) 2807: { 2808: tree ctype = NULL_TREE; 2809: ctype = DECL_CLASS_CONTEXT (newdecl); 1.1.1.2 ! root 2810: TREE_TYPE (newdecl) = build_exception_variant (newtype, 1.1 root 2811: TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); 1.1.1.2 ! root 2812: TREE_TYPE (olddecl) = build_exception_variant (newtype, 1.1 root 2813: TYPE_RAISES_EXCEPTIONS (oldtype)); 2814: 2815: if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0)) 2816: { 1.1.1.2 ! root 2817: cp_error ("declaration of `%D' throws different exceptions...", 1.1 root 2818: newdecl); 2819: cp_error_at ("...from previous declaration here", olddecl); 2820: } 2821: } 2822: TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; 2823: 2824: /* Lay the type out, unless already done. */ 1.1.1.2 ! root 2825: if (oldtype != TREE_TYPE (newdecl) ! 2826: && TREE_TYPE (newdecl) != error_mark_node) ! 2827: layout_type (TREE_TYPE (newdecl)); ! 2828: ! 2829: if (TREE_CODE (newdecl) == VAR_DECL ! 2830: || TREE_CODE (newdecl) == PARM_DECL ! 2831: || TREE_CODE (newdecl) == RESULT_DECL ! 2832: || TREE_CODE (newdecl) == FIELD_DECL ! 2833: || TREE_CODE (newdecl) == TYPE_DECL) ! 2834: layout_decl (newdecl, 0); 1.1 root 2835: 2836: /* Merge the type qualifiers. */ 2837: if (TREE_READONLY (newdecl)) 2838: TREE_READONLY (olddecl) = 1; 2839: if (TREE_THIS_VOLATILE (newdecl)) 2840: TREE_THIS_VOLATILE (olddecl) = 1; 2841: 2842: /* Merge the initialization information. */ 2843: if (DECL_INITIAL (newdecl) == NULL_TREE 2844: && DECL_INITIAL (olddecl) != NULL_TREE) 2845: { 2846: DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 2847: DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); 2848: DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); 2849: } 2850: 2851: /* Merge the section attribute. 2852: We want to issue an error if the sections conflict but that must be 2853: done later in decl_attributes since we are called before attributes 2854: are assigned. */ 2855: if (DECL_SECTION_NAME (newdecl) == NULL_TREE) 2856: DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); 2857: 2858: /* Keep the old rtl since we can safely use it, unless it's the 2859: call to abort() used for abstract virtuals. */ 2860: if ((DECL_LANG_SPECIFIC (olddecl) 2861: && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) 2862: || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) 2863: DECL_RTL (newdecl) = DECL_RTL (olddecl); 2864: 2865: pop_obstacks (); 2866: } 2867: /* If cannot merge, then use the new type and qualifiers, 2868: and don't preserve the old rtl. */ 2869: else 2870: { 2871: /* Clean out any memory we had of the old declaration. */ 2872: tree oldstatic = value_member (olddecl, static_aggregates); 2873: if (oldstatic) 2874: TREE_VALUE (oldstatic) = error_mark_node; 2875: 2876: TREE_TYPE (olddecl) = TREE_TYPE (newdecl); 2877: TREE_READONLY (olddecl) = TREE_READONLY (newdecl); 2878: TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); 2879: TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); 2880: } 2881: 2882: /* Merge the storage class information. */ 1.1.1.2 ! root 2883: DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); ! 2884: TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); ! 2885: TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl); ! 2886: if (! DECL_EXTERNAL (olddecl)) ! 2887: DECL_EXTERNAL (newdecl) = 0; 1.1 root 2888: 1.1.1.2 ! root 2889: if (TREE_CODE (newdecl) == FUNCTION_DECL) 1.1 root 2890: { 1.1.1.2 ! root 2891: DECL_C_STATIC (newdecl) = DECL_C_STATIC (olddecl); ! 2892: DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl); ! 2893: DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl); 1.1 root 2894: } 2895: 2896: if (TREE_CODE (newdecl) == FUNCTION_DECL) 2897: { 1.1.1.2 ! root 2898: DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl); 1.1 root 2899: 1.1.1.2 ! root 2900: /* If either decl says `inline', this fn is inline, unless its ! 2901: definition was passed already. */ ! 2902: if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE) ! 2903: DECL_INLINE (olddecl) = 1; ! 2904: DECL_INLINE (newdecl) = DECL_INLINE (olddecl); 1.1 root 2905: 2906: if (! types_match) 2907: { 2908: DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl); 2909: DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl); 2910: DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl); 2911: DECL_RESULT (olddecl) = DECL_RESULT (newdecl); 2912: DECL_RTL (olddecl) = DECL_RTL (newdecl); 2913: } 2914: if (new_defines_function) 2915: /* If defining a function declared with other language 2916: linkage, use the previously declared language linkage. */ 2917: DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); 2918: else 2919: { 2920: /* If redeclaring a builtin function, and not a definition, 2921: it stays built in. */ 2922: if (DECL_BUILT_IN (olddecl)) 2923: { 2924: DECL_BUILT_IN (newdecl) = 1; 2925: DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); 2926: /* If we're keeping the built-in definition, keep the rtl, 2927: regardless of declaration matches. */ 2928: DECL_RTL (newdecl) = DECL_RTL (olddecl); 2929: } 2930: else 2931: DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); 2932: 2933: DECL_RESULT (newdecl) = DECL_RESULT (olddecl); 2934: if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))) 2935: /* Previously saved insns go together with 2936: the function's previous definition. */ 2937: DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 2938: /* Don't clear out the arguments if we're redefining a function. */ 2939: if (DECL_ARGUMENTS (olddecl)) 2940: DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); 2941: } 1.1.1.2 ! root 2942: if (DECL_LANG_SPECIFIC (olddecl)) ! 2943: DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl); ! 2944: } ! 2945: ! 2946: if (TREE_CODE (newdecl) == NAMESPACE_DECL) ! 2947: { ! 2948: NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); 1.1 root 2949: } 2950: 2951: if (TREE_CODE (newdecl) == TEMPLATE_DECL) 2952: { 2953: if (DECL_TEMPLATE_INFO (olddecl)->length) 2954: DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); 2955: DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl); 2956: DECL_TEMPLATE_INSTANTIATIONS (newdecl) 2957: = DECL_TEMPLATE_INSTANTIATIONS (olddecl); 2958: if (DECL_CHAIN (newdecl) == NULL_TREE) 2959: DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); 2960: } 2961: 2962: /* Now preserve various other info from the definition. */ 2963: TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); 2964: TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); 2965: DECL_COMMON (newdecl) = DECL_COMMON (olddecl); 2966: DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); 2967: 2968: /* Don't really know how much of the language-specific 2969: values we should copy from old to new. */ 2970: if (DECL_LANG_SPECIFIC (olddecl)) 2971: { 2972: DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); 2973: DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); 1.1.1.2 ! root 2974: DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); 1.1 root 2975: } 2976: 2977: if (TREE_CODE (newdecl) == FUNCTION_DECL) 2978: { 2979: int function_size; 2980: struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); 2981: struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); 2982: 2983: function_size = sizeof (struct tree_decl); 2984: 2985: bcopy ((char *) newdecl + sizeof (struct tree_common), 2986: (char *) olddecl + sizeof (struct tree_common), 2987: function_size - sizeof (struct tree_common)); 2988: 2989: /* Can we safely free the storage used by newdecl? */ 2990: 2991: #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \ 2992: & ~ obstack_alignment_mask (&permanent_obstack)) 2993: 2994: if ((char *)newdecl + ROUND (function_size) 2995: + ROUND (sizeof (struct lang_decl)) 2996: == obstack_next_free (&permanent_obstack)) 2997: { 2998: DECL_MAIN_VARIANT (newdecl) = olddecl; 2999: DECL_LANG_SPECIFIC (olddecl) = ol; 3000: bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); 3001: 3002: obstack_free (&permanent_obstack, newdecl); 3003: } 3004: else if (LANG_DECL_PERMANENT (ol)) 3005: { 3006: if (DECL_MAIN_VARIANT (olddecl) == olddecl) 3007: { 3008: /* Save these lang_decls that would otherwise be lost. */ 3009: extern tree free_lang_decl_chain; 3010: tree free_lang_decl = (tree) ol; 3011: TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; 3012: free_lang_decl_chain = free_lang_decl; 3013: } 3014: else 3015: { 3016: /* Storage leak. */ 3017: } 3018: } 3019: } 3020: else 3021: { 3022: bcopy ((char *) newdecl + sizeof (struct tree_common), 3023: (char *) olddecl + sizeof (struct tree_common), 3024: sizeof (struct tree_decl) - sizeof (struct tree_common) 3025: + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); 3026: } 3027: 3028: DECL_UID (olddecl) = olddecl_uid; 3029: if (olddecl_friend) 3030: DECL_FRIEND_P (olddecl) = 1; 3031: 3032: return 1; 3033: } 3034: 3035: /* Record a decl-node X as belonging to the current lexical scope. 3036: Check for errors (such as an incompatible declaration for the same 3037: name already seen in the same scope). 3038: 3039: Returns either X or an old decl for the same name. 3040: If an old decl is returned, it may have been smashed 3041: to agree with what X says. */ 3042: 3043: tree 3044: pushdecl (x) 3045: tree x; 3046: { 3047: register tree t; 3048: #if 0 /* not yet, should get fixed properly later */ 3049: register tree name; 3050: #else 3051: register tree name = DECL_ASSEMBLER_NAME (x); 3052: #endif 3053: register struct binding_level *b = current_binding_level; 3054: 3055: #if 0 3056: static int nglobals; int len; 3057: 3058: len = list_length (global_binding_level->names); 3059: if (len < nglobals) 3060: my_friendly_abort (8); 3061: else if (len > nglobals) 3062: nglobals = len; 3063: #endif 3064: 3065: if (x != current_function_decl 3066: /* Don't change DECL_CONTEXT of virtual methods. */ 3067: && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x)) 3068: && ! DECL_CONTEXT (x)) 3069: DECL_CONTEXT (x) = current_function_decl; 3070: /* A local declaration for a function doesn't constitute nesting. */ 3071: if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0) 3072: DECL_CONTEXT (x) = 0; 3073: 3074: #if 0 /* not yet, should get fixed properly later */ 3075: /* For functions and class static data, we currently look up the encoded 3076: form of the name. For types, we want the real name. The former will 3077: probably be changed soon, according to MDT. */ 3078: if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) 3079: name = DECL_ASSEMBLER_NAME (x); 3080: else 3081: name = DECL_NAME (x); 3082: #else 3083: /* Type are looked up using the DECL_NAME, as that is what the rest of the 3084: compiler wants to use. */ 1.1.1.2 ! root 3085: if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL ! 3086: || TREE_CODE (x) == NAMESPACE_DECL) 1.1 root 3087: name = DECL_NAME (x); 3088: #endif 3089: 3090: if (name) 3091: { 3092: char *file; 3093: int line; 3094: 3095: t = lookup_name_current_level (name); 3096: if (t == error_mark_node) 3097: { 3098: /* error_mark_node is 0 for a while during initialization! */ 3099: t = NULL_TREE; 3100: cp_error_at ("`%#D' used prior to declaration", x); 3101: } 3102: 3103: else if (t != NULL_TREE) 3104: { 1.1.1.2 ! root 3105: file = DECL_SOURCE_FILE (t); ! 3106: line = DECL_SOURCE_LINE (t); ! 3107: if (TREE_CODE (x) == VAR_DECL && DECL_DEAD_FOR_LOCAL (x)) ! 3108: ; /* This is OK. */ ! 3109: else if (TREE_CODE (t) == PARM_DECL) 1.1 root 3110: { 3111: if (DECL_CONTEXT (t) == NULL_TREE) 3112: fatal ("parse errors have confused me too much"); 3113: } 1.1.1.2 ! root 3114: else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c) 1.1 root 3115: || (TREE_CODE (x) == TEMPLATE_DECL 3116: && ! DECL_TEMPLATE_IS_CLASS (x))) 3117: && is_overloaded_fn (t)) 3118: /* don't do anything just yet */; 1.1.1.2 ! root 3119: else if (t == wchar_decl_node) ! 3120: { ! 3121: if (pedantic && ! DECL_IN_SYSTEM_HEADER (x)) ! 3122: cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x)); ! 3123: ! 3124: /* Throw away the redeclaration. */ ! 3125: return t; ! 3126: } 1.1 root 3127: else if (TREE_CODE (t) != TREE_CODE (x)) 3128: { 3129: if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)) 3130: || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x))) 3131: { 3132: /* We do nothing special here, because C++ does such nasty 3133: things with TYPE_DECLs. Instead, just let the TYPE_DECL 3134: get shadowed, and know that if we need to find a TYPE_DECL 3135: for a given name, we can look in the IDENTIFIER_TYPE_VALUE 3136: slot of the identifier. */ 3137: ; 3138: } 3139: else if (duplicate_decls (x, t)) 3140: return t; 3141: } 3142: else if (duplicate_decls (x, t)) 3143: { 3144: #if 0 3145: /* This is turned off until I have time to do it right (bpk). */ 3146: 3147: /* Also warn if they did a prototype with `static' on it, but 3148: then later left the `static' off. */ 3149: if (! TREE_PUBLIC (name) && TREE_PUBLIC (x)) 3150: { 3151: if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t)) 3152: return t; 3153: 3154: if (extra_warnings) 3155: { 3156: cp_warning ("`static' missing from declaration of `%D'", 3157: t); 3158: warning_with_file_and_line (file, line, 3159: "previous declaration of `%s'", 3160: decl_as_string (t, 0)); 3161: } 3162: 3163: /* Now fix things so it'll do what they expect. */ 3164: if (current_function_decl) 3165: TREE_PUBLIC (current_function_decl) = 0; 3166: } 3167: /* Due to interference in memory reclamation (X may be 3168: obstack-deallocated at this point), we must guard against 3169: one really special case. [jason: This should be handled 3170: by start_function] */ 3171: if (current_function_decl == x) 3172: current_function_decl = t; 3173: #endif 3174: if (TREE_CODE (t) == TYPE_DECL) 3175: SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t)); 1.1.1.2 ! root 3176: else if (TREE_CODE (t) == FUNCTION_DECL) ! 3177: check_default_args (t); 1.1 root 3178: 3179: return t; 3180: } 3181: } 3182: 3183: if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x)) 3184: { 3185: t = push_overloaded_decl (x, 1); 3186: if (t != x || DECL_LANGUAGE (x) == lang_c) 3187: return t; 3188: } 3189: else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x)) 3190: return push_overloaded_decl (x, 0); 3191: 3192: /* If declaring a type as a typedef, and the type has no known 3193: typedef name, install this TYPE_DECL as its typedef name. */ 3194: if (TREE_CODE (x) == TYPE_DECL) 3195: { 3196: tree type = TREE_TYPE (x); 3197: tree name = (type != error_mark_node) ? TYPE_NAME (type) : x; 3198: 3199: if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL) 3200: { 3201: /* If these are different names, and we're at the global 3202: binding level, make two equivalent definitions. */ 3203: name = x; 3204: if (global_bindings_p ()) 3205: TYPE_NAME (type) = x; 3206: } 3207: else 3208: { 3209: tree tname = DECL_NAME (name); 3210: 1.1.1.2 ! root 3211: /* This is a disgusting kludge for dealing with UPTs. */ 1.1 root 3212: if (global_bindings_p () && ANON_AGGRNAME_P (tname)) 3213: { 3214: /* do gratuitous C++ typedefing, and make sure that 3215: we access this type either through TREE_TYPE field 3216: or via the tags list. */ 3217: TYPE_NAME (TREE_TYPE (x)) = x; 3218: pushtag (tname, TREE_TYPE (x), 0); 3219: } 3220: } 3221: my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140); 3222: 1.1.1.2 ! root 3223: /* Don't set nested_typename on template type parms, for instance. ! 3224: Any artificial decls that need DECL_NESTED_TYPENAME will have it ! 3225: set in pushtag. */ ! 3226: if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x)) ! 3227: set_nested_typename (x, current_class_name, DECL_NAME (x), type); 1.1 root 3228: 3229: if (type != error_mark_node 3230: && TYPE_NAME (type) 3231: && TYPE_IDENTIFIER (type)) 3232: set_identifier_type_value_with_scope (DECL_NAME (x), type, b); 3233: } 3234: 3235: /* Multiple external decls of the same identifier ought to match. 3236: 3237: We get warnings about inline functions where they are defined. 3238: We get warnings about other functions from push_overloaded_decl. 3239: 3240: Avoid duplicate warnings where they are used. */ 3241: if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL) 3242: { 3243: tree decl; 3244: 3245: if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE 3246: && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) 3247: || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))) 3248: decl = IDENTIFIER_GLOBAL_VALUE (name); 3249: else 3250: decl = NULL_TREE; 3251: 3252: if (decl 3253: /* If different sort of thing, we already gave an error. */ 3254: && TREE_CODE (decl) == TREE_CODE (x) 3255: && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1)) 3256: { 3257: cp_pedwarn ("type mismatch with previous external decl", x); 3258: cp_pedwarn_at ("previous external decl of `%#D'", decl); 3259: } 3260: } 3261: 3262: /* In PCC-compatibility mode, extern decls of vars with no current decl 3263: take effect at top level no matter where they are. */ 3264: if (flag_traditional && DECL_EXTERNAL (x) 3265: && lookup_name (name, 0) == NULL_TREE) 3266: b = global_binding_level; 3267: 3268: /* This name is new in its binding level. 3269: Install the new declaration and return it. */ 3270: if (b == global_binding_level) 3271: { 3272: /* Install a global value. */ 3273: 3274: /* If the first global decl has external linkage, 3275: warn if we later see static one. */ 1.1.1.2 ! root 3276: if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x)) 1.1 root 3277: TREE_PUBLIC (name) = 1; 3278: 1.1.1.2 ! root 3279: /* Don't install an artificial TYPE_DECL if we already have ! 3280: another _DECL with that name. */ 1.1 root 3281: if (TREE_CODE (x) != TYPE_DECL 3282: || t == NULL_TREE 1.1.1.2 ! root 3283: || ! DECL_ARTIFICIAL (x)) 1.1 root 3284: IDENTIFIER_GLOBAL_VALUE (name) = x; 3285: 3286: /* Don't forget if the function was used via an implicit decl. */ 3287: if (IDENTIFIER_IMPLICIT_DECL (name) 3288: && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) 3289: TREE_USED (x) = 1; 3290: 3291: /* Don't forget if its address was taken in that way. */ 3292: if (IDENTIFIER_IMPLICIT_DECL (name) 3293: && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) 3294: TREE_ADDRESSABLE (x) = 1; 3295: 3296: /* Warn about mismatches against previous implicit decl. */ 3297: if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE 3298: /* If this real decl matches the implicit, don't complain. */ 3299: && ! (TREE_CODE (x) == FUNCTION_DECL 3300: && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) 3301: cp_warning 3302: ("`%D' was previously implicitly declared to return `int'", x); 3303: 3304: /* If new decl is `static' and an `extern' was seen previously, 3305: warn about it. */ 3306: if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t)) 3307: warn_extern_redeclared_static (x, t); 3308: } 3309: else 3310: { 3311: /* Here to install a non-global value. */ 3312: tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); 3313: tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); 3314: 1.1.1.2 ! root 3315: /* Don't install an artificial TYPE_DECL if we already have ! 3316: another _DECL with that name. */ ! 3317: if (TREE_CODE (x) != TYPE_DECL ! 3318: || t == NULL_TREE ! 3319: || ! DECL_ARTIFICIAL (x)) ! 3320: { ! 3321: b->shadowed = tree_cons (name, oldlocal, b->shadowed); ! 3322: IDENTIFIER_LOCAL_VALUE (name) = x; ! 3323: } 1.1 root 3324: 3325: /* If this is a TYPE_DECL, push it into the type value slot. */ 3326: if (TREE_CODE (x) == TYPE_DECL) 3327: set_identifier_type_value_with_scope (name, TREE_TYPE (x), b); 3328: 1.1.1.2 ! root 3329: /* Clear out any TYPE_DECL shadowed by a namespace so that ! 3330: we won't think this is a type. The C struct hack doesn't ! 3331: go through namespaces. */ ! 3332: if (TREE_CODE (x) == NAMESPACE_DECL) ! 3333: set_identifier_type_value_with_scope (name, NULL_TREE, b); ! 3334: 1.1 root 3335: /* If this is an extern function declaration, see if we 3336: have a global definition or declaration for the function. */ 3337: if (oldlocal == NULL_TREE 1.1.1.2 ! root 3338: && DECL_EXTERNAL (x) 1.1 root 3339: && oldglobal != NULL_TREE 3340: && TREE_CODE (x) == FUNCTION_DECL 3341: && TREE_CODE (oldglobal) == FUNCTION_DECL) 3342: { 3343: /* We have one. Their types must agree. */ 1.1.1.2 ! root 3344: if (decls_match (x, oldglobal)) ! 3345: /* OK */; ! 3346: else 1.1 root 3347: { 3348: cp_warning ("extern declaration of `%#D' doesn't match", x); 3349: cp_warning_at ("global declaration `%#D'", oldglobal); 3350: } 3351: } 3352: /* If we have a local external declaration, 3353: and no file-scope declaration has yet been seen, 3354: then if we later have a file-scope decl it must not be static. */ 3355: if (oldlocal == NULL_TREE 3356: && oldglobal == NULL_TREE 3357: && DECL_EXTERNAL (x) 3358: && TREE_PUBLIC (x)) 3359: { 3360: TREE_PUBLIC (name) = 1; 3361: } 3362: 3363: if (DECL_FROM_INLINE (x)) 3364: /* Inline decls shadow nothing. */; 3365: 3366: /* Warn if shadowing an argument at the top level of the body. */ 3367: else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) 3368: && TREE_CODE (oldlocal) == PARM_DECL 3369: && TREE_CODE (x) != PARM_DECL) 3370: { 3371: /* Go to where the parms should be and see if we 3372: find them there. */ 3373: struct binding_level *b = current_binding_level->level_chain; 3374: 3375: if (cleanup_label) 3376: b = b->level_chain; 3377: 3378: /* ARM $8.3 */ 3379: if (b->parm_flag == 1) 3380: cp_error ("declaration of `%#D' shadows a parameter", name); 3381: } 1.1.1.2 ! root 3382: else if (oldlocal != NULL_TREE && b->is_for_scope ! 3383: && !DECL_DEAD_FOR_LOCAL (oldlocal)) ! 3384: { ! 3385: warning ("variable `%s' shadows local", ! 3386: IDENTIFIER_POINTER (name)); ! 3387: cp_warning_at (" this is the shadowed declaration", oldlocal); ! 3388: } 1.1 root 3389: /* Maybe warn if shadowing something else. */ 3390: else if (warn_shadow && !DECL_EXTERNAL (x) 3391: /* No shadow warnings for internally generated vars. */ 3392: && ! DECL_ARTIFICIAL (x) 3393: /* No shadow warnings for vars made for inlining. */ 3394: && ! DECL_FROM_INLINE (x)) 3395: { 3396: char *warnstring = NULL; 3397: 3398: if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) 3399: warnstring = "declaration of `%s' shadows a parameter"; 3400: else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE 1.1.1.2 ! root 3401: && current_class_decl 1.1 root 3402: && !TREE_STATIC (name)) 3403: warnstring = "declaration of `%s' shadows a member of `this'"; 3404: else if (oldlocal != NULL_TREE) 3405: warnstring = "declaration of `%s' shadows previous local"; 3406: else if (oldglobal != NULL_TREE) 3407: warnstring = "declaration of `%s' shadows global declaration"; 3408: 3409: if (warnstring) 3410: warning (warnstring, IDENTIFIER_POINTER (name)); 3411: } 3412: } 3413: 1.1.1.2 ! root 3414: if (TREE_CODE (x) == FUNCTION_DECL) ! 3415: check_default_args (x); 1.1 root 3416: 1.1.1.2 ! root 3417: /* Keep count of variables in this level with incomplete type. */ ! 3418: if (TREE_CODE (x) == VAR_DECL ! 3419: && TREE_TYPE (x) != error_mark_node ! 3420: && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE ! 3421: && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) ! 3422: /* RTTI TD entries are created while defining the type_info. */ ! 3423: || (TYPE_LANG_SPECIFIC (TREE_TYPE (x)) ! 3424: && TYPE_BEING_DEFINED (TREE_TYPE (x))))) ! 3425: b->incomplete = tree_cons (NULL_TREE, x, b->incomplete); 1.1 root 3426: } 3427: 3428: /* Put decls on list in reverse order. 3429: We will reverse them later if necessary. */ 3430: TREE_CHAIN (x) = b->names; 3431: b->names = x; 3432: if (! (b != global_binding_level || TREE_PERMANENT (x))) 3433: my_friendly_abort (124); 3434: 3435: return x; 3436: } 3437: 3438: /* Same as pushdecl, but define X in binding-level LEVEL. */ 3439: 3440: static tree 3441: pushdecl_with_scope (x, level) 3442: tree x; 3443: struct binding_level *level; 3444: { 3445: register struct binding_level *b = current_binding_level; 3446: 3447: current_binding_level = level; 3448: x = pushdecl (x); 3449: current_binding_level = b; 3450: return x; 3451: } 3452: 3453: /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, 3454: if appropriate. */ 3455: tree 3456: pushdecl_top_level (x) 3457: tree x; 3458: { 3459: register struct binding_level *b = inner_binding_level; 3460: register tree t = pushdecl_with_scope (x, global_binding_level); 3461: 3462: /* Now, the type_shadowed stack may screw us. Munge it so it does 3463: what we want. */ 3464: if (TREE_CODE (x) == TYPE_DECL) 3465: { 3466: tree name = DECL_NAME (x); 3467: tree newval; 3468: tree *ptr = (tree *)0; 3469: for (; b != global_binding_level; b = b->level_chain) 3470: { 3471: tree shadowed = b->type_shadowed; 3472: for (; shadowed; shadowed = TREE_CHAIN (shadowed)) 3473: if (TREE_PURPOSE (shadowed) == name) 3474: { 3475: ptr = &TREE_VALUE (shadowed); 3476: /* Can't break out of the loop here because sometimes 3477: a binding level will have duplicate bindings for 3478: PT names. It's gross, but I haven't time to fix it. */ 3479: } 3480: } 3481: newval = TREE_TYPE (x); 3482: if (ptr == (tree *)0) 3483: { 3484: /* @@ This shouldn't be needed. My test case "zstring.cc" trips 3485: up here if this is changed to an assertion. --KR */ 3486: SET_IDENTIFIER_TYPE_VALUE (name, newval); 3487: } 3488: else 3489: { 3490: #if 0 3491: /* Disabled this 11/10/92, since there are many cases which 3492: behave just fine when *ptr doesn't satisfy either of these. 3493: For example, nested classes declared as friends of their enclosing 3494: class will not meet this criteria. (bpk) */ 3495: my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141); 3496: #endif 3497: *ptr = newval; 3498: } 3499: } 3500: return t; 3501: } 3502: 3503: /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL, 3504: if appropriate. */ 3505: void 3506: push_overloaded_decl_top_level (x, forget) 3507: tree x; 3508: int forget; 3509: { 3510: struct binding_level *b = current_binding_level; 3511: 3512: current_binding_level = global_binding_level; 3513: push_overloaded_decl (x, forget); 3514: current_binding_level = b; 3515: } 3516: 3517: /* Make the declaration of X appear in CLASS scope. */ 3518: tree 3519: pushdecl_class_level (x) 3520: tree x; 3521: { 3522: /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class 3523: scope looks for the pre-mangled name. */ 3524: register tree name = DECL_NAME (x); 3525: 3526: if (name) 3527: { 3528: if (TYPE_BEING_DEFINED (current_class_type)) 3529: { 3530: /* Check for inconsistent use of this name in the class body. 3531: Types, enums, and static vars are checked here; other 3532: members are checked in finish_struct. */ 3533: tree icv = IDENTIFIER_CLASS_VALUE (name); 3534: 3535: if (icv 3536: /* Don't complain about inherited names. */ 3537: && id_in_current_class (name) 3538: /* Or shadowed tags. */ 3539: && !(TREE_CODE (icv) == TYPE_DECL 3540: && DECL_CONTEXT (icv) == current_class_type)) 3541: { 3542: cp_error ("declaration of identifier `%D' as `%#D'", name, x); 3543: cp_error_at ("conflicts with previous use in class as `%#D'", 3544: icv); 3545: } 3546: } 3547: 3548: push_class_level_binding (name, x); 3549: if (TREE_CODE (x) == TYPE_DECL) 3550: { 3551: set_identifier_type_value (name, TREE_TYPE (x)); 1.1.1.2 ! root 3552: ! 3553: /* Don't set nested_typename on template type parms, for instance. ! 3554: Any artificial decls that need DECL_NESTED_TYPENAME will have it ! 3555: set in pushtag. */ ! 3556: if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x)) 1.1 root 3557: set_nested_typename (x, current_class_name, name, TREE_TYPE (x)); 3558: } 3559: } 3560: return x; 3561: } 3562: 3563: /* This function is used to push the mangled decls for nested types into 3564: the appropriate scope. Previously pushdecl_top_level was used, but that 3565: is incorrect for members of local classes. */ 3566: tree 3567: pushdecl_nonclass_level (x) 3568: tree x; 3569: { 3570: struct binding_level *b = current_binding_level; 3571: 3572: #if 0 3573: /* Get out of class scope -- this isn't necessary, because class scope 3574: doesn't make it into current_binding_level. */ 3575: while (b->parm_flag == 2) 3576: b = b->level_chain; 3577: #else 3578: my_friendly_assert (b->parm_flag != 2, 180); 3579: #endif 3580: 3581: /* Get out of template binding levels */ 3582: while (b->pseudo_global) 3583: b = b->level_chain; 3584: 3585: pushdecl_with_scope (x, b); 3586: } 3587: 3588: /* Make the declaration(s) of X appear in CLASS scope 3589: under the name NAME. */ 3590: void 3591: push_class_level_binding (name, x) 3592: tree name; 3593: tree x; 3594: { 1.1.1.2 ! root 3595: if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) ! 3596: && purpose_member (name, class_binding_level->class_shadowed)) ! 3597: return; ! 3598: 1.1 root 3599: maybe_push_cache_obstack (); 3600: class_binding_level->class_shadowed 3601: = tree_cons (name, IDENTIFIER_CLASS_VALUE (name), 3602: class_binding_level->class_shadowed); 3603: pop_obstacks (); 3604: IDENTIFIER_CLASS_VALUE (name) = x; 3605: obstack_ptr_grow (&decl_obstack, x); 3606: } 3607: 3608: /* Tell caller how to interpret a TREE_LIST which contains 3609: chains of FUNCTION_DECLS. */ 3610: int 3611: overloaded_globals_p (list) 3612: tree list; 3613: { 3614: my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142); 3615: 3616: /* Don't commit caller to seeing them as globals. */ 3617: if (TREE_NONLOCAL_FLAG (list)) 3618: return -1; 3619: /* Do commit caller to seeing them as globals. */ 3620: if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE) 3621: return 1; 3622: /* Do commit caller to not seeing them as globals. */ 3623: return 0; 3624: } 3625: 3626: /* DECL is a FUNCTION_DECL which may have other definitions already in 3627: place. We get around this by making the value of the identifier point 3628: to a list of all the things that want to be referenced by that name. It 3629: is then up to the users of that name to decide what to do with that 3630: list. 3631: 3632: DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT 3633: slot. It is dealt with the same way. 3634: 3635: The value returned may be a previous declaration if we guessed wrong 3636: about what language DECL should belong to (C or C++). Otherwise, 3637: it's always DECL (and never something that's not a _DECL). */ 3638: tree 3639: push_overloaded_decl (decl, forgettable) 3640: tree decl; 3641: int forgettable; 3642: { 3643: tree orig_name = DECL_NAME (decl); 3644: tree old; 3645: int doing_global = (global_bindings_p () || ! forgettable 3646: || flag_traditional || pseudo_global_level_p ()); 3647: 3648: if (doing_global) 3649: { 3650: old = IDENTIFIER_GLOBAL_VALUE (orig_name); 3651: if (old && TREE_CODE (old) == FUNCTION_DECL 3652: && DECL_ARTIFICIAL (old) 3653: && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old))) 3654: { 3655: if (duplicate_decls (decl, old)) 3656: return old; 3657: old = NULL_TREE; 3658: } 3659: } 3660: else 3661: { 3662: old = IDENTIFIER_LOCAL_VALUE (orig_name); 3663: 3664: if (! purpose_member (orig_name, current_binding_level->shadowed)) 3665: { 3666: current_binding_level->shadowed 3667: = tree_cons (orig_name, old, current_binding_level->shadowed); 3668: old = NULL_TREE; 3669: } 3670: } 3671: 3672: if (old) 3673: { 3674: #if 0 3675: /* We cache the value of builtin functions as ADDR_EXPRs 3676: in the name space. Convert it to some kind of _DECL after 3677: remembering what to forget. */ 3678: if (TREE_CODE (old) == ADDR_EXPR) 3679: old = TREE_OPERAND (old, 0); 3680: else 3681: #endif 1.1.1.2 ! root 3682: if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) 1.1 root 3683: { 3684: tree t = TREE_TYPE (old); 3685: if (IS_AGGR_TYPE (t) && warn_shadow) 3686: cp_warning ("`%#D' hides constructor for `%#T'", decl, t); 3687: old = NULL_TREE; 3688: } 3689: else if (is_overloaded_fn (old)) 3690: { 3691: tree tmp; 3692: 3693: for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp)) 3694: if (decl == tmp || duplicate_decls (decl, tmp)) 3695: return tmp; 3696: } 1.1.1.2 ! root 3697: else ! 3698: { ! 3699: cp_error_at ("previous non-function declaration `%#D'", old); ! 3700: cp_error ("conflicts with function declaration `%#D'", decl); ! 3701: return decl; ! 3702: } 1.1 root 3703: } 3704: 3705: if (old || TREE_CODE (decl) == TEMPLATE_DECL) 3706: { 3707: if (old && is_overloaded_fn (old)) 3708: DECL_CHAIN (decl) = get_first_fn (old); 3709: else 3710: DECL_CHAIN (decl) = NULL_TREE; 3711: old = tree_cons (orig_name, decl, NULL_TREE); 3712: TREE_TYPE (old) = unknown_type_node; 3713: } 3714: else 3715: /* orig_name is not ambiguous. */ 3716: old = decl; 3717: 3718: if (doing_global) 3719: IDENTIFIER_GLOBAL_VALUE (orig_name) = old; 3720: else 3721: IDENTIFIER_LOCAL_VALUE (orig_name) = old; 3722: 3723: return decl; 3724: } 3725: 3726: /* Generate an implicit declaration for identifier FUNCTIONID 3727: as a function of type int (). Print a warning if appropriate. */ 3728: 3729: tree 3730: implicitly_declare (functionid) 3731: tree functionid; 3732: { 3733: register tree decl; 3734: int temp = allocation_temporary_p (); 3735: 3736: push_obstacks_nochange (); 3737: 3738: /* Save the decl permanently so we can warn if definition follows. 3739: In ANSI C, warn_implicit is usually false, so the saves little space. 3740: But in C++, it's usually true, hence the extra code. */ 1.1.1.2 ! root 3741: if (temp && (flag_traditional || !warn_implicit || toplevel_bindings_p ())) 1.1 root 3742: end_temporary_allocation (); 3743: 3744: /* We used to reuse an old implicit decl here, 3745: but this loses with inline functions because it can clobber 3746: the saved decl chains. */ 3747: decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type); 3748: 3749: DECL_EXTERNAL (decl) = 1; 3750: TREE_PUBLIC (decl) = 1; 3751: 3752: /* ANSI standard says implicit declarations are in the innermost block. 3753: So we record the decl in the standard fashion. 3754: If flag_traditional is set, pushdecl does it top-level. */ 3755: pushdecl (decl); 3756: rest_of_decl_compilation (decl, NULL_PTR, 0, 0); 3757: 3758: if (warn_implicit 3759: /* Only one warning per identifier. */ 3760: && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) 3761: { 3762: cp_pedwarn ("implicit declaration of function `%#D'", decl); 3763: } 3764: 3765: SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); 3766: 3767: pop_obstacks (); 3768: 3769: return decl; 3770: } 3771: 3772: /* Return zero if the declaration NEWDECL is valid 3773: when the declaration OLDDECL (assumed to be for the same name) 3774: has already been seen. 3775: Otherwise return an error message format string with a %s 3776: where the identifier should go. */ 3777: 3778: static char * 3779: redeclaration_error_message (newdecl, olddecl) 3780: tree newdecl, olddecl; 3781: { 3782: if (TREE_CODE (newdecl) == TYPE_DECL) 3783: { 3784: /* Because C++ can put things into name space for free, 3785: constructs like "typedef struct foo { ... } foo" 3786: would look like an erroneous redeclaration. */ 3787: if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0)) 3788: return 0; 3789: else 3790: return "redefinition of `%#D'"; 3791: } 3792: else if (TREE_CODE (newdecl) == FUNCTION_DECL) 3793: { 3794: /* If this is a pure function, its olddecl will actually be 3795: the original initialization to `0' (which we force to call 3796: abort()). Don't complain about redefinition in this case. */ 3797: if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) 3798: return 0; 3799: 1.1.1.2 ! root 3800: /* We'll complain about linkage mismatches in ! 3801: warn_extern_redeclared_static. */ ! 3802: ! 3803: /* defining the same name twice is no good. */ 1.1 root 3804: if (DECL_INITIAL (olddecl) != NULL_TREE 1.1.1.2 ! root 3805: && DECL_INITIAL (newdecl) != NULL_TREE) 1.1 root 3806: { 3807: if (DECL_NAME (olddecl) == NULL_TREE) 3808: return "`%#D' not declared in class"; 3809: else 3810: return "redefinition of `%#D'"; 3811: } 3812: return 0; 3813: } 3814: else if (TREE_CODE (newdecl) == TEMPLATE_DECL) 3815: { 3816: if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl)) 3817: return "redefinition of `%#D'"; 3818: return 0; 3819: } 3820: else if (current_binding_level == global_binding_level) 3821: { 3822: /* Objects declared at top level: */ 3823: /* If at least one is a reference, it's ok. */ 3824: if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) 3825: return 0; 3826: /* Reject two definitions. */ 3827: return "redefinition of `%#D'"; 3828: } 3829: else 3830: { 3831: /* Objects declared with block scope: */ 3832: /* Reject two definitions, and reject a definition 3833: together with an external reference. */ 3834: if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))) 3835: return "redeclaration of `%#D'"; 3836: return 0; 3837: } 3838: } 3839: 3840: /* Get the LABEL_DECL corresponding to identifier ID as a label. 3841: Create one if none exists so far for the current function. 3842: This function is called for both label definitions and label references. */ 3843: 3844: tree 3845: lookup_label (id) 3846: tree id; 3847: { 3848: register tree decl = IDENTIFIER_LABEL_VALUE (id); 3849: 3850: if (current_function_decl == NULL_TREE) 3851: { 3852: error ("label `%s' referenced outside of any function", 3853: IDENTIFIER_POINTER (id)); 3854: return NULL_TREE; 3855: } 3856: 3857: if ((decl == NULL_TREE 3858: || DECL_SOURCE_LINE (decl) == 0) 3859: && (named_label_uses == NULL_TREE 3860: || TREE_PURPOSE (named_label_uses) != current_binding_level->names 3861: || TREE_VALUE (named_label_uses) != decl)) 3862: { 3863: named_label_uses 3864: = tree_cons (current_binding_level->names, decl, named_label_uses); 3865: TREE_TYPE (named_label_uses) = (tree)current_binding_level; 3866: } 3867: 3868: /* Use a label already defined or ref'd with this name. */ 3869: if (decl != NULL_TREE) 3870: { 3871: /* But not if it is inherited and wasn't declared to be inheritable. */ 3872: if (DECL_CONTEXT (decl) != current_function_decl 3873: && ! C_DECLARED_LABEL_FLAG (decl)) 3874: return shadow_label (id); 3875: return decl; 3876: } 3877: 3878: decl = build_decl (LABEL_DECL, id, void_type_node); 3879: 3880: /* A label not explicitly declared must be local to where it's ref'd. */ 3881: DECL_CONTEXT (decl) = current_function_decl; 3882: 3883: DECL_MODE (decl) = VOIDmode; 3884: 3885: /* Say where one reference is to the label, 3886: for the sake of the error if it is not defined. */ 3887: DECL_SOURCE_LINE (decl) = lineno; 3888: DECL_SOURCE_FILE (decl) = input_filename; 3889: 3890: SET_IDENTIFIER_LABEL_VALUE (id, decl); 3891: 3892: named_labels = tree_cons (NULL_TREE, decl, named_labels); 3893: TREE_VALUE (named_label_uses) = decl; 3894: 3895: return decl; 3896: } 3897: 3898: /* Make a label named NAME in the current function, 3899: shadowing silently any that may be inherited from containing functions 3900: or containing scopes. 3901: 3902: Note that valid use, if the label being shadowed 3903: comes from another scope in the same function, 3904: requires calling declare_nonlocal_label right away. */ 3905: 3906: tree 3907: shadow_label (name) 3908: tree name; 3909: { 3910: register tree decl = IDENTIFIER_LABEL_VALUE (name); 3911: 3912: if (decl != NULL_TREE) 3913: { 3914: shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); 3915: SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); 3916: SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE); 3917: } 3918: 3919: return lookup_label (name); 3920: } 3921: 3922: /* Define a label, specifying the location in the source file. 3923: Return the LABEL_DECL node for the label, if the definition is valid. 3924: Otherwise return 0. */ 3925: 3926: tree 3927: define_label (filename, line, name) 3928: char *filename; 3929: int line; 3930: tree name; 3931: { 3932: tree decl = lookup_label (name); 3933: 3934: /* After labels, make any new cleanups go into their 3935: own new (temporary) binding contour. */ 3936: current_binding_level->more_cleanups_ok = 0; 3937: 3938: /* If label with this name is known from an outer context, shadow it. */ 3939: if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) 3940: { 3941: shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); 3942: SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); 3943: decl = lookup_label (name); 3944: } 3945: 1.1.1.2 ! root 3946: if (name == get_identifier ("wchar_t")) ! 3947: cp_pedwarn ("label named wchar_t"); ! 3948: 1.1 root 3949: if (DECL_INITIAL (decl) != NULL_TREE) 3950: { 3951: cp_error ("duplicate label `%D'", decl); 3952: return 0; 3953: } 3954: else 3955: { 3956: tree uses, prev; 1.1.1.2 ! root 3957: int identified = 0; 1.1 root 3958: 3959: /* Mark label as having been defined. */ 3960: DECL_INITIAL (decl) = error_mark_node; 3961: /* Say where in the source. */ 3962: DECL_SOURCE_FILE (decl) = filename; 3963: DECL_SOURCE_LINE (decl) = line; 3964: 3965: for (prev = NULL_TREE, uses = named_label_uses; 3966: uses; 3967: prev = uses, uses = TREE_CHAIN (uses)) 3968: if (TREE_VALUE (uses) == decl) 3969: { 3970: struct binding_level *b = current_binding_level; 3971: while (b) 3972: { 3973: tree new_decls = b->names; 3974: tree old_decls = ((tree)b == TREE_TYPE (uses) 3975: ? TREE_PURPOSE (uses) : NULL_TREE); 3976: while (new_decls != old_decls) 3977: { 3978: if (TREE_CODE (new_decls) == VAR_DECL 3979: /* Don't complain about crossing initialization 3980: of internal entities. They can't be accessed, 3981: and they should be cleaned up 3982: by the time we get to the label. */ 3983: && ! DECL_ARTIFICIAL (new_decls) 3984: && ((DECL_INITIAL (new_decls) != NULL_TREE 3985: && DECL_INITIAL (new_decls) != error_mark_node) 3986: || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) 3987: { 1.1.1.2 ! root 3988: if (! identified) ! 3989: cp_error ("jump to label `%D'", decl); ! 3990: identified = 1; ! 3991: cp_error_at (" crosses initialization of `%#D'", ! 3992: new_decls); 1.1 root 3993: } 3994: new_decls = TREE_CHAIN (new_decls); 3995: } 3996: if ((tree)b == TREE_TYPE (uses)) 3997: break; 3998: b = b->level_chain; 3999: } 4000: 4001: if (prev) 4002: TREE_CHAIN (prev) = TREE_CHAIN (uses); 4003: else 4004: named_label_uses = TREE_CHAIN (uses); 4005: } 4006: current_function_return_value = NULL_TREE; 4007: return decl; 4008: } 4009: } 4010: 1.1.1.2 ! root 4011: struct cp_switch ! 4012: { ! 4013: struct binding_level *level; ! 4014: struct cp_switch *next; ! 4015: }; ! 4016: ! 4017: static struct cp_switch *switch_stack; ! 4018: ! 4019: void ! 4020: push_switch () ! 4021: { ! 4022: struct cp_switch *p ! 4023: = (struct cp_switch *) oballoc (sizeof (struct cp_switch)); ! 4024: p->level = current_binding_level; ! 4025: p->next = switch_stack; ! 4026: switch_stack = p; ! 4027: } ! 4028: ! 4029: void ! 4030: pop_switch () ! 4031: { ! 4032: switch_stack = switch_stack->next; ! 4033: } ! 4034: 1.1 root 4035: /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ 4036: /* XXX Note decl is never actually used. (bpk) */ 4037: void 4038: define_case_label (decl) 4039: tree decl; 4040: { 4041: tree cleanup = last_cleanup_this_contour (); 1.1.1.2 ! root 4042: struct binding_level *b = current_binding_level; ! 4043: int identified = 0; ! 4044: 1.1 root 4045: if (cleanup) 4046: { 4047: static int explained = 0; 1.1.1.2 ! root 4048: cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); ! 4049: warning ("where case label appears here"); 1.1 root 4050: if (!explained) 4051: { 1.1.1.2 ! root 4052: warning ("(enclose actions of previous case statements requiring"); ! 4053: warning ("destructors in their own binding contours.)"); 1.1 root 4054: explained = 1; 4055: } 4056: } 4057: 1.1.1.2 ! root 4058: for (; b && b != switch_stack->level; b = b->level_chain) ! 4059: { ! 4060: tree new_decls = b->names; ! 4061: for (; new_decls; new_decls = TREE_CHAIN (new_decls)) ! 4062: { ! 4063: if (TREE_CODE (new_decls) == VAR_DECL ! 4064: /* Don't complain about crossing initialization ! 4065: of internal entities. They can't be accessed, ! 4066: and they should be cleaned up ! 4067: by the time we get to the label. */ ! 4068: && ! DECL_ARTIFICIAL (new_decls) ! 4069: && ((DECL_INITIAL (new_decls) != NULL_TREE ! 4070: && DECL_INITIAL (new_decls) != error_mark_node) ! 4071: || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) ! 4072: { ! 4073: if (! identified) ! 4074: error ("jump to case label"); ! 4075: identified = 1; ! 4076: cp_error_at (" crosses initialization of `%#D'", ! 4077: new_decls); ! 4078: } ! 4079: } ! 4080: } ! 4081: 1.1 root 4082: /* After labels, make any new cleanups go into their 4083: own new (temporary) binding contour. */ 4084: 4085: current_binding_level->more_cleanups_ok = 0; 4086: current_function_return_value = NULL_TREE; 4087: } 4088: 4089: /* Return the list of declarations of the current level. 4090: Note that this list is in reverse order unless/until 4091: you nreverse it; and when you do nreverse it, you must 4092: store the result back using `storedecls' or you will lose. */ 4093: 4094: tree 4095: getdecls () 4096: { 4097: return current_binding_level->names; 4098: } 4099: 4100: /* Return the list of type-tags (for structs, etc) of the current level. */ 4101: 4102: tree 4103: gettags () 4104: { 4105: return current_binding_level->tags; 4106: } 4107: 4108: /* Store the list of declarations of the current level. 4109: This is done for the parameter declarations of a function being defined, 4110: after they are modified in the light of any missing parameters. */ 4111: 4112: static void 4113: storedecls (decls) 4114: tree decls; 4115: { 4116: current_binding_level->names = decls; 4117: } 4118: 4119: /* Similarly, store the list of tags of the current level. */ 4120: 4121: static void 4122: storetags (tags) 4123: tree tags; 4124: { 4125: current_binding_level->tags = tags; 4126: } 4127: 4128: /* Given NAME, an IDENTIFIER_NODE, 4129: return the structure (or union or enum) definition for that name. 4130: Searches binding levels from BINDING_LEVEL up to the global level. 4131: If THISLEVEL_ONLY is nonzero, searches only the specified context 4132: (but skips any tag-transparent contexts to find one that is 4133: meaningful for tags). 4134: FORM says which kind of type the caller wants; 4135: it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. 4136: If the wrong kind of type is found, and it's not a template, an error is 4137: reported. */ 4138: 4139: static tree 4140: lookup_tag (form, name, binding_level, thislevel_only) 4141: enum tree_code form; 4142: struct binding_level *binding_level; 4143: tree name; 4144: int thislevel_only; 4145: { 4146: register struct binding_level *level; 4147: 4148: for (level = binding_level; level; level = level->level_chain) 4149: { 4150: register tree tail; 4151: if (ANON_AGGRNAME_P (name)) 4152: for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) 4153: { 4154: /* There's no need for error checking here, because 4155: anon names are unique throughout the compilation. */ 4156: if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) 4157: return TREE_VALUE (tail); 4158: } 4159: else 4160: for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) 4161: { 4162: if (TREE_PURPOSE (tail) == name) 4163: { 4164: enum tree_code code = TREE_CODE (TREE_VALUE (tail)); 4165: /* Should tighten this up; it'll probably permit 4166: UNION_TYPE and a struct template, for example. */ 4167: if (code != form 4168: && !(form != ENUMERAL_TYPE 4169: && (code == TEMPLATE_DECL 4170: || code == UNINSTANTIATED_P_TYPE))) 4171: 4172: { 4173: /* Definition isn't the kind we were looking for. */ 4174: cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), 4175: form); 4176: } 4177: return TREE_VALUE (tail); 4178: } 4179: } 4180: if (thislevel_only && ! level->tag_transparent) 4181: return NULL_TREE; 4182: if (current_class_type && level->level_chain == global_binding_level) 4183: { 4184: /* Try looking in this class's tags before heading into 4185: global binding level. */ 4186: tree context = current_class_type; 4187: while (context) 4188: { 4189: switch (TREE_CODE_CLASS (TREE_CODE (context))) 4190: { 4191: tree these_tags; 4192: case 't': 4193: these_tags = CLASSTYPE_TAGS (context); 4194: if (ANON_AGGRNAME_P (name)) 4195: while (these_tags) 4196: { 4197: if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) 4198: == name) 4199: return TREE_VALUE (tail); 4200: these_tags = TREE_CHAIN (these_tags); 4201: } 4202: else 4203: while (these_tags) 4204: { 4205: if (TREE_PURPOSE (these_tags) == name) 4206: { 4207: if (TREE_CODE (TREE_VALUE (these_tags)) != form) 4208: { 4209: cp_error ("`%#D' redeclared as %C in class scope", 4210: TREE_VALUE (tail), form); 4211: } 4212: return TREE_VALUE (tail); 4213: } 4214: these_tags = TREE_CHAIN (these_tags); 4215: } 4216: /* If this type is not yet complete, then don't 4217: look at its context. */ 4218: if (TYPE_SIZE (context) == NULL_TREE) 4219: goto no_context; 4220: /* Go to next enclosing type, if any. */ 4221: context = DECL_CONTEXT (TYPE_NAME (context)); 4222: break; 4223: case 'd': 4224: context = DECL_CONTEXT (context); 4225: break; 4226: default: 4227: my_friendly_abort (10); 4228: } 4229: continue; 4230: no_context: 4231: break; 4232: } 4233: } 4234: } 4235: return NULL_TREE; 4236: } 4237: 4238: void 4239: set_current_level_tags_transparency (tags_transparent) 4240: int tags_transparent; 4241: { 4242: current_binding_level->tag_transparent = tags_transparent; 4243: } 4244: 4245: /* Given a type, find the tag that was defined for it and return the tag name. 4246: Otherwise return 0. However, the value can never be 0 4247: in the cases in which this is used. 4248: 4249: C++: If NAME is non-zero, this is the new name to install. This is 4250: done when replacing anonymous tags with real tag names. */ 4251: 4252: static tree 4253: lookup_tag_reverse (type, name) 4254: tree type; 4255: tree name; 4256: { 4257: register struct binding_level *level; 4258: 4259: for (level = current_binding_level; level; level = level->level_chain) 4260: { 4261: register tree tail; 4262: for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) 4263: { 4264: if (TREE_VALUE (tail) == type) 4265: { 4266: if (name) 4267: TREE_PURPOSE (tail) = name; 4268: return TREE_PURPOSE (tail); 4269: } 4270: } 4271: } 4272: return NULL_TREE; 4273: } 4274: 4275: /* Given type TYPE which was not declared in C++ language context, 4276: attempt to find a name by which it is referred. */ 4277: tree 4278: typedecl_for_tag (tag) 4279: tree tag; 4280: { 4281: struct binding_level *b = current_binding_level; 4282: 4283: if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL) 4284: return TYPE_NAME (tag); 4285: 4286: while (b) 4287: { 4288: tree decls = b->names; 4289: while (decls) 4290: { 4291: if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag) 4292: break; 4293: decls = TREE_CHAIN (decls); 4294: } 4295: if (decls) 4296: return decls; 4297: b = b->level_chain; 4298: } 4299: return NULL_TREE; 4300: } 4301: 4302: /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). 4303: Return the type value, or NULL_TREE if not found. */ 4304: static tree 4305: lookup_nested_type (type, context) 4306: tree type; 4307: tree context; 4308: { 4309: if (context == NULL_TREE) 4310: return NULL_TREE; 4311: while (context) 4312: { 4313: switch (TREE_CODE (context)) 4314: { 4315: case TYPE_DECL: 4316: { 4317: tree ctype = TREE_TYPE (context); 4318: tree match = value_member (type, CLASSTYPE_TAGS (ctype)); 4319: if (match) 4320: return TREE_VALUE (match); 4321: context = DECL_CONTEXT (context); 4322: 4323: /* When we have a nested class whose member functions have 4324: local types (e.g., a set of enums), we'll arrive here 4325: with the DECL_CONTEXT as the actual RECORD_TYPE node for 4326: the enclosing class. Instead, we want to make sure we 4327: come back in here with the TYPE_DECL, not the RECORD_TYPE. */ 4328: if (context && TREE_CODE (context) == RECORD_TYPE) 4329: context = TREE_CHAIN (context); 4330: } 4331: break; 4332: case FUNCTION_DECL: 1.1.1.2 ! root 4333: if (TYPE_NAME (type) && TYPE_IDENTIFIER (type)) ! 4334: return lookup_name (TYPE_IDENTIFIER (type), 1); ! 4335: return NULL_TREE; 1.1 root 4336: default: 4337: my_friendly_abort (12); 4338: } 4339: } 4340: return NULL_TREE; 4341: } 4342: 1.1.1.2 ! root 4343: /* Look up NAME in the NAMESPACE. */ ! 4344: tree ! 4345: lookup_namespace_name (namespace, name) ! 4346: tree namespace, name; ! 4347: { ! 4348: struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace); ! 4349: tree x; ! 4350: ! 4351: for (x = NULL_TREE; b && !x; b = b->level_chain) ! 4352: { ! 4353: for (x = b->names; x; x = TREE_CHAIN (x)) ! 4354: if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) ! 4355: break; ! 4356: /* Must find directly in the namespace. */ ! 4357: break; ! 4358: } ! 4359: return x; ! 4360: } ! 4361: 1.1 root 4362: /* Look up NAME in the current binding level and its superiors in the 4363: namespace of variables, functions and typedefs. Return a ..._DECL 4364: node of some kind representing its definition if there is only one 4365: such declaration, or return a TREE_LIST with all the overloaded 4366: definitions if there are many, or return 0 if it is undefined. 4367: 4368: If PREFER_TYPE is > 0, we prefer TYPE_DECLs. 4369: If PREFER_TYPE is -2, we're being called from yylex(). (UGLY) 4370: Otherwise we prefer non-TYPE_DECLs. */ 4371: 4372: tree 4373: lookup_name_real (name, prefer_type, nonclass) 4374: tree name; 4375: int prefer_type, nonclass; 4376: { 4377: register tree val; 4378: int yylex = 0; 1.1.1.2 ! root 4379: tree from_obj = NULL_TREE; 1.1 root 4380: 4381: if (prefer_type == -2) 4382: { 4383: extern int looking_for_typename; 1.1.1.2 ! root 4384: tree type; 1.1 root 4385: 4386: yylex = 1; 4387: prefer_type = looking_for_typename; 1.1.1.2 ! root 4388: ! 4389: if (got_scope) ! 4390: type = got_scope; ! 4391: else if (got_object != error_mark_node) ! 4392: type = got_object; 1.1 root 4393: 1.1.1.2 ! root 4394: if (type) 1.1 root 4395: { 1.1.1.2 ! root 4396: if (type == error_mark_node) 1.1 root 4397: return error_mark_node; 1.1.1.2 ! root 4398: else if (type == void_type_node) 1.1 root 4399: val = IDENTIFIER_GLOBAL_VALUE (name); 1.1.1.2 ! root 4400: else if (TREE_CODE (type) == TEMPLATE_TYPE_PARM 1.1 root 4401: /* TFIXME -- don't do this for UPTs in new model. */ 1.1.1.2 ! root 4402: || TREE_CODE (type) == UNINSTANTIATED_P_TYPE) 1.1 root 4403: { 4404: if (prefer_type > 0) 1.1.1.2 ! root 4405: val = create_nested_upt (type, name); 1.1 root 4406: else 4407: val = NULL_TREE; 4408: } 1.1.1.2 ! root 4409: else if (TREE_CODE (type) == NAMESPACE_DECL) ! 4410: { ! 4411: val = lookup_namespace_name (type, name); ! 4412: } ! 4413: else if (! IS_AGGR_TYPE (type)) 1.1 root 4414: /* Someone else will give an error about this if needed. */ 4415: val = NULL_TREE; 1.1.1.2 ! root 4416: else if (TYPE_BEING_DEFINED (type)) 1.1 root 4417: { 4418: val = IDENTIFIER_CLASS_VALUE (name); 1.1.1.2 ! root 4419: if (val && DECL_CONTEXT (val) != type) 1.1 root 4420: { 4421: struct binding_level *b = class_binding_level; 4422: for (val = NULL_TREE; b; b = b->level_chain) 4423: { 4424: tree t = purpose_member (name, b->class_shadowed); 4425: if (t && TREE_VALUE (t) 1.1.1.2 ! root 4426: && DECL_CONTEXT (TREE_VALUE (t)) == type) 1.1 root 4427: { 4428: val = TREE_VALUE (t); 4429: break; 4430: } 4431: } 4432: } 4433: if (val == NULL_TREE 1.1.1.2 ! root 4434: && CLASSTYPE_LOCAL_TYPEDECLS (type)) ! 4435: val = lookup_field (type, name, 0, 1); 1.1 root 4436: } 1.1.1.2 ! root 4437: else if (type == current_class_type) 1.1 root 4438: val = IDENTIFIER_CLASS_VALUE (name); 4439: else 1.1.1.2 ! root 4440: val = lookup_field (type, name, 0, prefer_type); 1.1 root 4441: } 1.1.1.2 ! root 4442: else ! 4443: val = NULL_TREE; ! 4444: ! 4445: if (got_scope) ! 4446: goto done; ! 4447: ! 4448: /* This special lookup only applies to types. */ ! 4449: else if (got_object && val && TREE_CODE (val) == TYPE_DECL) ! 4450: from_obj = val; 1.1 root 4451: } 4452: 4453: if (current_binding_level != global_binding_level 4454: && IDENTIFIER_LOCAL_VALUE (name)) 4455: val = IDENTIFIER_LOCAL_VALUE (name); 4456: /* In C++ class fields are between local and global scope, 4457: just before the global scope. */ 4458: else if (current_class_type && ! nonclass) 4459: { 4460: val = IDENTIFIER_CLASS_VALUE (name); 4461: if (val == NULL_TREE 4462: && TYPE_BEING_DEFINED (current_class_type) 4463: && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type)) 4464: /* Try to find values from base classes if we are presently 4465: defining a type. We are presently only interested in 4466: TYPE_DECLs. */ 4467: val = lookup_field (current_class_type, name, 0, 1); 4468: 4469: /* yylex() calls this with -2, since we should never start digging for 4470: the nested name at the point where we haven't even, for example, 4471: created the COMPONENT_REF or anything like that. */ 4472: if (val == NULL_TREE) 4473: val = lookup_nested_field (name, ! yylex); 4474: 4475: if (val == NULL_TREE) 4476: val = IDENTIFIER_GLOBAL_VALUE (name); 4477: } 4478: else 4479: val = IDENTIFIER_GLOBAL_VALUE (name); 4480: 4481: done: 4482: if (val) 4483: { 1.1.1.2 ! root 4484: if (from_obj && from_obj != val) ! 4485: cp_error ("lookup in the scope of `%#T' does not match lookup in the current scope", ! 4486: got_object); ! 4487: 1.1 root 4488: if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template) 4489: || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0) 1.1.1.2 ! root 4490: ; ! 4491: else if (IDENTIFIER_HAS_TYPE_VALUE (name)) ! 4492: val = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name)); ! 4493: else if (TREE_TYPE (val) == error_mark_node) ! 4494: val = error_mark_node; 1.1 root 4495: } 1.1.1.2 ! root 4496: else if (from_obj) ! 4497: val = from_obj; 1.1 root 4498: 4499: return val; 4500: } 4501: 4502: tree 4503: lookup_name_nonclass (name) 4504: tree name; 4505: { 4506: return lookup_name_real (name, 0, 1); 4507: } 4508: 4509: tree 4510: lookup_name (name, prefer_type) 4511: tree name; 4512: int prefer_type; 4513: { 4514: return lookup_name_real (name, prefer_type, 0); 4515: } 4516: 4517: /* Similar to `lookup_name' but look only at current binding level. */ 4518: 4519: tree 4520: lookup_name_current_level (name) 4521: tree name; 4522: { 4523: register tree t = NULL_TREE; 4524: 4525: if (current_binding_level == global_binding_level) 4526: { 4527: t = IDENTIFIER_GLOBAL_VALUE (name); 4528: 4529: /* extern "C" function() */ 4530: if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) 4531: t = TREE_VALUE (t); 4532: } 4533: else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE) 4534: { 4535: struct binding_level *b = current_binding_level; 4536: while (1) 4537: { 4538: for (t = b->names; t; t = TREE_CHAIN (t)) 1.1.1.2 ! root 4539: if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name) 1.1 root 4540: goto out; 4541: if (b->keep == 2) 4542: b = b->level_chain; 4543: else 4544: break; 4545: } 4546: out: 4547: ; 4548: } 4549: 4550: return t; 4551: } 4552: 4553: /* Arrange for the user to get a source line number, even when the 4554: compiler is going down in flames, so that she at least has a 4555: chance of working around problems in the compiler. We used to 4556: call error(), but that let the segmentation fault continue 4557: through; now, it's much more passive by asking them to send the 4558: maintainers mail about the problem. */ 4559: 4560: static void 4561: signal_catch (sig) 4562: int sig; 4563: { 4564: signal (SIGSEGV, SIG_DFL); 4565: #ifdef SIGIOT 4566: signal (SIGIOT, SIG_DFL); 4567: #endif 4568: #ifdef SIGILL 4569: signal (SIGILL, SIG_DFL); 4570: #endif 4571: #ifdef SIGABRT 4572: signal (SIGABRT, SIG_DFL); 4573: #endif 4574: #ifdef SIGBUS 4575: signal (SIGBUS, SIG_DFL); 4576: #endif 4577: my_friendly_abort (0); 4578: } 4579: 4580: /* Array for holding types considered "built-in". These types 4581: are output in the module in which `main' is defined. */ 4582: static tree *builtin_type_tdescs_arr; 4583: static int builtin_type_tdescs_len, builtin_type_tdescs_max; 4584: 4585: /* Push the declarations of builtin types into the namespace. 4586: RID_INDEX, if < RID_MAX is the index of the builtin type 4587: in the array RID_POINTERS. NAME is the name used when looking 4588: up the builtin type. TYPE is the _TYPE node for the builtin type. */ 4589: 4590: static void 4591: record_builtin_type (rid_index, name, type) 4592: enum rid rid_index; 4593: char *name; 4594: tree type; 4595: { 4596: tree rname = NULL_TREE, tname = NULL_TREE; 4597: tree tdecl; 4598: 4599: if ((int) rid_index < (int) RID_MAX) 4600: rname = ridpointers[(int) rid_index]; 4601: if (name) 4602: tname = get_identifier (name); 4603: 4604: TYPE_BUILT_IN (type) = 1; 4605: 4606: if (tname) 4607: { 4608: #if 0 /* not yet, should get fixed properly later */ 4609: tdecl = pushdecl (make_type_decl (tname, type)); 4610: #else 4611: tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); 4612: #endif 4613: set_identifier_type_value (tname, NULL_TREE); 4614: if ((int) rid_index < (int) RID_MAX) 4615: IDENTIFIER_GLOBAL_VALUE (tname) = tdecl; 4616: } 4617: if (rname != NULL_TREE) 4618: { 4619: if (tname != NULL_TREE) 4620: { 4621: set_identifier_type_value (rname, NULL_TREE); 4622: IDENTIFIER_GLOBAL_VALUE (rname) = tdecl; 4623: } 4624: else 4625: { 4626: #if 0 /* not yet, should get fixed properly later */ 4627: tdecl = pushdecl (make_type_decl (rname, type)); 4628: #else 4629: tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); 4630: #endif 4631: set_identifier_type_value (rname, NULL_TREE); 4632: } 4633: } 4634: 1.1.1.2 ! root 4635: if (flag_rtti) 1.1 root 4636: { 4637: if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max) 4638: { 4639: builtin_type_tdescs_max *= 2; 4640: builtin_type_tdescs_arr 4641: = (tree *)xrealloc (builtin_type_tdescs_arr, 4642: builtin_type_tdescs_max * sizeof (tree)); 4643: } 4644: builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type; 4645: if (TREE_CODE (type) != POINTER_TYPE) 4646: { 4647: builtin_type_tdescs_arr[builtin_type_tdescs_len++] 4648: = build_pointer_type (type); 4649: builtin_type_tdescs_arr[builtin_type_tdescs_len++] 4650: = build_pointer_type (build_type_variant (type, 1, 0)); 4651: } 4652: if (TREE_CODE (type) != VOID_TYPE) 4653: { 4654: builtin_type_tdescs_arr[builtin_type_tdescs_len++] 4655: = build_reference_type (type); 4656: builtin_type_tdescs_arr[builtin_type_tdescs_len++] 4657: = build_reference_type (build_type_variant (type, 1, 0)); 4658: } 4659: } 4660: } 4661: 4662: static void 4663: output_builtin_tdesc_entries () 4664: { 4665: extern struct obstack permanent_obstack; 4666: 4667: /* If there's more than one main in this file, don't crash. */ 4668: if (builtin_type_tdescs_arr == 0) 4669: return; 4670: 4671: push_obstacks (&permanent_obstack, &permanent_obstack); 4672: while (builtin_type_tdescs_len > 0) 4673: { 4674: tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len]; 4675: tree tdesc = build_t_desc (type, 0); 4676: TREE_ASM_WRITTEN (tdesc) = 0; 4677: build_t_desc (type, 2); 4678: } 4679: free (builtin_type_tdescs_arr); 4680: builtin_type_tdescs_arr = 0; 4681: pop_obstacks (); 4682: } 4683: 4684: /* Push overloaded decl, in global scope, with one argument so it 4685: can be used as a callback from define_function. */ 4686: static void 4687: push_overloaded_decl_1 (x) 4688: tree x; 4689: { 4690: push_overloaded_decl (x, 0); 4691: } 4692: 1.1.1.2 ! root 4693: #define builtin_function(NAME, TYPE, CODE, LIBNAME) \ ! 4694: define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME) ! 4695: ! 4696: #ifdef __GNUC__ ! 4697: __inline ! 4698: #endif ! 4699: tree auto_function (name, type, code) ! 4700: tree name, type; ! 4701: enum built_in_function code; ! 4702: { ! 4703: return define_function ! 4704: (IDENTIFIER_POINTER (name), type, code, (void (*)())push_overloaded_decl_1, ! 4705: IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type), ! 4706: 0))); ! 4707: } ! 4708: 1.1 root 4709: /* Create the predefined scalar types of C, 4710: and some nodes representing standard constants (0, 1, (void *)0). 4711: Initialize the global binding level. 4712: Make definitions for built-in primitive functions. */ 4713: 4714: void 4715: init_decl_processing () 4716: { 4717: tree decl; 4718: register tree endlink, int_endlink, double_endlink, ptr_endlink; 4719: tree fields[20]; 4720: /* Either char* or void*. */ 4721: tree traditional_ptr_type_node; 4722: /* Data type of memcpy. */ 4723: tree memcpy_ftype; 4724: #if 0 /* Not yet. */ 4725: /* Data type of strncpy. */ 4726: tree strncpy_ftype; 4727: #endif 4728: int wchar_type_size; 4729: tree temp; 4730: tree array_domain_type; 1.1.1.2 ! root 4731: extern int flag_strict_prototype; 1.1 root 4732: 4733: /* Have to make these distinct before we try using them. */ 4734: lang_name_cplusplus = get_identifier ("C++"); 4735: lang_name_c = get_identifier ("C"); 4736: 1.1.1.2 ! root 4737: if (flag_strict_prototype == 2) ! 4738: { ! 4739: if (pedantic) ! 4740: strict_prototypes_lang_c = strict_prototypes_lang_cplusplus; ! 4741: } ! 4742: else ! 4743: strict_prototypes_lang_c = flag_strict_prototype; 1.1 root 4744: 4745: /* Initially, C. */ 4746: current_lang_name = lang_name_c; 4747: 4748: current_function_decl = NULL_TREE; 4749: named_labels = NULL_TREE; 4750: named_label_uses = NULL_TREE; 4751: current_binding_level = NULL_BINDING_LEVEL; 4752: free_binding_level = NULL_BINDING_LEVEL; 4753: 4754: /* Because most segmentation signals can be traced back into user 4755: code, catch them and at least give the user a chance of working 4756: around compiler bugs. */ 4757: signal (SIGSEGV, signal_catch); 4758: 4759: /* We will also catch aborts in the back-end through signal_catch and 4760: give the user a chance to see where the error might be, and to defeat 4761: aborts in the back-end when there have been errors previously in their 4762: code. */ 4763: #ifdef SIGIOT 4764: signal (SIGIOT, signal_catch); 4765: #endif 4766: #ifdef SIGILL 4767: signal (SIGILL, signal_catch); 4768: #endif 4769: #ifdef SIGABRT 4770: signal (SIGABRT, signal_catch); 4771: #endif 4772: #ifdef SIGBUS 4773: signal (SIGBUS, signal_catch); 4774: #endif 4775: 4776: gcc_obstack_init (&decl_obstack); 1.1.1.2 ! root 4777: if (flag_rtti) 1.1 root 4778: { 4779: builtin_type_tdescs_max = 100; 4780: builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree)); 4781: } 4782: 4783: /* Must lay these out before anything else gets laid out. */ 4784: error_mark_node = make_node (ERROR_MARK); 4785: TREE_PERMANENT (error_mark_node) = 1; 4786: TREE_TYPE (error_mark_node) = error_mark_node; 4787: error_mark_list = build_tree_list (error_mark_node, error_mark_node); 4788: TREE_TYPE (error_mark_list) = error_mark_node; 4789: 4790: /* Make the binding_level structure for global names. */ 4791: pushlevel (0); 4792: global_binding_level = current_binding_level; 4793: 4794: this_identifier = get_identifier (THIS_NAME); 4795: in_charge_identifier = get_identifier (IN_CHARGE_NAME); 4796: pfn_identifier = get_identifier (VTABLE_PFN_NAME); 4797: index_identifier = get_identifier (VTABLE_INDEX_NAME); 4798: delta_identifier = get_identifier (VTABLE_DELTA_NAME); 4799: delta2_identifier = get_identifier (VTABLE_DELTA2_NAME); 4800: pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2"); 1.1.1.2 ! root 4801: if (flag_handle_signatures) ! 4802: { ! 4803: tag_identifier = get_identifier (SIGTABLE_TAG_NAME); ! 4804: vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME); ! 4805: vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME); ! 4806: } 1.1 root 4807: 4808: /* Define `int' and `char' first so that dbx will output them first. */ 4809: 4810: integer_type_node = make_signed_type (INT_TYPE_SIZE); 4811: record_builtin_type (RID_INT, NULL_PTR, integer_type_node); 4812: 4813: /* Define `char', which is like either `signed char' or `unsigned char' 4814: but not the same as either. */ 4815: 4816: char_type_node = 4817: (flag_signed_char 4818: ? make_signed_type (CHAR_TYPE_SIZE) 4819: : make_unsigned_type (CHAR_TYPE_SIZE)); 4820: record_builtin_type (RID_CHAR, "char", char_type_node); 4821: 4822: long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); 4823: record_builtin_type (RID_LONG, "long int", long_integer_type_node); 4824: 4825: unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); 4826: record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); 4827: 4828: long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); 4829: record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); 4830: record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); 4831: 4832: long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); 4833: record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); 4834: 4835: long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); 4836: record_builtin_type (RID_MAX, "long long unsigned int", 4837: long_long_unsigned_type_node); 4838: record_builtin_type (RID_MAX, "long long unsigned", 4839: long_long_unsigned_type_node); 4840: 4841: /* `unsigned long' is the standard type for sizeof. 4842: Traditionally, use a signed type. 4843: Note that stddef.h uses `unsigned long', 4844: and this must agree, even of long and int are the same size. */ 4845: sizetype 4846: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); 4847: if (flag_traditional && TREE_UNSIGNED (sizetype)) 4848: sizetype = signed_type (sizetype); 4849: 4850: ptrdiff_type_node 4851: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); 4852: 4853: TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype; 4854: TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype; 4855: TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype; 4856: TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype; 4857: TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype; 4858: TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype; 4859: TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype; 4860: 4861: short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); 4862: record_builtin_type (RID_SHORT, "short int", short_integer_type_node); 4863: short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); 4864: record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); 4865: record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); 4866: 4867: /* Define both `signed char' and `unsigned char'. */ 4868: signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); 4869: record_builtin_type (RID_MAX, "signed char", signed_char_type_node); 4870: unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); 4871: record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); 4872: 4873: /* These are types that type_for_size and type_for_mode use. */ 4874: intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); 4875: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); 4876: intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); 4877: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); 4878: intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); 4879: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); 4880: intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); 4881: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); 4882: unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); 4883: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); 4884: unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); 4885: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); 4886: unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); 4887: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); 4888: unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); 4889: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); 4890: 4891: float_type_node = make_node (REAL_TYPE); 4892: TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; 4893: record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node); 4894: layout_type (float_type_node); 4895: 4896: double_type_node = make_node (REAL_TYPE); 4897: if (flag_short_double) 4898: TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; 4899: else 4900: TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; 4901: record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node); 4902: layout_type (double_type_node); 4903: 4904: long_double_type_node = make_node (REAL_TYPE); 4905: TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; 4906: record_builtin_type (RID_MAX, "long double", long_double_type_node); 4907: layout_type (long_double_type_node); 4908: 4909: integer_zero_node = build_int_2 (0, 0); 4910: TREE_TYPE (integer_zero_node) = integer_type_node; 4911: integer_one_node = build_int_2 (1, 0); 4912: TREE_TYPE (integer_one_node) = integer_type_node; 4913: integer_two_node = build_int_2 (2, 0); 4914: TREE_TYPE (integer_two_node) = integer_type_node; 4915: integer_three_node = build_int_2 (3, 0); 4916: TREE_TYPE (integer_three_node) = integer_type_node; 4917: 1.1.1.2 ! root 4918: boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); ! 4919: TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); ! 4920: record_builtin_type (RID_BOOL, "bool", boolean_type_node); ! 4921: boolean_false_node = build_int_2 (0, 0); ! 4922: TREE_TYPE (boolean_false_node) = boolean_type_node; ! 4923: boolean_true_node = build_int_2 (1, 0); ! 4924: TREE_TYPE (boolean_true_node) = boolean_type_node; 1.1 root 4925: 4926: /* These are needed by stor-layout.c. */ 4927: size_zero_node = size_int (0); 4928: size_one_node = size_int (1); 4929: 4930: void_type_node = make_node (VOID_TYPE); 4931: record_builtin_type (RID_VOID, NULL_PTR, void_type_node); 4932: layout_type (void_type_node); /* Uses integer_zero_node. */ 4933: void_list_node = build_tree_list (NULL_TREE, void_type_node); 4934: TREE_PARMLIST (void_list_node) = 1; 4935: 4936: null_pointer_node = build_int_2 (0, 0); 4937: TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); 4938: layout_type (TREE_TYPE (null_pointer_node)); 4939: 4940: /* Used for expressions that do nothing, but are not errors. */ 4941: void_zero_node = build_int_2 (0, 0); 4942: TREE_TYPE (void_zero_node) = void_type_node; 4943: 4944: string_type_node = build_pointer_type (char_type_node); 4945: const_string_type_node = 4946: build_pointer_type (build_type_variant (char_type_node, 1, 0)); 4947: record_builtin_type (RID_MAX, NULL_PTR, string_type_node); 4948: 4949: /* Make a type to be the domain of a few array types 4950: whose domains don't really matter. 4951: 200 is small enough that it always fits in size_t 4952: and large enough that it can hold most function names for the 4953: initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ 4954: array_domain_type = build_index_type (build_int_2 (200, 0)); 4955: 4956: /* make a type for arrays of characters. 4957: With luck nothing will ever really depend on the length of this 4958: array type. */ 4959: char_array_type_node 4960: = build_array_type (char_type_node, array_domain_type); 4961: /* Likewise for arrays of ints. */ 4962: int_array_type_node 4963: = build_array_type (integer_type_node, array_domain_type); 4964: 4965: /* This is just some anonymous class type. Nobody should ever 4966: need to look inside this envelope. */ 4967: class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); 4968: 4969: default_function_type 4970: = build_function_type (integer_type_node, NULL_TREE); 4971: build_pointer_type (default_function_type); 4972: 4973: ptr_type_node = build_pointer_type (void_type_node); 4974: const_ptr_type_node = 4975: build_pointer_type (build_type_variant (void_type_node, 1, 0)); 4976: record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); 4977: endlink = void_list_node; 4978: int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); 4979: double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); 4980: ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink); 4981: 4982: double_ftype_double 4983: = build_function_type (double_type_node, double_endlink); 4984: 4985: double_ftype_double_double 4986: = build_function_type (double_type_node, 4987: tree_cons (NULL_TREE, double_type_node, 4988: double_endlink)); 4989: 4990: int_ftype_int 4991: = build_function_type (integer_type_node, int_endlink); 4992: 4993: long_ftype_long 4994: = build_function_type (long_integer_type_node, 4995: tree_cons (NULL_TREE, long_integer_type_node, 4996: endlink)); 4997: 4998: void_ftype_ptr_ptr_int 4999: = build_function_type (void_type_node, 5000: tree_cons (NULL_TREE, ptr_type_node, 5001: tree_cons (NULL_TREE, ptr_type_node, 5002: int_endlink))); 5003: 5004: int_ftype_cptr_cptr_sizet 5005: = build_function_type (integer_type_node, 5006: tree_cons (NULL_TREE, const_ptr_type_node, 5007: tree_cons (NULL_TREE, const_ptr_type_node, 5008: tree_cons (NULL_TREE, 5009: sizetype, 5010: endlink)))); 5011: 5012: void_ftype_ptr_int_int 5013: = build_function_type (void_type_node, 5014: tree_cons (NULL_TREE, ptr_type_node, 5015: tree_cons (NULL_TREE, integer_type_node, 5016: int_endlink))); 5017: 5018: string_ftype_ptr_ptr /* strcpy prototype */ 5019: = build_function_type (string_type_node, 5020: tree_cons (NULL_TREE, string_type_node, 5021: tree_cons (NULL_TREE, 5022: const_string_type_node, 5023: endlink))); 5024: 5025: #if 0 5026: /* Not yet. */ 5027: strncpy_ftype /* strncpy prototype */ 5028: = build_function_type (string_type_node, 5029: tree_cons (NULL_TREE, string_type_node, 5030: tree_cons (NULL_TREE, const_string_type_node, 5031: tree_cons (NULL_TREE, 5032: sizetype, 5033: endlink)))); 5034: #endif 5035: 5036: int_ftype_string_string /* strcmp prototype */ 5037: = build_function_type (integer_type_node, 5038: tree_cons (NULL_TREE, const_string_type_node, 5039: tree_cons (NULL_TREE, 5040: const_string_type_node, 5041: endlink))); 5042: 5043: sizet_ftype_string /* strlen prototype */ 5044: = build_function_type (sizetype, 5045: tree_cons (NULL_TREE, const_string_type_node, 5046: endlink)); 5047: 5048: traditional_ptr_type_node 5049: = (flag_traditional ? string_type_node : ptr_type_node); 5050: 5051: memcpy_ftype /* memcpy prototype */ 5052: = build_function_type (traditional_ptr_type_node, 5053: tree_cons (NULL_TREE, ptr_type_node, 5054: tree_cons (NULL_TREE, const_ptr_type_node, 5055: tree_cons (NULL_TREE, 5056: sizetype, 5057: endlink)))); 5058: 5059: if (flag_huge_objects) 5060: delta_type_node = long_integer_type_node; 5061: else 5062: delta_type_node = short_integer_type_node; 5063: 5064: builtin_function ("__builtin_constant_p", int_ftype_int, 5065: BUILT_IN_CONSTANT_P, NULL_PTR); 5066: 5067: builtin_return_address_fndecl = 5068: builtin_function ("__builtin_return_address", 5069: build_function_type (ptr_type_node, 5070: tree_cons (NULL_TREE, 5071: unsigned_type_node, 5072: endlink)), 5073: BUILT_IN_RETURN_ADDRESS, NULL_PTR); 5074: 5075: builtin_function ("__builtin_frame_address", 5076: build_function_type (ptr_type_node, 5077: tree_cons (NULL_TREE, 5078: unsigned_type_node, 5079: endlink)), 5080: BUILT_IN_FRAME_ADDRESS, NULL_PTR); 5081: 5082: 5083: builtin_function ("__builtin_alloca", 5084: build_function_type (ptr_type_node, 5085: tree_cons (NULL_TREE, 5086: sizetype, 5087: endlink)), 5088: BUILT_IN_ALLOCA, "alloca"); 5089: /* Define alloca, ffs as builtins. 5090: Declare _exit just to mark it as volatile. */ 5091: if (! flag_no_builtin && !flag_no_nonansi_builtin) 5092: { 5093: temp = builtin_function ("alloca", 5094: build_function_type (ptr_type_node, 5095: tree_cons (NULL_TREE, 5096: sizetype, 5097: endlink)), 5098: BUILT_IN_ALLOCA, NULL_PTR); 5099: /* Suppress error if redefined as a non-function. */ 5100: DECL_BUILT_IN_NONANSI (temp) = 1; 5101: temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); 5102: /* Suppress error if redefined as a non-function. */ 5103: DECL_BUILT_IN_NONANSI (temp) = 1; 5104: temp = builtin_function ("_exit", build_function_type (void_type_node, 5105: int_endlink), 5106: NOT_BUILT_IN, NULL_PTR); 5107: TREE_THIS_VOLATILE (temp) = 1; 5108: TREE_SIDE_EFFECTS (temp) = 1; 5109: /* Suppress error if redefined as a non-function. */ 5110: DECL_BUILT_IN_NONANSI (temp) = 1; 5111: } 5112: 5113: builtin_function ("__builtin_abs", int_ftype_int, 5114: BUILT_IN_ABS, NULL_PTR); 5115: builtin_function ("__builtin_fabs", double_ftype_double, 5116: BUILT_IN_FABS, NULL_PTR); 5117: builtin_function ("__builtin_labs", long_ftype_long, 5118: BUILT_IN_LABS, NULL_PTR); 5119: builtin_function ("__builtin_ffs", int_ftype_int, 5120: BUILT_IN_FFS, NULL_PTR); 5121: builtin_function ("__builtin_fsqrt", double_ftype_double, 5122: BUILT_IN_FSQRT, NULL_PTR); 5123: builtin_function ("__builtin_sin", double_ftype_double, 5124: BUILT_IN_SIN, "sin"); 5125: builtin_function ("__builtin_cos", double_ftype_double, 5126: BUILT_IN_COS, "cos"); 5127: builtin_function ("__builtin_saveregs", 5128: build_function_type (ptr_type_node, NULL_TREE), 5129: BUILT_IN_SAVEREGS, NULL_PTR); 5130: /* EXPAND_BUILTIN_VARARGS is obsolete. */ 5131: #if 0 5132: builtin_function ("__builtin_varargs", 5133: build_function_type (ptr_type_node, 5134: tree_cons (NULL_TREE, 5135: integer_type_node, 5136: endlink)), 5137: BUILT_IN_VARARGS, NULL_PTR); 5138: #endif 5139: builtin_function ("__builtin_classify_type", default_function_type, 5140: BUILT_IN_CLASSIFY_TYPE, NULL_PTR); 5141: builtin_function ("__builtin_next_arg", 5142: build_function_type (ptr_type_node, NULL_TREE), 5143: BUILT_IN_NEXT_ARG, NULL_PTR); 5144: builtin_function ("__builtin_args_info", 5145: build_function_type (integer_type_node, 5146: tree_cons (NULL_TREE, 5147: integer_type_node, 5148: endlink)), 5149: BUILT_IN_ARGS_INFO, NULL_PTR); 5150: 5151: /* Untyped call and return. */ 5152: builtin_function ("__builtin_apply_args", 5153: build_function_type (ptr_type_node, NULL_TREE), 5154: BUILT_IN_APPLY_ARGS, NULL_PTR); 5155: 5156: temp = tree_cons (NULL_TREE, 5157: build_pointer_type (build_function_type (void_type_node, 5158: NULL_TREE)), 5159: tree_cons (NULL_TREE, 5160: ptr_type_node, 5161: tree_cons (NULL_TREE, 5162: sizetype, 5163: endlink))); 5164: builtin_function ("__builtin_apply", 5165: build_function_type (ptr_type_node, temp), 5166: BUILT_IN_APPLY, NULL_PTR); 5167: builtin_function ("__builtin_return", 5168: build_function_type (void_type_node, 5169: tree_cons (NULL_TREE, 5170: ptr_type_node, 5171: endlink)), 5172: BUILT_IN_RETURN, NULL_PTR); 5173: 5174: /* Currently under experimentation. */ 5175: builtin_function ("__builtin_memcpy", memcpy_ftype, 5176: BUILT_IN_MEMCPY, "memcpy"); 5177: builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, 5178: BUILT_IN_MEMCMP, "memcmp"); 5179: builtin_function ("__builtin_strcmp", int_ftype_string_string, 5180: BUILT_IN_STRCMP, "strcmp"); 5181: builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, 5182: BUILT_IN_STRCPY, "strcpy"); 5183: #if 0 5184: /* Not yet. */ 5185: builtin_function ("__builtin_strncpy", strncpy_ftype, 5186: BUILT_IN_STRNCPY, "strncpy"); 5187: #endif 5188: builtin_function ("__builtin_strlen", sizet_ftype_string, 5189: BUILT_IN_STRLEN, "strlen"); 5190: 5191: if (!flag_no_builtin) 5192: { 5193: #if 0 /* These do not work well with libg++. */ 5194: builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); 5195: builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); 5196: builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); 5197: #endif 5198: builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); 5199: builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, 5200: NULL_PTR); 5201: builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR); 5202: builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, 5203: NULL_PTR); 5204: #if 0 5205: /* Not yet. */ 5206: builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR); 5207: #endif 5208: builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR); 5209: builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); 5210: builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); 5211: 5212: /* Declare these functions volatile 5213: to avoid spurious "control drops through" warnings. */ 5214: temp = builtin_function ("abort", 5215: build_function_type (void_type_node, endlink), 5216: NOT_BUILT_IN, NULL_PTR); 5217: TREE_THIS_VOLATILE (temp) = 1; 5218: TREE_SIDE_EFFECTS (temp) = 1; 5219: /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on 5220: them... */ 5221: DECL_BUILT_IN_NONANSI (temp) = 1; 5222: temp = builtin_function ("exit", build_function_type (void_type_node, 5223: int_endlink), 5224: NOT_BUILT_IN, NULL_PTR); 5225: TREE_THIS_VOLATILE (temp) = 1; 5226: TREE_SIDE_EFFECTS (temp) = 1; 5227: DECL_BUILT_IN_NONANSI (temp) = 1; 5228: } 5229: 5230: #if 0 5231: /* Support for these has not been written in either expand_builtin 5232: or build_function_call. */ 5233: builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0); 5234: builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0); 5235: builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 5236: 0); 5237: builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0); 5238: builtin_function ("__builtin_fmod", double_ftype_double_double, 5239: BUILT_IN_FMOD, 0); 5240: builtin_function ("__builtin_frem", double_ftype_double_double, 5241: BUILT_IN_FREM, 0); 5242: builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 5243: 0); 5244: builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 5245: 0); 5246: builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 5247: 0); 5248: #endif 5249: 5250: /* C++ extensions */ 5251: 5252: unknown_type_node = make_node (UNKNOWN_TYPE); 5253: #if 0 /* not yet, should get fixed properly later */ 5254: pushdecl (make_type_decl (get_identifier ("unknown type"), 5255: unknown_type_node)); 5256: #else 5257: decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"), 5258: unknown_type_node)); 5259: /* Make sure the "unknown type" typedecl gets ignored for debug info. */ 5260: DECL_IGNORED_P (decl) = 1; 5261: TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; 5262: #endif 5263: TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node); 5264: TYPE_ALIGN (unknown_type_node) = 1; 5265: TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node); 5266: /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ 5267: TREE_TYPE (unknown_type_node) = unknown_type_node; 5268: /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */ 5269: TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; 5270: TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; 5271: 5272: /* This is for handling opaque types in signatures. */ 5273: opaque_type_node = copy_node (ptr_type_node); 5274: TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node; 5275: record_builtin_type (RID_MAX, 0, opaque_type_node); 5276: 5277: /* This is special for C++ so functions can be overloaded. */ 5278: wchar_type_node 5279: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); 5280: wchar_type_size = TYPE_PRECISION (wchar_type_node); 5281: signed_wchar_type_node = make_signed_type (wchar_type_size); 5282: unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); 5283: wchar_type_node 5284: = TREE_UNSIGNED (wchar_type_node) 5285: ? unsigned_wchar_type_node 5286: : signed_wchar_type_node; 5287: record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); 5288: 5289: /* Artificial declaration of wchar_t -- can be bashed */ 5290: wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"), 5291: wchar_type_node); 5292: pushdecl (wchar_decl_node); 5293: 5294: /* This is for wide string constants. */ 5295: wchar_array_type_node 5296: = build_array_type (wchar_type_node, array_domain_type); 5297: 5298: /* This is a hack that should go away when we deliver the 5299: real gc code. */ 5300: if (flag_gc) 5301: { 5302: builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0); 5303: pushdecl (lookup_name (get_identifier ("__gc_main"), 0)); 5304: } 5305: 5306: if (flag_vtable_thunks) 5307: { 5308: /* Make sure we get a unique function type, so we can give 5309: its pointer type a name. (This wins for gdb.) */ 5310: tree vfunc_type = make_node (FUNCTION_TYPE); 5311: TREE_TYPE (vfunc_type) = integer_type_node; 5312: TYPE_ARG_TYPES (vfunc_type) = NULL_TREE; 5313: layout_type (vfunc_type); 5314: 5315: vtable_entry_type = build_pointer_type (vfunc_type); 5316: } 5317: else 5318: { 5319: vtable_entry_type = make_lang_type (RECORD_TYPE); 5320: fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, 5321: delta_type_node); 5322: fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, 5323: delta_type_node); 5324: fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, 5325: ptr_type_node); 5326: finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, 5327: double_type_node); 5328: 5329: /* Make this part of an invisible union. */ 5330: fields[3] = copy_node (fields[2]); 5331: TREE_TYPE (fields[3]) = delta_type_node; 5332: DECL_NAME (fields[3]) = delta2_identifier; 5333: DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node); 5334: DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node); 5335: TREE_UNSIGNED (fields[3]) = 0; 5336: TREE_CHAIN (fields[2]) = fields[3]; 5337: vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0); 5338: } 5339: record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); 5340: 5341: vtbl_type_node 5342: = build_array_type (vtable_entry_type, NULL_TREE); 5343: layout_type (vtbl_type_node); 5344: vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0); 5345: record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node); 5346: 5347: /* Simplify life by making a "sigtable_entry_type". Give its 5348: fields names so that the debugger can use them. */ 5349: 5350: if (flag_handle_signatures) 5351: { 5352: sigtable_entry_type = make_lang_type (RECORD_TYPE); 1.1.1.2 ! root 5353: fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier, ! 5354: delta_type_node); ! 5355: fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier, ! 5356: delta_type_node); ! 5357: fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier, ! 5358: delta_type_node); ! 5359: fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier, ! 5360: delta_type_node); ! 5361: fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier, 1.1 root 5362: ptr_type_node); 1.1.1.2 ! root 5363: ! 5364: /* Set the alignment to the max of the alignment of ptr_type_node and ! 5365: delta_type_node. Double alignment wastes a word on the Sparc. */ ! 5366: finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4, ! 5367: (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node)) ! 5368: ? ptr_type_node ! 5369: : delta_type_node); ! 5370: ! 5371: /* Make this part of an invisible union. */ ! 5372: fields[5] = copy_node (fields[4]); ! 5373: TREE_TYPE (fields[5]) = delta_type_node; ! 5374: DECL_NAME (fields[5]) = vt_off_identifier; ! 5375: DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node); ! 5376: DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node); ! 5377: TREE_UNSIGNED (fields[5]) = 0; ! 5378: TREE_CHAIN (fields[4]) = fields[5]; ! 5379: 1.1 root 5380: sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0); 5381: record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); 5382: } 5383: 1.1.1.2 ! root 5384: #if 0 ! 5385: if (flag_rtti) 1.1 root 5386: { 5387: /* Must build __t_desc type. Currently, type descriptors look like this: 5388: 5389: struct __t_desc 5390: { 5391: const char *name; 5392: int size; 5393: int bits; 5394: struct __t_desc *points_to; 5395: int ivars_count, meths_count; 5396: struct __i_desc *ivars[]; 5397: struct __m_desc *meths[]; 5398: struct __t_desc *parents[]; 5399: struct __t_desc *vbases[]; 5400: int offsets[]; 5401: }; 5402: 5403: ...as per Linton's paper. */ 5404: 5405: __t_desc_type_node = make_lang_type (RECORD_TYPE); 5406: __i_desc_type_node = make_lang_type (RECORD_TYPE); 5407: __m_desc_type_node = make_lang_type (RECORD_TYPE); 5408: __t_desc_array_type = 1.1.1.2 ! root 5409: build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE); 1.1 root 5410: __i_desc_array_type = 1.1.1.2 ! root 5411: build_array_type (build_pointer_type (__i_desc_type_node), NULL_TREE); 1.1 root 5412: __m_desc_array_type = 1.1.1.2 ! root 5413: build_array_type (build_pointer_type (__m_desc_type_node), NULL_TREE); 1.1 root 5414: 5415: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), 5416: string_type_node); 5417: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"), 5418: unsigned_type_node); 5419: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"), 5420: unsigned_type_node); 5421: fields[3] = build_lang_field_decl (FIELD_DECL, 5422: get_identifier ("points_to"), 1.1.1.2 ! root 5423: build_pointer_type (__t_desc_type_node)); 1.1 root 5424: fields[4] = build_lang_field_decl (FIELD_DECL, 5425: get_identifier ("ivars_count"), 5426: integer_type_node); 5427: fields[5] = build_lang_field_decl (FIELD_DECL, 5428: get_identifier ("meths_count"), 5429: integer_type_node); 5430: fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"), 5431: build_pointer_type (__i_desc_array_type)); 5432: fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"), 5433: build_pointer_type (__m_desc_array_type)); 5434: fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"), 5435: build_pointer_type (__t_desc_array_type)); 5436: fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"), 5437: build_pointer_type (__t_desc_array_type)); 5438: fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"), 5439: build_pointer_type (integer_type_node)); 5440: finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node); 5441: 5442: /* ivar descriptors look like this: 5443: 5444: struct __i_desc 5445: { 5446: const char *name; 5447: int offset; 5448: struct __t_desc *type; 5449: }; 5450: */ 5451: 5452: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), 5453: string_type_node); 5454: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"), 5455: integer_type_node); 5456: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"), 1.1.1.2 ! root 5457: build_pointer_type (__t_desc_type_node)); 1.1 root 5458: finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, 5459: integer_type_node); 5460: 5461: /* method descriptors look like this: 5462: 5463: struct __m_desc 5464: { 5465: const char *name; 5466: int vindex; 5467: struct __t_desc *vcontext; 5468: struct __t_desc *return_type; 5469: void (*address)(); 5470: short parm_count; 5471: short required_parms; 5472: struct __t_desc *parm_types[]; 5473: }; 5474: */ 5475: 5476: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), 5477: string_type_node); 5478: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"), 5479: integer_type_node); 5480: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"), 1.1.1.2 ! root 5481: build_pointer_type (__t_desc_type_node)); 1.1 root 5482: fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"), 1.1.1.2 ! root 5483: build_pointer_type (__t_desc_type_node)); 1.1 root 5484: fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"), 5485: build_pointer_type (default_function_type)); 5486: fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"), 5487: short_integer_type_node); 5488: fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"), 5489: short_integer_type_node); 5490: fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"), 1.1.1.2 ! root 5491: build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE))); 1.1 root 5492: finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, 5493: integer_type_node); 5494: } 5495: 1.1.1.2 ! root 5496: if (flag_rtti) 1.1 root 5497: { 5498: int i = builtin_type_tdescs_len; 5499: while (i > 0) 5500: { 5501: tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0); 5502: TREE_ASM_WRITTEN (tdesc) = 1; 5503: TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1; 5504: } 5505: } 1.1.1.2 ! root 5506: #endif /*flag_rtti*/ ! 5507: ! 5508: /* Now, C++. */ ! 5509: current_lang_name = lang_name_cplusplus; 1.1 root 5510: 5511: auto_function (ansi_opname[(int) NEW_EXPR], 5512: build_function_type (ptr_type_node, 5513: tree_cons (NULL_TREE, sizetype, 5514: void_list_node)), 5515: NOT_BUILT_IN); 5516: auto_function (ansi_opname[(int) VEC_NEW_EXPR], 5517: build_function_type (ptr_type_node, 5518: tree_cons (NULL_TREE, sizetype, 5519: void_list_node)), 5520: NOT_BUILT_IN); 5521: auto_function (ansi_opname[(int) DELETE_EXPR], 5522: build_function_type (void_type_node, 5523: tree_cons (NULL_TREE, ptr_type_node, 5524: void_list_node)), 5525: NOT_BUILT_IN); 5526: auto_function (ansi_opname[(int) VEC_DELETE_EXPR], 5527: build_function_type (void_type_node, 5528: tree_cons (NULL_TREE, ptr_type_node, 5529: void_list_node)), 5530: NOT_BUILT_IN); 5531: 5532: abort_fndecl 5533: = define_function ("__pure_virtual", 5534: build_function_type (void_type_node, void_list_node), 5535: NOT_BUILT_IN, 0, 0); 5536: 5537: /* Perform other language dependent initializations. */ 5538: init_class_processing (); 5539: init_init_processing (); 5540: init_search_processing (); 5541: 5542: if (flag_handle_exceptions) 5543: init_exception_processing (); 5544: if (flag_gc) 5545: init_gc_processing (); 5546: if (flag_no_inline) 5547: { 5548: flag_inline_functions = 0; 5549: #if 0 1.1.1.2 ! root 5550: /* This causes unnecessary emission of inline functions. */ 1.1 root 5551: flag_default_inline = 0; 5552: #endif 5553: } 5554: if (flag_cadillac) 5555: init_cadillac (); 5556: 5557: /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ 5558: declare_function_name (); 5559: 5560: /* Prepare to check format strings against argument lists. */ 5561: init_function_format_info (); 5562: } 5563: 1.1.1.2 ! root 5564: /* initialize type descriptor type node of various rtti type. */ ! 5565: ! 5566: int ! 5567: init_type_desc() ! 5568: { ! 5569: tree tdecl; ! 5570: ! 5571: tdecl = lookup_name (get_identifier ("type_info"), 0); ! 5572: if (tdecl == NULL_TREE) ! 5573: return 0; ! 5574: __t_desc_type_node = TREE_TYPE(tdecl); ! 5575: __tp_desc_type_node = build_pointer_type (__t_desc_type_node); ! 5576: ! 5577: #if 0 ! 5578: tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0); ! 5579: if (tdecl == NULL_TREE) ! 5580: return 0; ! 5581: __baselist_desc_type_node = TREE_TYPE (tdecl); ! 5582: #endif ! 5583: ! 5584: tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0); ! 5585: if (tdecl == NULL_TREE) ! 5586: return 0; ! 5587: __bltn_desc_type_node = TREE_TYPE (tdecl); ! 5588: ! 5589: tdecl = lookup_name (get_identifier ("__user_type_info"), 0); ! 5590: if (tdecl == NULL_TREE) ! 5591: return 0; ! 5592: __user_desc_type_node = TREE_TYPE (tdecl); ! 5593: ! 5594: tdecl = lookup_name (get_identifier ("__class_type_info"), 0); ! 5595: if (tdecl == NULL_TREE) ! 5596: return 0; ! 5597: __class_desc_type_node = TREE_TYPE (tdecl); ! 5598: ! 5599: tdecl = lookup_field (__class_desc_type_node, ! 5600: get_identifier ("access_mode"), 0, 0); ! 5601: if (tdecl == NULL_TREE) ! 5602: return 0; ! 5603: __access_mode_type_node = TREE_TYPE (tdecl); ! 5604: ! 5605: tdecl = lookup_name (get_identifier ("__attr_type_info"), 0); ! 5606: if (tdecl == NULL_TREE) ! 5607: return 0; ! 5608: __attr_desc_type_node = TREE_TYPE (tdecl); ! 5609: ! 5610: tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0); ! 5611: if (tdecl == NULL_TREE) ! 5612: return 0; ! 5613: __ptr_desc_type_node = TREE_TYPE (tdecl); ! 5614: ! 5615: tdecl = lookup_name (get_identifier ("__func_type_info"), 0); ! 5616: if (tdecl == NULL_TREE) ! 5617: return 0; ! 5618: __func_desc_type_node = TREE_TYPE (tdecl); ! 5619: ! 5620: tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0); ! 5621: if (tdecl == NULL_TREE) ! 5622: return 0; ! 5623: __ptmf_desc_type_node = TREE_TYPE (tdecl); ! 5624: ! 5625: tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0); ! 5626: if (tdecl == NULL_TREE) ! 5627: return 0; ! 5628: __ptmd_desc_type_node = TREE_TYPE (tdecl); ! 5629: ! 5630: return 1; ! 5631: } 1.1 root 5632: /* Make a definition for a builtin function named NAME and whose data type 5633: is TYPE. TYPE should be a function type with argument types. 5634: FUNCTION_CODE tells later passes how to compile calls to this function. 5635: See tree.h for its possible values. 5636: 5637: If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, 5638: the name to be called if we can't opencode the function. */ 5639: 5640: tree 5641: define_function (name, type, function_code, pfn, library_name) 5642: char *name; 5643: tree type; 5644: enum built_in_function function_code; 5645: void (*pfn)(); 5646: char *library_name; 5647: { 5648: tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); 5649: DECL_EXTERNAL (decl) = 1; 5650: TREE_PUBLIC (decl) = 1; 1.1.1.2 ! root 5651: DECL_ARTIFICIAL (decl) = 1; 1.1 root 5652: 5653: /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, 5654: we cannot change DECL_ASSEMBLER_NAME until we have installed this 5655: function in the namespace. */ 5656: if (pfn) (*pfn) (decl); 5657: if (library_name) 5658: DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); 5659: make_function_rtl (decl); 5660: if (function_code != NOT_BUILT_IN) 5661: { 5662: DECL_BUILT_IN (decl) = 1; 5663: DECL_FUNCTION_CODE (decl) = function_code; 5664: } 5665: return decl; 5666: } 5667: 5668: /* Called when a declaration is seen that contains no names to declare. 5669: If its type is a reference to a structure, union or enum inherited 5670: from a containing scope, shadow that tag name for the current scope 5671: with a forward reference. 5672: If its type defines a new named structure or union 5673: or defines an enum, it is valid but we need not do anything here. 5674: Otherwise, it is an error. 5675: 5676: C++: may have to grok the declspecs to learn about static, 5677: complain for anonymous unions. */ 5678: 5679: void 5680: shadow_tag (declspecs) 5681: tree declspecs; 5682: { 5683: int found_tag = 0; 5684: tree ob_modifier = NULL_TREE; 5685: register tree link; 5686: register enum tree_code code, ok_code = ERROR_MARK; 5687: register tree t = NULL_TREE; 5688: 5689: for (link = declspecs; link; link = TREE_CHAIN (link)) 5690: { 5691: register tree value = TREE_VALUE (link); 5692: 5693: code = TREE_CODE (value); 5694: if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE) 5695: { 5696: my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261); 5697: 5698: if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0) 5699: cp_error ("forward declaration of `%#T'", value); 5700: 5701: t = value; 5702: ok_code = code; 5703: found_tag++; 5704: } 5705: else if (value == ridpointers[(int) RID_STATIC] 5706: || value == ridpointers[(int) RID_EXTERN] 5707: || value == ridpointers[(int) RID_AUTO] 1.1.1.2 ! root 5708: || value == ridpointers[(int) RID_REGISTER] ! 5709: || value == ridpointers[(int) RID_INLINE] ! 5710: || value == ridpointers[(int) RID_VIRTUAL] ! 5711: || value == ridpointers[(int) RID_EXPLICIT]) 1.1 root 5712: ob_modifier = value; 5713: } 5714: 5715: /* This is where the variables in an anonymous union are 5716: declared. An anonymous union declaration looks like: 5717: union { ... } ; 5718: because there is no declarator after the union, the parser 5719: sends that declaration here. */ 5720: if (ok_code == UNION_TYPE 5721: && t != NULL_TREE 5722: && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE 5723: && ANON_AGGRNAME_P (TYPE_NAME (t))) 5724: || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL 5725: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))) 5726: { 5727: /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have 5728: function members. */ 5729: if (TYPE_FIELDS (t)) 5730: { 5731: tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, 1.1.1.2 ! root 5732: NULL_TREE, NULL_TREE); 1.1 root 5733: finish_anon_union (decl); 5734: } 5735: else 5736: error ("anonymous union cannot have a function member"); 5737: } 5738: else 5739: { 5740: /* Anonymous unions are objects, that's why we only check for 5741: inappropriate specifiers in this branch. */ 1.1.1.2 ! root 5742: 1.1 root 5743: if (ob_modifier) 1.1.1.2 ! root 5744: { ! 5745: if (ob_modifier == ridpointers[(int) RID_INLINE] ! 5746: || ob_modifier == ridpointers[(int) RID_VIRTUAL]) ! 5747: cp_error ("`%D' can only be specified for functions", ob_modifier); ! 5748: else if (ob_modifier == ridpointers[(int) RID_EXPLICIT]) ! 5749: cp_error ("`%D' can only be specified for constructors", ! 5750: ob_modifier); ! 5751: else ! 5752: cp_error ("`%D' can only be specified for objects and functions", ! 5753: ob_modifier); ! 5754: } 1.1 root 5755: 5756: if (found_tag == 0) 5757: pedwarn ("abstract declarator used as declaration"); 5758: else if (found_tag > 1) 5759: pedwarn ("multiple types in one declaration"); 5760: } 5761: } 5762: 5763: /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ 5764: 5765: tree 5766: groktypename (typename) 5767: tree typename; 5768: { 5769: if (TREE_CODE (typename) != TREE_LIST) 5770: return typename; 5771: return grokdeclarator (TREE_VALUE (typename), 5772: TREE_PURPOSE (typename), 1.1.1.2 ! root 5773: TYPENAME, 0, NULL_TREE, NULL_TREE); 1.1 root 5774: } 5775: 5776: /* Decode a declarator in an ordinary declaration or data definition. 5777: This is called as soon as the type information and variable name 5778: have been parsed, before parsing the initializer if any. 5779: Here we create the ..._DECL node, fill in its type, 5780: and put it on the list of decls for the current context. 5781: The ..._DECL node is returned as the value. 5782: 5783: Exception: for arrays where the length is not specified, 1.1.1.2 ! root 5784: the type is left null, to be filled in by `cp_finish_decl'. 1.1 root 5785: 5786: Function definitions do not come here; they go to start_function 5787: instead. However, external and forward declarations of functions 5788: do go through here. Structure field declarations are done by 5789: grokfield and not through here. */ 5790: 5791: /* Set this to zero to debug not using the temporary obstack 5792: to parse initializers. */ 5793: int debug_temp_inits = 1; 5794: 5795: tree 5796: start_decl (declarator, declspecs, initialized, raises) 5797: tree declarator, declspecs; 5798: int initialized; 5799: tree raises; 5800: { 5801: register tree decl; 5802: register tree type, tem; 5803: tree context; 5804: extern int have_extern_spec; 5805: extern int used_extern_spec; 5806: 5807: int init_written = initialized; 5808: 5809: /* This should only be done once on the top most decl. */ 5810: if (have_extern_spec && !used_extern_spec) 5811: { 5812: declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), 5813: declspecs); 5814: used_extern_spec = 1; 5815: } 5816: 1.1.1.2 ! root 5817: decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises, ! 5818: NULL_TREE); 1.1 root 5819: if (decl == NULL_TREE || decl == void_type_node) 5820: return NULL_TREE; 5821: 5822: type = TREE_TYPE (decl); 5823: 5824: /* Don't lose if destructors must be executed at file-level. */ 5825: if (TREE_STATIC (decl) 5826: && TYPE_NEEDS_DESTRUCTOR (type) 5827: && !TREE_PERMANENT (decl)) 5828: { 5829: push_obstacks (&permanent_obstack, &permanent_obstack); 5830: decl = copy_node (decl); 5831: if (TREE_CODE (type) == ARRAY_TYPE) 5832: { 5833: tree itype = TYPE_DOMAIN (type); 5834: if (itype && ! TREE_PERMANENT (itype)) 5835: { 5836: itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); 5837: type = build_cplus_array_type (TREE_TYPE (type), itype); 5838: TREE_TYPE (decl) = type; 5839: } 5840: } 5841: pop_obstacks (); 5842: } 5843: 1.1.1.2 ! root 5844: /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ 1.1 root 5845: push_obstacks_nochange (); 5846: 5847: context 5848: = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) 5849: ? DECL_CLASS_CONTEXT (decl) 5850: : DECL_CONTEXT (decl); 5851: 5852: if (processing_template_decl) 5853: { 5854: tree d; 5855: if (TREE_CODE (decl) == FUNCTION_DECL) 5856: { 5857: /* Declarator is a call_expr; extract arguments from it, since 5858: grokdeclarator didn't do it. */ 5859: tree args; 5860: args = copy_to_permanent (last_function_parms); 5861: if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) 5862: { 5863: tree t = TREE_TYPE (decl); 5864: 5865: t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */ 5866: if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE) 5867: { 5868: t = build_pointer_type (t); /* base type of `this' */ 5869: #if 1 5870: /* I suspect this is wrong. */ 5871: t = build_type_variant (t, flag_this_is_variable <= 0, 5872: 0); /* type of `this' */ 5873: #else 5874: t = build_type_variant (t, 0, 0); /* type of `this' */ 5875: #endif 5876: t = build (PARM_DECL, t, this_identifier); 5877: TREE_CHAIN (t) = args; 5878: args = t; 5879: } 5880: } 5881: DECL_ARGUMENTS (decl) = args; 5882: } 5883: d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl)); 5884: TREE_PUBLIC (d) = TREE_PUBLIC (decl); 5885: TREE_STATIC (d) = TREE_STATIC (decl); 5886: DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl) 5887: && !(context && !DECL_THIS_EXTERN (decl))); 5888: DECL_TEMPLATE_RESULT (d) = decl; 5889: decl = d; 5890: } 5891: 5892: /* If this type of object needs a cleanup, and control may 5893: jump past it, make a new binding level so that it is cleaned 5894: up only when it is initialized first. */ 5895: if (TYPE_NEEDS_DESTRUCTOR (type) 5896: && current_binding_level->more_cleanups_ok == 0) 5897: pushlevel_temporary (1); 5898: 5899: if (initialized) 5900: /* Is it valid for this decl to have an initializer at all? 5901: If not, set INITIALIZED to zero, which will indirectly 1.1.1.2 ! root 5902: tell `cp_finish_decl' to ignore the initializer once it is parsed. */ 1.1 root 5903: switch (TREE_CODE (decl)) 5904: { 5905: case TYPE_DECL: 5906: /* typedef foo = bar means give foo the same type as bar. 1.1.1.2 ! root 5907: We haven't parsed bar yet, so `cp_finish_decl' will fix that up. 1.1 root 5908: Any other case of an initialization in a TYPE_DECL is an error. */ 5909: if (pedantic || list_length (declspecs) > 1) 5910: { 5911: cp_error ("typedef `%D' is initialized", decl); 5912: initialized = 0; 5913: } 5914: break; 5915: 5916: case FUNCTION_DECL: 5917: cp_error ("function `%#D' is initialized like a variable", decl); 5918: initialized = 0; 5919: break; 5920: 5921: default: 5922: /* Don't allow initializations for incomplete types except for 5923: arrays which might be completed by the initialization. */ 5924: if (type == error_mark_node) 5925: ; /* Don't complain again. */ 5926: else if (TYPE_SIZE (type) != NULL_TREE) 5927: ; /* A complete type is ok. */ 5928: else if (TREE_CODE (type) != ARRAY_TYPE) 5929: { 5930: cp_error ("variable `%#D' has initializer but incomplete type", 5931: decl); 5932: initialized = 0; 5933: } 5934: else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE) 5935: { 5936: cp_error ("elements of array `%#D' have incomplete type", decl); 5937: initialized = 0; 5938: } 5939: } 5940: 5941: if (!initialized 5942: && TREE_CODE (decl) != TYPE_DECL 5943: && TREE_CODE (decl) != TEMPLATE_DECL 5944: && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) 5945: { 5946: if (TYPE_SIZE (type) == NULL_TREE) 5947: { 5948: cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", 5949: decl); 5950: /* Change the type so that assemble_variable will give 5951: DECL an rtl we can live with: (mem (const_int 0)). */ 5952: TREE_TYPE (decl) = error_mark_node; 5953: type = error_mark_node; 5954: } 5955: else 5956: { 5957: /* If any base type in the hierarchy of TYPE needs a constructor, 5958: then we set initialized to 1. This way any nodes which are 5959: created for the purposes of initializing this aggregate 5960: will live as long as it does. This is necessary for global 5961: aggregates which do not have their initializers processed until 5962: the end of the file. */ 5963: initialized = TYPE_NEEDS_CONSTRUCTING (type); 5964: } 5965: } 5966: 5967: if (initialized) 5968: { 1.1.1.2 ! root 5969: if (! toplevel_bindings_p () 1.1 root 5970: && DECL_EXTERNAL (decl)) 5971: cp_warning ("declaration of `%#D' has `extern' and is initialized", 5972: decl); 5973: DECL_EXTERNAL (decl) = 0; 1.1.1.2 ! root 5974: if ( toplevel_bindings_p ()) 1.1 root 5975: TREE_STATIC (decl) = 1; 5976: 5977: /* Tell `pushdecl' this is an initialized decl 5978: even though we don't yet have the initializer expression. 1.1.1.2 ! root 5979: Also tell `cp_finish_decl' it may store the real initializer. */ 1.1 root 5980: DECL_INITIAL (decl) = error_mark_node; 5981: } 5982: 5983: if (context && TYPE_SIZE (context) != NULL_TREE) 5984: { 5985: if (TREE_CODE (decl) == VAR_DECL) 5986: { 5987: tree field = lookup_field (context, DECL_NAME (decl), 0, 0); 5988: if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) 5989: cp_error ("`%#D' is not a static member of `%#T'", decl, context); 5990: else if (duplicate_decls (decl, field)) 5991: decl = field; 5992: } 1.1.1.2 ! root 5993: else ! 5994: { ! 5995: tree field = check_classfn (context, NULL_TREE, decl); ! 5996: if (field && duplicate_decls (decl, field)) ! 5997: decl = field; ! 5998: } ! 5999: ! 6000: /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */ 1.1 root 6001: if (DECL_LANG_SPECIFIC (decl)) 6002: DECL_IN_AGGR_P (decl) = 0; 1.1.1.2 ! root 6003: if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context)) ! 6004: SET_DECL_TEMPLATE_SPECIALIZATION (decl); ! 6005: ! 6006: /* Stupid stupid stupid stupid (jason 7/21/95) */ ! 6007: if (pedantic && DECL_EXTERNAL (decl) ! 6008: && ! DECL_TEMPLATE_SPECIALIZATION (decl)) ! 6009: cp_pedwarn ("declaration of `%#D' outside of class is not definition", ! 6010: decl); ! 6011: 1.1 root 6012: pushclass (context, 2); 6013: } 6014: 6015: /* Add this decl to the current binding level, but not if it 6016: comes from another scope, e.g. a static member variable. 6017: TEM may equal DECL or it may be a previous decl of the same name. */ 6018: 6019: if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE) 6020: || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ()) 6021: || TREE_CODE (type) == LANG_TYPE) 6022: tem = decl; 6023: else 6024: tem = pushdecl (decl); 6025: 6026: /* Tell the back-end to use or not use .common as appropriate. If we say 6027: -fconserve-space, we want this to save space, at the expense of wrong 6028: semantics. If we say -fno-conserve-space, we want this to produce 6029: errors about redefs; to do this we force variables into the data 6030: segment. Common storage is okay for non-public uninitialized data; 6031: the linker can't match it with storage from other files, and we may 6032: save some disk space. */ 6033: DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); 6034: 6035: #if 0 6036: /* We don't do this yet for GNU C++. */ 6037: /* For a local variable, define the RTL now. */ 1.1.1.2 ! root 6038: if (! toplevel_bindings_p () 1.1 root 6039: /* But not if this is a duplicate decl 6040: and we preserved the rtl from the previous one 6041: (which may or may not happen). */ 6042: && DECL_RTL (tem) == NULL_RTX) 6043: { 6044: if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) 6045: expand_decl (tem); 6046: else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE 6047: && DECL_INITIAL (tem) != NULL_TREE) 6048: expand_decl (tem); 6049: } 6050: #endif 6051: 6052: if (TREE_CODE (decl) == TEMPLATE_DECL) 6053: { 6054: tree result = DECL_TEMPLATE_RESULT (decl); 6055: if (DECL_CONTEXT (result) != NULL_TREE) 6056: { 6057: tree type; 6058: type = DECL_CONTEXT (result); 6059: 6060: if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE) 6061: { 6062: cp_error ("declaration of `%D' in non-template type `%T'", 6063: decl, type); 6064: return NULL_TREE; 6065: } 6066: 6067: if (TREE_CODE (result) == FUNCTION_DECL) 6068: return tem; 6069: else if (TREE_CODE (result) == VAR_DECL) 6070: { 6071: #if 0 6072: tree tmpl = UPT_TEMPLATE (type); 6073: 6074: fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__); 6075: print_node_brief (stderr, "", DECL_NAME (tem), 0); 6076: fprintf (stderr, " to class %s\n", 6077: IDENTIFIER_POINTER (DECL_NAME (tmpl))); 6078: DECL_TEMPLATE_MEMBERS (tmpl) 6079: = perm_tree_cons (DECL_NAME (tem), tem, 6080: DECL_TEMPLATE_MEMBERS (tmpl)); 6081: return tem; 6082: #else 6083: sorry ("static data member templates"); 6084: return NULL_TREE; 6085: #endif 6086: } 6087: else 6088: my_friendly_abort (13); 6089: } 6090: else if (TREE_CODE (result) == FUNCTION_DECL) 6091: /*tem = push_overloaded_decl (tem, 0)*/; 6092: else if (TREE_CODE (result) == VAR_DECL) 6093: { 6094: cp_error ("data template `%#D' must be member of a class template", 6095: result); 6096: return NULL_TREE; 6097: } 6098: else if (TREE_CODE (result) == TYPE_DECL) 6099: { 6100: cp_error ("invalid template `%#D'", result); 6101: return NULL_TREE; 6102: } 6103: else 6104: my_friendly_abort (14); 6105: } 6106: 6107: if (init_written 6108: && ! (TREE_CODE (tem) == PARM_DECL 6109: || (TREE_READONLY (tem) 6110: && (TREE_CODE (tem) == VAR_DECL 6111: || TREE_CODE (tem) == FIELD_DECL)))) 6112: { 6113: /* When parsing and digesting the initializer, 6114: use temporary storage. Do this even if we will ignore the value. */ 1.1.1.2 ! root 6115: if (toplevel_bindings_p () && debug_temp_inits) 1.1 root 6116: { 6117: if (TYPE_NEEDS_CONSTRUCTING (type) 6118: || TREE_CODE (type) == REFERENCE_TYPE) 6119: /* In this case, the initializer must lay down in permanent 6120: storage, since it will be saved until `finish_file' is run. */ 6121: ; 6122: else 6123: temporary_allocation (); 6124: } 6125: } 6126: 6127: if (flag_cadillac) 6128: cadillac_start_decl (tem); 6129: 6130: return tem; 6131: } 6132: 6133: #if 0 /* unused */ 6134: static void 6135: make_temporary_for_reference (decl, ctor_call, init, cleanupp) 6136: tree decl, ctor_call, init; 6137: tree *cleanupp; 6138: { 6139: tree type = TREE_TYPE (decl); 6140: tree target_type = TREE_TYPE (type); 6141: tree tmp, tmp_addr; 6142: 6143: if (ctor_call) 6144: { 6145: tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1)); 6146: if (TREE_CODE (tmp_addr) == NOP_EXPR) 6147: tmp_addr = TREE_OPERAND (tmp_addr, 0); 6148: my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146); 6149: tmp = TREE_OPERAND (tmp_addr, 0); 6150: } 6151: else 6152: { 1.1.1.2 ! root 6153: tmp = get_temp_name (target_type, toplevel_bindings_p ()); 1.1 root 6154: tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0); 6155: } 6156: 6157: TREE_TYPE (tmp_addr) = build_pointer_type (target_type); 1.1.1.2 ! root 6158: DECL_INITIAL (decl) = convert (build_pointer_type (target_type), tmp_addr); 1.1 root 6159: TREE_TYPE (DECL_INITIAL (decl)) = type; 6160: if (TYPE_NEEDS_CONSTRUCTING (target_type)) 6161: { 1.1.1.2 ! root 6162: if (toplevel_bindings_p ()) 1.1 root 6163: { 6164: /* lay this variable out now. Otherwise `output_addressed_constants' 6165: gets confused by its initializer. */ 6166: make_decl_rtl (tmp, NULL_PTR, 1); 6167: static_aggregates = perm_tree_cons (init, tmp, static_aggregates); 6168: } 6169: else 6170: { 6171: if (ctor_call != NULL_TREE) 6172: init = ctor_call; 6173: else 6174: init = build_method_call (tmp, constructor_name_full (target_type), 6175: build_tree_list (NULL_TREE, init), 6176: NULL_TREE, LOOKUP_NORMAL); 6177: DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init, 6178: DECL_INITIAL (decl)); 6179: *cleanupp = maybe_build_cleanup (tmp); 6180: } 6181: } 6182: else 6183: { 6184: DECL_INITIAL (tmp) = init; 1.1.1.2 ! root 6185: TREE_STATIC (tmp) = toplevel_bindings_p (); ! 6186: cp_finish_decl (tmp, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); 1.1 root 6187: } 6188: if (TREE_STATIC (tmp)) 6189: preserve_initializer (); 6190: } 6191: #endif 6192: 6193: /* Handle initialization of references. 1.1.1.2 ! root 6194: These three arguments from from `cp_finish_decl', and have the 1.1 root 6195: same meaning here that they do there. */ 6196: /* quotes on semantics can be found in ARM 8.4.3. */ 6197: static void 6198: grok_reference_init (decl, type, init, cleanupp) 6199: tree decl, type, init; 6200: tree *cleanupp; 6201: { 6202: tree tmp; 6203: 6204: if (init == NULL_TREE) 6205: { 1.1.1.2 ! root 6206: if ((DECL_LANG_SPECIFIC (decl) == 0 ! 6207: || DECL_IN_AGGR_P (decl) == 0) ! 6208: && ! DECL_THIS_EXTERN (decl)) 1.1 root 6209: { 6210: cp_error ("`%D' declared as reference but not initialized", decl); 6211: if (TREE_CODE (decl) == VAR_DECL) 6212: SET_DECL_REFERENCE_SLOT (decl, error_mark_node); 6213: } 6214: return; 6215: } 6216: 6217: if (init == error_mark_node) 6218: return; 6219: 6220: if (TREE_CODE (type) == REFERENCE_TYPE 6221: && TREE_CODE (init) == CONSTRUCTOR) 6222: { 6223: cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl); 6224: return; 6225: } 6226: 6227: if (TREE_CODE (init) == TREE_LIST) 6228: init = build_compound_expr (init); 6229: 1.1.1.2 ! root 6230: if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE) ! 6231: init = convert_from_reference (init); ! 6232: 1.1 root 6233: if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE 6234: && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) 6235: { 6236: /* Note: default conversion is only called in very special cases. */ 6237: init = default_conversion (init); 6238: } 6239: 6240: tmp = convert_to_reference 6241: (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl); 6242: 6243: if (tmp == error_mark_node) 6244: goto fail; 6245: else if (tmp != NULL_TREE) 6246: { 6247: tree subtype = TREE_TYPE (type); 6248: init = tmp; 6249: 6250: /* Associate the cleanup with the reference so that we 6251: don't get burned by "aggressive" cleanup policy. */ 6252: if (TYPE_NEEDS_DESTRUCTOR (subtype)) 6253: { 6254: if (TREE_CODE (init) == WITH_CLEANUP_EXPR) 6255: { 6256: *cleanupp = TREE_OPERAND (init, 2); 6257: TREE_OPERAND (init, 2) = error_mark_node; 6258: } 6259: else 6260: { 6261: if (TREE_CODE (tmp) == ADDR_EXPR) 6262: tmp = TREE_OPERAND (tmp, 0); 6263: if (TREE_CODE (tmp) == TARGET_EXPR) 6264: { 6265: *cleanupp = build_delete 1.1.1.2 ! root 6266: (build_pointer_type (subtype), 1.1 root 6267: build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0), 6268: integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0); 6269: TREE_OPERAND (tmp, 2) = error_mark_node; 6270: } 6271: } 6272: } 6273: 6274: DECL_INITIAL (decl) = save_expr (init); 6275: } 6276: else 6277: { 6278: cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); 6279: goto fail; 6280: } 6281: 6282: /* ?? Can this be optimized in some cases to 6283: hand back the DECL_INITIAL slot?? */ 6284: if (TYPE_SIZE (TREE_TYPE (type))) 6285: { 6286: init = convert_from_reference (decl); 6287: if (TREE_PERMANENT (decl)) 6288: init = copy_to_permanent (init); 6289: SET_DECL_REFERENCE_SLOT (decl, init); 6290: } 6291: 6292: if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) 6293: { 6294: expand_static_init (decl, DECL_INITIAL (decl)); 6295: DECL_INITIAL (decl) = NULL_TREE; 6296: } 6297: return; 6298: 6299: fail: 6300: if (TREE_CODE (decl) == VAR_DECL) 6301: SET_DECL_REFERENCE_SLOT (decl, error_mark_node); 6302: return; 6303: } 6304: 1.1.1.2 ! root 6305: /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from ! 6306: mucking with forces it does not comprehend (i.e. initialization with a ! 6307: constructor). If we are at global scope and won't go into COMMON, fill ! 6308: it in with a dummy CONSTRUCTOR to force the variable into .data; ! 6309: otherwise we can use error_mark_node. */ ! 6310: ! 6311: static tree ! 6312: obscure_complex_init (decl, init) ! 6313: tree decl, init; ! 6314: { ! 6315: if (! flag_no_inline && TREE_STATIC (decl)) ! 6316: { ! 6317: if (extract_init (decl, init)) ! 6318: return NULL_TREE; ! 6319: } ! 6320: ! 6321: if (toplevel_bindings_p () && ! DECL_COMMON (decl)) ! 6322: DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE, ! 6323: NULL_TREE); ! 6324: else ! 6325: DECL_INITIAL (decl) = error_mark_node; ! 6326: ! 6327: return init; ! 6328: } ! 6329: 1.1 root 6330: /* Finish processing of a declaration; 6331: install its line number and initial value. 6332: If the length of an array type is not known before, 6333: it must be determined now, from the initial value, or it is an error. 6334: 6335: Call `pop_obstacks' iff NEED_POP is nonzero. 6336: 1.1.1.2 ! root 6337: For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers 1.1 root 6338: for aggregates that have constructors alive on the permanent obstack, 6339: so that the global initializing functions can be written at the end. 6340: 6341: INIT0 holds the value of an initializer that should be allowed to escape 6342: the normal rules. 6343: 1.1.1.2 ! root 6344: FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0 ! 6345: if the (init) syntax was used. ! 6346: 1.1 root 6347: For functions that take default parameters, DECL points to its 1.1.1.2 ! root 6348: "maximal" instantiation. `cp_finish_decl' must then also declared its 1.1 root 6349: subsequently lower and lower forms of instantiation, checking for 6350: ambiguity as it goes. This can be sped up later. */ 6351: 6352: void 1.1.1.2 ! root 6353: cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) 1.1 root 6354: tree decl, init; 6355: tree asmspec_tree; 6356: int need_pop; 1.1.1.2 ! root 6357: int flags; 1.1 root 6358: { 6359: register tree type; 6360: tree cleanup = NULL_TREE, ttype; 6361: int was_incomplete; 6362: int temporary = allocation_temporary_p (); 6363: char *asmspec = NULL; 6364: int was_readonly = 0; 6365: 6366: /* If this is 0, then we did not change obstacks. */ 6367: if (! decl) 6368: { 6369: if (init) 6370: error ("assignment (not initialization) in declaration"); 6371: return; 6372: } 6373: 6374: /* If a name was specified, get the string. */ 6375: if (asmspec_tree) 6376: asmspec = TREE_STRING_POINTER (asmspec_tree); 6377: 6378: /* If the type of the thing we are declaring either has 6379: a constructor, or has a virtual function table pointer, 6380: AND its initialization was accepted by `start_decl', 6381: then we stayed on the permanent obstack through the 6382: declaration, otherwise, changed obstacks as GCC would. */ 6383: 6384: type = TREE_TYPE (decl); 6385: 6386: if (type == error_mark_node) 6387: { 1.1.1.2 ! root 6388: if (toplevel_bindings_p () && temporary) 1.1 root 6389: end_temporary_allocation (); 6390: 6391: return; 6392: } 6393: 6394: was_incomplete = (DECL_SIZE (decl) == NULL_TREE); 6395: 6396: /* Take care of TYPE_DECLs up front. */ 6397: if (TREE_CODE (decl) == TYPE_DECL) 6398: { 6399: if (init && DECL_INITIAL (decl)) 6400: { 6401: /* typedef foo = bar; store the type of bar as the type of foo. */ 6402: TREE_TYPE (decl) = type = TREE_TYPE (init); 6403: DECL_INITIAL (decl) = init = NULL_TREE; 6404: } 6405: if (type != error_mark_node 6406: && IS_AGGR_TYPE (type) && DECL_NAME (decl)) 6407: { 6408: if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) 6409: cp_warning ("shadowing previous type declaration of `%#D'", decl); 6410: set_identifier_type_value (DECL_NAME (decl), type); 6411: CLASSTYPE_GOT_SEMICOLON (type) = 1; 6412: } 6413: GNU_xref_decl (current_function_decl, decl); 6414: rest_of_decl_compilation (decl, NULL_PTR, 6415: DECL_CONTEXT (decl) == NULL_TREE, 0); 6416: goto finish_end; 6417: } 6418: if (TREE_CODE (decl) != FUNCTION_DECL) 6419: { 6420: ttype = target_type (type); 6421: #if 0 /* WTF? -KR 6422: Leave this out until we can figure out why it was 6423: needed/desirable in the first place. Then put a comment 6424: here explaining why. Or just delete the code if no ill 6425: effects arise. */ 6426: if (TYPE_NAME (ttype) 6427: && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL 6428: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype))) 6429: { 6430: tree old_id = TYPE_IDENTIFIER (ttype); 6431: char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2); 6432: /* Need to preserve template data for UPT nodes. */ 6433: tree old_template = IDENTIFIER_TEMPLATE (old_id); 6434: newname[0] = '_'; 6435: bcopy (IDENTIFIER_POINTER (old_id), newname + 1, 6436: IDENTIFIER_LENGTH (old_id) + 1); 6437: old_id = get_identifier (newname); 6438: lookup_tag_reverse (ttype, old_id); 6439: TYPE_IDENTIFIER (ttype) = old_id; 6440: IDENTIFIER_TEMPLATE (old_id) = old_template; 6441: } 6442: #endif 6443: } 6444: 6445: if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) 6446: && TYPE_NEEDS_CONSTRUCTING (type)) 6447: { 6448: 6449: /* Currently, GNU C++ puts constants in text space, making them 6450: impossible to initialize. In the future, one would hope for 6451: an operating system which understood the difference between 6452: initialization and the running of a program. */ 6453: was_readonly = 1; 6454: TREE_READONLY (decl) = 0; 6455: } 6456: 6457: if (TREE_CODE (decl) == FIELD_DECL) 6458: { 6459: if (init && init != error_mark_node) 6460: my_friendly_assert (TREE_PERMANENT (init), 147); 6461: 6462: if (asmspec) 6463: { 6464: /* This must override the asm specifier which was placed 1.1.1.2 ! root 6465: by grokclassfn. Lay this out fresh. */ 1.1 root 6466: DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; 6467: DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); 6468: make_decl_rtl (decl, asmspec, 0); 6469: } 6470: } 6471: /* If `start_decl' didn't like having an initialization, ignore it now. */ 6472: else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) 6473: init = NULL_TREE; 6474: else if (DECL_EXTERNAL (decl)) 6475: ; 6476: else if (TREE_CODE (type) == REFERENCE_TYPE 6477: || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type))) 6478: { 6479: if (TREE_STATIC (decl)) 6480: make_decl_rtl (decl, NULL_PTR, 1.1.1.2 ! root 6481: toplevel_bindings_p () 1.1 root 6482: || pseudo_global_level_p ()); 6483: grok_reference_init (decl, type, init, &cleanup); 6484: init = NULL_TREE; 6485: } 6486: 6487: GNU_xref_decl (current_function_decl, decl); 6488: 6489: if (TREE_CODE (decl) == FIELD_DECL) 6490: ; 6491: else if (TREE_CODE (decl) == CONST_DECL) 6492: { 6493: my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); 6494: 6495: DECL_INITIAL (decl) = init; 6496: 6497: /* This will keep us from needing to worry about our obstacks. */ 6498: my_friendly_assert (init != NULL_TREE, 149); 6499: init = NULL_TREE; 6500: } 6501: else if (init) 6502: { 6503: if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) 6504: { 6505: if (TREE_CODE (type) == ARRAY_TYPE) 6506: init = digest_init (type, init, (tree *) 0); 6507: else if (TREE_CODE (init) == CONSTRUCTOR) 6508: { 1.1.1.2 ! root 6509: if (TYPE_NON_AGGREGATE_CLASS (type)) 1.1 root 6510: { 6511: cp_error ("`%D' must be initialized by constructor, not by `{...}'", 6512: decl); 6513: init = error_mark_node; 6514: } 6515: else 6516: goto dont_use_constructor; 6517: } 6518: } 6519: else 6520: { 6521: dont_use_constructor: 6522: if (TREE_CODE (init) != TREE_VEC) 6523: init = store_init_value (decl, init); 6524: } 1.1.1.2 ! root 6525: ! 6526: if (init) ! 6527: /* We must hide the initializer so that expand_decl ! 6528: won't try to do something it does not understand. */ ! 6529: init = obscure_complex_init (decl, init); 1.1 root 6530: } 6531: else if (DECL_EXTERNAL (decl)) 6532: ; 6533: else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' 6534: && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) 6535: { 6536: tree ctype = type; 6537: while (TREE_CODE (ctype) == ARRAY_TYPE) 6538: ctype = TREE_TYPE (ctype); 6539: if (! TYPE_NEEDS_CONSTRUCTING (ctype)) 6540: { 6541: if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype)) 6542: cp_error ("structure `%D' with uninitialized const members", decl); 6543: if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype)) 6544: cp_error ("structure `%D' with uninitialized reference members", 6545: decl); 6546: } 6547: 6548: if (TREE_CODE (decl) == VAR_DECL 6549: && !DECL_INITIAL (decl) 6550: && !TYPE_NEEDS_CONSTRUCTING (type) 6551: && (TYPE_READONLY (type) || TREE_READONLY (decl))) 6552: cp_error ("uninitialized const `%D'", decl); 6553: 1.1.1.2 ! root 6554: if (TYPE_SIZE (type) != NULL_TREE ! 6555: && TYPE_NEEDS_CONSTRUCTING (type)) ! 6556: init = obscure_complex_init (decl, NULL_TREE); 1.1 root 6557: } 6558: else if (TREE_CODE (decl) == VAR_DECL 6559: && TREE_CODE (type) != REFERENCE_TYPE 6560: && (TYPE_READONLY (type) || TREE_READONLY (decl))) 6561: { 6562: /* ``Unless explicitly declared extern, a const object does not have 6563: external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 6564: However, if it's `const int foo = 1; const int foo;', don't complain 6565: about the second decl, since it does have an initializer before. 6566: We deliberately don't complain about arrays, because they're 6567: supposed to be initialized by a constructor. */ 6568: if (! DECL_INITIAL (decl) 6569: && TREE_CODE (type) != ARRAY_TYPE 6570: && (!pedantic || !current_class_type)) 6571: cp_error ("uninitialized const `%#D'", decl); 6572: } 6573: 6574: /* For top-level declaration, the initial value was read in 6575: the temporary obstack. MAXINDEX, rtl, etc. to be made below 6576: must go in the permanent obstack; but don't discard the 6577: temporary data yet. */ 6578: 1.1.1.2 ! root 6579: if (toplevel_bindings_p () && temporary) 1.1 root 6580: end_temporary_allocation (); 6581: 6582: /* Deduce size of array from initialization, if not already known. */ 6583: 6584: if (TREE_CODE (type) == ARRAY_TYPE 6585: && TYPE_DOMAIN (type) == NULL_TREE 6586: && TREE_CODE (decl) != TYPE_DECL) 6587: { 6588: int do_default 6589: = (TREE_STATIC (decl) 6590: /* Even if pedantic, an external linkage array 6591: may have incomplete type at first. */ 6592: ? pedantic && ! DECL_EXTERNAL (decl) 6593: : !DECL_EXTERNAL (decl)); 6594: tree initializer = init ? init : DECL_INITIAL (decl); 6595: int failure = complete_array_type (type, initializer, do_default); 6596: 6597: if (failure == 1) 6598: cp_error ("initializer fails to determine size of `%D'", decl); 6599: 6600: if (failure == 2) 6601: { 6602: if (do_default) 6603: cp_error ("array size missing in `%D'", decl); 6604: /* If a `static' var's size isn't known, make it extern as 6605: well as static, so it does not get allocated. If it's not 6606: `static', then don't mark it extern; finish_incomplete_decl 6607: will give it a default size and it will get allocated. */ 6608: else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) 6609: DECL_EXTERNAL (decl) = 1; 6610: } 6611: 6612: if (pedantic && TYPE_DOMAIN (type) != NULL_TREE 6613: && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 6614: integer_zero_node)) 6615: cp_error ("zero-size array `%D'", decl); 6616: 6617: layout_decl (decl, 0); 6618: } 6619: 6620: if (TREE_CODE (decl) == VAR_DECL) 6621: { 6622: if (DECL_SIZE (decl) == NULL_TREE 6623: && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE) 6624: layout_decl (decl, 0); 6625: 6626: if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) 6627: { 6628: /* A static variable with an incomplete type: 6629: that is an error if it is initialized. 6630: Otherwise, let it through, but if it is not `extern' 6631: then it may cause an error message later. */ 6632: if (DECL_INITIAL (decl) != NULL_TREE) 6633: cp_error ("storage size of `%D' isn't known", decl); 6634: init = NULL_TREE; 6635: } 6636: else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) 6637: { 6638: /* An automatic variable with an incomplete type: that is an error. 6639: Don't talk about array types here, since we took care of that 6640: message in grokdeclarator. */ 6641: cp_error ("storage size of `%D' isn't known", decl); 6642: TREE_TYPE (decl) = error_mark_node; 6643: } 6644: else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) 6645: /* Let debugger know it should output info for this type. */ 6646: note_debug_info_needed (ttype); 6647: 1.1.1.2 ! root 6648: if (TREE_STATIC (decl) && DECL_CONTEXT (decl) ! 6649: && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't') ! 6650: note_debug_info_needed (DECL_CONTEXT (decl)); ! 6651: 1.1 root 6652: if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) 6653: && DECL_SIZE (decl) != NULL_TREE 6654: && ! TREE_CONSTANT (DECL_SIZE (decl))) 6655: { 6656: if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) 6657: constant_expression_warning (DECL_SIZE (decl)); 6658: else 6659: cp_error ("storage size of `%D' isn't constant", decl); 6660: } 6661: 6662: if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type)) 6663: { 6664: int yes = suspend_momentary (); 6665: 6666: /* If INIT comes from a functional cast, use the cleanup 6667: we built for that. Otherwise, make our own cleanup. */ 6668: if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR 6669: && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1)) 6670: { 6671: cleanup = TREE_OPERAND (init, 2); 6672: init = TREE_OPERAND (init, 0); 6673: current_binding_level->have_cleanups = 1; 6674: } 6675: else 6676: cleanup = maybe_build_cleanup (decl); 6677: resume_momentary (yes); 6678: } 6679: } 6680: /* PARM_DECLs get cleanups, too. */ 6681: else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) 6682: { 6683: if (temporary) 6684: end_temporary_allocation (); 6685: cleanup = maybe_build_cleanup (decl); 6686: if (temporary) 6687: resume_temporary_allocation (); 6688: } 6689: 6690: /* Output the assembler code and/or RTL code for variables and functions, 6691: unless the type is an undefined structure or union. 6692: If not, it will get done when the type is completed. */ 6693: 6694: if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL 6695: || TREE_CODE (decl) == RESULT_DECL) 6696: { 6697: /* ??? FIXME: What about nested classes? */ 1.1.1.2 ! root 6698: int toplev = toplevel_bindings_p () || pseudo_global_level_p (); 1.1 root 6699: int was_temp 6700: = ((flag_traditional 6701: || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type))) 6702: && allocation_temporary_p ()); 6703: 6704: if (was_temp) 6705: end_temporary_allocation (); 6706: 6707: if (TREE_CODE (decl) == VAR_DECL 1.1.1.2 ! root 6708: && ! toplevel_bindings_p () 1.1 root 6709: && ! TREE_STATIC (decl) 6710: && type_needs_gc_entry (type)) 6711: DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index); 6712: 6713: if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) 6714: make_decl_rtl (decl, NULL_PTR, toplev); 6715: else if (TREE_CODE (decl) == VAR_DECL 6716: && TREE_READONLY (decl) 6717: && DECL_INITIAL (decl) != NULL_TREE 6718: && DECL_INITIAL (decl) != error_mark_node 6719: && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) 6720: { 6721: DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); 6722: 6723: if (asmspec) 6724: DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); 6725: 6726: if (! toplev 6727: && TREE_STATIC (decl) 6728: && ! TREE_SIDE_EFFECTS (decl) 6729: && ! TREE_PUBLIC (decl) 6730: && ! DECL_EXTERNAL (decl) 6731: && ! TYPE_NEEDS_DESTRUCTOR (type) 6732: && DECL_MODE (decl) != BLKmode) 6733: { 6734: /* If this variable is really a constant, then fill its DECL_RTL 6735: slot with something which won't take up storage. 6736: If something later should take its address, we can always give 6737: it legitimate RTL at that time. */ 6738: DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); 6739: store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); 6740: TREE_ASM_WRITTEN (decl) = 1; 6741: } 6742: else if (toplev && ! TREE_PUBLIC (decl)) 6743: { 6744: /* If this is a static const, change its apparent linkage 1.1.1.2 ! root 6745: if it belongs to a #pragma interface. */ 1.1 root 6746: if (!interface_unknown) 6747: { 6748: TREE_PUBLIC (decl) = 1; 6749: DECL_EXTERNAL (decl) = interface_only; 6750: } 6751: make_decl_rtl (decl, asmspec, toplev); 6752: } 6753: else 6754: rest_of_decl_compilation (decl, asmspec, toplev, 0); 6755: } 6756: else if (TREE_CODE (decl) == VAR_DECL 6757: && DECL_LANG_SPECIFIC (decl) 6758: && DECL_IN_AGGR_P (decl)) 6759: { 6760: if (TREE_STATIC (decl)) 6761: { 6762: if (init == NULL_TREE 6763: #ifdef DEFAULT_STATIC_DEFS 6764: /* If this code is dead, then users must 6765: explicitly declare static member variables 6766: outside the class def'n as well. */ 6767: && TYPE_NEEDS_CONSTRUCTING (type) 6768: #endif 6769: ) 6770: { 6771: DECL_EXTERNAL (decl) = 1; 6772: make_decl_rtl (decl, asmspec, 1); 6773: } 6774: else 6775: rest_of_decl_compilation (decl, asmspec, toplev, 0); 6776: } 6777: else 6778: /* Just a constant field. Should not need any rtl. */ 6779: goto finish_end0; 6780: } 6781: else 6782: rest_of_decl_compilation (decl, asmspec, toplev, 0); 6783: 6784: if (was_temp) 6785: resume_temporary_allocation (); 6786: 6787: if (type != error_mark_node 6788: && TYPE_LANG_SPECIFIC (type) 6789: && CLASSTYPE_ABSTRACT_VIRTUALS (type)) 6790: abstract_virtuals_error (decl, type); 6791: else if ((TREE_CODE (type) == FUNCTION_TYPE 6792: || TREE_CODE (type) == METHOD_TYPE) 6793: && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) 6794: && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) 6795: abstract_virtuals_error (decl, TREE_TYPE (type)); 6796: 6797: if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type)) 6798: signature_error (decl, type); 6799: else if ((TREE_CODE (type) == FUNCTION_TYPE 6800: || TREE_CODE (type) == METHOD_TYPE) 6801: && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) 6802: && IS_SIGNATURE (TREE_TYPE (type))) 6803: signature_error (decl, TREE_TYPE (type)); 6804: 6805: if (TREE_CODE (decl) == FUNCTION_DECL) 1.1.1.2 ! root 6806: ; 1.1 root 6807: else if (DECL_EXTERNAL (decl)) 6808: ; 6809: else if (TREE_STATIC (decl) && type != error_mark_node) 6810: { 6811: /* Cleanups for static variables are handled by `finish_file'. */ 1.1.1.2 ! root 6812: if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE ! 6813: || TYPE_NEEDS_DESTRUCTOR (type)) 1.1 root 6814: expand_static_init (decl, init); 6815: 6816: /* Make entry in appropriate vector. */ 6817: if (flag_gc && type_needs_gc_entry (type)) 6818: build_static_gc_entry (decl, type); 6819: } 6820: else if (! toplev) 6821: { 6822: tree old_cleanups = cleanups_this_call; 6823: /* This is a declared decl which must live until the 6824: end of the binding contour. It may need a cleanup. */ 6825: 6826: /* Recompute the RTL of a local array now 6827: if it used to be an incomplete type. */ 6828: if (was_incomplete && ! TREE_STATIC (decl)) 6829: { 6830: /* If we used it already as memory, it must stay in memory. */ 6831: TREE_ADDRESSABLE (decl) = TREE_USED (decl); 6832: /* If it's still incomplete now, no init will save it. */ 6833: if (DECL_SIZE (decl) == NULL_TREE) 6834: DECL_INITIAL (decl) = NULL_TREE; 6835: expand_decl (decl); 6836: } 6837: else if (! TREE_ASM_WRITTEN (decl) 6838: && (TYPE_SIZE (type) != NULL_TREE 6839: || TREE_CODE (type) == ARRAY_TYPE)) 6840: { 6841: /* Do this here, because we did not expand this decl's 6842: rtl in start_decl. */ 6843: if (DECL_RTL (decl) == NULL_RTX) 6844: expand_decl (decl); 6845: else if (cleanup) 6846: { 6847: /* XXX: Why don't we use decl here? */ 6848: /* Ans: Because it was already expanded? */ 1.1.1.2 ! root 6849: if (! cp_expand_decl_cleanup (NULL_TREE, cleanup)) 1.1 root 6850: cp_error ("parser lost in parsing declaration of `%D'", 6851: decl); 6852: /* Cleanup used up here. */ 6853: cleanup = NULL_TREE; 6854: } 6855: } 6856: 6857: if (DECL_SIZE (decl) && type != error_mark_node) 6858: { 6859: /* Compute and store the initial value. */ 6860: expand_decl_init (decl); 6861: 6862: if (init || TYPE_NEEDS_CONSTRUCTING (type)) 6863: { 6864: emit_line_note (DECL_SOURCE_FILE (decl), 6865: DECL_SOURCE_LINE (decl)); 1.1.1.2 ! root 6866: expand_aggr_init (decl, init, 0, flags); 1.1 root 6867: } 6868: 6869: /* Set this to 0 so we can tell whether an aggregate which 6870: was initialized was ever used. Don't do this if it has a 6871: destructor, so we don't complain about the 'resource 6872: allocation is initialization' idiom. */ 6873: if (TYPE_NEEDS_CONSTRUCTING (type) && cleanup == NULL_TREE) 6874: TREE_USED (decl) = 0; 6875: 6876: /* Store the cleanup, if there was one. */ 6877: if (cleanup) 6878: { 1.1.1.2 ! root 6879: if (! cp_expand_decl_cleanup (decl, cleanup)) 1.1 root 6880: cp_error ("parser lost in parsing declaration of `%D'", 6881: decl); 6882: } 6883: } 6884: /* Cleanup any temporaries needed for the initial value. */ 6885: expand_cleanups_to (old_cleanups); 6886: } 6887: finish_end0: 6888: 6889: /* Undo call to `pushclass' that was done in `start_decl' 6890: due to initialization of qualified member variable. 6891: I.e., Foo::x = 10; */ 6892: { 1.1.1.2 ! root 6893: tree context = DECL_REAL_CONTEXT (decl); 1.1 root 6894: if (context 6895: && TREE_CODE_CLASS (TREE_CODE (context)) == 't' 6896: && (TREE_CODE (decl) == VAR_DECL 6897: /* We also have a pushclass done that we need to undo here 6898: if we're at top level and declare a method. */ 6899: || (TREE_CODE (decl) == FUNCTION_DECL 6900: /* If size hasn't been set, we're still defining it, 6901: and therefore inside the class body; don't pop 6902: the binding level.. */ 6903: && TYPE_SIZE (context) != NULL_TREE 6904: /* The binding level gets popped elsewhere for a 6905: friend declaration inside another class. */ 6906: /* 6907: && TYPE_IDENTIFIER (context) == current_class_name 6908: */ 6909: && context == current_class_type 6910: ))) 6911: popclass (1); 6912: } 6913: } 6914: 6915: finish_end: 6916: 6917: /* If requested, warn about definitions of large data objects. */ 6918: 6919: if (warn_larger_than 6920: && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) 6921: && !DECL_EXTERNAL (decl)) 6922: { 6923: register tree decl_size = DECL_SIZE (decl); 6924: 6925: if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) 6926: { 6927: unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT; 6928: 6929: if (units > larger_than_size) 6930: warning_with_decl (decl, "size of `%s' is %u bytes", units); 6931: } 6932: } 6933: 6934: if (need_pop) 6935: { 6936: /* Resume permanent allocation, if not within a function. */ 6937: /* The corresponding push_obstacks_nochange is in start_decl, 6938: start_method, groktypename, and in grokfield. */ 6939: pop_obstacks (); 6940: } 6941: 6942: if (was_readonly) 6943: TREE_READONLY (decl) = 1; 6944: 6945: if (flag_cadillac) 6946: cadillac_finish_decl (decl); 6947: } 6948: 1.1.1.2 ! root 6949: /* This is here for a midend callback from c-common.c */ ! 6950: void ! 6951: finish_decl (decl, init, asmspec_tree) ! 6952: tree decl, init; ! 6953: tree asmspec_tree; ! 6954: { ! 6955: cp_finish_decl (decl, init, asmspec_tree, 1, 0); ! 6956: } ! 6957: 1.1 root 6958: void 6959: expand_static_init (decl, init) 6960: tree decl; 6961: tree init; 6962: { 6963: tree oldstatic = value_member (decl, static_aggregates); 6964: tree old_cleanups; 6965: 6966: if (oldstatic) 6967: { 6968: if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) 6969: cp_error ("multiple initializations given for `%D'", decl); 6970: } 1.1.1.2 ! root 6971: else if (! toplevel_bindings_p () && ! pseudo_global_level_p ()) 1.1 root 6972: { 6973: /* Emit code to perform this initialization but once. */ 6974: tree temp; 6975: 6976: /* Remember this information until end of file. */ 6977: push_obstacks (&permanent_obstack, &permanent_obstack); 6978: 6979: /* Emit code to perform this initialization but once. */ 6980: temp = get_temp_name (integer_type_node, 1); 6981: rest_of_decl_compilation (temp, NULL_PTR, 0, 0); 6982: expand_start_cond (build_binary_op (EQ_EXPR, temp, 6983: integer_zero_node, 1), 0); 6984: old_cleanups = cleanups_this_call; 6985: expand_assignment (temp, integer_one_node, 0, 0); 1.1.1.2 ! root 6986: if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)) ! 6987: || (init && TREE_CODE (init) == TREE_LIST)) 1.1 root 6988: { 1.1.1.2 ! root 6989: expand_aggr_init (decl, init, 0, 0); 1.1 root 6990: do_pending_stack_adjust (); 6991: } 1.1.1.2 ! root 6992: else if (init) 1.1 root 6993: expand_assignment (decl, init, 0, 0); 1.1.1.2 ! root 6994: 1.1 root 6995: /* Cleanup any temporaries needed for the initial value. */ 6996: expand_cleanups_to (old_cleanups); 6997: expand_end_cond (); 6998: if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) 6999: { 7000: static_aggregates = perm_tree_cons (temp, decl, static_aggregates); 7001: TREE_STATIC (static_aggregates) = 1; 7002: } 7003: 7004: /* Resume old (possibly temporary) allocation. */ 7005: pop_obstacks (); 7006: } 7007: else 7008: { 7009: /* This code takes into account memory allocation 7010: policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING 7011: does not hold for this object, then we must make permanent 7012: the storage currently in the temporary obstack. */ 7013: if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) 7014: preserve_initializer (); 7015: static_aggregates = perm_tree_cons (init, decl, static_aggregates); 7016: } 7017: } 7018: 7019: /* Make TYPE a complete type based on INITIAL_VALUE. 7020: Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, 7021: 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ 7022: 7023: int 7024: complete_array_type (type, initial_value, do_default) 7025: tree type, initial_value; 7026: int do_default; 7027: { 7028: register tree maxindex = NULL_TREE; 7029: int value = 0; 7030: 7031: if (initial_value) 7032: { 7033: /* Note MAXINDEX is really the maximum index, 7034: one less than the size. */ 7035: if (TREE_CODE (initial_value) == STRING_CST) 1.1.1.2 ! root 7036: { ! 7037: int eltsize ! 7038: = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); ! 7039: maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) ! 7040: / eltsize) - 1, 0); ! 7041: } 1.1 root 7042: else if (TREE_CODE (initial_value) == CONSTRUCTOR) 7043: { 1.1.1.2 ! root 7044: tree elts = CONSTRUCTOR_ELTS (initial_value); ! 7045: maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); ! 7046: for (; elts; elts = TREE_CHAIN (elts)) ! 7047: { ! 7048: if (TREE_PURPOSE (elts)) ! 7049: maxindex = TREE_PURPOSE (elts); ! 7050: else ! 7051: maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); ! 7052: } ! 7053: maxindex = copy_node (maxindex); 1.1 root 7054: } 7055: else 7056: { 7057: /* Make an error message unless that happened already. */ 7058: if (initial_value != error_mark_node) 7059: value = 1; 7060: 7061: /* Prevent further error messages. */ 7062: maxindex = build_int_2 (0, 0); 7063: } 7064: } 7065: 7066: if (!maxindex) 7067: { 7068: if (do_default) 7069: maxindex = build_int_2 (0, 0); 7070: value = 2; 7071: } 7072: 7073: if (maxindex) 7074: { 7075: tree itype; 7076: 7077: TYPE_DOMAIN (type) = build_index_type (maxindex); 1.1.1.2 ! root 7078: if (! TREE_TYPE (maxindex)) 1.1 root 7079: TREE_TYPE (maxindex) = TYPE_DOMAIN (type); 7080: if (initial_value) 7081: itype = TREE_TYPE (initial_value); 7082: else 7083: itype = NULL; 7084: if (itype && !TYPE_DOMAIN (itype)) 7085: TYPE_DOMAIN (itype) = TYPE_DOMAIN (type); 1.1.1.2 ! root 7086: /* The type of the main variant should never be used for arrays ! 7087: of different sizes. It should only ever be completed with the ! 7088: size of the array. */ ! 7089: if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type))) ! 7090: TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type); 1.1 root 7091: } 7092: 7093: /* Lay out the type now that we can get the real answer. */ 7094: 7095: layout_type (type); 7096: 7097: return value; 7098: } 7099: 7100: /* Return zero if something is declared to be a member of type 7101: CTYPE when in the context of CUR_TYPE. STRING is the error 7102: message to print in that case. Otherwise, quietly return 1. */ 7103: static int 7104: member_function_or_else (ctype, cur_type, string) 7105: tree ctype, cur_type; 7106: char *string; 7107: { 7108: if (ctype && ctype != cur_type) 7109: { 7110: error (string, TYPE_NAME_STRING (ctype)); 7111: return 0; 7112: } 7113: return 1; 7114: } 7115: 7116: /* Subroutine of `grokdeclarator'. */ 7117: 7118: /* Generate errors possibly applicable for a given set of specifiers. 7119: This is for ARM $7.1.2. */ 7120: static void 7121: bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) 7122: tree object; 7123: char *type; 7124: int virtualp, quals, friendp, raises, inlinep; 7125: { 7126: if (virtualp) 7127: cp_error ("`%D' declared as a `virtual' %s", object, type); 7128: if (inlinep) 7129: cp_error ("`%D' declared as an `inline' %s", object, type); 7130: if (quals) 7131: cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", 7132: object, type); 7133: if (friendp) 7134: cp_error_at ("invalid friend declaration", object); 7135: if (raises) 1.1.1.2 ! root 7136: cp_error_at ("invalid exception specifications", object); 1.1 root 7137: } 7138: 7139: /* CTYPE is class type, or null if non-class. 7140: TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE 7141: or METHOD_TYPE. 7142: DECLARATOR is the function's name. 7143: VIRTUALP is truthvalue of whether the function is virtual or not. 7144: FLAGS are to be passed through to `grokclassfn'. 7145: QUALS are qualifiers indicating whether the function is `const' 7146: or `volatile'. 7147: RAISES is a list of exceptions that this function can raise. 7148: CHECK is 1 if we must find this method in CTYPE, 0 if we should 7149: not look, and -1 if we should not call `grokclassfn' at all. */ 7150: static tree 7151: grokfndecl (ctype, type, declarator, virtualp, flags, quals, 1.1.1.2 ! root 7152: raises, attrlist, check, publicp, inlinep) 1.1 root 7153: tree ctype, type; 7154: tree declarator; 7155: int virtualp; 7156: enum overload_flags flags; 1.1.1.2 ! root 7157: tree quals, raises, attrlist; ! 7158: int check, publicp, inlinep; 1.1 root 7159: { 7160: tree cname, decl; 7161: int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; 7162: 7163: if (ctype) 7164: cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL 7165: ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); 7166: else 7167: cname = NULL_TREE; 7168: 7169: if (raises) 7170: { 1.1.1.2 ! root 7171: type = build_exception_variant (type, raises); 1.1 root 7172: raises = TYPE_RAISES_EXCEPTIONS (type); 7173: } 7174: decl = build_lang_decl (FUNCTION_DECL, declarator, type); 7175: /* propagate volatile out from type to decl */ 7176: if (TYPE_VOLATILE (type)) 7177: TREE_THIS_VOLATILE (decl) = 1; 7178: 7179: /* Should probably propagate const out from type to decl I bet (mrs). */ 7180: if (staticp) 7181: { 7182: DECL_STATIC_FUNCTION_P (decl) = 1; 7183: DECL_CONTEXT (decl) = ctype; 7184: DECL_CLASS_CONTEXT (decl) = ctype; 7185: } 7186: 1.1.1.2 ! root 7187: /* All function decls start out public; we'll fix their linkage later (at ! 7188: definition or EOF) if appropriate. */ ! 7189: TREE_PUBLIC (decl) = 1; ! 7190: ! 7191: if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main")) ! 7192: { ! 7193: if (inlinep) ! 7194: error ("cannot declare `main' to be inline"); ! 7195: else if (! publicp) ! 7196: error ("cannot declare `main' to be static"); ! 7197: inlinep = 0; ! 7198: publicp = 1; ! 7199: } ! 7200: ! 7201: if (! publicp) ! 7202: DECL_C_STATIC (decl) = 1; ! 7203: ! 7204: if (inlinep) ! 7205: DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1; 1.1 root 7206: 7207: DECL_EXTERNAL (decl) = 1; 7208: if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) 7209: { 7210: cp_error ("%smember function `%D' cannot have `%T' method qualifier", 7211: (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); 7212: quals = NULL_TREE; 7213: } 7214: 7215: if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) 7216: grok_op_properties (decl, virtualp, check < 0); 7217: 7218: /* Caller will do the rest of this. */ 7219: if (check < 0) 7220: return decl; 7221: 7222: if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) 7223: { 7224: tree tmp; 7225: /* Just handle constructors here. We could do this 7226: inside the following if stmt, but I think 7227: that the code is more legible by breaking this 7228: case out. See comments below for what each of 7229: the following calls is supposed to do. */ 7230: DECL_CONSTRUCTOR_P (decl) = 1; 7231: 7232: grokclassfn (ctype, declarator, decl, flags, quals); 7233: if (check) 7234: check_classfn (ctype, declarator, decl); 7235: if (! grok_ctor_properties (ctype, decl)) 7236: return NULL_TREE; 7237: 7238: if (check == 0 && ! current_function_decl) 7239: { 7240: /* FIXME: this should only need to look at 7241: IDENTIFIER_GLOBAL_VALUE. */ 7242: tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); 7243: if (tmp == NULL_TREE) 7244: IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; 7245: else if (TREE_CODE (tmp) != TREE_CODE (decl)) 7246: cp_error ("inconsistent declarations for `%D'", decl); 7247: else 7248: { 7249: duplicate_decls (decl, tmp); 7250: decl = tmp; 7251: /* avoid creating circularities. */ 7252: DECL_CHAIN (decl) = NULL_TREE; 7253: } 7254: make_decl_rtl (decl, NULL_PTR, 1); 7255: } 7256: } 7257: else 7258: { 7259: tree tmp; 7260: 7261: /* Function gets the ugly name, field gets the nice one. 7262: This call may change the type of the function (because 7263: of default parameters)! */ 7264: if (ctype != NULL_TREE) 7265: grokclassfn (ctype, cname, decl, flags, quals); 7266: 7267: if (ctype != NULL_TREE && check) 7268: check_classfn (ctype, cname, decl); 7269: 7270: if (ctype == NULL_TREE || check) 7271: return decl; 7272: 7273: /* Now install the declaration of this function so that others may 7274: find it (esp. its DECL_FRIENDLIST). Don't do this for local class 7275: methods, though. */ 7276: if (! current_function_decl) 7277: { 7278: /* FIXME: this should only need to look at 7279: IDENTIFIER_GLOBAL_VALUE. */ 7280: tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); 7281: if (tmp == NULL_TREE) 7282: IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; 7283: else if (TREE_CODE (tmp) != TREE_CODE (decl)) 7284: cp_error ("inconsistent declarations for `%D'", decl); 7285: else 7286: { 7287: duplicate_decls (decl, tmp); 7288: decl = tmp; 7289: /* avoid creating circularities. */ 7290: DECL_CHAIN (decl) = NULL_TREE; 7291: } 1.1.1.2 ! root 7292: ! 7293: if (attrlist) ! 7294: cplus_decl_attributes (decl, TREE_PURPOSE (attrlist), ! 7295: TREE_VALUE (attrlist)); 1.1 root 7296: make_decl_rtl (decl, NULL_PTR, 1); 7297: } 7298: 7299: /* If this declaration supersedes the declaration of 7300: a method declared virtual in the base class, then 7301: mark this field as being virtual as well. */ 7302: { 7303: tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype)); 7304: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; 7305: 7306: for (i = 0; i < n_baselinks; i++) 7307: { 7308: tree base_binfo = TREE_VEC_ELT (binfos, i); 7309: if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) 7310: || flag_all_virtual == 1) 7311: { 7312: tmp = get_matching_virtual (base_binfo, decl, 7313: flags == DTOR_FLAG); 7314: if (tmp) 7315: { 7316: /* If this function overrides some virtual in some base 7317: class, then the function itself is also necessarily 7318: virtual, even if the user didn't explicitly say so. */ 7319: DECL_VIRTUAL_P (decl) = 1; 7320: 7321: /* The TMP we really want is the one from the deepest 7322: baseclass on this path, taking care not to 7323: duplicate if we have already found it (via another 7324: path to its virtual baseclass. */ 7325: if (staticp) 7326: { 7327: cp_error ("method `%D' may not be declared static", 7328: decl); 7329: cp_error_at ("(since `%D' declared virtual in base class.)", 7330: tmp); 7331: break; 7332: } 7333: virtualp = 1; 7334: 7335: { 7336: /* The argument types may have changed... */ 7337: tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); 7338: tree base_variant = TREE_TYPE (TREE_VALUE (argtypes)); 7339: 7340: argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))), 7341: TREE_CHAIN (argtypes)); 7342: /* But the return type has not. */ 7343: type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes); 7344: if (raises) 7345: { 1.1.1.2 ! root 7346: type = build_exception_variant (type, raises); 1.1 root 7347: raises = TYPE_RAISES_EXCEPTIONS (type); 7348: } 7349: TREE_TYPE (decl) = type; 7350: DECL_VINDEX (decl) 7351: = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl)); 7352: } 7353: break; 7354: } 7355: } 7356: } 7357: } 7358: if (virtualp) 7359: { 7360: if (DECL_VINDEX (decl) == NULL_TREE) 7361: DECL_VINDEX (decl) = error_mark_node; 7362: IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; 7363: if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) 7364: /* If this function is derived from a template, don't 7365: make it public. This shouldn't be here, but there's 7366: no good way to override the interface pragmas for one 7367: function or class only. Bletch. */ 7368: && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE 7369: && (write_virtuals == 2 7370: || (write_virtuals == 3 7371: && CLASSTYPE_INTERFACE_KNOWN (ctype)))) 7372: TREE_PUBLIC (decl) = 1; 7373: } 7374: } 7375: return decl; 7376: } 7377: 7378: static tree 1.1.1.2 ! root 7379: grokvardecl (type, declarator, specbits, initialized, constp) 1.1 root 7380: tree type; 7381: tree declarator; 7382: RID_BIT_TYPE specbits; 7383: int initialized; 1.1.1.2 ! root 7384: int constp; 1.1 root 7385: { 7386: tree decl; 7387: 7388: if (TREE_CODE (type) == OFFSET_TYPE) 7389: { 7390: /* If you declare a static member so that it 7391: can be initialized, the code will reach here. */ 7392: tree basetype = TYPE_OFFSET_BASETYPE (type); 7393: type = TREE_TYPE (type); 7394: decl = build_lang_field_decl (VAR_DECL, declarator, type); 7395: DECL_CONTEXT (decl) = basetype; 7396: DECL_CLASS_CONTEXT (decl) = basetype; 7397: DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator); 7398: } 7399: else 7400: decl = build_decl (VAR_DECL, declarator, type); 7401: 1.1.1.2 ! root 7402: DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl)); ! 7403: 1.1 root 7404: if (RIDBIT_SETP (RID_EXTERN, specbits)) 7405: { 7406: DECL_THIS_EXTERN (decl) = 1; 7407: DECL_EXTERNAL (decl) = !initialized; 7408: } 7409: 7410: /* In class context, static means one per class, 7411: public access, and static storage. */ 7412: if (DECL_FIELD_CONTEXT (decl) != NULL_TREE 7413: && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl))) 7414: { 7415: TREE_PUBLIC (decl) = 1; 7416: TREE_STATIC (decl) = 1; 7417: DECL_EXTERNAL (decl) = 0; 7418: } 7419: /* At top level, either `static' or no s.c. makes a definition 7420: (perhaps tentative), and absence of `static' makes it public. */ 1.1.1.2 ! root 7421: else if (toplevel_bindings_p ()) 1.1 root 7422: { 1.1.1.2 ! root 7423: TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits) ! 7424: && (DECL_THIS_EXTERN (decl) || ! constp)); 1.1 root 7425: TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); 7426: } 7427: /* Not at top level, only `static' makes a static definition. */ 7428: else 7429: { 7430: TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits); 7431: TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); 7432: } 7433: return decl; 7434: } 7435: 7436: /* Create a canonical pointer to member function type. */ 7437: 7438: tree 7439: build_ptrmemfunc_type (type) 7440: tree type; 7441: { 7442: tree fields[4]; 7443: tree t; 7444: tree u; 7445: 7446: /* If a canonical type already exists for this type, use it. We use 7447: this method instead of type_hash_canon, because it only does a 7448: simple equality check on the list of field members. */ 7449: 7450: if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type))) 7451: return t; 7452: 7453: push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); 7454: 7455: u = make_lang_type (UNION_TYPE); 1.1.1.2 ! root 7456: IS_AGGR_TYPE (u) = 0; 1.1 root 7457: fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type); 7458: fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, 7459: delta_type_node); 7460: finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node); 7461: TYPE_NAME (u) = NULL_TREE; 7462: 7463: t = make_lang_type (RECORD_TYPE); 7464: 7465: /* Let the front-end know this is a pointer to member function. */ 1.1.1.2 ! root 7466: TYPE_PTRMEMFUNC_FLAG (t) = 1; 1.1 root 7467: /* and not really an aggregate. */ 7468: IS_AGGR_TYPE (t) = 0; 7469: 7470: fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, 7471: delta_type_node); 7472: fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, 7473: delta_type_node); 7474: fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u); 7475: finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node); 7476: 7477: pop_obstacks (); 7478: 7479: /* Zap out the name so that the back-end will give us the debugging 7480: information for this anonymous RECORD_TYPE. */ 7481: TYPE_NAME (t) = NULL_TREE; 7482: 7483: TYPE_SET_PTRMEMFUNC_TYPE (type, t); 7484: 7485: /* Seems to be wanted. */ 7486: CLASSTYPE_GOT_SEMICOLON (t) = 1; 7487: return t; 7488: } 7489: 7490: /* Given declspecs and a declarator, 7491: determine the name and type of the object declared 7492: and construct a ..._DECL node for it. 7493: (In one case we can return a ..._TYPE node instead. 7494: For invalid input we sometimes return 0.) 7495: 7496: DECLSPECS is a chain of tree_list nodes whose value fields 7497: are the storage classes and type specifiers. 7498: 7499: DECL_CONTEXT says which syntactic context this declaration is in: 7500: NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. 7501: FUNCDEF for a function definition. Like NORMAL but a few different 7502: error messages in each case. Return value may be zero meaning 7503: this definition is too screwy to try to parse. 7504: MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to 7505: handle member functions (which have FIELD context). 7506: Return value may be zero meaning this definition is too screwy to 7507: try to parse. 7508: PARM for a parameter declaration (either within a function prototype 7509: or before a function body). Make a PARM_DECL, or return void_type_node. 1.1.1.2 ! root 7510: CATCHPARM for a parameter declaration before a catch clause. 1.1 root 7511: TYPENAME if for a typename (in a cast or sizeof). 7512: Don't make a DECL node; just return the ..._TYPE node. 7513: FIELD for a struct or union field; make a FIELD_DECL. 7514: BITFIELD for a field with specified width. 7515: INITIALIZED is 1 if the decl has an initializer. 7516: 7517: In the TYPENAME case, DECLARATOR is really an absolute declarator. 7518: It may also be so in the PARM case, for a prototype where the 7519: argument type is specified but not the name. 7520: 7521: This function is where the complicated C meanings of `static' 7522: and `extern' are interpreted. 7523: 7524: For C++, if there is any monkey business to do, the function which 7525: calls this one must do it, i.e., prepending instance variables, 7526: renaming overloaded function names, etc. 7527: 7528: Note that for this C++, it is an error to define a method within a class 7529: which does not belong to that class. 7530: 7531: Except in the case where SCOPE_REFs are implicitly known (such as 7532: methods within a class being redundantly qualified), 7533: declarations which involve SCOPE_REFs are returned as SCOPE_REFs 7534: (class_name::decl_name). The caller must also deal with this. 7535: 7536: If a constructor or destructor is seen, and the context is FIELD, 7537: then the type gains the attribute TREE_HAS_x. If such a declaration 7538: is erroneous, NULL_TREE is returned. 7539: 7540: QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member 7541: function, these are the qualifiers to give to the `this' pointer. 7542: 7543: May return void_type_node if the declarator turned out to be a friend. 7544: See grokfield for details. */ 7545: 7546: enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; 7547: 7548: tree 1.1.1.2 ! root 7549: grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrlist) 1.1 root 7550: tree declspecs; 7551: tree declarator; 7552: enum decl_context decl_context; 7553: int initialized; 1.1.1.2 ! root 7554: tree raises, attrlist; 1.1 root 7555: { 7556: RID_BIT_TYPE specbits; 7557: int nclasses = 0; 7558: tree spec; 7559: tree type = NULL_TREE; 7560: int longlong = 0; 7561: int constp; 7562: int volatilep; 1.1.1.2 ! root 7563: int virtualp, explicitp, friendp, inlinep, staticp; 1.1 root 7564: int explicit_int = 0; 7565: int explicit_char = 0; 7566: int opaque_typedef = 0; 7567: tree typedef_decl = NULL_TREE; 7568: char *name; 7569: tree typedef_type = NULL_TREE; 7570: int funcdef_flag = 0; 7571: enum tree_code innermost_code = ERROR_MARK; 7572: int bitfield = 0; 7573: int size_varies = 0; 1.1.1.2 ! root 7574: tree decl_machine_attr = NULL_TREE; 1.1 root 7575: /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. 7576: All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ 7577: tree init = NULL_TREE; 7578: 7579: /* Keep track of what sort of function is being processed 7580: so that we can warn about default return values, or explicit 7581: return values which do not match prescribed defaults. */ 7582: enum return_types return_type = return_normal; 7583: 7584: tree dname = NULL_TREE; 7585: tree ctype = current_class_type; 7586: tree ctor_return_type = NULL_TREE; 7587: enum overload_flags flags = NO_SPECIAL; 7588: tree quals = NULL_TREE; 7589: 7590: RIDBIT_RESET_ALL (specbits); 7591: if (decl_context == FUNCDEF) 7592: funcdef_flag = 1, decl_context = NORMAL; 7593: else if (decl_context == MEMFUNCDEF) 7594: funcdef_flag = -1, decl_context = FIELD; 7595: else if (decl_context == BITFIELD) 7596: bitfield = 1, decl_context = FIELD; 7597: 7598: if (flag_traditional && allocation_temporary_p ()) 7599: end_temporary_allocation (); 7600: 7601: /* Look inside a declarator for the name being declared 7602: and get it as a string, for an error message. */ 7603: { 7604: tree last = NULL_TREE; 7605: register tree decl = declarator; 7606: name = NULL; 7607: 7608: while (decl) 7609: switch (TREE_CODE (decl)) 7610: { 7611: case COND_EXPR: 7612: ctype = NULL_TREE; 7613: decl = TREE_OPERAND (decl, 0); 7614: break; 7615: 7616: case BIT_NOT_EXPR: /* for C++ destructors! */ 7617: { 7618: tree name = TREE_OPERAND (decl, 0); 7619: tree rename = NULL_TREE; 7620: 7621: my_friendly_assert (flags == NO_SPECIAL, 152); 7622: flags = DTOR_FLAG; 7623: return_type = return_dtor; 7624: my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); 7625: if (ctype == NULL_TREE) 7626: { 7627: if (current_class_type == NULL_TREE) 7628: { 7629: error ("destructors must be member functions"); 7630: flags = NO_SPECIAL; 7631: } 7632: else 7633: { 7634: tree t = constructor_name (current_class_name); 7635: if (t != name) 7636: rename = t; 7637: } 7638: } 7639: else 7640: { 7641: tree t = constructor_name (ctype); 7642: if (t != name) 7643: rename = t; 7644: } 7645: 7646: if (rename) 7647: { 7648: error ("destructor `%s' must match class name `%s'", 7649: IDENTIFIER_POINTER (name), 7650: IDENTIFIER_POINTER (rename)); 7651: TREE_OPERAND (decl, 0) = rename; 7652: } 7653: decl = name; 7654: } 7655: break; 7656: 7657: case ADDR_EXPR: /* C++ reference declaration */ 7658: /* fall through */ 7659: case ARRAY_REF: 7660: case INDIRECT_REF: 7661: ctype = NULL_TREE; 7662: innermost_code = TREE_CODE (decl); 7663: last = decl; 7664: decl = TREE_OPERAND (decl, 0); 7665: break; 7666: 7667: case CALL_EXPR: 7668: if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) 7669: { 7670: /* This is actually a variable declaration using constructor 1.1.1.2 ! root 7671: syntax. We need to call start_decl and cp_finish_decl so we 1.1 root 7672: can get the variable initialized... */ 7673: 7674: if (last) 7675: /* We need to insinuate ourselves into the declarator in place 7676: of the CALL_EXPR. */ 7677: TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0); 7678: else 7679: declarator = TREE_OPERAND (decl, 0); 7680: 7681: init = TREE_OPERAND (decl, 1); 7682: 7683: decl = start_decl (declarator, declspecs, 1, NULL_TREE); 1.1.1.2 ! root 7684: finish_decl (decl, init, NULL_TREE); 1.1 root 7685: return 0; 7686: } 7687: innermost_code = TREE_CODE (decl); 7688: if (decl_context == FIELD && ctype == NULL_TREE) 7689: ctype = current_class_type; 1.1.1.2 ! root 7690: if (ctype ! 7691: && TREE_OPERAND (decl, 0) == constructor_name_full (ctype)) ! 7692: TREE_OPERAND (decl, 0) = constructor_name (ctype); ! 7693: decl = TREE_OPERAND (decl, 0); 1.1 root 7694: if (ctype != NULL_TREE 7695: && decl != NULL_TREE && flags != DTOR_FLAG 7696: && decl == constructor_name (ctype)) 7697: { 7698: return_type = return_ctor; 7699: ctor_return_type = ctype; 7700: } 7701: ctype = NULL_TREE; 7702: break; 7703: 7704: case IDENTIFIER_NODE: 7705: dname = decl; 7706: decl = NULL_TREE; 7707: 7708: if (! IDENTIFIER_OPNAME_P (dname) 7709: /* Linux headers use '__op'. Arrgh. */ 7710: || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname)) 7711: name = IDENTIFIER_POINTER (dname); 7712: else 7713: { 7714: if (IDENTIFIER_TYPENAME_P (dname)) 7715: { 7716: my_friendly_assert (flags == NO_SPECIAL, 154); 7717: flags = TYPENAME_FLAG; 7718: ctor_return_type = TREE_TYPE (dname); 7719: return_type = return_conversion; 7720: } 7721: name = operator_name_string (dname); 7722: } 7723: break; 7724: 7725: case RECORD_TYPE: 7726: case UNION_TYPE: 7727: case ENUMERAL_TYPE: 7728: /* Parse error puts this typespec where 7729: a declarator should go. */ 7730: error ("declarator name missing"); 7731: dname = TYPE_NAME (decl); 7732: if (dname && TREE_CODE (dname) == TYPE_DECL) 7733: dname = DECL_NAME (dname); 7734: name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>"; 7735: declspecs = temp_tree_cons (NULL_TREE, decl, declspecs); 7736: decl = NULL_TREE; 7737: break; 7738: 7739: /* C++ extension */ 7740: case SCOPE_REF: 7741: { 7742: /* Perform error checking, and convert class names to types. 7743: We may call grokdeclarator multiple times for the same 7744: tree structure, so only do the conversion once. In this 7745: case, we have exactly what we want for `ctype'. */ 7746: tree cname = TREE_OPERAND (decl, 0); 7747: if (cname == NULL_TREE) 7748: ctype = NULL_TREE; 7749: /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */ 7750: else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname)) 7751: || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE) 7752: ctype = cname; 7753: else if (! is_aggr_typedef (cname, 1)) 7754: { 7755: TREE_OPERAND (decl, 0) = NULL_TREE; 7756: } 7757: /* Must test TREE_OPERAND (decl, 1), in case user gives 7758: us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ 7759: else if (TREE_OPERAND (decl, 1) 7760: && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) 7761: { 7762: TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname); 7763: } 7764: else if (ctype == NULL_TREE) 7765: { 7766: ctype = IDENTIFIER_TYPE_VALUE (cname); 7767: TREE_OPERAND (decl, 0) = ctype; 7768: } 7769: else if (TREE_COMPLEXITY (decl) == current_class_depth) 7770: TREE_OPERAND (decl, 0) = ctype; 7771: else 7772: { 7773: if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname), 7774: ctype)) 7775: { 7776: cp_error ("type `%T' is not derived from type `%T'", 7777: IDENTIFIER_TYPE_VALUE (cname), ctype); 7778: TREE_OPERAND (decl, 0) = NULL_TREE; 7779: } 7780: else 7781: { 7782: ctype = IDENTIFIER_TYPE_VALUE (cname); 7783: TREE_OPERAND (decl, 0) = ctype; 7784: } 7785: } 7786: 1.1.1.2 ! root 7787: if (ctype ! 7788: && TREE_OPERAND (decl, 1) == constructor_name_full (ctype)) ! 7789: TREE_OPERAND (decl, 1) = constructor_name (ctype); 1.1 root 7790: decl = TREE_OPERAND (decl, 1); 7791: if (ctype) 7792: { 7793: if (TREE_CODE (decl) == IDENTIFIER_NODE 7794: && constructor_name (ctype) == decl) 7795: { 7796: return_type = return_ctor; 7797: ctor_return_type = ctype; 7798: } 7799: else if (TREE_CODE (decl) == BIT_NOT_EXPR 7800: && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE 1.1.1.2 ! root 7801: && (constructor_name (ctype) == TREE_OPERAND (decl, 0) ! 7802: || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) 1.1 root 7803: { 7804: return_type = return_dtor; 7805: ctor_return_type = ctype; 7806: flags = DTOR_FLAG; 1.1.1.2 ! root 7807: decl = TREE_OPERAND (decl, 0) = constructor_name (ctype); 1.1 root 7808: } 7809: } 7810: } 7811: break; 7812: 7813: case ERROR_MARK: 7814: decl = NULL_TREE; 7815: break; 7816: 7817: default: 7818: return 0; /* We used to do a 155 abort here. */ 7819: } 7820: if (name == NULL) 7821: name = "type name"; 7822: } 7823: 7824: /* A function definition's declarator must have the form of 7825: a function declarator. */ 7826: 7827: if (funcdef_flag && innermost_code != CALL_EXPR) 7828: return 0; 7829: 1.1.1.2 ! root 7830: if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG) ! 7831: && innermost_code != CALL_EXPR ! 7832: && ! (ctype && declspecs == NULL_TREE)) ! 7833: { ! 7834: cp_error ("declaration of `%D' as non-function", dname); ! 7835: return void_type_node; ! 7836: } ! 7837: 1.1 root 7838: /* Anything declared one level down from the top level 7839: must be one of the parameters of a function 7840: (because the body is at least two levels down). */ 7841: 7842: /* This heuristic cannot be applied to C++ nodes! Fixed, however, 7843: by not allowing C++ class definitions to specify their parameters 7844: with xdecls (must be spec.d in the parmlist). 7845: 7846: Since we now wait to push a class scope until we are sure that 7847: we are in a legitimate method context, we must set oldcname 1.1.1.2 ! root 7848: explicitly (since current_class_name is not yet alive). ! 7849: ! 7850: We also want to avoid calling this a PARM if it is in a namespace. */ 1.1 root 7851: 1.1.1.2 ! root 7852: if (decl_context == NORMAL && ! namespace_bindings_p ()) ! 7853: { ! 7854: struct binding_level *b = current_binding_level; ! 7855: current_binding_level = b->level_chain; ! 7856: if (current_binding_level != 0 && toplevel_bindings_p ()) ! 7857: decl_context = PARM; ! 7858: current_binding_level = b; ! 7859: } 1.1 root 7860: 7861: /* Look through the decl specs and record which ones appear. 7862: Some typespecs are defined as built-in typenames. 7863: Others, the ones that are modifiers of other types, 7864: are represented by bits in SPECBITS: set the bits for 7865: the modifiers that appear. Storage class keywords are also in SPECBITS. 7866: 7867: If there is a typedef name or a type, store the type in TYPE. 7868: This includes builtin typedefs such as `int'. 7869: 7870: Set EXPLICIT_INT if the type is `int' or `char' and did not 7871: come from a user typedef. 7872: 7873: Set LONGLONG if `long' is mentioned twice. 7874: 7875: For C++, constructors and destructors have their own fast treatment. */ 7876: 7877: for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) 7878: { 7879: register int i; 7880: register tree id; 7881: 7882: /* Certain parse errors slip through. For example, 7883: `int class;' is not caught by the parser. Try 7884: weakly to recover here. */ 7885: if (TREE_CODE (spec) != TREE_LIST) 7886: return 0; 7887: 7888: id = TREE_VALUE (spec); 7889: 7890: if (TREE_CODE (id) == IDENTIFIER_NODE) 7891: { 7892: if (id == ridpointers[(int) RID_INT] 7893: || id == ridpointers[(int) RID_CHAR] 7894: || id == ridpointers[(int) RID_BOOL] 7895: || id == ridpointers[(int) RID_WCHAR]) 7896: { 7897: if (type) 1.1.1.2 ! root 7898: { ! 7899: if (id == ridpointers[(int) RID_BOOL]) ! 7900: error ("`bool' is now a keyword"); ! 7901: else ! 7902: cp_error ("extraneous `%T' ignored", id); ! 7903: } 1.1 root 7904: else 7905: { 7906: if (id == ridpointers[(int) RID_INT]) 7907: explicit_int = 1; 7908: else if (id == ridpointers[(int) RID_CHAR]) 7909: explicit_char = 1; 7910: type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); 7911: } 7912: goto found; 7913: } 7914: /* C++ aggregate types. */ 7915: if (IDENTIFIER_HAS_TYPE_VALUE (id)) 7916: { 7917: if (type) 7918: cp_error ("multiple declarations `%T' and `%T'", type, id); 7919: else 7920: type = IDENTIFIER_TYPE_VALUE (id); 7921: goto found; 7922: } 7923: 7924: for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++) 7925: { 7926: if (ridpointers[i] == id) 7927: { 7928: if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) 7929: { 1.1.1.2 ! root 7930: if (pedantic && ! in_system_header) ! 7931: pedwarn ("ANSI C++ does not support `long long'"); 1.1 root 7932: else if (longlong) 7933: error ("`long long long' is too long for GCC"); 7934: else 7935: longlong = 1; 7936: } 7937: else if (RIDBIT_SETP (i, specbits)) 7938: pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); 7939: RIDBIT_SET (i, specbits); 7940: goto found; 7941: } 7942: } 7943: } 7944: if (type) 7945: error ("two or more data types in declaration of `%s'", name); 7946: else if (TREE_CODE (id) == IDENTIFIER_NODE) 7947: { 7948: register tree t = lookup_name (id, 1); 7949: if (!t || TREE_CODE (t) != TYPE_DECL) 7950: error ("`%s' fails to be a typedef or built in type", 7951: IDENTIFIER_POINTER (id)); 7952: else 7953: { 7954: type = TREE_TYPE (t); 1.1.1.2 ! root 7955: decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); 1.1 root 7956: typedef_decl = t; 7957: } 7958: } 7959: else if (TREE_CODE (id) != ERROR_MARK) 7960: /* Can't change CLASS nodes into RECORD nodes here! */ 7961: type = id; 7962: 7963: found: ; 7964: } 7965: 7966: typedef_type = type; 7967: 7968: /* No type at all: default to `int', and set EXPLICIT_INT 7969: because it was not a user-defined typedef. 7970: Except when we have a `typedef' inside a signature, in 7971: which case the type defaults to `unknown type' and is 7972: instantiated when assigning to a signature pointer or ref. */ 7973: 7974: if (type == NULL_TREE 7975: && (RIDBIT_SETP (RID_SIGNED, specbits) 7976: || RIDBIT_SETP (RID_UNSIGNED, specbits) 7977: || RIDBIT_SETP (RID_LONG, specbits) 7978: || RIDBIT_SETP (RID_SHORT, specbits))) 7979: { 7980: /* These imply 'int'. */ 7981: type = integer_type_node; 7982: explicit_int = 1; 7983: } 7984: 7985: if (type == NULL_TREE) 7986: { 7987: explicit_int = -1; 7988: if (return_type == return_dtor) 7989: type = void_type_node; 7990: else if (return_type == return_ctor) 1.1.1.2 ! root 7991: type = build_pointer_type (ctor_return_type); 1.1 root 7992: else if (return_type == return_conversion) 7993: type = ctor_return_type; 7994: else if (current_class_type 7995: && IS_SIGNATURE (current_class_type) 7996: && (RIDBIT_SETP (RID_TYPEDEF, specbits) 7997: || SIGNATURE_GROKKING_TYPEDEF (current_class_type)) 7998: && (decl_context == FIELD || decl_context == NORMAL)) 7999: { 8000: explicit_int = 0; 8001: opaque_typedef = 1; 8002: type = copy_node (opaque_type_node); 8003: } 8004: /* access declaration */ 8005: else if (decl_context == FIELD && declarator 8006: && TREE_CODE (declarator) == SCOPE_REF) 8007: type = void_type_node; 8008: else 8009: { 8010: if (funcdef_flag) 8011: { 8012: if (warn_return_type 8013: && return_type == return_normal) 8014: /* Save warning until we know what is really going on. */ 8015: warn_about_return_type = 1; 8016: } 8017: else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) 8018: pedwarn ("ANSI C++ forbids typedef which does not specify a type"); 8019: else if (declspecs == NULL_TREE && 8020: (innermost_code != CALL_EXPR || pedantic)) 8021: cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class", 8022: dname); 8023: type = integer_type_node; 8024: } 8025: } 8026: else if (return_type == return_dtor) 8027: { 8028: error ("return type specification for destructor invalid"); 8029: type = void_type_node; 8030: } 8031: else if (return_type == return_ctor) 8032: { 8033: error ("return type specification for constructor invalid"); 1.1.1.2 ! root 8034: type = build_pointer_type (ctor_return_type); 1.1 root 8035: } 8036: else if (return_type == return_conversion) 8037: { 1.1.1.2 ! root 8038: if (comptypes (type, ctor_return_type, 1) == 0) 1.1 root 8039: cp_error ("operator `%T' declared to return `%T'", 8040: ctor_return_type, type); 8041: else 8042: cp_pedwarn ("return type specified for `operator %T'", 8043: ctor_return_type); 8044: 8045: type = ctor_return_type; 8046: } 8047: /* Catch typedefs that only specify a type, like 'typedef int;'. */ 8048: else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE) 8049: { 8050: /* Template "this is a type" syntax; just ignore for now. */ 8051: if (processing_template_defn) 8052: return void_type_node; 8053: } 8054: 8055: ctype = NULL_TREE; 8056: 8057: /* Now process the modifiers that were specified 8058: and check for invalid combinations. */ 8059: 8060: /* Long double is a special combination. */ 8061: 8062: if (RIDBIT_SETP (RID_LONG, specbits) 8063: && TYPE_MAIN_VARIANT (type) == double_type_node) 8064: { 8065: RIDBIT_RESET (RID_LONG, specbits); 8066: type = build_type_variant (long_double_type_node, TYPE_READONLY (type), 8067: TYPE_VOLATILE (type)); 8068: } 8069: 8070: /* Check all other uses of type modifiers. */ 8071: 8072: if (RIDBIT_SETP (RID_UNSIGNED, specbits) 8073: || RIDBIT_SETP (RID_SIGNED, specbits) 8074: || RIDBIT_SETP (RID_LONG, specbits) 8075: || RIDBIT_SETP (RID_SHORT, specbits)) 8076: { 8077: int ok = 0; 8078: 8079: if (TREE_CODE (type) == REAL_TYPE) 8080: error ("short, signed or unsigned invalid for `%s'", name); 1.1.1.2 ! root 8081: else if (TREE_CODE (type) != INTEGER_TYPE) 1.1 root 8082: error ("long, short, signed or unsigned invalid for `%s'", name); 8083: else if (RIDBIT_SETP (RID_LONG, specbits) 8084: && RIDBIT_SETP (RID_SHORT, specbits)) 8085: error ("long and short specified together for `%s'", name); 8086: else if ((RIDBIT_SETP (RID_LONG, specbits) 8087: || RIDBIT_SETP (RID_SHORT, specbits)) 8088: && explicit_char) 8089: error ("long or short specified with char for `%s'", name); 8090: else if ((RIDBIT_SETP (RID_LONG, specbits) 8091: || RIDBIT_SETP (RID_SHORT, specbits)) 8092: && TREE_CODE (type) == REAL_TYPE) 8093: error ("long or short specified with floating type for `%s'", name); 8094: else if (RIDBIT_SETP (RID_SIGNED, specbits) 8095: && RIDBIT_SETP (RID_UNSIGNED, specbits)) 8096: error ("signed and unsigned given together for `%s'", name); 8097: else 8098: { 8099: ok = 1; 8100: if (!explicit_int && !explicit_char && pedantic) 8101: { 8102: pedwarn ("long, short, signed or unsigned used invalidly for `%s'", 8103: name); 8104: if (flag_pedantic_errors) 8105: ok = 0; 8106: } 8107: } 8108: 8109: /* Discard the type modifiers if they are invalid. */ 8110: if (! ok) 8111: { 8112: RIDBIT_RESET (RID_UNSIGNED, specbits); 8113: RIDBIT_RESET (RID_SIGNED, specbits); 8114: RIDBIT_RESET (RID_LONG, specbits); 8115: RIDBIT_RESET (RID_SHORT, specbits); 8116: longlong = 0; 8117: } 8118: } 8119: 8120: /* Decide whether an integer type is signed or not. 8121: Optionally treat bitfields as signed by default. */ 8122: if (RIDBIT_SETP (RID_UNSIGNED, specbits) 8123: /* Traditionally, all bitfields are unsigned. */ 8124: || (bitfield && flag_traditional) 8125: || (bitfield && ! flag_signed_bitfields 8126: && (explicit_int || explicit_char 8127: /* A typedef for plain `int' without `signed' 8128: can be controlled just like plain `int'. */ 8129: || ! (typedef_decl != NULL_TREE 8130: && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) 8131: && TREE_CODE (type) != ENUMERAL_TYPE 8132: && RIDBIT_NOTSETP (RID_SIGNED, specbits))) 8133: { 8134: if (longlong) 8135: type = long_long_unsigned_type_node; 8136: else if (RIDBIT_SETP (RID_LONG, specbits)) 8137: type = long_unsigned_type_node; 8138: else if (RIDBIT_SETP (RID_SHORT, specbits)) 8139: type = short_unsigned_type_node; 8140: else if (type == char_type_node) 8141: type = unsigned_char_type_node; 8142: else if (typedef_decl) 8143: type = unsigned_type (type); 8144: else 8145: type = unsigned_type_node; 8146: } 8147: else if (RIDBIT_SETP (RID_SIGNED, specbits) 8148: && type == char_type_node) 8149: type = signed_char_type_node; 8150: else if (longlong) 8151: type = long_long_integer_type_node; 8152: else if (RIDBIT_SETP (RID_LONG, specbits)) 8153: type = long_integer_type_node; 8154: else if (RIDBIT_SETP (RID_SHORT, specbits)) 8155: type = short_integer_type_node; 8156: 8157: /* Set CONSTP if this declaration is `const', whether by 8158: explicit specification or via a typedef. 8159: Likewise for VOLATILEP. */ 8160: 8161: constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type); 8162: volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type); 8163: staticp = 0; 8164: inlinep = !! RIDBIT_SETP (RID_INLINE, specbits); 8165: #if 0 8166: /* This sort of redundancy is blessed in a footnote to the Sep 94 WP. */ 8167: if (constp > 1) 8168: warning ("duplicate `const'"); 8169: if (volatilep > 1) 8170: warning ("duplicate `volatile'"); 8171: #endif 8172: virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); 1.1.1.2 ! root 8173: RIDBIT_RESET (RID_VIRTUAL, specbits); ! 8174: explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0; ! 8175: RIDBIT_RESET (RID_EXPLICIT, specbits); 1.1 root 8176: 8177: if (RIDBIT_SETP (RID_STATIC, specbits)) 8178: staticp = 1 + (decl_context == FIELD); 8179: 8180: if (virtualp && staticp == 2) 8181: { 8182: cp_error ("member `%D' cannot be declared both virtual and static", 8183: dname); 8184: staticp = 0; 8185: } 8186: friendp = RIDBIT_SETP (RID_FRIEND, specbits); 8187: RIDBIT_RESET (RID_FRIEND, specbits); 8188: 8189: if (RIDBIT_SETP (RID_MUTABLE, specbits)) 8190: { 8191: if (decl_context == PARM) 8192: { 1.1.1.2 ! root 8193: error ("non-member `%s' cannot be declared `mutable'", name); 1.1 root 8194: RIDBIT_RESET (RID_MUTABLE, specbits); 8195: } 8196: else if (friendp || decl_context == TYPENAME) 8197: { 1.1.1.2 ! root 8198: error ("non-object member `%s' cannot be declared `mutable'", name); 1.1 root 8199: RIDBIT_RESET (RID_MUTABLE, specbits); 8200: } 8201: #if 0 8202: if (RIDBIT_SETP (RID_TYPEDEF, specbits)) 8203: { 1.1.1.2 ! root 8204: error ("non-object member `%s' cannot be declared `mutable'", name); 1.1 root 8205: RIDBIT_RESET (RID_MUTABLE, specbits); 8206: } 8207: /* Because local typedefs are parsed twice, we don't want this 8208: message here. */ 8209: else if (decl_context != FIELD) 8210: { 1.1.1.2 ! root 8211: error ("non-member `%s' cannot be declared `mutable'", name); 1.1 root 8212: RIDBIT_RESET (RID_MUTABLE, specbits); 8213: } 8214: #endif 8215: } 8216: 8217: /* Warn if two storage classes are given. Default to `auto'. */ 8218: 8219: if (RIDBIT_ANY_SET (specbits)) 8220: { 8221: if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++; 8222: if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++; 8223: if (decl_context == PARM && nclasses > 0) 8224: error ("storage class specifiers invalid in parameter declarations"); 8225: if (RIDBIT_SETP (RID_TYPEDEF, specbits)) 8226: { 8227: if (decl_context == PARM) 8228: error ("typedef declaration invalid in parameter declaration"); 8229: nclasses++; 8230: } 8231: if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++; 8232: if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++; 8233: } 8234: 8235: /* Give error if `virtual' is used outside of class declaration. */ 1.1.1.2 ! root 8236: if (virtualp ! 8237: && (current_class_name == NULL_TREE || decl_context != FIELD)) 1.1 root 8238: { 8239: error ("virtual outside class declaration"); 8240: virtualp = 0; 8241: } 8242: if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits)) 8243: { 8244: error ("only members can be declared mutable"); 8245: RIDBIT_RESET (RID_MUTABLE, specbits); 8246: } 8247: 8248: /* Static anonymous unions are dealt with here. */ 8249: if (staticp && decl_context == TYPENAME 8250: && TREE_CODE (declspecs) == TREE_LIST 8251: && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE 8252: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs)))) 8253: decl_context = FIELD; 8254: 8255: /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual' 8256: is used in a signature member function declaration. */ 8257: if (decl_context == FIELD 8258: && IS_SIGNATURE (current_class_type) 8259: && RIDBIT_NOTSETP(RID_TYPEDEF, specbits) 8260: && !SIGNATURE_GROKKING_TYPEDEF (current_class_type)) 8261: { 8262: if (constp) 8263: { 8264: error ("`const' specified for signature member function `%s'", name); 8265: constp = 0; 8266: } 8267: if (volatilep) 8268: { 8269: error ("`volatile' specified for signature member function `%s'", 8270: name); 8271: volatilep = 0; 8272: } 8273: if (inlinep) 8274: { 8275: error ("`inline' specified for signature member function `%s'", name); 8276: /* Later, we'll make signature member functions inline. */ 8277: inlinep = 0; 8278: } 8279: if (friendp) 8280: { 8281: error ("`friend' declaration in signature definition"); 8282: friendp = 0; 8283: } 8284: if (virtualp) 8285: { 8286: error ("`virtual' specified for signature member function `%s'", 8287: name); 8288: /* Later, we'll make signature member functions virtual. */ 8289: virtualp = 0; 8290: } 8291: } 8292: 8293: /* Warn about storage classes that are invalid for certain 8294: kinds of declarations (parameters, typenames, etc.). */ 8295: 8296: if (nclasses > 1) 8297: error ("multiple storage classes in declaration of `%s'", name); 8298: else if (decl_context != NORMAL && nclasses > 0) 8299: { 1.1.1.2 ! root 8300: if ((decl_context == PARM || decl_context == CATCHPARM) 1.1 root 8301: && (RIDBIT_SETP (RID_REGISTER, specbits) 8302: || RIDBIT_SETP (RID_AUTO, specbits))) 8303: ; 8304: else if (decl_context == FIELD 8305: && RIDBIT_SETP (RID_TYPEDEF, specbits)) 8306: { 8307: /* Processing a typedef declaration nested within a class type 8308: definition. */ 8309: register tree scanner; 8310: register tree previous_declspec; 8311: tree loc_typedecl; 8312: 8313: if (initialized) 8314: error ("typedef declaration includes an initializer"); 8315: 8316: /* To process a class-local typedef declaration, we descend down 8317: the chain of declspecs looking for the `typedef' spec. When 8318: we find it, we replace it with `static', and then recursively 8319: call `grokdeclarator' with the original declarator and with 8320: the newly adjusted declspecs. This call should return a 8321: FIELD_DECL node with the TREE_TYPE (and other parts) set 8322: appropriately. We can then just change the TREE_CODE on that 8323: from FIELD_DECL to TYPE_DECL and we're done. */ 8324: 8325: for (previous_declspec = NULL_TREE, scanner = declspecs; 8326: scanner; 8327: previous_declspec = scanner, scanner = TREE_CHAIN (scanner)) 8328: { 8329: if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF]) 8330: break; 8331: } 8332: 8333: if (previous_declspec) 8334: TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner); 8335: else 8336: declspecs = TREE_CHAIN (scanner); 8337: 8338: declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC], 8339: declspecs); 8340: 8341: /* In the recursive call to grokdeclarator we need to know 8342: whether we are working on a signature-local typedef. */ 8343: if (IS_SIGNATURE (current_class_type)) 8344: SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1; 8345: 8346: loc_typedecl = 1.1.1.2 ! root 8347: grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE); 1.1 root 8348: 8349: if (previous_declspec) 8350: TREE_CHAIN (previous_declspec) = scanner; 8351: 8352: if (loc_typedecl != error_mark_node) 8353: { 8354: register int i = sizeof (struct lang_decl_flags) / sizeof (int); 8355: register int *pi; 8356: 8357: TREE_SET_CODE (loc_typedecl, TYPE_DECL); 8358: /* This is the same field as DECL_ARGUMENTS, which is set for 8359: function typedefs by the above grokdeclarator. */ 8360: DECL_NESTED_TYPENAME (loc_typedecl) = 0; 8361: 8362: pi = (int *) permalloc (sizeof (struct lang_decl_flags)); 8363: while (i > 0) 8364: pi[--i] = 0; 8365: DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi; 8366: } 8367: 8368: if (IS_SIGNATURE (current_class_type)) 8369: { 8370: SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0; 8371: if (loc_typedecl != error_mark_node && opaque_typedef) 8372: SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; 8373: } 8374: 8375: return loc_typedecl; 8376: } 8377: else if (decl_context == FIELD 8378: && (! IS_SIGNATURE (current_class_type) 8379: || SIGNATURE_GROKKING_TYPEDEF (current_class_type)) 8380: /* C++ allows static class elements */ 8381: && RIDBIT_SETP (RID_STATIC, specbits)) 8382: /* C++ also allows inlines and signed and unsigned elements, 8383: but in those cases we don't come in here. */ 8384: ; 8385: else 8386: { 8387: if (decl_context == FIELD) 8388: { 1.1.1.2 ! root 8389: tree tmp = NULL_TREE; ! 8390: register int op = 0; ! 8391: ! 8392: if (declarator) ! 8393: { ! 8394: tmp = TREE_OPERAND (declarator, 0); ! 8395: op = IDENTIFIER_OPNAME_P (tmp); ! 8396: } 1.1 root 8397: error ("storage class specified for %s `%s'", 8398: IS_SIGNATURE (current_class_type) 8399: ? (op 8400: ? "signature member operator" 8401: : "signature member function") 1.1.1.2 ! root 8402: : (op ? "member operator" : "field"), 1.1 root 8403: op ? operator_name_string (tmp) : name); 8404: } 8405: else 1.1.1.2 ! root 8406: error (((decl_context == PARM || decl_context == CATCHPARM) 1.1 root 8407: ? "storage class specified for parameter `%s'" 8408: : "storage class specified for typename"), name); 8409: RIDBIT_RESET (RID_REGISTER, specbits); 8410: RIDBIT_RESET (RID_AUTO, specbits); 8411: RIDBIT_RESET (RID_EXTERN, specbits); 8412: 8413: if (decl_context == FIELD && IS_SIGNATURE (current_class_type)) 8414: { 8415: RIDBIT_RESET (RID_STATIC, specbits); 8416: staticp = 0; 8417: } 8418: } 8419: } 8420: else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag) 8421: { 1.1.1.2 ! root 8422: if (toplevel_bindings_p ()) 1.1 root 8423: { 1.1.1.2 ! root 8424: /* It's common practice (and completely valid) to have a const 1.1 root 8425: be initialized and declared extern. */ 8426: if (! constp) 8427: warning ("`%s' initialized and declared `extern'", name); 8428: } 8429: else 8430: error ("`%s' has both `extern' and initializer", name); 8431: } 8432: else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag 1.1.1.2 ! root 8433: && ! toplevel_bindings_p ()) 1.1 root 8434: error ("nested function `%s' declared `extern'", name); 1.1.1.2 ! root 8435: else if (toplevel_bindings_p ()) 1.1 root 8436: { 8437: if (RIDBIT_SETP (RID_AUTO, specbits)) 8438: error ("top-level declaration of `%s' specifies `auto'", name); 8439: #if 0 8440: if (RIDBIT_SETP (RID_REGISTER, specbits)) 8441: error ("top-level declaration of `%s' specifies `register'", name); 8442: #endif 8443: #if 0 8444: /* I'm not sure under what circumstances we should turn 8445: on the extern bit, and under what circumstances we should 8446: warn if other bits are turned on. */ 8447: if (decl_context == NORMAL 8448: && RIDBIT_NOSETP (RID_EXTERN, specbits) 8449: && ! root_lang_context_p ()) 8450: { 8451: RIDBIT_SET (RID_EXTERN, specbits); 8452: } 8453: #endif 8454: } 8455: 8456: /* Now figure out the structure of the declarator proper. 8457: Descend through it, creating more complex types, until we reach 8458: the declared identifier (or NULL_TREE, in an absolute declarator). */ 8459: 8460: while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) 8461: { 8462: /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), 8463: an INDIRECT_REF (for *...), 8464: a CALL_EXPR (for ...(...)), 8465: an identifier (for the name being declared) 8466: or a null pointer (for the place in an absolute declarator 8467: where the name was omitted). 8468: For the last two cases, we have just exited the loop. 8469: 8470: For C++ it could also be 8471: a SCOPE_REF (for class :: ...). In this case, we have converted 8472: sensible names to types, and those are the values we use to 8473: qualify the member name. 8474: an ADDR_EXPR (for &...), 8475: a BIT_NOT_EXPR (for destructors) 8476: 8477: At this point, TYPE is the type of elements of an array, 8478: or for a function to return, or for a pointer to point to. 8479: After this sequence of ifs, TYPE is the type of the 8480: array or function or pointer, and DECLARATOR has had its 8481: outermost layer removed. */ 8482: 8483: if (TREE_CODE (type) == ERROR_MARK) 8484: { 8485: if (TREE_CODE (declarator) == SCOPE_REF) 8486: declarator = TREE_OPERAND (declarator, 1); 8487: else 8488: declarator = TREE_OPERAND (declarator, 0); 8489: continue; 8490: } 8491: if (quals != NULL_TREE 8492: && (declarator == NULL_TREE 8493: || TREE_CODE (declarator) != SCOPE_REF)) 8494: { 8495: if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE) 8496: ctype = TYPE_METHOD_BASETYPE (type); 8497: if (ctype != NULL_TREE) 8498: { 8499: #if 0 /* not yet, should get fixed properly later */ 8500: tree dummy = make_type_decl (NULL_TREE, type); 8501: #else 8502: tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); 8503: #endif 8504: ctype = grok_method_quals (ctype, dummy, quals); 8505: type = TREE_TYPE (dummy); 8506: quals = NULL_TREE; 8507: } 8508: } 8509: switch (TREE_CODE (declarator)) 8510: { 8511: case ARRAY_REF: 8512: { 8513: register tree itype = NULL_TREE; 8514: register tree size = TREE_OPERAND (declarator, 1); 1.1.1.2 ! root 8515: /* The index is a signed object `sizetype' bits wide. */ ! 8516: tree index_type = signed_type (sizetype); 1.1 root 8517: 8518: declarator = TREE_OPERAND (declarator, 0); 8519: 8520: /* Check for some types that there cannot be arrays of. */ 8521: 8522: if (TYPE_MAIN_VARIANT (type) == void_type_node) 8523: { 8524: cp_error ("declaration of `%D' as array of voids", dname); 8525: type = error_mark_node; 8526: } 8527: 8528: if (TREE_CODE (type) == FUNCTION_TYPE) 8529: { 8530: cp_error ("declaration of `%D' as array of functions", dname); 8531: type = error_mark_node; 8532: } 8533: 8534: /* ARM $8.4.3: Since you can't have a pointer to a reference, 8535: you can't have arrays of references. If we allowed them, 1.1.1.2 ! root 8536: then we'd be saying x[i] is valid for an array x, but 1.1 root 8537: then you'd have to ask: what does `*(x + i)' mean? */ 8538: if (TREE_CODE (type) == REFERENCE_TYPE) 8539: { 8540: if (decl_context == TYPENAME) 8541: cp_error ("cannot make arrays of references"); 8542: else 8543: cp_error ("declaration of `%D' as array of references", 8544: dname); 8545: type = error_mark_node; 8546: } 8547: 8548: if (TREE_CODE (type) == OFFSET_TYPE) 8549: { 8550: cp_error ("declaration of `%D' as array of data members", 8551: dname); 8552: type = error_mark_node; 8553: } 8554: 8555: if (TREE_CODE (type) == METHOD_TYPE) 8556: { 8557: cp_error ("declaration of `%D' as array of function members", 8558: dname); 8559: type = error_mark_node; 8560: } 8561: 8562: if (size == error_mark_node) 8563: type = error_mark_node; 8564: 8565: if (type == error_mark_node) 8566: continue; 8567: 8568: if (size) 8569: { 8570: /* Must suspend_momentary here because the index 8571: type may need to live until the end of the function. 8572: For example, it is used in the declaration of a 8573: variable which requires destructing at the end of 8574: the function; then build_vec_delete will need this 8575: value. */ 8576: int yes = suspend_momentary (); 8577: /* might be a cast */ 8578: if (TREE_CODE (size) == NOP_EXPR 8579: && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) 8580: size = TREE_OPERAND (size, 0); 8581: 8582: /* If this is a template parameter, it'll be constant, but 8583: we don't know what the value is yet. */ 8584: if (TREE_CODE (size) == TEMPLATE_CONST_PARM) 8585: goto dont_grok_size; 8586: 8587: if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE 8588: && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) 8589: { 8590: cp_error ("size of array `%D' has non-integer type", 8591: dname); 8592: size = integer_one_node; 8593: } 8594: if (TREE_READONLY_DECL_P (size)) 8595: size = decl_constant_value (size); 1.1.1.2 ! root 8596: if (pedantic && integer_zerop (size)) 1.1 root 8597: cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname); 8598: if (TREE_CONSTANT (size)) 8599: { 1.1.1.2 ! root 8600: int old_flag_pedantic_errors = flag_pedantic_errors; ! 8601: int old_pedantic = pedantic; ! 8602: pedantic = flag_pedantic_errors = 1; ! 8603: /* Always give overflow errors on array subscripts. */ 1.1 root 8604: constant_expression_warning (size); 1.1.1.2 ! root 8605: pedantic = old_pedantic; ! 8606: flag_pedantic_errors = old_flag_pedantic_errors; 1.1 root 8607: if (INT_CST_LT (size, integer_zero_node)) 8608: { 8609: cp_error ("size of array `%D' is negative", dname); 8610: size = integer_one_node; 8611: } 8612: } 8613: else 8614: { 1.1.1.2 ! root 8615: if (pedantic) 1.1 root 8616: { 8617: if (dname) 8618: cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", 8619: dname); 8620: else 8621: cp_pedwarn ("ANSI C++ forbids variable-size array"); 8622: } 8623: /* Make sure the array size remains visibly nonconstant 1.1.1.2 ! root 8624: even if it is (eg) a const variable with known value. */ 1.1 root 8625: size_varies = 1; 8626: } 1.1.1.2 ! root 8627: ! 8628: dont_grok_size: ! 8629: itype = ! 8630: fold (build_binary_op (MINUS_EXPR, ! 8631: convert (index_type, size), ! 8632: convert (index_type, ! 8633: integer_one_node), 1)); ! 8634: if (! TREE_CONSTANT (itype)) ! 8635: itype = variable_size (itype); ! 8636: itype = build_index_type (itype); 1.1 root 8637: resume_momentary (yes); 8638: } 8639: 8640: /* Build the array type itself, then merge any constancy or 8641: volatility into the target type. We must do it in this order 8642: to ensure that the TYPE_MAIN_VARIANT field of the array type 8643: is set correctly. */ 8644: 8645: type = build_cplus_array_type (type, itype); 8646: if (constp || volatilep) 8647: type = cp_build_type_variant (type, constp, volatilep); 8648: 8649: ctype = NULL_TREE; 8650: } 8651: break; 8652: 8653: case CALL_EXPR: 8654: { 8655: tree arg_types; 8656: int funcdecl_p; 8657: tree inner_parms = TREE_OPERAND (declarator, 1); 8658: tree inner_decl = TREE_OPERAND (declarator, 0); 8659: 8660: /* Declaring a function type. 8661: Make sure we have a valid type for the function to return. */ 8662: #if 0 8663: /* Is this an error? Should they be merged into TYPE here? */ 8664: if (pedantic && (constp || volatilep)) 8665: pedwarn ("function declared to return const or volatile result"); 8666: #else 8667: /* Merge any constancy or volatility into the function return 8668: type. */ 8669: 8670: if (constp || volatilep) 8671: { 8672: type = cp_build_type_variant (type, constp, volatilep); 8673: if (IS_AGGR_TYPE (type)) 8674: build_pointer_type (type); 8675: constp = 0; 8676: volatilep = 0; 8677: } 8678: #endif 8679: 8680: /* Warn about some types functions can't return. */ 8681: 8682: if (TREE_CODE (type) == FUNCTION_TYPE) 8683: { 8684: error ("`%s' declared as function returning a function", name); 8685: type = integer_type_node; 8686: } 8687: if (TREE_CODE (type) == ARRAY_TYPE) 8688: { 8689: error ("`%s' declared as function returning an array", name); 8690: type = integer_type_node; 8691: } 8692: 8693: if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) 8694: inner_decl = TREE_OPERAND (inner_decl, 1); 8695: 1.1.1.2 ! root 8696: /* Pick up type qualifiers which should be applied to `this'. */ ! 8697: quals = TREE_OPERAND (declarator, 2); ! 8698: 1.1 root 8699: /* Say it's a definition only for the CALL_EXPR 8700: closest to the identifier. */ 8701: funcdecl_p = 1.1.1.2 ! root 8702: inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE ! 8703: || TREE_CODE (inner_decl) == BIT_NOT_EXPR); 1.1 root 8704: 8705: if (ctype == NULL_TREE 8706: && decl_context == FIELD 8707: && funcdecl_p 8708: && (friendp == 0 || dname == current_class_name)) 8709: ctype = current_class_type; 8710: 8711: if (ctype && return_type == return_conversion) 8712: TYPE_HAS_CONVERSION (ctype) = 1; 8713: if (ctype && constructor_name (ctype) == dname) 8714: { 8715: /* We are within a class's scope. If our declarator name 8716: is the same as the class name, and we are defining 8717: a function, then it is a constructor/destructor, and 8718: therefore returns a void type. */ 8719: 8720: if (flags == DTOR_FLAG) 8721: { 8722: /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may 8723: not be declared const or volatile. A destructor 8724: may not be static. */ 8725: if (staticp == 2) 8726: error ("destructor cannot be static member function"); 1.1.1.2 ! root 8727: if (quals) 1.1 root 8728: { 1.1.1.2 ! root 8729: error ("destructors cannot be declared `const' or `volatile'"); 1.1 root 8730: return void_type_node; 8731: } 8732: if (decl_context == FIELD) 8733: { 8734: if (! member_function_or_else (ctype, current_class_type, 8735: "destructor for alien class `%s' cannot be a member")) 8736: return void_type_node; 8737: } 8738: } 8739: else /* it's a constructor. */ 8740: { 1.1.1.2 ! root 8741: if (explicitp == 1) ! 8742: explicitp = 2; 1.1 root 8743: /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may 8744: not be declared const or volatile. A constructor may 8745: not be virtual. A constructor may not be static. */ 8746: if (staticp == 2) 8747: error ("constructor cannot be static member function"); 8748: if (virtualp) 8749: { 8750: pedwarn ("constructors cannot be declared virtual"); 8751: virtualp = 0; 8752: } 1.1.1.2 ! root 8753: if (quals) 1.1 root 8754: { 1.1.1.2 ! root 8755: error ("constructors cannot be declared `const' or `volatile'"); 1.1 root 8756: return void_type_node; 8757: } 8758: { 8759: RID_BIT_TYPE tmp_bits; 8760: bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE)); 8761: RIDBIT_RESET (RID_INLINE, tmp_bits); 8762: RIDBIT_RESET (RID_STATIC, tmp_bits); 8763: if (RIDBIT_ANY_SET (tmp_bits)) 8764: error ("return value type specifier for constructor ignored"); 8765: } 1.1.1.2 ! root 8766: type = build_pointer_type (ctype); 1.1 root 8767: if (decl_context == FIELD && 8768: IS_SIGNATURE (current_class_type)) 8769: { 8770: error ("constructor not allowed in signature"); 8771: return void_type_node; 8772: } 8773: else if (decl_context == FIELD) 8774: { 8775: if (! member_function_or_else (ctype, current_class_type, 8776: "constructor for alien class `%s' cannot be member")) 8777: return void_type_node; 8778: TYPE_HAS_CONSTRUCTOR (ctype) = 1; 8779: if (return_type != return_ctor) 8780: return NULL_TREE; 8781: } 8782: } 8783: if (decl_context == FIELD) 8784: staticp = 0; 8785: } 1.1.1.2 ! root 8786: else if (friendp) 1.1 root 8787: { 1.1.1.2 ! root 8788: if (initialized) ! 8789: error ("can't initialize friend function `%s'", name); ! 8790: if (virtualp) ! 8791: { ! 8792: /* Cannot be both friend and virtual. */ ! 8793: error ("virtual functions cannot be friends"); ! 8794: RIDBIT_RESET (RID_FRIEND, specbits); ! 8795: friendp = 0; ! 8796: } ! 8797: if (decl_context == NORMAL) ! 8798: error ("friend declaration not in class definition"); ! 8799: if (current_function_decl && funcdef_flag) ! 8800: cp_error ("can't define friend function `%s' in a local class definition", ! 8801: name); 1.1 root 8802: } 8803: 8804: /* Traditionally, declaring return type float means double. */ 8805: 8806: if (flag_traditional 8807: && TYPE_MAIN_VARIANT (type) == float_type_node) 8808: { 8809: type = build_type_variant (double_type_node, 8810: TYPE_READONLY (type), 8811: TYPE_VOLATILE (type)); 8812: } 8813: 8814: /* Construct the function type and go to the next 8815: inner layer of declarator. */ 8816: 8817: declarator = TREE_OPERAND (declarator, 0); 8818: 8819: /* FIXME: This is where default args should be fully 8820: processed. */ 8821: 8822: arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0); 8823: 8824: if (declarator) 8825: { 8826: /* Get past destructors, etc. 8827: We know we have one because FLAGS will be non-zero. 8828: 8829: Complain about improper parameter lists here. */ 8830: if (TREE_CODE (declarator) == BIT_NOT_EXPR) 8831: { 8832: declarator = TREE_OPERAND (declarator, 0); 8833: 8834: if (strict_prototype == 0 && arg_types == NULL_TREE) 8835: arg_types = void_list_node; 8836: else if (arg_types == NULL_TREE 8837: || arg_types != void_list_node) 8838: { 8839: error ("destructors cannot be specified with parameters"); 8840: arg_types = void_list_node; 8841: } 8842: } 8843: } 8844: 8845: /* ANSI seems to say that `const int foo ();' 8846: does not make the function foo const. */ 8847: type = build_function_type (type, 8848: flag_traditional ? 0 : arg_types); 8849: } 8850: break; 8851: 8852: case ADDR_EXPR: 8853: case INDIRECT_REF: 8854: /* Filter out pointers-to-references and references-to-references. 8855: We can get these if a TYPE_DECL is used. */ 8856: 8857: if (TREE_CODE (type) == REFERENCE_TYPE) 8858: { 8859: error ("cannot declare %s to references", 8860: TREE_CODE (declarator) == ADDR_EXPR 8861: ? "references" : "pointers"); 8862: declarator = TREE_OPERAND (declarator, 0); 8863: continue; 8864: } 8865: 1.1.1.2 ! root 8866: if (TREE_CODE (type) == OFFSET_TYPE ! 8867: && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE ! 8868: || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE)) ! 8869: { ! 8870: cp_error ("cannot declare pointer to `%#T' member", ! 8871: TREE_TYPE (type)); ! 8872: type = TREE_TYPE (type); ! 8873: } ! 8874: 1.1 root 8875: /* Merge any constancy or volatility into the target type 8876: for the pointer. */ 8877: 8878: if (constp || volatilep) 8879: { 8880: /* A const or volatile signature pointer/reference is 8881: pointing to a const or volatile object, i.e., the 8882: `optr' is const or volatile, respectively, not the 8883: signature pointer/reference itself. */ 8884: if (! IS_SIGNATURE (type)) 8885: { 8886: type = cp_build_type_variant (type, constp, volatilep); 8887: if (IS_AGGR_TYPE (type)) 8888: build_pointer_type (type); 8889: constp = 0; 8890: volatilep = 0; 8891: } 8892: } 8893: 8894: if (IS_SIGNATURE (type)) 8895: { 8896: if (TREE_CODE (declarator) == ADDR_EXPR) 8897: { 8898: if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE 8899: && TYPE_SIZE (type)) 8900: cp_warning ("empty signature `%T' used in signature reference declaration", 8901: type); 8902: #if 0 8903: type = build_signature_reference_type (type, 8904: constp, volatilep); 8905: #else 8906: sorry ("signature reference"); 8907: return NULL_TREE; 8908: #endif 8909: } 8910: else 8911: { 8912: if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE 8913: && TYPE_SIZE (type)) 8914: cp_warning ("empty signature `%T' used in signature pointer declaration", 8915: type); 8916: type = build_signature_pointer_type (type, 8917: constp, volatilep); 8918: } 8919: constp = 0; 8920: volatilep = 0; 8921: } 8922: else if (TREE_CODE (declarator) == ADDR_EXPR) 8923: { 8924: if (TREE_CODE (type) == FUNCTION_TYPE) 8925: { 8926: error ("cannot declare references to functions; use pointer to function instead"); 8927: type = build_pointer_type (type); 8928: } 8929: else 8930: { 8931: if (TYPE_MAIN_VARIANT (type) == void_type_node) 8932: error ("invalid type: `void &'"); 8933: else 8934: type = build_reference_type (type); 8935: } 8936: } 8937: else if (TREE_CODE (type) == METHOD_TYPE) 8938: { 8939: type = build_ptrmemfunc_type (build_pointer_type (type)); 8940: } 8941: else 8942: type = build_pointer_type (type); 8943: 8944: /* Process a list of type modifier keywords (such as 8945: const or volatile) that were given inside the `*' or `&'. */ 8946: 8947: if (TREE_TYPE (declarator)) 8948: { 8949: register tree typemodlist; 8950: int erred = 0; 8951: for (typemodlist = TREE_TYPE (declarator); typemodlist; 8952: typemodlist = TREE_CHAIN (typemodlist)) 8953: { 8954: if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) 8955: constp++; 8956: else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) 8957: volatilep++; 8958: else if (!erred) 8959: { 8960: erred = 1; 8961: error ("invalid type modifier within %s declarator", 8962: TREE_CODE (declarator) == ADDR_EXPR 8963: ? "reference" : "pointer"); 8964: } 8965: } 8966: if (constp > 1) 8967: pedwarn ("duplicate `const'"); 8968: if (volatilep > 1) 8969: pedwarn ("duplicate `volatile'"); 8970: if (TREE_CODE (declarator) == ADDR_EXPR 8971: && (constp || volatilep)) 8972: { 8973: if (constp) 1.1.1.2 ! root 8974: pedwarn ("discarding `const' applied to a reference"); 1.1 root 8975: if (volatilep) 1.1.1.2 ! root 8976: pedwarn ("discarding `volatile' applied to a reference"); 1.1 root 8977: constp = volatilep = 0; 8978: } 8979: } 8980: declarator = TREE_OPERAND (declarator, 0); 8981: ctype = NULL_TREE; 8982: break; 8983: 8984: case SCOPE_REF: 8985: { 8986: /* We have converted type names to NULL_TREE if the 8987: name was bogus, or to a _TYPE node, if not. 8988: 8989: The variable CTYPE holds the type we will ultimately 8990: resolve to. The code here just needs to build 8991: up appropriate member types. */ 8992: tree sname = TREE_OPERAND (declarator, 1); 8993: /* Destructors can have their visibilities changed as well. */ 8994: if (TREE_CODE (sname) == BIT_NOT_EXPR) 8995: sname = TREE_OPERAND (sname, 0); 8996: 8997: if (TREE_COMPLEXITY (declarator) == 0) 8998: /* This needs to be here, in case we are called 8999: multiple times. */ ; 9000: else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) 9001: /* don't fall out into global scope. Hides real bug? --eichin */ ; 9002: else if (TREE_COMPLEXITY (declarator) == current_class_depth) 9003: { 9004: /* This pop_nested_class corresponds to the 9005: push_nested_class used to push into class scope for 9006: parsing the argument list of a function decl, in 9007: qualified_id. */ 9008: pop_nested_class (1); 9009: TREE_COMPLEXITY (declarator) = current_class_depth; 9010: } 9011: else 9012: my_friendly_abort (16); 9013: 9014: if (TREE_OPERAND (declarator, 0) == NULL_TREE) 9015: { 9016: /* We had a reference to a global decl, or 9017: perhaps we were given a non-aggregate typedef, 9018: in which case we cleared this out, and should just 9019: keep going as though it wasn't there. */ 9020: declarator = sname; 9021: continue; 9022: } 9023: ctype = TREE_OPERAND (declarator, 0); 9024: 9025: if (sname == NULL_TREE) 9026: goto done_scoping; 9027: 9028: if (TREE_CODE (sname) == IDENTIFIER_NODE) 9029: { 9030: /* This is the `standard' use of the scoping operator: 9031: basetype :: member . */ 9032: 1.1.1.2 ! root 9033: if (ctype == current_class_type) ! 9034: { ! 9035: /* class A { ! 9036: void A::f (); ! 9037: }; ! 9038: ! 9039: Is this ill-formed? */ ! 9040: ! 9041: if (pedantic) ! 9042: cp_pedwarn ("extra qualification `%T::' on member `%s' ignored", ! 9043: ctype, name); ! 9044: } ! 9045: else if (TREE_CODE (type) == FUNCTION_TYPE) 1.1 root 9046: { 9047: if (current_class_type == NULL_TREE 9048: || friendp) 9049: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), 9050: TREE_TYPE (type), TYPE_ARG_TYPES (type)); 9051: else 9052: { 9053: cp_error ("cannot declare member function `%T::%s' within `%T'", 9054: ctype, name, current_class_type); 9055: return void_type_node; 9056: } 9057: } 9058: else if (TYPE_SIZE (ctype) != NULL_TREE 9059: || (RIDBIT_SETP (RID_TYPEDEF, specbits))) 9060: { 9061: tree t; 9062: /* have to move this code elsewhere in this function. 1.1.1.2 ! root 9063: this code is used for i.e., typedef int A::M; M *pm; ! 9064: ! 9065: It is? How? jason 10/2/94 */ 1.1 root 9066: 9067: if (explicit_int == -1 && decl_context == FIELD 9068: && funcdef_flag == 0) 9069: { 9070: /* The code in here should only be used to build 9071: stuff that will be grokked as access decls. */ 9072: t = lookup_field (ctype, sname, 0, 0); 9073: if (t) 9074: { 9075: t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); 9076: DECL_INITIAL (t) = init; 9077: return t; 9078: } 9079: /* No such field, try member functions. */ 9080: t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0); 9081: if (t) 9082: { 9083: if (flags == DTOR_FLAG) 9084: t = TREE_VALUE (t); 9085: else if (CLASSTYPE_METHOD_VEC (ctype) 9086: && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0)) 9087: { 9088: /* Don't include destructor with constructors. */ 9089: t = DECL_CHAIN (TREE_VALUE (t)); 9090: if (t == NULL_TREE) 1.1.1.2 ! root 9091: cp_error ("`%T' does not have any constructors", ! 9092: ctype); 1.1 root 9093: t = build_tree_list (NULL_TREE, t); 9094: } 9095: t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); 9096: DECL_INITIAL (t) = init; 9097: return t; 9098: } 9099: 9100: cp_error 9101: ("field `%D' is not a member of structure `%T'", 9102: sname, ctype); 9103: } 9104: 9105: if (current_class_type) 9106: { 1.1.1.2 ! root 9107: cp_error ("cannot declare member `%T::%s' within `%T'", ! 9108: ctype, name, current_class_type); ! 9109: return void_type_node; 1.1 root 9110: } 9111: type = build_offset_type (ctype, type); 9112: } 9113: else if (uses_template_parms (ctype)) 9114: { 9115: enum tree_code c; 9116: if (TREE_CODE (type) == FUNCTION_TYPE) 9117: { 9118: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), 9119: TREE_TYPE (type), 9120: TYPE_ARG_TYPES (type)); 9121: c = FUNCTION_DECL; 9122: } 9123: } 9124: else 9125: { 9126: cp_error ("structure `%T' not yet defined", ctype); 9127: return error_mark_node; 9128: } 9129: 9130: declarator = sname; 9131: } 9132: else if (TREE_CODE (sname) == SCOPE_REF) 9133: my_friendly_abort (17); 9134: else 9135: { 9136: done_scoping: 9137: declarator = TREE_OPERAND (declarator, 1); 9138: if (declarator && TREE_CODE (declarator) == CALL_EXPR) 9139: /* In this case, we will deal with it later. */ 9140: ; 9141: else 9142: { 9143: if (TREE_CODE (type) == FUNCTION_TYPE) 9144: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type)); 9145: else 9146: type = build_offset_type (ctype, type); 9147: } 9148: } 9149: } 9150: break; 9151: 9152: case BIT_NOT_EXPR: 9153: declarator = TREE_OPERAND (declarator, 0); 9154: break; 9155: 9156: case RECORD_TYPE: 9157: case UNION_TYPE: 9158: case ENUMERAL_TYPE: 9159: declarator = NULL_TREE; 9160: break; 9161: 9162: case ERROR_MARK: 9163: declarator = NULL_TREE; 9164: break; 9165: 9166: default: 9167: my_friendly_abort (158); 9168: } 9169: } 9170: 1.1.1.2 ! root 9171: if (explicitp == 1) ! 9172: { ! 9173: error ("only constructors can be declared `explicit'"); ! 9174: explicitp = 0; ! 9175: } ! 9176: 1.1 root 9177: /* Now TYPE has the actual type. */ 9178: 9179: /* If this is declaring a typedef name, return a TYPE_DECL. */ 9180: 1.1.1.2 ! root 9181: if (RIDBIT_SETP (RID_MUTABLE, specbits)) ! 9182: { ! 9183: if (constp) ! 9184: { ! 9185: error ("const `%s' cannot be declared `mutable'", name); ! 9186: RIDBIT_RESET (RID_MUTABLE, specbits); ! 9187: } ! 9188: else if (staticp) ! 9189: { ! 9190: error ("static `%s' cannot be declared `mutable'", name); ! 9191: RIDBIT_RESET (RID_MUTABLE, specbits); ! 9192: } ! 9193: } ! 9194: 1.1 root 9195: if (RIDBIT_SETP (RID_TYPEDEF, specbits)) 9196: { 9197: tree decl; 9198: 9199: /* Note that the grammar rejects storage classes 9200: in typenames, fields or parameters. */ 9201: if (constp || volatilep) 9202: type = cp_build_type_variant (type, constp, volatilep); 9203: 9204: /* If the user declares "struct {...} foo" then `foo' will have 9205: an anonymous name. Fill that name in now. Nothing can 9206: refer to it, so nothing needs know about the name change. 9207: The TYPE_NAME field was filled in by build_struct_xref. */ 9208: if (type != error_mark_node 9209: && TYPE_NAME (type) 9210: && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 9211: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) 9212: { 9213: /* replace the anonymous name with the real name everywhere. */ 9214: lookup_tag_reverse (type, declarator); 9215: TYPE_IDENTIFIER (type) = declarator; 9216: 9217: if (TYPE_LANG_SPECIFIC (type)) 9218: TYPE_WAS_ANONYMOUS (type) = 1; 9219: 9220: { 9221: tree d = TYPE_NAME (type), c = DECL_CONTEXT (d); 9222: 9223: if (!c) 9224: set_nested_typename (d, 0, declarator, type); 9225: else if (TREE_CODE (c) == FUNCTION_DECL) 9226: set_nested_typename (d, DECL_ASSEMBLER_NAME (c), 9227: declarator, type); 9228: else 9229: set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type); 1.1.1.2 ! root 9230: ! 9231: DECL_ASSEMBLER_NAME (d) = DECL_NAME (d); ! 9232: DECL_ASSEMBLER_NAME (d) ! 9233: = get_identifier (build_overload_name (type, 1, 1)); 1.1 root 9234: } 9235: } 9236: 9237: #if 0 /* not yet, should get fixed properly later */ 9238: decl = make_type_decl (declarator, type); 9239: #else 9240: decl = build_decl (TYPE_DECL, declarator, type); 9241: #endif 9242: if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE) 9243: { 9244: cp_error_at ("typedef name may not be class-qualified", decl); 9245: return NULL_TREE; 9246: } 9247: else if (quals) 9248: { 9249: if (ctype == NULL_TREE) 9250: { 9251: if (TREE_CODE (type) != METHOD_TYPE) 9252: cp_error_at ("invalid type qualifier for non-method type", decl); 9253: else 9254: ctype = TYPE_METHOD_BASETYPE (type); 9255: } 9256: if (ctype != NULL_TREE) 9257: grok_method_quals (ctype, decl, quals); 9258: } 9259: 9260: if (RIDBIT_SETP (RID_SIGNED, specbits) 9261: || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) 9262: C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; 9263: 9264: if (RIDBIT_SETP (RID_MUTABLE, specbits)) 9265: { 9266: error ("non-object member `%s' cannot be declared mutable", name); 9267: } 9268: 9269: return decl; 9270: } 9271: 9272: /* Detect the case of an array type of unspecified size 9273: which came, as such, direct from a typedef name. 9274: We must copy the type, so that each identifier gets 9275: a distinct type, so that each identifier's size can be 9276: controlled separately by its own initializer. */ 9277: 9278: if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE 9279: && TYPE_DOMAIN (type) == NULL_TREE) 9280: { 9281: type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); 9282: } 9283: 9284: /* If this is a type name (such as, in a cast or sizeof), 9285: compute the type and return it now. */ 9286: 9287: if (decl_context == TYPENAME) 9288: { 9289: /* Note that the grammar rejects storage classes 9290: in typenames, fields or parameters. */ 9291: if (constp || volatilep) 9292: if (IS_SIGNATURE (type)) 9293: error ("`const' or `volatile' specified with signature type"); 9294: else 9295: type = cp_build_type_variant (type, constp, volatilep); 9296: 9297: /* Special case: "friend class foo" looks like a TYPENAME context. */ 9298: if (friendp) 9299: { 1.1.1.2 ! root 9300: if (volatilep) ! 9301: { ! 9302: cp_error ("`volatile' specified for friend class declaration"); ! 9303: volatilep = 0; ! 9304: } ! 9305: if (inlinep) ! 9306: { ! 9307: cp_error ("`inline' specified for friend class declaration"); ! 9308: inlinep = 0; ! 9309: } ! 9310: ! 9311: /* Only try to do this stuff if we didn't already give up. */ ! 9312: if (type != integer_type_node) ! 9313: { ! 9314: /* A friendly class? */ ! 9315: if (current_class_type) ! 9316: make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); ! 9317: else ! 9318: error ("trying to make class `%s' a friend of global scope", ! 9319: TYPE_NAME_STRING (type)); ! 9320: type = void_type_node; ! 9321: } 1.1 root 9322: } 9323: else if (quals) 9324: { 9325: #if 0 /* not yet, should get fixed properly later */ 9326: tree dummy = make_type_decl (declarator, type); 9327: #else 9328: tree dummy = build_decl (TYPE_DECL, declarator, type); 9329: #endif 9330: if (ctype == NULL_TREE) 9331: { 9332: my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); 9333: ctype = TYPE_METHOD_BASETYPE (type); 9334: } 9335: grok_method_quals (ctype, dummy, quals); 9336: type = TREE_TYPE (dummy); 9337: } 9338: 9339: return type; 9340: } 9341: else if (declarator == NULL_TREE && decl_context != PARM 1.1.1.2 ! root 9342: && decl_context != CATCHPARM 1.1 root 9343: && TREE_CODE (type) != UNION_TYPE 9344: && ! bitfield) 9345: { 9346: cp_error ("abstract declarator `%T' used as declaration", type); 9347: declarator = make_anon_name (); 9348: } 9349: 9350: /* `void' at top level (not within pointer) 9351: is allowed only in typedefs or type names. 9352: We don't complain about parms either, but that is because 9353: a better error message can be made later. */ 9354: 9355: if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) 9356: { 1.1.1.2 ! root 9357: if (! declarator) ! 9358: error ("unnamed variable or field declared void"); ! 9359: else if (TREE_CODE (declarator) == IDENTIFIER_NODE) 1.1 root 9360: { 9361: if (IDENTIFIER_OPNAME_P (declarator)) 9362: #if 0 /* How could this happen? */ 9363: error ("operator `%s' declared void", 9364: operator_name_string (declarator)); 9365: #else 9366: my_friendly_abort (356); 9367: #endif 9368: else 9369: error ("variable or field `%s' declared void", name); 9370: } 9371: else 9372: error ("variable or field declared void"); 9373: type = integer_type_node; 9374: } 9375: 9376: /* Now create the decl, which may be a VAR_DECL, a PARM_DECL 9377: or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ 9378: 9379: { 9380: register tree decl; 9381: 9382: if (decl_context == PARM) 9383: { 9384: if (ctype) 9385: error ("cannot use `::' in parameter declaration"); 9386: 9387: /* A parameter declared as an array of T is really a pointer to T. 9388: One declared as a function is really a pointer to a function. 9389: One declared as a member is really a pointer to member. */ 9390: 9391: if (TREE_CODE (type) == ARRAY_TYPE) 9392: { 9393: /* Transfer const-ness of array into that of type pointed to. */ 9394: type = build_pointer_type 9395: (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); 9396: volatilep = constp = 0; 9397: } 9398: else if (TREE_CODE (type) == FUNCTION_TYPE) 9399: type = build_pointer_type (type); 9400: else if (TREE_CODE (type) == OFFSET_TYPE) 9401: type = build_pointer_type (type); 1.1.1.2 ! root 9402: else if (type == void_type_node && declarator) ! 9403: { ! 9404: error ("declaration of `%s' as void", name); ! 9405: return NULL_TREE; ! 9406: } 1.1 root 9407: 9408: decl = build_decl (PARM_DECL, declarator, type); 9409: 9410: bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, 9411: inlinep, friendp, raises != NULL_TREE); 9412: if (current_class_type 9413: && IS_SIGNATURE (current_class_type)) 9414: { 9415: if (inlinep) 9416: error ("parameter of signature member function declared `inline'"); 9417: if (RIDBIT_SETP (RID_AUTO, specbits)) 9418: error ("parameter of signature member function declared `auto'"); 9419: if (RIDBIT_SETP (RID_REGISTER, specbits)) 9420: error ("parameter of signature member function declared `register'"); 9421: } 9422: 9423: /* Compute the type actually passed in the parmlist, 9424: for the case where there is no prototype. 9425: (For example, shorts and chars are passed as ints.) 9426: When there is a prototype, this is overridden later. */ 9427: 9428: DECL_ARG_TYPE (decl) = type_promotes_to (type); 9429: } 9430: else if (decl_context == FIELD) 9431: { 9432: if (type == error_mark_node) 9433: { 9434: /* Happens when declaring arrays of sizes which 9435: are error_mark_node, for example. */ 9436: decl = NULL_TREE; 9437: } 9438: else if (TREE_CODE (type) == FUNCTION_TYPE) 9439: { 9440: int publicp = 0; 9441: 9442: if (friendp == 0) 9443: { 9444: if (ctype == NULL_TREE) 9445: ctype = current_class_type; 9446: 9447: if (ctype == NULL_TREE) 9448: { 9449: cp_error ("can't make `%D' into a method -- not in a class", 9450: declarator); 9451: return void_type_node; 9452: } 9453: 9454: /* ``A union may [ ... ] not [ have ] virtual functions.'' 9455: ARM 9.5 */ 9456: if (virtualp && TREE_CODE (ctype) == UNION_TYPE) 9457: { 9458: cp_error ("function `%D' declared virtual inside a union", 9459: declarator); 9460: return void_type_node; 9461: } 9462: 9463: if (declarator == ansi_opname[(int) NEW_EXPR] 9464: || declarator == ansi_opname[(int) VEC_NEW_EXPR] 9465: || declarator == ansi_opname[(int) DELETE_EXPR] 9466: || declarator == ansi_opname[(int) VEC_DELETE_EXPR]) 9467: { 9468: if (virtualp) 9469: { 9470: cp_error ("`%D' cannot be declared virtual, since it is always static", 9471: declarator); 9472: virtualp = 0; 9473: } 9474: } 9475: else if (staticp < 2) 9476: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), 9477: TREE_TYPE (type), TYPE_ARG_TYPES (type)); 9478: } 9479: 9480: /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ 1.1.1.2 ! root 9481: publicp = (! friendp ! 9482: || RIDBIT_SETP (RID_EXTERN, specbits) ! 9483: || ! (funcdef_flag < 0 || inlinep)); 1.1 root 9484: decl = grokfndecl (ctype, type, declarator, 1.1.1.2 ! root 9485: virtualp, flags, quals, raises, attrlist, ! 9486: friendp ? -1 : 0, publicp, inlinep); 1.1 root 9487: if (decl == NULL_TREE) 9488: return NULL_TREE; 1.1.1.2 ! root 9489: decl = build_decl_attribute_variant (decl, decl_machine_attr); 1.1 root 9490: 1.1.1.2 ! root 9491: if (explicitp == 2) ! 9492: DECL_NONCONVERTING_P (decl) = 1; 1.1 root 9493: } 9494: else if (TREE_CODE (type) == METHOD_TYPE) 9495: { 1.1.1.2 ! root 9496: /* We only get here for friend declarations of ! 9497: members of other classes. */ 1.1 root 9498: /* All method decls are public, so tell grokfndecl to set 9499: TREE_PUBLIC, also. */ 9500: decl = grokfndecl (ctype, type, declarator, 1.1.1.2 ! root 9501: virtualp, flags, quals, raises, attrlist, ! 9502: friendp ? -1 : 0, 1, 0); 1.1 root 9503: if (decl == NULL_TREE) 9504: return NULL_TREE; 9505: } 9506: else if (TYPE_SIZE (type) == NULL_TREE && !staticp 9507: && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) 9508: { 1.1.1.2 ! root 9509: if (declarator) ! 9510: cp_error ("field `%D' has incomplete type", declarator); ! 9511: else ! 9512: cp_error ("name `%T' has incomplete type", type); 1.1 root 9513: 9514: /* If we're instantiating a template, tell them which 9515: instantiation made the field's type be incomplete. */ 9516: if (current_class_type 9517: && TYPE_NAME (current_class_type) 9518: && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type))) 9519: && declspecs && TREE_VALUE (declspecs) 9520: && TREE_TYPE (TREE_VALUE (declspecs)) == type) 1.1.1.2 ! root 9521: cp_error (" in instantiation of template `%T'", ! 9522: current_class_type); ! 9523: 1.1 root 9524: type = error_mark_node; 9525: decl = NULL_TREE; 9526: } 9527: else 9528: { 9529: if (friendp) 9530: { 9531: error ("`%s' is neither function nor method; cannot be declared friend", 9532: IDENTIFIER_POINTER (declarator)); 9533: friendp = 0; 9534: } 9535: decl = NULL_TREE; 9536: } 9537: 9538: if (friendp) 9539: { 9540: /* Friends are treated specially. */ 9541: if (ctype == current_class_type) 9542: warning ("member functions are implicitly friends of their class"); 9543: else 9544: { 9545: tree t = NULL_TREE; 9546: if (decl && DECL_NAME (decl)) 9547: t = do_friend (ctype, declarator, decl, 9548: last_function_parms, flags, quals); 9549: if (t && funcdef_flag) 9550: return t; 9551: 9552: return void_type_node; 9553: } 9554: } 9555: 9556: /* Structure field. It may not be a function, except for C++ */ 9557: 9558: if (decl == NULL_TREE) 9559: { 9560: if (initialized) 9561: { 9562: /* Motion 10 at San Diego: If a static const integral data 9563: member is initialized with an integral constant 9564: expression, the initializer may appear either in the 9565: declaration (within the class), or in the definition, 9566: but not both. If it appears in the class, the member is 9567: a member constant. The file-scope definition is always 9568: required. */ 9569: if (staticp) 9570: { 9571: if (pedantic) 9572: { 9573: if (! constp) 9574: cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'", 9575: declarator); 9576: 9577: else if (! INTEGRAL_TYPE_P (type)) 9578: cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type); 9579: } 9580: } 9581: 9582: /* Note that initialization of const members is prohibited 9583: by the draft ANSI standard, though it appears to be in 9584: common practice. 12.6.2: The argument list is used to 9585: initialize the named nonstatic member.... This (or an 9586: initializer list) is the only way to initialize 9587: nonstatic const and reference members. */ 1.1.1.2 ! root 9588: else if (pedantic || ! constp) 1.1 root 9589: cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'", 9590: constp ? "const member" : "member", declarator); 9591: } 9592: 9593: if (staticp || (constp && initialized)) 9594: { 1.1.1.2 ! root 9595: /* ANSI C++ Apr '95 wp 9.2 */ ! 9596: if (staticp && declarator == current_class_name) ! 9597: cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class", ! 9598: declarator); ! 9599: 1.1 root 9600: /* C++ allows static class members. 9601: All other work for this is done by grokfield. 9602: This VAR_DECL is built by build_lang_field_decl. 9603: All other VAR_DECLs are built by build_decl. */ 9604: decl = build_lang_field_decl (VAR_DECL, declarator, type); 9605: TREE_STATIC (decl) = 1; 9606: /* In class context, 'static' means public access. */ 9607: TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp; 9608: } 9609: else 9610: { 9611: decl = build_lang_field_decl (FIELD_DECL, declarator, type); 9612: if (RIDBIT_SETP (RID_MUTABLE, specbits)) 9613: { 9614: DECL_MUTABLE_P (decl) = 1; 9615: RIDBIT_RESET (RID_MUTABLE, specbits); 9616: } 9617: } 9618: 9619: bad_specifiers (decl, "field", virtualp, quals != NULL_TREE, 9620: inlinep, friendp, raises != NULL_TREE); 9621: } 9622: } 9623: else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) 9624: { 9625: tree original_name = declarator; 9626: int publicp = 0; 9627: 9628: if (! declarator) 9629: return NULL_TREE; 9630: 9631: if (RIDBIT_SETP (RID_AUTO, specbits)) 9632: error ("storage class `auto' invalid for function `%s'", name); 9633: else if (RIDBIT_SETP (RID_REGISTER, specbits)) 9634: error ("storage class `register' invalid for function `%s'", name); 9635: 9636: /* Function declaration not at top level. 9637: Storage classes other than `extern' are not allowed 9638: and `extern' makes no difference. */ 1.1.1.2 ! root 9639: if (! toplevel_bindings_p () 1.1 root 9640: && ! processing_template_decl 9641: && (RIDBIT_SETP (RID_STATIC, specbits) 9642: || RIDBIT_SETP (RID_INLINE, specbits)) 9643: && pedantic) 9644: { 9645: if (RIDBIT_SETP (RID_STATIC, specbits)) 9646: pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name); 9647: else 9648: pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name); 9649: } 9650: 9651: if (ctype == NULL_TREE) 9652: { 9653: if (virtualp) 9654: { 9655: error ("virtual non-class function `%s'", name); 9656: virtualp = 0; 9657: } 9658: 9659: if (current_lang_name == lang_name_cplusplus 9660: && ! (IDENTIFIER_LENGTH (original_name) == 4 9661: && IDENTIFIER_POINTER (original_name)[0] == 'm' 9662: && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0) 9663: && ! (IDENTIFIER_LENGTH (original_name) > 10 9664: && IDENTIFIER_POINTER (original_name)[0] == '_' 9665: && IDENTIFIER_POINTER (original_name)[1] == '_' 9666: && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0)) 9667: /* Plain overloading: will not be grok'd by grokclassfn. */ 9668: declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); 9669: } 9670: else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) 9671: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), 9672: TREE_TYPE (type), TYPE_ARG_TYPES (type)); 9673: 1.1.1.2 ! root 9674: /* Record presence of `static'. In C++, `inline' implies `static'. */ ! 9675: publicp = (ctype != NULL_TREE ! 9676: || RIDBIT_SETP (RID_EXTERN, specbits) ! 9677: || (!RIDBIT_SETP (RID_STATIC, specbits) ! 9678: && !RIDBIT_SETP (RID_INLINE, specbits))); 1.1 root 9679: 9680: decl = grokfndecl (ctype, type, original_name, 1.1.1.2 ! root 9681: virtualp, flags, quals, raises, attrlist, 1.1 root 9682: processing_template_decl ? 0 : friendp ? 2 : 1, 1.1.1.2 ! root 9683: publicp, inlinep); 1.1 root 9684: if (decl == NULL_TREE) 9685: return NULL_TREE; 9686: 9687: if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c) 1.1.1.2 ! root 9688: DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator); 1.1 root 9689: 9690: if (staticp == 1) 9691: { 9692: int illegal_static = 0; 9693: 9694: /* Don't allow a static member function in a class, and forbid 9695: declaring main to be static. */ 9696: if (TREE_CODE (type) == METHOD_TYPE) 9697: { 9698: cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl); 9699: illegal_static = 1; 9700: } 9701: else if (current_function_decl) 9702: { 9703: /* FIXME need arm citation */ 9704: error ("cannot declare static function inside another function"); 9705: illegal_static = 1; 9706: } 9707: 9708: if (illegal_static) 9709: { 9710: staticp = 0; 9711: RIDBIT_RESET (RID_STATIC, specbits); 9712: } 9713: } 1.1.1.2 ! root 9714: } ! 9715: else ! 9716: { ! 9717: /* It's a variable. */ 1.1 root 9718: 1.1.1.2 ! root 9719: if (decl_context == CATCHPARM) 1.1 root 9720: { 1.1.1.2 ! root 9721: if (ctype) ! 9722: { ! 9723: ctype = NULL_TREE; ! 9724: error ("cannot use `::' in parameter declaration"); ! 9725: } 1.1 root 9726: 1.1.1.2 ! root 9727: /* A parameter declared as an array of T is really a pointer to T. ! 9728: One declared as a function is really a pointer to a function. ! 9729: One declared as a member is really a pointer to member. */ 1.1 root 9730: 1.1.1.2 ! root 9731: if (TREE_CODE (type) == ARRAY_TYPE) 1.1 root 9732: { 1.1.1.2 ! root 9733: /* Transfer const-ness of array into that of type pointed to. */ ! 9734: type = build_pointer_type ! 9735: (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); ! 9736: volatilep = constp = 0; ! 9737: } ! 9738: else if (TREE_CODE (type) == FUNCTION_TYPE) ! 9739: type = build_pointer_type (type); ! 9740: else if (TREE_CODE (type) == OFFSET_TYPE) ! 9741: type = build_pointer_type (type); 1.1 root 9742: } 9743: 9744: /* An uninitialized decl with `extern' is a reference. */ 1.1.1.2 ! root 9745: decl = grokvardecl (type, declarator, specbits, initialized, constp); 1.1 root 9746: bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, 9747: inlinep, friendp, raises != NULL_TREE); 9748: 9749: if (ctype) 9750: { 9751: DECL_CONTEXT (decl) = ctype; 9752: if (staticp == 1) 9753: { 1.1.1.2 ! root 9754: cp_pedwarn ("static member `%D' re-declared as static", decl); 1.1 root 9755: staticp = 0; 9756: RIDBIT_RESET (RID_STATIC, specbits); 9757: } 1.1.1.2 ! root 9758: if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl)) 1.1 root 9759: { 1.1.1.2 ! root 9760: cp_error ("static member `%D' declared `register'", decl); ! 9761: RIDBIT_RESET (RID_REGISTER, specbits); ! 9762: } ! 9763: if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic) ! 9764: { ! 9765: cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage", ! 9766: decl); 1.1 root 9767: RIDBIT_RESET (RID_EXTERN, specbits); 9768: } 9769: } 9770: } 9771: 9772: if (RIDBIT_SETP (RID_MUTABLE, specbits)) 9773: { 9774: error ("`%s' cannot be declared mutable", name); 9775: } 9776: 9777: /* Record `register' declaration for warnings on & 9778: and in case doing stupid register allocation. */ 9779: 9780: if (RIDBIT_SETP (RID_REGISTER, specbits)) 9781: DECL_REGISTER (decl) = 1; 9782: 9783: if (RIDBIT_SETP (RID_EXTERN, specbits)) 9784: DECL_THIS_EXTERN (decl) = 1; 9785: 1.1.1.2 ! root 9786: if (RIDBIT_SETP (RID_STATIC, specbits)) ! 9787: DECL_THIS_STATIC (decl) = 1; ! 9788: 1.1 root 9789: /* Record constancy and volatility. */ 9790: 9791: if (constp) 9792: TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE; 9793: if (volatilep) 9794: { 9795: TREE_SIDE_EFFECTS (decl) = 1; 9796: TREE_THIS_VOLATILE (decl) = 1; 9797: } 9798: 9799: return decl; 9800: } 9801: } 9802: 9803: /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist. 9804: An empty exprlist is a parmlist. An exprlist which 9805: contains only identifiers at the global level 9806: is a parmlist. Otherwise, it is an exprlist. */ 9807: int 9808: parmlist_is_exprlist (exprs) 9809: tree exprs; 9810: { 9811: if (exprs == NULL_TREE || TREE_PARMLIST (exprs)) 9812: return 0; 9813: 1.1.1.2 ! root 9814: if (toplevel_bindings_p ()) 1.1 root 9815: { 9816: /* At the global level, if these are all identifiers, 9817: then it is a parmlist. */ 9818: while (exprs) 9819: { 9820: if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE) 9821: return 1; 9822: exprs = TREE_CHAIN (exprs); 9823: } 9824: return 0; 9825: } 9826: return 1; 9827: } 9828: 9829: /* Subroutine of `grokparms'. In a fcn definition, arg types must 9830: be complete. 9831: 9832: C++: also subroutine of `start_function'. */ 9833: static void 9834: require_complete_types_for_parms (parms) 9835: tree parms; 9836: { 9837: while (parms) 9838: { 9839: tree type = TREE_TYPE (parms); 9840: if (TYPE_SIZE (type) == NULL_TREE) 9841: { 9842: if (DECL_NAME (parms)) 9843: error ("parameter `%s' has incomplete type", 9844: IDENTIFIER_POINTER (DECL_NAME (parms))); 9845: else 9846: error ("parameter has incomplete type"); 9847: TREE_TYPE (parms) = error_mark_node; 9848: } 9849: #if 0 9850: /* If the arg types are incomplete in a declaration, 9851: they must include undefined tags. 9852: These tags can never be defined in the scope of the declaration, 9853: so the types can never be completed, 9854: and no call can be compiled successfully. */ 9855: /* This is not the right behavior for C++, but not having 9856: it is also probably wrong. */ 9857: else 9858: { 9859: /* Now warn if is a pointer to an incomplete type. */ 9860: while (TREE_CODE (type) == POINTER_TYPE 9861: || TREE_CODE (type) == REFERENCE_TYPE) 9862: type = TREE_TYPE (type); 9863: type = TYPE_MAIN_VARIANT (type); 9864: if (TYPE_SIZE (type) == NULL_TREE) 9865: { 9866: if (DECL_NAME (parm) != NULL_TREE) 9867: warning ("parameter `%s' points to incomplete type", 9868: IDENTIFIER_POINTER (DECL_NAME (parm))); 9869: else 9870: warning ("parameter points to incomplete type"); 9871: } 9872: } 9873: #endif 9874: parms = TREE_CHAIN (parms); 9875: } 9876: } 9877: 9878: /* Decode the list of parameter types for a function type. 9879: Given the list of things declared inside the parens, 9880: return a list of types. 9881: 9882: The list we receive can have three kinds of elements: 9883: an IDENTIFIER_NODE for names given without types, 9884: a TREE_LIST node for arguments given as typespecs or names with typespecs, 9885: or void_type_node, to mark the end of an argument list 9886: when additional arguments are not permitted (... was not used). 9887: 9888: FUNCDEF_FLAG is nonzero for a function definition, 0 for 9889: a mere declaration. A nonempty identifier-list gets an error message 9890: when FUNCDEF_FLAG is zero. 9891: If FUNCDEF_FLAG is 1, then parameter types must be complete. 9892: If FUNCDEF_FLAG is -1, then parameter types may be incomplete. 9893: 9894: If all elements of the input list contain types, 9895: we return a list of the types. 9896: If all elements contain no type (except perhaps a void_type_node 9897: at the end), we return a null list. 9898: If some have types and some do not, it is an error, and we 9899: return a null list. 9900: 9901: Also set last_function_parms to either 9902: a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. 9903: A list of names is converted to a chain of PARM_DECLs 9904: by store_parm_decls so that ultimately it is always a chain of decls. 9905: 9906: Note that in C++, parameters can take default values. These default 9907: values are in the TREE_PURPOSE field of the TREE_LIST. It is 9908: an error to specify default values which are followed by parameters 9909: that have no default values, or an ELLIPSES. For simplicities sake, 9910: only parameters which are specified with their types can take on 9911: default values. */ 9912: 9913: static tree 9914: grokparms (first_parm, funcdef_flag) 9915: tree first_parm; 9916: int funcdef_flag; 9917: { 9918: tree result = NULL_TREE; 9919: tree decls = NULL_TREE; 9920: 9921: if (first_parm != NULL_TREE 9922: && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) 9923: { 9924: if (! funcdef_flag) 9925: pedwarn ("parameter names (without types) in function declaration"); 9926: last_function_parms = first_parm; 9927: return NULL_TREE; 9928: } 9929: else if (first_parm != NULL_TREE 9930: && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST 9931: && TREE_VALUE (first_parm) != void_type_node) 9932: my_friendly_abort (145); 9933: else 9934: { 9935: /* Types were specified. This is a list of declarators 9936: each represented as a TREE_LIST node. */ 9937: register tree parm, chain; 9938: int any_init = 0, any_error = 0, saw_void = 0; 9939: 9940: if (first_parm != NULL_TREE) 9941: { 9942: tree last_result = NULL_TREE; 9943: tree last_decl = NULL_TREE; 9944: 9945: for (parm = first_parm; parm != NULL_TREE; parm = chain) 9946: { 9947: tree type, list_node = parm; 9948: register tree decl = TREE_VALUE (parm); 9949: tree init = TREE_PURPOSE (parm); 9950: 9951: chain = TREE_CHAIN (parm); 9952: /* @@ weak defense against parse errors. */ 9953: if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST) 9954: { 9955: /* Give various messages as the need arises. */ 9956: if (TREE_CODE (decl) == STRING_CST) 9957: error ("invalid string constant `%s'", 9958: TREE_STRING_POINTER (decl)); 9959: else if (TREE_CODE (decl) == INTEGER_CST) 9960: error ("invalid integer constant in parameter list, did you forget to give parameter name?"); 9961: continue; 9962: } 9963: 9964: if (decl != void_type_node) 9965: { 9966: /* @@ May need to fetch out a `raises' here. */ 9967: decl = grokdeclarator (TREE_VALUE (decl), 9968: TREE_PURPOSE (decl), 1.1.1.2 ! root 9969: PARM, init != NULL_TREE, ! 9970: NULL_TREE, NULL_TREE); 1.1 root 9971: if (! decl) 9972: continue; 9973: type = TREE_TYPE (decl); 9974: if (TYPE_MAIN_VARIANT (type) == void_type_node) 9975: decl = void_type_node; 9976: else if (TREE_CODE (type) == METHOD_TYPE) 9977: { 9978: if (DECL_NAME (decl)) 9979: /* Cannot use `error_with_decl' here because 9980: we don't have DECL_CONTEXT set up yet. */ 9981: error ("parameter `%s' invalidly declared method type", 9982: IDENTIFIER_POINTER (DECL_NAME (decl))); 9983: else 9984: error ("parameter invalidly declared method type"); 9985: type = build_pointer_type (type); 9986: TREE_TYPE (decl) = type; 9987: } 9988: else if (TREE_CODE (type) == OFFSET_TYPE) 9989: { 9990: if (DECL_NAME (decl)) 9991: error ("parameter `%s' invalidly declared offset type", 9992: IDENTIFIER_POINTER (DECL_NAME (decl))); 9993: else 9994: error ("parameter invalidly declared offset type"); 9995: type = build_pointer_type (type); 9996: TREE_TYPE (decl) = type; 9997: } 9998: else if (TREE_CODE (type) == RECORD_TYPE 9999: && TYPE_LANG_SPECIFIC (type) 10000: && CLASSTYPE_ABSTRACT_VIRTUALS (type)) 10001: { 10002: abstract_virtuals_error (decl, type); 10003: any_error = 1; /* seems like a good idea */ 10004: } 10005: else if (TREE_CODE (type) == RECORD_TYPE 10006: && TYPE_LANG_SPECIFIC (type) 10007: && IS_SIGNATURE (type)) 10008: { 10009: signature_error (decl, type); 10010: any_error = 1; /* seems like a good idea */ 10011: } 10012: } 10013: 10014: if (decl == void_type_node) 10015: { 10016: if (result == NULL_TREE) 10017: { 10018: result = void_list_node; 10019: last_result = result; 10020: } 10021: else 10022: { 10023: TREE_CHAIN (last_result) = void_list_node; 10024: last_result = void_list_node; 10025: } 10026: saw_void = 1; 10027: if (chain 10028: && (chain != void_list_node || TREE_CHAIN (chain))) 10029: error ("`void' in parameter list must be entire list"); 10030: break; 10031: } 10032: 10033: /* Since there is a prototype, args are passed in their own types. */ 10034: DECL_ARG_TYPE (decl) = TREE_TYPE (decl); 10035: #ifdef PROMOTE_PROTOTYPES 10036: if ((TREE_CODE (type) == INTEGER_TYPE 10037: || TREE_CODE (type) == ENUMERAL_TYPE) 10038: && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) 10039: DECL_ARG_TYPE (decl) = integer_type_node; 10040: #endif 10041: if (!any_error) 10042: { 10043: if (init) 10044: { 10045: any_init++; 10046: if (TREE_CODE (init) == SAVE_EXPR) 10047: PARM_DECL_EXPR (init) = 1; 1.1.1.2 ! root 10048: else if (TREE_CODE (init) == VAR_DECL ! 10049: || TREE_CODE (init) == PARM_DECL) 1.1 root 10050: { 10051: if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init))) 10052: { 10053: /* ``Local variables may not be used in default 10054: argument expressions.'' dpANSI C++ 8.2.6 */ 10055: /* If extern int i; within a function is not 10056: considered a local variable, then this code is 10057: wrong. */ 10058: cp_error ("local variable `%D' may not be used as a default argument", init); 10059: any_error = 1; 10060: } 10061: else if (TREE_READONLY_DECL_P (init)) 10062: init = decl_constant_value (init); 10063: } 10064: else 10065: init = require_instantiated_type (type, init, integer_zero_node); 1.1.1.2 ! root 10066: } ! 10067: #if 0 /* This is too early to check; trailing parms might be merged in by ! 10068: duplicate_decls. */ 1.1 root 10069: else if (any_init) 10070: { 10071: error ("all trailing parameters must have default arguments"); 10072: any_error = 1; 10073: } 1.1.1.2 ! root 10074: #endif 1.1 root 10075: } 10076: else 10077: init = NULL_TREE; 10078: 10079: if (decls == NULL_TREE) 10080: { 10081: decls = decl; 10082: last_decl = decls; 10083: } 10084: else 10085: { 10086: TREE_CHAIN (last_decl) = decl; 10087: last_decl = decl; 10088: } 10089: if (TREE_PERMANENT (list_node)) 10090: { 10091: TREE_PURPOSE (list_node) = init; 10092: TREE_VALUE (list_node) = type; 10093: TREE_CHAIN (list_node) = NULL_TREE; 10094: } 10095: else 10096: list_node = saveable_tree_cons (init, type, NULL_TREE); 10097: if (result == NULL_TREE) 10098: { 10099: result = list_node; 10100: last_result = result; 10101: } 10102: else 10103: { 10104: TREE_CHAIN (last_result) = list_node; 10105: last_result = list_node; 10106: } 10107: } 10108: if (last_result) 10109: TREE_CHAIN (last_result) = NULL_TREE; 10110: /* If there are no parameters, and the function does not end 10111: with `...', then last_decl will be NULL_TREE. */ 10112: if (last_decl != NULL_TREE) 10113: TREE_CHAIN (last_decl) = NULL_TREE; 10114: } 10115: } 10116: 10117: last_function_parms = decls; 10118: 10119: /* In a fcn definition, arg types must be complete. */ 10120: if (funcdef_flag > 0) 10121: require_complete_types_for_parms (last_function_parms); 10122: 10123: return result; 10124: } 10125: 10126: /* These memoizing functions keep track of special properties which 10127: a class may have. `grok_ctor_properties' notices whether a class 10128: has a constructor of the form X(X&), and also complains 10129: if the class has a constructor of the form X(X). 10130: `grok_op_properties' takes notice of the various forms of 10131: operator= which are defined, as well as what sorts of type conversion 10132: may apply. Both functions take a FUNCTION_DECL as an argument. */ 10133: int 10134: grok_ctor_properties (ctype, decl) 10135: tree ctype, decl; 10136: { 10137: tree parmtypes = FUNCTION_ARG_CHAIN (decl); 10138: tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; 10139: 10140: /* When a type has virtual baseclasses, a magical first int argument is 10141: added to any ctor so we can tell if the class has been initialized 10142: yet. This could screw things up in this function, so we deliberately 10143: ignore the leading int if we're in that situation. */ 10144: if (parmtypes 10145: && TREE_VALUE (parmtypes) == integer_type_node 10146: && TYPE_USES_VIRTUAL_BASECLASSES (ctype)) 10147: { 10148: parmtypes = TREE_CHAIN (parmtypes); 10149: parmtype = TREE_VALUE (parmtypes); 10150: } 10151: 10152: if (TREE_CODE (parmtype) == REFERENCE_TYPE 10153: && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype) 10154: { 10155: if (TREE_CHAIN (parmtypes) == NULL_TREE 10156: || TREE_CHAIN (parmtypes) == void_list_node 10157: || TREE_PURPOSE (TREE_CHAIN (parmtypes))) 10158: { 10159: TYPE_HAS_INIT_REF (ctype) = 1; 10160: if (TYPE_READONLY (TREE_TYPE (parmtype))) 10161: TYPE_HAS_CONST_INIT_REF (ctype) = 1; 10162: } 10163: else 10164: TYPE_GETS_INIT_AGGR (ctype) = 1; 10165: } 10166: else if (TYPE_MAIN_VARIANT (parmtype) == ctype) 10167: { 10168: if (TREE_CHAIN (parmtypes) != NULL_TREE 10169: && TREE_CHAIN (parmtypes) == void_list_node) 10170: { 10171: cp_error ("invalid constructor; you probably meant `%T (%T&)'", 10172: ctype, ctype); 10173: SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); 10174: 10175: return 0; 10176: } 10177: else 10178: TYPE_GETS_INIT_AGGR (ctype) = 1; 10179: } 10180: else if (TREE_CODE (parmtype) == VOID_TYPE 10181: || TREE_PURPOSE (parmtypes) != NULL_TREE) 10182: TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; 10183: 10184: return 1; 10185: } 10186: 10187: /* An operator with this name can be either unary or binary. */ 10188: static int 10189: ambi_op_p (name) 10190: tree name; 10191: { 10192: return (name == ansi_opname [(int) INDIRECT_REF] 10193: || name == ansi_opname [(int) ADDR_EXPR] 10194: || name == ansi_opname [(int) NEGATE_EXPR] 10195: || name == ansi_opname[(int) POSTINCREMENT_EXPR] 10196: || name == ansi_opname[(int) POSTDECREMENT_EXPR] 10197: || name == ansi_opname [(int) CONVERT_EXPR]); 10198: } 10199: 10200: /* An operator with this name can only be unary. */ 10201: static int 10202: unary_op_p (name) 10203: tree name; 10204: { 10205: return (name == ansi_opname [(int) TRUTH_NOT_EXPR] 10206: || name == ansi_opname [(int) BIT_NOT_EXPR] 10207: || name == ansi_opname [(int) COMPONENT_REF] 10208: || OPERATOR_TYPENAME_P (name)); 10209: } 10210: 10211: /* Do a little sanity-checking on how they declared their operator. */ 10212: static void 10213: grok_op_properties (decl, virtualp, friendp) 10214: tree decl; 10215: int virtualp, friendp; 10216: { 10217: tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); 10218: int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); 10219: tree name = DECL_NAME (decl); 10220: 10221: if (current_class_type == NULL_TREE) 10222: friendp = 1; 10223: 10224: if (! friendp) 10225: { 10226: if (name == ansi_opname[(int) MODIFY_EXPR]) 10227: TYPE_HAS_ASSIGNMENT (current_class_type) = 1; 10228: else if (name == ansi_opname[(int) CALL_EXPR]) 10229: TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1; 10230: else if (name == ansi_opname[(int) ARRAY_REF]) 10231: TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1; 10232: else if (name == ansi_opname[(int) COMPONENT_REF] 10233: || name == ansi_opname[(int) MEMBER_REF]) 10234: TYPE_OVERLOADS_ARROW (current_class_type) = 1; 10235: else if (name == ansi_opname[(int) NEW_EXPR]) 10236: TYPE_GETS_NEW (current_class_type) |= 1; 10237: else if (name == ansi_opname[(int) DELETE_EXPR]) 10238: TYPE_GETS_DELETE (current_class_type) |= 1; 10239: else if (name == ansi_opname[(int) VEC_NEW_EXPR]) 10240: TYPE_GETS_NEW (current_class_type) |= 2; 10241: else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) 10242: TYPE_GETS_DELETE (current_class_type) |= 2; 10243: } 10244: 10245: if (name == ansi_opname[(int) NEW_EXPR] 10246: || name == ansi_opname[(int) VEC_NEW_EXPR]) 10247: { 10248: /* When the compiler encounters the definition of A::operator new, it 10249: doesn't look at the class declaration to find out if it's static. */ 10250: if (methodp) 10251: revert_static_member_fn (&decl, NULL, NULL); 10252: 10253: /* Take care of function decl if we had syntax errors. */ 10254: if (argtypes == NULL_TREE) 10255: TREE_TYPE (decl) = 10256: build_function_type (ptr_type_node, 10257: hash_tree_chain (integer_type_node, 10258: void_list_node)); 10259: else 10260: TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); 10261: } 10262: else if (name == ansi_opname[(int) DELETE_EXPR] 10263: || name == ansi_opname[(int) VEC_DELETE_EXPR]) 10264: { 10265: if (methodp) 10266: revert_static_member_fn (&decl, NULL, NULL); 10267: 10268: if (argtypes == NULL_TREE) 10269: TREE_TYPE (decl) = 10270: build_function_type (void_type_node, 10271: hash_tree_chain (ptr_type_node, 10272: void_list_node)); 10273: else 10274: { 10275: TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); 10276: 10277: if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR] 10278: && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))) 10279: != void_list_node)) 10280: TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1; 10281: } 10282: } 10283: else 10284: { 10285: /* An operator function must either be a non-static member function 10286: or have at least one parameter of a class, a reference to a class, 10287: an enumeration, or a reference to an enumeration. 13.4.0.6 */ 10288: if (! methodp || DECL_STATIC_FUNCTION_P (decl)) 10289: { 10290: if (OPERATOR_TYPENAME_P (name) 10291: || name == ansi_opname[(int) CALL_EXPR] 10292: || name == ansi_opname[(int) MODIFY_EXPR] 10293: || name == ansi_opname[(int) COMPONENT_REF] 10294: || name == ansi_opname[(int) ARRAY_REF]) 10295: cp_error ("`%D' must be a nonstatic member function", decl); 10296: else 10297: { 10298: tree p = argtypes; 10299: 10300: if (DECL_STATIC_FUNCTION_P (decl)) 10301: cp_error ("`%D' must be either a non-static member function or a non-member function", decl); 10302: 10303: if (p) 10304: for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p)) 10305: { 10306: tree arg = TREE_VALUE (p); 10307: if (TREE_CODE (arg) == REFERENCE_TYPE) 10308: arg = TREE_TYPE (arg); 10309: 10310: /* This lets bad template code slip through. */ 10311: if (IS_AGGR_TYPE (arg) 10312: || TREE_CODE (arg) == ENUMERAL_TYPE 10313: || TREE_CODE (arg) == TEMPLATE_TYPE_PARM) 10314: goto foundaggr; 10315: } 10316: cp_error 10317: ("`%D' must have an argument of class or enumerated type", 10318: decl); 10319: foundaggr: 10320: ; 10321: } 10322: } 10323: 10324: if (name == ansi_opname[(int) CALL_EXPR] 10325: || name == ansi_opname[(int) METHOD_CALL_EXPR]) 10326: return; /* no restrictions on args */ 10327: 10328: if (IDENTIFIER_TYPENAME_P (name)) 10329: { 10330: tree t = TREE_TYPE (name); 10331: if (TREE_CODE (t) == VOID_TYPE) 10332: pedwarn ("void is not a valid type conversion operator"); 10333: else if (! friendp) 10334: { 10335: int ref = (TREE_CODE (t) == REFERENCE_TYPE); 10336: char *what = 0; 10337: if (ref) 10338: t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); 10339: 10340: if (t == current_class_type) 10341: what = "the same type"; 10342: else if (IS_AGGR_TYPE (t) 10343: && DERIVED_FROM_P (t, current_class_type)) 10344: what = "a base class"; 10345: 10346: if (what) 10347: warning ("conversion to %s%s will never use a type conversion operator", 10348: ref ? "a reference to " : "", what); 10349: } 10350: } 10351: 10352: if (name == ansi_opname[(int) MODIFY_EXPR]) 10353: { 10354: tree parmtype; 10355: 10356: if (list_length (argtypes) != 3 && methodp) 10357: { 10358: cp_error ("`%D' must take exactly one argument", decl); 10359: return; 10360: } 10361: parmtype = TREE_VALUE (TREE_CHAIN (argtypes)); 10362: 10363: if (copy_assignment_arg_p (parmtype, virtualp) 10364: && ! friendp) 10365: { 10366: TYPE_HAS_ASSIGN_REF (current_class_type) = 1; 10367: if (TREE_CODE (parmtype) != REFERENCE_TYPE 10368: || TYPE_READONLY (TREE_TYPE (parmtype))) 10369: TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; 10370: #if 0 /* Too soon; done in grok_function_init */ 10371: if (DECL_ABSTRACT_VIRTUAL_P (decl)) 10372: TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1; 10373: #endif 10374: } 10375: } 10376: else if (name == ansi_opname[(int) COND_EXPR]) 10377: { 10378: /* 13.4.0.3 */ 10379: pedwarn ("ANSI C++ prohibits overloading operator ?:"); 10380: if (list_length (argtypes) != 4) 10381: cp_error ("`%D' must take exactly three arguments", decl); 10382: } 10383: else if (ambi_op_p (name)) 10384: { 10385: if (list_length (argtypes) == 2) 10386: /* prefix */; 10387: else if (list_length (argtypes) == 3) 10388: { 10389: if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] 10390: || name == ansi_opname[(int) POSTDECREMENT_EXPR]) 10391: && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node) 10392: { 10393: if (methodp) 10394: cp_error ("postfix `%D' must take `int' as its argument", 10395: decl); 10396: else 10397: cp_error 10398: ("postfix `%D' must take `int' as its second argument", 10399: decl); 10400: } 10401: } 10402: else 10403: { 10404: if (methodp) 10405: cp_error ("`%D' must take either zero or one argument", decl); 10406: else 10407: cp_error ("`%D' must take either one or two arguments", decl); 10408: } 10409: } 10410: else if (unary_op_p (name)) 10411: { 10412: if (list_length (argtypes) != 2) 10413: { 10414: if (methodp) 10415: cp_error ("`%D' must take `void'", decl); 10416: else 10417: cp_error ("`%D' must take exactly one argument", decl); 10418: } 10419: } 10420: else /* if (binary_op_p (name)) */ 10421: { 10422: if (list_length (argtypes) != 3) 10423: { 10424: if (methodp) 10425: cp_error ("`%D' must take exactly one argument", decl); 10426: else 10427: cp_error ("`%D' must take exactly two arguments", decl); 10428: } 10429: } 10430: 10431: /* 13.4.0.8 */ 10432: if (argtypes) 10433: for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes)) 10434: if (TREE_PURPOSE (argtypes)) 10435: { 10436: TREE_PURPOSE (argtypes) = NULL_TREE; 10437: if (name == ansi_opname[(int) POSTINCREMENT_EXPR] 10438: || name == ansi_opname[(int) POSTDECREMENT_EXPR]) 10439: { 10440: if (pedantic) 10441: cp_pedwarn ("`%D' cannot have default arguments", decl); 10442: } 10443: else 10444: cp_error ("`%D' cannot have default arguments", decl); 10445: } 10446: } 10447: } 10448: 10449: /* Get the struct, enum or union (CODE says which) with tag NAME. 10450: Define the tag as a forward-reference if it is not defined. 10451: 10452: C++: If a class derivation is given, process it here, and report 10453: an error if multiple derivation declarations are not identical. 10454: 10455: If this is a definition, come in through xref_tag and only look in 10456: the current frame for the name (since C++ allows new names in any 10457: scope.) */ 10458: 10459: tree 10460: xref_tag (code_type_node, name, binfo, globalize) 10461: tree code_type_node; 10462: tree name, binfo; 10463: int globalize; 10464: { 10465: enum tag_types tag_code; 10466: enum tree_code code; 10467: int temp = 0; 1.1.1.2 ! root 10468: int i; 1.1 root 10469: register tree ref, t; 10470: struct binding_level *b = inner_binding_level; 10471: 10472: tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); 10473: switch (tag_code) 10474: { 10475: case record_type: 10476: case class_type: 10477: case signature_type: 10478: code = RECORD_TYPE; 10479: break; 10480: case union_type: 10481: code = UNION_TYPE; 10482: break; 10483: case enum_type: 10484: code = ENUMERAL_TYPE; 10485: break; 10486: default: 10487: my_friendly_abort (18); 10488: } 10489: 10490: /* If a cross reference is requested, look up the type 10491: already defined for this tag and return it. */ 10492: t = IDENTIFIER_TYPE_VALUE (name); 10493: if (t && TREE_CODE (t) != code) 10494: t = NULL_TREE; 10495: 1.1.1.2 ! root 10496: if (! globalize) 1.1 root 10497: { 10498: /* If we know we are defining this tag, only look it up in this scope 10499: * and don't try to find it as a type. */ 1.1.1.2 ! root 10500: if (t && TYPE_CONTEXT(t) && TREE_MANGLED (name)) ! 10501: ref = t; 1.1 root 10502: else 10503: ref = lookup_tag (code, name, b, 1); 10504: } 10505: else 10506: { 10507: if (t) 10508: ref = t; 10509: else 10510: ref = lookup_tag (code, name, b, 0); 10511: 10512: if (! ref) 10513: { 10514: /* Try finding it as a type declaration. If that wins, use it. */ 10515: ref = lookup_name (name, 1); 10516: if (ref && TREE_CODE (ref) == TYPE_DECL 10517: && TREE_CODE (TREE_TYPE (ref)) == code) 10518: ref = TREE_TYPE (ref); 10519: else 10520: ref = NULL_TREE; 10521: } 10522: } 10523: 10524: push_obstacks_nochange (); 10525: 10526: if (! ref) 10527: { 10528: /* If no such tag is yet defined, create a forward-reference node 10529: and record it as the "definition". 10530: When a real declaration of this type is found, 10531: the forward-reference will be altered into a real type. */ 10532: 10533: /* In C++, since these migrate into the global scope, we must 10534: build them on the permanent obstack. */ 10535: 10536: temp = allocation_temporary_p (); 10537: if (temp) 10538: end_temporary_allocation (); 10539: 10540: if (code == ENUMERAL_TYPE) 10541: { 10542: ref = make_node (ENUMERAL_TYPE); 10543: 10544: /* Give the type a default layout like unsigned int 10545: to avoid crashing if it does not get defined. */ 10546: TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); 10547: TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); 10548: TREE_UNSIGNED (ref) = 1; 10549: TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); 10550: TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); 10551: TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); 10552: 10553: /* Enable us to recognize when a type is created in class context. 10554: To do nested classes correctly, this should probably be cleared 10555: out when we leave this classes scope. Currently this in only 10556: done in `start_enum'. */ 10557: 10558: pushtag (name, ref, globalize); 10559: if (flag_cadillac) 10560: cadillac_start_enum (ref); 10561: } 10562: else 10563: { 10564: struct binding_level *old_b = class_binding_level; 10565: 10566: ref = make_lang_type (code); 10567: 10568: if (tag_code == signature_type) 10569: { 10570: SET_SIGNATURE (ref); 10571: /* Since a signature type will be turned into the type 10572: of signature tables, it's not only an interface. */ 10573: CLASSTYPE_INTERFACE_ONLY (ref) = 0; 10574: SET_CLASSTYPE_INTERFACE_KNOWN (ref); 10575: /* A signature doesn't have a vtable. */ 10576: CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0; 10577: } 10578: 10579: #ifdef NONNESTED_CLASSES 10580: /* Class types don't nest the way enums do. */ 10581: class_binding_level = (struct binding_level *)0; 10582: #endif 10583: pushtag (name, ref, globalize); 10584: class_binding_level = old_b; 10585: 10586: if (flag_cadillac) 10587: cadillac_start_struct (ref); 10588: } 10589: } 10590: else 10591: { 10592: /* If it no longer looks like a nested type, make sure it's 10593: in global scope. */ 10594: if (b == global_binding_level && !class_binding_level 10595: && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE) 10596: IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref); 10597: 1.1.1.2 ! root 10598: #if 0 1.1 root 10599: if (binfo) 10600: { 10601: tree tt1 = binfo; 10602: tree tt2 = TYPE_BINFO_BASETYPES (ref); 10603: 10604: if (TYPE_BINFO_BASETYPES (ref)) 10605: for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1)) 10606: if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i)))) 10607: { 10608: cp_error ("redeclaration of derivation chain of type `%#T'", 10609: ref); 10610: break; 10611: } 10612: 10613: if (tt1 == NULL_TREE) 10614: /* The user told us something we already knew. */ 10615: goto just_return; 10616: 10617: /* In C++, since these migrate into the global scope, we must 10618: build them on the permanent obstack. */ 10619: end_temporary_allocation (); 10620: } 1.1.1.2 ! root 10621: #endif 1.1 root 10622: } 10623: 10624: if (binfo) 1.1.1.2 ! root 10625: xref_basetypes (code_type_node, name, ref, binfo); 1.1 root 10626: 1.1.1.2 ! root 10627: just_return: 1.1 root 10628: 10629: /* Until the type is defined, tentatively accept whatever 10630: structure tag the user hands us. */ 10631: if (TYPE_SIZE (ref) == NULL_TREE 10632: && ref != current_class_type 10633: /* Have to check this, in case we have contradictory tag info. */ 10634: && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) 10635: { 10636: if (tag_code == class_type) 10637: CLASSTYPE_DECLARED_CLASS (ref) = 1; 10638: else if (tag_code == record_type || tag_code == signature_type) 10639: CLASSTYPE_DECLARED_CLASS (ref) = 0; 10640: } 10641: 10642: pop_obstacks (); 10643: 10644: return ref; 10645: } 1.1.1.2 ! root 10646: ! 10647: void ! 10648: xref_basetypes (code_type_node, name, ref, binfo) ! 10649: tree code_type_node; ! 10650: tree name, ref; ! 10651: tree binfo; ! 10652: { ! 10653: /* In the declaration `A : X, Y, ... Z' we mark all the types ! 10654: (A, X, Y, ..., Z) so we can check for duplicates. */ ! 10655: tree binfos; ! 10656: int i, len; ! 10657: enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); ! 10658: ! 10659: if (tag_code == union_type) ! 10660: { ! 10661: cp_error ("derived union `%T' invalid", ref); ! 10662: return; ! 10663: } ! 10664: ! 10665: len = list_length (binfo); ! 10666: push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref)); ! 10667: ! 10668: SET_CLASSTYPE_MARKED (ref); ! 10669: BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len); ! 10670: ! 10671: for (i = 0; binfo; binfo = TREE_CHAIN (binfo)) ! 10672: { ! 10673: /* The base of a derived struct is public by default. */ ! 10674: int via_public ! 10675: = (TREE_PURPOSE (binfo) == (tree)access_public ! 10676: || TREE_PURPOSE (binfo) == (tree)access_public_virtual ! 10677: || (tag_code != class_type ! 10678: && (TREE_PURPOSE (binfo) == (tree)access_default ! 10679: || TREE_PURPOSE (binfo) == (tree)access_default_virtual))); ! 10680: int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected; ! 10681: int via_virtual ! 10682: = (TREE_PURPOSE (binfo) == (tree)access_private_virtual ! 10683: || TREE_PURPOSE (binfo) == (tree)access_public_virtual ! 10684: || TREE_PURPOSE (binfo) == (tree)access_default_virtual); ! 10685: tree basetype = TREE_TYPE (TREE_VALUE (binfo)); ! 10686: tree base_binfo; ! 10687: ! 10688: GNU_xref_hier (IDENTIFIER_POINTER (name), ! 10689: IDENTIFIER_POINTER (TREE_VALUE (binfo)), ! 10690: via_public, via_virtual, 0); ! 10691: ! 10692: if (basetype && TREE_CODE (basetype) == TYPE_DECL) ! 10693: basetype = TREE_TYPE (basetype); ! 10694: if (!basetype || TREE_CODE (basetype) != RECORD_TYPE) ! 10695: { ! 10696: cp_error ("base type `%T' fails to be a struct or class type", ! 10697: TREE_VALUE (binfo)); ! 10698: continue; ! 10699: } ! 10700: #if 1 ! 10701: /* This code replaces similar code in layout_basetypes. */ ! 10702: else if (TYPE_INCOMPLETE (basetype)) ! 10703: { ! 10704: cp_error ("base class `%T' has incomplete type", basetype); ! 10705: continue; ! 10706: } ! 10707: #endif ! 10708: else ! 10709: { ! 10710: if (CLASSTYPE_MARKED (basetype)) ! 10711: { ! 10712: if (basetype == ref) ! 10713: cp_error ("recursive type `%T' undefined", basetype); ! 10714: else ! 10715: cp_error ("duplicate base type `%T' invalid", basetype); ! 10716: continue; ! 10717: } ! 10718: ! 10719: /* Note that the BINFO records which describe individual ! 10720: inheritances are *not* shared in the lattice! They ! 10721: cannot be shared because a given baseclass may be ! 10722: inherited with different `accessibility' by different ! 10723: derived classes. (Each BINFO record describing an ! 10724: individual inheritance contains flags which say what ! 10725: the `accessibility' of that particular inheritance is.) */ ! 10726: ! 10727: base_binfo = make_binfo (integer_zero_node, basetype, ! 10728: TYPE_BINFO_VTABLE (basetype), ! 10729: TYPE_BINFO_VIRTUALS (basetype), NULL_TREE); ! 10730: ! 10731: TREE_VEC_ELT (binfos, i) = base_binfo; ! 10732: TREE_VIA_PUBLIC (base_binfo) = via_public; ! 10733: TREE_VIA_PROTECTED (base_binfo) = via_protected; ! 10734: TREE_VIA_VIRTUAL (base_binfo) = via_virtual; ! 10735: BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref); ! 10736: ! 10737: SET_CLASSTYPE_MARKED (basetype); ! 10738: #if 0 ! 10739: /* XYZZY TEST VIRTUAL BASECLASSES */ ! 10740: if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE ! 10741: && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype) ! 10742: && via_virtual == 0) ! 10743: { ! 10744: warning ("making type `%s' a virtual baseclass", ! 10745: TYPE_NAME_STRING (basetype)); ! 10746: via_virtual = 1; ! 10747: } ! 10748: #endif ! 10749: /* We are free to modify these bits because they are meaningless ! 10750: at top level, and BASETYPE is a top-level type. */ ! 10751: if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) ! 10752: { ! 10753: TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; ! 10754: TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; ! 10755: } ! 10756: ! 10757: TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype); ! 10758: TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype); ! 10759: TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype); ! 10760: CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype); ! 10761: i += 1; ! 10762: } ! 10763: } ! 10764: if (i) ! 10765: TREE_VEC_LENGTH (binfos) = i; ! 10766: else ! 10767: BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; ! 10768: ! 10769: if (i > 1) ! 10770: TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; ! 10771: else if (i == 1) ! 10772: TYPE_USES_MULTIPLE_INHERITANCE (ref) ! 10773: = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0))); ! 10774: if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) ! 10775: TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; ! 10776: ! 10777: /* Unmark all the types. */ ! 10778: while (--i >= 0) ! 10779: CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); ! 10780: CLEAR_CLASSTYPE_MARKED (ref); ! 10781: ! 10782: pop_obstacks (); ! 10783: } ! 10784: 1.1 root 10785: 10786: static tree current_local_enum = NULL_TREE; 10787: 10788: /* Begin compiling the definition of an enumeration type. 10789: NAME is its name (or null if anonymous). 10790: Returns the type object, as yet incomplete. 10791: Also records info about it so that build_enumerator 10792: may be used to declare the individual values as they are read. */ 10793: 10794: tree 10795: start_enum (name) 10796: tree name; 10797: { 10798: register tree enumtype = NULL_TREE; 10799: struct binding_level *b = inner_binding_level; 10800: 10801: /* If this is the real definition for a previous forward reference, 10802: fill in the contents in the same object that used to be the 10803: forward reference. */ 10804: 10805: if (name != NULL_TREE) 10806: enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); 10807: 10808: if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) 10809: cp_error ("multiple definition of enum `%T'", enumtype); 10810: else 10811: { 10812: enumtype = make_node (ENUMERAL_TYPE); 10813: pushtag (name, enumtype, 0); 10814: } 10815: 10816: if (current_class_type) 10817: TREE_ADDRESSABLE (b->tags) = 1; 10818: current_local_enum = NULL_TREE; 10819: 10820: #if 0 /* This stuff gets cleared in finish_enum anyway. */ 10821: if (TYPE_VALUES (enumtype) != NULL_TREE) 10822: /* Completely replace its old definition. 10823: The old enumerators remain defined, however. */ 10824: TYPE_VALUES (enumtype) = NULL_TREE; 10825: 10826: /* Initially, set up this enum as like `int' 10827: so that we can create the enumerators' declarations and values. 10828: Later on, the precision of the type may be changed and 10829: it may be laid out again. */ 10830: 10831: TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); 10832: TYPE_SIZE (enumtype) = NULL_TREE; 10833: fixup_signed_type (enumtype); 10834: #endif 10835: 10836: /* We copy this value because enumerated type constants 10837: are really of the type of the enumerator, not integer_type_node. */ 10838: enum_next_value = copy_node (integer_zero_node); 10839: enum_overflow = 0; 10840: 10841: GNU_xref_decl (current_function_decl, enumtype); 10842: return enumtype; 10843: } 10844: 10845: /* After processing and defining all the values of an enumeration type, 10846: install their decls in the enumeration type and finish it off. 10847: ENUMTYPE is the type object and VALUES a list of name-value pairs. 10848: Returns ENUMTYPE. */ 10849: 10850: tree 10851: finish_enum (enumtype, values) 10852: register tree enumtype, values; 10853: { 10854: register tree minnode, maxnode; 10855: /* Calculate the maximum value of any enumerator in this type. */ 10856: 10857: if (values) 10858: { 10859: register tree pair; 10860: register tree value = DECL_INITIAL (TREE_VALUE (values)); 10861: 10862: /* Speed up the main loop by performing some precalculations */ 10863: TREE_TYPE (TREE_VALUE (values)) = enumtype; 10864: TREE_TYPE (value) = enumtype; 10865: TREE_VALUE (values) = value; 10866: minnode = maxnode = value; 10867: 10868: for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) 10869: { 10870: value = DECL_INITIAL (TREE_VALUE (pair)); 10871: TREE_TYPE (TREE_VALUE (pair)) = enumtype; 10872: TREE_TYPE (value) = enumtype; 10873: TREE_VALUE (pair) = value; 10874: if (tree_int_cst_lt (maxnode, value)) 10875: maxnode = value; 10876: else if (tree_int_cst_lt (value, minnode)) 10877: minnode = value; 10878: } 10879: } 10880: else 10881: maxnode = minnode = integer_zero_node; 10882: 10883: TYPE_VALUES (enumtype) = values; 10884: 10885: { 10886: int unsignedp = tree_int_cst_sgn (minnode) >= 0; 10887: int lowprec = min_precision (minnode, unsignedp); 10888: int highprec = min_precision (maxnode, unsignedp); 10889: int precision = MAX (lowprec, highprec); 10890: 1.1.1.2 ! root 10891: TYPE_SIZE (enumtype) = NULL_TREE; 1.1 root 10892: 1.1.1.2 ! root 10893: /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */ 1.1 root 10894: 10895: TYPE_PRECISION (enumtype) = precision; 10896: if (unsignedp) 10897: fixup_unsigned_type (enumtype); 10898: else 10899: fixup_signed_type (enumtype); 1.1.1.2 ! root 10900: ! 10901: if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node)) ! 10902: /* Use the width of the narrowest normal C type which is wide enough. */ ! 10903: TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size ! 10904: (precision, 1)); ! 10905: else ! 10906: TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); ! 10907: ! 10908: TYPE_SIZE (enumtype) = 0; ! 10909: layout_type (enumtype); 1.1 root 10910: } 10911: 10912: if (flag_cadillac) 10913: cadillac_finish_enum (enumtype); 10914: 10915: { 10916: register tree tem; 10917: 10918: /* Fix up all variant types of this enum type. */ 10919: for (tem = TYPE_MAIN_VARIANT (enumtype); tem; 10920: tem = TYPE_NEXT_VARIANT (tem)) 10921: { 10922: TYPE_VALUES (tem) = TYPE_VALUES (enumtype); 10923: TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); 10924: TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); 10925: TYPE_SIZE (tem) = TYPE_SIZE (enumtype); 10926: TYPE_MODE (tem) = TYPE_MODE (enumtype); 10927: TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); 10928: TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); 10929: TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); 10930: } 10931: } 10932: 10933: /* Finish debugging output for this type. */ 10934: #if 0 10935: /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging 10936: information should *not* be generated? I think not. */ 10937: if (! DECL_IGNORED_P (TYPE_NAME (enumtype))) 10938: #endif 10939: rest_of_type_compilation (enumtype, global_bindings_p ()); 10940: 10941: return enumtype; 10942: } 10943: 10944: /* Build and install a CONST_DECL for one value of the 10945: current enumeration type (one that was begun with start_enum). 10946: Return a tree-list containing the name and its value. 10947: Assignment of sequential values by default is handled here. */ 10948: 10949: tree 10950: build_enumerator (name, value) 10951: tree name, value; 10952: { 10953: tree decl, result; 10954: /* Change this to zero if we find VALUE is not shareable. */ 10955: int shareable = 1; 10956: 10957: /* Remove no-op casts from the value. */ 10958: if (value) 10959: STRIP_TYPE_NOPS (value); 10960: 10961: /* Validate and default VALUE. */ 10962: if (value != NULL_TREE) 10963: { 10964: if (TREE_READONLY_DECL_P (value)) 10965: { 10966: value = decl_constant_value (value); 10967: shareable = 0; 10968: } 10969: 10970: if (TREE_CODE (value) == INTEGER_CST) 10971: { 10972: value = default_conversion (value); 10973: constant_expression_warning (value); 10974: } 10975: else 10976: { 10977: cp_error ("enumerator value for `%D' not integer constant", name); 10978: value = NULL_TREE; 10979: } 10980: } 10981: 10982: /* The order of things is reversed here so that we 10983: can check for possible sharing of enum values, 10984: to keep that from happening. */ 10985: /* Default based on previous value. */ 10986: if (value == NULL_TREE) 10987: { 10988: value = enum_next_value; 10989: if (enum_overflow) 10990: cp_error ("overflow in enumeration values at `%D'", name); 10991: } 10992: 10993: /* Remove no-op casts from the value. */ 10994: if (value) 10995: STRIP_TYPE_NOPS (value); 10996: 10997: /* Make up for hacks in lex.c. */ 10998: if (value == integer_zero_node) 10999: value = build_int_2 (0, 0); 11000: else if (value == integer_one_node) 11001: value = build_int_2 (1, 0); 11002: else if (TREE_CODE (value) == INTEGER_CST 11003: && (shareable == 0 11004: || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)) 11005: { 11006: value = copy_node (value); 11007: TREE_TYPE (value) = integer_type_node; 11008: } 11009: 11010: /* C++ associates enums with global, function, or class declarations. */ 11011: 11012: decl = current_scope (); 11013: if (decl && decl == current_class_type) 11014: { 11015: /* This enum declaration is local to the class, so we must put 11016: it in that class's list of decls. */ 11017: decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); 11018: DECL_INITIAL (decl) = value; 11019: TREE_READONLY (decl) = 1; 11020: pushdecl_class_level (decl); 11021: TREE_CHAIN (decl) = current_local_enum; 11022: current_local_enum = decl; 11023: } 11024: else 11025: { 11026: /* It's a global enum, or it's local to a function. (Note local to 11027: a function could mean local to a class method. */ 11028: decl = build_decl (CONST_DECL, name, integer_type_node); 11029: DECL_INITIAL (decl) = value; 11030: 11031: pushdecl (decl); 11032: GNU_xref_decl (current_function_decl, decl); 11033: } 11034: 11035: /* Set basis for default for next value. */ 11036: enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, 11037: integer_one_node, PLUS_EXPR); 11038: enum_overflow = tree_int_cst_lt (enum_next_value, value); 11039: 11040: if (enum_next_value == integer_one_node) 11041: enum_next_value = copy_node (enum_next_value); 11042: 11043: result = saveable_tree_cons (name, decl, NULL_TREE); 11044: return result; 11045: } 11046: 11047: tree 11048: grok_enum_decls (type, decl) 11049: tree type, decl; 11050: { 11051: tree d = current_local_enum; 11052: 11053: if (d == NULL_TREE) 11054: return decl; 11055: 11056: while (1) 11057: { 11058: TREE_TYPE (d) = type; 11059: if (TREE_CHAIN (d) == NULL_TREE) 11060: { 11061: TREE_CHAIN (d) = decl; 11062: break; 11063: } 11064: d = TREE_CHAIN (d); 11065: } 11066: 11067: decl = current_local_enum; 11068: current_local_enum = NULL_TREE; 11069: 11070: return decl; 11071: } 11072: 11073: /* Create the FUNCTION_DECL for a function definition. 11074: DECLSPECS and DECLARATOR are the parts of the declaration; 11075: they describe the function's name and the type it returns, 11076: but twisted together in a fashion that parallels the syntax of C. 11077: 11078: This function creates a binding context for the function body 11079: as well as setting up the FUNCTION_DECL in current_function_decl. 11080: 11081: Returns 1 on success. If the DECLARATOR is not suitable for a function 11082: (it defines a datum instead), we return 0, which tells 11083: yyparse to report a parse error. 11084: 11085: For C++, we must first check whether that datum makes any sense. 11086: For example, "class A local_a(1,2);" means that variable local_a 11087: is an aggregate of type A, which should have a constructor 11088: applied to it with the argument list [1, 2]. 11089: 11090: @@ There is currently no way to retrieve the storage 11091: @@ allocated to FUNCTION (or all of its parms) if we return 11092: @@ something we had previously. */ 11093: 11094: int 1.1.1.2 ! root 11095: start_function (declspecs, declarator, raises, attrs, pre_parsed_p) ! 11096: tree declspecs, declarator, raises, attrs; 1.1 root 11097: int pre_parsed_p; 11098: { 11099: tree decl1, olddecl; 11100: tree ctype = NULL_TREE; 11101: tree fntype; 11102: tree restype; 11103: extern int have_extern_spec; 11104: extern int used_extern_spec; 11105: int doing_friend = 0; 11106: 11107: /* Sanity check. */ 11108: my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160); 11109: my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); 11110: 11111: /* Assume, until we see it does. */ 11112: current_function_returns_value = 0; 11113: current_function_returns_null = 0; 11114: warn_about_return_type = 0; 1.1.1.2 ! root 11115: named_labels = 0; ! 11116: shadowed_labels = 0; 1.1 root 11117: current_function_assigns_this = 0; 11118: current_function_just_assigned_this = 0; 11119: current_function_parms_stored = 0; 11120: original_result_rtx = NULL_RTX; 11121: current_function_obstack_index = 0; 11122: current_function_obstack_usage = 0; 1.1.1.2 ! root 11123: base_init_expr = NULL_TREE; ! 11124: protect_list = NULL_TREE; ! 11125: current_base_init_list = NULL_TREE; ! 11126: current_member_init_list = NULL_TREE; ! 11127: ctor_label = dtor_label = NULL_TREE; 1.1 root 11128: 11129: clear_temp_name (); 11130: 11131: /* This should only be done once on the top most decl. */ 11132: if (have_extern_spec && !used_extern_spec) 11133: { 11134: declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); 11135: used_extern_spec = 1; 11136: } 11137: 11138: if (pre_parsed_p) 11139: { 11140: decl1 = declarator; 11141: 11142: if (! DECL_ARGUMENTS (decl1) 11143: && !DECL_STATIC_FUNCTION_P (decl1) 11144: && DECL_CONTEXT (decl1) 11145: && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1))) 11146: && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1))))) 11147: { 11148: cp_error ("redeclaration of `%#D'", decl1); 11149: if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) 11150: cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); 11151: else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))) 11152: cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))); 11153: } 11154: 1.1.1.2 ! root 11155: /* This can happen if a template class is instantiated as part of the ! 11156: specialization of a member function which is defined in the class ! 11157: template. We should just use the specialization, but for now give an ! 11158: error. */ ! 11159: if (DECL_INITIAL (decl1) != NULL_TREE) ! 11160: { ! 11161: cp_error_at ("specialization of `%#D' not supported", decl1); ! 11162: cp_error ("when defined in the class template body", decl1); ! 11163: } ! 11164: 1.1 root 11165: last_function_parms = DECL_ARGUMENTS (decl1); 11166: last_function_parm_tags = NULL_TREE; 11167: fntype = TREE_TYPE (decl1); 11168: if (TREE_CODE (fntype) == METHOD_TYPE) 11169: ctype = TYPE_METHOD_BASETYPE (fntype); 11170: 11171: /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a 11172: class is in the (lexical) scope of the class in which it is 11173: defined. */ 11174: if (!ctype && DECL_FRIEND_P (decl1)) 11175: { 11176: ctype = DECL_CLASS_CONTEXT (decl1); 11177: 11178: /* CTYPE could be null here if we're dealing with a template; 11179: for example, `inline friend float foo()' inside a template 11180: will have no CTYPE set. */ 11181: if (ctype && TREE_CODE (ctype) != RECORD_TYPE) 11182: ctype = NULL_TREE; 11183: else 11184: doing_friend = 1; 11185: } 11186: 11187: raises = TYPE_RAISES_EXCEPTIONS (fntype); 11188: 11189: /* In a fcn definition, arg types must be complete. */ 11190: require_complete_types_for_parms (last_function_parms); 1.1.1.2 ! root 11191: ! 11192: /* In case some arg types were completed since the declaration was ! 11193: parsed, fix up the decls. */ ! 11194: { ! 11195: tree t = last_function_parms; ! 11196: for (; t; t = TREE_CHAIN (t)) ! 11197: layout_decl (t, 0); ! 11198: } 1.1 root 11199: } 11200: else 11201: { 1.1.1.2 ! root 11202: decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises, ! 11203: NULL_TREE); 1.1 root 11204: /* If the declarator is not suitable for a function definition, 11205: cause a syntax error. */ 11206: if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; 11207: 11208: fntype = TREE_TYPE (decl1); 11209: 11210: restype = TREE_TYPE (fntype); 11211: if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype) 11212: && ! CLASSTYPE_GOT_SEMICOLON (restype)) 11213: { 11214: cp_error ("semicolon missing after declaration of `%#T'", restype); 11215: shadow_tag (build_tree_list (NULL_TREE, restype)); 11216: CLASSTYPE_GOT_SEMICOLON (restype) = 1; 11217: if (TREE_CODE (fntype) == FUNCTION_TYPE) 11218: fntype = build_function_type (integer_type_node, 11219: TYPE_ARG_TYPES (fntype)); 11220: else 11221: fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), 11222: integer_type_node, 11223: TYPE_ARG_TYPES (fntype)); 11224: TREE_TYPE (decl1) = fntype; 11225: } 11226: 11227: if (TREE_CODE (fntype) == METHOD_TYPE) 11228: ctype = TYPE_METHOD_BASETYPE (fntype); 11229: else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4 11230: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main") 11231: && DECL_CONTEXT (decl1) == NULL_TREE) 11232: { 11233: /* If this doesn't return integer_type, complain. */ 11234: if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) 11235: { 11236: if (pedantic || warn_return_type) 1.1.1.2 ! root 11237: pedwarn ("return type for `main' changed to integer type"); 1.1 root 11238: TREE_TYPE (decl1) = fntype = default_function_type; 11239: } 11240: warn_about_return_type = 0; 11241: } 11242: } 11243: 11244: /* Warn if function was previously implicitly declared 11245: (but not if we warned then). */ 11246: if (! warn_implicit 11247: && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) 11248: cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); 11249: 11250: current_function_decl = decl1; 11251: 11252: if (flag_cadillac) 11253: cadillac_start_function (decl1); 11254: else 11255: announce_function (decl1); 11256: 11257: if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE) 11258: { 11259: if (IS_AGGR_TYPE (TREE_TYPE (fntype))) 11260: error_with_aggr_type (TREE_TYPE (fntype), 11261: "return-type `%s' is an incomplete type"); 11262: else 11263: error ("return-type is an incomplete type"); 11264: 11265: /* Make it return void instead, but don't change the 11266: type of the DECL_RESULT, in case we have a named return value. */ 11267: if (ctype) 11268: TREE_TYPE (decl1) 11269: = build_cplus_method_type (build_type_variant (ctype, 11270: TREE_READONLY (decl1), 11271: TREE_SIDE_EFFECTS (decl1)), 11272: void_type_node, 11273: FUNCTION_ARG_CHAIN (decl1)); 11274: else 11275: TREE_TYPE (decl1) 11276: = build_function_type (void_type_node, 11277: TYPE_ARG_TYPES (TREE_TYPE (decl1))); 1.1.1.2 ! root 11278: DECL_RESULT (decl1) ! 11279: = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); ! 11280: TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype)); ! 11281: TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype)); 1.1 root 11282: } 11283: 1.1.1.2 ! root 11284: if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) ! 11285: && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) ! 11286: abstract_virtuals_error (decl1, TREE_TYPE (fntype)); ! 11287: 1.1 root 11288: if (warn_about_return_type) 11289: warning ("return-type defaults to `int'"); 11290: 11291: /* Make the init_value nonzero so pushdecl knows this is not tentative. 11292: error_mark_node is replaced below (in poplevel) with the BLOCK. */ 11293: DECL_INITIAL (decl1) = error_mark_node; 11294: 11295: /* Didn't get anything from C. */ 11296: olddecl = NULL_TREE; 11297: 11298: /* This function exists in static storage. 11299: (This does not mean `static' in the C sense!) */ 11300: TREE_STATIC (decl1) = 1; 11301: 11302: /* Record the decl so that the function name is defined. 11303: If we already have a decl for this name, and it is a FUNCTION_DECL, 11304: use the old decl. */ 11305: 11306: if (pre_parsed_p == 0) 11307: { 11308: current_function_decl = decl1 = pushdecl (decl1); 11309: DECL_MAIN_VARIANT (decl1) = decl1; 11310: fntype = TREE_TYPE (decl1); 11311: } 11312: else 11313: current_function_decl = decl1; 11314: 1.1.1.2 ! root 11315: if (DECL_INTERFACE_KNOWN (decl1)) ! 11316: { ! 11317: if (DECL_NOT_REALLY_EXTERN (decl1)) ! 11318: DECL_EXTERNAL (decl1) = 0; ! 11319: } 1.1 root 11320: /* If this function belongs to an interface, it is public. 11321: If it belongs to someone else's interface, it is also external. 11322: It doesn't matter whether it's inline or not. */ 1.1.1.2 ! root 11323: else if (interface_unknown == 0) 1.1 root 11324: { 1.1.1.2 ! root 11325: if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) ! 11326: DECL_EXTERNAL (decl1) ! 11327: = (interface_only ! 11328: || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines)); ! 11329: else ! 11330: DECL_EXTERNAL (decl1) = 0; ! 11331: DECL_NOT_REALLY_EXTERN (decl1) = 0; ! 11332: DECL_INTERFACE_KNOWN (decl1) = 1; 1.1 root 11333: } 11334: else 11335: { 11336: /* This is a definition, not a reference. 1.1.1.2 ! root 11337: So clear DECL_EXTERNAL. */ ! 11338: DECL_EXTERNAL (decl1) = 0; ! 11339: ! 11340: if (DECL_THIS_INLINE (decl1) && ! DECL_INTERFACE_KNOWN (decl1)) ! 11341: DECL_DEFER_OUTPUT (decl1) = 1; ! 11342: else ! 11343: { ! 11344: DECL_INTERFACE_KNOWN (decl1) = 1; ! 11345: if (DECL_C_STATIC (decl1)) ! 11346: TREE_PUBLIC (decl1) = 0; ! 11347: } 1.1 root 11348: } 11349: 11350: if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) 11351: { 11352: if (TREE_CODE (fntype) == METHOD_TYPE) 11353: TREE_TYPE (decl1) = fntype 11354: = build_function_type (TREE_TYPE (fntype), 11355: TREE_CHAIN (TYPE_ARG_TYPES (fntype))); 11356: last_function_parms = TREE_CHAIN (last_function_parms); 11357: DECL_ARGUMENTS (decl1) = last_function_parms; 11358: ctype = NULL_TREE; 11359: } 11360: restype = TREE_TYPE (fntype); 11361: 11362: if (ctype) 11363: { 11364: push_nested_class (ctype, 1); 11365: 11366: /* If we're compiling a friend function, neither of the variables 11367: current_class_decl nor current_class_type will have values. */ 11368: if (! doing_friend) 11369: { 11370: /* We know that this was set up by `grokclassfn'. 11371: We do not wait until `store_parm_decls', since evil 11372: parse errors may never get us to that point. Here 11373: we keep the consistency between `current_class_type' 11374: and `current_class_decl'. */ 1.1.1.2 ! root 11375: tree t = last_function_parms; ! 11376: ! 11377: my_friendly_assert (t != NULL_TREE ! 11378: && TREE_CODE (t) == PARM_DECL, 162); ! 11379: ! 11380: if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) ! 11381: { ! 11382: int i = suspend_momentary (); ! 11383: ! 11384: /* Fool build_indirect_ref. */ ! 11385: current_class_decl = NULL_TREE; ! 11386: C_C_D = build_indirect_ref (t, NULL_PTR); ! 11387: current_class_decl = t; ! 11388: resume_momentary (i); 1.1 root 11389: } 11390: else 1.1.1.2 ! root 11391: /* We're having a signature pointer here. */ ! 11392: C_C_D = current_class_decl = t; ! 11393: 1.1 root 11394: } 11395: } 11396: else 11397: { 11398: if (DECL_STATIC_FUNCTION_P (decl1)) 11399: push_nested_class (DECL_CONTEXT (decl1), 2); 11400: else 11401: push_memoized_context (0, 1); 1.1.1.2 ! root 11402: current_class_decl = C_C_D = NULL_TREE; 1.1 root 11403: } 11404: 1.1.1.2 ! root 11405: pushlevel (0); ! 11406: current_binding_level->parm_flag = 1; ! 11407: ! 11408: /* Save the parm names or decls from this function's declarator ! 11409: where store_parm_decls will find them. */ ! 11410: current_function_parms = last_function_parms; ! 11411: current_function_parm_tags = last_function_parm_tags; ! 11412: ! 11413: GNU_xref_function (decl1, current_function_parms); ! 11414: ! 11415: if (attrs) ! 11416: cplus_decl_attributes (decl1, NULL_TREE, attrs); ! 11417: make_function_rtl (decl1); ! 11418: 1.1 root 11419: /* Allocate further tree nodes temporarily during compilation 11420: of this function only. Tiemann moved up here from bottom of fn. */ 11421: temporary_allocation (); 11422: 11423: /* Promote the value to int before returning it. */ 11424: if (C_PROMOTING_INTEGER_TYPE_P (restype)) 11425: { 11426: /* It retains unsignedness if traditional or if it isn't 11427: really getting wider. */ 11428: if (TREE_UNSIGNED (restype) 11429: && (flag_traditional 11430: || TYPE_PRECISION (restype) 11431: == TYPE_PRECISION (integer_type_node))) 11432: restype = unsigned_type_node; 11433: else 11434: restype = integer_type_node; 11435: } 11436: if (DECL_RESULT (decl1) == NULL_TREE) 1.1.1.2 ! root 11437: { ! 11438: DECL_RESULT (decl1) ! 11439: = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype)); ! 11440: TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype); ! 11441: TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype); ! 11442: } 1.1 root 11443: 1.1.1.2 ! root 11444: if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)) ! 11445: && DECL_LANGUAGE (decl1) == lang_cplusplus) 1.1 root 11446: { 11447: dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 11448: ctor_label = NULL_TREE; 11449: } 11450: else 11451: { 11452: dtor_label = NULL_TREE; 11453: if (DECL_CONSTRUCTOR_P (decl1)) 11454: ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 11455: } 11456: 11457: /* If this fcn was already referenced via a block-scope `extern' decl 11458: (or an implicit decl), propagate certain information about the usage. */ 11459: if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) 11460: TREE_ADDRESSABLE (decl1) = 1; 11461: 11462: return 1; 11463: } 11464: 1.1.1.2 ! root 11465: void ! 11466: expand_start_early_try_stmts () ! 11467: { ! 11468: rtx insns; ! 11469: start_sequence (); ! 11470: expand_start_try_stmts (); ! 11471: insns = get_insns (); ! 11472: end_sequence (); ! 11473: store_in_parms (insns); ! 11474: } ! 11475: ! 11476: void ! 11477: store_in_parms (insns) ! 11478: rtx insns; ! 11479: { ! 11480: rtx last_parm_insn; ! 11481: ! 11482: last_parm_insn = get_first_nonparm_insn (); ! 11483: if (last_parm_insn == NULL_RTX) ! 11484: emit_insns (insns); ! 11485: else ! 11486: emit_insns_before (insns, previous_insn (last_parm_insn)); ! 11487: } ! 11488: 1.1 root 11489: /* Store the parameter declarations into the current function declaration. 11490: This is called after parsing the parameter declarations, before 11491: digesting the body of the function. 11492: 11493: Also install to binding contour return value identifier, if any. */ 11494: 11495: void 11496: store_parm_decls () 11497: { 11498: register tree fndecl = current_function_decl; 11499: register tree parm; 11500: int parms_have_cleanups = 0; 11501: 11502: /* This is either a chain of PARM_DECLs (when a prototype is used). */ 11503: tree specparms = current_function_parms; 11504: 11505: /* This is a list of types declared among parms in a prototype. */ 11506: tree parmtags = current_function_parm_tags; 11507: 11508: /* This is a chain of any other decls that came in among the parm 11509: declarations. If a parm is declared with enum {foo, bar} x; 11510: then CONST_DECLs for foo and bar are put here. */ 11511: tree nonparms = NULL_TREE; 11512: 1.1.1.2 ! root 11513: if (toplevel_bindings_p ()) 1.1 root 11514: fatal ("parse errors have confused me too much"); 11515: 11516: /* Initialize RTL machinery. */ 11517: init_function_start (fndecl, input_filename, lineno); 11518: 11519: /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ 11520: declare_function_name (); 11521: 11522: /* Create a binding level for the parms. */ 11523: expand_start_bindings (0); 11524: 11525: if (specparms != NULL_TREE) 11526: { 11527: /* This case is when the function was defined with an ANSI prototype. 11528: The parms already have decls, so we need not do anything here 11529: except record them as in effect 11530: and complain if any redundant old-style parm decls were written. */ 11531: 11532: register tree next; 11533: 11534: /* Must clear this because it might contain TYPE_DECLs declared 11535: at class level. */ 11536: storedecls (NULL_TREE); 11537: for (parm = nreverse (specparms); parm; parm = next) 11538: { 11539: next = TREE_CHAIN (parm); 11540: if (TREE_CODE (parm) == PARM_DECL) 11541: { 11542: tree cleanup = maybe_build_cleanup (parm); 11543: if (DECL_NAME (parm) == NULL_TREE) 11544: { 11545: #if 0 11546: cp_error_at ("parameter name omitted", parm); 11547: #else 11548: /* for C++, this is not an error. */ 11549: pushdecl (parm); 11550: #endif 11551: } 11552: else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) 11553: cp_error ("parameter `%D' declared void", parm); 11554: else 11555: { 11556: /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. 11557: A parameter is assumed not to have any side effects. 11558: If this should change for any reason, then this 11559: will have to wrap the bashed reference type in a save_expr. 11560: 11561: Also, if the parameter type is declared to be an X 11562: and there is an X(X&) constructor, we cannot lay it 11563: into the stack (any more), so we make this parameter 11564: look like it is really of reference type. Functions 11565: which pass parameters to this function will know to 11566: create a temporary in their frame, and pass a reference 11567: to that. */ 11568: 11569: if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE 11570: && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) 11571: SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); 11572: 11573: pushdecl (parm); 11574: } 11575: if (cleanup) 11576: { 11577: expand_decl (parm); 1.1.1.2 ! root 11578: if (! cp_expand_decl_cleanup (parm, cleanup)) 1.1 root 11579: cp_error ("parser lost in parsing declaration of `%D'", 11580: parm); 11581: parms_have_cleanups = 1; 11582: } 11583: } 11584: else 11585: { 11586: /* If we find an enum constant or a type tag, 11587: put it aside for the moment. */ 11588: TREE_CHAIN (parm) = NULL_TREE; 11589: nonparms = chainon (nonparms, parm); 11590: } 11591: } 11592: 11593: /* Get the decls in their original chain order 11594: and record in the function. This is all and only the 11595: PARM_DECLs that were pushed into scope by the loop above. */ 11596: DECL_ARGUMENTS (fndecl) = getdecls (); 11597: 11598: storetags (chainon (parmtags, gettags ())); 11599: } 11600: else 11601: DECL_ARGUMENTS (fndecl) = NULL_TREE; 11602: 11603: /* Now store the final chain of decls for the arguments 11604: as the decl-chain of the current lexical scope. 11605: Put the enumerators in as well, at the front so that 11606: DECL_ARGUMENTS is not modified. */ 11607: 11608: storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); 11609: 11610: /* Initialize the RTL code for the function. */ 11611: DECL_SAVED_INSNS (fndecl) = NULL_RTX; 11612: expand_function_start (fndecl, parms_have_cleanups); 11613: 11614: /* Create a binding contour which can be used to catch 11615: cleanup-generated temporaries. Also, if the return value needs or 11616: has initialization, deal with that now. */ 11617: if (parms_have_cleanups) 11618: { 11619: pushlevel (0); 11620: expand_start_bindings (0); 11621: } 11622: 11623: current_function_parms_stored = 1; 11624: 11625: if (flag_gc) 11626: { 11627: maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node); 1.1.1.2 ! root 11628: if (! cp_expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup)) 1.1 root 11629: cp_error ("parser lost in parsing declaration of `%D'", fndecl); 11630: } 11631: 11632: /* If this function is `main', emit a call to `__main' 11633: to run global initializers, etc. */ 11634: if (DECL_NAME (fndecl) 11635: && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 11636: && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 11637: && DECL_CONTEXT (fndecl) == NULL_TREE) 11638: { 11639: expand_main_function (); 11640: 11641: if (flag_gc) 11642: expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE), 11643: 0, VOIDmode, 0); 1.1.1.2 ! root 11644: #if 0 ! 11645: /* done at a different time */ ! 11646: if (flag_rtti) 1.1 root 11647: output_builtin_tdesc_entries (); 1.1.1.2 ! root 11648: #endif ! 11649: } ! 11650: ! 11651: /* Take care of exception handling things. */ ! 11652: if (flag_handle_exceptions) ! 11653: { ! 11654: rtx insns; ! 11655: start_sequence (); ! 11656: ! 11657: /* Mark the start of a stack unwinder if we need one. */ ! 11658: start_eh_unwinder (); ! 11659: ! 11660: /* Do the starting of the exception specifications, if we have any. */ ! 11661: if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) ! 11662: expand_start_eh_spec (); ! 11663: ! 11664: insns = get_insns (); ! 11665: end_sequence (); ! 11666: ! 11667: if (insns) ! 11668: store_in_parms (insns); 1.1 root 11669: } 11670: } 11671: 11672: /* Bind a name and initialization to the return value of 11673: the current function. */ 11674: void 11675: store_return_init (return_id, init) 11676: tree return_id, init; 11677: { 11678: tree decl = DECL_RESULT (current_function_decl); 11679: 1.1.1.2 ! root 11680: if (pedantic) 1.1 root 11681: /* Give this error as many times as there are occurrences, 11682: so that users can use Emacs compilation buffers to find 11683: and fix all such places. */ 11684: pedwarn ("ANSI C++ does not permit named return values"); 11685: 11686: if (return_id != NULL_TREE) 11687: { 11688: if (DECL_NAME (decl) == NULL_TREE) 11689: { 11690: DECL_NAME (decl) = return_id; 11691: DECL_ASSEMBLER_NAME (decl) = return_id; 11692: } 11693: else 11694: error ("return identifier `%s' already in place", 11695: IDENTIFIER_POINTER (DECL_NAME (decl))); 11696: } 11697: 11698: /* Can't let this happen for constructors. */ 11699: if (DECL_CONSTRUCTOR_P (current_function_decl)) 11700: { 11701: error ("can't redefine default return value for constructors"); 11702: return; 11703: } 11704: 11705: /* If we have a named return value, put that in our scope as well. */ 11706: if (DECL_NAME (decl) != NULL_TREE) 11707: { 11708: /* If this named return value comes in a register, 11709: put it in a pseudo-register. */ 11710: if (DECL_REGISTER (decl)) 11711: { 11712: original_result_rtx = DECL_RTL (decl); 11713: DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); 11714: } 11715: 1.1.1.2 ! root 11716: /* Let `cp_finish_decl' know that this initializer is ok. */ 1.1 root 11717: DECL_INITIAL (decl) = init; 11718: pushdecl (decl); 1.1.1.2 ! root 11719: cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); 1.1 root 11720: } 11721: } 11722: 11723: 11724: /* Finish up a function declaration and compile that function 11725: all the way to assembler language output. The free the storage 11726: for the function definition. 11727: 11728: This is called after parsing the body of the function definition. 11729: LINENO is the current line number. 11730: 11731: C++: CALL_POPLEVEL is non-zero if an extra call to poplevel 11732: (and expand_end_bindings) must be made to take care of the binding 11733: contour for the base initializers. This is only relevant for 11734: constructors. */ 11735: 11736: void 1.1.1.2 ! root 11737: finish_function (lineno, call_poplevel, nested) 1.1 root 11738: int lineno; 11739: int call_poplevel; 1.1.1.2 ! root 11740: int nested; 1.1 root 11741: { 11742: register tree fndecl = current_function_decl; 11743: tree fntype, ctype = NULL_TREE; 1.1.1.2 ! root 11744: rtx last_parm_insn, insns; 1.1 root 11745: /* Label to use if this function is supposed to return a value. */ 11746: tree no_return_label = NULL_TREE; 11747: tree decls = NULL_TREE; 11748: 11749: /* When we get some parse errors, we can end up without a 11750: current_function_decl, so cope. */ 11751: if (fndecl == NULL_TREE) 11752: return; 11753: 11754: fntype = TREE_TYPE (fndecl); 11755: 11756: /* TREE_READONLY (fndecl) = 1; 11757: This caused &foo to be of type ptr-to-const-function 11758: which then got a warning when stored in a ptr-to-function variable. */ 11759: 11760: /* This happens on strange parse errors. */ 11761: if (! current_function_parms_stored) 11762: { 11763: call_poplevel = 0; 11764: store_parm_decls (); 11765: } 11766: 11767: if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) 11768: { 11769: tree ttype = target_type (fntype); 11770: tree parmdecl; 11771: 11772: if (IS_AGGR_TYPE (ttype)) 11773: /* Let debugger know it should output info for this type. */ 11774: note_debug_info_needed (ttype); 11775: 11776: for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) 11777: { 11778: ttype = target_type (TREE_TYPE (parmdecl)); 11779: if (IS_AGGR_TYPE (ttype)) 11780: /* Let debugger know it should output info for this type. */ 11781: note_debug_info_needed (ttype); 11782: } 11783: } 11784: 11785: /* Clean house because we will need to reorder insns here. */ 11786: do_pending_stack_adjust (); 11787: 11788: if (dtor_label) 11789: { 11790: tree binfo = TYPE_BINFO (current_class_type); 11791: tree cond = integer_one_node; 11792: tree exprstmt, vfields; 11793: tree in_charge_node = lookup_name (in_charge_identifier, 0); 11794: tree virtual_size; 11795: int ok_to_optimize_dtor = 0; 11796: 11797: if (current_function_assigns_this) 1.1.1.2 ! root 11798: cond = build (NE_EXPR, boolean_type_node, 1.1 root 11799: current_class_decl, integer_zero_node); 11800: else 11801: { 11802: int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); 11803: 11804: /* If this destructor is empty, then we don't need to check 11805: whether `this' is NULL in some cases. */ 11806: if ((flag_this_is_variable & 1) == 0) 11807: ok_to_optimize_dtor = 1; 1.1.1.2 ! root 11808: else if (get_last_insn () == get_first_nonparm_insn ()) 1.1 root 11809: ok_to_optimize_dtor 11810: = (n_baseclasses == 0 11811: || (n_baseclasses == 1 11812: && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); 11813: } 11814: 11815: /* These initializations might go inline. Protect 11816: the binding level of the parms. */ 11817: pushlevel (0); 11818: expand_start_bindings (0); 11819: 11820: if (current_function_assigns_this) 11821: { 11822: current_function_assigns_this = 0; 11823: current_function_just_assigned_this = 0; 11824: } 11825: 11826: /* Generate the code to call destructor on base class. 11827: If this destructor belongs to a class with virtual 11828: functions, then set the virtual function table 11829: pointer to represent the type of our base class. */ 11830: 11831: /* This side-effect makes call to `build_delete' generate the 11832: code we have to have at the end of this destructor. */ 11833: TYPE_HAS_DESTRUCTOR (current_class_type) = 0; 11834: 11835: /* These are two cases where we cannot delegate deletion. */ 11836: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) 11837: || TYPE_GETS_REG_DELETE (current_class_type)) 11838: exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node, 11839: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); 11840: else 11841: exprstmt = build_delete (current_class_type, C_C_D, in_charge_node, 11842: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); 11843: 11844: /* If we did not assign to this, then `this' is non-zero at 11845: the end of a destructor. As a special optimization, don't 11846: emit test if this is an empty destructor. If it does nothing, 11847: it does nothing. If it calls a base destructor, the base 11848: destructor will perform the test. */ 11849: 11850: if (exprstmt != error_mark_node 11851: && (TREE_CODE (exprstmt) != NOP_EXPR 11852: || TREE_OPERAND (exprstmt, 0) != integer_zero_node 11853: || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) 11854: { 11855: expand_label (dtor_label); 11856: if (cond != integer_one_node) 11857: expand_start_cond (cond, 0); 11858: if (exprstmt != void_zero_node) 11859: /* Don't call `expand_expr_stmt' if we're not going to do 11860: anything, since -Wall will give a diagnostic. */ 11861: expand_expr_stmt (exprstmt); 11862: 11863: /* Run destructor on all virtual baseclasses. */ 11864: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 11865: { 11866: tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); 11867: expand_start_cond (build (BIT_AND_EXPR, integer_type_node, 11868: in_charge_node, integer_two_node), 0); 11869: while (vbases) 11870: { 11871: if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) 11872: { 1.1.1.2 ! root 11873: tree ptr = convert_pointer_to_vbase (BINFO_TYPE (vbases), current_class_decl); ! 11874: expand_expr_stmt (build_delete (build_pointer_type (BINFO_TYPE (vbases)), 1.1 root 11875: ptr, integer_zero_node, 11876: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0)); 11877: } 11878: vbases = TREE_CHAIN (vbases); 11879: } 11880: expand_end_cond (); 11881: } 11882: 11883: do_pending_stack_adjust (); 11884: if (cond != integer_one_node) 11885: expand_end_cond (); 11886: } 11887: 11888: TYPE_HAS_DESTRUCTOR (current_class_type) = 1; 11889: 11890: virtual_size = c_sizeof (current_class_type); 11891: 11892: /* At the end, call delete if that's what's requested. */ 11893: if (TYPE_GETS_REG_DELETE (current_class_type)) 11894: /* This NOP_EXPR means we are in a static call context. */ 11895: exprstmt = 11896: build_method_call 11897: (build_indirect_ref 1.1.1.2 ! root 11898: (build1 (NOP_EXPR, build_pointer_type (current_class_type), 1.1 root 11899: error_mark_node), 11900: NULL_PTR), 11901: ansi_opname[(int) DELETE_EXPR], 11902: tree_cons (NULL_TREE, current_class_decl, 11903: build_tree_list (NULL_TREE, virtual_size)), 11904: NULL_TREE, LOOKUP_NORMAL); 11905: else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 11906: exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0, 11907: virtual_size); 11908: else 11909: exprstmt = NULL_TREE; 11910: 11911: if (exprstmt) 11912: { 11913: cond = build (BIT_AND_EXPR, integer_type_node, 11914: in_charge_node, integer_one_node); 11915: expand_start_cond (cond, 0); 11916: expand_expr_stmt (exprstmt); 11917: expand_end_cond (); 11918: } 11919: 11920: /* End of destructor. */ 11921: expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0); 11922: poplevel (2, 0, 0); /* XXX change to 1 */ 11923: 11924: /* Back to the top of destructor. */ 11925: /* Dont execute destructor code if `this' is NULL. */ 1.1.1.2 ! root 11926: ! 11927: start_sequence (); 1.1 root 11928: 11929: /* Make all virtual function table pointers in non-virtual base 11930: classes point to CURRENT_CLASS_TYPE's virtual function 11931: tables. */ 11932: expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl); 11933: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 11934: expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0); 11935: if (! ok_to_optimize_dtor) 11936: { 11937: cond = build_binary_op (NE_EXPR, 11938: current_class_decl, integer_zero_node, 1); 11939: expand_start_cond (cond, 0); 11940: } 1.1.1.2 ! root 11941: ! 11942: insns = get_insns (); ! 11943: end_sequence (); ! 11944: ! 11945: last_parm_insn = get_first_nonparm_insn (); ! 11946: if (last_parm_insn == NULL_RTX) ! 11947: last_parm_insn = get_last_insn (); ! 11948: else ! 11949: last_parm_insn = previous_insn (last_parm_insn); ! 11950: ! 11951: emit_insns_after (insns, last_parm_insn); ! 11952: 1.1 root 11953: if (! ok_to_optimize_dtor) 11954: expand_end_cond (); 11955: } 11956: else if (current_function_assigns_this) 11957: { 11958: /* Does not need to call emit_base_init, because 11959: that is done (if needed) just after assignment to this 11960: is seen. */ 11961: 11962: if (DECL_CONSTRUCTOR_P (current_function_decl)) 11963: { 1.1.1.2 ! root 11964: end_protect_partials (); 1.1 root 11965: expand_label (ctor_label); 11966: ctor_label = NULL_TREE; 11967: 11968: if (call_poplevel) 11969: { 11970: decls = getdecls (); 11971: expand_end_bindings (decls, decls != NULL_TREE, 0); 11972: poplevel (decls != NULL_TREE, 0, 0); 11973: } 11974: c_expand_return (current_class_decl); 11975: } 11976: else if (TYPE_MAIN_VARIANT (TREE_TYPE ( 11977: DECL_RESULT (current_function_decl))) != void_type_node 11978: && return_label != NULL_RTX) 11979: no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 11980: 11981: current_function_assigns_this = 0; 11982: current_function_just_assigned_this = 0; 1.1.1.2 ! root 11983: base_init_expr = NULL_TREE; 1.1 root 11984: } 11985: else if (DECL_CONSTRUCTOR_P (fndecl)) 11986: { 11987: tree allocated_this; 11988: tree cond, thenclause; 11989: /* Allow constructor for a type to get a new instance of the object 11990: using `build_new'. */ 11991: tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); 11992: CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; 11993: 11994: DECL_RETURNS_FIRST_ARG (fndecl) = 1; 11995: 11996: if (flag_this_is_variable > 0) 11997: { 11998: cond = build_binary_op (EQ_EXPR, 11999: current_class_decl, integer_zero_node, 1); 12000: thenclause = build_modify_expr (current_class_decl, NOP_EXPR, 12001: build_new (NULL_TREE, current_class_type, void_type_node, 0)); 12002: } 12003: 12004: CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; 12005: 1.1.1.2 ! root 12006: start_sequence (); 1.1 root 12007: 12008: if (flag_this_is_variable > 0) 12009: { 12010: expand_start_cond (cond, 0); 12011: expand_expr_stmt (thenclause); 12012: expand_end_cond (); 12013: } 12014: 12015: #if 0 12016: if (DECL_NAME (fndecl) == NULL_TREE 12017: && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE) 12018: build_default_constructor (fndecl); 12019: #endif 12020: 12021: /* Emit insns from `emit_base_init' which sets up virtual 12022: function table pointer(s). */ 1.1.1.2 ! root 12023: if (base_init_expr) ! 12024: { ! 12025: expand_expr_stmt (base_init_expr); ! 12026: base_init_expr = NULL_TREE; ! 12027: } ! 12028: ! 12029: insns = get_insns (); ! 12030: end_sequence (); 1.1 root 12031: 12032: /* This is where the body of the constructor begins. 12033: If there were no insns in this function body, then the 12034: last_parm_insn is also the last insn. 12035: 12036: If optimization is enabled, last_parm_insn may move, so 12037: we don't hold on to it (across emit_base_init). */ 12038: last_parm_insn = get_first_nonparm_insn (); 12039: if (last_parm_insn == NULL_RTX) 1.1.1.2 ! root 12040: last_parm_insn = get_last_insn (); 1.1 root 12041: else 12042: last_parm_insn = previous_insn (last_parm_insn); 12043: 1.1.1.2 ! root 12044: emit_insns_after (insns, last_parm_insn); ! 12045: ! 12046: end_protect_partials (); 1.1 root 12047: 12048: /* This is where the body of the constructor ends. */ 12049: expand_label (ctor_label); 12050: ctor_label = NULL_TREE; 12051: 12052: if (call_poplevel) 12053: { 1.1.1.2 ! root 12054: decls = getdecls (); ! 12055: expand_end_bindings (decls, decls != NULL_TREE, 0); 1.1 root 12056: poplevel (decls != NULL_TREE, 1, 0); 12057: } 12058: 12059: c_expand_return (current_class_decl); 12060: 12061: current_function_assigns_this = 0; 12062: current_function_just_assigned_this = 0; 12063: } 12064: else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 12065: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") 12066: && DECL_CONTEXT (fndecl) == NULL_TREE) 12067: { 12068: /* Make it so that `main' always returns 0 by default. */ 12069: #ifdef VMS 12070: c_expand_return (integer_one_node); 12071: #else 12072: c_expand_return (integer_zero_node); 12073: #endif 12074: } 12075: else if (return_label != NULL_RTX 12076: && current_function_return_value == NULL_TREE 12077: && ! DECL_NAME (DECL_RESULT (current_function_decl))) 12078: no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 12079: 12080: if (flag_gc) 12081: expand_gc_prologue_and_epilogue (); 12082: 12083: /* If this function is supposed to return a value, ensure that 12084: we do not fall into the cleanups by mistake. The end of our 12085: function will look like this: 12086: 12087: user code (may have return stmt somewhere) 12088: goto no_return_label 12089: cleanup_label: 12090: cleanups 12091: goto return_label 12092: no_return_label: 12093: NOTE_INSN_FUNCTION_END 12094: return_label: 12095: things for return 12096: 12097: If the user omits a return stmt in the USER CODE section, we 12098: will have a control path which reaches NOTE_INSN_FUNCTION_END. 12099: Otherwise, we won't. */ 12100: if (no_return_label) 12101: { 12102: DECL_CONTEXT (no_return_label) = fndecl; 12103: DECL_INITIAL (no_return_label) = error_mark_node; 12104: DECL_SOURCE_FILE (no_return_label) = input_filename; 12105: DECL_SOURCE_LINE (no_return_label) = lineno; 12106: expand_goto (no_return_label); 12107: } 12108: 12109: if (cleanup_label) 12110: { 12111: /* remove the binding contour which is used 12112: to catch cleanup-generated temporaries. */ 12113: expand_end_bindings (0, 0, 0); 12114: poplevel (0, 0, 0); 12115: } 12116: 12117: if (cleanup_label) 12118: /* Emit label at beginning of cleanup code for parameters. */ 12119: emit_label (cleanup_label); 12120: 12121: /* Get return value into register if that's where it's supposed to be. */ 12122: if (original_result_rtx) 12123: fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); 12124: 12125: /* Finish building code that will trigger warnings if users forget 12126: to make their functions return values. */ 12127: if (no_return_label || cleanup_label) 12128: emit_jump (return_label); 12129: if (no_return_label) 12130: { 12131: /* We don't need to call `expand_*_return' here because we 12132: don't need any cleanups here--this path of code is only 12133: for error checking purposes. */ 12134: expand_label (no_return_label); 12135: } 12136: 1.1.1.2 ! root 12137: /* Generate rtl for function exit. */ ! 12138: expand_function_end (input_filename, lineno, 1); ! 12139: ! 12140: if (flag_handle_exceptions) ! 12141: expand_exception_blocks (); ! 12142: ! 12143: /* This must come after expand_function_end because cleanups might ! 12144: have declarations (from inline functions) that need to go into ! 12145: this function's blocks. */ ! 12146: if (current_binding_level->parm_flag != 1) ! 12147: my_friendly_abort (122); ! 12148: poplevel (1, 0, 1); ! 12149: 1.1 root 12150: /* reset scope for C++: if we were in the scope of a class, 12151: then when we finish this function, we are not longer so. 12152: This cannot be done until we know for sure that no more 12153: class members will ever be referenced in this function 12154: (i.e., calls to destructors). */ 12155: if (current_class_name) 12156: { 12157: ctype = current_class_type; 12158: pop_nested_class (1); 12159: } 12160: else 12161: pop_memoized_context (1); 12162: 12163: /* Must mark the RESULT_DECL as being in this function. */ 12164: DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl); 12165: 12166: /* Obey `register' declarations if `setjmp' is called in this fn. */ 12167: if (flag_traditional && current_function_calls_setjmp) 12168: setjmp_protect (DECL_INITIAL (fndecl)); 12169: 12170: /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point 12171: to the FUNCTION_DECL node itself. */ 12172: BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; 12173: 12174: /* So we can tell if jump_optimize sets it to 1. */ 12175: can_reach_end = 0; 12176: 1.1.1.2 ! root 12177: /* Run the optimizers and output the assembler code for this function. */ ! 12178: rest_of_compilation (fndecl); 1.1 root 12179: 1.1.1.2 ! root 12180: if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) 1.1 root 12181: { 1.1.1.2 ! root 12182: /* Set DECL_EXTERNAL so that assemble_external will be called as ! 12183: necessary. We'll clear it again in finish_file. */ ! 12184: if (! DECL_EXTERNAL (fndecl)) ! 12185: DECL_NOT_REALLY_EXTERN (fndecl) = 1; ! 12186: DECL_EXTERNAL (fndecl) = 1; 1.1 root 12187: mark_inline_for_output (fndecl); 12188: } 12189: 12190: if (ctype && TREE_ASM_WRITTEN (fndecl)) 12191: note_debug_info_needed (ctype); 12192: 12193: current_function_returns_null |= can_reach_end; 12194: 12195: /* Since we don't normally go through c_expand_return for constructors, 12196: this normally gets the wrong value. 12197: Also, named return values have their return codes emitted after 12198: NOTE_INSN_FUNCTION_END, confusing jump.c. */ 12199: if (DECL_CONSTRUCTOR_P (fndecl) 12200: || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) 12201: current_function_returns_null = 0; 12202: 12203: if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) 12204: cp_warning ("`noreturn' function `%D' does return", fndecl); 12205: else if ((warn_return_type || pedantic) 12206: && current_function_returns_null 12207: && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node) 12208: { 12209: /* If this function returns non-void and control can drop through, 12210: complain. */ 12211: cp_pedwarn ("control reaches end of non-void function `%D'", fndecl); 12212: } 12213: /* With just -W, complain only if function returns both with 12214: and without a value. */ 12215: else if (extra_warnings 12216: && current_function_returns_value && current_function_returns_null) 12217: warning ("this function may return with or without a value"); 12218: 12219: /* Free all the tree nodes making up this function. */ 12220: /* Switch back to allocating nodes permanently 12221: until we start another function. */ 1.1.1.2 ! root 12222: if (! nested) ! 12223: permanent_allocation (1); 1.1 root 12224: 12225: if (flag_cadillac) 12226: cadillac_finish_function (fndecl); 12227: 12228: if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) 12229: { 12230: /* Stop pointing to the local nodes about to be freed. */ 12231: /* But DECL_INITIAL must remain nonzero so we know this 12232: was an actual function definition. */ 12233: DECL_INITIAL (fndecl) = error_mark_node; 12234: if (! DECL_CONSTRUCTOR_P (fndecl) 12235: || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype))) 12236: DECL_ARGUMENTS (fndecl) = NULL_TREE; 12237: } 12238: 1.1.1.2 ! root 12239: if (DECL_STATIC_CONSTRUCTOR (fndecl)) ! 12240: static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); ! 12241: if (DECL_STATIC_DESTRUCTOR (fndecl)) ! 12242: static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); ! 12243: ! 12244: if (! nested) ! 12245: { ! 12246: /* Let the error reporting routines know that we're outside a ! 12247: function. For a nested function, this value is used in ! 12248: pop_cp_function_context and then reset via pop_function_context. */ ! 12249: current_function_decl = NULL_TREE; ! 12250: } ! 12251: 1.1 root 12252: named_label_uses = NULL_TREE; 1.1.1.2 ! root 12253: current_class_decl = NULL_TREE; 1.1 root 12254: } 12255: 12256: /* Create the FUNCTION_DECL for a function definition. 12257: LINE1 is the line number that the definition absolutely begins on. 12258: LINE2 is the line number that the name of the function appears on. 12259: DECLSPECS and DECLARATOR are the parts of the declaration; 12260: they describe the return type and the name of the function, 12261: but twisted together in a fashion that parallels the syntax of C. 12262: 12263: This function creates a binding context for the function body 12264: as well as setting up the FUNCTION_DECL in current_function_decl. 12265: 12266: Returns a FUNCTION_DECL on success. 12267: 12268: If the DECLARATOR is not suitable for a function (it defines a datum 12269: instead), we return 0, which tells yyparse to report a parse error. 12270: 12271: May return void_type_node indicating that this method is actually 12272: a friend. See grokfield for more details. 12273: 12274: Came here with a `.pushlevel' . 12275: 12276: DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING 12277: CHANGES TO CODE IN `grokfield'. */ 12278: tree 12279: start_method (declspecs, declarator, raises) 12280: tree declarator, declspecs, raises; 12281: { 1.1.1.2 ! root 12282: tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises, ! 12283: NULL_TREE); 1.1 root 12284: 12285: /* Something too ugly to handle. */ 12286: if (fndecl == NULL_TREE) 12287: return NULL_TREE; 12288: 12289: /* Pass friends other than inline friend functions back. */ 12290: if (TYPE_MAIN_VARIANT (fndecl) == void_type_node) 12291: return fndecl; 12292: 12293: if (TREE_CODE (fndecl) != FUNCTION_DECL) 12294: /* Not a function, tell parser to report parse error. */ 12295: return NULL_TREE; 12296: 12297: if (IS_SIGNATURE (current_class_type)) 12298: { 12299: IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; 12300: /* In case we need this info later. */ 12301: HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1; 12302: } 12303: 12304: if (DECL_IN_AGGR_P (fndecl)) 12305: { 12306: if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) 12307: { 12308: if (DECL_CONTEXT (fndecl)) 12309: cp_error ("`%D' is already defined in class %s", fndecl, 12310: TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); 12311: } 12312: return void_type_node; 12313: } 12314: 1.1.1.2 ! root 12315: DECL_THIS_INLINE (fndecl) = 1; ! 12316: 1.1 root 12317: if (flag_default_inline) 12318: DECL_INLINE (fndecl) = 1; 12319: 12320: if (processing_template_defn) 1.1.1.2 ! root 12321: { ! 12322: SET_DECL_IMPLICIT_INSTANTIATION (fndecl); ! 12323: repo_template_used (fndecl); ! 12324: } 1.1 root 12325: 12326: /* We read in the parameters on the maybepermanent_obstack, 12327: but we won't be getting back to them until after we 12328: may have clobbered them. So the call to preserve_data 12329: will keep them safe. */ 12330: preserve_data (); 12331: 12332: if (! DECL_FRIEND_P (fndecl)) 12333: { 12334: if (DECL_CHAIN (fndecl) != NULL_TREE) 12335: { 12336: /* Need a fresh node here so that we don't get circularity 12337: when we link these together. If FNDECL was a friend, then 12338: `pushdecl' does the right thing, which is nothing wrt its 12339: current value of DECL_CHAIN. */ 12340: fndecl = copy_node (fndecl); 12341: } 12342: if (TREE_CHAIN (fndecl)) 12343: { 12344: fndecl = copy_node (fndecl); 12345: TREE_CHAIN (fndecl) = NULL_TREE; 12346: } 12347: 12348: if (DECL_CONSTRUCTOR_P (fndecl)) 12349: { 12350: if (! grok_ctor_properties (current_class_type, fndecl)) 12351: return void_type_node; 12352: } 12353: else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) 12354: grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0); 12355: } 12356: 1.1.1.2 ! root 12357: cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0); 1.1 root 12358: 12359: /* Make a place for the parms */ 12360: pushlevel (0); 12361: current_binding_level->parm_flag = 1; 12362: 12363: DECL_IN_AGGR_P (fndecl) = 1; 12364: return fndecl; 12365: } 12366: 12367: /* Go through the motions of finishing a function definition. 12368: We don't compile this method until after the whole class has 12369: been processed. 12370: 12371: FINISH_METHOD must return something that looks as though it 12372: came from GROKFIELD (since we are defining a method, after all). 12373: 12374: This is called after parsing the body of the function definition. 12375: STMTS is the chain of statements that makes up the function body. 12376: 12377: DECL is the ..._DECL that `start_method' provided. */ 12378: 12379: tree 12380: finish_method (decl) 12381: tree decl; 12382: { 12383: register tree fndecl = decl; 12384: tree old_initial; 12385: 12386: register tree link; 12387: 12388: if (TYPE_MAIN_VARIANT (decl) == void_type_node) 12389: return decl; 12390: 12391: old_initial = DECL_INITIAL (fndecl); 12392: 12393: /* Undo the level for the parms (from start_method). 12394: This is like poplevel, but it causes nothing to be 12395: saved. Saving information here confuses symbol-table 12396: output routines. Besides, this information will 12397: be correctly output when this method is actually 12398: compiled. */ 12399: 12400: /* Clear out the meanings of the local variables of this level; 12401: also record in each decl which block it belongs to. */ 12402: 12403: for (link = current_binding_level->names; link; link = TREE_CHAIN (link)) 12404: { 12405: if (DECL_NAME (link) != NULL_TREE) 12406: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; 12407: my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163); 12408: DECL_CONTEXT (link) = NULL_TREE; 12409: } 12410: 12411: /* Restore all name-meanings of the outer levels 12412: that were shadowed by this level. */ 12413: 12414: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) 12415: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 12416: for (link = current_binding_level->class_shadowed; 12417: link; link = TREE_CHAIN (link)) 12418: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 12419: for (link = current_binding_level->type_shadowed; 12420: link; link = TREE_CHAIN (link)) 12421: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 12422: 12423: GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, 12424: (HOST_WIDE_INT) current_binding_level->level_chain, 12425: current_binding_level->parm_flag, 12426: current_binding_level->keep, 12427: current_binding_level->tag_transparent); 12428: 12429: poplevel (0, 0, 0); 12430: 12431: DECL_INITIAL (fndecl) = old_initial; 12432: 12433: /* We used to check if the context of FNDECL was different from 12434: current_class_type as another way to get inside here. This didn't work 12435: for String.cc in libg++. */ 12436: if (DECL_FRIEND_P (fndecl)) 12437: { 12438: CLASSTYPE_INLINE_FRIENDS (current_class_type) 12439: = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type)); 12440: decl = void_type_node; 12441: } 12442: 12443: return decl; 12444: } 12445: 12446: /* Called when a new struct TYPE is defined. 12447: If this structure or union completes the type of any previous 12448: variable declaration, lay it out and output its rtl. */ 12449: 12450: void 12451: hack_incomplete_structures (type) 12452: tree type; 12453: { 1.1.1.2 ! root 12454: tree *list; 1.1 root 12455: 1.1.1.2 ! root 12456: if (current_binding_level->incomplete == NULL_TREE) 1.1 root 12457: return; 12458: 12459: if (!type) /* Don't do this for class templates. */ 12460: return; 12461: 1.1.1.2 ! root 12462: for (list = ¤t_binding_level->incomplete; *list; ) ! 12463: { ! 12464: tree decl = TREE_VALUE (*list); ! 12465: if (decl && TREE_TYPE (decl) == type ! 12466: || (TREE_TYPE (decl) ! 12467: && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE ! 12468: && TREE_TYPE (TREE_TYPE (decl)) == type)) ! 12469: { ! 12470: int toplevel = toplevel_bindings_p (); ! 12471: if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE ! 12472: && TREE_TYPE (TREE_TYPE (decl)) == type) ! 12473: layout_type (TREE_TYPE (decl)); ! 12474: layout_decl (decl, 0); ! 12475: rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); ! 12476: if (! toplevel) ! 12477: { ! 12478: tree cleanup; ! 12479: expand_decl (decl); ! 12480: cleanup = maybe_build_cleanup (decl); ! 12481: expand_decl_init (decl); ! 12482: if (! cp_expand_decl_cleanup (decl, cleanup)) ! 12483: cp_error ("parser lost in parsing declaration of `%D'", ! 12484: decl); ! 12485: } ! 12486: *list = TREE_CHAIN (*list); ! 12487: } ! 12488: else ! 12489: list = &TREE_CHAIN (*list); ! 12490: } 1.1 root 12491: } 12492: 12493: /* Nonzero if presently building a cleanup. Needed because 12494: SAVE_EXPRs are not the right things to use inside of cleanups. 12495: They are only ever evaluated once, where the cleanup 12496: might be evaluated several times. In this case, a later evaluation 12497: of the cleanup might fill in the SAVE_EXPR_RTL, and it will 12498: not be valid for an earlier cleanup. */ 12499: 12500: int building_cleanup; 12501: 12502: /* If DECL is of a type which needs a cleanup, build that cleanup here. 12503: We don't build cleanups if just going for syntax checking, since 12504: fixup_cleanups does not know how to not handle them. 12505: 12506: Don't build these on the momentary obstack; they must live 12507: the life of the binding contour. */ 12508: tree 12509: maybe_build_cleanup (decl) 12510: tree decl; 12511: { 12512: tree type = TREE_TYPE (decl); 12513: if (TYPE_NEEDS_DESTRUCTOR (type)) 12514: { 12515: int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; 12516: tree rval; 12517: int old_building_cleanup = building_cleanup; 12518: building_cleanup = 1; 12519: 12520: if (TREE_CODE (decl) != PARM_DECL) 12521: temp = suspend_momentary (); 12522: 12523: if (TREE_CODE (type) == ARRAY_TYPE) 12524: rval = decl; 12525: else 12526: { 12527: mark_addressable (decl); 12528: rval = build_unary_op (ADDR_EXPR, decl, 0); 12529: } 12530: 12531: /* Optimize for space over speed here. */ 12532: if (! TYPE_USES_VIRTUAL_BASECLASSES (type) 12533: || flag_expensive_optimizations) 12534: flags |= LOOKUP_NONVIRTUAL; 12535: 12536: rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0); 12537: 12538: if (TYPE_USES_VIRTUAL_BASECLASSES (type) 12539: && ! TYPE_HAS_DESTRUCTOR (type)) 12540: rval = build_compound_expr (tree_cons (NULL_TREE, rval, 12541: build_tree_list (NULL_TREE, build_vbase_delete (type, decl)))); 12542: 12543: if (TREE_CODE (decl) != PARM_DECL) 12544: resume_momentary (temp); 12545: 12546: building_cleanup = old_building_cleanup; 12547: 12548: return rval; 12549: } 12550: return 0; 12551: } 12552: 12553: /* Expand a C++ expression at the statement level. 12554: This is needed to ferret out nodes which have UNKNOWN_TYPE. 12555: The C++ type checker should get all of these out when 12556: expressions are combined with other, type-providing, expressions, 12557: leaving only orphan expressions, such as: 12558: 12559: &class::bar; / / takes its address, but does nothing with it. 12560: 12561: */ 12562: void 12563: cplus_expand_expr_stmt (exp) 12564: tree exp; 12565: { 12566: if (TREE_TYPE (exp) == unknown_type_node) 12567: { 12568: if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST) 12569: error ("address of overloaded function with no contextual type information"); 12570: else if (TREE_CODE (exp) == COMPONENT_REF) 12571: warning ("useless reference to a member function name, did you forget the ()?"); 12572: } 12573: else 12574: { 12575: int remove_implicit_immediately = 0; 12576: 12577: if (TREE_CODE (exp) == FUNCTION_DECL) 12578: { 12579: cp_warning ("reference, not call, to function `%D'", exp); 12580: warning ("at this point in file"); 12581: } 12582: 12583: #if 0 12584: /* We should do this eventually, but right now this causes regex.o from 12585: libg++ to miscompile, and tString to core dump. */ 12586: exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp); 12587: #endif 12588: expand_expr_stmt (break_out_cleanups (exp)); 12589: } 12590: 12591: /* Clean up any pending cleanups. This happens when a function call 12592: returns a cleanup-needing value that nobody uses. */ 12593: expand_cleanups_to (NULL_TREE); 12594: } 12595: 12596: /* When a stmt has been parsed, this function is called. 12597: 12598: Currently, this function only does something within a 12599: constructor's scope: if a stmt has just assigned to this, 12600: and we are in a derived class, we call `emit_base_init'. */ 12601: 12602: void 12603: finish_stmt () 12604: { 12605: extern struct nesting *cond_stack, *loop_stack, *case_stack; 12606: 12607: 12608: if (current_function_assigns_this 12609: || ! current_function_just_assigned_this) 12610: return; 12611: if (DECL_CONSTRUCTOR_P (current_function_decl)) 12612: { 12613: /* Constructors must wait until we are out of control 12614: zones before calling base constructors. */ 12615: if (cond_stack || loop_stack || case_stack) 12616: return; 1.1.1.2 ! root 12617: expand_expr_stmt (base_init_expr); 1.1 root 12618: check_base_init (current_class_type); 12619: } 12620: current_function_assigns_this = 1; 12621: 12622: if (flag_cadillac) 12623: cadillac_finish_stmt (); 12624: } 12625: 12626: /* Change a static member function definition into a FUNCTION_TYPE, instead 12627: of the METHOD_TYPE that we create when it's originally parsed. 12628: 12629: WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES 12630: (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of 12631: other decls. Either pass the addresses of local variables or NULL. */ 12632: 12633: void 12634: revert_static_member_fn (decl, fn, argtypes) 12635: tree *decl, *fn, *argtypes; 12636: { 12637: tree tmp; 12638: tree function = fn ? *fn : TREE_TYPE (*decl); 12639: tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function); 12640: 1.1.1.2 ! root 12641: if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args)))) ! 12642: cp_error ("static member function `%#D' declared const", *decl); ! 12643: if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args)))) ! 12644: cp_error ("static member function `%#D' declared volatile", *decl); ! 12645: 1.1 root 12646: args = TREE_CHAIN (args); 12647: tmp = build_function_type (TREE_TYPE (function), args); 12648: tmp = build_type_variant (tmp, TYPE_READONLY (function), 12649: TYPE_VOLATILE (function)); 1.1.1.2 ! root 12650: tmp = build_exception_variant (tmp, 1.1 root 12651: TYPE_RAISES_EXCEPTIONS (function)); 12652: TREE_TYPE (*decl) = tmp; 1.1.1.2 ! root 12653: if (DECL_ARGUMENTS (*decl)) ! 12654: DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl)); 1.1 root 12655: DECL_STATIC_FUNCTION_P (*decl) = 1; 12656: if (fn) 12657: *fn = tmp; 12658: if (argtypes) 12659: *argtypes = args; 12660: } 12661: 12662: int 12663: id_in_current_class (id) 12664: tree id; 12665: { 12666: return !!purpose_member (id, class_binding_level->class_shadowed); 12667: } 1.1.1.2 ! root 12668: ! 12669: struct cp_function ! 12670: { ! 12671: int returns_value; ! 12672: int returns_null; ! 12673: int warn_about_return_type; ! 12674: int assigns_this; ! 12675: int just_assigned_this; ! 12676: int parms_stored; ! 12677: int temp_name_counter; ! 12678: tree named_labels; ! 12679: tree shadowed_labels; ! 12680: tree ctor_label; ! 12681: tree dtor_label; ! 12682: tree protect_list; ! 12683: tree base_init_list; ! 12684: tree member_init_list; ! 12685: tree base_init_expr; ! 12686: tree class_decl; ! 12687: tree C_C_D; ! 12688: rtx result_rtx; ! 12689: struct cp_function *next; ! 12690: struct binding_level *binding_level; ! 12691: }; ! 12692: ! 12693: struct cp_function *cp_function_chain; ! 12694: ! 12695: extern int temp_name_counter; ! 12696: ! 12697: /* Save and reinitialize the variables ! 12698: used during compilation of a C++ function. */ ! 12699: ! 12700: void ! 12701: push_cp_function_context (context) ! 12702: tree context; ! 12703: { ! 12704: struct cp_function *p ! 12705: = (struct cp_function *) xmalloc (sizeof (struct cp_function)); ! 12706: ! 12707: push_function_context_to (context); ! 12708: ! 12709: p->next = cp_function_chain; ! 12710: cp_function_chain = p; ! 12711: ! 12712: p->named_labels = named_labels; ! 12713: p->shadowed_labels = shadowed_labels; ! 12714: p->returns_value = current_function_returns_value; ! 12715: p->returns_null = current_function_returns_null; ! 12716: p->warn_about_return_type = warn_about_return_type; ! 12717: p->binding_level = current_binding_level; ! 12718: p->ctor_label = ctor_label; ! 12719: p->dtor_label = dtor_label; ! 12720: p->assigns_this = current_function_assigns_this; ! 12721: p->just_assigned_this = current_function_just_assigned_this; ! 12722: p->parms_stored = current_function_parms_stored; ! 12723: p->result_rtx = original_result_rtx; ! 12724: p->base_init_expr = base_init_expr; ! 12725: p->protect_list = protect_list; ! 12726: p->temp_name_counter = temp_name_counter; ! 12727: p->base_init_list = current_base_init_list; ! 12728: p->member_init_list = current_member_init_list; ! 12729: p->class_decl = current_class_decl; ! 12730: p->C_C_D = C_C_D; ! 12731: } ! 12732: ! 12733: /* Restore the variables used during compilation of a C++ function. */ ! 12734: ! 12735: void ! 12736: pop_cp_function_context (context) ! 12737: tree context; ! 12738: { ! 12739: struct cp_function *p = cp_function_chain; ! 12740: tree link; ! 12741: ! 12742: /* Bring back all the labels that were shadowed. */ ! 12743: for (link = shadowed_labels; link; link = TREE_CHAIN (link)) ! 12744: if (DECL_NAME (TREE_VALUE (link)) != 0) ! 12745: SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), ! 12746: TREE_VALUE (link)); ! 12747: ! 12748: #if 0 ! 12749: if (DECL_SAVED_INSNS (current_function_decl) == 0) ! 12750: { ! 12751: /* Stop pointing to the local nodes about to be freed. */ ! 12752: /* But DECL_INITIAL must remain nonzero so we know this ! 12753: was an actual function definition. */ ! 12754: DECL_INITIAL (current_function_decl) = error_mark_node; ! 12755: DECL_ARGUMENTS (current_function_decl) = 0; ! 12756: } ! 12757: #endif ! 12758: ! 12759: pop_function_context_from (context); ! 12760: ! 12761: cp_function_chain = p->next; ! 12762: ! 12763: named_labels = p->named_labels; ! 12764: shadowed_labels = p->shadowed_labels; ! 12765: current_function_returns_value = p->returns_value; ! 12766: current_function_returns_null = p->returns_null; ! 12767: warn_about_return_type = p->warn_about_return_type; ! 12768: current_binding_level = p->binding_level; ! 12769: ctor_label = p->ctor_label; ! 12770: dtor_label = p->dtor_label; ! 12771: protect_list = p->protect_list; ! 12772: current_function_assigns_this = p->assigns_this; ! 12773: current_function_just_assigned_this = p->just_assigned_this; ! 12774: current_function_parms_stored = p->parms_stored; ! 12775: original_result_rtx = p->result_rtx; ! 12776: base_init_expr = p->base_init_expr; ! 12777: temp_name_counter = p->temp_name_counter; ! 12778: current_base_init_list = p->base_init_list; ! 12779: current_member_init_list = p->member_init_list; ! 12780: current_class_decl = p->class_decl; ! 12781: C_C_D = p->C_C_D; ! 12782: ! 12783: free (p); ! 12784: } ! 12785: ! 12786: /* FSF LOCAL dje prefix attributes */ ! 12787: /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two ! 12788: lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE). ! 12789: ! 12790: The head of the declspec list is stored in DECLSPECS. ! 12791: The head of the attribute list is stored in PREFIX_ATTRIBUTES. ! 12792: ! 12793: Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of ! 12794: the list elements. We drop the containing TREE_LIST nodes and link the ! 12795: resulting attributes together the way decl_attributes expects them. */ ! 12796: ! 12797: void ! 12798: split_specs_attrs (specs_attrs, declspecs, prefix_attributes) ! 12799: tree specs_attrs; ! 12800: tree *declspecs, *prefix_attributes; ! 12801: { ! 12802: tree t, s, a, next, specs, attrs; ! 12803: ! 12804: /* This can happen in c++ (eg: decl: typespec initdecls ';'). */ ! 12805: if (specs_attrs != NULL_TREE ! 12806: && TREE_CODE (specs_attrs) != TREE_LIST) ! 12807: { ! 12808: *declspecs = specs_attrs; ! 12809: *prefix_attributes = NULL_TREE; ! 12810: return; ! 12811: } ! 12812: ! 12813: /* Remember to keep the lists in the same order, element-wise. */ ! 12814: ! 12815: specs = s = NULL_TREE; ! 12816: attrs = a = NULL_TREE; ! 12817: for (t = specs_attrs; t; t = next) ! 12818: { ! 12819: next = TREE_CHAIN (t); ! 12820: /* Declspecs have a non-NULL TREE_VALUE. */ ! 12821: if (TREE_VALUE (t) != NULL_TREE) ! 12822: { ! 12823: if (specs == NULL_TREE) ! 12824: specs = s = t; ! 12825: else ! 12826: { ! 12827: TREE_CHAIN (s) = t; ! 12828: s = t; ! 12829: } ! 12830: } ! 12831: else ! 12832: { ! 12833: if (attrs == NULL_TREE) ! 12834: attrs = a = TREE_PURPOSE (t); ! 12835: else ! 12836: { ! 12837: TREE_CHAIN (a) = TREE_PURPOSE (t); ! 12838: a = TREE_PURPOSE (t); ! 12839: } ! 12840: } ! 12841: } ! 12842: ! 12843: /* Terminate the lists. */ ! 12844: if (s != NULL_TREE) ! 12845: TREE_CHAIN (s) = NULL_TREE; ! 12846: if (a != NULL_TREE) ! 12847: TREE_CHAIN (a) = NULL_TREE; ! 12848: ! 12849: /* All done. */ ! 12850: *declspecs = specs; ! 12851: *prefix_attributes = attrs; ! 12852: } ! 12853: ! 12854: /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes. ! 12855: This function is used by the parser when a rule will accept attributes ! 12856: in a particular position, but we don't want to support that just yet. ! 12857: ! 12858: A warning is issued for every ignored attribute. */ ! 12859: ! 12860: tree ! 12861: strip_attrs (specs_attrs) ! 12862: tree specs_attrs; ! 12863: { ! 12864: tree specs, attrs; ! 12865: ! 12866: split_specs_attrs (specs_attrs, &specs, &attrs); ! 12867: ! 12868: while (attrs) ! 12869: { ! 12870: warning ("`%s' attribute ignored", ! 12871: IDENTIFIER_POINTER (TREE_PURPOSE (attrs))); ! 12872: attrs = TREE_CHAIN (attrs); ! 12873: } ! 12874: ! 12875: return specs; ! 12876: } ! 12877: /* END FSF LOCAL */ ! 12878:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.