|
|
1.1 root 1: /* Functions related to building classes and their related objects. 1.1.1.2 ! root 2: Copyright (C) 1987, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 1.1 root 3: Contributed by Michael Tiemann ([email protected]) 4: 5: This file is part of GNU CC. 6: 7: GNU CC is free software; you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation; either version 2, or (at your option) 10: any later version. 11: 12: GNU CC is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with GNU CC; see the file COPYING. If not, write to 1.1.1.2 ! root 19: the Free Software Foundation, 59 Temple Place - Suite 330, ! 20: Boston, MA 02111-1307, USA. */ 1.1 root 21: 22: 23: /* High-level class interface. */ 24: 25: #include "config.h" 26: #include "tree.h" 27: #include <stdio.h> 28: #include "cp-tree.h" 29: #include "flags.h" 1.1.1.2 ! root 30: #include "rtl.h" ! 31: #include "output.h" 1.1 root 32: 33: #include "obstack.h" 34: #define obstack_chunk_alloc xmalloc 35: #define obstack_chunk_free free 36: 37: extern struct obstack permanent_obstack; 38: 39: /* This is how we tell when two virtual member functions are really the 40: same. */ 41: #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL)) 42: 43: extern void set_class_shadows PROTO ((tree)); 44: 45: /* Way of stacking class types. */ 46: static tree *current_class_base, *current_class_stack; 47: static int current_class_stacksize; 48: int current_class_depth; 49: 50: struct class_level 51: { 52: /* The previous class level. */ 53: struct class_level *level_chain; 54: 55: /* The class instance variable, as a PARM_DECL. */ 56: tree decl; 57: /* The class instance variable, as an object. */ 58: tree object; 59: /* The virtual function table pointer 60: for the class instance variable. */ 61: tree vtable_decl; 62: 63: /* Name of the current class. */ 64: tree name; 65: /* Type of the current class. */ 66: tree type; 67: 68: /* Flags for this class level. */ 69: int this_is_variable; 70: int memoized_lookups; 71: int save_memoized; 72: int unused; 73: }; 74: 75: tree current_class_decl, C_C_D; /* PARM_DECL: the class instance variable */ 76: 77: /* The following two can be derived from the previous one */ 78: tree current_class_name; /* IDENTIFIER_NODE: name of current class */ 79: tree current_class_type; /* _TYPE: the type of the current class */ 80: tree previous_class_type; /* _TYPE: the previous type that was a class */ 81: tree previous_class_values; /* TREE_LIST: copy of the class_shadowed list 82: when leaving an outermost class scope. */ 83: static tree get_vfield_name PROTO((tree)); 84: tree the_null_vtable_entry; 85: 86: /* Way of stacking language names. */ 87: tree *current_lang_base, *current_lang_stack; 88: int current_lang_stacksize; 89: 90: /* Names of languages we recognize. */ 91: tree lang_name_c, lang_name_cplusplus; 92: tree current_lang_name; 93: 1.1.1.2 ! root 94: char *dont_allow_type_definitions; ! 95: 1.1 root 96: /* When layout out an aggregate type, the size of the 97: basetypes (virtual and non-virtual) is passed to layout_record 98: via this node. */ 99: static tree base_layout_decl; 100: 101: /* Variables shared between class.c and call.c. */ 102: 103: int n_vtables = 0; 104: int n_vtable_entries = 0; 105: int n_vtable_searches = 0; 106: int n_vtable_elems = 0; 107: int n_convert_harshness = 0; 108: int n_compute_conversion_costs = 0; 109: int n_build_method_call = 0; 110: int n_inner_fields_searched = 0; 111: 112: /* Virtual baseclass things. */ 113: tree 114: build_vbase_pointer (exp, type) 115: tree exp, type; 116: { 117: char *name; 118: 119: name = (char *) alloca (TYPE_NAME_LENGTH (type) + sizeof (VBASE_NAME) + 1); 120: sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (type)); 121: return build_component_ref (exp, get_identifier (name), 0, 0); 122: } 123: 124: /* Is the type of the EXPR, the complete type of the object? 125: If we are going to be wrong, we must be conservative, and return 0. */ 126: int 127: complete_type_p (expr) 128: tree expr; 129: { 130: tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); 131: while (1) 132: { 133: switch (TREE_CODE (expr)) 134: { 135: case SAVE_EXPR: 136: case INDIRECT_REF: 137: case ADDR_EXPR: 138: case NOP_EXPR: 139: case CONVERT_EXPR: 140: expr = TREE_OPERAND (expr, 0); 141: continue; 142: 143: case CALL_EXPR: 144: if (! TREE_HAS_CONSTRUCTOR (expr)) 145: break; 146: /* fall through... */ 147: case VAR_DECL: 148: case FIELD_DECL: 149: if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE 150: && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr))) 151: && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type) 152: return 1; 153: /* fall through... */ 154: case TARGET_EXPR: 155: case PARM_DECL: 156: if (IS_AGGR_TYPE (TREE_TYPE (expr)) 157: && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type) 158: return 1; 159: /* fall through... */ 160: case PLUS_EXPR: 161: default: 162: break; 163: } 164: break; 165: } 166: return 0; 167: } 168: 169: /* Build multi-level access to EXPR using hierarchy path PATH. 170: CODE is PLUS_EXPR if we are going with the grain, 171: and MINUS_EXPR if we are not (in which case, we cannot traverse 172: virtual baseclass links). 173: 174: TYPE is the type we want this path to have on exit. 175: 176: ALIAS_THIS is non-zero if EXPR in an expression involving `this'. */ 177: tree 178: build_vbase_path (code, type, expr, path, alias_this) 179: enum tree_code code; 180: tree type, expr, path; 181: int alias_this; 182: { 183: register int changed = 0; 184: tree last = NULL_TREE, last_virtual = NULL_TREE; 185: int nonnull = 0; 186: int fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull); 187: tree null_expr = 0, nonnull_expr; 188: tree basetype; 189: tree offset = integer_zero_node; 190: 1.1.1.2 ! root 191: if (nonnull == 0 && (alias_this && flag_this_is_variable <= 0)) ! 192: nonnull = 1; ! 193: 1.1 root 194: /* We need additional logic to convert back to the unconverted type 195: (the static type of the complete object), and then convert back 196: to the type we want. Until that is done, or until we can 197: recognize when that is, we cannot do the short cut logic. (mrs) */ 1.1.1.2 ! root 198: /* Do this, until we can undo any previous conversions. See net35.C 1.1 root 199: for a testcase. */ 200: fixed_type_p = complete_type_p (expr); 201: 202: if (!fixed_type_p && TREE_SIDE_EFFECTS (expr)) 203: expr = save_expr (expr); 204: nonnull_expr = expr; 205: 206: if (BINFO_INHERITANCE_CHAIN (path)) 207: { 208: tree reverse_path = NULL_TREE; 209: 210: while (path) 211: { 212: tree r = copy_node (path); 213: BINFO_INHERITANCE_CHAIN (r) = reverse_path; 214: reverse_path = r; 215: path = BINFO_INHERITANCE_CHAIN (path); 216: } 217: path = reverse_path; 218: } 219: 220: basetype = BINFO_TYPE (path); 221: 222: while (path) 223: { 224: if (TREE_VIA_VIRTUAL (path)) 225: { 226: last_virtual = BINFO_TYPE (path); 227: if (code == PLUS_EXPR) 228: { 229: changed = ! fixed_type_p; 230: 231: if (changed) 232: { 233: extern int flag_assume_nonnull_objects; 234: tree ind; 235: 236: /* We already check for ambiguous things in the caller, just 237: find a path. */ 238: if (last) 239: { 240: tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0); 241: nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr); 242: } 243: ind = build_indirect_ref (nonnull_expr, NULL_PTR); 244: nonnull_expr = build_vbase_pointer (ind, last_virtual); 1.1.1.2 ! root 245: if (nonnull == 0 ! 246: && (TREE_CODE (type) == POINTER_TYPE ! 247: || !flag_assume_nonnull_objects) 1.1 root 248: && null_expr == NULL_TREE) 249: { 1.1.1.2 ! root 250: null_expr = build1 (NOP_EXPR, build_pointer_type (last_virtual), integer_zero_node); ! 251: expr = build (COND_EXPR, build_pointer_type (last_virtual), ! 252: build (EQ_EXPR, boolean_type_node, expr, 1.1 root 253: integer_zero_node), 254: null_expr, nonnull_expr); 255: } 256: } 257: /* else we'll figure out the offset below. */ 258: 259: /* Happens in the case of parse errors. */ 260: if (nonnull_expr == error_mark_node) 261: return error_mark_node; 262: } 263: else 264: { 265: cp_error ("cannot cast up from virtual baseclass `%T'", 266: last_virtual); 267: return error_mark_node; 268: } 269: } 270: last = path; 271: path = BINFO_INHERITANCE_CHAIN (path); 272: } 273: /* LAST is now the last basetype assoc on the path. */ 274: 275: /* A pointer to a virtual base member of a non-null object 276: is non-null. Therefore, we only need to test for zeroness once. 277: Make EXPR the canonical expression to deal with here. */ 278: if (null_expr) 279: { 280: TREE_OPERAND (expr, 2) = nonnull_expr; 281: TREE_TYPE (TREE_OPERAND (expr, 1)) = TREE_TYPE (nonnull_expr); 282: } 283: else 284: expr = nonnull_expr; 285: 286: /* If we go through any virtual base pointers, make sure that 287: casts to BASETYPE from the last virtual base class use 288: the right value for BASETYPE. */ 289: if (changed) 290: { 291: tree intype = TREE_TYPE (TREE_TYPE (expr)); 1.1.1.2 ! root 292: if (TYPE_MAIN_VARIANT (intype) != BINFO_TYPE (last)) 1.1 root 293: { 294: tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0); 295: offset = BINFO_OFFSET (binfo); 296: } 297: } 298: else 299: { 300: if (last_virtual) 301: { 302: offset = BINFO_OFFSET (binfo_member (last_virtual, 303: CLASSTYPE_VBASECLASSES (basetype))); 304: offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last)); 305: } 306: else 307: offset = BINFO_OFFSET (last); 308: } 309: 310: if (TREE_INT_CST_LOW (offset)) 311: { 1.1.1.2 ! root 312: /* Bash types to make the backend happy. */ ! 313: offset = convert (type, offset); ! 314: expr = build1 (NOP_EXPR, type, expr); ! 315: 1.1 root 316: /* For multiple inheritance: if `this' can be set by any 317: function, then it could be 0 on entry to any function. 318: Preserve such zeroness here. Otherwise, only in the 319: case of constructors need we worry, and in those cases, 1.1.1.2 ! root 320: it will be zero, or initialized to some valid value to 1.1 root 321: which we may add. */ 1.1.1.2 ! root 322: if (nonnull == 0) 1.1 root 323: { 324: if (null_expr) 325: TREE_TYPE (null_expr) = type; 326: else 327: null_expr = build1 (NOP_EXPR, type, integer_zero_node); 328: if (TREE_SIDE_EFFECTS (expr)) 329: expr = save_expr (expr); 330: 331: return build (COND_EXPR, type, 1.1.1.2 ! root 332: build (EQ_EXPR, boolean_type_node, expr, integer_zero_node), 1.1 root 333: null_expr, 334: build (code, type, expr, offset)); 335: } 336: else return build (code, type, expr, offset); 337: } 338: 339: /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may 340: be used multiple times in initialization of multiple inheritance. */ 341: if (null_expr) 342: { 343: TREE_TYPE (expr) = type; 344: return expr; 345: } 346: else 347: return build1 (NOP_EXPR, type, expr); 348: } 349: 350: /* Virtual function things. */ 351: 352: /* Virtual functions to be dealt with after laying out our base 353: classes. We do all overrides after we layout virtual base classes. 354: */ 355: static tree pending_hard_virtuals; 356: static int doing_hard_virtuals; 357: 358: /* Build an entry in the virtual function table. 359: DELTA is the offset for the `this' pointer. 360: PFN is an ADDR_EXPR containing a pointer to the virtual function. 361: Note that the index (DELTA2) in the virtual function table 362: is always 0. */ 363: tree 364: build_vtable_entry (delta, pfn) 365: tree delta, pfn; 366: { 367: 368: if (flag_vtable_thunks) 369: { 370: HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta); 371: extern tree make_thunk (); 372: if (idelta) 373: { 374: pfn = build1 (ADDR_EXPR, vtable_entry_type, 375: make_thunk (pfn, idelta)); 376: TREE_READONLY (pfn) = 1; 377: TREE_CONSTANT (pfn) = 1; 378: } 379: #ifdef GATHER_STATISTICS 380: n_vtable_entries += 1; 381: #endif 382: return pfn; 383: } 384: else 385: { 386: extern int flag_huge_objects; 387: tree elems = tree_cons (NULL_TREE, delta, 388: tree_cons (NULL_TREE, integer_zero_node, 389: build_tree_list (NULL_TREE, pfn))); 390: tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems); 391: 392: /* DELTA is constructed by `size_int', which means it may be an 393: unsigned quantity on some platforms. Therefore, we cannot use 394: `int_fits_type_p', because when DELTA is really negative, 395: `force_fit_type' will make it look like a very large number. */ 396: 397: if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (delta_type_node)) 398: < TREE_INT_CST_LOW (delta)) 399: || (TREE_INT_CST_LOW (delta) 400: < TREE_INT_CST_LOW (TYPE_MIN_VALUE (delta_type_node)))) 401: if (flag_huge_objects) 402: sorry ("object size exceeds built-in limit for virtual function table implementation"); 403: else 404: sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects"); 405: 406: TREE_CONSTANT (entry) = 1; 407: TREE_STATIC (entry) = 1; 408: TREE_READONLY (entry) = 1; 409: 410: #ifdef GATHER_STATISTICS 411: n_vtable_entries += 1; 412: #endif 413: 414: return entry; 415: } 416: } 417: 418: /* Given an object INSTANCE, return an expression which yields the 419: virtual function corresponding to INDEX. There are many special 420: cases for INSTANCE which we take care of here, mainly to avoid 421: creating extra tree nodes when we don't have to. */ 422: tree 423: build_vfn_ref (ptr_to_instptr, instance, idx) 424: tree *ptr_to_instptr, instance; 425: tree idx; 426: { 427: extern int building_cleanup; 428: tree vtbl, aref; 429: tree basetype = TREE_TYPE (instance); 430: 431: if (TREE_CODE (basetype) == REFERENCE_TYPE) 432: basetype = TREE_TYPE (basetype); 433: 434: if (instance == C_C_D) 1.1.1.2 ! root 435: vtbl = build_indirect_ref (build_vfield_ref (instance, basetype), ! 436: NULL_PTR); 1.1 root 437: else 438: { 439: if (optimize) 440: { 441: /* Try to figure out what a reference refers to, and 442: access its virtual function table directly. */ 443: tree ref = NULL_TREE; 444: 445: if (TREE_CODE (instance) == INDIRECT_REF 446: && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE) 447: ref = TREE_OPERAND (instance, 0); 448: else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) 449: ref = instance; 450: 451: if (ref && TREE_CODE (ref) == VAR_DECL 452: && DECL_INITIAL (ref)) 453: { 454: tree init = DECL_INITIAL (ref); 455: 456: while (TREE_CODE (init) == NOP_EXPR 457: || TREE_CODE (init) == NON_LVALUE_EXPR) 458: init = TREE_OPERAND (init, 0); 459: if (TREE_CODE (init) == ADDR_EXPR) 460: { 461: init = TREE_OPERAND (init, 0); 462: if (IS_AGGR_TYPE (TREE_TYPE (init)) 463: && (TREE_CODE (init) == PARM_DECL 464: || TREE_CODE (init) == VAR_DECL)) 465: instance = init; 466: } 467: } 468: } 469: 470: if (IS_AGGR_TYPE (TREE_TYPE (instance)) 471: && (TREE_CODE (instance) == RESULT_DECL 472: || TREE_CODE (instance) == PARM_DECL 473: || TREE_CODE (instance) == VAR_DECL)) 474: vtbl = TYPE_BINFO_VTABLE (basetype); 475: else 476: vtbl = build_indirect_ref (build_vfield_ref (instance, basetype), 477: NULL_PTR); 478: } 1.1.1.2 ! root 479: assemble_external (vtbl); 1.1 root 480: aref = build_array_ref (vtbl, idx); 481: 482: /* Save the intermediate result in a SAVE_EXPR so we don't have to 483: compute each component of the virtual function pointer twice. */ 484: if (!building_cleanup && TREE_CODE (aref) == INDIRECT_REF) 485: TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0)); 486: 487: if (flag_vtable_thunks) 488: return aref; 489: else 490: { 1.1.1.2 ! root 491: if (ptr_to_instptr) ! 492: *ptr_to_instptr ! 493: = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr), ! 494: *ptr_to_instptr, ! 495: convert (ptrdiff_type_node, ! 496: build_component_ref (aref, delta_identifier, 0, 0))); 1.1 root 497: return build_component_ref (aref, pfn_identifier, 0, 0); 498: } 499: } 500: 501: /* Return the name of the virtual function table (as an IDENTIFIER_NODE) 502: for the given TYPE. */ 503: static tree 504: get_vtable_name (type) 505: tree type; 506: { 507: tree type_id = build_typename_overload (type); 508: char *buf = (char *)alloca (strlen (VTABLE_NAME_FORMAT) 509: + IDENTIFIER_LENGTH (type_id) + 2); 510: char *ptr = IDENTIFIER_POINTER (type_id); 511: int i; 512: for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ; 513: #if 0 514: /* We don't take off the numbers; prepare_fresh_vtable uses the 515: DECL_ASSEMBLER_NAME for the type, which includes the number 516: in `3foo'. If we were to pull them off here, we'd end up with 517: something like `_vt.foo.3bar', instead of a uniform definition. */ 518: while (ptr[i] >= '0' && ptr[i] <= '9') 519: i += 1; 520: #endif 521: sprintf (buf, VTABLE_NAME_FORMAT, ptr+i); 522: return get_identifier (buf); 523: } 524: 525: /* Build a virtual function for type TYPE. 526: If BINFO is non-NULL, build the vtable starting with the initial 527: approximation that it is the same as the one which is the head of 528: the association list. */ 529: static tree 530: build_vtable (binfo, type) 531: tree binfo, type; 532: { 533: tree name = get_vtable_name (type); 534: tree virtuals, decl; 535: 536: if (binfo) 537: { 538: virtuals = copy_list (BINFO_VIRTUALS (binfo)); 539: decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo))); 540: } 541: else 542: { 543: virtuals = NULL_TREE; 544: decl = build_decl (VAR_DECL, name, void_type_node); 545: } 546: 547: #ifdef GATHER_STATISTICS 548: n_vtables += 1; 549: n_vtable_elems += list_length (virtuals); 550: #endif 551: 552: /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */ 1.1.1.2 ! root 553: import_export_vtable (decl, type, 0); 1.1 root 554: 555: IDENTIFIER_GLOBAL_VALUE (name) = decl = pushdecl_top_level (decl); 556: /* Initialize the association list for this type, based 557: on our first approximation. */ 558: TYPE_BINFO_VTABLE (type) = decl; 559: TYPE_BINFO_VIRTUALS (type) = virtuals; 560: 561: TREE_STATIC (decl) = 1; 562: #ifndef WRITABLE_VTABLES 563: /* Make them READONLY by default. (mrs) */ 564: TREE_READONLY (decl) = 1; 565: #endif 566: /* At one time the vtable info was grabbed 2 words at a time. This 567: fails on sparc unless you have 8-byte alignment. (tiemann) */ 568: DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node), 569: DECL_ALIGN (decl)); 570: 571: /* Why is this conditional? (mrs) */ 572: if (binfo && write_virtuals >= 0) 573: DECL_VIRTUAL_P (decl) = 1; 574: DECL_CONTEXT (decl) = type; 575: 576: binfo = TYPE_BINFO (type); 577: SET_BINFO_NEW_VTABLE_MARKED (binfo); 578: return decl; 579: } 580: 581: /* Given a base type PARENT, and a derived type TYPE, build 582: a name which distinguishes exactly the PARENT member of TYPE's type. 583: 584: FORMAT is a string which controls how sprintf formats the name 585: we have generated. 586: 587: For example, given 588: 589: class A; class B; class C : A, B; 590: 591: it is possible to distinguish "A" from "C's A". And given 592: 593: class L; 594: class A : L; class B : L; class C : A, B; 595: 596: it is possible to distinguish "L" from "A's L", and also from 597: "C's L from A". 598: 599: Make sure to use the DECL_ASSEMBLER_NAME of the TYPE_NAME of the 600: type, as template have DECL_NAMEs like: X<int>, whereas the 601: DECL_ASSEMBLER_NAME is set to be something the assembler can handle. 602: */ 603: static tree 604: build_type_pathname (format, parent, type) 605: char *format; 606: tree parent, type; 607: { 608: extern struct obstack temporary_obstack; 609: char *first, *base, *name; 610: int i; 611: tree id; 612: 613: parent = TYPE_MAIN_VARIANT (parent); 614: 615: /* Remember where to cut the obstack to. */ 616: first = obstack_base (&temporary_obstack); 617: 618: /* Put on TYPE+PARENT. */ 619: obstack_grow (&temporary_obstack, 620: TYPE_ASSEMBLER_NAME_STRING (type), 621: TYPE_ASSEMBLER_NAME_LENGTH (type)); 622: #ifdef JOINER 623: obstack_1grow (&temporary_obstack, JOINER); 624: #else 625: obstack_1grow (&temporary_obstack, '_'); 626: #endif 627: obstack_grow0 (&temporary_obstack, 628: TYPE_ASSEMBLER_NAME_STRING (parent), 629: TYPE_ASSEMBLER_NAME_LENGTH (parent)); 630: i = obstack_object_size (&temporary_obstack); 631: base = obstack_base (&temporary_obstack); 632: obstack_finish (&temporary_obstack); 633: 634: /* Put on FORMAT+TYPE+PARENT. */ 635: obstack_blank (&temporary_obstack, strlen (format) + i + 1); 636: name = obstack_base (&temporary_obstack); 637: sprintf (name, format, base); 638: id = get_identifier (name); 639: obstack_free (&temporary_obstack, first); 640: 641: return id; 642: } 643: 1.1.1.2 ! root 644: /* Update the rtti info for this class. */ ! 645: static void ! 646: set_rtti_entry (virtuals, offset, type) ! 647: tree virtuals, offset, type; ! 648: { ! 649: if (! flag_vtable_thunks) ! 650: TREE_VALUE (virtuals) ! 651: = build_vtable_entry (offset, ! 652: (flag_rtti ! 653: ? build_t_desc (type, 0) ! 654: : integer_zero_node)); ! 655: else ! 656: { ! 657: tree vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, offset); ! 658: TREE_CONSTANT (vfn) = 1; ! 659: ! 660: TREE_VALUE (virtuals) ! 661: = build_vtable_entry (integer_zero_node, vfn); ! 662: /* The second slot is for the tdesc pointer when thunks are used. */ ! 663: vfn = flag_rtti ! 664: ? build_t_desc (type, 0) ! 665: : integer_zero_node; ! 666: vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, vfn); ! 667: TREE_CONSTANT (vfn) = 1; ! 668: ! 669: TREE_VALUE (TREE_CHAIN (virtuals)) ! 670: = build_vtable_entry (integer_zero_node, vfn); ! 671: } ! 672: } ! 673: 1.1 root 674: /* Give TYPE a new virtual function table which is initialized 675: with a skeleton-copy of its original initialization. The only 676: entry that changes is the `delta' entry, so we can really 677: share a lot of structure. 678: 679: FOR_TYPE is the derived type which caused this table to 680: be needed. 681: 682: BINFO is the type association which provided TYPE for FOR_TYPE. */ 683: static void 684: prepare_fresh_vtable (binfo, for_type) 685: tree binfo, for_type; 686: { 687: tree basetype = BINFO_TYPE (binfo); 688: tree orig_decl = BINFO_VTABLE (binfo); 689: /* This name is too simplistic. We can have multiple basetypes for 690: for_type, and we really want different names. (mrs) */ 691: tree name = build_type_pathname (VTABLE_NAME_FORMAT, basetype, for_type); 692: tree new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl)); 1.1.1.2 ! root 693: tree path, offset; 1.1 root 694: int result; 695: 696: /* Remember which class this vtable is really for. */ 697: DECL_CONTEXT (new_decl) = for_type; 698: 699: TREE_STATIC (new_decl) = 1; 700: BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl); 701: DECL_VIRTUAL_P (new_decl) = 1; 702: #ifndef WRITABLE_VTABLES 703: /* Make them READONLY by default. (mrs) */ 704: TREE_READONLY (new_decl) = 1; 705: #endif 706: DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl); 707: 708: /* Make fresh virtual list, so we can smash it later. */ 709: BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo)); 1.1.1.2 ! root 710: ! 711: if (TREE_VIA_VIRTUAL (binfo)) ! 712: offset = BINFO_OFFSET (binfo_member (BINFO_TYPE (binfo), ! 713: CLASSTYPE_VBASECLASSES (for_type))); ! 714: else ! 715: offset = BINFO_OFFSET (binfo); ! 716: ! 717: set_rtti_entry (BINFO_VIRTUALS (binfo), ! 718: size_binop (MINUS_EXPR, integer_zero_node, offset), ! 719: for_type); 1.1 root 720: 721: #ifdef GATHER_STATISTICS 722: n_vtables += 1; 723: n_vtable_elems += list_length (BINFO_VIRTUALS (binfo)); 724: #endif 725: 726: /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */ 1.1.1.2 ! root 727: import_export_vtable (new_decl, for_type, 0); 1.1 root 728: 729: if (TREE_VIA_VIRTUAL (binfo)) 730: my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo), 731: CLASSTYPE_VBASECLASSES (current_class_type)), 732: 170); 733: SET_BINFO_NEW_VTABLE_MARKED (binfo); 734: } 735: 736: /* Access the virtual function table entry that logically 737: contains BASE_FNDECL. VIRTUALS is the virtual function table's 738: initializer. We can run off the end, when dealing with virtual 739: destructors in MI situations, return NULL_TREE in that case. */ 740: static tree 741: get_vtable_entry (virtuals, base_fndecl) 742: tree virtuals, base_fndecl; 743: { 1.1.1.2 ! root 744: unsigned HOST_WIDE_INT n = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD 1.1 root 745: ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)) 746: & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1)) 747: : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))); 748: 749: #ifdef GATHER_STATISTICS 1.1.1.2 ! root 750: n_vtable_searches += n; 1.1 root 751: #endif 752: 1.1.1.2 ! root 753: while (n > 0 && virtuals) 1.1 root 754: { 1.1.1.2 ! root 755: --n; 1.1 root 756: virtuals = TREE_CHAIN (virtuals); 757: } 758: return virtuals; 759: } 760: 761: /* Put new entry ENTRY into virtual function table initializer 762: VIRTUALS. 763: 764: Also update DECL_VINDEX (FNDECL). */ 765: 766: static void 767: modify_vtable_entry (old_entry_in_list, new_entry, fndecl) 768: tree old_entry_in_list, new_entry, fndecl; 769: { 770: tree base_fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)), 0); 771: 772: #ifdef NOTQUITE 773: cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl), 774: DECL_ASSEMBLER_NAME (fndecl)); 775: #endif 776: TREE_VALUE (old_entry_in_list) = new_entry; 777: 778: /* Now assign virtual dispatch information, if unset. */ 779: /* We can dispatch this, through any overridden base function. */ 780: if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST) 781: { 782: DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl); 783: DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl); 784: } 785: } 786: 787: /* Access the virtual function table entry i. VIRTUALS is the virtual 788: function table's initializer. */ 789: static tree 1.1.1.2 ! root 790: get_vtable_entry_n (virtuals, n) 1.1 root 791: tree virtuals; 1.1.1.2 ! root 792: unsigned HOST_WIDE_INT n; 1.1 root 793: { 1.1.1.2 ! root 794: while (n > 0) 1.1 root 795: { 1.1.1.2 ! root 796: --n; 1.1 root 797: virtuals = TREE_CHAIN (virtuals); 798: } 799: return virtuals; 800: } 801: 802: /* Add a virtual function to all the appropriate vtables for the class 803: T. DECL_VINDEX(X) should be error_mark_node, if we want to 804: allocate a new slot in our table. If it is error_mark_node, we 805: know that no other function from another vtable is overridden by X. 806: HAS_VIRTUAL keeps track of how many virtuals there are in our main 807: vtable for the type, and we build upon the PENDING_VIRTUALS list 808: and return it. */ 809: static tree 810: add_virtual_function (pending_virtuals, has_virtual, fndecl, t) 811: tree pending_virtuals; 812: int *has_virtual; 813: tree fndecl; 814: tree t; /* Structure type. */ 815: { 816: /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely 817: convert to void *. Make such a conversion here. */ 818: tree vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl); 819: TREE_CONSTANT (vfn) = 1; 820: 821: #ifndef DUMB_USER 822: if (current_class_type == 0) 823: cp_warning ("internal problem, current_class_type is zero when adding `%D', please report", 824: fndecl); 825: if (current_class_type && t != current_class_type) 826: cp_warning ("internal problem, current_class_type differs when adding `%D', please report", 827: fndecl); 828: #endif 829: 830: /* If the virtual function is a redefinition of a prior one, 831: figure out in which base class the new definition goes, 832: and if necessary, make a fresh virtual function table 833: to hold that entry. */ 834: if (DECL_VINDEX (fndecl) == error_mark_node) 835: { 836: tree entry; 837: 1.1.1.2 ! root 838: if (flag_rtti && *has_virtual == 0) 1.1 root 839: { 1.1.1.2 ! root 840: /* CLASSTYPE_RTTI is only used as a Boolean (NULL or not). */ ! 841: CLASSTYPE_RTTI (t) = integer_one_node; 1.1 root 842: } 843: 1.1.1.2 ! root 844: /* If we are using thunks, use two slots at the front, one ! 845: for the offset pointer, one for the tdesc pointer. */ ! 846: if (*has_virtual == 0 && flag_vtable_thunks) ! 847: { ! 848: *has_virtual = 1; ! 849: } ! 850: 1.1 root 851: /* Build a new INT_CST for this DECL_VINDEX. */ 852: { 853: static tree index_table[256]; 854: tree index; 1.1.1.2 ! root 855: /* We skip a slot for the offset/tdesc entry. */ 1.1 root 856: int i = ++(*has_virtual); 857: 858: if (i >= 256 || index_table[i] == 0) 859: { 860: index = build_int_2 (i, 0); 861: if (i < 256) 862: index_table[i] = index; 863: } 864: else 865: index = index_table[i]; 866: 867: /* Now assign virtual dispatch information. */ 868: DECL_VINDEX (fndecl) = index; 869: DECL_CONTEXT (fndecl) = t; 870: } 871: entry = build_vtable_entry (integer_zero_node, vfn); 872: pending_virtuals = tree_cons (DECL_VINDEX (fndecl), entry, pending_virtuals); 873: } 874: /* Might already be INTEGER_CST if declared twice in class. We will 875: give error later or we've already given it. */ 876: else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST) 877: { 878: /* Need an entry in some other virtual function table. 879: Deal with this after we have laid out our virtual base classes. */ 880: pending_hard_virtuals = temp_tree_cons (fndecl, vfn, pending_hard_virtuals); 881: } 882: return pending_virtuals; 883: } 884: 885: /* Obstack on which to build the vector of class methods. */ 886: struct obstack class_obstack; 887: extern struct obstack *current_obstack; 888: 889: /* Add method METHOD to class TYPE. This is used when a method 890: has been defined which did not initially appear in the class definition, 891: and helps cut down on spurious error messages. 892: 893: FIELDS is the entry in the METHOD_VEC vector entry of the class type where 894: the method should be added. */ 895: void 896: add_method (type, fields, method) 897: tree type, *fields, method; 898: { 899: /* We must make a copy of METHOD here, since we must be sure that 900: we have exclusive title to this method's DECL_CHAIN. */ 901: tree decl; 902: 903: push_obstacks (&permanent_obstack, &permanent_obstack); 904: { 905: decl = copy_node (method); 906: if (DECL_RTL (decl) == 0 907: && (!processing_template_decl 908: || !uses_template_parms (decl))) 909: { 910: make_function_rtl (decl); 911: DECL_RTL (method) = DECL_RTL (decl); 912: } 913: } 914: 915: if (fields && *fields) 916: { 917: /* Take care not to hide destructor. */ 918: DECL_CHAIN (decl) = DECL_CHAIN (*fields); 919: DECL_CHAIN (*fields) = decl; 920: } 921: else if (CLASSTYPE_METHOD_VEC (type) == 0) 922: { 923: tree method_vec = make_node (TREE_VEC); 924: if (TYPE_IDENTIFIER (type) == DECL_NAME (decl)) 925: { 926: TREE_VEC_ELT (method_vec, 0) = decl; 927: TREE_VEC_LENGTH (method_vec) = 1; 928: } 929: else 930: { 931: /* ??? Is it possible for there to have been enough room in the 932: current chunk for the tree_vec structure but not a tree_vec 933: plus a tree*? Will this work in that case? */ 934: obstack_free (current_obstack, method_vec); 935: obstack_blank (current_obstack, sizeof (struct tree_vec) + sizeof (tree *)); 936: TREE_VEC_ELT (method_vec, 1) = decl; 937: TREE_VEC_LENGTH (method_vec) = 2; 938: obstack_finish (current_obstack); 939: } 940: CLASSTYPE_METHOD_VEC (type) = method_vec; 941: } 942: else 943: { 944: tree method_vec = CLASSTYPE_METHOD_VEC (type); 945: int len = TREE_VEC_LENGTH (method_vec); 946: 947: /* Adding a new ctor or dtor. This is easy because our 948: METHOD_VEC always has a slot for such entries. */ 949: if (TYPE_IDENTIFIER (type) == DECL_NAME (decl)) 950: { 951: /* TREE_VEC_ELT (method_vec, 0) = decl; */ 952: if (decl != TREE_VEC_ELT (method_vec, 0)) 953: { 954: DECL_CHAIN (decl) = TREE_VEC_ELT (method_vec, 0); 955: TREE_VEC_ELT (method_vec, 0) = decl; 956: } 957: } 958: else 959: { 960: /* This is trickier. We try to extend the TREE_VEC in-place, 961: but if that does not work, we copy all its data to a new 962: TREE_VEC that's large enough. */ 963: struct obstack *ob = &class_obstack; 964: tree *end = (tree *)obstack_next_free (ob); 965: 966: if (end != TREE_VEC_END (method_vec)) 967: { 968: ob = current_obstack; 969: TREE_VEC_LENGTH (method_vec) += 1; 970: TREE_VEC_ELT (method_vec, len) = NULL_TREE; 971: method_vec = copy_node (method_vec); 972: TREE_VEC_LENGTH (method_vec) -= 1; 973: } 974: else 975: { 976: tree tmp_vec = (tree) obstack_base (ob); 977: if (obstack_room (ob) < sizeof (tree)) 978: { 979: obstack_blank (ob, sizeof (struct tree_common) 980: + tree_code_length[(int) TREE_VEC] 981: * sizeof (char *) 982: + len * sizeof (tree)); 983: tmp_vec = (tree) obstack_base (ob); 984: bcopy ((char *) method_vec, (char *) tmp_vec, 985: (sizeof (struct tree_common) 986: + tree_code_length[(int) TREE_VEC] * sizeof (char *) 987: + (len-1) * sizeof (tree))); 988: method_vec = tmp_vec; 989: } 990: else 991: obstack_blank (ob, sizeof (tree)); 992: } 993: 994: obstack_finish (ob); 995: TREE_VEC_ELT (method_vec, len) = decl; 996: TREE_VEC_LENGTH (method_vec) = len + 1; 997: CLASSTYPE_METHOD_VEC (type) = method_vec; 998: 999: if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type)) 1000: { 1001: /* ??? May be better to know whether these can be extended? */ 1002: tree baselink_vec = CLASSTYPE_BASELINK_VEC (type); 1003: 1004: TREE_VEC_LENGTH (baselink_vec) += 1; 1005: CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec); 1006: TREE_VEC_LENGTH (baselink_vec) -= 1; 1007: 1008: TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0; 1009: } 1010: } 1011: } 1012: DECL_CONTEXT (decl) = type; 1013: DECL_CLASS_CONTEXT (decl) = type; 1014: 1015: pop_obstacks (); 1016: } 1017: 1018: /* Subroutines of finish_struct. */ 1019: 1020: /* Look through the list of fields for this struct, deleting 1021: duplicates as we go. This must be recursive to handle 1022: anonymous unions. 1023: 1024: FIELD is the field which may not appear anywhere in FIELDS. 1025: FIELD_PTR, if non-null, is the starting point at which 1026: chained deletions may take place. 1027: The value returned is the first acceptable entry found 1028: in FIELDS. 1029: 1030: Note that anonymous fields which are not of UNION_TYPE are 1031: not duplicates, they are just anonymous fields. This happens 1032: when we have unnamed bitfields, for example. */ 1033: static tree 1034: delete_duplicate_fields_1 (field, fields) 1035: tree field, fields; 1036: { 1037: tree x; 1038: tree prev = 0; 1039: if (DECL_NAME (field) == 0) 1040: { 1041: if (TREE_CODE (TREE_TYPE (field)) != UNION_TYPE) 1042: return fields; 1043: 1044: for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x)) 1045: fields = delete_duplicate_fields_1 (x, fields); 1046: return fields; 1047: } 1048: else 1049: { 1050: for (x = fields; x; prev = x, x = TREE_CHAIN (x)) 1051: { 1052: if (DECL_NAME (x) == 0) 1053: { 1054: if (TREE_CODE (TREE_TYPE (x)) != UNION_TYPE) 1055: continue; 1056: TYPE_FIELDS (TREE_TYPE (x)) 1057: = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x))); 1058: if (TYPE_FIELDS (TREE_TYPE (x)) == 0) 1059: { 1060: if (prev == 0) 1061: fields = TREE_CHAIN (fields); 1062: else 1063: TREE_CHAIN (prev) = TREE_CHAIN (x); 1064: } 1065: } 1066: else 1067: { 1068: if (DECL_NAME (field) == DECL_NAME (x)) 1069: { 1070: if (TREE_CODE (field) == CONST_DECL 1071: && TREE_CODE (x) == CONST_DECL) 1072: cp_error_at ("duplicate enum value `%D'", x); 1073: else if (TREE_CODE (field) == CONST_DECL 1074: || TREE_CODE (x) == CONST_DECL) 1075: cp_error_at ("duplicate field `%D' (as enum and non-enum)", 1076: x); 1077: else if (TREE_CODE (field) == TYPE_DECL 1078: && TREE_CODE (x) == TYPE_DECL) 1079: cp_error_at ("duplicate nested type `%D'", x); 1080: else if (TREE_CODE (field) == TYPE_DECL 1081: || TREE_CODE (x) == TYPE_DECL) 1082: cp_error_at ("duplicate field `%D' (as type and non-type)", 1083: x); 1084: else 1085: cp_error_at ("duplicate member `%D'", x); 1086: if (prev == 0) 1087: fields = TREE_CHAIN (fields); 1088: else 1089: TREE_CHAIN (prev) = TREE_CHAIN (x); 1090: } 1091: } 1092: } 1093: } 1094: return fields; 1095: } 1096: 1097: static void 1098: delete_duplicate_fields (fields) 1099: tree fields; 1100: { 1101: tree x; 1102: for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x)) 1103: TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x)); 1104: } 1105: 1106: /* Change the access of FDECL to ACCESS in T. 1107: Return 1 if change was legit, otherwise return 0. */ 1108: static int 1109: alter_access (t, fdecl, access) 1110: tree t; 1111: tree fdecl; 1112: enum access_type access; 1113: { 1114: tree elem = purpose_member (t, DECL_ACCESS (fdecl)); 1115: if (elem && TREE_VALUE (elem) != (tree)access) 1116: { 1117: if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL) 1118: { 1119: cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl)); 1120: } 1121: else 1122: error ("conflicting access specifications for field `%s', ignored", 1123: IDENTIFIER_POINTER (DECL_NAME (fdecl))); 1124: } 1.1.1.2 ! root 1125: else if (TREE_PRIVATE (fdecl)) ! 1126: { ! 1127: if (access != access_private) ! 1128: cp_error_at ("cannot make private `%D' non-private", fdecl); ! 1129: goto alter; ! 1130: } 1.1 root 1131: else if (TREE_PROTECTED (fdecl)) 1132: { 1.1.1.2 ! root 1133: if (access != access_protected) ! 1134: cp_error_at ("cannot make protected `%D' non-protected", fdecl); 1.1 root 1135: goto alter; 1136: } 1137: /* ARM 11.3: an access declaration may not be used to restrict access 1138: to a member that is accessible in the base class. */ 1.1.1.2 ! root 1139: else if (access != access_public) 1.1 root 1140: cp_error_at ("cannot reduce access of public member `%D'", fdecl); 1141: else if (elem == NULL_TREE) 1142: { 1143: alter: 1144: DECL_ACCESS (fdecl) = tree_cons (t, (tree)access, 1145: DECL_ACCESS (fdecl)); 1146: return 1; 1147: } 1148: return 0; 1149: } 1150: 1151: /* Return the offset to the main vtable for a given base BINFO. */ 1152: tree 1153: get_vfield_offset (binfo) 1154: tree binfo; 1155: { 1156: return size_binop (PLUS_EXPR, 1157: size_binop (FLOOR_DIV_EXPR, 1158: DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))), 1159: size_int (BITS_PER_UNIT)), 1160: BINFO_OFFSET (binfo)); 1161: } 1162: 1163: /* Get the offset to the start of the original binfo that we derived 1164: this binfo from. If we find TYPE first, return the offset only 1165: that far. The shortened search is useful because the this pointer 1166: on method calling is expected to point to a DECL_CONTEXT (fndecl) 1167: object, and not a baseclass of it. */ 1168: static tree 1169: get_derived_offset (binfo, type) 1170: tree binfo, type; 1171: { 1172: tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo))); 1173: tree offset2; 1174: int i; 1175: while (BINFO_BASETYPES (binfo) 1176: && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1) 1177: { 1178: tree binfos = BINFO_BASETYPES (binfo); 1179: if (BINFO_TYPE (binfo) == type) 1180: break; 1181: binfo = TREE_VEC_ELT (binfos, i); 1182: } 1183: offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo))); 1184: return size_binop (MINUS_EXPR, offset1, offset2); 1185: } 1186: 1187: /* If FOR_TYPE needs to reinitialize virtual function table pointers 1188: for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST. 1189: Returns BASE_INIT_LIST appropriately modified. */ 1190: 1191: static tree 1192: maybe_fixup_vptrs (for_type, binfo, base_init_list) 1193: tree for_type, binfo, base_init_list; 1194: { 1195: /* Now reinitialize any slots that don't fall under our virtual 1196: function table pointer. */ 1197: tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)); 1198: while (vfields) 1199: { 1200: tree basetype = VF_NORMAL_VALUE (vfields) 1201: ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields)) 1202: : VF_BASETYPE_VALUE (vfields); 1203: 1204: tree base_binfo = get_binfo (basetype, for_type, 0); 1205: /* Punt until this is implemented. */ 1206: if (1 /* BINFO_MODIFIED (base_binfo) */) 1207: { 1208: tree base_offset = get_vfield_offset (base_binfo); 1209: if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type))) 1210: && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo))) 1211: base_init_list = tree_cons (error_mark_node, base_binfo, 1212: base_init_list); 1213: } 1214: vfields = TREE_CHAIN (vfields); 1215: } 1216: return base_init_list; 1217: } 1218: 1219: /* If TYPE does not have a constructor, then the compiler must 1220: manually deal with all of the initialization this type requires. 1221: 1222: If a base initializer exists only to fill in the virtual function 1223: table pointer, then we mark that fact with the TREE_VIRTUAL bit. 1224: This way, we avoid multiple initializations of the same field by 1225: each virtual function table up the class hierarchy. 1226: 1227: Virtual base class pointers are not initialized here. They are 1228: initialized only at the "top level" of object creation. If we 1229: initialized them here, we would have to skip a lot of work. */ 1230: 1231: static void 1232: build_class_init_list (type) 1233: tree type; 1234: { 1235: tree base_init_list = NULL_TREE; 1236: tree member_init_list = NULL_TREE; 1237: 1238: /* Since we build member_init_list and base_init_list using 1239: tree_cons, backwards fields the all through work. */ 1240: tree x; 1241: tree binfos = BINFO_BASETYPES (TYPE_BINFO (type)); 1242: int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; 1243: 1244: for (x = TYPE_FIELDS (type); x; x = TREE_CHAIN (x)) 1245: { 1246: if (TREE_CODE (x) != FIELD_DECL) 1247: continue; 1248: 1249: if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x)) 1250: || DECL_INITIAL (x) != NULL_TREE) 1251: member_init_list = tree_cons (x, type, member_init_list); 1252: } 1253: member_init_list = nreverse (member_init_list); 1254: 1255: /* We will end up doing this last. Need special marker 1256: to avoid infinite regress. */ 1257: if (TYPE_VIRTUAL_P (type)) 1258: { 1259: base_init_list = build_tree_list (error_mark_node, TYPE_BINFO (type)); 1260: if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type) == 0) 1261: TREE_VALUE (base_init_list) = NULL_TREE; 1262: TREE_ADDRESSABLE (base_init_list) = 1; 1263: } 1264: 1265: /* Each base class which needs to have initialization 1266: of some kind gets to make such requests known here. */ 1267: for (i = n_baseclasses-1; i >= 0; i--) 1268: { 1269: tree base_binfo = TREE_VEC_ELT (binfos, i); 1270: tree blist; 1271: 1272: /* Don't initialize virtual baseclasses this way. */ 1273: if (TREE_VIA_VIRTUAL (base_binfo)) 1274: continue; 1275: 1276: if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (base_binfo))) 1277: { 1278: /* ...and the last shall come first... */ 1279: base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list); 1280: base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list); 1281: continue; 1282: } 1283: 1284: if ((blist = CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (base_binfo))) == NULL_TREE) 1285: /* Nothing to initialize. */ 1286: continue; 1287: 1288: /* ...ditto... */ 1289: base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list); 1290: 1291: /* This is normally true for single inheritance. 1292: The win is we can shrink the chain of initializations 1293: to be done by only converting to the actual type 1294: we are interested in. */ 1295: if (TREE_VALUE (blist) 1296: && TREE_CODE (TREE_VALUE (blist)) == TREE_VEC 1297: && tree_int_cst_equal (BINFO_OFFSET (base_binfo), 1298: BINFO_OFFSET (TREE_VALUE (blist)))) 1299: { 1300: if (base_init_list) 1301: { 1302: /* Does it do more than just fill in a 1303: virtual function table pointer? */ 1304: if (! TREE_ADDRESSABLE (blist)) 1305: base_init_list = build_tree_list (blist, base_init_list); 1306: /* Can we get by just with the virtual function table 1307: pointer that it fills in? */ 1308: else if (TREE_ADDRESSABLE (base_init_list) 1309: && TREE_VALUE (base_init_list) == 0) 1310: base_init_list = blist; 1311: /* Maybe, but it is not obvious as the previous case. */ 1312: else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type)) 1313: { 1314: tree last = tree_last (base_init_list); 1315: while (TREE_VALUE (last) 1316: && TREE_CODE (TREE_VALUE (last)) == TREE_LIST) 1317: last = tree_last (TREE_VALUE (last)); 1318: if (TREE_VALUE (last) == 0) 1319: base_init_list = build_tree_list (blist, base_init_list); 1320: } 1321: } 1322: else 1323: base_init_list = blist; 1324: } 1325: else 1326: { 1327: /* The function expand_aggr_init knows how to do the 1328: initialization of `basetype' without getting 1329: an explicit `blist'. */ 1330: if (base_init_list) 1331: base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list); 1332: else 1333: base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo)); 1334: } 1335: } 1336: 1337: if (base_init_list) 1338: if (member_init_list) 1339: CLASSTYPE_BASE_INIT_LIST (type) = build_tree_list (base_init_list, member_init_list); 1340: else 1341: CLASSTYPE_BASE_INIT_LIST (type) = base_init_list; 1342: else if (member_init_list) 1343: CLASSTYPE_BASE_INIT_LIST (type) = member_init_list; 1344: } 1345: 1346: struct base_info 1347: { 1348: int has_virtual; 1349: int max_has_virtual; 1350: int n_ancestors; 1351: tree vfield; 1352: tree vfields; 1353: char cant_have_default_ctor; 1354: char cant_have_const_ctor; 1355: char cant_synth_copy_ctor; 1356: char cant_synth_asn_ref; 1357: char no_const_asn_ref; 1358: char needs_virtual_dtor; 1359: }; 1360: 1361: /* Record information about type T derived from its base classes. 1362: Store most of that information in T itself, and place the 1363: remaining information in the struct BASE_INFO. 1364: 1365: Propagate basetype offsets throughout the lattice. Note that the 1366: lattice topped by T is really a pair: it's a DAG that gives the 1367: structure of the derivation hierarchy, and it's a list of the 1368: virtual baseclasses that appear anywhere in the DAG. When a vbase 1369: type appears in the DAG, it's offset is 0, and it's children start 1370: their offsets from that point. When a vbase type appears in the list, 1371: its offset is the offset it has in the hierarchy, and its children's 1372: offsets include that offset in theirs. 1373: 1374: Returns the index of the first base class to have virtual functions, 1375: or -1 if no such base class. 1376: 1377: Note that at this point TYPE_BINFO (t) != t_binfo. */ 1378: 1379: static int 1380: finish_base_struct (t, b, t_binfo) 1381: tree t; 1382: struct base_info *b; 1383: tree t_binfo; 1384: { 1385: tree binfos = BINFO_BASETYPES (t_binfo); 1386: int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; 1387: int first_vfn_base_index = -1; 1388: bzero ((char *) b, sizeof (struct base_info)); 1389: 1390: for (i = 0; i < n_baseclasses; i++) 1391: { 1392: tree base_binfo = TREE_VEC_ELT (binfos, i); 1393: tree basetype = BINFO_TYPE (base_binfo); 1394: 1395: /* If the type of basetype is incomplete, then 1396: we already complained about that fact 1397: (and we should have fixed it up as well). */ 1398: if (TYPE_SIZE (basetype) == 0) 1399: { 1400: int j; 1401: /* The base type is of incomplete type. It is 1402: probably best to pretend that it does not 1403: exist. */ 1404: if (i == n_baseclasses-1) 1405: TREE_VEC_ELT (binfos, i) = NULL_TREE; 1406: TREE_VEC_LENGTH (binfos) -= 1; 1407: n_baseclasses -= 1; 1408: for (j = i; j+1 < n_baseclasses; j++) 1409: TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1); 1410: } 1411: 1412: if (TYPE_HAS_INIT_REF (basetype) 1413: && !TYPE_HAS_CONST_INIT_REF (basetype)) 1414: b->cant_have_const_ctor = 1; 1415: if (! TYPE_HAS_INIT_REF (basetype) 1416: || (TYPE_HAS_NONPUBLIC_CTOR (basetype) == 2 1417: && ! is_friend_type (t, basetype))) 1418: b->cant_synth_copy_ctor = 1; 1419: 1420: if (TYPE_HAS_CONSTRUCTOR (basetype) 1421: && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)) 1422: { 1423: b->cant_have_default_ctor = 1; 1424: if (! TYPE_HAS_CONSTRUCTOR (t)) 1425: { 1426: cp_pedwarn ("base `%T' with only non-default constructor", 1427: basetype); 1428: cp_pedwarn ("in class without a constructor"); 1429: } 1430: } 1431: 1432: if (TYPE_HAS_ASSIGN_REF (basetype) 1433: && !TYPE_HAS_CONST_ASSIGN_REF (basetype)) 1434: b->no_const_asn_ref = 1; 1435: if (! TYPE_HAS_ASSIGN_REF (basetype) 1436: || TYPE_HAS_ABSTRACT_ASSIGN_REF (basetype) 1437: || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (basetype) == 2 1438: && ! is_friend_type (t, basetype))) 1439: b->cant_synth_asn_ref = 1; 1440: 1441: b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype); 1442: TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype); 1443: TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype); 1444: TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype); 1.1.1.2 ! root 1445: TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype); 1.1 root 1446: 1447: TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype); 1448: TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype); 1449: TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype); 1450: 1451: if (! TREE_VIA_VIRTUAL (base_binfo) 1452: #if 0 1453: /* This cannot be done, as prepare_fresh_vtable wants to modify 1454: binfos associated with vfields anywhere in the hierarchy, not 1455: just immediate base classes. Due to unsharing, the compiler 1456: might consume 3% more memory on a real program. 1457: */ 1458: && ! BINFO_OFFSET_ZEROP (base_binfo) 1459: #endif 1460: && BINFO_BASETYPES (base_binfo)) 1461: { 1462: tree base_binfos = BINFO_BASETYPES (base_binfo); 1463: tree chain = NULL_TREE; 1464: int j; 1465: 1466: /* Now unshare the structure beneath BASE_BINFO. */ 1467: for (j = TREE_VEC_LENGTH (base_binfos)-1; 1468: j >= 0; j--) 1469: { 1470: tree base_base_binfo = TREE_VEC_ELT (base_binfos, j); 1471: if (! TREE_VIA_VIRTUAL (base_base_binfo)) 1472: TREE_VEC_ELT (base_binfos, j) 1473: = make_binfo (BINFO_OFFSET (base_base_binfo), 1474: base_base_binfo, 1475: BINFO_VTABLE (base_base_binfo), 1476: BINFO_VIRTUALS (base_base_binfo), 1477: chain); 1478: chain = TREE_VEC_ELT (base_binfos, j); 1479: TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo); 1480: TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo); 1.1.1.2 ! root 1481: BINFO_INHERITANCE_CHAIN (chain) = base_binfo; 1.1 root 1482: } 1483: 1484: /* Completely unshare potentially shared data, and 1485: update what is ours. */ 1486: propagate_binfo_offsets (base_binfo, BINFO_OFFSET (base_binfo)); 1487: } 1488: 1489: if (! TREE_VIA_VIRTUAL (base_binfo)) 1490: CLASSTYPE_N_SUPERCLASSES (t) += 1; 1491: 1492: if (TYPE_VIRTUAL_P (basetype)) 1493: { 1494: /* If there's going to be a destructor needed, make 1495: sure it will be virtual. */ 1496: b->needs_virtual_dtor = 1; 1497: 1498: /* Don't borrow virtuals from virtual baseclasses. */ 1499: if (TREE_VIA_VIRTUAL (base_binfo)) 1500: continue; 1501: 1502: if (first_vfn_base_index < 0) 1503: { 1504: tree vfields; 1505: first_vfn_base_index = i; 1506: 1507: /* Update these two, now that we know what vtable we are 1508: going to extend. This is so that we can add virtual 1509: functions, and override them properly. */ 1510: BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype); 1511: BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype); 1512: b->has_virtual = CLASSTYPE_VSIZE (basetype); 1513: b->vfield = CLASSTYPE_VFIELD (basetype); 1514: b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype)); 1515: vfields = b->vfields; 1516: while (vfields) 1517: { 1518: if (VF_BINFO_VALUE (vfields) == NULL_TREE 1519: || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields))) 1520: { 1521: tree value = VF_BASETYPE_VALUE (vfields); 1522: if (DECL_NAME (CLASSTYPE_VFIELD (value)) 1523: == DECL_NAME (CLASSTYPE_VFIELD (basetype))) 1524: VF_NORMAL_VALUE (b->vfields) = basetype; 1525: else 1526: VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields); 1527: } 1528: vfields = TREE_CHAIN (vfields); 1529: } 1530: CLASSTYPE_VFIELD (t) = b->vfield; 1531: } 1532: else 1533: { 1534: /* Only add unique vfields, and flatten them out as we go. */ 1535: tree vfields = CLASSTYPE_VFIELDS (basetype); 1536: while (vfields) 1537: { 1538: if (VF_BINFO_VALUE (vfields) == NULL_TREE 1539: || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields))) 1540: { 1541: tree value = VF_BASETYPE_VALUE (vfields); 1542: b->vfields = tree_cons (base_binfo, value, b->vfields); 1543: if (DECL_NAME (CLASSTYPE_VFIELD (value)) 1544: == DECL_NAME (CLASSTYPE_VFIELD (basetype))) 1545: VF_NORMAL_VALUE (b->vfields) = basetype; 1546: else 1547: VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields); 1548: } 1549: vfields = TREE_CHAIN (vfields); 1550: } 1551: 1552: if (b->has_virtual == 0) 1553: { 1554: first_vfn_base_index = i; 1555: 1556: /* Update these two, now that we know what vtable we are 1557: going to extend. This is so that we can add virtual 1558: functions, and override them properly. */ 1559: BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype); 1560: BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype); 1561: b->has_virtual = CLASSTYPE_VSIZE (basetype); 1562: b->vfield = CLASSTYPE_VFIELD (basetype); 1563: CLASSTYPE_VFIELD (t) = b->vfield; 1564: /* When we install the first one, set the VF_NORMAL_VALUE 1565: to be the current class, as this it is the most derived 1566: class. Hopefully, this is not set to something else 1567: later. (mrs) */ 1568: vfields = b->vfields; 1569: while (vfields) 1570: { 1571: if (DECL_NAME (CLASSTYPE_VFIELD (t)) 1572: == DECL_NAME (CLASSTYPE_VFIELD (basetype))) 1573: { 1574: VF_NORMAL_VALUE (vfields) = t; 1575: /* There should only be one of them! And it should 1576: always be found, if we get into here. (mrs) */ 1577: break; 1578: } 1579: vfields = TREE_CHAIN (vfields); 1580: } 1581: } 1582: } 1583: } 1584: } 1585: 1586: /* Must come after offsets are fixed for all bases. */ 1587: for (i = 0; i < n_baseclasses; i++) 1588: { 1589: tree base_binfo = TREE_VEC_ELT (binfos, i); 1590: tree basetype = BINFO_TYPE (base_binfo); 1591: 1592: if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2) 1593: { 1594: cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity", 1595: basetype, t); 1596: b->cant_synth_asn_ref = 1; 1597: b->cant_synth_copy_ctor = 1; 1598: } 1599: } 1600: { 1601: tree v = get_vbase_types (t_binfo); 1602: 1603: for (; v; v = TREE_CHAIN (v)) 1604: { 1605: tree basetype = BINFO_TYPE (v); 1606: if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2) 1607: { 1608: if (extra_warnings) 1609: cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity", 1610: basetype, t); 1611: b->cant_synth_asn_ref = 1; 1612: b->cant_synth_copy_ctor = 1; 1613: } 1614: } 1615: } 1616: 1617: { 1618: tree vfields; 1619: /* Find the base class with the largest number of virtual functions. */ 1620: for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields)) 1621: { 1622: if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual) 1623: b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)); 1624: if (VF_DERIVED_VALUE (vfields) 1625: && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual) 1626: b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)); 1627: } 1628: } 1629: 1630: if (b->vfield == 0) 1631: /* If all virtual functions come only from virtual baseclasses. */ 1632: return -1; 1633: return first_vfn_base_index; 1634: } 1635: 1636: static int 1637: typecode_p (type, code) 1638: tree type; 1639: enum tree_code code; 1640: { 1641: return (TREE_CODE (type) == code 1642: || (TREE_CODE (type) == REFERENCE_TYPE 1643: && TREE_CODE (TREE_TYPE (type)) == code)); 1644: } 1645: 1646: /* Set memoizing fields and bits of T (and its variants) for later use. 1647: MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */ 1648: static void 1649: finish_struct_bits (t, max_has_virtual) 1650: tree t; 1651: int max_has_virtual; 1652: { 1653: int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t); 1654: tree method_vec = CLASSTYPE_METHOD_VEC (t); 1655: 1656: /* Fix up variants (if any). */ 1657: tree variants = TYPE_NEXT_VARIANT (t); 1658: while (variants) 1659: { 1660: /* These fields are in the _TYPE part of the node, not in 1661: the TYPE_LANG_SPECIFIC component, so they are not shared. */ 1662: TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t); 1663: TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t); 1664: TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t); 1665: TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t); 1666: 1667: TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t); 1668: TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t); 1669: TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t); 1670: /* Copy whatever these are holding today. */ 1671: TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t); 1672: TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t); 1673: variants = TYPE_NEXT_VARIANT (variants); 1674: } 1675: 1676: if (n_baseclasses && max_has_virtual) 1677: { 1678: /* Done by `finish_struct' for classes without baseclasses. */ 1679: int might_have_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0; 1680: tree binfos = TYPE_BINFO_BASETYPES (t); 1681: for (i = n_baseclasses-1; i >= 0; i--) 1682: { 1683: might_have_abstract_virtuals 1684: |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0); 1685: if (might_have_abstract_virtuals) 1686: break; 1687: } 1688: if (might_have_abstract_virtuals) 1689: { 1690: /* We use error_mark_node from override_one_vtable to signal 1691: an artificial abstract. */ 1692: if (CLASSTYPE_ABSTRACT_VIRTUALS (t) == error_mark_node) 1693: CLASSTYPE_ABSTRACT_VIRTUALS (t) = NULL_TREE; 1694: CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t); 1695: } 1696: } 1697: 1698: if (n_baseclasses) 1699: { 1700: /* Notice whether this class has type conversion functions defined. */ 1701: tree binfo = TYPE_BINFO (t); 1702: tree binfos = BINFO_BASETYPES (binfo); 1703: tree basetype; 1704: 1705: for (i = n_baseclasses-1; i >= 0; i--) 1706: { 1707: basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i)); 1708: 1709: if (TYPE_HAS_CONVERSION (basetype)) 1710: { 1711: TYPE_HAS_CONVERSION (t) = 1; 1712: TYPE_HAS_INT_CONVERSION (t) |= TYPE_HAS_INT_CONVERSION (basetype); 1713: TYPE_HAS_REAL_CONVERSION (t) |= TYPE_HAS_REAL_CONVERSION (basetype); 1714: } 1715: if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t)) 1716: CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1; 1717: } 1718: } 1719: 1.1.1.2 ! root 1720: /* If this type has a copy constructor, force its mode to be BLKmode, and ! 1721: force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to ! 1722: be passed by invisible reference and prevent it from being returned in ! 1723: a register. */ ! 1724: if (! TYPE_HAS_TRIVIAL_INIT_REF (t)) 1.1 root 1725: { 1.1.1.2 ! root 1726: tree variants; 1.1 root 1727: if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL) 1728: DECL_MODE (TYPE_NAME (t)) = BLKmode; 1.1.1.2 ! root 1729: for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants)) 1.1 root 1730: { 1731: TYPE_MODE (variants) = BLKmode; 1732: TREE_ADDRESSABLE (variants) = 1; 1733: } 1734: } 1735: } 1736: 1.1.1.2 ! root 1737: /* Add FN to the method_vec growing on the class_obstack. Used by ! 1738: finish_struct_methods. */ ! 1739: static void ! 1740: grow_method (fn, method_vec_ptr) ! 1741: tree fn; ! 1742: tree *method_vec_ptr; ! 1743: { ! 1744: tree method_vec = (tree)obstack_base (&class_obstack); ! 1745: tree *testp = &TREE_VEC_ELT (method_vec, 0); ! 1746: if (*testp == NULL_TREE) ! 1747: testp++; ! 1748: while (((HOST_WIDE_INT) testp ! 1749: < (HOST_WIDE_INT) obstack_next_free (&class_obstack)) ! 1750: && DECL_NAME (*testp) != DECL_NAME (fn)) ! 1751: testp++; ! 1752: if ((HOST_WIDE_INT) testp ! 1753: < (HOST_WIDE_INT) obstack_next_free (&class_obstack)) ! 1754: { ! 1755: tree x, prev_x; ! 1756: ! 1757: for (x = *testp; x; x = DECL_CHAIN (x)) ! 1758: { ! 1759: if (DECL_NAME (fn) == ansi_opname[(int) DELETE_EXPR] ! 1760: || DECL_NAME (fn) == ansi_opname[(int) VEC_DELETE_EXPR]) ! 1761: { ! 1762: /* ANSI C++ June 5 1992 WP 12.5.5.1 */ ! 1763: cp_error_at ("`%D' overloaded", fn); ! 1764: cp_error_at ("previous declaration as `%D' here", x); ! 1765: } ! 1766: if (DECL_ASSEMBLER_NAME (fn)==DECL_ASSEMBLER_NAME (x)) ! 1767: { ! 1768: /* We complain about multiple destructors on sight, ! 1769: so we do not repeat the warning here. Friend-friend ! 1770: ambiguities are warned about outside this loop. */ ! 1771: if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn))) ! 1772: cp_error_at ("ambiguous method `%#D' in structure", fn); ! 1773: break; ! 1774: } ! 1775: prev_x = x; ! 1776: } ! 1777: if (x == 0) ! 1778: { ! 1779: if (*testp) ! 1780: DECL_CHAIN (prev_x) = fn; ! 1781: else ! 1782: *testp = fn; ! 1783: } ! 1784: } ! 1785: else ! 1786: { ! 1787: obstack_ptr_grow (&class_obstack, fn); ! 1788: *method_vec_ptr = (tree)obstack_base (&class_obstack); ! 1789: } ! 1790: } ! 1791: 1.1 root 1792: /* Warn about duplicate methods in fn_fields. Also compact method 1793: lists so that lookup can be made faster. 1794: 1795: Algorithm: Outer loop builds lists by method name. Inner loop 1796: checks for redundant method names within a list. 1797: 1798: Data Structure: List of method lists. The outer list is a 1799: TREE_LIST, whose TREE_PURPOSE field is the field name and the 1.1.1.2 ! root 1800: TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN ! 1801: links the entire list of methods for TYPE_METHODS. Friends are ! 1802: chained in the same way as member functions (? TREE_CHAIN or ! 1803: DECL_CHAIN), but they live in the TREE_TYPE field of the outer ! 1804: list. That allows them to be quickly deleted, and requires no ! 1805: extra storage. 1.1 root 1806: 1807: If there are any constructors/destructors, they are moved to the 1808: front of the list. This makes pushclass more efficient. 1809: 1810: We also link each field which has shares a name with its baseclass 1811: to the head of the list of fields for that base class. This allows 1812: us to reduce search time in places like `build_method_call' to 1813: consider only reasonably likely functions. */ 1814: 1815: static tree 1816: finish_struct_methods (t, fn_fields, nonprivate_method) 1817: tree t; 1818: tree fn_fields; 1819: int nonprivate_method; 1820: { 1821: tree method_vec; 1.1.1.2 ! root 1822: tree save_fn_fields = tree_cons (NULL_TREE, NULL_TREE, fn_fields); ! 1823: tree lastp; 1.1 root 1824: tree name = constructor_name (t); 1825: int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t); 1826: 1827: /* Now prepare to gather fn_fields into vector. */ 1828: struct obstack *ambient_obstack = current_obstack; 1829: current_obstack = &class_obstack; 1830: method_vec = make_node (TREE_VEC); 1831: /* Room has been saved for constructors and destructors. */ 1832: current_obstack = ambient_obstack; 1833: /* Now make this a live vector. */ 1834: obstack_free (&class_obstack, method_vec); 1835: obstack_blank (&class_obstack, sizeof (struct tree_vec)); 1836: 1.1.1.2 ! root 1837: /* First fill in entry 0 with the constructors, and the next few with ! 1838: type conversion operators (if any). */ ! 1839: ! 1840: for (lastp = save_fn_fields; fn_fields; fn_fields = TREE_CHAIN (lastp)) 1.1 root 1841: { 1842: tree fn_name = DECL_NAME (fn_fields); 1843: if (fn_name == NULL_TREE) 1844: fn_name = name; 1845: 1846: /* Clear out this flag. 1847: 1848: @@ Doug may figure out how to break 1849: @@ this with nested classes and friends. */ 1850: DECL_IN_AGGR_P (fn_fields) = 0; 1851: 1852: /* Note here that a copy ctor is private, so we don't dare generate 1853: a default copy constructor for a class that has a member 1854: of this type without making sure they have access to it. */ 1855: if (fn_name == name) 1856: { 1857: tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields); 1858: tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; 1859: 1860: if (TREE_CODE (parmtype) == REFERENCE_TYPE 1861: && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t) 1862: { 1863: if (TREE_CHAIN (parmtypes) == NULL_TREE 1864: || TREE_CHAIN (parmtypes) == void_list_node 1865: || TREE_PURPOSE (TREE_CHAIN (parmtypes))) 1866: { 1867: if (TREE_PROTECTED (fn_fields)) 1868: TYPE_HAS_NONPUBLIC_CTOR (t) = 1; 1869: else if (TREE_PRIVATE (fn_fields)) 1870: TYPE_HAS_NONPUBLIC_CTOR (t) = 2; 1871: } 1872: } 1.1.1.2 ! root 1873: /* Constructors are handled easily in search routines. */ ! 1874: DECL_CHAIN (fn_fields) = TREE_VEC_ELT (method_vec, 0); ! 1875: TREE_VEC_ELT (method_vec, 0) = fn_fields; 1.1 root 1876: } 1.1.1.2 ! root 1877: else if (IDENTIFIER_TYPENAME_P (fn_name)) ! 1878: { ! 1879: tree return_type = TREE_TYPE (TREE_TYPE (fn_fields)); ! 1880: ! 1881: if (typecode_p (return_type, INTEGER_TYPE) ! 1882: || typecode_p (return_type, BOOLEAN_TYPE) ! 1883: || typecode_p (return_type, ENUMERAL_TYPE)) ! 1884: TYPE_HAS_INT_CONVERSION (t) = 1; ! 1885: else if (typecode_p (return_type, REAL_TYPE)) ! 1886: TYPE_HAS_REAL_CONVERSION (t) = 1; ! 1887: ! 1888: grow_method (fn_fields, &method_vec); ! 1889: } ! 1890: else ! 1891: { ! 1892: lastp = fn_fields; ! 1893: continue; ! 1894: } ! 1895: ! 1896: TREE_CHAIN (lastp) = TREE_CHAIN (fn_fields); ! 1897: TREE_CHAIN (fn_fields) = NULL_TREE; ! 1898: } ! 1899: ! 1900: fn_fields = TREE_CHAIN (save_fn_fields); ! 1901: while (fn_fields) ! 1902: { ! 1903: tree nextp; ! 1904: tree fn_name = DECL_NAME (fn_fields); ! 1905: if (fn_name == NULL_TREE) ! 1906: fn_name = name; ! 1907: ! 1908: nextp = TREE_CHAIN (fn_fields); ! 1909: TREE_CHAIN (fn_fields) = NULL_TREE; ! 1910: ! 1911: if (fn_name == ansi_opname[(int) MODIFY_EXPR]) 1.1 root 1912: { 1913: tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields)); 1914: 1915: if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields))) 1916: { 1917: if (TREE_PROTECTED (fn_fields)) 1918: TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1; 1919: else if (TREE_PRIVATE (fn_fields)) 1920: TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2; 1921: } 1922: } 1923: 1.1.1.2 ! root 1924: grow_method (fn_fields, &method_vec); 1.1 root 1925: fn_fields = nextp; 1926: } 1927: 1928: TREE_VEC_LENGTH (method_vec) = (tree *)obstack_next_free (&class_obstack) 1929: - (&TREE_VEC_ELT (method_vec, 0)); 1930: obstack_finish (&class_obstack); 1931: CLASSTYPE_METHOD_VEC (t) = method_vec; 1932: 1933: if (nonprivate_method == 0 1934: && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE 1935: && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE) 1936: { 1937: tree binfos = BINFO_BASETYPES (TYPE_BINFO (t)); 1938: for (i = 0; i < n_baseclasses; i++) 1939: if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i)) 1940: || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i))) 1941: { 1942: nonprivate_method = 1; 1943: break; 1944: } 1945: if (nonprivate_method == 0) 1946: cp_warning ("all member functions in class `%T' are private", t); 1947: } 1948: 1949: /* If there are constructors (and destructors), they are at the 1950: front. Place destructors at very front. Also warn if all 1951: constructors and/or destructors are private (in which case this 1952: class is effectively unusable. */ 1953: if (TYPE_HAS_DESTRUCTOR (t)) 1954: { 1955: tree dtor, prev; 1956: 1957: for (dtor = TREE_VEC_ELT (method_vec, 0); 1958: dtor; 1959: prev = dtor, dtor = DECL_CHAIN (dtor)) 1960: { 1961: if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (dtor))) 1962: { 1963: if (TREE_PRIVATE (dtor) 1964: && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE 1965: && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE 1966: && warn_ctor_dtor_privacy) 1967: cp_warning ("`%#T' only defines a private destructor and has no friends", 1968: t); 1969: break; 1970: } 1971: } 1972: 1973: /* Wild parse errors can cause this to happen. */ 1974: if (dtor == NULL_TREE) 1975: TYPE_HAS_DESTRUCTOR (t) = 0; 1976: else if (dtor != TREE_VEC_ELT (method_vec, 0)) 1977: { 1978: DECL_CHAIN (prev) = DECL_CHAIN (dtor); 1979: DECL_CHAIN (dtor) = TREE_VEC_ELT (method_vec, 0); 1980: TREE_VEC_ELT (method_vec, 0) = dtor; 1981: } 1982: } 1983: 1984: /* Now for each member function (except for constructors and 1985: destructors), compute where member functions of the same 1986: name reside in base classes. */ 1987: if (n_baseclasses != 0 1988: && TREE_VEC_LENGTH (method_vec) > 1) 1989: { 1990: int len = TREE_VEC_LENGTH (method_vec); 1991: tree baselink_vec = make_tree_vec (len); 1992: int any_links = 0; 1993: tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t)); 1994: 1995: for (i = 1; i < len; i++) 1996: { 1997: TREE_VEC_ELT (baselink_vec, i) 1998: = get_baselinks (baselink_binfo, t, DECL_NAME (TREE_VEC_ELT (method_vec, i))); 1999: if (TREE_VEC_ELT (baselink_vec, i) != 0) 2000: any_links = 1; 2001: } 2002: if (any_links != 0) 2003: CLASSTYPE_BASELINK_VEC (t) = baselink_vec; 2004: else 2005: obstack_free (current_obstack, baselink_vec); 2006: } 2007: 2008: /* Now add the methods to the TYPE_METHODS of T, arranged in a chain. */ 2009: { 2010: tree x, last_x = NULL_TREE; 2011: int limit = TREE_VEC_LENGTH (method_vec); 2012: 2013: for (i = 1; i < limit; i++) 2014: { 2015: for (x = TREE_VEC_ELT (method_vec, i); x; x = DECL_CHAIN (x)) 2016: { 2017: if (last_x != NULL_TREE) 2018: TREE_CHAIN (last_x) = x; 2019: last_x = x; 2020: } 2021: } 2022: 2023: /* Put ctors and dtors at the front of the list. */ 2024: x = TREE_VEC_ELT (method_vec, 0); 2025: if (x) 2026: { 2027: while (DECL_CHAIN (x)) 2028: { 2029: /* Let's avoid being circular about this. */ 2030: if (x == DECL_CHAIN (x)) 2031: break; 2032: TREE_CHAIN (x) = DECL_CHAIN (x); 2033: x = DECL_CHAIN (x); 2034: } 2035: if (TREE_VEC_LENGTH (method_vec) > 1) 2036: TREE_CHAIN (x) = TREE_VEC_ELT (method_vec, 1); 2037: else 2038: TREE_CHAIN (x) = NULL_TREE; 2039: } 2040: } 2041: 2042: TYPE_METHODS (t) = method_vec; 2043: 2044: return method_vec; 2045: } 2046: 2047: /* Emit error when a duplicate definition of a type is seen. Patch up. */ 2048: 2049: void 2050: duplicate_tag_error (t) 2051: tree t; 2052: { 2053: cp_error ("redefinition of `%#T'", t); 1.1.1.2 ! root 2054: cp_error_at ("previous definition here", t); 1.1 root 2055: 2056: /* Pretend we haven't defined this type. */ 2057: 2058: /* All of the component_decl's were TREE_CHAINed together in the parser. 2059: finish_struct_methods walks these chains and assembles all methods with 2060: the same base name into DECL_CHAINs. Now we don't need the parser chains 2061: anymore, so we unravel them. 2062: */ 2063: /* 2064: * This used to be in finish_struct, but it turns out that the 2065: * TREE_CHAIN is used by dbxout_type_methods and perhaps some other things... 2066: */ 2067: if (CLASSTYPE_METHOD_VEC(t)) 2068: { 2069: tree tv = CLASSTYPE_METHOD_VEC(t); 2070: int i, len = TREE_VEC_LENGTH (tv); 2071: for (i = 0; i < len; i++) 2072: { 2073: tree unchain = TREE_VEC_ELT (tv, i); 2074: while (unchain != NULL_TREE) 2075: { 2076: TREE_CHAIN (unchain) = NULL_TREE; 2077: unchain = DECL_CHAIN(unchain); 2078: } 2079: } 2080: } 2081: 2082: if (TYPE_LANG_SPECIFIC (t)) 2083: { 2084: tree as_list = CLASSTYPE_AS_LIST (t); 2085: tree binfo = TYPE_BINFO (t); 2086: tree binfo_as_list = CLASSTYPE_BINFO_AS_LIST (t); 2087: int interface_only = CLASSTYPE_INTERFACE_ONLY (t); 2088: int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t); 2089: 2090: bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type)); 2091: BINFO_BASETYPES(binfo) = NULL_TREE; 2092: 2093: CLASSTYPE_AS_LIST (t) = as_list; 2094: TYPE_BINFO (t) = binfo; 2095: CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list; 2096: CLASSTYPE_INTERFACE_ONLY (t) = interface_only; 2097: SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown); 2098: CLASSTYPE_VBASE_SIZE (t) = integer_zero_node; 2099: TYPE_REDEFINED (t) = 1; 2100: } 2101: TYPE_SIZE (t) = NULL_TREE; 2102: TYPE_MODE (t) = VOIDmode; 2103: TYPE_FIELDS (t) = NULL_TREE; 2104: TYPE_METHODS (t) = NULL_TREE; 2105: TYPE_VFIELD (t) = NULL_TREE; 2106: TYPE_CONTEXT (t) = NULL_TREE; 2107: } 2108: 2109: /* finish up all new vtables. */ 2110: static void 2111: finish_vtbls (binfo, do_self, t) 2112: tree binfo, t; 2113: int do_self; 2114: { 2115: tree binfos = BINFO_BASETYPES (binfo); 2116: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; 2117: 2118: /* Should we use something besides CLASSTYPE_VFIELDS? */ 2119: if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) 2120: { 2121: if (BINFO_NEW_VTABLE_MARKED (binfo)) 2122: { 2123: tree decl, context; 2124: 2125: decl = BINFO_VTABLE (binfo); 2126: context = DECL_CONTEXT (decl); 2127: DECL_CONTEXT (decl) = 0; 2128: if (write_virtuals >= 0 2129: && DECL_INITIAL (decl) != BINFO_VIRTUALS (binfo)) 2130: DECL_INITIAL (decl) = build_nt (CONSTRUCTOR, NULL_TREE, 2131: BINFO_VIRTUALS (binfo)); 1.1.1.2 ! root 2132: cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0, 0); 1.1 root 2133: DECL_CONTEXT (decl) = context; 2134: } 2135: CLEAR_BINFO_NEW_VTABLE_MARKED (binfo); 2136: } 2137: 2138: for (i = 0; i < n_baselinks; i++) 2139: { 2140: tree base_binfo = TREE_VEC_ELT (binfos, i); 2141: int is_not_base_vtable = 2142: i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); 2143: if (TREE_VIA_VIRTUAL (base_binfo)) 2144: { 2145: base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t)); 2146: } 2147: finish_vtbls (base_binfo, is_not_base_vtable, t); 2148: } 2149: } 2150: 2151: /* True if we should override the given BASE_FNDECL with the given 2152: FNDECL. */ 2153: static int 2154: overrides (fndecl, base_fndecl) 2155: tree fndecl, base_fndecl; 2156: { 2157: /* Destructors have special names. */ 2158: if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) && 2159: DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) 2160: return 1; 2161: if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) || 2162: DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl))) 2163: return 0; 2164: if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl)) 2165: { 2166: tree rettype, base_rettype, types, base_types; 2167: #if 0 2168: retypes = TREE_TYPE (TREE_TYPE (fndecl)); 2169: base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl)); 2170: #endif 2171: types = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); 2172: base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl)); 2173: if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (base_types))) 2174: == TYPE_READONLY (TREE_TYPE (TREE_VALUE (types)))) 2175: && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types), 3)) 2176: return 1; 2177: } 2178: return 0; 2179: } 2180: 2181: static tree 2182: get_class_offset_1 (parent, binfo, context, t, fndecl) 2183: tree parent, binfo, context, t, fndecl; 2184: { 2185: tree binfos = BINFO_BASETYPES (binfo); 2186: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; 2187: tree rval = NULL_TREE; 2188: 2189: if (binfo == parent) 2190: return error_mark_node; 2191: 2192: for (i = 0; i < n_baselinks; i++) 2193: { 2194: tree base_binfo = TREE_VEC_ELT (binfos, i); 2195: tree nrval; 2196: 2197: if (TREE_VIA_VIRTUAL (base_binfo)) 2198: base_binfo = binfo_member (BINFO_TYPE (base_binfo), 2199: CLASSTYPE_VBASECLASSES (t)); 2200: nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl); 2201: /* See if we have a new value */ 2202: if (nrval && (nrval != error_mark_node || rval==0)) 2203: { 2204: /* Only compare if we have two offsets */ 2205: if (rval && rval != error_mark_node 2206: && ! tree_int_cst_equal (nrval, rval)) 2207: { 2208: /* Only give error if the two offsets are different */ 2209: error ("every virtual function must have a unique final overrider"); 2210: cp_error (" found two (or more) `%T' class subobjects in `%T'", context, t); 2211: cp_error (" with virtual `%D' from virtual base class", fndecl); 2212: return rval; 2213: } 2214: rval = nrval; 2215: } 2216: 2217: if (rval && BINFO_TYPE (binfo) == context) 2218: { 2219: my_friendly_assert (rval == error_mark_node 2220: || tree_int_cst_equal (rval, BINFO_OFFSET (binfo)), 999); 2221: rval = BINFO_OFFSET (binfo); 2222: } 2223: } 2224: return rval; 2225: } 2226: 2227: /* Get the offset to the CONTEXT subobject that is related to the 2228: given BINFO. */ 2229: static tree 2230: get_class_offset (context, t, binfo, fndecl) 2231: tree context, t, binfo, fndecl; 2232: { 2233: tree first_binfo = binfo; 2234: tree offset; 2235: int i; 2236: 2237: if (context == t) 2238: return integer_zero_node; 2239: 2240: if (BINFO_TYPE (binfo) == context) 2241: return BINFO_OFFSET (binfo); 2242: 2243: /* Check less derived binfos first. */ 2244: while (BINFO_BASETYPES (binfo) 2245: && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1) 2246: { 2247: tree binfos = BINFO_BASETYPES (binfo); 2248: binfo = TREE_VEC_ELT (binfos, i); 2249: if (BINFO_TYPE (binfo) == context) 2250: return BINFO_OFFSET (binfo); 2251: } 2252: 2253: /* Ok, not found in the less derived binfos, now check the more 2254: derived binfos. */ 2255: offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl); 2256: if (offset==0 || TREE_CODE (offset) != INTEGER_CST) 2257: my_friendly_abort (999); /* we have to find it. */ 2258: return offset; 2259: } 2260: 1.1.1.2 ! root 2261: /* Skip RTTI information at the front of the virtual list. */ ! 2262: unsigned HOST_WIDE_INT ! 2263: skip_rtti_stuff (virtuals) ! 2264: tree *virtuals; ! 2265: { ! 2266: int n; ! 2267: ! 2268: n = 0; ! 2269: if (*virtuals) ! 2270: { ! 2271: /* We always reserve a slot for the offset/tdesc entry. */ ! 2272: ++n; ! 2273: *virtuals = TREE_CHAIN (*virtuals); ! 2274: } ! 2275: if (flag_vtable_thunks && *virtuals) ! 2276: { ! 2277: /* The second slot is reserved for the tdesc pointer when thunks ! 2278: are used. */ ! 2279: ++n; ! 2280: *virtuals = TREE_CHAIN (*virtuals); ! 2281: } ! 2282: return n; ! 2283: } ! 2284: 1.1 root 2285: static void 2286: modify_one_vtable (binfo, t, fndecl, pfn) 2287: tree binfo, t, fndecl, pfn; 2288: { 2289: tree virtuals = BINFO_VIRTUALS (binfo); 1.1.1.2 ! root 2290: tree old_rtti; 1.1 root 2291: unsigned HOST_WIDE_INT n; 2292: 1.1.1.2 ! root 2293: /* update rtti entry */ ! 2294: if (flag_rtti) ! 2295: { ! 2296: if (binfo == TYPE_BINFO (t)) ! 2297: { ! 2298: if (! BINFO_NEW_VTABLE_MARKED (binfo)) ! 2299: build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t))), t); ! 2300: } ! 2301: else ! 2302: { ! 2303: if (! BINFO_NEW_VTABLE_MARKED (binfo)) ! 2304: prepare_fresh_vtable (binfo, t); ! 2305: } ! 2306: } ! 2307: if (fndecl == NULL_TREE) ! 2308: return; ! 2309: ! 2310: n = skip_rtti_stuff (&virtuals); ! 2311: 1.1 root 2312: while (virtuals) 2313: { 2314: tree current_fndecl = TREE_VALUE (virtuals); 2315: current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl); 2316: current_fndecl = TREE_OPERAND (current_fndecl, 0); 2317: if (current_fndecl && overrides (fndecl, current_fndecl)) 2318: { 2319: tree base_offset, offset; 2320: tree context = DECL_CLASS_CONTEXT (fndecl); 2321: tree vfield = CLASSTYPE_VFIELD (t); 2322: tree this_offset; 2323: 2324: offset = get_class_offset (context, t, binfo, fndecl); 2325: 2326: /* Find the right offset for the this pointer based on the 2327: base class we just found. We have to take into 2328: consideration the virtual base class pointers that we 2329: stick in before the virtual function table pointer. 2330: 1.1.1.2 ! root 2331: Also, we want just the delta between the most base class 1.1 root 2332: that we derived this vfield from and us. */ 2333: base_offset = size_binop (PLUS_EXPR, 2334: get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)), 2335: BINFO_OFFSET (binfo)); 2336: this_offset = size_binop (MINUS_EXPR, offset, base_offset); 2337: 2338: /* Make sure we can modify the derived association with immunity. */ 1.1.1.2 ! root 2339: if (TREE_USED (binfo)) 1.1 root 2340: my_friendly_assert (0, 999); 1.1.1.2 ! root 2341: 1.1 root 2342: if (binfo == TYPE_BINFO (t)) 2343: { 2344: /* In this case, it is *type*'s vtable we are modifying. 2345: We start with the approximation that it's vtable is that 2346: of the immediate base class. */ 2347: if (! BINFO_NEW_VTABLE_MARKED (binfo)) 2348: build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t); 2349: } 2350: else 2351: { 2352: /* This is our very own copy of `basetype' to play with. 2353: Later, we will fill in all the virtual functions 2354: that override the virtual functions in these base classes 2355: which are not defined by the current type. */ 2356: if (! BINFO_NEW_VTABLE_MARKED (binfo)) 2357: prepare_fresh_vtable (binfo, t); 2358: } 2359: 2360: #ifdef NOTQUITE 2361: cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo))); 2362: #endif 2363: modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n), 2364: build_vtable_entry (this_offset, pfn), 2365: fndecl); 2366: } 2367: ++n; 2368: virtuals = TREE_CHAIN (virtuals); 2369: } 2370: } 2371: 2372: /* These are the ones that are not through virtual base classes. */ 2373: static void 2374: modify_all_direct_vtables (binfo, do_self, t, fndecl, pfn) 2375: tree binfo, t, fndecl, pfn; 2376: int do_self; 2377: { 2378: tree binfos = BINFO_BASETYPES (binfo); 2379: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; 2380: 2381: /* Should we use something besides CLASSTYPE_VFIELDS? */ 2382: if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) 2383: { 2384: modify_one_vtable (binfo, t, fndecl, pfn); 2385: } 2386: 2387: for (i = 0; i < n_baselinks; i++) 2388: { 2389: tree base_binfo = TREE_VEC_ELT (binfos, i); 2390: int is_not_base_vtable = 2391: i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); 2392: if (! TREE_VIA_VIRTUAL (base_binfo)) 2393: modify_all_direct_vtables (base_binfo, is_not_base_vtable, t, fndecl, pfn); 2394: } 2395: } 2396: 1.1.1.2 ! root 2397: /* Fixup all the delta entries in this one vtable that need updating. */ 1.1 root 2398: static void 1.1.1.2 ! root 2399: fixup_vtable_deltas1 (binfo, t) 1.1 root 2400: tree binfo, t; 2401: { 2402: tree virtuals = BINFO_VIRTUALS (binfo); 2403: unsigned HOST_WIDE_INT n; 2404: 1.1.1.2 ! root 2405: n = skip_rtti_stuff (&virtuals); ! 2406: 1.1 root 2407: while (virtuals) 2408: { 2409: tree fndecl = TREE_VALUE (virtuals); 2410: tree pfn = FNADDR_FROM_VTABLE_ENTRY (fndecl); 2411: tree delta = DELTA_FROM_VTABLE_ENTRY (fndecl); 2412: fndecl = TREE_OPERAND (pfn, 0); 2413: if (fndecl) 2414: { 2415: tree base_offset, offset; 2416: tree context = DECL_CLASS_CONTEXT (fndecl); 2417: tree vfield = CLASSTYPE_VFIELD (t); 2418: tree this_offset; 2419: 2420: offset = get_class_offset (context, t, binfo, fndecl); 2421: 2422: /* Find the right offset for the this pointer based on the 2423: base class we just found. We have to take into 2424: consideration the virtual base class pointers that we 2425: stick in before the virtual function table pointer. 2426: 1.1.1.2 ! root 2427: Also, we want just the delta between the most base class 1.1 root 2428: that we derived this vfield from and us. */ 2429: base_offset = size_binop (PLUS_EXPR, 2430: get_derived_offset (binfo, DECL_CONTEXT (fndecl)), 2431: BINFO_OFFSET (binfo)); 2432: this_offset = size_binop (MINUS_EXPR, offset, base_offset); 2433: 2434: if (! tree_int_cst_equal (this_offset, delta)) 2435: { 2436: /* Make sure we can modify the derived association with immunity. */ 2437: if (TREE_USED (binfo)) 2438: my_friendly_assert (0, 999); 2439: 2440: if (binfo == TYPE_BINFO (t)) 2441: { 2442: /* In this case, it is *type*'s vtable we are modifying. 2443: We start with the approximation that it's vtable is that 2444: of the immediate base class. */ 2445: if (! BINFO_NEW_VTABLE_MARKED (binfo)) 2446: build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t); 2447: } 2448: else 2449: { 2450: /* This is our very own copy of `basetype' to play with. 2451: Later, we will fill in all the virtual functions 2452: that override the virtual functions in these base classes 2453: which are not defined by the current type. */ 2454: if (! BINFO_NEW_VTABLE_MARKED (binfo)) 2455: prepare_fresh_vtable (binfo, t); 2456: } 2457: 2458: modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n), 2459: build_vtable_entry (this_offset, pfn), 2460: fndecl); 2461: } 2462: } 2463: ++n; 2464: virtuals = TREE_CHAIN (virtuals); 2465: } 2466: } 2467: 1.1.1.2 ! root 2468: /* Fixup all the delta entries in all the direct vtables that need updating. ! 2469: This happens when we have non-overridden virtual functions from a ! 2470: virtual base class, that are at a different offset, in the new ! 2471: hierarchy, because the layout of the virtual bases has changed. */ ! 2472: static void ! 2473: fixup_vtable_deltas (binfo, init_self, t) ! 2474: tree binfo, t; ! 2475: int init_self; ! 2476: { ! 2477: tree binfos = BINFO_BASETYPES (binfo); ! 2478: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; ! 2479: ! 2480: for (i = 0; i < n_baselinks; i++) ! 2481: { ! 2482: tree base_binfo = TREE_VEC_ELT (binfos, i); ! 2483: int is_not_base_vtable = ! 2484: i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); ! 2485: if (! TREE_VIA_VIRTUAL (base_binfo)) ! 2486: fixup_vtable_deltas (base_binfo, is_not_base_vtable, t); ! 2487: } ! 2488: /* Should we use something besides CLASSTYPE_VFIELDS? */ ! 2489: if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) ! 2490: { ! 2491: fixup_vtable_deltas1 (binfo, t); ! 2492: } ! 2493: } ! 2494: 1.1 root 2495: /* These are the ones that are through virtual base classes. */ 2496: static void 2497: modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl, pfn) 2498: tree binfo, t, fndecl, pfn; 2499: int do_self, via_virtual; 2500: { 2501: tree binfos = BINFO_BASETYPES (binfo); 2502: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; 2503: 2504: /* Should we use something besides CLASSTYPE_VFIELDS? */ 2505: if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) 2506: { 2507: modify_one_vtable (binfo, t, fndecl, pfn); 2508: } 2509: 2510: for (i = 0; i < n_baselinks; i++) 2511: { 2512: tree base_binfo = TREE_VEC_ELT (binfos, i); 2513: int is_not_base_vtable = 2514: i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); 2515: if (TREE_VIA_VIRTUAL (base_binfo)) 2516: { 2517: via_virtual = 1; 2518: base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t)); 2519: } 2520: modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl, pfn); 2521: } 2522: } 2523: 2524: static void 2525: modify_all_vtables (t, fndecl, vfn) 2526: tree t, fndecl, vfn; 2527: { 2528: /* Do these first, so that we will make use of any non-virtual class's 2529: vtable, over a virtual classes vtable. */ 2530: modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl, vfn); 2531: if (TYPE_USES_VIRTUAL_BASECLASSES (t)) 2532: modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl, vfn); 2533: } 2534: 2535: /* Here, we already know that they match in every respect. 2536: All we have to check is where they had their declarations. */ 2537: static int 2538: strictly_overrides (fndecl1, fndecl2) 2539: tree fndecl1, fndecl2; 2540: { 2541: int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2), 2542: DECL_CLASS_CONTEXT (fndecl1), 2543: 0, (tree *)0); 2544: if (distance == -2 || distance > 0) 2545: return 1; 2546: return 0; 2547: } 2548: 2549: /* Merge overrides for one vtable. 2550: If we want to merge in same function, we are fine. 2551: else 2552: if one has a DECL_CLASS_CONTEXT that is a parent of the 2553: other, than choose the more derived one 2554: else 2555: potentially ill-formed (see 10.3 [class.virtual]) 2556: we have to check later to see if there was an 2557: override in this class. If there was ok, if not 2558: then it is ill-formed. (mrs) 2559: 2560: We take special care to reuse a vtable, if we can. */ 2561: static void 2562: override_one_vtable (binfo, old, t) 2563: tree binfo, old, t; 2564: { 2565: tree virtuals = BINFO_VIRTUALS (binfo); 2566: tree old_virtuals = BINFO_VIRTUALS (old); 2567: enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED; 2568: 2569: /* If we have already committed to modifying it, then don't try and 2570: reuse another vtable. */ 2571: if (BINFO_NEW_VTABLE_MARKED (binfo)) 2572: choose = NEITHER; 2573: 1.1.1.2 ! root 2574: skip_rtti_stuff (&virtuals); ! 2575: skip_rtti_stuff (&old_virtuals); 1.1 root 2576: 2577: while (virtuals) 2578: { 2579: tree fndecl = TREE_VALUE (virtuals); 2580: tree old_fndecl = TREE_VALUE (old_virtuals); 2581: fndecl = FNADDR_FROM_VTABLE_ENTRY (fndecl); 2582: old_fndecl = FNADDR_FROM_VTABLE_ENTRY (old_fndecl); 2583: fndecl = TREE_OPERAND (fndecl, 0); 2584: old_fndecl = TREE_OPERAND (old_fndecl, 0); 2585: /* First check to see if they are the same. */ 2586: if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl)) 2587: { 2588: /* No need to do anything. */ 2589: } 2590: else if (strictly_overrides (fndecl, old_fndecl)) 2591: { 2592: if (choose == UNDECIDED) 2593: choose = REUSE_NEW; 2594: else if (choose == REUSE_OLD) 2595: { 2596: choose = NEITHER; 2597: if (! BINFO_NEW_VTABLE_MARKED (binfo)) 2598: { 2599: prepare_fresh_vtable (binfo, t); 2600: override_one_vtable (binfo, old, t); 2601: return; 2602: } 2603: } 2604: } 2605: else if (strictly_overrides (old_fndecl, fndecl)) 2606: { 2607: if (choose == UNDECIDED) 2608: choose = REUSE_OLD; 2609: else if (choose == REUSE_NEW) 2610: { 2611: choose = NEITHER; 2612: if (! BINFO_NEW_VTABLE_MARKED (binfo)) 2613: { 2614: prepare_fresh_vtable (binfo, t); 2615: override_one_vtable (binfo, old, t); 2616: return; 2617: } 2618: TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals); 2619: } 2620: else if (choose == NEITHER) 2621: { 2622: TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals); 2623: } 2624: } 2625: else 2626: { 2627: choose = NEITHER; 2628: if (! BINFO_NEW_VTABLE_MARKED (binfo)) 2629: { 2630: prepare_fresh_vtable (binfo, t); 2631: override_one_vtable (binfo, old, t); 2632: return; 2633: } 2634: { 1.1.1.2 ! root 2635: /* This MUST be overridden, or the class is ill-formed. */ 1.1 root 2636: /* For now, we just make it abstract. */ 2637: tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0); 2638: tree vfn; 2639: 2640: fndecl = copy_node (fndecl); 2641: copy_lang_decl (fndecl); 2642: DECL_ABSTRACT_VIRTUAL_P (fndecl) = 1; 2643: /* Make sure we search for it later. */ 2644: if (! CLASSTYPE_ABSTRACT_VIRTUALS (t)) 2645: CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node; 2646: 2647: vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl); 2648: TREE_CONSTANT (vfn) = 1; 2649: 2650: /* We can use integer_zero_node, as we will will core dump 2651: if this is used anyway. */ 2652: TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, vfn); 2653: } 2654: } 2655: virtuals = TREE_CHAIN (virtuals); 2656: old_virtuals = TREE_CHAIN (old_virtuals); 2657: } 2658: 2659: /* Let's reuse the old vtable. */ 2660: if (choose == REUSE_OLD) 2661: { 2662: BINFO_VTABLE (binfo) = BINFO_VTABLE (old); 2663: BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old); 2664: } 2665: } 2666: 2667: /* Merge in overrides for virtual bases. 2668: BINFO is the hierarchy we want to modify, and OLD has the potential 2669: overrides. */ 2670: static void 2671: merge_overrides (binfo, old, do_self, t) 2672: tree binfo, old, t; 2673: int do_self; 2674: { 2675: tree binfos = BINFO_BASETYPES (binfo); 2676: tree old_binfos = BINFO_BASETYPES (old); 2677: int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; 2678: 2679: /* Should we use something besides CLASSTYPE_VFIELDS? */ 2680: if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo))) 2681: { 2682: override_one_vtable (binfo, old, t); 2683: } 2684: 2685: for (i = 0; i < n_baselinks; i++) 2686: { 2687: tree base_binfo = TREE_VEC_ELT (binfos, i); 2688: tree old_base_binfo = TREE_VEC_ELT (old_binfos, i); 2689: int is_not_base_vtable = 2690: i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo)); 2691: if (! TREE_VIA_VIRTUAL (base_binfo)) 2692: merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t); 2693: } 2694: } 2695: 1.1.1.2 ! root 2696: extern int interface_only, interface_unknown; ! 2697: 1.1 root 2698: /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration 2699: (or C++ class declaration). 2700: 2701: For C++, we must handle the building of derived classes. 2702: Also, C++ allows static class members. The way that this is 2703: handled is to keep the field name where it is (as the DECL_NAME 2704: of the field), and place the overloaded decl in the DECL_FIELD_BITPOS 2705: of the field. layout_record and layout_union will know about this. 2706: 2707: More C++ hair: inline functions have text in their 2708: DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into 2709: meaningful tree structure. After the struct has been laid out, set 2710: things up so that this can happen. 2711: 2712: And still more: virtual functions. In the case of single inheritance, 2713: when a new virtual function is seen which redefines a virtual function 2714: from the base class, the new virtual function is placed into 2715: the virtual function table at exactly the same address that 2716: it had in the base class. When this is extended to multiple 2717: inheritance, the same thing happens, except that multiple virtual 2718: function tables must be maintained. The first virtual function 2719: table is treated in exactly the same way as in the case of single 2720: inheritance. Additional virtual function tables have different 2721: DELTAs, which tell how to adjust `this' to point to the right thing. 2722: 2723: LIST_OF_FIELDLISTS is just that. The elements of the list are 2724: TREE_LIST elements, whose TREE_PURPOSE field tells what access 2725: the list has, and the TREE_VALUE slot gives the actual fields. 2726: 2727: If flag_all_virtual == 1, then we lay all functions into 2728: the virtual function table, as though they were declared 2729: virtual. Constructors do not lay down in the virtual function table. 2730: 2731: If flag_all_virtual == 2, then we lay all functions into 2732: the virtual function table, such that virtual functions 2733: occupy a space by themselves, and then all functions 2734: of the class occupy a space by themselves. This is illustrated 2735: in the following diagram: 2736: 2737: class A; class B : A; 2738: 2739: Class A's vtbl: Class B's vtbl: 2740: -------------------------------------------------------------------- 2741: | A's virtual functions| | B's virtual functions | 2742: | | | (may inherit some from A). | 2743: -------------------------------------------------------------------- 2744: | All of A's functions | | All of A's functions | 2745: | (such as a->A::f). | | (such as b->A::f) | 2746: -------------------------------------------------------------------- 2747: | B's new virtual functions | 2748: | (not defined in A.) | 2749: ------------------------------- 2750: | All of B's functions | 2751: | (such as b->B::f) | 2752: ------------------------------- 2753: 2754: this allows the program to make references to any function, virtual 2755: or otherwise in a type-consistent manner. */ 2756: 2757: tree 1.1.1.2 ! root 2758: finish_struct_1 (t, warn_anon) 1.1 root 2759: tree t; 2760: int warn_anon; 2761: { 2762: int old; 2763: int round_up_size = 1; 2764: 1.1.1.2 ! root 2765: tree name = TYPE_IDENTIFIER (t); 1.1 root 2766: enum tree_code code = TREE_CODE (t); 1.1.1.2 ! root 2767: tree fields = TYPE_FIELDS (t); ! 2768: tree fn_fields = CLASSTYPE_METHODS (t); ! 2769: tree x, last_x, method_vec; 1.1 root 2770: int needs_virtual_dtor; 2771: int all_virtual; 2772: int has_virtual; 2773: int max_has_virtual; 2774: tree pending_virtuals = NULL_TREE; 2775: tree abstract_virtuals = NULL_TREE; 2776: tree vfield; 2777: tree vfields; 2778: int cant_have_default_ctor; 2779: int cant_have_const_ctor; 2780: int cant_synth_copy_ctor; 2781: int cant_synth_asn_ref; 2782: int no_const_asn_ref; 2783: 2784: /* The index of the first base class which has virtual 2785: functions. Only applied to non-virtual baseclasses. */ 2786: int first_vfn_base_index; 2787: 2788: int n_baseclasses; 2789: int any_default_members = 0; 2790: int const_sans_init = 0; 2791: int ref_sans_init = 0; 2792: int nonprivate_method = 0; 2793: tree t_binfo = TYPE_BINFO (t); 2794: tree access_decls = NULL_TREE; 1.1.1.2 ! root 2795: int aggregate = 1; 1.1 root 2796: 1.1.1.2 ! root 2797: if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) 1.1 root 2798: pedwarn ("anonymous class type not used to declare any objects"); 2799: 2800: if (TYPE_SIZE (t)) 2801: { 2802: if (IS_AGGR_TYPE (t)) 2803: cp_error ("redefinition of `%#T'", t); 2804: else 2805: my_friendly_abort (172); 2806: popclass (0); 2807: return t; 2808: } 2809: 1.1.1.2 ! root 2810: if (dont_allow_type_definitions) ! 2811: { ! 2812: pedwarn ("types cannot be defined %s", ! 2813: dont_allow_type_definitions); ! 2814: } 1.1 root 2815: 2816: GNU_xref_decl (current_function_decl, t); 2817: 2818: /* If this type was previously laid out as a forward reference, 2819: make sure we lay it out again. */ 2820: 2821: TYPE_SIZE (t) = NULL_TREE; 2822: CLASSTYPE_GOT_SEMICOLON (t) = 0; 2823: 2824: #if 0 2825: /* This is in general too late to do this. I moved the main case up to 2826: left_curly, what else needs to move? */ 2827: if (! IS_SIGNATURE (t)) 2828: { 2829: my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999); 2830: my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t) == ! interface_unknown, 999); 2831: } 2832: #endif 2833: 1.1.1.2 ! root 2834: #if 0 ! 2835: if (flag_rtti) 1.1 root 2836: build_t_desc (t, 0); 1.1.1.2 ! root 2837: #endif 1.1 root 2838: 2839: TYPE_BINFO (t) = NULL_TREE; 2840: 2841: old = suspend_momentary (); 2842: 2843: /* Install struct as DECL_FIELD_CONTEXT of each field decl. 2844: Also process specified field sizes. 2845: Set DECL_FIELD_SIZE to the specified size, or 0 if none specified. 2846: The specified size is found in the DECL_INITIAL. 2847: Store 0 there, except for ": 0" fields (so we can find them 2848: and delete them, below). */ 2849: 2850: if (t_binfo && BINFO_BASETYPES (t_binfo)) 2851: n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo)); 2852: else 2853: n_baseclasses = 0; 2854: 2855: if (n_baseclasses > 0) 2856: { 2857: struct base_info base_info; 2858: 2859: /* If using multiple inheritance, this may cause variants of our 2860: basetypes to be used (instead of their canonical forms). */ 1.1.1.2 ! root 2861: tree vf = layout_basetypes (t, BINFO_BASETYPES (t_binfo)); ! 2862: last_x = tree_last (vf); ! 2863: fields = chainon (vf, fields); 1.1 root 2864: 2865: first_vfn_base_index = finish_base_struct (t, &base_info, t_binfo); 2866: /* Remember where we got our vfield from */ 2867: CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index; 2868: has_virtual = base_info.has_virtual; 2869: max_has_virtual = base_info.max_has_virtual; 2870: CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors; 2871: vfield = base_info.vfield; 2872: vfields = base_info.vfields; 2873: cant_have_default_ctor = base_info.cant_have_default_ctor; 2874: cant_have_const_ctor = base_info.cant_have_const_ctor; 2875: cant_synth_copy_ctor = base_info.cant_synth_copy_ctor; 2876: cant_synth_asn_ref = base_info.cant_synth_asn_ref; 2877: no_const_asn_ref = base_info.no_const_asn_ref; 2878: needs_virtual_dtor = base_info.needs_virtual_dtor; 2879: n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo)); 1.1.1.2 ! root 2880: aggregate = 0; 1.1 root 2881: } 2882: else 2883: { 2884: first_vfn_base_index = -1; 2885: has_virtual = 0; 2886: max_has_virtual = has_virtual; 2887: vfield = NULL_TREE; 2888: vfields = NULL_TREE; 2889: last_x = NULL_TREE; 2890: cant_have_default_ctor = 0; 2891: cant_have_const_ctor = 0; 2892: cant_synth_copy_ctor = 0; 2893: cant_synth_asn_ref = 0; 2894: no_const_asn_ref = 0; 2895: needs_virtual_dtor = 0; 2896: } 2897: 2898: #if 0 2899: /* Both of these should be done before now. */ 2900: if (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t) 2901: && ! IS_SIGNATURE (t)) 2902: { 2903: my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999); 2904: my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t) == ! interface_only, 999); 2905: } 2906: #endif 2907: 2908: /* The three of these are approximations which may later be 2909: modified. Needed at this point to make add_virtual_function 2910: and modify_vtable_entries work. */ 2911: TREE_CHAIN (t_binfo) = TYPE_BINFO (t); 2912: TYPE_BINFO (t) = t_binfo; 2913: CLASSTYPE_VFIELDS (t) = vfields; 2914: CLASSTYPE_VFIELD (t) = vfield; 2915: 2916: if (IS_SIGNATURE (t)) 2917: all_virtual = 0; 2918: else if (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t)) 2919: all_virtual = 1; 2920: else 2921: all_virtual = 0; 2922: 1.1.1.2 ! root 2923: for (x = CLASSTYPE_METHODS (t); x; x = TREE_CHAIN (x)) 1.1 root 2924: { 1.1.1.2 ! root 2925: GNU_xref_member (current_class_name, x); ! 2926: ! 2927: nonprivate_method |= ! TREE_PRIVATE (x); ! 2928: ! 2929: /* If this was an evil function, don't keep it in class. */ ! 2930: if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x))) ! 2931: continue; ! 2932: ! 2933: DECL_CLASS_CONTEXT (x) = t; ! 2934: ! 2935: /* Do both of these, even though they're in the same union; ! 2936: if the insn `r' member and the size `i' member are ! 2937: different sizes, as on the alpha, the larger of the two ! 2938: will end up with garbage in it. */ ! 2939: DECL_SAVED_INSNS (x) = NULL_RTX; ! 2940: DECL_FIELD_SIZE (x) = 0; ! 2941: ! 2942: /* The name of the field is the original field name ! 2943: Save this in auxiliary field for later overloading. */ ! 2944: if (DECL_VINDEX (x) ! 2945: || (all_virtual == 1 && ! DECL_CONSTRUCTOR_P (x))) ! 2946: { ! 2947: pending_virtuals = add_virtual_function (pending_virtuals, ! 2948: &has_virtual, x, t); ! 2949: if (DECL_ABSTRACT_VIRTUAL_P (x)) ! 2950: abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals); ! 2951: else ! 2952: TREE_USED (x) = 1; ! 2953: } 1.1 root 2954: } 2955: 1.1.1.2 ! root 2956: for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x)) 1.1 root 2957: { 1.1.1.2 ! root 2958: GNU_xref_member (current_class_name, x); 1.1 root 2959: 1.1.1.2 ! root 2960: /* Handle access declarations. */ ! 2961: if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF) 1.1 root 2962: { 1.1.1.2 ! root 2963: tree fdecl = TREE_OPERAND (DECL_NAME (x), 1); ! 2964: enum access_type access ! 2965: = TREE_PRIVATE (x) ? access_private : ! 2966: TREE_PROTECTED (x) ? access_protected : access_public; 1.1 root 2967: 1.1.1.2 ! root 2968: if (last_x) ! 2969: TREE_CHAIN (last_x) = TREE_CHAIN (x); ! 2970: else ! 2971: fields = TREE_CHAIN (x); 1.1 root 2972: 1.1.1.2 ! root 2973: access_decls = tree_cons ((tree) access, fdecl, access_decls); ! 2974: continue; ! 2975: } 1.1 root 2976: 1.1.1.2 ! root 2977: last_x = x; 1.1 root 2978: 1.1.1.2 ! root 2979: if (TREE_CODE (x) == TYPE_DECL) ! 2980: continue; 1.1 root 2981: 1.1.1.2 ! root 2982: /* If we've gotten this far, it's a data member, possibly static, ! 2983: or an enumerator. */ 1.1 root 2984: 1.1.1.2 ! root 2985: DECL_FIELD_CONTEXT (x) = t; 1.1 root 2986: 1.1.1.2 ! root 2987: /* ``A local class cannot have static data members.'' ARM 9.4 */ ! 2988: if (current_function_decl && TREE_STATIC (x)) ! 2989: cp_error_at ("field `%D' in local class cannot be static", x); 1.1 root 2990: 1.1.1.2 ! root 2991: /* Perform error checking that did not get done in ! 2992: grokdeclarator. */ ! 2993: if (TREE_CODE (TREE_TYPE (x)) == FUNCTION_TYPE) ! 2994: { ! 2995: cp_error_at ("field `%D' invalidly declared function type", ! 2996: x); ! 2997: TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x)); ! 2998: } ! 2999: else if (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE) ! 3000: { ! 3001: cp_error_at ("field `%D' invalidly declared method type", x); ! 3002: TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x)); ! 3003: } ! 3004: else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE) ! 3005: { ! 3006: cp_error_at ("field `%D' invalidly declared offset type", x); ! 3007: TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x)); ! 3008: } 1.1 root 3009: 1.1.1.2 ! root 3010: #if 0 ! 3011: if (DECL_NAME (x) == constructor_name (t)) ! 3012: cant_have_default_ctor = cant_synth_copy_ctor = 1; ! 3013: #endif 1.1 root 3014: 1.1.1.2 ! root 3015: if (TREE_TYPE (x) == error_mark_node) ! 3016: continue; ! 3017: ! 3018: DECL_SAVED_INSNS (x) = NULL_RTX; ! 3019: DECL_FIELD_SIZE (x) = 0; 1.1 root 3020: 1.1.1.2 ! root 3021: /* When this goes into scope, it will be a non-local reference. */ ! 3022: DECL_NONLOCAL (x) = 1; 1.1 root 3023: 1.1.1.2 ! root 3024: if (TREE_CODE (x) == CONST_DECL) ! 3025: continue; 1.1 root 3026: 1.1.1.2 ! root 3027: if (TREE_CODE (x) == VAR_DECL) ! 3028: { ! 3029: if (TREE_CODE (t) == UNION_TYPE) ! 3030: /* Unions cannot have static members. */ ! 3031: cp_error_at ("field `%D' declared static in union", x); ! 3032: ! 3033: continue; ! 3034: } 1.1 root 3035: 1.1.1.2 ! root 3036: /* Now it can only be a FIELD_DECL. */ 1.1 root 3037: 1.1.1.2 ! root 3038: if (TREE_PRIVATE (x) || TREE_PROTECTED (x)) ! 3039: aggregate = 0; 1.1 root 3040: 1.1.1.2 ! root 3041: /* If this is of reference type, check if it needs an init. ! 3042: Also do a little ANSI jig if necessary. */ ! 3043: if (TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE) ! 3044: { ! 3045: if (DECL_INITIAL (x) == NULL_TREE) ! 3046: ref_sans_init = 1; 1.1 root 3047: 1.1.1.2 ! root 3048: /* ARM $12.6.2: [A member initializer list] (or, for an ! 3049: aggregate, initialization by a brace-enclosed list) is the ! 3050: only way to initialize nonstatic const and reference ! 3051: members. */ ! 3052: cant_synth_asn_ref = 1; ! 3053: cant_have_default_ctor = 1; 1.1 root 3054: 1.1.1.2 ! root 3055: if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings) 1.1 root 3056: { 1.1.1.2 ! root 3057: if (DECL_NAME (x)) ! 3058: cp_warning_at ("non-static reference `%#D' in class without a constructor", x); ! 3059: else ! 3060: cp_warning_at ("non-static reference in class without a constructor", x); 1.1 root 3061: } 1.1.1.2 ! root 3062: } 1.1 root 3063: 1.1.1.2 ! root 3064: /* If any field is const, the structure type is pseudo-const. */ ! 3065: if (TREE_READONLY (x)) ! 3066: { ! 3067: C_TYPE_FIELDS_READONLY (t) = 1; ! 3068: if (DECL_INITIAL (x) == NULL_TREE) ! 3069: const_sans_init = 1; 1.1 root 3070: 1.1.1.2 ! root 3071: /* ARM $12.6.2: [A member initializer list] (or, for an ! 3072: aggregate, initialization by a brace-enclosed list) is the ! 3073: only way to initialize nonstatic const and reference ! 3074: members. */ ! 3075: cant_synth_asn_ref = 1; ! 3076: cant_have_default_ctor = 1; 1.1 root 3077: 1.1.1.2 ! root 3078: if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t) ! 3079: && extra_warnings) ! 3080: { ! 3081: if (DECL_NAME (x)) ! 3082: cp_warning_at ("non-static const member `%#D' in class without a constructor", x); ! 3083: else ! 3084: cp_warning_at ("non-static const member in class without a constructor", x); ! 3085: } ! 3086: } ! 3087: else ! 3088: { ! 3089: /* A field that is pseudo-const makes the structure ! 3090: likewise. */ ! 3091: tree t1 = TREE_TYPE (x); ! 3092: while (TREE_CODE (t1) == ARRAY_TYPE) ! 3093: t1 = TREE_TYPE (t1); ! 3094: if (IS_AGGR_TYPE (t1)) ! 3095: { ! 3096: if (C_TYPE_FIELDS_READONLY (t1)) ! 3097: C_TYPE_FIELDS_READONLY (t) = 1; ! 3098: if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1)) ! 3099: const_sans_init = 1; 1.1 root 3100: } 1.1.1.2 ! root 3101: } 1.1 root 3102: 1.1.1.2 ! root 3103: /* We set DECL_BIT_FIELD tentatively in grokbitfield. ! 3104: If the type and width are valid, we'll keep it set. ! 3105: Otherwise, the flag is cleared. */ ! 3106: if (DECL_BIT_FIELD (x)) ! 3107: { ! 3108: DECL_BIT_FIELD (x) = 0; ! 3109: /* Invalid bit-field size done by grokfield. */ ! 3110: /* Detect invalid bit-field type. */ ! 3111: if (DECL_INITIAL (x) ! 3112: && ! INTEGRAL_TYPE_P (TREE_TYPE (x))) 1.1 root 3113: { 1.1.1.2 ! root 3114: cp_error_at ("bit-field `%#D' with non-integral type", x); ! 3115: DECL_INITIAL (x) = NULL; ! 3116: } 1.1 root 3117: 1.1.1.2 ! root 3118: /* Detect and ignore out of range field width. */ ! 3119: if (DECL_INITIAL (x)) ! 3120: { ! 3121: register int width = TREE_INT_CST_LOW (DECL_INITIAL (x)); 1.1 root 3122: 1.1.1.2 ! root 3123: if (width < 0) 1.1 root 3124: { 1.1.1.2 ! root 3125: DECL_INITIAL (x) = NULL; ! 3126: cp_error_at ("negative width in bit-field `%D'", x); 1.1 root 3127: } 1.1.1.2 ! root 3128: else if (width == 0 && DECL_NAME (x) != 0) 1.1 root 3129: { 1.1.1.2 ! root 3130: DECL_INITIAL (x) = NULL; ! 3131: cp_error_at ("zero width for bit-field `%D'", x); 1.1 root 3132: } 1.1.1.2 ! root 3133: else if (width ! 3134: > TYPE_PRECISION (long_long_unsigned_type_node)) 1.1 root 3135: { 1.1.1.2 ! root 3136: /* The backend will dump if you try to use something ! 3137: too big; avoid that. */ 1.1 root 3138: DECL_INITIAL (x) = NULL; 1.1.1.2 ! root 3139: sorry ("bit-fields larger than %d bits", ! 3140: TYPE_PRECISION (long_long_unsigned_type_node)); ! 3141: cp_error_at (" in declaration of `%D'", x); 1.1 root 3142: } 1.1.1.2 ! root 3143: else if (width > TYPE_PRECISION (TREE_TYPE (x)) ! 3144: && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE) 1.1 root 3145: { 1.1.1.2 ! root 3146: cp_warning_at ("width of `%D' exceeds its type", x); 1.1 root 3147: } 1.1.1.2 ! root 3148: else if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE ! 3149: && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)), ! 3150: TREE_UNSIGNED (TREE_TYPE (x))) > width) ! 3151: || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)), ! 3152: TREE_UNSIGNED (TREE_TYPE (x))) > width))) 1.1 root 3153: { 1.1.1.2 ! root 3154: cp_warning_at ("`%D' is too small to hold all values of `%#T'", ! 3155: x, TREE_TYPE (x)); ! 3156: } ! 3157: } 1.1 root 3158: 1.1.1.2 ! root 3159: /* Process valid field width. */ ! 3160: if (DECL_INITIAL (x)) ! 3161: { ! 3162: register int width = TREE_INT_CST_LOW (DECL_INITIAL (x)); ! 3163: ! 3164: if (width == 0) ! 3165: { 1.1 root 3166: #ifdef EMPTY_FIELD_BOUNDARY 1.1.1.2 ! root 3167: /* field size 0 => mark following field as "aligned" */ ! 3168: if (TREE_CHAIN (x)) ! 3169: DECL_ALIGN (TREE_CHAIN (x)) ! 3170: = MAX (DECL_ALIGN (TREE_CHAIN (x)), EMPTY_FIELD_BOUNDARY); ! 3171: /* field of size 0 at the end => round up the size. */ ! 3172: else ! 3173: round_up_size = EMPTY_FIELD_BOUNDARY; 1.1 root 3174: #endif 3175: #ifdef PCC_BITFIELD_TYPE_MATTERS 1.1.1.2 ! root 3176: DECL_ALIGN (x) = MAX (DECL_ALIGN (x), ! 3177: TYPE_ALIGN (TREE_TYPE (x))); 1.1 root 3178: #endif 3179: } 3180: else 1.1.1.2 ! root 3181: { ! 3182: DECL_INITIAL (x) = NULL_TREE; ! 3183: DECL_FIELD_SIZE (x) = width; ! 3184: DECL_BIT_FIELD (x) = 1; ! 3185: /* Traditionally a bit field is unsigned ! 3186: even if declared signed. */ ! 3187: if (flag_traditional ! 3188: && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE) ! 3189: TREE_TYPE (x) = unsigned_type_node; ! 3190: } 1.1 root 3191: } 3192: else 1.1.1.2 ! root 3193: /* Non-bit-fields are aligned for their type. */ ! 3194: DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x))); ! 3195: } ! 3196: else ! 3197: { ! 3198: tree type = TREE_TYPE (x); 1.1 root 3199: 1.1.1.2 ! root 3200: if (TREE_CODE (type) == ARRAY_TYPE) ! 3201: type = TREE_TYPE (type); 1.1 root 3202: 1.1.1.2 ! root 3203: if (TYPE_LANG_SPECIFIC (type) && ! ANON_UNION_P (x) ! 3204: && ! TYPE_PTRMEMFUNC_P (type)) ! 3205: { ! 3206: /* Never let anything with uninheritable virtuals ! 3207: make it through without complaint. */ ! 3208: if (CLASSTYPE_ABSTRACT_VIRTUALS (type)) ! 3209: abstract_virtuals_error (x, type); 1.1 root 3210: 1.1.1.2 ! root 3211: /* Don't let signatures make it through either. */ ! 3212: if (IS_SIGNATURE (type)) ! 3213: signature_error (x, type); 1.1 root 3214: 1.1.1.2 ! root 3215: if (code == UNION_TYPE) ! 3216: { ! 3217: char *fie = NULL; ! 3218: if (TYPE_NEEDS_CONSTRUCTING (type)) ! 3219: fie = "constructor"; ! 3220: else if (TYPE_NEEDS_DESTRUCTOR (type)) ! 3221: fie = "destructor"; ! 3222: else if (TYPE_HAS_REAL_ASSIGNMENT (type)) ! 3223: fie = "assignment operator"; ! 3224: if (fie) ! 3225: cp_error_at ("member `%#D' with %s not allowed in union", x, ! 3226: fie); ! 3227: } ! 3228: else ! 3229: { ! 3230: TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type); ! 3231: TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type); ! 3232: TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type); ! 3233: TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type); ! 3234: } 1.1 root 3235: 1.1.1.2 ! root 3236: if (! TYPE_HAS_INIT_REF (type) ! 3237: || (TYPE_HAS_NONPUBLIC_CTOR (type) ! 3238: && ! is_friend (t, type))) ! 3239: cant_synth_copy_ctor = 1; ! 3240: else if (!TYPE_HAS_CONST_INIT_REF (type)) ! 3241: cant_have_const_ctor = 1; ! 3242: ! 3243: if (! TYPE_HAS_ASSIGN_REF (type) ! 3244: || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (type) ! 3245: && ! is_friend (t, type))) ! 3246: cant_synth_asn_ref = 1; ! 3247: else if (!TYPE_HAS_CONST_ASSIGN_REF (type)) ! 3248: no_const_asn_ref = 1; 1.1 root 3249: 1.1.1.2 ! root 3250: if (TYPE_HAS_CONSTRUCTOR (type) ! 3251: && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type)) ! 3252: { ! 3253: cant_have_default_ctor = 1; ! 3254: #if 0 ! 3255: /* This is wrong for aggregates. */ ! 3256: if (! TYPE_HAS_CONSTRUCTOR (t)) 1.1 root 3257: { 1.1.1.2 ! root 3258: if (DECL_NAME (x)) ! 3259: cp_pedwarn_at ("member `%#D' with only non-default constructor", x); ! 3260: else ! 3261: cp_pedwarn_at ("member with only non-default constructor", x); ! 3262: cp_pedwarn_at ("in class without a constructor", ! 3263: x); 1.1 root 3264: } 1.1.1.2 ! root 3265: #endif 1.1 root 3266: } 3267: } 1.1.1.2 ! root 3268: if (DECL_INITIAL (x) != NULL_TREE) ! 3269: { ! 3270: /* `build_class_init_list' does not recognize ! 3271: non-FIELD_DECLs. */ ! 3272: if (code == UNION_TYPE && any_default_members != 0) ! 3273: cp_error_at ("multiple fields in union `%T' initialized"); ! 3274: any_default_members = 1; ! 3275: } 1.1 root 3276: } 3277: } 3278: 3279: /* If this type has any constant members which did not come 3280: with their own initialization, mark that fact here. It is 3281: not an error here, since such types can be saved either by their 3282: constructors, or by fortuitous initialization. */ 3283: CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init; 3284: CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init; 3285: CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals; 3286: 3287: /* Synthesize any needed methods. Note that methods will be synthesized 3288: for anonymous unions; grok_x_components undoes that. */ 3289: 1.1.1.2 ! root 3290: if (! fn_fields) ! 3291: nonprivate_method = 1; ! 3292: 1.1 root 3293: if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t) 3294: && !IS_SIGNATURE (t)) 3295: { 3296: /* Here we must cons up a destructor on the fly. */ 3297: tree dtor = cons_up_default_function (t, name, needs_virtual_dtor != 0); 3298: 3299: /* If we couldn't make it work, then pretend we didn't need it. */ 3300: if (dtor == void_type_node) 3301: TYPE_NEEDS_DESTRUCTOR (t) = 0; 3302: else 3303: { 3304: /* Link dtor onto end of fn_fields. */ 1.1.1.2 ! root 3305: ! 3306: TREE_CHAIN (dtor) = fn_fields; ! 3307: fn_fields = dtor; 1.1 root 3308: 3309: if (DECL_VINDEX (dtor) == NULL_TREE 3310: && (needs_virtual_dtor 3311: || pending_virtuals != NULL_TREE 3312: || pending_hard_virtuals != NULL_TREE)) 3313: DECL_VINDEX (dtor) = error_mark_node; 3314: if (DECL_VINDEX (dtor)) 3315: pending_virtuals = add_virtual_function (pending_virtuals, 3316: &has_virtual, dtor, t); 3317: nonprivate_method = 1; 3318: } 3319: } 3320: 3321: TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t); 1.1.1.2 ! root 3322: if (flag_rtti && (max_has_virtual > 0 || needs_virtual_dtor) && ! 3323: has_virtual == 0) ! 3324: has_virtual = 1; 1.1 root 3325: 3326: TYPE_HAS_COMPLEX_INIT_REF (t) 3327: |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t) 1.1.1.2 ! root 3328: || any_default_members); 1.1 root 3329: TYPE_NEEDS_CONSTRUCTING (t) 3330: |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t) 3331: || has_virtual || any_default_members || first_vfn_base_index >= 0); 1.1.1.2 ! root 3332: if (! IS_SIGNATURE (t)) ! 3333: CLASSTYPE_NON_AGGREGATE (t) ! 3334: = ! aggregate || has_virtual || TYPE_HAS_CONSTRUCTOR (t); 1.1 root 3335: 3336: /* ARM $12.1: A default constructor will be generated for a class X 3337: only if no constructor has been declared for class X. So we 3338: check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate 3339: one if they declared a constructor in this class. */ 3340: if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor 3341: && ! IS_SIGNATURE (t)) 3342: { 3343: tree default_fn = cons_up_default_function (t, name, 2); 3344: TREE_CHAIN (default_fn) = fn_fields; 3345: fn_fields = default_fn; 3346: } 3347: 3348: /* Create default copy constructor, if needed. */ 3349: if (! TYPE_HAS_INIT_REF (t) && ! cant_synth_copy_ctor 3350: && ! IS_SIGNATURE (t)) 3351: { 3352: /* ARM 12.18: You get either X(X&) or X(const X&), but 3353: not both. --Chip */ 3354: tree default_fn = cons_up_default_function (t, name, 3355: 3 + cant_have_const_ctor); 3356: TREE_CHAIN (default_fn) = fn_fields; 3357: fn_fields = default_fn; 3358: } 3359: 3360: TYPE_HAS_REAL_ASSIGNMENT (t) |= TYPE_HAS_ASSIGNMENT (t); 3361: TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t); 3362: TYPE_HAS_COMPLEX_ASSIGN_REF (t) 1.1.1.2 ! root 3363: |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t); 1.1 root 3364: 3365: if (! TYPE_HAS_ASSIGN_REF (t) && ! cant_synth_asn_ref 3366: && ! IS_SIGNATURE (t)) 3367: { 3368: tree default_fn = cons_up_default_function (t, name, 3369: 5 + no_const_asn_ref); 3370: TREE_CHAIN (default_fn) = fn_fields; 3371: fn_fields = default_fn; 3372: } 3373: 3374: if (fn_fields) 3375: { 3376: method_vec = finish_struct_methods (t, fn_fields, nonprivate_method); 3377: 3378: if (TYPE_HAS_CONSTRUCTOR (t) 3379: && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE 3380: && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE) 3381: { 3382: int nonprivate_ctor = 0; 3383: tree ctor; 3384: 3385: for (ctor = TREE_VEC_ELT (method_vec, 0); 3386: ctor; 3387: ctor = DECL_CHAIN (ctor)) 3388: if (! TREE_PRIVATE (ctor)) 3389: { 3390: nonprivate_ctor = 1; 3391: break; 3392: } 3393: 3394: if (nonprivate_ctor == 0 && warn_ctor_dtor_privacy) 3395: cp_warning ("`%#T' only defines private constructors and has no friends", 3396: t); 3397: } 3398: } 3399: else 3400: { 3401: method_vec = 0; 3402: 3403: /* Just in case these got accidentally 3404: filled in by syntax errors. */ 3405: TYPE_HAS_CONSTRUCTOR (t) = 0; 3406: TYPE_HAS_DESTRUCTOR (t) = 0; 3407: } 3408: 3409: { 3410: int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0; 3411: 3412: for (access_decls = nreverse (access_decls); access_decls; 3413: access_decls = TREE_CHAIN (access_decls)) 3414: { 3415: tree fdecl = TREE_VALUE (access_decls); 3416: tree flist = NULL_TREE; 3417: tree name; 3418: enum access_type access = (enum access_type)TREE_PURPOSE(access_decls); 3419: int i = TREE_VEC_ELT (method_vec, 0) ? 0 : 1; 3420: tree tmp; 3421: 3422: if (TREE_CODE (fdecl) == TREE_LIST) 3423: { 3424: flist = fdecl; 3425: fdecl = TREE_VALUE (flist); 3426: } 3427: 3428: name = DECL_NAME (fdecl); 3429: 3430: for (; i < n_methods; i++) 3431: if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name) 3432: { 3433: cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t); 3434: cp_error_at (" because of local method `%#D' with same name", 3435: TREE_VEC_ELT (method_vec, i)); 3436: fdecl = NULL_TREE; 3437: break; 3438: } 3439: 3440: if (! fdecl) 3441: continue; 3442: 3443: for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp)) 3444: if (DECL_NAME (tmp) == name) 3445: { 3446: cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t); 3447: cp_error_at (" because of local field `%#D' with same name", tmp); 3448: fdecl = NULL_TREE; 3449: break; 3450: } 3451: 3452: if (!fdecl) 3453: continue; 3454: 3455: /* Make type T see field decl FDECL with access ACCESS.*/ 3456: if (flist) 3457: { 3458: fdecl = TREE_VALUE (flist); 3459: while (fdecl) 3460: { 3461: if (alter_access (t, fdecl, access) == 0) 3462: break; 3463: fdecl = DECL_CHAIN (fdecl); 3464: } 3465: } 3466: else 3467: alter_access (t, fdecl, access); 3468: } 3469: 3470: } 3471: 3472: if (vfield == NULL_TREE && has_virtual) 3473: { 3474: /* We build this decl with ptr_type_node, and 3475: change the type when we know what it should be. */ 3476: vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t), 3477: ptr_type_node); 3478: /* If you change any of the below, take a look at all the 3479: other VFIELD_BASEs and VTABLE_BASEs in the code, and change 3480: them too. */ 3481: DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE); 3482: CLASSTYPE_VFIELD (t) = vfield; 3483: DECL_VIRTUAL_P (vfield) = 1; 3484: DECL_FIELD_CONTEXT (vfield) = t; 3485: DECL_CLASS_CONTEXT (vfield) = t; 3486: DECL_FCONTEXT (vfield) = t; 1.1.1.2 ! root 3487: DECL_SAVED_INSNS (vfield) = NULL_RTX; 1.1 root 3488: DECL_FIELD_SIZE (vfield) = 0; 3489: DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node); 1.1.1.2 ! root 3490: if (CLASSTYPE_RTTI (t)) 1.1 root 3491: { 3492: /* vfield is always first entry in structure. */ 3493: TREE_CHAIN (vfield) = fields; 3494: fields = vfield; 3495: } 3496: else if (last_x) 3497: { 3498: my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175); 3499: TREE_CHAIN (last_x) = vfield; 3500: last_x = vfield; 3501: } 3502: else 3503: fields = vfield; 3504: vfields = chainon (vfields, CLASSTYPE_AS_LIST (t)); 3505: } 3506: 3507: /* Now DECL_INITIAL is null on all members except for zero-width bit-fields. 3508: And they have already done their work. 3509: 3510: C++: maybe we will support default field initialization some day... */ 3511: 3512: /* Delete all zero-width bit-fields from the front of the fieldlist */ 3513: while (fields && DECL_BIT_FIELD (fields) 3514: && DECL_INITIAL (fields)) 3515: fields = TREE_CHAIN (fields); 3516: /* Delete all such fields from the rest of the fields. */ 3517: for (x = fields; x;) 3518: { 3519: if (TREE_CHAIN (x) && DECL_BIT_FIELD (TREE_CHAIN (x)) 3520: && DECL_INITIAL (TREE_CHAIN (x))) 3521: TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x)); 3522: else 3523: x = TREE_CHAIN (x); 3524: } 3525: /* Delete all duplicate fields from the fields */ 3526: delete_duplicate_fields (fields); 3527: 3528: /* Catch function/field name conflict. We don't need to do this for a 3529: signature, since it can only contain the fields constructed in 3530: append_signature_fields. */ 3531: if (! IS_SIGNATURE (t)) 3532: { 3533: int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0; 3534: for (x = fields; x; x = TREE_CHAIN (x)) 3535: { 3536: tree name = DECL_NAME (x); 3537: int i = /*TREE_VEC_ELT (method_vec, 0) ? 0 : */ 1; 3538: for (; i < n_methods; ++i) 3539: if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name) 3540: { 3541: cp_error_at ("data member `%#D' conflicts with", x); 3542: cp_error_at ("function member `%#D'", 3543: TREE_VEC_ELT (method_vec, i)); 3544: break; 3545: } 3546: } 3547: } 3548: 3549: /* Now we have the final fieldlist for the data fields. Record it, 3550: then lay out the structure or union (including the fields). */ 3551: 3552: TYPE_FIELDS (t) = fields; 3553: 3554: /* If there's a :0 field at the end, round the size to the 3555: EMPTY_FIELD_BOUNDARY. */ 3556: TYPE_ALIGN (t) = round_up_size; 3557: 3558: /* Pass layout information about base classes to layout_type, if any. */ 3559: if (n_baseclasses) 3560: { 3561: tree pseudo_basetype = TREE_TYPE (base_layout_decl); 3562: 3563: TREE_CHAIN (base_layout_decl) = TYPE_FIELDS (t); 3564: TYPE_FIELDS (t) = base_layout_decl; 3565: 3566: TYPE_SIZE (pseudo_basetype) = CLASSTYPE_SIZE (t); 3567: TYPE_MODE (pseudo_basetype) = TYPE_MODE (t); 3568: TYPE_ALIGN (pseudo_basetype) = CLASSTYPE_ALIGN (t); 3569: DECL_ALIGN (base_layout_decl) = TYPE_ALIGN (pseudo_basetype); 3570: /* Don't re-use old size. */ 3571: DECL_SIZE (base_layout_decl) = NULL_TREE; 3572: } 3573: 3574: layout_type (t); 3575: 3576: { 3577: tree field; 3578: for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field)) 3579: { 3580: if (TREE_STATIC (field)) 3581: continue; 3582: if (TREE_CODE (field) != FIELD_DECL) 3583: continue; 3584: 3585: /* If this field is an anonymous union, 3586: give each union-member the same position as the union has. 3587: 3588: ??? This is a real kludge because it makes the structure 3589: of the types look strange. This feature is only used by 3590: C++, which should have build_component_ref build two 3591: COMPONENT_REF operations, one for the union and one for 3592: the inner field. We set the offset of this field to zero 3593: so that either the old or the correct method will work. 3594: Setting DECL_FIELD_CONTEXT is wrong unless the inner fields are 3595: moved into the type of this field, but nothing seems to break 3596: by doing this. */ 3597: 3598: if (DECL_NAME (field) == NULL_TREE 3599: && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) 3600: { 3601: tree uelt = TYPE_FIELDS (TREE_TYPE (field)); 3602: for (; uelt; uelt = TREE_CHAIN (uelt)) 3603: { 3604: if (TREE_CODE (uelt) != FIELD_DECL) 3605: continue; 3606: 1.1.1.2 ! root 3607: if (TREE_PRIVATE (uelt)) ! 3608: cp_pedwarn_at ("private member `%#D' in anonymous union", ! 3609: uelt); ! 3610: else if (TREE_PROTECTED (uelt)) ! 3611: cp_pedwarn_at ("protected member `%#D' in anonymous union", ! 3612: uelt); ! 3613: 1.1 root 3614: DECL_FIELD_CONTEXT (uelt) = DECL_FIELD_CONTEXT (field); 3615: DECL_FIELD_BITPOS (uelt) = DECL_FIELD_BITPOS (field); 3616: } 3617: 3618: DECL_FIELD_BITPOS (field) = integer_zero_node; 3619: } 3620: } 3621: } 3622: 3623: if (n_baseclasses) 3624: TYPE_FIELDS (t) = TREE_CHAIN (TYPE_FIELDS (t)); 3625: 3626: /* C++: do not let empty structures exist. */ 3627: if (integer_zerop (TYPE_SIZE (t))) 3628: TYPE_SIZE (t) = TYPE_SIZE (char_type_node); 3629: 3630: /* Set the TYPE_DECL for this type to contain the right 3631: value for DECL_OFFSET, so that we can use it as part 3632: of a COMPONENT_REF for multiple inheritance. */ 3633: 3634: if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL) 3635: layout_decl (TYPE_NAME (t), 0); 3636: 3637: /* Now fix up any virtual base class types that we left lying 3638: around. We must get these done before we try to lay out the 3639: virtual function table. */ 3640: doing_hard_virtuals = 1; 3641: pending_hard_virtuals = nreverse (pending_hard_virtuals); 3642: 3643: if (TYPE_USES_VIRTUAL_BASECLASSES (t)) 3644: { 3645: tree vbases; 3646: 3647: max_has_virtual = layout_vbasetypes (t, max_has_virtual); 3648: vbases = CLASSTYPE_VBASECLASSES (t); 3649: CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases); 3650: 1.1.1.2 ! root 3651: /* The rtti code should do this. (mrs) */ ! 3652: #if 0 1.1 root 3653: while (vbases) 3654: { 1.1.1.2 ! root 3655: /* Update rtti info with offsets for virtual baseclasses. */ ! 3656: if (flag_rtti && ! BINFO_NEW_VTABLE_MARKED (vbases)) 1.1 root 3657: prepare_fresh_vtable (vbases, t); 3658: vbases = TREE_CHAIN (vbases); 3659: } 1.1.1.2 ! root 3660: #endif 1.1 root 3661: 3662: { 3663: /* Now fixup overrides of all functions in vtables from all 3664: direct or indirect virtual base classes. */ 3665: tree binfos = BINFO_BASETYPES (TYPE_BINFO (t)); 3666: int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0; 3667: 3668: for (i = 0; i < n_baseclasses; i++) 3669: { 3670: tree base_binfo = TREE_VEC_ELT (binfos, i); 3671: tree basetype = BINFO_TYPE (base_binfo); 3672: tree vbases; 3673: 3674: vbases = CLASSTYPE_VBASECLASSES (basetype); 3675: while (vbases) 3676: { 3677: merge_overrides (binfo_member (BINFO_TYPE (vbases), 3678: CLASSTYPE_VBASECLASSES (t)), 3679: vbases, 1, t); 3680: vbases = TREE_CHAIN (vbases); 3681: } 3682: } 3683: } 3684: 3685: /* Now fixup any virtual function entries from virtual bases 3686: that have different deltas. */ 3687: vbases = CLASSTYPE_VBASECLASSES (t); 3688: while (vbases) 3689: { 1.1.1.2 ! root 3690: /* We might be able to shorten the amount of work we do by 1.1 root 3691: only doing this for vtables that come from virtual bases 3692: that have differing offsets, but don't want to miss any 3693: entries. */ 1.1.1.2 ! root 3694: fixup_vtable_deltas (vbases, 1, t); 1.1 root 3695: vbases = TREE_CHAIN (vbases); 3696: } 3697: } 3698: 3699: /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we 3700: might need to know it for setting up the offsets in the vtable 3701: (or in thunks) below. */ 3702: if (vfield != NULL_TREE 3703: && DECL_FIELD_CONTEXT (vfield) != t) 3704: { 3705: tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0); 3706: tree offset = BINFO_OFFSET (binfo); 3707: 3708: vfield = copy_node (vfield); 3709: copy_lang_decl (vfield); 3710: 3711: if (! integer_zerop (offset)) 3712: offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT)); 3713: DECL_FIELD_CONTEXT (vfield) = t; 3714: DECL_CLASS_CONTEXT (vfield) = t; 3715: DECL_FIELD_BITPOS (vfield) 3716: = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield)); 3717: CLASSTYPE_VFIELD (t) = vfield; 3718: } 3719: 3720: #ifdef NOTQUITE 3721: cp_warning ("Doing hard virtuals for %T...", t); 3722: #endif 1.1.1.2 ! root 3723: ! 3724: if (has_virtual > max_has_virtual) ! 3725: max_has_virtual = has_virtual; ! 3726: if (max_has_virtual > 0) ! 3727: TYPE_VIRTUAL_P (t) = 1; ! 3728: ! 3729: if (flag_rtti && TYPE_VIRTUAL_P (t) && !pending_hard_virtuals) ! 3730: modify_all_vtables (t, NULL_TREE, NULL_TREE); ! 3731: 1.1 root 3732: while (pending_hard_virtuals) 3733: { 3734: modify_all_vtables (t, 3735: TREE_PURPOSE (pending_hard_virtuals), 3736: TREE_VALUE (pending_hard_virtuals)); 3737: pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals); 3738: } 3739: doing_hard_virtuals = 0; 3740: 3741: /* Under our model of GC, every C++ class gets its own virtual 3742: function table, at least virtually. */ 1.1.1.2 ! root 3743: if (pending_virtuals || (flag_rtti && TYPE_VIRTUAL_P (t))) 1.1 root 3744: { 3745: pending_virtuals = nreverse (pending_virtuals); 3746: /* We must enter these virtuals into the table. */ 3747: if (first_vfn_base_index < 0) 3748: { 1.1.1.2 ! root 3749: /* The first slot is for the rtti offset. */ ! 3750: pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals); ! 3751: ! 3752: /* The second slot is for the tdesc pointer when thunks are used. */ ! 3753: if (flag_vtable_thunks) ! 3754: pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals); ! 3755: ! 3756: set_rtti_entry (pending_virtuals, integer_zero_node, t); 1.1 root 3757: build_vtable (NULL_TREE, t); 3758: } 3759: else 3760: { 1.1.1.2 ! root 3761: tree offset; 1.1 root 3762: /* Here we know enough to change the type of our virtual 3763: function table, but we will wait until later this function. */ 3764: 3765: if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t))) 3766: build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t); 3767: 1.1.1.2 ! root 3768: offset = get_derived_offset (TYPE_BINFO (t), NULL_TREE); ! 3769: offset = size_binop (MINUS_EXPR, integer_zero_node, offset); ! 3770: set_rtti_entry (TYPE_BINFO_VIRTUALS (t), offset, t); 1.1 root 3771: } 3772: 3773: /* If this type has basetypes with constructors, then those 3774: constructors might clobber the virtual function table. But 3775: they don't if the derived class shares the exact vtable of the base 3776: class. */ 3777: 3778: CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1; 3779: } 3780: else if (first_vfn_base_index >= 0) 3781: { 3782: tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index); 3783: /* This class contributes nothing new to the virtual function 3784: table. However, it may have declared functions which 3785: went into the virtual function table "inherited" from the 3786: base class. If so, we grab a copy of those updated functions, 3787: and pretend they are ours. */ 3788: 3789: /* See if we should steal the virtual info from base class. */ 3790: if (TYPE_BINFO_VTABLE (t) == NULL_TREE) 3791: TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo); 3792: if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE) 3793: TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo); 3794: if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo)) 3795: CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1; 3796: } 3797: 3798: if (max_has_virtual || first_vfn_base_index >= 0) 3799: { 3800: CLASSTYPE_VSIZE (t) = has_virtual; 3801: if (first_vfn_base_index >= 0) 3802: { 3803: if (pending_virtuals) 3804: TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t), 3805: pending_virtuals); 3806: } 3807: else if (has_virtual) 3808: { 3809: TYPE_BINFO_VIRTUALS (t) = pending_virtuals; 3810: if (write_virtuals >= 0) 3811: DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1; 3812: } 3813: } 3814: 3815: /* Now lay out the virtual function table. */ 3816: if (has_virtual) 3817: { 3818: tree atype, itype; 3819: 3820: if (TREE_TYPE (vfield) == ptr_type_node) 3821: { 3822: /* We must create a pointer to this table because 3823: the one inherited from base class does not exist. 3824: We will fill in the type when we know what it 3825: should really be. Use `size_int' so values are memoized 3826: in common cases. */ 3827: itype = build_index_type (size_int (has_virtual)); 3828: atype = build_array_type (vtable_entry_type, itype); 3829: layout_type (atype); 3830: TREE_TYPE (vfield) = build_pointer_type (atype); 3831: } 3832: else 3833: { 3834: atype = TREE_TYPE (TREE_TYPE (vfield)); 3835: 3836: if (has_virtual != TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype)))) 3837: { 3838: /* We must extend (or create) the boundaries on this array, 3839: because we picked up virtual functions from multiple 3840: base classes. */ 3841: itype = build_index_type (size_int (has_virtual)); 3842: atype = build_array_type (vtable_entry_type, itype); 3843: layout_type (atype); 3844: vfield = copy_node (vfield); 3845: TREE_TYPE (vfield) = build_pointer_type (atype); 3846: } 3847: } 3848: 3849: CLASSTYPE_VFIELD (t) = vfield; 3850: if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype) 3851: { 3852: TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype; 1.1.1.2 ! root 3853: DECL_SIZE (TYPE_BINFO_VTABLE (t)) = 0; 1.1 root 3854: layout_decl (TYPE_BINFO_VTABLE (t), 0); 3855: /* At one time the vtable info was grabbed 2 words at a time. This 3856: fails on sparc unless you have 8-byte alignment. (tiemann) */ 3857: DECL_ALIGN (TYPE_BINFO_VTABLE (t)) 3858: = MAX (TYPE_ALIGN (double_type_node), 3859: DECL_ALIGN (TYPE_BINFO_VTABLE (t))); 3860: } 3861: } 3862: else if (first_vfn_base_index >= 0) 3863: CLASSTYPE_VFIELD (t) = vfield; 3864: CLASSTYPE_VFIELDS (t) = vfields; 3865: 3866: finish_struct_bits (t, max_has_virtual); 3867: 1.1.1.2 ! root 3868: /* Complete the rtl for any static member objects of the type we're ! 3869: working on. */ 1.1 root 3870: for (x = fields; x; x = TREE_CHAIN (x)) 3871: { 3872: if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x) 3873: && TREE_TYPE (x) == t) 3874: { 3875: DECL_MODE (x) = TYPE_MODE (t); 3876: make_decl_rtl (x, NULL, 0); 3877: } 3878: } 3879: 3880: /* Now add the tags, if any, to the list of TYPE_DECLs 3881: defined for this type. */ 3882: if (CLASSTYPE_TAGS (t)) 3883: { 3884: x = CLASSTYPE_TAGS (t); 3885: last_x = tree_last (TYPE_FIELDS (t)); 3886: while (x) 3887: { 3888: tree tag = TYPE_NAME (TREE_VALUE (x)); 1.1.1.2 ! root 3889: ! 3890: /* Check to see if it is already there. This will be the case if ! 3891: was do enum { red; } color; */ ! 3892: if (chain_member (tag, TYPE_FIELDS (t))) ! 3893: { ! 3894: x = TREE_CHAIN (x); ! 3895: continue; ! 3896: } 1.1 root 3897: 3898: #ifdef DWARF_DEBUGGING_INFO 3899: if (write_symbols == DWARF_DEBUG) 3900: { 3901: /* Notify dwarfout.c that this TYPE_DECL node represent a 3902: gratuitous typedef. */ 3903: DECL_IGNORED_P (tag) = 1; 3904: } 3905: #endif /* DWARF_DEBUGGING_INFO */ 3906: 3907: TREE_NONLOCAL_FLAG (TREE_VALUE (x)) = 0; 3908: x = TREE_CHAIN (x); 3909: last_x = chainon (last_x, tag); 3910: } 3911: if (TYPE_FIELDS (t) == NULL_TREE) 3912: TYPE_FIELDS (t) = last_x; 3913: CLASSTYPE_LOCAL_TYPEDECLS (t) = 1; 3914: } 3915: 3916: if (TYPE_HAS_CONSTRUCTOR (t)) 3917: { 3918: tree vfields = CLASSTYPE_VFIELDS (t); 3919: 3920: while (vfields) 3921: { 3922: /* Mark the fact that constructor for T 3923: could affect anybody inheriting from T 3924: who wants to initialize vtables for VFIELDS's type. */ 3925: if (VF_DERIVED_VALUE (vfields)) 3926: TREE_ADDRESSABLE (vfields) = 1; 3927: vfields = TREE_CHAIN (vfields); 3928: } 3929: if (any_default_members != 0) 3930: build_class_init_list (t); 3931: } 3932: else if (TYPE_NEEDS_CONSTRUCTING (t)) 3933: build_class_init_list (t); 3934: 1.1.1.2 ! root 3935: if (! IS_SIGNATURE (t)) 1.1 root 3936: embrace_waiting_friends (t); 3937: 3938: /* Write out inline function definitions. */ 3939: do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t)); 3940: CLASSTYPE_INLINE_FRIENDS (t) = 0; 3941: 3942: if (CLASSTYPE_VSIZE (t) != 0) 3943: { 3944: #if 0 3945: /* This is now done above. */ 3946: if (DECL_FIELD_CONTEXT (vfield) != t) 3947: { 3948: tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0); 3949: tree offset = BINFO_OFFSET (binfo); 3950: 3951: vfield = copy_node (vfield); 3952: copy_lang_decl (vfield); 3953: 3954: if (! integer_zerop (offset)) 3955: offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT)); 3956: DECL_FIELD_CONTEXT (vfield) = t; 3957: DECL_CLASS_CONTEXT (vfield) = t; 3958: DECL_FIELD_BITPOS (vfield) 3959: = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield)); 3960: CLASSTYPE_VFIELD (t) = vfield; 3961: } 3962: #endif 3963: 3964: /* In addition to this one, all the other vfields should be listed. */ 3965: /* Before that can be done, we have to have FIELD_DECLs for them, and 3966: a place to find them. */ 3967: TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield); 3968: 3969: if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t) 3970: && DECL_VINDEX (TREE_VEC_ELT (method_vec, 0)) == NULL_TREE) 3971: cp_warning ("`%#T' has virtual functions but non-virtual destructor", 3972: t); 3973: } 3974: 3975: /* Make the rtl for any new vtables we have created, and unmark 3976: the base types we marked. */ 3977: finish_vtbls (TYPE_BINFO (t), 1, t); 3978: TYPE_BEING_DEFINED (t) = 0; 1.1.1.2 ! root 3979: hack_incomplete_structures (t); 1.1 root 3980: 3981: #if 0 3982: if (TYPE_NAME (t) && TYPE_IDENTIFIER (t)) 3983: undo_template_name_overload (TYPE_IDENTIFIER (t), 1); 3984: #endif 3985: if (current_class_type) 3986: popclass (0); 3987: else 3988: error ("trying to finish struct, but kicked out due to previous parse errors."); 3989: 3990: resume_momentary (old); 3991: 3992: if (flag_cadillac) 3993: cadillac_finish_struct (t); 3994: 3995: #if 0 3996: /* This has to be done after we have sorted out what to do with 3997: the enclosing type. */ 3998: if (write_symbols != DWARF_DEBUG) 3999: { 4000: /* Be smarter about nested classes here. If a type is nested, 4001: only output it if we would output the enclosing type. */ 4002: if (DECL_CONTEXT (TYPE_NAME (t)) 4003: && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (TYPE_NAME (t)))) == 't') 4004: DECL_IGNORED_P (TYPE_NAME (t)) = TREE_ASM_WRITTEN (TYPE_NAME (t)); 4005: } 4006: #endif 4007: 4008: if (write_symbols != DWARF_DEBUG) 4009: { 4010: /* If the type has methods, we want to think about cutting down 4011: the amount of symbol table stuff we output. The value stored in 4012: the TYPE_DECL's DECL_IGNORED_P slot is a first approximation. 4013: For example, if a member function is seen and we decide to 4014: write out that member function, then we can change the value 4015: of the DECL_IGNORED_P slot, and the type will be output when 4016: that member function's debug info is written out. */ 4017: if (CLASSTYPE_METHOD_VEC (t)) 4018: { 4019: extern tree pending_vtables; 4020: 4021: /* Don't output full info about any type 4022: which does not have its implementation defined here. */ 4023: if (TYPE_VIRTUAL_P (t) && write_virtuals == 2) 4024: TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) 4025: = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0); 4026: else if (CLASSTYPE_INTERFACE_ONLY (t)) 4027: TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1; 4028: else if (CLASSTYPE_INTERFACE_UNKNOWN (t)) 4029: /* Only a first approximation! */ 4030: TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1; 4031: } 4032: else if (CLASSTYPE_INTERFACE_ONLY (t)) 4033: TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1; 4034: } 4035: 4036: /* Finish debugging output for this type. */ 1.1.1.2 ! root 4037: rest_of_type_compilation (t, toplevel_bindings_p ()); 1.1 root 4038: 4039: return t; 4040: } 1.1.1.2 ! root 4041: ! 4042: tree ! 4043: finish_struct (t, list_of_fieldlists, warn_anon) ! 4044: tree t; ! 4045: tree list_of_fieldlists; ! 4046: int warn_anon; ! 4047: { ! 4048: tree fields = NULL_TREE, fn_fields, *tail; ! 4049: tree *tail_user_methods = &CLASSTYPE_METHODS (t); ! 4050: tree name = TYPE_NAME (t); ! 4051: tree x, last_x = NULL_TREE; ! 4052: enum access_type access; ! 4053: ! 4054: if (TREE_CODE (name) == TYPE_DECL) ! 4055: { ! 4056: extern int lineno; ! 4057: ! 4058: DECL_SOURCE_FILE (name) = input_filename; ! 4059: /* For TYPE_DECL that are not typedefs (those marked with a line ! 4060: number of zero, we don't want to mark them as real typedefs. ! 4061: If this fails one needs to make sure real typedefs have a ! 4062: previous line number, even if it is wrong, that way the below ! 4063: will fill in the right line number. (mrs) */ ! 4064: if (DECL_SOURCE_LINE (name)) ! 4065: DECL_SOURCE_LINE (name) = lineno; ! 4066: CLASSTYPE_SOURCE_LINE (t) = lineno; ! 4067: name = DECL_NAME (name); ! 4068: } ! 4069: ! 4070: /* Append the fields we need for constructing signature tables. */ ! 4071: if (IS_SIGNATURE (t)) ! 4072: append_signature_fields (list_of_fieldlists); ! 4073: ! 4074: tail = &fn_fields; ! 4075: if (last_x && list_of_fieldlists) ! 4076: TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists); ! 4077: ! 4078: /* For signatures, we made all methods `public' in the parser and ! 4079: reported an error if a access specifier was used. */ ! 4080: if (CLASSTYPE_DECLARED_CLASS (t) == 0) ! 4081: { ! 4082: if (list_of_fieldlists ! 4083: && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default) ! 4084: TREE_PURPOSE (list_of_fieldlists) = (tree)access_public; ! 4085: } ! 4086: else if (list_of_fieldlists ! 4087: && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default) ! 4088: TREE_PURPOSE (list_of_fieldlists) = (tree)access_private; ! 4089: ! 4090: while (list_of_fieldlists) ! 4091: { ! 4092: access = (enum access_type)TREE_PURPOSE (list_of_fieldlists); ! 4093: ! 4094: for (x = TREE_VALUE (list_of_fieldlists); x; x = TREE_CHAIN (x)) ! 4095: { ! 4096: TREE_PRIVATE (x) = access == access_private; ! 4097: TREE_PROTECTED (x) = access == access_protected; ! 4098: ! 4099: /* Check for inconsistent use of this name in the class body. ! 4100: Enums, types and static vars have already been checked. */ ! 4101: if (TREE_CODE (x) != TYPE_DECL ! 4102: && TREE_CODE (x) != CONST_DECL && TREE_CODE (x) != VAR_DECL) ! 4103: { ! 4104: tree name = DECL_NAME (x); ! 4105: tree icv; ! 4106: ! 4107: /* Don't get confused by access decls. */ ! 4108: if (name && TREE_CODE (name) == IDENTIFIER_NODE) ! 4109: icv = IDENTIFIER_CLASS_VALUE (name); ! 4110: else ! 4111: icv = NULL_TREE; ! 4112: ! 4113: if (icv ! 4114: /* Don't complain about constructors. */ ! 4115: && name != constructor_name (current_class_type) ! 4116: /* Or inherited names. */ ! 4117: && id_in_current_class (name) ! 4118: /* Or shadowed tags. */ ! 4119: && !(TREE_CODE (icv) == TYPE_DECL ! 4120: && DECL_CONTEXT (icv) == t)) ! 4121: { ! 4122: cp_error_at ("declaration of identifier `%D' as `%+#D'", ! 4123: name, x); ! 4124: cp_error_at ("conflicts with other use in class as `%#D'", ! 4125: icv); ! 4126: } ! 4127: } ! 4128: ! 4129: if (TREE_CODE (x) == FUNCTION_DECL) ! 4130: { ! 4131: if (last_x) ! 4132: TREE_CHAIN (last_x) = TREE_CHAIN (x); ! 4133: /* Link x onto end of fn_fields and CLASSTYPE_METHODS. */ ! 4134: *tail = x; ! 4135: tail = &TREE_CHAIN (x); ! 4136: *tail_user_methods = x; ! 4137: tail_user_methods = &DECL_NEXT_METHOD (x); ! 4138: continue; ! 4139: } ! 4140: ! 4141: #if 0 ! 4142: /* Handle access declarations. */ ! 4143: if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF) ! 4144: { ! 4145: tree n = DECL_NAME (x); ! 4146: x = build_decl ! 4147: (USING_DECL, DECL_NAME (TREE_OPERAND (n, 1)), TREE_TYPE (x)); ! 4148: DECL_RESULT (x) = n; ! 4149: } ! 4150: #endif ! 4151: ! 4152: if (! fields) ! 4153: fields = x; ! 4154: last_x = x; ! 4155: } ! 4156: list_of_fieldlists = TREE_CHAIN (list_of_fieldlists); ! 4157: /* link the tail while we have it! */ ! 4158: if (last_x) ! 4159: { ! 4160: TREE_CHAIN (last_x) = NULL_TREE; ! 4161: ! 4162: if (list_of_fieldlists ! 4163: && TREE_VALUE (list_of_fieldlists) ! 4164: && TREE_CODE (TREE_VALUE (list_of_fieldlists)) != FUNCTION_DECL) ! 4165: TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists); ! 4166: } ! 4167: } ! 4168: ! 4169: *tail = NULL_TREE; ! 4170: *tail_user_methods = NULL_TREE; ! 4171: TYPE_FIELDS (t) = fields; ! 4172: ! 4173: if (0 && processing_template_defn) ! 4174: { ! 4175: CLASSTYPE_METHOD_VEC (t) = finish_struct_methods (t, fn_fields, 1); ! 4176: return t; ! 4177: } ! 4178: else ! 4179: return finish_struct_1 (t, warn_anon); ! 4180: } 1.1 root 4181: 4182: /* Return non-zero if the effective type of INSTANCE is static. 4183: Used to determine whether the virtual function table is needed 4184: or not. 4185: 4186: *NONNULL is set iff INSTANCE can be known to be nonnull, regardless 4187: of our knowledge of its type. */ 4188: int 4189: resolves_to_fixed_type_p (instance, nonnull) 4190: tree instance; 4191: int *nonnull; 4192: { 4193: switch (TREE_CODE (instance)) 4194: { 4195: case INDIRECT_REF: 4196: /* Check that we are not going through a cast of some sort. */ 4197: if (TREE_TYPE (instance) 4198: == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0)))) 4199: instance = TREE_OPERAND (instance, 0); 4200: /* fall through... */ 4201: case CALL_EXPR: 4202: /* This is a call to a constructor, hence it's never zero. */ 4203: if (TREE_HAS_CONSTRUCTOR (instance)) 4204: { 4205: if (nonnull) 4206: *nonnull = 1; 4207: return 1; 4208: } 4209: return 0; 4210: 4211: case SAVE_EXPR: 4212: /* This is a call to a constructor, hence it's never zero. */ 4213: if (TREE_HAS_CONSTRUCTOR (instance)) 4214: { 4215: if (nonnull) 4216: *nonnull = 1; 4217: return 1; 4218: } 4219: return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); 4220: 4221: case RTL_EXPR: 4222: /* This is a call to `new', hence it's never zero. */ 4223: if (TREE_CALLS_NEW (instance)) 4224: { 4225: if (nonnull) 4226: *nonnull = 1; 4227: return 1; 4228: } 4229: return 0; 4230: 4231: case PLUS_EXPR: 4232: case MINUS_EXPR: 4233: if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST) 4234: /* Propagate nonnull. */ 4235: resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); 4236: if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR) 4237: return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); 4238: return 0; 4239: 4240: case NOP_EXPR: 4241: case CONVERT_EXPR: 4242: return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); 4243: 4244: case ADDR_EXPR: 4245: if (nonnull) 4246: *nonnull = 1; 4247: return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); 4248: 4249: case COMPONENT_REF: 4250: return resolves_to_fixed_type_p (TREE_OPERAND (instance, 1), nonnull); 4251: 4252: case WITH_CLEANUP_EXPR: 4253: if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR) 4254: return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull); 4255: /* fall through... */ 4256: case VAR_DECL: 4257: case FIELD_DECL: 4258: if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE 4259: && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance)))) 4260: { 4261: if (nonnull) 4262: *nonnull = 1; 4263: return 1; 4264: } 4265: /* fall through... */ 4266: case TARGET_EXPR: 4267: case PARM_DECL: 4268: if (IS_AGGR_TYPE (TREE_TYPE (instance))) 4269: { 4270: if (nonnull) 4271: *nonnull = 1; 4272: return 1; 4273: } 4274: else if (nonnull) 4275: { 4276: if (instance == current_class_decl 4277: && flag_this_is_variable <= 0) 4278: { 4279: /* Some people still use `this = 0' inside destructors. */ 4280: *nonnull = ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl)); 4281: /* In a constructor, we know our type. */ 4282: if (flag_this_is_variable < 0) 4283: return 1; 4284: } 4285: else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) 4286: /* Reference variables should be references to objects. */ 4287: *nonnull = 1; 4288: } 4289: return 0; 4290: 4291: default: 4292: return 0; 4293: } 4294: } 4295: 4296: void 4297: init_class_processing () 4298: { 4299: current_class_depth = 0; 4300: current_class_stacksize = 10; 4301: current_class_base = (tree *)xmalloc(current_class_stacksize * sizeof (tree)); 4302: current_class_stack = current_class_base; 4303: 4304: current_lang_stacksize = 10; 4305: current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree)); 4306: current_lang_stack = current_lang_base; 4307: 4308: /* Keep these values lying around. */ 4309: the_null_vtable_entry = build_vtable_entry (integer_zero_node, integer_zero_node); 4310: base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node); 4311: TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE); 4312: 4313: gcc_obstack_init (&class_obstack); 4314: } 4315: 4316: /* Set current scope to NAME. CODE tells us if this is a 4317: STRUCT, UNION, or ENUM environment. 4318: 4319: NAME may end up being NULL_TREE if this is an anonymous or 4320: late-bound struct (as in "struct { ... } foo;") */ 4321: 4322: /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to 4323: appropriate values, found by looking up the type definition of 4324: NAME (as a CODE). 4325: 4326: If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names 4327: which can be seen locally to the class. They are shadowed by 4328: any subsequent local declaration (including parameter names). 4329: 4330: If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names 4331: which have static meaning (i.e., static members, static 4332: member functions, enum declarations, etc). 4333: 4334: If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names 4335: which can be seen locally to the class (as in 1), but 4336: know that we are doing this for declaration purposes 4337: (i.e. friend foo::bar (int)). 4338: 4339: So that we may avoid calls to lookup_name, we cache the _TYPE 4340: nodes of local TYPE_DECLs in the TREE_TYPE field of the name. 4341: 4342: For multiple inheritance, we perform a two-pass depth-first search 4343: of the type lattice. The first pass performs a pre-order search, 4344: marking types after the type has had its fields installed in 4345: the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely 4346: unmarks the marked types. If a field or member function name 4347: appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of 4348: that name becomes `error_mark_node'. */ 4349: 4350: void 4351: pushclass (type, modify) 4352: tree type; 4353: int modify; 4354: { 4355: push_memoized_context (type, modify); 4356: 4357: current_class_depth++; 4358: *current_class_stack++ = current_class_name; 4359: *current_class_stack++ = current_class_type; 4360: if (current_class_stack >= current_class_base + current_class_stacksize) 4361: { 4362: current_class_base = 4363: (tree *)xrealloc (current_class_base, 4364: sizeof (tree) * (current_class_stacksize + 10)); 4365: current_class_stack = current_class_base + current_class_stacksize; 4366: current_class_stacksize += 10; 4367: } 4368: 4369: current_class_name = TYPE_NAME (type); 4370: if (TREE_CODE (current_class_name) == TYPE_DECL) 4371: current_class_name = DECL_NAME (current_class_name); 4372: current_class_type = type; 4373: 4374: if (previous_class_type != NULL_TREE 4375: && (type != previous_class_type || TYPE_SIZE (previous_class_type) == NULL_TREE) 4376: && current_class_depth == 1) 4377: { 4378: /* Forcibly remove any old class remnants. */ 4379: popclass (-1); 4380: previous_class_type = NULL_TREE; 4381: } 4382: 4383: pushlevel_class (); 4384: 4385: if (modify) 4386: { 4387: tree tags; 4388: tree this_fndecl = current_function_decl; 4389: 4390: if (current_function_decl 4391: && DECL_CONTEXT (current_function_decl) 4392: && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL) 4393: current_function_decl = DECL_CONTEXT (current_function_decl); 4394: else 4395: current_function_decl = NULL_TREE; 4396: 4397: if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) 4398: declare_uninstantiated_type_level (); 4399: else if (type != previous_class_type || current_class_depth > 1) 4400: { 4401: build_mi_matrix (type); 4402: push_class_decls (type); 4403: free_mi_matrix (); 4404: if (current_class_depth == 1) 4405: previous_class_type = type; 4406: } 4407: else 4408: { 4409: tree item; 4410: 1.1.1.2 ! root 4411: /* Hooray, we successfully cached; let's just install the 1.1 root 4412: cached class_shadowed list, and walk through it to get the 4413: IDENTIFIER_TYPE_VALUEs correct. */ 4414: set_class_shadows (previous_class_values); 4415: for (item = previous_class_values; item; item = TREE_CHAIN (item)) 4416: { 4417: tree id = TREE_PURPOSE (item); 4418: tree decl = IDENTIFIER_CLASS_VALUE (id); 4419: 4420: if (TREE_CODE (decl) == TYPE_DECL) 4421: set_identifier_type_value (id, TREE_TYPE (decl)); 4422: } 4423: unuse_fields (type); 4424: } 4425: 4426: if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (type))) 4427: overload_template_name (current_class_name, 0); 4428: 4429: for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags)) 4430: { 4431: TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 1; 4432: if (! TREE_PURPOSE (tags)) 4433: continue; 4434: pushtag (TREE_PURPOSE (tags), TREE_VALUE (tags), 0); 4435: } 4436: 4437: current_function_decl = this_fndecl; 4438: } 4439: 4440: if (flag_cadillac) 4441: cadillac_push_class (type); 4442: } 4443: 4444: /* Get out of the current class scope. If we were in a class scope 4445: previously, that is the one popped to. The flag MODIFY tells whether 4446: the current scope declarations needs to be modified as a result of 4447: popping to the previous scope. 0 is used for class definitions. */ 4448: void 4449: popclass (modify) 4450: int modify; 4451: { 4452: if (flag_cadillac) 4453: cadillac_pop_class (); 4454: 4455: if (modify < 0) 4456: { 4457: /* Back this old class out completely. */ 4458: tree tags = CLASSTYPE_TAGS (previous_class_type); 4459: tree t; 4460: 4461: /* This code can be seen as a cache miss. When we've cached a 4462: class' scope's bindings and we can't use them, we need to reset 4463: them. This is it! */ 4464: for (t = previous_class_values; t; t = TREE_CHAIN (t)) 4465: IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE; 4466: while (tags) 4467: { 4468: TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0; 4469: tags = TREE_CHAIN (tags); 4470: } 4471: goto ret; 4472: } 4473: 4474: if (modify) 4475: { 4476: /* Just remove from this class what didn't make 4477: it into IDENTIFIER_CLASS_VALUE. */ 4478: tree tags = CLASSTYPE_TAGS (current_class_type); 4479: 4480: while (tags) 4481: { 4482: TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0; 4483: tags = TREE_CHAIN (tags); 4484: } 4485: if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type))) 4486: undo_template_name_overload (current_class_name, 0); 4487: } 4488: 4489: /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition, 4490: since not all class decls make it there currently. */ 4491: poplevel_class (! modify); 4492: 4493: /* Since poplevel_class does the popping of class decls nowadays, 4494: this really only frees the obstack used for these decls. 4495: That's why it had to be moved down here. */ 4496: if (modify) 4497: pop_class_decls (current_class_type); 4498: 4499: current_class_depth--; 4500: current_class_type = *--current_class_stack; 4501: current_class_name = *--current_class_stack; 4502: 4503: pop_memoized_context (modify); 4504: 4505: ret: 4506: ; 4507: } 4508: 4509: /* When entering a class scope, all enclosing class scopes' names with 4510: static meaning (static variables, static functions, types and enumerators) 4511: have to be visible. This recursive function calls pushclass for all 4512: enclosing class contexts until global or a local scope is reached. 4513: TYPE is the enclosed class and MODIFY is equivalent with the pushclass 4514: formal of the same name. */ 4515: 4516: void 4517: push_nested_class (type, modify) 4518: tree type; 4519: int modify; 4520: { 4521: tree context; 4522: 1.1.1.2 ! root 4523: if (type == NULL_TREE || type == error_mark_node || ! IS_AGGR_TYPE (type)) 1.1 root 4524: return; 4525: 4526: context = DECL_CONTEXT (TYPE_NAME (type)); 4527: 4528: if (context && TREE_CODE (context) == RECORD_TYPE) 4529: push_nested_class (context, 2); 4530: pushclass (type, modify); 4531: } 4532: 4533: /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */ 4534: 4535: void 4536: pop_nested_class (modify) 4537: int modify; 4538: { 4539: tree context = DECL_CONTEXT (TYPE_NAME (current_class_type)); 4540: 4541: popclass (modify); 4542: if (context && TREE_CODE (context) == RECORD_TYPE) 4543: pop_nested_class (modify); 4544: } 4545: 4546: /* Set global variables CURRENT_LANG_NAME to appropriate value 4547: so that behavior of name-mangling machinery is correct. */ 4548: 4549: void 4550: push_lang_context (name) 4551: tree name; 4552: { 4553: *current_lang_stack++ = current_lang_name; 4554: if (current_lang_stack >= current_lang_base + current_lang_stacksize) 4555: { 4556: current_lang_base = 4557: (tree *)xrealloc (current_lang_base, 4558: sizeof (tree) * (current_lang_stacksize + 10)); 4559: current_lang_stack = current_lang_base + current_lang_stacksize; 4560: current_lang_stacksize += 10; 4561: } 4562: 4563: if (name == lang_name_cplusplus) 4564: { 4565: strict_prototype = strict_prototypes_lang_cplusplus; 4566: current_lang_name = name; 4567: } 4568: else if (name == lang_name_c) 4569: { 4570: strict_prototype = strict_prototypes_lang_c; 4571: current_lang_name = name; 4572: } 4573: else 4574: error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name)); 4575: 4576: if (flag_cadillac) 4577: cadillac_push_lang (name); 4578: } 4579: 4580: /* Get out of the current language scope. */ 4581: void 4582: pop_lang_context () 4583: { 4584: if (flag_cadillac) 4585: cadillac_pop_lang (); 4586: 4587: current_lang_name = *--current_lang_stack; 4588: if (current_lang_name == lang_name_cplusplus) 4589: strict_prototype = strict_prototypes_lang_cplusplus; 4590: else if (current_lang_name == lang_name_c) 4591: strict_prototype = strict_prototypes_lang_c; 4592: } 4593: 4594: int 4595: root_lang_context_p () 4596: { 4597: return current_lang_stack == current_lang_base; 4598: } 4599: 4600: /* Type instantiation routines. */ 4601: 4602: /* This function will instantiate the type of the expression given 4603: in RHS to match the type of LHSTYPE. If LHSTYPE is NULL_TREE, 4604: or other errors exist, the TREE_TYPE of RHS will be ERROR_MARK_NODE. 4605: 4606: This function is used in build_modify_expr, convert_arguments, 4607: build_c_cast, and compute_conversion_costs. */ 4608: tree 4609: instantiate_type (lhstype, rhs, complain) 4610: tree lhstype, rhs; 4611: int complain; 4612: { 4613: if (TREE_CODE (lhstype) == UNKNOWN_TYPE) 4614: { 4615: if (complain) 4616: error ("not enough type information"); 4617: return error_mark_node; 4618: } 4619: 4620: if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs))) 4621: return rhs; 4622: 4623: /* This should really only be used when attempting to distinguish 4624: what sort of a pointer to function we have. For now, any 4625: arithmetic operation which is not supported on pointers 4626: is rejected as an error. */ 4627: 4628: switch (TREE_CODE (rhs)) 4629: { 4630: case TYPE_EXPR: 4631: case CONVERT_EXPR: 4632: case SAVE_EXPR: 4633: case CONSTRUCTOR: 4634: case BUFFER_REF: 4635: my_friendly_abort (177); 4636: return error_mark_node; 4637: 4638: case INDIRECT_REF: 4639: case ARRAY_REF: 4640: TREE_TYPE (rhs) = lhstype; 4641: lhstype = build_pointer_type (lhstype); 4642: TREE_OPERAND (rhs, 0) 4643: = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain); 4644: if (TREE_OPERAND (rhs, 0) == error_mark_node) 4645: return error_mark_node; 4646: 4647: return rhs; 4648: 4649: case NOP_EXPR: 4650: rhs = copy_node (TREE_OPERAND (rhs, 0)); 4651: TREE_TYPE (rhs) = unknown_type_node; 4652: return instantiate_type (lhstype, rhs, complain); 4653: 4654: case COMPONENT_REF: 4655: { 4656: tree field = TREE_OPERAND (rhs, 1); 4657: if (TREE_CODE (field) == TREE_LIST) 4658: { 4659: tree function = instantiate_type (lhstype, field, complain); 4660: if (function == error_mark_node) 4661: return error_mark_node; 4662: my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 185); 4663: if (DECL_VINDEX (function)) 4664: { 4665: tree base = TREE_OPERAND (rhs, 0); 4666: tree base_ptr = build_unary_op (ADDR_EXPR, base, 0); 4667: if (base_ptr == error_mark_node) 4668: return error_mark_node; 4669: base_ptr = convert_pointer_to (DECL_CONTEXT (function), base_ptr); 4670: if (base_ptr == error_mark_node) 4671: return error_mark_node; 4672: return build_vfn_ref (&base_ptr, base, DECL_VINDEX (function)); 4673: } 4674: return function; 4675: } 4676: 4677: my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 178); 4678: my_friendly_assert (!(TREE_CODE (TREE_TYPE (field)) == FUNCTION_TYPE 4679: || TREE_CODE (TREE_TYPE (field)) == METHOD_TYPE), 4680: 179); 4681: 4682: TREE_TYPE (rhs) = lhstype; 4683: /* First look for an exact match */ 4684: 4685: while (field && TREE_TYPE (field) != lhstype) 1.1.1.2 ! root 4686: field = DECL_CHAIN (field); 1.1 root 4687: if (field) 4688: { 4689: TREE_OPERAND (rhs, 1) = field; 4690: return rhs; 4691: } 4692: 4693: /* No exact match found, look for a compatible function. */ 4694: field = TREE_OPERAND (rhs, 1); 4695: while (field && ! comptypes (lhstype, TREE_TYPE (field), 0)) 1.1.1.2 ! root 4696: field = DECL_CHAIN (field); 1.1 root 4697: if (field) 4698: { 4699: TREE_OPERAND (rhs, 1) = field; 1.1.1.2 ! root 4700: field = DECL_CHAIN (field); 1.1 root 4701: while (field && ! comptypes (lhstype, TREE_TYPE (field), 0)) 1.1.1.2 ! root 4702: field = DECL_CHAIN (field); 1.1 root 4703: if (field) 4704: { 4705: if (complain) 4706: error ("ambiguous overload for COMPONENT_REF requested"); 4707: return error_mark_node; 4708: } 4709: } 4710: else 4711: { 4712: if (complain) 4713: error ("no appropriate overload exists for COMPONENT_REF"); 4714: return error_mark_node; 4715: } 4716: return rhs; 4717: } 4718: 4719: case TREE_LIST: 4720: { 4721: tree elem, baselink, name; 4722: int globals = overloaded_globals_p (rhs); 4723: 4724: #if 0 /* obsolete */ 4725: /* If there's only one function we know about, return that. */ 4726: if (globals > 0 && TREE_CHAIN (rhs) == NULL_TREE) 4727: return TREE_VALUE (rhs); 4728: #endif 4729: 4730: /* First look for an exact match. Search either overloaded 4731: functions or member functions. May have to undo what 4732: `default_conversion' might do to lhstype. */ 4733: 1.1.1.2 ! root 4734: if (TYPE_PTRMEMFUNC_P (lhstype)) ! 4735: lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype); ! 4736: 1.1 root 4737: if (TREE_CODE (lhstype) == POINTER_TYPE) 4738: if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE 4739: || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE) 4740: lhstype = TREE_TYPE (lhstype); 4741: else 4742: { 4743: if (complain) 4744: error ("invalid type combination for overload"); 4745: return error_mark_node; 4746: } 4747: 4748: if (TREE_CODE (lhstype) != FUNCTION_TYPE && globals > 0) 4749: { 4750: if (complain) 4751: cp_error ("cannot resolve overloaded function `%D' based on non-function type", 4752: TREE_PURPOSE (rhs)); 4753: return error_mark_node; 4754: } 4755: 4756: if (globals > 0) 4757: { 4758: elem = get_first_fn (rhs); 4759: while (elem) 4760: if (! comptypes (lhstype, TREE_TYPE (elem), 1)) 4761: elem = DECL_CHAIN (elem); 4762: else 4763: return elem; 4764: 4765: /* No exact match found, look for a compatible template. */ 4766: { 4767: tree save_elem = 0; 4768: for (elem = get_first_fn (rhs); elem; elem = DECL_CHAIN (elem)) 4769: if (TREE_CODE (elem) == TEMPLATE_DECL) 4770: { 4771: int n = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (elem)); 4772: tree *t = (tree *) alloca (sizeof (tree) * n); 1.1.1.2 ! root 4773: int i, d = 0; 1.1 root 4774: i = type_unification (DECL_TEMPLATE_PARMS (elem), t, 4775: TYPE_ARG_TYPES (TREE_TYPE (elem)), 4776: TYPE_ARG_TYPES (lhstype), &d, 0); 4777: if (i == 0) 4778: { 4779: if (save_elem) 4780: { 4781: cp_error ("ambiguous template instantiation converting to `%#T'", lhstype); 4782: return error_mark_node; 4783: } 4784: save_elem = instantiate_template (elem, t); 4785: /* Check the return type. */ 4786: if (! comptypes (TREE_TYPE (lhstype), 4787: TREE_TYPE (TREE_TYPE (save_elem)), 1)) 4788: save_elem = 0; 4789: } 4790: } 4791: if (save_elem) 4792: return save_elem; 4793: } 4794: 4795: /* No match found, look for a compatible function. */ 4796: elem = get_first_fn (rhs); 1.1.1.2 ! root 4797: while (elem && comp_target_types (lhstype, ! 4798: TREE_TYPE (elem), 1) <= 0) 1.1 root 4799: elem = DECL_CHAIN (elem); 4800: if (elem) 4801: { 4802: tree save_elem = elem; 4803: elem = DECL_CHAIN (elem); 1.1.1.2 ! root 4804: while (elem && comp_target_types (lhstype, ! 4805: TREE_TYPE (elem), 0) <= 0) 1.1 root 4806: elem = DECL_CHAIN (elem); 4807: if (elem) 4808: { 4809: if (complain) 4810: { 4811: cp_error ("cannot resolve overload to target type `%#T'", 4812: lhstype); 4813: cp_error_at (" ambiguity between `%#D'", save_elem); 4814: cp_error_at (" and `%#D', at least", elem); 4815: } 4816: return error_mark_node; 4817: } 4818: return save_elem; 4819: } 4820: if (complain) 4821: { 4822: cp_error ("cannot resolve overload to target type `%#T'", 4823: lhstype); 4824: cp_error (" because no suitable overload of function `%D' exists", 4825: TREE_PURPOSE (rhs)); 4826: } 4827: return error_mark_node; 4828: } 4829: 4830: if (TREE_NONLOCAL_FLAG (rhs)) 4831: { 4832: /* Got to get it as a baselink. */ 4833: rhs = lookup_fnfields (TYPE_BINFO (current_class_type), 4834: TREE_PURPOSE (rhs), 0); 4835: } 4836: else 4837: { 4838: my_friendly_assert (TREE_CHAIN (rhs) == NULL_TREE, 181); 4839: if (TREE_CODE (TREE_VALUE (rhs)) == TREE_LIST) 4840: rhs = TREE_VALUE (rhs); 4841: my_friendly_assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL, 4842: 182); 4843: } 4844: 4845: for (baselink = rhs; baselink; 4846: baselink = next_baselink (baselink)) 4847: { 4848: elem = TREE_VALUE (baselink); 4849: while (elem) 4850: if (comptypes (lhstype, TREE_TYPE (elem), 1)) 4851: return elem; 4852: else 1.1.1.2 ! root 4853: elem = DECL_CHAIN (elem); 1.1 root 4854: } 4855: 4856: /* No exact match found, look for a compatible method. */ 4857: for (baselink = rhs; baselink; 4858: baselink = next_baselink (baselink)) 4859: { 4860: elem = TREE_VALUE (baselink); 1.1.1.2 ! root 4861: while (elem && comp_target_types (lhstype, ! 4862: TREE_TYPE (elem), 1) <= 0) ! 4863: elem = DECL_CHAIN (elem); 1.1 root 4864: if (elem) 4865: { 4866: tree save_elem = elem; 1.1.1.2 ! root 4867: elem = DECL_CHAIN (elem); ! 4868: while (elem && comp_target_types (lhstype, ! 4869: TREE_TYPE (elem), 0) <= 0) ! 4870: elem = DECL_CHAIN (elem); 1.1 root 4871: if (elem) 4872: { 4873: if (complain) 4874: error ("ambiguous overload for overloaded method requested"); 4875: return error_mark_node; 4876: } 4877: return save_elem; 4878: } 4879: name = DECL_NAME (TREE_VALUE (rhs)); 4880: #if 0 4881: if (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0) 4882: { 4883: /* Try to instantiate from non-member functions. */ 4884: rhs = lookup_name_nonclass (name); 4885: if (rhs && TREE_CODE (rhs) == TREE_LIST) 4886: { 4887: /* This code seems to be missing a `return'. */ 4888: my_friendly_abort (4); 4889: instantiate_type (lhstype, rhs, complain); 4890: } 4891: } 4892: #endif 4893: } 4894: if (complain) 1.1.1.2 ! root 4895: cp_error ("no compatible member functions named `%D'", name); 1.1 root 4896: return error_mark_node; 4897: } 4898: 4899: case CALL_EXPR: 4900: /* This is too hard for now. */ 4901: my_friendly_abort (183); 4902: return error_mark_node; 4903: 4904: case PLUS_EXPR: 4905: case MINUS_EXPR: 4906: case COMPOUND_EXPR: 4907: TREE_OPERAND (rhs, 0) 4908: = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain); 4909: if (TREE_OPERAND (rhs, 0) == error_mark_node) 4910: return error_mark_node; 4911: TREE_OPERAND (rhs, 1) 4912: = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain); 4913: if (TREE_OPERAND (rhs, 1) == error_mark_node) 4914: return error_mark_node; 4915: 4916: TREE_TYPE (rhs) = lhstype; 4917: return rhs; 4918: 4919: case MULT_EXPR: 4920: case TRUNC_DIV_EXPR: 4921: case FLOOR_DIV_EXPR: 4922: case CEIL_DIV_EXPR: 4923: case ROUND_DIV_EXPR: 4924: case RDIV_EXPR: 4925: case TRUNC_MOD_EXPR: 4926: case FLOOR_MOD_EXPR: 4927: case CEIL_MOD_EXPR: 4928: case ROUND_MOD_EXPR: 4929: case FIX_ROUND_EXPR: 4930: case FIX_FLOOR_EXPR: 4931: case FIX_CEIL_EXPR: 4932: case FIX_TRUNC_EXPR: 4933: case FLOAT_EXPR: 4934: case NEGATE_EXPR: 4935: case ABS_EXPR: 4936: case MAX_EXPR: 4937: case MIN_EXPR: 4938: case FFS_EXPR: 4939: 4940: case BIT_AND_EXPR: 4941: case BIT_IOR_EXPR: 4942: case BIT_XOR_EXPR: 4943: case LSHIFT_EXPR: 4944: case RSHIFT_EXPR: 4945: case LROTATE_EXPR: 4946: case RROTATE_EXPR: 4947: 4948: case PREINCREMENT_EXPR: 4949: case PREDECREMENT_EXPR: 4950: case POSTINCREMENT_EXPR: 4951: case POSTDECREMENT_EXPR: 4952: if (complain) 1.1.1.2 ! root 4953: error ("invalid operation on uninstantiated type"); 1.1 root 4954: return error_mark_node; 4955: 4956: case TRUTH_AND_EXPR: 4957: case TRUTH_OR_EXPR: 4958: case TRUTH_XOR_EXPR: 4959: case LT_EXPR: 4960: case LE_EXPR: 4961: case GT_EXPR: 4962: case GE_EXPR: 4963: case EQ_EXPR: 4964: case NE_EXPR: 4965: case TRUTH_ANDIF_EXPR: 4966: case TRUTH_ORIF_EXPR: 4967: case TRUTH_NOT_EXPR: 4968: if (complain) 4969: error ("not enough type information"); 4970: return error_mark_node; 4971: 4972: case COND_EXPR: 4973: if (type_unknown_p (TREE_OPERAND (rhs, 0))) 4974: { 4975: if (complain) 4976: error ("not enough type information"); 4977: return error_mark_node; 4978: } 4979: TREE_OPERAND (rhs, 1) 4980: = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain); 4981: if (TREE_OPERAND (rhs, 1) == error_mark_node) 4982: return error_mark_node; 4983: TREE_OPERAND (rhs, 2) 4984: = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), complain); 4985: if (TREE_OPERAND (rhs, 2) == error_mark_node) 4986: return error_mark_node; 4987: 4988: TREE_TYPE (rhs) = lhstype; 4989: return rhs; 4990: 4991: case MODIFY_EXPR: 4992: TREE_OPERAND (rhs, 1) 4993: = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain); 4994: if (TREE_OPERAND (rhs, 1) == error_mark_node) 4995: return error_mark_node; 4996: 4997: TREE_TYPE (rhs) = lhstype; 4998: return rhs; 4999: 5000: case ADDR_EXPR: 5001: if (TYPE_PTRMEMFUNC_P (lhstype)) 5002: lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype); 5003: else if (TREE_CODE (lhstype) != POINTER_TYPE) 5004: { 5005: if (complain) 5006: error ("type for resolving address of overloaded function must be pointer type"); 5007: return error_mark_node; 5008: } 5009: TREE_TYPE (rhs) = lhstype; 5010: lhstype = TREE_TYPE (lhstype); 5011: { 5012: tree fn = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain); 5013: if (fn == error_mark_node) 5014: return error_mark_node; 5015: mark_addressable (fn); 5016: TREE_OPERAND (rhs, 0) = fn; 5017: TREE_CONSTANT (rhs) = staticp (fn); 5018: } 5019: return rhs; 5020: 5021: case ENTRY_VALUE_EXPR: 5022: my_friendly_abort (184); 5023: return error_mark_node; 5024: 5025: case ERROR_MARK: 5026: return error_mark_node; 5027: 5028: default: 5029: my_friendly_abort (185); 5030: return error_mark_node; 5031: } 5032: } 5033: 5034: /* Return the name of the virtual function pointer field 5035: (as an IDENTIFIER_NODE) for the given TYPE. Note that 5036: this may have to look back through base types to find the 5037: ultimate field name. (For single inheritance, these could 5038: all be the same name. Who knows for multiple inheritance). */ 5039: static tree 5040: get_vfield_name (type) 5041: tree type; 5042: { 5043: tree binfo = TYPE_BINFO (type); 5044: char *buf; 5045: 5046: while (BINFO_BASETYPES (binfo) 5047: && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0))) 5048: && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0))) 5049: binfo = BINFO_BASETYPE (binfo, 0); 5050: 5051: type = BINFO_TYPE (binfo); 5052: buf = (char *)alloca (sizeof (VFIELD_NAME_FORMAT) 5053: + TYPE_NAME_LENGTH (type) + 2); 5054: sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type)); 5055: return get_identifier (buf); 5056: } 5057: 5058: void 5059: print_class_statistics () 5060: { 5061: #ifdef GATHER_STATISTICS 5062: fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness); 5063: fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs); 5064: fprintf (stderr, "build_method_call = %d (inner = %d)\n", 5065: n_build_method_call, n_inner_fields_searched); 5066: if (n_vtables) 5067: { 5068: fprintf (stderr, "vtables = %d; vtable searches = %d\n", 5069: n_vtables, n_vtable_searches); 5070: fprintf (stderr, "vtable entries = %d; vtable elems = %d\n", 5071: n_vtable_entries, n_vtable_elems); 5072: } 5073: #endif 5074: } 5075: 5076: /* Push an obstack which is sufficiently long-lived to hold such class 5077: decls that may be cached in the previous_class_values list. For now, let's 5078: use the permanent obstack, later we may create a dedicated obstack just 5079: for this purpose. The effect is undone by pop_obstacks. */ 5080: void 5081: maybe_push_cache_obstack () 5082: { 5083: push_obstacks_nochange (); 5084: if (current_class_depth == 1) 5085: current_obstack = &permanent_obstack; 5086: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.