|
|
1.1 root 1: /* Process declarations and variables for C compiler. 1.1.1.5 root 2: Copyright (C) 1988, 1992, 1993 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 19: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 20: 21: 22: /* Process declarations and symbol lookup for C front end. 23: Also constructs types; the standard scalar types at initialization, 24: and structure, union, array and enum types when they are declared. */ 25: 26: /* ??? not all decl nodes are given the most useful possible 27: line numbers. For example, the CONST_DECLs for enum values. */ 28: 29: #include <stdio.h> 30: #include "config.h" 31: #include "tree.h" 1.1.1.4 root 32: #include "rtl.h" 1.1 root 33: #include "flags.h" 34: #include "cp-tree.h" 1.1.1.5 root 35: #include "cp-decl.h" 1.1 root 36: #include "cp-lex.h" 1.1.1.4 root 37: #include <sys/types.h> 1.1 root 38: #include <signal.h> 39: #include "obstack.h" 40: 41: #define obstack_chunk_alloc xmalloc 42: #define obstack_chunk_free free 43: 44: extern struct obstack permanent_obstack; 45: 1.1.1.6 ! root 46: extern int current_class_depth; ! 47: 1.1 root 48: /* Stack of places to restore the search obstack back to. */ 49: 50: /* Obstack used for remembering local class declarations (like 51: enums and static (const) members. */ 52: #include "stack.h" 53: static struct obstack decl_obstack; 54: static struct stack_level *decl_stack; 55: 56: #ifndef CHAR_TYPE_SIZE 57: #define CHAR_TYPE_SIZE BITS_PER_UNIT 58: #endif 59: 60: #ifndef SHORT_TYPE_SIZE 61: #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) 62: #endif 63: 64: #ifndef INT_TYPE_SIZE 65: #define INT_TYPE_SIZE BITS_PER_WORD 66: #endif 67: 68: #ifndef LONG_TYPE_SIZE 69: #define LONG_TYPE_SIZE BITS_PER_WORD 70: #endif 71: 72: #ifndef LONG_LONG_TYPE_SIZE 73: #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) 74: #endif 75: 76: #ifndef WCHAR_UNSIGNED 77: #define WCHAR_UNSIGNED 0 78: #endif 79: 80: #ifndef FLOAT_TYPE_SIZE 81: #define FLOAT_TYPE_SIZE BITS_PER_WORD 82: #endif 83: 84: #ifndef DOUBLE_TYPE_SIZE 85: #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) 86: #endif 87: 88: #ifndef LONG_DOUBLE_TYPE_SIZE 89: #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) 90: #endif 91: 92: /* We let tm.h override the types used here, to handle trivial differences 93: such as the choice of unsigned int or long unsigned int for size_t. 94: When machines start needing nontrivial differences in the size type, 95: it would be best to do something here to figure out automatically 96: from other information what type to use. */ 97: 98: #ifndef SIZE_TYPE 99: #define SIZE_TYPE "long unsigned int" 100: #endif 101: 102: #ifndef PTRDIFF_TYPE 103: #define PTRDIFF_TYPE "long int" 104: #endif 105: 106: #ifndef WCHAR_TYPE 107: #define WCHAR_TYPE "int" 108: #endif 109: 110: #define builtin_function(NAME, TYPE, CODE, LIBNAME) \ 111: define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME) 112: #define auto_function(NAME, TYPE, CODE) \ 1.1.1.2 root 113: do { \ 114: tree __name = NAME; \ 115: tree __type = TYPE; \ 116: define_function (IDENTIFIER_POINTER (__name), __type, CODE, \ 117: (void (*)())push_overloaded_decl_1, \ 118: IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\ 119: } while (0) 1.1 root 120: 1.1.1.5 root 121: static tree grokparms PROTO((tree, int)); 122: static tree lookup_nested_type PROTO((tree, tree)); 123: static char *redeclaration_error_message PROTO((tree, tree)); 124: static int parmlist_is_random PROTO((tree)); 125: static void grok_op_properties PROTO((tree, int)); 126: static void expand_static_init PROTO((tree, tree)); 127: static void deactivate_exception_cleanups PROTO((void)); 1.1 root 128: 1.1.1.5 root 129: tree define_function PROTO((char *, tree, enum built_in_function, void (*)(), char *)); 1.1 root 130: 131: /* a node which has tree code ERROR_MARK, and whose type is itself. 132: All erroneous expressions are replaced with this node. All functions 133: that accept nodes as arguments should avoid generating error messages 134: if this node is one of the arguments, since it is undesirable to get 135: multiple error messages from one error in the input. */ 136: 137: tree error_mark_node; 138: 139: /* Erroneous argument lists can use this *IFF* they do not modify it. */ 140: tree error_mark_list; 141: 142: /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ 143: 144: tree short_integer_type_node; 145: tree integer_type_node; 146: tree long_integer_type_node; 147: tree long_long_integer_type_node; 148: 149: tree short_unsigned_type_node; 150: tree unsigned_type_node; 151: tree long_unsigned_type_node; 152: tree long_long_unsigned_type_node; 153: 154: tree ptrdiff_type_node; 155: 156: tree unsigned_char_type_node; 157: tree signed_char_type_node; 158: tree char_type_node; 159: tree wchar_type_node; 160: tree signed_wchar_type_node; 161: tree unsigned_wchar_type_node; 162: 163: tree float_type_node; 164: tree double_type_node; 165: tree long_double_type_node; 166: 1.1.1.4 root 167: tree intQI_type_node; 168: tree intHI_type_node; 169: tree intSI_type_node; 170: tree intDI_type_node; 171: 172: tree unsigned_intQI_type_node; 173: tree unsigned_intHI_type_node; 174: tree unsigned_intSI_type_node; 175: tree unsigned_intDI_type_node; 176: 1.1 root 177: /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */ 178: 179: tree void_type_node, void_list_node; 180: tree void_zero_node; 181: 182: /* Nodes for types `void *' and `const void *'. */ 183: 184: tree ptr_type_node, const_ptr_type_node; 185: 186: /* Nodes for types `char *' and `const char *'. */ 187: 188: tree string_type_node, const_string_type_node; 189: 190: /* Type `char[256]' or something like it. 191: Used when an array of char is needed and the size is irrelevant. */ 192: 193: tree char_array_type_node; 194: 195: /* Type `int[256]' or something like it. 196: Used when an array of int needed and the size is irrelevant. */ 197: 198: tree int_array_type_node; 199: 200: /* Type `wchar_t[256]' or something like it. 201: Used when a wide string literal is created. */ 202: 203: tree wchar_array_type_node; 204: 205: /* type `int ()' -- used for implicit declaration of functions. */ 206: 207: tree default_function_type; 208: 209: /* function types `double (double)' and `double (double, double)', etc. */ 210: 211: tree double_ftype_double, double_ftype_double_double; 212: tree int_ftype_int, long_ftype_long; 213: 214: /* Function type `void (void *, void *, int)' and similar ones. */ 215: 216: tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int; 217: 218: /* Function type `char *(char *, char *)' and similar ones */ 219: tree string_ftype_ptr_ptr, int_ftype_string_string; 220: 221: /* Function type `size_t (const char *)' */ 222: tree sizet_ftype_string; 223: 224: /* Function type `int (const void *, const void *, size_t)' */ 225: tree int_ftype_cptr_cptr_sizet; 226: 227: /* C++ extensions */ 228: tree vtable_entry_type; 229: tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node; 230: tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; 231: tree class_star_type_node; 232: tree class_type_node, record_type_node, union_type_node, enum_type_node; 233: tree exception_type_node, unknown_type_node; 234: tree maybe_gc_cleanup; 235: 236: /* Used for virtual function tables. */ 237: tree vtbl_mask; 238: 239: /* Array type `(void *)[]' */ 240: tree vtbl_type_node; 241: 242: /* Static decls which do not have static initializers have no 243: initializers as far as GNU C is concerned. EMPTY_INIT_NODE 244: is a static initializer which makes varasm code place the decl 245: in data rather than in bss space. Such gymnastics are necessary 246: to avoid the problem that the linker will not include a library 247: file if all the library appears to contribute are bss variables. */ 248: 249: tree empty_init_node; 250: 251: /* In a destructor, the point at which all derived class destroying 252: has been done, just before any base class destroying will be done. */ 253: 254: tree dtor_label; 255: 256: /* In a constructor, the point at which we are ready to return 257: the pointer to the initialized object. */ 258: 259: tree ctor_label; 260: 261: /* A FUNCTION_DECL which can call `unhandled_exception'. 1.1.1.2 root 262: Not necessarily the one that the user will declare, 1.1 root 263: but sufficient to be called by routines that want to abort the program. */ 264: 265: tree unhandled_exception_fndecl; 266: 1.1.1.2 root 267: /* A FUNCTION_DECL which can call `abort'. Not necessarily the 1.1 root 268: one that the user will declare, but sufficient to be called 269: by routines that want to abort the program. */ 270: 271: tree abort_fndecl; 272: 1.1.1.4 root 273: extern rtx cleanup_label, return_label; 274: 1.1 root 275: /* If original DECL_RESULT of current function was a register, 276: but due to being an addressable named return value, would up 277: on the stack, this variable holds the named return value's 278: original location. */ 1.1.1.4 root 279: rtx original_result_rtx; 1.1 root 280: 281: /* Sequence of insns which represents base initialization. */ 1.1.1.4 root 282: rtx base_init_insns; 1.1 root 283: 284: /* C++: Keep these around to reduce calls to `get_identifier'. 285: Identifiers for `this' in member functions and the auto-delete 286: parameter for destructors. */ 287: tree this_identifier, in_charge_identifier; 1.1.1.6 ! root 288: /* Used in pointer to member functions, and in vtables. */ ! 289: tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; ! 290: tree pfn_or_delta2_identifier; 1.1 root 291: 292: /* A list (chain of TREE_LIST nodes) of named label uses. 293: The TREE_PURPOSE field is the list of variables defined 294: the the label's scope defined at the point of use. 295: The TREE_VALUE field is the LABEL_DECL used. 296: The TREE_TYPE field holds `current_binding_level' at the 297: point of the label's use. 298: 299: Used only for jumps to as-yet undefined labels, since 300: jumps to defined labels can have their validity checked 301: by stmt.c. */ 302: 303: static tree named_label_uses; 304: 305: /* A list of objects which have constructors or destructors 306: which reside in the global scope. The decl is stored in 307: the TREE_VALUE slot and the initializer is stored 308: in the TREE_PURPOSE slot. */ 309: tree static_aggregates; 310: 311: /* A list of functions which were declared inline, but later had their 312: address taken. Used only for non-virtual member functions, since we can 313: find other functions easily enough. */ 314: tree pending_addressable_inlines; 315: 316: /* A list of overloaded functions which we should forget ever 317: existed, such as functions declared in a function's scope, 318: once we leave that function's scope. */ 319: static tree overloads_to_forget; 320: 321: /* -- end of C++ */ 322: 323: /* Two expressions that are constants with value zero. 324: The first is of type `int', the second of type `void *'. */ 325: 326: tree integer_zero_node; 327: tree null_pointer_node; 328: 329: /* A node for the integer constants 1, 2, and 3. */ 330: 331: tree integer_one_node, integer_two_node, integer_three_node; 332: 333: /* Nonzero if we have seen an invalid cross reference 334: to a struct, union, or enum, but not yet printed the message. */ 335: 336: tree pending_invalid_xref; 337: /* File and line to appear in the eventual error message. */ 338: char *pending_invalid_xref_file; 339: int pending_invalid_xref_line; 340: 341: /* While defining an enum type, this is 1 plus the last enumerator 342: constant value. */ 343: 344: static tree enum_next_value; 345: 346: /* Parsing a function declarator leaves a list of parameter names 347: or a chain or parameter decls here. */ 348: 349: tree last_function_parms; 350: 351: /* Parsing a function declarator leaves here a chain of structure 352: and enum types declared in the parmlist. */ 353: 354: static tree last_function_parm_tags; 355: 356: /* After parsing the declarator that starts a function definition, 357: `start_function' puts here the list of parameter names or chain of decls. 358: `store_parm_decls' finds it here. */ 359: 360: static tree current_function_parms; 361: 362: /* Similar, for last_function_parm_tags. */ 363: static tree current_function_parm_tags; 364: 365: /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function 366: that have names. Here so we can clear out their names' definitions 367: at the end of the function. */ 368: 369: static tree named_labels; 370: 371: /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ 372: 373: static tree shadowed_labels; 374: 1.1.1.4 root 375: #if 0 /* Not needed by C++ */ 1.1 root 376: /* Nonzero when store_parm_decls is called indicates a varargs function. 377: Value not meaningful after store_parm_decls. */ 378: 379: static int c_function_varargs; 1.1.1.4 root 380: #endif 1.1 root 381: 382: /* The FUNCTION_DECL for the function currently being compiled, 383: or 0 if between functions. */ 384: tree current_function_decl; 385: 386: /* Set to 0 at beginning of a function definition, set to 1 if 387: a return statement that specifies a return value is seen. */ 388: 389: int current_function_returns_value; 390: 391: /* Set to 0 at beginning of a function definition, set to 1 if 392: a return statement with no argument is seen. */ 393: 394: int current_function_returns_null; 395: 396: /* Set to 0 at beginning of a function definition, and whenever 397: a label (case or named) is defined. Set to value of expression 398: returned from function when that value can be transformed into 399: a named return value. */ 400: 401: tree current_function_return_value; 402: 403: /* Set to nonzero by `grokdeclarator' for a function 404: whose return type is defaulted, if warnings for this are desired. */ 405: 406: static int warn_about_return_type; 407: 1.1.1.2 root 408: /* Nonzero when starting a function declared `extern inline'. */ 1.1 root 409: 410: static int current_extern_inline; 411: 412: /* Nonzero means give `double' the same size as `float'. */ 413: 414: extern int flag_short_double; 415: 1.1.1.5 root 416: /* Nonzero means don't recognize any builtin functions. */ 417: 418: extern int flag_no_builtin; 419: 420: /* Nonzero means do emit exported implementations of functions even if 421: they can be inlined. */ 422: 423: extern int flag_implement_inlines; 424: 1.1.1.4 root 425: /* Nonzero means handle things in ANSI, instead of GNU fashion. This 426: flag should be tested for language behavior that's different between 427: ANSI and GNU, but not so horrible as to merit a PEDANTIC label. */ 428: 429: extern int flag_ansi; 430: 1.1 root 431: /* Pointers to the base and current top of the language name stack. */ 432: 433: extern tree *current_lang_base, *current_lang_stack; 434: 435: /* C and C++ flags are in cp-decl2.c. */ 436: 437: /* Set to 0 at beginning of a constructor, set to 1 438: if that function does an allocation before referencing its 439: instance variable. */ 440: int current_function_assigns_this; 441: int current_function_just_assigned_this; 442: 443: /* Set to 0 at beginning of a function. Set non-zero when 444: store_parm_decls is called. Don't call store_parm_decls 445: if this flag is non-zero! */ 446: int current_function_parms_stored; 447: 448: /* Current end of entries in the gc obstack for stack pointer variables. */ 449: 450: int current_function_obstack_index; 451: 452: /* Flag saying whether we have used the obstack in this function or not. */ 453: 454: int current_function_obstack_usage; 1.1.1.4 root 455: 456: /* Flag used when debugging cp-spew.c */ 457: 458: extern int spew_debug; 1.1.1.6 ! root 459: ! 460: /* This is a copy of the class_shadowed list of the previous class binding ! 461: contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs ! 462: when entering another class scope (i.e. a cache miss). */ ! 463: extern tree previous_class_values; ! 464: 1.1 root 465: 466: /* Allocate a level of searching. */ 467: struct stack_level * 468: push_decl_level (stack, obstack) 469: struct stack_level *stack; 470: struct obstack *obstack; 471: { 472: struct stack_level tem; 473: tem.prev = stack; 474: 1.1.1.5 root 475: return push_stack_level (obstack, (char *)&tem, sizeof (tem)); 1.1 root 476: } 477: 478: /* Discard a level of decl allocation. */ 479: 480: static struct stack_level * 481: pop_decl_level (stack) 482: struct stack_level *stack; 483: { 1.1.1.6 ! root 484: #if !NEW_CLASS_SCOPING 1.1 root 485: tree *bp, *tp; 486: struct obstack *obstack = stack->obstack; 487: bp = stack->first; 488: tp = (tree *)obstack_next_free (obstack); 489: while (tp != bp) 490: { 491: --tp; 492: if (*tp != NULL_TREE) 493: IDENTIFIER_CLASS_VALUE (DECL_NAME (*tp)) = NULL_TREE; 494: } 1.1.1.6 ! root 495: #endif 1.1 root 496: return pop_stack_level (stack); 497: } 498: 499: /* For each binding contour we allocate a binding_level structure 500: * which records the names defined in that contour. 501: * Contours include: 502: * 0) the global one 503: * 1) one for each function definition, 504: * where internal declarations of the parameters appear. 505: * 2) one for each compound statement, 506: * to record its declarations. 507: * 508: * The current meaning of a name can be found by searching the levels from 509: * the current one out to the global one. 510: * 511: * Off to the side, may be the class_binding_level. This exists 512: * only to catch class-local declarations. It is otherwise 513: * nonexistent. 514: * 515: * Also there may be binding levels that catch cleanups that 516: * must be run when exceptions occur. 517: */ 518: 519: /* Note that the information in the `names' component of the global contour 520: is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ 521: 522: struct binding_level 523: { 524: /* A chain of _DECL nodes for all variables, constants, functions, 525: * and typedef types. These are in the reverse of the order supplied. 526: */ 527: tree names; 528: 529: /* A list of structure, union and enum definitions, 530: * for looking up tag names. 531: * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, 532: * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, 533: * or ENUMERAL_TYPE node. 534: * 535: * C++: the TREE_VALUE nodes can be simple types for component_bindings. 536: * 537: */ 538: tree tags; 539: 540: /* For each level, a list of shadowed outer-level local definitions 541: to be restored when this level is popped. 542: Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and 543: whose TREE_VALUE is its old definition (a kind of ..._DECL node). */ 544: tree shadowed; 545: 546: /* Same, for IDENTIFIER_CLASS_VALUE. */ 547: tree class_shadowed; 548: 549: /* Same, for IDENTIFIER_TYPE_VALUE. */ 550: tree type_shadowed; 551: 552: /* For each level (except not the global one), 553: a chain of BLOCK nodes for all the levels 554: that were entered and exited one level down. */ 555: tree blocks; 556: 1.1.1.4 root 557: /* The BLOCK node for this level, if one has been preallocated. 558: If 0, the BLOCK is allocated (if needed) when the level is popped. */ 559: tree this_block; 560: 1.1 root 561: /* The binding level which this one is contained in (inherits from). */ 562: struct binding_level *level_chain; 563: 564: /* Number of decls in `names' that have incomplete 565: structure or union types. */ 566: unsigned short n_incomplete; 567: 568: /* 1 for the level that holds the parameters of a function. 569: 2 for the level that holds a class declaration. 570: 3 for levels that hold parameter declarations. */ 571: unsigned parm_flag : 4; 572: 573: /* 1 means make a BLOCK for this level regardless of all else. 574: 2 for temporary binding contours created by the compiler. */ 575: unsigned keep : 3; 576: 577: /* Nonzero if this level "doesn't exist" for tags. */ 578: unsigned tag_transparent : 1; 579: 580: /* Nonzero if this level can safely have additional 581: cleanup-needing variables added to it. */ 582: unsigned more_cleanups_ok : 1; 583: unsigned have_cleanups : 1; 584: 585: /* Nonzero if this level can safely have additional 586: exception-raising statements added to it. */ 587: unsigned more_exceptions_ok : 1; 588: unsigned have_exceptions : 1; 589: 590: /* Nonzero if we should accept any name as an identifier in 591: this scope. This happens in some template definitions. */ 592: unsigned accept_any : 1; 593: 1.1.1.4 root 594: /* Nonzero if this level is for completing a template class definition 595: inside a binding level that temporarily binds the parameters. This 596: means that definitions here should not be popped off when unwinding 597: this binding level. (Not actually implemented this way, 598: unfortunately.) */ 599: unsigned pseudo_global : 1; 600: 601: /* Two bits left for this word. */ 1.1 root 602: 1.1.1.6 ! root 603: #if defined(DEBUG_CP_BINDING_LEVELS) ! 604: /* Binding depth at which this level began. */ ! 605: unsigned binding_depth; ! 606: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 1.1 root 607: }; 608: 1.1.1.6 ! root 609: #define NULL_BINDING_LEVEL ((struct binding_level *) NULL) 1.1 root 610: 611: /* The binding level currently in effect. */ 612: 613: static struct binding_level *current_binding_level; 614: 615: /* The binding level of the current class, if any. */ 616: 617: static struct binding_level *class_binding_level; 618: 619: /* A chain of binding_level structures awaiting reuse. */ 620: 621: static struct binding_level *free_binding_level; 622: 623: /* The outermost binding level, for names of file scope. 624: This is created when the compiler is started and exists 625: through the entire run. */ 626: 627: static struct binding_level *global_binding_level; 628: 629: /* Binding level structures are initialized by copying this one. */ 630: 631: static struct binding_level clear_binding_level; 632: 633: /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ 634: 635: static int keep_next_level_flag; 636: 1.1.1.6 ! root 637: #if defined(DEBUG_CP_BINDING_LEVELS) ! 638: static int binding_depth = 0; ! 639: static int is_class_level = 0; 1.1 root 640: 1.1.1.6 ! root 641: static void ! 642: indent () ! 643: { ! 644: register unsigned i; 1.1 root 645: 1.1.1.6 ! root 646: for (i = 0; i < binding_depth*2; i++) ! 647: putc (' ', stderr); ! 648: } ! 649: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 1.1 root 650: 651: static void 652: push_binding_level (newlevel, tag_transparent, keep) 653: struct binding_level *newlevel; 1.1.1.4 root 654: int tag_transparent, keep; 1.1 root 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; 1.1.1.5 root 662: class_binding_level = (struct binding_level *)0; 1.1 root 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->more_exceptions_ok = 1; 672: newlevel->keep = keep; 1.1.1.6 ! root 673: #if defined(DEBUG_CP_BINDING_LEVELS) ! 674: newlevel->binding_depth = binding_depth; ! 675: indent (); ! 676: fprintf (stderr, "push %s level 0x%08x line %d\n", ! 677: (is_class_level) ? "class" : "block", newlevel, lineno); ! 678: is_class_level = 0; ! 679: binding_depth++; ! 680: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 1.1 root 681: } 682: 683: static void 684: pop_binding_level () 685: { 1.1.1.6 ! root 686: if (class_binding_level) ! 687: current_binding_level = class_binding_level; ! 688: 1.1 root 689: if (global_binding_level) 1.1.1.4 root 690: { 691: /* cannot pop a level, if there are none left to pop. */ 692: if (current_binding_level == global_binding_level) 693: my_friendly_abort (123); 694: } 1.1 root 695: /* Pop the current level, and free the structure for reuse. */ 1.1.1.6 ! root 696: #if defined(DEBUG_CP_BINDING_LEVELS) ! 697: binding_depth--; ! 698: indent (); ! 699: fprintf (stderr, "pop %s level 0x%08x line %d\n", ! 700: (is_class_level) ? "class" : "block", ! 701: current_binding_level, lineno); ! 702: if (is_class_level != (current_binding_level == class_binding_level)) ! 703: #if 0 /* XXX Don't abort when we're watching how things are being managed. */ ! 704: abort (); ! 705: #else ! 706: { ! 707: indent (); ! 708: fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); ! 709: } ! 710: #endif ! 711: is_class_level = 0; ! 712: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ 1.1 root 713: { 714: register struct binding_level *level = current_binding_level; 715: current_binding_level = current_binding_level->level_chain; 716: level->level_chain = free_binding_level; 1.1.1.6 ! root 717: #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ ! 718: if (level->binding_depth != binding_depth) ! 719: abort (); ! 720: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ ! 721: free_binding_level = level; ! 722: ! 723: class_binding_level = current_binding_level; ! 724: if (class_binding_level->parm_flag != 2) ! 725: class_binding_level = 0; ! 726: while (current_binding_level->parm_flag == 2) ! 727: current_binding_level = current_binding_level->level_chain; 1.1 root 728: } 729: } 730: 731: /* Nonzero if we are currently in the global binding level. */ 732: 733: int 734: global_bindings_p () 735: { 736: return current_binding_level == global_binding_level; 737: } 738: 739: void 740: keep_next_level () 741: { 742: keep_next_level_flag = 1; 743: } 744: 745: /* Nonzero if the current level needs to have a BLOCK made. */ 746: 747: int 748: kept_level_p () 749: { 1.1.1.5 root 750: return (current_binding_level->blocks != NULL_TREE 1.1.1.4 root 751: || current_binding_level->keep 1.1.1.5 root 752: || current_binding_level->names != NULL_TREE 753: || (current_binding_level->tags != NULL_TREE 1.1.1.4 root 754: && !current_binding_level->tag_transparent)); 1.1 root 755: } 756: 757: /* Identify this binding level as a level of parameters. */ 758: 759: void 760: declare_parm_level () 761: { 762: current_binding_level->parm_flag = 1; 763: } 764: 765: /* Identify this binding level as a level of a default exception handler. */ 766: 767: void 768: declare_implicit_exception () 769: { 770: current_binding_level->parm_flag = 3; 771: } 772: 773: /* Nonzero if current binding contour contains expressions 774: that might raise exceptions. */ 775: 776: int 777: have_exceptions_p () 778: { 779: return current_binding_level->have_exceptions; 780: } 781: 782: void 783: declare_uninstantiated_type_level () 784: { 785: current_binding_level->accept_any = 1; 786: } 787: 788: int 789: uninstantiated_type_level_p () 790: { 791: return current_binding_level->accept_any; 792: } 793: 1.1.1.4 root 794: void 795: declare_pseudo_global_level () 796: { 797: current_binding_level->pseudo_global = 1; 798: } 799: 800: int 801: pseudo_global_level_p () 802: { 803: return current_binding_level->pseudo_global; 804: } 805: 1.1.1.6 ! root 806: void ! 807: set_class_shadows (shadows) ! 808: tree shadows; ! 809: { ! 810: class_binding_level->class_shadowed = shadows; ! 811: } ! 812: 1.1 root 813: /* Enter a new binding level. 814: If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, 815: not for that of tags. */ 816: 817: void 818: pushlevel (tag_transparent) 819: int tag_transparent; 820: { 821: register struct binding_level *newlevel = NULL_BINDING_LEVEL; 822: 823: /* If this is the top level of a function, 824: just make sure that NAMED_LABELS is 0. 825: They should have been set to 0 at the end of the previous function. */ 826: 827: if (current_binding_level == global_binding_level) 1.1.1.4 root 828: my_friendly_assert (named_labels == NULL_TREE, 134); 1.1 root 829: 830: /* Reuse or create a struct for this binding level. */ 831: 1.1.1.6 ! root 832: #if defined(DEBUG_CP_BINDING_LEVELS) ! 833: if (0) ! 834: #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ 1.1 root 835: if (free_binding_level) 1.1.1.6 ! root 836: #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ 1.1 root 837: { 838: newlevel = free_binding_level; 839: free_binding_level = free_binding_level->level_chain; 840: } 841: else 842: { 843: /* Create a new `struct binding_level'. */ 844: newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); 845: } 846: push_binding_level (newlevel, tag_transparent, keep_next_level_flag); 1.1.1.6 ! root 847: GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); 1.1 root 848: keep_next_level_flag = 0; 849: } 850: 851: void 852: pushlevel_temporary (tag_transparent) 853: int tag_transparent; 854: { 855: pushlevel (tag_transparent); 856: current_binding_level->keep = 2; 857: clear_last_expr (); 1.1.1.4 root 858: 859: /* Note we don't call push_momentary() here. Otherwise, it would cause 860: cleanups to be allocated on the momentary obstack, and they will be 861: overwritten by the next statement. */ 862: 1.1 root 863: expand_start_bindings (0); 864: } 865: 866: /* Exit a binding level. 867: Pop the level off, and restore the state of the identifier-decl mappings 868: that were in effect when this level was entered. 869: 870: If KEEP == 1, this level had explicit declarations, so 871: and create a "block" (a BLOCK node) for the level 872: to record its declarations and subblocks for symbol table output. 873: 874: If KEEP == 2, this level's subblocks go to the front, 875: not the back of the current binding level. This happens, 876: for instance, when code for constructors and destructors 877: need to generate code at the end of a function which must 878: be moved up to the front of the function. 879: 880: If FUNCTIONBODY is nonzero, this level is the body of a function, 881: so create a block as if KEEP were set and also clear out all 882: label names. 883: 884: If REVERSE is nonzero, reverse the order of decls before putting 885: them into the BLOCK. */ 886: 887: tree 888: poplevel (keep, reverse, functionbody) 889: int keep; 890: int reverse; 891: int functionbody; 892: { 893: register tree link; 894: /* The chain of decls was accumulated in reverse order. 895: Put it into forward order, just for cleanliness. */ 896: tree decls; 897: int tmp = functionbody; 898: int implicit_try_block = current_binding_level->parm_flag == 3; 899: int real_functionbody = current_binding_level->keep == 2 900: ? ((functionbody = 0), tmp) : functionbody; 901: tree tags = functionbody >= 0 ? current_binding_level->tags : 0; 902: tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; 1.1.1.5 root 903: tree block = NULL_TREE; 1.1 root 904: tree decl; 1.1.1.4 root 905: int block_previously_created; 1.1 root 906: 1.1.1.5 root 907: GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, 908: (HOST_WIDE_INT) current_binding_level->level_chain, 1.1 root 909: current_binding_level->parm_flag, 910: current_binding_level->keep, 911: current_binding_level->tag_transparent); 912: 913: if (current_binding_level->keep == 1) 914: keep = 1; 915: 916: /* This warning is turned off because it causes warnings for 917: declarations like `extern struct foo *x'. */ 918: #if 0 919: /* Warn about incomplete structure types in this level. */ 920: for (link = tags; link; link = TREE_CHAIN (link)) 1.1.1.5 root 921: if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE) 1.1 root 922: { 923: tree type = TREE_VALUE (link); 924: char *errmsg; 925: switch (TREE_CODE (type)) 926: { 927: case RECORD_TYPE: 928: errmsg = "`struct %s' incomplete in scope ending here"; 929: break; 930: case UNION_TYPE: 931: errmsg = "`union %s' incomplete in scope ending here"; 932: break; 933: case ENUMERAL_TYPE: 934: errmsg = "`enum %s' incomplete in scope ending here"; 935: break; 936: } 937: if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) 938: error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type))); 939: else 940: /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ 941: error (errmsg, TYPE_NAME_STRING (type)); 942: } 943: #endif /* 0 */ 944: 945: /* Get the decls in the order they were written. 946: Usually current_binding_level->names is in reverse order. 947: But parameter decls were previously put in forward order. */ 948: 949: if (reverse) 950: current_binding_level->names 951: = decls = nreverse (current_binding_level->names); 952: else 953: decls = current_binding_level->names; 954: 955: /* Output any nested inline functions within this block 956: if they weren't already output. */ 957: 958: for (decl = decls; decl; decl = TREE_CHAIN (decl)) 959: if (TREE_CODE (decl) == FUNCTION_DECL 960: && ! TREE_ASM_WRITTEN (decl) 1.1.1.5 root 961: && DECL_INITIAL (decl) != NULL_TREE 1.1 root 962: && TREE_ADDRESSABLE (decl)) 1.1.1.5 root 963: { 964: /* If this decl was copied from a file-scope decl 965: on account of a block-scope extern decl, 966: propagate TREE_ADDRESSABLE to the file-scope decl. */ 967: if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) 968: TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; 969: else 1.1.1.6 ! root 970: { ! 971: push_function_context (); ! 972: output_inline_function (decl); ! 973: pop_function_context (); ! 974: } 1.1.1.5 root 975: } 1.1 root 976: 977: /* If there were any declarations or structure tags in that level, 978: or if this level is a function body, 979: create a BLOCK to record them for the life of this function. */ 980: 1.1.1.5 root 981: block = NULL_TREE; 982: block_previously_created = (current_binding_level->this_block != NULL_TREE); 1.1.1.4 root 983: if (block_previously_created) 984: block = current_binding_level->this_block; 985: else if (keep == 1 || functionbody) 986: block = make_node (BLOCK); 1.1.1.5 root 987: if (block != NULL_TREE) 1.1.1.4 root 988: { 989: BLOCK_VARS (block) = decls; 990: BLOCK_TYPE_TAGS (block) = tags; 991: BLOCK_SUBBLOCKS (block) = subblocks; 1.1.1.6 ! root 992: /* If we created the block earlier on, and we are just diddling it now, ! 993: then it already should have a proper BLOCK_END_NOTE value associated ! 994: with it, so avoid trashing that. Otherwise, for a new block, install ! 995: a new BLOCK_END_NOTE value. */ ! 996: if (! block_previously_created) ! 997: remember_end_note (block); 1.1.1.4 root 998: } 1.1 root 999: 1000: /* In each subblock, record that this is its superior. */ 1001: 1002: if (keep >= 0) 1003: for (link = subblocks; link; link = TREE_CHAIN (link)) 1004: BLOCK_SUPERCONTEXT (link) = block; 1005: 1006: /* Clear out the meanings of the local variables of this level. */ 1007: 1008: for (link = decls; link; link = TREE_CHAIN (link)) 1009: { 1.1.1.5 root 1010: if (DECL_NAME (link) != NULL_TREE) 1.1 root 1011: { 1012: /* If the ident. was used or addressed via a local extern decl, 1013: don't forget that fact. */ 1.1.1.4 root 1014: if (DECL_EXTERNAL (link)) 1.1 root 1015: { 1016: if (TREE_USED (link)) 1017: TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; 1018: if (TREE_ADDRESSABLE (link)) 1019: TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; 1020: } 1.1.1.5 root 1021: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; 1.1 root 1022: } 1023: } 1024: 1025: /* Restore all name-meanings of the outer levels 1026: that were shadowed by this level. */ 1027: 1028: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) 1029: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 1030: for (link = current_binding_level->class_shadowed; 1031: link; link = TREE_CHAIN (link)) 1032: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 1033: for (link = current_binding_level->type_shadowed; 1034: link; link = TREE_CHAIN (link)) 1035: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 1036: 1037: /* If the level being exited is the top level of a function, 1038: check over all the labels. */ 1039: 1040: if (functionbody) 1041: { 1.1.1.4 root 1042: /* If this is the top level block of a function, 1043: the vars are the function's parameters. 1044: Don't leave them in the BLOCK because they are 1045: found in the FUNCTION_DECL instead. */ 1046: 1047: BLOCK_VARS (block) = 0; 1048: 1.1 root 1049: /* Clear out the definitions of all label names, 1050: since their scopes end here. */ 1051: 1052: for (link = named_labels; link; link = TREE_CHAIN (link)) 1053: { 1.1.1.4 root 1054: register tree label = TREE_VALUE (link); 1055: 1.1.1.5 root 1056: if (DECL_INITIAL (label) == NULL_TREE) 1.1 root 1057: { 1.1.1.6 ! root 1058: cp_error_at ("label `%D' used but not defined", label); 1.1 root 1059: /* Avoid crashing later. */ 1.1.1.4 root 1060: define_label (input_filename, 1, DECL_NAME (label)); 1.1 root 1061: } 1.1.1.4 root 1062: else if (warn_unused && !TREE_USED (label)) 1.1.1.6 ! root 1063: cp_warning_at ("label `%D' defined but not used", label); ! 1064: SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE); 1.1.1.4 root 1065: 1066: /* Put the labels into the "variables" of the 1067: top-level block, so debugger can see them. */ 1068: TREE_CHAIN (label) = BLOCK_VARS (block); 1069: BLOCK_VARS (block) = label; 1.1 root 1070: } 1071: 1.1.1.5 root 1072: named_labels = NULL_TREE; 1.1 root 1073: } 1074: 1075: /* Any uses of undefined labels now operate under constraints 1076: of next binding contour. */ 1077: { 1078: struct binding_level *level_chain; 1079: level_chain = current_binding_level->level_chain; 1080: if (level_chain) 1081: { 1082: tree labels; 1083: for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels)) 1084: if (TREE_TYPE (labels) == (tree)current_binding_level) 1085: { 1086: TREE_TYPE (labels) = (tree)level_chain; 1087: TREE_PURPOSE (labels) = level_chain->names; 1088: } 1089: } 1090: } 1091: 1092: tmp = current_binding_level->keep; 1093: 1094: pop_binding_level (); 1.1.1.4 root 1095: if (functionbody) 1096: DECL_INITIAL (current_function_decl) = block; 1097: else if (block) 1.1 root 1098: { 1.1.1.4 root 1099: if (!block_previously_created) 1100: current_binding_level->blocks 1101: = chainon (current_binding_level->blocks, block); 1.1 root 1102: } 1103: /* If we did not make a block for the level just exited, 1104: any blocks made for inner levels 1105: (since they cannot be recorded as subblocks in that level) 1106: must be carried forward so they will later become subblocks 1107: of something else. */ 1108: else if (subblocks) 1.1.1.6 ! root 1109: { ! 1110: if (keep == 2) ! 1111: current_binding_level->blocks ! 1112: = chainon (subblocks, current_binding_level->blocks); ! 1113: else ! 1114: current_binding_level->blocks ! 1115: = chainon (current_binding_level->blocks, subblocks); ! 1116: } 1.1 root 1117: 1118: /* Take care of compiler's internal binding structures. */ 1119: if (tmp == 2 && !implicit_try_block) 1120: { 1121: #if 0 1122: /* We did not call push_momentary for this 1123: binding contour, so there is nothing to pop. */ 1124: pop_momentary (); 1125: #endif 1126: expand_end_bindings (getdecls (), keep, 1); 1.1.1.6 ! root 1127: /* Each and every BLOCK node created here in `poplevel' is important ! 1128: (e.g. for proper debugging information) so if we created one ! 1129: earlier, mark it as "used". */ ! 1130: if (block) ! 1131: TREE_USED (block) = 1; 1.1 root 1132: block = poplevel (keep, reverse, real_functionbody); 1133: } 1.1.1.6 ! root 1134: ! 1135: /* Each and every BLOCK node created here in `poplevel' is important ! 1136: (e.g. for proper debugging information) so if we created one ! 1137: earlier, mark it as "used". */ 1.1 root 1138: if (block) 1139: TREE_USED (block) = 1; 1140: return block; 1141: } 1142: 1.1.1.4 root 1143: /* Delete the node BLOCK from the current binding level. 1144: This is used for the block inside a stmt expr ({...}) 1145: so that the block can be reinserted where appropriate. */ 1146: 1147: void 1148: delete_block (block) 1149: tree block; 1150: { 1151: tree t; 1152: if (current_binding_level->blocks == block) 1153: current_binding_level->blocks = TREE_CHAIN (block); 1154: for (t = current_binding_level->blocks; t;) 1155: { 1156: if (TREE_CHAIN (t) == block) 1157: TREE_CHAIN (t) = TREE_CHAIN (block); 1158: else 1159: t = TREE_CHAIN (t); 1160: } 1.1.1.5 root 1161: TREE_CHAIN (block) = NULL_TREE; 1.1.1.4 root 1162: /* Clear TREE_USED which is always set by poplevel. 1163: The flag is set again if insert_block is called. */ 1164: TREE_USED (block) = 0; 1165: } 1166: 1167: /* Insert BLOCK at the end of the list of subblocks of the 1168: current binding level. This is used when a BIND_EXPR is expanded, 1169: to handle the BLOCK node inside the BIND_EXPR. */ 1170: 1171: void 1172: insert_block (block) 1173: tree block; 1174: { 1175: TREE_USED (block) = 1; 1176: current_binding_level->blocks 1177: = chainon (current_binding_level->blocks, block); 1178: } 1179: 1.1 root 1180: /* Add BLOCK to the current list of blocks for this binding contour. */ 1181: void 1182: add_block_current_level (block) 1183: tree block; 1184: { 1185: current_binding_level->blocks 1186: = chainon (current_binding_level->blocks, block); 1187: } 1188: 1.1.1.4 root 1189: /* Set the BLOCK node for the innermost scope 1190: (the one we are currently in). */ 1191: 1192: void 1193: set_block (block) 1194: register tree block; 1195: { 1196: current_binding_level->this_block = block; 1197: } 1198: 1.1 root 1199: /* Do a pushlevel for class declarations. */ 1200: void 1201: pushlevel_class () 1202: { 1.1.1.6 ! root 1203: register struct binding_level *newlevel; ! 1204: ! 1205: /* Reuse or create a struct for this binding level. */ ! 1206: #if defined(DEBUG_CP_BINDING_LEVELS) ! 1207: if (0) ! 1208: #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ ! 1209: if (free_binding_level) ! 1210: #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ ! 1211: { ! 1212: newlevel = free_binding_level; ! 1213: free_binding_level = free_binding_level->level_chain; ! 1214: } ! 1215: else ! 1216: { ! 1217: /* Create a new `struct binding_level'. */ ! 1218: newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); ! 1219: } ! 1220: ! 1221: #if defined(DEBUG_CP_BINDING_LEVELS) ! 1222: is_class_level = 1; ! 1223: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ ! 1224: ! 1225: push_binding_level (newlevel, 0, 0); ! 1226: 1.1 root 1227: decl_stack = push_decl_level (decl_stack, &decl_obstack); 1228: class_binding_level = current_binding_level; 1229: class_binding_level->parm_flag = 2; 1.1.1.6 ! root 1230: /* We have just pushed into a new binding level. Now, fake out the rest ! 1231: of the compiler. Set the `current_binding_level' back to point to ! 1232: the most closely containing non-class binding level. */ 1.1 root 1233: do 1234: { 1235: current_binding_level = current_binding_level->level_chain; 1236: } 1237: while (current_binding_level->parm_flag == 2); 1238: } 1239: 1240: /* ...and a poplevel for class declarations. */ 1241: tree 1242: poplevel_class () 1243: { 1244: register struct binding_level *level = class_binding_level; 1.1.1.5 root 1245: tree block = NULL_TREE; 1.1 root 1246: tree shadowed; 1247: 1.1.1.6 ! root 1248: my_friendly_assert (level != 0, 354); ! 1249: 1.1 root 1250: decl_stack = pop_decl_level (decl_stack); 1.1.1.6 ! root 1251: #if !NEW_CLASS_SCOPING 1.1 root 1252: for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) 1253: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); 1254: for (shadowed = level->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) 1255: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); 1256: for (shadowed = level->type_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) 1257: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); 1.1.1.6 ! root 1258: #else ! 1259: for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) ! 1260: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); ! 1261: /* If we're leaving a toplevel class, don't bother to do the setting ! 1262: of IDENTIFER_CLASS_VALUE to NULL_TREE, since first of all this slot ! 1263: shouldn't even be used when current_class_type isn't set, and second, ! 1264: if we don't touch it here, we're able to use the caching effect if the ! 1265: next time we're entering a class scope, it is the same class. */ ! 1266: if (current_class_depth != 1) ! 1267: for (shadowed = level->class_shadowed; ! 1268: shadowed; ! 1269: shadowed = TREE_CHAIN (shadowed)) ! 1270: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); ! 1271: else ! 1272: /* Remember to save what IDENTIFIER's were bound in this scope so we ! 1273: can recover from cache misses. */ ! 1274: previous_class_values = class_binding_level->class_shadowed; ! 1275: for (shadowed = level->type_shadowed; ! 1276: shadowed; ! 1277: shadowed = TREE_CHAIN (shadowed)) ! 1278: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); ! 1279: #endif 1.1 root 1280: 1.1.1.5 root 1281: GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, 1282: (HOST_WIDE_INT) class_binding_level->level_chain, 1.1 root 1283: class_binding_level->parm_flag, 1284: class_binding_level->keep, 1285: class_binding_level->tag_transparent); 1286: 1287: if (class_binding_level->parm_flag != 2) 1.1.1.5 root 1288: class_binding_level = (struct binding_level *)0; 1.1 root 1289: 1.1.1.6 ! root 1290: /* Now, pop out of the the binding level which we created up in the ! 1291: `pushlevel_class' routine. */ ! 1292: #if defined(DEBUG_CP_BINDING_LEVELS) ! 1293: is_class_level = 1; ! 1294: #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ ! 1295: ! 1296: pop_binding_level (); 1.1 root 1297: 1298: return block; 1299: } 1300: 1301: /* For debugging. */ 1302: int no_print_functions = 0; 1303: int no_print_builtins = 0; 1304: 1305: void 1306: print_binding_level (lvl) 1307: struct binding_level *lvl; 1308: { 1309: tree t; 1310: int i = 0, len; 1.1.1.4 root 1311: fprintf (stderr, " blocks="); 1312: fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks); 1313: fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d", 1314: lvl->n_incomplete, lvl->parm_flag, lvl->keep); 1.1 root 1315: if (lvl->tag_transparent) 1316: fprintf (stderr, " tag-transparent"); 1317: if (lvl->more_cleanups_ok) 1318: fprintf (stderr, " more-cleanups-ok"); 1319: if (lvl->have_cleanups) 1320: fprintf (stderr, " have-cleanups"); 1321: if (lvl->more_exceptions_ok) 1322: fprintf (stderr, " more-exceptions-ok"); 1323: if (lvl->have_exceptions) 1324: fprintf (stderr, " have-exceptions"); 1325: fprintf (stderr, "\n"); 1326: if (lvl->names) 1327: { 1328: fprintf (stderr, " names:\t"); 1329: /* We can probably fit 3 names to a line? */ 1330: for (t = lvl->names; t; t = TREE_CHAIN (t)) 1331: { 1332: if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) 1333: continue; 1334: if (no_print_builtins 1335: && (TREE_CODE(t) == TYPE_DECL) 1336: && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>"))) 1337: continue; 1338: 1339: /* Function decls tend to have longer names. */ 1340: if (TREE_CODE (t) == FUNCTION_DECL) 1341: len = 3; 1342: else 1343: len = 2; 1344: i += len; 1345: if (i > 6) 1346: { 1347: fprintf (stderr, "\n\t"); 1348: i = len; 1349: } 1350: print_node_brief (stderr, "", t, 0); 1351: if (TREE_CODE (t) == ERROR_MARK) 1352: break; 1353: } 1354: if (i) 1355: fprintf (stderr, "\n"); 1356: } 1357: if (lvl->tags) 1358: { 1359: fprintf (stderr, " tags:\t"); 1360: i = 0; 1361: for (t = lvl->tags; t; t = TREE_CHAIN (t)) 1362: { 1363: if (TREE_PURPOSE (t) == NULL_TREE) 1364: len = 3; 1.1.1.3 root 1365: else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) 1.1 root 1366: len = 2; 1367: else 1368: len = 4; 1369: i += len; 1370: if (i > 5) 1371: { 1372: fprintf (stderr, "\n\t"); 1373: i = len; 1374: } 1375: if (TREE_PURPOSE (t) == NULL_TREE) 1376: { 1377: print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0); 1378: fprintf (stderr, ">"); 1379: } 1.1.1.3 root 1380: else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) 1.1 root 1381: print_node_brief (stderr, "", TREE_VALUE (t), 0); 1382: else 1383: { 1384: print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0); 1385: print_node_brief (stderr, "", TREE_VALUE (t), 0); 1386: fprintf (stderr, ">"); 1387: } 1388: } 1389: if (i) 1390: fprintf (stderr, "\n"); 1391: } 1392: if (lvl->shadowed) 1393: { 1394: fprintf (stderr, " shadowed:"); 1395: for (t = lvl->shadowed; t; t = TREE_CHAIN (t)) 1396: { 1397: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); 1398: } 1399: fprintf (stderr, "\n"); 1400: } 1401: if (lvl->class_shadowed) 1402: { 1403: fprintf (stderr, " class-shadowed:"); 1404: for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t)) 1405: { 1406: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); 1407: } 1408: fprintf (stderr, "\n"); 1409: } 1410: if (lvl->type_shadowed) 1411: { 1412: fprintf (stderr, " type-shadowed:"); 1413: for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) 1414: { 1415: #if 0 1416: fprintf (stderr, "\n\t"); 1417: print_node_brief (stderr, "<", TREE_PURPOSE (t), 0); 1418: if (TREE_VALUE (t)) 1419: print_node_brief (stderr, " ", TREE_VALUE (t), 0); 1420: else 1421: fprintf (stderr, " (none)"); 1422: fprintf (stderr, ">"); 1423: #else 1424: fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); 1425: #endif 1426: } 1427: fprintf (stderr, "\n"); 1428: } 1429: } 1430: 1431: void 1432: print_other_binding_stack (stack) 1433: struct binding_level *stack; 1434: { 1435: struct binding_level *level; 1436: for (level = stack; level != global_binding_level; level = level->level_chain) 1437: { 1.1.1.4 root 1438: fprintf (stderr, "binding level "); 1439: fprintf (stderr, HOST_PTR_PRINTF, level); 1440: fprintf (stderr, "\n"); 1.1 root 1441: print_binding_level (level); 1442: } 1443: } 1444: 1445: void 1446: print_binding_stack () 1447: { 1448: struct binding_level *b; 1.1.1.4 root 1449: fprintf (stderr, "current_binding_level="); 1450: fprintf (stderr, HOST_PTR_PRINTF, current_binding_level); 1451: fprintf (stderr, "\nclass_binding_level="); 1452: fprintf (stderr, HOST_PTR_PRINTF, class_binding_level); 1453: fprintf (stderr, "\nglobal_binding_level="); 1454: fprintf (stderr, HOST_PTR_PRINTF, global_binding_level); 1455: fprintf (stderr, "\n"); 1.1 root 1456: if (class_binding_level) 1457: { 1458: for (b = class_binding_level; b; b = b->level_chain) 1459: if (b == current_binding_level) 1460: break; 1461: if (b) 1462: b = class_binding_level; 1463: else 1464: b = current_binding_level; 1465: } 1466: else 1467: b = current_binding_level; 1468: print_other_binding_stack (b); 1469: fprintf (stderr, "global:\n"); 1470: print_binding_level (global_binding_level); 1471: } 1472: 1473: /* Subroutines for reverting temporarily to top-level for instantiation 1474: of templates and such. We actually need to clear out the class- and 1475: local-value slots of all identifiers, so that only the global values 1476: are at all visible. Simply setting current_binding_level to the global 1477: scope isn't enough, because more binding levels may be pushed. */ 1478: struct saved_scope { 1479: struct binding_level *old_binding_level; 1480: tree old_bindings; 1481: struct saved_scope *prev; 1482: tree class_name, class_type, class_decl, function_decl; 1483: struct binding_level *class_bindings; 1.1.1.6 ! root 1484: tree previous_class_type; 1.1 root 1485: }; 1486: static struct saved_scope *current_saved_scope; 1487: extern tree prev_class_type; 1488: 1489: void 1490: push_to_top_level () 1491: { 1492: struct saved_scope *s = 1493: (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); 1494: struct binding_level *b = current_binding_level; 1495: tree old_bindings = NULL_TREE; 1496: 1497: /* Have to include global_binding_level, because class-level decls 1498: aren't listed anywhere useful. */ 1499: for (; b; b = b->level_chain) 1500: { 1501: tree t; 1502: for (t = b->names; t; t = TREE_CHAIN (t)) 1503: if (b != global_binding_level) 1504: { 1505: tree binding, t1, t2 = t; 1506: tree id = DECL_ASSEMBLER_NAME (t2); 1507: 1508: if (!id 1509: || (!IDENTIFIER_LOCAL_VALUE (id) 1510: && !IDENTIFIER_CLASS_VALUE (id))) 1511: continue; 1512: 1513: for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) 1514: if (TREE_VEC_ELT (t1, 0) == id) 1515: goto skip_it; 1516: 1517: binding = make_tree_vec (4); 1518: if (id) 1519: { 1.1.1.4 root 1520: my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); 1.1 root 1521: TREE_VEC_ELT (binding, 0) = id; 1522: TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id); 1523: TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); 1524: TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); 1.1.1.5 root 1525: IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; 1526: IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; 1.1.1.6 ! root 1527: #if !NEW_CLASS_SCOPING ! 1528: /* The type unwinding below should take care of this. */ 1.1 root 1529: adjust_type_value (id); 1.1.1.6 ! root 1530: #endif 1.1 root 1531: } 1532: TREE_CHAIN (binding) = old_bindings; 1533: old_bindings = binding; 1534: skip_it: 1535: ; 1536: } 1537: /* Unwind type-value slots back to top level. */ 1538: if (b != global_binding_level) 1539: for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) 1540: SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); 1541: } 1542: 1543: s->old_binding_level = current_binding_level; 1544: current_binding_level = global_binding_level; 1545: 1546: s->class_name = current_class_name; 1547: s->class_type = current_class_type; 1548: s->class_decl = current_class_decl; 1549: s->function_decl = current_function_decl; 1550: s->class_bindings = class_binding_level; 1.1.1.6 ! root 1551: s->previous_class_type = previous_class_type; 1.1.1.5 root 1552: current_class_name = current_class_type = current_class_decl = NULL_TREE; 1553: current_function_decl = NULL_TREE; 1554: class_binding_level = (struct binding_level *)0; 1.1.1.6 ! root 1555: previous_class_type = NULL_TREE; 1.1 root 1556: 1557: s->prev = current_saved_scope; 1558: s->old_bindings = old_bindings; 1559: current_saved_scope = s; 1560: } 1561: 1562: void 1563: pop_from_top_level () 1564: { 1565: struct saved_scope *s = current_saved_scope; 1566: tree t; 1567: 1.1.1.6 ! root 1568: if (previous_class_type) ! 1569: previous_class_type = NULL_TREE; 1.1 root 1570: 1571: current_binding_level = s->old_binding_level; 1572: current_saved_scope = s->prev; 1573: for (t = s->old_bindings; t; t = TREE_CHAIN (t)) 1574: { 1575: tree id = TREE_VEC_ELT (t, 0); 1576: if (id) 1577: { 1578: IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1); 1579: IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2); 1580: IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); 1581: } 1582: } 1583: current_class_name = s->class_name; 1584: current_class_type = s->class_type; 1.1.1.3 root 1585: current_class_decl = s->class_decl; 1.1.1.2 root 1586: if (current_class_type) 1587: C_C_D = CLASSTYPE_INST_VAR (current_class_type); 1588: else 1589: C_C_D = NULL_TREE; 1.1 root 1590: current_function_decl = s->function_decl; 1591: class_binding_level = s->class_bindings; 1.1.1.6 ! root 1592: previous_class_type = s->previous_class_type; 1.1 root 1593: free (s); 1594: } 1595: 1596: /* Push a definition of struct, union or enum tag "name". 1597: "type" should be the type node. 1598: We assume that the tag "name" is not already defined. 1599: 1600: Note that the definition may really be just a forward reference. 1.1.1.5 root 1601: In that case, the TYPE_SIZE will be a NULL_TREE. 1.1 root 1602: 1603: C++ gratuitously puts all these tags in the name space. */ 1604: 1.1.1.2 root 1605: /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, 1.1 root 1606: record the shadowed value for this binding contour. TYPE is 1607: the type that ID maps to. */ 1608: void 1609: set_identifier_type_value (id, type) 1610: tree id; 1611: tree type; 1612: { 1.1.1.6 ! root 1613: #if NEW_CLASS_SCOPING ! 1614: if (class_binding_level) ! 1615: { ! 1616: tree old_type_value = IDENTIFIER_TYPE_VALUE (id); ! 1617: class_binding_level->type_shadowed ! 1618: = tree_cons (id, old_type_value, class_binding_level->type_shadowed); ! 1619: } ! 1620: else if (current_binding_level != global_binding_level) ! 1621: { ! 1622: tree old_type_value = IDENTIFIER_TYPE_VALUE (id); ! 1623: current_binding_level->type_shadowed ! 1624: = tree_cons (id, old_type_value, current_binding_level->type_shadowed); ! 1625: } ! 1626: #else 1.1 root 1627: if (current_binding_level != global_binding_level) 1628: { 1629: tree old_type_value = IDENTIFIER_TYPE_VALUE (id); 1630: current_binding_level->type_shadowed 1631: = tree_cons (id, old_type_value, current_binding_level->type_shadowed); 1632: } 1633: else if (class_binding_level) 1634: { 1635: tree old_type_value = IDENTIFIER_TYPE_VALUE (id); 1636: class_binding_level->type_shadowed 1637: = tree_cons (id, old_type_value, class_binding_level->type_shadowed); 1638: } 1.1.1.6 ! root 1639: #endif 1.1 root 1640: SET_IDENTIFIER_TYPE_VALUE (id, type); 1641: } 1642: 1643: /* 1644: * local values can need to be shadowed too, but it only happens 1645: * explicitly from pushdecl, in support of nested enums. 1646: */ 1647: void 1648: set_identifier_local_value (id, type) 1649: tree id; 1650: tree type; 1651: { 1652: if (current_binding_level != global_binding_level) 1653: { 1654: tree old_local_value = IDENTIFIER_LOCAL_VALUE (id); 1655: current_binding_level->shadowed 1656: = tree_cons (id, old_local_value, current_binding_level->shadowed); 1657: } 1658: else if (class_binding_level) 1659: { 1660: tree old_local_value = IDENTIFIER_LOCAL_VALUE (id); 1661: class_binding_level->shadowed 1662: = tree_cons (id, old_local_value, class_binding_level->shadowed); 1663: } 1664: IDENTIFIER_LOCAL_VALUE (id) = type; 1.1.1.6 ! root 1665: ! 1666: #if NEW_CLASS_SCOPING ! 1667: /* If this is a TYPE_DECL, push it into the type value slot. */ ! 1668: if (TREE_CODE (type) == TYPE_DECL) ! 1669: set_identifier_type_value (id, TREE_TYPE (type)); ! 1670: #endif 1.1 root 1671: } 1672: 1673: /* Subroutine "set_nested_typename" builds the nested-typename of 1674: the type decl in question. (Argument CLASSNAME can actually be 1675: a function as well, if that's the smallest containing scope.) */ 1676: 1677: static void 1678: set_nested_typename (decl, classname, name, type) 1679: tree decl, classname, name, type; 1680: { 1.1.1.4 root 1681: my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136); 1.1.1.5 root 1682: if (classname != NULL_TREE) 1.1 root 1683: { 1684: char *buf; 1.1.1.4 root 1685: my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137); 1686: my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138); 1.1 root 1687: buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname) 1688: + IDENTIFIER_LENGTH (name)); 1689: sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname), 1690: IDENTIFIER_POINTER (name)); 1691: DECL_NESTED_TYPENAME (decl) = get_identifier (buf); 1.1.1.6 ! root 1692: ! 1693: /* When NEW_CLASS_SCOPING is set to 1: ! 1694: ! 1695: This is a special usage of IDENTIFIER_TYPE_VALUE which have no ! 1696: correspondence in any binding_level. This is ok since the ! 1697: DECL_NESTED_TYPENAME is just a convenience identifier whose ! 1698: IDENTIFIER_TYPE_VALUE will remain constant from now on. */ 1.1 root 1699: SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type); 1700: } 1701: else 1702: DECL_NESTED_TYPENAME (decl) = name; 1703: } 1704: 1.1.1.2 root 1705: #if 0 /* not yet, should get fixed properly later */ 1706: /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME. 1707: Other routines shouldn't use build_decl directly; they'll produce 1708: incorrect results with `-g' unless they duplicate this code. 1709: 1710: This is currently needed mainly for dbxout.c, but we can make 1711: use of it in cp-method.c later as well. */ 1712: tree 1713: make_type_decl (name, type) 1714: tree name, type; 1715: { 1716: tree decl, id; 1717: decl = build_decl (TYPE_DECL, name, type); 1718: if (TYPE_NAME (type) == name) 1719: /* Class/union/enum definition, or a redundant typedef for same. */ 1720: { 1721: id = get_identifier (build_overload_name (type, 1, 1)); 1722: DECL_ASSEMBLER_NAME (decl) = id; 1723: } 1724: else if (TYPE_NAME (type) != NULL_TREE) 1725: /* Explicit typedef, or implicit typedef for template expansion. */ 1726: DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type)); 1727: else 1728: { 1.1.1.6 ! root 1729: /* XXX: Typedef for unnamed struct; some other situations. 1.1.1.2 root 1730: TYPE_NAME is null; what's right here? */ 1731: } 1732: return decl; 1733: } 1734: #endif 1.1.1.6 ! root 1735: 1.1 root 1736: void 1737: pushtag (name, type) 1738: tree name, type; 1739: { 1740: register struct binding_level *b; 1741: 1742: if (class_binding_level) 1743: b = class_binding_level; 1744: else 1745: { 1746: b = current_binding_level; 1747: while (b->tag_transparent) b = b->level_chain; 1748: } 1749: 1.1.1.4 root 1750: if (b == global_binding_level) 1751: b->tags = perm_tree_cons (name, type, b->tags); 1752: else 1753: b->tags = saveable_tree_cons (name, type, b->tags); 1754: 1.1 root 1755: if (name) 1756: { 1757: /* Record the identifier as the type's name if it has none. */ 1758: 1.1.1.5 root 1759: if (TYPE_NAME (type) == NULL_TREE) 1.1 root 1760: TYPE_NAME (type) = name; 1.1.1.2 root 1761: 1.1 root 1762: /* Do C++ gratuitous typedefing. */ 1763: if (IDENTIFIER_TYPE_VALUE (name) != type 1764: && (TREE_CODE (type) != RECORD_TYPE 1.1.1.5 root 1765: || class_binding_level == (struct binding_level *)0 1.1 root 1766: || !CLASSTYPE_DECLARED_EXCEPTION (type))) 1767: { 1768: register tree d; 1.1.1.5 root 1769: if (current_class_type == NULL_TREE 1.1 root 1770: || TYPE_SIZE (current_class_type) != NULL_TREE) 1771: { 1772: if (current_lang_name == lang_name_cplusplus) 1773: d = lookup_nested_type (type, current_class_type ? TYPE_NAME (current_class_type) : NULL_TREE); 1774: else 1775: d = NULL_TREE; 1776: 1777: if (d == NULL_TREE) 1778: { 1.1.1.2 root 1779: #if 0 /* not yet, should get fixed properly later */ 1780: d = make_type_decl (name, type); 1781: DECL_ASSEMBLER_NAME (d) = get_identifier (build_overload_name (type, 1, 1)); 1782: #else 1.1 root 1783: d = build_decl (TYPE_DECL, name, type); 1.1.1.4 root 1784: DECL_ASSEMBLER_NAME (d) = get_identifier (build_overload_name (type, 1, 1)); 1.1.1.2 root 1785: #endif 1.1.1.6 ! root 1786: #ifdef DWARF_DEBUGGING_INFO ! 1787: if (write_symbols == DWARF_DEBUG) ! 1788: { ! 1789: /* Mark the TYPE_DECL node we created just above as an ! 1790: gratuitous one. We need to do this so that dwarfout.c ! 1791: will understand that it is not supposed to output a ! 1792: TAG_typedef DIE for it. */ ! 1793: DECL_IGNORED_P (d) = 1; ! 1794: } ! 1795: #endif /* DWARF_DEBUGGING_INFO */ 1.1 root 1796: set_identifier_type_value (name, type); 1797: } 1798: else 1799: d = TYPE_NAME (d); 1800: 1801: /* If it is anonymous, then we are called from pushdecl, 1802: and we don't want to infinitely recurse. Also, if the 1803: name is already in scope, we don't want to push it 1804: again--pushdecl is only for pushing new decls. */ 1805: if (! ANON_AGGRNAME_P (name) 1.1.1.4 root 1806: && TYPE_NAME (type) 1.1 root 1807: && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL 1808: || lookup_name (name, 1) != TYPE_NAME (type))) 1809: { 1810: if (class_binding_level) 1811: d = pushdecl_class_level (d); 1812: else 1813: d = pushdecl (d); 1814: } 1815: } 1816: else 1817: { 1818: /* Make nested declarations go into class-level scope. */ 1819: d = build_lang_field_decl (TYPE_DECL, name, type); 1.1.1.6 ! root 1820: #ifdef DWARF_DEBUGGING_INFO ! 1821: if (write_symbols == DWARF_DEBUG) ! 1822: { ! 1823: /* Mark the TYPE_DECL node we created just above as an ! 1824: gratuitous one. We need to do this so that dwarfout.c ! 1825: will understand that it is not supposed to output a ! 1826: TAG_typedef DIE for it. */ ! 1827: DECL_IGNORED_P (d) = 1; ! 1828: } ! 1829: #endif /* DWARF_DEBUGGING_INFO */ ! 1830: #if !NEW_CLASS_SCOPING 1.1 root 1831: set_identifier_type_value (name, type); 1.1.1.6 ! root 1832: #else ! 1833: /* Make sure we're in this type's scope when we push the ! 1834: decl for a template, otherwise class_binding_level will ! 1835: be NULL and we'll end up dying inside of ! 1836: push_class_level_binding. */ ! 1837: if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) ! 1838: pushclass (type, 0); 1.1 root 1839: d = pushdecl_class_level (d); 1.1.1.6 ! root 1840: if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) ! 1841: popclass (0); ! 1842: #endif ! 1843: } ! 1844: if (write_symbols != DWARF_DEBUG) ! 1845: { ! 1846: if (ANON_AGGRNAME_P (name)) ! 1847: DECL_IGNORED_P (d) = 1; 1.1 root 1848: } 1849: TYPE_NAME (type) = d; 1850: 1851: if ((current_class_type == NULL_TREE 1852: && current_function_decl == NULL_TREE) 1853: || current_lang_name != lang_name_cplusplus) 1854: /* Non-nested class. */ 1855: DECL_NESTED_TYPENAME (d) = name; 1856: else if (current_function_decl != NULL_TREE) 1857: { 1858: /* Function-nested class. */ 1859: set_nested_typename (d, DECL_ASSEMBLER_NAME (current_function_decl), 1860: name, type); 1861: /* This builds the links for classes nested in fn scope. */ 1862: DECL_CONTEXT (d) = current_function_decl; 1863: } 1864: else if (TYPE_SIZE (current_class_type) == NULL_TREE) 1865: { 1866: /* Class-nested class. */ 1867: set_nested_typename (d, DECL_NESTED_TYPENAME (TYPE_NAME (current_class_type)), 1868: name, type); 1869: /* This builds the links for classes nested in type scope. */ 1870: DECL_CONTEXT (d) = current_class_type; 1871: DECL_CLASS_CONTEXT (d) = current_class_type; 1872: } 1.1.1.6 ! root 1873: TYPE_CONTEXT (type) = DECL_CONTEXT (d); 1.1 root 1874: } 1875: if (b->parm_flag == 2) 1876: { 1877: TREE_NONLOCAL_FLAG (type) = 1; 1.1.1.6 ! root 1878: #if !NEW_CLASS_SCOPING 1.1 root 1879: IDENTIFIER_CLASS_VALUE (name) = TYPE_NAME (type); 1.1.1.6 ! root 1880: #endif 1.1 root 1881: if (TYPE_SIZE (current_class_type) == NULL_TREE) 1882: CLASSTYPE_TAGS (current_class_type) = b->tags; 1883: } 1.1.1.4 root 1884: } 1.1 root 1885: 1.1.1.4 root 1886: if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) 1887: /* Use the canonical TYPE_DECL for this node. */ 1888: TYPE_STUB_DECL (type) = TYPE_NAME (type); 1889: else 1890: { 1891: /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE 1892: will be the tagged type we just added to the current 1893: binding level. This fake NULL-named TYPE_DECL node helps 1894: dwarfout.c to know when it needs to output a 1895: representation of a tagged type, and it also gives us a 1896: convenient place to record the "scope start" address for 1897: the tagged type. */ 1.1 root 1898: 1.1.1.2 root 1899: #if 0 /* not yet, should get fixed properly later */ 1.1.1.6 ! root 1900: TYPE_STUB_DECL (type) = pushdecl (make_type_decl (NULL_TREE, type)); 1.1.1.2 root 1901: #else 1.1.1.5 root 1902: TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type)); 1.1.1.2 root 1903: #endif 1.1 root 1904: } 1905: } 1906: 1907: /* Counter used to create anonymous type names. */ 1908: static int anon_cnt = 0; 1909: 1910: /* Return an IDENTIFIER which can be used as a name for 1911: anonymous structs and unions. */ 1912: tree 1913: make_anon_name () 1914: { 1915: char buf[32]; 1916: 1917: sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++); 1918: return get_identifier (buf); 1919: } 1920: 1921: /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. 1922: This keeps dbxout from getting confused. */ 1923: void 1924: clear_anon_tags () 1925: { 1.1.1.4 root 1926: register struct binding_level *b; 1.1 root 1927: register tree tags; 1928: static int last_cnt = 0; 1929: 1930: /* Fast out if no new anon names were declared. */ 1931: if (last_cnt == anon_cnt) 1932: return; 1933: 1.1.1.4 root 1934: b = current_binding_level; 1935: while (b->tag_transparent) 1936: b = b->level_chain; 1.1 root 1937: tags = b->tags; 1938: while (tags) 1939: { 1940: /* A NULL purpose means we have already processed all tags 1941: from here to the end of the list. */ 1942: if (TREE_PURPOSE (tags) == NULL_TREE) 1943: break; 1944: if (ANON_AGGRNAME_P (TREE_PURPOSE (tags))) 1945: TREE_PURPOSE (tags) = NULL_TREE; 1946: tags = TREE_CHAIN (tags); 1947: } 1948: last_cnt = anon_cnt; 1949: } 1950: 1951: /* Subroutine of duplicate_decls: return truthvalue of whether 1.1.1.6 ! root 1952: or not types of these decls match. ! 1953: ! 1954: For C++, we must compare the parameter list so that `int' can match ! 1955: `int&' in a parameter position, but `int&' is not confused with ! 1956: `const int&'. */ 1.1 root 1957: static int 1958: decls_match (newdecl, olddecl) 1959: tree newdecl, olddecl; 1960: { 1961: int types_match; 1962: 1963: if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL) 1964: { 1965: tree f1 = TREE_TYPE (newdecl); 1966: tree f2 = TREE_TYPE (olddecl); 1967: tree p1 = TYPE_ARG_TYPES (f1); 1968: tree p2 = TYPE_ARG_TYPES (f2); 1969: 1970: /* When we parse a static member function definition, 1971: we put together a FUNCTION_DECL which thinks its type 1972: is METHOD_TYPE. Change that to FUNCTION_TYPE, and 1973: proceed. */ 1.1.1.4 root 1974: if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) 1975: revert_static_member_fn (&f1, &newdecl, &p1); 1976: else if (TREE_CODE (f2) == METHOD_TYPE 1977: && DECL_STATIC_FUNCTION_P (newdecl)) 1978: revert_static_member_fn (&f2, &olddecl, &p2); 1979: 1.1 root 1980: /* Here we must take care of the case where new default 1981: parameters are specified. Also, warn if an old 1982: declaration becomes ambiguous because default 1983: parameters may cause the two to be ambiguous. */ 1984: if (TREE_CODE (f1) != TREE_CODE (f2)) 1985: { 1986: if (TREE_CODE (f1) == OFFSET_TYPE) 1.1.1.6 ! root 1987: cp_compiler_error ("`%D' redeclared as member function", newdecl); 1.1 root 1988: else 1.1.1.6 ! root 1989: cp_compiler_error ("`%D' redeclared as non-member function", newdecl); 1.1 root 1990: return 0; 1991: } 1992: 1993: if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)), 1.1.1.6 ! root 1994: TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 2)) ! 1995: types_match = compparms (p1, p2, 2); ! 1996: else ! 1997: types_match = 0; 1.1 root 1998: } 1999: else 2000: { 2001: if (TREE_TYPE (newdecl) == error_mark_node) 2002: types_match = TREE_TYPE (olddecl) == error_mark_node; 1.1.1.4 root 2003: else if (TREE_TYPE (olddecl) == NULL_TREE) 2004: types_match = TREE_TYPE (newdecl) == NULL_TREE; 1.1 root 2005: else 2006: types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1); 2007: } 2008: 2009: return types_match; 2010: } 2011: 2012: /* Handle when a new declaration NEWDECL has the same name as an old 2013: one OLDDECL in the same binding contour. Prints an error message 2014: if appropriate. 2015: 2016: If safely possible, alter OLDDECL to look like NEWDECL, and return 1. 2017: Otherwise, return 0. */ 2018: 2019: static int 2020: duplicate_decls (newdecl, olddecl) 2021: register tree newdecl, olddecl; 2022: { 2023: extern struct obstack permanent_obstack; 1.1.1.4 root 2024: unsigned olddecl_uid = DECL_UID (olddecl); 1.1.1.6 ! root 2025: int olddecl_friend = 0, types_match = 0; 1.1.1.4 root 2026: int new_defines_function; 1.1 root 2027: 2028: if (TREE_CODE (olddecl) == TREE_LIST 2029: && TREE_CODE (newdecl) == FUNCTION_DECL) 2030: { 2031: /* If a new decl finds a list of old decls, then 2032: we assume that the new decl has C linkage, and 2033: that the old decls have C++ linkage. In this case, 2034: we must look through the list to see whether 2035: there is an ambiguity or not. */ 2036: tree olddecls = olddecl; 1.1.1.6 ! root 2037: tree previous_c_decl = NULL_TREE; 1.1 root 2038: 2039: /* If the overload list is empty, just install the decl. */ 2040: if (TREE_VALUE (olddecls) == NULL_TREE) 2041: { 2042: TREE_VALUE (olddecls) = newdecl; 2043: return 1; 2044: } 2045: 2046: while (olddecls) 2047: { 1.1.1.6 ! root 2048: if (DECL_LANGUAGE (TREE_VALUE (olddecls)) == lang_c) ! 2049: previous_c_decl = TREE_VALUE (olddecls); ! 2050: 1.1 root 2051: if (decls_match (newdecl, TREE_VALUE (olddecls))) 2052: { 2053: if (TREE_CODE (newdecl) == VAR_DECL) 2054: ; 2055: else if (DECL_LANGUAGE (newdecl) 2056: != DECL_LANGUAGE (TREE_VALUE (olddecls))) 2057: { 1.1.1.6 ! root 2058: cp_error ! 2059: ("declaration of `%#D' with different language linkage", ! 2060: newdecl); ! 2061: cp_error_at ("previous declaration here", TREE_VALUE (olddecls)); 1.1 root 2062: } 2063: types_match = 1; 2064: break; 2065: } 2066: olddecls = TREE_CHAIN (olddecls); 2067: } 2068: if (olddecls) 1.1.1.6 ! root 2069: olddecl = TREE_VALUE (olddecls); 1.1 root 2070: else 1.1.1.6 ! root 2071: { ! 2072: if (previous_c_decl != NULL_TREE ! 2073: && DECL_LANGUAGE (newdecl) == lang_c) ! 2074: { ! 2075: cp_error ("declaration of C function `%#D' conflicts with previous declaration", newdecl); ! 2076: cp_error_at ("`%#D' declared previously at this point in file", previous_c_decl); ! 2077: } ! 2078: else ! 2079: { ! 2080: /* If we found no match, make this join the other ! 2081: overloaded decls. */ ! 2082: DECL_OVERLOADED (newdecl) = 1; ! 2083: } ! 2084: return 1; ! 2085: } 1.1 root 2086: } 2087: else 1.1.1.4 root 2088: { 2089: if (TREE_CODE (olddecl) != TREE_LIST) 2090: olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl); 2091: types_match = decls_match (newdecl, olddecl); 2092: } 1.1 root 2093: 1.1.1.6 ! root 2094: /* If either the type of the new decl or the type of the old decl is an ! 2095: error_mark_node, then that implies that we have already issued an ! 2096: error (earlier) for some bogus type specification, and in that case, ! 2097: it is rather pointless to harass the user with yet more error message ! 2098: about the same declaration, so well just pretent the types match here. */ ! 2099: if ((TREE_TYPE (newdecl) ! 2100: && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK) ! 2101: || (TREE_TYPE (olddecl) ! 2102: && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK)) ! 2103: types_match = 1; 1.1 root 2104: 2105: /* If this decl has linkage, and the old one does too, maybe no error. */ 2106: if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) 2107: { 1.1.1.6 ! root 2108: cp_error ("`%#D' redeclared as different kind of symbol", newdecl); 1.1 root 2109: if (TREE_CODE (olddecl) == TREE_LIST) 2110: olddecl = TREE_VALUE (olddecl); 1.1.1.6 ! root 2111: cp_error_at ("previous declaration of `%#D'", olddecl); 1.1 root 2112: 2113: /* New decl is completely inconsistent with the old one => 2114: tell caller to replace the old one. */ 2115: 2116: return 0; 2117: } 2118: 2119: if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL 2120: && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl) 2121: /* If -traditional, avoid error for redeclaring fcn 2122: after implicit decl. */ 2123: ; 1.1.1.6 ! root 2124: else if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_BUILT_IN (olddecl)) 1.1 root 2125: { 1.1.1.6 ! root 2126: /* A function declaration for a built-in function. */ ! 2127: if (!TREE_PUBLIC (newdecl)) ! 2128: { ! 2129: /* If you declare a built-in function name as static, the ! 2130: built-in definition is overridden, ! 2131: but optionally warn this was a bad choice of name. */ ! 2132: if (warn_shadow) ! 2133: cp_warning ("shadowing built-in function `%#D'", newdecl); ! 2134: /* Discard the old built-in function. */ ! 2135: return 0; ! 2136: } 1.1 root 2137: if (!types_match) 2138: { 1.1.1.6 ! root 2139: cp_warning ("declaration of `%#D'", newdecl); ! 2140: cp_warning ("conflicts with built-in declaration `%#D'", ! 2141: olddecl); ! 2142: return 0; 1.1 root 2143: } 2144: } 2145: else if (!types_match) 2146: { 2147: tree oldtype = TREE_TYPE (olddecl); 2148: tree newtype = TREE_TYPE (newdecl); 2149: int give_error = 0; 2150: 2151: /* Already complained about this, so don't do so again. */ 2152: if (current_class_type == NULL_TREE 2153: || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) 2154: { 2155: give_error = 1; 1.1.1.6 ! root 2156: ! 2157: /* Since we're doing this before finish_struct can set the ! 2158: line number on NEWDECL, we just do a regular error here. */ ! 2159: if (DECL_SOURCE_LINE (newdecl) == 0) ! 2160: cp_error ("conflicting types for `%#D'", newdecl); ! 2161: else ! 2162: cp_error_at ("conflicting types for `%#D'", newdecl); 1.1 root 2163: } 2164: 2165: /* Check for function type mismatch 2166: involving an empty arglist vs a nonempty one. */ 2167: if (TREE_CODE (olddecl) == FUNCTION_DECL 2168: && comptypes (TREE_TYPE (oldtype), 2169: TREE_TYPE (newtype), 1) 1.1.1.5 root 2170: && ((TYPE_ARG_TYPES (oldtype) == NULL_TREE 2171: && DECL_INITIAL (olddecl) == NULL_TREE) 2172: || (TYPE_ARG_TYPES (newtype) == NULL_TREE 2173: && DECL_INITIAL (newdecl) == NULL_TREE))) 1.1 root 2174: { 2175: /* Classify the problem further. */ 2176: register tree t = TYPE_ARG_TYPES (oldtype); 1.1.1.6 ! root 2177: 1.1.1.5 root 2178: if (t == NULL_TREE) 1.1 root 2179: t = TYPE_ARG_TYPES (newtype); 2180: for (; t; t = TREE_CHAIN (t)) 2181: { 2182: register tree type = TREE_VALUE (t); 2183: 1.1.1.5 root 2184: if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node) 1.1 root 2185: { 1.1.1.6 ! root 2186: give_error = 1; 1.1 root 2187: error ("A parameter list with an ellipsis can't match"); 2188: error ("an empty parameter name list declaration."); 2189: break; 2190: } 2191: 1.1.1.4 root 2192: if (TYPE_MAIN_VARIANT (type) == float_type_node 2193: || C_PROMOTING_INTEGER_TYPE_P (type)) 1.1 root 2194: { 1.1.1.6 ! root 2195: give_error = 1; 1.1 root 2196: error ("An argument type that has a default promotion"); 2197: error ("can't match an empty parameter name list declaration."); 2198: break; 2199: } 2200: } 2201: } 2202: if (give_error) 1.1.1.6 ! root 2203: cp_error_at ("previous declaration as `%#D'", olddecl); 1.1 root 2204: 2205: /* There is one thing GNU C++ cannot tolerate: a constructor 2206: which takes the type of object being constructed. 2207: Farm that case out here. */ 2208: if (TREE_CODE (newdecl) == FUNCTION_DECL 2209: && DECL_CONSTRUCTOR_P (newdecl)) 2210: { 2211: tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype)); 2212: 2213: if (tmp != NULL_TREE 2214: && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp)) 2215: == TYPE_METHOD_BASETYPE (newtype))) 2216: { 2217: tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl)); 2218: tree argtypes 2219: = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)), 2220: TREE_CHAIN (tmp)); 2221: 2222: DECL_ARG_TYPE (parm) 2223: = TREE_TYPE (parm) 2224: = TYPE_REFERENCE_TO (TREE_VALUE (tmp)); 2225: 2226: TREE_TYPE (newdecl) = newtype 2227: = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype), 2228: TREE_TYPE (newtype), argtypes); 2229: error ("constructor cannot take as argument the type being constructed"); 2230: SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl), current_class_type); 2231: } 2232: } 2233: } 2234: else 2235: { 2236: char *errmsg = redeclaration_error_message (newdecl, olddecl); 2237: if (errmsg) 2238: { 2239: error_with_decl (newdecl, errmsg); 2240: if (DECL_NAME (olddecl) != NULL_TREE) 1.1.1.6 ! root 2241: cp_error_at ((DECL_INITIAL (olddecl) ! 2242: && current_binding_level == global_binding_level) ! 2243: ? "`%#D' previously defined here" ! 2244: : "`%#D' previously declared here", olddecl); 1.1 root 2245: } 2246: else if (TREE_CODE (olddecl) == FUNCTION_DECL 1.1.1.5 root 2247: && DECL_INITIAL (olddecl) != NULL_TREE 2248: && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE 2249: && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE) 1.1 root 2250: { 2251: /* Prototype decl follows defn w/o prototype. */ 1.1.1.6 ! root 2252: cp_warning_at ("prototype for `%#D'", newdecl); ! 2253: cp_warning_at ("follows non-prototype definition here", olddecl); 1.1 root 2254: } 1.1.1.6 ! root 2255: else if (TREE_CODE (olddecl) == FUNCTION_DECL ! 2256: && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)) ! 2257: /* extern "C" int foo (); ! 2258: int foo () { bar (); } ! 2259: is OK. */ ! 2260: if (current_lang_stack == current_lang_base) ! 2261: DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); ! 2262: else ! 2263: { ! 2264: cp_error_at ("previous declaration of `%#D' with %L linkage", ! 2265: olddecl, DECL_LANGUAGE (olddecl)); ! 2266: cp_error ("conflicts with new declaration with %L linkage", ! 2267: DECL_LANGUAGE (newdecl)); ! 2268: } 1.1 root 2269: 2270: /* These bits are logically part of the type. */ 2271: if (pedantic 2272: && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl) 2273: || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))) 1.1.1.6 ! root 2274: cp_error_at ("type qualifiers for `%D' conflict with previous decl", newdecl); ! 2275: } ! 2276: ! 2277: /* We have committed to returning 1 at this point. */ ! 2278: if (TREE_CODE (newdecl) == FUNCTION_DECL) ! 2279: { ! 2280: /* Now that functions must hold information normally held ! 2281: by field decls, there is extra work to do so that ! 2282: declaration information does not get destroyed during ! 2283: definition. */ ! 2284: if (DECL_VINDEX (olddecl)) ! 2285: DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); ! 2286: if (DECL_CONTEXT (olddecl)) ! 2287: DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); ! 2288: if (DECL_CLASS_CONTEXT (olddecl)) ! 2289: DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); ! 2290: if (DECL_CHAIN (newdecl) == NULL_TREE) ! 2291: DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); ! 2292: if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) ! 2293: DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); 1.1 root 2294: } 2295: 2296: /* Deal with C++: must preserve virtual function table size. */ 2297: if (TREE_CODE (olddecl) == TYPE_DECL) 2298: { 1.1.1.6 ! root 2299: register tree newtype = TREE_TYPE (newdecl); ! 2300: register tree oldtype = TREE_TYPE (olddecl); ! 2301: ! 2302: if (newtype != error_mark_node && oldtype != error_mark_node ! 2303: && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype)) 1.1 root 2304: { 1.1.1.6 ! root 2305: CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype); ! 2306: CLASSTYPE_FRIEND_CLASSES (newtype) ! 2307: = CLASSTYPE_FRIEND_CLASSES (oldtype); 1.1 root 2308: } 1.1.1.3 root 2309: /* why assert here? Just because debugging information is 2310: messed up? (mrs) */ 2311: /* it happens on something like: 2312: typedef struct Thing { 2313: Thing(); 2314: int x; 2315: } Thing; 2316: */ 1.1.1.4 root 2317: #if 0 2318: my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), 139); 2319: #endif 1.1 root 2320: } 2321: 1.1.1.4 root 2322: /* Special handling ensues if new decl is a function definition. */ 2323: new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL 1.1.1.5 root 2324: && DECL_INITIAL (newdecl) != NULL_TREE); 1.1.1.4 root 2325: 2326: /* Optionally warn about more than one declaration for the same name, 2327: but don't warn about a function declaration followed by a definition. */ 1.1.1.5 root 2328: if (warn_redundant_decls 2329: && DECL_SOURCE_LINE (olddecl) != 0 2330: && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)) 1.1.1.4 root 2331: { 1.1.1.6 ! root 2332: cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); ! 2333: cp_warning ("previous declaration of `%D'", olddecl); 1.1.1.4 root 2334: } 1.1 root 2335: 2336: /* Copy all the DECL_... slots specified in the new decl 2337: except for any that we copy here from the old type. */ 2338: 2339: if (types_match) 2340: { 2341: /* Automatically handles default parameters. */ 2342: tree oldtype = TREE_TYPE (olddecl); 2343: /* Merge the data types specified in the two decls. */ 2344: tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); 2345: 2346: if (TREE_CODE (newdecl) == VAR_DECL) 1.1.1.4 root 2347: DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); 1.1 root 2348: /* Do this after calling `common_type' so that default 2349: parameters don't confuse us. */ 2350: else if (TREE_CODE (newdecl) == FUNCTION_DECL 2351: && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) 2352: != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) 2353: { 2354: tree ctype = NULL_TREE; 2355: ctype = DECL_CLASS_CONTEXT (newdecl); 2356: TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype, 2357: TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); 2358: TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype, 2359: TYPE_RAISES_EXCEPTIONS (oldtype)); 2360: 1.1.1.5 root 2361: if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE(olddecl), 0)) 1.1 root 2362: { 1.1.1.6 ! root 2363: cp_error ("declaration of `%D' raises different exceptions...", newdecl); ! 2364: cp_error_at ("...from previous declaration here", olddecl); 1.1 root 2365: } 2366: } 2367: TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; 2368: 2369: /* Lay the type out, unless already done. */ 2370: if (oldtype != TREE_TYPE (newdecl)) 2371: { 2372: if (TREE_TYPE (newdecl) != error_mark_node) 2373: layout_type (TREE_TYPE (newdecl)); 2374: if (TREE_CODE (newdecl) != FUNCTION_DECL 2375: && TREE_CODE (newdecl) != TYPE_DECL 2376: && TREE_CODE (newdecl) != CONST_DECL) 2377: layout_decl (newdecl, 0); 2378: } 2379: else 2380: { 2381: /* Since the type is OLDDECL's, make OLDDECL's size go with. */ 2382: DECL_SIZE (newdecl) = DECL_SIZE (olddecl); 2383: } 2384: 2385: /* Merge the type qualifiers. */ 2386: if (TREE_READONLY (newdecl)) 2387: TREE_READONLY (olddecl) = 1; 2388: if (TREE_THIS_VOLATILE (newdecl)) 2389: TREE_THIS_VOLATILE (olddecl) = 1; 2390: 2391: /* Merge the initialization information. */ 1.1.1.5 root 2392: if (DECL_INITIAL (newdecl) == NULL_TREE) 1.1 root 2393: DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 1.1.1.4 root 2394: /* Keep the old rtl since we can safely use it, unless it's the 2395: call to abort() used for abstract virtuals. */ 2396: if ((DECL_LANG_SPECIFIC (olddecl) 2397: && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) 2398: || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) 2399: DECL_RTL (newdecl) = DECL_RTL (olddecl); 1.1 root 2400: } 2401: /* If cannot merge, then use the new type and qualifiers, 2402: and don't preserve the old rtl. */ 2403: else 2404: { 2405: /* Clean out any memory we had of the old declaration. */ 2406: tree oldstatic = value_member (olddecl, static_aggregates); 2407: if (oldstatic) 2408: TREE_VALUE (oldstatic) = error_mark_node; 2409: 2410: TREE_TYPE (olddecl) = TREE_TYPE (newdecl); 2411: TREE_READONLY (olddecl) = TREE_READONLY (newdecl); 2412: TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); 2413: TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); 2414: } 2415: 2416: /* Merge the storage class information. */ 1.1.1.4 root 2417: if (DECL_EXTERNAL (newdecl)) 1.1 root 2418: { 2419: TREE_STATIC (newdecl) = TREE_STATIC (olddecl); 1.1.1.4 root 2420: DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl); 1.1 root 2421: 2422: /* For functions, static overrides non-static. */ 2423: if (TREE_CODE (newdecl) == FUNCTION_DECL) 2424: { 2425: TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl); 2426: /* This is since we don't automatically 2427: copy the attributes of NEWDECL into OLDDECL. */ 2428: TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); 2429: /* If this clears `static', clear it in the identifier too. */ 2430: if (! TREE_PUBLIC (olddecl)) 2431: TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0; 2432: } 2433: else 2434: TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); 2435: } 2436: else 2437: { 2438: TREE_STATIC (olddecl) = TREE_STATIC (newdecl); 2439: /* A `const' which was not declared `extern' and is 2440: in static storage is invisible. */ 2441: if (TREE_CODE (newdecl) == VAR_DECL 2442: && TREE_READONLY (newdecl) && TREE_STATIC (newdecl) 1.1.1.4 root 2443: && ! DECL_THIS_EXTERN (newdecl)) 1.1 root 2444: TREE_PUBLIC (newdecl) = 0; 2445: TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl); 2446: } 1.1.1.4 root 2447: 1.1 root 2448: /* If either decl says `inline', this fn is inline, 2449: unless its definition was passed already. */ 1.1.1.5 root 2450: if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE) 1.1.1.4 root 2451: DECL_INLINE (olddecl) = 1; 2452: DECL_INLINE (newdecl) = DECL_INLINE (olddecl); 1.1 root 2453: 2454: if (TREE_CODE (newdecl) == FUNCTION_DECL) 2455: { 1.1.1.4 root 2456: if (new_defines_function) 1.1 root 2457: /* If defining a function declared with other language 2458: linkage, use the previously declared language linkage. */ 2459: DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); 2460: else 2461: { 2462: /* If redeclaring a builtin function, and not a definition, 2463: it stays built in. */ 2464: if (DECL_BUILT_IN (olddecl)) 2465: { 2466: DECL_BUILT_IN (newdecl) = 1; 2467: DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl)); 2468: /* If we're keeping the built-in definition, keep the rtl, 2469: regardless of declaration matches. */ 2470: DECL_RTL (newdecl) = DECL_RTL (olddecl); 2471: } 2472: else 2473: DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); 2474: 2475: DECL_RESULT (newdecl) = DECL_RESULT (olddecl); 2476: if (DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)) 2477: /* Previously saved insns go together with 2478: the function's previous definition. */ 2479: DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); 2480: /* Don't clear out the arguments if we're redefining a function. */ 2481: if (DECL_ARGUMENTS (olddecl)) 2482: DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); 2483: } 2484: } 2485: 2486: /* Now preserve various other info from the definition. */ 2487: TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); 2488: TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); 2489: 2490: /* Don't really know how much of the language-specific 2491: values we should copy from old to new. */ 2492: #if 1 2493: if (DECL_LANG_SPECIFIC (olddecl)) 2494: DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); 2495: #endif 2496: 2497: if (TREE_CODE (newdecl) == FUNCTION_DECL) 2498: { 2499: int function_size; 2500: struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); 2501: struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); 2502: 2503: function_size = sizeof (struct tree_decl); 2504: 2505: bcopy ((char *) newdecl + sizeof (struct tree_common), 2506: (char *) olddecl + sizeof (struct tree_common), 2507: function_size - sizeof (struct tree_common)); 2508: 1.1.1.4 root 2509: if ((char *)newdecl + ((function_size + sizeof (struct lang_decl) 2510: + obstack_alignment_mask (&permanent_obstack)) 2511: & ~ obstack_alignment_mask (&permanent_obstack)) 2512: == obstack_next_free (&permanent_obstack)) 1.1 root 2513: { 2514: DECL_MAIN_VARIANT (newdecl) = olddecl; 2515: DECL_LANG_SPECIFIC (olddecl) = ol; 1.1.1.4 root 2516: bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); 1.1 root 2517: 2518: obstack_free (&permanent_obstack, newdecl); 2519: } 2520: else if (LANG_DECL_PERMANENT (ol)) 2521: { 2522: if (DECL_MAIN_VARIANT (olddecl) == olddecl) 2523: { 2524: /* Save these lang_decls that would otherwise be lost. */ 2525: extern tree free_lang_decl_chain; 2526: tree free_lang_decl = (tree) ol; 2527: TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; 2528: free_lang_decl_chain = free_lang_decl; 2529: } 2530: else 2531: { 2532: /* Storage leak. */ 2533: } 2534: } 2535: } 2536: else 2537: { 2538: bcopy ((char *) newdecl + sizeof (struct tree_common), 2539: (char *) olddecl + sizeof (struct tree_common), 2540: sizeof (struct tree_decl) - sizeof (struct tree_common) 2541: + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); 2542: } 2543: 1.1.1.4 root 2544: DECL_UID (olddecl) = olddecl_uid; 2545: if (olddecl_friend) 2546: DECL_FRIEND_P (olddecl) = 1; 2547: 1.1 root 2548: return 1; 2549: } 2550: 1.1.1.6 ! root 2551: #if !NEW_CLASS_SCOPING ! 2552: /* This was always a hack, that never should've been necessary. */ 1.1 root 2553: void 2554: adjust_type_value (id) 2555: tree id; 2556: { 2557: tree t; 2558: 2559: if (current_binding_level != global_binding_level) 2560: { 2561: if (current_binding_level != class_binding_level) 2562: { 2563: t = IDENTIFIER_LOCAL_VALUE (id); 2564: if (t && TREE_CODE (t) == TYPE_DECL) 2565: { 2566: set_it: 2567: SET_IDENTIFIER_TYPE_VALUE (id, TREE_TYPE (t)); 2568: return; 2569: } 2570: } 2571: else 1.1.1.3 root 2572: my_friendly_abort (7); 1.1 root 2573: 2574: if (current_class_type) 2575: { 2576: t = IDENTIFIER_CLASS_VALUE (id); 2577: if (t && TREE_CODE (t) == TYPE_DECL) 2578: goto set_it; 2579: } 2580: } 2581: 2582: t = IDENTIFIER_GLOBAL_VALUE (id); 2583: if (t && TREE_CODE (t) == TYPE_DECL) 2584: goto set_it; 2585: if (t && TREE_CODE (t) == TEMPLATE_DECL) 2586: SET_IDENTIFIER_TYPE_VALUE (id, NULL_TREE); 2587: } 1.1.1.6 ! root 2588: #endif 1.1 root 2589: 2590: /* Record a decl-node X as belonging to the current lexical scope. 2591: Check for errors (such as an incompatible declaration for the same 2592: name already seen in the same scope). 2593: 2594: Returns either X or an old decl for the same name. 2595: If an old decl is returned, it may have been smashed 2596: to agree with what X says. */ 2597: 2598: tree 2599: pushdecl (x) 2600: tree x; 2601: { 2602: register tree t; 1.1.1.2 root 2603: #if 0 /* not yet, should get fixed properly later */ 2604: register tree name; 2605: #else 1.1 root 2606: register tree name = DECL_ASSEMBLER_NAME (x); 1.1.1.2 root 2607: #endif 1.1 root 2608: register struct binding_level *b = current_binding_level; 2609: 2610: #if 0 2611: static int nglobals; int len; 2612: 2613: len = list_length (global_binding_level->names); 2614: if (len < nglobals) 1.1.1.3 root 2615: my_friendly_abort (8); 1.1 root 2616: else if (len > nglobals) 2617: nglobals = len; 2618: #endif 2619: 1.1.1.4 root 2620: /* Don't change DECL_CONTEXT of virtual methods. */ 2621: if (x != current_function_decl 2622: && (TREE_CODE (x) != FUNCTION_DECL 2623: || !DECL_VIRTUAL_P (x))) 2624: DECL_CONTEXT (x) = current_function_decl; 1.1.1.5 root 2625: /* A local declaration for a function doesn't constitute nesting. */ 2626: if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0) 2627: DECL_CONTEXT (x) = 0; 1.1.1.4 root 2628: 1.1.1.2 root 2629: #if 0 /* not yet, should get fixed properly later */ 2630: /* For functions and class static data, we currently look up the encoded 2631: form of the name. For types, we want the real name. The former will 2632: probably be changed soon, according to MDT. */ 2633: if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) 2634: name = DECL_ASSEMBLER_NAME (x); 2635: else 2636: name = DECL_NAME (x); 1.1.1.4 root 2637: #else 2638: /* Type are looked up using the DECL_NAME, as that is what the rest of the 2639: compiler wants to use. */ 2640: if (TREE_CODE (x) == TYPE_DECL) 2641: name = DECL_NAME (x); 1.1.1.2 root 2642: #endif 1.1.1.4 root 2643: 1.1 root 2644: if (name) 2645: { 2646: char *file; 2647: int line; 2648: 2649: t = lookup_name_current_level (name); 1.1.1.5 root 2650: if (t == error_mark_node) 1.1 root 2651: { 1.1.1.5 root 2652: /* error_mark_node is 0 for a while during initialization! */ 2653: t = NULL_TREE; 1.1.1.6 ! root 2654: cp_error_at ("`%#D' used prior to declaration", x); 1.1 root 2655: } 2656: 1.1.1.5 root 2657: if (t != NULL_TREE) 1.1 root 2658: { 2659: if (TREE_CODE (t) == PARM_DECL) 2660: { 2661: if (DECL_CONTEXT (t) == NULL_TREE) 2662: fatal ("parse errors have confused me too much"); 2663: } 2664: file = DECL_SOURCE_FILE (t); 2665: line = DECL_SOURCE_LINE (t); 2666: } 2667: 1.1.1.5 root 2668: if (t != NULL_TREE && TREE_CODE (t) != TREE_CODE (x)) 1.1 root 2669: { 2670: if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL) 2671: { 2672: /* We do nothing special here, because C++ does such nasty 2673: things with TYPE_DECLs. Instead, just let the TYPE_DECL 2674: get shadowed, and know that if we need to find a TYPE_DECL 2675: for a given name, we can look in the IDENTIFIER_TYPE_VALUE 2676: slot of the identifier. */ 2677: ; 2678: } 2679: else if (duplicate_decls (x, t)) 2680: return t; 2681: } 1.1.1.5 root 2682: else if (t != NULL_TREE && duplicate_decls (x, t)) 1.1 root 2683: { 2684: /* If this decl is `static' and an `extern' was seen previously, 2685: that is erroneous. But don't complain if -traditional, 2686: since traditional compilers don't complain. 2687: 2688: Note that this does not apply to the C++ case of declaring 2689: a variable `extern const' and then later `const'. */ 2690: if (!flag_traditional && TREE_PUBLIC (name) 1.1.1.4 root 2691: && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x) && ! DECL_INLINE (x)) 1.1 root 2692: { 2693: /* Due to interference in memory reclamation (X may be 2694: obstack-deallocated at this point), we must guard against 2695: one really special case. */ 2696: if (current_function_decl == x) 2697: current_function_decl = t; 2698: if (IDENTIFIER_IMPLICIT_DECL (name)) 1.1.1.6 ! root 2699: cp_warning ("`%D' was declared implicitly `extern' and later `static'", t); 1.1 root 2700: else 1.1.1.6 ! root 2701: cp_warning ("`%D' was declared `extern' and later `static'", ! 2702: x); ! 2703: cp_warning_at ("previous declaration of `%D'", t); ! 2704: } ! 2705: #if 0 ! 2706: /* This is turned off until I have time to do it right (bpk). */ ! 2707: ! 2708: /* Also warn if they did a prototype with `static' on it, but ! 2709: then later left the `static' off. */ ! 2710: else if (! TREE_PUBLIC (name) && TREE_PUBLIC (x)) ! 2711: { ! 2712: if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t)) ! 2713: return t; ! 2714: ! 2715: if (current_function_decl == x) ! 2716: current_function_decl = t; ! 2717: ! 2718: if (extra_warnings) ! 2719: { ! 2720: cp_warning ("`static' missing from declaration of `%D'", t); ! 2721: warning_with_file_and_line (file, line, ! 2722: "previous declaration of `%s'", ! 2723: decl_as_string (t, 0)); ! 2724: } ! 2725: ! 2726: /* Now fix things so it'll do what they expect. */ ! 2727: if (current_function_decl) ! 2728: TREE_PUBLIC (current_function_decl) = 0; 1.1 root 2729: } 1.1.1.6 ! root 2730: #endif 1.1 root 2731: return t; 2732: } 2733: 2734: /* If declaring a type as a typedef, and the type has no known 1.1.1.6 ! root 2735: typedef name, install this TYPE_DECL as its typedef name. */ 1.1 root 2736: if (TREE_CODE (x) == TYPE_DECL) 2737: { 1.1.1.6 ! root 2738: tree type = TREE_TYPE (x); ! 2739: tree name = (type != error_mark_node) ? TYPE_NAME (type) : x; 1.1 root 2740: 2741: if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL) 2742: { 2743: /* If these are different names, and we're at the global 2744: binding level, make two equivalent definitions. */ 2745: name = x; 2746: if (global_bindings_p ()) 1.1.1.6 ! root 2747: TYPE_NAME (type) = x; 1.1 root 2748: } 2749: else 2750: { 2751: tree tname = DECL_NAME (name); 1.1.1.6 ! root 2752: 1.1 root 2753: if (global_bindings_p () && ANON_AGGRNAME_P (tname)) 2754: { 1.1.1.6 ! root 2755: /* do gratuitous C++ typedefing, and make sure that ! 2756: we access this type either through TREE_TYPE field ! 2757: or via the tags list. */ 1.1 root 2758: TYPE_NAME (TREE_TYPE (x)) = x; 2759: pushtag (tname, TREE_TYPE (x)); 2760: } 2761: } 1.1.1.4 root 2762: my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140); 1.1.1.6 ! root 2763: 1.1 root 2764: if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name)) 1.1.1.6 ! root 2765: set_nested_typename (x, current_class_name, ! 2766: DECL_NAME (name), type); ! 2767: ! 2768: if (type != error_mark_node ! 2769: && TYPE_NAME (type) ! 2770: && TYPE_IDENTIFIER (type)) ! 2771: set_identifier_type_value (DECL_NAME (x), type); ! 2772: } ! 2773: ! 2774: /* Multiple external decls of the same identifier ought to match. ! 2775: ! 2776: We get warnings about inline functions where they are defined. ! 2777: Avoid duplicate warnings where they are used. */ ! 2778: if (TREE_PUBLIC (x) && !DECL_INLINE (x)) ! 2779: { ! 2780: tree decl; ! 2781: ! 2782: if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE ! 2783: && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) ! 2784: || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))) ! 2785: decl = IDENTIFIER_GLOBAL_VALUE (name); ! 2786: else ! 2787: decl = NULL_TREE; ! 2788: ! 2789: if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1) ! 2790: /* If old decl is built-in, we already warned if we should. */ ! 2791: && !DECL_BUILT_IN (decl)) ! 2792: { ! 2793: cp_pedwarn_at ("type mismatch with previous external decl", x); ! 2794: cp_pedwarn_at ("previous external decl of `%D'", decl); 1.1 root 2795: } 2796: } 2797: 2798: /* In PCC-compatibility mode, extern decls of vars with no current decl 2799: take effect at top level no matter where they are. */ 1.1.1.4 root 2800: if (flag_traditional && DECL_EXTERNAL (x) 1.1.1.5 root 2801: && lookup_name (name, 0) == NULL_TREE) 1.1 root 2802: b = global_binding_level; 2803: 2804: /* This name is new in its binding level. 2805: Install the new declaration and return it. */ 2806: if (b == global_binding_level) 2807: { 2808: /* Install a global value. */ 2809: 2810: /* Rule for VAR_DECLs, but not for other kinds of _DECLs: 2811: A `const' which was not declared `extern' is invisible. */ 2812: if (TREE_CODE (x) == VAR_DECL 1.1.1.4 root 2813: && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x)) 1.1 root 2814: TREE_PUBLIC (x) = 0; 2815: 2816: /* If the first global decl has external linkage, 2817: warn if we later see static one. */ 1.1.1.5 root 2818: if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x)) 1.1 root 2819: TREE_PUBLIC (name) = 1; 2820: 2821: /* Don't install a TYPE_DECL if we already have another 2822: sort of _DECL with that name. */ 2823: if (TREE_CODE (x) != TYPE_DECL 2824: || t == NULL_TREE 2825: || TREE_CODE (t) == TYPE_DECL) 2826: IDENTIFIER_GLOBAL_VALUE (name) = x; 2827: 2828: /* Don't forget if the function was used via an implicit decl. */ 2829: if (IDENTIFIER_IMPLICIT_DECL (name) 2830: && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) 2831: TREE_USED (x) = 1; 2832: 2833: /* Don't forget if its address was taken in that way. */ 2834: if (IDENTIFIER_IMPLICIT_DECL (name) 2835: && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) 2836: TREE_ADDRESSABLE (x) = 1; 2837: 2838: /* Warn about mismatches against previous implicit decl. */ 1.1.1.5 root 2839: if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE 1.1 root 2840: /* If this real decl matches the implicit, don't complain. */ 2841: && ! (TREE_CODE (x) == FUNCTION_DECL 2842: && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) 1.1.1.6 ! root 2843: cp_warning ! 2844: ("`%D' was previously implicitly declared to return `int'", x); 1.1 root 2845: 2846: /* If this decl is `static' and an `extern' was seen previously, 2847: that is erroneous. Don't do this for TYPE_DECLs. */ 2848: if (TREE_PUBLIC (name) 2849: && TREE_CODE (x) != TYPE_DECL 1.1.1.4 root 2850: && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x)) 1.1 root 2851: { 2852: if (IDENTIFIER_IMPLICIT_DECL (name)) 1.1.1.6 ! root 2853: cp_warning ! 2854: ("`%D' was declared implicitly `extern' and later `static'", ! 2855: x); 1.1 root 2856: else 1.1.1.6 ! root 2857: cp_warning ! 2858: ("`%D' was declared `extern' and later `static'", x); 1.1 root 2859: } 2860: } 2861: else 2862: { 2863: /* Here to install a non-global value. */ 2864: tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); 2865: tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); 2866: set_identifier_local_value (name, x); 2867: 2868: /* If this is an extern function declaration, see if we 1.1.1.4 root 2869: have a global definition or declaration for the function. */ 1.1.1.5 root 2870: if (oldlocal == NULL_TREE 1.1.1.4 root 2871: && DECL_EXTERNAL (x) && !DECL_INLINE (x) 1.1.1.5 root 2872: && oldglobal != NULL_TREE 1.1 root 2873: && TREE_CODE (x) == FUNCTION_DECL 2874: && TREE_CODE (oldglobal) == FUNCTION_DECL) 2875: { 2876: /* We have one. Their types must agree. */ 2877: if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1)) 1.1.1.6 ! root 2878: { ! 2879: cp_warning ("extern declaration of `%#D' doesn't match", x); ! 2880: cp_warning_at ("global declaration `%#D'", oldglobal); ! 2881: } 1.1.1.4 root 2882: else 2883: { 2884: /* Inner extern decl is inline if global one is. 2885: Copy enough to really inline it. */ 2886: if (DECL_INLINE (oldglobal)) 2887: { 2888: DECL_INLINE (x) = DECL_INLINE (oldglobal); 2889: DECL_INITIAL (x) = (current_function_decl == oldglobal 1.1.1.5 root 2890: ? NULL_TREE : DECL_INITIAL (oldglobal)); 1.1.1.4 root 2891: DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal); 1.1.1.6 ! root 2892: DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal); 1.1.1.4 root 2893: DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal); 2894: DECL_RESULT (x) = DECL_RESULT (oldglobal); 2895: TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal); 2896: DECL_ABSTRACT_ORIGIN (x) = oldglobal; 2897: } 2898: /* Inner extern decl is built-in if global one is. */ 2899: if (DECL_BUILT_IN (oldglobal)) 2900: { 2901: DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal); 2902: DECL_SET_FUNCTION_CODE (x, DECL_FUNCTION_CODE (oldglobal)); 2903: } 2904: /* Keep the arg types from a file-scope fcn defn. */ 1.1.1.5 root 2905: if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != NULL_TREE 1.1.1.4 root 2906: && DECL_INITIAL (oldglobal) 1.1.1.5 root 2907: && TYPE_ARG_TYPES (TREE_TYPE (x)) == NULL_TREE) 1.1.1.4 root 2908: TREE_TYPE (x) = TREE_TYPE (oldglobal); 2909: } 1.1 root 2910: } 2911: /* If we have a local external declaration, 2912: and no file-scope declaration has yet been seen, 2913: then if we later have a file-scope decl it must not be static. */ 1.1.1.5 root 2914: if (oldlocal == NULL_TREE 2915: && oldglobal == NULL_TREE 1.1.1.4 root 2916: && DECL_EXTERNAL (x) 1.1 root 2917: && TREE_PUBLIC (x)) 2918: { 2919: TREE_PUBLIC (name) = 1; 2920: } 2921: 2922: if (DECL_FROM_INLINE (x)) 2923: /* Inline decls shadow nothing. */; 2924: 2925: /* Warn if shadowing an argument at the top level of the body. */ 1.1.1.5 root 2926: else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) 1.1 root 2927: && TREE_CODE (oldlocal) == PARM_DECL 2928: && TREE_CODE (x) != PARM_DECL) 2929: { 2930: /* Go to where the parms should be and see if we 2931: find them there. */ 2932: struct binding_level *b = current_binding_level->level_chain; 2933: 2934: if (cleanup_label) 2935: b = b->level_chain; 2936: 1.1.1.5 root 2937: /* ARM $8.3 */ 1.1 root 2938: if (b->parm_flag == 1) 1.1.1.6 ! root 2939: cp_error ("declaration of `%#D' shadows a parameter", name); 1.1 root 2940: } 2941: /* Maybe warn if shadowing something else. */ 1.1.1.4 root 2942: else if (warn_shadow && !DECL_EXTERNAL (x) 1.1.1.3 root 2943: /* No shadow warnings for internally generated vars. */ 1.1.1.4 root 2944: && DECL_SOURCE_LINE (x) != 0 1.1 root 2945: /* No shadow warnings for vars made for inlining. */ 2946: && ! DECL_FROM_INLINE (x)) 2947: { 1.1.1.5 root 2948: char *warnstring = NULL; 1.1 root 2949: 1.1.1.5 root 2950: if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) 1.1 root 2951: warnstring = "declaration of `%s' shadows a parameter"; 1.1.1.6 ! root 2952: else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE ! 2953: && !TREE_STATIC (name)) 1.1 root 2954: warnstring = "declaration of `%s' shadows a member of `this'"; 1.1.1.5 root 2955: else if (oldlocal != NULL_TREE) 1.1 root 2956: warnstring = "declaration of `%s' shadows previous local"; 1.1.1.5 root 2957: else if (oldglobal != NULL_TREE) 1.1 root 2958: warnstring = "declaration of `%s' shadows global declaration"; 2959: 2960: if (warnstring) 2961: warning (warnstring, IDENTIFIER_POINTER (name)); 2962: } 2963: 2964: /* If storing a local value, there may already be one (inherited). 2965: If so, record it for restoration when this binding level ends. */ 1.1.1.5 root 2966: if (oldlocal != NULL_TREE) 1.1 root 2967: b->shadowed = tree_cons (name, oldlocal, b->shadowed); 2968: } 2969: 2970: /* Keep count of variables in this level with incomplete type. */ 2971: if (TREE_CODE (x) != TEMPLATE_DECL 2972: && TREE_CODE (x) != CPLUS_CATCH_DECL 1.1.1.5 root 2973: && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE 1.1 root 2974: && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) 2975: { 2976: if (++b->n_incomplete == 0) 2977: error ("too many incomplete variables at this point"); 2978: } 2979: } 2980: 2981: if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE) 2982: { 1.1.1.6 ! root 2983: #if !NEW_CLASS_SCOPING 1.1 root 2984: adjust_type_value (name); 1.1.1.6 ! root 2985: #endif 1.1 root 2986: if (current_class_name) 2987: { 2988: if (!DECL_NESTED_TYPENAME (x)) 2989: set_nested_typename (x, current_class_name, DECL_NAME (x), 2990: TREE_TYPE (x)); 1.1.1.6 ! root 2991: #if !NEW_CLASS_SCOPING 1.1 root 2992: adjust_type_value (DECL_NESTED_TYPENAME (x)); 1.1.1.6 ! root 2993: #endif 1.1 root 2994: } 2995: } 2996: 2997: /* Put decls on list in reverse order. 2998: We will reverse them later if necessary. */ 2999: TREE_CHAIN (x) = b->names; 3000: b->names = x; 1.1.1.4 root 3001: if (! (b != global_binding_level || TREE_PERMANENT (x))) 3002: my_friendly_abort (124); 1.1 root 3003: 3004: return x; 3005: } 3006: 3007: /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, 3008: if appropriate. */ 3009: tree 3010: pushdecl_top_level (x) 3011: tree x; 3012: { 3013: register tree t; 3014: register struct binding_level *b = current_binding_level; 3015: 3016: current_binding_level = global_binding_level; 3017: t = pushdecl (x); 3018: current_binding_level = b; 3019: if (class_binding_level) 3020: b = class_binding_level; 3021: /* Now, the type_shadowed stack may screw us. Munge it so it does 3022: what we want. */ 3023: if (TREE_CODE (x) == TYPE_DECL) 3024: { 3025: tree name = DECL_NAME (x); 3026: tree newval; 1.1.1.5 root 3027: tree *ptr = (tree *)0; 1.1 root 3028: for (; b != global_binding_level; b = b->level_chain) 3029: { 3030: tree shadowed = b->type_shadowed; 3031: for (; shadowed; shadowed = TREE_CHAIN (shadowed)) 3032: if (TREE_PURPOSE (shadowed) == name) 3033: { 3034: ptr = &TREE_VALUE (shadowed); 3035: /* Can't break out of the loop here because sometimes 3036: a binding level will have duplicate bindings for 3037: PT names. It's gross, but I haven't time to fix it. */ 3038: } 3039: } 3040: newval = TREE_TYPE (x); 1.1.1.5 root 3041: if (ptr == (tree *)0) 1.1 root 3042: { 3043: /* @@ This shouldn't be needed. My test case "zstring.cc" trips 3044: up here if this is changed to an assertion. --KR */ 3045: SET_IDENTIFIER_TYPE_VALUE (name, newval); 3046: } 3047: else 3048: { 1.1.1.4 root 3049: #if 0 3050: /* Disabled this 11/10/92, since there are many cases which 3051: behave just fine when *ptr doesn't satisfy either of these. 3052: For example, nested classes declared as friends of their enclosing 3053: class will not meet this criteria. (bpk) */ 3054: my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141); 3055: #endif 1.1 root 3056: *ptr = newval; 3057: } 3058: } 3059: return t; 3060: } 3061: 3062: /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL, 3063: if appropriate. */ 3064: void 3065: push_overloaded_decl_top_level (x, forget) 3066: tree x; 3067: int forget; 3068: { 3069: struct binding_level *b = current_binding_level; 3070: 3071: current_binding_level = global_binding_level; 3072: push_overloaded_decl (x, forget); 3073: current_binding_level = b; 3074: } 3075: 3076: /* Make the declaration of X appear in CLASS scope. */ 3077: tree 3078: pushdecl_class_level (x) 3079: tree x; 3080: { 3081: /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class 3082: scope looks for the pre-mangled name. */ 3083: register tree name = DECL_NAME (x); 3084: 3085: if (name) 3086: { 1.1.1.6 ! root 3087: #if NEW_CLASS_SCOPING ! 3088: push_class_level_binding (name, x); ! 3089: if (TREE_CODE (x) == TYPE_DECL) ! 3090: { ! 3091: set_identifier_type_value (name, TREE_TYPE (x)); ! 3092: if (!DECL_NESTED_TYPENAME (x)) ! 3093: set_nested_typename (x, current_class_name, name, TREE_TYPE (x)); ! 3094: } ! 3095: #else 1.1 root 3096: tree oldclass = IDENTIFIER_CLASS_VALUE (name); 3097: if (oldclass) 3098: class_binding_level->class_shadowed 3099: = tree_cons (name, oldclass, class_binding_level->class_shadowed); 3100: IDENTIFIER_CLASS_VALUE (name) = x; 3101: obstack_ptr_grow (&decl_obstack, x); 3102: if (TREE_CODE (x) == TYPE_DECL && !DECL_NESTED_TYPENAME (x)) 3103: set_nested_typename (x, current_class_name, name, TREE_TYPE (x)); 1.1.1.6 ! root 3104: #endif 1.1 root 3105: } 3106: return x; 3107: } 3108: 1.1.1.6 ! root 3109: #if NEW_CLASS_SCOPING ! 3110: /* Make the declaration(s) of X appear in CLASS scope ! 3111: under the name NAME. */ ! 3112: void ! 3113: push_class_level_binding (name, x) ! 3114: tree name; ! 3115: tree x; ! 3116: { ! 3117: maybe_push_cache_obstack (); ! 3118: class_binding_level->class_shadowed ! 3119: = tree_cons (name, IDENTIFIER_CLASS_VALUE (name), ! 3120: class_binding_level->class_shadowed); ! 3121: pop_obstacks (); ! 3122: IDENTIFIER_CLASS_VALUE (name) = x; ! 3123: obstack_ptr_grow (&decl_obstack, x); ! 3124: } ! 3125: #endif ! 3126: 1.1 root 3127: /* Tell caller how to interpret a TREE_LIST which contains 3128: chains of FUNCTION_DECLS. */ 3129: int 3130: overloaded_globals_p (list) 3131: tree list; 3132: { 1.1.1.4 root 3133: my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142); 1.1 root 3134: 3135: /* Don't commit caller to seeing them as globals. */ 3136: if (TREE_NONLOCAL_FLAG (list)) 3137: return -1; 3138: /* Do commit caller to seeing them as globals. */ 3139: if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE) 3140: return 1; 3141: /* Do commit caller to not seeing them as globals. */ 3142: return 0; 3143: } 3144: 3145: /* DECL is a FUNCTION_DECL which may have other definitions already in place. 3146: We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_NAME (DECL)) 3147: point to a list of all the things that want to be referenced by that name. 3148: It is then up to the users of that name to decide what to do with that 3149: list. 3150: 3151: DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT 3152: slot. It is dealt with the same way. 3153: 3154: The value returned may be a previous declaration if we guessed wrong 3155: about what language DECL should belong to (C or C++). Otherwise, 3156: it's always DECL (and never something that's not a _DECL). */ 3157: tree 3158: push_overloaded_decl (decl, forgettable) 3159: tree decl; 3160: int forgettable; 3161: { 3162: tree orig_name = DECL_NAME (decl); 3163: tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name); 3164: 3165: DECL_OVERLOADED (decl) = 1; 3166: if (glob) 3167: { 3168: if (TREE_CODE (glob) != TREE_LIST) 3169: { 3170: if (DECL_LANGUAGE (decl) == lang_c) 3171: { 3172: if (TREE_CODE (glob) == FUNCTION_DECL) 3173: { 3174: if (DECL_LANGUAGE (glob) == lang_c) 3175: { 1.1.1.6 ! root 3176: cp_error ("C-language function `%D' overloaded here", decl); ! 3177: cp_error_at ("Previous C-language version of this function was `%D'", glob); 1.1 root 3178: } 3179: } 3180: else 1.1.1.3 root 3181: my_friendly_abort (9); 1.1 root 3182: } 3183: if (forgettable 3184: && ! flag_traditional 3185: && TREE_PERMANENT (glob) == 1 3186: && !global_bindings_p ()) 3187: overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget); 3188: /* We cache the value of builtin functions as ADDR_EXPRs 3189: in the name space. Convert it to some kind of _DECL after 3190: remembering what to forget. */ 3191: if (TREE_CODE (glob) == ADDR_EXPR) 3192: glob = TREE_OPERAND (glob, 0); 3193: 3194: if (TREE_CODE (glob) == FUNCTION_DECL 3195: && DECL_LANGUAGE (glob) != DECL_LANGUAGE (decl) 1.1.1.6 ! root 3196: && comptypes (TREE_TYPE (glob), TREE_TYPE (decl), 2)) 1.1 root 3197: { 3198: if (current_lang_stack == current_lang_base) 3199: { 3200: DECL_LANGUAGE (decl) = DECL_LANGUAGE (glob); 3201: return glob; 3202: } 3203: else 3204: { 1.1.1.6 ! root 3205: cp_error ("conflicting language contexts for declaration of `%D';", decl); ! 3206: cp_error_at ("conflicts with previous declaration here", glob); 1.1 root 3207: } 3208: } 3209: if (pedantic && TREE_CODE (glob) == VAR_DECL) 3210: { 1.1.1.4 root 3211: my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (glob)) == 'd', 143); 1.1.1.6 ! root 3212: cp_error ("non-function declaration `%D'", glob); ! 3213: cp_error_at ("conflicts with function declaration `%D'", decl); 1.1 root 3214: } 1.1.1.2 root 3215: glob = tree_cons (orig_name, glob, NULL_TREE); 1.1 root 3216: glob = tree_cons (TREE_PURPOSE (glob), decl, glob); 3217: IDENTIFIER_GLOBAL_VALUE (orig_name) = glob; 3218: TREE_TYPE (glob) = unknown_type_node; 3219: return decl; 3220: } 3221: 3222: if (TREE_VALUE (glob) == NULL_TREE) 3223: { 3224: TREE_VALUE (glob) = decl; 3225: return decl; 3226: } 3227: if (TREE_CODE (decl) != TEMPLATE_DECL) 3228: { 3229: tree name = DECL_ASSEMBLER_NAME (decl); 3230: tree tmp; 3231: 3232: for (tmp = glob; tmp; tmp = TREE_CHAIN (tmp)) 3233: { 3234: if (TREE_CODE (TREE_VALUE (tmp)) == FUNCTION_DECL 3235: && comptypes (TREE_TYPE (TREE_VALUE (tmp)), TREE_TYPE (decl), 1.1.1.6 ! root 3236: 2)) 1.1 root 3237: { 1.1.1.6 ! root 3238: if (DECL_LANGUAGE (TREE_VALUE (tmp)) != DECL_LANGUAGE (decl)) ! 3239: { ! 3240: cp_error_at ("conflicting language contexts for declaration of `%D';", decl); ! 3241: cp_error_at ("conflicts with previous declaration here", TREE_VALUE (tmp)); ! 3242: } ! 3243: else if (TREE_CODE (TREE_VALUE (tmp)) != TEMPLATE_DECL ! 3244: && DECL_ASSEMBLER_NAME (TREE_VALUE (tmp)) != name) ! 3245: { ! 3246: cp_error ("new declaration `%#D'", decl); ! 3247: cp_error_at ("ambiguates old declaration `%#D'", ! 3248: TREE_VALUE (tmp)); ! 3249: } 1.1 root 3250: } 1.1.1.6 ! root 3251: /* If we really have seen this before, then if it ambiguates ! 3252: something, we've already given an error before. */ 1.1 root 3253: if (TREE_CODE (TREE_VALUE (tmp)) != TEMPLATE_DECL 3254: && DECL_ASSEMBLER_NAME (TREE_VALUE (tmp)) == name) 3255: return decl; 3256: } 3257: } 3258: } 3259: if (DECL_LANGUAGE (decl) == lang_c) 3260: { 3261: tree decls = glob; 3262: while (decls && DECL_LANGUAGE (TREE_VALUE (decls)) == lang_cplusplus) 3263: decls = TREE_CHAIN (decls); 3264: if (decls) 3265: { 1.1.1.6 ! root 3266: cp_error ("C-language function `%D' overloaded here", decl); ! 3267: cp_error_at ! 3268: ("Previous C-language version of this function was `%D'", ! 3269: TREE_VALUE (decls)); 1.1 root 3270: } 3271: } 3272: 3273: if (forgettable 3274: && ! flag_traditional 1.1.1.5 root 3275: && (glob == NULL_TREE || TREE_PERMANENT (glob) == 1) 1.1.1.4 root 3276: && !global_bindings_p () 3277: && !pseudo_global_level_p ()) 1.1 root 3278: overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget); 3279: glob = tree_cons (orig_name, decl, glob); 3280: IDENTIFIER_GLOBAL_VALUE (orig_name) = glob; 3281: TREE_TYPE (glob) = unknown_type_node; 3282: return decl; 3283: } 3284: 3285: /* Generate an implicit declaration for identifier FUNCTIONID 3286: as a function of type int (). Print a warning if appropriate. */ 3287: 3288: tree 3289: implicitly_declare (functionid) 3290: tree functionid; 3291: { 3292: register tree decl; 3293: int temp = allocation_temporary_p (); 3294: 3295: push_obstacks_nochange (); 3296: 3297: /* Save the decl permanently so we can warn if definition follows. 3298: In ANSI C, warn_implicit is usually false, so the saves little space. 3299: But in C++, it's usually true, hence the extra code. */ 3300: if (temp && (flag_traditional || !warn_implicit 3301: || current_binding_level == global_binding_level)) 3302: end_temporary_allocation (); 3303: 3304: /* We used to reuse an old implicit decl here, 3305: but this loses with inline functions because it can clobber 3306: the saved decl chains. */ 1.1.1.5 root 3307: decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type); 1.1 root 3308: 1.1.1.4 root 3309: DECL_EXTERNAL (decl) = 1; 1.1 root 3310: TREE_PUBLIC (decl) = 1; 3311: 3312: /* ANSI standard says implicit declarations are in the innermost block. 3313: So we record the decl in the standard fashion. 3314: If flag_traditional is set, pushdecl does it top-level. */ 3315: pushdecl (decl); 1.1.1.5 root 3316: rest_of_decl_compilation (decl, NULL_PTR, 0, 0); 1.1 root 3317: 3318: if (warn_implicit 3319: /* Only one warning per identifier. */ 1.1.1.5 root 3320: && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) 1.1 root 3321: { 1.1.1.6 ! root 3322: cp_pedwarn ("implicit declaration of function `%#D'", decl); 1.1 root 3323: } 3324: 3325: SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); 3326: 3327: pop_obstacks (); 3328: 3329: return decl; 3330: } 3331: 3332: /* Return zero if the declaration NEWDECL is valid 3333: when the declaration OLDDECL (assumed to be for the same name) 3334: has already been seen. 3335: Otherwise return an error message format string with a %s 3336: where the identifier should go. */ 3337: 3338: static char * 3339: redeclaration_error_message (newdecl, olddecl) 3340: tree newdecl, olddecl; 3341: { 3342: if (TREE_CODE (newdecl) == TYPE_DECL) 3343: { 3344: /* Because C++ can put things into name space for free, 3345: constructs like "typedef struct foo { ... } foo" 3346: would look like an erroneous redeclaration. */ 1.1.1.6 ! root 3347: if (comptypes (newdecl, olddecl, 0)) 1.1 root 3348: return 0; 3349: else 3350: return "redefinition of `%s'"; 3351: } 3352: else if (TREE_CODE (newdecl) == FUNCTION_DECL) 3353: { 1.1.1.4 root 3354: /* If this is a pure function, its olddecl will actually be 3355: the original initialization to `0' (which we force to call 3356: abort()). Don't complain about redefinition in this case. */ 3357: if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) 3358: return 0; 3359: 1.1 root 3360: /* Declarations of functions can insist on internal linkage 3361: but they can't be inconsistent with internal linkage, 3362: so there can be no error on that account. 3363: However defining the same name twice is no good. */ 1.1.1.5 root 3364: if (DECL_INITIAL (olddecl) != NULL_TREE 3365: && DECL_INITIAL (newdecl) != NULL_TREE 1.1 root 3366: /* However, defining once as extern inline and a second 3367: time in another way is ok. */ 1.1.1.4 root 3368: && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl) 3369: && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl)))) 1.1 root 3370: { 3371: if (DECL_NAME (olddecl) == NULL_TREE) 3372: return "`%s' not declared in class"; 3373: else 3374: return "redefinition of `%s'"; 3375: } 3376: return 0; 3377: } 3378: else if (current_binding_level == global_binding_level) 3379: { 3380: /* Objects declared at top level: */ 3381: /* If at least one is a reference, it's ok. */ 1.1.1.4 root 3382: if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) 1.1 root 3383: return 0; 3384: /* Reject two definitions. */ 1.1.1.5 root 3385: if (DECL_INITIAL (olddecl) != NULL_TREE 3386: && DECL_INITIAL (newdecl) != NULL_TREE) 1.1 root 3387: return "redefinition of `%s'"; 3388: /* Now we have two tentative defs, or one tentative and one real def. */ 3389: /* Insist that the linkage match. */ 3390: if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl)) 3391: return "conflicting declarations of `%s'"; 3392: return 0; 3393: } 3394: else 3395: { 3396: /* Objects declared with block scope: */ 3397: /* Reject two definitions, and reject a definition 3398: together with an external reference. */ 1.1.1.4 root 3399: if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))) 1.1 root 3400: return "redeclaration of `%s'"; 3401: return 0; 3402: } 3403: } 3404: 3405: /* Get the LABEL_DECL corresponding to identifier ID as a label. 3406: Create one if none exists so far for the current function. 3407: This function is called for both label definitions and label references. */ 3408: 3409: tree 3410: lookup_label (id) 3411: tree id; 3412: { 3413: register tree decl = IDENTIFIER_LABEL_VALUE (id); 3414: 1.1.1.6 ! root 3415: if (current_function_decl == NULL_TREE) ! 3416: { ! 3417: error ("label `%s' referenced outside of any function", ! 3418: IDENTIFIER_POINTER (id)); ! 3419: return NULL_TREE; ! 3420: } ! 3421: 1.1.1.5 root 3422: if ((decl == NULL_TREE 1.1 root 3423: || DECL_SOURCE_LINE (decl) == 0) 1.1.1.6 ! root 3424: && (named_label_uses == NULL_TREE 1.1 root 3425: || TREE_PURPOSE (named_label_uses) != current_binding_level->names 3426: || TREE_VALUE (named_label_uses) != decl)) 3427: { 3428: named_label_uses 3429: = tree_cons (current_binding_level->names, decl, named_label_uses); 3430: TREE_TYPE (named_label_uses) = (tree)current_binding_level; 3431: } 3432: 1.1.1.2 root 3433: /* Use a label already defined or ref'd with this name. */ 1.1.1.5 root 3434: if (decl != NULL_TREE) 1.1.1.2 root 3435: { 3436: /* But not if it is inherited and wasn't declared to be inheritable. */ 3437: if (DECL_CONTEXT (decl) != current_function_decl 3438: && ! C_DECLARED_LABEL_FLAG (decl)) 3439: return shadow_label (id); 3440: return decl; 3441: } 1.1 root 3442: 3443: decl = build_decl (LABEL_DECL, id, void_type_node); 3444: 3445: /* A label not explicitly declared must be local to where it's ref'd. */ 3446: DECL_CONTEXT (decl) = current_function_decl; 3447: 3448: DECL_MODE (decl) = VOIDmode; 3449: 3450: /* Say where one reference is to the label, 3451: for the sake of the error if it is not defined. */ 3452: DECL_SOURCE_LINE (decl) = lineno; 3453: DECL_SOURCE_FILE (decl) = input_filename; 3454: 3455: SET_IDENTIFIER_LABEL_VALUE (id, decl); 3456: 3457: named_labels = tree_cons (NULL_TREE, decl, named_labels); 3458: TREE_VALUE (named_label_uses) = decl; 3459: 3460: return decl; 3461: } 3462: 1.1.1.2 root 3463: /* Make a label named NAME in the current function, 3464: shadowing silently any that may be inherited from containing functions 3465: or containing scopes. 3466: 3467: Note that valid use, if the label being shadowed 3468: comes from another scope in the same function, 3469: requires calling declare_nonlocal_label right away. */ 3470: 3471: tree 3472: shadow_label (name) 3473: tree name; 3474: { 3475: register tree decl = IDENTIFIER_LABEL_VALUE (name); 3476: 1.1.1.5 root 3477: if (decl != NULL_TREE) 1.1.1.2 root 3478: { 3479: shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); 1.1.1.6 ! root 3480: SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); ! 3481: SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE); 1.1.1.2 root 3482: } 3483: 3484: return lookup_label (name); 3485: } 3486: 1.1 root 3487: /* Define a label, specifying the location in the source file. 3488: Return the LABEL_DECL node for the label, if the definition is valid. 3489: Otherwise return 0. */ 3490: 3491: tree 3492: define_label (filename, line, name) 3493: char *filename; 3494: int line; 3495: tree name; 3496: { 3497: tree decl = lookup_label (name); 3498: 3499: /* After labels, make any new cleanups go into their 3500: own new (temporary) binding contour. */ 3501: current_binding_level->more_cleanups_ok = 0; 3502: 1.1.1.2 root 3503: /* If label with this name is known from an outer context, shadow it. */ 1.1.1.5 root 3504: if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) 1.1.1.2 root 3505: { 3506: shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); 1.1.1.6 ! root 3507: SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); 1.1.1.2 root 3508: decl = lookup_label (name); 3509: } 3510: 1.1.1.5 root 3511: if (DECL_INITIAL (decl) != NULL_TREE) 1.1 root 3512: { 1.1.1.6 ! root 3513: cp_error ("duplicate label `%D'", decl); 1.1 root 3514: return 0; 3515: } 3516: else 3517: { 3518: tree uses, prev; 3519: 3520: /* Mark label as having been defined. */ 3521: DECL_INITIAL (decl) = error_mark_node; 3522: /* Say where in the source. */ 3523: DECL_SOURCE_FILE (decl) = filename; 3524: DECL_SOURCE_LINE (decl) = line; 3525: 1.1.1.5 root 3526: for (prev = NULL_TREE, uses = named_label_uses; 1.1 root 3527: uses; 3528: prev = uses, uses = TREE_CHAIN (uses)) 3529: if (TREE_VALUE (uses) == decl) 3530: { 3531: struct binding_level *b = current_binding_level; 1.1.1.5 root 3532: while (b) 1.1 root 3533: { 3534: tree new_decls = b->names; 3535: tree old_decls = ((tree)b == TREE_TYPE (uses) 3536: ? TREE_PURPOSE (uses) : NULL_TREE); 3537: while (new_decls != old_decls) 3538: { 3539: if (TREE_CODE (new_decls) == VAR_DECL 3540: /* Don't complain about crossing initialization 1.1.1.5 root 3541: of internal entities. They can't be accessed, 1.1 root 3542: and they should be cleaned up 3543: by the time we get to the label. */ 1.1.1.5 root 3544: && DECL_SOURCE_LINE (new_decls) != 0 1.1 root 3545: && ((DECL_INITIAL (new_decls) != NULL_TREE 3546: && DECL_INITIAL (new_decls) != error_mark_node) 3547: || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) 3548: { 3549: if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE) 1.1.1.6 ! root 3550: cp_error ("invalid jump to label `%D'", decl); 1.1 root 3551: SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl); 1.1.1.6 ! root 3552: cp_error ("crosses initialization of `%D'", new_decls); 1.1 root 3553: } 3554: new_decls = TREE_CHAIN (new_decls); 3555: } 3556: if ((tree)b == TREE_TYPE (uses)) 3557: break; 3558: b = b->level_chain; 3559: } 3560: 3561: if (prev) 3562: TREE_CHAIN (prev) = TREE_CHAIN (uses); 3563: else 3564: named_label_uses = TREE_CHAIN (uses); 3565: } 3566: current_function_return_value = NULL_TREE; 3567: return decl; 3568: } 3569: } 3570: 3571: /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ 1.1.1.5 root 3572: /* XXX Note decl is never actually used. (bpk) */ 1.1 root 3573: void 3574: define_case_label (decl) 3575: tree decl; 3576: { 3577: tree cleanup = last_cleanup_this_contour (); 3578: if (cleanup) 3579: { 3580: static int explained = 0; 1.1.1.6 ! root 3581: cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); 1.1 root 3582: error ("where case label appears here"); 3583: if (!explained) 3584: { 3585: error ("(enclose actions of previous case statements requiring"); 3586: error ("destructors in their own binding contours.)"); 3587: explained = 1; 3588: } 3589: } 3590: 3591: /* After labels, make any new cleanups go into their 3592: own new (temporary) binding contour. */ 3593: 3594: current_binding_level->more_cleanups_ok = 0; 3595: current_function_return_value = NULL_TREE; 3596: } 3597: 3598: /* Return the list of declarations of the current level. 3599: Note that this list is in reverse order unless/until 3600: you nreverse it; and when you do nreverse it, you must 3601: store the result back using `storedecls' or you will lose. */ 3602: 3603: tree 3604: getdecls () 3605: { 3606: return current_binding_level->names; 3607: } 3608: 3609: /* Return the list of type-tags (for structs, etc) of the current level. */ 3610: 3611: tree 3612: gettags () 3613: { 3614: return current_binding_level->tags; 3615: } 3616: 3617: /* Store the list of declarations of the current level. 3618: This is done for the parameter declarations of a function being defined, 3619: after they are modified in the light of any missing parameters. */ 3620: 3621: static void 3622: storedecls (decls) 3623: tree decls; 3624: { 3625: current_binding_level->names = decls; 3626: } 3627: 3628: /* Similarly, store the list of tags of the current level. */ 3629: 3630: static void 3631: storetags (tags) 3632: tree tags; 3633: { 3634: current_binding_level->tags = tags; 3635: } 3636: 3637: /* Given NAME, an IDENTIFIER_NODE, 3638: return the structure (or union or enum) definition for that name. 3639: Searches binding levels from BINDING_LEVEL up to the global level. 3640: If THISLEVEL_ONLY is nonzero, searches only the specified context 3641: (but skips any tag-transparent contexts to find one that is 3642: meaningful for tags). 3643: FORM says which kind of type the caller wants; 3644: it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. 3645: If the wrong kind of type is found, and it's not a template, an error is 3646: reported. */ 3647: 3648: static tree 3649: lookup_tag (form, name, binding_level, thislevel_only) 3650: enum tree_code form; 3651: struct binding_level *binding_level; 3652: tree name; 3653: int thislevel_only; 3654: { 3655: register struct binding_level *level; 3656: 3657: for (level = binding_level; level; level = level->level_chain) 3658: { 3659: register tree tail; 1.1.1.2 root 3660: if (ANON_AGGRNAME_P (name)) 3661: for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) 3662: { 3663: /* There's no need for error checking here, because 3664: anon names are unique throughout the compilation. */ 1.1.1.3 root 3665: if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) 1.1 root 3666: return TREE_VALUE (tail); 1.1.1.2 root 3667: } 3668: else 3669: for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) 3670: { 3671: if (TREE_PURPOSE (tail) == name) 3672: { 3673: enum tree_code code = TREE_CODE (TREE_VALUE (tail)); 3674: /* Should tighten this up; it'll probably permit 3675: UNION_TYPE and a struct template, for example. */ 3676: if (code != form 3677: && !(form != ENUMERAL_TYPE 3678: && (code == TEMPLATE_DECL 3679: || code == UNINSTANTIATED_P_TYPE))) 3680: 3681: { 3682: /* Definition isn't the kind we were looking for. */ 1.1.1.6 ! root 3683: cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), ! 3684: form); 1.1.1.2 root 3685: } 3686: return TREE_VALUE (tail); 3687: } 3688: } 1.1 root 3689: if (thislevel_only && ! level->tag_transparent) 3690: return NULL_TREE; 3691: if (current_class_type && level->level_chain == global_binding_level) 3692: { 3693: /* Try looking in this class's tags before heading into 3694: global binding level. */ 3695: tree context = current_class_type; 3696: while (context) 3697: { 3698: switch (TREE_CODE_CLASS (TREE_CODE (context))) 3699: { 3700: case 't': 3701: { 3702: tree these_tags = CLASSTYPE_TAGS (context); 1.1.1.2 root 3703: if (ANON_AGGRNAME_P (name)) 3704: while (these_tags) 3705: { 1.1.1.3 root 3706: if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) 1.1.1.2 root 3707: == name) 1.1 root 3708: return TREE_VALUE (tail); 1.1.1.2 root 3709: these_tags = TREE_CHAIN (these_tags); 3710: } 3711: else 3712: while (these_tags) 3713: { 3714: if (TREE_PURPOSE (these_tags) == name) 3715: { 3716: if (TREE_CODE (TREE_VALUE (these_tags)) != form) 3717: { 1.1.1.6 ! root 3718: cp_error ("`%#D' redeclared as %C in class scope", ! 3719: TREE_VALUE (tail), form); 1.1.1.2 root 3720: } 3721: return TREE_VALUE (tail); 3722: } 3723: these_tags = TREE_CHAIN (these_tags); 3724: } 1.1 root 3725: /* If this type is not yet complete, then don't 3726: look at its context. */ 3727: if (TYPE_SIZE (context) == NULL_TREE) 3728: goto no_context; 3729: /* Go to next enclosing type, if any. */ 3730: context = DECL_CONTEXT (TYPE_NAME (context)); 3731: break; 3732: case 'd': 3733: context = DECL_CONTEXT (context); 3734: break; 3735: default: 1.1.1.3 root 3736: my_friendly_abort (10); 1.1 root 3737: } 3738: continue; 3739: } 3740: no_context: 3741: break; 3742: } 3743: } 3744: } 3745: return NULL_TREE; 3746: } 3747: 3748: void 3749: set_current_level_tags_transparency (tags_transparent) 1.1.1.4 root 3750: int tags_transparent; 1.1 root 3751: { 3752: current_binding_level->tag_transparent = tags_transparent; 3753: } 3754: 3755: /* Given a type, find the tag that was defined for it and return the tag name. 3756: Otherwise return 0. However, the value can never be 0 3757: in the cases in which this is used. 3758: 3759: C++: If NAME is non-zero, this is the new name to install. This is 3760: done when replacing anonymous tags with real tag names. */ 3761: 3762: static tree 3763: lookup_tag_reverse (type, name) 3764: tree type; 3765: tree name; 3766: { 3767: register struct binding_level *level; 3768: 3769: for (level = current_binding_level; level; level = level->level_chain) 3770: { 3771: register tree tail; 3772: for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) 3773: { 3774: if (TREE_VALUE (tail) == type) 3775: { 3776: if (name) 3777: TREE_PURPOSE (tail) = name; 3778: return TREE_PURPOSE (tail); 3779: } 3780: } 3781: } 3782: return NULL_TREE; 3783: } 3784: 3785: /* Given type TYPE which was not declared in C++ language context, 1.1.1.2 root 3786: attempt to find a name by which it is referred. */ 1.1 root 3787: tree 3788: typedecl_for_tag (tag) 3789: tree tag; 3790: { 3791: struct binding_level *b = current_binding_level; 3792: 3793: if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL) 3794: return TYPE_NAME (tag); 3795: 3796: while (b) 3797: { 3798: tree decls = b->names; 3799: while (decls) 3800: { 3801: if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag) 3802: break; 3803: decls = TREE_CHAIN (decls); 3804: } 3805: if (decls) 3806: return decls; 3807: b = b->level_chain; 3808: } 3809: return NULL_TREE; 3810: } 3811: 3812: /* Called when we must retroactively globalize a type we previously 1.1.1.2 root 3813: thought needed to be nested. This happens, for example, when 1.1 root 3814: a `friend class' declaration is seen for an undefined type. */ 3815: 3816: static void 3817: globalize_nested_type (type) 3818: tree type; 3819: { 3820: tree t, prev = NULL_TREE, d = TYPE_NAME (type); 3821: struct binding_level *b; 1.1.1.6 ! root 3822: tree name = DECL_NAME (d); ! 3823: #if NEW_CLASS_SCOPING ! 3824: tree class_shadower = NULL_TREE, type_shadower = NULL_TREE, shadow; ! 3825: #endif 1.1 root 3826: 1.1.1.4 root 3827: my_friendly_assert (TREE_CODE (d) == TYPE_DECL, 144); 1.1 root 3828: /* If the type value has already been globalized, then we're set. */ 1.1.1.6 ! root 3829: if (IDENTIFIER_GLOBAL_VALUE (name) == d) 1.1 root 3830: return; 1.1.1.6 ! root 3831: if (IDENTIFIER_HAS_TYPE_VALUE (name)) 1.1 root 3832: { 3833: /* If this type already made it into the global tags, 3834: silently return. */ 3835: if (value_member (type, global_binding_level->tags)) 3836: return; 3837: } 3838: 1.1.1.6 ! root 3839: #if NEW_CLASS_SCOPING ! 3840: if (DECL_LANG_SPECIFIC (d)) ! 3841: DECL_CLASS_CONTEXT (d) = NULL_TREE; ! 3842: #else 1.1 root 3843: set_identifier_type_value (DECL_NESTED_TYPENAME (d), NULL_TREE); 1.1.1.6 ! root 3844: #endif 1.1 root 3845: DECL_CONTEXT (d) = NULL_TREE; 1.1.1.6 ! root 3846: TYPE_CONTEXT (d) = NULL_TREE; ! 3847: DECL_NESTED_TYPENAME (d) = name; 1.1 root 3848: if (class_binding_level) 3849: b = class_binding_level; 3850: else 3851: b = current_binding_level; 3852: while (b != global_binding_level) 3853: { 3854: prev = NULL_TREE; 3855: if (b->parm_flag == 2) 3856: for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t)) 3857: if (TREE_VALUE (t) == type) 3858: goto found; 1.1.1.6 ! root 3859: #if NEW_CLASS_SCOPING ! 3860: /* Find (im?)possible objects shadowing the type we're globalizing. */ ! 3861: class_shadower = purpose_member (name, b->class_shadowed); ! 3862: type_shadower = purpose_member (name, b->type_shadowed); ! 3863: #endif 1.1 root 3864: b = b->level_chain; 3865: } 3866: /* We failed to find this tag anywhere up the binding chains. 3867: B is now the global binding level... check there. */ 3868: prev = NULL_TREE; 3869: if (b->parm_flag == 2) 3870: for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t)) 3871: if (TREE_VALUE (t) == type) 3872: goto foundglobal; 3873: /* It wasn't in global scope either, so this is an anonymous forward ref 3874: of some kind; let it happen. */ 3875: return; 3876: 3877: foundglobal: 3878: print_node_brief (stderr, "Tried to globalize already-global type ", 3879: type, 0); 1.1.1.3 root 3880: my_friendly_abort (11); 1.1 root 3881: 3882: found: 3883: /* Pull the tag out of the nested binding contour. */ 3884: if (prev) 3885: TREE_CHAIN (prev) = TREE_CHAIN (t); 3886: else 3887: b->tags = TREE_CHAIN (t); 3888: 1.1.1.6 ! root 3889: #if NEW_CLASS_SCOPING ! 3890: /* Find and remove the corresponding entry from the class_shadowed list, ! 3891: and move the shadowed value to a possibly later shadow. If there were ! 3892: no such beast (could there ever be?), install the previously shadowed ! 3893: value as the IDENTIFIER_CLASS_VALUE. */ ! 3894: prev = NULL_TREE; ! 3895: for (shadow = b->class_shadowed; ! 3896: shadow != NULL_TREE; ! 3897: prev = shadow, shadow = TREE_CHAIN (shadow)) ! 3898: if (TREE_PURPOSE (shadow) == name) ! 3899: break; ! 3900: ! 3901: if (shadow) ! 3902: { ! 3903: /* An example where shadow is NULL is when you have something ! 3904: like `class foo { public: struct bar; bar *x(); };', since ! 3905: bar isn't added to the class_shadowed list until it's been ! 3906: defined. */ ! 3907: ! 3908: if (prev) ! 3909: TREE_CHAIN (prev) = TREE_CHAIN (shadow); ! 3910: else ! 3911: b->class_shadowed = TREE_CHAIN (shadow); ! 3912: ! 3913: if (class_shadower) ! 3914: TREE_VALUE (class_shadower) = TREE_VALUE (shadow); ! 3915: else ! 3916: IDENTIFIER_CLASS_VALUE (name) = TREE_VALUE (shadow); ! 3917: } ! 3918: ! 3919: /* Find and remove the corresponding entry from the type_shadowed list, ! 3920: and move the shadowed value to a possibly later shadow. If there were ! 3921: no such beast (could there ever be?), install the previously shadowed ! 3922: value as the IDENTIFIER_TYPE_VALUE. */ ! 3923: prev = NULL_TREE; ! 3924: for (shadow = b->type_shadowed; ! 3925: shadow != NULL_TREE; ! 3926: prev = shadow, shadow = TREE_CHAIN (shadow)) ! 3927: if (TREE_PURPOSE (shadow) == name) ! 3928: break; ! 3929: ! 3930: if (shadow) ! 3931: { ! 3932: if (prev) ! 3933: TREE_CHAIN (prev) = TREE_CHAIN (shadow); ! 3934: else ! 3935: b->type_shadowed = TREE_CHAIN (shadow); ! 3936: ! 3937: if (type_shadower) ! 3938: TREE_VALUE (type_shadower) = TREE_VALUE (shadow); ! 3939: else ! 3940: SET_IDENTIFIER_TYPE_VALUE (name, TREE_VALUE (shadow)); ! 3941: } ! 3942: #else 1.1 root 3943: set_identifier_type_value (TREE_PURPOSE (t), TREE_VALUE (t)); 1.1.1.6 ! root 3944: #endif 1.1 root 3945: global_binding_level->tags 3946: = perm_tree_cons (TREE_PURPOSE (t), TREE_VALUE (t), 3947: global_binding_level->tags); 3948: 3949: /* Pull the tag out of the class's tags (if there). 3950: It won't show up if it appears e.g. in a parameter declaration 3951: or definition of a member function of this type. */ 3952: if (current_class_type != NULL_TREE) 3953: { 3954: for (t = CLASSTYPE_TAGS (current_class_type), prev = NULL_TREE; 3955: t != NULL_TREE; 3956: prev = t, t = TREE_CHAIN (t)) 3957: if (TREE_VALUE (t) == type) 3958: break; 3959: 3960: if (t != NULL_TREE) 3961: { 3962: if (prev) 3963: TREE_CHAIN (prev) = TREE_CHAIN (t); 3964: else 3965: CLASSTYPE_TAGS (current_class_type) = TREE_CHAIN (t); 3966: } 3967: } 3968: 3969: pushdecl_top_level (d); 3970: } 3971: 3972: static void 3973: maybe_globalize_type (type) 3974: tree type; 3975: { 3976: if ((((TREE_CODE (type) == RECORD_TYPE 3977: || TREE_CODE (type) == UNION_TYPE) 3978: && ! TYPE_BEING_DEFINED (type)) 3979: || TREE_CODE (type) == ENUMERAL_TYPE) 3980: && TYPE_SIZE (type) == NULL_TREE 3981: /* This part is gross. We keep calling here with types that 3982: are instantiations of templates, when that type should is 3983: global, or doesn't have the type decl established yet, 3984: so globalizing will fail (because it won't find the type in any 3985: non-global scope). So we short-circuit that path. */ 3986: && !(TYPE_NAME (type) != NULL_TREE 1.1.1.3 root 3987: && TYPE_IDENTIFIER (type) != NULL_TREE 3988: && ! IDENTIFIER_HAS_TYPE_VALUE (TYPE_IDENTIFIER (type))) 1.1 root 3989: ) 3990: globalize_nested_type (type); 3991: } 3992: 3993: /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). 3994: Return the type value, or NULL_TREE if not found. */ 3995: static tree 3996: lookup_nested_type (type, context) 3997: tree type; 3998: tree context; 3999: { 4000: if (context == NULL_TREE) 4001: return NULL_TREE; 4002: while (context) 4003: { 4004: switch (TREE_CODE (context)) 4005: { 4006: case TYPE_DECL: 4007: { 4008: tree ctype = TREE_TYPE (context); 4009: tree match = value_member (type, CLASSTYPE_TAGS (ctype)); 4010: if (match) 4011: return TREE_VALUE (match); 4012: context = DECL_CONTEXT (context); 1.1.1.5 root 4013: 4014: /* When we have a nested class whose member functions have 4015: local types (e.g., a set of enums), we'll arrive here 4016: with the DECL_CONTEXT as the actual RECORD_TYPE node for 4017: the enclosing class. Instead, we want to make sure we 4018: come back in here with the TYPE_DECL, not the RECORD_TYPE. */ 4019: if (context && TREE_CODE (context) == RECORD_TYPE) 4020: context = TREE_CHAIN (context); 1.1 root 4021: } 4022: break; 4023: case FUNCTION_DECL: 4024: return TYPE_IDENTIFIER (type) ? lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE; 4025: break; 4026: default: 1.1.1.3 root 4027: my_friendly_abort (12); 1.1 root 4028: } 4029: } 4030: return NULL_TREE; 4031: } 4032: 1.1.1.3 root 4033: /* Look up NAME in the current binding level and its superiors in the 4034: namespace of variables, functions and typedefs. Return a ..._DECL 4035: node of some kind representing its definition if there is only one 4036: such declaration, or return a TREE_LIST with all the overloaded 4037: definitions if there are many, or return 0 if it is undefined. 1.1 root 4038: 4039: If PREFER_TYPE is > 0, we prefer TYPE_DECLs. 4040: If PREFER_TYPE is = 0, we prefer non-TYPE_DECLs. 4041: If PREFER_TYPE is < 0, we arbitrate according to lexical context. */ 4042: 4043: tree 4044: lookup_name (name, prefer_type) 4045: tree name; 1.1.1.4 root 4046: int prefer_type; 1.1 root 4047: { 4048: register tree val; 4049: 4050: if (current_binding_level != global_binding_level 4051: && IDENTIFIER_LOCAL_VALUE (name)) 4052: val = IDENTIFIER_LOCAL_VALUE (name); 4053: /* In C++ class fields are between local and global scope, 4054: just before the global scope. */ 4055: else if (current_class_type) 4056: { 4057: val = IDENTIFIER_CLASS_VALUE (name); 4058: if (val == NULL_TREE 1.1.1.5 root 4059: && TYPE_SIZE (current_class_type) == NULL_TREE 1.1 root 4060: && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type)) 4061: { 4062: /* Try to find values from base classes 4063: if we are presently defining a type. 4064: We are presently only interested in TYPE_DECLs. */ 1.1.1.5 root 4065: val = lookup_field (current_class_type, name, 0, prefer_type < 0); 1.1 root 4066: if (val == error_mark_node) 4067: return val; 4068: if (val && TREE_CODE (val) != TYPE_DECL) 4069: val = NULL_TREE; 4070: } 1.1.1.5 root 4071: 4072: /* yylex() calls this with -2, since we should never start digging for 4073: the nested name at the point where we haven't even, for example, 4074: created the COMPONENT_REF or anything like that. */ 1.1 root 4075: if (val == NULL_TREE) 1.1.1.5 root 4076: val = lookup_nested_field (name, prefer_type != -2); 4077: 1.1.1.4 root 4078: if (val == NULL_TREE) 1.1 root 4079: val = IDENTIFIER_GLOBAL_VALUE (name); 4080: } 4081: else 4082: val = IDENTIFIER_GLOBAL_VALUE (name); 4083: 4084: if (val) 4085: { 4086: extern int looking_for_typename; 4087: 4088: /* Arbitrate between finding a TYPE_DECL and finding 4089: other kinds of _DECLs. */ 4090: if (TREE_CODE (val) == TYPE_DECL || looking_for_typename < 0) 4091: return val; 4092: 4093: if (IDENTIFIER_HAS_TYPE_VALUE (name)) 4094: { 4095: register tree val_as_type = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name)); 4096: 4097: if (val == val_as_type || prefer_type > 0 4098: || looking_for_typename > 0) 4099: return val_as_type; 4100: if (prefer_type == 0) 4101: return val; 4102: return arbitrate_lookup (name, val, val_as_type); 4103: } 4104: if (TREE_TYPE (val) == error_mark_node) 4105: return error_mark_node; 4106: } 4107: 4108: return val; 4109: } 4110: 4111: /* Similar to `lookup_name' but look only at current binding level. */ 4112: 1.1.1.5 root 4113: tree 1.1 root 4114: lookup_name_current_level (name) 4115: tree name; 4116: { 4117: register tree t; 4118: 4119: if (current_binding_level == global_binding_level) 4120: return IDENTIFIER_GLOBAL_VALUE (name); 4121: 1.1.1.5 root 4122: if (IDENTIFIER_LOCAL_VALUE (name) == NULL_TREE) 1.1 root 4123: return 0; 4124: 4125: for (t = current_binding_level->names; t; t = TREE_CHAIN (t)) 4126: if (DECL_NAME (t) == name) 4127: break; 4128: 4129: return t; 4130: } 4131: 1.1.1.4 root 4132: /* Arrange for the user to get a source line number, even when the 4133: compiler is going down in flames, so that she at least has a 4134: chance of working around problems in the compiler. We used to 4135: call error(), but that let the segmentation fault continue 4136: through; now, it's much more passive by asking them to send the 4137: maintainers mail about the problem. */ 4138: 1.1.1.5 root 4139: static void 1.1.1.6 ! root 4140: signal_catch (sig) 1.1.1.5 root 4141: int sig; 1.1.1.4 root 4142: { 4143: signal (SIGSEGV, SIG_DFL); 1.1.1.5 root 4144: #ifdef SIGIOT 4145: signal (SIGIOT, SIG_DFL); 4146: #endif 4147: #ifdef SIGILL 4148: signal (SIGILL, SIG_DFL); 4149: #endif 4150: #ifdef SIGABRT 4151: signal (SIGABRT, SIG_DFL); 4152: #endif 1.1.1.6 ! root 4153: #ifdef SIGBUS ! 4154: signal (SIGBUS, SIG_DFL); ! 4155: #endif 1.1.1.4 root 4156: my_friendly_abort (0); 4157: } 4158: 1.1 root 4159: /* Array for holding types considered "built-in". These types 4160: are output in the module in which `main' is defined. */ 4161: static tree *builtin_type_tdescs_arr; 4162: static int builtin_type_tdescs_len, builtin_type_tdescs_max; 4163: 4164: /* Push the declarations of builtin types into the namespace. 4165: RID_INDEX, if < RID_MAX is the index of the builtin type 4166: in the array RID_POINTERS. NAME is the name used when looking 4167: up the builtin type. TYPE is the _TYPE node for the builtin type. */ 4168: 4169: static void 4170: record_builtin_type (rid_index, name, type) 4171: enum rid rid_index; 4172: char *name; 4173: tree type; 4174: { 4175: tree rname = NULL_TREE, tname = NULL_TREE; 4176: tree tdecl; 4177: 1.1.1.2 root 4178: if ((int) rid_index < (int) RID_MAX) 1.1 root 4179: rname = ridpointers[(int) rid_index]; 4180: if (name) 4181: tname = get_identifier (name); 4182: 1.1.1.6 ! root 4183: TYPE_BUILT_IN (type) = 1; ! 4184: 1.1 root 4185: if (tname) 4186: { 1.1.1.2 root 4187: #if 0 /* not yet, should get fixed properly later */ 4188: tdecl = pushdecl (make_type_decl (tname, type)); 4189: #else 1.1 root 4190: tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); 1.1.1.2 root 4191: #endif 1.1 root 4192: set_identifier_type_value (tname, NULL_TREE); 1.1.1.2 root 4193: if ((int) rid_index < (int) RID_MAX) 1.1 root 4194: IDENTIFIER_GLOBAL_VALUE (tname) = tdecl; 4195: } 4196: if (rname != NULL_TREE) 4197: { 4198: if (tname != NULL_TREE) 4199: { 4200: set_identifier_type_value (rname, NULL_TREE); 4201: IDENTIFIER_GLOBAL_VALUE (rname) = tdecl; 4202: } 4203: else 4204: { 1.1.1.2 root 4205: #if 0 /* not yet, should get fixed properly later */ 4206: tdecl = pushdecl (make_type_decl (rname, type)); 4207: #else 1.1 root 4208: tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); 1.1.1.2 root 4209: #endif 1.1 root 4210: set_identifier_type_value (rname, NULL_TREE); 4211: } 4212: } 4213: 4214: if (flag_dossier) 4215: { 4216: if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max) 4217: { 4218: builtin_type_tdescs_max *= 2; 4219: builtin_type_tdescs_arr 4220: = (tree *)xrealloc (builtin_type_tdescs_arr, 4221: builtin_type_tdescs_max * sizeof (tree)); 4222: } 4223: builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type; 4224: if (TREE_CODE (type) != POINTER_TYPE) 4225: { 4226: builtin_type_tdescs_arr[builtin_type_tdescs_len++] 4227: = build_pointer_type (type); 4228: builtin_type_tdescs_arr[builtin_type_tdescs_len++] 4229: = build_type_variant (TYPE_POINTER_TO (type), 1, 0); 4230: } 4231: if (TREE_CODE (type) != VOID_TYPE) 4232: { 4233: builtin_type_tdescs_arr[builtin_type_tdescs_len++] 4234: = build_reference_type (type); 4235: builtin_type_tdescs_arr[builtin_type_tdescs_len++] 4236: = build_type_variant (TYPE_REFERENCE_TO (type), 1, 0); 4237: } 4238: } 4239: } 4240: 4241: static void 4242: output_builtin_tdesc_entries () 4243: { 4244: extern struct obstack permanent_obstack; 4245: 4246: /* If there's more than one main in this file, don't crash. */ 4247: if (builtin_type_tdescs_arr == 0) 4248: return; 4249: 4250: push_obstacks (&permanent_obstack, &permanent_obstack); 4251: while (builtin_type_tdescs_len > 0) 4252: { 4253: tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len]; 4254: tree tdesc = build_t_desc (type, 0); 4255: TREE_ASM_WRITTEN (tdesc) = 0; 4256: build_t_desc (type, 2); 4257: } 4258: free (builtin_type_tdescs_arr); 4259: builtin_type_tdescs_arr = 0; 4260: pop_obstacks (); 4261: } 4262: 4263: /* Push overloaded decl, in global scope, with one argument so it 4264: can be used as a callback from define_function. */ 4265: static void 4266: push_overloaded_decl_1 (x) 4267: tree x; 4268: { 4269: push_overloaded_decl (x, 0); 4270: } 4271: 4272: /* Create the predefined scalar types of C, 4273: and some nodes representing standard constants (0, 1, (void *)0). 4274: Initialize the global binding level. 4275: Make definitions for built-in primitive functions. */ 4276: 4277: void 4278: init_decl_processing () 4279: { 1.1.1.5 root 4280: tree decl; 1.1 root 4281: register tree endlink, int_endlink, double_endlink, ptr_endlink; 4282: tree fields[20]; 4283: /* Either char* or void*. */ 4284: tree traditional_ptr_type_node; 4285: /* Data type of memcpy. */ 4286: tree memcpy_ftype; 1.1.1.6 ! root 4287: /* Data type of strncpy. */ ! 4288: tree strncpy_ftype; 1.1 root 4289: int wchar_type_size; 1.1.1.6 ! root 4290: tree temp; ! 4291: tree array_domain_type; 1.1 root 4292: 4293: /* Have to make these distinct before we try using them. */ 4294: lang_name_cplusplus = get_identifier ("C++"); 4295: lang_name_c = get_identifier ("C"); 4296: 4297: /* Initially, C. */ 4298: current_lang_name = lang_name_c; 4299: 4300: current_function_decl = NULL_TREE; 4301: named_labels = NULL_TREE; 4302: named_label_uses = NULL_TREE; 4303: current_binding_level = NULL_BINDING_LEVEL; 4304: free_binding_level = NULL_BINDING_LEVEL; 4305: 1.1.1.4 root 4306: /* Because most segmentation signals can be traced back into user 4307: code, catch them and at least give the user a chance of working 4308: around compiler bugs. */ 1.1.1.6 ! root 4309: signal (SIGSEGV, signal_catch); 1.1.1.4 root 4310: 1.1.1.6 ! root 4311: /* We will also catch aborts in the back-end through signal_catch and ! 4312: give the user a chance to see where the error might be, and to defeat ! 4313: aborts in the back-end when there have been errors previously in their ! 4314: code. */ 1.1.1.5 root 4315: #ifdef SIGIOT 1.1.1.6 ! root 4316: signal (SIGIOT, signal_catch); 1.1.1.5 root 4317: #endif 4318: #ifdef SIGILL 1.1.1.6 ! root 4319: signal (SIGILL, signal_catch); 1.1.1.5 root 4320: #endif 4321: #ifdef SIGABRT 1.1.1.6 ! root 4322: signal (SIGABRT, signal_catch); ! 4323: #endif ! 4324: #ifdef SIGBUS ! 4325: signal (SIGBUS, signal_catch); 1.1.1.5 root 4326: #endif 4327: 1.1 root 4328: gcc_obstack_init (&decl_obstack); 4329: if (flag_dossier) 4330: { 4331: builtin_type_tdescs_max = 100; 4332: builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree)); 4333: } 4334: 4335: /* Must lay these out before anything else gets laid out. */ 4336: error_mark_node = make_node (ERROR_MARK); 4337: TREE_PERMANENT (error_mark_node) = 1; 4338: TREE_TYPE (error_mark_node) = error_mark_node; 4339: error_mark_list = build_tree_list (error_mark_node, error_mark_node); 4340: TREE_TYPE (error_mark_list) = error_mark_node; 4341: 4342: pushlevel (0); /* make the binding_level structure for global names. */ 4343: global_binding_level = current_binding_level; 4344: 4345: this_identifier = get_identifier (THIS_NAME); 4346: in_charge_identifier = get_identifier (IN_CHARGE_NAME); 1.1.1.6 ! root 4347: pfn_identifier = get_identifier (VTABLE_PFN_NAME); ! 4348: index_identifier = get_identifier (VTABLE_INDEX_NAME); ! 4349: delta_identifier = get_identifier (VTABLE_DELTA_NAME); ! 4350: delta2_identifier = get_identifier (VTABLE_DELTA2_NAME); ! 4351: pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2"); 1.1 root 4352: 4353: /* Define `int' and `char' first so that dbx will output them first. */ 4354: 4355: integer_type_node = make_signed_type (INT_TYPE_SIZE); 1.1.1.5 root 4356: record_builtin_type (RID_INT, NULL_PTR, integer_type_node); 1.1 root 4357: 4358: /* Define `char', which is like either `signed char' or `unsigned char' 4359: but not the same as either. */ 4360: 4361: char_type_node = 4362: (flag_signed_char 4363: ? make_signed_type (CHAR_TYPE_SIZE) 4364: : make_unsigned_type (CHAR_TYPE_SIZE)); 4365: record_builtin_type (RID_CHAR, "char", char_type_node); 4366: 4367: long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); 4368: record_builtin_type (RID_LONG, "long int", long_integer_type_node); 4369: 4370: unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); 4371: record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); 4372: 4373: long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); 4374: record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); 4375: record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); 4376: 4377: /* `unsigned long' is the standard type for sizeof. 4378: Traditionally, use a signed type. 4379: Note that stddef.h uses `unsigned long', 4380: and this must agree, even of long and int are the same size. */ 1.1.1.6 ! root 4381: sizetype ! 4382: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); ! 4383: if (flag_traditional && TREE_UNSIGNED (sizetype)) ! 4384: sizetype = signed_type (sizetype); 1.1 root 4385: 4386: ptrdiff_type_node 4387: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); 4388: 4389: TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype; 4390: TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype; 4391: TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype; 4392: TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype; 4393: TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype; 4394: 4395: short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); 4396: record_builtin_type (RID_SHORT, "short int", short_integer_type_node); 4397: long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); 4398: record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); 4399: short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); 4400: record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); 4401: record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); 4402: long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); 4403: record_builtin_type (RID_MAX, "long long unsigned int", long_long_unsigned_type_node); 4404: record_builtin_type (RID_MAX, "long long unsigned", long_long_unsigned_type_node); 4405: 4406: /* Define both `signed char' and `unsigned char'. */ 4407: signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); 4408: record_builtin_type (RID_MAX, "signed char", signed_char_type_node); 4409: unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); 4410: record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); 4411: 1.1.1.4 root 4412: /* These are types that type_for_size and type_for_mode use. */ 4413: intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); 4414: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); 4415: intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); 4416: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); 4417: intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); 4418: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); 4419: intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); 4420: pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); 4421: unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); 4422: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); 4423: unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); 4424: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); 4425: unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); 4426: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); 4427: unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); 4428: pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); 4429: 1.1 root 4430: float_type_node = make_node (REAL_TYPE); 4431: TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; 1.1.1.6 ! root 4432: record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node); 1.1 root 4433: layout_type (float_type_node); 4434: 4435: double_type_node = make_node (REAL_TYPE); 4436: if (flag_short_double) 4437: TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; 4438: else 4439: TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; 1.1.1.6 ! root 4440: record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node); 1.1 root 4441: layout_type (double_type_node); 4442: 4443: long_double_type_node = make_node (REAL_TYPE); 4444: TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; 4445: record_builtin_type (RID_MAX, "long double", long_double_type_node); 4446: layout_type (long_double_type_node); 4447: 4448: integer_zero_node = build_int_2 (0, 0); 4449: TREE_TYPE (integer_zero_node) = integer_type_node; 4450: integer_one_node = build_int_2 (1, 0); 4451: TREE_TYPE (integer_one_node) = integer_type_node; 4452: integer_two_node = build_int_2 (2, 0); 4453: TREE_TYPE (integer_two_node) = integer_type_node; 4454: integer_three_node = build_int_2 (3, 0); 4455: TREE_TYPE (integer_three_node) = integer_type_node; 4456: empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE); 4457: 4458: /* These are needed by stor-layout.c. */ 4459: size_zero_node = size_int (0); 4460: size_one_node = size_int (1); 4461: 4462: void_type_node = make_node (VOID_TYPE); 1.1.1.6 ! root 4463: record_builtin_type (RID_VOID, NULL_PTR, void_type_node); 1.1 root 4464: layout_type (void_type_node); /* Uses integer_zero_node. */ 4465: void_list_node = build_tree_list (NULL_TREE, void_type_node); 4466: TREE_PARMLIST (void_list_node) = 1; 4467: 4468: null_pointer_node = build_int_2 (0, 0); 4469: TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); 4470: layout_type (TREE_TYPE (null_pointer_node)); 4471: 4472: /* Used for expressions that do nothing, but are not errors. */ 4473: void_zero_node = build_int_2 (0, 0); 4474: TREE_TYPE (void_zero_node) = void_type_node; 4475: 4476: string_type_node = build_pointer_type (char_type_node); 4477: const_string_type_node = build_pointer_type (build_type_variant (char_type_node, 1, 0)); 1.1.1.6 ! root 4478: record_builtin_type (RID_MAX, NULL_PTR, string_type_node); ! 4479: ! 4480: /* Make a type to be the domain of a few array types ! 4481: whose domains don't really matter. ! 4482: 200 is small enough that it always fits in size_t ! 4483: and large enough that it can hold most function names for the ! 4484: initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ ! 4485: array_domain_type = build_index_type (build_int_2 (200, 0)); 1.1 root 4486: 1.1.1.6 ! root 4487: /* make a type for arrays of characters. 1.1 root 4488: With luck nothing will ever really depend on the length of this 4489: array type. */ 4490: char_array_type_node 1.1.1.6 ! root 4491: = build_array_type (char_type_node, array_domain_type); 1.1 root 4492: /* Likewise for arrays of ints. */ 4493: int_array_type_node 1.1.1.6 ! root 4494: = build_array_type (integer_type_node, array_domain_type); 1.1 root 4495: 4496: /* This is just some anonymous class type. Nobody should ever 4497: need to look inside this envelope. */ 4498: class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); 4499: 4500: default_function_type 4501: = build_function_type (integer_type_node, NULL_TREE); 4502: build_pointer_type (default_function_type); 4503: 4504: ptr_type_node = build_pointer_type (void_type_node); 4505: const_ptr_type_node = build_pointer_type (build_type_variant (void_type_node, 1, 0)); 1.1.1.6 ! root 4506: record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); 1.1 root 4507: endlink = void_list_node; 4508: int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); 4509: double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); 4510: ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink); 4511: 4512: double_ftype_double 4513: = build_function_type (double_type_node, double_endlink); 4514: 4515: double_ftype_double_double 4516: = build_function_type (double_type_node, 4517: tree_cons (NULL_TREE, double_type_node, double_endlink)); 4518: 4519: int_ftype_int 4520: = build_function_type (integer_type_node, int_endlink); 4521: 4522: long_ftype_long 4523: = build_function_type (long_integer_type_node, 4524: tree_cons (NULL_TREE, long_integer_type_node, endlink)); 4525: 4526: void_ftype_ptr_ptr_int 4527: = build_function_type (void_type_node, 4528: tree_cons (NULL_TREE, ptr_type_node, 4529: tree_cons (NULL_TREE, ptr_type_node, 4530: int_endlink))); 4531: 4532: int_ftype_cptr_cptr_sizet 4533: = build_function_type (integer_type_node, 4534: tree_cons (NULL_TREE, const_ptr_type_node, 4535: tree_cons (NULL_TREE, const_ptr_type_node, 4536: tree_cons (NULL_TREE, 4537: sizetype, 4538: endlink)))); 4539: 4540: void_ftype_ptr_int_int 4541: = build_function_type (void_type_node, 4542: tree_cons (NULL_TREE, ptr_type_node, 4543: tree_cons (NULL_TREE, integer_type_node, 4544: int_endlink))); 4545: 4546: string_ftype_ptr_ptr /* strcpy prototype */ 4547: = build_function_type (string_type_node, 4548: tree_cons (NULL_TREE, string_type_node, 4549: tree_cons (NULL_TREE, 4550: const_string_type_node, 4551: endlink))); 4552: 1.1.1.6 ! root 4553: #if 0 ! 4554: /* Not yet. */ ! 4555: strncpy_ftype /* strncpy prototype */ ! 4556: = build_function_type (string_type_node, ! 4557: tree_cons (NULL_TREE, string_type_node, ! 4558: tree_cons (NULL_TREE, const_string_type_node, ! 4559: tree_cons (NULL_TREE, ! 4560: sizetype, ! 4561: endlink)))); ! 4562: #endif ! 4563: 1.1 root 4564: int_ftype_string_string /* strcmp prototype */ 4565: = build_function_type (integer_type_node, 4566: tree_cons (NULL_TREE, const_string_type_node, 4567: tree_cons (NULL_TREE, 4568: const_string_type_node, 4569: endlink))); 4570: 4571: sizet_ftype_string /* strlen prototype */ 4572: = build_function_type (sizetype, 4573: tree_cons (NULL_TREE, const_string_type_node, 4574: endlink)); 4575: 4576: traditional_ptr_type_node 4577: = (flag_traditional ? string_type_node : ptr_type_node); 4578: 4579: memcpy_ftype /* memcpy prototype */ 4580: = build_function_type (traditional_ptr_type_node, 4581: tree_cons (NULL_TREE, ptr_type_node, 4582: tree_cons (NULL_TREE, const_ptr_type_node, 4583: tree_cons (NULL_TREE, 4584: sizetype, 4585: endlink)))); 4586: 4587: #ifdef VTABLE_USES_MASK 4588: /* This is primarily for virtual function definition. We 4589: declare an array of `void *', which can later be 4590: converted to the appropriate function pointer type. 4591: To do pointers to members, we need a mask which can 4592: distinguish an index value into a virtual function table 4593: from an address. */ 1.1.1.4 root 4594: vtbl_mask = build_int_2 (~((HOST_WIDE_INT) VINDEX_MAX - 1), -1); 1.1 root 4595: #endif 4596: 4597: vtbl_type_node 4598: = build_array_type (ptr_type_node, NULL_TREE); 4599: layout_type (vtbl_type_node); 4600: vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0); 1.1.1.6 ! root 4601: record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node); 1.1 root 4602: 1.1.1.4 root 4603: builtin_function ("__builtin_constant_p", int_ftype_int, 1.1.1.5 root 4604: BUILT_IN_CONSTANT_P, NULL_PTR); 1.1 root 4605: 4606: builtin_function ("__builtin_alloca", 4607: build_function_type (ptr_type_node, 4608: tree_cons (NULL_TREE, 4609: sizetype, 4610: endlink)), 4611: BUILT_IN_ALLOCA, "alloca"); 4612: #if 0 4613: builtin_function ("alloca", 4614: build_function_type (ptr_type_node, 4615: tree_cons (NULL_TREE, 4616: sizetype, 4617: endlink)), 1.1.1.5 root 4618: BUILT_IN_ALLOCA, NULL_PTR); 1.1 root 4619: #endif 4620: 1.1.1.5 root 4621: builtin_function ("__builtin_abs", int_ftype_int, 4622: BUILT_IN_ABS, NULL_PTR); 4623: builtin_function ("__builtin_fabs", double_ftype_double, 4624: BUILT_IN_FABS, NULL_PTR); 4625: builtin_function ("__builtin_labs", long_ftype_long, 4626: BUILT_IN_LABS, NULL_PTR); 4627: builtin_function ("__builtin_ffs", int_ftype_int, 4628: BUILT_IN_FFS, NULL_PTR); 4629: builtin_function ("__builtin_fsqrt", double_ftype_double, 4630: BUILT_IN_FSQRT, NULL_PTR); 4631: builtin_function ("__builtin_sin", double_ftype_double, 4632: BUILT_IN_SIN, "sin"); 4633: builtin_function ("__builtin_cos", double_ftype_double, 4634: BUILT_IN_COS, "cos"); 1.1.1.4 root 4635: builtin_function ("__builtin_saveregs", 4636: build_function_type (ptr_type_node, NULL_TREE), 1.1.1.5 root 4637: BUILT_IN_SAVEREGS, NULL_PTR); 4638: /* EXPAND_BUILTIN_VARARGS is obsolete. */ 4639: #if 0 1.1 root 4640: builtin_function ("__builtin_varargs", 4641: build_function_type (ptr_type_node, 4642: tree_cons (NULL_TREE, 4643: integer_type_node, 4644: endlink)), 1.1.1.5 root 4645: BUILT_IN_VARARGS, NULL_PTR); 1.1 root 4646: #endif 4647: builtin_function ("__builtin_classify_type", default_function_type, 1.1.1.5 root 4648: BUILT_IN_CLASSIFY_TYPE, NULL_PTR); 1.1 root 4649: builtin_function ("__builtin_next_arg", 4650: build_function_type (ptr_type_node, endlink), 1.1.1.5 root 4651: BUILT_IN_NEXT_ARG, NULL_PTR); 4652: builtin_function ("__builtin_args_info", 4653: build_function_type (integer_type_node, 4654: tree_cons (NULL_TREE, 4655: integer_type_node, 4656: endlink)), 4657: BUILT_IN_ARGS_INFO, NULL_PTR); 1.1 root 4658: 1.1.1.6 ! root 4659: /* Untyped call and return. */ ! 4660: builtin_function ("__builtin_apply_args", ! 4661: build_function_type (ptr_type_node, NULL_TREE), ! 4662: BUILT_IN_APPLY_ARGS, NULL_PTR); ! 4663: ! 4664: temp = tree_cons (NULL_TREE, ! 4665: build_pointer_type (build_function_type (void_type_node, ! 4666: NULL_TREE)), ! 4667: tree_cons (NULL_TREE, ! 4668: ptr_type_node, ! 4669: tree_cons (NULL_TREE, ! 4670: sizetype, ! 4671: endlink))); ! 4672: builtin_function ("__builtin_apply", ! 4673: build_function_type (ptr_type_node, temp), ! 4674: BUILT_IN_APPLY, NULL_PTR); ! 4675: builtin_function ("__builtin_return", ! 4676: build_function_type (void_type_node, ! 4677: tree_cons (NULL_TREE, ! 4678: ptr_type_node, ! 4679: endlink)), ! 4680: BUILT_IN_RETURN, NULL_PTR); ! 4681: 1.1 root 4682: /* Currently under experimentation. */ 4683: builtin_function ("__builtin_memcpy", memcpy_ftype, 4684: BUILT_IN_MEMCPY, "memcpy"); 4685: builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, 4686: BUILT_IN_MEMCMP, "memcmp"); 4687: builtin_function ("__builtin_strcmp", int_ftype_string_string, 4688: BUILT_IN_STRCMP, "strcmp"); 4689: builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, 4690: BUILT_IN_STRCPY, "strcpy"); 1.1.1.6 ! root 4691: #if 0 ! 4692: /* Not yet. */ ! 4693: builtin_function ("__builtin_strncpy", strncpy_ftype, ! 4694: BUILT_IN_STRNCPY, "strncpy"); ! 4695: #endif 1.1 root 4696: builtin_function ("__builtin_strlen", sizet_ftype_string, 4697: BUILT_IN_STRLEN, "strlen"); 1.1.1.5 root 4698: 4699: if (!flag_no_builtin) 4700: { 4701: #if 0 /* These do not work well with libg++. */ 4702: builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); 4703: builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); 4704: builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); 4705: #endif 4706: builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); 4707: builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, 4708: NULL_PTR); 4709: builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR); 4710: builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, NULL_PTR); 1.1.1.6 ! root 4711: #if 0 ! 4712: /* Not yet. */ ! 4713: builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR); ! 4714: #endif 1.1.1.5 root 4715: builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR); 4716: builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); 4717: builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); 4718: } 1.1 root 4719: 4720: #if 0 4721: /* Support for these has not been written in either expand_builtin 4722: or build_function_call. */ 4723: builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0); 4724: builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0); 4725: builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 0); 4726: builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0); 4727: builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, 0); 4728: builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, 0); 4729: builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 0); 4730: builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 0); 4731: builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 0); 4732: #endif 4733: 4734: /* C++ extensions */ 4735: 4736: unknown_type_node = make_node (UNKNOWN_TYPE); 1.1.1.2 root 4737: #if 0 /* not yet, should get fixed properly later */ 4738: pushdecl (make_type_decl (get_identifier ("unknown type"), 4739: unknown_type_node)); 4740: #else 1.1.1.5 root 4741: decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"), 1.1 root 4742: unknown_type_node)); 1.1.1.5 root 4743: /* Make sure the "unknown type" typedecl gets ignored for debug info. */ 4744: DECL_IGNORED_P (decl) = 1; 1.1.1.2 root 4745: #endif 1.1 root 4746: TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node); 4747: TYPE_ALIGN (unknown_type_node) = 1; 4748: TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node); 4749: /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ 4750: TREE_TYPE (unknown_type_node) = unknown_type_node; 4751: /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */ 4752: TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; 4753: TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; 4754: 1.1.1.4 root 4755: /* This is special for C++ so functions can be overloaded. */ 4756: wchar_type_node 4757: = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); 4758: wchar_type_size = TYPE_PRECISION (wchar_type_node); 4759: signed_wchar_type_node = make_signed_type (wchar_type_size); 4760: unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); 4761: wchar_type_node 4762: = TREE_UNSIGNED (wchar_type_node) 4763: ? unsigned_wchar_type_node 4764: : signed_wchar_type_node; 4765: record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); 4766: 4767: /* This is for wide string constants. */ 4768: wchar_array_type_node 1.1.1.6 ! root 4769: = build_array_type (wchar_type_node, array_domain_type); 1.1.1.4 root 4770: 1.1 root 4771: /* This is a hack that should go away when we deliver the 4772: real gc code. */ 4773: if (flag_gc) 4774: { 4775: builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0); 4776: pushdecl (lookup_name (get_identifier ("__gc_main"), 0)); 4777: } 4778: 4779: /* Simplify life by making a "vtable_entry_type". Give its 4780: fields names so that the debugger can use them. */ 4781: 4782: vtable_entry_type = make_lang_type (RECORD_TYPE); 1.1.1.6 ! root 4783: fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, short_integer_type_node); ! 4784: fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, short_integer_type_node); ! 4785: fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, ptr_type_node); 1.1 root 4786: finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, 4787: double_type_node); 4788: 4789: /* Make this part of an invisible union. */ 4790: fields[3] = copy_node (fields[2]); 4791: TREE_TYPE (fields[3]) = short_integer_type_node; 1.1.1.6 ! root 4792: DECL_NAME (fields[3]) = delta2_identifier; 1.1 root 4793: DECL_MODE (fields[3]) = TYPE_MODE (short_integer_type_node); 4794: DECL_SIZE (fields[3]) = TYPE_SIZE (short_integer_type_node); 4795: TREE_UNSIGNED (fields[3]) = 0; 4796: TREE_CHAIN (fields[2]) = fields[3]; 4797: vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0); 4798: record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); 4799: 4800: if (flag_dossier) 4801: { 4802: /* Must build __t_desc type. Currently, type descriptors look like this: 4803: 4804: struct __t_desc 4805: { 4806: const char *name; 4807: int size; 4808: int bits; 4809: struct __t_desc *points_to; 4810: int ivars_count, meths_count; 4811: struct __i_desc *ivars[]; 4812: struct __m_desc *meths[]; 4813: struct __t_desc *parents[]; 4814: struct __t_desc *vbases[]; 4815: int offsets[]; 4816: }; 4817: 4818: ...as per Linton's paper. */ 4819: 4820: __t_desc_type_node = make_lang_type (RECORD_TYPE); 4821: __i_desc_type_node = make_lang_type (RECORD_TYPE); 4822: __m_desc_type_node = make_lang_type (RECORD_TYPE); 4823: __t_desc_array_type = build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE); 4824: __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE); 4825: __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE); 4826: 4827: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), 4828: string_type_node); 4829: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"), 4830: unsigned_type_node); 4831: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"), 4832: unsigned_type_node); 4833: fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("points_to"), 4834: TYPE_POINTER_TO (__t_desc_type_node)); 4835: fields[4] = build_lang_field_decl (FIELD_DECL, 4836: get_identifier ("ivars_count"), 4837: integer_type_node); 4838: fields[5] = build_lang_field_decl (FIELD_DECL, 4839: get_identifier ("meths_count"), 4840: integer_type_node); 4841: fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"), 4842: build_pointer_type (__i_desc_array_type)); 4843: fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"), 4844: build_pointer_type (__m_desc_array_type)); 4845: fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"), 4846: build_pointer_type (__t_desc_array_type)); 4847: fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"), 4848: build_pointer_type (__t_desc_array_type)); 4849: fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"), 4850: build_pointer_type (integer_type_node)); 4851: finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node); 4852: 4853: /* ivar descriptors look like this: 4854: 4855: struct __i_desc 4856: { 4857: const char *name; 4858: int offset; 4859: struct __t_desc *type; 4860: }; 4861: */ 4862: 4863: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), 4864: string_type_node); 4865: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"), 4866: integer_type_node); 4867: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"), 4868: TYPE_POINTER_TO (__t_desc_type_node)); 4869: finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, integer_type_node); 4870: 4871: /* method descriptors look like this: 4872: 4873: struct __m_desc 4874: { 4875: const char *name; 4876: int vindex; 4877: struct __t_desc *vcontext; 4878: struct __t_desc *return_type; 4879: void (*address)(); 4880: short parm_count; 4881: short required_parms; 4882: struct __t_desc *parm_types[]; 4883: }; 4884: */ 4885: 4886: fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), 4887: string_type_node); 4888: fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"), 4889: integer_type_node); 4890: fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"), 4891: TYPE_POINTER_TO (__t_desc_type_node)); 4892: fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"), 4893: TYPE_POINTER_TO (__t_desc_type_node)); 4894: fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"), 4895: build_pointer_type (default_function_type)); 4896: fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"), 4897: short_integer_type_node); 4898: fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"), 4899: short_integer_type_node); 4900: fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"), 4901: build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE))); 4902: finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node); 4903: } 4904: 4905: /* Now, C++. */ 4906: current_lang_name = lang_name_cplusplus; 4907: if (flag_dossier) 4908: { 4909: int i = builtin_type_tdescs_len; 4910: while (i > 0) 4911: { 4912: tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0); 4913: TREE_ASM_WRITTEN (tdesc) = 1; 4914: TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1; 4915: } 4916: } 4917: 1.1.1.2 root 4918: auto_function (ansi_opname[(int) NEW_EXPR], 4919: build_function_type (ptr_type_node, 4920: tree_cons (NULL_TREE, sizetype, 4921: void_list_node)), 4922: NOT_BUILT_IN); 4923: auto_function (ansi_opname[(int) DELETE_EXPR], 4924: build_function_type (void_type_node, 4925: tree_cons (NULL_TREE, ptr_type_node, 4926: void_list_node)), 4927: NOT_BUILT_IN); 1.1 root 4928: 4929: abort_fndecl 4930: = define_function ("abort", 4931: build_function_type (void_type_node, void_list_node), 4932: NOT_BUILT_IN, 0, 0); 4933: 4934: unhandled_exception_fndecl 4935: = define_function ("__unhandled_exception", 4936: build_function_type (void_type_node, NULL_TREE), 4937: NOT_BUILT_IN, 0, 0); 4938: 4939: /* Perform other language dependent initializations. */ 4940: init_class_processing (); 4941: init_init_processing (); 4942: init_search_processing (); 4943: 4944: if (flag_handle_exceptions) 4945: { 4946: if (flag_handle_exceptions == 2) 4947: /* Too much trouble to inline all the trys needed for this. */ 4948: flag_this_is_variable = 2; 4949: init_exception_processing (); 4950: } 4951: if (flag_gc) 4952: init_gc_processing (); 4953: if (flag_no_inline) 4954: flag_inline_functions = 0, flag_default_inline = 0; 4955: if (flag_cadillac) 4956: init_cadillac (); 4957: 1.1.1.3 root 4958: /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ 4959: declare_function_name (); 1.1 root 4960: } 4961: 4962: /* Make a definition for a builtin function named NAME and whose data type 4963: is TYPE. TYPE should be a function type with argument types. 4964: FUNCTION_CODE tells later passes how to compile calls to this function. 4965: See tree.h for its possible values. 4966: 4967: If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, 4968: the name to be called if we can't opencode the function. */ 4969: 4970: tree 4971: define_function (name, type, function_code, pfn, library_name) 4972: char *name; 4973: tree type; 4974: enum built_in_function function_code; 4975: void (*pfn)(); 4976: char *library_name; 4977: { 4978: tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); 1.1.1.4 root 4979: DECL_EXTERNAL (decl) = 1; 1.1 root 4980: TREE_PUBLIC (decl) = 1; 4981: 4982: /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, 4983: we cannot change DECL_ASSEMBLER_NAME until we have installed this 4984: function in the namespace. */ 4985: if (pfn) (*pfn) (decl); 4986: if (library_name) 4987: DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); 4988: make_function_rtl (decl); 4989: if (function_code != NOT_BUILT_IN) 4990: { 4991: DECL_BUILT_IN (decl) = 1; 4992: DECL_SET_FUNCTION_CODE (decl, function_code); 4993: } 4994: return decl; 4995: } 4996: 4997: /* Called when a declaration is seen that contains no names to declare. 4998: If its type is a reference to a structure, union or enum inherited 4999: from a containing scope, shadow that tag name for the current scope 5000: with a forward reference. 5001: If its type defines a new named structure or union 5002: or defines an enum, it is valid but we need not do anything here. 5003: Otherwise, it is an error. 5004: 5005: C++: may have to grok the declspecs to learn about static, 5006: complain for anonymous unions. */ 5007: 5008: void 5009: shadow_tag (declspecs) 5010: tree declspecs; 5011: { 5012: int found_tag = 0; 5013: int warned = 0; 1.1.1.6 ! root 5014: int static_or_extern = 0; 1.1 root 5015: register tree link; 5016: register enum tree_code code, ok_code = ERROR_MARK; 5017: register tree t = NULL_TREE; 5018: 5019: for (link = declspecs; link; link = TREE_CHAIN (link)) 5020: { 5021: register tree value = TREE_VALUE (link); 5022: 5023: code = TREE_CODE (value); 5024: if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE) 5025: /* Used to test also that TYPE_SIZE (value) != 0. 5026: That caused warning for `struct foo;' at top level in the file. */ 5027: { 5028: register tree name = TYPE_NAME (value); 5029: 5030: if (name == NULL_TREE) 5031: name = lookup_tag_reverse (value, NULL_TREE); 5032: 5033: if (name && TREE_CODE (name) == TYPE_DECL) 5034: name = DECL_NAME (name); 5035: 5036: if (class_binding_level) 5037: t = lookup_tag (code, name, class_binding_level, 1); 5038: else 5039: t = lookup_tag (code, name, current_binding_level, 1); 5040: 1.1.1.5 root 5041: if (t == NULL_TREE) 1.1 root 5042: { 5043: push_obstacks (&permanent_obstack, &permanent_obstack); 5044: if (IS_AGGR_TYPE_CODE (code)) 5045: t = make_lang_type (code); 5046: else 5047: t = make_node (code); 5048: pushtag (name, t); 5049: pop_obstacks (); 5050: ok_code = code; 5051: break; 5052: } 1.1.1.5 root 5053: else if (name != NULL_TREE || code == ENUMERAL_TYPE) 1.1 root 5054: ok_code = code; 5055: 5056: if (ok_code != ERROR_MARK) 5057: found_tag++; 5058: else 5059: { 5060: if (!warned) 1.1.1.5 root 5061: pedwarn ("useless keyword or type name in declaration"); 1.1 root 5062: warned = 1; 5063: } 5064: } 1.1.1.6 ! root 5065: else if (value == ridpointers[(int) RID_STATIC] ! 5066: || value == ridpointers[(int) RID_EXTERN]) ! 5067: static_or_extern = 1; 1.1 root 5068: } 5069: 5070: /* This is where the variables in an anonymous union are 5071: declared. An anonymous union declaration looks like: 5072: union { ... } ; 5073: because there is no declarator after the union, the parser 5074: sends that declaration here. */ 5075: if (ok_code == UNION_TYPE 5076: && t != NULL_TREE 5077: && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE 5078: && ANON_AGGRNAME_P (TYPE_NAME (t))) 5079: || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL 1.1.1.4 root 5080: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))) 1.1 root 5081: { 1.1.1.4 root 5082: /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have 5083: function members. */ 5084: if (TYPE_FIELDS (t)) 5085: { 5086: tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE); 5087: finish_anon_union (decl); 5088: } 5089: else 5090: error ("anonymous union cannot have a function member"); 1.1 root 5091: } 1.1.1.6 ! root 5092: else 1.1 root 5093: { 1.1.1.6 ! root 5094: /* Anonymous unions are objects, that's why we only check for ! 5095: static/extern specifiers in this branch. */ ! 5096: if (static_or_extern) ! 5097: error ("static/extern can only be specified for objects and functions"); ! 5098: ! 5099: if (ok_code == RECORD_TYPE ! 5100: && found_tag == 1 ! 5101: && TYPE_LANG_SPECIFIC (t) ! 5102: && CLASSTYPE_DECLARED_EXCEPTION (t)) 1.1 root 5103: { 1.1.1.6 ! root 5104: if (TYPE_SIZE (t)) ! 5105: cp_error ("redeclaration of exception `%T'", t); ! 5106: else ! 5107: { ! 5108: tree ename, decl; 1.1 root 5109: 1.1.1.6 ! root 5110: push_obstacks (&permanent_obstack, &permanent_obstack); 1.1 root 5111: 1.1.1.6 ! root 5112: pushclass (t, 0); ! 5113: finish_exception (t, NULL_TREE); 1.1 root 5114: 1.1.1.6 ! root 5115: ename = TYPE_NAME (t); ! 5116: if (TREE_CODE (ename) == TYPE_DECL) ! 5117: ename = DECL_NAME (ename); ! 5118: decl = build_lang_field_decl (VAR_DECL, ename, t); ! 5119: finish_exception_decl (current_class_name, decl); ! 5120: end_exception_decls (); 1.1 root 5121: 1.1.1.6 ! root 5122: pop_obstacks (); ! 5123: } 1.1 root 5124: } 1.1.1.6 ! root 5125: else if (!warned && found_tag > 1) ! 5126: warning ("multiple types in one declaration"); 1.1 root 5127: } 5128: } 5129: 5130: /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ 5131: 5132: tree 5133: groktypename (typename) 5134: tree typename; 5135: { 5136: if (TREE_CODE (typename) != TREE_LIST) 5137: return typename; 5138: return grokdeclarator (TREE_VALUE (typename), 5139: TREE_PURPOSE (typename), 5140: TYPENAME, 0, NULL_TREE); 5141: } 5142: 5143: /* Decode a declarator in an ordinary declaration or data definition. 5144: This is called as soon as the type information and variable name 5145: have been parsed, before parsing the initializer if any. 5146: Here we create the ..._DECL node, fill in its type, 5147: and put it on the list of decls for the current context. 5148: The ..._DECL node is returned as the value. 5149: 5150: Exception: for arrays where the length is not specified, 5151: the type is left null, to be filled in by `finish_decl'. 5152: 5153: Function definitions do not come here; they go to start_function 5154: instead. However, external and forward declarations of functions 5155: do go through here. Structure field declarations are done by 5156: grokfield and not through here. */ 5157: 5158: /* Set this to zero to debug not using the temporary obstack 5159: to parse initializers. */ 5160: int debug_temp_inits = 1; 5161: 5162: tree 5163: start_decl (declarator, declspecs, initialized, raises) 1.1.1.6 ! root 5164: tree declarator, declspecs; 1.1 root 5165: int initialized; 5166: tree raises; 5167: { 1.1.1.4 root 5168: register tree decl; 1.1 root 5169: register tree type, tem; 5170: tree context; 1.1.1.4 root 5171: extern int have_extern_spec; 5172: extern int used_extern_spec; 1.1 root 5173: 5174: int init_written = initialized; 5175: 1.1.1.4 root 5176: /* This should only be done once on the top most decl. */ 5177: if (have_extern_spec && !used_extern_spec) 5178: { 5179: declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); 5180: used_extern_spec = 1; 5181: } 5182: 5183: decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises); 5184: if (decl == NULL_TREE || decl == void_type_node) 5185: return NULL_TREE; 1.1 root 5186: 5187: type = TREE_TYPE (decl); 5188: 5189: /* Don't lose if destructors must be executed at file-level. */ 5190: if (TREE_STATIC (decl) 5191: && TYPE_NEEDS_DESTRUCTOR (type) 1.1.1.5 root 5192: && !TREE_PERMANENT (decl)) 1.1 root 5193: { 5194: push_obstacks (&permanent_obstack, &permanent_obstack); 5195: decl = copy_node (decl); 5196: if (TREE_CODE (type) == ARRAY_TYPE) 5197: { 5198: tree itype = TYPE_DOMAIN (type); 5199: if (itype && ! TREE_PERMANENT (itype)) 5200: { 5201: itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); 5202: type = build_cplus_array_type (TREE_TYPE (type), itype); 5203: TREE_TYPE (decl) = type; 5204: } 5205: } 5206: pop_obstacks (); 5207: } 5208: 5209: /* Interesting work for this is done in `finish_exception_decl'. */ 5210: if (TREE_CODE (type) == RECORD_TYPE 5211: && CLASSTYPE_DECLARED_EXCEPTION (type)) 5212: return decl; 5213: 5214: /* Corresponding pop_obstacks is done in `finish_decl'. */ 5215: push_obstacks_nochange (); 5216: 1.1.1.4 root 5217: context 5218: = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) 5219: ? DECL_CLASS_CONTEXT (decl) 5220: : DECL_CONTEXT (decl); 1.1 root 5221: 5222: if (processing_template_decl) 5223: { 5224: tree d; 5225: if (TREE_CODE (decl) == FUNCTION_DECL) 5226: { 5227: /* Declarator is a call_expr; extract arguments from it, since 5228: grokdeclarator didn't do it. */ 5229: tree args; 5230: args = copy_to_permanent (last_function_parms); 5231: if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) 5232: { 1.1.1.2 root 5233: tree t = TREE_TYPE (decl); 1.1 root 5234: tree decl; 5235: 5236: t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */ 1.1.1.2 root 5237: if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE) 5238: { 5239: t = build_pointer_type (t); /* base type of `this' */ 1.1.1.3 root 5240: #if 1 5241: /* I suspect this is wrong. */ 1.1.1.2 root 5242: t = build_type_variant (t, flag_this_is_variable <= 0, 5243: 0); /* type of `this' */ 1.1.1.3 root 5244: #else 5245: t = build_type_variant (t, 0, 0); /* type of `this' */ 5246: #endif 1.1.1.2 root 5247: t = build (PARM_DECL, t, this_identifier); 5248: TREE_CHAIN (t) = args; 5249: args = t; 5250: } 1.1 root 5251: } 5252: DECL_ARGUMENTS (decl) = args; 5253: } 5254: d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl)); 1.1.1.6 ! root 5255: if (interface_unknown && flag_external_templates) ! 5256: warn_if_unknown_interface (); ! 5257: TREE_PUBLIC (d) = TREE_PUBLIC (decl) = flag_external_templates && !interface_unknown; 1.1 root 5258: TREE_STATIC (d) = TREE_STATIC (decl); 1.1.1.4 root 5259: DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl) 5260: && !(context && !DECL_THIS_EXTERN (decl))); 1.1 root 5261: DECL_TEMPLATE_RESULT (d) = decl; 5262: DECL_OVERLOADED (d) = 1; 5263: decl = d; 5264: } 5265: 5266: if (context && TYPE_SIZE (context) != NULL_TREE) 5267: { 5268: /* If it was not explicitly declared `extern', 1.1.1.4 root 5269: revoke any previous claims of DECL_EXTERNAL. */ 5270: if (DECL_THIS_EXTERN (decl) == 0) 5271: DECL_EXTERNAL (decl) = 0; 1.1 root 5272: if (DECL_LANG_SPECIFIC (decl)) 5273: DECL_IN_AGGR_P (decl) = 0; 5274: pushclass (context, 2); 5275: } 5276: 5277: /* If this type of object needs a cleanup, and control may 5278: jump past it, make a new binding level so that it is cleaned 5279: up only when it is initialized first. */ 5280: if (TYPE_NEEDS_DESTRUCTOR (type) 5281: && current_binding_level->more_cleanups_ok == 0) 5282: pushlevel_temporary (1); 5283: 5284: if (initialized) 5285: /* Is it valid for this decl to have an initializer at all? 5286: If not, set INITIALIZED to zero, which will indirectly 5287: tell `finish_decl' to ignore the initializer once it is parsed. */ 5288: switch (TREE_CODE (decl)) 5289: { 5290: case TYPE_DECL: 5291: /* typedef foo = bar means give foo the same type as bar. 5292: We haven't parsed bar yet, so `finish_decl' will fix that up. 5293: Any other case of an initialization in a TYPE_DECL is an error. */ 5294: if (pedantic || list_length (declspecs) > 1) 5295: { 1.1.1.6 ! root 5296: cp_error ("typedef `%D' is initialized", decl); 1.1 root 5297: initialized = 0; 5298: } 5299: break; 5300: 5301: case FUNCTION_DECL: 1.1.1.6 ! root 5302: cp_error ("function `%#D' is initialized like a variable", decl); 1.1 root 5303: initialized = 0; 5304: break; 5305: 5306: default: 1.1.1.6 ! root 5307: /* Don't allow initializations for incomplete types except for ! 5308: arrays which might be completed by the initialization. */ 1.1.1.5 root 5309: if (TYPE_SIZE (type) != NULL_TREE) 1.1 root 5310: ; /* A complete type is ok. */ 5311: else if (TREE_CODE (type) != ARRAY_TYPE) 5312: { 1.1.1.6 ! root 5313: cp_error ("variable `%#D' has initializer but incomplete type", ! 5314: decl); 1.1 root 5315: initialized = 0; 5316: } 1.1.1.5 root 5317: else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE) 1.1 root 5318: { 1.1.1.6 ! root 5319: cp_error ("elements of array `%#D' have incomplete type", decl); 1.1 root 5320: initialized = 0; 5321: } 5322: } 5323: 5324: if (!initialized 5325: && TREE_CODE (decl) != TYPE_DECL 5326: && TREE_CODE (decl) != TEMPLATE_DECL 1.1.1.4 root 5327: && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) 1.1 root 5328: { 1.1.1.5 root 5329: if (TYPE_SIZE (type) == NULL_TREE) 1.1 root 5330: { 1.1.1.6 ! root 5331: cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", ! 5332: decl); 1.1 root 5333: /* Change the type so that assemble_variable will give 5334: DECL an rtl we can live with: (mem (const_int 0)). */ 5335: TREE_TYPE (decl) = error_mark_node; 5336: type = error_mark_node; 5337: } 5338: else 5339: { 5340: /* If any base type in the hierarchy of TYPE needs a constructor, 5341: then we set initialized to 1. This way any nodes which are 5342: created for the purposes of initializing this aggregate 5343: will live as long as it does. This is necessary for global 5344: aggregates which do not have their initializers processed until 5345: the end of the file. */ 5346: initialized = TYPE_NEEDS_CONSTRUCTING (type); 5347: } 5348: } 5349: 5350: if (initialized) 5351: { 5352: if (current_binding_level != global_binding_level 1.1.1.4 root 5353: && DECL_EXTERNAL (decl)) 1.1.1.6 ! root 5354: cp_warning ("declaration of `%#D' has `extern' and is initialized", ! 5355: decl); 1.1.1.4 root 5356: DECL_EXTERNAL (decl) = 0; 1.1 root 5357: if (current_binding_level == global_binding_level) 5358: TREE_STATIC (decl) = 1; 5359: 5360: /* Tell `pushdecl' this is an initialized decl 5361: even though we don't yet have the initializer expression. 5362: Also tell `finish_decl' it may store the real initializer. */ 5363: DECL_INITIAL (decl) = error_mark_node; 5364: } 5365: 5366: /* Add this decl to the current binding level, but not if it 5367: comes from another scope, e.g. a static member variable. 5368: TEM may equal DECL or it may be a previous decl of the same name. */ 5369: if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE) 5370: || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ()) 5371: || TREE_CODE (type) == LANG_TYPE) 5372: tem = decl; 5373: else 5374: { 5375: tem = pushdecl (decl); 5376: if (TREE_CODE (tem) == TREE_LIST) 5377: { 5378: tree tem2 = value_member (decl, tem); 5379: if (tem2 != NULL_TREE) 5380: tem = TREE_VALUE (tem2); 5381: else 5382: { 5383: while (tem && ! decls_match (decl, TREE_VALUE (tem))) 5384: tem = TREE_CHAIN (tem); 5385: if (tem == NULL_TREE) 5386: tem = decl; 5387: else 5388: tem = TREE_VALUE (tem); 5389: } 5390: } 5391: } 5392: 5393: #if 0 5394: /* We don't do this yet for GNU C++. */ 5395: /* For a local variable, define the RTL now. */ 5396: if (current_binding_level != global_binding_level 5397: /* But not if this is a duplicate decl 5398: and we preserved the rtl from the previous one 5399: (which may or may not happen). */ 1.1.1.5 root 5400: && DECL_RTL (tem) == NULL_RTX) 1.1 root 5401: { 1.1.1.5 root 5402: if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) 1.1 root 5403: expand_decl (tem); 5404: else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE 1.1.1.5 root 5405: && DECL_INITIAL (tem) != NULL_TREE) 1.1 root 5406: expand_decl (tem); 5407: } 5408: #endif 5409: 5410: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_OVERLOADED (decl)) 5411: /* @@ Also done in start_function. */ 5412: tem = push_overloaded_decl (tem, 1); 5413: else if (TREE_CODE (decl) == TEMPLATE_DECL) 5414: { 5415: tree result = DECL_TEMPLATE_RESULT (decl); 5416: if (DECL_CONTEXT (result) != NULL_TREE) 5417: { 1.1.1.4 root 5418: tree type; 1.1 root 5419: type = DECL_CONTEXT (result); 1.1.1.6 ! root 5420: ! 5421: if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE) ! 5422: { ! 5423: cp_error ("declaration of `%D' in non-template type `%T'", ! 5424: decl, type); ! 5425: return NULL_TREE; ! 5426: } ! 5427: 1.1 root 5428: if (/* TREE_CODE (result) == VAR_DECL */ 1) 5429: { 5430: #if 0 5431: tree tmpl = UPT_TEMPLATE (type); 5432: 5433: fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__); 5434: print_node_brief (stderr, "", DECL_NAME (tem), 0); 5435: fprintf (stderr, " to class %s\n", 5436: IDENTIFIER_POINTER (DECL_NAME (tmpl))); 5437: DECL_TEMPLATE_MEMBERS (tmpl) 5438: = perm_tree_cons (DECL_NAME (tem), tem, 5439: DECL_TEMPLATE_MEMBERS (tmpl)); 5440: #endif 5441: return tem; 5442: } 1.1.1.3 root 5443: my_friendly_abort (13); 1.1 root 5444: } 5445: else if (TREE_CODE (result) == FUNCTION_DECL) 5446: tem = push_overloaded_decl (tem, 0); 1.1.1.2 root 5447: else if (TREE_CODE (result) == VAR_DECL 5448: || TREE_CODE (result) == TYPE_DECL) 1.1 root 5449: { 1.1.1.6 ! root 5450: cp_error ("invalid template `%#D'", result); 1.1.1.4 root 5451: return NULL_TREE; 1.1 root 5452: } 5453: else 1.1.1.3 root 5454: my_friendly_abort (14); 1.1 root 5455: } 5456: 5457: if (init_written 5458: && ! (TREE_CODE (tem) == PARM_DECL 5459: || (TREE_READONLY (tem) 5460: && (TREE_CODE (tem) == VAR_DECL 5461: || TREE_CODE (tem) == FIELD_DECL)))) 5462: { 5463: /* When parsing and digesting the initializer, 5464: use temporary storage. Do this even if we will ignore the value. */ 5465: if (current_binding_level == global_binding_level && debug_temp_inits) 5466: { 5467: if (TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE) 5468: /* In this case, the initializer must lay down in permanent 5469: storage, since it will be saved until `finish_file' is run. */ 5470: ; 5471: else 5472: temporary_allocation (); 5473: } 5474: } 5475: 5476: if (flag_cadillac) 5477: cadillac_start_decl (tem); 5478: 5479: return tem; 5480: } 5481: 5482: static void 5483: make_temporary_for_reference (decl, ctor_call, init, cleanupp) 5484: tree decl, ctor_call, init; 5485: tree *cleanupp; 5486: { 5487: tree type = TREE_TYPE (decl); 5488: tree target_type = TREE_TYPE (type); 5489: tree tmp, tmp_addr; 5490: 5491: if (ctor_call) 5492: { 5493: tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1)); 5494: if (TREE_CODE (tmp_addr) == NOP_EXPR) 5495: tmp_addr = TREE_OPERAND (tmp_addr, 0); 1.1.1.4 root 5496: my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146); 1.1 root 5497: tmp = TREE_OPERAND (tmp_addr, 0); 5498: } 5499: else 5500: { 5501: tmp = get_temp_name (target_type, 5502: current_binding_level == global_binding_level); 5503: tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0); 5504: } 5505: 5506: TREE_TYPE (tmp_addr) = build_pointer_type (target_type); 5507: DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr); 5508: TREE_TYPE (DECL_INITIAL (decl)) = type; 5509: if (TYPE_NEEDS_CONSTRUCTING (target_type)) 5510: { 5511: if (current_binding_level == global_binding_level) 5512: { 5513: /* lay this variable out now. Otherwise `output_addressed_constants' 5514: gets confused by its initializer. */ 1.1.1.5 root 5515: make_decl_rtl (tmp, NULL_PTR, 1); 1.1 root 5516: static_aggregates = perm_tree_cons (init, tmp, static_aggregates); 5517: } 5518: else 5519: { 5520: if (ctor_call != NULL_TREE) 5521: init = ctor_call; 5522: else 1.1.1.6 ! root 5523: init = build_method_call (tmp, constructor_name_full (target_type), 1.1 root 5524: build_tree_list (NULL_TREE, init), 5525: NULL_TREE, LOOKUP_NORMAL); 5526: DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init, 5527: DECL_INITIAL (decl)); 5528: *cleanupp = maybe_build_cleanup (tmp); 5529: } 5530: } 5531: else 5532: { 5533: DECL_INITIAL (tmp) = init; 5534: TREE_STATIC (tmp) = current_binding_level == global_binding_level; 5535: finish_decl (tmp, init, 0, 0); 5536: } 5537: if (TREE_STATIC (tmp)) 5538: preserve_initializer (); 5539: } 5540: 5541: /* Handle initialization of references. 5542: These three arguments from from `finish_decl', and have the 5543: same meaning here that they do there. */ 1.1.1.3 root 5544: /* quotes on semantics can be found in ARM 8.4.3. */ 1.1 root 5545: static void 5546: grok_reference_init (decl, type, init, cleanupp) 5547: tree decl, type, init; 5548: tree *cleanupp; 5549: { 1.1.1.5 root 5550: char *errstr = NULL; 1.1 root 5551: int is_reference; 5552: tree tmp; 5553: tree this_ptr_type, actual_init; 5554: 5555: if (init == NULL_TREE) 5556: { 1.1.1.5 root 5557: if (DECL_LANG_SPECIFIC (decl) == 0 5558: || DECL_IN_AGGR_P (decl) == 0) 1.1 root 5559: { 5560: error ("variable declared as reference not initialized"); 5561: if (TREE_CODE (decl) == VAR_DECL) 5562: SET_DECL_REFERENCE_SLOT (decl, error_mark_node); 5563: } 5564: return; 5565: } 5566: 1.1.1.6 ! root 5567: if (TREE_CODE (type) == REFERENCE_TYPE ! 5568: && TREE_CODE (init) == CONSTRUCTOR) ! 5569: { ! 5570: error ("ANSI C++ forbids use of initializer list for a reference initializer"); ! 5571: return; ! 5572: } ! 5573: 1.1 root 5574: if (TREE_CODE (init) == TREE_LIST) 5575: init = build_compound_expr (init); 5576: is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE; 5577: tmp = is_reference ? convert_from_reference (init) : init; 5578: 5579: if (is_reference) 5580: { 5581: if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)), 5582: TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0)) 5583: errstr = "initialization of `%s' from dissimilar reference type"; 5584: else if (TYPE_READONLY (TREE_TYPE (type)) 5585: >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (init)))) 5586: { 5587: is_reference = 0; 5588: init = tmp; 5589: } 5590: } 5591: else 5592: { 5593: if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE 5594: && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) 5595: { 5596: /* Note: default conversion is only called in very 5597: special cases. */ 5598: init = default_conversion (init); 5599: } 1.1.1.4 root 5600: if (TREE_CODE (TREE_TYPE (type)) == TREE_CODE (TREE_TYPE (init))) 1.1 root 5601: { 1.1.1.4 root 5602: if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)), 5603: TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0)) 5604: { 5605: /* This section implements ANSI C++ June 5 1992 WP 8.4.3.5. */ 5606: 5607: /* A reference to a volatile T cannot be initialized with 5608: a const T, and vice-versa. */ 5609: if (TYPE_VOLATILE (TREE_TYPE (type)) && TREE_READONLY (init)) 5610: errstr = "cannot initialize a reference to a volatile T with a const T"; 5611: else if (TYPE_READONLY (TREE_TYPE (type)) && TREE_THIS_VOLATILE (init)) 5612: errstr = "cannot initialize a reference to a const T with a volatile T"; 5613: /* A reference to a plain T can be initialized only with 5614: a plain T. */ 5615: else if (!TYPE_VOLATILE (TREE_TYPE (type)) 5616: && !TYPE_READONLY (TREE_TYPE (type))) 5617: { 5618: if (TREE_READONLY (init)) 5619: errstr = "cannot initialize a reference to T with a const T"; 5620: else if (TREE_THIS_VOLATILE (init)) 5621: errstr = "cannot initialize a reference to T with a volatile T"; 5622: } 5623: } 5624: else 5625: init = convert (TREE_TYPE (type), init); 1.1 root 5626: } 5627: else if (init != error_mark_node 5628: && ! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)), 5629: TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0)) 5630: errstr = "invalid type conversion for reference"; 5631: } 5632: 5633: if (errstr) 5634: { 5635: /* Things did not go smoothly; look for operator& type conversion. */ 5636: if (IS_AGGR_TYPE (TREE_TYPE (tmp))) 5637: { 5638: tmp = build_type_conversion (CONVERT_EXPR, type, init, 0); 5639: if (tmp != NULL_TREE) 5640: { 5641: init = tmp; 5642: if (tmp == error_mark_node) 5643: errstr = "ambiguous pointer conversion"; 5644: else 1.1.1.5 root 5645: errstr = NULL; 1.1 root 5646: is_reference = 1; 5647: } 5648: else 5649: { 5650: tmp = build_type_conversion (CONVERT_EXPR, TREE_TYPE (type), init, 0); 5651: if (tmp != NULL_TREE) 5652: { 5653: init = tmp; 5654: if (tmp == error_mark_node) 5655: errstr = "ambiguous pointer conversion"; 5656: else 1.1.1.5 root 5657: errstr = NULL; 1.1 root 5658: is_reference = 0; 5659: } 5660: } 5661: } 5662: /* Look for constructor. */ 5663: else if (IS_AGGR_TYPE (TREE_TYPE (type)) 5664: && TYPE_HAS_CONSTRUCTOR (TREE_TYPE (type))) 5665: { 5666: tmp = get_temp_name (TREE_TYPE (type), 5667: current_binding_level == global_binding_level); 1.1.1.6 ! root 5668: tmp = build_method_call (tmp, constructor_name_full (TREE_TYPE (type)), 1.1 root 5669: build_tree_list (NULL_TREE, init), 5670: NULL_TREE, LOOKUP_NORMAL); 5671: if (tmp == NULL_TREE || tmp == error_mark_node) 5672: { 5673: if (TREE_CODE (decl) == VAR_DECL) 5674: SET_DECL_REFERENCE_SLOT (decl, error_mark_node); 1.1.1.6 ! root 5675: cp_error_at ("constructor failed to build reference initializer", decl); 1.1 root 5676: return; 5677: } 5678: make_temporary_for_reference (decl, tmp, init, cleanupp); 5679: goto done; 5680: } 5681: } 5682: 5683: if (errstr) 5684: { 5685: error_with_decl (decl, errstr); 5686: if (TREE_CODE (decl) == VAR_DECL) 5687: SET_DECL_REFERENCE_SLOT (decl, error_mark_node); 5688: return; 5689: } 5690: 1.1.1.2 root 5691: /* In the case of initialization, it is permissible 1.1 root 5692: to assign one reference to another. */ 5693: this_ptr_type = build_pointer_type (TREE_TYPE (type)); 5694: 5695: if (is_reference) 5696: { 5697: if (TREE_SIDE_EFFECTS (init)) 5698: DECL_INITIAL (decl) = save_expr (init); 5699: else 5700: DECL_INITIAL (decl) = init; 5701: } 5702: else if (lvalue_p (init)) 5703: { 5704: tmp = build_unary_op (ADDR_EXPR, init, 0); 5705: if (TREE_CODE (tmp) == ADDR_EXPR 5706: && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR) 5707: { 5708: /* Associate the cleanup with the reference so that we 5709: don't get burned by "aggressive" cleanup policy. */ 5710: *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2); 5711: TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node; 5712: } 5713: if (IS_AGGR_TYPE (TREE_TYPE (this_ptr_type))) 5714: DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp); 5715: else 5716: DECL_INITIAL (decl) = convert (this_ptr_type, tmp); 5717: 5718: DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); 5719: if (DECL_INITIAL (decl) == current_class_decl) 5720: DECL_INITIAL (decl) = copy_node (current_class_decl); 5721: TREE_TYPE (DECL_INITIAL (decl)) = type; 5722: } 5723: else if ((actual_init = unary_complex_lvalue (ADDR_EXPR, init))) 5724: { 5725: /* The initializer for this decl goes into its 5726: DECL_REFERENCE_SLOT. Make sure that we can handle 5727: multiple evaluations without ill effect. */ 5728: if (TREE_CODE (actual_init) == ADDR_EXPR 5729: && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR) 5730: actual_init = save_expr (actual_init); 5731: DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init); 5732: DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); 5733: TREE_TYPE (DECL_INITIAL (decl)) = type; 5734: } 5735: else if (TYPE_READONLY (TREE_TYPE (type))) 5736: /* Section 8.4.3 allows us to make a temporary for 5737: the initialization of const&. */ 5738: make_temporary_for_reference (decl, NULL_TREE, init, cleanupp); 5739: else 5740: { 1.1.1.6 ! root 5741: cp_error ("type mismatch in initialization of `%D' (use `const')", decl); 1.1 root 5742: DECL_INITIAL (decl) = error_mark_node; 5743: } 5744: 5745: done: 5746: /* ?? Can this be optimized in some cases to 5747: hand back the DECL_INITIAL slot?? */ 5748: if (TYPE_SIZE (TREE_TYPE (type))) 5749: { 5750: init = convert_from_reference (decl); 5751: if (TREE_PERMANENT (decl)) 5752: init = copy_to_permanent (init); 5753: SET_DECL_REFERENCE_SLOT (decl, init); 5754: } 5755: 5756: if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) 5757: { 5758: expand_static_init (decl, DECL_INITIAL (decl)); 1.1.1.5 root 5759: DECL_INITIAL (decl) = NULL_TREE; 1.1 root 5760: } 5761: } 5762: 5763: /* Finish processing of a declaration; 5764: install its line number and initial value. 5765: If the length of an array type is not known before, 5766: it must be determined now, from the initial value, or it is an error. 5767: 5768: Call `pop_obstacks' iff NEED_POP is nonzero. 5769: 5770: For C++, `finish_decl' must be fairly evasive: it must keep initializers 5771: for aggregates that have constructors alive on the permanent obstack, 5772: so that the global initializing functions can be written at the end. 5773: 5774: INIT0 holds the value of an initializer that should be allowed to escape 5775: the normal rules. 5776: 1.1.1.2 root 5777: For functions that take default parameters, DECL points to its 1.1.1.3 root 5778: "maximal" instantiation. `finish_decl' must then also declared its 1.1 root 5779: subsequently lower and lower forms of instantiation, checking for 5780: ambiguity as it goes. This can be sped up later. */ 5781: 5782: void 5783: finish_decl (decl, init, asmspec_tree, need_pop) 5784: tree decl, init; 5785: tree asmspec_tree; 5786: int need_pop; 5787: { 5788: register tree type; 5789: tree cleanup = NULL_TREE, ttype; 5790: int was_incomplete; 5791: int temporary = allocation_temporary_p (); 1.1.1.5 root 5792: char *asmspec = NULL; 1.1 root 5793: int was_readonly = 0; 5794: 5795: /* If this is 0, then we did not change obstacks. */ 5796: if (! decl) 5797: { 5798: if (init) 5799: error ("assignment (not initialization) in declaration"); 5800: return; 5801: } 5802: 5803: if (asmspec_tree) 5804: { 5805: asmspec = TREE_STRING_POINTER (asmspec_tree); 5806: /* Zero out old RTL, since we will rewrite it. */ 1.1.1.5 root 5807: DECL_RTL (decl) = NULL_RTX; 1.1 root 5808: } 5809: 5810: /* If the type of the thing we are declaring either has 5811: a constructor, or has a virtual function table pointer, 5812: AND its initialization was accepted by `start_decl', 5813: then we stayed on the permanent obstack through the 5814: declaration, otherwise, changed obstacks as GCC would. */ 5815: 5816: type = TREE_TYPE (decl); 5817: 1.1.1.5 root 5818: was_incomplete = (DECL_SIZE (decl) == NULL_TREE); 1.1 root 5819: 5820: /* Take care of TYPE_DECLs up front. */ 5821: if (TREE_CODE (decl) == TYPE_DECL) 5822: { 5823: if (init && DECL_INITIAL (decl)) 5824: { 5825: /* typedef foo = bar; store the type of bar as the type of foo. */ 5826: TREE_TYPE (decl) = type = TREE_TYPE (init); 1.1.1.5 root 5827: DECL_INITIAL (decl) = init = NULL_TREE; 1.1 root 5828: } 1.1.1.4 root 5829: if (IS_AGGR_TYPE (type) && DECL_NAME (decl)) 1.1 root 5830: { 5831: if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) 1.1.1.6 ! root 5832: cp_warning ("shadowing previous type declaration of `%#D'", decl); 1.1 root 5833: set_identifier_type_value (DECL_NAME (decl), type); 5834: CLASSTYPE_GOT_SEMICOLON (type) = 1; 5835: } 5836: GNU_xref_decl (current_function_decl, decl); 1.1.1.5 root 5837: rest_of_decl_compilation (decl, NULL_PTR, 5838: DECL_CONTEXT (decl) == NULL_TREE, 0); 1.1 root 5839: goto finish_end; 5840: } 1.1.1.4 root 5841: if (type != error_mark_node && IS_AGGR_TYPE (type) 5842: && CLASSTYPE_DECLARED_EXCEPTION (type)) 1.1 root 5843: { 5844: finish_exception_decl (NULL_TREE, decl); 5845: CLASSTYPE_GOT_SEMICOLON (type) = 1; 5846: goto finish_end; 5847: } 5848: if (TREE_CODE (decl) != FUNCTION_DECL) 5849: { 5850: ttype = target_type (type); 5851: #if 0 /* WTF? -KR 5852: Leave this out until we can figure out why it was 5853: needed/desirable in the first place. Then put a comment 5854: here explaining why. Or just delete the code if no ill 5855: effects arise. */ 5856: if (TYPE_NAME (ttype) 5857: && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL 5858: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype))) 5859: { 5860: tree old_id = TYPE_IDENTIFIER (ttype); 5861: char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2); 5862: /* Need to preserve template data for UPT nodes. */ 5863: tree old_template = IDENTIFIER_TEMPLATE (old_id); 5864: newname[0] = '_'; 5865: bcopy (IDENTIFIER_POINTER (old_id), newname + 1, 5866: IDENTIFIER_LENGTH (old_id) + 1); 5867: old_id = get_identifier (newname); 5868: lookup_tag_reverse (ttype, old_id); 5869: TYPE_IDENTIFIER (ttype) = old_id; 5870: IDENTIFIER_TEMPLATE (old_id) = old_template; 5871: } 5872: #endif 5873: } 5874: 1.1.1.4 root 5875: if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) 1.1 root 5876: && TYPE_NEEDS_CONSTRUCTING (type)) 5877: { 5878: 5879: /* Currently, GNU C++ puts constants in text space, making them 5880: impossible to initialize. In the future, one would hope for 5881: an operating system which understood the difference between 5882: initialization and the running of a program. */ 5883: was_readonly = 1; 5884: TREE_READONLY (decl) = 0; 5885: } 5886: 5887: if (TREE_CODE (decl) == FIELD_DECL) 5888: { 5889: if (init && init != error_mark_node) 1.1.1.4 root 5890: my_friendly_assert (TREE_PERMANENT (init), 147); 1.1 root 5891: 5892: if (asmspec) 5893: { 5894: /* This must override the asm specifier which was placed 5895: by grokclassfn. Lay this out fresh. 5896: 5897: @@ Should emit an error if this redefines an asm-specified 5898: @@ name, or if we have already used the function's name. */ 1.1.1.5 root 5899: DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; 1.1 root 5900: DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); 5901: make_decl_rtl (decl, asmspec, 0); 5902: } 5903: } 5904: /* If `start_decl' didn't like having an initialization, ignore it now. */ 1.1.1.5 root 5905: else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) 5906: init = NULL_TREE; 1.1.1.4 root 5907: else if (DECL_EXTERNAL (decl)) 1.1 root 5908: ; 5909: else if (TREE_CODE (type) == REFERENCE_TYPE) 5910: { 5911: grok_reference_init (decl, type, init, &cleanup); 1.1.1.5 root 5912: init = NULL_TREE; 1.1 root 5913: } 5914: 5915: GNU_xref_decl (current_function_decl, decl); 5916: 1.1.1.4 root 5917: if (TREE_CODE (decl) == FIELD_DECL || DECL_EXTERNAL (decl)) 1.1 root 5918: ; 5919: else if (TREE_CODE (decl) == CONST_DECL) 5920: { 1.1.1.4 root 5921: my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); 1.1 root 5922: 5923: DECL_INITIAL (decl) = init; 5924: 5925: /* This will keep us from needing to worry about our obstacks. */ 1.1.1.5 root 5926: my_friendly_assert (init != NULL_TREE, 149); 5927: init = NULL_TREE; 1.1 root 5928: } 5929: else if (init) 5930: { 5931: if (TYPE_NEEDS_CONSTRUCTING (type)) 5932: { 5933: if (TREE_CODE (type) == ARRAY_TYPE) 1.1.1.5 root 5934: init = digest_init (type, init, (tree *) 0); 1.1 root 5935: else if (TREE_CODE (init) == CONSTRUCTOR 5936: && CONSTRUCTOR_ELTS (init) != NULL_TREE) 5937: { 1.1.1.6 ! root 5938: cp_error ("`%D' must be initialized by constructor, not by `{...}'", decl); 1.1 root 5939: init = error_mark_node; 5940: } 5941: #if 0 5942: /* fix this in `build_functional_cast' instead. 5943: Here's the trigger code: 5944: 5945: struct ostream 5946: { 5947: ostream (); 5948: ostream (int, char *); 5949: ostream (char *); 5950: operator char *(); 5951: ostream (void *); 5952: operator void *(); 5953: operator << (int); 5954: }; 5955: int buf_size = 1024; 5956: static char buf[buf_size]; 5957: const char *debug(int i) { 5958: char *b = &buf[0]; 5959: ostream o = ostream(buf_size, b); 5960: o << i; 5961: return buf; 5962: } 5963: */ 5964: 5965: else if (TREE_CODE (init) == TARGET_EXPR 5966: && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR)) 5967: { 5968: /* User wrote something like `foo x = foo (args)' */ 1.1.1.4 root 5969: my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150); 5970: my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151); 1.1 root 5971: 5972: /* User wrote exactly `foo x = foo (args)' */ 5973: if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init)) 5974: { 5975: init = build (CALL_EXPR, TREE_TYPE (init), 5976: TREE_OPERAND (TREE_OPERAND (init, 1), 0), 5977: TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0); 5978: TREE_SIDE_EFFECTS (init) = 1; 5979: } 5980: } 5981: #endif 5982: 5983: /* We must hide the initializer so that expand_decl 5984: won't try to do something it does not understand. */ 5985: if (current_binding_level == global_binding_level) 5986: { 1.1.1.5 root 5987: tree value = digest_init (type, empty_init_node, (tree *) 0); 1.1 root 5988: DECL_INITIAL (decl) = value; 5989: } 5990: else 5991: DECL_INITIAL (decl) = error_mark_node; 5992: } 5993: else 5994: { 5995: if (TREE_CODE (init) != TREE_VEC) 5996: init = store_init_value (decl, init); 5997: 5998: if (init) 5999: /* Don't let anyone try to initialize this variable 6000: until we are ready to do so. */ 6001: DECL_INITIAL (decl) = error_mark_node; 6002: } 6003: } 6004: else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' 1.1.1.6 ! root 6005: && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)) ! 6006: && init != NULL_TREE) 1.1 root 6007: { 6008: tree ctype = type; 6009: while (TREE_CODE (ctype) == ARRAY_TYPE) 6010: ctype = TREE_TYPE (ctype); 6011: if (! TYPE_NEEDS_CONSTRUCTOR (ctype)) 6012: { 6013: if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype)) 1.1.1.6 ! root 6014: cp_error ("structure `%D' with uninitialized const members", decl); 1.1 root 6015: if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype)) 1.1.1.6 ! root 6016: cp_error ("structure `%D' with uninitialized reference members", decl); 1.1 root 6017: } 6018: 6019: if (TREE_CODE (decl) == VAR_DECL 6020: && !TYPE_NEEDS_CONSTRUCTING (type) 6021: && (TYPE_READONLY (type) || TREE_READONLY (decl))) 1.1.1.6 ! root 6022: cp_error ("uninitialized const `%D'", decl); 1.1 root 6023: 6024: /* Initialize variables in need of static initialization 6025: with `empty_init_node' to keep assemble_variable from putting them 6026: in the wrong program space. (Common storage is okay for non-public 6027: uninitialized data; the linker can't match it with storage from other 6028: files, and we may save some disk space.) */ 6029: if (flag_pic == 0 6030: && TREE_STATIC (decl) 6031: && TREE_PUBLIC (decl) 1.1.1.4 root 6032: && ! DECL_EXTERNAL (decl) 1.1 root 6033: && TREE_CODE (decl) == VAR_DECL 6034: && TYPE_NEEDS_CONSTRUCTING (type) 1.1.1.5 root 6035: && (DECL_INITIAL (decl) == NULL_TREE 1.1 root 6036: || DECL_INITIAL (decl) == error_mark_node)) 6037: { 1.1.1.5 root 6038: tree value = digest_init (type, empty_init_node, (tree *) 0); 1.1 root 6039: DECL_INITIAL (decl) = value; 6040: } 6041: } 6042: else if (TREE_CODE (decl) == VAR_DECL 6043: && TREE_CODE (type) != REFERENCE_TYPE 6044: && (TYPE_READONLY (type) || TREE_READONLY (decl))) 6045: { 1.1.1.4 root 6046: /* ``Unless explicitly declared extern, a const object does not have 1.1.1.5 root 6047: external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 6048: However, if it's `const int foo = 1; const int foo;', don't complain 1.1.1.6 ! root 6049: about the second decl, since it does have an initializer before. ! 6050: We deliberately don't complain about arrays, because they're ! 6051: supposed to be initialized by a constructor. */ ! 6052: if (! DECL_INITIAL (decl) ! 6053: && TREE_CODE (type) != ARRAY_TYPE ! 6054: && (!pedantic || !current_class_type)) ! 6055: cp_error ("uninitialized const `%#D'", decl); 1.1 root 6056: } 6057: 6058: /* For top-level declaration, the initial value was read in 6059: the temporary obstack. MAXINDEX, rtl, etc. to be made below 6060: must go in the permanent obstack; but don't discard the 6061: temporary data yet. */ 6062: 6063: if (current_binding_level == global_binding_level && temporary) 6064: end_temporary_allocation (); 6065: 6066: /* Deduce size of array from initialization, if not already known. */ 6067: 6068: if (TREE_CODE (type) == ARRAY_TYPE 1.1.1.5 root 6069: && TYPE_DOMAIN (type) == NULL_TREE 1.1 root 6070: && TREE_CODE (decl) != TYPE_DECL) 6071: { 6072: int do_default 6073: = (TREE_STATIC (decl) 6074: /* Even if pedantic, an external linkage array 6075: may have incomplete type at first. */ 1.1.1.4 root 6076: ? pedantic && DECL_EXTERNAL (decl) 6077: : !DECL_EXTERNAL (decl)); 1.1 root 6078: tree initializer = init ? init : DECL_INITIAL (decl); 6079: int failure = complete_array_type (type, initializer, do_default); 6080: 6081: if (failure == 1) 1.1.1.6 ! root 6082: cp_error ("initializer fails to determine size of `%D'", decl); 1.1 root 6083: 6084: if (failure == 2) 6085: { 6086: if (do_default) 1.1.1.6 ! root 6087: cp_error ("array size missing in `%D'", decl); ! 6088: /* If a `static' var's size isn't known, make it extern as ! 6089: well as static, so it does not get allocated. If it's not ! 6090: `static', then don't mark it extern; finish_incomplete_decl ! 6091: will give it a default size and it will get allocated. */ ! 6092: else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) 1.1.1.4 root 6093: DECL_EXTERNAL (decl) = 1; 1.1 root 6094: } 6095: 1.1.1.5 root 6096: if (pedantic && TYPE_DOMAIN (type) != NULL_TREE 1.1 root 6097: && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 6098: integer_zero_node)) 1.1.1.6 ! root 6099: cp_error ("zero-size array `%D'", decl); 1.1 root 6100: 6101: layout_decl (decl, 0); 6102: } 6103: 6104: if (TREE_CODE (decl) == VAR_DECL) 6105: { 1.1.1.6 ! root 6106: if (DECL_SIZE (decl) == NULL_TREE ! 6107: && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE) ! 6108: layout_decl (decl, 0); ! 6109: 1.1.1.5 root 6110: if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) 1.1 root 6111: { 6112: /* A static variable with an incomplete type: 6113: that is an error if it is initialized or `static'. 6114: Otherwise, let it through, but if it is not `extern' 6115: then it may cause an error message later. */ 1.1.1.5 root 6116: if (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl) != NULL_TREE) 1.1.1.6 ! root 6117: cp_error ("storage size of `%D' isn't known", decl); 1.1.1.5 root 6118: init = NULL_TREE; 1.1 root 6119: } 1.1.1.5 root 6120: else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) 1.1 root 6121: { 1.1.1.5 root 6122: /* An automatic variable with an incomplete type: that is an error. 6123: Don't talk about array types here, since we took care of that 6124: message in grokdeclarator. */ 1.1.1.6 ! root 6125: cp_error ("storage size of `%D' isn't known", decl); 1.1 root 6126: TREE_TYPE (decl) = error_mark_node; 6127: } 1.1.1.4 root 6128: else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) 1.1 root 6129: /* Let debugger know it should output info for this type. */ 6130: note_debug_info_needed (ttype); 6131: 1.1.1.4 root 6132: if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) 1.1.1.5 root 6133: && DECL_SIZE (decl) != NULL_TREE 6134: && ! TREE_CONSTANT (DECL_SIZE (decl))) 1.1.1.6 ! root 6135: { ! 6136: if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) ! 6137: constant_expression_warning (DECL_SIZE (decl)); ! 6138: else ! 6139: cp_error ("storage size of `%D' isn't constant", decl); ! 6140: } 1.1 root 6141: 1.1.1.4 root 6142: if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type)) 1.1 root 6143: { 6144: int yes = suspend_momentary (); 6145: 6146: /* If INIT comes from a functional cast, use the cleanup 6147: we built for that. Otherwise, make our own cleanup. */ 6148: if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR 6149: && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1)) 6150: { 6151: cleanup = TREE_OPERAND (init, 2); 6152: init = TREE_OPERAND (init, 0); 6153: current_binding_level->have_cleanups = 1; 6154: current_binding_level->more_exceptions_ok = 0; 6155: } 6156: else 6157: cleanup = maybe_build_cleanup (decl); 6158: resume_momentary (yes); 6159: } 6160: } 6161: /* PARM_DECLs get cleanups, too. */ 6162: else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) 6163: { 6164: if (temporary) 6165: end_temporary_allocation (); 6166: cleanup = maybe_build_cleanup (decl); 6167: if (temporary) 6168: resume_temporary_allocation (); 6169: } 6170: 6171: /* Output the assembler code and/or RTL code for variables and functions, 6172: unless the type is an undefined structure or union. 6173: If not, it will get done when the type is completed. */ 6174: 6175: if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL 6176: || TREE_CODE (decl) == RESULT_DECL) 6177: { 1.1.1.6 ! root 6178: /* ??? FIXME: What about nested classes? */ ! 6179: int toplev = (current_binding_level == global_binding_level ! 6180: || pseudo_global_level_p ()); 1.1 root 6181: int was_temp 6182: = ((flag_traditional 6183: || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type))) 6184: && allocation_temporary_p ()); 6185: 6186: if (was_temp) 6187: end_temporary_allocation (); 6188: 6189: /* If we are in need of a cleanup, get out of any implicit 6190: handlers that have been established so far. */ 6191: if (cleanup && current_binding_level->parm_flag == 3) 6192: { 6193: pop_implicit_try_blocks (decl); 6194: current_binding_level->more_exceptions_ok = 0; 6195: } 6196: 6197: if (TREE_CODE (decl) == VAR_DECL 6198: && current_binding_level != global_binding_level 6199: && ! TREE_STATIC (decl) 6200: && type_needs_gc_entry (type)) 6201: DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index); 6202: 6203: if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) 1.1.1.5 root 6204: make_decl_rtl (decl, NULL_PTR, toplev); 1.1 root 6205: else if (TREE_CODE (decl) == VAR_DECL 6206: && TREE_READONLY (decl) 1.1.1.5 root 6207: && DECL_INITIAL (decl) != NULL_TREE 1.1 root 6208: && DECL_INITIAL (decl) != error_mark_node 6209: && DECL_INITIAL (decl) != empty_init_node) 6210: { 6211: DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); 6212: 6213: if (asmspec) 6214: DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); 6215: 6216: if (! toplev 6217: && TREE_STATIC (decl) 6218: && ! TREE_SIDE_EFFECTS (decl) 6219: && ! TREE_PUBLIC (decl) 1.1.1.4 root 6220: && ! DECL_EXTERNAL (decl) 1.1 root 6221: && ! TYPE_NEEDS_DESTRUCTOR (type) 6222: && DECL_MODE (decl) != BLKmode) 6223: { 6224: /* If this variable is really a constant, then fill its DECL_RTL 6225: slot with something which won't take up storage. 6226: If something later should take its address, we can always give 6227: it legitimate RTL at that time. */ 1.1.1.4 root 6228: DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); 1.1 root 6229: store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); 6230: TREE_ASM_WRITTEN (decl) = 1; 6231: } 6232: else if (toplev) 6233: { 6234: /* Keep GCC from complaining that this variable 6235: is defined but never used. */ 1.1.1.4 root 6236: TREE_USED (decl) = 1; 1.1 root 6237: /* If this is a static const, change its apparent linkage 6238: if it belongs to a #pragma interface. */ 1.1.1.4 root 6239: if (TREE_STATIC (decl) && !interface_unknown) 1.1 root 6240: { 1.1.1.4 root 6241: TREE_PUBLIC (decl) = 1; 6242: DECL_EXTERNAL (decl) = interface_only; 1.1 root 6243: } 6244: make_decl_rtl (decl, asmspec, toplev); 6245: } 6246: else 6247: rest_of_decl_compilation (decl, asmspec, toplev, 0); 6248: } 6249: else if (TREE_CODE (decl) == VAR_DECL 6250: && DECL_LANG_SPECIFIC (decl) 6251: && DECL_IN_AGGR_P (decl)) 6252: { 6253: if (TREE_STATIC (decl)) 1.1.1.6 ! root 6254: { ! 6255: if (init == NULL_TREE 1.1 root 6256: #ifdef DEFAULT_STATIC_DEFS 1.1.1.6 ! root 6257: /* If this code is dead, then users must ! 6258: explicitly declare static member variables ! 6259: outside the class def'n as well. */ ! 6260: && TYPE_NEEDS_CONSTRUCTING (type) 1.1 root 6261: #endif 1.1.1.6 ! root 6262: ) ! 6263: { ! 6264: DECL_EXTERNAL (decl) = 1; ! 6265: make_decl_rtl (decl, asmspec, 1); ! 6266: } ! 6267: else ! 6268: rest_of_decl_compilation (decl, asmspec, toplev, 0); ! 6269: } 1.1 root 6270: else 6271: /* Just a constant field. Should not need any rtl. */ 6272: goto finish_end0; 6273: } 6274: else 6275: rest_of_decl_compilation (decl, asmspec, toplev, 0); 6276: 6277: if (was_temp) 6278: resume_temporary_allocation (); 6279: 1.1.1.4 root 6280: if (type != error_mark_node 6281: && TYPE_LANG_SPECIFIC (type) 6282: && CLASSTYPE_ABSTRACT_VIRTUALS (type)) 1.1 root 6283: abstract_virtuals_error (decl, type); 1.1.1.3 root 6284: else if ((TREE_CODE (type) == FUNCTION_TYPE 6285: || TREE_CODE (type) == METHOD_TYPE) 1.1 root 6286: && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) 6287: && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) 6288: abstract_virtuals_error (decl, TREE_TYPE (type)); 6289: 6290: if (TREE_CODE (decl) == FUNCTION_DECL) 6291: { 6292: /* C++: Handle overloaded functions with default parameters. */ 6293: if (DECL_OVERLOADED (decl)) 6294: { 6295: tree parmtypes = TYPE_ARG_TYPES (type); 6296: tree prev = NULL_TREE; 1.1.1.2 root 6297: tree original_name = DECL_NAME (decl); 1.1 root 6298: struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl); 1.1.1.2 root 6299: /* All variants will share an uncollectible lang_decl. */ 1.1 root 6300: copy_decl_lang_specific (decl); 6301: 6302: while (parmtypes && parmtypes != void_list_node) 6303: { 1.1.1.6 ! root 6304: /* The default value for the parameter in parmtypes is ! 6305: stored in the TREE_PURPOSE of the TREE_LIST. */ 1.1 root 6306: if (TREE_PURPOSE (parmtypes)) 6307: { 6308: tree fnname, fndecl; 1.1.1.6 ! root 6309: tree *argp; ! 6310: ! 6311: argp = prev ? & TREE_CHAIN (prev) ! 6312: : & TYPE_ARG_TYPES (type); 1.1 root 6313: 6314: *argp = NULL_TREE; 6315: fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0); 6316: *argp = parmtypes; 6317: fndecl = build_decl (FUNCTION_DECL, fnname, type); 1.1.1.4 root 6318: DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl); 1.1 root 6319: TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl); 1.1.1.4 root 6320: DECL_INLINE (fndecl) = DECL_INLINE (decl); 1.1 root 6321: /* Keep G++ from thinking this function is unused. 6322: It is only used to speed up search in name space. */ 6323: TREE_USED (fndecl) = 1; 6324: TREE_ASM_WRITTEN (fndecl) = 1; 6325: DECL_INITIAL (fndecl) = NULL_TREE; 6326: DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl); 6327: fndecl = pushdecl (fndecl); 6328: DECL_INITIAL (fndecl) = error_mark_node; 6329: DECL_RTL (fndecl) = DECL_RTL (decl); 6330: } 6331: prev = parmtypes; 6332: parmtypes = TREE_CHAIN (parmtypes); 6333: } 6334: DECL_LANG_SPECIFIC (decl) = tmp_lang_decl; 6335: } 6336: } 1.1.1.4 root 6337: else if (DECL_EXTERNAL (decl)) 1.1 root 6338: ; 6339: else if (TREE_STATIC (decl) && type != error_mark_node) 6340: { 6341: /* Cleanups for static variables are handled by `finish_file'. */ 6342: if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE) 6343: expand_static_init (decl, init); 1.1.1.4 root 6344: else if (TYPE_NEEDS_DESTRUCTOR (type)) 6345: static_aggregates = perm_tree_cons (NULL_TREE, decl, 6346: static_aggregates); 1.1 root 6347: 6348: /* Make entry in appropriate vector. */ 6349: if (flag_gc && type_needs_gc_entry (type)) 6350: build_static_gc_entry (decl, type); 6351: } 1.1.1.6 ! root 6352: else if (! toplev) 1.1 root 6353: { 6354: /* This is a declared decl which must live until the 6355: end of the binding contour. It may need a cleanup. */ 6356: 6357: /* Recompute the RTL of a local array now 6358: if it used to be an incomplete type. */ 6359: if (was_incomplete && ! TREE_STATIC (decl)) 6360: { 6361: /* If we used it already as memory, it must stay in memory. */ 6362: TREE_ADDRESSABLE (decl) = TREE_USED (decl); 6363: /* If it's still incomplete now, no init will save it. */ 1.1.1.5 root 6364: if (DECL_SIZE (decl) == NULL_TREE) 6365: DECL_INITIAL (decl) = NULL_TREE; 1.1 root 6366: expand_decl (decl); 6367: } 6368: else if (! TREE_ASM_WRITTEN (decl) 1.1.1.5 root 6369: && (TYPE_SIZE (type) != NULL_TREE 6370: || TREE_CODE (type) == ARRAY_TYPE)) 1.1 root 6371: { 6372: /* Do this here, because we did not expand this decl's 6373: rtl in start_decl. */ 1.1.1.5 root 6374: if (DECL_RTL (decl) == NULL_RTX) 1.1 root 6375: expand_decl (decl); 6376: else if (cleanup) 6377: { 6378: expand_decl_cleanup (NULL_TREE, cleanup); 6379: /* Cleanup used up here. */ 1.1.1.5 root 6380: cleanup = NULL_TREE; 1.1 root 6381: } 6382: } 6383: 6384: if (DECL_SIZE (decl) && type != error_mark_node) 6385: { 6386: /* Compute and store the initial value. */ 6387: expand_decl_init (decl); 6388: 6389: if (init || TYPE_NEEDS_CONSTRUCTING (type)) 6390: { 6391: emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); 6392: expand_aggr_init (decl, init, 0); 6393: } 6394: 6395: /* Set this to 0 so we can tell whether an aggregate 6396: which was initialized was ever used. */ 6397: if (TYPE_NEEDS_CONSTRUCTING (type)) 6398: TREE_USED (decl) = 0; 6399: 6400: /* Store the cleanup, if there was one. */ 6401: if (cleanup) 6402: { 6403: if (! expand_decl_cleanup (decl, cleanup)) 1.1.1.6 ! root 6404: cp_error ("parser lost in parsing declaration of `%D'", decl); 1.1 root 6405: } 6406: } 6407: } 6408: finish_end0: 6409: 6410: /* Undo call to `pushclass' that was done in `start_decl' 6411: due to initialization of qualified member variable. 6412: I.e., Foo::x = 10; */ 6413: { 6414: tree context = DECL_CONTEXT (decl); 6415: if (context 1.1.1.4 root 6416: && TREE_CODE_CLASS (TREE_CODE (context)) == 't' 1.1 root 6417: && (TREE_CODE (decl) == VAR_DECL 6418: /* We also have a pushclass done that we need to undo here 6419: if we're at top level and declare a method. */ 6420: || (TREE_CODE (decl) == FUNCTION_DECL 6421: /* If size hasn't been set, we're still defining it, 6422: and therefore inside the class body; don't pop 6423: the binding level.. */ 1.1.1.5 root 6424: && TYPE_SIZE (context) != NULL_TREE 1.1 root 6425: /* The binding level gets popped elsewhere for a 6426: friend declaration inside another class. */ 1.1.1.3 root 6427: && TYPE_IDENTIFIER (context) == current_class_name 1.1 root 6428: ))) 6429: popclass (1); 6430: } 6431: } 6432: 6433: finish_end: 6434: 6435: if (need_pop) 6436: { 6437: /* Resume permanent allocation, if not within a function. */ 6438: /* The corresponding push_obstacks_nochange is in start_decl, 6439: start_method, groktypename, and in grokfield. */ 6440: pop_obstacks (); 6441: } 6442: 6443: if (was_readonly) 6444: TREE_READONLY (decl) = 1; 6445: 6446: if (flag_cadillac) 6447: cadillac_finish_decl (decl); 6448: } 6449: 6450: static void 6451: expand_static_init (decl, init) 6452: tree decl; 6453: tree init; 6454: { 6455: tree oldstatic = value_member (decl, static_aggregates); 6456: if (oldstatic) 6457: { 1.1.1.6 ! root 6458: if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) ! 6459: cp_error ("multiple initializations given for `%D'", decl); 1.1 root 6460: } 6461: else if (current_binding_level != global_binding_level) 6462: { 6463: /* Emit code to perform this initialization but once. */ 6464: tree temp; 6465: 6466: /* Remember this information until end of file. */ 6467: push_obstacks (&permanent_obstack, &permanent_obstack); 6468: 6469: /* Emit code to perform this initialization but once. */ 6470: temp = get_temp_name (integer_type_node, 1); 1.1.1.5 root 6471: rest_of_decl_compilation (temp, NULL_PTR, 0, 0); 1.1 root 6472: expand_start_cond (build_binary_op (EQ_EXPR, temp, 1.1.1.5 root 6473: integer_zero_node, 1), 0); 1.1 root 6474: expand_assignment (temp, integer_one_node, 0, 0); 6475: if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) 6476: { 6477: expand_aggr_init (decl, init, 0); 6478: do_pending_stack_adjust (); 6479: } 6480: else 6481: expand_assignment (decl, init, 0, 0); 6482: expand_end_cond (); 6483: if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) 6484: { 6485: static_aggregates = perm_tree_cons (temp, decl, static_aggregates); 6486: TREE_STATIC (static_aggregates) = 1; 6487: } 6488: 6489: /* Resume old (possibly temporary) allocation. */ 6490: pop_obstacks (); 6491: } 6492: else 6493: { 6494: /* This code takes into account memory allocation 6495: policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING 6496: does not hold for this object, then we must make permanent 6497: the storage currently in the temporary obstack. */ 6498: if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) 6499: preserve_initializer (); 6500: static_aggregates = perm_tree_cons (init, decl, static_aggregates); 6501: } 6502: } 6503: 6504: /* Make TYPE a complete type based on INITIAL_VALUE. 1.1.1.2 root 6505: Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, 1.1 root 6506: 2 if there was no information (in which case assume 1 if DO_DEFAULT). */ 6507: 6508: int 6509: complete_array_type (type, initial_value, do_default) 1.1.1.5 root 6510: tree type, initial_value; 1.1 root 6511: int do_default; 6512: { 6513: register tree maxindex = NULL_TREE; 6514: int value = 0; 6515: 6516: if (initial_value) 6517: { 6518: /* Note MAXINDEX is really the maximum index, 6519: one less than the size. */ 6520: if (TREE_CODE (initial_value) == STRING_CST) 6521: maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0); 6522: else if (TREE_CODE (initial_value) == CONSTRUCTOR) 6523: { 6524: register int nelts 6525: = list_length (CONSTRUCTOR_ELTS (initial_value)); 1.1.1.6 ! root 6526: maxindex = build_int_2 (nelts - 1, - (nelts == 0)); 1.1 root 6527: } 6528: else 6529: { 6530: /* Make an error message unless that happened already. */ 6531: if (initial_value != error_mark_node) 6532: value = 1; 6533: 6534: /* Prevent further error messages. */ 1.1.1.6 ! root 6535: maxindex = build_int_2 (0, 0); 1.1 root 6536: } 6537: } 6538: 6539: if (!maxindex) 6540: { 6541: if (do_default) 1.1.1.6 ! root 6542: maxindex = build_int_2 (0, 0); 1.1 root 6543: value = 2; 6544: } 6545: 6546: if (maxindex) 6547: { 6548: TYPE_DOMAIN (type) = build_index_type (maxindex); 6549: if (!TREE_TYPE (maxindex)) 6550: TREE_TYPE (maxindex) = TYPE_DOMAIN (type); 6551: } 6552: 6553: /* Lay out the type now that we can get the real answer. */ 6554: 6555: layout_type (type); 6556: 6557: return value; 6558: } 6559: 6560: /* Return zero if something is declared to be a member of type 6561: CTYPE when in the context of CUR_TYPE. STRING is the error 6562: message to print in that case. Otherwise, quietly return 1. */ 6563: static int 6564: member_function_or_else (ctype, cur_type, string) 6565: tree ctype, cur_type; 6566: char *string; 6567: { 6568: if (ctype && ctype != cur_type) 6569: { 6570: error (string, TYPE_NAME_STRING (ctype)); 6571: return 0; 6572: } 6573: return 1; 6574: } 6575: 6576: /* Subroutine of `grokdeclarator'. */ 6577: 1.1.1.6 ! root 6578: /* Generate errors possibly applicable for a given set of specifiers. ! 6579: This is for ARM $7.1.2. */ ! 6580: static void ! 6581: bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) ! 6582: tree object; ! 6583: char *type; ! 6584: int virtualp, quals, inlinep, friendp, raises; ! 6585: { ! 6586: if (virtualp) ! 6587: cp_error ("`%D' declared as a `virtual' %s", object, type); ! 6588: if (inlinep) ! 6589: cp_error ("`%D' declared as an `inline' %s", object, type); ! 6590: if (quals) ! 6591: cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", object, type); ! 6592: if (friendp) ! 6593: cp_error_at ("invalid friend declaration", object); ! 6594: if (raises) ! 6595: cp_error_at ("invalid raises declaration", object); ! 6596: } ! 6597: 1.1 root 6598: /* CTYPE is class type, or null if non-class. 6599: TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE 6600: or METHOD_TYPE. 6601: DECLARATOR is the function's name. 6602: VIRTUALP is truthvalue of whether the function is virtual or not. 6603: FLAGS are to be passed through to `grokclassfn'. 6604: QUALS are qualifiers indicating whether the function is `const' 6605: or `volatile'. 6606: RAISES is a list of exceptions that this function can raise. 6607: CHECK is 1 if we must find this method in CTYPE, 0 if we should 6608: not look, and -1 if we should not call `grokclassfn' at all. */ 6609: static tree 1.1.1.5 root 6610: grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check, publicp) 1.1 root 6611: tree ctype, type; 6612: tree declarator; 6613: int virtualp; 6614: enum overload_flags flags; 6615: tree quals, raises; 1.1.1.5 root 6616: int check, publicp; 1.1 root 6617: { 6618: tree cname, decl; 6619: int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; 6620: 6621: if (ctype) 6622: cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL 6623: ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); 6624: else 6625: cname = NULL_TREE; 6626: 6627: if (raises) 6628: { 6629: type = build_exception_variant (ctype, type, raises); 6630: raises = TYPE_RAISES_EXCEPTIONS (type); 6631: } 6632: decl = build_lang_decl (FUNCTION_DECL, declarator, type); 1.1.1.4 root 6633: /* propagate volatile out from type to decl */ 6634: if (TYPE_VOLATILE (type)) 6635: TREE_THIS_VOLATILE (decl) = 1; 1.1.1.5 root 6636: 6637: /* Should probably propagate const out from type to decl I bet (mrs). */ 1.1 root 6638: if (staticp) 6639: { 6640: DECL_STATIC_FUNCTION_P (decl) = 1; 6641: DECL_CONTEXT (decl) = ctype; 6642: DECL_CLASS_CONTEXT (decl) = ctype; 6643: } 1.1.1.5 root 6644: 6645: if (publicp) 6646: TREE_PUBLIC (decl) = 1; 6647: 1.1.1.4 root 6648: DECL_EXTERNAL (decl) = 1; 1.1 root 6649: if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) 6650: { 1.1.1.6 ! root 6651: cp_error ("%smember function `%D' cannot have `%T' method qualifier", ! 6652: (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); 1.1 root 6653: quals = NULL_TREE; 6654: } 6655: 1.1.1.6 ! root 6656: if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) ! 6657: grok_op_properties (decl, virtualp); 1.1.1.4 root 6658: 1.1 root 6659: /* Caller will do the rest of this. */ 6660: if (check < 0) 6661: return decl; 6662: 6663: if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) 6664: { 6665: tree tmp; 6666: /* Just handle constructors here. We could do this 6667: inside the following if stmt, but I think 6668: that the code is more legible by breaking this 6669: case out. See comments below for what each of 6670: the following calls is supposed to do. */ 6671: DECL_CONSTRUCTOR_P (decl) = 1; 6672: 6673: grokclassfn (ctype, declarator, decl, flags, quals); 6674: if (check) 1.1.1.5 root 6675: check_classfn (ctype, declarator, decl); 1.1 root 6676: grok_ctor_properties (ctype, decl); 6677: if (check == 0) 6678: { 6679: /* FIXME: this should only need to look at IDENTIFIER_GLOBAL_VALUE. */ 6680: tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); 1.1.1.5 root 6681: if (tmp == NULL_TREE) 1.1 root 6682: IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; 6683: else if (TREE_CODE (tmp) != TREE_CODE (decl)) 1.1.1.6 ! root 6684: cp_error ("inconsistent declarations for `%D'", decl); 1.1 root 6685: else 6686: { 6687: duplicate_decls (decl, tmp); 6688: decl = tmp; 1.1.1.5 root 6689: /* avoid creating circularities. */ 6690: DECL_CHAIN (decl) = NULL_TREE; 1.1 root 6691: } 1.1.1.5 root 6692: make_decl_rtl (decl, NULL_PTR, 1); 1.1 root 6693: } 6694: } 6695: else 6696: { 6697: tree tmp; 6698: 6699: /* Function gets the ugly name, field gets the nice one. 6700: This call may change the type of the function (because 1.1.1.4 root 6701: of default parameters)! */ 1.1 root 6702: if (ctype != NULL_TREE) 6703: grokclassfn (ctype, cname, decl, flags, quals); 6704: 6705: if (ctype != NULL_TREE && check) 1.1.1.5 root 6706: check_classfn (ctype, cname, decl); 1.1 root 6707: 6708: if (ctype == NULL_TREE || check) 6709: return decl; 6710: 6711: /* Now install the declaration of this function so that 6712: others may find it (esp. its DECL_FRIENDLIST). 6713: Pretend we are at top level, we will get true 6714: reference later, perhaps. 6715: 6716: FIXME: This should only need to look at IDENTIFIER_GLOBAL_VALUE. */ 6717: tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); 1.1.1.5 root 6718: if (tmp == NULL_TREE) 1.1 root 6719: IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; 6720: else if (TREE_CODE (tmp) != TREE_CODE (decl)) 1.1.1.6 ! root 6721: cp_error ("inconsistent declarations for `%D'", decl); 1.1 root 6722: else 6723: { 6724: duplicate_decls (decl, tmp); 6725: decl = tmp; 1.1.1.5 root 6726: /* avoid creating circularities. */ 6727: DECL_CHAIN (decl) = NULL_TREE; 1.1 root 6728: } 1.1.1.5 root 6729: make_decl_rtl (decl, NULL_PTR, 1); 1.1 root 6730: 6731: /* If this declaration supersedes the declaration of 6732: a method declared virtual in the base class, then 6733: mark this field as being virtual as well. */ 6734: { 6735: tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype)); 6736: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; 6737: 6738: for (i = 0; i < n_baselinks; i++) 6739: { 1.1.1.4 root 6740: tree base_binfo = TREE_VEC_ELT (binfos, i); 6741: if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) || flag_all_virtual == 1) 1.1 root 6742: { 1.1.1.4 root 6743: tmp = get_first_matching_virtual (base_binfo, decl, 1.1 root 6744: flags == DTOR_FLAG); 6745: if (tmp) 6746: { 1.1.1.6 ! root 6747: /* If this function overrides some virtual in some base ! 6748: class, then the function itself is also necessarily ! 6749: virtual, even if the user didn't explicitly say so. */ ! 6750: DECL_VIRTUAL_P (decl) = 1; ! 6751: 1.1 root 6752: /* The TMP we really want is the one from the deepest 6753: baseclass on this path, taking care not to 6754: duplicate if we have already found it (via another 6755: path to its virtual baseclass. */ 6756: if (staticp) 6757: { 1.1.1.6 ! root 6758: cp_error ("method `%D' may not be declared static", decl); ! 6759: cp_error_at ("(since `%D' declared virtual in base class.)", tmp); 1.1 root 6760: break; 6761: } 6762: virtualp = 1; 6763: 1.1.1.4 root 6764: if ((TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (base_binfo)) 1.1 root 6765: || TYPE_USES_MULTIPLE_INHERITANCE (ctype)) 1.1.1.4 root 6766: && BINFO_TYPE (base_binfo) != DECL_CONTEXT (tmp)) 1.1 root 6767: tmp = get_first_matching_virtual (TYPE_BINFO (DECL_CONTEXT (tmp)), 6768: decl, flags == DTOR_FLAG); 6769: if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE) 6770: { 6771: /* The argument types may have changed... */ 6772: tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); 6773: tree base_variant = TREE_TYPE (TREE_VALUE (argtypes)); 6774: 6775: argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))), 6776: TREE_CHAIN (argtypes)); 6777: /* But the return type has not. */ 6778: type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes); 6779: if (raises) 6780: { 6781: type = build_exception_variant (ctype, type, raises); 6782: raises = TYPE_RAISES_EXCEPTIONS (type); 6783: } 6784: TREE_TYPE (decl) = type; 6785: DECL_VINDEX (decl) 6786: = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl)); 6787: } 6788: } 6789: } 6790: } 6791: } 6792: if (virtualp) 6793: { 6794: if (DECL_VINDEX (decl) == NULL_TREE) 6795: DECL_VINDEX (decl) = error_mark_node; 6796: IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; 6797: if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) 1.1.1.4 root 6798: /* If this function is derived from a template, don't 6799: make it public. This shouldn't be here, but there's 6800: no good way to override the interface pragmas for one 6801: function or class only. Bletch. */ 6802: && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE 1.1 root 6803: && (write_virtuals == 2 6804: || (write_virtuals == 3 1.1.1.6 ! root 6805: && CLASSTYPE_INTERFACE_KNOWN (ctype)))) 1.1 root 6806: TREE_PUBLIC (decl) = 1; 6807: } 6808: } 6809: return decl; 6810: } 6811: 6812: static tree 1.1.1.5 root 6813: grokvardecl (type, declarator, specbits, initialized) 6814: tree type; 1.1 root 6815: tree declarator; 1.1.1.5 root 6816: RID_BIT_TYPE specbits; 6817: int initialized; 1.1 root 6818: { 6819: tree decl; 6820: 6821: if (TREE_CODE (type) == OFFSET_TYPE) 6822: { 6823: /* If you declare a static member so that it 6824: can be initialized, the code will reach here. */ 6825: tree field = lookup_field (TYPE_OFFSET_BASETYPE (type), 1.1.1.4 root 6826: declarator, 0, 0); 1.1 root 6827: if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) 6828: { 6829: tree basetype = TYPE_OFFSET_BASETYPE (type); 6830: error ("`%s' is not a static member of class `%s'", 6831: IDENTIFIER_POINTER (declarator), 6832: TYPE_NAME_STRING (basetype)); 6833: type = TREE_TYPE (type); 6834: decl = build_lang_field_decl (VAR_DECL, declarator, type); 6835: DECL_CONTEXT (decl) = basetype; 6836: DECL_CLASS_CONTEXT (decl) = basetype; 6837: } 6838: else 6839: { 6840: tree f_type = TREE_TYPE (field); 6841: tree o_type = TREE_TYPE (type); 6842: 6843: if (TYPE_SIZE (f_type) == NULL_TREE) 6844: { 6845: if (TREE_CODE (f_type) != TREE_CODE (o_type) 6846: || (TREE_CODE (f_type) == ARRAY_TYPE 6847: && TREE_TYPE (f_type) != TREE_TYPE (o_type))) 6848: error ("redeclaration of type for `%s'", 6849: IDENTIFIER_POINTER (declarator)); 1.1.1.2 root 6850: else if (TYPE_SIZE (o_type) != NULL_TREE) 6851: TREE_TYPE (field) = type; 1.1 root 6852: } 6853: else if (f_type != o_type) 6854: error ("redeclaration of type for `%s'", 6855: IDENTIFIER_POINTER (declarator)); 6856: decl = field; 6857: if (initialized && DECL_INITIAL (decl) 6858: /* Complain about multiply-initialized 6859: member variables, but don't be faked 6860: out if initializer is faked up from `empty_init_node'. */ 6861: && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR 6862: || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE)) 6863: error_with_aggr_type (DECL_CONTEXT (decl), 6864: "multiple initializations of static member `%s::%s'", 6865: IDENTIFIER_POINTER (DECL_NAME (decl))); 6866: } 6867: } 1.1.1.6 ! root 6868: else ! 6869: decl = build_decl (VAR_DECL, declarator, type); 1.1 root 6870: 1.1.1.6 ! root 6871: if (RIDBIT_SETP (RID_EXTERN, specbits)) 1.1 root 6872: { 1.1.1.4 root 6873: DECL_THIS_EXTERN (decl) = 1; 6874: DECL_EXTERNAL (decl) = !initialized; 1.1 root 6875: } 6876: 6877: /* In class context, static means one per class, 6878: public visibility, and static storage. */ 1.1.1.5 root 6879: if (DECL_FIELD_CONTEXT (decl) != NULL_TREE 1.1 root 6880: && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl))) 6881: { 6882: TREE_PUBLIC (decl) = 1; 6883: TREE_STATIC (decl) = 1; 1.1.1.4 root 6884: DECL_EXTERNAL (decl) = !initialized; 1.1 root 6885: } 6886: /* At top level, either `static' or no s.c. makes a definition 6887: (perhaps tentative), and absence of `static' makes it public. */ 6888: else if (current_binding_level == global_binding_level) 6889: { 1.1.1.6 ! root 6890: TREE_PUBLIC (decl) = RIDBIT_NOTSETP (RID_STATIC, specbits); 1.1.1.4 root 6891: TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); 1.1 root 6892: } 6893: /* Not at top level, only `static' makes a static definition. */ 6894: else 6895: { 1.1.1.6 ! root 6896: TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits); 1.1.1.4 root 6897: TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); 1.1 root 6898: } 6899: return decl; 6900: } 6901: 1.1.1.6 ! root 6902: /* Create a canonical pointer to member function type. */ ! 6903: ! 6904: static tree ! 6905: build_ptrmemfunc_type (type) ! 6906: tree type; ! 6907: { ! 6908: tree fields[4]; ! 6909: tree t; ! 6910: tree u; ! 6911: ! 6912: /* If a canonical type already exists for this type, use it. We use ! 6913: this method instead of type_hash_canon, because it only does a ! 6914: simple equality check on the list of field members. */ ! 6915: ! 6916: if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type))) ! 6917: return t; ! 6918: ! 6919: u = make_lang_type (UNION_TYPE); ! 6920: fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type); ! 6921: fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, short_integer_type_node); ! 6922: finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node); ! 6923: TYPE_NAME (u) = NULL_TREE; ! 6924: ! 6925: t = make_lang_type (RECORD_TYPE); ! 6926: ! 6927: /* Let the front-end know this is a pointer to member function. */ ! 6928: TYPE_PTRMEMFUNC_FLAG(t) = 1; ! 6929: ! 6930: fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, short_integer_type_node); ! 6931: fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, short_integer_type_node); ! 6932: fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u); ! 6933: finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node); ! 6934: ! 6935: /* Zap out the name so that the back-end will give us the debugging ! 6936: information for this anonymous RECORD_TYPE. */ ! 6937: TYPE_NAME (t) = NULL_TREE; ! 6938: ! 6939: TYPE_SET_PTRMEMFUNC_TYPE (type, t); ! 6940: ! 6941: /* Seems to be wanted. */ ! 6942: CLASSTYPE_GOT_SEMICOLON (t) = 1; ! 6943: return t; ! 6944: } ! 6945: 1.1 root 6946: /* Given declspecs and a declarator, 6947: determine the name and type of the object declared 6948: and construct a ..._DECL node for it. 6949: (In one case we can return a ..._TYPE node instead. 6950: For invalid input we sometimes return 0.) 6951: 6952: DECLSPECS is a chain of tree_list nodes whose value fields 6953: are the storage classes and type specifiers. 6954: 6955: DECL_CONTEXT says which syntactic context this declaration is in: 6956: NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. 6957: FUNCDEF for a function definition. Like NORMAL but a few different 6958: error messages in each case. Return value may be zero meaning 6959: this definition is too screwy to try to parse. 6960: MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to 6961: handle member functions (which have FIELD context). 6962: Return value may be zero meaning this definition is too screwy to 6963: try to parse. 6964: PARM for a parameter declaration (either within a function prototype 6965: or before a function body). Make a PARM_DECL, or return void_type_node. 6966: TYPENAME if for a typename (in a cast or sizeof). 6967: Don't make a DECL node; just return the ..._TYPE node. 6968: FIELD for a struct or union field; make a FIELD_DECL. 6969: BITFIELD for a field with specified width. 6970: INITIALIZED is 1 if the decl has an initializer. 6971: 6972: In the TYPENAME case, DECLARATOR is really an absolute declarator. 6973: It may also be so in the PARM case, for a prototype where the 6974: argument type is specified but not the name. 6975: 6976: This function is where the complicated C meanings of `static' 1.1.1.2 root 6977: and `extern' are interpreted. 1.1 root 6978: 6979: For C++, if there is any monkey business to do, the function which 6980: calls this one must do it, i.e., prepending instance variables, 6981: renaming overloaded function names, etc. 6982: 6983: Note that for this C++, it is an error to define a method within a class 6984: which does not belong to that class. 6985: 1.1.1.2 root 6986: Except in the case where SCOPE_REFs are implicitly known (such as 1.1 root 6987: methods within a class being redundantly qualified), 6988: declarations which involve SCOPE_REFs are returned as SCOPE_REFs 6989: (class_name::decl_name). The caller must also deal with this. 6990: 6991: If a constructor or destructor is seen, and the context is FIELD, 1.1.1.2 root 6992: then the type gains the attribute TREE_HAS_x. If such a declaration 1.1 root 6993: is erroneous, NULL_TREE is returned. 6994: 6995: QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member 6996: function, these are the qualifiers to give to the `this' pointer. 6997: 6998: May return void_type_node if the declarator turned out to be a friend. 6999: See grokfield for details. */ 7000: 1.1.1.5 root 7001: enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; 1.1 root 7002: 7003: tree 7004: grokdeclarator (declarator, declspecs, decl_context, initialized, raises) 7005: tree declspecs; 7006: tree declarator; 7007: enum decl_context decl_context; 7008: int initialized; 7009: tree raises; 7010: { 1.1.1.6 ! root 7011: RID_BIT_TYPE specbits; 1.1 root 7012: int nclasses = 0; 7013: tree spec; 7014: tree type = NULL_TREE; 7015: int longlong = 0; 7016: int constp; 7017: int volatilep; 7018: int virtualp, friendp, inlinep, staticp; 7019: int explicit_int = 0; 7020: int explicit_char = 0; 1.1.1.5 root 7021: tree typedef_decl = NULL_TREE; 1.1 root 7022: char *name; 1.1.1.5 root 7023: tree typedef_type = NULL_TREE; 1.1 root 7024: int funcdef_flag = 0; 7025: enum tree_code innermost_code = ERROR_MARK; 7026: int bitfield = 0; 1.1.1.4 root 7027: int size_varies = 0; 1.1 root 7028: /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. 7029: All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ 1.1.1.5 root 7030: tree init = NULL_TREE; 1.1 root 7031: 7032: /* Keep track of what sort of function is being processed 7033: so that we can warn about default return values, or explicit 7034: return values which do not match prescribed defaults. */ 7035: enum return_types return_type = return_normal; 7036: 7037: tree dname = NULL_TREE; 7038: tree ctype = current_class_type; 7039: tree ctor_return_type = NULL_TREE; 7040: enum overload_flags flags = NO_SPECIAL; 7041: int seen_scope_ref = 0; 1.1.1.5 root 7042: tree quals = NULL_TREE; 1.1 root 7043: 1.1.1.6 ! root 7044: RIDBIT_RESET_ALL (specbits); 1.1 root 7045: if (decl_context == FUNCDEF) 7046: funcdef_flag = 1, decl_context = NORMAL; 7047: else if (decl_context == MEMFUNCDEF) 7048: funcdef_flag = -1, decl_context = FIELD; 7049: else if (decl_context == BITFIELD) 7050: bitfield = 1, decl_context = FIELD; 7051: 7052: if (flag_traditional && allocation_temporary_p ()) 7053: end_temporary_allocation (); 7054: 7055: /* Look inside a declarator for the name being declared 7056: and get it as a string, for an error message. */ 7057: { 1.1.1.5 root 7058: tree type, last = NULL_TREE; 1.1 root 7059: register tree decl = declarator; 1.1.1.5 root 7060: name = NULL; 1.1 root 7061: 7062: /* If we see something of the form `aggr_type xyzzy (a, b, c)' 7063: it is either an old-style function declaration or a call to 7064: a constructor. The following conditional makes recognizes this 7065: case as being a call to a constructor. Too bad if it is not. */ 7066: 7067: /* For Doug Lea, also grok `aggr_type xyzzy (a, b, c)[10][10][10]'. */ 7068: while (decl && TREE_CODE (decl) == ARRAY_REF) 7069: { 7070: last = decl; 7071: decl = TREE_OPERAND (decl, 0); 7072: } 7073: 7074: if (decl && declspecs 7075: && TREE_CODE (decl) == CALL_EXPR 7076: && TREE_OPERAND (decl, 0) 7077: && (TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE 7078: || TREE_CODE (TREE_OPERAND (decl, 0)) == SCOPE_REF)) 7079: { 7080: type = TREE_CODE (TREE_VALUE (declspecs)) == IDENTIFIER_NODE 7081: ? lookup_name (TREE_VALUE (declspecs), 1) : 7082: (IS_AGGR_TYPE (TREE_VALUE (declspecs)) 7083: ? TYPE_NAME (TREE_VALUE (declspecs)) : NULL_TREE); 7084: 1.1.1.6 ! root 7085: /* We used to restrict this to just aggregate types for ! 7086: function-call notation for initialization. But since it ! 7087: can be done for more than aggregates (e.g., `int a(b);'), ! 7088: it's no longer restrained. */ ! 7089: if (type ! 7090: && TREE_CODE (type) == TYPE_DECL 1.1 root 7091: && parmlist_is_exprlist (TREE_OPERAND (decl, 1))) 7092: { 7093: if (decl_context == FIELD 7094: && TREE_CHAIN (TREE_OPERAND (decl, 1))) 7095: { 7096: /* That was an initializer list. */ 7097: sorry ("initializer lists for field declarations"); 7098: decl = TREE_OPERAND (decl, 0); 7099: if (last) 7100: { 7101: TREE_OPERAND (last, 0) = decl; 7102: decl = declarator; 7103: } 7104: declarator = decl; 7105: init = error_mark_node; 7106: goto bot; 7107: } 7108: else 7109: { 7110: init = TREE_OPERAND (decl, 1); 7111: if (last) 7112: { 7113: TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0); 7114: if (pedantic && init) 1.1.1.3 root 7115: { 1.1 root 7116: error ("arrays cannot take initializers"); 1.1.1.3 root 7117: init = error_mark_node; 7118: } 1.1 root 7119: } 7120: else 7121: declarator = TREE_OPERAND (declarator, 0); 1.1.1.6 ! root 7122: ! 7123: /* When dealing with scalar initializations we have to get ! 7124: rid of the surrounding TREE_LIST around the initializer. */ ! 7125: if (! IS_AGGR_TYPE (TREE_TYPE (type))) ! 7126: init = TREE_VALUE (init); ! 7127: 1.1 root 7128: decl = start_decl (declarator, declspecs, 1, NULL_TREE); 7129: finish_decl (decl, init, NULL_TREE, 1); 7130: return 0; 7131: } 7132: } 7133: 7134: if (parmlist_is_random (TREE_OPERAND (decl, 1))) 7135: { 7136: decl = TREE_OPERAND (decl, 0); 7137: if (TREE_CODE (decl) == SCOPE_REF) 7138: { 7139: if (TREE_COMPLEXITY (decl)) 1.1.1.3 root 7140: my_friendly_abort (15); 1.1 root 7141: decl = TREE_OPERAND (decl, 1); 7142: } 7143: if (TREE_CODE (decl) == IDENTIFIER_NODE) 7144: name = IDENTIFIER_POINTER (decl); 7145: if (name) 7146: error ("bad parameter list specification for function `%s'", 7147: name); 7148: else 7149: error ("bad parameter list specification for function"); 1.1.1.4 root 7150: return void_type_node; 1.1 root 7151: } 7152: bot: 7153: ; 7154: } 7155: else 7156: /* It didn't look like we thought it would, leave the ARRAY_REFs on. */ 7157: decl = declarator; 7158: 7159: while (decl) 7160: switch (TREE_CODE (decl)) 7161: { 7162: case COND_EXPR: 7163: ctype = NULL_TREE; 7164: decl = TREE_OPERAND (decl, 0); 7165: break; 7166: 7167: case BIT_NOT_EXPR: /* for C++ destructors! */ 7168: { 7169: tree name = TREE_OPERAND (decl, 0); 7170: tree rename = NULL_TREE; 7171: 1.1.1.4 root 7172: my_friendly_assert (flags == NO_SPECIAL, 152); 1.1 root 7173: flags = DTOR_FLAG; 7174: return_type = return_dtor; 1.1.1.4 root 7175: my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); 1.1 root 7176: if (ctype == NULL_TREE) 7177: { 7178: if (current_class_type == NULL_TREE) 7179: { 7180: error ("destructors must be member functions"); 7181: flags = NO_SPECIAL; 7182: } 7183: else 7184: { 7185: tree t = constructor_name (current_class_name); 7186: if (t != name) 7187: rename = t; 7188: } 7189: } 7190: else 7191: { 7192: tree t = constructor_name (ctype); 7193: if (t != name) 7194: rename = t; 7195: } 7196: 7197: if (rename) 7198: { 7199: error ("destructor `%s' must match class name `%s'", 7200: IDENTIFIER_POINTER (name), 7201: IDENTIFIER_POINTER (rename)); 7202: TREE_OPERAND (decl, 0) = rename; 7203: } 7204: decl = name; 7205: } 7206: break; 7207: 7208: case ADDR_EXPR: /* C++ reference declaration */ 7209: /* fall through */ 7210: case ARRAY_REF: 7211: case INDIRECT_REF: 7212: ctype = NULL_TREE; 7213: innermost_code = TREE_CODE (decl); 7214: decl = TREE_OPERAND (decl, 0); 7215: break; 7216: 7217: case CALL_EXPR: 7218: innermost_code = TREE_CODE (decl); 7219: decl = TREE_OPERAND (decl, 0); 7220: if (decl_context == FIELD && ctype == NULL_TREE) 7221: ctype = current_class_type; 7222: if (ctype != NULL_TREE 7223: && decl != NULL_TREE && flags != DTOR_FLAG 7224: && decl == constructor_name (ctype)) 7225: { 7226: return_type = return_ctor; 7227: ctor_return_type = ctype; 7228: } 7229: ctype = NULL_TREE; 7230: break; 7231: 7232: case IDENTIFIER_NODE: 7233: dname = decl; 7234: name = IDENTIFIER_POINTER (decl); 1.1.1.5 root 7235: decl = NULL_TREE; 1.1 root 7236: break; 7237: 7238: case RECORD_TYPE: 7239: case UNION_TYPE: 7240: case ENUMERAL_TYPE: 7241: /* Parse error puts this typespec where 7242: a declarator should go. */ 7243: error ("declarator name missing"); 7244: dname = TYPE_NAME (decl); 7245: if (dname && TREE_CODE (dname) == TYPE_DECL) 7246: dname = DECL_NAME (dname); 7247: name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>"; 7248: declspecs = temp_tree_cons (NULL_TREE, decl, declspecs); 1.1.1.5 root 7249: decl = NULL_TREE; 1.1 root 7250: break; 7251: 1.1.1.6 ! root 7252: case TYPE_EXPR: 1.1.1.4 root 7253: my_friendly_assert (flags == NO_SPECIAL, 154); 1.1 root 7254: flags = TYPENAME_FLAG; 1.1.1.6 ! root 7255: name = "operator <typename>"; /* We don't know the type yet. */ 1.1 root 7256: /* Go to the absdcl. */ 7257: decl = TREE_OPERAND (decl, 0); 7258: return_type = return_conversion; 7259: break; 7260: 7261: /* C++ extension */ 7262: case SCOPE_REF: 7263: if (seen_scope_ref == 1) 7264: error ("multiple `::' terms in declarator invalid"); 7265: seen_scope_ref += 1; 7266: { 7267: /* Perform error checking, and convert class names to types. 7268: We may call grokdeclarator multiple times for the same 7269: tree structure, so only do the conversion once. In this 7270: case, we have exactly what we want for `ctype'. */ 7271: tree cname = TREE_OPERAND (decl, 0); 7272: if (cname == NULL_TREE) 7273: ctype = NULL_TREE; 7274: /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */ 7275: else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname)) 7276: || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE) 7277: ctype = cname; 7278: else if (! is_aggr_typedef (cname, 1)) 7279: { 1.1.1.5 root 7280: TREE_OPERAND (decl, 0) = NULL_TREE; 1.1 root 7281: } 7282: /* Must test TREE_OPERAND (decl, 1), in case user gives 7283: us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ 7284: else if (TREE_OPERAND (decl, 1) 7285: && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) 7286: { 7287: TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname); 7288: } 7289: else if (ctype == NULL_TREE) 7290: { 7291: ctype = IDENTIFIER_TYPE_VALUE (cname); 7292: TREE_OPERAND (decl, 0) = ctype; 7293: } 7294: else if (TREE_COMPLEXITY (decl) == current_class_depth) 7295: TREE_OPERAND (decl, 0) = ctype; 7296: else 7297: { 1.1.1.4 root 7298: if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname), ctype)) 1.1 root 7299: { 7300: error ("type `%s' is not derived from type `%s'", 7301: IDENTIFIER_POINTER (cname), 7302: TYPE_NAME_STRING (ctype)); 1.1.1.5 root 7303: TREE_OPERAND (decl, 0) = NULL_TREE; 1.1 root 7304: } 7305: else 7306: { 7307: ctype = IDENTIFIER_TYPE_VALUE (cname); 7308: TREE_OPERAND (decl, 0) = ctype; 7309: } 7310: } 7311: 7312: decl = TREE_OPERAND (decl, 1); 7313: if (ctype) 7314: { 7315: if (TREE_CODE (decl) == IDENTIFIER_NODE 7316: && constructor_name (ctype) == decl) 7317: { 7318: return_type = return_ctor; 7319: ctor_return_type = ctype; 7320: } 7321: else if (TREE_CODE (decl) == BIT_NOT_EXPR 7322: && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE 7323: && constructor_name (ctype) == TREE_OPERAND (decl, 0)) 7324: { 7325: return_type = return_dtor; 7326: ctor_return_type = ctype; 7327: flags = DTOR_FLAG; 7328: decl = TREE_OPERAND (decl, 0); 7329: } 7330: } 7331: } 7332: break; 7333: 7334: case ERROR_MARK: 7335: decl = NULL_TREE; 7336: break; 7337: 7338: default: 1.1.1.6 ! root 7339: return 0; /* We used to do a 155 abort here. */ 1.1 root 7340: } 1.1.1.5 root 7341: if (name == NULL) 1.1 root 7342: name = "type name"; 7343: } 7344: 7345: /* A function definition's declarator must have the form of 7346: a function declarator. */ 7347: 7348: if (funcdef_flag && innermost_code != CALL_EXPR) 7349: return 0; 7350: 7351: /* Anything declared one level down from the top level 7352: must be one of the parameters of a function 7353: (because the body is at least two levels down). */ 7354: 7355: /* This heuristic cannot be applied to C++ nodes! Fixed, however, 7356: by not allowing C++ class definitions to specify their parameters 7357: with xdecls (must be spec.d in the parmlist). 7358: 7359: Since we now wait to push a class scope until we are sure that 7360: we are in a legitimate method context, we must set oldcname 7361: explicitly (since current_class_name is not yet alive). */ 7362: 7363: if (decl_context == NORMAL 7364: && current_binding_level->level_chain == global_binding_level) 7365: decl_context = PARM; 7366: 7367: /* Look through the decl specs and record which ones appear. 7368: Some typespecs are defined as built-in typenames. 7369: Others, the ones that are modifiers of other types, 7370: are represented by bits in SPECBITS: set the bits for 7371: the modifiers that appear. Storage class keywords are also in SPECBITS. 7372: 7373: If there is a typedef name or a type, store the type in TYPE. 7374: This includes builtin typedefs such as `int'. 7375: 7376: Set EXPLICIT_INT if the type is `int' or `char' and did not 7377: come from a user typedef. 7378: 7379: Set LONGLONG if `long' is mentioned twice. 7380: 7381: For C++, constructors and destructors have their own fast treatment. */ 7382: 7383: for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) 7384: { 7385: register int i; 7386: register tree id = TREE_VALUE (spec); 7387: 7388: /* Certain parse errors slip through. For example, 7389: `int class;' is not caught by the parser. Try 7390: weakly to recover here. */ 7391: if (TREE_CODE (spec) != TREE_LIST) 7392: return 0; 7393: 7394: if (TREE_CODE (id) == IDENTIFIER_NODE) 7395: { 7396: if (id == ridpointers[(int) RID_INT]) 7397: { 7398: if (type) 7399: error ("extraneous `int' ignored"); 7400: else 7401: { 7402: explicit_int = 1; 7403: type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); 7404: } 7405: goto found; 7406: } 7407: if (id == ridpointers[(int) RID_CHAR]) 7408: { 7409: if (type) 7410: error ("extraneous `char' ignored"); 7411: else 7412: { 7413: explicit_char = 1; 7414: type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); 7415: } 7416: goto found; 7417: } 1.1.1.4 root 7418: if (id == ridpointers[(int) RID_WCHAR]) 7419: { 7420: if (type) 7421: error ("extraneous `__wchar_t' ignored"); 7422: else 7423: { 7424: type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); 7425: } 7426: goto found; 7427: } 1.1 root 7428: /* C++ aggregate types. */ 7429: if (IDENTIFIER_HAS_TYPE_VALUE (id)) 7430: { 7431: if (type) 7432: error ("multiple declarations `%s' and `%s'", 7433: IDENTIFIER_POINTER (type), 7434: IDENTIFIER_POINTER (id)); 7435: else 7436: type = IDENTIFIER_TYPE_VALUE (id); 7437: goto found; 7438: } 7439: 7440: for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++) 7441: { 7442: if (ridpointers[i] == id) 7443: { 1.1.1.6 ! root 7444: if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) 1.1 root 7445: { 1.1.1.6 ! root 7446: #if 0 1.1 root 7447: if (pedantic) 1.1.1.3 root 7448: pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); 1.1.1.6 ! root 7449: else ! 7450: #endif ! 7451: if (longlong) 1.1.1.4 root 7452: error ("`long long long' is too long for GCC"); 1.1 root 7453: else 7454: longlong = 1; 7455: } 1.1.1.6 ! root 7456: else if (RIDBIT_SETP (i, specbits)) 1.1 root 7457: warning ("duplicate `%s'", IDENTIFIER_POINTER (id)); 1.1.1.6 ! root 7458: RIDBIT_SET (i, specbits); 1.1 root 7459: goto found; 7460: } 7461: } 7462: } 7463: if (type) 7464: error ("two or more data types in declaration of `%s'", name); 7465: else if (TREE_CODE (id) == IDENTIFIER_NODE) 7466: { 7467: register tree t = lookup_name (id, 1); 7468: if (!t || TREE_CODE (t) != TYPE_DECL) 7469: error ("`%s' fails to be a typedef or built in type", 7470: IDENTIFIER_POINTER (id)); 7471: else 7472: { 7473: type = TREE_TYPE (t); 7474: typedef_decl = t; 7475: } 7476: } 7477: else if (TREE_CODE (id) != ERROR_MARK) 7478: /* Can't change CLASS nodes into RECORD nodes here! */ 7479: type = id; 7480: 7481: found: {} 7482: } 7483: 7484: typedef_type = type; 7485: 7486: /* No type at all: default to `int', and set EXPLICIT_INT 7487: because it was not a user-defined typedef. */ 7488: 1.1.1.5 root 7489: if (type == NULL_TREE) 1.1 root 7490: { 7491: explicit_int = -1; 7492: if (return_type == return_dtor) 7493: type = void_type_node; 7494: else if (return_type == return_ctor) 7495: type = TYPE_POINTER_TO (ctor_return_type); 7496: else 7497: { 7498: if (funcdef_flag && explicit_warn_return_type 7499: && return_type == return_normal 1.1.1.6 ! root 7500: && ! (RIDBIT_SETP (RID_SIGNED, specbits) ! 7501: || RIDBIT_SETP (RID_UNSIGNED, specbits) ! 7502: || RIDBIT_SETP (RID_LONG, specbits) ! 7503: || RIDBIT_SETP (RID_SHORT, specbits))) 1.1 root 7504: warn_about_return_type = 1; 7505: /* Save warning until we know what is really going on. */ 7506: type = integer_type_node; 7507: } 7508: } 7509: else if (return_type == return_dtor) 7510: { 7511: error ("return type specification for destructor invalid"); 7512: type = void_type_node; 7513: } 7514: else if (return_type == return_ctor) 7515: { 7516: error ("return type specification for constructor invalid"); 7517: type = TYPE_POINTER_TO (ctor_return_type); 7518: } 1.1.1.6 ! root 7519: else if (RIDBIT_SETP (RID_FRIEND, specbits) 1.1 root 7520: && IS_AGGR_TYPE (type) 7521: && ! TYPE_BEING_DEFINED (type) 7522: && TYPE_SIZE (type) == NULL_TREE 7523: && ! ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)) 1.1.1.4 root 7524: && current_function_decl == NULL_TREE 7525: && decl_context != PARM) 1.1 root 7526: { 7527: /* xref_tag will make friend class declarations look like 7528: nested class declarations. Retroactively change that 7529: if the type has not yet been defined. 7530: 7531: ??? ANSI C++ doesn't say what to do in this case yet. */ 7532: globalize_nested_type (type); 7533: } 7534: 7535: ctype = NULL_TREE; 7536: 7537: /* Now process the modifiers that were specified 7538: and check for invalid combinations. */ 7539: 7540: /* Long double is a special combination. */ 7541: 1.1.1.6 ! root 7542: if (RIDBIT_SETP (RID_LONG, specbits) 1.1.1.4 root 7543: && TYPE_MAIN_VARIANT (type) == double_type_node) 1.1 root 7544: { 1.1.1.6 ! root 7545: RIDBIT_RESET (RID_LONG, specbits); 1.1.1.4 root 7546: type = build_type_variant (long_double_type_node, TYPE_READONLY (type), 7547: TYPE_VOLATILE (type)); 1.1 root 7548: } 7549: 7550: /* Check all other uses of type modifiers. */ 7551: 1.1.1.6 ! root 7552: if (RIDBIT_SETP (RID_UNSIGNED, specbits) ! 7553: || RIDBIT_SETP (RID_SIGNED, specbits) ! 7554: || RIDBIT_SETP (RID_LONG, specbits) ! 7555: || RIDBIT_SETP (RID_SHORT, specbits)) 1.1 root 7556: { 7557: int ok = 0; 7558: 7559: if (TREE_CODE (type) == REAL_TYPE) 7560: error ("short, signed or unsigned invalid for `%s'", name); 1.1.1.4 root 7561: else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node) 1.1 root 7562: error ("long, short, signed or unsigned invalid for `%s'", name); 1.1.1.6 ! root 7563: else if (RIDBIT_SETP (RID_LONG, specbits) ! 7564: && RIDBIT_SETP (RID_SHORT, specbits)) 1.1 root 7565: error ("long and short specified together for `%s'", name); 1.1.1.6 ! root 7566: else if ((RIDBIT_SETP (RID_LONG, specbits) ! 7567: || RIDBIT_SETP (RID_SHORT, specbits)) 1.1 root 7568: && explicit_char) 7569: error ("long or short specified with char for `%s'", name); 1.1.1.6 ! root 7570: else if ((RIDBIT_SETP (RID_LONG, specbits) ! 7571: || RIDBIT_SETP (RID_SHORT, specbits)) 1.1 root 7572: && TREE_CODE (type) == REAL_TYPE) 7573: error ("long or short specified with floating type for `%s'", name); 1.1.1.6 ! root 7574: else if (RIDBIT_SETP (RID_SIGNED, specbits) ! 7575: && RIDBIT_SETP (RID_UNSIGNED, specbits)) 1.1 root 7576: error ("signed and unsigned given together for `%s'", name); 7577: else 7578: { 7579: ok = 1; 7580: if (!explicit_int && !explicit_char && pedantic) 7581: { 7582: pedwarn ("long, short, signed or unsigned used invalidly for `%s'", 7583: name); 7584: if (flag_pedantic_errors) 7585: ok = 0; 7586: } 7587: } 7588: 7589: /* Discard the type modifiers if they are invalid. */ 7590: if (! ok) 7591: { 1.1.1.6 ! root 7592: RIDBIT_RESET (RID_UNSIGNED, specbits); ! 7593: RIDBIT_RESET (RID_SIGNED, specbits); ! 7594: RIDBIT_RESET (RID_LONG, specbits); ! 7595: RIDBIT_RESET (RID_SHORT, specbits); 1.1 root 7596: longlong = 0; 7597: } 7598: } 7599: 7600: /* Decide whether an integer type is signed or not. 7601: Optionally treat bitfields as signed by default. */ 1.1.1.6 ! root 7602: if (RIDBIT_SETP (RID_UNSIGNED, specbits) 1.1 root 7603: /* Traditionally, all bitfields are unsigned. */ 7604: || (bitfield && flag_traditional) 7605: || (bitfield && ! flag_signed_bitfields 7606: && (explicit_int || explicit_char 7607: /* A typedef for plain `int' without `signed' 7608: can be controlled just like plain `int'. */ 1.1.1.5 root 7609: || ! (typedef_decl != NULL_TREE 1.1 root 7610: && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) 7611: && TREE_CODE (type) != ENUMERAL_TYPE 1.1.1.6 ! root 7612: && RIDBIT_NOTSETP (RID_SIGNED, specbits))) 1.1 root 7613: { 7614: if (longlong) 7615: type = long_long_unsigned_type_node; 1.1.1.6 ! root 7616: else if (RIDBIT_SETP (RID_LONG, specbits)) 1.1 root 7617: type = long_unsigned_type_node; 1.1.1.6 ! root 7618: else if (RIDBIT_SETP (RID_SHORT, specbits)) 1.1 root 7619: type = short_unsigned_type_node; 7620: else if (type == char_type_node) 7621: type = unsigned_char_type_node; 7622: else if (typedef_decl) 7623: type = unsigned_type (type); 7624: else 7625: type = unsigned_type_node; 7626: } 1.1.1.6 ! root 7627: else if (RIDBIT_SETP (RID_SIGNED, specbits) 1.1 root 7628: && type == char_type_node) 7629: type = signed_char_type_node; 7630: else if (longlong) 7631: type = long_long_integer_type_node; 1.1.1.6 ! root 7632: else if (RIDBIT_SETP (RID_LONG, specbits)) 1.1 root 7633: type = long_integer_type_node; 1.1.1.6 ! root 7634: else if (RIDBIT_SETP (RID_SHORT, specbits)) 1.1 root 7635: type = short_integer_type_node; 7636: 7637: /* Set CONSTP if this declaration is `const', whether by 7638: explicit specification or via a typedef. 7639: Likewise for VOLATILEP. */ 7640: 1.1.1.6 ! root 7641: constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type); ! 7642: volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type); 1.1 root 7643: staticp = 0; 1.1.1.6 ! root 7644: inlinep = !! RIDBIT_SETP (RID_INLINE, specbits); 1.1 root 7645: if (constp > 1) 7646: warning ("duplicate `const'"); 7647: if (volatilep > 1) 7648: warning ("duplicate `volatile'"); 1.1.1.6 ! root 7649: virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); ! 7650: if (RIDBIT_SETP (RID_STATIC, specbits)) 1.1 root 7651: staticp = 1 + (decl_context == FIELD); 7652: 7653: if (virtualp && staticp == 2) 7654: { 7655: error ("member `%s' cannot be declared both virtual and static", name); 7656: staticp = 0; 7657: } 1.1.1.6 ! root 7658: friendp = RIDBIT_SETP (RID_FRIEND, specbits); ! 7659: RIDBIT_RESET (RID_VIRTUAL, specbits); ! 7660: RIDBIT_RESET (RID_FRIEND, specbits); ! 7661: ! 7662: if (RIDBIT_SETP (RID_MUTABLE, specbits)) ! 7663: { ! 7664: if (decl_context == PARM) ! 7665: { ! 7666: error ("non-member `%s' cannot be declared mutable", name); ! 7667: RIDBIT_RESET (RID_MUTABLE, specbits); ! 7668: } ! 7669: else if (friendp || decl_context == TYPENAME) ! 7670: { ! 7671: error ("non-object member `%s' cannot be declared mutable", name); ! 7672: RIDBIT_RESET (RID_MUTABLE, specbits); ! 7673: } ! 7674: else if (staticp) ! 7675: { ! 7676: error ("static `%s' cannot be declared mutable", name); ! 7677: RIDBIT_RESET (RID_MUTABLE, specbits); ! 7678: } ! 7679: #if 0 ! 7680: if (RIDBIT_SETP (RID_TYPEDEF, specbits)) ! 7681: { ! 7682: error ("non-object member `%s' cannot be declared mutable", name); ! 7683: RIDBIT_RESET (RID_MUTABLE, specbits); ! 7684: } ! 7685: /* Because local typedefs are parsed twice, we don't want this ! 7686: message here. */ ! 7687: else if (decl_context != FIELD) ! 7688: { ! 7689: error ("non-member `%s' cannot be declared mutable", name); ! 7690: RIDBIT_RESET (RID_MUTABLE, specbits); ! 7691: } ! 7692: #endif ! 7693: } 1.1 root 7694: 7695: /* Warn if two storage classes are given. Default to `auto'. */ 7696: 1.1.1.6 ! root 7697: if (RIDBIT_ANY_SET (specbits)) 1.1 root 7698: { 1.1.1.6 ! root 7699: if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++; ! 7700: if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++; 1.1 root 7701: if (decl_context == PARM && nclasses > 0) 7702: error ("storage class specifiers invalid in parameter declarations"); 1.1.1.6 ! root 7703: if (RIDBIT_SETP (RID_TYPEDEF, specbits)) 1.1 root 7704: { 7705: if (decl_context == PARM) 7706: error ("typedef declaration invalid in parameter declaration"); 7707: nclasses++; 7708: } 1.1.1.6 ! root 7709: if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++; ! 7710: if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++; 1.1 root 7711: } 7712: 7713: /* Give error if `virtual' is used outside of class declaration. */ 7714: if (virtualp && current_class_name == NULL_TREE) 7715: { 7716: error ("virtual outside class declaration"); 7717: virtualp = 0; 7718: } 1.1.1.6 ! root 7719: if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits)) ! 7720: { ! 7721: error ("only members can be declared mutable"); ! 7722: RIDBIT_RESET (RID_MUTABLE, specbits); ! 7723: } ! 7724: ! 7725: /* Static anonymous unions are dealt with here. */ ! 7726: if (staticp && decl_context == TYPENAME ! 7727: && TREE_CODE (declspecs) == TREE_LIST ! 7728: && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE ! 7729: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs)))) ! 7730: decl_context = FIELD; 1.1 root 7731: 7732: /* Warn about storage classes that are invalid for certain 7733: kinds of declarations (parameters, typenames, etc.). */ 7734: 7735: if (nclasses > 1) 7736: error ("multiple storage classes in declaration of `%s'", name); 7737: else if (decl_context != NORMAL && nclasses > 0) 7738: { 7739: if (decl_context == PARM 1.1.1.6 ! root 7740: && (RIDBIT_SETP (RID_REGISTER, specbits) ! 7741: || RIDBIT_SETP (RID_AUTO, specbits))) 1.1 root 7742: ; 1.1.1.6 ! root 7743: else if (decl_context == FIELD ! 7744: && RIDBIT_SETP (RID_TYPEDEF, specbits)) ! 7745: { ! 7746: /* Processing a typedef declaration nested within a class type ! 7747: definition. */ ! 7748: register tree scanner; ! 7749: register tree previous_declspec; ! 7750: tree loc_typedecl; ! 7751: ! 7752: if (initialized) ! 7753: error ("typedef declaration includes an initializer"); ! 7754: ! 7755: /* To process a class-local typedef declaration, we descend down ! 7756: the chain of declspecs looking for the `typedef' spec. When we ! 7757: find it, we splice it out of the chain of declspecs, and then ! 7758: recursively call `grokdeclarator' with the original declarator ! 7759: and with the newly adjusted declspecs. This call should return ! 7760: a FIELD_DECL node with the TREE_TYPE (and other parts) set ! 7761: appropriately. We can then just change the TREE_CODE on that ! 7762: from FIELD_DECL to TYPE_DECL and we're done. */ ! 7763: ! 7764: for (previous_declspec = NULL_TREE, scanner = declspecs; ! 7765: scanner; ! 7766: previous_declspec = scanner, scanner = TREE_CHAIN (scanner)) ! 7767: { ! 7768: if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF]) ! 7769: break; ! 7770: } ! 7771: if (previous_declspec) ! 7772: TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner); ! 7773: else ! 7774: declspecs = TREE_CHAIN (scanner); ! 7775: ! 7776: loc_typedecl = ! 7777: grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE); ! 7778: ! 7779: if (loc_typedecl != error_mark_node) ! 7780: { ! 7781: register int i = sizeof (struct lang_decl_flags) / sizeof (int); ! 7782: register int *pi; ! 7783: ! 7784: TREE_SET_CODE (loc_typedecl, TYPE_DECL); ! 7785: ! 7786: pi = (int *) permalloc (sizeof (struct lang_decl_flags)); ! 7787: while (i > 0) ! 7788: pi[--i] = 0; ! 7789: DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi; 1.1 root 7790: } 1.1.1.6 ! root 7791: ! 7792: return loc_typedecl; 1.1 root 7793: } 1.1.1.3 root 7794: else if (decl_context == FIELD 1.1.1.4 root 7795: /* C++ allows static class elements */ 1.1.1.6 ! root 7796: && RIDBIT_SETP (RID_STATIC, specbits)) 1.1.1.4 root 7797: /* C++ also allows inlines and signed and unsigned elements, 7798: but in those cases we don't come in here. */ 1.1.1.3 root 7799: ; 1.1 root 7800: else 7801: { 1.1.1.4 root 7802: if (decl_context == FIELD) 7803: { 7804: tree tmp = TREE_OPERAND (declarator, 0); 7805: register int op = IDENTIFIER_OPNAME_P (tmp); 7806: error ("storage class specified for %s `%s'", 7807: op ? "member operator" : "structure field", 7808: op ? operator_name_string (tmp) : name); 7809: } 7810: else 7811: error ((decl_context == PARM 7812: ? "storage class specified for parameter `%s'" 7813: : "storage class specified for typename"), name); 1.1.1.6 ! root 7814: RIDBIT_RESET (RID_REGISTER, specbits); ! 7815: RIDBIT_RESET (RID_AUTO, specbits); ! 7816: RIDBIT_RESET (RID_EXTERN, specbits); 1.1 root 7817: } 7818: } 1.1.1.6 ! root 7819: else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag) 1.1 root 7820: { 1.1.1.4 root 7821: if (current_binding_level == global_binding_level) 1.1.1.5 root 7822: { 7823: /* It's common practice (and completely legal) to have a const 7824: be initialized and declared extern. */ 7825: if (! constp) 7826: warning ("`%s' initialized and declared `extern'", name); 7827: } 1.1.1.4 root 7828: else 7829: error ("`%s' has both `extern' and initializer", name); 1.1 root 7830: } 1.1.1.6 ! root 7831: else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag 1.1 root 7832: && current_binding_level != global_binding_level) 7833: error ("nested function `%s' declared `extern'", name); 7834: else if (current_binding_level == global_binding_level) 7835: { 1.1.1.6 ! root 7836: if (RIDBIT_SETP (RID_AUTO, specbits)) 1.1 root 7837: error ("top-level declaration of `%s' specifies `auto'", name); 7838: #if 0 1.1.1.6 ! root 7839: if (RIDBIT_SETP (RID_REGISTER, specbits)) 1.1 root 7840: error ("top-level declaration of `%s' specifies `register'", name); 7841: #endif 7842: #if 0 7843: /* I'm not sure under what circumstances we should turn 7844: on the extern bit, and under what circumstances we should 7845: warn if other bits are turned on. */ 7846: if (decl_context == NORMAL 1.1.1.6 ! root 7847: && RIDBIT_NOSETP (RID_EXTERN, specbits) 1.1 root 7848: && ! root_lang_context_p ()) 7849: { 1.1.1.6 ! root 7850: RIDBIT_SET (RID_EXTERN, specbits); 1.1 root 7851: } 7852: #endif 7853: } 7854: 7855: /* Now figure out the structure of the declarator proper. 7856: Descend through it, creating more complex types, until we reach 7857: the declared identifier (or NULL_TREE, in an absolute declarator). */ 7858: 7859: while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) 7860: { 7861: /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), 7862: an INDIRECT_REF (for *...), 7863: a CALL_EXPR (for ...(...)), 7864: an identifier (for the name being declared) 7865: or a null pointer (for the place in an absolute declarator 7866: where the name was omitted). 7867: For the last two cases, we have just exited the loop. 7868: 7869: For C++ it could also be 7870: a SCOPE_REF (for class :: ...). In this case, we have converted 7871: sensible names to types, and those are the values we use to 7872: qualify the member name. 7873: an ADDR_EXPR (for &...), 7874: a BIT_NOT_EXPR (for destructors) 7875: a TYPE_EXPR (for operator typenames) 7876: 7877: At this point, TYPE is the type of elements of an array, 7878: or for a function to return, or for a pointer to point to. 7879: After this sequence of ifs, TYPE is the type of the 7880: array or function or pointer, and DECLARATOR has had its 7881: outermost layer removed. */ 7882: 7883: if (TREE_CODE (type) == ERROR_MARK) 7884: { 7885: if (TREE_CODE (declarator) == SCOPE_REF) 7886: declarator = TREE_OPERAND (declarator, 1); 7887: else 7888: declarator = TREE_OPERAND (declarator, 0); 7889: continue; 7890: } 7891: if (quals != NULL_TREE 7892: && (declarator == NULL_TREE 7893: || TREE_CODE (declarator) != SCOPE_REF)) 7894: { 7895: if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE) 7896: ctype = TYPE_METHOD_BASETYPE (type); 7897: if (ctype != NULL_TREE) 7898: { 1.1.1.2 root 7899: #if 0 /* not yet, should get fixed properly later */ 7900: tree dummy = make_type_decl (NULL_TREE, type); 7901: #else 1.1 root 7902: tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); 1.1.1.2 root 7903: #endif 1.1 root 7904: ctype = grok_method_quals (ctype, dummy, quals); 7905: type = TREE_TYPE (dummy); 7906: quals = NULL_TREE; 7907: } 7908: } 7909: switch (TREE_CODE (declarator)) 7910: { 7911: case ARRAY_REF: 7912: maybe_globalize_type (type); 7913: { 7914: register tree itype = NULL_TREE; 7915: register tree size = TREE_OPERAND (declarator, 1); 7916: 7917: declarator = TREE_OPERAND (declarator, 0); 7918: 7919: /* Check for some types that there cannot be arrays of. */ 7920: 1.1.1.4 root 7921: if (TYPE_MAIN_VARIANT (type) == void_type_node) 1.1 root 7922: { 1.1.1.6 ! root 7923: cp_error ("declaration of `%D' as array of voids", dname); 1.1 root 7924: type = error_mark_node; 7925: } 7926: 7927: if (TREE_CODE (type) == FUNCTION_TYPE) 7928: { 1.1.1.6 ! root 7929: cp_error ("declaration of `%D' as array of functions", dname); 1.1 root 7930: type = error_mark_node; 7931: } 7932: 1.1.1.5 root 7933: /* ARM $8.4.3: Since you can't have a pointer to a reference, 7934: you can't have arrays of references. If we allowed them, 7935: then we'd be saying x[i] is legal for an array x, but 7936: then you'd have to ask: what does `*(x + i)' mean? */ 7937: if (TREE_CODE (type) == REFERENCE_TYPE) 1.1.1.6 ! root 7938: { ! 7939: cp_error ("declaration of `%D' as array of references", dname); ! 7940: type = error_mark_node; ! 7941: } ! 7942: ! 7943: if (TREE_CODE (type) == OFFSET_TYPE) ! 7944: { ! 7945: cp_error ("declaration of `%D' as array of data members", ! 7946: dname); ! 7947: type = error_mark_node; ! 7948: } ! 7949: ! 7950: if (TREE_CODE (type) == METHOD_TYPE) ! 7951: { ! 7952: cp_error ("declaration of `%D' as array of function members", ! 7953: dname); ! 7954: type = error_mark_node; ! 7955: } 1.1.1.5 root 7956: 1.1 root 7957: if (size == error_mark_node) 7958: type = error_mark_node; 7959: 7960: if (type == error_mark_node) 7961: continue; 7962: 7963: if (size) 7964: { 7965: /* Must suspend_momentary here because the index 7966: type may need to live until the end of the function. 7967: For example, it is used in the declaration of a 7968: variable which requires destructing at the end of 7969: the function; then build_vec_delete will need this 7970: value. */ 7971: int yes = suspend_momentary (); 7972: /* might be a cast */ 7973: if (TREE_CODE (size) == NOP_EXPR 7974: && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) 7975: size = TREE_OPERAND (size, 0); 7976: 7977: /* If this is a template parameter, it'll be constant, but 7978: we don't know what the value is yet. */ 7979: if (TREE_CODE (size) == TEMPLATE_CONST_PARM) 7980: goto dont_grok_size; 7981: 7982: if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE 7983: && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) 7984: { 1.1.1.6 ! root 7985: cp_error ("size of array `%D' has non-integer type", ! 7986: dname); 1.1 root 7987: size = integer_one_node; 7988: } 7989: if (TREE_READONLY_DECL_P (size)) 7990: size = decl_constant_value (size); 7991: if (pedantic && integer_zerop (size)) 1.1.1.6 ! root 7992: cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname); 1.1 root 7993: if (TREE_CONSTANT (size)) 7994: { 1.1.1.6 ! root 7995: constant_expression_warning (size); 1.1 root 7996: if (INT_CST_LT (size, integer_zero_node)) 7997: { 1.1.1.6 ! root 7998: cp_error ("size of array `%D' is negative", dname); 1.1 root 7999: size = integer_one_node; 8000: } 8001: itype = build_index_type (size_binop (MINUS_EXPR, size, 8002: integer_one_node)); 8003: } 8004: else 8005: { 8006: if (pedantic) 1.1.1.6 ! root 8007: cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", dname); 1.1 root 8008: dont_grok_size: 1.1.1.5 root 8009: itype = 8010: build_binary_op (MINUS_EXPR, size, integer_one_node, 1); 1.1.1.4 root 8011: /* Make sure the array size remains visibly nonconstant 8012: even if it is (eg) a const variable with known value. */ 8013: size_varies = 1; 8014: itype = variable_size (itype); 1.1 root 8015: itype = build_index_type (itype); 8016: } 8017: resume_momentary (yes); 8018: } 8019: 1.1.1.6 ! root 8020: /* Build the array type itself, then merge any constancy or ! 8021: volatility into the target type. We must do it in this order ! 8022: to ensure that the TYPE_MAIN_VARIANT field of the array type ! 8023: is set correctly. */ 1.1 root 8024: 1.1.1.6 ! root 8025: type = build_cplus_array_type (type, itype); 1.1 root 8026: if (constp || volatilep) 8027: type = build_type_variant (type, constp, volatilep); 8028: 8029: ctype = NULL_TREE; 8030: } 8031: break; 8032: 8033: case CALL_EXPR: 8034: maybe_globalize_type (type); 8035: { 8036: tree arg_types; 8037: 8038: /* Declaring a function type. 8039: Make sure we have a valid type for the function to return. */ 1.1.1.3 root 8040: #if 0 1.1 root 8041: /* Is this an error? Should they be merged into TYPE here? */ 8042: if (pedantic && (constp || volatilep)) 1.1.1.3 root 8043: pedwarn ("function declared to return const or volatile result"); 8044: #else 8045: /* Merge any constancy or volatility into the target type 8046: for the pointer. */ 8047: 8048: if (constp || volatilep) 8049: { 8050: type = build_type_variant (type, constp, volatilep); 8051: if (IS_AGGR_TYPE (type)) 8052: build_pointer_type (type); 8053: constp = 0; 8054: volatilep = 0; 8055: } 8056: #endif 1.1 root 8057: 8058: /* Warn about some types functions can't return. */ 8059: 8060: if (TREE_CODE (type) == FUNCTION_TYPE) 8061: { 8062: error ("`%s' declared as function returning a function", name); 8063: type = integer_type_node; 8064: } 8065: if (TREE_CODE (type) == ARRAY_TYPE) 8066: { 8067: error ("`%s' declared as function returning an array", name); 8068: type = integer_type_node; 8069: } 8070: 8071: if (ctype == NULL_TREE 8072: && decl_context == FIELD 8073: && (friendp == 0 || dname == current_class_name)) 8074: ctype = current_class_type; 8075: 8076: if (ctype && flags == TYPENAME_FLAG) 8077: TYPE_HAS_CONVERSION (ctype) = 1; 8078: if (ctype && constructor_name (ctype) == dname) 8079: { 8080: /* We are within a class's scope. If our declarator name 8081: is the same as the class name, and we are defining 8082: a function, then it is a constructor/destructor, and 8083: therefore returns a void type. */ 8084: 8085: if (flags == DTOR_FLAG) 8086: { 1.1.1.4 root 8087: /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may 8088: not be declared const or volatile. A destructor 8089: may not be static. */ 1.1 root 8090: if (staticp == 2) 8091: error ("destructor cannot be static member function"); 1.1.1.4 root 8092: if (TYPE_READONLY (type)) 1.1 root 8093: { 1.1.1.4 root 8094: error ("destructors cannot be declared `const'"); 8095: return void_type_node; 1.1 root 8096: } 1.1.1.4 root 8097: if (TYPE_VOLATILE (type)) 1.1 root 8098: { 1.1.1.4 root 8099: error ("destructors cannot be declared `volatile'"); 8100: return void_type_node; 1.1 root 8101: } 8102: if (decl_context == FIELD) 8103: { 8104: if (! member_function_or_else (ctype, current_class_type, 1.1.1.4 root 8105: "destructor for alien class `%s' cannot be a member")) 8106: return void_type_node; 1.1 root 8107: } 8108: } 1.1.1.4 root 8109: else /* it's a constructor. */ 1.1 root 8110: { 1.1.1.4 root 8111: /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may 8112: not be declared const or volatile. A constructor may 8113: not be virtual. A constructor may not be static. */ 1.1 root 8114: if (staticp == 2) 8115: error ("constructor cannot be static member function"); 1.1.1.3 root 8116: if (virtualp) 1.1 root 8117: { 1.1.1.3 root 8118: pedwarn ("constructors cannot be declared virtual"); 1.1 root 8119: virtualp = 0; 8120: } 1.1.1.4 root 8121: if (TYPE_READONLY (type)) 8122: { 8123: error ("constructors cannot be declared `const'"); 8124: return void_type_node; 8125: } 8126: if (TYPE_VOLATILE (type)) 8127: { 8128: error ("constructors cannot be declared `volatile'"); 8129: return void_type_node; 8130: } 1.1.1.6 ! root 8131: { ! 8132: int inlinep, staticp; ! 8133: inlinep = RIDBIT_SETP (RID_INLINE, specbits); ! 8134: staticp = RIDBIT_SETP (RID_STATIC, specbits); ! 8135: RIDBIT_RESET (RID_INLINE, specbits); ! 8136: RIDBIT_RESET (RID_STATIC, specbits); ! 8137: if (RIDBIT_ANY_SET (specbits)) ! 8138: error ("return value type specifier for constructor ignored"); ! 8139: if (inlinep) ! 8140: RIDBIT_SET (RID_INLINE, specbits); ! 8141: if (staticp) ! 8142: RIDBIT_SET (RID_STATIC, specbits); ! 8143: } 1.1 root 8144: type = TYPE_POINTER_TO (ctype); 8145: if (decl_context == FIELD) 8146: { 8147: if (! member_function_or_else (ctype, current_class_type, 8148: "constructor for alien class `%s' cannot be member")) 1.1.1.4 root 8149: return void_type_node; 1.1 root 8150: TYPE_HAS_CONSTRUCTOR (ctype) = 1; 1.1.1.5 root 8151: if (return_type != return_ctor) 8152: return NULL_TREE; 1.1 root 8153: } 8154: } 8155: if (decl_context == FIELD) 8156: staticp = 0; 8157: } 8158: else if (friendp && virtualp) 8159: { 8160: /* Cannot be both friend and virtual. */ 8161: error ("virtual functions cannot be friends"); 1.1.1.6 ! root 8162: RIDBIT_RESET (RID_FRIEND, specbits); 1.1 root 8163: } 8164: 8165: if (decl_context == NORMAL && friendp) 8166: error ("friend declaration not in class definition"); 8167: 8168: /* Pick up type qualifiers which should be applied to `this'. */ 8169: quals = TREE_OPERAND (declarator, 2); 8170: 8171: /* Traditionally, declaring return type float means double. */ 8172: 1.1.1.4 root 8173: if (flag_traditional 8174: && TYPE_MAIN_VARIANT (type) == float_type_node) 8175: { 8176: type = build_type_variant (double_type_node, 8177: TYPE_READONLY (type), 8178: TYPE_VOLATILE (type)); 8179: } 1.1 root 8180: 8181: /* Construct the function type and go to the next 8182: inner layer of declarator. */ 8183: 8184: { 8185: int funcdef_p; 8186: tree inner_parms = TREE_OPERAND (declarator, 1); 8187: tree inner_decl = TREE_OPERAND (declarator, 0); 8188: 8189: declarator = TREE_OPERAND (declarator, 0); 8190: 8191: if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) 8192: inner_decl = TREE_OPERAND (inner_decl, 1); 8193: 8194: /* Say it's a definition only for the CALL_EXPR 8195: closest to the identifier. */ 8196: funcdef_p = 8197: (inner_decl && 8198: (TREE_CODE (inner_decl) == IDENTIFIER_NODE 8199: || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0; 8200: 1.1.1.6 ! root 8201: /* FIXME: This is where default args should be fully processed. */ ! 8202: 1.1 root 8203: arg_types = grokparms (inner_parms, funcdef_p); 8204: } 8205: 8206: if (declarator) 8207: { 1.1.1.4 root 8208: /* Get past destructors, etc. 1.1 root 8209: We know we have one because FLAGS will be non-zero. 8210: 8211: Complain about improper parameter lists here. */ 8212: if (TREE_CODE (declarator) == BIT_NOT_EXPR) 8213: { 8214: declarator = TREE_OPERAND (declarator, 0); 8215: 8216: if (strict_prototype == 0 && arg_types == NULL_TREE) 8217: arg_types = void_list_node; 8218: else if (arg_types == NULL_TREE 8219: || arg_types != void_list_node) 8220: { 8221: error ("destructors cannot be specified with parameters"); 8222: arg_types = void_list_node; 8223: } 8224: } 8225: } 1.1.1.3 root 8226: /* the top level const or volatile is attached semantically only 8227: to the function not the actual type. */ 8228: if (TYPE_READONLY (type) || TYPE_VOLATILE (type)) 8229: { 8230: int constp = TYPE_READONLY (type); 8231: int volatilep = TYPE_VOLATILE (type); 8232: type = build_function_type (TYPE_MAIN_VARIANT (type), 8233: flag_traditional 8234: ? 0 8235: : arg_types); 8236: type = build_type_variant (type, constp, volatilep); 8237: } 8238: else 8239: type = build_function_type (type, 8240: flag_traditional 8241: ? 0 8242: : arg_types); 1.1 root 8243: } 8244: break; 8245: 8246: case ADDR_EXPR: 8247: case INDIRECT_REF: 8248: maybe_globalize_type (type); 8249: 8250: /* Filter out pointers-to-references and references-to-references. 8251: We can get these if a TYPE_DECL is used. */ 8252: 8253: if (TREE_CODE (type) == REFERENCE_TYPE) 8254: { 8255: error ("cannot declare %s to references", 8256: TREE_CODE (declarator) == ADDR_EXPR 8257: ? "references" : "pointers"); 8258: declarator = TREE_OPERAND (declarator, 0); 8259: continue; 8260: } 8261: 8262: /* Merge any constancy or volatility into the target type 8263: for the pointer. */ 8264: 8265: if (constp || volatilep) 8266: { 8267: type = build_type_variant (type, constp, volatilep); 8268: if (IS_AGGR_TYPE (type)) 8269: build_pointer_type (type); 1.1.1.2 root 8270: constp = 0; 8271: volatilep = 0; 1.1 root 8272: } 8273: 8274: if (TREE_CODE (declarator) == ADDR_EXPR) 8275: { 8276: if (TREE_CODE (type) == FUNCTION_TYPE) 8277: { 8278: error ("cannot declare references to functions; use pointer to function instead"); 8279: type = build_pointer_type (type); 8280: } 8281: else 8282: { 8283: if (TYPE_MAIN_VARIANT (type) == void_type_node) 8284: error ("invalid type: `void &'"); 8285: else 8286: type = build_reference_type (type); 8287: } 8288: } 1.1.1.6 ! root 8289: else if (TREE_CODE (type) == METHOD_TYPE) ! 8290: { ! 8291: type = build_ptrmemfunc_type (build_pointer_type (type)); ! 8292: } 1.1 root 8293: else 8294: type = build_pointer_type (type); 8295: 8296: /* Process a list of type modifier keywords (such as 8297: const or volatile) that were given inside the `*' or `&'. */ 8298: 8299: if (TREE_TYPE (declarator)) 8300: { 8301: register tree typemodlist; 8302: int erred = 0; 8303: for (typemodlist = TREE_TYPE (declarator); typemodlist; 8304: typemodlist = TREE_CHAIN (typemodlist)) 8305: { 8306: if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST]) 8307: constp++; 8308: else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE]) 8309: volatilep++; 8310: else if (!erred) 8311: { 8312: erred = 1; 8313: error ("invalid type modifier within %s declarator", 8314: TREE_CODE (declarator) == ADDR_EXPR 8315: ? "reference" : "pointer"); 8316: } 8317: } 8318: if (constp > 1) 8319: warning ("duplicate `const'"); 8320: if (volatilep > 1) 8321: warning ("duplicate `volatile'"); 8322: } 8323: declarator = TREE_OPERAND (declarator, 0); 8324: ctype = NULL_TREE; 8325: break; 8326: 8327: case SCOPE_REF: 8328: { 8329: /* We have converted type names to NULL_TREE if the 8330: name was bogus, or to a _TYPE node, if not. 8331: 8332: The variable CTYPE holds the type we will ultimately 8333: resolve to. The code here just needs to build 8334: up appropriate member types. */ 8335: tree sname = TREE_OPERAND (declarator, 1); 1.1.1.4 root 8336: /* Destructors can have their visibilities changed as well. */ 8337: if (TREE_CODE (sname) == BIT_NOT_EXPR) 8338: sname = TREE_OPERAND (sname, 0); 1.1 root 8339: 8340: if (TREE_COMPLEXITY (declarator) == 0) 8341: /* This needs to be here, in case we are called 8342: multiple times. */ ; 1.1.1.3 root 8343: else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) 8344: /* don't fall out into global scope. Hides real bug? --eichin */ ; 1.1 root 8345: else if (TREE_COMPLEXITY (declarator) == current_class_depth) 8346: { 1.1.1.6 ! root 8347: /* I'm not really sure what pushclass calls this popclass ! 8348: corresponds to. One is in build_push_scope and that has ! 8349: been changed to a push_nested_class call, that's why I ! 8350: try to use pop_nested_class here instead. ! 8351: [email protected] */ ! 8352: #if NEW_CLASS_SCOPING ! 8353: pop_nested_class (1); ! 8354: TREE_COMPLEXITY (declarator) = current_class_depth; ! 8355: #else 1.1 root 8356: TREE_COMPLEXITY (declarator) -= 1; 1.1.1.4 root 8357: /* This popclass conflicts with the poplevel over in 8358: grokdeclarator. See ``This poplevel conflicts'' */ 1.1 root 8359: popclass (1); 1.1.1.6 ! root 8360: #endif 1.1 root 8361: } 8362: else 1.1.1.3 root 8363: my_friendly_abort (16); 1.1 root 8364: 8365: if (TREE_OPERAND (declarator, 0) == NULL_TREE) 8366: { 8367: /* We had a reference to a global decl, or 8368: perhaps we were given a non-aggregate typedef, 8369: in which case we cleared this out, and should just 8370: keep going as though it wasn't there. */ 8371: declarator = sname; 8372: continue; 8373: } 8374: ctype = TREE_OPERAND (declarator, 0); 8375: 8376: if (sname == NULL_TREE) 8377: goto done_scoping; 8378: 8379: if (TREE_CODE (sname) == IDENTIFIER_NODE) 8380: { 8381: /* This is the `standard' use of the scoping operator: 8382: basetype :: member . */ 8383: 1.1.1.6 ! root 8384: if (TREE_CODE (type) == FUNCTION_TYPE) 1.1.1.4 root 8385: { 1.1.1.6 ! root 8386: if (current_class_type == NULL_TREE ! 8387: || TYPE_MAIN_VARIANT (ctype) == current_class_type ! 8388: || friendp) 1.1.1.4 root 8389: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), 8390: TREE_TYPE (type), TYPE_ARG_TYPES (type)); 8391: else 8392: { 1.1.1.6 ! root 8393: error ("cannot declare member function `%s::%s' within this class", ! 8394: TYPE_NAME_STRING (ctype), name); ! 8395: return void_type_node; 1.1.1.4 root 8396: } 8397: } 1.1.1.6 ! root 8398: else if (TYPE_MAIN_VARIANT (ctype) == current_class_type) ! 8399: { ! 8400: if (extra_warnings) ! 8401: warning ("extra qualification `%s' on member `%s' ignored", ! 8402: TYPE_NAME_STRING (ctype), name); ! 8403: type = build_offset_type (ctype, type); ! 8404: } 1.1.1.5 root 8405: else if (TYPE_SIZE (ctype) != NULL_TREE 1.1.1.6 ! root 8406: || (RIDBIT_SETP (RID_TYPEDEF, specbits))) 1.1 root 8407: { 8408: tree t; 8409: /* have to move this code elsewhere in this function. 8410: this code is used for i.e., typedef int A::M; M *pm; */ 8411: 1.1.1.4 root 8412: if (explicit_int == -1 && decl_context == FIELD 8413: && funcdef_flag == 0) 1.1 root 8414: { 1.1.1.4 root 8415: /* The code in here should only be used to build 8416: stuff that will be grokked as visibility decls. */ 8417: t = lookup_field (ctype, sname, 0, 0); 1.1 root 8418: if (t) 8419: { 8420: t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); 8421: DECL_INITIAL (t) = init; 8422: return t; 8423: } 8424: /* No such field, try member functions. */ 8425: t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0); 8426: if (t) 8427: { 8428: if (flags == DTOR_FLAG) 8429: t = TREE_VALUE (t); 8430: else if (CLASSTYPE_METHOD_VEC (ctype) 8431: && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0)) 8432: { 8433: /* Don't include destructor with constructors. */ 8434: t = DECL_CHAIN (TREE_VALUE (t)); 8435: if (t == NULL_TREE) 8436: error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname)); 8437: t = build_tree_list (NULL_TREE, t); 8438: } 8439: t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); 8440: DECL_INITIAL (t) = init; 8441: return t; 8442: } 8443: 8444: if (flags == TYPENAME_FLAG) 1.1.1.6 ! root 8445: cp_error ("type conversion is not a member of structure `%T'", ctype); 1.1 root 8446: else 1.1.1.6 ! root 8447: cp_error ! 8448: ("field `%D' is not a member of structure `%T'", ! 8449: sname, ctype); 1.1 root 8450: } 1.1.1.6 ! root 8451: ! 8452: if (current_class_type) 1.1.1.4 root 8453: { 1.1.1.6 ! root 8454: if (TYPE_MAIN_VARIANT (ctype) != current_class_type) 1.1.1.4 root 8455: { 1.1.1.6 ! root 8456: cp_error ("cannot declare member `%T::%s' within `%T'", ! 8457: ctype, name, current_class_type); ! 8458: return void_type_node; 1.1.1.4 root 8459: } 1.1.1.6 ! root 8460: else if (extra_warnings) ! 8461: cp_warning ("extra qualification `%T' on member `%s' ignored", ! 8462: ctype, name); 1.1.1.4 root 8463: } 1.1.1.6 ! root 8464: type = build_offset_type (ctype, type); 1.1 root 8465: } 8466: else if (uses_template_parms (ctype)) 8467: { 8468: enum tree_code c; 8469: if (TREE_CODE (type) == FUNCTION_TYPE) 8470: { 1.1.1.2 root 8471: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), 1.1 root 8472: TREE_TYPE (type), 8473: TYPE_ARG_TYPES (type)); 8474: c = FUNCTION_DECL; 8475: } 8476: } 8477: else 1.1.1.6 ! root 8478: { ! 8479: cp_error ("structure `%T' not yet defined", ctype); ! 8480: return error_mark_node; ! 8481: } ! 8482: 1.1 root 8483: declarator = sname; 8484: } 8485: else if (TREE_CODE (sname) == TYPE_EXPR) 8486: { 8487: /* A TYPE_EXPR will change types out from under us. 8488: So do the TYPE_EXPR now, and make this SCOPE_REF 8489: inner to the TYPE_EXPR's CALL_EXPR. 8490: 8491: This does not work if we don't get a CALL_EXPR back. 8492: I did not think about error recovery, hence the 1.1.1.5 root 8493: my_friendly_abort. */ 1.1 root 8494: 8495: /* Get the CALL_EXPR. */ 8496: sname = grokoptypename (sname, 0); 1.1.1.4 root 8497: my_friendly_assert (TREE_CODE (sname) == CALL_EXPR, 157); 1.1 root 8498: type = TREE_TYPE (TREE_OPERAND (sname, 0)); 8499: /* Scope the CALL_EXPR's name. */ 8500: TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0); 8501: /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position. */ 8502: TREE_OPERAND (sname, 0) = declarator; 8503: /* Now work from the CALL_EXPR. */ 8504: declarator = sname; 8505: continue; 8506: } 8507: else if (TREE_CODE (sname) == SCOPE_REF) 1.1.1.3 root 8508: my_friendly_abort (17); 1.1 root 8509: else 8510: { 8511: done_scoping: 8512: declarator = TREE_OPERAND (declarator, 1); 8513: if (declarator && TREE_CODE (declarator) == CALL_EXPR) 8514: /* In this case, we will deal with it later. */ 8515: ; 8516: else 8517: { 8518: if (TREE_CODE (type) == FUNCTION_TYPE) 1.1.1.2 root 8519: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type)); 1.1 root 8520: else 1.1.1.2 root 8521: type = build_offset_type (ctype, type); 1.1 root 8522: } 8523: } 8524: } 8525: break; 8526: 8527: case BIT_NOT_EXPR: 8528: declarator = TREE_OPERAND (declarator, 0); 8529: break; 8530: 8531: case TYPE_EXPR: 8532: declarator = grokoptypename (declarator, 0); 8533: if (explicit_int != -1) 1.1.1.6 ! root 8534: { ! 8535: tree stype = TREE_TYPE (TREE_OPERAND (declarator, 0)); ! 8536: if (comp_target_types (type, stype, 1) == 0) ! 8537: cp_error ("`operator %T' declared to return `%T'", stype, ! 8538: type); ! 8539: else ! 8540: cp_pedwarn ("return type specified for `operator %T'", type); ! 8541: } ! 8542: dname = declarator; 1.1 root 8543: type = TREE_TYPE (TREE_OPERAND (declarator, 0)); 8544: maybe_globalize_type (type); 8545: break; 8546: 8547: case RECORD_TYPE: 8548: case UNION_TYPE: 8549: case ENUMERAL_TYPE: 1.1.1.5 root 8550: declarator = NULL_TREE; 1.1 root 8551: break; 8552: 8553: case ERROR_MARK: 1.1.1.5 root 8554: declarator = NULL_TREE; 1.1 root 8555: break; 8556: 8557: default: 1.1.1.5 root 8558: my_friendly_abort (158); 1.1 root 8559: } 8560: } 8561: 8562: /* Now TYPE has the actual type. */ 8563: 8564: /* If this is declaring a typedef name, return a TYPE_DECL. */ 8565: 1.1.1.6 ! root 8566: if (RIDBIT_SETP (RID_TYPEDEF, specbits)) 1.1 root 8567: { 8568: tree decl; 8569: 8570: /* Note that the grammar rejects storage classes 8571: in typenames, fields or parameters. */ 8572: if (constp || volatilep) 8573: type = build_type_variant (type, constp, volatilep); 8574: 8575: /* If the user declares "struct {...} foo" then `foo' will have 8576: an anonymous name. Fill that name in now. Nothing can 8577: refer to it, so nothing needs know about the name change. 8578: The TYPE_NAME field was filled in by build_struct_xref. */ 1.1.1.6 ! root 8579: if (type != error_mark_node ! 8580: && TYPE_NAME (type) 1.1 root 8581: && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 8582: && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) 8583: { 8584: /* replace the anonymous name with the real name everywhere. */ 8585: lookup_tag_reverse (type, declarator); 8586: TYPE_IDENTIFIER (type) = declarator; 8587: } 8588: 1.1.1.2 root 8589: #if 0 /* not yet, should get fixed properly later */ 8590: decl = make_type_decl (declarator, type); 8591: #else 1.1 root 8592: decl = build_decl (TYPE_DECL, declarator, type); 1.1.1.2 root 8593: #endif 1.1.1.6 ! root 8594: if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE) ! 8595: { ! 8596: cp_error_at ("typedef name may not be class-qualified", decl); ! 8597: TREE_TYPE (decl) = error_mark_node; ! 8598: } ! 8599: else if (quals) 1.1 root 8600: { 8601: if (ctype == NULL_TREE) 8602: { 8603: if (TREE_CODE (type) != METHOD_TYPE) 1.1.1.6 ! root 8604: cp_error_at ("invalid type qualifier for non-method type", decl); 1.1 root 8605: else 8606: ctype = TYPE_METHOD_BASETYPE (type); 8607: } 8608: if (ctype != NULL_TREE) 8609: grok_method_quals (ctype, decl, quals); 8610: } 8611: 1.1.1.6 ! root 8612: if (RIDBIT_SETP (RID_SIGNED, specbits) 1.1 root 8613: || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) 8614: C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; 8615: 1.1.1.6 ! root 8616: if (RIDBIT_SETP (RID_MUTABLE, specbits)) ! 8617: { ! 8618: error ("non-object member `%s' cannot be declared mutable", name); ! 8619: } ! 8620: 1.1 root 8621: return decl; 8622: } 8623: 8624: /* Detect the case of an array type of unspecified size 8625: which came, as such, direct from a typedef name. 8626: We must copy the type, so that each identifier gets 8627: a distinct type, so that each identifier's size can be 8628: controlled separately by its own initializer. */ 8629: 8630: if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE 1.1.1.5 root 8631: && TYPE_DOMAIN (type) == NULL_TREE) 1.1 root 8632: { 8633: type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); 8634: } 8635: 8636: /* If this is a type name (such as, in a cast or sizeof), 8637: compute the type and return it now. */ 8638: 8639: if (decl_context == TYPENAME) 8640: { 8641: /* Note that the grammar rejects storage classes 8642: in typenames, fields or parameters. */ 8643: if (constp || volatilep) 8644: type = build_type_variant (type, constp, volatilep); 8645: 8646: /* Special case: "friend class foo" looks like a TYPENAME context. */ 8647: if (friendp) 8648: { 8649: /* A friendly class? */ 1.1.1.4 root 8650: if (current_class_type) 8651: make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); 8652: else 8653: error("trying to make class `%s' a friend of global scope", 8654: TYPE_NAME_STRING (type)); 1.1 root 8655: type = void_type_node; 8656: } 8657: else if (quals) 8658: { 1.1.1.2 root 8659: #if 0 /* not yet, should get fixed properly later */ 8660: tree dummy = make_type_decl (declarator, type); 8661: #else 1.1 root 8662: tree dummy = build_decl (TYPE_DECL, declarator, type); 1.1.1.2 root 8663: #endif 1.1 root 8664: if (ctype == NULL_TREE) 8665: { 1.1.1.4 root 8666: my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); 1.1 root 8667: ctype = TYPE_METHOD_BASETYPE (type); 8668: } 8669: grok_method_quals (ctype, dummy, quals); 8670: type = TREE_TYPE (dummy); 8671: } 8672: 8673: return type; 8674: } 8675: 8676: /* `void' at top level (not within pointer) 8677: is allowed only in typedefs or type names. 8678: We don't complain about parms either, but that is because 8679: a better error message can be made later. */ 8680: 1.1.1.4 root 8681: if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) 1.1 root 8682: { 8683: if (declarator != NULL_TREE 8684: && TREE_CODE (declarator) == IDENTIFIER_NODE) 1.1.1.5 root 8685: { 8686: if (IDENTIFIER_OPNAME_P (declarator)) 1.1.1.6 ! root 8687: #if 0 /* How could this happen? */ 1.1.1.5 root 8688: error ("operator `%s' declared void", 8689: operator_name_string (declarator)); 1.1.1.6 ! root 8690: #else ! 8691: my_friendly_abort (356); ! 8692: #endif 1.1.1.5 root 8693: else 8694: error ("variable or field `%s' declared void", name); 8695: } 1.1 root 8696: else 8697: error ("variable or field declared void"); 8698: type = integer_type_node; 8699: } 8700: 8701: /* Now create the decl, which may be a VAR_DECL, a PARM_DECL 8702: or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ 8703: 8704: { 8705: register tree decl; 8706: 8707: if (decl_context == PARM) 8708: { 8709: tree parmtype = type; 8710: 8711: if (ctype) 8712: error ("cannot use `::' in parameter declaration"); 8713: 8714: /* A parameter declared as an array of T is really a pointer to T. 8715: One declared as a function is really a pointer to a function. 8716: One declared as a member is really a pointer to member. 8717: 8718: Don't be misled by references. */ 8719: 8720: if (TREE_CODE (type) == REFERENCE_TYPE) 8721: type = TREE_TYPE (type); 8722: 8723: if (TREE_CODE (type) == ARRAY_TYPE) 8724: { 8725: if (parmtype == type) 8726: { 8727: /* Transfer const-ness of array into that of type 8728: pointed to. */ 8729: type = build_pointer_type 8730: (build_type_variant (TREE_TYPE (type), constp, volatilep)); 8731: volatilep = constp = 0; 8732: } 8733: else 8734: type = build_pointer_type (TREE_TYPE (type)); 8735: } 8736: else if (TREE_CODE (type) == FUNCTION_TYPE) 8737: type = build_pointer_type (type); 8738: else if (TREE_CODE (type) == OFFSET_TYPE) 8739: type = build_pointer_type (type); 8740: 8741: if (TREE_CODE (parmtype) == REFERENCE_TYPE) 8742: { 8743: /* Transfer const-ness of reference into that of type pointed to. */ 1.1.1.4 root 8744: type = build_type_variant (build_reference_type (type), constp, volatilep); 1.1 root 8745: constp = volatilep = 0; 8746: } 8747: 8748: decl = build_decl (PARM_DECL, declarator, type); 8749: 1.1.1.6 ! root 8750: bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, ! 8751: inlinep, friendp, raises != NULL_TREE); ! 8752: 1.1 root 8753: /* Compute the type actually passed in the parmlist, 8754: for the case where there is no prototype. 8755: (For example, shorts and chars are passed as ints.) 8756: When there is a prototype, this is overridden later. */ 8757: 8758: DECL_ARG_TYPE (decl) = type; 1.1.1.4 root 8759: if (TYPE_MAIN_VARIANT (type) == float_type_node) 8760: DECL_ARG_TYPE (decl) = build_type_variant (double_type_node, 8761: TYPE_READONLY (type), 8762: TYPE_VOLATILE (type)); 8763: else if (C_PROMOTING_INTEGER_TYPE_P (type)) 8764: { 8765: tree argtype; 8766: 8767: /* Retain unsignedness if traditional or if not really 8768: getting wider. */ 8769: if (TREE_UNSIGNED (type) 8770: && (flag_traditional 8771: || TYPE_PRECISION (type) 8772: == TYPE_PRECISION (integer_type_node))) 8773: argtype = unsigned_type_node; 8774: else 8775: argtype = integer_type_node; 8776: DECL_ARG_TYPE (decl) = build_type_variant (argtype, 8777: TYPE_READONLY (type), 8778: TYPE_VOLATILE (type)); 8779: } 1.1 root 8780: } 8781: else if (decl_context == FIELD) 8782: { 8783: if (type == error_mark_node) 8784: { 8785: /* Happens when declaring arrays of sizes which 8786: are error_mark_node, for example. */ 8787: decl = NULL_TREE; 8788: } 8789: else if (TREE_CODE (type) == FUNCTION_TYPE) 8790: { 1.1.1.5 root 8791: int publicp = 0; 8792: 1.1 root 8793: if (friendp == 0) 8794: { 8795: if (ctype == NULL_TREE) 8796: ctype = current_class_type; 1.1.1.4 root 8797: 8798: if (ctype == NULL_TREE) 8799: { 1.1.1.6 ! root 8800: cp_error ("can't make `%D' into a method -- not in a class", ! 8801: declarator); 1.1.1.4 root 8802: return void_type_node; 8803: } 8804: 8805: /* ``A union may [ ... ] not [ have ] virtual functions.'' 8806: ARM 9.5 */ 8807: if (virtualp && TREE_CODE (ctype) == UNION_TYPE) 8808: { 8809: error ("function `%s' declared virtual inside a union", 8810: IDENTIFIER_POINTER (declarator)); 8811: return void_type_node; 8812: } 8813: 1.1 root 8814: /* Don't convert type of operators new and delete to 8815: METHOD_TYPE; they remain FUNCTION_TYPEs. */ 8816: if (staticp < 2 1.1.1.2 root 8817: && declarator != ansi_opname[(int) NEW_EXPR] 8818: && declarator != ansi_opname[(int) DELETE_EXPR]) 8819: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), 8820: TREE_TYPE (type), TYPE_ARG_TYPES (type)); 1.1 root 8821: } 1.1.1.5 root 8822: 8823: /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ 1.1.1.6 ! root 8824: publicp = (RIDBIT_SETP (RID_EXTERN, specbits) 1.1.1.5 root 8825: || (ctype != NULL_TREE && funcdef_flag >= 0) 8826: || (friendp 1.1.1.6 ! root 8827: && RIDBIT_NOTSETP (RID_STATIC, specbits) ! 8828: && RIDBIT_NOTSETP (RID_INLINE, specbits)) 1.1.1.5 root 8829: ); 8830: decl = grokfndecl (ctype, type, declarator, 8831: virtualp, flags, quals, 8832: raises, friendp ? -1 : 0, publicp); 1.1.1.4 root 8833: DECL_INLINE (decl) = inlinep; 1.1 root 8834: } 8835: else if (TREE_CODE (type) == METHOD_TYPE) 8836: { 1.1.1.5 root 8837: /* All method decls are public, so tell grokfndecl to set 8838: TREE_PUBLIC, also. */ 8839: decl = grokfndecl (ctype, type, declarator, 8840: virtualp, flags, quals, 8841: raises, friendp ? -1 : 0, 1); 1.1.1.4 root 8842: DECL_INLINE (decl) = inlinep; 1.1 root 8843: } 8844: else if (TREE_CODE (type) == RECORD_TYPE 8845: && CLASSTYPE_DECLARED_EXCEPTION (type)) 8846: { 8847: /* Handle a class-local exception declaration. */ 8848: decl = build_lang_field_decl (VAR_DECL, declarator, type); 8849: if (ctype == NULL_TREE) 8850: ctype = current_class_type; 8851: finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL 8852: ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl); 8853: return void_type_node; 8854: } 1.1.1.5 root 8855: else if (TYPE_SIZE (type) == NULL_TREE && !staticp 1.1 root 8856: && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) 8857: { 8858: if (declarator) 8859: error ("field `%s' has incomplete type", 8860: IDENTIFIER_POINTER (declarator)); 8861: else 8862: error ("field has incomplete type"); 1.1.1.5 root 8863: 8864: /* If we're instantiating a template, tell them which 8865: instantiation made the field's type be incomplete. */ 8866: if (current_class_type 1.1.1.6 ! root 8867: && TYPE_NAME (current_class_type) ! 8868: && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type))) 1.1.1.5 root 8869: && declspecs && TREE_VALUE (declspecs) 8870: && TREE_TYPE (TREE_VALUE (declspecs)) == type) 8871: error (" in instantiation of template `%s'", 8872: TYPE_NAME_STRING (current_class_type)); 8873: 1.1 root 8874: type = error_mark_node; 8875: decl = NULL_TREE; 8876: } 8877: else 8878: { 8879: if (friendp) 8880: { 8881: if (declarator) 8882: error ("`%s' is neither function nor method; cannot be declared friend", 8883: IDENTIFIER_POINTER (declarator)); 8884: else 8885: { 8886: error ("invalid friend declaration"); 8887: return void_type_node; 8888: } 8889: friendp = 0; 8890: } 8891: decl = NULL_TREE; 8892: } 8893: 8894: if (friendp) 8895: { 8896: /* Friends are treated specially. */ 8897: if (ctype == current_class_type) 8898: warning ("member functions are implicitly friends of their class"); 1.1.1.6 ! root 8899: else if (decl && DECL_NAME (decl)) ! 8900: return do_friend (ctype, declarator, decl, ! 8901: last_function_parms, flags, quals); ! 8902: else ! 8903: return void_type_node; 1.1 root 8904: } 8905: 8906: /* Structure field. It may not be a function, except for C++ */ 8907: 1.1.1.5 root 8908: if (decl == NULL_TREE) 1.1 root 8909: { 1.1.1.4 root 8910: /* ANSI C++ June 5 1992 WP 9.2.2 and 9.4.2. A member-declarator 8911: cannot have an initializer, and a static member declaration must 8912: be defined elsewhere. */ 8913: if (initialized) 8914: { 8915: if (staticp) 8916: error ("static member `%s' must be defined separately from its declaration", 8917: IDENTIFIER_POINTER (declarator)); 1.1.1.6 ! root 8918: /* Note that initialization of const members is prohibited ! 8919: by the draft ANSI standard, though it appears to be in ! 8920: common practice. 12.6.2: The argument list is used to ! 8921: initialize the named nonstatic member.... This (or an ! 8922: aggregate) is the only way to initialize nonstatic const ! 8923: and reference members. */ 1.1.1.5 root 8924: else if (!pedantic && (!constp || flag_ansi)) 8925: warning ("ANSI C++ forbids initialization of %s `%s'", 8926: constp ? "const member" : "member", 8927: IDENTIFIER_POINTER (declarator)); 1.1.1.4 root 8928: } 8929: 1.1 root 8930: if (staticp || (constp && initialized)) 8931: { 8932: /* C++ allows static class members. 8933: All other work for this is done by grokfield. 8934: This VAR_DECL is built by build_lang_field_decl. 8935: All other VAR_DECLs are built by build_decl. */ 8936: decl = build_lang_field_decl (VAR_DECL, declarator, type); 8937: if (staticp || TREE_CODE (type) == ARRAY_TYPE) 8938: TREE_STATIC (decl) = 1; 8939: /* In class context, static means public visibility. */ 8940: TREE_PUBLIC (decl) = 1; 1.1.1.4 root 8941: DECL_EXTERNAL (decl) = !initialized; 1.1 root 8942: } 8943: else 1.1.1.6 ! root 8944: { ! 8945: decl = build_lang_field_decl (FIELD_DECL, declarator, type); ! 8946: if (RIDBIT_SETP (RID_MUTABLE, specbits)) ! 8947: { ! 8948: DECL_MUTABLE_P (decl) = 1; ! 8949: RIDBIT_RESET (RID_MUTABLE, specbits); ! 8950: } ! 8951: } ! 8952: ! 8953: bad_specifiers (decl, "field", virtualp, quals != NULL_TREE, ! 8954: inlinep, friendp, raises != NULL_TREE); 1.1 root 8955: } 8956: } 8957: else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) 8958: { 8959: int was_overloaded = 0; 8960: tree original_name = declarator; 1.1.1.5 root 8961: int publicp = 0; 1.1 root 8962: 1.1.1.6 ! root 8963: if (! declarator) ! 8964: return NULL_TREE; 1.1 root 8965: 1.1.1.6 ! root 8966: if (RIDBIT_SETP (RID_AUTO, specbits) ! 8967: || RIDBIT_SETP (RID_REGISTER, specbits)) 1.1 root 8968: error ("invalid storage class for function `%s'", name); 1.1.1.6 ! root 8969: 1.1 root 8970: /* Function declaration not at top level. 8971: Storage classes other than `extern' are not allowed 8972: and `extern' makes no difference. */ 8973: if (current_binding_level != global_binding_level 1.1.1.6 ! root 8974: && (RIDBIT_SETP (RID_STATIC, specbits) || RIDBIT_SETP (RID_INLINE, specbits)) 1.1 root 8975: && pedantic) 1.1.1.3 root 8976: pedwarn ("invalid storage class for function `%s'", name); 1.1 root 8977: 8978: if (ctype == NULL_TREE) 8979: { 8980: if (virtualp) 8981: { 8982: error ("virtual non-class function `%s'", name); 8983: virtualp = 0; 8984: } 1.1.1.5 root 8985: 1.1 root 8986: if (current_lang_name == lang_name_cplusplus 8987: && ! (IDENTIFIER_LENGTH (original_name) == 4 8988: && IDENTIFIER_POINTER (original_name)[0] == 'm' 8989: && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0) 8990: && ! (IDENTIFIER_LENGTH (original_name) > 10 8991: && IDENTIFIER_POINTER (original_name)[0] == '_' 8992: && IDENTIFIER_POINTER (original_name)[1] == '_' 8993: && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0)) 8994: { 8995: /* Plain overloading: will not be grok'd by grokclassfn. */ 1.1.1.2 root 8996: declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); 1.1 root 8997: was_overloaded = 1; 8998: } 8999: } 9000: else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) 1.1.1.2 root 9001: type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), 9002: TREE_TYPE (type), TYPE_ARG_TYPES (type)); 1.1.1.5 root 9003: 9004: /* Record presence of `static'. In C++, `inline' is like `static'. 9005: Methods of classes should be public, unless we're dropping them 9006: into some other file, so we don't clear TREE_PUBLIC for them. */ 9007: publicp 9008: = ((ctype 1.1.1.6 ! root 9009: && CLASSTYPE_INTERFACE_KNOWN (ctype) 1.1.1.5 root 9010: && ! CLASSTYPE_INTERFACE_ONLY (ctype)) 1.1.1.6 ! root 9011: || !(RIDBIT_SETP (RID_STATIC, specbits) ! 9012: || RIDBIT_SETP (RID_INLINE, specbits))); 1.1.1.5 root 9013: 9014: decl = grokfndecl (ctype, type, original_name, 9015: virtualp, flags, quals, 1.1 root 9016: raises, 1.1.1.5 root 9017: processing_template_decl ? 0 : friendp ? 2 : 1, 9018: publicp); 9019: 1.1.1.6 ! root 9020: if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c) 1.1 root 9021: DECL_ASSEMBLER_NAME (decl) = declarator; 1.1.1.5 root 9022: 1.1.1.4 root 9023: if (staticp == 1) 1.1 root 9024: { 1.1.1.4 root 9025: int illegal_static = 0; 9026: 1.1.1.5 root 9027: /* Don't allow a static member function in a class, and forbid 9028: declaring main to be static. */ 1.1.1.4 root 9029: if (TREE_CODE (type) == METHOD_TYPE) 9030: { 1.1.1.6 ! root 9031: cp_error_at ("cannot declare member function `%D' to have static linkage", decl); 1.1.1.4 root 9032: illegal_static = 1; 9033: } 9034: else if (! was_overloaded 9035: && ! ctype 1.1.1.5 root 9036: && IDENTIFIER_LENGTH (original_name) == 4 9037: && IDENTIFIER_POINTER (original_name)[0] == 'm' 1.1.1.4 root 9038: && ! strcmp (IDENTIFIER_POINTER (original_name), "main")) 9039: { 9040: error ("cannot declare function `main' to have static linkage"); 9041: illegal_static = 1; 9042: } 9043: 9044: if (illegal_static) 9045: { 9046: staticp = 0; 1.1.1.6 ! root 9047: RIDBIT_RESET (RID_STATIC, specbits); 1.1.1.4 root 9048: } 1.1 root 9049: } 9050: 9051: /* Record presence of `inline', if it is reasonable. */ 9052: if (inlinep) 9053: { 9054: tree last = tree_last (TYPE_ARG_TYPES (type)); 9055: 9056: if (! was_overloaded 9057: && ! ctype 9058: && ! strcmp (IDENTIFIER_POINTER (original_name), "main")) 1.1.1.6 ! root 9059: error ("cannot inline function `main'"); 1.1 root 9060: else if (last && last != void_list_node) 1.1.1.6 ! root 9061: cp_warning ("cannot inline function `%D' which takes `...'", original_name); 1.1 root 9062: else 9063: /* Assume that otherwise the function can be inlined. */ 1.1.1.4 root 9064: DECL_INLINE (decl) = 1; 1.1 root 9065: 1.1.1.6 ! root 9066: if (RIDBIT_SETP (RID_EXTERN, specbits)) 1.1.1.4 root 9067: { 9068: current_extern_inline = 1; 1.1.1.6 ! root 9069: if (flag_ansi || pedantic || flag_pedantic_errors) ! 9070: pedwarn ("ANSI C++ does not permit `extern inline'"); 1.1.1.4 root 9071: } 1.1 root 9072: } 9073: if (was_overloaded) 9074: DECL_OVERLOADED (decl) = 1; 9075: } 9076: else 9077: { 9078: /* It's a variable. */ 9079: 9080: /* An uninitialized decl with `extern' is a reference. */ 1.1.1.5 root 9081: decl = grokvardecl (type, declarator, specbits, initialized); 1.1.1.6 ! root 9082: bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, ! 9083: inlinep, friendp, raises != NULL_TREE); ! 9084: 1.1.1.4 root 9085: if (ctype) 1.1 root 9086: { 1.1.1.4 root 9087: if (staticp == 1) 9088: { 1.1.1.6 ! root 9089: cp_error ("static member `%D' re-declared as static", ! 9090: decl); 1.1.1.4 root 9091: staticp = 0; 1.1.1.6 ! root 9092: RIDBIT_RESET (RID_STATIC, specbits); 1.1.1.4 root 9093: } 1.1.1.6 ! root 9094: if (RIDBIT_SETP (RID_EXTERN, specbits)) 1.1.1.4 root 9095: { 1.1.1.6 ! root 9096: cp_error ("cannot explicitly declare member `%#D' to have extern linkage", ! 9097: decl); ! 9098: RIDBIT_RESET (RID_EXTERN, specbits); 1.1.1.4 root 9099: } 1.1 root 9100: } 9101: } 9102: 1.1.1.6 ! root 9103: if (RIDBIT_SETP (RID_MUTABLE, specbits)) ! 9104: { ! 9105: error ("`%s' cannot be declared mutable", name); ! 9106: } ! 9107: 1.1 root 9108: /* Record `register' declaration for warnings on & 9109: and in case doing stupid register allocation. */ 9110: 1.1.1.6 ! root 9111: if (RIDBIT_SETP (RID_REGISTER, specbits)) 1.1.1.4 root 9112: DECL_REGISTER (decl) = 1; 1.1 root 9113: 9114: /* Record constancy and volatility. */ 9115: 9116: if (constp) 9117: TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE; 9118: if (volatilep) 9119: { 9120: TREE_SIDE_EFFECTS (decl) = 1; 9121: TREE_THIS_VOLATILE (decl) = 1; 9122: } 9123: 9124: return decl; 9125: } 9126: } 9127: 9128: /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist. 9129: An empty exprlist is a parmlist. An exprlist which 9130: contains only identifiers at the global level 9131: is a parmlist. Otherwise, it is an exprlist. */ 9132: int 9133: parmlist_is_exprlist (exprs) 9134: tree exprs; 9135: { 9136: if (exprs == NULL_TREE || TREE_PARMLIST (exprs)) 9137: return 0; 9138: 9139: if (current_binding_level == global_binding_level) 9140: { 9141: /* At the global level, if these are all identifiers, 9142: then it is a parmlist. */ 9143: while (exprs) 9144: { 9145: if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE) 9146: return 1; 9147: exprs = TREE_CHAIN (exprs); 9148: } 9149: return 0; 9150: } 9151: return 1; 9152: } 9153: 9154: /* Make sure that the this list of PARMS has a chance of being 9155: grokked by `grokparms'. 9156: 9157: @@ This is really weak, but the grammar does not allow us 9158: @@ to easily reject things that this has to catch as syntax errors. */ 9159: static int 9160: parmlist_is_random (parms) 9161: tree parms; 9162: { 9163: if (parms == NULL_TREE) 9164: return 0; 9165: 9166: if (TREE_CODE (parms) != TREE_LIST) 9167: return 1; 9168: 9169: while (parms) 9170: { 9171: if (parms == void_list_node) 9172: return 0; 9173: 9174: if (TREE_CODE (TREE_VALUE (parms)) != TREE_LIST) 9175: return 1; 9176: /* Don't get faked out by overloaded functions, which 9177: masquerade as TREE_LISTs! */ 9178: if (TREE_TYPE (TREE_VALUE (parms)) == unknown_type_node) 9179: return 1; 9180: parms = TREE_CHAIN (parms); 9181: } 9182: return 0; 9183: } 9184: 9185: /* Subroutine of `grokparms'. In a fcn definition, arg types must 9186: be complete. 9187: 9188: C++: also subroutine of `start_function'. */ 9189: static void 9190: require_complete_types_for_parms (parms) 9191: tree parms; 9192: { 9193: while (parms) 9194: { 9195: tree type = TREE_TYPE (parms); 1.1.1.5 root 9196: if (TYPE_SIZE (type) == NULL_TREE) 1.1 root 9197: { 9198: if (DECL_NAME (parms)) 9199: error ("parameter `%s' has incomplete type", 9200: IDENTIFIER_POINTER (DECL_NAME (parms))); 9201: else 9202: error ("parameter has incomplete type"); 9203: TREE_TYPE (parms) = error_mark_node; 9204: } 9205: #if 0 9206: /* If the arg types are incomplete in a declaration, 9207: they must include undefined tags. 9208: These tags can never be defined in the scope of the declaration, 9209: so the types can never be completed, 9210: and no call can be compiled successfully. */ 9211: /* This is not the right behavior for C++, but not having 9212: it is also probably wrong. */ 9213: else 9214: { 9215: /* Now warn if is a pointer to an incomplete type. */ 9216: while (TREE_CODE (type) == POINTER_TYPE 9217: || TREE_CODE (type) == REFERENCE_TYPE) 9218: type = TREE_TYPE (type); 9219: type = TYPE_MAIN_VARIANT (type); 1.1.1.5 root 9220: if (TYPE_SIZE (type) == NULL_TREE) 1.1 root 9221: { 1.1.1.5 root 9222: if (DECL_NAME (parm) != NULL_TREE) 1.1 root 9223: warning ("parameter `%s' points to incomplete type", 9224: IDENTIFIER_POINTER (DECL_NAME (parm))); 9225: else 9226: warning ("parameter points to incomplete type"); 9227: } 9228: } 9229: #endif 9230: parms = TREE_CHAIN (parms); 9231: } 9232: } 9233: 9234: /* Decode the list of parameter types for a function type. 9235: Given the list of things declared inside the parens, 9236: return a list of types. 9237: 9238: The list we receive can have three kinds of elements: 9239: an IDENTIFIER_NODE for names given without types, 9240: a TREE_LIST node for arguments given as typespecs or names with typespecs, 9241: or void_type_node, to mark the end of an argument list 9242: when additional arguments are not permitted (... was not used). 9243: 9244: FUNCDEF_FLAG is nonzero for a function definition, 0 for 9245: a mere declaration. A nonempty identifier-list gets an error message 9246: when FUNCDEF_FLAG is zero. 9247: If FUNCDEF_FLAG is 1, then parameter types must be complete. 9248: If FUNCDEF_FLAG is -1, then parameter types may be incomplete. 9249: 9250: If all elements of the input list contain types, 9251: we return a list of the types. 9252: If all elements contain no type (except perhaps a void_type_node 9253: at the end), we return a null list. 9254: If some have types and some do not, it is an error, and we 9255: return a null list. 9256: 9257: Also set last_function_parms to either 9258: a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. 9259: A list of names is converted to a chain of PARM_DECLs 9260: by store_parm_decls so that ultimately it is always a chain of decls. 9261: 1.1.1.2 root 9262: Note that in C++, parameters can take default values. These default 1.1 root 9263: values are in the TREE_PURPOSE field of the TREE_LIST. It is 9264: an error to specify default values which are followed by parameters 9265: that have no default values, or an ELLIPSES. For simplicities sake, 9266: only parameters which are specified with their types can take on 9267: default values. */ 9268: 9269: static tree 9270: grokparms (first_parm, funcdef_flag) 9271: tree first_parm; 9272: int funcdef_flag; 9273: { 9274: tree result = NULL_TREE; 9275: tree decls = NULL_TREE; 9276: 1.1.1.5 root 9277: if (first_parm != NULL_TREE 1.1 root 9278: && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) 9279: { 9280: if (! funcdef_flag) 9281: warning ("parameter names (without types) in function declaration"); 9282: last_function_parms = first_parm; 1.1.1.5 root 9283: return NULL_TREE; 1.1 root 9284: } 9285: else 9286: { 9287: /* Types were specified. This is a list of declarators 9288: each represented as a TREE_LIST node. */ 9289: register tree parm, chain; 9290: int any_init = 0, any_error = 0, saw_void = 0; 9291: 9292: if (first_parm != NULL_TREE) 9293: { 9294: tree last_result = NULL_TREE; 9295: tree last_decl = NULL_TREE; 9296: 9297: for (parm = first_parm; parm != NULL_TREE; parm = chain) 9298: { 9299: tree type, list_node = parm; 9300: register tree decl = TREE_VALUE (parm); 9301: tree init = TREE_PURPOSE (parm); 9302: 9303: chain = TREE_CHAIN (parm); 9304: /* @@ weak defense against parse errors. */ 9305: if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST) 9306: { 9307: /* Give various messages as the need arises. */ 9308: if (TREE_CODE (decl) == STRING_CST) 9309: error ("invalid string constant `%s'", 9310: TREE_STRING_POINTER (decl)); 9311: else if (TREE_CODE (decl) == INTEGER_CST) 9312: error ("invalid integer constant in parameter list, did you forget to give parameter name?"); 9313: continue; 9314: } 9315: 9316: if (decl != void_type_node) 9317: { 9318: /* @@ May need to fetch out a `raises' here. */ 9319: decl = grokdeclarator (TREE_VALUE (decl), 9320: TREE_PURPOSE (decl), 1.1.1.4 root 9321: PARM, init != NULL_TREE, NULL_TREE); 9322: if (! decl) 9323: continue; 1.1 root 9324: type = TREE_TYPE (decl); 1.1.1.4 root 9325: if (TYPE_MAIN_VARIANT (type) == void_type_node) 1.1 root 9326: decl = void_type_node; 9327: else if (TREE_CODE (type) == METHOD_TYPE) 9328: { 9329: if (DECL_NAME (decl)) 9330: /* Cannot use `error_with_decl' here because 9331: we don't have DECL_CONTEXT set up yet. */ 9332: error ("parameter `%s' invalidly declared method type", 9333: IDENTIFIER_POINTER (DECL_NAME (decl))); 9334: else 9335: error ("parameter invalidly declared method type"); 9336: type = build_pointer_type (type); 9337: TREE_TYPE (decl) = type; 9338: } 9339: else if (TREE_CODE (type) == OFFSET_TYPE) 9340: { 9341: if (DECL_NAME (decl)) 9342: error ("parameter `%s' invalidly declared offset type", 9343: IDENTIFIER_POINTER (DECL_NAME (decl))); 9344: else 9345: error ("parameter invalidly declared offset type"); 9346: type = build_pointer_type (type); 9347: TREE_TYPE (decl) = type; 9348: } 9349: else if (TREE_CODE (type) == RECORD_TYPE 9350: && TYPE_LANG_SPECIFIC (type) 9351: && CLASSTYPE_ABSTRACT_VIRTUALS (type)) 9352: { 9353: abstract_virtuals_error (decl, type); 9354: any_error = 1; /* seems like a good idea */ 9355: } 9356: } 9357: 9358: if (decl == void_type_node) 9359: { 9360: if (result == NULL_TREE) 9361: { 9362: result = void_list_node; 9363: last_result = result; 9364: } 9365: else 9366: { 9367: TREE_CHAIN (last_result) = void_list_node; 9368: last_result = void_list_node; 9369: } 9370: saw_void = 1; 9371: if (chain 9372: && (chain != void_list_node || TREE_CHAIN (chain))) 9373: error ("`void' in parameter list must be entire list"); 9374: break; 9375: } 9376: 9377: /* Since there is a prototype, args are passed in their own types. */ 9378: DECL_ARG_TYPE (decl) = TREE_TYPE (decl); 9379: #ifdef PROMOTE_PROTOTYPES 1.1.1.6 ! root 9380: if ((TREE_CODE (type) == INTEGER_TYPE ! 9381: || TREE_CODE (type) == ENUMERAL_TYPE) ! 9382: && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) 1.1 root 9383: DECL_ARG_TYPE (decl) = integer_type_node; 9384: #endif 9385: if (!any_error) 9386: { 9387: if (init) 9388: { 9389: any_init++; 9390: if (TREE_CODE (init) == SAVE_EXPR) 9391: PARM_DECL_EXPR (init) = 1; 1.1.1.4 root 9392: else if (TREE_CODE (init) == VAR_DECL) 9393: { 9394: if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init))) 9395: { 9396: /* ``Local variables may not be used in default 9397: argument expressions.'' dpANSI C++ 8.2.6 */ 9398: /* If extern int i; within a function is not 9399: considered a local variable, then this code is 9400: wrong. */ 1.1.1.6 ! root 9401: cp_error ("local variable `%D' may not be used as a default argument", init); 1.1.1.4 root 9402: any_error = 1; 9403: } 9404: else if (TREE_READONLY_DECL_P (init)) 9405: init = decl_constant_value (init); 9406: } 1.1 root 9407: else 9408: init = require_instantiated_type (type, init, integer_zero_node); 9409: } 9410: else if (any_init) 9411: { 9412: error ("all trailing parameters must have default arguments"); 9413: any_error = 1; 9414: } 9415: } 9416: else 9417: init = NULL_TREE; 9418: 9419: if (decls == NULL_TREE) 9420: { 9421: decls = decl; 9422: last_decl = decls; 9423: } 9424: else 9425: { 9426: TREE_CHAIN (last_decl) = decl; 9427: last_decl = decl; 9428: } 9429: if (TREE_PERMANENT (list_node)) 9430: { 9431: TREE_PURPOSE (list_node) = init; 9432: TREE_VALUE (list_node) = type; 1.1.1.5 root 9433: TREE_CHAIN (list_node) = NULL_TREE; 1.1 root 9434: } 9435: else 9436: list_node = saveable_tree_cons (init, type, NULL_TREE); 9437: if (result == NULL_TREE) 9438: { 9439: result = list_node; 9440: last_result = result; 9441: } 9442: else 9443: { 9444: TREE_CHAIN (last_result) = list_node; 9445: last_result = list_node; 9446: } 9447: } 9448: if (last_result) 9449: TREE_CHAIN (last_result) = NULL_TREE; 9450: /* If there are no parameters, and the function does not end 9451: with `...', then last_decl will be NULL_TREE. */ 9452: if (last_decl != NULL_TREE) 9453: TREE_CHAIN (last_decl) = NULL_TREE; 9454: } 9455: } 9456: 9457: last_function_parms = decls; 9458: 9459: /* In a fcn definition, arg types must be complete. */ 9460: if (funcdef_flag > 0) 9461: require_complete_types_for_parms (last_function_parms); 9462: 9463: return result; 9464: } 9465: 9466: /* These memoizing functions keep track of special properties which 9467: a class may have. `grok_ctor_properties' notices whether a class 1.1.1.6 ! root 9468: has a constructor of the form X(X&), and also complains 1.1 root 9469: if the class has a constructor of the form X(X). 9470: `grok_op_properties' takes notice of the various forms of 9471: operator= which are defined, as well as what sorts of type conversion 9472: may apply. Both functions take a FUNCTION_DECL as an argument. */ 9473: void 9474: grok_ctor_properties (ctype, decl) 9475: tree ctype, decl; 9476: { 9477: tree parmtypes = FUNCTION_ARG_CHAIN (decl); 9478: tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; 9479: 1.1.1.6 ! root 9480: /* When a type has virtual baseclasses, a magical first int argument is ! 9481: added to any ctor so we can tell if the class has been initialized ! 9482: yet. This could screw things up in this function, so we deliberately ! 9483: ignore the leading int if we're in that situation. */ ! 9484: if (parmtypes ! 9485: && TREE_VALUE (parmtypes) == integer_type_node ! 9486: && TYPE_USES_VIRTUAL_BASECLASSES (ctype)) 1.1.1.4 root 9487: { 9488: parmtypes = TREE_CHAIN (parmtypes); 9489: parmtype = TREE_VALUE (parmtypes); 9490: } 9491: 1.1 root 9492: if (TREE_CODE (parmtype) == REFERENCE_TYPE 9493: && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype) 9494: { 9495: if (TREE_CHAIN (parmtypes) == NULL_TREE 9496: || TREE_CHAIN (parmtypes) == void_list_node 9497: || TREE_PURPOSE (TREE_CHAIN (parmtypes))) 9498: { 9499: TYPE_HAS_INIT_REF (ctype) = 1; 9500: TYPE_GETS_INIT_REF (ctype) = 1; 9501: if (TYPE_READONLY (TREE_TYPE (parmtype))) 9502: TYPE_GETS_CONST_INIT_REF (ctype) = 1; 9503: } 9504: else 9505: TYPE_GETS_INIT_AGGR (ctype) = 1; 9506: } 9507: else if (TYPE_MAIN_VARIANT (parmtype) == ctype) 9508: { 9509: if (TREE_CHAIN (parmtypes) != NULL_TREE 9510: && TREE_CHAIN (parmtypes) == void_list_node) 9511: error ("invalid constructor; you probably meant `%s (%s&)'", 9512: TYPE_NAME_STRING (ctype), 9513: TYPE_NAME_STRING (ctype)); 9514: SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); 9515: TYPE_GETS_INIT_AGGR (ctype) = 1; 9516: } 9517: else if (TREE_CODE (parmtype) == VOID_TYPE 9518: || TREE_PURPOSE (parmtypes) != NULL_TREE) 9519: TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; 9520: } 9521: 1.1.1.6 ! root 9522: /* An operator with this name can be either unary or binary. */ ! 9523: int ambi_op_p (name) ! 9524: tree name; ! 9525: { ! 9526: return (name == ansi_opname [(int) INDIRECT_REF] ! 9527: || name == ansi_opname [(int) ADDR_EXPR] ! 9528: || name == ansi_opname [(int) NEGATE_EXPR] ! 9529: || name == ansi_opname[(int) POSTINCREMENT_EXPR] ! 9530: || name == ansi_opname[(int) POSTDECREMENT_EXPR] ! 9531: || name == ansi_opname [(int) CONVERT_EXPR]); ! 9532: } ! 9533: ! 9534: /* An operator with this name can only be unary. */ ! 9535: int unary_op_p (name) ! 9536: tree name; ! 9537: { ! 9538: return (name == ansi_opname [(int) TRUTH_NOT_EXPR] ! 9539: || name == ansi_opname [(int) BIT_NOT_EXPR] ! 9540: || name == ansi_opname [(int) COMPONENT_REF] ! 9541: || OPERATOR_TYPENAME_P (name)); ! 9542: } ! 9543: 1.1.1.5 root 9544: /* Do a little sanity-checking on how they declared their operator. */ 1.1 root 9545: static void 1.1.1.4 root 9546: grok_op_properties (decl, virtualp) 1.1 root 9547: tree decl; 1.1.1.4 root 9548: int virtualp; 1.1 root 9549: { 9550: tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); 1.1.1.6 ! root 9551: int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); ! 9552: tree name = DECL_NAME (decl); 1.1 root 9553: 1.1.1.6 ! root 9554: if (name == ansi_opname[(int) NEW_EXPR]) 1.1 root 9555: { 1.1.1.6 ! root 9556: #if 0 /* When the compiler encounters the definition of A::operator new, it ! 9557: doesn't look at the class declaration to find out if it's static. */ ! 9558: my_friendly_assert (!methodp, 355); ! 9559: #endif ! 9560: ! 9561: /* Take care of function decl if we had syntax errors. */ ! 9562: if (argtypes == NULL_TREE) ! 9563: TREE_TYPE (decl) = ! 9564: build_function_type (ptr_type_node, ! 9565: hash_tree_chain (integer_type_node, ! 9566: void_list_node)); ! 9567: else ! 9568: decl = coerce_new_type (TREE_TYPE (decl)); ! 9569: } ! 9570: else if (name == ansi_opname[(int) DELETE_EXPR]) ! 9571: { ! 9572: #if 0 ! 9573: my_friendly_assert (!methodp, 355); ! 9574: #endif ! 9575: ! 9576: if (argtypes == NULL_TREE) ! 9577: TREE_TYPE (decl) = ! 9578: build_function_type (void_type_node, ! 9579: hash_tree_chain (ptr_type_node, ! 9580: void_list_node)); ! 9581: else ! 9582: decl = coerce_delete_type (TREE_TYPE (decl)); ! 9583: } ! 9584: /* 13.4.0.3 */ ! 9585: else if (name == ansi_opname[(int) COND_EXPR]) ! 9586: error("`operator ?:' cannot be overloaded"); ! 9587: else ! 9588: { ! 9589: /* An operator function must either be a non-static member function ! 9590: or have at least one parameter of a class, a reference to a class, ! 9591: an enumeration, or a reference to an enumeration. 13.4.0.6 */ ! 9592: if (! methodp) ! 9593: { ! 9594: if (OPERATOR_TYPENAME_P (name) ! 9595: || name == ansi_opname[(int) CALL_EXPR] ! 9596: || name == ansi_opname[(int) MODIFY_EXPR] ! 9597: || name == ansi_opname[(int) COMPONENT_REF] ! 9598: || name == ansi_opname[(int) ARRAY_REF]) ! 9599: cp_error ("`%D' must be a nonstatic member function", decl); 1.1.1.4 root 9600: else 1.1.1.6 ! root 9601: { ! 9602: tree p = argtypes; ! 9603: ! 9604: if (p) ! 9605: for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p)) ! 9606: { ! 9607: tree arg = TREE_VALUE (p); ! 9608: if (TREE_CODE (arg) == REFERENCE_TYPE) ! 9609: arg = TREE_TYPE (arg); ! 9610: ! 9611: /* This lets bad template code slip through. */ ! 9612: if (IS_AGGR_TYPE (arg) ! 9613: || TREE_CODE (arg) == ENUMERAL_TYPE ! 9614: || TREE_CODE (arg) == TEMPLATE_TYPE_PARM) ! 9615: goto foundaggr; ! 9616: } ! 9617: cp_error ! 9618: ("`%D' must have an argument of class or enumerated type", ! 9619: decl); ! 9620: foundaggr: ! 9621: ; ! 9622: } 1.1 root 9623: } 1.1.1.6 ! root 9624: ! 9625: if (name == ansi_opname[(int) CALL_EXPR] ! 9626: || name == ansi_opname[(int) METHOD_CALL_EXPR]) ! 9627: return; /* no restrictions on args */ ! 9628: ! 9629: if (name == ansi_opname[(int) MODIFY_EXPR]) 1.1 root 9630: { 1.1.1.6 ! root 9631: tree parmtype; ! 9632: ! 9633: if (list_length (argtypes) != 3 && methodp) ! 9634: { ! 9635: cp_error ("`%D' must take exactly one argument", decl); ! 9636: return; ! 9637: } ! 9638: parmtype = TREE_VALUE (TREE_CHAIN (argtypes)); 1.1.1.4 root 9639: 1.1.1.6 ! root 9640: if (TREE_CODE (parmtype) == REFERENCE_TYPE ! 9641: && TREE_TYPE (parmtype) == current_class_type) ! 9642: { ! 9643: TYPE_HAS_ASSIGN_REF (current_class_type) = 1; ! 9644: TYPE_GETS_ASSIGN_REF (current_class_type) = 1; ! 9645: if (TYPE_READONLY (TREE_TYPE (parmtype))) ! 9646: TYPE_GETS_CONST_INIT_REF (current_class_type) = 1; ! 9647: } ! 9648: } ! 9649: else if (ambi_op_p (name)) ! 9650: { ! 9651: if (list_length (argtypes) == 2) ! 9652: /* prefix */; ! 9653: else if (list_length (argtypes) == 3) ! 9654: { ! 9655: if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] ! 9656: || name == ansi_opname[(int) POSTDECREMENT_EXPR]) ! 9657: && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node) ! 9658: { ! 9659: if (methodp) ! 9660: cp_error ("postfix `%D' must take `int' as its argument", ! 9661: decl); ! 9662: else ! 9663: cp_error ! 9664: ("postfix `%D' must take `int' as its second argument", ! 9665: decl); ! 9666: } ! 9667: } 1.1.1.4 root 9668: else 1.1.1.6 ! root 9669: { ! 9670: if (methodp) ! 9671: cp_error ("`%D' must take either zero or one argument", decl); ! 9672: else ! 9673: cp_error ("`%D' must take either one or two arguments", decl); ! 9674: } 1.1 root 9675: } 1.1.1.6 ! root 9676: else if (unary_op_p (name)) 1.1.1.4 root 9677: { 1.1.1.6 ! root 9678: if (list_length (argtypes) != 2) ! 9679: { ! 9680: if (methodp) ! 9681: cp_error ("`%D' must take `void'", decl); ! 9682: else ! 9683: cp_error ("`%D' must take exactly one argument", decl); ! 9684: } 1.1.1.4 root 9685: } 1.1.1.6 ! root 9686: else /* if (binary_op_p (name)) */ 1.1 root 9687: { 1.1.1.6 ! root 9688: if (list_length (argtypes) != 3) ! 9689: { ! 9690: if (methodp) ! 9691: cp_error ("`%D' must take exactly one argument", decl); ! 9692: else ! 9693: cp_error ("`%D' must take exactly two arguments", decl); ! 9694: } 1.1 root 9695: } 1.1.1.6 ! root 9696: ! 9697: /* 13.4.0.8 */ ! 9698: if (argtypes) ! 9699: for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes)) ! 9700: if (TREE_PURPOSE (argtypes)) ! 9701: { ! 9702: TREE_PURPOSE (argtypes) = NULL_TREE; ! 9703: cp_error ("`%D' cannot have default arguments", decl); ! 9704: } 1.1 root 9705: } 9706: } 9707: 9708: /* Get the struct, enum or union (CODE says which) with tag NAME. 9709: Define the tag as a forward-reference if it is not defined. 9710: 9711: C++: If a class derivation is given, process it here, and report 9712: an error if multiple derivation declarations are not identical. 9713: 9714: If this is a definition, come in through xref_tag and only look in 9715: the current frame for the name (since C++ allows new names in any 1.1.1.5 root 9716: scope.) */ 1.1 root 9717: 9718: /* avoid rewriting all callers of xref_tag */ 9719: static int xref_next_defn = 0; 9720: 9721: tree 9722: xref_defn_tag (code_type_node, name, binfo) 9723: tree code_type_node; 9724: tree name, binfo; 9725: { 9726: tree rv, ncp; 9727: xref_next_defn = 1; 9728: 9729: if (class_binding_level) 9730: { 9731: tree n1; 9732: char *buf; 9733: /* we need to build a new IDENTIFIER_NODE for name which nukes 9734: * the pieces... */ 9735: n1 = IDENTIFIER_LOCAL_VALUE (current_class_name); 9736: if (n1) 9737: n1 = DECL_NAME (n1); 9738: else 9739: n1 = current_class_name; 9740: 9741: buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1) 9742: + IDENTIFIER_LENGTH (name)); 9743: 9744: sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1), 9745: IDENTIFIER_POINTER (name)); 9746: ncp = get_identifier (buf); 9747: #ifdef SPEW_DEBUG 1.1.1.4 root 9748: if (spew_debug) 9749: printf("*** %s ***\n", IDENTIFIER_POINTER (ncp)); 1.1 root 9750: #endif 9751: #if 0 9752: IDENTIFIER_LOCAL_VALUE (name) = 9753: build_lang_decl (TYPE_DECL, ncp, NULL_TREE); 9754: #endif 9755: rv = xref_tag (code_type_node, name, binfo); 1.1.1.6 ! root 9756: { ! 9757: register tree type_decl = build_lang_decl (TYPE_DECL, ncp, rv); ! 9758: #ifdef DWARF_DEBUGGING_INFO ! 9759: /* Mark the TYPE_DECL node created just above as a gratuitous one ! 9760: so that dwarfout.c will know not to generate a TAG_typedef DIE ! 9761: for it. */ ! 9762: if (write_symbols == DWARF_DEBUG) ! 9763: DECL_IGNORED_P (type_decl) = 1; ! 9764: #endif /* DWARF_DEBUGGING_INFO */ ! 9765: pushdecl_top_level (type_decl); ! 9766: } 1.1 root 9767: } 9768: else 9769: { 9770: rv = xref_tag (code_type_node, name, binfo); 9771: } 9772: xref_next_defn = 0; 9773: return rv; 9774: } 9775: 9776: tree 9777: xref_tag (code_type_node, name, binfo) 9778: tree code_type_node; 9779: tree name, binfo; 9780: { 9781: enum tag_types tag_code; 9782: enum tree_code code; 9783: int temp = 0; 9784: int i, len; 9785: register tree ref; 9786: struct binding_level *b 9787: = (class_binding_level ? class_binding_level : current_binding_level); 9788: 9789: tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); 9790: switch (tag_code) 9791: { 9792: case record_type: 9793: case class_type: 9794: case exception_type: 9795: code = RECORD_TYPE; 9796: len = list_length (binfo); 9797: break; 9798: case union_type: 9799: code = UNION_TYPE; 9800: if (binfo) 9801: { 1.1.1.6 ! root 9802: cp_error ("derived union `%T' invalid", name); 1.1 root 9803: binfo = NULL_TREE; 9804: } 9805: len = 0; 9806: break; 9807: case enum_type: 9808: code = ENUMERAL_TYPE; 9809: break; 9810: default: 1.1.1.3 root 9811: my_friendly_abort (18); 1.1 root 9812: } 9813: 9814: /* If a cross reference is requested, look up the type 9815: already defined for this tag and return it. */ 9816: if (xref_next_defn) 9817: { 9818: /* If we know we are defining this tag, only look it up in this scope 9819: * and don't try to find it as a type. */ 9820: xref_next_defn = 0; 9821: ref = lookup_tag (code, name, b, 1); 9822: } 9823: else 9824: { 9825: ref = lookup_tag (code, name, b, 0); 9826: 9827: if (! ref) 9828: { 9829: /* Try finding it as a type declaration. If that wins, use it. */ 9830: ref = lookup_name (name, 1); 9831: if (ref && TREE_CODE (ref) == TYPE_DECL 9832: && TREE_CODE (TREE_TYPE (ref)) == code) 9833: ref = TREE_TYPE (ref); 9834: else 9835: ref = NULL_TREE; 9836: } 9837: } 9838: 9839: push_obstacks_nochange (); 9840: 9841: if (! ref) 9842: { 9843: /* If no such tag is yet defined, create a forward-reference node 9844: and record it as the "definition". 9845: When a real declaration of this type is found, 9846: the forward-reference will be altered into a real type. */ 9847: 9848: /* In C++, since these migrate into the global scope, we must 9849: build them on the permanent obstack. */ 9850: 9851: temp = allocation_temporary_p (); 9852: if (temp) 9853: end_temporary_allocation (); 9854: 9855: if (code == ENUMERAL_TYPE) 9856: { 9857: ref = make_node (ENUMERAL_TYPE); 9858: 9859: /* Give the type a default layout like unsigned int 9860: to avoid crashing if it does not get defined. */ 1.1.1.4 root 9861: TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); 1.1 root 9862: TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); 9863: TREE_UNSIGNED (ref) = 1; 9864: TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); 9865: TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); 9866: TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); 9867: 9868: /* Enable us to recognize when a type is created in class context. 9869: To do nested classes correctly, this should probably be cleared 9870: out when we leave this classes scope. Currently this in only 9871: done in `start_enum'. */ 9872: 9873: pushtag (name, ref); 9874: if (flag_cadillac) 9875: cadillac_start_enum (ref); 9876: } 9877: else if (tag_code == exception_type) 9878: { 9879: ref = make_lang_type (code); 9880: /* Enable us to recognize when an exception type is created in 9881: class context. To do nested classes correctly, this should 9882: probably be cleared out when we leave this class's scope. */ 9883: CLASSTYPE_DECLARED_EXCEPTION (ref) = 1; 9884: pushtag (name, ref); 9885: if (flag_cadillac) 9886: cadillac_start_struct (ref); 9887: } 9888: else 9889: { 9890: extern tree pending_vtables; 9891: struct binding_level *old_b = class_binding_level; 9892: int needs_writing; 9893: 9894: ref = make_lang_type (code); 9895: 9896: /* Record how to set the visibility of this class's 9897: virtual functions. If write_virtuals == 2 or 3, then 9898: inline virtuals are ``extern inline''. */ 9899: switch (write_virtuals) 9900: { 9901: case 0: 9902: case 1: 9903: needs_writing = 1; 9904: break; 9905: case 2: 9906: needs_writing = !! value_member (name, pending_vtables); 9907: break; 9908: case 3: 1.1.1.6 ! root 9909: needs_writing = ! CLASSTYPE_INTERFACE_ONLY (ref) ! 9910: && CLASSTYPE_INTERFACE_KNOWN (ref); 1.1 root 9911: break; 9912: default: 9913: needs_writing = 0; 9914: } 9915: 9916: CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing; 9917: 9918: #ifdef NONNESTED_CLASSES 9919: /* Class types don't nest the way enums do. */ 1.1.1.5 root 9920: class_binding_level = (struct binding_level *)0; 1.1 root 9921: #endif 9922: pushtag (name, ref); 9923: class_binding_level = old_b; 9924: 9925: if (flag_cadillac) 9926: cadillac_start_struct (ref); 9927: } 9928: } 9929: else 9930: { 9931: if (IS_AGGR_TYPE_CODE (code)) 9932: { 9933: if (IS_AGGR_TYPE (ref) 9934: && ((tag_code == exception_type) 9935: != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1))) 9936: { 1.1.1.6 ! root 9937: cp_error ("type `%T' is both exception and aggregate type", ref); 1.1 root 9938: CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type); 9939: } 9940: } 9941: 9942: /* If it no longer looks like a nested type, make sure it's 9943: in global scope. */ 9944: if (b == global_binding_level && !class_binding_level 9945: && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE) 9946: IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref); 9947: 9948: if (binfo) 9949: { 9950: tree tt1 = binfo; 9951: tree tt2 = TYPE_BINFO_BASETYPES (ref); 9952: 9953: if (TYPE_BINFO_BASETYPES (ref)) 9954: for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1)) 9955: if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i)))) 9956: { 1.1.1.6 ! root 9957: cp_error ("redeclaration of derivation chain of type `%#T'", ! 9958: ref); 1.1 root 9959: break; 9960: } 9961: 9962: if (tt1 == NULL_TREE) 9963: /* The user told us something we already knew. */ 9964: goto just_return; 9965: 9966: /* In C++, since these migrate into the global scope, we must 9967: build them on the permanent obstack. */ 9968: end_temporary_allocation (); 9969: } 9970: } 9971: 9972: if (binfo) 9973: { 9974: /* In the declaration `A : X, Y, ... Z' we mark all the types 9975: (A, X, Y, ..., Z) so we can check for duplicates. */ 9976: tree binfos; 9977: 9978: SET_CLASSTYPE_MARKED (ref); 9979: BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len); 9980: 9981: for (i = 0; binfo; binfo = TREE_CHAIN (binfo)) 9982: { 9983: /* The base of a derived struct is public. */ 9984: int via_public = (tag_code != class_type 9985: || TREE_PURPOSE (binfo) == (tree)visibility_public 9986: || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual); 1.1.1.4 root 9987: int via_protected = TREE_PURPOSE (binfo) == (tree)visibility_protected; 1.1 root 9988: int via_virtual = (TREE_PURPOSE (binfo) == (tree)visibility_private_virtual 9989: || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual 9990: || TREE_PURPOSE (binfo) == (tree)visibility_default_virtual); 9991: tree basetype = TREE_TYPE (TREE_VALUE (binfo)); 1.1.1.4 root 9992: tree base_binfo; 1.1 root 9993: 9994: GNU_xref_hier (IDENTIFIER_POINTER (name), 9995: IDENTIFIER_POINTER (TREE_VALUE (binfo)), 9996: via_public, via_virtual, 0); 9997: 9998: if (basetype && TREE_CODE (basetype) == TYPE_DECL) 9999: basetype = TREE_TYPE (basetype); 10000: if (!basetype || TREE_CODE (basetype) != RECORD_TYPE) 10001: { 10002: error ("base type `%s' fails to be a struct or class type", 10003: IDENTIFIER_POINTER (TREE_VALUE (binfo))); 10004: continue; 10005: } 1.1.1.5 root 10006: #if 1 10007: /* This code replaces similar code in layout_basetypes. */ 10008: else if (TYPE_SIZE (basetype) == NULL_TREE) 1.1 root 10009: { 1.1.1.6 ! root 10010: cp_error ("base class `%T' has incomplete type", basetype); 1.1 root 10011: continue; 10012: } 10013: #endif 10014: else 10015: { 10016: if (CLASSTYPE_MARKED (basetype)) 10017: { 10018: if (basetype == ref) 1.1.1.6 ! root 10019: cp_error ("recursive type `%T' undefined", basetype); 1.1 root 10020: else 1.1.1.6 ! root 10021: cp_error ("duplicate base type `%T' invalid", basetype); 1.1 root 10022: continue; 10023: } 10024: 1.1.1.4 root 10025: /* Note that the BINFO records which describe individual 10026: inheritances are *not* shared in the lattice! They 10027: cannot be shared because a given baseclass may be 1.1.1.5 root 10028: inherited with different `accessibility' by different 1.1.1.4 root 10029: derived classes. (Each BINFO record describing an 10030: individual inheritance contains flags which say what 1.1.1.5 root 10031: the `accessibility' of that particular inheritance is.) */ 1.1.1.4 root 10032: 10033: base_binfo = make_binfo (integer_zero_node, basetype, 10034: TYPE_BINFO_VTABLE (basetype), 10035: TYPE_BINFO_VIRTUALS (basetype), 0); 10036: 10037: TREE_VEC_ELT (binfos, i) = base_binfo; 10038: TREE_VIA_PUBLIC (base_binfo) = via_public; 10039: TREE_VIA_PROTECTED (base_binfo) = via_protected; 10040: TREE_VIA_VIRTUAL (base_binfo) = via_virtual; 1.1 root 10041: 10042: SET_CLASSTYPE_MARKED (basetype); 10043: #if 0 10044: /* XYZZY TEST VIRTUAL BASECLASSES */ 1.1.1.5 root 10045: if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE 1.1 root 10046: && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype) 10047: && via_virtual == 0) 10048: { 10049: warning ("making type `%s' a virtual baseclass", 10050: TYPE_NAME_STRING (basetype)); 10051: via_virtual = 1; 10052: } 10053: #endif 10054: /* We are free to modify these bits because they are meaningless 10055: at top level, and BASETYPE is a top-level type. */ 10056: if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) 10057: { 10058: TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; 10059: TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; 10060: } 10061: 10062: TYPE_GETS_ASSIGNMENT (ref) |= TYPE_GETS_ASSIGNMENT (basetype); 10063: TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype); 10064: TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype); 10065: TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype); 10066: CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype); 10067: i += 1; 10068: } 10069: } 10070: if (i) 10071: TREE_VEC_LENGTH (binfos) = i; 10072: else 10073: BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; 10074: 10075: if (i > 1) 10076: TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; 10077: else if (i == 1) 10078: TYPE_USES_MULTIPLE_INHERITANCE (ref) 10079: = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0))); 10080: if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) 10081: TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; 10082: 10083: /* Unmark all the types. */ 10084: while (--i >= 0) 10085: CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); 10086: CLEAR_CLASSTYPE_MARKED (ref); 10087: } 10088: 10089: just_return: 10090: 10091: /* Until the type is defined, tentatively accept whatever 10092: structure tag the user hands us. */ 10093: if (TYPE_SIZE (ref) == NULL_TREE 10094: && ref != current_class_type 10095: /* Have to check this, in case we have contradictory tag info. */ 10096: && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) 10097: { 10098: if (tag_code == class_type) 10099: CLASSTYPE_DECLARED_CLASS (ref) = 1; 10100: else if (tag_code == record_type) 10101: CLASSTYPE_DECLARED_CLASS (ref) = 0; 10102: } 10103: 10104: pop_obstacks (); 10105: 10106: return ref; 10107: } 10108: 1.1.1.5 root 10109: static tree current_local_enum = NULL_TREE; 10110: 1.1 root 10111: /* Begin compiling the definition of an enumeration type. 10112: NAME is its name (or null if anonymous). 10113: Returns the type object, as yet incomplete. 10114: Also records info about it so that build_enumerator 10115: may be used to declare the individual values as they are read. */ 10116: 10117: tree 10118: start_enum (name) 10119: tree name; 10120: { 1.1.1.5 root 10121: register tree enumtype = NULL_TREE; 1.1 root 10122: struct binding_level *b 10123: = (class_binding_level ? class_binding_level : current_binding_level); 10124: 10125: /* If this is the real definition for a previous forward reference, 10126: fill in the contents in the same object that used to be the 10127: forward reference. */ 10128: 1.1.1.5 root 10129: if (name != NULL_TREE) 1.1 root 10130: enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); 10131: 1.1.1.6 ! root 10132: if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) ! 10133: cp_error ("multiple definition of enum `%T'", enumtype); ! 10134: else 1.1 root 10135: { 10136: enumtype = make_node (ENUMERAL_TYPE); 10137: pushtag (name, enumtype); 10138: } 10139: 1.1.1.5 root 10140: if (current_class_type) 10141: TREE_ADDRESSABLE (b->tags) = 1; 10142: current_local_enum = NULL_TREE; 10143: 10144: if (TYPE_VALUES (enumtype) != NULL_TREE) 1.1.1.6 ! root 10145: /* Completely replace its old definition. ! 10146: The old enumerators remain defined, however. */ ! 10147: TYPE_VALUES (enumtype) = NULL_TREE; 1.1 root 10148: 10149: /* Initially, set up this enum as like `int' 10150: so that we can create the enumerators' declarations and values. 10151: Later on, the precision of the type may be changed and 10152: it may be laid out again. */ 10153: 10154: TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); 1.1.1.5 root 10155: TYPE_SIZE (enumtype) = NULL_TREE; 1.1 root 10156: fixup_unsigned_type (enumtype); 10157: 10158: /* We copy this value because enumerated type constants 10159: are really of the type of the enumerator, not integer_type_node. */ 10160: enum_next_value = copy_node (integer_zero_node); 10161: 10162: GNU_xref_decl (current_function_decl, enumtype); 10163: return enumtype; 10164: } 10165: 10166: /* After processing and defining all the values of an enumeration type, 10167: install their decls in the enumeration type and finish it off. 10168: ENUMTYPE is the type object and VALUES a list of name-value pairs. 10169: Returns ENUMTYPE. */ 10170: 10171: tree 10172: finish_enum (enumtype, values) 10173: register tree enumtype, values; 10174: { 1.1.1.6 ! root 10175: register tree pair, tem; 1.1.1.4 root 10176: register HOST_WIDE_INT maxvalue = 0; 10177: register HOST_WIDE_INT minvalue = 0; 10178: register HOST_WIDE_INT i; 1.1 root 10179: 10180: TYPE_VALUES (enumtype) = values; 10181: 10182: /* Calculate the maximum value of any enumerator in this type. */ 10183: 10184: if (values) 10185: { 10186: /* Speed up the main loop by performing some precalculations */ 10187: 1.1.1.4 root 10188: HOST_WIDE_INT value = TREE_INT_CST_LOW (TREE_VALUE (values)); 1.1 root 10189: TREE_TYPE (TREE_VALUE (values)) = enumtype; 10190: minvalue = maxvalue = value; 10191: 10192: for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) 10193: { 10194: value = TREE_INT_CST_LOW (TREE_VALUE (pair)); 10195: if (value > maxvalue) 10196: maxvalue = value; 10197: else if (value < minvalue) 10198: minvalue = value; 10199: TREE_TYPE (TREE_VALUE (pair)) = enumtype; 10200: } 10201: } 10202: 10203: if (flag_short_enums) 10204: { 10205: /* Determine the precision this type needs, lay it out, and define it. */ 10206: 10207: for (i = maxvalue; i; i >>= 1) 10208: TYPE_PRECISION (enumtype)++; 10209: 10210: if (!TYPE_PRECISION (enumtype)) 10211: TYPE_PRECISION (enumtype) = 1; 10212: 10213: /* Cancel the laying out previously done for the enum type, 10214: so that fixup_unsigned_type will do it over. */ 1.1.1.5 root 10215: TYPE_SIZE (enumtype) = NULL_TREE; 1.1 root 10216: 10217: fixup_unsigned_type (enumtype); 10218: } 10219: 10220: TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue; 10221: 10222: /* An enum can have some negative values; then it is signed. */ 10223: if (minvalue < 0) 10224: { 10225: TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue; 10226: TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1; 10227: TREE_UNSIGNED (enumtype) = 0; 10228: } 10229: if (flag_cadillac) 10230: cadillac_finish_enum (enumtype); 10231: 1.1.1.6 ! root 10232: /* Fix up all variant types of this enum type. */ ! 10233: for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem)) ! 10234: { ! 10235: TYPE_VALUES (tem) = TYPE_VALUES (enumtype); ! 10236: TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); ! 10237: TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); ! 10238: TYPE_SIZE (tem) = TYPE_SIZE (enumtype); ! 10239: TYPE_MODE (tem) = TYPE_MODE (enumtype); ! 10240: TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); ! 10241: TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); ! 10242: TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); ! 10243: } ! 10244: 1.1 root 10245: /* Finish debugging output for this type. */ 1.1.1.4 root 10246: #if 0 10247: /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging 10248: information should *not* be generated? I think not. */ 1.1 root 10249: if (! DECL_IGNORED_P (TYPE_NAME (enumtype))) 1.1.1.4 root 10250: #endif 1.1 root 10251: rest_of_type_compilation (enumtype, global_bindings_p ()); 10252: 10253: return enumtype; 10254: } 10255: 10256: /* Build and install a CONST_DECL for one value of the 10257: current enumeration type (one that was begun with start_enum). 10258: Return a tree-list containing the name and its value. 10259: Assignment of sequential values by default is handled here. */ 10260: 10261: tree 10262: build_enumerator (name, value) 10263: tree name, value; 10264: { 10265: tree decl, result; 10266: /* Change this to zero if we find VALUE is not shareable. */ 10267: int shareable = 1; 10268: 1.1.1.5 root 10269: /* Remove no-op casts from the value. */ 10270: if (value) 10271: STRIP_TYPE_NOPS (value); 10272: 1.1 root 10273: /* Validate and default VALUE. */ 1.1.1.5 root 10274: if (value != NULL_TREE) 1.1 root 10275: { 10276: if (TREE_READONLY_DECL_P (value)) 10277: { 10278: value = decl_constant_value (value); 10279: shareable = 0; 10280: } 10281: 1.1.1.6 ! root 10282: if (TREE_CODE (value) == INTEGER_CST) ! 10283: { ! 10284: value = default_conversion (value); ! 10285: constant_expression_warning (value); ! 10286: } ! 10287: else 1.1 root 10288: { 10289: error ("enumerator value for `%s' not integer constant", 10290: IDENTIFIER_POINTER (name)); 1.1.1.5 root 10291: value = NULL_TREE; 1.1 root 10292: } 10293: } 1.1.1.6 ! root 10294: 1.1 root 10295: /* The order of things is reversed here so that we 10296: can check for possible sharing of enum values, 10297: to keep that from happening. */ 10298: /* Default based on previous value. */ 1.1.1.5 root 10299: if (value == NULL_TREE) 1.1 root 10300: value = enum_next_value; 10301: 10302: /* Remove no-op casts from the value. */ 1.1.1.4 root 10303: if (value) 10304: STRIP_TYPE_NOPS (value); 1.1 root 10305: 10306: /* Make up for hacks in cp-lex.c. */ 10307: if (value == integer_zero_node) 10308: value = build_int_2 (0, 0); 10309: else if (value == integer_one_node) 10310: value = build_int_2 (1, 0); 10311: else if (TREE_CODE (value) == INTEGER_CST 10312: && (shareable == 0 10313: || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)) 10314: { 10315: value = copy_node (value); 10316: TREE_TYPE (value) = integer_type_node; 10317: } 10318: 10319: result = saveable_tree_cons (name, value, NULL_TREE); 10320: 10321: /* C++ associates enums with global, function, or class declarations. */ 10322: 1.1.1.6 ! root 10323: /* There are a number of cases we need to be aware of here: ! 10324: current_class_type current_function_decl ! 10325: * global enums NULL NULL ! 10326: * fn-local enum NULL SET ! 10327: * class-local enum SET NULL ! 10328: * class->fn->enum SET SET ! 10329: * fn->class->enum SET SET ! 10330: ! 10331: Those last two make life interesting. If it's a fn-local enum which is ! 10332: itself inside a class, we need the enum to go into the fn's decls (our ! 10333: second case below). But if it's a class-local enum and the class itself ! 10334: is inside a function, we need that enum to go into the decls for the ! 10335: class. To achieve this last goal, we must see if, when both ! 10336: current_class_decl and current_function_decl are set, the class was ! 10337: declared inside that function. If so, we know to put the enum into ! 10338: the class's scope. */ ! 10339: ! 10340: if ((current_class_type && ! current_function_decl) ! 10341: || (current_class_type && current_function_decl ! 10342: && TYPE_CONTEXT (current_class_type) == current_function_decl)) 1.1.1.5 root 10343: { 1.1.1.6 ! root 10344: /* This enum declaration is local to the class, so we must put ! 10345: it in that class's list of decls. */ 1.1.1.5 root 10346: decl = build_lang_field_decl (CONST_DECL, name, integer_type_node); 10347: DECL_INITIAL (decl) = value; 10348: TREE_READONLY (decl) = 1; 10349: pushdecl_class_level (decl); 10350: TREE_CHAIN (decl) = current_local_enum; 10351: current_local_enum = decl; 10352: } 1.1.1.6 ! root 10353: else ! 10354: { ! 10355: /* It's a global enum, or it's local to a function. (Note local to ! 10356: a function could mean local to a class method. */ ! 10357: decl = build_decl (CONST_DECL, name, integer_type_node); ! 10358: DECL_INITIAL (decl) = value; ! 10359: ! 10360: pushdecl (decl); ! 10361: GNU_xref_decl (current_function_decl, decl); ! 10362: } 1.1.1.5 root 10363: 1.1 root 10364: /* Set basis for default for next value. */ 10365: enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, 10366: integer_one_node, PLUS_EXPR); 10367: if (enum_next_value == integer_one_node) 10368: enum_next_value = copy_node (enum_next_value); 10369: 10370: return result; 10371: } 10372: 10373: tree 10374: grok_enum_decls (type, decl) 10375: tree type, decl; 10376: { 1.1.1.5 root 10377: tree d = current_local_enum; 10378: 10379: if (d == NULL_TREE) 1.1 root 10380: return decl; 1.1.1.5 root 10381: 10382: while (1) 1.1 root 10383: { 1.1.1.5 root 10384: TREE_TYPE (d) = type; 10385: if (TREE_CHAIN (d) == NULL_TREE) 10386: { 10387: TREE_CHAIN (d) = decl; 10388: break; 10389: } 10390: d = TREE_CHAIN (d); 1.1 root 10391: } 1.1.1.5 root 10392: 10393: decl = current_local_enum; 10394: current_local_enum = NULL_TREE; 10395: 1.1 root 10396: return decl; 10397: } 10398: 10399: /* Create the FUNCTION_DECL for a function definition. 10400: DECLSPECS and DECLARATOR are the parts of the declaration; 10401: they describe the function's name and the type it returns, 10402: but twisted together in a fashion that parallels the syntax of C. 10403: 10404: This function creates a binding context for the function body 10405: as well as setting up the FUNCTION_DECL in current_function_decl. 10406: 10407: Returns 1 on success. If the DECLARATOR is not suitable for a function 10408: (it defines a datum instead), we return 0, which tells 10409: yyparse to report a parse error. 10410: 10411: For C++, we must first check whether that datum makes any sense. 1.1.1.4 root 10412: For example, "class A local_a(1,2);" means that variable local_a 10413: is an aggregate of type A, which should have a constructor 1.1 root 10414: applied to it with the argument list [1, 2]. 10415: 10416: @@ There is currently no way to retrieve the storage 10417: @@ allocated to FUNCTION (or all of its parms) if we return 10418: @@ something we had previously. */ 10419: 10420: int 10421: start_function (declspecs, declarator, raises, pre_parsed_p) 10422: tree declarator, declspecs, raises; 10423: int pre_parsed_p; 10424: { 10425: extern tree EHS_decl; 10426: tree decl1, olddecl; 10427: tree ctype = NULL_TREE; 10428: tree fntype; 10429: tree restype; 1.1.1.4 root 10430: extern int have_extern_spec; 10431: extern int used_extern_spec; 10432: int doing_friend = 0; 1.1 root 10433: 10434: if (flag_handle_exceptions && EHS_decl == NULL_TREE) 10435: init_exception_processing_1 (); 10436: 10437: /* Sanity check. */ 1.1.1.4 root 10438: my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160); 10439: my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); 1.1 root 10440: 10441: /* Assume, until we see it does. */ 10442: current_function_returns_value = 0; 10443: current_function_returns_null = 0; 10444: warn_about_return_type = 0; 10445: current_extern_inline = 0; 10446: current_function_assigns_this = 0; 10447: current_function_just_assigned_this = 0; 10448: current_function_parms_stored = 0; 1.1.1.5 root 10449: original_result_rtx = NULL_RTX; 1.1 root 10450: current_function_obstack_index = 0; 10451: current_function_obstack_usage = 0; 10452: 10453: clear_temp_name (); 10454: 1.1.1.4 root 10455: /* This should only be done once on the top most decl. */ 10456: if (have_extern_spec && !used_extern_spec) 10457: { 10458: declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); 10459: used_extern_spec = 1; 10460: } 10461: 1.1 root 10462: if (pre_parsed_p) 10463: { 10464: decl1 = declarator; 1.1.1.6 ! root 10465: ! 10466: if (! DECL_ARGUMENTS (decl1) ! 10467: && !DECL_STATIC_FUNCTION_P (decl1) ! 10468: && DECL_CONTEXT (decl1) ! 10469: && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1))) ! 10470: && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1))))) ! 10471: { ! 10472: cp_error ("redeclaration of `%#D'", decl1); ! 10473: if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) ! 10474: cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); ! 10475: else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))) ! 10476: cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))); ! 10477: } ! 10478: 1.1 root 10479: last_function_parms = DECL_ARGUMENTS (decl1); 1.1.1.5 root 10480: last_function_parm_tags = NULL_TREE; 1.1 root 10481: fntype = TREE_TYPE (decl1); 10482: if (TREE_CODE (fntype) == METHOD_TYPE) 10483: ctype = TYPE_METHOD_BASETYPE (fntype); 10484: 1.1.1.4 root 10485: /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a 10486: class is in the (lexical) scope of the class in which it is 10487: defined. */ 10488: if (!ctype && DECL_FRIEND_P (decl1)) 10489: { 10490: ctype = TREE_TYPE (TREE_CHAIN (decl1)); 1.1.1.5 root 10491: 10492: /* CTYPE could be null here if we're dealing with a template; 10493: for example, `inline friend float foo()' inside a template 10494: will have no CTYPE set. */ 10495: if (ctype && TREE_CODE (ctype) != RECORD_TYPE) 1.1.1.4 root 10496: ctype = NULL_TREE; 10497: else 10498: doing_friend = 1; 10499: } 10500: 1.1 root 10501: if ( !(DECL_VINDEX (decl1) 10502: && write_virtuals >= 2 10503: && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype))) 1.1.1.4 root 10504: current_extern_inline = TREE_PUBLIC (decl1) && DECL_INLINE (decl1); 1.1 root 10505: 10506: raises = TYPE_RAISES_EXCEPTIONS (fntype); 10507: 10508: /* In a fcn definition, arg types must be complete. */ 10509: require_complete_types_for_parms (last_function_parms); 10510: } 10511: else 10512: { 10513: decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises); 10514: /* If the declarator is not suitable for a function definition, 10515: cause a syntax error. */ 1.1.1.5 root 10516: if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; 1.1 root 10517: 10518: fntype = TREE_TYPE (decl1); 10519: 10520: restype = TREE_TYPE (fntype); 1.1.1.6 ! root 10521: if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype) 1.1 root 10522: && ! CLASSTYPE_GOT_SEMICOLON (restype)) 10523: { 1.1.1.6 ! root 10524: cp_error ("semicolon missing after declaration of `%#T'", restype); 1.1 root 10525: shadow_tag (build_tree_list (NULL_TREE, restype)); 10526: CLASSTYPE_GOT_SEMICOLON (restype) = 1; 10527: if (TREE_CODE (fntype) == FUNCTION_TYPE) 10528: fntype = build_function_type (integer_type_node, 10529: TYPE_ARG_TYPES (fntype)); 10530: else 1.1.1.2 root 10531: fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), 1.1 root 10532: integer_type_node, 10533: TYPE_ARG_TYPES (fntype)); 10534: TREE_TYPE (decl1) = fntype; 10535: } 10536: 10537: if (TREE_CODE (fntype) == METHOD_TYPE) 10538: ctype = TYPE_METHOD_BASETYPE (fntype); 10539: else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4 10540: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main") 10541: && DECL_CONTEXT (decl1) == NULL_TREE) 10542: { 1.1.1.4 root 10543: /* If this doesn't return integer_type, complain. */ 10544: if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) 1.1 root 10545: { 10546: warning ("return type for `main' changed to integer type"); 10547: TREE_TYPE (decl1) = fntype = default_function_type; 10548: } 10549: warn_about_return_type = 0; 10550: } 10551: } 10552: 10553: /* Warn if function was previously implicitly declared 10554: (but not if we warned then). */ 1.1.1.5 root 10555: if (! warn_implicit 10556: && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) 1.1.1.6 ! root 10557: cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); 1.1 root 10558: 10559: current_function_decl = decl1; 10560: 10561: if (flag_cadillac) 10562: cadillac_start_function (decl1); 10563: else 10564: announce_function (decl1); 10565: 1.1.1.5 root 10566: if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE) 1.1 root 10567: { 10568: if (IS_AGGR_TYPE (TREE_TYPE (fntype))) 10569: error_with_aggr_type (TREE_TYPE (fntype), 10570: "return-type `%s' is an incomplete type"); 10571: else 10572: error ("return-type is an incomplete type"); 10573: 10574: /* Make it return void instead, but don't change the 10575: type of the DECL_RESULT, in case we have a named return value. */ 10576: if (ctype) 10577: TREE_TYPE (decl1) 1.1.1.5 root 10578: = build_cplus_method_type (build_type_variant (ctype, 10579: TREE_READONLY (decl1), 10580: TREE_SIDE_EFFECTS (decl1)), 1.1 root 10581: void_type_node, 10582: FUNCTION_ARG_CHAIN (decl1)); 10583: else 10584: TREE_TYPE (decl1) 10585: = build_function_type (void_type_node, 10586: TYPE_ARG_TYPES (TREE_TYPE (decl1))); 10587: DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype)); 10588: } 10589: 10590: if (warn_about_return_type) 10591: warning ("return-type defaults to `int'"); 10592: 10593: /* Make the init_value nonzero so pushdecl knows this is not tentative. 10594: error_mark_node is replaced below (in poplevel) with the BLOCK. */ 10595: DECL_INITIAL (decl1) = error_mark_node; 10596: 10597: /* Didn't get anything from C. */ 1.1.1.5 root 10598: olddecl = NULL_TREE; 1.1 root 10599: 10600: /* This function exists in static storage. 10601: (This does not mean `static' in the C sense!) */ 10602: TREE_STATIC (decl1) = 1; 10603: 1.1.1.3 root 10604: /* If this function belongs to an interface, it is public. 10605: If it belongs to someone else's interface, it is also external. 1.1 root 10606: It doesn't matter whether it's inline or not. */ 10607: if (interface_unknown == 0) 10608: { 1.1.1.3 root 10609: TREE_PUBLIC (decl1) = 1; 1.1.1.5 root 10610: DECL_EXTERNAL (decl1) = (interface_only 10611: || (DECL_INLINE (decl1) 10612: && ! flag_implement_inlines)); 1.1 root 10613: } 10614: else 10615: /* This is a definition, not a reference. 1.1.1.4 root 10616: So normally clear DECL_EXTERNAL. 1.1 root 10617: However, `extern inline' acts like a declaration except for 1.1.1.4 root 10618: defining how to inline. So set DECL_EXTERNAL in that case. */ 10619: DECL_EXTERNAL (decl1) = current_extern_inline; 1.1 root 10620: 1.1.1.6 ! root 10621: /* Now see if this is the implementation of a declared function. */ 1.1.1.5 root 10622: if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus 10623: && !DECL_CONTEXT (decl1)) 1.1 root 10624: { 10625: olddecl = lookup_name_current_level (DECL_NAME (decl1)); 10626: if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL) 10627: olddecl = NULL_TREE; 10628: if (olddecl && DECL_NAME (decl1) != DECL_NAME (olddecl)) 10629: { 10630: /* Collision between user and internal naming scheme. */ 10631: olddecl = lookup_name_current_level (DECL_ASSEMBLER_NAME (decl1)); 10632: if (olddecl == NULL_TREE) 10633: olddecl = decl1; 10634: } 10635: if (olddecl && olddecl != decl1 10636: && DECL_NAME (decl1) == DECL_NAME (olddecl)) 10637: { 10638: if (TREE_CODE (olddecl) == FUNCTION_DECL 1.1.1.5 root 10639: && decls_match (decl1, olddecl)) 1.1 root 10640: { 10641: olddecl = DECL_MAIN_VARIANT (olddecl); 10642: /* The following copy is needed to handle forcing a function's 10643: linkage to obey the linkage of the original decl. */ 10644: DECL_ASSEMBLER_NAME (decl1) = DECL_ASSEMBLER_NAME (olddecl); 10645: DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl); 1.1.1.6 ! root 10646: if (! DECL_BUILT_IN (olddecl) && DECL_INITIAL (olddecl)) 1.1 root 10647: redeclaration_error_message (decl1, olddecl); 1.1.1.6 ! root 10648: if (duplicate_decls (decl1, olddecl)) ! 10649: decl1 = olddecl; ! 10650: else ! 10651: olddecl = NULL_TREE; 1.1 root 10652: } 10653: else 10654: olddecl = NULL_TREE; 10655: } 10656: } 10657: 10658: /* Record the decl so that the function name is defined. 10659: If we already have a decl for this name, and it is a FUNCTION_DECL, 10660: use the old decl. */ 10661: 10662: if (olddecl) 10663: current_function_decl = olddecl; 10664: else if (pre_parsed_p == 0) 10665: { 10666: current_function_decl = pushdecl (decl1); 10667: if (TREE_CODE (current_function_decl) == TREE_LIST) 10668: { 10669: /* @@ revert to modified original declaration. */ 10670: decl1 = DECL_MAIN_VARIANT (decl1); 10671: current_function_decl = decl1; 10672: } 10673: else 10674: { 10675: decl1 = current_function_decl; 10676: DECL_MAIN_VARIANT (decl1) = decl1; 10677: } 10678: fntype = TREE_TYPE (decl1); 10679: } 10680: else 10681: current_function_decl = decl1; 10682: 10683: if (DECL_OVERLOADED (decl1)) 10684: decl1 = push_overloaded_decl (decl1, 1); 10685: 1.1.1.5 root 10686: if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) 1.1 root 10687: { 10688: if (TREE_CODE (fntype) == METHOD_TYPE) 10689: TREE_TYPE (decl1) = fntype 10690: = build_function_type (TREE_TYPE (fntype), 10691: TREE_CHAIN (TYPE_ARG_TYPES (fntype))); 10692: last_function_parms = TREE_CHAIN (last_function_parms); 10693: DECL_ARGUMENTS (decl1) = last_function_parms; 1.1.1.5 root 10694: ctype = NULL_TREE; 1.1 root 10695: } 10696: restype = TREE_TYPE (fntype); 10697: 10698: pushlevel (0); 10699: current_binding_level->parm_flag = 1; 10700: 10701: /* Save the parm names or decls from this function's declarator 10702: where store_parm_decls will find them. */ 10703: current_function_parms = last_function_parms; 10704: current_function_parm_tags = last_function_parm_tags; 10705: 10706: GNU_xref_function (decl1, current_function_parms); 10707: 10708: make_function_rtl (decl1); 10709: 10710: if (ctype) 10711: { 1.1.1.6 ! root 10712: #if NEW_CLASS_SCOPING ! 10713: push_nested_class (ctype, 1); ! 10714: #else 1.1 root 10715: pushclass (ctype, 1); 1.1.1.6 ! root 10716: #endif 1.1.1.4 root 10717: 10718: /* If we're compiling a friend function, neither of the variables 10719: current_class_decl nor current_class_type will have values. */ 10720: if (! doing_friend) 10721: { 10722: /* We know that this was set up by `grokclassfn'. 10723: We do not wait until `store_parm_decls', since evil 10724: parse errors may never get us to that point. Here 10725: we keep the consistency between `current_class_type' 10726: and `current_class_decl'. */ 10727: current_class_decl = last_function_parms; 10728: my_friendly_assert (current_class_decl != NULL_TREE 10729: && TREE_CODE (current_class_decl) == PARM_DECL, 162); 10730: if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE) 10731: { 10732: tree variant = TREE_TYPE (TREE_TYPE (current_class_decl)); 10733: if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE) 10734: { 10735: /* Can't call build_indirect_ref here, because it has special 10736: logic to return C_C_D given this argument. */ 10737: C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl); 10738: CLASSTYPE_INST_VAR (ctype) = C_C_D; 10739: } 10740: else 10741: { 10742: C_C_D = CLASSTYPE_INST_VAR (ctype); 10743: /* `current_class_decl' is different for every 10744: function we compile. */ 10745: TREE_OPERAND (C_C_D, 0) = current_class_decl; 10746: } 10747: TREE_READONLY (C_C_D) = TYPE_READONLY (variant); 10748: TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant); 10749: TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant); 1.1 root 10750: } 10751: else 1.1.1.4 root 10752: C_C_D = current_class_decl; 1.1 root 10753: } 10754: } 10755: else 10756: { 10757: if (DECL_STATIC_FUNCTION_P (decl1)) 1.1.1.6 ! root 10758: #if NEW_CLASS_SCOPING ! 10759: push_nested_class (DECL_CONTEXT (decl1), 2); ! 10760: #else 1.1 root 10761: pushclass (DECL_CONTEXT (decl1), 2); 1.1.1.6 ! root 10762: #endif 1.1 root 10763: else 10764: push_memoized_context (0, 1); 10765: } 10766: 10767: /* Allocate further tree nodes temporarily during compilation 10768: of this function only. Tiemann moved up here from bottom of fn. */ 10769: temporary_allocation (); 10770: 10771: /* Promote the value to int before returning it. */ 1.1.1.4 root 10772: if (C_PROMOTING_INTEGER_TYPE_P (restype)) 10773: { 10774: /* It retains unsignedness if traditional or if it isn't 10775: really getting wider. */ 10776: if (TREE_UNSIGNED (restype) 10777: && (flag_traditional 10778: || TYPE_PRECISION (restype) 10779: == TYPE_PRECISION (integer_type_node))) 10780: restype = unsigned_type_node; 10781: else 10782: restype = integer_type_node; 10783: } 1.1 root 10784: if (DECL_RESULT (decl1) == NULL_TREE) 10785: DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype); 10786: 10787: if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1))) 10788: { 10789: dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 10790: ctor_label = NULL_TREE; 10791: } 10792: else 10793: { 10794: dtor_label = NULL_TREE; 10795: if (DECL_CONSTRUCTOR_P (decl1)) 10796: ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 10797: } 10798: 10799: /* If this fcn was already referenced via a block-scope `extern' decl 10800: (or an implicit decl), propagate certain information about the usage. */ 10801: if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) 10802: TREE_ADDRESSABLE (decl1) = 1; 10803: 10804: return 1; 10805: } 10806: 10807: /* Store the parameter declarations into the current function declaration. 10808: This is called after parsing the parameter declarations, before 10809: digesting the body of the function. 10810: 10811: Also install to binding contour return value identifier, if any. */ 10812: 10813: void 10814: store_parm_decls () 10815: { 10816: register tree fndecl = current_function_decl; 10817: register tree parm; 10818: int parms_have_cleanups = 0; 10819: tree eh_decl; 10820: 10821: /* This is either a chain of PARM_DECLs (when a prototype is used). */ 10822: tree specparms = current_function_parms; 10823: 10824: /* This is a list of types declared among parms in a prototype. */ 10825: tree parmtags = current_function_parm_tags; 10826: 10827: /* This is a chain of any other decls that came in among the parm 10828: declarations. If a parm is declared with enum {foo, bar} x; 10829: then CONST_DECLs for foo and bar are put here. */ 1.1.1.5 root 10830: tree nonparms = NULL_TREE; 1.1 root 10831: 10832: if (current_binding_level == global_binding_level) 10833: fatal ("parse errors have confused me too much"); 10834: 10835: /* Initialize RTL machinery. */ 10836: init_function_start (fndecl, input_filename, lineno); 10837: 1.1.1.3 root 10838: /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ 10839: declare_function_name (); 10840: 1.1 root 10841: /* Create a binding level for the parms. */ 10842: expand_start_bindings (0); 10843: 10844: /* Prepare to catch raises, if appropriate. */ 10845: if (flag_handle_exceptions) 10846: { 10847: /* Get this cleanup to be run last, since it 10848: is a call to `longjmp'. */ 10849: setup_exception_throw_decl (); 10850: eh_decl = current_binding_level->names; 10851: current_binding_level->names = TREE_CHAIN (current_binding_level->names); 10852: } 10853: if (flag_handle_exceptions) 10854: expand_start_try (integer_one_node, 0, 1); 10855: 1.1.1.5 root 10856: if (specparms != NULL_TREE) 1.1 root 10857: { 10858: /* This case is when the function was defined with an ANSI prototype. 10859: The parms already have decls, so we need not do anything here 10860: except record them as in effect 10861: and complain if any redundant old-style parm decls were written. */ 10862: 10863: register tree next; 10864: 10865: /* Must clear this because it might contain TYPE_DECLs declared 10866: at class level. */ 10867: storedecls (NULL_TREE); 10868: for (parm = nreverse (specparms); parm; parm = next) 10869: { 10870: next = TREE_CHAIN (parm); 10871: if (TREE_CODE (parm) == PARM_DECL) 10872: { 10873: tree cleanup = maybe_build_cleanup (parm); 1.1.1.5 root 10874: if (DECL_NAME (parm) == NULL_TREE) 1.1 root 10875: { 10876: #if 0 1.1.1.6 ! root 10877: cp_error_at ("parameter name omitted", parm); 1.1 root 10878: #else 10879: /* for C++, this is not an error. */ 10880: pushdecl (parm); 10881: #endif 10882: } 1.1.1.4 root 10883: else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) 1.1.1.6 ! root 10884: cp_error ("parameter `%D' declared void", parm); 1.1 root 10885: else 10886: { 10887: /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. 10888: A parameter is assumed not to have any side effects. 10889: If this should change for any reason, then this 10890: will have to wrap the bashed reference type in a save_expr. 10891: 10892: Also, if the parameter type is declared to be an X 10893: and there is an X(X&) constructor, we cannot lay it 10894: into the stack (any more), so we make this parameter 10895: look like it is really of reference type. Functions 10896: which pass parameters to this function will know to 10897: create a temporary in their frame, and pass a reference 10898: to that. */ 10899: 10900: if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE 10901: && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) 10902: SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); 10903: 10904: pushdecl (parm); 10905: } 10906: if (cleanup) 10907: { 10908: expand_decl (parm); 10909: expand_decl_cleanup (parm, cleanup); 10910: parms_have_cleanups = 1; 10911: } 10912: } 10913: else 10914: { 10915: /* If we find an enum constant or a type tag, 10916: put it aside for the moment. */ 1.1.1.5 root 10917: TREE_CHAIN (parm) = NULL_TREE; 1.1 root 10918: nonparms = chainon (nonparms, parm); 10919: } 10920: } 10921: 10922: /* Get the decls in their original chain order 10923: and record in the function. This is all and only the 10924: PARM_DECLs that were pushed into scope by the loop above. */ 10925: DECL_ARGUMENTS (fndecl) = getdecls (); 10926: 10927: storetags (chainon (parmtags, gettags ())); 10928: } 10929: else 1.1.1.5 root 10930: DECL_ARGUMENTS (fndecl) = NULL_TREE; 1.1 root 10931: 10932: /* Now store the final chain of decls for the arguments 10933: as the decl-chain of the current lexical scope. 10934: Put the enumerators in as well, at the front so that 10935: DECL_ARGUMENTS is not modified. */ 10936: 10937: storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); 10938: 10939: /* Initialize the RTL code for the function. */ 1.1.1.5 root 10940: DECL_SAVED_INSNS (fndecl) = NULL_RTX; 1.1 root 10941: expand_function_start (fndecl, parms_have_cleanups); 10942: 10943: if (flag_handle_exceptions) 10944: { 1.1.1.2 root 10945: /* Make the throw decl visible at this level, just 1.1 root 10946: not in the way of the parameters. */ 10947: pushdecl (eh_decl); 10948: expand_decl_init (eh_decl); 10949: } 10950: 10951: /* Create a binding contour which can be used to catch 10952: cleanup-generated temporaries. Also, if the return value needs or 10953: has initialization, deal with that now. */ 10954: if (parms_have_cleanups) 10955: { 10956: pushlevel (0); 10957: expand_start_bindings (0); 10958: } 10959: 10960: current_function_parms_stored = 1; 10961: 10962: if (flag_gc) 10963: { 10964: maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node); 10965: expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup); 10966: } 10967: 10968: /* If this function is `main', emit a call to `__main' 10969: to run global initializers, etc. */ 10970: if (DECL_NAME (fndecl) 10971: && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 10972: && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 10973: && DECL_CONTEXT (fndecl) == NULL_TREE) 10974: { 10975: expand_main_function (); 10976: 10977: if (flag_gc) 10978: expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE), 10979: 0, VOIDmode, 0); 10980: 10981: if (flag_dossier) 10982: output_builtin_tdesc_entries (); 10983: } 10984: } 10985: 10986: /* Bind a name and initialization to the return value of 10987: the current function. */ 10988: void 10989: store_return_init (return_id, init) 10990: tree return_id, init; 10991: { 10992: tree decl = DECL_RESULT (current_function_decl); 10993: 10994: if (pedantic) 1.1.1.2 root 10995: /* Give this error as many times as there are occurrences, 1.1 root 10996: so that users can use Emacs compilation buffers to find 10997: and fix all such places. */ 10998: error ("ANSI C++ does not permit named return values"); 10999: 11000: if (return_id != NULL_TREE) 11001: { 1.1.1.5 root 11002: if (DECL_NAME (decl) == NULL_TREE) 1.1 root 11003: { 11004: DECL_NAME (decl) = return_id; 11005: DECL_ASSEMBLER_NAME (decl) = return_id; 11006: } 11007: else 11008: error ("return identifier `%s' already in place", 11009: IDENTIFIER_POINTER (DECL_NAME (decl))); 11010: } 11011: 11012: /* Can't let this happen for constructors. */ 11013: if (DECL_CONSTRUCTOR_P (current_function_decl)) 11014: { 11015: error ("can't redefine default return value for constructors"); 11016: return; 11017: } 11018: 11019: /* If we have a named return value, put that in our scope as well. */ 1.1.1.5 root 11020: if (DECL_NAME (decl) != NULL_TREE) 1.1 root 11021: { 11022: /* If this named return value comes in a register, 11023: put it in a pseudo-register. */ 1.1.1.4 root 11024: if (DECL_REGISTER (decl)) 1.1 root 11025: { 11026: original_result_rtx = DECL_RTL (decl); 1.1.1.4 root 11027: DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); 1.1 root 11028: } 11029: 11030: /* Let `finish_decl' know that this initializer is ok. */ 11031: DECL_INITIAL (decl) = init; 11032: pushdecl (decl); 11033: finish_decl (decl, init, 0, 0); 11034: } 11035: } 11036: 11037: /* Generate code for default X(X&) constructor. */ 11038: static void 11039: build_default_constructor (fndecl) 11040: tree fndecl; 11041: { 11042: int i = CLASSTYPE_N_BASECLASSES (current_class_type); 11043: tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); 11044: tree fields = TYPE_FIELDS (current_class_type); 11045: tree binfos = TYPE_BINFO_BASETYPES (current_class_type); 11046: 11047: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 11048: parm = TREE_CHAIN (parm); 11049: parm = DECL_REFERENCE_SLOT (parm); 11050: 11051: while (--i >= 0) 11052: { 11053: tree basetype = TREE_VEC_ELT (binfos, i); 11054: if (TYPE_GETS_INIT_REF (basetype)) 11055: { 11056: tree name = TYPE_NAME (basetype); 11057: if (TREE_CODE (name) == TYPE_DECL) 11058: name = DECL_NAME (name); 11059: current_base_init_list = tree_cons (name, parm, current_base_init_list); 11060: } 11061: } 11062: for (; fields; fields = TREE_CHAIN (fields)) 11063: { 11064: tree name, init; 11065: if (TREE_STATIC (fields)) 11066: continue; 11067: if (TREE_CODE (fields) != FIELD_DECL) 11068: continue; 11069: if (DECL_NAME (fields)) 11070: { 11071: if (VFIELD_NAME_P (DECL_NAME (fields))) 11072: continue; 11073: if (VBASE_NAME_P (DECL_NAME (fields))) 11074: continue; 11075: 11076: /* True for duplicate members. */ 11077: if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields) 11078: continue; 11079: } 11080: 11081: init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields); 1.1.1.6 ! root 11082: init = build_tree_list (NULL_TREE, init); 1.1 root 11083: 11084: current_member_init_list 1.1.1.6 ! root 11085: = tree_cons (DECL_NAME (fields), init, current_member_init_list); 1.1 root 11086: } 11087: } 11088: 11089: 1.1.1.6 ! root 11090: /* Get the binfo associated with the vfield. */ ! 11091: ! 11092: tree ! 11093: get_binfo_from_vfield (vfield) ! 11094: tree vfield; ! 11095: { ! 11096: if (VF_BINFO_VALUE (vfield)) ! 11097: return VF_BINFO_VALUE (vfield); ! 11098: /* Not sure where it is. maybe get_binfo on ! 11099: VF_BASETYPE_VALUE (vfield), VF_DERIVED_VALUE (vfield)... */ ! 11100: my_friendly_abort (350); ! 11101: return NULL_TREE; ! 11102: } ! 11103: 1.1 root 11104: /* Finish up a function declaration and compile that function 11105: all the way to assembler language output. The free the storage 11106: for the function definition. 11107: 11108: This is called after parsing the body of the function definition. 11109: LINENO is the current line number. 11110: 11111: C++: CALL_POPLEVEL is non-zero if an extra call to poplevel 11112: (and expand_end_bindings) must be made to take care of the binding 11113: contour for the base initializers. This is only relevant for 11114: constructors. */ 11115: 11116: void 11117: finish_function (lineno, call_poplevel) 11118: int lineno; 11119: int call_poplevel; 11120: { 11121: register tree fndecl = current_function_decl; 1.1.1.5 root 11122: tree fntype, ctype = NULL_TREE; 1.1.1.4 root 11123: rtx head, last_parm_insn, mark; 1.1 root 11124: extern int sets_exception_throw_decl; 11125: /* Label to use if this function is supposed to return a value. */ 1.1.1.5 root 11126: tree no_return_label = NULL_TREE; 1.1.1.6 ! root 11127: tree decls = NULL_TREE; 1.1.1.5 root 11128: 11129: /* When we get some parse errors, we can end up without a 11130: current_function_decl, so cope. */ 11131: if (fndecl == NULL_TREE) 11132: return; 11133: 11134: fntype = TREE_TYPE (fndecl); 1.1 root 11135: 11136: /* TREE_READONLY (fndecl) = 1; 11137: This caused &foo to be of type ptr-to-const-function 11138: which then got a warning when stored in a ptr-to-function variable. */ 11139: 11140: /* This happens on strange parse errors. */ 11141: if (! current_function_parms_stored) 11142: { 11143: call_poplevel = 0; 11144: store_parm_decls (); 11145: } 11146: 1.1.1.4 root 11147: if (write_symbols != NO_DEBUG && TREE_CODE (fntype) != METHOD_TYPE) 1.1 root 11148: { 11149: tree ttype = target_type (fntype); 11150: tree parmdecl; 11151: 11152: if (IS_AGGR_TYPE (ttype)) 11153: /* Let debugger know it should output info for this type. */ 11154: note_debug_info_needed (ttype); 11155: 11156: for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) 11157: { 11158: ttype = target_type (TREE_TYPE (parmdecl)); 11159: if (IS_AGGR_TYPE (ttype)) 11160: /* Let debugger know it should output info for this type. */ 11161: note_debug_info_needed (ttype); 11162: } 11163: } 11164: 11165: /* Clean house because we will need to reorder insns here. */ 11166: do_pending_stack_adjust (); 11167: 11168: if (dtor_label) 11169: { 11170: tree binfo = TYPE_BINFO (current_class_type); 11171: tree cond = integer_one_node; 11172: tree exprstmt, vfields; 11173: tree in_charge_node = lookup_name (in_charge_identifier, 0); 1.1.1.4 root 11174: tree virtual_size; 1.1 root 11175: int ok_to_optimize_dtor = 0; 11176: 11177: if (current_function_assigns_this) 11178: cond = build (NE_EXPR, integer_type_node, 11179: current_class_decl, integer_zero_node); 11180: else 11181: { 11182: int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); 11183: 11184: /* If this destructor is empty, then we don't need to check 11185: whether `this' is NULL in some cases. */ 11186: mark = get_last_insn (); 1.1.1.4 root 11187: last_parm_insn = get_first_nonparm_insn (); 1.1 root 11188: 11189: if ((flag_this_is_variable & 1) == 0) 11190: ok_to_optimize_dtor = 1; 11191: else if (mark == last_parm_insn) 11192: ok_to_optimize_dtor 11193: = (n_baseclasses == 0 11194: || (n_baseclasses == 1 11195: && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); 11196: } 11197: 11198: /* These initializations might go inline. Protect 11199: the binding level of the parms. */ 11200: pushlevel (0); 1.1.1.6 ! root 11201: expand_start_bindings (0); 1.1 root 11202: 11203: if (current_function_assigns_this) 11204: { 11205: current_function_assigns_this = 0; 11206: current_function_just_assigned_this = 0; 11207: } 11208: 11209: /* Generate the code to call destructor on base class. 11210: If this destructor belongs to a class with virtual 11211: functions, then set the virtual function table 11212: pointer to represent the type of our base class. */ 11213: 11214: /* This side-effect makes call to `build_delete' generate the 11215: code we have to have at the end of this destructor. */ 11216: TYPE_HAS_DESTRUCTOR (current_class_type) = 0; 11217: 11218: /* These are two cases where we cannot delegate deletion. */ 11219: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) 11220: || TREE_GETS_DELETE (current_class_type)) 11221: exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node, 1.1.1.6 ! root 11222: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); 1.1 root 11223: else 11224: exprstmt = build_delete (current_class_type, C_C_D, in_charge_node, 1.1.1.6 ! root 11225: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); 1.1 root 11226: 11227: /* If we did not assign to this, then `this' is non-zero at 11228: the end of a destructor. As a special optimization, don't 11229: emit test if this is an empty destructor. If it does nothing, 11230: it does nothing. If it calls a base destructor, the base 11231: destructor will perform the test. */ 11232: 11233: if (exprstmt != error_mark_node 11234: && (TREE_CODE (exprstmt) != NOP_EXPR 11235: || TREE_OPERAND (exprstmt, 0) != integer_zero_node 11236: || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) 11237: { 11238: expand_label (dtor_label); 11239: if (cond != integer_one_node) 11240: expand_start_cond (cond, 0); 11241: if (exprstmt != void_zero_node) 11242: /* Don't call `expand_expr_stmt' if we're not going to do 11243: anything, since -Wall will give a diagnostic. */ 11244: expand_expr_stmt (exprstmt); 11245: 11246: /* Run destructor on all virtual baseclasses. */ 11247: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 11248: { 11249: tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); 11250: expand_start_cond (build (BIT_AND_EXPR, integer_type_node, 11251: in_charge_node, integer_two_node), 0); 11252: while (vbases) 11253: { 11254: if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) 11255: { 11256: tree ptr = convert_pointer_to_vbase (vbases, current_class_decl); 11257: expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)), 11258: ptr, integer_zero_node, 1.1.1.6 ! root 11259: LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0)); 1.1 root 11260: } 11261: vbases = TREE_CHAIN (vbases); 11262: } 11263: expand_end_cond (); 11264: } 11265: 11266: do_pending_stack_adjust (); 11267: if (cond != integer_one_node) 11268: expand_end_cond (); 11269: } 11270: 11271: TYPE_HAS_DESTRUCTOR (current_class_type) = 1; 11272: 1.1.1.4 root 11273: virtual_size = c_sizeof (current_class_type); 11274: 1.1 root 11275: /* At the end, call delete if that's what's requested. */ 11276: if (TREE_GETS_DELETE (current_class_type)) 11277: /* This NOP_EXPR means we are in a static call context. */ 1.1.1.4 root 11278: exprstmt = 11279: build_method_call 11280: (build1 (NOP_EXPR, 11281: TYPE_POINTER_TO (current_class_type), error_mark_node), 11282: ansi_opname[(int) DELETE_EXPR], 11283: tree_cons (NULL_TREE, current_class_decl, 11284: build_tree_list (NULL_TREE, virtual_size)), 11285: NULL_TREE, LOOKUP_NORMAL); 1.1 root 11286: else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 1.1.1.4 root 11287: exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0, 11288: virtual_size); 1.1 root 11289: else 1.1.1.5 root 11290: exprstmt = NULL_TREE; 1.1 root 11291: 11292: if (exprstmt) 11293: { 11294: cond = build (BIT_AND_EXPR, integer_type_node, 11295: in_charge_node, integer_one_node); 11296: expand_start_cond (cond, 0); 11297: expand_expr_stmt (exprstmt); 11298: expand_end_cond (); 11299: } 11300: 11301: /* End of destructor. */ 1.1.1.6 ! root 11302: expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0); ! 11303: poplevel (2, 0, 0); /* XXX change to 1 */ 1.1 root 11304: 11305: /* Back to the top of destructor. */ 11306: /* Dont execute destructor code if `this' is NULL. */ 11307: mark = get_last_insn (); 1.1.1.4 root 11308: last_parm_insn = get_first_nonparm_insn (); 1.1.1.5 root 11309: if (last_parm_insn == NULL_RTX) 1.1.1.4 root 11310: last_parm_insn = mark; 11311: else 11312: last_parm_insn = previous_insn (last_parm_insn); 1.1 root 11313: 11314: /* Make all virtual function table pointers point to CURRENT_CLASS_TYPE's 11315: virtual function tables. */ 11316: if (CLASSTYPE_VFIELDS (current_class_type)) 11317: { 11318: for (vfields = CLASSTYPE_VFIELDS (current_class_type); 11319: TREE_CHAIN (vfields); 11320: vfields = TREE_CHAIN (vfields)) 1.1.1.4 root 11321: { 11322: tree vf_decl = current_class_decl; 11323: /* ??? This may need to be a loop if there are multiple 11324: levels of replication. */ 11325: if (VF_BINFO_VALUE (vfields)) 11326: vf_decl = convert_pointer_to (VF_BINFO_VALUE (vfields), vf_decl); 11327: if (vf_decl != error_mark_node) 1.1.1.5 root 11328: { 11329: expand_expr_stmt (build_virtual_init (binfo, 1.1.1.6 ! root 11330: get_binfo_from_vfield (vfields), 1.1.1.5 root 11331: vf_decl)); 11332: } 1.1.1.4 root 11333: } 1.1 root 11334: expand_expr_stmt (build_virtual_init (binfo, binfo, 11335: current_class_decl)); 11336: } 11337: if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) 11338: expand_expr_stmt (build_vbase_vtables_init (binfo, binfo, 11339: C_C_D, current_class_decl, 0)); 11340: if (! ok_to_optimize_dtor) 11341: { 1.1.1.5 root 11342: cond = build_binary_op (NE_EXPR, 11343: current_class_decl, integer_zero_node, 1); 1.1 root 11344: expand_start_cond (cond, 0); 11345: } 11346: if (mark != get_last_insn ()) 11347: reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn); 11348: if (! ok_to_optimize_dtor) 1.1.1.4 root 11349: expand_end_cond (); 1.1 root 11350: } 11351: else if (current_function_assigns_this) 11352: { 11353: /* Does not need to call emit_base_init, because 11354: that is done (if needed) just after assignment to this 11355: is seen. */ 11356: 11357: if (DECL_CONSTRUCTOR_P (current_function_decl)) 11358: { 11359: expand_label (ctor_label); 11360: ctor_label = NULL_TREE; 11361: 11362: if (call_poplevel) 11363: { 1.1.1.6 ! root 11364: decls = getdecls (); 1.1 root 11365: if (flag_handle_exceptions == 2) 11366: deactivate_exception_cleanups (); 1.1.1.5 root 11367: expand_end_bindings (decls, decls != NULL_TREE, 0); 11368: poplevel (decls != NULL_TREE, 0, 0); 1.1 root 11369: } 11370: c_expand_return (current_class_decl); 11371: } 1.1.1.4 root 11372: else if (TYPE_MAIN_VARIANT (TREE_TYPE ( 11373: DECL_RESULT (current_function_decl))) != void_type_node 1.1.1.5 root 11374: && return_label != NULL_RTX) 1.1 root 11375: no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 11376: 11377: current_function_assigns_this = 0; 11378: current_function_just_assigned_this = 0; 1.1.1.5 root 11379: base_init_insns = NULL_RTX; 1.1 root 11380: } 11381: else if (DECL_CONSTRUCTOR_P (fndecl)) 11382: { 11383: tree allocated_this; 11384: tree cond, thenclause; 11385: /* Allow constructor for a type to get a new instance of the object 11386: using `build_new'. */ 11387: tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); 11388: CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; 11389: 11390: DECL_RETURNS_FIRST_ARG (fndecl) = 1; 11391: 1.1.1.2 root 11392: if (flag_this_is_variable > 0) 1.1 root 11393: { 1.1.1.5 root 11394: cond = build_binary_op (EQ_EXPR, 11395: current_class_decl, integer_zero_node, 1); 1.1 root 11396: thenclause = build_modify_expr (current_class_decl, NOP_EXPR, 11397: build_new (NULL_TREE, current_class_type, void_type_node, 0)); 11398: if (flag_handle_exceptions == 2) 11399: { 11400: tree cleanup, cleanup_deallocate; 1.1.1.4 root 11401: tree virtual_size; 11402: 11403: /* This is the size of the virtual object pointed to by 11404: allocated_this. In this case, it is simple. */ 11405: virtual_size = c_sizeof (current_class_type); 1.1 root 11406: 11407: allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node); 1.1.1.4 root 11408: DECL_REGISTER (allocated_this) = 1; 1.1 root 11409: DECL_INITIAL (allocated_this) = error_mark_node; 11410: expand_decl (allocated_this); 11411: expand_decl_init (allocated_this); 11412: /* How we cleanup `this' if an exception was raised before 11413: we are ready to bail out. */ 11414: cleanup = TREE_GETS_DELETE (current_class_type) 1.1.1.5 root 11415: ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this, virtual_size, NULL_TREE) 1.1.1.4 root 11416: /* The size of allocated_this is wrong, and hence the 11417: second argument to operator delete will be wrong. */ 11418: : build_delete (TREE_TYPE (allocated_this), allocated_this, 11419: integer_three_node, 1.1.1.6 ! root 11420: LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1); 1.1 root 11421: cleanup_deallocate 11422: = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node); 11423: cleanup = tree_cons (NULL_TREE, cleanup, 11424: build_tree_list (NULL_TREE, cleanup_deallocate)); 11425: 11426: expand_decl_cleanup (allocated_this, 11427: build (COND_EXPR, integer_type_node, 11428: build (NE_EXPR, integer_type_node, 11429: allocated_this, integer_zero_node), 11430: build_compound_expr (cleanup), 11431: integer_zero_node)); 11432: } 11433: } 11434: else if (TREE_GETS_NEW (current_class_type)) 11435: /* Just check visibility here. */ 11436: build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node), 1.1.1.2 root 11437: ansi_opname[(int) NEW_EXPR], 1.1 root 11438: build_tree_list (NULL_TREE, integer_zero_node), 11439: NULL_TREE, LOOKUP_NORMAL); 11440: 11441: CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; 11442: 11443: /* must keep the first insn safe. */ 1.1.1.4 root 11444: head = get_insns (); 1.1 root 11445: 11446: /* this note will come up to the top with us. */ 11447: mark = get_last_insn (); 11448: 1.1.1.2 root 11449: if (flag_this_is_variable > 0) 1.1 root 11450: { 11451: expand_start_cond (cond, 0); 11452: expand_expr_stmt (thenclause); 11453: if (flag_handle_exceptions == 2) 11454: expand_assignment (allocated_this, current_class_decl, 0, 0); 11455: expand_end_cond (); 11456: } 11457: 11458: if (DECL_NAME (fndecl) == NULL_TREE 11459: && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE) 11460: build_default_constructor (fndecl); 11461: 11462: /* Emit insns from `emit_base_init' which sets up virtual 11463: function table pointer(s). */ 11464: emit_insns (base_init_insns); 1.1.1.5 root 11465: base_init_insns = NULL_RTX; 1.1 root 11466: 11467: /* This is where the body of the constructor begins. 11468: If there were no insns in this function body, then the 11469: last_parm_insn is also the last insn. 11470: 11471: If optimization is enabled, last_parm_insn may move, so 11472: we don't hold on to it (across emit_base_init). */ 1.1.1.4 root 11473: last_parm_insn = get_first_nonparm_insn (); 1.1.1.6 ! root 11474: if (last_parm_insn == NULL_RTX) ! 11475: last_parm_insn = mark; ! 11476: else ! 11477: last_parm_insn = previous_insn (last_parm_insn); 1.1 root 11478: 11479: if (mark != get_last_insn ()) 11480: reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn); 11481: 11482: /* This is where the body of the constructor ends. */ 11483: expand_label (ctor_label); 11484: ctor_label = NULL_TREE; 11485: if (flag_handle_exceptions == 2) 11486: { 11487: expand_assignment (allocated_this, integer_zero_node, 0, 0); 11488: if (call_poplevel) 11489: deactivate_exception_cleanups (); 11490: } 11491: 11492: pop_implicit_try_blocks (NULL_TREE); 11493: 11494: if (call_poplevel) 11495: { 1.1.1.6 ! root 11496: expand_end_bindings (decls = getdecls (), decls != NULL_TREE, 0); ! 11497: poplevel (decls != NULL_TREE, 1, 0); 1.1 root 11498: } 11499: 11500: c_expand_return (current_class_decl); 11501: 11502: current_function_assigns_this = 0; 11503: current_function_just_assigned_this = 0; 11504: } 11505: else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 11506: && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") 11507: && DECL_CONTEXT (fndecl) == NULL_TREE) 11508: { 11509: /* Make it so that `main' always returns 0 by default. */ 11510: #ifdef VMS 11511: c_expand_return (integer_one_node); 11512: #else 11513: c_expand_return (integer_zero_node); 11514: #endif 11515: } 1.1.1.5 root 11516: else if (return_label != NULL_RTX 11517: && current_function_return_value == NULL_TREE 1.1 root 11518: && ! DECL_NAME (DECL_RESULT (current_function_decl))) 11519: no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); 11520: 11521: if (flag_gc) 11522: expand_gc_prologue_and_epilogue (); 11523: 11524: /* That's the end of the vtable decl's life. Need to mark it such 11525: if doing stupid register allocation. 11526: 11527: Note that current_vtable_decl is really an INDIRECT_REF 11528: on top of a VAR_DECL here. */ 11529: if (obey_regdecls && current_vtable_decl) 11530: use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0))); 11531: 11532: /* If this function is supposed to return a value, ensure that 11533: we do not fall into the cleanups by mistake. The end of our 11534: function will look like this: 11535: 11536: user code (may have return stmt somewhere) 11537: goto no_return_label 11538: cleanup_label: 11539: cleanups 11540: goto return_label 11541: no_return_label: 11542: NOTE_INSN_FUNCTION_END 11543: return_label: 11544: things for return 11545: 11546: If the user omits a return stmt in the USER CODE section, we 11547: will have a control path which reaches NOTE_INSN_FUNCTION_END. 11548: Otherwise, we won't. */ 11549: if (no_return_label) 11550: { 11551: DECL_CONTEXT (no_return_label) = fndecl; 11552: DECL_INITIAL (no_return_label) = error_mark_node; 11553: DECL_SOURCE_FILE (no_return_label) = input_filename; 11554: DECL_SOURCE_LINE (no_return_label) = lineno; 11555: expand_goto (no_return_label); 11556: } 11557: 11558: if (cleanup_label) 11559: { 11560: /* remove the binding contour which is used 11561: to catch cleanup-generated temporaries. */ 11562: expand_end_bindings (0, 0, 0); 11563: poplevel (0, 0, 0); 11564: } 11565: 11566: if (cleanup_label) 1.1.1.2 root 11567: /* Emit label at beginning of cleanup code for parameters. */ 1.1 root 11568: emit_label (cleanup_label); 11569: 11570: #if 1 11571: /* Cheap hack to get better code from GNU C++. Remove when cse is fixed. */ 11572: if (exception_throw_decl && sets_exception_throw_decl == 0) 11573: expand_assignment (exception_throw_decl, integer_zero_node, 0, 0); 11574: #endif 11575: 11576: if (flag_handle_exceptions) 11577: { 11578: expand_end_try (); 11579: expand_start_except (0, 0); 11580: expand_end_except (); 11581: } 11582: 1.1.1.2 root 11583: /* Get return value into register if that's where it's supposed to be. */ 1.1 root 11584: if (original_result_rtx) 11585: fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); 11586: 11587: /* Finish building code that will trigger warnings if users forget 11588: to make their functions return values. */ 1.1.1.2 root 11589: if (no_return_label || cleanup_label) 11590: emit_jump (return_label); 1.1 root 11591: if (no_return_label) 11592: { 11593: /* We don't need to call `expand_*_return' here because we 11594: don't need any cleanups here--this path of code is only 11595: for error checking purposes. */ 11596: expand_label (no_return_label); 11597: } 11598: 11599: /* reset scope for C++: if we were in the scope of a class, 11600: then when we finish this function, we are not longer so. 11601: This cannot be done until we know for sure that no more 11602: class members will ever be referenced in this function 11603: (i.e., calls to destructors). */ 11604: if (current_class_name) 11605: { 11606: ctype = current_class_type; 1.1.1.6 ! root 11607: #if NEW_CLASS_SCOPING ! 11608: pop_nested_class (1); ! 11609: #else 1.1 root 11610: popclass (1); 1.1.1.6 ! root 11611: #endif 1.1 root 11612: } 11613: else 11614: pop_memoized_context (1); 11615: 11616: /* Forget about all overloaded functions defined in 11617: this scope which go away. */ 11618: while (overloads_to_forget) 11619: { 11620: IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget)) 11621: = TREE_VALUE (overloads_to_forget); 11622: overloads_to_forget = TREE_CHAIN (overloads_to_forget); 11623: } 11624: 11625: /* Generate rtl for function exit. */ 1.1.1.6 ! root 11626: expand_function_end (input_filename, lineno, 1); 1.1 root 11627: 11628: /* This must come after expand_function_end because cleanups might 11629: have declarations (from inline functions) that need to go into 11630: this function's blocks. */ 1.1.1.4 root 11631: if (current_binding_level->parm_flag != 1) 11632: my_friendly_abort (122); 1.1 root 11633: poplevel (1, 0, 1); 11634: 1.1.1.5 root 11635: /* Must mark the RESULT_DECL as being in this function. */ 11636: DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl); 11637: 11638: /* Obey `register' declarations if `setjmp' is called in this fn. */ 11639: if (flag_traditional && current_function_calls_setjmp) 11640: setjmp_protect (DECL_INITIAL (fndecl)); 11641: 1.1.1.4 root 11642: /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point 11643: to the FUNCTION_DECL node itself. */ 11644: BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; 11645: 1.1 root 11646: /* So we can tell if jump_optimize sets it to 1. */ 11647: can_reach_end = 0; 11648: 11649: /* ??? Compensate for Sun brain damage in dealing with data segments 11650: of PIC code. */ 11651: if (flag_pic 11652: && (DECL_CONSTRUCTOR_P (fndecl) 11653: || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) 11654: && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype))) 1.1.1.4 root 11655: DECL_INLINE (fndecl) = 0; 1.1 root 11656: 1.1.1.4 root 11657: if (DECL_EXTERNAL (fndecl) 1.1 root 11658: /* This function is just along for the ride. If we can make 11659: it inline, that's great. Otherwise, just punt it. */ 1.1.1.4 root 11660: && (DECL_INLINE (fndecl) == 0 1.1 root 11661: || flag_no_inline 11662: || function_cannot_inline_p (fndecl))) 11663: { 11664: extern int rtl_dump_and_exit; 11665: int old_rtl_dump_and_exit = rtl_dump_and_exit; 1.1.1.4 root 11666: int inline_spec = DECL_INLINE (fndecl); 1.1 root 11667: 11668: /* This throws away the code for FNDECL. */ 11669: rtl_dump_and_exit = 1; 11670: /* This throws away the memory of the code for FNDECL. */ 11671: if (flag_no_inline) 1.1.1.4 root 11672: DECL_INLINE (fndecl) = 0; 1.1 root 11673: rest_of_compilation (fndecl); 11674: rtl_dump_and_exit = old_rtl_dump_and_exit; 1.1.1.4 root 11675: DECL_INLINE (fndecl) = inline_spec; 1.1 root 11676: } 11677: else 11678: { 11679: /* Run the optimizers and output the assembler code for this function. */ 11680: rest_of_compilation (fndecl); 11681: } 11682: 11683: if (ctype && TREE_ASM_WRITTEN (fndecl)) 11684: note_debug_info_needed (ctype); 11685: 11686: current_function_returns_null |= can_reach_end; 11687: 11688: /* Since we don't normally go through c_expand_return for constructors, 11689: this normally gets the wrong value. 11690: Also, named return values have their return codes emitted after 11691: NOTE_INSN_FUNCTION_END, confusing jump.c. */ 1.1.1.5 root 11692: if (DECL_CONSTRUCTOR_P (fndecl) 11693: || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) 1.1 root 11694: current_function_returns_null = 0; 11695: 11696: if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) 11697: warning ("`volatile' function does return"); 11698: else if (warn_return_type && current_function_returns_null 1.1.1.4 root 11699: && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node) 1.1 root 11700: { 11701: /* If this function returns non-void and control can drop through, 11702: complain. */ 1.1.1.3 root 11703: pedwarn ("control reaches end of non-void function"); 1.1 root 11704: } 11705: /* With just -W, complain only if function returns both with 11706: and without a value. */ 11707: else if (extra_warnings 11708: && current_function_returns_value && current_function_returns_null) 11709: warning ("this function may return with or without a value"); 11710: 11711: /* Free all the tree nodes making up this function. */ 11712: /* Switch back to allocating nodes permanently 11713: until we start another function. */ 11714: permanent_allocation (); 11715: 11716: if (flag_cadillac) 11717: cadillac_finish_function (fndecl); 11718: 1.1.1.5 root 11719: if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) 1.1 root 11720: { 11721: /* Stop pointing to the local nodes about to be freed. */ 11722: /* But DECL_INITIAL must remain nonzero so we know this 11723: was an actual function definition. */ 11724: DECL_INITIAL (fndecl) = error_mark_node; 11725: if (! DECL_CONSTRUCTOR_P (fndecl) 11726: || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype))) 1.1.1.5 root 11727: DECL_ARGUMENTS (fndecl) = NULL_TREE; 1.1 root 11728: } 11729: 11730: /* Let the error reporting routines know that we're outside a function. */ 11731: current_function_decl = NULL_TREE; 11732: named_label_uses = NULL_TREE; 11733: } 11734: 11735: /* Create the FUNCTION_DECL for a function definition. 11736: LINE1 is the line number that the definition absolutely begins on. 11737: LINE2 is the line number that the name of the function appears on. 11738: DECLSPECS and DECLARATOR are the parts of the declaration; 11739: they describe the function's name and the type it returns, 11740: but twisted together in a fashion that parallels the syntax of C. 11741: 11742: This function creates a binding context for the function body 11743: as well as setting up the FUNCTION_DECL in current_function_decl. 11744: 11745: Returns a FUNCTION_DECL on success. 11746: 11747: If the DECLARATOR is not suitable for a function (it defines a datum 11748: instead), we return 0, which tells yyparse to report a parse error. 11749: 11750: May return void_type_node indicating that this method is actually 11751: a friend. See grokfield for more details. 11752: 11753: Came here with a `.pushlevel' . 11754: 11755: DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING 11756: CHANGES TO CODE IN `grokfield'. */ 11757: tree 11758: start_method (declspecs, declarator, raises) 11759: tree declarator, declspecs, raises; 11760: { 11761: tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises); 11762: 11763: /* Something too ugly to handle. */ 1.1.1.5 root 11764: if (fndecl == NULL_TREE) 11765: return NULL_TREE; 1.1 root 11766: 11767: /* Pass friends other than inline friend functions back. */ 1.1.1.4 root 11768: if (TYPE_MAIN_VARIANT (fndecl) == void_type_node) 11769: return fndecl; 1.1 root 11770: 11771: if (TREE_CODE (fndecl) != FUNCTION_DECL) 11772: /* Not a function, tell parser to report parse error. */ 1.1.1.5 root 11773: return NULL_TREE; 1.1 root 11774: 11775: if (DECL_IN_AGGR_P (fndecl)) 11776: { 11777: if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) 1.1.1.5 root 11778: { 11779: if (DECL_CONTEXT (fndecl)) 1.1.1.6 ! root 11780: cp_error ("`%D' is already defined in class %s", fndecl, 1.1.1.5 root 11781: TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); 11782: } 1.1 root 11783: return void_type_node; 11784: } 11785: 11786: /* If we're expanding a template, a function must be explicitly declared 11787: inline if we're to compile it now. If it isn't, we have to wait to see 11788: whether it's needed, and whether an override exists. */ 11789: if (flag_default_inline && !processing_template_defn) 1.1.1.4 root 11790: DECL_INLINE (fndecl) = 1; 1.1 root 11791: 11792: /* We read in the parameters on the maybepermanent_obstack, 11793: but we won't be getting back to them until after we 11794: may have clobbered them. So the call to preserve_data 11795: will keep them safe. */ 11796: preserve_data (); 11797: 11798: if (! DECL_FRIEND_P (fndecl)) 11799: { 11800: if (DECL_CHAIN (fndecl) != NULL_TREE) 11801: { 11802: /* Need a fresh node here so that we don't get circularity 11803: when we link these together. If FNDECL was a friend, then 11804: `pushdecl' does the right thing, which is nothing wrt its 11805: current value of DECL_CHAIN. */ 11806: fndecl = copy_node (fndecl); 11807: } 1.1.1.5 root 11808: if (TREE_CHAIN (fndecl)) 11809: { 11810: fndecl = copy_node (fndecl); 11811: TREE_CHAIN (fndecl) = NULL_TREE; 11812: } 1.1 root 11813: 11814: if (DECL_CONSTRUCTOR_P (fndecl)) 11815: grok_ctor_properties (current_class_type, fndecl); 11816: else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) 1.1.1.4 root 11817: grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl)); 1.1 root 11818: } 11819: 1.1.1.5 root 11820: finish_decl (fndecl, NULL_TREE, NULL_TREE, 0); 1.1 root 11821: 11822: /* Make a place for the parms */ 11823: pushlevel (0); 11824: current_binding_level->parm_flag = 1; 11825: 11826: DECL_IN_AGGR_P (fndecl) = 1; 11827: return fndecl; 11828: } 11829: 11830: /* Go through the motions of finishing a function definition. 11831: We don't compile this method until after the whole class has 11832: been processed. 11833: 11834: FINISH_METHOD must return something that looks as though it 11835: came from GROKFIELD (since we are defining a method, after all). 11836: 11837: This is called after parsing the body of the function definition. 11838: STMTS is the chain of statements that makes up the function body. 11839: 11840: DECL is the ..._DECL that `start_method' provided. */ 11841: 11842: tree 11843: finish_method (decl) 11844: tree decl; 11845: { 11846: register tree fndecl = decl; 11847: tree old_initial; 1.1.1.4 root 11848: tree context = DECL_CONTEXT (fndecl); 1.1 root 11849: 11850: register tree link; 11851: 1.1.1.4 root 11852: if (TYPE_MAIN_VARIANT (decl) == void_type_node) 1.1 root 11853: return decl; 11854: 11855: old_initial = DECL_INITIAL (fndecl); 11856: 11857: /* Undo the level for the parms (from start_method). 11858: This is like poplevel, but it causes nothing to be 11859: saved. Saving information here confuses symbol-table 11860: output routines. Besides, this information will 11861: be correctly output when this method is actually 11862: compiled. */ 11863: 11864: /* Clear out the meanings of the local variables of this level; 11865: also record in each decl which block it belongs to. */ 11866: 11867: for (link = current_binding_level->names; link; link = TREE_CHAIN (link)) 11868: { 1.1.1.5 root 11869: if (DECL_NAME (link) != NULL_TREE) 1.1 root 11870: IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0; 1.1.1.4 root 11871: my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163); 1.1.1.5 root 11872: DECL_CONTEXT (link) = NULL_TREE; 1.1 root 11873: } 11874: 11875: /* Restore all name-meanings of the outer levels 11876: that were shadowed by this level. */ 11877: 11878: for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) 11879: IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 11880: for (link = current_binding_level->class_shadowed; 11881: link; link = TREE_CHAIN (link)) 11882: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 11883: for (link = current_binding_level->type_shadowed; 11884: link; link = TREE_CHAIN (link)) 11885: IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); 11886: 1.1.1.5 root 11887: GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, 11888: (HOST_WIDE_INT) current_binding_level->level_chain, 1.1 root 11889: current_binding_level->parm_flag, 11890: current_binding_level->keep, 11891: current_binding_level->tag_transparent); 11892: 1.1.1.6 ! root 11893: poplevel (0, 0, 0); 1.1 root 11894: 11895: DECL_INITIAL (fndecl) = old_initial; 1.1.1.6 ! root 11896: ! 11897: /* We used to check if the context of FNDECL was different from ! 11898: current_class_type as another way to get inside here. This didn't work ! 11899: for String.cc in libg++. */ 1.1 root 11900: if (DECL_FRIEND_P (fndecl)) 11901: { 11902: CLASSTYPE_INLINE_FRIENDS (current_class_type) 11903: = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type)); 11904: decl = void_type_node; 11905: } 11906: 11907: return decl; 11908: } 11909: 11910: /* Called when a new struct TYPE is defined. 11911: If this structure or union completes the type of any previous 11912: variable declaration, lay it out and output its rtl. */ 11913: 11914: void 11915: hack_incomplete_structures (type) 11916: tree type; 11917: { 11918: tree decl; 11919: 11920: if (current_binding_level->n_incomplete == 0) 11921: return; 11922: 11923: if (!type) /* Don't do this for class templates. */ 11924: return; 11925: 11926: for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl)) 11927: if (TREE_TYPE (decl) == type 11928: || (TREE_TYPE (decl) 11929: && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE 11930: && TREE_TYPE (TREE_TYPE (decl)) == type)) 11931: { 11932: if (TREE_CODE (decl) == TYPE_DECL) 11933: layout_type (TREE_TYPE (decl)); 11934: else 11935: { 11936: int toplevel = global_binding_level == current_binding_level; 1.1.1.4 root 11937: if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE 11938: && TREE_TYPE (TREE_TYPE (decl)) == type) 11939: layout_type (TREE_TYPE (decl)); 1.1 root 11940: layout_decl (decl, 0); 1.1.1.5 root 11941: rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); 1.1 root 11942: if (! toplevel) 11943: { 11944: expand_decl (decl); 11945: expand_decl_cleanup (decl, maybe_build_cleanup (decl)); 11946: expand_decl_init (decl); 11947: } 11948: } 1.1.1.4 root 11949: my_friendly_assert (current_binding_level->n_incomplete > 0, 164); 1.1 root 11950: --current_binding_level->n_incomplete; 11951: } 11952: } 11953: 11954: /* Nonzero if presently building a cleanup. Needed because 11955: SAVE_EXPRs are not the right things to use inside of cleanups. 11956: They are only ever evaluated once, where the cleanup 11957: might be evaluated several times. In this case, a later evaluation 11958: of the cleanup might fill in the SAVE_EXPR_RTL, and it will 11959: not be valid for an earlier cleanup. */ 11960: 11961: int building_cleanup; 11962: 11963: /* If DECL is of a type which needs a cleanup, build that cleanup here. 11964: We don't build cleanups if just going for syntax checking, since 11965: fixup_cleanups does not know how to not handle them. 11966: 11967: Don't build these on the momentary obstack; they must live 11968: the life of the binding contour. */ 11969: tree 11970: maybe_build_cleanup (decl) 11971: tree decl; 11972: { 11973: tree type = TREE_TYPE (decl); 11974: if (TYPE_NEEDS_DESTRUCTOR (type)) 11975: { 11976: int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; 11977: tree rval; 11978: int old_building_cleanup = building_cleanup; 11979: building_cleanup = 1; 11980: 11981: if (TREE_CODE (decl) != PARM_DECL) 11982: temp = suspend_momentary (); 11983: 11984: if (TREE_CODE (type) == ARRAY_TYPE) 11985: rval = decl; 11986: else 11987: { 11988: mark_addressable (decl); 11989: rval = build_unary_op (ADDR_EXPR, decl, 0); 11990: } 11991: 11992: /* Optimize for space over speed here. */ 11993: if (! TYPE_USES_VIRTUAL_BASECLASSES (type) 11994: || flag_expensive_optimizations) 11995: flags |= LOOKUP_NONVIRTUAL; 11996: 11997: /* Use TYPE_MAIN_VARIANT so we don't get a warning about 11998: calling delete on a `const' variable. */ 11999: if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval)))) 12000: rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval); 12001: 1.1.1.6 ! root 12002: rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0); 1.1 root 12003: 12004: if (TYPE_USES_VIRTUAL_BASECLASSES (type) 12005: && ! TYPE_HAS_DESTRUCTOR (type)) 12006: rval = build_compound_expr (tree_cons (NULL_TREE, rval, 12007: build_tree_list (NULL_TREE, build_vbase_delete (type, decl)))); 12008: 12009: current_binding_level->have_cleanups = 1; 12010: current_binding_level->more_exceptions_ok = 0; 12011: 12012: if (TREE_CODE (decl) != PARM_DECL) 12013: resume_momentary (temp); 12014: 12015: building_cleanup = old_building_cleanup; 12016: 12017: return rval; 12018: } 12019: return 0; 12020: } 12021: 12022: /* Expand a C++ expression at the statement level. 12023: This is needed to ferret out nodes which have UNKNOWN_TYPE. 12024: The C++ type checker should get all of these out when 12025: expressions are combined with other, type-providing, expressions, 12026: leaving only orphan expressions, such as: 12027: 12028: &class::bar; / / takes its address, but does nothing with it. 12029: 12030: */ 12031: void 12032: cplus_expand_expr_stmt (exp) 12033: tree exp; 12034: { 12035: if (TREE_TYPE (exp) == unknown_type_node) 12036: { 12037: if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST) 12038: error ("address of overloaded function with no contextual type information"); 12039: else if (TREE_CODE (exp) == COMPONENT_REF) 12040: warning ("useless reference to a member function name, did you forget the ()?"); 12041: } 12042: else 12043: { 12044: int remove_implicit_immediately = 0; 12045: 12046: if (TREE_CODE (exp) == FUNCTION_DECL) 1.1.1.2 root 12047: { 1.1.1.6 ! root 12048: cp_warning ("reference, not call, to function `%D'", exp); 1.1.1.2 root 12049: warning ("at this point in file"); 12050: } 1.1 root 12051: if (TREE_RAISES (exp)) 12052: { 1.1.1.4 root 12053: my_friendly_assert (flag_handle_exceptions, 165); 1.1 root 12054: if (flag_handle_exceptions == 2) 12055: { 12056: if (! current_binding_level->more_exceptions_ok) 12057: { 12058: extern struct nesting *nesting_stack, *block_stack; 12059: 12060: remove_implicit_immediately 12061: = (nesting_stack != block_stack); 12062: cplus_expand_start_try (1); 12063: } 12064: current_binding_level->have_exceptions = 1; 12065: } 12066: } 12067: 12068: expand_expr_stmt (break_out_cleanups (exp)); 12069: 12070: if (remove_implicit_immediately) 12071: pop_implicit_try_blocks (NULL_TREE); 12072: } 12073: 12074: /* Clean up any pending cleanups. This happens when a function call 12075: returns a cleanup-needing value that nobody uses. */ 12076: expand_cleanups_to (NULL_TREE); 12077: } 12078: 12079: /* When a stmt has been parsed, this function is called. 12080: 12081: Currently, this function only does something within a 12082: constructor's scope: if a stmt has just assigned to this, 12083: and we are in a derived class, we call `emit_base_init'. */ 12084: 12085: void 12086: finish_stmt () 12087: { 12088: extern struct nesting *cond_stack, *loop_stack, *case_stack; 12089: 12090: 12091: if (current_function_assigns_this 12092: || ! current_function_just_assigned_this) 12093: return; 12094: if (DECL_CONSTRUCTOR_P (current_function_decl)) 12095: { 12096: /* Constructors must wait until we are out of control 12097: zones before calling base constructors. */ 12098: if (cond_stack || loop_stack || case_stack) 12099: return; 12100: emit_insns (base_init_insns); 12101: check_base_init (current_class_type); 12102: } 12103: current_function_assigns_this = 1; 12104: 12105: if (flag_cadillac) 12106: cadillac_finish_stmt (); 12107: } 12108: 12109: void 12110: pop_implicit_try_blocks (decl) 12111: tree decl; 12112: { 12113: if (decl) 12114: { 1.1.1.4 root 12115: my_friendly_assert (current_binding_level->parm_flag == 3, 166); 1.1 root 12116: current_binding_level->names = TREE_CHAIN (decl); 12117: } 12118: 12119: while (current_binding_level->parm_flag == 3) 12120: { 12121: tree name = get_identifier ("(compiler error)"); 12122: tree orig_ex_type = current_exception_type; 12123: tree orig_ex_decl = current_exception_decl; 12124: tree orig_ex_obj = current_exception_object; 12125: tree decl = cplus_expand_end_try (2); 12126: 12127: /* @@ It would be nice to make all these point 12128: to exactly the same handler. */ 12129: /* Start hidden EXCEPT. */ 12130: cplus_expand_start_except (name, decl); 12131: /* reraise ALL. */ 12132: cplus_expand_reraise (NULL_TREE); 12133: current_exception_type = orig_ex_type; 12134: current_exception_decl = orig_ex_decl; 12135: current_exception_object = orig_ex_obj; 12136: /* This will reraise for us. */ 12137: cplus_expand_end_except (error_mark_node); 12138: } 12139: 12140: if (decl) 12141: { 12142: TREE_CHAIN (decl) = current_binding_level->names; 12143: current_binding_level->names = decl; 12144: } 12145: } 12146: 12147: /* Push a cleanup onto the current binding contour that will cause 12148: ADDR to be cleaned up, in the case that an exception propagates 12149: through its binding contour. */ 12150: 12151: void 12152: push_exception_cleanup (addr) 12153: tree addr; 12154: { 12155: tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node); 12156: tree cleanup; 12157: 12158: decl = pushdecl (decl); 1.1.1.4 root 12159: DECL_REGISTER (decl) = 1; 1.1 root 12160: store_init_value (decl, addr); 12161: expand_decl (decl); 12162: expand_decl_init (decl); 12163: 12164: cleanup = build (COND_EXPR, integer_type_node, 12165: build (NE_EXPR, integer_type_node, 12166: decl, integer_zero_node), 12167: build_delete (TREE_TYPE (addr), decl, 12168: lookup_name (in_charge_identifier, 0), 1.1.1.6 ! root 12169: LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0), 1.1 root 12170: integer_zero_node); 12171: expand_decl_cleanup (decl, cleanup); 12172: } 12173: 12174: /* For each binding contour, emit code that deactivates the 12175: exception cleanups. All other cleanups are left as they were. */ 12176: 12177: static void 12178: deactivate_exception_cleanups () 12179: { 12180: struct binding_level *b = current_binding_level; 12181: tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME); 12182: while (b != class_binding_level) 12183: { 12184: if (b->parm_flag == 3) 12185: { 12186: tree decls = b->names; 12187: while (decls) 12188: { 12189: if (DECL_NAME (decls) == xyzzy) 12190: expand_assignment (decls, integer_zero_node, 0, 0); 12191: decls = TREE_CHAIN (decls); 12192: } 12193: } 12194: b = b->level_chain; 12195: } 12196: } 1.1.1.4 root 12197: 12198: /* Change a static member function definition into a FUNCTION_TYPE, instead 12199: of the METHOD_TYPE that we create when it's originally parsed. */ 1.1.1.5 root 12200: void 1.1.1.4 root 12201: revert_static_member_fn (fn, decl, argtypes) 12202: tree *fn, *decl, *argtypes; 12203: { 12204: tree tmp, function = *fn; 12205: 12206: *argtypes = TREE_CHAIN (*argtypes); 12207: tmp = build_function_type (TREE_TYPE (function), *argtypes); 12208: tmp = build_type_variant (tmp, TYPE_READONLY (function), 12209: TYPE_VOLATILE (function)); 12210: tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp, 12211: TYPE_RAISES_EXCEPTIONS (function)); 12212: TREE_TYPE (*decl) = tmp; 12213: *fn = tmp; 12214: DECL_STATIC_FUNCTION_P (*decl) = 1; 12215: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.