home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / g++-1.42.0 / cplus-init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  112.0 KB  |  3,682 lines

  1. /* Handle initialization things in C++.
  2.    Copyright (C) 1987 Free Software Foundation, Inc.
  3.    Contributed by Michael Tiemann (tiemann@mcc.com)
  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 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* High-level class interface. */
  23.  
  24. #include "config.h"
  25. #include "tree.h"
  26. #include "cplus-tree.h"
  27. #include "flags.h"
  28. #include "assert.h"
  29.  
  30. /* For expand_asm_operands.  */
  31. extern char *input_filename;
  32. extern int lineno;
  33.  
  34. #define NULL 0
  35.  
  36. /* In C++, structures with well-defined constructors are initialized by
  37.    those constructors, unasked.  CURRENT_BASE_INIT_LIST
  38.    holds a list of stmts for a BASE_INIT term in the grammar.
  39.    This list has one element for each base class which must be
  40.    initialized.  The list elements are [basename, init], with
  41.    type basetype.  This allows the possibly anachronistic form
  42.    (assuming d : a, b, c) "d (int a) : c(a+5), b (a-4), a (a+3)"
  43.    where each successive term can be handed down the constructor
  44.    line.  Perhaps this was not intended.  */
  45. tree current_base_init_list, current_member_init_list;
  46.  
  47. void init_init_processing ();
  48. void emit_base_init ();
  49. void check_base_init ();
  50. static void expand_aggr_vbase_init ();
  51. void expand_member_init ();
  52. void expand_aggr_init ();
  53. tree build_virtual_init ();
  54. tree build_vbase_delete ();
  55.  
  56. static void expand_aggr_init_1 ();
  57. static void expand_recursive_init_1 ();
  58. static void expand_recursive_init ();
  59. tree expand_vec_init ();
  60. tree build_vec_delete ();
  61.  
  62. static void add_friend (), add_friends ();
  63.  
  64. int is_aggr_typedef ();
  65. /* Cache _builtin_new and _builtin_delete exprs.  */
  66. static tree BIN, BIVN, BID;
  67.  
  68. #ifdef SOS
  69. tree get_linktable_name (), get_dtable_name (), get_sos_dtable ();
  70. static tree __sosFindCode, __sosLookup, __sosImport;
  71. static tree build_dynamic_new ();
  72. #endif
  73. static tree minus_one;
  74.  
  75. extern struct rtx_def *start_sequence (), *get_insns (), *get_last_insn ();
  76. extern struct rtx_def *const0_rtx;
  77.  
  78. /* Set up local variable for this file.  MUST BE CALLED AFTER
  79.    INIT_DECL_PROCESSING.  */
  80.  
  81. void init_init_processing ()
  82. {
  83.   BIN = default_conversion (TREE_VALUE (lookup_name (get_identifier ("__builtin_new"))));
  84.   BIVN = default_conversion (TREE_VALUE (lookup_name (get_identifier ("__builtin_vec_new"))));
  85.   BID = default_conversion (TREE_VALUE (lookup_name (get_identifier ("__builtin_delete"))));
  86.   minus_one = build_int_2 (-1, -1);
  87. #ifdef SOS
  88.   if (flag_all_virtual == 2)
  89.     {
  90.       __sosFindCode = default_conversion (lookup_name (get_identifier ("sosFindCode")));
  91.       __sosLookup = default_conversion (lookup_name (get_identifier ("sosLookup")));
  92.       __sosImport = default_conversion (lookup_name (get_identifier ("sosImport")));
  93.     }
  94. #endif
  95. }
  96.  
  97. /* Perform whatever initialization have yet to be done on the
  98.    base class of the class variable.  These actions are in
  99.    the global variable CURRENT_BASE_INIT_LIST.  Such an
  100.    action could be NULL_TREE, meaning that the user has explicitly
  101.    called the base class constructor with no arguments.
  102.  
  103.    If there is a need for a call to a constructor, we
  104.    must surround that call with a pushlevel/poplevel pair,
  105.    since we are technically at the PARM level of scope.
  106.  
  107.    Argument ASSIGNS_THIS_P is nonzero if the current function assigns
  108.    `this' explicitly.  We cannot get this value by checking
  109.    `current_function_assigns_this', since it is set up after this
  110.    function is called.  (although I don't know if its really
  111.    necessary to wait until afterward to do that.)
  112.  
  113.    Note that emit_base_init does *not* initialize virtual
  114.    base classes.  That is done specially, elsewhere.  */
  115.    
  116. void
  117. emit_base_init (t, immediately)
  118.      tree t;
  119.      int immediately;
  120. {
  121.   extern tree in_charge_identifier;
  122.  
  123.   tree member, decl;
  124.   tree init_list, basetype;
  125.   int pass, start;
  126.   int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
  127.   tree fields_to_unmark = NULL_TREE;
  128.   tree vfields;
  129.  
  130.   if (! immediately)
  131.     {
  132.       do_pending_stack_adjust ();
  133.       start_sequence ();
  134.       /* As a matter of principle, `start_sequence' should do this.  */
  135.       emit_note (0, -1);
  136.     }
  137.  
  138.   /* In this case, we always need IN_CHARGE_NODE, because we have
  139.      to know whether to deallocate or not before exiting.  */
  140.   if (flag_handle_exceptions == 2
  141.       && lookup_name (in_charge_identifier) == NULL_TREE)
  142.     {
  143.       tree in_charge_node = pushdecl (build_decl (VAR_DECL, in_charge_identifier,
  144.                           integer_type_node));
  145.       store_init_value (in_charge_node, build (EQ_EXPR, integer_type_node,
  146.                            current_class_decl,
  147.                            integer_zero_node));
  148.       expand_decl (in_charge_node);
  149.       expand_decl_init (in_charge_node);
  150.     }
  151.  
  152.   start = ! TYPE_USES_VIRTUAL_BASECLASSES (t);
  153.   for (pass = start; pass < 2; pass++)
  154.     {
  155.       tree vbase_init_list = NULL_TREE;
  156.       for (init_list = current_base_init_list; init_list;
  157.        init_list = TREE_CHAIN (init_list))
  158.     {
  159.       tree basename = TREE_PURPOSE (init_list);
  160.       tree basetype;
  161.       tree init = TREE_VALUE (init_list);
  162.  
  163.       if (basename == NULL_TREE)
  164.         {
  165.           /* Initializer for single base class.  Must not
  166.          use multiple inheritance or this is ambiguous.  */
  167.           switch (n_baseclasses)
  168.         {
  169.         case 0:
  170.           error ("type `%s' does not have a base class to initialize",
  171.              IDENTIFIER_POINTER (current_class_name));
  172.           return;
  173.         case 1:
  174.           break;
  175.         default:
  176.           error ("unnamed initializer ambiguous for type `%s' which uses multiple inheritance", IDENTIFIER_POINTER (current_class_name));
  177.           return;
  178.         }
  179.           basetype = CLASSTYPE_BASECLASS (t, 1);
  180.         }
  181.       else if (is_aggr_typedef (basename, 1))
  182.         {
  183.           basetype = basetype_or_else (TREE_TYPE (TREE_TYPE (basename)), t);
  184.           if (basetype == NULL_TREE)
  185.         continue;
  186.  
  187.           /* Virtual base classes are special cases.  Their initializers
  188.          are recorded with this constructor, and they are used when
  189.          this constructor is the top-level constructor called.  */
  190.           if (! TREE_VIA_VIRTUAL (basetype))
  191.         {
  192.           /* Otherwise, if it is not an immediate base class, complain.  */
  193.           for (i = n_baseclasses; i > 0; i--)
  194.             if (basetype == CLASSTYPE_BASECLASS (t, i))
  195.               break;
  196.           if (i == 0)
  197.             {
  198.               error ("type `%s' is not an immediate base class of type `%s'",
  199.                  IDENTIFIER_POINTER (basename),
  200.                  IDENTIFIER_POINTER (current_class_name));
  201.               continue;
  202.             }
  203.         }
  204.         }
  205.       else
  206.         continue;
  207.  
  208.       /* The base initialization list goes up to the first
  209.          base class which can actually use it.  */
  210.  
  211.       if (CLASSTYPE_MARKED6 (basetype))
  212.         {
  213.           error ("class `%s' initializer already specified",
  214.              IDENTIFIER_POINTER (basename));
  215.           continue;
  216.         }
  217.  
  218.       if (pass == start)
  219.         {
  220.           char *msgp = (! TYPE_HAS_CONSTRUCTOR (basetype))
  221.         ? "cannot pass initialization up to class `%s'" : 0;
  222.  
  223.           while (! TYPE_HAS_CONSTRUCTOR (basetype)
  224.              && CLASSTYPE_N_BASECLASSES (basetype) == 1)
  225.         basetype = CLASSTYPE_BASECLASS (basetype, 1);
  226.  
  227.           if (basetype)
  228.         {
  229.           if (msgp)
  230.             if (pedantic)
  231.               {
  232.             error_with_aggr_type (basetype, msgp);
  233.             continue;
  234.               }
  235.             else if (! TYPE_HAS_CONSTRUCTOR (basetype))
  236.               {
  237.             if (CLASSTYPE_N_BASECLASSES (basetype) == 0)
  238.               error_with_aggr_type (basetype, msgp);
  239.             else
  240.               sorry ("passing initializations up multiple inheritance lattice");
  241.             continue;
  242.               }
  243.         }
  244.           else
  245.         {
  246.           error ("no constructor found for initialization of `%s'",
  247.              IDENTIFIER_POINTER (basename));
  248.           continue;
  249.         }
  250.  
  251.           if (TREE_VIA_VIRTUAL (basetype))
  252.         {
  253.           CLASSTYPE_MARKED6 (basetype) = 1;
  254.           vbase_init_list = tree_cons (init, basetype, vbase_init_list);
  255.         }
  256.           if (pass == 0)
  257.         continue;
  258.         }
  259.       else if (TREE_VIA_VIRTUAL (basetype))
  260.         continue;
  261.  
  262.       CLASSTYPE_MARKED6 (basetype) = 1;
  263.       member = convert_pointer_to (basetype, current_class_decl);
  264.       expand_aggr_init_1 (t, 0,
  265.                   build_indirect_ref (member, 0), init,
  266.                   ! DECL_OFFSET (TYPE_NAME (basetype)),
  267.                   LOOKUP_PROTECTED_OK|LOOKUP_COMPLAIN);
  268.       if (flag_handle_exceptions == 2 && TYPE_NEEDS_DESTRUCTOR (basetype))
  269.         {
  270.           cplus_expand_start_try (1);
  271.           push_exception_cleanup (member);
  272.         }
  273.     }
  274.  
  275.       if (pass == 0)
  276.     {
  277.       tree first_arg = TREE_CHAIN (DECL_ARGUMENTS (current_function_decl));
  278.       tree vbases;
  279.  
  280.       if (DECL_COMPILER_GENERATED_P (current_function_decl)
  281.           && TREE_CHAIN (first_arg) != NULL_TREE)
  282.         {
  283.           /* If there are virtual baseclasses without initialization
  284.          specified, and this is a default X(X&) construcotr,
  285.          build the initialization list so that each virtual baseclass
  286.          of the new object is initialized from the virtual baseclass
  287.          of the incoming arg.  */
  288.           tree init_arg = build_unary_op (ADDR_EXPR, TREE_CHAIN (first_arg), 0);
  289.           for (vbases = CLASSTYPE_VBASECLASSES (t);
  290.            vbases; vbases = TREE_CHAIN (vbases))
  291.         {
  292.           basetype = TREE_TYPE (vbases);
  293.           if (CLASSTYPE_MARKED6 (basetype) == 0)
  294.             {
  295.               member = convert_pointer_to (basetype, init_arg);
  296.               if (member == init_arg)
  297.             member = TREE_CHAIN (first_arg);
  298.               else
  299.             TREE_TYPE (member) = build_reference_type (basetype);
  300.               vbase_init_list = tree_cons (convert_from_reference (member),
  301.                            basetype, vbase_init_list);
  302.               CLASSTYPE_MARKED6 (basetype) = 1;
  303.             }
  304.         }
  305.         }
  306.       expand_start_cond (first_arg, 0);
  307.       expand_aggr_vbase_init (t, C_C_D, current_class_decl,
  308.                   vbase_init_list);
  309.       expand_expr_stmt (build_vbase_vtables_init (t, t, C_C_D,
  310.                               current_class_decl, 1));
  311.       expand_end_cond ();
  312.     }
  313.     }
  314.   current_base_init_list = NULL_TREE;
  315.  
  316.   /* Now, perform default initialization of all base classes which
  317.      have not yet been initialized, and unmark baseclasses which
  318.      have been initialized.  */
  319.   for (i = 1; i <= n_baseclasses; i++)
  320.     {
  321.       tree base = current_class_decl;
  322.  
  323.       basetype = CLASSTYPE_BASECLASS (t, i);
  324.       if (TYPE_NEEDS_CONSTRUCTING (basetype))
  325.     {
  326.       if (! TREE_VIA_VIRTUAL (basetype)
  327.           && ! CLASSTYPE_MARKED6 (basetype))
  328.         {
  329.           tree ref;
  330.  
  331.           if (CLASSTYPE_OFFSET (basetype) == integer_zero_node)
  332.         base = build1 (NOP_EXPR, TYPE_POINTER_TO (basetype), current_class_decl);
  333.           else
  334.         base = build (PLUS_EXPR, TYPE_POINTER_TO (basetype), current_class_decl, CLASSTYPE_OFFSET (basetype));
  335.  
  336.           ref = build_indirect_ref (base, 0);
  337.           expand_aggr_init_1 (t, 0, ref, NULL_TREE,
  338.                   ! DECL_OFFSET (TYPE_NAME (basetype)),
  339.                   LOOKUP_PROTECTED_OK|LOOKUP_COMPLAIN);
  340.           if (flag_handle_exceptions == 2 && TYPE_NEEDS_DESTRUCTOR (basetype))
  341.         {
  342.           cplus_expand_start_try (1);
  343.           push_exception_cleanup (base);
  344.         }
  345.         }
  346.     }
  347.       CLASSTYPE_MARKED6 (basetype) = 0;
  348.     }
  349.  
  350.   /* Initialize all the virtual function table fields that
  351.      do not come from virtual base classes.  */
  352.   vfields = CLASSTYPE_VFIELDS (t);
  353.   while (vfields)
  354.     {
  355.       /* If the vtable installed by the constructor was not
  356.      the right one, fix that here.  */
  357.       if (TREE_ADDRESSABLE (vfields)
  358.       && (TYPE_HAS_CONSTRUCTOR (TREE_TYPE (vfields))
  359.           /* BASE_INIT_LIST has already initialized these guys.  */
  360.           || ! value_member (TREE_VALUE (vfields), CLASSTYPE_ASSOC (t))))
  361.     {
  362.       tree basetype = TYPE_MAIN_VARIANT (TREE_TYPE (vfields));
  363.       tree assoc = assoc_value (basetype, t);
  364.       if (ASSOC_VTABLE (assoc) != CLASS_ASSOC_VTABLE (basetype))
  365.         {
  366.           tree ptr = convert_pointer_to (basetype, current_class_decl);
  367.           expand_expr_stmt (build_virtual_init (t, basetype, ptr));
  368.         }
  369.     }
  370.       vfields = TREE_CHAIN (vfields);
  371.     }
  372.  
  373.   if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (t)
  374. #ifdef SOS
  375.        || TYPE_DYNAMIC (t)
  376. #endif
  377.        )
  378.     expand_expr_stmt (build_virtual_init (t, t, current_class_decl));
  379.  
  380.   /* Members we through expand_member_init.  We initialize all the members
  381.      needing initialization that did not get it so far.  */
  382.   for (; current_member_init_list;
  383.        current_member_init_list = TREE_CHAIN (current_member_init_list))
  384.     {
  385.       tree name = TREE_PURPOSE (current_member_init_list);
  386.       tree init = TREE_VALUE (current_member_init_list);
  387.       tree field = (TREE_CODE (name) == COMPONENT_REF
  388.             ? TREE_OPERAND (name, 1) : IDENTIFIER_CLASS_VALUE (name));
  389.       tree type;
  390.       
  391.       /* If one member shadows another, get the outermost one.  */
  392.       if (TREE_CODE (field) == TREE_LIST)
  393.     {
  394.       field = TREE_VALUE (field);
  395.       if (decl_type_context (field) != current_class_type)
  396.         error ("field `%s' not in immediate context");
  397.     }
  398.  
  399.       type = TREE_TYPE (field);
  400.  
  401.       if (TREE_STATIC (field))
  402.     {
  403.       error_with_aggr_type (DECL_FIELD_CONTEXT (field),
  404.                 "field `%s::%s' is static; only point of initialization is its declaration", IDENTIFIER_POINTER (name));
  405.       continue;
  406.     }
  407.  
  408.       if (DECL_NAME (field))
  409.     {
  410.       if (TREE_HAS_CONSTRUCTOR (field))
  411.         error ("multiple initializations given for member `%s'",
  412.            IDENTIFIER_POINTER (DECL_NAME (field)));
  413.     }
  414.  
  415.       /* Mark this node as having been initialized.  */
  416.       TREE_HAS_CONSTRUCTOR (field) = 1;
  417.       if (DECL_FIELD_CONTEXT (field) != t)
  418.     fields_to_unmark = tree_cons (NULL_TREE, field, fields_to_unmark);
  419.  
  420.       if (TREE_CODE (name) == COMPONENT_REF)
  421.     {
  422.       /* Initialization of anonymous union.  */
  423.       expand_assignment (name, init, 0, 0);
  424.       continue;
  425.     }
  426.       decl = build_component_ref (C_C_D, name, 0, 1);
  427.  
  428.       if (TYPE_NEEDS_CONSTRUCTING (type))
  429.     {
  430.       if (TREE_CODE (type) == ARRAY_TYPE
  431.           && TREE_CHAIN (init) == NULL_TREE
  432.           && TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE)
  433.         {
  434.           /* Initialization of one array from another.  */
  435.           expand_vec_init (TREE_OPERAND (decl, 1), decl,
  436.                    array_type_nelts (type), TREE_VALUE (init), 1);
  437.         }
  438.       else
  439.         expand_aggr_init (decl, init, 0);
  440.     }
  441.       else
  442.     {
  443.       if (init == NULL_TREE)
  444.         {
  445.           error ("types without constructors must have complete initializers");
  446.           init = error_mark_node;
  447.         }
  448.       else if (TREE_CHAIN (init))
  449.         {
  450.           warning ("initializer list treated as compound expression");
  451.           init = build_compound_expr (init);
  452.         }
  453.       else
  454.         init = TREE_VALUE (init);
  455.  
  456.       expand_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
  457.     }
  458.       if (flag_handle_exceptions == 2 && TYPE_NEEDS_DESTRUCTOR (type))
  459.     {
  460.       cplus_expand_start_try (1);
  461.       push_exception_cleanup (build_unary_op (ADDR_EXPR, decl, 0));
  462.     }
  463.     }
  464.  
  465.   for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
  466.     {
  467.       /* All we care about is this unique member.  It contains
  468.      all the information we need to know, and that right early.  */
  469.       tree type = TREE_TYPE (member);
  470.       tree init = TREE_HAS_CONSTRUCTOR (member)
  471.     ? error_mark_node : DECL_INITIAL (member);
  472.  
  473.       /* Unmark this field.  If it is from an anonymous union,
  474.          then unmark the field recursively.  */
  475.       TREE_HAS_CONSTRUCTOR (member) = 0;
  476.       if (TREE_ANON_UNION_ELEM (member))
  477.     emit_base_init (TREE_TYPE (member), 1);
  478.  
  479.       /* Member had explicit initializer.  */
  480.       if (init == error_mark_node)
  481.     continue;
  482.  
  483.       if (TREE_CODE (member) != FIELD_DECL)
  484.     continue;
  485.  
  486.       if (type == error_mark_node)
  487.     continue;
  488.  
  489.       if (TYPE_NEEDS_CONSTRUCTING (type))
  490.     {
  491.       if (init)
  492.         init = build_tree_list (NULL_TREE, init);
  493.       decl = build_component_ref (C_C_D, DECL_NAME (member), 0, 0);
  494.       expand_aggr_init (decl, init, 0);
  495.     }
  496.       else
  497.     {
  498.       if (init)
  499.         {
  500.           decl = build_component_ref (C_C_D, DECL_NAME (member), 0, 0);
  501.           expand_expr_stmt (build_modify_expr (decl, INIT_EXPR, init));
  502.         }
  503.       else if (TREE_CODE (TREE_TYPE (member)) == REFERENCE_TYPE)
  504.         warning ("uninitialized reference member `%s'",
  505.              IDENTIFIER_POINTER (DECL_NAME (member)));
  506.     }
  507.       if (flag_handle_exceptions == 2 && TYPE_NEEDS_DESTRUCTOR (type))
  508.     {
  509.       cplus_expand_start_try (1);
  510.       push_exception_cleanup (build_unary_op (ADDR_EXPR, decl, 0));
  511.     }
  512.     }
  513.   /* Unmark fields which are initialized for the base class.  */
  514.   while (fields_to_unmark)
  515.     {
  516.       TREE_HAS_CONSTRUCTOR (TREE_VALUE (fields_to_unmark)) = 0;
  517.       fields_to_unmark = TREE_CHAIN (fields_to_unmark);
  518.     }
  519.  
  520.   /* It is possible for the initializers to need cleanups.
  521.      Expand those cleanups now that all the initialization
  522.      has been done.  */
  523.   expand_cleanups_to (NULL_TREE);
  524.  
  525.   if (! immediately)
  526.     {
  527.       extern struct rtx_def *base_init_insns;
  528.  
  529.       do_pending_stack_adjust ();
  530.       assert (base_init_insns == 0);
  531.       base_init_insns = get_insns ();
  532.       end_sequence ();
  533.     }
  534.  
  535.   /* All the implicit try blocks we built up will be zapped
  536.      when we come to a real binding contour boundary.  */
  537. }
  538.  
  539. /* Check that all fields are properly initialized after
  540.    an assignment to `this'.  */
  541. void
  542. check_base_init (t)
  543.      tree t;
  544. {
  545.   tree member;
  546.   for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
  547.     {
  548.       if (DECL_NAME (member) && TREE_USED (member))
  549.     error ("field `%s' used before initialized (after assignment to `this')",
  550.            IDENTIFIER_POINTER (DECL_NAME (member)));
  551.     }
  552. }
  553.  
  554. /* This code sets up the virtual function tables appropriate for
  555.    the pointer DECL.  It is a one-ply initialization.
  556.  
  557.    TYPE is the exact type that DECL is supposed to be.  In
  558.    muliple inheritance, this might mean "C's A" if C : A, B.  */
  559. tree
  560. build_virtual_init (for_type, type, decl)
  561.      tree for_type, type;
  562.      tree decl;
  563. {
  564.   tree vtbl, vtbl_ptr;
  565.   tree vtype;
  566.  
  567. #ifdef SOS
  568.   if (TYPE_DYNAMIC (type))
  569.     vtbl = build1 (NOP_EXPR, ptr_type_node, lookup_name (get_identifier (AUTO_VTABLE_NAME)));
  570.   else
  571. #endif
  572.     {
  573. #if 1
  574.       vtbl = ASSOC_VTABLE (assoc_value (DECL_FIELD_CONTEXT (CLASSTYPE_VFIELD (type)),
  575.                     for_type));
  576. #else
  577.       assert (for_type == type);
  578.       vtbl = CLASS_ASSOC_VTABLE (for_type);
  579. #endif /* 1 */
  580.       TREE_USED (vtbl) = 1;
  581.       vtbl = build1 (ADDR_EXPR, TYPE_POINTER_TO (TREE_TYPE (vtbl)), vtbl);
  582.     }
  583.   vtype = DECL_CONTEXT (CLASSTYPE_VFIELD (type));
  584.   decl = convert_pointer_to (vtype, decl);
  585.   vtbl_ptr = build_vfield_ref (build_indirect_ref (decl, 0), vtype);
  586.  
  587.   /* Have to convert VTBL since array sizes may be different.  */
  588.   return build_modify_expr (vtbl_ptr, NOP_EXPR,
  589.                 convert (TREE_TYPE (vtbl_ptr), vtbl));
  590. }
  591.  
  592. /* Subroutine of `expand_aggr_vbase_init'.
  593.    BASETYPE is type that is being initialized.  INIT_LIST
  594.    is the list of initializers for the virtual baseclass.  */
  595. static void
  596. expand_aggr_vbase_init_1 (basetype, exp, addr, init_list)
  597.      tree basetype, init_list;
  598. {
  599.   tree init = value_member (basetype, init_list);
  600.   tree ref = build_indirect_ref (addr, 0);
  601.   if (init)
  602.     init = TREE_PURPOSE (init);
  603.   /* Call constructors, but don't set up vtables.  */
  604.   expand_aggr_init_1 (basetype, exp, ref, init, 0,
  605.               LOOKUP_PROTECTED_OK|LOOKUP_COMPLAIN|LOOKUP_SPECULATIVELY);
  606.   CLASSTYPE_MARKED6 (basetype) = 0;
  607. }
  608.  
  609. /* Initialize this object's virtual base class pointers.  This must be
  610.    done only at the top-level of the object being constructed.
  611.  
  612.    INIT_LIST is list of initialization for constructor to perform.  */
  613. static void
  614. expand_aggr_vbase_init (type, exp, addr, init_list)
  615.      tree type;
  616.      tree exp;
  617.      tree addr;
  618.      tree init_list;
  619. {
  620.   if (TYPE_USES_VIRTUAL_BASECLASSES (type))
  621.     {
  622.       tree result = init_vbase_pointers (type, addr);
  623.       tree basetype, vbases;
  624.  
  625.       if (result)
  626.     expand_expr_stmt (build_compound_expr (result));
  627.  
  628.       /* Mark everything as having an initializer
  629.      (either explicit or default).  */
  630.       for (vbases = CLASSTYPE_VBASECLASSES (type);
  631.        vbases; vbases = TREE_CHAIN (vbases))
  632.     CLASSTYPE_MARKED6 (TREE_TYPE (vbases)) = 1;
  633.  
  634.       /* First, initialize baseclasses which could be baseclasses
  635.      for other virtual baseclasses.  */
  636.       for (vbases = CLASSTYPE_VBASECLASSES (type);
  637.        vbases; vbases = TREE_CHAIN (vbases))
  638.     /* Don't initialize twice.  */
  639.     if (CLASSTYPE_MARKED6 (TREE_TYPE (vbases)))
  640.       {
  641.         tree assoc = purpose_member (TREE_TYPE (vbases), result);
  642.         assert (assoc != NULL_TREE);
  643.         expand_aggr_vbase_init_1 (TREE_PURPOSE (assoc), exp,
  644.                       TREE_OPERAND (TREE_VALUE (assoc), 0),
  645.                       init_list);
  646.       }
  647.  
  648.       /* Now initialize the baseclasses which don't have virtual baseclasses.  */
  649.       for (; result; result = TREE_CHAIN (result))
  650.     /* Don't initialize twice.  */
  651.     if (CLASSTYPE_MARKED6 (TREE_PURPOSE (result)))
  652.       {
  653.         abort ();
  654.         expand_aggr_vbase_init_1 (TREE_PURPOSE (result), exp,
  655.                       TREE_OPERAND (TREE_VALUE (result), 0),
  656.                       init_list);
  657.       }
  658.     }
  659. }
  660.  
  661. /* Function to give error message if member initialization specification
  662.    is erroneous.  FIELD is the member we decided to initialize.
  663.    TYPE is the type for which the initialization is being performed.
  664.    FIELD must be a member of TYPE, or the base type from which FIELD
  665.    comes must not need a constructor.
  666.    
  667.    MEMBER_NAME is the name of the member.  */
  668.  
  669. static int
  670. member_init_ok_or_else (field, type, member_name)
  671.      tree field;
  672.      tree type;
  673.      char *member_name;
  674. {
  675.   if (field == error_mark_node) return 0;
  676.   if (field == NULL_TREE)
  677.     {
  678.       error_with_aggr_type (type, "class `%s' does not have any field named `%s'",
  679.                 member_name);
  680.       return 0;
  681.     }
  682.   if (DECL_CONTEXT (field) != type
  683.       && TYPE_NEEDS_CONSTRUCTOR (DECL_CONTEXT (field)))
  684.     {
  685.       error ("member `%s' comes from base class needing constructor", member_name);
  686.       return 0;
  687.     }
  688.   return 1;
  689. }
  690.  
  691. /* If NAME is a viable field name for the aggregate DECL,
  692.    and PARMS is a viable parameter list, then expand an _EXPR
  693.    which describes this initialization.
  694.  
  695.    Note that we do not need to chase through the class's base classes
  696.    to look for NAME, because if it's in that list, it will be handled
  697.    by the constructor for that base class.
  698.  
  699.    We do not yet have a fixed-point finder to instantiate types
  700.    being fed to overloaded constructors.  If there is a unique
  701.    constructor, then argument types can be got from that one.
  702.  
  703.    If INIT is non-NULL, then it the initialization should
  704.    be placed in `current_base_init_list', where it will be processed
  705.    by `emit_base_init'.  */
  706. void
  707. expand_member_init (exp, name, init)
  708.      tree exp, name, init;
  709. {
  710.   extern tree ptr_type_node;    /* should be in tree.h */
  711.  
  712.   tree basetype = NULL_TREE, field;
  713.   tree parm;
  714.   tree rval, type;
  715.   tree actual_name;
  716.  
  717.   if (exp == NULL_TREE)
  718.     return;            /* complain about this later */
  719.  
  720.   type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
  721.  
  722.   if (name == NULL_TREE && IS_AGGR_TYPE (type))
  723.     switch (CLASSTYPE_N_BASECLASSES (type))
  724.       {
  725.       case 0:
  726.     error ("base class initializer specified, but no base class to initialize");
  727.     return;
  728.       case 1:
  729.     basetype = CLASSTYPE_BASECLASS (type, 1);
  730.     break;
  731.       default:
  732.     error ("initializer for unnamed base class ambiguous");
  733.     error_with_aggr_type (type, "(type `%s' uses multiple inheritance)");
  734.     return;
  735.       }
  736.  
  737.   if (init)
  738.     {
  739.       /* The grammar should not allow fields which have names
  740.      that are TYPENAMEs.  Therefore, if the field has
  741.      a non-NULL TREE_TYPE, we may assume that this is an
  742.      attempt to initialize a base class member of the current
  743.      type.  Otherwise, it is an attempt to initialize a
  744.      member field.  */
  745.  
  746.       if (init == void_type_node)
  747.     init = NULL_TREE;
  748.  
  749.       if (name == NULL_TREE || TREE_TYPE (name))
  750.     {
  751.       tree base_init;
  752.  
  753.       if (name == NULL_TREE)
  754.         if (basetype)
  755.           name = DECL_NAME (TYPE_NAME (basetype));
  756.         else
  757.           {
  758.         error ("no base class to initialize");
  759.         return;
  760.           }
  761.       else
  762.         {
  763.           basetype = TREE_TYPE (TREE_TYPE (name));
  764.           if (basetype != type
  765.           && ! value_member (basetype, TYPE_BASETYPES (type))
  766.           && ! value_member (basetype, CLASSTYPE_VBASECLASSES (type)))
  767.         {
  768.           if (IDENTIFIER_CLASS_VALUE (name))
  769.             goto try_member;
  770.           if (TYPE_USES_VIRTUAL_BASECLASSES (type))
  771.             error ("type `%s' is not an immediate or virtual basetype for `%s'",
  772.                IDENTIFIER_POINTER (name),
  773.                TYPE_NAME_STRING (type));
  774.           else
  775.             error ("type `%s' is not an immediate basetype for `%s'",
  776.                IDENTIFIER_POINTER (name),
  777.                TYPE_NAME_STRING (type));
  778.           return;
  779.         }
  780.         }
  781.  
  782.       if (purpose_member (name, current_base_init_list))
  783.         {
  784.           error ("base class `%s' already initialized",
  785.              IDENTIFIER_POINTER (name));
  786.           return;
  787.         }
  788.  
  789.       base_init = build_tree_list (name, init);
  790.       TREE_TYPE (base_init) = basetype;
  791.       current_base_init_list = chainon (current_base_init_list, base_init);
  792.     }
  793.       else
  794.     {
  795.       tree member_init;
  796.  
  797.     try_member:
  798.       field = lookup_field (type, name, 1);
  799.  
  800.       if (! member_init_ok_or_else (field, type, IDENTIFIER_POINTER (name)))
  801.         return;
  802.  
  803.       if (purpose_member (name, current_member_init_list))
  804.         {
  805.           error ("field `%s' already initialized", IDENTIFIER_POINTER (name));
  806.           return;
  807.         }
  808.  
  809.       member_init = build_tree_list (name, init);
  810.       TREE_TYPE (member_init) = TREE_TYPE (field);
  811.       current_member_init_list = chainon (current_member_init_list, member_init);
  812.     }
  813.       return;
  814.     }
  815.   else if (name == NULL_TREE)
  816.     {
  817.       compiler_error ("expand_member_init: name == NULL_TREE");
  818.       return;
  819.     }
  820.  
  821.   basetype = type;
  822.   field = lookup_field (basetype, name, 0);
  823.  
  824.   if (! member_init_ok_or_else (field, basetype, IDENTIFIER_POINTER (name)))
  825.     return;
  826.  
  827.   /* now see if there is a constructor for this type
  828.      which will take these args. */
  829.  
  830.   if (TYPE_HAS_CONSTRUCTOR (TREE_TYPE (field)))
  831.     {
  832.       tree parmtypes, fndecl;
  833.  
  834.       if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL)
  835.     {
  836.       /* just know that we've seen something for this node */
  837.       DECL_INITIAL (exp) = error_mark_node;
  838.       TREE_USED (exp) = 1;
  839.     }
  840.       type = TYPE_MAIN_VARIANT (TREE_TYPE (field));
  841.       actual_name = DECL_NAME (TYPE_NAME (type));
  842.       parm = build_component_ref (exp, name, 0, 0);
  843.  
  844.       /* Now get to the constructor.  */
  845.       field = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0);
  846.       /* Get past destructor, if any.  */
  847.       if (TYPE_HAS_DESTRUCTOR (type))
  848.     field = TREE_CHAIN (field);
  849.  
  850.       /* If the field is unique, we can use the parameter
  851.      types to guide possible type instantiation.  */
  852.       if (TREE_CHAIN (field) == NULL_TREE)
  853.     {
  854.       fndecl = TREE_TYPE (field);
  855.       parmtypes = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
  856.     }
  857.       else
  858.     {
  859.       parmtypes = NULL_TREE;
  860.       fndecl = NULL_TREE;
  861.     }
  862.  
  863.       init = actualparameterlist (parm, parmtypes, NULL_TREE, fndecl, LOOKUP_NORMAL);
  864.       if (init == NULL_TREE || TREE_TYPE (init) != error_mark_node)
  865.     rval = build_method_call (NULL_TREE, actual_name, init, NULL_TREE, LOOKUP_NORMAL);
  866.       else
  867.     return;
  868.  
  869.       if (rval != error_mark_node)
  870.     {
  871.       /* Now, fill in the first parm with our guy */
  872.       TREE_VALUE (TREE_OPERAND (rval, 1))
  873.         = build_unary_op (ADDR_EXPR, parm, 0);
  874.       TREE_TYPE (rval) = ptr_type_node;
  875.       TREE_VOLATILE (rval) = 1;
  876.     }
  877.     }
  878.   else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field)))
  879.     {
  880.       parm = build_component_ref (exp, name, 0, 0);
  881.       expand_aggr_init (parm, NULL_TREE, 0);
  882.       rval = error_mark_node;
  883.     }
  884.  
  885.   /* Now initialize the member.  It does not have to
  886.      be of aggregate type to receive initialization.  */
  887.   if (rval != error_mark_node)
  888.     expand_expr_stmt (rval);
  889. }
  890.  
  891. /* This is like `expand_member_init', only it stores one aggregate
  892.    value into another.
  893.  
  894.    INIT comes in two flavors: it is either a value which
  895.    is to be stored in EXP, or it is a parameter list
  896.    to go to a constructor, which will operate on EXP.
  897.    If `init' is a CONSTRUCTOR, then we emit a warning message,
  898.    explaining that such initializaitions are illegal.
  899.  
  900.    ALIAS_THIS is nonzero iff we are initializing something which is
  901.    essentially an alias for C_C_D.  In this case, the base constructor
  902.    may move it on us, and we must keep track of such deviations.
  903.  
  904.    If INIT resolves to a CALL_EXPR which happens to return
  905.    something of the type we are looking for, then we know
  906.    that we can safely use that call to perform the
  907.    initialization.
  908.  
  909.    The virtual function table pointer cannot be set up here, because
  910.    we do not really know its type.
  911.  
  912.    Virtual baseclass pointers are also set up here.
  913.  
  914.    This never calls operator=().
  915.  
  916.    When initializing, nothing is CONST.  */
  917.  
  918. void
  919. expand_aggr_init (exp, init, alias_this)
  920.      tree exp, init;
  921.      int alias_this;
  922. {
  923.   tree type = TREE_TYPE (exp);
  924.   tree addr;
  925.   int was_const = TREE_READONLY (exp);
  926.  
  927.   if (init == error_mark_node)
  928.     return;
  929.  
  930.   TREE_READONLY (exp) = 0;
  931.  
  932.   if (TREE_CODE (type) == ARRAY_TYPE)
  933.     {
  934.       /* Must arrange to initialize each element of EXP
  935.      from elements of INIT.  */
  936.       int was_const_elts = TREE_READONLY (TREE_TYPE (type));
  937.       tree itype = init ? TREE_TYPE (init) : NULL_TREE;
  938.       if (was_const_elts)
  939.     {
  940.       tree atype = build_cplus_array_type (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  941.                            TYPE_DOMAIN (type));
  942.       if (TREE_TYPE (exp) == TREE_TYPE (init))
  943.         TREE_TYPE (init) = atype;
  944.       TREE_TYPE (exp) = atype;
  945.     }
  946.       expand_vec_init (exp, exp, array_type_nelts (type), init,
  947.                init && TREE_TYPE (init) == TREE_TYPE (exp));
  948.       TREE_READONLY (exp) = was_const;
  949.       TREE_TYPE (exp) = type;
  950.       if (init) TREE_TYPE (init) = itype;
  951.       return;
  952.     }
  953.  
  954.   if (TREE_CODE (exp) == VAR_DECL || TREE_CODE (exp) == PARM_DECL)
  955.     /* just know that we've seen something for this node */
  956.     TREE_USED (exp) = 1;
  957.  
  958.   /* If initializing from a GNU C CONSTRUCTOR, consider the elts in the
  959.      constructor as parameters to an implicit GNU C++ constructor.  */
  960.   if (init && TREE_CODE (init) == CONSTRUCTOR
  961.       && TYPE_HAS_CONSTRUCTOR (type)
  962.       && TREE_TYPE (init) == type)
  963.     init = CONSTRUCTOR_ELTS (init);
  964.   expand_aggr_init_1 (type, exp, exp, init, alias_this, LOOKUP_NORMAL);
  965.   TREE_READONLY (exp) = was_const;
  966. }
  967.  
  968. /* This function is responsible for initializing EXP with INIT
  969.    (if any).
  970.  
  971.    FOR_TYPE is the type for who we are performing the initialization.
  972.    For example, if W is a virtual base class of A and B, and C : A, B
  973.    if we are initializing B, then W must contain B's W vtable, whereas
  974.    were we initializing C, W must contain C's W vtable.
  975.  
  976.    TRUE_EXP is nonzero if it is the true expression being initialized.
  977.    In this case, it may be EXP, or may just contain EXP.  The reason we
  978.    need this is because if EXP is a base element of TRUE_EXP, we
  979.    don't necessarily know by looking at EXP where its virtual
  980.    baseclass fields should really be pointing.  But we do know
  981.    from TRUE_EXP.  In constructors, we don't know anything about
  982.    the value being initialized.
  983.  
  984.    ALIAS_THIS serves the same purpose it serves for expand_aggr_init.
  985.  
  986.    FLAGS is just passes to `build_method_call'.  See that function for
  987.    its description.  */
  988.  
  989. static void
  990. expand_aggr_init_1 (for_type, true_exp, exp, init, alias_this, flags)
  991.      tree for_type;
  992.      tree true_exp, exp;
  993.      tree init;
  994.      int alias_this;
  995.      int flags;
  996. {
  997.   tree type = TREE_TYPE (exp);
  998.   tree init_type = NULL_TREE;
  999.   tree rval;
  1000.  
  1001.   assert (init != error_mark_node && type != error_mark_node);
  1002.  
  1003.   /* Use a function returning the desired type to initialize EXP for us.
  1004.      If the function is a constructor, and its first argument is
  1005.      NULL_TREE, know that it was meant for us--just slide exp on
  1006.      in and expand the constructor.  Constructors now come
  1007.      as NEW_EXPRs.  */
  1008.   if (init)
  1009.     {
  1010.       tree init_list = NULL_TREE;
  1011.  
  1012.       if (TREE_CODE (init) == TREE_LIST)
  1013.     {
  1014.       init_list = init;
  1015.       if (TREE_CHAIN (init) == NULL_TREE)
  1016.         init = TREE_VALUE (init);
  1017.     }
  1018.  
  1019.       init_type = TREE_TYPE (init);
  1020.  
  1021.       if (TREE_CODE (init) != TREE_LIST)
  1022.     {
  1023.       if (TREE_CODE (init_type) == ERROR_MARK)
  1024.         return;
  1025.  
  1026. #if 0
  1027.       /* These lines are found troublesome 5/11/89.  */
  1028.       if (TREE_CODE (init_type) == REFERENCE_TYPE)
  1029.         init_type = TREE_TYPE (init_type);
  1030. #endif
  1031.  
  1032.       /* This happens when we use C++'s functional cast notation.
  1033.          If the types match, then just use the NEW_EXPR
  1034.          directly.  Otherwise, we need to create the initializer
  1035.          separately from the object being initialized.  */
  1036.       if (TREE_CODE (init) == NEW_EXPR)
  1037.         {
  1038.           if (init_type == type)
  1039.         {
  1040.           if (TREE_CODE (exp) == VAR_DECL
  1041.               || TREE_CODE (exp) == RESULT_DECL)
  1042.             {
  1043.               /* Unify the initialization target.  */
  1044.               DECL_RTL (TREE_OPERAND (init, 0)) = DECL_RTL (exp);
  1045.             }
  1046.           else
  1047.             DECL_RTL (TREE_OPERAND (init, 0))
  1048.               = (struct rtx_def *)expand_expr (exp, 0, 0, 0);
  1049.           expand_expr_stmt (init);
  1050.           return;
  1051.         }
  1052.           else
  1053.         {
  1054.           init = TREE_OPERAND (init, 1);
  1055.           init = build (CALL_EXPR, init_type,
  1056.                 TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), 0);
  1057.           TREE_VOLATILE (init) = 1;
  1058. #if 0
  1059.           TREE_RAISES (init) = ??
  1060. #endif
  1061.             if (init_list)
  1062.               TREE_VALUE (init_list) = init;
  1063.         }
  1064.         }
  1065.  
  1066.       if (init_type == type && TREE_CODE (init) == CALL_EXPR
  1067. #if 0
  1068.           /* It is legal to directly initialize from a CALL_EXPR
  1069.          without going through X(X&), apparently.  */
  1070.           && ! TYPE_GETS_INIT_REF (type)
  1071. #endif
  1072.           )
  1073.         {
  1074.           /* A CALL_EXPR is a legitmate form of initialization, so
  1075.          we should not print this warning message.  */
  1076. #if 0
  1077.           /* Should have gone away due to 5/11/89 change.  */
  1078.           if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
  1079.         init = convert_from_reference (init);
  1080. #endif
  1081.           expand_assignment (exp, init, 0, 0);
  1082.           if (exp == DECL_RESULT (current_function_decl))
  1083.         {
  1084.           /* Failing this assertion means that the return value
  1085.              from receives multiple initializations.  */
  1086.           assert (DECL_INITIAL (exp) == NULL_TREE || DECL_INITIAL (exp) == error_mark_node);
  1087.           DECL_INITIAL (exp) = init;
  1088.         }
  1089.           return;
  1090.         }
  1091.       else if (init_type == type
  1092.            && TREE_CODE (init) == COND_EXPR)
  1093.         {
  1094.           /* Push value to be initialized into the cond, where possible.
  1095.              Avoid spurious warning messages when initializing the
  1096.          result of this function.  */
  1097.           TREE_OPERAND (init, 1)
  1098.         = build_modify_expr (exp, INIT_EXPR, TREE_OPERAND (init, 1));
  1099.           if (exp == DECL_RESULT (current_function_decl))
  1100.         DECL_INITIAL (exp) = NULL_TREE;
  1101.           TREE_OPERAND (init, 2)
  1102.         = build_modify_expr (exp, INIT_EXPR, TREE_OPERAND (init, 2));
  1103.           if (exp == DECL_RESULT (current_function_decl))
  1104.         DECL_INITIAL (exp) = init;
  1105.           expand_expr (init, const0_rtx, VOIDmode, 0);
  1106.           return;
  1107.         }
  1108.     }
  1109.  
  1110.       /* We did not know what we were initializing before.  Now we do.  */
  1111.       if (TREE_CODE (init) == NEW_EXPR)
  1112.     {
  1113.       tree tmp = TREE_OPERAND (TREE_OPERAND (init, 1), 1);
  1114.  
  1115.       assert (tmp != NULL_TREE);
  1116.  
  1117.       if (TREE_CODE (TREE_VALUE (tmp)) == NOP_EXPR
  1118.           && TREE_OPERAND (TREE_VALUE (tmp), 0) == integer_zero_node)
  1119.         {
  1120.           /* In order for this to work for RESULT_DECLs, if their
  1121.          type has a constructor, then they must be BLKmode
  1122.          so that they will be meaningfully addressable.  */
  1123.           tree arg = build_unary_op (ADDR_EXPR, exp, 0);
  1124.           init = TREE_OPERAND (init, 1);
  1125.           init = build (CALL_EXPR, build_pointer_type (TREE_TYPE (init)),
  1126.                 TREE_OPERAND (init, 0), TREE_OPERAND (init, 1), 0);
  1127.           TREE_VOLATILE (init) = 1;
  1128. #if 0
  1129.           TREE_RAISES (init) = ??
  1130. #endif
  1131.           TREE_VALUE (TREE_OPERAND (init, 1))
  1132.         = convert_pointer_to (TREE_TYPE (TREE_TYPE (TREE_VALUE (tmp))), arg);
  1133.  
  1134.           if (alias_this)
  1135.         {
  1136.           expand_assignment (current_function_decl, init, 0, 0);
  1137.           return;
  1138.         }
  1139.           if (exp == DECL_RESULT (current_function_decl))
  1140.         {
  1141.           if (DECL_INITIAL (DECL_RESULT (current_function_decl)))
  1142.             fatal ("return value from function receives multiple initializations");
  1143.           DECL_INITIAL (exp) = init;
  1144.         }
  1145.           expand_expr_stmt (init);
  1146.           return;
  1147.         }
  1148.     }
  1149.  
  1150.       /* Handle this case: when calling a constructor: xyzzy foo(bar);
  1151.      which really means:  xyzzy foo = bar; Ugh!
  1152.  
  1153.      We can also be called with an initializer for an object
  1154.      which has virtual functions, but no constructors.  In that
  1155.      case, we perform the assignment first, then initialize
  1156.      the virtual function table pointer fields.  */
  1157.  
  1158.       if (! TYPE_NEEDS_CONSTRUCTING (type))
  1159.     {
  1160.       if (init_list && TREE_CHAIN (init_list))
  1161.         {
  1162.           warning ("initializer list being treated as compound expression");
  1163.           init = convert (TREE_TYPE (exp), build_compound_expr (init_list));
  1164.           if (init == error_mark_node)
  1165.         return;
  1166.         }
  1167.       if (TREE_CODE (exp) == VAR_DECL
  1168.           && TREE_CODE (init) == CONSTRUCTOR
  1169.           && TREE_HAS_CONSTRUCTOR (init))
  1170.         store_init_value (exp, init);
  1171.       else
  1172.         expand_assignment (exp, init, 0, 0);
  1173.  
  1174.       if (TYPE_VIRTUAL_P (type))
  1175.         expand_recursive_init (for_type, true_exp, exp, init, CLASSTYPE_BASE_INIT_LIST (type), alias_this);
  1176.       return;
  1177.     }
  1178.  
  1179.       /* See whether we can go through a type conversion operator.
  1180.      This wins over going through a constructor because we may be
  1181.      able to avoid an X(X&) constructor.  */
  1182.       if (TREE_CODE (init) != TREE_LIST)
  1183.     {
  1184.       tree ttype = TREE_CODE (init_type) == REFERENCE_TYPE
  1185.         ? TREE_TYPE (init_type) : init_type;
  1186.  
  1187.       if (ttype != type && IS_AGGR_TYPE (ttype))
  1188.         {
  1189.           tree rval = build_type_conversion (CONVERT_EXPR, type, init, 0);
  1190.  
  1191.           if (rval)
  1192.         {
  1193.           expand_assignment (exp, rval, 0, 0);
  1194.           return;
  1195.         }
  1196.         }
  1197.     }
  1198.     }
  1199.  
  1200.   if (TYPE_HAS_CONSTRUCTOR (type))
  1201.     {
  1202.       /* It fails because there may not be a constructor which takes
  1203.      its own type as the first (or only parameter), but which does
  1204.      take other types via a conversion.  So, if the thing initializing
  1205.      the expression is a unit element of type X, first try X(X&),
  1206.      followed by initialization by X.  If neither of these work
  1207.      out, then look hard.  */
  1208.       tree parms = (init == NULL_TREE || TREE_CODE (init) == TREE_LIST)
  1209.     ? init : build_tree_list (NULL_TREE, init);
  1210.       int xxref_init_possible;
  1211.  
  1212.       if (parms) init = TREE_VALUE (parms);
  1213.  
  1214.       if (TYPE_HAS_INIT_REF (type)
  1215.       || init == NULL_TREE
  1216.       || TREE_CHAIN (parms) != NULL_TREE)
  1217.     xxref_init_possible = 0;
  1218.       else
  1219.     {
  1220.       xxref_init_possible = LOOKUP_SPECULATIVELY;
  1221.       flags &= ~LOOKUP_COMPLAIN;
  1222.     }
  1223.  
  1224.       if (TYPE_USES_VIRTUAL_BASECLASSES (type))
  1225.     {
  1226.       assert (TYPE_USES_VIRTUAL_BASECLASSES (for_type));
  1227.       if (true_exp == exp)
  1228.         parms = tree_cons (NULL_TREE, integer_one_node, parms);
  1229.       else
  1230.         parms = tree_cons (NULL_TREE, integer_zero_node, parms);
  1231.       flags |= LOOKUP_HAS_IN_CHARGE;
  1232.     }
  1233.       rval = build_method_call (exp, DECL_NAME (TYPE_NAME (type)), parms,
  1234.                 CLASSTYPE_AS_LIST (for_type), flags|xxref_init_possible);
  1235.       if (rval == NULL_TREE && xxref_init_possible)
  1236.     {
  1237.       tree init_type = TREE_TYPE (init);
  1238.       if (TREE_CODE (init_type) == REFERENCE_TYPE)
  1239.         init_type = TREE_TYPE (init_type);
  1240.       if (TYPE_MAIN_VARIANT (init_type) == TYPE_MAIN_VARIANT (type)
  1241.           || (IS_AGGR_TYPE (init_type)
  1242.           && get_base_type (type, init_type, 0)))
  1243.         {
  1244.           if (type == for_type
  1245.           && TYPE_USES_VIRTUAL_BASECLASSES (type))
  1246.         {
  1247.           tree addr = build_unary_op (ADDR_EXPR, exp, 0);
  1248.           expand_aggr_vbase_init (type, exp, addr, NULL_TREE);
  1249.  
  1250.           expand_expr_stmt (build_vbase_vtables_init (type, type, exp, addr, 1));
  1251.         }
  1252.           expand_expr_stmt (build_modify_expr (exp, INIT_EXPR, init));
  1253.           return;
  1254.         }
  1255.       else
  1256.         rval = build_method_call (exp, DECL_NAME (TYPE_NAME (type)), parms,
  1257.                       CLASSTYPE_AS_LIST (for_type), flags);
  1258.     }
  1259.  
  1260.       /* Private, protected, or otherwise unavailable.  */
  1261.       if (rval == error_mark_node && (flags&LOOKUP_COMPLAIN))
  1262.     error_with_aggr_type (for_type, "in base initialization for class `%s'");
  1263.       /* A valid initialization using constructor.  */
  1264.       else if (rval != error_mark_node && rval != NULL_TREE)
  1265.     {
  1266.       /* p. 222: if the base class assigns to `this', then that
  1267.          value is used in the derived class.  */
  1268.       if ((flag_this_is_variable & 1) && alias_this)
  1269.         {
  1270.           TREE_TYPE (rval) = TREE_TYPE (current_class_decl);
  1271.           expand_assignment (current_class_decl, rval, 0, 0);
  1272.         }
  1273.       else
  1274.         expand_expr_stmt (rval);
  1275.     }
  1276.       else if (parms && TREE_CHAIN (parms) == NULL_TREE)
  1277.     {
  1278.       /* If we are initializing one aggregate value
  1279.          from another, and though there are constructors,
  1280.          and none accept the initializer, just do a bitwise
  1281.          copy.
  1282.          
  1283.          @@ This should reject initializer which a constructor
  1284.          @@ rejected on visibility gounds, but there is
  1285.          @@ no way right now to recognize that case with
  1286.          @@ just `error_mark_node'.  */
  1287.       tree itype;
  1288.       init = TREE_VALUE (parms);
  1289.       itype = TREE_TYPE (init);
  1290.       if (TREE_CODE (itype) == REFERENCE_TYPE)
  1291.         {
  1292.           init = convert_from_reference (init);
  1293.           itype = TREE_TYPE (init);
  1294.         }
  1295.       itype = TYPE_MAIN_VARIANT (itype);
  1296.       if (comptypes (TYPE_MAIN_VARIANT (type), itype, 0))
  1297.         {
  1298.           warning ("bitwise copy in initialization of type `%s'",
  1299.                TYPE_NAME_STRING (type));
  1300.           rval = build (INIT_EXPR, type, exp, init);
  1301.           expand_expr_stmt (rval);
  1302.         }
  1303.       else
  1304.         {
  1305.           error_with_aggr_type (for_type, "in base initialization for class `%s',");
  1306.           error_with_aggr_type (type, "invalid initializer to constructor for type `%s'");
  1307.           return;
  1308.         }
  1309.     }
  1310.       else
  1311.     {
  1312.       if (init == NULL_TREE)
  1313.         assert (parms == NULL_TREE);
  1314.       if (parms == NULL_TREE && TREE_VIA_VIRTUAL (for_type))
  1315.         error_with_aggr_type (for_type, "virtual baseclass `%s' does not have default initializer");
  1316.       else
  1317.         {
  1318.           error_with_aggr_type (for_type, "in base initialization for class `%s',");
  1319.           /* This will make an error message for us.  */
  1320.           build_method_call (exp, DECL_NAME (TYPE_NAME (type)), parms,
  1321.                  CLASSTYPE_AS_LIST (for_type),
  1322.                  (TYPE_USES_VIRTUAL_BASECLASSES (type)
  1323.                   ? LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE
  1324.                   : LOOKUP_NORMAL));
  1325.         }
  1326.       return;
  1327.     }
  1328.       /* Constructor has been called, but vtables may be for TYPE
  1329.      rather than for FOR_TYPE.  */
  1330.     }
  1331.   else if (TREE_CODE (type) == ARRAY_TYPE)
  1332.     {
  1333.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (type)))
  1334.     expand_vec_init (exp, exp, array_type_nelts (type), init, 0);
  1335.       else if (TYPE_VIRTUAL_P (TREE_TYPE (type)))
  1336.     sorry ("arrays of objects with virtual functions but no constructors");
  1337.     }
  1338.   else
  1339.     expand_recursive_init (for_type, true_exp, exp, init, CLASSTYPE_BASE_INIT_LIST (type), alias_this);
  1340. }
  1341.  
  1342. /* A pointer which holds the initializer.  First call to
  1343.    expand_aggr_init gets this value pointed to, and sets it to init_null.  */
  1344. static tree *init_ptr, init_null;
  1345.  
  1346. /* Subroutine of expand_recursive_init:
  1347.  
  1348.    ADDR is the address of the expression being initialized.
  1349.    INIT_LIST is the cons-list of initializations to be performed.
  1350.    ALIAS_THIS is its same, lovable self.  */
  1351. static void
  1352. expand_recursive_init_1 (for_type, true_exp, addr, init_list, alias_this)
  1353.      tree for_type, true_exp, addr;
  1354.      tree init_list;
  1355.      int alias_this;
  1356. {
  1357.   while (init_list)
  1358.     {
  1359.       if (TREE_PURPOSE (init_list))
  1360.     {
  1361.       if (TREE_CODE (TREE_PURPOSE (init_list)) == FIELD_DECL)
  1362.         {
  1363.           tree member = TREE_PURPOSE (init_list);
  1364.           tree subexp = build_indirect_ref (convert_pointer_to (TREE_VALUE (init_list), addr), 0);
  1365.           tree member_base = build (COMPONENT_REF, TREE_TYPE (member), subexp, member);
  1366.           if (IS_AGGR_TYPE (TREE_TYPE (member)))
  1367.         expand_aggr_init (member_base, DECL_INITIAL (member), 0);
  1368.           else if (TREE_CODE (TREE_TYPE (member)) == ARRAY_TYPE
  1369.                && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (member)))
  1370.         {
  1371.           member_base = save_expr (default_conversion (member_base));
  1372.           expand_vec_init (member, member_base,
  1373.                    array_type_nelts (TREE_TYPE (member)),
  1374.                    DECL_INITIAL (member), 0);
  1375.         }
  1376.           else expand_expr_stmt (build_modify_expr (member_base, INIT_EXPR, DECL_INITIAL (member)));
  1377.         }
  1378.       else if (TREE_CODE (TREE_PURPOSE (init_list)) == TREE_LIST)
  1379.         {
  1380.           expand_recursive_init_1 (for_type, true_exp, addr, TREE_PURPOSE (init_list), alias_this);
  1381.           expand_recursive_init_1 (for_type, true_exp, addr, TREE_VALUE (init_list), alias_this);
  1382.         }
  1383.       else if (TREE_CODE (TREE_PURPOSE (init_list)) == ERROR_MARK)
  1384.         {
  1385.           /* Only initialize the virtual function tables if we
  1386.          are initializing the ultimate users of those vtables.  */
  1387.           if (TREE_VALUE (init_list))
  1388.         {
  1389.           expand_expr_stmt (build_virtual_init (for_type, TREE_VALUE (init_list), addr));
  1390.           if (TREE_VALUE (init_list) == for_type
  1391.               && TYPE_USES_VIRTUAL_BASECLASSES (for_type))
  1392.             expand_expr_stmt (build_vbase_vtables_init (for_type, TREE_VALUE (init_list), true_exp, addr, 1));
  1393.         }
  1394.         }
  1395.       else abort ();
  1396.     }
  1397.       else if (TREE_VALUE (init_list)
  1398.            && TREE_CODE (TREE_VALUE (init_list)) == RECORD_TYPE)
  1399.     {
  1400.       tree subexp = build_indirect_ref (convert_pointer_to (TREE_VALUE (init_list), addr), 0);
  1401.       expand_aggr_init_1 (for_type, true_exp, subexp, *init_ptr,
  1402.                   alias_this && ! DECL_OFFSET (TYPE_NAME (TREE_VALUE (init_list))),
  1403.                   LOOKUP_PROTECTED_OK|LOOKUP_COMPLAIN);
  1404.  
  1405.       /* INIT_PTR is used up.  */
  1406.       init_ptr = &init_null;
  1407.     }
  1408.       else
  1409.     abort ();
  1410.       init_list = TREE_CHAIN (init_list);
  1411.     }
  1412. }
  1413.  
  1414. /* Initialize EXP with INIT.  Type EXP does not have a constructor,
  1415.    but it has a baseclass with a constructor or a virtual function
  1416.    table which needs initializing.
  1417.  
  1418.    INIT_LIST is a cons-list describing what parts of EXP actually
  1419.    need to be initialized.  INIT is given to the *unique*, first
  1420.    constructor within INIT_LIST.  If there are multiple first
  1421.    constructors, such as with multiple inheritance, INIT must
  1422.    be zero or an ambiguity error is reported.
  1423.  
  1424.    ALIAS_THIS is passed from `expand_aggr_init'.  See comments
  1425.    there.  */
  1426.  
  1427. static void
  1428. expand_recursive_init (for_type, true_exp, exp, init, init_list, alias_this)
  1429.      tree for_type, true_exp, exp, init;
  1430.      tree init_list;
  1431.      int alias_this;
  1432. {
  1433.   tree *old_init_ptr = init_ptr;
  1434.   tree addr = build_unary_op (ADDR_EXPR, exp, 0);
  1435.   init_ptr = &init;
  1436.  
  1437.   if (true_exp == exp && TYPE_USES_VIRTUAL_BASECLASSES (for_type))
  1438.     {
  1439.       expand_aggr_vbase_init (for_type, exp, addr, init_list);
  1440.       expand_expr_stmt (build_vbase_vtables_init (for_type, for_type, true_exp, addr, 1));
  1441.     }
  1442.   expand_recursive_init_1 (for_type, true_exp, addr, init_list, alias_this);
  1443.  
  1444.   if (*init_ptr)
  1445.     {
  1446.       tree type = TREE_TYPE (exp);
  1447.  
  1448.       if (TREE_CODE (type) == REFERENCE_TYPE)
  1449.     type = TREE_TYPE (type);
  1450.       if (IS_AGGR_TYPE (type))
  1451.     error_with_aggr_type (type, "unexpected argument to constructor `%s'");
  1452.       else
  1453.     error ("unexpected argument to constructor");
  1454.     }
  1455.   init_ptr = old_init_ptr;
  1456. }
  1457.  
  1458. /* Report an error if NAME is not the name of a user-defined,
  1459.    aggregate type.  If OR_ELSE is nonzero, give an error message.  */
  1460. int
  1461. is_aggr_typedef (name, or_else)
  1462.      tree name;
  1463. {
  1464.   tree type = TREE_TYPE (name);
  1465.  
  1466.   if (type == NULL_TREE || TREE_CODE (type) != TYPE_DECL)
  1467.     {
  1468.       if (or_else)
  1469.     error ("`%s' fails to be an aggregate typedef",
  1470.            IDENTIFIER_POINTER (name));
  1471.       return 0;
  1472.     }
  1473.   type = TREE_TYPE (type);
  1474.   if (! IS_AGGR_TYPE (type))
  1475.     {
  1476.       fatal ("type `%s' is of non-aggregate type",
  1477.          IDENTIFIER_POINTER (name));
  1478.       return 0;
  1479.     }
  1480.   return 1;
  1481. }
  1482.  
  1483. /* This code could just as well go in `cplus-class.c', but is placed here for
  1484.    modularity.  */
  1485.  
  1486. /* For an expression of the form CNAME :: NAME (PARMLIST), build
  1487.    the appropriate function call.  */
  1488. tree
  1489. build_member_call (cname, name, parmlist)
  1490.      tree cname, name, parmlist;
  1491. {
  1492.   tree type, t;
  1493.   tree method_name = name;
  1494.   int dtor = 0;
  1495.   int dont_use_this = 0;
  1496.   tree basetype_path, decl;
  1497.  
  1498.   if (TREE_CODE (method_name) == BIT_NOT_EXPR)
  1499.     {
  1500.       method_name = TREE_OPERAND (method_name, 0);
  1501.       dtor = 1;
  1502.     }
  1503.  
  1504.   if (TREE_CODE (cname) == SCOPE_REF)
  1505.     {
  1506.       sorry ("multiple scope qualifications in build_member_call");
  1507.       return error_mark_node;
  1508.     }
  1509.  
  1510.   if (! is_aggr_typedef (cname, 1))
  1511.     return error_mark_node;
  1512.  
  1513.   /* An operator we did not like.  */
  1514.   if (name == NULL_TREE)
  1515.     return error_mark_node;
  1516.  
  1517.   if (dtor)
  1518.     {
  1519.       if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (TREE_TYPE (cname))))
  1520.     error ("type `%s' does not have a destructor",
  1521.            IDENTIFIER_POINTER (cname));
  1522.       else
  1523.     error ("destructor specification error");
  1524.       return error_mark_node;
  1525.     }
  1526.  
  1527.   if (TREE_CODE (name) == OP_IDENTIFIER)
  1528.     method_name = build_operator_fnname (&name, parmlist, 1);
  1529.   type = TREE_TYPE (TREE_TYPE (cname));
  1530.  
  1531.   /* No object?  Then just fake one up, and let build_method_call
  1532.      figure out what to do.  */
  1533.   if (current_class_type == 0
  1534.       || get_base_distance (type, current_class_type, 0, &basetype_path) == -1)
  1535.     dont_use_this = 1;
  1536.  
  1537.   if (dont_use_this)
  1538.     {
  1539.       basetype_path = NULL_TREE;
  1540.       decl = build1 (NOP_EXPR,
  1541.              TYPE_POINTER_TO (TREE_TYPE (TREE_TYPE (cname))),
  1542.              error_mark_node);
  1543.     }
  1544.   else if (current_class_decl == 0)
  1545.     {
  1546.       dont_use_this = 1;
  1547.       decl = build1 (NOP_EXPR,
  1548.              TYPE_POINTER_TO (TREE_TYPE (TREE_TYPE (cname))),
  1549.              error_mark_node);
  1550.     }
  1551.   else decl = current_class_decl;
  1552.  
  1553.   if (t = lookup_fnfields (CLASSTYPE_AS_LIST (type), method_name, 0))
  1554.     return build_method_call (decl, method_name, parmlist, basetype_path,
  1555.                   LOOKUP_NORMAL|LOOKUP_NONVIRTUAL);
  1556.   if (TREE_CODE (name) == IDENTIFIER_NODE
  1557.       && (t = lookup_field (CLASSTYPE_AS_LIST (type), name, 1)))
  1558.     {
  1559.       if (t == error_mark_node)
  1560.     return error_mark_node;
  1561.       if (TREE_CODE (t) == FIELD_DECL)
  1562.     {
  1563.       if (dont_use_this)
  1564.         {
  1565.           error ("invalid use of non-static field `%s'",
  1566.              IDENTIFIER_POINTER (name));
  1567.           return error_mark_node;
  1568.         }
  1569.       decl = build (COMPONENT_REF, TREE_TYPE (t), decl, t);
  1570.     }
  1571.       else if (TREE_CODE (t) == VAR_DECL)
  1572.     decl = t;
  1573.       else
  1574.     {
  1575.       error ("invalid use of member `%s::%s'",
  1576.          IDENTIFIER_POINTER (cname), name);
  1577.       return error_mark_node;
  1578.     }
  1579.       return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, decl, parmlist);
  1580.     }
  1581.   else
  1582.     {
  1583.       char *err_name;
  1584.       if (TREE_CODE (name) == OP_IDENTIFIER)
  1585.     {
  1586.       char *op_name = operator_name_string (method_name);
  1587.       err_name = (char *)alloca (13 + strlen (op_name));
  1588.       sprintf (err_name, "operator %s", op_name);
  1589.     }
  1590.       else if (TREE_CODE (name) == IDENTIFIER_NODE)
  1591.     err_name = IDENTIFIER_POINTER (name);
  1592.       else
  1593.     abort ();
  1594.  
  1595.       error ("no method `%s::%s'", IDENTIFIER_POINTER (cname), err_name);
  1596.       return error_mark_node;
  1597.     }
  1598. }
  1599.  
  1600. /* Build a reference to a member of an aggregate.  This is not a
  1601.    C++ `&', but really something which can have its address taken,
  1602.    and then act as a pointer to member, for example CNAME :: FIELD
  1603.    can have its address taken by saying & CNAME :: FIELD.
  1604.  
  1605.    @@ Prints out lousy diagnostics for operator <typename>
  1606.    @@ fields.
  1607.  
  1608.    @@ This function should be rewritten and placed in cplus-search.c.  */
  1609. tree
  1610. build_offset_ref (cname, name)
  1611.      tree cname, name;
  1612. {
  1613.   tree decl, type, fnfields, fields, t = error_mark_node;
  1614.   tree basetypes = NULL_TREE;
  1615.   int dtor = 0;
  1616.  
  1617.   if (TREE_CODE (cname) == SCOPE_REF)
  1618.     {
  1619.       sorry ("multiple scope qualifications in build_offset_ref");
  1620.       return error_mark_node;
  1621.     }
  1622.  
  1623.   if (! is_aggr_typedef (cname, 1))
  1624.     return error_mark_node;
  1625.  
  1626.   type = TREE_TYPE (TREE_TYPE (cname));
  1627.  
  1628.   if (TREE_CODE (name) == BIT_NOT_EXPR)
  1629.     {
  1630.       dtor = 1;
  1631.       name = TREE_OPERAND (name, 0);
  1632.     }
  1633.  
  1634.   if (TYPE_SIZE (type) == 0)
  1635.     {
  1636.       t = IDENTIFIER_CLASS_VALUE (name);
  1637.       if (t == 0)
  1638.     {
  1639.       error_with_aggr_type (type, "incomplete type `%s' does not have member `%s'", IDENTIFIER_POINTER (name));
  1640.       return error_mark_node;
  1641.     }
  1642.       if (TREE_CODE (t) == TYPE_DECL)
  1643.     {
  1644.       error_with_decl (t, "member `%s' is just a type declaration");
  1645.       return error_mark_node;
  1646.     }
  1647.       if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == CONST_DECL)
  1648.     {
  1649.       TREE_USED (t) = 1;
  1650.       return t;
  1651.     }
  1652.       if (TREE_CODE (t) == FIELD_DECL)
  1653.     sorry ("use of member in incomplete aggregate type");
  1654.       else if (TREE_CODE (t) == FUNCTION_DECL)
  1655.     sorry ("use of member function in incomplete aggregate type");
  1656.       else
  1657.     abort ();
  1658.       return error_mark_node;
  1659.     }
  1660.  
  1661.   /* Unresolved multi-arity operator.  */
  1662.   if (TREE_CODE (name) == OP_IDENTIFIER)
  1663.     {
  1664.       t = copy_node (name);
  1665.       TREE_TYPE (t) = unknown_type_node;
  1666.       return t;
  1667.     }
  1668.   if (TREE_CODE (name) == TYPE_EXPR)
  1669.     /* Pass a TYPE_DECL to build_component_type_expr.  */
  1670.     return build_component_type_expr (TREE_TYPE (cname), name, NULL_TREE, 1);
  1671.  
  1672.   fnfields = lookup_fnfields (CLASSTYPE_AS_LIST (type), name, 0);
  1673.   fields = lookup_field (type, name, 0);
  1674.  
  1675.   if (fields == error_mark_node)
  1676.     return error_mark_node;
  1677.  
  1678.   if (fnfields)
  1679.     {
  1680.       basetypes = TREE_PURPOSE (fnfields);
  1681.  
  1682.       /* Go from the TREE_BASELINK to the member function info.  */
  1683.       t = TREE_VALUE (fnfields);
  1684.  
  1685.       if (fields)
  1686.     {
  1687.       if (DECL_FIELD_CONTEXT (fields) == DECL_FIELD_CONTEXT (t))
  1688.         {
  1689.           error ("ambiguous member reference: member `%s' defined as both field and function",
  1690.              IDENTIFIER_POINTER (name));
  1691.           return error_mark_node;
  1692.         }
  1693.       if (get_base_type (DECL_FIELD_CONTEXT (fields), DECL_FIELD_CONTEXT (t), 0))
  1694.         ;
  1695.       else if (get_base_type (DECL_FIELD_CONTEXT (t), DECL_FIELD_CONTEXT (fields), 0))
  1696.         t = fields;
  1697.       else
  1698.         {
  1699.           error ("ambiguous member reference: member `%s' derives from distinct classes in multiple inheritance lattice");
  1700.           return error_mark_node;
  1701.         }
  1702.     }
  1703.  
  1704.       if (t == TREE_VALUE (fnfields))
  1705.     {
  1706.       extern int flag_save_memoized_contexts;
  1707.  
  1708.       /* This does not handle visibility checking yet.  */
  1709.       if (TREE_CHAIN (t) == NULL_TREE || dtor)
  1710.         {
  1711.           enum visibility_type visibility;
  1712.  
  1713.           /* unique functions are handled easily.  */
  1714.         unique:
  1715.           visibility = compute_visibility (basetypes, t);
  1716.           if (visibility == visibility_protected)
  1717.         {
  1718.           error_with_decl (t, "member function `%s' is protected");
  1719.           error ("in this context");
  1720.           return error_mark_node;
  1721.         }
  1722.           if (visibility == visibility_private)
  1723.         {
  1724.           error_with_decl (t, "member function `%s' is private");
  1725.           error ("in this context");
  1726.           return error_mark_node;
  1727.         }
  1728.           return build (OFFSET_REF, TREE_TYPE (t), NULL_TREE, t);
  1729.         }
  1730.  
  1731.       /* overloaded functions may need more work.  */
  1732.       if (cname == name)
  1733.         {
  1734.           if (TYPE_HAS_DESTRUCTOR (type)
  1735.           && TREE_CHAIN (TREE_CHAIN (t)) == NULL_TREE)
  1736.         {
  1737.           t = TREE_CHAIN (t);
  1738.           goto unique;
  1739.         }
  1740.         }
  1741.       if (flag_save_memoized_contexts
  1742.           && !TREE_PERMANENT (fnfields)
  1743.           && global_bindings_p ())
  1744.         fnfields = copy_list (fnfields);
  1745.       t = build_tree_list (error_mark_node, fnfields);
  1746.       TREE_TYPE (t) = build_member_type (type, unknown_type_node);
  1747.       return t;
  1748.     }
  1749.     }
  1750.  
  1751.   /* Now that we know we are looking for a field, see if we
  1752.      have access to that field.  Lookup_field will give us the
  1753.      error message.  */
  1754.  
  1755.   if (current_class_type == 0
  1756.       || get_base_distance (type, current_class_type, 0, &basetypes) == -1)
  1757.     {
  1758.       basetypes = CLASSTYPE_AS_LIST (type);
  1759.       decl = build1 (NOP_EXPR,
  1760.              TREE_TYPE (TREE_TYPE (cname)),
  1761.              error_mark_node);
  1762.     }
  1763.   else if (current_class_decl == 0)
  1764.     decl = build1 (NOP_EXPR, TREE_TYPE (TREE_TYPE (cname)),
  1765.            error_mark_node);
  1766.   else decl = C_C_D;
  1767.  
  1768.   t = lookup_field (basetypes, name, 1);
  1769.  
  1770.   if (t == error_mark_node)
  1771.     return error_mark_node;
  1772.  
  1773.   if (t == NULL_TREE)
  1774.     {
  1775.       if (OPERATOR_TYPENAME_P (name))
  1776.     error ("type conversion operator not a member of type `%s'",
  1777.            IDENTIFIER_POINTER (cname));
  1778.       else
  1779.     error ("field `%s' is not a member of type `%s'",
  1780.            IDENTIFIER_POINTER (name),
  1781.            IDENTIFIER_POINTER (cname));
  1782.       return error_mark_node;
  1783.     }
  1784.  
  1785.   if (TREE_CODE (t) == TYPE_DECL)
  1786.     {
  1787.       error_with_decl (t, "member `%s' is just a type declaration");
  1788.       return error_mark_node;
  1789.     }
  1790.   /* static class members and class-specific enum
  1791.      values can be returned without further ado.  */
  1792.   if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == CONST_DECL)
  1793.     {
  1794.       TREE_USED (t) = 1;
  1795.       return t;
  1796.     }
  1797.  
  1798.   /* static class functions too.  */
  1799.   if (TREE_CODE (t) == FUNCTION_DECL && TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE)
  1800.     abort ();
  1801.  
  1802.   /* In member functions, the form `cname::name' is no longer
  1803.      equivalent to `this->cname::name'.  */
  1804.   return build (OFFSET_REF, build_member_type (type, TREE_TYPE (t)), decl, t);
  1805. }
  1806.  
  1807. /* Given an object EXP and a member function reference MEMBER,
  1808.    return the address of the actual member function.  */
  1809. tree
  1810. get_member_function (exp_addr_ptr, exp, member)
  1811.      tree *exp_addr_ptr;
  1812.      tree exp, member;
  1813. {
  1814.   tree ctype = TREE_TYPE (exp);
  1815.   tree function = save_expr (build_unary_op (ADDR_EXPR, member, 0));
  1816.  
  1817.   if (TYPE_VIRTUAL_P (ctype)
  1818.       || (flag_all_virtual == 1
  1819.       && (TYPE_OVERLOADS_METHOD_CALL_EXPR (ctype)
  1820.           || TYPE_NEEDS_WRAPPER (ctype))))
  1821.     {
  1822.       tree e0, e1, e3;
  1823.       tree exp_addr;
  1824.  
  1825.       /* Save away the unadulterated `this' pointer.  */
  1826.       exp_addr = save_expr (*exp_addr_ptr);
  1827.  
  1828.       /* Cast function to signed integer.  */
  1829.       e0 = build1 (NOP_EXPR, integer_type_node, function);
  1830.  
  1831. #ifdef VTABLE_USES_MASK
  1832.       /* If we are willing to limit the number of
  1833.      virtual functions a class may have to some
  1834.      *small* number, then if, for a function address,
  1835.      we are passed some small number, we know that
  1836.      it is a virtual function index, and work from there.  */
  1837.       e1 = build (BIT_AND_EXPR, integer_type_node, e0, vtbl_mask);
  1838. #else
  1839.       /* There is a hack here that takes advantage of
  1840.      twos complement arithmetic, and the fact that
  1841.      there are more than one UNITS to the WORD.
  1842.      If the high bit is set for the `function',
  1843.      then we pretend it is a virtual function,
  1844.      and the array indexing will knock this bit
  1845.      out the top, leaving a valid index.  */
  1846. #if UNITS_PER_WORD <= 1
  1847.       virtual_functions_lose !;
  1848. #endif
  1849.       e1 = build (GT_EXPR, integer_type_node, e0, integer_zero_node);
  1850.       e1 = build_compound_expr (tree_cons (NULL_TREE, exp_addr,
  1851.                        build_tree_list (NULL_TREE, e1)));
  1852.       e1 = save_expr (e1);
  1853. #endif
  1854.  
  1855.       if (TREE_VOLATILE (*exp_addr_ptr))
  1856.     {
  1857.       exp = build_indirect_ref (exp_addr, 0);
  1858.       *exp_addr_ptr = exp_addr;
  1859.     }
  1860.  
  1861.       /* This is really hairy: if the function pointer is a pointer
  1862.      to a non-virtual member function, then we can't go mucking
  1863.      with the `this' pointer (any more than we aleady have to
  1864.      this point).  If it is a pointer to a virtual member function,
  1865.      then we have to adjust the `this' pointer according to
  1866.      what the virtual function table tells us.  */
  1867.  
  1868.       e3 = build_vfn_ref (exp_addr_ptr, exp, e0);
  1869.       assert (e3 != error_mark_node);
  1870.  
  1871.       /* Change this pointer type from `void *' to the
  1872.      type it is really supposed to be.  */
  1873.       TREE_TYPE (e3) = TREE_TYPE (function);
  1874.  
  1875.       /* If non-virtual, use what we had originally.  Otherwise,
  1876.      use the value we get from the virtual function table.  */
  1877.       *exp_addr_ptr = build_conditional_expr (e1, exp_addr, *exp_addr_ptr);
  1878.  
  1879.       function = build_conditional_expr (e1, function, e3);
  1880.     }
  1881.   return build_indirect_ref (function, 0);
  1882. }
  1883.  
  1884. /* If a OFFSET_REF made it through to here, then it did
  1885.    not have its address taken.  */
  1886.  
  1887. tree
  1888. resolve_offset_ref (exp)
  1889.      tree exp;
  1890. {
  1891.   tree base;
  1892.   tree member;
  1893.   tree basetype, addr;
  1894.  
  1895.   if (TREE_CODE (exp) == TREE_LIST)
  1896.     return build_unary_op (ADDR_EXPR, exp, 0);
  1897.  
  1898.   assert (TREE_CODE (exp) == OFFSET_REF);
  1899.   member = TREE_OPERAND (exp, 1);
  1900.   if (TREE_STATIC (member))
  1901.     {
  1902.       /* These were static members.  */
  1903.       if (mark_addressable (member) == 0)
  1904.     return error_mark_node;
  1905.       return member;
  1906.     }
  1907.  
  1908.   /* Syntax error can cause a member which should
  1909.      have been seen as static to be grok'd as non-static.  */
  1910.   if (TREE_CODE (member) == FIELD_DECL && C_C_D == NULL_TREE)
  1911.     {
  1912.       if (TREE_ADDRESSABLE (member) == 0)
  1913.     {
  1914.       error_with_decl (member, "member `%s' is non-static in static member function context");
  1915.       TREE_ADDRESSABLE (member) = 1;
  1916.     }
  1917.       return error_mark_node;
  1918.     }
  1919.  
  1920.   base = TREE_OPERAND (exp, 0);
  1921.   assert (base != NULL_TREE);
  1922.  
  1923.   /* The first case is really just a reference to a member of `this'.  */
  1924.   if (TREE_CODE (member) == FIELD_DECL
  1925.       && (base == C_C_D
  1926.       || (TREE_CODE (base) == NOP_EXPR
  1927.           && TREE_OPERAND (base, 0) == error_mark_node)))
  1928.     {
  1929.       tree basetype_path;
  1930.       enum visibility_type visibility;
  1931.  
  1932.       basetype = DECL_CONTEXT (member);
  1933.       if (get_base_distance (basetype, current_class_type, 0, &basetype_path) < 0)
  1934.     {
  1935.       error_not_base_type (basetype, current_class_type);
  1936.       return error_mark_node;
  1937.     }
  1938.       addr = convert_pointer_to (basetype, current_class_decl);
  1939.       visibility = compute_visibility (basetype_path, member);
  1940.       if (visibility == visibility_public)
  1941.     return build (COMPONENT_REF, TREE_TYPE (member),
  1942.               build_indirect_ref (addr, 0), member);
  1943.       if (visibility == visibility_protected)
  1944.     {
  1945.       error_with_decl ("member `%s' is protected");
  1946.       error ("in this context");
  1947.       return error_mark_node;
  1948.     }
  1949.       if (visibility == visibility_private)
  1950.     {
  1951.       error_with_decl ("member `%s' is private");
  1952.       error ("in this context");
  1953.       return error_mark_node;
  1954.     }
  1955.       abort ();
  1956.     }
  1957.   /* If this is a reference to a member function, then return
  1958.      the address of the member function (which may involve going
  1959.      through the object's vtable), otherwise, return an expression
  1960.      for the derefernced pointer-to-member construct.  */
  1961.   addr = build_unary_op (ADDR_EXPR, base, 0);
  1962.   if (TREE_CODE (TREE_TYPE (member)) == METHOD_TYPE)
  1963.     {
  1964.       basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (member));
  1965.       addr = convert_pointer_to (basetype, addr);
  1966.       return build_unary_op (ADDR_EXPR, get_member_function (&addr, build_indirect_ref (addr, 0), member), 0);
  1967.     }
  1968.   else if (TREE_CODE (TREE_TYPE (member)) == OFFSET_TYPE)
  1969.     {
  1970.       basetype = TYPE_OFFSET_BASETYPE (TREE_TYPE (member));
  1971.       addr = convert_pointer_to (basetype, addr);
  1972.       member = convert (ptr_type_node, build_unary_op (ADDR_EXPR, member, 0));
  1973.       return build1 (INDIRECT_REF, TREE_TYPE (exp),
  1974.              build (PLUS_EXPR, ptr_type_node, addr, member));
  1975.     }
  1976.   abort ();
  1977. }
  1978.  
  1979. /* Return either DECL or its known constant value (if it has one).  */
  1980.  
  1981. tree
  1982. decl_constant_value (decl)
  1983.      tree decl;
  1984. {
  1985.   if (
  1986. #if 0
  1987.       /* These may be necessary for C, but they break C++.  */
  1988.       ! TREE_PUBLIC (decl)
  1989.       /* Don't change a variable array bound or initial value to a constant
  1990.      in a place where a variable is invalid.  */
  1991.       && current_function_decl != 0
  1992.       && ! pedantic
  1993.       &&
  1994. #endif /* 0 */
  1995.       ! TREE_THIS_VOLATILE (decl)
  1996.       && DECL_INITIAL (decl) != 0
  1997.       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
  1998.       /* This is invalid if initial value is not constant.
  1999.      If it has either a function call, a memory reference,
  2000.      or a variable, then re-evaluating it could give different results.  */
  2001.       && TREE_LITERAL (DECL_INITIAL (decl))
  2002. #if 0
  2003.       /* Check for cases where this is sub-optimal, even though valid.  */
  2004.       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  2005.       && DECL_MODE (decl) != BLKmode
  2006. #endif
  2007.       )
  2008.     return DECL_INITIAL (decl);
  2009.   return decl;
  2010. }
  2011.  
  2012. /* Friend handling routines.  */
  2013. /* Friend data structures:
  2014.  
  2015.    Friend lists come from TYPE_DECL nodes.  Since all aggregate
  2016.    types are automatically typedef'd, these node are guaranteed
  2017.    to exist.
  2018.  
  2019.    The TREE_PURPOSE of a friend list is the name of the friend,
  2020.    and its TREE_VALUE is another list.
  2021.  
  2022.    The TREE_PURPOSE of that list is a type, which allows
  2023.    all functions of a given type to be friends.
  2024.    The TREE_VALUE of that list is an individual function
  2025.    which is a friend.
  2026.  
  2027.    Non-member friends will match only by their DECL.  Their
  2028.    member type is NULL_TREE, while the type of the inner
  2029.    list will either be of aggregate type or error_mark_node.  */
  2030.  
  2031. /* Tell if this function specified by FUNCTION_DECL
  2032.    can be a friend of type TYPE.
  2033.    Return nonzero if friend, zero otherwise.
  2034.  
  2035.    DECL can be zero if we are calling a constructor or accessing a
  2036.    member in global scope.  */
  2037. int
  2038. is_friend (type, decl)
  2039.      tree type, decl;
  2040. {
  2041.   tree typedecl = TYPE_NAME (type);
  2042.   tree ctype = NULL_TREE;
  2043.   tree list;
  2044.   tree name;
  2045.  
  2046.   if (decl == NULL_TREE)
  2047.     return 0;
  2048.  
  2049.   if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
  2050.     ctype = TYPE_METHOD_BASETYPE (TREE_TYPE (decl));
  2051.   else if (DECL_STATIC_FUNCTION_P (decl))
  2052.     ctype = DECL_CONTEXT (decl);
  2053.   if (ctype)
  2054.     {
  2055.       list = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (typedecl));
  2056.       while (list)
  2057.     {
  2058.       if (ctype == TREE_VALUE (list))
  2059.         return 1;
  2060.       list = TREE_CHAIN (list);
  2061.     }
  2062.     }
  2063.  
  2064.   list = DECL_FRIENDLIST (typedecl);
  2065.   name = DECL_ORIGINAL_NAME (decl);
  2066.   while (list)
  2067.     {
  2068.       if (name == TREE_PURPOSE (list))
  2069.     {
  2070.       tree friends = TREE_VALUE (list);
  2071.       name = DECL_NAME (decl);
  2072.       while (friends)
  2073.         {
  2074.           if (ctype == TREE_PURPOSE (friends))
  2075.         return 1;
  2076.           if (name == DECL_NAME (TREE_VALUE (friends)))
  2077.         return 1;
  2078.           friends = TREE_CHAIN (friends);
  2079.         }
  2080.       return 0;
  2081.     }
  2082.       list = TREE_CHAIN (list);
  2083.     }
  2084.   return 0;
  2085. }
  2086.  
  2087. /* Add a new friend to the friends of the aggregate type TYPE.
  2088.    DECL is the FUNCTION_DECL of the friend being added.  */
  2089. static void
  2090. add_friend (type, decl)
  2091.      tree type, decl;
  2092. {
  2093.   tree typedecl = TYPE_NAME (type);
  2094.   tree list = DECL_FRIENDLIST (typedecl);
  2095.   tree name = DECL_ORIGINAL_NAME (decl);
  2096.   tree ctype = TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
  2097.     ? TYPE_METHOD_BASETYPE (TREE_TYPE (decl)) : error_mark_node;
  2098.  
  2099.   while (list)
  2100.     {
  2101.       if (name == TREE_PURPOSE (list))
  2102.     {
  2103.       tree friends = TREE_VALUE (list);
  2104.       while (friends)
  2105.         {
  2106.           if (decl == TREE_VALUE (friends))
  2107.         {
  2108.           warning_with_decl (decl, "`%s' is already a friend of class `%s'", IDENTIFIER_POINTER (DECL_NAME (typedecl)));
  2109.           return;
  2110.         }
  2111.           friends = TREE_CHAIN (friends);
  2112.         }
  2113.       TREE_VALUE (list) = tree_cons (ctype, decl, TREE_VALUE (list));
  2114.       return;
  2115.     }
  2116.       list = TREE_CHAIN (list);
  2117.     }
  2118.   DECL_FRIENDLIST (typedecl)
  2119.     = tree_cons (DECL_ORIGINAL_NAME (decl),
  2120.          build_tree_list (error_mark_node, decl),
  2121.          DECL_FRIENDLIST (typedecl));
  2122.   if (! strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
  2123.          OPERATOR_MODIFY_FORMAT,
  2124.          OPERATOR_MODIFY_LENGTH))
  2125.     {
  2126.       tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  2127.       TYPE_HAS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
  2128.       TYPE_GETS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
  2129.       if (parmtypes && TREE_CHAIN (parmtypes))
  2130.     {
  2131.       tree parmtype = TREE_VALUE (TREE_CHAIN (parmtypes));
  2132.       if (TREE_CODE (parmtype) == REFERENCE_TYPE
  2133.           && TREE_TYPE (parmtypes) == TREE_TYPE (typedecl))
  2134.         {
  2135.           TYPE_HAS_ASSIGN_REF (TREE_TYPE (typedecl)) = 1;
  2136.           TYPE_GETS_ASSIGN_REF (TREE_TYPE (typedecl)) = 1;
  2137.         }
  2138.     }
  2139.     }
  2140. }
  2141.  
  2142. /* Declare that every member function NAME in FRIEND_TYPE
  2143.    (which may be NULL_TREE) is a friend of type TYPE.  */
  2144. static void
  2145. add_friends (type, name, friend_type)
  2146.      tree type, name, friend_type;
  2147. {
  2148.   tree typedecl = TYPE_NAME (type);
  2149.   tree list = DECL_FRIENDLIST (typedecl);
  2150.  
  2151.   while (list)
  2152.     {
  2153.       if (name == TREE_PURPOSE (list))
  2154.     {
  2155.       tree friends = TREE_VALUE (list);
  2156.       while (friends && TREE_PURPOSE (friends) != friend_type)
  2157.         friends = TREE_CHAIN (friends);
  2158.       if (friends)
  2159.         if (friend_type)
  2160.           warning ("method `%s::%s' is already a friend of class",
  2161.                TYPE_NAME_STRING (friend_type),
  2162.                IDENTIFIER_POINTER (name));
  2163.         else
  2164.           warning ("function `%s' is already a friend of class `%s'",
  2165.                IDENTIFIER_POINTER (name),
  2166.                IDENTIFIER_POINTER (DECL_NAME (typedecl)));
  2167.       else
  2168.         TREE_VALUE (list) = tree_cons (friend_type, NULL_TREE,
  2169.                        TREE_VALUE (list));
  2170.       return;
  2171.     }
  2172.       list = TREE_CHAIN (list);
  2173.     }
  2174.   DECL_FRIENDLIST (typedecl) =
  2175.     tree_cons (name,
  2176.            build_tree_list (friend_type, NULL_TREE),
  2177.            DECL_FRIENDLIST (typedecl));
  2178.   if (! strncmp (name, OPERATOR_MODIFY_FORMAT, OPERATOR_MODIFY_LENGTH))
  2179.     {
  2180.       TYPE_HAS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
  2181.       TYPE_GETS_ASSIGNMENT (TREE_TYPE (typedecl)) = 1;
  2182.       sorry ("declaring \"friend operator =\" will not find \"operator = (X&)\" if it exists");
  2183.     }
  2184. }
  2185.  
  2186. /* Set up a cross reference so that type TYPE will
  2187.    make member function CTYPE::DECL a friend when CTYPE
  2188.    is finally defined.  */
  2189. void
  2190. xref_friend (type, decl, ctype)
  2191.      tree type, decl, ctype;
  2192. {
  2193.   tree typedecl = TYPE_NAME (type);
  2194.   tree friend_decl = TYPE_NAME (ctype);
  2195.   tree t = tree_cons (NULL_TREE, ctype, DECL_UNDEFINED_FRIENDS (typedecl));
  2196.  
  2197.   DECL_UNDEFINED_FRIENDS (typedecl) = t;
  2198.   SET_DECL_WAITING_FRIENDS (friend_decl, tree_cons (type, t, DECL_WAITING_FRIENDS (friend_decl)));
  2199.   TREE_TYPE (DECL_WAITING_FRIENDS (friend_decl)) = decl;
  2200. }
  2201.  
  2202. /* Set up a cross reference so that functions with name NAME and
  2203.    type CTYPE know that they are friends of TYPE.  */
  2204. void
  2205. xref_friends (type, name, ctype)
  2206.      tree type, name, ctype;
  2207. {
  2208.   tree typedecl = TYPE_NAME (type);
  2209.   tree friend_decl = TYPE_NAME (ctype);
  2210.   tree t = tree_cons (NULL_TREE, ctype,
  2211.               DECL_UNDEFINED_FRIENDS (typedecl));
  2212.  
  2213.   DECL_UNDEFINED_FRIENDS (typedecl) = t;
  2214.   SET_DECL_WAITING_FRIENDS (friend_decl, tree_cons (type, t, DECL_WAITING_FRIENDS (friend_decl)));
  2215.   TREE_TYPE (DECL_WAITING_FRIENDS (friend_decl)) = name;
  2216. }
  2217.  
  2218. /* Make FRIEND_TYPE a friend class to TYPE.  If FRIEND_TYPE has already
  2219.    been defined, we make all of its member functions friends of
  2220.    TYPE.  If not, we make it a pending friend, which can later be added
  2221.    when its definition is seen.  If a type is defined, then its TYPE_DECL's
  2222.    DECL_UNDEFINED_FRIENDS contains a (possibly empty) list of friend
  2223.    classes that are not defined.  If a type has not yet been defined,
  2224.    then the DECL_WAITING_FRIENDS contains a list of types
  2225.    waiting to make it their friend.  Note that these two can both
  2226.    be in use at the same time!  */
  2227. void
  2228. make_friend_class (type, friend_type)
  2229.      tree type, friend_type;
  2230. {
  2231.   tree classes;
  2232.  
  2233.   if (type == friend_type)
  2234.     {
  2235.       warning ("class `%s' is implicitly friends with itself",
  2236.            TYPE_NAME_STRING (type));
  2237.       return;
  2238.     }
  2239.  
  2240. #ifdef FIELD_XREF
  2241.   FIELD_xref_hier(TYPE_NAME_STRING(type),
  2242.           TYPE_NAME_STRING(friend_type),0,0,1);
  2243. #endif
  2244.  
  2245.   classes = CLASSTYPE_FRIEND_CLASSES (type);
  2246.   while (classes && TREE_VALUE (classes) != friend_type)
  2247.     classes = TREE_CHAIN (classes);
  2248.   if (classes)
  2249.     warning ("class `%s' is already friends with class `%s'",
  2250.          TYPE_NAME_STRING (TREE_VALUE (classes)), TYPE_NAME_STRING (type));
  2251.   else
  2252.     {
  2253.       CLASSTYPE_FRIEND_CLASSES (type)
  2254.     = tree_cons (NULL_TREE, friend_type, CLASSTYPE_FRIEND_CLASSES (type));
  2255.     }
  2256. }
  2257.  
  2258. /* Main friend processor.  This is large, and for modularity purposes,
  2259.    has been removed from grokdeclarator.  It returns `void_type_node'
  2260.    to indicate that something happened, though a FIELD_DECL is
  2261.    not returned.
  2262.  
  2263.    CTYPE is the class this friend belongs to.
  2264.  
  2265.    DECLARATOR is the name of the friend.
  2266.  
  2267.    DECL is the FUNCTION_DECL that the friend is.
  2268.  
  2269.    In case we are parsing a friend which is part of an inline
  2270.    definition, we will need to store PARM_DECL chain that comes
  2271.    with it into the DECL_ARGUMENTS slot of the FUNCTION_DECL.
  2272.  
  2273.    FLAGS is just used for `grokclassfn'.
  2274.  
  2275.    QUALS say what special qualifies should apply to the object
  2276.    pointed to by `this'.  */
  2277. tree
  2278. do_friend (ctype, declarator, decl, parmdecls, flags, quals)
  2279.      tree ctype, declarator, decl, parmdecls;
  2280.      enum overload_flags flags;
  2281.      tree quals;
  2282. {
  2283.   if (ctype)
  2284.     {
  2285.       tree cname = TYPE_NAME (ctype);
  2286.       if (TREE_CODE (cname) == TYPE_DECL)
  2287.     cname = DECL_NAME (cname);
  2288.  
  2289.       /* A method friend.  */
  2290.       if (TREE_CODE (decl) == FUNCTION_DECL)
  2291.     {
  2292.       if (flags == NO_SPECIAL && ctype && declarator == cname)
  2293.         DECL_CONSTRUCTOR_P (decl) = 1;
  2294.  
  2295.       /* This will set up DECL_ARGUMENTS for us.  */
  2296.       grokclassfn (ctype, cname, decl, flags, TYPE_SIZE (ctype) != 0, quals);
  2297.       if (TREE_TYPE (decl) != error_mark_node)
  2298.         {
  2299.           if (TYPE_SIZE (ctype))
  2300.         {
  2301.           /* We don't call pushdecl here yet, or ever on this
  2302.              actual FUNCTION_DECL.  We must preserve its TREE_CHAIN
  2303.              until the end.  */
  2304.           make_decl_rtl (decl, NULL_TREE, 1);
  2305.           add_friend (current_class_type, decl);
  2306.         }
  2307.           else
  2308.         xref_friend (current_class_type, decl, ctype);
  2309.           DECL_FRIEND_P (decl) = 1;
  2310.         }
  2311.     }
  2312.       else
  2313.     {
  2314.       /* Possibly a bunch of method friends.  */
  2315.  
  2316.       /* Get the class they belong to.  */
  2317.       tree ctype = TREE_TYPE (TREE_TYPE (cname));
  2318.  
  2319.       /* This class is defined, use its methods now.  */
  2320.       if (TYPE_SIZE (ctype))
  2321.         {
  2322.           tree fields = lookup_fnfields (CLASSTYPE_AS_LIST (ctype), declarator, 0);
  2323.           if (fields)
  2324.         add_friends (current_class_type, declarator, ctype);
  2325.           else
  2326.         error ("method `%s' is not a member of class `%s'",
  2327.                IDENTIFIER_POINTER (declarator),
  2328.                IDENTIFIER_POINTER (cname));
  2329.         }
  2330.       else
  2331.         xref_friends (current_class_type, declarator, ctype);
  2332.       decl = void_type_node;
  2333.     }
  2334.     }
  2335.   else if (TREE_CODE (decl) == FUNCTION_DECL
  2336.        && ((IDENTIFIER_LENGTH (declarator) == 4
  2337.         && IDENTIFIER_POINTER (declarator)[0] == 'm'
  2338.         && ! strcmp (IDENTIFIER_POINTER (declarator), "main"))
  2339.            || (IDENTIFIER_LENGTH (declarator) > 10
  2340.            && IDENTIFIER_POINTER (declarator)[0] == '_'
  2341.            && IDENTIFIER_POINTER (declarator)[1] == '_'
  2342.            && strncmp (IDENTIFIER_POINTER (declarator)+2,
  2343.                    "builtin_", 8) == 0)))
  2344.     {
  2345.       /* raw "main", and builtin functions never gets overloaded,
  2346.      but they can become friends.  */
  2347.       TREE_PUBLIC (decl) = 1;
  2348.       add_friend (current_class_type, decl);
  2349.       DECL_FRIEND_P (decl) = 1;
  2350.       if (IDENTIFIER_POINTER (declarator)[0] == '_')
  2351.     {
  2352.       if (! strcmp (IDENTIFIER_POINTER (declarator)+10, "new"))
  2353.         TREE_GETS_NEW (current_class_type) = 0;
  2354.       else if (! strcmp (IDENTIFIER_POINTER (declarator)+10, "delete"))
  2355.         TREE_GETS_DELETE (current_class_type) = 0;
  2356.     }
  2357.       decl = void_type_node;
  2358.     }
  2359.   /* A global friend.
  2360.      @@ or possibly a friend from a base class ?!?  */
  2361.   else if (TREE_CODE (decl) == FUNCTION_DECL)
  2362.     {
  2363.       /* Friends must all go through the overload machinery,
  2364.      even though they may not technically be overloaded.
  2365.  
  2366.      Note that because classes all wind up being top-level
  2367.      in their scope, their friend wind up in top-level scope as well.  */
  2368.       DECL_NAME (decl) =
  2369.     build_decl_overload (IDENTIFIER_POINTER (declarator),
  2370.                  TYPE_ARG_TYPES (TREE_TYPE (decl)),
  2371.                  TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
  2372.       DECL_ASSEMBLER_NAME (decl) = IDENTIFIER_POINTER (DECL_NAME (decl));
  2373.       DECL_ARGUMENTS (decl) = parmdecls;
  2374.       /* We can call pushdecl here, because the TREE_CHAIN of this
  2375.      FUNCTION_DECL is not needed for other purposes.  */
  2376.       decl = pushdecl_top_level (decl);
  2377.  
  2378.       make_decl_rtl (decl, NULL_TREE, 1);
  2379.       add_friend (current_class_type, decl);
  2380.  
  2381.       if (! TREE_OVERLOADED (declarator)
  2382.       && IDENTIFIER_GLOBAL_VALUE (declarator)
  2383.       && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (declarator)) == FUNCTION_DECL)
  2384.     {
  2385.       error ("friend `%s' implicitly overloaded",
  2386.          IDENTIFIER_POINTER (declarator));
  2387.       error_with_decl (IDENTIFIER_GLOBAL_VALUE (declarator),
  2388.                "after declaration of non-overloaded `%s'");
  2389.     }
  2390.       DECL_FRIEND_P (decl) = 1;
  2391.       DECL_OVERLOADED (decl) = 1;
  2392.       TREE_OVERLOADED (declarator) = 1;
  2393.       push_overloaded_decl (decl);
  2394.     }
  2395.   else
  2396.     {
  2397.       /* @@ Should be able to ingest later definitions of this function
  2398.      before use.  */
  2399.       tree decl = IDENTIFIER_GLOBAL_VALUE (declarator);
  2400.       if (decl == NULL_TREE)
  2401.     {
  2402.       warning ("implicitly declaring `%s' as struct",
  2403.            IDENTIFIER_POINTER (declarator));
  2404.       decl = xref_tag (record_type_node, declarator, NULL_TREE);
  2405.       decl = TYPE_NAME (decl);
  2406.     }
  2407.  
  2408.       /* Allow abbreviated declarations of overloaded functions,
  2409.      but not if those functions are really class names.  */
  2410.       if (TREE_CODE (decl) == TREE_LIST && TREE_TYPE (TREE_PURPOSE (decl)))
  2411.     {
  2412.       warning ("`friend %s' archaic, use `friend class %s' instead",
  2413.            IDENTIFIER_POINTER (declarator),
  2414.            IDENTIFIER_POINTER (declarator));
  2415.       decl = TREE_TYPE (TREE_PURPOSE (decl));
  2416.     }
  2417.  
  2418.       if (TREE_CODE (decl) == TREE_LIST)
  2419.     add_friends (current_class_type, TREE_PURPOSE (decl), NULL_TREE);
  2420.       else
  2421.     make_friend_class (current_class_type, TREE_TYPE (decl));
  2422.       decl = void_type_node;
  2423.     }
  2424.   return decl;
  2425. }
  2426.  
  2427. /* TYPE has now been defined.  It may, however, have a number of things
  2428.    waiting make make it their friend.  We resolve these references
  2429.    here.  */
  2430. void
  2431. embrace_waiting_friends (type)
  2432.      tree type;
  2433. {
  2434.   tree decl = TYPE_NAME (type);
  2435.   tree waiters;
  2436.  
  2437.   if (TREE_CODE (decl) != TYPE_DECL)
  2438.     return;
  2439.  
  2440.   for (waiters = DECL_WAITING_FRIENDS (decl); waiters;
  2441.        waiters = TREE_CHAIN (waiters))
  2442.     {
  2443.       tree waiter = TREE_PURPOSE (waiters);
  2444.       tree waiter_prev = TREE_VALUE (waiters);
  2445.       tree decl = TREE_TYPE (waiters);
  2446.       tree name = decl ? (TREE_CODE (decl) == IDENTIFIER_NODE
  2447.               ? decl : DECL_ORIGINAL_NAME (decl)) : NULL_TREE;
  2448.       if (name)
  2449.     {
  2450.       /* @@ There may be work to be done since we have not verified
  2451.          @@ consistency between original and friend declarations
  2452.          @@ of the functions waiting to become friends.  */
  2453.       tree field = lookup_fnfields (CLASSTYPE_AS_LIST (type), name, 0);
  2454.       if (field)
  2455.         if (decl == name)
  2456.           add_friends (waiter, name, type);
  2457.         else
  2458.           add_friend (waiter, decl);
  2459.       else
  2460.         error_with_file_and_line (DECL_SOURCE_FILE (TYPE_NAME (waiter)),
  2461.                       DECL_SOURCE_LINE (TYPE_NAME (waiter)),
  2462.                       "no method `%s' defined in class `%s' to be friend",
  2463.                       IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (TREE_TYPE (waiters))),
  2464.                       TYPE_NAME_STRING (type));
  2465.     }
  2466.       else
  2467.     make_friend_class (type, waiter);
  2468.  
  2469.       if (TREE_CHAIN (waiter_prev))
  2470.     TREE_CHAIN (waiter_prev) = TREE_CHAIN (TREE_CHAIN (waiter_prev));
  2471.       else
  2472.     DECL_UNDEFINED_FRIENDS (TYPE_NAME (waiter)) = NULL_TREE;
  2473.     }
  2474. }
  2475.  
  2476. /* Generate a C++ "new" expression. DECL is either a TREE_LIST
  2477.    (which needs to go through some sort of groktypename) or it
  2478.    is the name of the class we are newing. INIT is an initialization value.
  2479.    It is either an EXPRLIST, an EXPR_NO_COMMAS, or something in braces.
  2480.    If INIT is void_type_node, it means do *not* call a constructor
  2481.    for this instance.
  2482.  
  2483.    For types with constructors, the data returned is initialized
  2484.    by the approriate constructor.
  2485.  
  2486.    Whether the type has a constructor or not, if it has a pointer
  2487.    to a virtual function table, then that pointer is set up
  2488.    here.
  2489.  
  2490.    Unless I am mistaken, a call to new () will return initialized
  2491.    data regardless of whether the constructor itself is private or
  2492.    not.
  2493.  
  2494.    PLACEMENT is the `placement' list for user-defined operator new ().  */
  2495.  
  2496. tree
  2497. build_new (placement, decl, init, use_global_new)
  2498.      tree placement;
  2499.      tree decl, init;
  2500.      int use_global_new;
  2501. {
  2502.   extern tree require_complete_type ();    /* typecheck.c */
  2503.   tree type, true_type, size, rval;
  2504.   tree init1 = NULL_TREE, nelts;
  2505.   int has_call = 0, has_array = 0;
  2506.   tree alignment = NULL_TREE;
  2507.   tree pending_sizes = NULL_TREE;
  2508.  
  2509.   if (decl == error_mark_node)
  2510.     return error_mark_node;
  2511.  
  2512.   if (TREE_CODE (decl) == TREE_LIST)
  2513.     {
  2514.       tree absdcl = TREE_VALUE (decl);
  2515.       tree last_absdcl = NULL_TREE;
  2516.       int old_immediate_size_expand;
  2517.  
  2518.       if (current_function_decl
  2519.       && DECL_CONSTRUCTOR_P (current_function_decl))
  2520.     {
  2521.       old_immediate_size_expand = immediate_size_expand;
  2522.       immediate_size_expand = 0;
  2523.     }
  2524.  
  2525.       nelts = integer_one_node;
  2526.  
  2527.       if (absdcl && TREE_CODE (absdcl) == CALL_EXPR)
  2528.     {
  2529.       /* probably meant to be a call */
  2530.       has_call = 1;
  2531.       init1 = TREE_OPERAND (absdcl, 1);
  2532.       absdcl = TREE_OPERAND (absdcl, 0);
  2533.       TREE_VALUE (decl) = absdcl;
  2534.     }
  2535.       while (absdcl && TREE_CODE (absdcl) == INDIRECT_REF)
  2536.     {
  2537.       last_absdcl = absdcl;
  2538.       absdcl = TREE_OPERAND (absdcl, 0);
  2539.     }
  2540.  
  2541.       while (absdcl && TREE_CODE (absdcl) == ARRAY_REF)
  2542.     {
  2543.       /* probably meant to be a vec new */
  2544.       tree this_nelts;
  2545.  
  2546.       has_array = 1;
  2547.       this_nelts = TREE_OPERAND (absdcl, 1);
  2548.       if (this_nelts)
  2549.         this_nelts = save_expr (this_nelts);
  2550.       absdcl = TREE_OPERAND (absdcl, 0);
  2551.       if (this_nelts == NULL_TREE)
  2552.         error ("new of array type fails to specify size");
  2553.       else if (this_nelts == integer_zero_node)
  2554.         {
  2555.           warning ("zero size array reserves no space");
  2556.           nelts = integer_zero_node;
  2557.         }
  2558.       else
  2559.         nelts = build_binary_op (MULT_EXPR, nelts, this_nelts);
  2560.     }
  2561.  
  2562.       if (last_absdcl)
  2563.     TREE_OPERAND (last_absdcl, 0) = absdcl;
  2564.       else
  2565.     TREE_VALUE (decl) = absdcl;
  2566.  
  2567.       type = true_type = groktypename (decl);
  2568.       if (! type || type == error_mark_node
  2569.       || true_type == error_mark_node)
  2570.     return error_mark_node;
  2571.  
  2572.       type = TYPE_MAIN_VARIANT (type);
  2573.       if (type == void_type_node)
  2574.     {
  2575.       error ("invalid type: `void []'");
  2576.       return error_mark_node;
  2577.     }
  2578.       if (current_function_decl
  2579.       && DECL_CONSTRUCTOR_P (current_function_decl))
  2580.     {
  2581.       pending_sizes = get_pending_sizes ();
  2582.       immediate_size_expand = old_immediate_size_expand;
  2583.     }
  2584.     }
  2585.   else if (TREE_CODE (decl) == IDENTIFIER_NODE)
  2586.     {
  2587.       if (TREE_TYPE (decl))
  2588.     {
  2589.       /* An aggregate type.  */
  2590.       decl = TREE_TYPE (decl);
  2591.       type = TREE_TYPE (decl);
  2592.     }
  2593.       else
  2594.     {
  2595.       /* A builtin type.  */
  2596.       decl = lookup_name (decl);
  2597.       assert (TREE_CODE (decl) == TYPE_DECL);
  2598.       type = TREE_TYPE (decl);
  2599.     }
  2600.       true_type = type;
  2601.     }
  2602.   else if (TREE_CODE (decl) == TYPE_DECL)
  2603.     {
  2604.       type = TREE_TYPE (decl);
  2605.       true_type = type;
  2606.     }
  2607.   else
  2608.     {
  2609.       type = decl;
  2610.       true_type = type;
  2611.       decl = TYPE_NAME (type);
  2612.     }
  2613.  
  2614.   if (TYPE_SIZE (type) == 0)
  2615.     {
  2616.       if (type == void_type_node)
  2617.     error ("invalid type for new: `void'");
  2618.       else
  2619.     incomplete_type_error (0, type);
  2620.       return error_mark_node;
  2621.     }
  2622.  
  2623.   if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  2624.     {
  2625.       abstract_virtuals_error (NULL_TREE, type);
  2626.       return error_mark_node;
  2627.     }
  2628.  
  2629.   size = size_in_bytes (type);
  2630.   if (has_array)
  2631.     size = fold (build_binary_op (MULT_EXPR, size, nelts));
  2632.  
  2633.   /* If this type has special alignment requirements, deal with them here.  */
  2634.   if (TYPE_ALIGN (type) > BITS_PER_WORD)
  2635.     {
  2636.       alignment = fold (build (MINUS_EXPR, integer_type_node,
  2637.                    c_alignof (type), integer_one_node));
  2638.       size = fold (build (PLUS_EXPR, integer_type_node, size, alignment));
  2639.     }
  2640.  
  2641.   if (has_call)
  2642.     init = init1;
  2643.  
  2644.   if (TREE_CODE (true_type) == ARRAY_TYPE)
  2645.     type = TREE_TYPE (true_type);
  2646.   else
  2647.     type = true_type;
  2648.  
  2649. #ifdef SOS
  2650.   rval = NULL_TREE;
  2651.   if (placement == void_type_node)
  2652.     {
  2653.       /* Simple "new dynamic" construct.  */
  2654.       if (! IS_AGGR_TYPE (type))
  2655.     {
  2656.       error ("dynamic new can only allocate objects of aggregate type");
  2657.       return error_mark_node;
  2658.     }
  2659.       else if (! is_aggr_typedef (DECL_NAME (TYPE_NAME (type)), 1))
  2660.     return error_mark_node;
  2661.       else
  2662.     rval = build_dynamic_new (type, size, NULL_TREE, init);
  2663.     }
  2664.   else if (placement && TREE_CODE (placement) == STRING_CST)
  2665.     {
  2666.       /* A "new dynamic" construct with filename argument.  */
  2667.       if (! IS_AGGR_TYPE (type))
  2668.     {
  2669.       error ("dynamic new can only allocate objects of aggregate type");
  2670.       return error_mark_node;
  2671.     }
  2672.       else if (! is_aggr_typedef (DECL_NAME (TYPE_NAME (type)), 1))
  2673.     return error_mark_node;
  2674.       else
  2675.     rval = build_dynamic_new (type, size, placement, init);
  2676.     }
  2677.   if (rval)
  2678.     {
  2679.       if (alignment)
  2680.     {
  2681.       rval = build (PLUS_EXPR, TYPE_POINTER_TO (type), rval, alignment);
  2682.       rval = build (BIT_AND_EXPR, TYPE_POINTER_TO (type),
  2683.             rval, build1 (BIT_NOT_EXPR, integer_type_node, alignment));
  2684.     }
  2685.       goto done;
  2686.     }
  2687. #endif
  2688.  
  2689.   if (has_array)
  2690.     {
  2691.       if (placement)
  2692.     {
  2693.       error ("placement syntax invalid for arrays");
  2694.       return error_mark_node;
  2695.     }
  2696.       rval = build (CALL_EXPR, build_pointer_type (type),
  2697.             BIN, build_tree_list (NULL_TREE, size), 0);
  2698.       if (alignment)
  2699.     {
  2700.       rval = build (PLUS_EXPR, TYPE_POINTER_TO (type), rval, alignment);
  2701.       rval = build (BIT_AND_EXPR, TYPE_POINTER_TO (type),
  2702.             rval, build1 (BIT_NOT_EXPR, integer_type_node, alignment));
  2703.     }
  2704.       TREE_CALLS_NEW (rval) = 1;
  2705.       TREE_VOLATILE (rval) = 1;
  2706.     }
  2707.   else
  2708.     {
  2709.       if (TYPE_LANG_SPECIFIC (type)
  2710.       && (TREE_GETS_NEW (type) && !use_global_new))
  2711.     rval = build_opfncall (NEW_EXPR, LOOKUP_NORMAL, TYPE_POINTER_TO (type), size, placement);
  2712.       else if (placement)
  2713.     {
  2714.       rval = build_opfncall (NEW_EXPR, LOOKUP_GLOBAL|LOOKUP_COMPLAIN, ptr_type_node, size, placement);
  2715.     }
  2716.       else if (flag_this_is_variable
  2717.            && TYPE_HAS_CONSTRUCTOR (type) && init != void_type_node)
  2718.     {
  2719.       if (init == NULL_TREE || TREE_CODE (init) == TREE_LIST)
  2720.         rval = NULL_TREE;
  2721.       else
  2722.         {
  2723.           error ("constructors take parameter lists");
  2724.           return error_mark_node;
  2725.         }
  2726.     }
  2727.       else
  2728.     {
  2729.       rval = build (CALL_EXPR, build_pointer_type (type),
  2730.             BIN, build_tree_list (NULL_TREE, size), 0);
  2731.       if (alignment)
  2732.         {
  2733.           rval = build (PLUS_EXPR, TYPE_POINTER_TO (type), rval, alignment);
  2734.           rval = build (BIT_AND_EXPR, TYPE_POINTER_TO (type),
  2735.                 rval, build1 (BIT_NOT_EXPR, integer_type_node, alignment));
  2736.         }
  2737.       TREE_CALLS_NEW (rval) = 1;
  2738.       TREE_VOLATILE (rval) = 1;
  2739.     }
  2740.       /* We've figured out where the allocation is to go.
  2741.      If we're not eliding constructors, then if a constructor
  2742.      is defined, we must go through it.  */
  2743.       if ((rval == NULL_TREE || !flag_elide_constructors)
  2744.       && TYPE_HAS_CONSTRUCTOR (type) && init != void_type_node)
  2745.     {
  2746.       int flags = LOOKUP_NORMAL;
  2747.  
  2748.       if (rval && TYPE_USES_VIRTUAL_BASECLASSES (type))
  2749.         {
  2750.           init = tree_cons (NULL_TREE, integer_one_node, init);
  2751.           flags |= LOOKUP_HAS_IN_CHARGE;
  2752.         }
  2753.       rval = build_method_call (rval, DECL_NAME (TYPE_NAME (type)), init,
  2754.                     NULL_TREE, flags);
  2755.       goto done;
  2756.     }
  2757.     }
  2758.   if (rval == error_mark_node)
  2759.     return error_mark_node;
  2760.   rval = save_expr (rval);
  2761.   TREE_HAS_CONSTRUCTOR (rval) = 1;
  2762.  
  2763.   /* Don't call any constructors or do any initialization.  */
  2764.   if (init == void_type_node)
  2765.     goto done;
  2766.  
  2767.   if (TYPE_NEEDS_CONSTRUCTING (type))
  2768.     {
  2769.       extern tree static_aggregates;
  2770.  
  2771.       if (current_function_decl == NULL_TREE)
  2772.     {
  2773.       /* In case of static initialization, SAVE_EXPR is good enough.  */
  2774.       init = copy_to_permanent (init);
  2775.       rval = copy_to_permanent (rval);
  2776.       static_aggregates = perm_tree_cons (init, rval, static_aggregates);
  2777.     }
  2778.       else
  2779.     {
  2780.       /* Have to wrap this in RTL_EXPR for two cases:
  2781.          in base or member initialization and if we
  2782.          are a branch of a ?: operator.  Since we
  2783.          can't easily know the latter, just do it always.  */
  2784.       tree xval = make_node (RTL_EXPR);
  2785.  
  2786.       TREE_TYPE (xval) = TREE_TYPE (rval);
  2787.       do_pending_stack_adjust ();
  2788.       start_sequence ();
  2789.  
  2790.       /* As a matter of principle, `start_sequence' should do this.  */
  2791.       emit_note (0, -1);
  2792.  
  2793.       if (has_array)
  2794.         rval = expand_vec_init (decl, rval,
  2795.                     build_binary_op (MINUS_EXPR, nelts, integer_one_node),
  2796.                     init, 0);
  2797.       else
  2798.         expand_aggr_init (build_indirect_ref (rval, 0), init, 0);
  2799.  
  2800.       do_pending_stack_adjust ();
  2801.  
  2802.       TREE_VOLATILE (xval) = 1;
  2803.       RTL_EXPR_SEQUENCE (xval) = get_insns ();
  2804.       end_sequence ();
  2805.  
  2806.       if (TREE_CODE (rval) == SAVE_EXPR)
  2807.         {
  2808.           /* Errors may cause this to not get evaluated.  */
  2809.           if (SAVE_EXPR_RTL (rval) == 0)
  2810.         SAVE_EXPR_RTL (rval) = const0_rtx;
  2811.           RTL_EXPR_RTL (xval) = SAVE_EXPR_RTL (rval);
  2812.         }
  2813.       else
  2814.         {
  2815.           assert (TREE_CODE (rval) == VAR_DECL);
  2816.           RTL_EXPR_RTL (xval) = DECL_RTL (rval);
  2817.         }
  2818.       rval = xval;
  2819.     }
  2820.     }
  2821.   else if (has_call || init)
  2822.     {
  2823.       if (IS_AGGR_TYPE (type))
  2824.     {
  2825.       error_with_aggr_type (type, "no constructor for type `%s'");
  2826.       rval = error_mark_node;
  2827.     }
  2828.       else
  2829.     {
  2830.       /* New 2.0 interpretation: `new int (10)' means
  2831.          allocate an int, and initialize it with 10.  */
  2832.       init = build_c_cast (type, init);
  2833.       rval = build (COMPOUND_EXPR, TREE_TYPE (rval),
  2834.             build_modify_expr (build_indirect_ref (rval, 0),
  2835.                        NOP_EXPR, init),
  2836.             rval);
  2837.       TREE_VOLATILE (rval) = 1;
  2838.     }
  2839.     }
  2840.  done:
  2841.   if (pending_sizes)
  2842.     rval = build_compound_expr (chainon (pending_sizes,
  2843.                      build_tree_list (NULL_TREE, rval)));
  2844.  
  2845.   return rval;
  2846. }
  2847.  
  2848. #ifdef SOS
  2849. /* Build a "new dynamic" call for type TYPE.  The size
  2850.    of the object we are newing is SIZE.  If "new dynamic" was
  2851.    given with an argument, that argument is in NAME.
  2852.    PARMS contains the parameters to the constructor.
  2853.    The first parameter must be an `ImportRequest *'.
  2854.  
  2855.    This is slightly hairy, because we must find the correct
  2856.    constructor by hand.  */
  2857. static tree
  2858. build_dynamic_new (type, size, name, parms)
  2859.      tree type, size;
  2860.      tree name, parms;
  2861. {
  2862.   tree import_parms, inner_parms;
  2863.   tree import_ptr = integer_zero_node;
  2864.   /* This variable is supposed to be the address of a "struct ref"
  2865.      object, but how and where should it be defined?  */
  2866.   tree lookup_tmp = integer_zero_node;
  2867.   tree import_tmp = build_unary_op (ADDR_EXPR, get_temp_name (ptr_type_node, 0), 0);
  2868.  
  2869.   if (name)
  2870.     {
  2871.       inner_parms = tree_cons (NULL_TREE, name,
  2872.                    build_tree_list (NULL_TREE, integer_zero_node));
  2873.       inner_parms = tree_cons (NULL_TREE, lookup_tmp, inner_parms);
  2874.       inner_parms = build_function_call (__sosLookup, inner_parms);
  2875.     }
  2876.   else
  2877.     inner_parms = integer_zero_node;
  2878.  
  2879.   import_parms = build_tree_list (NULL_TREE, inner_parms);
  2880.  
  2881.   if (CLASSTYPE_DYNAMIC_FILENAME (type))
  2882.     {
  2883.       inner_parms = tree_cons (NULL_TREE, CLASSTYPE_DYNAMIC_FILENAME (type),
  2884.                    build_tree_list (NULL_TREE, integer_zero_node));
  2885.       inner_parms = tree_cons (NULL_TREE, lookup_tmp, inner_parms);
  2886.       inner_parms = build_function_call (__sosLookup, inner_parms);
  2887.     }
  2888.   else
  2889.     inner_parms = integer_zero_node;
  2890.  
  2891.   import_parms = tree_cons (NULL_TREE, inner_parms, import_parms);
  2892.   import_parms = tree_cons (NULL_TREE, CLASSTYPE_TYPENAME_AS_STRING (type), import_parms);
  2893.   /* This is one parameter which could be (but should not be) evaluated twice.  */
  2894.   TREE_VALUE (parms) = save_expr (TREE_VALUE (parms));
  2895.  
  2896.   import_parms = tree_cons (NULL_TREE, TREE_VALUE (parms), import_parms);
  2897.  
  2898.   /* SOS?? Pass the address of a temporary which can hold the pointer
  2899.      to dynamic class table, but how and where is it defined? */
  2900.   import_parms = tree_cons (NULL_TREE, import_tmp, import_parms);
  2901.  
  2902.   import_ptr = build_function_call (__sosImport, import_parms);
  2903.  
  2904.   /* SOS?? Now, generate call to ctor, but using `import_ptr' as the function
  2905.      table.  Return the result of the call to the ctor.  */
  2906.   import_ptr = build1 (NOP_EXPR, TYPE_POINTER_TO (type), import_ptr);
  2907.   return build_method_call (import_ptr, DECL_NAME (TYPE_NAME (type)),
  2908.                 tree_cons (NULL_TREE, import_tmp, parms),
  2909.                 NULL_TREE, LOOKUP_DYNAMIC);
  2910. }
  2911.  
  2912. /* Return the name of the link table (as an IDENTIFIER_NODE)
  2913.    for the given TYPE.  */
  2914. tree
  2915. get_linktable_name (type)
  2916.      tree type;
  2917. {
  2918.   char *buf = (char *)alloca (4 + TYPE_NAME_LENGTH (type) + 1);
  2919.   tree name;
  2920.  
  2921.   assert (TYPE_DYNAMIC (type));
  2922.   sprintf (buf, "ZN_%s_", TYPE_NAME_STRING (type));
  2923.   return get_identifier (buf);
  2924. }
  2925.  
  2926. /* For a given type TYPE, grovel for a function table which
  2927.    can be used to support dynamic linking.  */
  2928. tree
  2929. get_sos_dtable (type, parms)
  2930.      tree type, parms;
  2931. {
  2932.   tree classname = CLASSTYPE_TYPENAME_AS_STRING (type);
  2933.   tree filename = CLASSTYPE_DYNAMIC_FILENAME (type);
  2934.   tree dyn_vtbl;
  2935.   /* This variable is supposed to be the address of a "struct ref"
  2936.      object, but how and where should it be defined?  */
  2937.   tree lookup_tmp = integer_zero_node;
  2938.  
  2939.   assert (TYPE_DYNAMIC (type));
  2940.  
  2941.   if (filename)
  2942.     {
  2943.       tree inner_parms = tree_cons (NULL_TREE, filename,
  2944.                     build_tree_list (NULL_TREE, integer_zero_node));
  2945.       inner_parms = tree_cons (NULL_TREE, lookup_tmp, inner_parms);
  2946.       parms = build_tree_list (NULL_TREE, build_function_call (__sosLookup, inner_parms));
  2947.     }
  2948.   else
  2949.     parms = build_tree_list (NULL_TREE, integer_zero_node);
  2950.  
  2951.   parms = tree_cons (NULL_TREE, classname, parms);
  2952.  
  2953.   dyn_vtbl = build_function_call (__sosFindCode, parms);
  2954.   TREE_TYPE (dyn_vtbl) = build_pointer_type (ptr_type_node);
  2955.   return dyn_vtbl;
  2956. }
  2957. #endif
  2958.  
  2959. /* `expand_vec_init' performs initialization of a vector of aggregate
  2960.    types.
  2961.  
  2962.    DECL is passed only for error reporting, and provides line number
  2963.    and source file name information.
  2964.    BASE is the space where the vector will be.
  2965.    MAXINDEX is the maximum index of the array (one less than the
  2966.         number of elements).
  2967.    INIT is the (possibly NULL) initializer.
  2968.  
  2969.    FROM_ARRAY is 0 if we should init everything with INIT
  2970.    (i.e., every element initialized from INIT).
  2971.    FROM_ARRAY is 1 if we should index into INIT in parallel
  2972.    with initialization of DECL.
  2973.    FROM_ARRAY is 2 if we should index into INIT in parallel,
  2974.    but use assignment instead of initialization.  */
  2975.  
  2976. tree
  2977. expand_vec_init (decl, base, maxindex, init, from_array)
  2978.      tree decl, base, maxindex, init;
  2979. {
  2980.   tree rval;
  2981.   tree iterator, base2 = NULL_TREE;
  2982.   tree type = TREE_TYPE (TREE_TYPE (base));
  2983.   tree size;
  2984.  
  2985.   maxindex = convert (integer_type_node, maxindex);
  2986.   if (maxindex == error_mark_node)
  2987.     return error_mark_node;
  2988.  
  2989.   if (current_function_decl == NULL_TREE)
  2990.     {
  2991.       rval = make_tree_vec (3);
  2992.       TREE_VEC_ELT (rval, 0) = base;
  2993.       TREE_VEC_ELT (rval, 1) = maxindex;
  2994.       TREE_VEC_ELT (rval, 2) = init;
  2995.       return rval;
  2996.     }
  2997.  
  2998.   size = size_in_bytes (type);
  2999.  
  3000.   /* Set to zero in case size is <= 0.  Optimizer will delete this if
  3001.      it is not needed.  */
  3002.   rval = get_temp_regvar (TYPE_POINTER_TO (type), null_pointer_node);
  3003.   base = default_conversion (base);
  3004.   expand_assignment (rval, base, 0, 0);
  3005.   base = get_temp_regvar (TYPE_POINTER_TO (type), base);
  3006.  
  3007.   if (init != NULL_TREE
  3008.       && TREE_CODE (init) == CONSTRUCTOR
  3009.       && TREE_TYPE (init) == TREE_TYPE (decl))
  3010.     {
  3011.       /* Initialization of array from {...}.  */
  3012.       tree elts = CONSTRUCTOR_ELTS (init);
  3013.       tree baseref = build1 (INDIRECT_REF, type, base);
  3014.       tree baseinc = build (PLUS_EXPR, TYPE_POINTER_TO (type), base, size);
  3015.       int host_i = TREE_INT_CST_LOW (maxindex);
  3016.  
  3017.       if (IS_AGGR_TYPE (type))
  3018.     {
  3019.       while (elts)
  3020.         {
  3021.           host_i -= 1;
  3022.           expand_aggr_init (baseref, TREE_VALUE (elts), 0);
  3023.  
  3024.           expand_assignment (base, baseinc, 0, 0);
  3025.           elts = TREE_CHAIN (elts);
  3026.         }
  3027.       /* Initialize any elements by default if possible.  */
  3028.       if (host_i >= 0)
  3029.         {
  3030.           if (TYPE_NEEDS_CONSTRUCTING (type) == 0)
  3031.         {
  3032.           if (obey_regdecls)
  3033.             use_variable (DECL_RTL (base));
  3034.           goto done_init;
  3035.         }
  3036.  
  3037.           iterator = get_temp_regvar (integer_type_node,
  3038.                       build_int_2 (host_i, 0));
  3039.           init = NULL_TREE;
  3040.           goto init_by_default;
  3041.         }
  3042.     }
  3043.       else
  3044.     while (elts)
  3045.       {
  3046.         expand_assignment (baseref, TREE_VALUE (elts), 0, 0);
  3047.  
  3048.         expand_assignment (base, baseinc, 0, 0);
  3049.         elts = TREE_CHAIN (elts);
  3050.       }
  3051.  
  3052.       if (obey_regdecls)
  3053.     use_variable (DECL_RTL (base));
  3054.     }
  3055.   else
  3056.     {
  3057.       iterator = get_temp_regvar (integer_type_node, maxindex);
  3058.  
  3059.     init_by_default:
  3060.  
  3061.       /* If initializing one array from another,
  3062.      initialize element by element.  */
  3063.       if (from_array)
  3064.     {
  3065.       if (decl == NULL_TREE
  3066.           || (init && TREE_TYPE (init) != TREE_TYPE (decl)))
  3067.         {
  3068.           sorry ("initialization of array from dissimilar array type");
  3069.           return error_mark_node;
  3070.         }
  3071.       if (init)
  3072.         {
  3073.           base2 = default_conversion (init);
  3074.           base2 = get_temp_regvar (TYPE_POINTER_TO (type), base2);
  3075.         }
  3076.       else if (TYPE_LANG_SPECIFIC (type)
  3077.            && TYPE_NEEDS_CONSTRUCTING (type)
  3078.            && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
  3079.         {
  3080.           error ("initializer ends prematurely");
  3081.           return;
  3082.         }
  3083.     }
  3084.  
  3085.       expand_start_cond (build (GE_EXPR, integer_type_node,
  3086.                 iterator, integer_zero_node), 0);
  3087.       expand_start_loop_continue_elsewhere (1);
  3088.  
  3089.       if (from_array)
  3090.     {
  3091.       tree to = build1 (INDIRECT_REF, type, base);
  3092.       tree from;
  3093.  
  3094.       if (base2)
  3095.         from = build1 (INDIRECT_REF, type, base2);
  3096.       else
  3097.         from = NULL_TREE;
  3098.  
  3099.       if (from_array == 2)
  3100.         expand_expr_stmt (build_modify_expr (to, NOP_EXPR, from));
  3101.       else if (TYPE_NEEDS_CONSTRUCTING (type))
  3102.         expand_aggr_init (to, from, 0);
  3103.       else if (from)
  3104.         expand_assignment (to, from, 0, 0);
  3105.       else abort ();
  3106.     }
  3107.       else if (TREE_CODE (type) == ARRAY_TYPE)
  3108.     {
  3109.       if (init != 0)
  3110.         sorry ("cannot initialize multi-dimensional array with initializer");
  3111.       expand_vec_init (decl, build1 (NOP_EXPR, TYPE_POINTER_TO (TREE_TYPE (type)), base),
  3112.                array_type_nelts (type), 0, 0);
  3113.     }
  3114.       else
  3115.     expand_aggr_init (build1 (INDIRECT_REF, type, base), init, 0);
  3116.  
  3117.       expand_assignment (base,
  3118.              build (PLUS_EXPR, TYPE_POINTER_TO (type), base, size),
  3119.              0, 0);
  3120.       if (base2)
  3121.     expand_assignment (base2,
  3122.                build (PLUS_EXPR, TYPE_POINTER_TO (type), base2, size), 0, 0);
  3123.       expand_loop_continue_here ();
  3124.       expand_exit_loop_if_false (build (NE_EXPR, integer_type_node,
  3125.                     build (PREDECREMENT_EXPR, integer_type_node, iterator, integer_one_node), minus_one));
  3126.  
  3127.       if (obey_regdecls)
  3128.     {
  3129.       use_variable (DECL_RTL (base));
  3130.       if (base2)
  3131.         use_variable (DECL_RTL (base2));
  3132.     }
  3133.       expand_end_loop ();
  3134.       expand_end_cond ();
  3135.       if (obey_regdecls)
  3136.     use_variable (DECL_RTL (iterator));
  3137.     }
  3138.  done_init:
  3139.  
  3140.   if (obey_regdecls)
  3141.     use_variable (DECL_RTL (rval));
  3142.   return rval;
  3143. }
  3144.  
  3145. /* Free up storage of type TYPE, at address ADDR.
  3146.    TYPE is a POINTER_TYPE.
  3147.  
  3148.    This does not call any destructors.  */
  3149. tree
  3150. build_x_delete (type, addr, use_global_delete)
  3151.      tree type, addr;
  3152.      int use_global_delete;
  3153. {
  3154.   tree rval;
  3155.  
  3156.   if (!use_global_delete
  3157.       && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  3158.       && TREE_GETS_DELETE (TREE_TYPE (type)))
  3159.     rval = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr);
  3160.   else
  3161.     {
  3162.       rval = build (CALL_EXPR, void_type_node, BID,
  3163.             build_tree_list (NULL_TREE, addr), 0);
  3164.       TREE_VOLATILE (rval) = 1;
  3165.     }
  3166.   return rval;
  3167. }
  3168.  
  3169. /* Generate a call to a destructor. TYPE is the type to cast ADDR to.
  3170.    ADDR is an expression which yields the store to be destroyed.
  3171.    AUTO_DELETE is nonzero if a call to DELETE should be made or not.
  3172.    If in the program, (AUTO_DELETE & 2) is non-zero, we tear down the
  3173.    virtual baseclasses.
  3174.    If in the program, (AUTO_DELETE & 1) is non-zero, then we deallocate.
  3175.  
  3176.    FLAGS is the logical disjunction of zero or more LOOKUP_
  3177.    flags.  See cplus-tree.h for more info.
  3178.  
  3179.    This function does not delete an object's virtual base classes.  */
  3180. tree
  3181. build_delete (type, addr, auto_delete, flags, use_global_delete)
  3182.      tree type, addr;
  3183.      tree auto_delete;
  3184.      int flags;
  3185.      int use_global_delete;
  3186. {
  3187.   tree function, parms;
  3188.   tree member;
  3189.   tree expr;
  3190.   tree ref;
  3191.   int ptr;
  3192.  
  3193.   if (addr == error_mark_node)
  3194.     return error_mark_node;
  3195.  
  3196.   /* Can happen when CURRENT_EXCEPTION_OBJECT gets its type
  3197.      set to `error_mark_node' before it gets properly cleaned up.  */
  3198.   if (type == error_mark_node)
  3199.     return error_mark_node;
  3200.  
  3201.   type = TYPE_MAIN_VARIANT (type);
  3202.  
  3203.   if (TREE_CODE (type) == POINTER_TYPE)
  3204.     {
  3205.       type = TREE_TYPE (type);
  3206.       if (TYPE_SIZE (type) == 0)
  3207.     {
  3208.       incomplete_type_error (0, type);
  3209.       return error_mark_node;
  3210.     }
  3211.       if (! IS_AGGR_TYPE (type))
  3212.     {
  3213.       expr = build (CALL_EXPR, void_type_node,
  3214.             BID, build_tree_list (NULL_TREE, addr), 0);
  3215.       TREE_VOLATILE (expr) = 1;
  3216.       return expr;
  3217.     }
  3218.       if (TREE_VOLATILE (addr))
  3219.     addr = save_expr (addr);
  3220.       ref = build_indirect_ref (addr, 0);
  3221.       ptr = 1;
  3222.     }
  3223.   else if (TREE_CODE (type) == ARRAY_TYPE)
  3224.     {
  3225.       if (TREE_VOLATILE (addr))
  3226.     addr = save_expr (addr);
  3227.       return build_vec_delete (addr, array_type_nelts (type), c_sizeof (TREE_TYPE (type)),
  3228.                    NULL_TREE, auto_delete, integer_two_node);
  3229.     }
  3230.   else
  3231.     {
  3232.       /* Don't check PROTECT here; leave that decision to the
  3233.      destructor.  If the destructor is visible, call it,
  3234.      else report error.  */
  3235.       addr = build_unary_op (ADDR_EXPR, addr, 0);
  3236.       if (TREE_VOLATILE (addr))
  3237.     addr = save_expr (addr);
  3238.  
  3239.       if (TREE_LITERAL (addr))
  3240.     addr = convert_pointer_to (type, addr);
  3241.       else
  3242.     addr = convert_force (build_pointer_type (type), addr);
  3243.  
  3244.       if (TREE_CODE (addr) == NOP_EXPR
  3245.       && TREE_OPERAND (addr, 0) == current_class_decl)
  3246.     ref = C_C_D;
  3247.       else
  3248.     ref = build_indirect_ref (addr, 0);
  3249.       ptr = 0;
  3250.     }
  3251.  
  3252.   assert (IS_AGGR_TYPE (type));
  3253.  
  3254.   if (! TYPE_NEEDS_DESTRUCTOR (type))
  3255.     {
  3256.       if (auto_delete == integer_zero_node)
  3257.     return build1 (NOP_EXPR, void_type_node, integer_zero_node);
  3258.       else if (TREE_GETS_DELETE (type) && !use_global_delete)
  3259.     return build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr);
  3260.       parms = build_tree_list (NULL_TREE, addr);
  3261.       expr = build (CALL_EXPR, void_type_node, BID, parms, 0);
  3262.       TREE_VOLATILE (expr) = 1;
  3263.       return expr;
  3264.     }
  3265.   parms = build_tree_list (NULL_TREE, addr);
  3266.  
  3267.   /* Below, we will reverse the order in which these calls are made.
  3268.      If we have a destructor, then that destructor will take care
  3269.      of the base classes; otherwise, we must do that here.  */
  3270.   if (TYPE_HAS_DESTRUCTOR (type))
  3271.     {
  3272.       tree field = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 0);
  3273.       tree basetypes = CLASSTYPE_AS_LIST (type);
  3274.  
  3275.       if (flags & LOOKUP_PROTECT)
  3276.     {
  3277.       enum visibility_type visibility = compute_visibility (basetypes, field);
  3278.  
  3279.       if (visibility == visibility_private)
  3280.         {
  3281.           if (flags & LOOKUP_COMPLAIN)
  3282.         error_with_aggr_type (type, "destructor for type `%s' is private in this scope");
  3283.           return error_mark_node;
  3284.         }
  3285.       else if (visibility == visibility_protected
  3286.            && (flags & LOOKUP_PROTECTED_OK) == 0)
  3287.         {
  3288.           if (flags & LOOKUP_COMPLAIN)
  3289.         error_with_aggr_type (type, "destructor for type `%s' is protected in this scope");
  3290.           return error_mark_node;
  3291.         }
  3292.     }
  3293.  
  3294.       /* Once we are in a destructor, try not going through
  3295.      the virtual function table to find the next destructor.  */
  3296.       if (DECL_VIRTUAL_P (field)
  3297.       && ! (flags & LOOKUP_NONVIRTUAL)
  3298.       && TREE_CODE (auto_delete) != PARM_DECL
  3299.       && (ptr == 1 || ! resolves_to_fixed_type_p (ref)))
  3300.     {
  3301.       /* This destructor must be called via virtual function table.  */
  3302.       field = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (DECL_VCONTEXT (field)), 0);
  3303.       expr = convert_pointer_to (DECL_CONTEXT (field), TREE_VALUE (parms));
  3304.       if (expr != TREE_VALUE (parms))
  3305.         {
  3306.           ref = build_indirect_ref (expr, 0);
  3307.           TREE_VALUE (parms) = expr;
  3308.         }
  3309.       function = build_vfn_ref (&TREE_VALUE (parms), ref, DECL_VINDEX (field));
  3310.       if (function == error_mark_node)
  3311.         return error_mark_node;
  3312.       TREE_TYPE (function) = build_pointer_type (TREE_TYPE (field));
  3313.       TREE_CHAIN (parms) = build_tree_list (NULL_TREE, auto_delete);
  3314.       expr = build_function_call (function, parms);
  3315.       if (ptr && (flags & LOOKUP_DESTRUCTOR) == 0)
  3316.         {
  3317.           /* Handle the case where a virtual destructor is
  3318.          being called on an item that is 0.
  3319.  
  3320.          @@ Does this really need to be done?  */
  3321.           tree ifexp = build_binary_op (NE_EXPR, addr, integer_zero_node);
  3322. #if 0
  3323.           if (TREE_CODE (ref) == VAR_DECL
  3324.           || TREE_CODE (ref) == COMPONENT_REF)
  3325.         warning ("losing in build_delete");
  3326. #endif
  3327.           expr = build (COND_EXPR, void_type_node,
  3328.                 ifexp, expr,
  3329.                 build1 (NOP_EXPR, void_type_node, integer_zero_node));
  3330.         }
  3331.     }
  3332.       else
  3333.     {
  3334.       tree ifexp;
  3335.  
  3336.       if ((flags & LOOKUP_DESTRUCTOR)
  3337.           || TREE_CODE (ref) == VAR_DECL
  3338.           || TREE_CODE (ref) == PARM_DECL
  3339.           || TREE_CODE (ref) == COMPONENT_REF
  3340.           || TREE_CODE (ref) == ARRAY_REF)
  3341.         /* These can't be 0.  */
  3342.         ifexp = integer_one_node;
  3343.       else
  3344.         /* Handle the case where a non-virtual destructor is
  3345.            being called on an item that is 0.  */
  3346.         ifexp = build_binary_op (NE_EXPR, addr, integer_zero_node);
  3347.  
  3348.       function = field;
  3349.  
  3350.       /* Used to mean that this destructor was known to be empty,
  3351.          but that's now obsolete.  */
  3352.       assert (DECL_INITIAL (function) != void_type_node);
  3353.  
  3354.       TREE_CHAIN (parms) = build_tree_list (NULL_TREE, auto_delete);
  3355.       expr = build_function_call (function, parms);
  3356.  
  3357.       if (ifexp != integer_one_node)
  3358.         expr = build (COND_EXPR, void_type_node,
  3359.               ifexp, expr,
  3360.               build1 (NOP_EXPR, void_type_node, integer_zero_node));
  3361.     }
  3362.       return expr;
  3363.     }
  3364.   else
  3365.     {
  3366.       /* This can get visibilties wrong.  */
  3367.       int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (type);
  3368.       tree basetype = n_baseclasses > 0 ? CLASSTYPE_BASECLASS (type, 1) : NULL_TREE;
  3369.       tree exprstmt = NULL_TREE;
  3370.       tree parent_auto_delete = auto_delete;
  3371.       tree cond;
  3372.  
  3373.       /* If this type does not have a destructor, but does have
  3374.      operator delete, call the parent parent destructor (if any),
  3375.      but let this node do the deleting.  Otherwise, it is ok
  3376.      to let the parent destructor do the deleting.  */
  3377.       if (TREE_GETS_DELETE (type) && !use_global_delete)
  3378.     {
  3379.       parent_auto_delete = integer_zero_node;
  3380.       if (auto_delete == integer_zero_node)
  3381.         cond = NULL_TREE;
  3382.       else
  3383.         {
  3384.           expr = build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, addr);
  3385.           if (expr == error_mark_node)
  3386.         return error_mark_node;
  3387.           if (auto_delete != integer_one_node)
  3388.         cond = build (COND_EXPR, void_type_node,
  3389.                   build (BIT_AND_EXPR, integer_type_node, auto_delete, integer_one_node),
  3390.                   expr,
  3391.                   build1 (NOP_EXPR, void_type_node, integer_zero_node));
  3392.           else cond = expr;
  3393.         }
  3394.     }
  3395.       else if (basetype == NULL_TREE
  3396.            || (CLASSTYPE_VIA_VIRTUAL (type, 1) == 0
  3397.            && ! TYPE_NEEDS_DESTRUCTOR (basetype)))
  3398.     {
  3399.       cond = build (COND_EXPR, void_type_node,
  3400.             build (BIT_AND_EXPR, integer_type_node, auto_delete, integer_one_node),
  3401.             build_function_call (BID, build_tree_list (NULL_TREE, addr)),
  3402.             build1 (NOP_EXPR, void_type_node, integer_zero_node));
  3403.     }
  3404.       else cond = NULL_TREE;
  3405.  
  3406.       if (cond)
  3407.     exprstmt = build_tree_list (NULL_TREE, cond);
  3408.  
  3409.       if (basetype
  3410.       && ! CLASSTYPE_VIA_VIRTUAL (type, 1)
  3411.       && TYPE_NEEDS_DESTRUCTOR (basetype))
  3412.     {
  3413.       tree this_auto_delete;
  3414.  
  3415.       if (CLASSTYPE_OFFSET (basetype) == integer_zero_node)
  3416.         this_auto_delete = parent_auto_delete;
  3417.       else
  3418.         this_auto_delete = integer_zero_node;
  3419.  
  3420.       expr = build_delete (TYPE_POINTER_TO (basetype), addr,
  3421.                    this_auto_delete, flags|LOOKUP_PROTECTED_OK, 0);
  3422.       exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
  3423.     }
  3424.  
  3425.       for (i = 2; i <= n_baseclasses; i++)
  3426.     {
  3427.       basetype = CLASSTYPE_BASECLASS (type, i);
  3428.       if (! TYPE_NEEDS_DESTRUCTOR (basetype)
  3429.           || CLASSTYPE_VIA_VIRTUAL (type, i))
  3430.         continue;
  3431.  
  3432.       /* May be zero offset if other baseclasses are virtual.  */
  3433.       expr = fold (build (PLUS_EXPR, TYPE_POINTER_TO (basetype),
  3434.                   addr, CLASSTYPE_OFFSET (basetype)));
  3435.  
  3436.       expr = build_delete (TYPE_POINTER_TO (basetype), expr,
  3437.                    integer_zero_node,
  3438.                    flags|LOOKUP_PROTECTED_OK, 0);
  3439.  
  3440.       exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
  3441.     }
  3442.  
  3443.       for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
  3444.     {
  3445.       if (TREE_CODE (member) != FIELD_DECL)
  3446.         continue;
  3447.       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (member)))
  3448.         {
  3449.           tree this_member = build_component_ref (ref, DECL_NAME (member), 0, 0);
  3450.           tree this_type = TREE_TYPE (member);
  3451.           expr = build_delete (this_type, this_member, integer_two_node, flags, 0);
  3452.           exprstmt = tree_cons (NULL_TREE, expr, exprstmt);
  3453.         }
  3454.     }
  3455.  
  3456.       if (exprstmt)
  3457.     return build_compound_expr (exprstmt);
  3458.       /* Virtual base classes make this function do nothing.  */
  3459.       return build1 (NOP_EXPR, void_type_node, integer_zero_node);
  3460.     }
  3461. }
  3462.  
  3463. /* For type TYPE, delete the virtual baseclass objects of DECL.  */
  3464.  
  3465. tree
  3466. build_vbase_delete (type, decl)
  3467.      tree type, decl;
  3468. {
  3469.   tree vbases = CLASSTYPE_VBASECLASSES (type);
  3470.   tree result = NULL_TREE;
  3471.   tree addr = build_unary_op (ADDR_EXPR, decl, 0);
  3472.   assert (addr != error_mark_node);
  3473.   while (vbases)
  3474.     {
  3475.       tree this_addr = convert_force (TYPE_POINTER_TO (TREE_VALUE (vbases)), addr);
  3476.       result = tree_cons (NULL_TREE,
  3477.               build_delete (TREE_TYPE (this_addr), this_addr,
  3478.                     integer_zero_node, LOOKUP_NORMAL, 0),
  3479.               result);
  3480.       vbases = TREE_CHAIN (vbases);
  3481.     }
  3482.   return build_compound_expr (nreverse (result));
  3483. }
  3484.  
  3485. /* Build a C++ vector delete expression.
  3486.    MAXINDEX is the number of elements to be deleted.
  3487.    ELT_SIZE is the nominal size of each element in the vector.
  3488.    BASE is the expression that should yield the store to be deleted.
  3489.    DTOR_DUMMY is a placeholder for a destructor.  The library function
  3490.    __builtin_vec_delete has a pointer to function in this position.
  3491.    This function expands (or synthesizes) these calls itself.
  3492.    AUTO_DELETE_VEC says whether the container (vector) should be deallocated.
  3493.    AUTO_DELETE say whether each item in the container should be deallocated.
  3494.  
  3495.    This also calls delete for virtual baseclasses of elements of the vector.  */
  3496. tree
  3497. build_vec_delete (base, maxindex, elt_size, dtor_dummy, auto_delete_vec, auto_delete)
  3498.      tree base, maxindex, elt_size;
  3499.      tree dtor_dummy;
  3500.      tree auto_delete_vec, auto_delete;
  3501. {
  3502.   tree ptype = TREE_TYPE (base);
  3503.   tree type;
  3504.   tree rval;
  3505.   /* Temporary variables used by the loop.  */
  3506.   tree iterator, tbase;
  3507.   tree size_exp;
  3508.  
  3509.   /* This is the body of the loop that implements the deletion of a
  3510.      single element, and moves temp variables to next elements.  */
  3511.   tree body;
  3512.  
  3513.   /* This is the LOOP_STMT that governs the deletetion of the elements.  */
  3514.   tree loop;
  3515.  
  3516.   /* This is the IF_STMT that governs whether the loop is executed at all.  */
  3517.   tree if_stmt;
  3518.  
  3519.   /* This is the ELSE_STMT that governs what to do after the loop has run.  */
  3520.   tree else_stmt = 0;
  3521.  
  3522.   /* This is the LET_STMT which holds the outermost iterator of the
  3523.      loop.  It is convenient to set this variable up and test it before
  3524.      executing any other code in the loop.  */
  3525.   tree block;
  3526.  
  3527.   if (TREE_CODE (ptype) == POINTER_TYPE)
  3528.     {
  3529.       if (maxindex == 0)
  3530.     {
  3531.       error ("must specify size for non array type");
  3532.       return error_mark_node;
  3533.     }
  3534.       maxindex = convert (integer_type_node, maxindex);
  3535.       if (maxindex == error_mark_node)
  3536.     return error_mark_node;
  3537.     }
  3538.   else if (TREE_CODE (ptype) == ARRAY_TYPE)
  3539.     {
  3540.       tree amaxindex = array_type_nelts (ptype);
  3541.       int multi = 0;
  3542.  
  3543.       maxindex = fold (convert (integer_type_node, maxindex));
  3544.  
  3545.       while (1)
  3546.     {
  3547.       if (maxindex == error_mark_node
  3548.           || (TREE_CODE (maxindex) == INTEGER_CST
  3549.           && TREE_INT_CST_LOW (maxindex) < 0))
  3550.         return error_mark_node;
  3551.       ptype = TREE_TYPE (ptype);
  3552.       if (TREE_CODE (ptype) != ARRAY_TYPE)
  3553.         break;
  3554.  
  3555.       if (multi == 0)
  3556.         {
  3557.           /* Convert from 0-based to 1-based indexing.  */
  3558.           maxindex = fold (build (PLUS_EXPR, integer_type_node,
  3559.                       maxindex, integer_one_node));
  3560.           multi = 1;
  3561.         }
  3562.       amaxindex = array_type_nelts (ptype);
  3563.       maxindex = fold (build (MULT_EXPR, integer_type_node,
  3564.                   fold (build (PLUS_EXPR, integer_type_node,
  3565.                            amaxindex, integer_one_node)),
  3566.                   maxindex));
  3567.     }
  3568.  
  3569.       if (multi)
  3570.     {
  3571.       /* Convert back to 0-based indexing.  */
  3572.       maxindex = fold (build (MINUS_EXPR, integer_type_node,
  3573.                   maxindex, integer_one_node));
  3574.       ptype = TYPE_POINTER_TO (ptype);
  3575.       base = build1 (NOP_EXPR, ptype, build_unary_op (ADDR_EXPR, base, 0));
  3576.     }
  3577.       else
  3578.     {
  3579.       if (amaxindex != 0
  3580.           && (TREE_CODE (maxindex) == INTEGER_CST || TREE_CODE (amaxindex) == INTEGER_CST)
  3581.           /* Since `grokdeclarator' drops the high word, we do too.  */
  3582.           && TREE_INT_CST_LOW (maxindex) != TREE_INT_CST_LOW (amaxindex))
  3583.         warning ("argument to vector delete disagrees with declared type of array");
  3584.       base = default_conversion (base);
  3585.       ptype = TREE_TYPE (base);
  3586.     }
  3587.     }
  3588.   else
  3589.     {
  3590.       error ("type to vector delete is neither pointer or array type");
  3591.       return error_mark_node;
  3592.     }
  3593.   type = TREE_TYPE (ptype);
  3594.  
  3595.   if (! IS_AGGR_TYPE (type) || ! TYPE_NEEDS_DESTRUCTOR (type))
  3596.     {
  3597.       if (extra_warnings)
  3598.     warning ("array size expression for delete ignored");
  3599.       rval = build (CALL_EXPR, void_type_node,
  3600.             BID, build_tree_list (NULL_TREE, base), 0);
  3601.       TREE_VOLATILE (rval) = 1;
  3602.       return rval;
  3603.     }
  3604.  
  3605.   size_exp = size_in_bytes (type);
  3606.   iterator = build_decl (VAR_DECL, NULL_TREE, integer_type_node);
  3607.   TREE_REGDECL (iterator) = 1;
  3608.   DECL_INITIAL (iterator) = maxindex;
  3609.   tbase = build_decl (VAR_DECL, NULL_TREE, ptype);
  3610.   TREE_REGDECL (tbase) = 1;
  3611.   DECL_INITIAL (tbase) = build (PLUS_EXPR, ptype, base,
  3612.                 build (MULT_EXPR, integer_type_node, size_exp,
  3613.                        build (PLUS_EXPR, integer_type_node, maxindex, integer_one_node)));
  3614.  
  3615.   block = build_let (input_filename, lineno, iterator, 0, 0, 0);
  3616.   TREE_TYPE (block) = void_type_node;
  3617.  
  3618.   if (auto_delete != integer_zero_node
  3619.       && auto_delete != integer_two_node)
  3620.     {
  3621.       body = build_tree_list (NULL_TREE,
  3622.                   build (CALL_EXPR, void_type_node,
  3623.                      BID, build_tree_list (NULL_TREE, base), 0));
  3624.       body = build (COND_EXPR, void_type_node,
  3625.             build (BIT_AND_EXPR, integer_type_node,
  3626.                auto_delete, integer_one_node),
  3627.             body, integer_zero_node);
  3628.     }
  3629.   else
  3630.     body = NULL_TREE;
  3631.  
  3632.   body = tree_cons (NULL_TREE,
  3633.             build_delete (ptype, tbase, auto_delete, LOOKUP_NORMAL, 0),
  3634.             body);
  3635.  
  3636.   body = tree_cons (NULL_TREE,
  3637.             build_modify_expr (tbase, NOP_EXPR, build (MINUS_EXPR, ptype, tbase, size_exp)),
  3638.             body);
  3639.  
  3640.   loop = build_loop (input_filename, lineno,
  3641.              tbase,
  3642.              build (NE_EXPR, integer_type_node,
  3643.                 build (PREDECREMENT_EXPR, integer_type_node,
  3644.                    iterator, integer_one_node),
  3645.                 minus_one),
  3646.              build_compound_expr (body));
  3647.   TREE_TYPE (loop) = void_type_node;
  3648.   TREE_VOLATILE (loop) = 1;
  3649.  
  3650.   /* ELSE_STMT holds the code which deletes the container.
  3651.      If you don't want to delete the container, make ELSE_STMT
  3652.      zero here.  */
  3653.   if (auto_delete_vec == integer_one_node)
  3654.     else_stmt = build_delete (ptr_type_node, base, integer_one_node, 0, 1);
  3655.   else if (auto_delete_vec != integer_zero_node
  3656.        && auto_delete_vec != integer_two_node)
  3657.     {
  3658.       else_stmt = build (COND_EXPR, void_type_node,
  3659.              build (BIT_AND_EXPR, integer_type_node, auto_delete_vec, integer_one_node),
  3660.              build_delete (ptr_type_node, base, integer_one_node, 0, 1),
  3661.              integer_zero_node);
  3662.       TREE_VOLATILE (else_stmt) = 1;
  3663.     }
  3664.   else
  3665.     else_stmt = 0;
  3666.  
  3667.   if_stmt = build_if (input_filename, lineno,
  3668.               build (GE_EXPR, integer_type_node,
  3669.                  iterator, integer_zero_node),
  3670.               loop, else_stmt);
  3671.  
  3672.   TREE_TYPE (if_stmt) = void_type_node;
  3673.   TREE_VOLATILE (if_stmt) = 1;
  3674.  
  3675.   /* BASE may be a SAVE_EXPR which must be evaluated before either
  3676.      branch of the IF/THEN/ELSE.  */
  3677.   STMT_BODY (block) = build (COMPOUND_EXPR, void_type_node, base, if_stmt);
  3678.   TREE_VOLATILE (block) = 1;
  3679.  
  3680.   return block;
  3681. }
  3682.