home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / cp / typeck.c < prev    next >
C/C++ Source or Header  |  1996-04-05  |  239KB  |  7,656 lines

  1. /* Build expressions with type checking for C++ compiler.
  2.    Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@cygnus.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 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22.  
  23. /* This file is part of the C++ front end.
  24.    It contains routines to build C++ expressions given their operands,
  25.    including computing the types of the result, C and C++ specific error
  26.    checks, and some optimization.
  27.  
  28.    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
  29.    and to process initializations in declarations (since they work
  30.    like a strange sort of assignment).  */
  31.  
  32. extern void error ();
  33. extern void warning ();
  34.  
  35. #include "config.h"
  36. #include <stdio.h>
  37. #include "tree.h"
  38. #include "rtl.h"
  39. #include "cp-tree.h"
  40. #include "flags.h"
  41. #include "output.h"
  42.  
  43. int mark_addressable ();
  44. static tree convert_for_assignment ();
  45. /* static */ tree convert_for_initialization ();
  46. extern tree shorten_compare ();
  47. extern void binary_op_error ();
  48. static tree pointer_int_sum ();
  49. static tree pointer_diff ();
  50. static tree convert_sequence ();
  51. /* static */ tree unary_complex_lvalue ();
  52. static tree get_delta_difference PROTO((tree, tree, int));
  53.  
  54. extern rtx original_result_rtx;
  55. extern int warn_synth;
  56.  
  57. /* Return the target type of TYPE, which meas return T for:
  58.    T*, T&, T[], T (...), and otherwise, just T.  */
  59.  
  60. tree
  61. target_type (type)
  62.      tree type;
  63. {
  64.   if (TREE_CODE (type) == REFERENCE_TYPE)
  65.     type = TREE_TYPE (type);
  66.   while (TREE_CODE (type) == POINTER_TYPE
  67.      || TREE_CODE (type) == ARRAY_TYPE
  68.      || TREE_CODE (type) == FUNCTION_TYPE
  69.      || TREE_CODE (type) == METHOD_TYPE
  70.      || TREE_CODE (type) == OFFSET_TYPE)
  71.     type = TREE_TYPE (type);
  72.   return type;
  73. }
  74.  
  75. /* Do `exp = require_complete_type (exp);' to make sure exp
  76.    does not have an incomplete type.  (That includes void types.)  */
  77.  
  78. tree
  79. require_complete_type (value)
  80.      tree value;
  81. {
  82.   tree type = TREE_TYPE (value);
  83.  
  84.   /* First, detect a valid value with a complete type.  */
  85.   if (TYPE_SIZE (type) != 0
  86.       && type != void_type_node
  87.       && ! (TYPE_LANG_SPECIFIC (type)
  88.         && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type))
  89.         && TYPE_SIZE (SIGNATURE_TYPE (type)) == 0))
  90.     return value;
  91.  
  92.   /* If we see X::Y, we build an OFFSET_TYPE which has
  93.      not been laid out.  Try to avoid an error by interpreting
  94.      it as this->X::Y, if reasonable.  */
  95.   if (TREE_CODE (value) == OFFSET_REF
  96.       && C_C_D != 0
  97.       && TREE_OPERAND (value, 0) == C_C_D)
  98.     {
  99.       tree base, member = TREE_OPERAND (value, 1);
  100.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  101.       my_friendly_assert (TREE_CODE (member) == FIELD_DECL, 305);
  102.       base = convert_pointer_to (basetype, current_class_decl);
  103.       value = build (COMPONENT_REF, TREE_TYPE (member),
  104.              build_indirect_ref (base, NULL_PTR), member);
  105.       return require_complete_type (value);
  106.     }
  107.  
  108.   incomplete_type_error (value, type);
  109.   return error_mark_node;
  110. }
  111.  
  112. /* Return truthvalue of whether type of EXP is instantiated.  */
  113. int
  114. type_unknown_p (exp)
  115.      tree exp;
  116. {
  117.   return (TREE_CODE (exp) == TREE_LIST
  118.       || TREE_TYPE (exp) == unknown_type_node
  119.       || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
  120.           && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node));
  121. }
  122.  
  123. /* Return truthvalue of whether T is function (or pfn) type.  */
  124. int
  125. fntype_p (t)
  126.      tree t;
  127. {
  128.   return (TREE_CODE (t) == FUNCTION_TYPE || TREE_CODE (t) == METHOD_TYPE
  129.       || (TREE_CODE (t) == POINTER_TYPE
  130.           && (TREE_CODE (TREE_TYPE (t)) == FUNCTION_TYPE
  131.           || TREE_CODE (TREE_TYPE (t)) == METHOD_TYPE)));
  132. }
  133.  
  134. /* Do `exp = require_instantiated_type (type, exp);' to make sure EXP
  135.    does not have an uninstantiated type.
  136.    TYPE is type to instantiate with, if uninstantiated.  */
  137. tree
  138. require_instantiated_type (type, exp, errval)
  139.      tree type, exp, errval;
  140. {
  141.   if (TREE_TYPE (exp) == NULL_TREE)
  142.     {
  143.       error ("argument list may not have an initializer list");
  144.       return errval;
  145.     }
  146.  
  147.   if (TREE_TYPE (exp) == unknown_type_node
  148.       || (TREE_CODE (TREE_TYPE (exp)) == OFFSET_TYPE
  149.       && TREE_TYPE (TREE_TYPE (exp)) == unknown_type_node))
  150.     {
  151.       exp = instantiate_type (type, exp, 1);
  152.       if (TREE_TYPE (exp) == error_mark_node)
  153.     return errval;
  154.     }
  155.   return exp;
  156. }
  157.  
  158. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  159.    as well as those of TYPE.  */
  160.  
  161. static tree
  162. qualify_type (type, like)
  163.      tree type, like;
  164. {
  165.   int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
  166.   int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
  167.   /* @@ Must do member pointers here.  */
  168.   return cp_build_type_variant (type, constflag, volflag);
  169. }
  170.  
  171. /* Return the common type of two parameter lists.
  172.    We assume that comptypes has already been done and returned 1;
  173.    if that isn't so, this may crash.
  174.  
  175.    As an optimization, free the space we allocate if the parameter
  176.    lists are already common.  */
  177.  
  178. tree
  179. commonparms (p1, p2)
  180.      tree p1, p2;
  181. {
  182.   tree oldargs = p1, newargs, n;
  183.   int i, len;
  184.   int any_change = 0;
  185.   char *first_obj = (char *) oballoc (0);
  186.  
  187.   len = list_length (p1);
  188.   newargs = tree_last (p1);
  189.  
  190.   if (newargs == void_list_node)
  191.     i = 1;
  192.   else
  193.     {
  194.       i = 0;
  195.       newargs = 0;
  196.     }
  197.  
  198.   for (; i < len; i++)
  199.     newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
  200.  
  201.   n = newargs;
  202.  
  203.   for (i = 0; p1;
  204.        p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n), i++)
  205.     {
  206.       if (TREE_PURPOSE (p1) && !TREE_PURPOSE (p2))
  207.     {
  208.       TREE_PURPOSE (n) = TREE_PURPOSE (p1);
  209.       any_change = 1;
  210.     }
  211.       else if (! TREE_PURPOSE (p1))
  212.     {
  213.       if (TREE_PURPOSE (p2))
  214.         {
  215.           TREE_PURPOSE (n) = TREE_PURPOSE (p2);
  216.           any_change = 1;
  217.         }
  218.     }
  219.       else
  220.     {
  221.       if (1 != simple_cst_equal (TREE_PURPOSE (p1), TREE_PURPOSE (p2)))
  222.         any_change = 1;
  223.       TREE_PURPOSE (n) = TREE_PURPOSE (p2);
  224.     }
  225.       if (TREE_VALUE (p1) != TREE_VALUE (p2))
  226.     {
  227.       any_change = 1;
  228.       TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
  229.     }
  230.       else
  231.     TREE_VALUE (n) = TREE_VALUE (p1);
  232.     }
  233.   if (! any_change)
  234.     {
  235.       obfree (first_obj);
  236.       return oldargs;
  237.     }
  238.  
  239.   return newargs;
  240. }
  241.  
  242. /* Return the common type of two types.
  243.    We assume that comptypes has already been done and returned 1;
  244.    if that isn't so, this may crash.
  245.  
  246.    This is the type for the result of most arithmetic operations
  247.    if the operands have the given two types.
  248.  
  249.    We do not deal with enumeral types here because they have already been
  250.    converted to integer types.  */
  251.  
  252. tree
  253. common_type (t1, t2)
  254.      tree t1, t2;
  255. {
  256.   register enum tree_code code1;
  257.   register enum tree_code code2;
  258.   tree attributes;
  259.  
  260.   /* Save time if the two types are the same.  */
  261.  
  262.   if (t1 == t2) return t1;
  263.  
  264.   /* If one type is nonsense, use the other.  */
  265.   if (t1 == error_mark_node)
  266.     return t2;
  267.   if (t2 == error_mark_node)
  268.     return t1;
  269.  
  270.   /* Merge the attributes */
  271.  
  272.   { register tree a1, a2;
  273.     a1 = TYPE_ATTRIBUTES (t1);
  274.     a2 = TYPE_ATTRIBUTES (t2);
  275.  
  276.     /* Either one unset?  Take the set one.  */
  277.  
  278.     if (!(attributes = a1))
  279.        attributes = a2;
  280.  
  281.     /* One that completely contains the other?  Take it.  */
  282.  
  283.     else if (a2 && !attribute_list_contained (a1, a2))
  284.        if (attribute_list_contained (a2, a1))
  285.       attributes = a2;
  286.        else
  287.     {
  288.       /* Pick the longest list, and hang on the other list.  */
  289.       /* ??? For the moment we punt on the issue of attrs with args.  */
  290.     
  291.       if (list_length (a1) < list_length (a2))
  292.          attributes = a2, a2 = a1;
  293.  
  294.       for (; a2; a2 = TREE_CHAIN (a2))
  295.         if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
  296.                   attributes) == NULL_TREE)
  297.           {
  298.         a1 = copy_node (a2);
  299.         TREE_CHAIN (a1) = attributes;
  300.         attributes = a1;
  301.           }
  302.     }
  303.   }
  304.  
  305.   /* Treat an enum type as the unsigned integer type of the same width.  */
  306.  
  307.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  308.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  309.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  310.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  311.  
  312.   code1 = TREE_CODE (t1);
  313.   code2 = TREE_CODE (t2);
  314.  
  315.   switch (code1)
  316.     {
  317.     case INTEGER_TYPE:
  318.     case REAL_TYPE:
  319.       /* If only one is real, use it as the result.  */
  320.  
  321.       if (code1 == REAL_TYPE && code2 != REAL_TYPE)
  322.     return build_type_attribute_variant (t1, attributes);
  323.  
  324.       if (code2 == REAL_TYPE && code1 != REAL_TYPE)
  325.         return build_type_attribute_variant (t2, attributes);
  326.  
  327.       /* Both real or both integers; use the one with greater precision.  */
  328.  
  329.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  330.     return build_type_attribute_variant (t1, attributes);
  331.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  332.         return build_type_attribute_variant (t2, attributes);
  333.  
  334.       /* Same precision.  Prefer longs to ints even when same size.  */
  335.   
  336.       if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
  337.       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
  338.         return build_type_attribute_variant (long_unsigned_type_node,
  339.                          attributes);
  340.  
  341.       if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
  342.       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
  343.     {
  344.       /* But preserve unsignedness from the other type,
  345.          since long cannot hold all the values of an unsigned int.  */
  346.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  347.          t1 = long_unsigned_type_node;
  348.       else
  349.          t1 = long_integer_type_node;
  350.       return build_type_attribute_variant (t1, attributes);
  351.     }
  352.  
  353.       if (TYPE_MAIN_VARIANT (t1) == long_double_type_node
  354.       || TYPE_MAIN_VARIANT (t2) == long_double_type_node)
  355.     return build_type_attribute_variant (long_double_type_node,
  356.                          attributes);      
  357.  
  358.       /* Otherwise prefer the unsigned one.  */
  359.  
  360.       if (TREE_UNSIGNED (t1))
  361.     return build_type_attribute_variant (t1, attributes);
  362.       else
  363.     return build_type_attribute_variant (t2, attributes);
  364.  
  365.     case POINTER_TYPE:
  366.     case REFERENCE_TYPE:
  367.       /* For two pointers, do this recursively on the target type,
  368.      and combine the qualifiers of the two types' targets.  */
  369.       /* This code was turned off; I don't know why.
  370.       But ANSI C++ specifies doing this with the qualifiers.
  371.       So I turned it on again.  */
  372.       {
  373.     tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (t1));
  374.     tree tt2 = TYPE_MAIN_VARIANT (TREE_TYPE (t2));
  375.     int constp
  376.       = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
  377.     int volatilep
  378.       = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
  379.     tree target;
  380.  
  381.     if (tt1 == tt2)
  382.       target = tt1;
  383.     else if (tt1 == void_type_node || tt2 == void_type_node)
  384.       target = void_type_node;
  385.     else
  386.       target = common_type (tt1, tt2);
  387.  
  388.     target = cp_build_type_variant (target, constp, volatilep);
  389.     if (code1 == POINTER_TYPE)
  390.       t1 = build_pointer_type (target);
  391.     else
  392.       t1 = build_reference_type (target);
  393.     t1 = build_type_attribute_variant (t1, attributes);
  394.  
  395.     if (TREE_CODE (target) == METHOD_TYPE)
  396.       t1 = build_ptrmemfunc_type (t1);
  397.  
  398.     return t1;
  399.       }
  400. #if 0
  401.     case POINTER_TYPE:
  402.       t1 = build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  403.       return build_type_attribute_variant (t1, attributes);
  404.  
  405.     case REFERENCE_TYPE:
  406.       t1 = build_reference_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  407.       return build_type_attribute_variant (t1, attributes);
  408. #endif
  409.  
  410.     case ARRAY_TYPE:
  411.       {
  412.     tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  413.     /* Save space: see if the result is identical to one of the args.  */
  414.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  415.       return build_type_attribute_variant (t1, attributes);
  416.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  417.       return build_type_attribute_variant (t2, attributes);
  418.     /* Merge the element types, and have a size if either arg has one.  */
  419.     t1 = build_cplus_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  420.     return build_type_attribute_variant (t1, attributes);
  421.       }
  422.  
  423.     case FUNCTION_TYPE:
  424.       /* Function types: prefer the one that specified arg types.
  425.      If both do, merge the arg types.  Also merge the return types.  */
  426.       {
  427.     tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  428.     tree p1 = TYPE_ARG_TYPES (t1);
  429.     tree p2 = TYPE_ARG_TYPES (t2);
  430.     tree rval, raises;
  431.  
  432.     /* Save space: see if the result is identical to one of the args.  */
  433.     if (valtype == TREE_TYPE (t1) && ! p2)
  434.       return build_type_attribute_variant (t1, attributes);
  435.     if (valtype == TREE_TYPE (t2) && ! p1)
  436.       return build_type_attribute_variant (t2, attributes);
  437.  
  438.     /* Simple way if one arg fails to specify argument types.  */
  439.     if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node)
  440.       {
  441.         rval = build_function_type (valtype, p2);
  442.         if ((raises = TYPE_RAISES_EXCEPTIONS (t2)))
  443.           rval = build_exception_variant (rval, raises);
  444.         return build_type_attribute_variant (rval, attributes);
  445.       }
  446.     raises = TYPE_RAISES_EXCEPTIONS (t1);
  447.     if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node)
  448.       {
  449.         rval = build_function_type (valtype, p1);
  450.         if (raises)
  451.           rval = build_exception_variant (rval, raises);
  452.         return build_type_attribute_variant (rval, attributes);
  453.       }
  454.  
  455.     rval = build_function_type (valtype, commonparms (p1, p2));
  456.     rval = build_exception_variant (rval, raises);
  457.     return build_type_attribute_variant (rval, attributes);
  458.       }
  459.  
  460.     case RECORD_TYPE:
  461.     case UNION_TYPE:
  462.       my_friendly_assert (TYPE_MAIN_VARIANT (t1) == t1
  463.               && TYPE_MAIN_VARIANT (t2) == t2, 306);
  464.  
  465.       if (DERIVED_FROM_P (t1, t2) && binfo_or_else (t1, t2))
  466.     return build_type_attribute_variant (t1, attributes);
  467.       else if (binfo_or_else (t2, t1))
  468.     return build_type_attribute_variant (t2, attributes);
  469.       else
  470.     compiler_error ("common_type called with uncommon aggregate types");
  471.  
  472.     case METHOD_TYPE:
  473.       if (TREE_CODE (TREE_TYPE (t1)) == TREE_CODE (TREE_TYPE (t2)))
  474.     {
  475.       /* Get this value the long way, since TYPE_METHOD_BASETYPE
  476.          is just the main variant of this.  */
  477.       tree basetype;
  478.       tree raises, t3;
  479.  
  480.       tree b1 = TYPE_OFFSET_BASETYPE (t1);
  481.       tree b2 = TYPE_OFFSET_BASETYPE (t2);
  482.  
  483.       if (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2))
  484.         basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t2)));
  485.       else
  486.         {
  487.           if (binfo_or_else (b2, b1) == NULL_TREE)
  488.         compiler_error ("common_type called with uncommon method types");
  489.           basetype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (t1)));
  490.         }
  491.  
  492.       raises = TYPE_RAISES_EXCEPTIONS (t1);
  493.  
  494.       /* If this was a member function type, get back to the
  495.          original type of type member function (i.e., without
  496.          the class instance variable up front.  */
  497.       t1 = build_function_type (TREE_TYPE (t1), TREE_CHAIN (TYPE_ARG_TYPES (t1)));
  498.       t2 = build_function_type (TREE_TYPE (t2), TREE_CHAIN (TYPE_ARG_TYPES (t2)));
  499.       t3 = common_type (t1, t2);
  500.       t3 = build_cplus_method_type (basetype, TREE_TYPE (t3), TYPE_ARG_TYPES (t3));
  501.       t1 = build_exception_variant (t3, raises);
  502.     }
  503.       else
  504.         compiler_error ("common_type called with uncommon method types");
  505.  
  506.       return build_type_attribute_variant (t1, attributes);
  507.  
  508.     case OFFSET_TYPE:
  509.       if (TREE_TYPE (t1) == TREE_TYPE (t2))
  510.     {
  511.       tree b1 = TYPE_OFFSET_BASETYPE (t1);
  512.       tree b2 = TYPE_OFFSET_BASETYPE (t2);
  513.  
  514.       if (DERIVED_FROM_P (b1, b2) && binfo_or_else (b1, b2))
  515.         return build_type_attribute_variant (t2, attributes);
  516.       else if (binfo_or_else (b2, b1))
  517.         return build_type_attribute_variant (t1, attributes);
  518.     }
  519.       compiler_error ("common_type called with uncommon member types");
  520.  
  521.     default:
  522.       return build_type_attribute_variant (t1, attributes);
  523.     }
  524. }
  525.  
  526. /* Return 1 if TYPE1 and TYPE2 raise the same exceptions.  */
  527. int
  528. compexcepttypes (t1, t2, strict)
  529.      tree t1, t2;
  530.      int strict;
  531. {
  532.   return TYPE_RAISES_EXCEPTIONS (t1) == TYPE_RAISES_EXCEPTIONS (t2);
  533. }
  534.  
  535. static int
  536. comp_array_types (cmp, t1, t2, strict)
  537.      register int (*cmp)();
  538.      tree t1, t2;
  539.      int strict;
  540. {
  541.   tree d1 = TYPE_DOMAIN (t1);
  542.   tree d2 = TYPE_DOMAIN (t2);
  543.  
  544.   /* Target types must match incl. qualifiers.  */
  545.   if (!(TREE_TYPE (t1) == TREE_TYPE (t2)
  546.     || (*cmp) (TREE_TYPE (t1), TREE_TYPE (t2), strict)))
  547.     return 0;
  548.  
  549.   /* Sizes must match unless one is missing or variable.  */
  550.   if (d1 == 0 || d2 == 0 || d1 == d2
  551.       || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  552.       || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  553.       || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  554.       || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  555.     return 1;
  556.  
  557.   return ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  558.        == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  559.       && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  560.           == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  561.       && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  562.           == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  563.       && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  564.           == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2))));
  565. }
  566.  
  567. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  568.    or various other operations.  This is what ANSI C++ speaks of as
  569.    "being the same".
  570.  
  571.    For C++: argument STRICT says we should be strict about this
  572.    comparison:
  573.  
  574.     2 : strict, except that if one type is a reference and
  575.         the other is not, compare the target type of the
  576.         reference to the type that's not a reference (ARM, p308).
  577.         This is used for checking for invalid overloading.
  578.     1 : strict (compared according to ANSI C)
  579.         This is used for checking whether two function decls match.
  580.     0 : <= (compared according to C++)
  581.     -1: <= or >= (relaxed)
  582.  
  583.    Otherwise, pointers involving base classes and derived classes
  584.    can be mixed as valid: i.e. a pointer to a base class may be assigned
  585.    to a pointer to one of its derived classes, as per C++. A pointer to
  586.    a derived class may be passed as a parameter to a function expecting a
  587.    pointer to a base classes. These allowances do not commute. In this
  588.    case, TYPE1 is assumed to be the base class, and TYPE2 is assumed to
  589.    be the derived class.  */
  590. int
  591. comptypes (type1, type2, strict)
  592.      tree type1, type2;
  593.      int strict;
  594. {
  595.   register tree t1 = type1;
  596.   register tree t2 = type2;
  597.   int attrval, val;
  598.  
  599.   /* Suppress errors caused by previously reported errors */
  600.  
  601.   if (t1 == t2)
  602.     return 1;
  603.  
  604.   /* This should never happen.  */
  605.   my_friendly_assert (t1 != error_mark_node, 307);
  606.  
  607.   if (t2 == error_mark_node)
  608.     return 0;
  609.  
  610.   if (strict < 0)
  611.     {
  612.       /* Treat an enum type as the unsigned integer type of the same width.  */
  613.  
  614.       if (TREE_CODE (t1) == ENUMERAL_TYPE)
  615.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  616.       if (TREE_CODE (t2) == ENUMERAL_TYPE)
  617.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  618.  
  619.       if (t1 == t2)
  620.     return 1;
  621.     }
  622.  
  623.   /* Different classes of types can't be compatible.  */
  624.  
  625.   if (TREE_CODE (t1) != TREE_CODE (t2))
  626.     {
  627.       if (strict == 2
  628.       && ((TREE_CODE (t1) == REFERENCE_TYPE)
  629.           ^ (TREE_CODE (t2) == REFERENCE_TYPE)))
  630.     {
  631.       if (TREE_CODE (t1) == REFERENCE_TYPE)
  632.         return comptypes (TREE_TYPE (t1), t2, 1);
  633.       return comptypes (t1, TREE_TYPE (t2), 1);
  634.     }
  635.  
  636.       return 0;
  637.     }
  638.   if (strict > 1)
  639.     strict = 1;
  640.  
  641.   /* Qualifiers must match.  */
  642.  
  643.   if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
  644.     return 0;
  645.   if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
  646.     return 0;
  647.  
  648.   /* Allow for two different type nodes which have essentially the same
  649.      definition.  Note that we already checked for equality of the type
  650.      type qualifiers (just above).  */
  651.  
  652.   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
  653.     return 1;
  654.  
  655. #ifdef COMP_TYPE_ATTRIBUTES
  656.   if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
  657.      return 0;
  658. #else
  659.   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  660.   attrval = 1;
  661. #endif
  662.  
  663.   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  664.   val = 0;
  665.  
  666.   switch (TREE_CODE (t1))
  667.     {
  668.     case RECORD_TYPE:
  669.     case UNION_TYPE:
  670. #ifdef OBJCPLUS
  671.       if (maybe_objc_comptypes (t1, t2, 0) == 1)
  672.          return 1;
  673. #endif
  674.       if (strict <= 0)
  675.     goto look_hard;
  676.       return 0;
  677.  
  678.     case OFFSET_TYPE:
  679.       val = (comptypes (build_pointer_type (TYPE_OFFSET_BASETYPE (t1)),
  680.             build_pointer_type (TYPE_OFFSET_BASETYPE (t2)), strict)
  681.          && comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict));
  682.       break;
  683.  
  684.     case METHOD_TYPE:
  685.       if (! compexcepttypes (t1, t2, strict))
  686.     return 0;
  687.  
  688.       /* This case is anti-symmetrical!
  689.      One can pass a base member (or member function)
  690.      to something expecting a derived member (or member function),
  691.      but not vice-versa!  */
  692.  
  693.       val = (comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict)
  694.          && compparms (TYPE_ARG_TYPES (t1),
  695.                TYPE_ARG_TYPES (t2), strict));
  696.       break;
  697.  
  698.     case POINTER_TYPE:
  699.     case REFERENCE_TYPE:
  700.       t1 = TREE_TYPE (t1);
  701.       t2 = TREE_TYPE (t2);
  702.       if (t1 == t2)
  703.     {
  704.       val = 1;
  705.       break;
  706.     }
  707.       if (strict <= 0)
  708.     {
  709. #ifdef OBJCPLUS
  710.           if (maybe_objc_comptypes (t1, t2, 0) == 1)
  711.         return 1;
  712. #endif /* OBJCPLUS */
  713.       if (TREE_CODE (t1) == RECORD_TYPE && TREE_CODE (t2) == RECORD_TYPE)
  714.         {
  715.           int rval;
  716.         look_hard:
  717.           rval = t1 == t2 || UNIQUELY_DERIVED_FROM_P (t1, t2);
  718.  
  719.           if (rval)
  720.         {
  721.           val = 1;
  722.           break;
  723.         }
  724.           if (strict < 0)
  725.         {
  726.           val = UNIQUELY_DERIVED_FROM_P (t2, t1);
  727.           break;
  728.         }
  729.         }
  730.       return 0;
  731.     }
  732.       else
  733.     val = comptypes (t1, t2, strict);
  734.       break;
  735.  
  736.     case FUNCTION_TYPE:
  737.       if (! compexcepttypes (t1, t2, strict))
  738.     return 0;
  739.  
  740.       val = ((TREE_TYPE (t1) == TREE_TYPE (t2)
  741.           || comptypes (TREE_TYPE (t1), TREE_TYPE (t2), strict))
  742.          && compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2), strict));
  743.       break;
  744.  
  745.     case ARRAY_TYPE:
  746.       /* Target types must match incl. qualifiers.  */
  747.       val = comp_array_types (comptypes, t1, t2, strict);
  748.       break;
  749.  
  750.     case TEMPLATE_TYPE_PARM:
  751.       return TEMPLATE_TYPE_IDX (t1) == TEMPLATE_TYPE_IDX (t2);
  752.  
  753.     case UNINSTANTIATED_P_TYPE:
  754.       if (UPT_TEMPLATE (t1) != UPT_TEMPLATE (t2))
  755.     return 0;
  756.       {
  757.     int i = TREE_VEC_LENGTH (UPT_PARMS (t1));
  758.     tree *p1 = &TREE_VEC_ELT (UPT_PARMS (t1), 0);
  759.     tree *p2 = &TREE_VEC_ELT (UPT_PARMS (t2), 0);
  760.     
  761.     while (i--)
  762.       {
  763.         if (TREE_CODE_CLASS (TREE_CODE (p1[i])) == 't')
  764.           {
  765.         if (! comptypes (p1[i], p2[i], 1))
  766.           return 0;
  767.           }
  768.         else
  769.           {
  770.         if (simple_cst_equal (p1[i], p2[i]) <= 0)
  771.           return 0;
  772.           }
  773.       }
  774.       }
  775.       return 1;
  776.     }
  777.   return attrval == 2 && val == 1 ? 2 : val;
  778. }
  779.  
  780. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  781.    ignoring their qualifiers.
  782.  
  783.    NPTRS is the number of pointers we can strip off and keep cool.
  784.    This is used to permit (for aggr A, aggr B) A, B* to convert to A*,
  785.    but to not permit B** to convert to A**.  */
  786.  
  787. int
  788. comp_target_types (ttl, ttr, nptrs)
  789.      tree ttl, ttr;
  790.      int nptrs;
  791. {
  792.   ttl = TYPE_MAIN_VARIANT (ttl);
  793.   ttr = TYPE_MAIN_VARIANT (ttr);
  794.   if (ttl == ttr)
  795.     return 1;
  796.  
  797. #ifdef OBJCPLUS
  798.  /* emits warnings as appropriate */
  799.   if (maybe_objc_comptypes (ttl, ttr, 1) == 1)
  800.     return 1;
  801. #endif /* OBJCPLUS */
  802.  
  803.   if (TREE_CODE (ttr) != TREE_CODE (ttl))
  804.     return 0;
  805.  
  806.   if (TREE_CODE (ttr) == POINTER_TYPE)
  807.     {
  808.       ttl = TREE_TYPE (ttl);
  809.       ttr = TREE_TYPE (ttr);
  810.  
  811.       if (nptrs > 0)
  812.     {
  813.       if (TREE_CODE (ttl) == VOID_TYPE
  814.            && TREE_CODE (ttr) != FUNCTION_TYPE
  815.            && TREE_CODE (ttr) != METHOD_TYPE
  816.            && TREE_CODE (ttr) != OFFSET_TYPE)
  817.         return 1;
  818.       else if (TREE_CODE (ttr) == VOID_TYPE
  819.            && TREE_CODE (ttl) != FUNCTION_TYPE
  820.            && TREE_CODE (ttl) != METHOD_TYPE
  821.            && TREE_CODE (ttl) != OFFSET_TYPE)
  822.         return -1;
  823.       else if (TREE_CODE (ttl) == POINTER_TYPE
  824.            || TREE_CODE (ttl) == ARRAY_TYPE)
  825.         {
  826.           if (comp_ptr_ttypes (ttl, ttr))
  827.         return 1;
  828.           else if (comp_ptr_ttypes (ttr, ttl))
  829.         return -1;
  830.           return 0;
  831.         }
  832.     }
  833.  
  834.       /* Const and volatile mean something different for function types,
  835.      so the usual checks are not appropriate.  */
  836.       if (TREE_CODE (ttl) == FUNCTION_TYPE || TREE_CODE (ttl) == METHOD_TYPE)
  837.     return comp_target_types (ttl, ttr, nptrs - 1);
  838.  
  839.       /* Make sure that the cv-quals change only in the same direction as
  840.      the target type.  */
  841.       {
  842.     int t;
  843.     int c = TYPE_READONLY (ttl) - TYPE_READONLY (ttr);
  844.     int v = TYPE_VOLATILE (ttl) - TYPE_VOLATILE (ttr);
  845.  
  846.     if ((c > 0 && v < 0) || (c < 0 && v > 0))
  847.       return 0;
  848.  
  849.     if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr))
  850.       return (c + v < 0) ? -1 : 1;
  851.  
  852.     t = comp_target_types (ttl, ttr, nptrs - 1);
  853.     if ((t == 1 && c + v >= 0) || (t == -1 && c + v <= 0))
  854.       return t;
  855.  
  856.     return 0;
  857.       }
  858.     }
  859.  
  860.   if (TREE_CODE (ttr) == REFERENCE_TYPE)
  861.     return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
  862.   if (TREE_CODE (ttr) == ARRAY_TYPE)
  863.     return comp_array_types (comp_target_types, ttl, ttr, 0);
  864.   else if (TREE_CODE (ttr) == FUNCTION_TYPE || TREE_CODE (ttr) == METHOD_TYPE)
  865.     if (comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
  866.       switch (comp_target_parms (TYPE_ARG_TYPES (ttl), TYPE_ARG_TYPES (ttr), 1))
  867.     {
  868.     case 0:
  869.       return 0;
  870.     case 1:
  871.       return 1;
  872.     case 2:
  873.       return -1;
  874.     default:
  875.       my_friendly_abort (112);
  876.     }
  877.     else
  878.       return 0;
  879.  
  880.   /* for C++ */
  881.   else if (TREE_CODE (ttr) == OFFSET_TYPE)
  882.     {
  883.       /* Contravariance: we can assign a pointer to base member to a pointer
  884.      to derived member.  Note difference from simple pointer case, where
  885.      we can pass a pointer to derived to a pointer to base.  */
  886.       if (comptypes (TYPE_OFFSET_BASETYPE (ttr), TYPE_OFFSET_BASETYPE (ttl), 0))
  887.     return comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs);
  888.       else if (comptypes (TYPE_OFFSET_BASETYPE (ttl), TYPE_OFFSET_BASETYPE (ttr), 0)
  889.            && comp_target_types (TREE_TYPE (ttl), TREE_TYPE (ttr), nptrs))
  890.     return -1;
  891.     }
  892.   else if (IS_AGGR_TYPE (ttl))
  893.     {
  894.       if (nptrs < 0)
  895.     return 0;
  896.       if (comptypes (build_pointer_type (ttl), build_pointer_type (ttr), 0))
  897.     return 1;
  898.       if (comptypes (build_pointer_type (ttr), build_pointer_type (ttl), 0))
  899.     return -1;
  900.       return 0;
  901.     }
  902.  
  903.   return 0;
  904. }
  905.  
  906. /* If two types share a common base type, return that basetype.
  907.    If there is not a unique most-derived base type, this function
  908.    returns ERROR_MARK_NODE.  */
  909. tree
  910. common_base_type (tt1, tt2)
  911.      tree tt1, tt2;
  912. {
  913.   tree best = NULL_TREE, tmp;
  914.   int i;
  915.  
  916.   /* If one is a baseclass of another, that's good enough.  */
  917.   if (UNIQUELY_DERIVED_FROM_P (tt1, tt2))
  918.     return tt1;
  919.   if (UNIQUELY_DERIVED_FROM_P (tt2, tt1))
  920.     return tt2;
  921.  
  922. #if 0
  923.   /* If they share a virtual baseclass, that's good enough.  */
  924.   for (tmp = CLASSTYPE_VBASECLASSES (tt1); tmp; tmp = TREE_CHAIN (tmp))
  925.     {
  926.       if (binfo_member (BINFO_TYPE (tmp), CLASSTYPE_VBASECLASSES (tt2)))
  927.     return BINFO_TYPE (tmp);
  928.     }
  929. #endif
  930.  
  931.   /* Otherwise, try to find a unique baseclass of TT1
  932.      that is shared by TT2, and follow that down.  */
  933.   for (i = CLASSTYPE_N_BASECLASSES (tt1)-1; i >= 0; i--)
  934.     {
  935.       tree basetype = TYPE_BINFO_BASETYPE (tt1, i);
  936.       tree trial = common_base_type (basetype, tt2);
  937.       if (trial)
  938.     {
  939.       if (trial == error_mark_node)
  940.         return trial;
  941.       if (best == NULL_TREE)
  942.         best = trial;
  943.       else if (best != trial)
  944.         return error_mark_node;
  945.     }
  946.     }
  947.  
  948.   /* Same for TT2.  */
  949.   for (i = CLASSTYPE_N_BASECLASSES (tt2)-1; i >= 0; i--)
  950.     {
  951.       tree basetype = TYPE_BINFO_BASETYPE (tt2, i);
  952.       tree trial = common_base_type (tt1, basetype);
  953.       if (trial)
  954.     {
  955.       if (trial == error_mark_node)
  956.         return trial;
  957.       if (best == NULL_TREE)
  958.         best = trial;
  959.       else if (best != trial)
  960.         return error_mark_node;
  961.     }
  962.     }
  963.   return best;
  964. }
  965.  
  966. /* Subroutines of `comptypes'.  */
  967.  
  968. /* Return 1 if two parameter type lists PARMS1 and PARMS2
  969.    are equivalent in the sense that functions with those parameter types
  970.    can have equivalent types.
  971.    If either list is empty, we win.
  972.    Otherwise, the two lists must be equivalent, element by element.
  973.  
  974.    C++: See comment above about TYPE1, TYPE2, STRICT.
  975.    If STRICT == 3, it means checking is strict, but do not compare
  976.    default parameter values.  */
  977. int
  978. compparms (parms1, parms2, strict)
  979.      tree parms1, parms2;
  980.      int strict;
  981. {
  982.   register tree t1 = parms1, t2 = parms2;
  983.  
  984.   /* An unspecified parmlist matches any specified parmlist
  985.      whose argument types don't need default promotions.  */
  986.  
  987.   if (strict <= 0 && t1 == 0)
  988.     return self_promoting_args_p (t2);
  989.   if (strict < 0 && t2 == 0)
  990.     return self_promoting_args_p (t1);
  991.  
  992.   while (1)
  993.     {
  994.       if (t1 == 0 && t2 == 0)
  995.     return 1;
  996.       /* If one parmlist is shorter than the other,
  997.      they fail to match, unless STRICT is <= 0.  */
  998.       if (t1 == 0 || t2 == 0)
  999.     {
  1000.       if (strict > 0)
  1001.         return 0;
  1002.       if (strict < 0)
  1003.         return 1;
  1004.       if (strict == 0)
  1005.         return t1 && TREE_PURPOSE (t1);
  1006.     }
  1007.       if (! comptypes (TREE_VALUE (t2), TREE_VALUE (t1), strict))
  1008.     {
  1009.       if (strict > 0)
  1010.         return 0;
  1011.       if (strict == 0)
  1012.         return t2 == void_list_node && TREE_PURPOSE (t1);
  1013.       return TREE_PURPOSE (t1) || TREE_PURPOSE (t2);
  1014.     }
  1015. #if 0
  1016.       /* Default parms are not part of the type of a function.  */
  1017.       if (strict != 3 && TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  1018.     {
  1019.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  1020.       if (cmp < 0)
  1021.         my_friendly_abort (113);
  1022.       if (cmp == 0)
  1023.         return 0;
  1024.     }
  1025. #endif
  1026.  
  1027.       t1 = TREE_CHAIN (t1);
  1028.       t2 = TREE_CHAIN (t2);
  1029.     }
  1030. }
  1031.  
  1032. /* This really wants return whether or not parameter type lists
  1033.    would make their owning functions assignment compatible or not.  */
  1034. int
  1035. comp_target_parms (parms1, parms2, strict)
  1036.      tree parms1, parms2;
  1037.      int strict;
  1038. {
  1039.   register tree t1 = parms1, t2 = parms2;
  1040.   int warn_contravariance = 0;
  1041.  
  1042.   /* An unspecified parmlist matches any specified parmlist
  1043.      whose argument types don't need default promotions.
  1044.      @@@ see 13.3.3 for a counterexample...  */
  1045.  
  1046.   if (t1 == 0 && t2 != 0)
  1047.     {
  1048.       cp_pedwarn ("ANSI C++ prohibits conversion from `(%#T)' to `(...)'",
  1049.           parms2);
  1050.       return self_promoting_args_p (t2);
  1051.     }
  1052.   if (t2 == 0)
  1053.     return self_promoting_args_p (t1);
  1054.  
  1055.   for (; t1 || t2; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
  1056.     {
  1057.       tree p1, p2;
  1058.  
  1059.       /* If one parmlist is shorter than the other,
  1060.      they fail to match, unless STRICT is <= 0.  */
  1061.       if (t1 == 0 || t2 == 0)
  1062.     {
  1063.       if (strict > 0)
  1064.         return 0;
  1065.       if (strict < 0)
  1066.         return 1 + warn_contravariance;
  1067.       return ((t1 && TREE_PURPOSE (t1)) + warn_contravariance);
  1068.     }
  1069.       p1 = TREE_VALUE (t1);
  1070.       p2 = TREE_VALUE (t2);
  1071.       if (p1 == p2)
  1072.     continue;
  1073.  
  1074.       if ((TREE_CODE (p1) == POINTER_TYPE && TREE_CODE (p2) == POINTER_TYPE)
  1075.       || (TREE_CODE (p1) == REFERENCE_TYPE && TREE_CODE (p2) == REFERENCE_TYPE))
  1076.     {
  1077.       if (strict <= 0
  1078.           && (TYPE_MAIN_VARIANT (TREE_TYPE (p1))
  1079.           == TYPE_MAIN_VARIANT (TREE_TYPE (p2))))
  1080.         continue;
  1081.  
  1082.       /* The following is wrong for contravariance,
  1083.          but many programs depend on it.  */
  1084.       if (TREE_TYPE (p1) == void_type_node)
  1085.         continue;
  1086.       if (TREE_TYPE (p2) == void_type_node)
  1087.         {
  1088.           warn_contravariance = 1;
  1089.           continue;
  1090.         }
  1091.       if (IS_AGGR_TYPE (TREE_TYPE (p1)))
  1092.         {
  1093.           if (comptypes (p2, p1, 0) == 0)
  1094.         {
  1095.           if (comptypes (p1, p2, 0) != 0)
  1096.             warn_contravariance = 1;
  1097.           else
  1098.             return 0;
  1099.         }
  1100.           continue;
  1101.         }
  1102.     }
  1103.       /* Note backwards order due to contravariance.  */
  1104.       if (comp_target_types (p2, p1, 1) == 0)
  1105.     {
  1106.       if (comp_target_types (p1, p2, 1))
  1107.         {
  1108.           warn_contravariance = 1;
  1109.           continue;
  1110.         }
  1111.       if (strict != 0)
  1112.         return 0;
  1113. #if 0
  1114.       /* What good do these cases do?  */
  1115.       if (strict == 0)
  1116.         return p2 == void_type_node && TREE_PURPOSE (t1);
  1117.       return TREE_PURPOSE (t1) || TREE_PURPOSE (t2);
  1118. #endif
  1119.     }
  1120.       /* Target types are compatible--just make sure that if
  1121.      we use parameter lists, that they are ok as well.  */
  1122.       if (TREE_CODE (p1) == FUNCTION_TYPE || TREE_CODE (p1) == METHOD_TYPE)
  1123.     switch (comp_target_parms (TYPE_ARG_TYPES (p1),
  1124.                    TYPE_ARG_TYPES (p2),
  1125.                    strict))
  1126.       {
  1127.       case 0:
  1128.         return 0;
  1129.       case 1:
  1130.         break;
  1131.       case 2:
  1132.         warn_contravariance = 1;
  1133.       }
  1134.  
  1135.       if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  1136.     {
  1137.       int cmp = simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
  1138.       if (cmp < 0)
  1139.         my_friendly_abort (114);
  1140.       if (cmp == 0)
  1141.         return 0;
  1142.     }
  1143.     }
  1144.   return 1 + warn_contravariance;
  1145. }
  1146.  
  1147. /* Return 1 if PARMS specifies a fixed number of parameters
  1148.    and none of their types is affected by default promotions.  */
  1149.  
  1150. int
  1151. self_promoting_args_p (parms)
  1152.      tree parms;
  1153. {
  1154.   register tree t;
  1155.   for (t = parms; t; t = TREE_CHAIN (t))
  1156.     {
  1157.       register tree type = TREE_VALUE (t);
  1158.  
  1159.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  1160.     return 0;
  1161.  
  1162.       if (TYPE_MAIN_VARIANT (type) == float_type_node)
  1163.     return 0;
  1164.  
  1165.       if (type == 0)
  1166.     return 0;
  1167.  
  1168.       if (C_PROMOTING_INTEGER_TYPE_P (type))
  1169.     return 0;
  1170.     }
  1171.   return 1;
  1172. }
  1173.  
  1174. /* Return an unsigned type the same as TYPE in other respects.
  1175.  
  1176.    C++: must make these work for type variants as well.  */
  1177.  
  1178. tree
  1179. unsigned_type (type)
  1180.      tree type;
  1181. {
  1182.   tree type1 = TYPE_MAIN_VARIANT (type);
  1183.   if (type1 == signed_char_type_node || type1 == char_type_node)
  1184.     return unsigned_char_type_node;
  1185.   if (type1 == integer_type_node)
  1186.     return unsigned_type_node;
  1187.   if (type1 == short_integer_type_node)
  1188.     return short_unsigned_type_node;
  1189.   if (type1 == long_integer_type_node)
  1190.     return long_unsigned_type_node;
  1191.   if (type1 == long_long_integer_type_node)
  1192.     return long_long_unsigned_type_node;
  1193.   return type;
  1194. }
  1195.  
  1196. /* Return a signed type the same as TYPE in other respects.  */
  1197.  
  1198. tree
  1199. signed_type (type)
  1200.      tree type;
  1201. {
  1202.   tree type1 = TYPE_MAIN_VARIANT (type);
  1203.   if (type1 == unsigned_char_type_node || type1 == char_type_node)
  1204.     return signed_char_type_node;
  1205.   if (type1 == unsigned_type_node)
  1206.     return integer_type_node;
  1207.   if (type1 == short_unsigned_type_node)
  1208.     return short_integer_type_node;
  1209.   if (type1 == long_unsigned_type_node)
  1210.     return long_integer_type_node;
  1211.   if (type1 == long_long_unsigned_type_node)
  1212.     return long_long_integer_type_node;
  1213.   return type;
  1214. }
  1215.  
  1216. /* Return a type the same as TYPE except unsigned or
  1217.    signed according to UNSIGNEDP.  */
  1218.  
  1219. tree
  1220. signed_or_unsigned_type (unsignedp, type)
  1221.      int unsignedp;
  1222.      tree type;
  1223. {
  1224.   if (! INTEGRAL_TYPE_P (type))
  1225.     return type;
  1226.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  1227.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  1228.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  1229.     return unsignedp ? unsigned_type_node : integer_type_node;
  1230.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  1231.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  1232.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  1233.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  1234.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) 
  1235.     return (unsignedp ? long_long_unsigned_type_node
  1236.         : long_long_integer_type_node);
  1237.   return type;
  1238. }
  1239.  
  1240. tree
  1241. c_sizeof (type)
  1242.      tree type;
  1243. {
  1244.   enum tree_code code = TREE_CODE (type);
  1245.   tree t;
  1246.  
  1247.   if (code == FUNCTION_TYPE)
  1248.     {
  1249.       if (pedantic || warn_pointer_arith)
  1250.     pedwarn ("ANSI C++ forbids taking the sizeof a function type");
  1251.       return size_int (1);
  1252.     }
  1253.   if (code == METHOD_TYPE)
  1254.     {
  1255.       if (pedantic || warn_pointer_arith)
  1256.     pedwarn ("ANSI C++ forbids taking the sizeof a method type");
  1257.       return size_int (1);
  1258.     }
  1259.   if (code == VOID_TYPE)
  1260.     {
  1261.       if (pedantic || warn_pointer_arith)
  1262.     pedwarn ("ANSI C++ forbids taking the sizeof a void type");
  1263.       return size_int (1);
  1264.     }
  1265.   if (code == ERROR_MARK)
  1266.     return size_int (1);
  1267.  
  1268.   /* ARM $5.3.2: ``When applied to a reference, the result is the size of the
  1269.      referenced object.'' */
  1270.   if (code == REFERENCE_TYPE)
  1271.     type = TREE_TYPE (type);
  1272.  
  1273.   /* We couldn't find anything in the ARM or the draft standard that says,
  1274.      one way or the other, if doing sizeof on something that doesn't have
  1275.      an object associated with it is correct or incorrect.  For example, if
  1276.      you declare `struct S { char str[16]; };', and in your program do
  1277.      a `sizeof (S::str)', should we flag that as an error or should we give
  1278.      the size of it?  Since it seems like a reasonable thing to do, we'll go
  1279.      with giving the value.  */
  1280.   if (code == OFFSET_TYPE)
  1281.     type = TREE_TYPE (type);
  1282.  
  1283.   /* @@ This also produces an error for a signature ref.
  1284.         In that case we should be able to do better.  */
  1285.   if (IS_SIGNATURE (type))
  1286.     {
  1287.       error ("`sizeof' applied to a signature type");
  1288.       return size_int (0);
  1289.     }
  1290.  
  1291.   if (TYPE_SIZE (type) == 0)
  1292.     {
  1293.       error ("`sizeof' applied to an incomplete type");
  1294.       return size_int (0);
  1295.     }
  1296.  
  1297.   /* Convert in case a char is more than one unit.  */
  1298.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  1299.           size_int (TYPE_PRECISION (char_type_node)));
  1300.   /* size_binop does not put the constant in range, so do it now.  */
  1301.   if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
  1302.     TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
  1303.   return t;
  1304. }
  1305.  
  1306. tree
  1307. c_sizeof_nowarn (type)
  1308.      tree type;
  1309. {
  1310.   enum tree_code code = TREE_CODE (type);
  1311.   tree t;
  1312.  
  1313.   if (code == FUNCTION_TYPE
  1314.       || code == METHOD_TYPE
  1315.       || code == VOID_TYPE
  1316.       || code == ERROR_MARK)
  1317.     return size_int (1);
  1318.   if (code == REFERENCE_TYPE)
  1319.     type = TREE_TYPE (type);
  1320.  
  1321.   if (TYPE_SIZE (type) == 0)
  1322.     {
  1323. #if 0
  1324.       /* ??? Tiemann, why have any diagnostic here?
  1325.      There is none in the corresponding function for C.  */
  1326.       warning ("sizeof applied to an incomplete type");
  1327. #endif
  1328.       return size_int (0);
  1329.     }
  1330.  
  1331.   /* Convert in case a char is more than one unit.  */
  1332.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  1333.           size_int (TYPE_PRECISION (char_type_node)));
  1334.   force_fit_type (t, 0);
  1335.   return t;
  1336. }
  1337.  
  1338. /* Implement the __alignof keyword: Return the minimum required
  1339.    alignment of TYPE, measured in bytes.  */
  1340.  
  1341. tree
  1342. c_alignof (type)
  1343.      tree type;
  1344. {
  1345.   enum tree_code code = TREE_CODE (type);
  1346.   tree t;
  1347.  
  1348.   if (code == FUNCTION_TYPE || code == METHOD_TYPE)
  1349.     return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  1350.  
  1351.   if (code == VOID_TYPE || code == ERROR_MARK)
  1352.     return size_int (1);
  1353.  
  1354.   /* C++: this is really correct!  */
  1355.   if (code == REFERENCE_TYPE)
  1356.     type = TREE_TYPE (type);
  1357.  
  1358.   /* @@ This also produces an error for a signature ref.
  1359.         In that case we should be able to do better.  */
  1360.   if (IS_SIGNATURE (type))
  1361.     {
  1362.       error ("`__alignof' applied to a signature type");
  1363.       return size_int (1);
  1364.     }
  1365.  
  1366.   t = size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  1367.   force_fit_type (t, 0);
  1368.   return t;
  1369. }
  1370.  
  1371. /* Perform default promotions for C data used in expressions.
  1372.    Arrays and functions are converted to pointers;
  1373.    enumeral types or short or char, to int.
  1374.    In addition, manifest constants symbols are replaced by their values.
  1375.  
  1376.    C++: this will automatically bash references to their target type.  */
  1377.  
  1378. tree
  1379. decay_conversion (exp)
  1380.      tree exp;
  1381. {
  1382.   register tree type = TREE_TYPE (exp);
  1383.   register enum tree_code code = TREE_CODE (type);
  1384.  
  1385.   if (code == OFFSET_TYPE /* || TREE_CODE (exp) == OFFSET_REF */ )
  1386.     {
  1387.       if (TREE_CODE (exp) == OFFSET_REF)
  1388.     return decay_conversion (resolve_offset_ref (exp));
  1389.  
  1390.       type = TREE_TYPE (type);
  1391.       code = TREE_CODE (type);
  1392.     }
  1393.  
  1394.   if (code == REFERENCE_TYPE)
  1395.     {
  1396.       exp = convert_from_reference (exp);
  1397.       type = TREE_TYPE (exp);
  1398.       code = TREE_CODE (type);
  1399.     }
  1400.  
  1401.   /* Constants can be used directly unless they're not loadable.  */
  1402.   if (TREE_CODE (exp) == CONST_DECL)
  1403.     exp = DECL_INITIAL (exp);
  1404.   /* Replace a nonvolatile const static variable with its value.  */
  1405.   else if (TREE_READONLY_DECL_P (exp))
  1406.     {
  1407.       exp = decl_constant_value (exp);
  1408.       type = TREE_TYPE (exp);
  1409.     }
  1410.  
  1411.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  1412.      Leave such NOP_EXPRs, since RHS is being used in non-lvalue context.  */
  1413.  
  1414.   if (code == VOID_TYPE)
  1415.     {
  1416.       error ("void value not ignored as it ought to be");
  1417.       return error_mark_node;
  1418.     }
  1419.   if (code == FUNCTION_TYPE)
  1420.     {
  1421.       return build_unary_op (ADDR_EXPR, exp, 0);
  1422.     }
  1423.   if (code == METHOD_TYPE)
  1424.     {
  1425.       if (TREE_CODE (exp) == OFFSET_REF)
  1426.     {
  1427.       my_friendly_assert (TREE_CODE (TREE_OPERAND (exp, 1)) == FUNCTION_DECL,
  1428.                   308);
  1429.       return build_unary_op (ADDR_EXPR, TREE_OPERAND (exp, 1), 0);
  1430.     }
  1431.       return build_unary_op (ADDR_EXPR, exp, 0);
  1432.     }
  1433.   if (code == ARRAY_TYPE)
  1434.     {
  1435.       register tree adr;
  1436.       tree restype;
  1437.       tree ptrtype;
  1438.       int constp, volatilep;
  1439.  
  1440.       if (TREE_CODE (exp) == INDIRECT_REF)
  1441.     {
  1442.       /* Stripping away the INDIRECT_REF is not the right
  1443.          thing to do for references...  */
  1444.       tree inner = TREE_OPERAND (exp, 0);
  1445.       if (TREE_CODE (TREE_TYPE (inner)) == REFERENCE_TYPE)
  1446.         {
  1447.           inner = build1 (CONVERT_EXPR,
  1448.                   build_pointer_type (TREE_TYPE (TREE_TYPE (inner))),
  1449.                   inner);
  1450.           TREE_REFERENCE_EXPR (inner) = 1;
  1451.         }
  1452.       return convert (build_pointer_type (TREE_TYPE (type)), inner);
  1453.     }
  1454.  
  1455.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  1456.     {
  1457.       tree op1 = decay_conversion (TREE_OPERAND (exp, 1));
  1458.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  1459.             TREE_OPERAND (exp, 0), op1);
  1460.     }
  1461.  
  1462.       if (!lvalue_p (exp)
  1463.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  1464.     {
  1465.       error ("invalid use of non-lvalue array");
  1466.       return error_mark_node;
  1467.     }
  1468.  
  1469.       constp = volatilep = 0;
  1470.       if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
  1471.       || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
  1472.     {
  1473.       constp = TREE_READONLY (exp);
  1474.       volatilep = TREE_THIS_VOLATILE (exp);
  1475.     }
  1476.  
  1477.       restype = TREE_TYPE (type);
  1478.       if (TYPE_READONLY (type) || TYPE_VOLATILE (type)
  1479.       || constp || volatilep)
  1480.     restype = cp_build_type_variant (restype,
  1481.                     TYPE_READONLY (type) || constp,
  1482.                     TYPE_VOLATILE (type) || volatilep);
  1483.       ptrtype = build_pointer_type (restype);
  1484.  
  1485.       if (TREE_CODE (exp) == VAR_DECL)
  1486.     {
  1487.       /* ??? This is not really quite correct
  1488.          in that the type of the operand of ADDR_EXPR
  1489.          is not the target type of the type of the ADDR_EXPR itself.
  1490.          Question is, can this lossage be avoided?  */
  1491.       adr = build1 (ADDR_EXPR, ptrtype, exp);
  1492.       if (mark_addressable (exp) == 0)
  1493.         return error_mark_node;
  1494.       TREE_CONSTANT (adr) = staticp (exp);
  1495.       TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
  1496.       return adr;
  1497.     }
  1498.       /* This way is better for a COMPONENT_REF since it can
  1499.      simplify the offset for a component.  */
  1500.       adr = build_unary_op (ADDR_EXPR, exp, 1);
  1501.       return convert (ptrtype, adr);
  1502.     }
  1503.  
  1504.   return exp;
  1505. }
  1506.  
  1507. tree
  1508. default_conversion (exp)
  1509.      tree exp;
  1510. {
  1511.   tree type;
  1512.   enum tree_code code;
  1513.  
  1514.   exp = decay_conversion (exp);
  1515.  
  1516.   type = TREE_TYPE (exp);
  1517.   code = TREE_CODE (type);
  1518.  
  1519.   if (INTEGRAL_CODE_P (code))
  1520.     {
  1521.       tree t = type_promotes_to (type);
  1522.       if (t != type)
  1523.     return convert (t, exp);
  1524.     }
  1525.   if (flag_traditional
  1526.       && TYPE_MAIN_VARIANT (type) == float_type_node)
  1527.     return convert (double_type_node, exp);
  1528.  
  1529.   return exp;
  1530. }
  1531.  
  1532. tree
  1533. build_object_ref (datum, basetype, field)
  1534.      tree datum, basetype, field;
  1535. {
  1536.   tree dtype;
  1537.   if (datum == error_mark_node)
  1538.     return error_mark_node;
  1539.  
  1540.   dtype = TREE_TYPE (datum);
  1541.   if (TREE_CODE (dtype) == REFERENCE_TYPE)
  1542.     dtype = TREE_TYPE (dtype);
  1543.   if (! IS_AGGR_TYPE_CODE (TREE_CODE (dtype)))
  1544.     {
  1545.       cp_error ("request for member `%T::%D' in expression of non-aggregate type `%T'",
  1546.         basetype, field, dtype);
  1547.       return error_mark_node;
  1548.     }
  1549.   else if (IS_SIGNATURE (IDENTIFIER_TYPE_VALUE (basetype)))
  1550.     {
  1551.       warning ("signature name in scope resolution ignored");
  1552.       return build_component_ref (datum, field, NULL_TREE, 1);
  1553.     }
  1554.   else if (is_aggr_typedef (basetype, 1))
  1555.     {
  1556.       tree real_basetype = IDENTIFIER_TYPE_VALUE (basetype);
  1557.       tree binfo = binfo_or_else (real_basetype, TREE_TYPE (datum));
  1558.       if (binfo)
  1559.     return build_component_ref (build_scoped_ref (datum, basetype),
  1560.                     field, binfo, 1);
  1561.     }
  1562.   return error_mark_node;
  1563. }
  1564.  
  1565. /* Like `build_component_ref, but uses an already found field.
  1566.    Must compute access for C_C_D.  Otherwise, ok.  */
  1567. tree
  1568. build_component_ref_1 (datum, field, protect)
  1569.      tree datum, field;
  1570.      int protect;
  1571. {
  1572.   register tree basetype = TREE_TYPE (datum);
  1573.   register enum tree_code code = TREE_CODE (basetype);
  1574.   register tree ref;
  1575.  
  1576.   if (code == REFERENCE_TYPE)
  1577.     {
  1578.       datum = convert_from_reference (datum);
  1579.       basetype = TREE_TYPE (datum);
  1580.       code = TREE_CODE (basetype);
  1581.     }
  1582.  
  1583.   if (! IS_AGGR_TYPE_CODE (code))
  1584.     {
  1585.       if (code != ERROR_MARK)
  1586.     cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
  1587.           field, datum, basetype);
  1588.       return error_mark_node;
  1589.     }
  1590.  
  1591.   if (TYPE_SIZE (basetype) == 0)
  1592.     {
  1593.       incomplete_type_error (0, basetype);
  1594.       return error_mark_node;
  1595.     }
  1596.  
  1597.   /* Look up component name in the structure type definition.  */
  1598.  
  1599.   if (field == error_mark_node)
  1600.     my_friendly_abort (115);
  1601.  
  1602.   if (TREE_STATIC (field))
  1603.     return field;
  1604.  
  1605.   if (datum == C_C_D)
  1606.     {
  1607.       enum access_type access
  1608.     = compute_access (TYPE_BINFO (current_class_type), field);
  1609.  
  1610.       if (access == access_private)
  1611.     {
  1612.       cp_error ("field `%D' is private", field);
  1613.       return error_mark_node;
  1614.     }
  1615.       else if (access == access_protected)
  1616.     {
  1617.       cp_error ("field `%D' is protected", field);
  1618.       return error_mark_node;
  1619.     }
  1620.     }
  1621.  
  1622.   ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
  1623.  
  1624.   if (TREE_READONLY (datum) || TREE_READONLY (field))
  1625.     TREE_READONLY (ref) = 1;
  1626.   if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  1627.     TREE_THIS_VOLATILE (ref) = 1;
  1628.   if (DECL_MUTABLE_P (field))
  1629.     TREE_READONLY (ref) = 0;
  1630.  
  1631.   return ref;
  1632. }
  1633.  
  1634. /* Given a COND_EXPR in T, return it in a form that we can, for
  1635.    example, use as an lvalue.  This code used to be in unary_complex_lvalue,
  1636.    but we needed it to deal with `a = (d == c) ? b : c' expressions, where
  1637.    we're dealing with aggregates.  So, we now call this in unary_complex_lvalue,
  1638.    and in build_modify_expr.  The case (in particular) that led to this was
  1639.    with CODE == ADDR_EXPR, since it's not an lvalue when we'd get it there.  */
  1640. static tree
  1641. rationalize_conditional_expr (code, t)
  1642.      enum tree_code code;
  1643.      tree t;
  1644. {
  1645.   return
  1646.     build_conditional_expr (TREE_OPERAND (t, 0),
  1647.                 build_unary_op (code, TREE_OPERAND (t, 1), 0),
  1648.                 build_unary_op (code, TREE_OPERAND (t, 2), 0));
  1649. }
  1650.  
  1651. tree
  1652. build_component_ref (datum, component, basetype_path, protect)
  1653.      tree datum, component, basetype_path;
  1654.      int protect;
  1655. {
  1656.   register tree basetype = TREE_TYPE (datum);
  1657.   register enum tree_code code = TREE_CODE (basetype);
  1658.   register tree field = NULL;
  1659.   register tree ref;
  1660.  
  1661.   /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it. */
  1662.   switch (TREE_CODE (datum))
  1663.     {
  1664.     case COMPOUND_EXPR:
  1665.       {
  1666.     tree value = build_component_ref (TREE_OPERAND (datum, 1), component,
  1667.                       basetype_path, protect);
  1668.     return build (COMPOUND_EXPR, TREE_TYPE (value),
  1669.               TREE_OPERAND (datum, 0), value);
  1670.       }
  1671.     case COND_EXPR:
  1672.       return build_conditional_expr
  1673.     (TREE_OPERAND (datum, 0),
  1674.      build_component_ref (TREE_OPERAND (datum, 1), component,
  1675.                   basetype_path, protect),
  1676.      build_component_ref (TREE_OPERAND (datum, 2), component,
  1677.                   basetype_path, protect));
  1678.     }
  1679.  
  1680.   if (code == REFERENCE_TYPE)
  1681.     {
  1682. #if 0
  1683.       /* TREE_REFERENCE_EXPRs are not converted by `convert_from_reference'.
  1684.      @@ Maybe that is not right.  */
  1685.       if (TREE_REFERENCE_EXPR (datum))
  1686.     datum = build1 (INDIRECT_REF, TREE_TYPE (basetype), datum);
  1687.       else
  1688. #endif
  1689.     datum = convert_from_reference (datum);
  1690.       basetype = TREE_TYPE (datum);
  1691.       code = TREE_CODE (basetype);
  1692.     }
  1693.  
  1694.   /* First, see if there is a field or component with name COMPONENT. */
  1695.   if (TREE_CODE (component) == TREE_LIST)
  1696.     {
  1697.       my_friendly_assert (!(TREE_CHAIN (component) == NULL_TREE
  1698.         && DECL_CHAIN (TREE_VALUE (component)) == NULL_TREE), 309);
  1699.       return build (COMPONENT_REF, TREE_TYPE (component), datum, component);
  1700.     }
  1701. #if 0
  1702.   if (TREE_CODE (component) == TYPE_EXPR)
  1703.     return build_component_type_expr (datum, component, NULL_TREE, protect);
  1704. #endif
  1705.  
  1706.   if (! IS_AGGR_TYPE_CODE (code))
  1707.     {
  1708.       if (code != ERROR_MARK)
  1709.     cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
  1710.           component, datum, basetype);
  1711.       return error_mark_node;
  1712.     }
  1713.  
  1714.   if (TYPE_SIZE (basetype) == 0)
  1715.     {
  1716.       incomplete_type_error (0, basetype);
  1717.       return error_mark_node;
  1718.     }
  1719.  
  1720.   if (TREE_CODE (component) == BIT_NOT_EXPR)
  1721.     {
  1722.       if (TYPE_IDENTIFIER (basetype) != TREE_OPERAND (component, 0))
  1723.     {
  1724.       cp_error ("destructor specifier `%T::~%T' must have matching names",
  1725.             basetype, TREE_OPERAND (component, 0));
  1726.       return error_mark_node;
  1727.     }
  1728.       if (! TYPE_HAS_DESTRUCTOR (basetype))
  1729.     {
  1730.       cp_error ("type `%T' has no destructor", basetype);
  1731.       return error_mark_node;
  1732.     }
  1733.       return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype), 0);
  1734.     }
  1735.  
  1736.   /* Look up component name in the structure type definition.  */
  1737.   if (CLASSTYPE_VFIELD (basetype)
  1738.       && DECL_NAME (CLASSTYPE_VFIELD (basetype)) == component)
  1739.     /* Special-case this because if we use normal lookups in an ambiguous
  1740.        hierarchy, the compiler will abort (because vptr lookups are
  1741.        not supposed to be ambiguous.  */
  1742.     field = CLASSTYPE_VFIELD (basetype);
  1743.   else
  1744.     {
  1745.       if (basetype_path == NULL_TREE)
  1746.     basetype_path = TYPE_BINFO (basetype);
  1747.       field = lookup_field (basetype_path, component,
  1748.                 protect && ! VFIELD_NAME_P (component), 0);
  1749.       if (field == error_mark_node)
  1750.     return error_mark_node;
  1751.  
  1752.       if (field == NULL_TREE)
  1753.     {
  1754.       /* Not found as a data field, look for it as a method.  If found,
  1755.          then if this is the only possible one, return it, else
  1756.          report ambiguity error.  */
  1757.       tree fndecls = lookup_fnfields (basetype_path, component, 1);
  1758.       if (fndecls == error_mark_node)
  1759.         return error_mark_node;
  1760.       if (fndecls)
  1761.         {
  1762.           if (TREE_CHAIN (fndecls) == NULL_TREE
  1763.           && DECL_CHAIN (TREE_VALUE (fndecls)) == NULL_TREE)
  1764.         {
  1765.           enum access_type access;
  1766.           tree fndecl;
  1767.  
  1768.           /* Unique, so use this one now.  */
  1769.           basetype = TREE_PURPOSE (fndecls);
  1770.           fndecl = TREE_VALUE (fndecls);
  1771.           access = compute_access (TREE_PURPOSE (fndecls), fndecl);
  1772.           if (access == access_public)
  1773.             {
  1774.               if (DECL_VINDEX (fndecl)
  1775.               && ! resolves_to_fixed_type_p (datum, 0))
  1776.             {
  1777.               tree addr = build_unary_op (ADDR_EXPR, datum, 0);
  1778.               addr = convert_pointer_to (DECL_CONTEXT (fndecl), addr);
  1779.               datum = build_indirect_ref (addr, NULL_PTR);
  1780.               my_friendly_assert (datum != error_mark_node, 310);
  1781.               fndecl = build_vfn_ref (&addr, datum, DECL_VINDEX (fndecl));
  1782.             }
  1783.               assemble_external (fndecl);
  1784.               return fndecl;
  1785.             }
  1786.           if (access == access_protected)
  1787.             cp_error ("member function `%D' is protected", fndecl);
  1788.           else
  1789.             cp_error ("member function `%D' is private", fndecl);
  1790.           return error_mark_node;
  1791.         }
  1792.           else
  1793.         {
  1794.           /* Just act like build_offset_ref, since the object does
  1795.                      not matter unless we're actually calling the function.  */
  1796.           tree t;
  1797.  
  1798.           for (t = TREE_VALUE (fndecls); t; t = DECL_CHAIN (t))
  1799.             assemble_external (t);
  1800.  
  1801.           t = build_tree_list (error_mark_node, fndecls);
  1802.           TREE_TYPE (t) = build_offset_type (basetype,
  1803.                              unknown_type_node);
  1804.           return t;
  1805.         }
  1806.         }
  1807.  
  1808. #if 0
  1809.       if (component == ansi_opname[(int) TYPE_EXPR])
  1810.         cp_error ("`%#T' has no such type conversion operator", basetype);
  1811.       else
  1812. #endif
  1813.         cp_error ("`%#T' has no member named `%D'", basetype, component);
  1814.       return error_mark_node;
  1815.     }
  1816.       else if (TREE_TYPE (field) == error_mark_node)
  1817.     return error_mark_node;
  1818.  
  1819.       if (TREE_CODE (field) != FIELD_DECL)
  1820.     {
  1821.       if (TREE_CODE (field) == TYPE_DECL)
  1822.         {
  1823.           cp_error ("invalid use of type decl `%#D' as expression", field);
  1824.           return error_mark_node;
  1825.         }
  1826.        if (DECL_RTL (field) != 0)
  1827.         assemble_external (field);
  1828.       TREE_USED (field) = 1;
  1829.       return field;
  1830.     }
  1831.     }
  1832.  
  1833.   if (DECL_FIELD_CONTEXT (field) != basetype
  1834.       && TYPE_USES_COMPLEX_INHERITANCE (basetype))
  1835.     {
  1836.       tree addr = build_unary_op (ADDR_EXPR, datum, 0);
  1837.       if (integer_zerop (addr))
  1838.     {
  1839.       error ("invalid reference to NULL ptr, use ptr-to-member instead");
  1840.       return error_mark_node;
  1841.     }
  1842.       addr = convert_pointer_to (DECL_FIELD_CONTEXT (field), addr);
  1843.       datum = build_indirect_ref (addr, NULL_PTR);
  1844.       my_friendly_assert (datum != error_mark_node, 311);
  1845.     }
  1846.   ref = fold (build (COMPONENT_REF, TREE_TYPE (field),
  1847.              break_out_cleanups (datum), field));
  1848.  
  1849.   if (TREE_READONLY (datum) || TREE_READONLY (field))
  1850.     TREE_READONLY (ref) = 1;
  1851.   if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  1852.     TREE_THIS_VOLATILE (ref) = 1;
  1853.   if (DECL_MUTABLE_P (field))
  1854.     TREE_READONLY (ref) = 0;
  1855.  
  1856.   return ref;
  1857. }
  1858.  
  1859. /* Given an expression PTR for a pointer, return an expression
  1860.    for the value pointed to.
  1861.    ERRORSTRING is the name of the operator to appear in error messages.
  1862.  
  1863.    This function may need to overload OPERATOR_FNNAME.
  1864.    Must also handle REFERENCE_TYPEs for C++.  */
  1865.  
  1866. tree
  1867. build_x_indirect_ref (ptr, errorstring)
  1868.      tree ptr;
  1869.      char *errorstring;
  1870. {
  1871.   tree rval = build_opfncall (INDIRECT_REF, LOOKUP_NORMAL, ptr, NULL_TREE, NULL_TREE);
  1872.   if (rval)
  1873.     return rval;
  1874.   return build_indirect_ref (ptr, errorstring);
  1875. }
  1876.  
  1877. tree
  1878. build_indirect_ref (ptr, errorstring)
  1879.      tree ptr;
  1880.      char *errorstring;
  1881. {
  1882.   register tree pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE ?
  1883.                ptr : default_conversion (ptr));
  1884.   register tree type = TREE_TYPE (pointer);
  1885.  
  1886.   if (ptr == current_class_decl)
  1887.     return C_C_D;
  1888.  
  1889.   if (IS_AGGR_TYPE (type))
  1890.     {
  1891.       ptr = build_expr_type_conversion (WANT_POINTER, pointer, 1);
  1892.  
  1893.       if (ptr)
  1894.     {
  1895.       pointer = ptr;
  1896.       type = TREE_TYPE (pointer);
  1897.     }
  1898.     }
  1899.  
  1900.   if (TREE_CODE (type) == POINTER_TYPE || TREE_CODE (type) == REFERENCE_TYPE)
  1901.     {
  1902.       if (TREE_CODE (pointer) == ADDR_EXPR
  1903.       && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (pointer, 0)))
  1904.           == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
  1905.       && (TREE_READONLY (TREE_OPERAND (pointer, 0))
  1906.           == TYPE_READONLY (TREE_TYPE (type)))
  1907.       && (TREE_THIS_VOLATILE (TREE_OPERAND (pointer, 0))
  1908.           == TYPE_VOLATILE (TREE_TYPE (type))))
  1909.     return TREE_OPERAND (pointer, 0);
  1910.       else
  1911.     {
  1912.       tree t = TREE_TYPE (type);
  1913.       register tree ref = build1 (INDIRECT_REF,
  1914.                       TYPE_MAIN_VARIANT (t), pointer);
  1915.  
  1916.       TREE_READONLY (ref) = TYPE_READONLY (t);
  1917.       TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
  1918.       TREE_SIDE_EFFECTS (ref)
  1919.         = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer);
  1920.       return ref;
  1921.     }
  1922.     }
  1923.   /* `pointer' won't be an error_mark_node if we were given a
  1924.      pointer to member, so it's cool to check for this here.  */
  1925.   else if (TYPE_PTRMEMFUNC_P (type))
  1926.     error ("invalid use of `%s' on pointer to member function", errorstring);
  1927.   else if (TREE_CODE (type) == RECORD_TYPE
  1928.        && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
  1929.     error ("cannot dereference signature pointer/reference");
  1930.   else if (pointer != error_mark_node)
  1931.     {
  1932.       if (errorstring)
  1933.     error ("invalid type argument of `%s'", errorstring);
  1934.       else
  1935.     error ("invalid type argument");
  1936.     }
  1937.   return error_mark_node;
  1938. }
  1939.  
  1940. /* This handles expressions of the form "a[i]", which denotes
  1941.    an array reference.
  1942.  
  1943.    This is logically equivalent in C to *(a+i), but we may do it differently.
  1944.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  1945.    This avoids forcing the array out of registers, and can work on
  1946.    arrays that are not lvalues (for example, members of structures returned
  1947.    by functions).
  1948.  
  1949.    If INDEX is of some user-defined type, it must be converted to
  1950.    integer type.  Otherwise, to make a compatible PLUS_EXPR, it
  1951.    will inherit the type of the array, which will be some pointer type.  */
  1952.  
  1953. tree
  1954. build_x_array_ref (array, index)
  1955.      tree array, index;
  1956. {
  1957.   tree rval = build_opfncall (ARRAY_REF, LOOKUP_NORMAL, array, index, NULL_TREE);
  1958.   if (rval)
  1959.     return rval;
  1960.   return build_array_ref (array, index);
  1961. }
  1962.  
  1963. tree
  1964. build_array_ref (array, idx)
  1965.      tree array, idx;
  1966. {
  1967.   tree itype;
  1968.  
  1969.   if (idx == 0)
  1970.     {
  1971.       error ("subscript missing in array reference");
  1972.       return error_mark_node;
  1973.     }
  1974.  
  1975.   if (TREE_TYPE (array) == error_mark_node
  1976.       || TREE_TYPE (idx) == error_mark_node)
  1977.     return error_mark_node;
  1978.  
  1979.   itype = TREE_TYPE (idx);
  1980.  
  1981.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  1982.       && TREE_CODE (array) != INDIRECT_REF)
  1983.     {
  1984.       tree rval, type;
  1985.  
  1986.       /* Subscripting with type char is likely to lose
  1987.      on a machine where chars are signed.
  1988.      So warn on any machine, but optionally.
  1989.      Don't warn for unsigned char since that type is safe.
  1990.      Don't warn for signed char because anyone who uses that
  1991.      must have done so deliberately.  */
  1992.       if (warn_char_subscripts
  1993.       && TYPE_MAIN_VARIANT (TREE_TYPE (idx)) == char_type_node)
  1994.     warning ("array subscript has type `char'");
  1995.  
  1996.       /* Apply default promotions *after* noticing character types.  */
  1997.       idx = default_conversion (idx);
  1998.  
  1999.       if (TREE_CODE (TREE_TYPE (idx)) != INTEGER_TYPE)
  2000.     {
  2001.       error ("array subscript is not an integer");
  2002.       return error_mark_node;
  2003.     }
  2004.  
  2005.       /* An array that is indexed by a non-constant
  2006.      cannot be stored in a register; we must be able to do
  2007.      address arithmetic on its address.
  2008.      Likewise an array of elements of variable size.  */
  2009.       if (TREE_CODE (idx) != INTEGER_CST
  2010.       || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
  2011.           && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
  2012.     {
  2013.       if (mark_addressable (array) == 0)
  2014.         return error_mark_node;
  2015.     }
  2016.       /* An array that is indexed by a constant value which is not within
  2017.      the array bounds cannot be stored in a register either; because we
  2018.      would get a crash in store_bit_field/extract_bit_field when trying
  2019.      to access a non-existent part of the register.  */
  2020.       if (TREE_CODE (idx) == INTEGER_CST
  2021.       && TYPE_VALUES (TREE_TYPE (array))
  2022.       && ! int_fits_type_p (idx, TYPE_VALUES (TREE_TYPE (array))))
  2023.     {
  2024.       if (mark_addressable (array) == 0)
  2025.         return error_mark_node;
  2026.     }
  2027.  
  2028.       if (pedantic && !lvalue_p (array))
  2029.     pedwarn ("ANSI C++ forbids subscripting non-lvalue array");
  2030.  
  2031.       /* Note in C++ it is valid to subscript a `register' array, since
  2032.      it is valid to take the address of something with that
  2033.      storage specification.  */
  2034.       if (extra_warnings)
  2035.     {
  2036.       tree foo = array;
  2037.       while (TREE_CODE (foo) == COMPONENT_REF)
  2038.         foo = TREE_OPERAND (foo, 0);
  2039.       if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
  2040.         warning ("subscripting array declared `register'");
  2041.     }
  2042.  
  2043.       type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
  2044.       rval = build (ARRAY_REF, type, array, idx);
  2045.       /* Array ref is const/volatile if the array elements are
  2046.      or if the array is..  */
  2047.       TREE_READONLY (rval)
  2048.     |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
  2049.         | TREE_READONLY (array));
  2050.       TREE_SIDE_EFFECTS (rval)
  2051.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  2052.         | TREE_SIDE_EFFECTS (array));
  2053.       TREE_THIS_VOLATILE (rval)
  2054.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  2055.         /* This was added by rms on 16 Nov 91.
  2056.            It fixes  vol struct foo *a;  a->elts[1] 
  2057.            in an inline function.
  2058.            Hope it doesn't break something else.  */
  2059.         | TREE_THIS_VOLATILE (array));
  2060.       return require_complete_type (fold (rval));
  2061.     }
  2062.  
  2063.   {
  2064.     tree ar = default_conversion (array);
  2065.     tree ind = default_conversion (idx);
  2066.  
  2067.     /* Put the integer in IND to simplify error checking.  */
  2068.     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
  2069.       {
  2070.     tree temp = ar;
  2071.     ar = ind;
  2072.     ind = temp;
  2073.       }
  2074.  
  2075.     if (ar == error_mark_node)
  2076.       return ar;
  2077.  
  2078.     if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
  2079.       {
  2080.     error ("subscripted value is neither array nor pointer");
  2081.     return error_mark_node;
  2082.       }
  2083.     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  2084.       {
  2085.     error ("array subscript is not an integer");
  2086.     return error_mark_node;
  2087.       }
  2088.  
  2089.     return build_indirect_ref (build_binary_op_nodefault (PLUS_EXPR, ar, ind, PLUS_EXPR),
  2090.                    "array indexing");
  2091.   }
  2092. }
  2093.  
  2094. /* Build a function call to function FUNCTION with parameters PARAMS.
  2095.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  2096.    TREE_VALUE of each node is a parameter-expression.
  2097.    FUNCTION's data type may be a function type or a pointer-to-function.
  2098.  
  2099.    For C++: If FUNCTION's data type is a TREE_LIST, then the tree list
  2100.    is the list of possible methods that FUNCTION could conceivably
  2101.    be.  If the list of methods comes from a class, then it will be
  2102.    a list of lists (where each element is associated with the class
  2103.    that produced it), otherwise it will be a simple list (for
  2104.    functions overloaded in global scope).
  2105.  
  2106.    In the first case, TREE_VALUE (function) is the head of one of those
  2107.    lists, and TREE_PURPOSE is the name of the function.
  2108.  
  2109.    In the second case, TREE_PURPOSE (function) is the function's
  2110.    name directly.
  2111.  
  2112.    DECL is the class instance variable, usually CURRENT_CLASS_DECL.  */
  2113.  
  2114. /*
  2115.  * [eichin:19911015.1726EST] actually return a possibly incomplete
  2116.  * type
  2117.  */
  2118. tree
  2119. build_x_function_call (function, params, decl)
  2120.      tree function, params, decl;
  2121. {
  2122.   tree type;
  2123.   int is_method;
  2124.  
  2125.   if (function == error_mark_node)
  2126.     return error_mark_node;
  2127.  
  2128.   type = TREE_TYPE (function);
  2129.   is_method = ((TREE_CODE (function) == TREE_LIST
  2130.         && current_class_type != NULL_TREE
  2131.         && IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (function)) == function)
  2132.            || TREE_CODE (function) == IDENTIFIER_NODE
  2133.            || TREE_CODE (type) == METHOD_TYPE
  2134.            || TYPE_PTRMEMFUNC_P (type));
  2135.  
  2136.   /* Handle methods, friends, and overloaded functions, respectively.  */
  2137.   if (is_method)
  2138.     {
  2139.       if (TREE_CODE (function) == FUNCTION_DECL)
  2140.     {
  2141.       if (DECL_NAME (function))
  2142.         function = DECL_NAME (function);
  2143.       else
  2144.         function = TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function));
  2145.     }
  2146.       else if (TREE_CODE (function) == TREE_LIST)
  2147.     {
  2148. #if 0
  2149.       if (TREE_CODE (TREE_VALUE (function)) == TREE_LIST)
  2150.         function = TREE_PURPOSE (TREE_VALUE (function));
  2151.       else
  2152.         function = TREE_PURPOSE (function);
  2153. #else
  2154.       my_friendly_assert (TREE_CODE (TREE_VALUE (function)) == FUNCTION_DECL, 312);
  2155.       function = TREE_PURPOSE (function);
  2156. #endif
  2157.     }
  2158.       else if (TREE_CODE (function) != IDENTIFIER_NODE)
  2159.     {
  2160.       if (TREE_CODE (function) == OFFSET_REF)
  2161.         {
  2162.           if (TREE_OPERAND (function, 0))
  2163.         decl = TREE_OPERAND (function, 0);
  2164.         }
  2165.       /* Call via a pointer to member function.  */
  2166.       if (decl == NULL_TREE)
  2167.         {
  2168.           error ("pointer to member function called, but not in class scope");
  2169.           return error_mark_node;
  2170.         }
  2171.       /* What other type of POINTER_TYPE could this be? */
  2172.       if (TREE_CODE (TREE_TYPE (function)) != POINTER_TYPE
  2173.           && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (function))
  2174.           && TREE_CODE (function) != OFFSET_REF)
  2175.         function = build (OFFSET_REF, TREE_TYPE (type), NULL_TREE, function);
  2176.       goto do_x_function;
  2177.     }
  2178.  
  2179.       /* this is an abbreviated method call.
  2180.          must go through here in case it is a virtual function.
  2181.      @@ Perhaps this could be optimized.  */
  2182.  
  2183.       if (decl == NULL_TREE)
  2184.     {
  2185.       if (current_class_type == NULL_TREE)
  2186.         {
  2187.           error ("object missing in call to method `%s'",
  2188.              IDENTIFIER_POINTER (function));
  2189.           return error_mark_node;
  2190.         }
  2191.       /* Yow: call from a static member function.  */
  2192.       decl = build1 (NOP_EXPR, build_pointer_type (current_class_type),
  2193.              error_mark_node);
  2194.       decl = build_indirect_ref (decl, NULL_PTR);
  2195.     }
  2196.  
  2197.       return build_method_call (decl, function, params,
  2198.                 NULL_TREE, LOOKUP_NORMAL);
  2199.     }
  2200.   else if (TREE_CODE (function) == COMPONENT_REF
  2201.        && type == unknown_type_node)
  2202.     {
  2203.       /* Should we undo what was done in build_component_ref? */
  2204.       if (TREE_CODE (TREE_PURPOSE (TREE_OPERAND (function, 1))) == TREE_VEC)
  2205.     /* Get the name that build_component_ref hid. */
  2206.     function = DECL_NAME (TREE_VALUE (TREE_OPERAND (function, 1)));
  2207.       else
  2208.     function = TREE_PURPOSE (TREE_OPERAND (function, 1));
  2209.       return build_method_call (decl, function, params,
  2210.                 NULL_TREE, LOOKUP_NORMAL);
  2211.     }
  2212.   else if (TREE_CODE (function) == TREE_LIST)
  2213.     {
  2214.       if (TREE_VALUE (function) == NULL_TREE)
  2215.     {
  2216.       cp_error ("function `%D' declared overloaded, but no definitions appear with which to resolve it?!?",
  2217.             TREE_PURPOSE (function));
  2218.       return error_mark_node;
  2219.     }
  2220.       else
  2221.     {
  2222.       tree val = TREE_VALUE (function);
  2223.  
  2224.       if (TREE_CODE (val) == TEMPLATE_DECL)
  2225.         return build_overload_call_maybe
  2226.           (function, params, LOOKUP_COMPLAIN, (struct candidate *)0);
  2227.       else if (DECL_CHAIN (val) != NULL_TREE)
  2228.         return build_overload_call
  2229.           (function, params, LOOKUP_COMPLAIN, (struct candidate *)0);
  2230.       else
  2231.         my_friendly_abort (360);
  2232.     }
  2233.     }
  2234.  
  2235.  do_x_function:
  2236.   if (TREE_CODE (function) == OFFSET_REF)
  2237.     {
  2238.       /* If the component is a data element (or a virtual function), we play
  2239.      games here to make things work.  */
  2240.       tree decl_addr;
  2241.  
  2242.       if (TREE_OPERAND (function, 0))
  2243.     decl = TREE_OPERAND (function, 0);
  2244.       else
  2245.     decl = C_C_D;
  2246.  
  2247.       decl_addr = build_unary_op (ADDR_EXPR, decl, 0);
  2248.       function = get_member_function_from_ptrfunc (&decl_addr,
  2249.                            TREE_OPERAND (function, 1));
  2250.       params = tree_cons (NULL_TREE, decl_addr, params);
  2251.       return build_function_call (function, params);
  2252.     }
  2253.  
  2254.   type = TREE_TYPE (function);
  2255.   if (type != error_mark_node)
  2256.     {
  2257.       if (TREE_CODE (type) == REFERENCE_TYPE)
  2258.     type = TREE_TYPE (type);
  2259.  
  2260.       if (TYPE_LANG_SPECIFIC (type) && TYPE_OVERLOADS_CALL_EXPR (type))
  2261.     return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, function, params, NULL_TREE);
  2262.     }
  2263.  
  2264.   if (is_method)
  2265.     {
  2266.       tree fntype = TREE_TYPE (function);
  2267.       tree ctypeptr;
  2268.  
  2269.       /* Explicitly named method?  */
  2270.       if (TREE_CODE (function) == FUNCTION_DECL)
  2271.     ctypeptr = build_pointer_type (DECL_CLASS_CONTEXT (function));
  2272.       /* Expression with ptr-to-method type?  It could either be a plain
  2273.      usage, or it might be a case where the ptr-to-method is being
  2274.      passed in as an argument.  */
  2275.       else if (TYPE_PTRMEMFUNC_P (fntype))
  2276.     {
  2277.       tree rec = TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (fntype)));
  2278.       ctypeptr = build_pointer_type (rec);
  2279.     }
  2280.       /* Unexpected node type?  */
  2281.       else
  2282.     my_friendly_abort (116);
  2283.       if (decl == NULL_TREE)
  2284.     {
  2285.       if (current_function_decl
  2286.           && DECL_STATIC_FUNCTION_P (current_function_decl))
  2287.         error ("invalid call to member function needing `this' in static member function scope");
  2288.       else
  2289.         error ("pointer to member function called, but not in class scope");
  2290.       return error_mark_node;
  2291.     }
  2292.       if (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE
  2293.       && ! TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))
  2294.     {
  2295.       decl = build_unary_op (ADDR_EXPR, decl, 0);
  2296.       decl = convert_pointer_to (TREE_TYPE (ctypeptr), decl);
  2297.     }
  2298.       else
  2299.     decl = build_c_cast (ctypeptr, decl, 0);
  2300.       params = tree_cons (NULL_TREE, decl, params);
  2301.     }
  2302.  
  2303.   return build_function_call (function, params);
  2304. }
  2305.  
  2306. /* Resolve a pointer to member function.  INSTANCE is the object
  2307.    instance to use, if the member points to a virtual member.  */
  2308.  
  2309. tree
  2310. get_member_function_from_ptrfunc (instance_ptrptr, function)
  2311.      tree *instance_ptrptr;
  2312.      tree function;
  2313. {
  2314.   if (TREE_CODE (function) == OFFSET_REF)
  2315.     {
  2316.       function = TREE_OPERAND (function, 1);
  2317.     }
  2318.  
  2319.   if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
  2320.     {
  2321.       tree fntype, index, e1, delta, delta2, e2, e3, aref, vtbl;
  2322.       tree instance;
  2323.  
  2324.       tree instance_ptr = *instance_ptrptr;
  2325.  
  2326.       if (TREE_SIDE_EFFECTS (instance_ptr))
  2327.     instance_ptr = save_expr (instance_ptr);
  2328.  
  2329.       if (TREE_SIDE_EFFECTS (function))
  2330.     function = save_expr (function);
  2331.  
  2332.       fntype = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (function));
  2333.       index = save_expr (build_component_ref (function,
  2334.                           index_identifier,
  2335.                           0, 0));
  2336.       e1 = build (GT_EXPR, boolean_type_node, index,
  2337.           convert (delta_type_node, integer_zero_node));
  2338.       delta = convert (ptrdiff_type_node,
  2339.                build_component_ref (function, delta_identifier, 0, 0));
  2340.       delta2 = DELTA2_FROM_PTRMEMFUNC (function);
  2341.  
  2342.       /* convert down to the right base, before using the instance. */
  2343.       instance
  2344.     = convert_pointer_to_real (TYPE_METHOD_BASETYPE (TREE_TYPE (fntype)),
  2345.                    instance_ptr);
  2346.       if (instance == error_mark_node)
  2347.     return instance;
  2348.  
  2349.       vtbl = convert_pointer_to (ptr_type_node, instance);
  2350.       vtbl
  2351.     = build (PLUS_EXPR,
  2352.          build_pointer_type (build_pointer_type (vtable_entry_type)),
  2353.          vtbl, convert (ptrdiff_type_node, delta2));
  2354.       vtbl = build_indirect_ref (vtbl, NULL_PTR);
  2355.       aref = build_array_ref (vtbl, build_binary_op (MINUS_EXPR,
  2356.                              index,
  2357.                              integer_one_node, 1));
  2358.       if (! flag_vtable_thunks)
  2359.     {
  2360.       aref = save_expr (aref);
  2361.  
  2362.       /* Save the intermediate result in a SAVE_EXPR so we don't have to
  2363.          compute each component of the virtual function pointer twice.  */ 
  2364.       if (/* !building_cleanup && */ TREE_CODE (aref) == INDIRECT_REF)
  2365.         TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
  2366.       
  2367.       delta = build_binary_op (PLUS_EXPR,
  2368.                    build_conditional_expr (e1, build_component_ref (aref, delta_identifier, 0, 0), integer_zero_node),
  2369.                    delta, 1);
  2370.     }
  2371.  
  2372.       *instance_ptrptr = build (PLUS_EXPR, TREE_TYPE (instance_ptr),
  2373.                 instance_ptr, delta);
  2374.       if (flag_vtable_thunks)
  2375.     e2 = aref;
  2376.       else
  2377.     e2 = build_component_ref (aref, pfn_identifier, 0, 0);
  2378.  
  2379.       e3 = PFN_FROM_PTRMEMFUNC (function);
  2380.       TREE_TYPE (e2) = TREE_TYPE (e3);
  2381.       function = build_conditional_expr (e1, e2, e3);
  2382.  
  2383.       /* Make sure this doesn't get evaluated first inside one of the
  2384.          branches of the COND_EXPR.  */
  2385.       if (TREE_CODE (instance_ptr) == SAVE_EXPR)
  2386.     function = build (COMPOUND_EXPR, TREE_TYPE (function),
  2387.               instance_ptr, function);
  2388.     }
  2389.   return function;
  2390. }
  2391.  
  2392. tree
  2393. build_function_call_real (function, params, require_complete, flags)
  2394.      tree function, params;
  2395.      int require_complete, flags;
  2396. {
  2397.   register tree fntype, fndecl;
  2398.   register tree value_type;
  2399.   register tree coerced_params;
  2400.   tree name = NULL_TREE, assembler_name = NULL_TREE;
  2401.   int is_method;
  2402.  
  2403.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2404.      Strip such NOP_EXPRs, since FUNCTION is used in non-lvalue context.  */
  2405.   if (TREE_CODE (function) == NOP_EXPR
  2406.       && TREE_TYPE (function) == TREE_TYPE (TREE_OPERAND (function, 0)))
  2407.     function = TREE_OPERAND (function, 0);
  2408.  
  2409.   if (TREE_CODE (function) == FUNCTION_DECL)
  2410.     {
  2411.       name = DECL_NAME (function);
  2412.       assembler_name = DECL_ASSEMBLER_NAME (function);
  2413.  
  2414.       GNU_xref_call (current_function_decl,
  2415.              IDENTIFIER_POINTER (name ? name
  2416.                      : TYPE_IDENTIFIER (DECL_CLASS_CONTEXT (function))));
  2417.       assemble_external (function);
  2418.       fndecl = function;
  2419.  
  2420.       /* Convert anything with function type to a pointer-to-function.  */
  2421.       if (pedantic
  2422.       && name
  2423.       && IDENTIFIER_LENGTH (name) == 4
  2424.       && ! strcmp (IDENTIFIER_POINTER (name), "main")
  2425.       && DECL_CONTEXT (function) == NULL_TREE)
  2426.     {
  2427.       pedwarn ("ANSI C++ forbids calling `main' from within program");
  2428.     }
  2429.  
  2430.       if (pedantic && DECL_THIS_INLINE (function) && ! DECL_INITIAL (function)
  2431.       && ! DECL_ARTIFICIAL (function)
  2432.       && ! DECL_PENDING_INLINE_INFO (function))
  2433.     cp_pedwarn ("inline function `%#D' called before definition",
  2434.             function);
  2435.  
  2436.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  2437.      (because calling an inline function does not mean the function
  2438.      needs to be separately compiled).  */
  2439.  
  2440.       if (DECL_INLINE (function))
  2441.     {
  2442.       /* Is it a synthesized method that needs to be synthesized?  */
  2443.       if (DECL_ARTIFICIAL (function) && ! flag_no_inline
  2444.           && ! DECL_INITIAL (function)
  2445.           /* Kludge: don't synthesize for default args.  */
  2446.           && current_function_decl)
  2447.         synthesize_method (function);
  2448.  
  2449.       fntype = build_type_variant (TREE_TYPE (function),
  2450.                        TREE_READONLY (function),
  2451.                        TREE_THIS_VOLATILE (function));
  2452.       function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
  2453.     }
  2454.       else
  2455.     {
  2456.       assemble_external (function);
  2457.       TREE_USED (function) = 1;
  2458.       function = default_conversion (function);
  2459.     }
  2460.     }
  2461.   else
  2462.     {
  2463.       fndecl = NULL_TREE;
  2464.  
  2465.       /* Convert anything with function type to a pointer-to-function.  */
  2466.       if (function == error_mark_node)
  2467.     return error_mark_node;
  2468.       function = default_conversion (function);
  2469.     }
  2470.  
  2471.   fntype = TREE_TYPE (function);
  2472.  
  2473.   if (TYPE_PTRMEMFUNC_P (fntype))
  2474.     {
  2475.       tree instance_ptr = build_unary_op (ADDR_EXPR, C_C_D, 0);
  2476.       fntype = TYPE_PTRMEMFUNC_FN_TYPE (fntype);
  2477.       function = get_member_function_from_ptrfunc (&instance_ptr, function);
  2478.     }
  2479.  
  2480.   is_method = (TREE_CODE (fntype) == POINTER_TYPE
  2481.            && TREE_CODE (TREE_TYPE (fntype)) == METHOD_TYPE);
  2482.  
  2483.   if (!((TREE_CODE (fntype) == POINTER_TYPE
  2484.      && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE)
  2485.     || is_method))
  2486.     {
  2487.       cp_error ("`%E' cannot be used as a function", function);
  2488.       return error_mark_node;
  2489.     }
  2490.  
  2491.   /* fntype now gets the type of function pointed to.  */
  2492.   fntype = TREE_TYPE (fntype);
  2493.  
  2494.   /* Convert the parameters to the types declared in the
  2495.      function prototype, or apply default promotions.  */
  2496.  
  2497.   if (flags & LOOKUP_COMPLAIN)
  2498.     coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
  2499.                     params, fndecl, LOOKUP_NORMAL);
  2500.   else
  2501.     coerced_params = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
  2502.                     params, fndecl, 0);
  2503.  
  2504.   if (coerced_params == error_mark_node)
  2505.     if (flags & LOOKUP_SPECULATIVELY)
  2506.       return NULL_TREE;
  2507.     else
  2508.       return error_mark_node;
  2509.  
  2510.   /* Check for errors in format strings.  */
  2511.  
  2512.   if (warn_format && (name || assembler_name))
  2513.     check_function_format (name, assembler_name, coerced_params);
  2514.  
  2515.   /* Recognize certain built-in functions so we can make tree-codes
  2516.      other than CALL_EXPR.  We do this when it enables fold-const.c
  2517.      to do something useful.  */
  2518.  
  2519.   if (TREE_CODE (function) == ADDR_EXPR
  2520.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
  2521.       && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
  2522.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  2523.       {
  2524.       case BUILT_IN_ABS:
  2525.       case BUILT_IN_LABS:
  2526.       case BUILT_IN_FABS:
  2527.     if (coerced_params == 0)
  2528.       return integer_zero_node;
  2529.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  2530.       }
  2531.  
  2532.   /* C++ */
  2533.   value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
  2534.   {
  2535.     register tree result = 
  2536.       build (CALL_EXPR, value_type,
  2537.          function, coerced_params, NULL_TREE);
  2538.  
  2539.     TREE_SIDE_EFFECTS (result) = 1;
  2540.  
  2541.     if (! require_complete)
  2542.       return convert_from_reference (result);
  2543.     if (value_type == void_type_node)
  2544.       return result;
  2545.     result = require_complete_type (result);
  2546.     return convert_from_reference (result);
  2547.   }
  2548. }
  2549.  
  2550. tree
  2551. build_function_call (function, params)
  2552.      tree function, params;
  2553. {
  2554.   return build_function_call_real (function, params, 1, LOOKUP_NORMAL);
  2555. }
  2556.      
  2557. tree
  2558. build_function_call_maybe (function, params)
  2559.      tree function, params;
  2560. {
  2561.   return build_function_call_real (function, params, 0, 0);
  2562. }
  2563.  
  2564.  
  2565. /* Convert the actual parameter expressions in the list VALUES
  2566.    to the types in the list TYPELIST.
  2567.    If parmdecls is exhausted, or when an element has NULL as its type,
  2568.    perform the default conversions.
  2569.  
  2570.    RETURN_LOC is the location of the return value, if known, NULL_TREE
  2571.    otherwise.  This is useful in the case where we can avoid creating
  2572.    a temporary variable in the case where we can initialize the return
  2573.    value directly.  If we are not eliding constructors, then we set this
  2574.    to NULL_TREE to avoid this avoidance.
  2575.  
  2576.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  2577.  
  2578.    This is also where warnings about wrong number of args are generated.
  2579.    
  2580.    Return a list of expressions for the parameters as converted.
  2581.  
  2582.    Both VALUES and the returned value are chains of TREE_LIST nodes
  2583.    with the elements of the list in the TREE_VALUE slots of those nodes.
  2584.  
  2585.    In C++, unspecified trailing parameters can be filled in with their
  2586.    default arguments, if such were specified.  Do so here.  */
  2587.  
  2588. tree
  2589. convert_arguments (return_loc, typelist, values, fndecl, flags)
  2590.      tree return_loc, typelist, values, fndecl;
  2591.      int flags;
  2592. {
  2593.   extern tree gc_protect_fndecl;
  2594.   register tree typetail, valtail;
  2595.   register tree result = NULL_TREE;
  2596.   char *called_thing;
  2597.   int i = 0;
  2598.  
  2599.   if (! flag_elide_constructors)
  2600.     return_loc = 0;
  2601.  
  2602.   if (fndecl)
  2603.     {
  2604.       if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
  2605.     {
  2606.       if (DECL_NAME (fndecl) == NULL_TREE
  2607.           || IDENTIFIER_HAS_TYPE_VALUE (DECL_NAME (fndecl)))
  2608.         called_thing = "constructor";
  2609.       else
  2610.         called_thing = "member function";
  2611.     }
  2612.       else
  2613.     called_thing = "function";
  2614.     }
  2615.  
  2616.   for (valtail = values, typetail = typelist;
  2617.        valtail;
  2618.        valtail = TREE_CHAIN (valtail), i++)
  2619.     {
  2620.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  2621.       register tree val = TREE_VALUE (valtail);
  2622.  
  2623.       if (val == error_mark_node)
  2624.     return error_mark_node;
  2625.  
  2626.       if (type == void_type_node)
  2627.     {
  2628.       if (fndecl)
  2629.         {
  2630.           char *buf = (char *)alloca (40 + strlen (called_thing));
  2631.           sprintf (buf, "too many arguments to %s `%%s'", called_thing);
  2632.           error_with_decl (fndecl, buf);
  2633.           error ("at this point in file");
  2634.         }
  2635.       else
  2636.         error ("too many arguments to function");
  2637.       /* In case anybody wants to know if this argument
  2638.          list is valid.  */
  2639.       if (result)
  2640.         TREE_TYPE (tree_last (result)) = error_mark_node;
  2641.       break;
  2642.     }
  2643.  
  2644.       /* The tree type of the parameter being passed may not yet be
  2645.      known.  In this case, its type is TYPE_UNKNOWN, and will
  2646.      be instantiated by the type given by TYPE.  If TYPE
  2647.      is also NULL, the tree type of VAL is ERROR_MARK_NODE.  */
  2648.       if (type && type_unknown_p (val))
  2649.     val = require_instantiated_type (type, val, integer_zero_node);
  2650.       else if (type_unknown_p (val))
  2651.     {
  2652.       /* Strip the `&' from an overloaded FUNCTION_DECL.  */
  2653.       if (TREE_CODE (val) == ADDR_EXPR)
  2654.         val = TREE_OPERAND (val, 0);
  2655.       if (TREE_CODE (val) == TREE_LIST
  2656.           && TREE_CHAIN (val) == NULL_TREE
  2657.           && TREE_TYPE (TREE_VALUE (val)) != NULL_TREE
  2658.           && (TREE_TYPE (val) == unknown_type_node
  2659.           || DECL_CHAIN (TREE_VALUE (val)) == NULL_TREE))
  2660.         /* Instantiates automatically.  */
  2661.         val = TREE_VALUE (val);
  2662.       else
  2663.         {
  2664.           error ("insufficient type information in parameter list");
  2665.           val = integer_zero_node;
  2666.         }
  2667.     }
  2668.       else if (TREE_CODE (val) == OFFSET_REF
  2669.         && TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
  2670.     {
  2671.       /* This is unclean.  Should be handled elsewhere. */
  2672.       val = build_unary_op (ADDR_EXPR, val, 0);
  2673.     }
  2674.       else if (TREE_CODE (val) == OFFSET_REF)
  2675.     val = resolve_offset_ref (val);
  2676.  
  2677.       {
  2678. #if 0
  2679.     /* This code forces the assumption that if we have a ptr-to-func
  2680.        type in an arglist, that every routine that wants to check
  2681.        its validity has done so, and thus we need not do any
  2682.        more conversion.  I don't remember why this is necessary.  */
  2683.     else if (TREE_CODE (ttype) == FUNCTION_TYPE
  2684.          && (type == NULL
  2685.              || TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
  2686.              || TREE_CODE (TREE_TYPE (type)) == VOID_TYPE))
  2687.       {
  2688.         type = build_pointer_type (ttype);
  2689.       }
  2690. #endif
  2691.       }
  2692.  
  2693.       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  2694.      Strip such NOP_EXPRs, since VAL is used in non-lvalue context.  */
  2695.       if (TREE_CODE (val) == NOP_EXPR
  2696.       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0))
  2697.       && (type == 0 || TREE_CODE (type) != REFERENCE_TYPE))
  2698.     val = TREE_OPERAND (val, 0);
  2699.  
  2700.       if (type == 0 || TREE_CODE (type) != REFERENCE_TYPE)
  2701.     {
  2702.       if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  2703.           || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE
  2704.           || TREE_CODE (TREE_TYPE (val)) == METHOD_TYPE)
  2705.         val = default_conversion (val);
  2706.  
  2707.       val = require_complete_type (val);
  2708.     }
  2709.  
  2710.       if (val == error_mark_node)
  2711.     return error_mark_node;
  2712.  
  2713.       if (type != 0)
  2714.     {
  2715.       /* Formal parm type is specified by a function prototype.  */
  2716.       tree parmval;
  2717.  
  2718.       if (TYPE_SIZE (type) == 0)
  2719.         {
  2720.           error ("parameter type of called function is incomplete");
  2721.           parmval = val;
  2722.         }
  2723.       else
  2724.         {
  2725. #if 0 && defined (PROMOTE_PROTOTYPES)
  2726.           /* This breaks user-defined conversions.  */
  2727.           /* Rather than truncating and then reextending,
  2728.          convert directly to int, if that's the type we will want.  */
  2729.           if (! flag_traditional
  2730.           && (TREE_CODE (type) == INTEGER_TYPE
  2731.               || TREE_CODE (type) == ENUMERAL_TYPE)
  2732.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2733.         type = integer_type_node;
  2734. #endif
  2735.           parmval = convert_for_initialization (return_loc, type, val, flags,
  2736.                             "argument passing", fndecl, i);
  2737. #ifdef PROMOTE_PROTOTYPES
  2738.           if ((TREE_CODE (type) == INTEGER_TYPE
  2739.            || TREE_CODE (type) == ENUMERAL_TYPE)
  2740.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2741.         parmval = default_conversion (parmval);
  2742. #endif
  2743.         }
  2744.  
  2745.       if (parmval == error_mark_node)
  2746.         return error_mark_node;
  2747.  
  2748.       result = tree_cons (NULL_TREE, parmval, result);
  2749.     }
  2750.       else
  2751.     {
  2752.       if (TREE_CODE (TREE_TYPE (val)) == REFERENCE_TYPE)
  2753.         val = convert_from_reference (val);
  2754.  
  2755.       if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  2756.           && (TYPE_PRECISION (TREE_TYPE (val))
  2757.           < TYPE_PRECISION (double_type_node)))
  2758.         /* Convert `float' to `double'.  */
  2759.         result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
  2760.       else if (TYPE_LANG_SPECIFIC (TREE_TYPE (val))
  2761.            && ! TYPE_HAS_TRIVIAL_INIT_REF (TREE_TYPE (val)))
  2762.         {
  2763.           cp_warning ("cannot pass objects of type `%T' through `...'",
  2764.               TREE_TYPE (val));
  2765.           result = tree_cons (NULL_TREE, val, result);
  2766.         }
  2767.       else
  2768.         /* Convert `short' and `char' to full-size `int'.  */
  2769.         result = tree_cons (NULL_TREE, default_conversion (val), result);
  2770.     }
  2771.  
  2772.       if (flag_gc
  2773.       /* There are certain functions for which we don't need
  2774.          to protect our arguments.  GC_PROTECT_FNDECL is one.  */
  2775.       && fndecl != gc_protect_fndecl
  2776.       && type_needs_gc_entry (TREE_TYPE (TREE_VALUE (result)))
  2777.       && ! value_safe_from_gc (NULL_TREE, TREE_VALUE (result)))
  2778.     /* This will build a temporary variable whose cleanup is
  2779.        to clear the obstack entry.  */
  2780.     TREE_VALUE (result) = protect_value_from_gc (NULL_TREE,
  2781.                              TREE_VALUE (result));
  2782.  
  2783.       if (typetail)
  2784.     typetail = TREE_CHAIN (typetail);
  2785.     }
  2786.  
  2787.   if (typetail != 0 && typetail != void_list_node)
  2788.     {
  2789.       /* See if there are default arguments that can be used */
  2790.       if (TREE_PURPOSE (typetail))
  2791.     {
  2792.       for (; typetail != void_list_node; ++i)
  2793.         {
  2794.           tree type = TREE_VALUE (typetail);
  2795.           tree val = break_out_target_exprs (TREE_PURPOSE (typetail));
  2796.           tree parmval;
  2797.  
  2798.           if (val == NULL_TREE)
  2799.         parmval = error_mark_node;
  2800.           else if (TREE_CODE (val) == CONSTRUCTOR)
  2801.         {
  2802.           parmval = digest_init (type, val, (tree *)0);
  2803.           parmval = convert_for_initialization (return_loc, type, parmval, flags,
  2804.                             "default constructor", fndecl, i);
  2805.         }
  2806.           else
  2807.         {
  2808.           /* This could get clobbered by the following call.  */
  2809.           if (TREE_HAS_CONSTRUCTOR (val))
  2810.             val = copy_node (val);
  2811.  
  2812.           parmval = convert_for_initialization (return_loc, type, val, flags,
  2813.                             "default argument", fndecl, i);
  2814. #ifdef PROMOTE_PROTOTYPES
  2815.           if ((TREE_CODE (type) == INTEGER_TYPE
  2816.                || TREE_CODE (type) == ENUMERAL_TYPE)
  2817.               && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  2818.             parmval = default_conversion (parmval);
  2819. #endif
  2820.         }
  2821.  
  2822.           if (parmval == error_mark_node)
  2823.         return error_mark_node;
  2824.  
  2825.           if (flag_gc
  2826.           && type_needs_gc_entry (TREE_TYPE (parmval))
  2827.           && ! value_safe_from_gc (NULL_TREE, parmval))
  2828.         parmval = protect_value_from_gc (NULL_TREE, parmval);
  2829.  
  2830.           result = tree_cons (0, parmval, result);
  2831.           typetail = TREE_CHAIN (typetail);
  2832.           /* ends with `...'.  */
  2833.           if (typetail == NULL_TREE)
  2834.         break;
  2835.         }
  2836.     }
  2837.       else
  2838.     {
  2839.       if (fndecl)
  2840.         {
  2841.           char *buf = (char *)alloca (32 + strlen (called_thing));
  2842.           sprintf (buf, "too few arguments to %s `%%#D'", called_thing);
  2843.           cp_error_at (buf, fndecl);
  2844.           error ("at this point in file");
  2845.         }
  2846.       else
  2847.         error ("too few arguments to function");
  2848.       return error_mark_list;
  2849.     }
  2850.     }
  2851.  
  2852.   return nreverse (result);
  2853. }
  2854.  
  2855. /* Build a binary-operation expression, after performing default
  2856.    conversions on the operands.  CODE is the kind of expression to build.  */
  2857.  
  2858. tree
  2859. build_x_binary_op (code, arg1, arg2)
  2860.      enum tree_code code;
  2861.      tree arg1, arg2;
  2862. {
  2863.   tree rval = build_opfncall (code, LOOKUP_SPECULATIVELY,
  2864.                   arg1, arg2, NULL_TREE);
  2865.   if (rval)
  2866.     return build_opfncall (code, LOOKUP_NORMAL, arg1, arg2, NULL_TREE);
  2867.   if (code == MEMBER_REF)
  2868.     return build_m_component_ref (build_indirect_ref (arg1, NULL_PTR),
  2869.                   arg2);
  2870.   return build_binary_op (code, arg1, arg2, 1);
  2871. }
  2872.  
  2873. tree
  2874. build_binary_op (code, arg1, arg2, convert_p)
  2875.      enum tree_code code;
  2876.      tree arg1, arg2;
  2877.      int convert_p;
  2878. {
  2879.   tree args[2];
  2880.  
  2881.   args[0] = arg1;
  2882.   args[1] = arg2;
  2883.  
  2884.   if (convert_p)
  2885.     {
  2886.       tree args_save [2];
  2887.       tree type0, type1;
  2888.       args[0] = decay_conversion (args[0]);
  2889.       args[1] = decay_conversion (args[1]);
  2890.  
  2891.       if (args[0] == error_mark_node || args[1] == error_mark_node)
  2892.     return error_mark_node;
  2893.  
  2894.       type0 = TREE_TYPE (args[0]);
  2895.       type1 = TREE_TYPE (args[1]);
  2896.  
  2897.       if (type_unknown_p (args[0]))
  2898.     {
  2899.       args[0] = instantiate_type (type1, args[0], 1);
  2900.       args[0] = decay_conversion (args[0]);
  2901.     }
  2902.       else if (type_unknown_p (args[1]))
  2903.     {
  2904.       args[1] = require_instantiated_type (type0, args[1],
  2905.                            error_mark_node);
  2906.       args[1] = decay_conversion (args[1]);
  2907.     }
  2908.  
  2909.       if (IS_AGGR_TYPE (type0) || IS_AGGR_TYPE (type1))
  2910.     {
  2911.       /* Try to convert this to something reasonable.  */
  2912.       if (! build_default_binary_type_conversion(code, &args[0], &args[1]))
  2913.         {
  2914.           cp_error ("no match for `%O(%#T, %#T)'", code,
  2915.             TREE_TYPE (arg1), TREE_TYPE (arg2));
  2916.           return error_mark_node;
  2917.         }
  2918.     }
  2919.     }
  2920.   return build_binary_op_nodefault (code, args[0], args[1], code);
  2921. }
  2922.  
  2923. /* Build a binary-operation expression without default conversions.
  2924.    CODE is the kind of expression to build.
  2925.    This function differs from `build' in several ways:
  2926.    the data type of the result is computed and recorded in it,
  2927.    warnings are generated if arg data types are invalid,
  2928.    special handling for addition and subtraction of pointers is known,
  2929.    and some optimization is done (operations on narrow ints
  2930.    are done in the narrower type when that gives the same result).
  2931.    Constant folding is also done before the result is returned.
  2932.  
  2933.    ERROR_CODE is the code that determines what to say in error messages.
  2934.    It is usually, but not always, the same as CODE.
  2935.  
  2936.    Note that the operands will never have enumeral types
  2937.    because either they have just had the default conversions performed
  2938.    or they have both just been converted to some other type in which
  2939.    the arithmetic is to be done.
  2940.  
  2941.    C++: must do special pointer arithmetic when implementing
  2942.    multiple inheritance, and deal with pointer to member functions.  */
  2943.  
  2944. tree
  2945. build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
  2946.      enum tree_code code;
  2947.      tree orig_op0, orig_op1;
  2948.      enum tree_code error_code;
  2949. {
  2950.   tree op0, op1;
  2951.   register enum tree_code code0, code1;
  2952.   tree type0, type1;
  2953.  
  2954.   /* Expression code to give to the expression when it is built.
  2955.      Normally this is CODE, which is what the caller asked for,
  2956.      but in some special cases we change it.  */
  2957.   register enum tree_code resultcode = code;
  2958.  
  2959.   /* Data type in which the computation is to be performed.
  2960.      In the simplest cases this is the common type of the arguments.  */
  2961.   register tree result_type = NULL;
  2962.  
  2963.   /* Nonzero means operands have already been type-converted
  2964.      in whatever way is necessary.
  2965.      Zero means they need to be converted to RESULT_TYPE.  */
  2966.   int converted = 0;
  2967.  
  2968.   /* Nonzero means create the expression with this type, rather than
  2969.      RESULT_TYPE.  */
  2970.   tree build_type = 0;
  2971.  
  2972.   /* Nonzero means after finally constructing the expression
  2973.      convert it to this type.  */
  2974.   tree final_type = 0;
  2975.  
  2976.   /* Nonzero if this is an operation like MIN or MAX which can
  2977.      safely be computed in short if both args are promoted shorts.
  2978.      Also implies COMMON.
  2979.      -1 indicates a bitwise operation; this makes a difference
  2980.      in the exact conditions for when it is safe to do the operation
  2981.      in a narrower mode.  */
  2982.   int shorten = 0;
  2983.  
  2984.   /* Nonzero if this is a comparison operation;
  2985.      if both args are promoted shorts, compare the original shorts.
  2986.      Also implies COMMON.  */
  2987.   int short_compare = 0;
  2988.  
  2989.   /* Nonzero if this is a right-shift operation, which can be computed on the
  2990.      original short and then promoted if the operand is a promoted short.  */
  2991.   int short_shift = 0;
  2992.  
  2993.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  2994.   int common = 0;
  2995.  
  2996.   /* Apply default conversions.  */
  2997.   if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
  2998.       || code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
  2999.       || code == TRUTH_XOR_EXPR)
  3000.     {
  3001.       op0 = decay_conversion (orig_op0);
  3002.       op1 = decay_conversion (orig_op1);
  3003.     }
  3004.   else
  3005.     {
  3006.       op0 = default_conversion (orig_op0);
  3007.       op1 = default_conversion (orig_op1);
  3008.     }
  3009.  
  3010.   type0 = TREE_TYPE (op0);
  3011.   type1 = TREE_TYPE (op1);
  3012.  
  3013.   /* The expression codes of the data types of the arguments tell us
  3014.      whether the arguments are integers, floating, pointers, etc.  */
  3015.   code0 = TREE_CODE (type0);
  3016.   code1 = TREE_CODE (type1);
  3017.  
  3018.   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
  3019.   STRIP_TYPE_NOPS (op0);
  3020.   STRIP_TYPE_NOPS (op1);
  3021.  
  3022.   /* If an error was already reported for one of the arguments,
  3023.      avoid reporting another error.  */
  3024.  
  3025.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  3026.     return error_mark_node;
  3027.  
  3028.   switch (code)
  3029.     {
  3030.     case PLUS_EXPR:
  3031.       /* Handle the pointer + int case.  */
  3032.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3033.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  3034.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  3035.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  3036.       else
  3037.     common = 1;
  3038.       break;
  3039.  
  3040.     case MINUS_EXPR:
  3041.       /* Subtraction of two similar pointers.
  3042.      We must subtract them as integers, then divide by object size.  */
  3043.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  3044.       && comp_target_types (type0, type1, 1))
  3045.     return pointer_diff (op0, op1);
  3046.       /* Handle pointer minus int.  Just like pointer plus int.  */
  3047.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3048.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  3049.       else
  3050.     common = 1;
  3051.       break;
  3052.  
  3053.     case MULT_EXPR:
  3054.       common = 1;
  3055.       break;
  3056.  
  3057.     case TRUNC_DIV_EXPR:
  3058.     case CEIL_DIV_EXPR:
  3059.     case FLOOR_DIV_EXPR:
  3060.     case ROUND_DIV_EXPR:
  3061.     case EXACT_DIV_EXPR:
  3062.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3063.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3064.     {
  3065.       if (TREE_CODE (op1) == INTEGER_CST && integer_zerop (op1))
  3066.         cp_warning ("division by zero in `%E / 0'", op0);
  3067.       else if (TREE_CODE (op1) == REAL_CST && real_zerop (op1))
  3068.         cp_warning ("division by zero in `%E / 0.'", op0);
  3069.           
  3070.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  3071.         resultcode = RDIV_EXPR;
  3072.       else
  3073.         /* When dividing two signed integers, we have to promote to int.
  3074.            unless we divide by a constant != -1.  Note that default
  3075.            conversion will have been performed on the operands at this
  3076.            point, so we have to dig out the original type to find out if
  3077.            it was unsigned.  */
  3078.         shorten = ((TREE_CODE (op0) == NOP_EXPR
  3079.             && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  3080.                || (TREE_CODE (op1) == INTEGER_CST
  3081.                && (TREE_INT_CST_LOW (op1) != -1
  3082.                    || TREE_INT_CST_HIGH (op1) != -1)));
  3083.       common = 1;
  3084.     }
  3085.       break;
  3086.  
  3087.     case BIT_AND_EXPR:
  3088.     case BIT_ANDTC_EXPR:
  3089.     case BIT_IOR_EXPR:
  3090.     case BIT_XOR_EXPR:
  3091.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  3092.     shorten = -1;
  3093.       /* If one operand is a constant, and the other is a short type
  3094.      that has been converted to an int,
  3095.      really do the work in the short type and then convert the
  3096.      result to int.  If we are lucky, the constant will be 0 or 1
  3097.      in the short type, making the entire operation go away.  */
  3098.       if (TREE_CODE (op0) == INTEGER_CST
  3099.       && TREE_CODE (op1) == NOP_EXPR
  3100.       && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  3101.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  3102.     {
  3103.       final_type = result_type;
  3104.       op1 = TREE_OPERAND (op1, 0);
  3105.       result_type = TREE_TYPE (op1);
  3106.     }
  3107.       if (TREE_CODE (op1) == INTEGER_CST
  3108.       && TREE_CODE (op0) == NOP_EXPR
  3109.       && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  3110.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  3111.     {
  3112.       final_type = result_type;
  3113.       op0 = TREE_OPERAND (op0, 0);
  3114.       result_type = TREE_TYPE (op0);
  3115.     }
  3116.       break;
  3117.  
  3118.     case TRUNC_MOD_EXPR:
  3119.     case FLOOR_MOD_EXPR:
  3120.       if (code1 == INTEGER_TYPE && integer_zerop (op1))
  3121.     cp_warning ("division by zero in `%E % 0'", op0);
  3122.       else if (code1 == REAL_TYPE && real_zerop (op1))
  3123.     cp_warning ("division by zero in `%E % 0.'", op0);
  3124.       
  3125.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  3126.     {
  3127.       /* Although it would be tempting to shorten always here, that loses
  3128.          on some targets, since the modulo instruction is undefined if the
  3129.          quotient can't be represented in the computation mode.  We shorten
  3130.          only if unsigned or if dividing by something we know != -1.  */
  3131.       shorten = ((TREE_CODE (op0) == NOP_EXPR
  3132.               && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  3133.              || (TREE_CODE (op1) == INTEGER_CST
  3134.              && (TREE_INT_CST_LOW (op1) != -1
  3135.                  || TREE_INT_CST_HIGH (op1) != -1)));
  3136.       common = 1;
  3137.     }
  3138.       break;
  3139.  
  3140.     case TRUTH_ANDIF_EXPR:
  3141.     case TRUTH_ORIF_EXPR:
  3142.     case TRUTH_AND_EXPR:
  3143.     case TRUTH_OR_EXPR:
  3144.       result_type = boolean_type_node;
  3145.       break;
  3146.  
  3147.       /* Shift operations: result has same type as first operand;
  3148.      always convert second operand to int.
  3149.      Also set SHORT_SHIFT if shifting rightward.  */
  3150.  
  3151.     case RSHIFT_EXPR:
  3152.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  3153.     {
  3154.       result_type = type0;
  3155.       if (TREE_CODE (op1) == INTEGER_CST)
  3156.         {
  3157.           if (tree_int_cst_lt (op1, integer_zero_node))
  3158.         warning ("right shift count is negative");
  3159.           else
  3160.         {
  3161.           if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
  3162.             short_shift = 1;
  3163.           if (TREE_INT_CST_HIGH (op1) != 0
  3164.               || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  3165.               >= TYPE_PRECISION (type0)))
  3166.             warning ("right shift count >= width of type");
  3167.         }
  3168.         }
  3169.       /* Convert the shift-count to an integer, regardless of
  3170.          size of value being shifted.  */
  3171.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  3172.         op1 = convert (integer_type_node, op1);
  3173.       /* Avoid converting op1 to result_type later.  */
  3174.       converted = 1;
  3175.     }
  3176.       break;
  3177.  
  3178.     case LSHIFT_EXPR:
  3179.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  3180.     {
  3181.       result_type = type0;
  3182.       if (TREE_CODE (op1) == INTEGER_CST)
  3183.         {
  3184.           if (tree_int_cst_lt (op1, integer_zero_node))
  3185.         warning ("left shift count is negative");
  3186.           else if (TREE_INT_CST_HIGH (op1) != 0
  3187.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  3188.                >= TYPE_PRECISION (type0)))
  3189.         warning ("left shift count >= width of type");
  3190.         }
  3191.       /* Convert the shift-count to an integer, regardless of
  3192.          size of value being shifted.  */
  3193.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  3194.         op1 = convert (integer_type_node, op1);
  3195.       /* Avoid converting op1 to result_type later.  */
  3196.       converted = 1;
  3197.     }
  3198.       break;
  3199.  
  3200.     case RROTATE_EXPR:
  3201.     case LROTATE_EXPR:
  3202.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  3203.     {
  3204.       result_type = type0;
  3205.       if (TREE_CODE (op1) == INTEGER_CST)
  3206.         {
  3207.           if (tree_int_cst_lt (op1, integer_zero_node))
  3208.         warning ("%s rotate count is negative",
  3209.              (code == LROTATE_EXPR) ? "left" : "right");
  3210.           else if (TREE_INT_CST_HIGH (op1) != 0
  3211.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  3212.                >= TYPE_PRECISION (type0)))
  3213.         warning ("%s rotate count >= width of type",
  3214.              (code == LROTATE_EXPR) ? "left" : "right");
  3215.         }
  3216.       /* Convert the shift-count to an integer, regardless of
  3217.          size of value being shifted.  */
  3218.       if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  3219.         op1 = convert (integer_type_node, op1);
  3220.     }
  3221.       break;
  3222.  
  3223.     case EQ_EXPR:
  3224.     case NE_EXPR:
  3225.       build_type = boolean_type_node; 
  3226.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3227.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3228.     short_compare = 1;
  3229.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  3230.     {
  3231.       register tree tt0 = TYPE_MAIN_VARIANT (TREE_TYPE (type0));
  3232.       register tree tt1 = TYPE_MAIN_VARIANT (TREE_TYPE (type1));
  3233.  
  3234.       if (comp_target_types (type0, type1, 1))
  3235.         result_type = common_type (type0, type1);
  3236.       else if (tt0 == void_type_node)
  3237.         {
  3238.           if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE
  3239.           && tree_int_cst_lt (TYPE_SIZE (type0), TYPE_SIZE (type1)))
  3240.         pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
  3241.           else if (TREE_CODE (tt1) == OFFSET_TYPE)
  3242.         pedwarn ("ANSI C++ forbids conversion of a pointer to member to `void *'");
  3243.         }
  3244.       else if (tt1 == void_type_node)
  3245.         {
  3246.           if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE
  3247.           && tree_int_cst_lt (TYPE_SIZE (type1), TYPE_SIZE (type0)))
  3248.         pedwarn ("ANSI C++ forbids comparison of `void *' with function pointer");
  3249.         }
  3250.       else
  3251. #ifdef OBJCPLUS
  3252.         {
  3253.           if (maybe_objc_comptypes (tt0, tt1, 1) != 1)
  3254.             cp_pedwarn ("comparison of distinct object pointer types");
  3255.         }
  3256. #else
  3257.         cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
  3258.             type0, type1);
  3259. #endif
  3260.  
  3261.       if (result_type == NULL_TREE)
  3262.         result_type = ptr_type_node;
  3263.     }
  3264.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  3265.            && integer_zerop (op1))
  3266.     result_type = type0;
  3267.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  3268.            && integer_zerop (op0))
  3269.     result_type = type1;
  3270.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3271.     {
  3272.       result_type = type0;
  3273.       error ("ANSI C++ forbids comparison between pointer and integer");
  3274.     }
  3275.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  3276.     {
  3277.       result_type = type1;
  3278.       error ("ANSI C++ forbids comparison between pointer and integer");
  3279.     }
  3280.       else if (TYPE_PTRMEMFUNC_P (type0) && TREE_CODE (op1) == INTEGER_CST
  3281.            && integer_zerop (op1))
  3282.     {
  3283.       op0 = build_component_ref (op0, index_identifier, 0, 0);
  3284.       op1 = integer_zero_node;
  3285.       result_type = TREE_TYPE (op0);
  3286.     }
  3287.       else if (TYPE_PTRMEMFUNC_P (type1) && TREE_CODE (op0) == INTEGER_CST
  3288.            && integer_zerop (op0))
  3289.     {
  3290.       op0 = build_component_ref (op1, index_identifier, 0, 0);
  3291.       op1 = integer_zero_node;
  3292.       result_type = TREE_TYPE (op0);
  3293.     }
  3294.       else if (TYPE_PTRMEMFUNC_P (type0) && TYPE_PTRMEMFUNC_P (type1)
  3295.            && (TYPE_PTRMEMFUNC_FN_TYPE (type0)
  3296.            == TYPE_PTRMEMFUNC_FN_TYPE (type1)))
  3297.     {
  3298.       /* The code we generate for the test is:
  3299.  
  3300.       (op0.index == op1.index
  3301.        && ((op1.index != -1 && op0.delta2 == op1.delta2)
  3302.            || op0.pfn == op1.pfn)) */
  3303.  
  3304.       tree index0 = build_component_ref (op0, index_identifier, 0, 0);
  3305.       tree index1 = save_expr (build_component_ref (op1, index_identifier, 0, 0));
  3306.       tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
  3307.       tree pfn1 = PFN_FROM_PTRMEMFUNC (op1);
  3308.       tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
  3309.       tree delta21 = DELTA2_FROM_PTRMEMFUNC (op1);
  3310.       tree e1, e2, e3;
  3311.       tree integer_neg_one_node
  3312.         = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1);
  3313.       e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
  3314.       e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
  3315.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
  3316.       e3 = build_binary_op (EQ_EXPR, pfn0, pfn1, 1);
  3317.       e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
  3318.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
  3319.       if (code == EQ_EXPR)
  3320.         return e2;
  3321.       return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
  3322.     }
  3323.       else if (TYPE_PTRMEMFUNC_P (type0)
  3324.            && TYPE_PTRMEMFUNC_FN_TYPE (type0) == type1)
  3325.     {
  3326.       tree index0 = build_component_ref (op0, index_identifier, 0, 0);
  3327.       tree index1;
  3328.       tree pfn0 = PFN_FROM_PTRMEMFUNC (op0);
  3329.       tree delta20 = DELTA2_FROM_PTRMEMFUNC (op0);
  3330.       tree delta21 = integer_zero_node;
  3331.       tree e1, e2, e3;
  3332.       tree integer_neg_one_node
  3333.         = build_binary_op (MINUS_EXPR, integer_zero_node, integer_one_node, 1);
  3334.       if (TREE_CODE (TREE_OPERAND (op1, 0)) == FUNCTION_DECL
  3335.           && DECL_VINDEX (TREE_OPERAND (op1, 0)))
  3336.         {
  3337.           /* Map everything down one to make room for the null pointer to member.  */
  3338.           index1 = size_binop (PLUS_EXPR,
  3339.                    DECL_VINDEX (TREE_OPERAND (op1, 0)),
  3340.                    integer_one_node);
  3341.           op1 = integer_zero_node;
  3342.           delta21 = CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE (TREE_TYPE (type1)));
  3343.           delta21 = DECL_FIELD_BITPOS (delta21);
  3344.           delta21 = size_binop (FLOOR_DIV_EXPR, delta21, size_int (BITS_PER_UNIT));
  3345.         }
  3346.       else
  3347.         index1 = integer_neg_one_node;
  3348.       {
  3349.         tree nop1 = build1 (NOP_EXPR, TYPE_PTRMEMFUNC_FN_TYPE (type0), op1);
  3350.         TREE_CONSTANT (nop1) = TREE_CONSTANT (op1);
  3351.         op1 = nop1;
  3352.       }
  3353.       e1 = build_binary_op (EQ_EXPR, index0, index1, 1);
  3354.       e2 = build_binary_op (NE_EXPR, index1, integer_neg_one_node, 1);
  3355.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e2, build_binary_op (EQ_EXPR, delta20, delta21, 1), 1);
  3356.       e3 = build_binary_op (EQ_EXPR, pfn0, op1, 1);
  3357.       e2 = build_binary_op (TRUTH_ORIF_EXPR, e2, e3, 1);
  3358.       e2 = build_binary_op (TRUTH_ANDIF_EXPR, e1, e2, 1);
  3359.       if (code == EQ_EXPR)
  3360.         return e2;
  3361.       return build_binary_op (EQ_EXPR, e2, integer_zero_node, 1);
  3362.     }
  3363.       else if (TYPE_PTRMEMFUNC_P (type1)
  3364.            && TYPE_PTRMEMFUNC_FN_TYPE (type1) == type0)
  3365.     {
  3366.       return build_binary_op (code, op1, op0, 1);
  3367.     }
  3368.       break;
  3369.  
  3370.     case MAX_EXPR:
  3371.     case MIN_EXPR:
  3372.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3373.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3374.     shorten = 1;
  3375.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  3376.     {
  3377.       if (comp_target_types (type0, type1, 1))
  3378.         result_type = common_type (type0, type1);
  3379.       else
  3380.         {
  3381.           cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
  3382.               type0, type1);
  3383.           result_type = ptr_type_node;
  3384.         }
  3385.     }
  3386.       break;
  3387.  
  3388.     case LE_EXPR:
  3389.     case GE_EXPR:
  3390.     case LT_EXPR:
  3391.     case GT_EXPR:
  3392.       build_type = boolean_type_node;
  3393.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3394.        && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3395.     short_compare = 1;
  3396.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  3397.     {
  3398.       if (comp_target_types (type0, type1, 1))
  3399.         result_type = common_type (type0, type1);
  3400.       else
  3401.         {
  3402.           cp_pedwarn ("comparison of distinct pointer types `%T' and `%T' lacks a cast",
  3403.               type0, type1);
  3404.           result_type = ptr_type_node;
  3405.         }
  3406.     }
  3407.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  3408.            && integer_zerop (op1))
  3409.     result_type = type0;
  3410.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  3411.            && integer_zerop (op0))
  3412.     result_type = type1;
  3413.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3414.     {
  3415.       result_type = type0;
  3416.       if (pedantic)
  3417.         pedwarn ("ANSI C++ forbids comparison between pointer and integer");
  3418.       else if (! flag_traditional)
  3419.         warning ("comparison between pointer and integer");
  3420.     }
  3421.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  3422.     {
  3423.       result_type = type1;
  3424.       if (pedantic)
  3425.         pedwarn ("ANSI C++ forbids comparison between pointer and integer");
  3426.       else if (! flag_traditional)
  3427.         warning ("comparison between pointer and integer");
  3428.     }
  3429.       break;
  3430.     }
  3431.  
  3432.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  3433.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  3434.     {
  3435.       if (shorten || common || short_compare)
  3436.     result_type = common_type (type0, type1);
  3437.  
  3438.       /* For certain operations (which identify themselves by shorten != 0)
  3439.      if both args were extended from the same smaller type,
  3440.      do the arithmetic in that type and then extend.
  3441.  
  3442.      shorten !=0 and !=1 indicates a bitwise operation.
  3443.      For them, this optimization is safe only if
  3444.      both args are zero-extended or both are sign-extended.
  3445.      Otherwise, we might change the result.
  3446.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  3447.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  3448.  
  3449.       if (shorten)
  3450.     {
  3451.       int unsigned0, unsigned1;
  3452.       tree arg0 = get_narrower (op0, &unsigned0);
  3453.       tree arg1 = get_narrower (op1, &unsigned1);
  3454.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  3455.       int uns = TREE_UNSIGNED (result_type);
  3456.       tree type;
  3457.  
  3458.       final_type = result_type;
  3459.  
  3460.       /* Handle the case that OP0 does not *contain* a conversion
  3461.          but it *requires* conversion to FINAL_TYPE.  */
  3462.  
  3463.       if (op0 == arg0 && TREE_TYPE (op0) != final_type)
  3464.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  3465.       if (op1 == arg1 && TREE_TYPE (op1) != final_type)
  3466.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  3467.  
  3468.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  3469.  
  3470.       /* For bitwise operations, signedness of nominal type
  3471.          does not matter.  Consider only how operands were extended.  */
  3472.       if (shorten == -1)
  3473.         uns = unsigned0;
  3474.  
  3475.       /* Note that in all three cases below we refrain from optimizing
  3476.          an unsigned operation on sign-extended args.
  3477.          That would not be valid.  */
  3478.  
  3479.       /* Both args variable: if both extended in same way
  3480.          from same width, do it in that width.
  3481.          Do it unsigned if args were zero-extended.  */
  3482.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  3483.            < TYPE_PRECISION (result_type))
  3484.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  3485.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  3486.           && unsigned0 == unsigned1
  3487.           && (unsigned0 || !uns))
  3488.         result_type
  3489.           = signed_or_unsigned_type (unsigned0,
  3490.                      common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  3491.       else if (TREE_CODE (arg0) == INTEGER_CST
  3492.            && (unsigned1 || !uns)
  3493.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  3494.                < TYPE_PRECISION (result_type))
  3495.            && (type = signed_or_unsigned_type (unsigned1,
  3496.                                TREE_TYPE (arg1)),
  3497.                int_fits_type_p (arg0, type)))
  3498.         result_type = type;
  3499.       else if (TREE_CODE (arg1) == INTEGER_CST
  3500.            && (unsigned0 || !uns)
  3501.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  3502.                < TYPE_PRECISION (result_type))
  3503.            && (type = signed_or_unsigned_type (unsigned0,
  3504.                                TREE_TYPE (arg0)),
  3505.                int_fits_type_p (arg1, type)))
  3506.         result_type = type;
  3507.     }
  3508.  
  3509.       /* Shifts can be shortened if shifting right.  */
  3510.  
  3511.       if (short_shift)
  3512.     {
  3513.       int unsigned_arg;
  3514.       tree arg0 = get_narrower (op0, &unsigned_arg);
  3515.  
  3516.       final_type = result_type;
  3517.  
  3518.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  3519.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  3520.  
  3521.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  3522.           /* We can shorten only if the shift count is less than the
  3523.          number of bits in the smaller type size.  */
  3524.           && TREE_INT_CST_HIGH (op1) == 0
  3525.           && TYPE_PRECISION (TREE_TYPE (arg0)) > TREE_INT_CST_LOW (op1)
  3526.           /* If arg is sign-extended and then unsigned-shifted,
  3527.          we can simulate this with a signed shift in arg's type
  3528.          only if the extended result is at least twice as wide
  3529.          as the arg.  Otherwise, the shift could use up all the
  3530.          ones made by sign-extension and bring in zeros.
  3531.          We can't optimize that case at all, but in most machines
  3532.          it never happens because available widths are 2**N.  */
  3533.           && (!TREE_UNSIGNED (final_type)
  3534.           || unsigned_arg
  3535.           || ((unsigned) 2 * TYPE_PRECISION (TREE_TYPE (arg0))
  3536.               <= TYPE_PRECISION (result_type))))
  3537.         {
  3538.           /* Do an unsigned shift if the operand was zero-extended.  */
  3539.           result_type
  3540.         = signed_or_unsigned_type (unsigned_arg,
  3541.                        TREE_TYPE (arg0));
  3542.           /* Convert value-to-be-shifted to that type.  */
  3543.           if (TREE_TYPE (op0) != result_type)
  3544.         op0 = convert (result_type, op0);
  3545.           converted = 1;
  3546.         }
  3547.     }
  3548.  
  3549.       /* Comparison operations are shortened too but differently.
  3550.      They identify themselves by setting short_compare = 1.  */
  3551.  
  3552.       if (short_compare)
  3553.     {
  3554.       /* Don't write &op0, etc., because that would prevent op0
  3555.          from being kept in a register.
  3556.          Instead, make copies of the our local variables and
  3557.          pass the copies by reference, then copy them back afterward.  */
  3558.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  3559.       enum tree_code xresultcode = resultcode;
  3560.       tree val 
  3561.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  3562.       if (val != 0)
  3563.         return convert (boolean_type_node, val);
  3564.       op0 = xop0, op1 = xop1;
  3565.       converted = 1;
  3566.       resultcode = xresultcode;
  3567.     }
  3568.  
  3569.       if (short_compare && extra_warnings)
  3570.     {
  3571.       int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
  3572.       int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
  3573.  
  3574.       int unsignedp0, unsignedp1;
  3575.       tree primop0 = get_narrower (op0, &unsignedp0);
  3576.       tree primop1 = get_narrower (op1, &unsignedp1);
  3577.  
  3578.       /* Give warnings for comparisons between signed and unsigned
  3579.          quantities that may fail.  */
  3580.       /* Do the checking based on the original operand trees, so that
  3581.          casts will be considered, but default promotions won't be.  */
  3582.  
  3583.       /* Do not warn if the comparison is being done in a signed type,
  3584.          since the signed type will only be chosen if it can represent
  3585.          all the values of the unsigned type.  */
  3586.       if (! TREE_UNSIGNED (result_type))
  3587.         /* OK */;
  3588.       /* Do not warn if both operands are unsigned.  */
  3589.       else if (op0_signed == op1_signed)
  3590.         /* OK */;
  3591.       /* Do not warn if the signed quantity is an unsuffixed
  3592.          integer literal (or some static constant expression
  3593.          involving such literals) and it is non-negative.  */
  3594.       else if ((op0_signed && TREE_CODE (orig_op0) == INTEGER_CST
  3595.             && tree_int_cst_sgn (orig_op0) >= 0)
  3596.            || (op1_signed && TREE_CODE (orig_op1) == INTEGER_CST
  3597.                && tree_int_cst_sgn (orig_op1) >= 0))
  3598.         /* OK */;
  3599.       /* Do not warn if the comparison is an equality operation,
  3600.          the unsigned quantity is an integral constant and it does
  3601.          not use the most significant bit of result_type.  */
  3602.       else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR)
  3603.            && ((op0_signed && TREE_CODE (orig_op1) == INTEGER_CST
  3604.             && int_fits_type_p (orig_op1, signed_type (result_type))
  3605.             || (op1_signed && TREE_CODE (orig_op0) == INTEGER_CST
  3606.                 && int_fits_type_p (orig_op0, signed_type (result_type))))))
  3607.         /* OK */;
  3608.       else
  3609.         warning ("comparison between signed and unsigned");
  3610.  
  3611.       /* Warn if two unsigned values are being compared in a size
  3612.          larger than their original size, and one (and only one) is the
  3613.          result of a `~' operator.  This comparison will always fail.
  3614.  
  3615.          Also warn if one operand is a constant, and the constant does not
  3616.          have all bits set that are set in the ~ operand when it is
  3617.          extended.  */
  3618.  
  3619.       if (TREE_CODE (primop0) == BIT_NOT_EXPR
  3620.           ^ TREE_CODE (primop1) == BIT_NOT_EXPR)
  3621.         {
  3622.           if (TREE_CODE (primop0) == BIT_NOT_EXPR)
  3623.         primop0 = get_narrower (TREE_OPERAND (op0, 0), &unsignedp0);
  3624.           if (TREE_CODE (primop1) == BIT_NOT_EXPR)
  3625.         primop1 = get_narrower (TREE_OPERAND (op1, 0), &unsignedp1);
  3626.           
  3627.           if (TREE_CODE (primop0) == INTEGER_CST
  3628.           || TREE_CODE (primop1) == INTEGER_CST)
  3629.         {
  3630.           tree primop;
  3631.           HOST_WIDE_INT constant, mask;
  3632.           int unsignedp;
  3633.           unsigned bits;
  3634.  
  3635.           if (TREE_CODE (primop0) == INTEGER_CST)
  3636.             {
  3637.               primop = primop1;
  3638.               unsignedp = unsignedp1;
  3639.               constant = TREE_INT_CST_LOW (primop0);
  3640.             }
  3641.           else
  3642.             {
  3643.               primop = primop0;
  3644.               unsignedp = unsignedp0;
  3645.               constant = TREE_INT_CST_LOW (primop1);
  3646.             }
  3647.  
  3648.           bits = TYPE_PRECISION (TREE_TYPE (primop));
  3649.           if (bits < TYPE_PRECISION (result_type)
  3650.               && bits < HOST_BITS_PER_LONG && unsignedp)
  3651.             {
  3652.               mask = (~ (HOST_WIDE_INT) 0) << bits;
  3653.               if ((mask & constant) != mask)
  3654.             warning ("comparison of promoted ~unsigned with constant");
  3655.             }
  3656.         }
  3657.           else if (unsignedp0 && unsignedp1
  3658.                && (TYPE_PRECISION (TREE_TYPE (primop0))
  3659.                < TYPE_PRECISION (result_type))
  3660.                && (TYPE_PRECISION (TREE_TYPE (primop1))
  3661.                < TYPE_PRECISION (result_type)))
  3662.         warning ("comparison of promoted ~unsigned with unsigned");
  3663.         }
  3664.     }
  3665.     }
  3666.  
  3667.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  3668.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  3669.      Then the expression will be built.
  3670.      It will be given type FINAL_TYPE if that is nonzero;
  3671.      otherwise, it will be given type RESULT_TYPE.  */
  3672.  
  3673.   if (!result_type)
  3674.     {
  3675.       cp_error ("invalid operands `%T' and `%T' to binary `%O'",
  3676.         TREE_TYPE (orig_op0), TREE_TYPE (orig_op1), error_code);
  3677.       return error_mark_node;
  3678.     }
  3679.  
  3680.   if (! converted)
  3681.     {
  3682.       if (TREE_TYPE (op0) != result_type)
  3683.     op0 = convert (result_type, op0); 
  3684.       if (TREE_TYPE (op1) != result_type)
  3685.     op1 = convert (result_type, op1); 
  3686.     }
  3687.  
  3688.   if (build_type == NULL_TREE)
  3689.     build_type = result_type;
  3690.  
  3691.   {
  3692.     register tree result = build (resultcode, build_type, op0, op1);
  3693.     register tree folded;
  3694.  
  3695.     folded = fold (result);
  3696.     if (folded == result)
  3697.       TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  3698.     if (final_type != 0)
  3699.       return convert (final_type, folded);
  3700.     return folded;
  3701.   }
  3702. }
  3703.  
  3704. /* Return a tree for the sum or difference (RESULTCODE says which)
  3705.    of pointer PTROP and integer INTOP.  */
  3706.  
  3707. static tree
  3708. pointer_int_sum (resultcode, ptrop, intop)
  3709.      enum tree_code resultcode;
  3710.      register tree ptrop, intop;
  3711. {
  3712.   tree size_exp;
  3713.  
  3714.   register tree result;
  3715.   register tree folded = fold (intop);
  3716.  
  3717.   /* The result is a pointer of the same type that is being added.  */
  3718.  
  3719.   register tree result_type = TREE_TYPE (ptrop);
  3720.  
  3721.   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
  3722.     {
  3723.       if (pedantic || warn_pointer_arith)
  3724.     pedwarn ("ANSI C++ forbids using pointer of type `void *' in arithmetic");
  3725.       size_exp = integer_one_node;
  3726.     }
  3727.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  3728.     {
  3729.       if (pedantic || warn_pointer_arith)
  3730.     pedwarn ("ANSI C++ forbids using pointer to a function in arithmetic");
  3731.       size_exp = integer_one_node;
  3732.     }
  3733.   else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
  3734.     {
  3735.       if (pedantic || warn_pointer_arith)
  3736.     pedwarn ("ANSI C++ forbids using pointer to a method in arithmetic");
  3737.       size_exp = integer_one_node;
  3738.     }
  3739.   else if (TREE_CODE (TREE_TYPE (result_type)) == OFFSET_TYPE)
  3740.     {
  3741.       if (pedantic)
  3742.     pedwarn ("ANSI C++ forbids using pointer to a member in arithmetic");
  3743.       size_exp = integer_one_node;
  3744.     }
  3745.   else
  3746.     size_exp = size_in_bytes (TREE_TYPE (result_type));
  3747.  
  3748.   /* Needed to make OOPS V2R3 work.  */
  3749.   intop = folded;
  3750.   if (TREE_CODE (intop) == INTEGER_CST
  3751.       && TREE_INT_CST_LOW (intop) == 0
  3752.       && TREE_INT_CST_HIGH (intop) == 0)
  3753.     return ptrop;
  3754.  
  3755.   /* If what we are about to multiply by the size of the elements
  3756.      contains a constant term, apply distributive law
  3757.      and multiply that constant term separately.
  3758.      This helps produce common subexpressions.  */
  3759.  
  3760.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  3761.       && ! TREE_CONSTANT (intop)
  3762.       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
  3763.       && TREE_CONSTANT (size_exp))
  3764.     {
  3765.       enum tree_code subcode = resultcode;
  3766.       if (TREE_CODE (intop) == MINUS_EXPR)
  3767.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  3768.       ptrop = build_binary_op (subcode, ptrop, TREE_OPERAND (intop, 1), 1);
  3769.       intop = TREE_OPERAND (intop, 0);
  3770.     }
  3771.  
  3772.   /* Convert the integer argument to a type the same size as a pointer
  3773.      so the multiply won't overflow spuriously.  */
  3774.  
  3775.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  3776.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  3777.  
  3778.   /* Replace the integer argument with a suitable product by the object size.
  3779.      Do this multiplication as signed, then convert to the appropriate
  3780.      pointer type (actually unsigned integral).  */
  3781.  
  3782.   intop = convert (result_type,
  3783.            build_binary_op (MULT_EXPR, intop,
  3784.                     convert (TREE_TYPE (intop), size_exp), 1));
  3785.  
  3786.   /* Create the sum or difference.  */
  3787.  
  3788.   result = build (resultcode, result_type, ptrop, intop);
  3789.  
  3790.   folded = fold (result);
  3791.   if (folded == result)
  3792.     TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
  3793.   return folded;
  3794. }
  3795.  
  3796. /* Return a tree for the difference of pointers OP0 and OP1.
  3797.    The resulting tree has type int.  */
  3798.  
  3799. static tree
  3800. pointer_diff (op0, op1)
  3801.      register tree op0, op1;
  3802. {
  3803.   register tree result, folded;
  3804.   tree restype = ptrdiff_type_node;
  3805.   tree target_type = TREE_TYPE (TREE_TYPE (op0));
  3806.  
  3807.   if (pedantic)
  3808.     {
  3809.       if (TREE_CODE (target_type) == VOID_TYPE)
  3810.     pedwarn ("ANSI C++ forbids using pointer of type `void *' in subtraction");
  3811.       if (TREE_CODE (target_type) == FUNCTION_TYPE)
  3812.     pedwarn ("ANSI C++ forbids using pointer to a function in subtraction");
  3813.       if (TREE_CODE (target_type) == METHOD_TYPE)
  3814.     pedwarn ("ANSI C++ forbids using pointer to a method in subtraction");
  3815.       if (TREE_CODE (target_type) == OFFSET_TYPE)
  3816.     pedwarn ("ANSI C++ forbids using pointer to a member in subtraction");
  3817.     }
  3818.  
  3819.   /* First do the subtraction as integers;
  3820.      then drop through to build the divide operator.  */
  3821.  
  3822.   op0 = build_binary_op (MINUS_EXPR,
  3823.              convert (restype, op0), convert (restype, op1), 1);
  3824.  
  3825.   /* This generates an error if op1 is a pointer to an incomplete type.  */
  3826.   if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
  3827.     error ("arithmetic on pointer to an incomplete type");
  3828.  
  3829.   op1 = ((TREE_CODE (target_type) == VOID_TYPE
  3830.       || TREE_CODE (target_type) == FUNCTION_TYPE
  3831.       || TREE_CODE (target_type) == METHOD_TYPE
  3832.       || TREE_CODE (target_type) == OFFSET_TYPE)
  3833.      ? integer_one_node
  3834.      : size_in_bytes (target_type));
  3835.  
  3836.   /* Do the division.  */
  3837.  
  3838.   result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
  3839.  
  3840.   folded = fold (result);
  3841.   if (folded == result)
  3842.     TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  3843.   return folded;
  3844. }
  3845.  
  3846. /* Handle the case of taking the address of a COMPONENT_REF.
  3847.    Called by `build_unary_op' and `build_up_reference'.
  3848.  
  3849.    ARG is the COMPONENT_REF whose address we want.
  3850.    ARGTYPE is the pointer type that this address should have.
  3851.    MSG is an error message to print if this COMPONENT_REF is not
  3852.    addressable (such as a bitfield).  */
  3853.  
  3854. tree
  3855. build_component_addr (arg, argtype, msg)
  3856.      tree arg, argtype;
  3857.      char *msg;
  3858. {
  3859.   tree field = TREE_OPERAND (arg, 1);
  3860.   tree basetype = decl_type_context (field);
  3861.   tree rval = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  3862.  
  3863.   if (DECL_BIT_FIELD (field))
  3864.     {
  3865.       error (msg, IDENTIFIER_POINTER (DECL_NAME (field)));
  3866.       return error_mark_node;
  3867.     }
  3868.  
  3869.   if (flag_gc)
  3870.     cp_warning ("address of `%T::%D' taken", basetype, field);
  3871.  
  3872.   if (TREE_CODE (field) == FIELD_DECL
  3873.       && TYPE_USES_COMPLEX_INHERITANCE (basetype))
  3874.     {
  3875.       /* Can't convert directly to ARGTYPE, since that
  3876.      may have the same pointer type as one of our
  3877.      baseclasses.  */
  3878.       rval = build1 (NOP_EXPR, argtype,
  3879.              convert_pointer_to (basetype, rval));
  3880.       TREE_CONSTANT (rval) = TREE_CONSTANT (TREE_OPERAND (rval, 0));
  3881.     }
  3882.   else
  3883.     /* This conversion is harmless.  */
  3884.     rval = convert_force (argtype, rval, 0);
  3885.  
  3886.   if (! integer_zerop (DECL_FIELD_BITPOS (field)))
  3887.     {
  3888.       tree offset = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
  3889.                 size_int (BITS_PER_UNIT));
  3890.       int flag = TREE_CONSTANT (rval);
  3891.       rval = fold (build (PLUS_EXPR, argtype,
  3892.               rval, convert (argtype, offset)));
  3893.       TREE_CONSTANT (rval) = flag;
  3894.     }
  3895.   return rval;
  3896. }
  3897.    
  3898. /* Construct and perhaps optimize a tree representation
  3899.    for a unary operation.  CODE, a tree_code, specifies the operation
  3900.    and XARG is the operand.  */
  3901.  
  3902. tree
  3903. build_x_unary_op (code, xarg)
  3904.      enum tree_code code;
  3905.      tree xarg;
  3906. {
  3907.   /* & rec, on incomplete RECORD_TYPEs is the simple opr &, not an
  3908.      error message. */
  3909.   if (code == ADDR_EXPR
  3910.       && ((IS_AGGR_TYPE_CODE (TREE_CODE (TREE_TYPE (xarg)))
  3911.        && TYPE_SIZE (TREE_TYPE (xarg)) == NULL_TREE)
  3912.       || (TREE_CODE (xarg) == OFFSET_REF)))
  3913.     /* don't look for a function */;
  3914.   else
  3915.     {
  3916.       tree rval = build_opfncall (code, LOOKUP_SPECULATIVELY, xarg,
  3917.                   NULL_TREE, NULL_TREE);
  3918.       if (rval)
  3919.     return build_opfncall (code, LOOKUP_NORMAL, xarg,
  3920.                    NULL_TREE, NULL_TREE);
  3921.     }
  3922.   return build_unary_op (code, xarg, 0);
  3923. }
  3924.  
  3925. /* Just like truthvalue_conversion, but we want a CLEANUP_POINT_EXPR.  */
  3926.    
  3927. tree
  3928. condition_conversion (expr)
  3929.      tree expr;
  3930. {
  3931.   tree t = convert (boolean_type_node, expr);
  3932.   t = fold (build1 (CLEANUP_POINT_EXPR, boolean_type_node, t));
  3933.   return t;
  3934. }
  3935.                    
  3936. /* C++: Must handle pointers to members.
  3937.  
  3938.    Perhaps type instantiation should be extended to handle conversion
  3939.    from aggregates to types we don't yet know we want?  (Or are those
  3940.    cases typically errors which should be reported?)
  3941.  
  3942.    NOCONVERT nonzero suppresses the default promotions
  3943.    (such as from short to int).  */
  3944. tree
  3945. build_unary_op (code, xarg, noconvert)
  3946.      enum tree_code code;
  3947.      tree xarg;
  3948.      int noconvert;
  3949. {
  3950.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  3951.   register tree arg = xarg;
  3952.   register tree argtype = 0;
  3953.   char *errstring = NULL;
  3954.   tree val;
  3955.  
  3956.   if (arg == error_mark_node)
  3957.     return error_mark_node;
  3958.  
  3959.   switch (code)
  3960.     {
  3961.     case CONVERT_EXPR:
  3962.       /* This is used for unary plus, because a CONVERT_EXPR
  3963.      is enough to prevent anybody from looking inside for
  3964.      associativity, but won't generate any code.  */
  3965.       if (!(arg = build_expr_type_conversion
  3966.         (WANT_ARITH | WANT_ENUM | WANT_POINTER, arg, 1)))
  3967.     errstring = "wrong type argument to unary plus";
  3968.       else
  3969.     {
  3970.       if (!noconvert)
  3971.        arg = default_conversion (arg);
  3972.       arg = build1 (NON_LVALUE_EXPR, TREE_TYPE (arg), arg);
  3973.     }
  3974.       break;
  3975.  
  3976.     case NEGATE_EXPR:
  3977.       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, 1)))
  3978.     errstring = "wrong type argument to unary minus";
  3979.       else if (!noconvert)
  3980.     arg = default_conversion (arg);
  3981.       break;
  3982.  
  3983.     case BIT_NOT_EXPR:
  3984.       if (!(arg = build_expr_type_conversion (WANT_INT | WANT_ENUM, arg, 1)))
  3985.     errstring = "wrong type argument to bit-complement";
  3986.       else if (!noconvert)
  3987.     arg = default_conversion (arg);
  3988.       break;
  3989.  
  3990.     case ABS_EXPR:
  3991.       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_ENUM, arg, 1)))
  3992.     errstring = "wrong type argument to abs";
  3993.       else if (!noconvert)
  3994.     arg = default_conversion (arg);
  3995.       break;
  3996.  
  3997.     case TRUTH_NOT_EXPR:
  3998.       arg = convert (boolean_type_node, arg);
  3999.       val = invert_truthvalue (arg);
  4000.       if (arg != error_mark_node)
  4001.     return val;
  4002.       errstring = "in argument to unary !";
  4003.       break;
  4004.  
  4005.     case NOP_EXPR:
  4006.       break;
  4007.       
  4008.     case PREINCREMENT_EXPR:
  4009.     case POSTINCREMENT_EXPR:
  4010.     case PREDECREMENT_EXPR:
  4011.     case POSTDECREMENT_EXPR:
  4012.       /* Handle complex lvalues (when permitted)
  4013.      by reduction to simpler cases.  */
  4014.  
  4015.       val = unary_complex_lvalue (code, arg);
  4016.       if (val != 0)
  4017.     return val;
  4018.  
  4019.       /* Report invalid types.  */
  4020.  
  4021.       if (!(arg = build_expr_type_conversion (WANT_ARITH | WANT_POINTER,
  4022.                           arg, 1)))
  4023.     {
  4024.       if (code == PREINCREMENT_EXPR)
  4025.         errstring ="no pre-increment operator for type";
  4026.       else if (code == POSTINCREMENT_EXPR)
  4027.         errstring ="no post-increment operator for type";
  4028.       else if (code == PREDECREMENT_EXPR)
  4029.         errstring ="no pre-decrement operator for type";
  4030.       else
  4031.         errstring ="no post-decrement operator for type";
  4032.       break;
  4033.     }
  4034.  
  4035.       /* Report something read-only.  */
  4036.  
  4037.       if (TYPE_READONLY (TREE_TYPE (arg))
  4038.       || TREE_READONLY (arg))
  4039.     readonly_error (arg, ((code == PREINCREMENT_EXPR
  4040.                    || code == POSTINCREMENT_EXPR)
  4041.                   ? "increment" : "decrement"),
  4042.             0);
  4043.  
  4044.       {
  4045.     register tree inc;
  4046.     tree result_type = TREE_TYPE (arg);
  4047.  
  4048.     arg = get_unwidened (arg, 0);
  4049.     argtype = TREE_TYPE (arg);
  4050.  
  4051.     /* ARM $5.2.5 last annotation says this should be forbidden.  */
  4052.     if (TREE_CODE (argtype) == ENUMERAL_TYPE)
  4053.       pedwarn ("ANSI C++ forbids %sing an enum",
  4054.            (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  4055.            ? "increment" : "decrement");
  4056.         
  4057.     /* Compute the increment.  */
  4058.  
  4059.     if (TREE_CODE (argtype) == POINTER_TYPE)
  4060.       {
  4061.         enum tree_code tmp = TREE_CODE (TREE_TYPE (argtype));
  4062.         if (TYPE_SIZE (TREE_TYPE (argtype)) == 0)
  4063.           cp_error ("cannot %s a pointer to incomplete type `%T'",
  4064.             ((code == PREINCREMENT_EXPR
  4065.               || code == POSTINCREMENT_EXPR)
  4066.              ? "increment" : "decrement"), TREE_TYPE (argtype));
  4067.         else if (tmp == FUNCTION_TYPE || tmp == METHOD_TYPE
  4068.              || tmp == VOID_TYPE || tmp == OFFSET_TYPE)
  4069.           cp_pedwarn ("ANSI C++ forbids %sing a pointer of type `%T'",
  4070.               ((code == PREINCREMENT_EXPR
  4071.                 || code == POSTINCREMENT_EXPR)
  4072.                ? "increment" : "decrement"), argtype);
  4073.         inc = c_sizeof_nowarn (TREE_TYPE (argtype));
  4074.       }
  4075.     else
  4076.       inc = integer_one_node;
  4077.  
  4078.     inc = convert (argtype, inc);
  4079.  
  4080.     /* Handle incrementing a cast-expression.  */
  4081.  
  4082.     switch (TREE_CODE (arg))
  4083.       {
  4084.       case NOP_EXPR:
  4085.       case CONVERT_EXPR:
  4086.       case FLOAT_EXPR:
  4087.       case FIX_TRUNC_EXPR:
  4088.       case FIX_FLOOR_EXPR:
  4089.       case FIX_ROUND_EXPR:
  4090.       case FIX_CEIL_EXPR:
  4091.         {
  4092.           tree incremented, modify, value;
  4093.           if (! lvalue_p (arg) && pedantic)
  4094.         pedwarn ("cast to non-reference type used as lvalue");
  4095.           arg = stabilize_reference (arg);
  4096.           if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  4097.         value = arg;
  4098.           else
  4099.         value = save_expr (arg);
  4100.           incremented = build (((code == PREINCREMENT_EXPR
  4101.                      || code == POSTINCREMENT_EXPR)
  4102.                     ? PLUS_EXPR : MINUS_EXPR),
  4103.                    argtype, value, inc);
  4104.           TREE_SIDE_EFFECTS (incremented) = 1;
  4105.           modify = build_modify_expr (arg, NOP_EXPR, incremented);
  4106.           return build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  4107.         }
  4108.       }
  4109.  
  4110.     /* Complain about anything else that is not a true lvalue.  */
  4111.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  4112.                     || code == POSTINCREMENT_EXPR)
  4113.                    ? "increment" : "decrement")))
  4114.       return error_mark_node;
  4115.  
  4116.     /* Forbid using -- on `bool'.  */
  4117.     if (TREE_TYPE (arg) == boolean_type_node)
  4118.       {
  4119.         if (code == POSTDECREMENT_EXPR || code == PREDECREMENT_EXPR)
  4120.           {
  4121.         cp_error ("invalid use of `--' on bool variable `%D'", arg);
  4122.         return error_mark_node;
  4123.           }
  4124. #if 0
  4125.         /* This will only work if someone can convince Kenner to accept
  4126.            my patch to expand_increment. (jason)  */
  4127.         val = build (code, TREE_TYPE (arg), arg, inc);
  4128. #else
  4129.         if (code == POSTINCREMENT_EXPR)
  4130.           {
  4131.         arg = stabilize_reference (arg);
  4132.         val = build (MODIFY_EXPR, TREE_TYPE (arg), arg,
  4133.                  boolean_true_node);
  4134.         TREE_SIDE_EFFECTS (val) = 1;
  4135.         arg = save_expr (arg);
  4136.         val = build (COMPOUND_EXPR, TREE_TYPE (arg), val, arg);
  4137.         val = build (COMPOUND_EXPR, TREE_TYPE (arg), arg, val);
  4138.           }
  4139.         else
  4140.           val = build (MODIFY_EXPR, TREE_TYPE (arg), arg,
  4141.                boolean_true_node);
  4142. #endif
  4143.       }
  4144.     else
  4145.       val = build (code, TREE_TYPE (arg), arg, inc);
  4146.  
  4147.     TREE_SIDE_EFFECTS (val) = 1;
  4148.     return convert (result_type, val);
  4149.       }
  4150.  
  4151.     case ADDR_EXPR:
  4152.       /* Note that this operation never does default_conversion
  4153.      regardless of NOCONVERT.  */
  4154.  
  4155.       argtype = TREE_TYPE (arg);
  4156.       if (TREE_CODE (argtype) == REFERENCE_TYPE)
  4157.     {
  4158.       arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
  4159.       TREE_REFERENCE_EXPR (arg) = 1;
  4160.       return arg;
  4161.     }
  4162.       else if (pedantic
  4163.            && TREE_CODE (arg) == FUNCTION_DECL
  4164.            && DECL_NAME (arg)
  4165.            && DECL_CONTEXT (arg) == NULL_TREE
  4166.            && IDENTIFIER_LENGTH (DECL_NAME (arg)) == 4
  4167.            && IDENTIFIER_POINTER (DECL_NAME (arg))[0] == 'm'
  4168.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (arg)), "main"))
  4169.     /* ARM $3.4 */
  4170.     pedwarn ("taking address of function `main'");
  4171.  
  4172.       /* Let &* cancel out to simplify resulting code.  */
  4173.       if (TREE_CODE (arg) == INDIRECT_REF)
  4174.     {
  4175.       /* We don't need to have `current_class_decl' wrapped in a
  4176.          NON_LVALUE_EXPR node.  */
  4177.       if (arg == C_C_D)
  4178.         return current_class_decl;
  4179.  
  4180.       /* Keep `default_conversion' from converting if
  4181.          ARG is of REFERENCE_TYPE.  */
  4182.       arg = TREE_OPERAND (arg, 0);
  4183.       if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE)
  4184.         {
  4185.           if (TREE_CODE (arg) == VAR_DECL && DECL_INITIAL (arg)
  4186.           && !TREE_SIDE_EFFECTS (DECL_INITIAL (arg)))
  4187.         arg = DECL_INITIAL (arg);
  4188.           arg = build1 (CONVERT_EXPR, build_pointer_type (TREE_TYPE (TREE_TYPE (arg))), arg);
  4189.           TREE_REFERENCE_EXPR (arg) = 1;
  4190.           TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
  4191.         }
  4192.       else if (lvalue_p (arg))
  4193.         /* Don't let this be an lvalue.  */
  4194.         return non_lvalue (arg);
  4195.       return arg;
  4196.     }
  4197.  
  4198.       /* For &x[y], return x+y */
  4199.       if (TREE_CODE (arg) == ARRAY_REF)
  4200.     {
  4201.       if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
  4202.         return error_mark_node;
  4203.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  4204.                   TREE_OPERAND (arg, 1), 1);
  4205.     }
  4206.  
  4207.       /* Uninstantiated types are all functions.  Taking the
  4208.      address of a function is a no-op, so just return the
  4209.      argument.  */
  4210.  
  4211.       if (TREE_CODE (arg) == IDENTIFIER_NODE
  4212.       && IDENTIFIER_OPNAME_P (arg))
  4213.     {
  4214.       my_friendly_abort (117);
  4215.       /* We don't know the type yet, so just work around the problem.
  4216.          We know that this will resolve to an lvalue.  */
  4217.       return build1 (ADDR_EXPR, unknown_type_node, arg);
  4218.     }
  4219.  
  4220.       if (TREE_CODE (arg) == TREE_LIST)
  4221.     {
  4222.       if (TREE_CODE (TREE_VALUE (arg)) == FUNCTION_DECL
  4223.           && DECL_CHAIN (TREE_VALUE (arg)) == NULL_TREE)
  4224.         /* Unique overloaded non-member function.  */
  4225.         return build_unary_op (ADDR_EXPR, TREE_VALUE (arg), 0);
  4226.       if (TREE_CHAIN (arg) == NULL_TREE
  4227.           && TREE_CODE (TREE_VALUE (arg)) == TREE_LIST
  4228.           && DECL_CHAIN (TREE_VALUE (TREE_VALUE (arg))) == NULL_TREE)
  4229.         /* Unique overloaded member function.  */
  4230.         return build_unary_op (ADDR_EXPR, TREE_VALUE (TREE_VALUE (arg)),
  4231.                    0);
  4232.       return build1 (ADDR_EXPR, unknown_type_node, arg);
  4233.     }
  4234.  
  4235.       /* Handle complex lvalues (when permitted)
  4236.      by reduction to simpler cases.  */
  4237.       val = unary_complex_lvalue (code, arg);
  4238.       if (val != 0)
  4239.     return val;
  4240.  
  4241.       switch (TREE_CODE (arg))
  4242.     {
  4243.     case NOP_EXPR:
  4244.     case CONVERT_EXPR:
  4245.     case FLOAT_EXPR:
  4246.     case FIX_TRUNC_EXPR:
  4247.     case FIX_FLOOR_EXPR:
  4248.     case FIX_ROUND_EXPR:
  4249.     case FIX_CEIL_EXPR:
  4250.       if (! lvalue_p (arg) && pedantic)
  4251.         pedwarn ("taking the address of a cast to non-reference type");
  4252.     }
  4253.  
  4254.       /* Allow the address of a constructor if all the elements
  4255.      are constant.  */
  4256.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
  4257.     ;
  4258.       /* Anything not already handled and not a true memory reference
  4259.      is an error.  */
  4260.       else if (TREE_CODE (argtype) != FUNCTION_TYPE
  4261.            && TREE_CODE (argtype) != METHOD_TYPE
  4262.            && !lvalue_or_else (arg, "unary `&'"))
  4263.     return error_mark_node;
  4264.  
  4265.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  4266.       /* If the lvalue is const or volatile,
  4267.      merge that into the type that the address will point to.  */
  4268.       if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
  4269.       || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
  4270.     {
  4271.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  4272.         argtype = cp_build_type_variant (argtype,
  4273.                         TREE_READONLY (arg),
  4274.                         TREE_THIS_VOLATILE (arg));
  4275.     }
  4276.  
  4277.       argtype = build_pointer_type (argtype);
  4278.  
  4279.       if (mark_addressable (arg) == 0)
  4280.     return error_mark_node;
  4281.  
  4282.       {
  4283.     tree addr;
  4284.  
  4285.     if (TREE_CODE (arg) == COMPONENT_REF)
  4286.       addr = build_component_addr (arg, argtype,
  4287.                        "attempt to take address of bit-field structure member `%s'");
  4288.     else
  4289.       addr = build1 (code, argtype, arg);
  4290.  
  4291.     /* Address of a static or external variable or
  4292.        function counts as a constant */
  4293.     if (staticp (arg))
  4294.       TREE_CONSTANT (addr) = 1;
  4295.     return addr;
  4296.       }
  4297.     }
  4298.  
  4299.   if (!errstring)
  4300.     {
  4301.       if (argtype == 0)
  4302.     argtype = TREE_TYPE (arg);
  4303.       return fold (build1 (code, argtype, arg));
  4304.     }
  4305.  
  4306.   error (errstring);
  4307.   return error_mark_node;
  4308. }
  4309.  
  4310. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  4311.    convert ARG with the same conversions in the same order
  4312.    and return the result.  */
  4313.  
  4314. static tree
  4315. convert_sequence (conversions, arg)
  4316.      tree conversions;
  4317.      tree arg;
  4318. {
  4319.   switch (TREE_CODE (conversions))
  4320.     {
  4321.     case NOP_EXPR:
  4322.     case CONVERT_EXPR:
  4323.     case FLOAT_EXPR:
  4324.     case FIX_TRUNC_EXPR:
  4325.     case FIX_FLOOR_EXPR:
  4326.     case FIX_ROUND_EXPR:
  4327.     case FIX_CEIL_EXPR:
  4328.       return convert (TREE_TYPE (conversions),
  4329.               convert_sequence (TREE_OPERAND (conversions, 0),
  4330.                     arg));
  4331.  
  4332.     default:
  4333.       return arg;
  4334.     }
  4335. }
  4336.  
  4337. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  4338.    for certain kinds of expressions which are not really lvalues
  4339.    but which we can accept as lvalues.
  4340.  
  4341.    If ARG is not a kind of expression we can handle, return zero.  */
  4342.    
  4343. tree
  4344. unary_complex_lvalue (code, arg)
  4345.      enum tree_code code;
  4346.      tree arg;
  4347. {
  4348.   /* Handle (a, b) used as an "lvalue".  */
  4349.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  4350.     {
  4351.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  4352.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  4353.             TREE_OPERAND (arg, 0), real_result);
  4354.     }
  4355.  
  4356.   /* Handle (a ? b : c) used as an "lvalue".  */
  4357.   if (TREE_CODE (arg) == COND_EXPR)
  4358.     return rationalize_conditional_expr (code, arg);
  4359.  
  4360.   if (TREE_CODE (arg) == MODIFY_EXPR
  4361.       || TREE_CODE (arg) == PREINCREMENT_EXPR
  4362.       || TREE_CODE (arg) == PREDECREMENT_EXPR)
  4363.     return unary_complex_lvalue
  4364.       (code, build (COMPOUND_EXPR, TREE_TYPE (TREE_OPERAND (arg, 0)),
  4365.             arg, TREE_OPERAND (arg, 0)));
  4366.  
  4367.   if (code != ADDR_EXPR)
  4368.     return 0;
  4369.  
  4370.   /* Handle (a = b) used as an "lvalue" for `&'.  */
  4371.   if (TREE_CODE (arg) == MODIFY_EXPR
  4372.       || TREE_CODE (arg) == INIT_EXPR)
  4373.     {
  4374.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
  4375.       return build (COMPOUND_EXPR, TREE_TYPE (real_result), arg, real_result);
  4376.     }
  4377.  
  4378.   if (TREE_CODE (arg) == WITH_CLEANUP_EXPR)
  4379.     {
  4380.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 0), 0);
  4381.       real_result = build (WITH_CLEANUP_EXPR, TREE_TYPE (real_result),
  4382.                real_result, 0, TREE_OPERAND (arg, 2));
  4383.       return real_result;
  4384.     }
  4385.  
  4386.   if (TREE_CODE (TREE_TYPE (arg)) == FUNCTION_TYPE
  4387.       || TREE_CODE (TREE_TYPE (arg)) == METHOD_TYPE
  4388.       || TREE_CODE (TREE_TYPE (arg)) == OFFSET_TYPE)
  4389.     {
  4390.       /* The representation of something of type OFFSET_TYPE
  4391.      is really the representation of a pointer to it.
  4392.      Here give the representation its true type.  */
  4393.       tree t;
  4394.       tree offset;
  4395.  
  4396.       my_friendly_assert (TREE_CODE (arg) != SCOPE_REF, 313);
  4397.  
  4398.       if (TREE_CODE (arg) != OFFSET_REF)
  4399.     return 0;
  4400.  
  4401.       t = TREE_OPERAND (arg, 1);
  4402.  
  4403.       if (TREE_CODE (t) == FUNCTION_DECL) /* Check all this code for right semantics. */
  4404.     return build_unary_op (ADDR_EXPR, t, 0);
  4405.       if (TREE_CODE (t) == VAR_DECL)
  4406.     return build_unary_op (ADDR_EXPR, t, 0);
  4407.       else
  4408.     {
  4409.       if (TREE_OPERAND (arg, 0)
  4410.           && (TREE_CODE (TREE_OPERAND (arg, 0)) != NOP_EXPR
  4411.           || TREE_OPERAND (TREE_OPERAND (arg, 0), 0) != error_mark_node))
  4412.         if (TREE_CODE (t) != FIELD_DECL)
  4413.           {
  4414.         /* Don't know if this should return address to just
  4415.            _DECL, or actual address resolved in this expression.  */
  4416.         sorry ("address of bound pointer-to-member expression");
  4417.         return error_mark_node;
  4418.           }
  4419.  
  4420.       offset = get_delta_difference (DECL_FIELD_CONTEXT (t), 
  4421.                      TREE_TYPE (TREE_OPERAND (arg, 0)),
  4422.                      0);
  4423.       offset = size_binop (PLUS_EXPR, offset,
  4424.                    size_binop (EASY_DIV_EXPR,
  4425.                        DECL_FIELD_BITPOS (t),
  4426.                        size_int (BITS_PER_UNIT)));
  4427.       return convert (build_pointer_type (TREE_TYPE (arg)), offset);
  4428.     }
  4429.     }
  4430.  
  4431.   if (TREE_CODE (arg) == OFFSET_REF)
  4432.     {
  4433.       tree left = TREE_OPERAND (arg, 0), left_addr;
  4434.       tree right_addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 1), 0);
  4435.  
  4436.       if (left == 0)
  4437.     if (current_class_decl)
  4438.       left_addr = current_class_decl;
  4439.     else
  4440.       {
  4441.         error ("no `this' for pointer to member");
  4442.         return error_mark_node;
  4443.       }
  4444.       else
  4445.     left_addr = build_unary_op (ADDR_EXPR, left, 0);
  4446.  
  4447.       return build (PLUS_EXPR, build_pointer_type (TREE_TYPE (arg)),
  4448.             build1 (NOP_EXPR, integer_type_node, left_addr),
  4449.             build1 (NOP_EXPR, integer_type_node, right_addr));
  4450.     }
  4451.  
  4452.   /* We permit compiler to make function calls returning
  4453.      objects of aggregate type look like lvalues.  */
  4454.   {
  4455.     tree targ = arg;
  4456.  
  4457.     if (TREE_CODE (targ) == SAVE_EXPR)
  4458.       targ = TREE_OPERAND (targ, 0);
  4459.  
  4460.     if (TREE_CODE (targ) == CALL_EXPR && IS_AGGR_TYPE (TREE_TYPE (targ)))
  4461.       {
  4462.     if (TREE_CODE (arg) == SAVE_EXPR)
  4463.       targ = arg;
  4464.     else
  4465.       targ = build_cplus_new (TREE_TYPE (arg), arg, 1);
  4466.     return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (arg)), targ);
  4467.       }
  4468.  
  4469.     if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == INDIRECT_REF)
  4470.       return build (SAVE_EXPR, build_pointer_type (TREE_TYPE (arg)),
  4471.              TREE_OPERAND (targ, 0), current_function_decl, NULL);
  4472.  
  4473.     /* We shouldn't wrap WITH_CLEANUP_EXPRs inside of SAVE_EXPRs, but in case
  4474.        we do, here's how to handle it.  */
  4475.     if (TREE_CODE (arg) == SAVE_EXPR && TREE_CODE (targ) == WITH_CLEANUP_EXPR)
  4476.       {
  4477. #if 0
  4478.     /* Not really a bug, but something to turn on when testing.  */
  4479.     compiler_error ("WITH_CLEANUP_EXPR wrapped in SAVE_EXPR");
  4480. #endif
  4481.     return unary_complex_lvalue (ADDR_EXPR, targ);
  4482.       }
  4483.   }
  4484.  
  4485.   /* Don't let anything else be handled specially.  */
  4486.   return 0;
  4487. }
  4488.  
  4489. /* Mark EXP saying that we need to be able to take the
  4490.    address of it; it should not be allocated in a register.
  4491.    Value is 1 if successful.
  4492.  
  4493.    C++: we do not allow `current_class_decl' to be addressable.  */
  4494.  
  4495. int
  4496. mark_addressable (exp)
  4497.      tree exp;
  4498. {
  4499.   register tree x = exp;
  4500.  
  4501.   if (TREE_ADDRESSABLE (x) == 1)
  4502.     return 1;
  4503.  
  4504.   while (1)
  4505.     switch (TREE_CODE (x))
  4506.       {
  4507.       case ADDR_EXPR:
  4508.       case COMPONENT_REF:
  4509.       case ARRAY_REF:
  4510.     x = TREE_OPERAND (x, 0);
  4511.     break;
  4512.  
  4513.       case PARM_DECL:
  4514.     if (x == current_class_decl)
  4515.       {
  4516.         error ("address of `this' not available");
  4517.         TREE_ADDRESSABLE (x) = 1; /* so compiler doesn't die later */
  4518.         put_var_into_stack (x);
  4519.         return 1;
  4520.       }
  4521.       case VAR_DECL:
  4522.     if (TREE_STATIC (x)
  4523.         && TREE_READONLY (x)
  4524.         && DECL_RTL (x) != 0
  4525.         && ! decl_in_memory_p (x))
  4526.       {
  4527.         /* We thought this would make a good constant variable,
  4528.            but we were wrong.  */
  4529.         push_obstacks_nochange ();
  4530.         end_temporary_allocation ();
  4531.  
  4532.         TREE_ASM_WRITTEN (x) = 0;
  4533.         DECL_RTL (x) = 0;
  4534.         rest_of_decl_compilation (x, 0, IDENTIFIER_LOCAL_VALUE (x) == 0, 0);
  4535.         TREE_ADDRESSABLE (x) = 1;
  4536.  
  4537.         pop_obstacks ();
  4538.  
  4539.         return 1;
  4540.       }
  4541.     /* Caller should not be trying to mark initialized
  4542.        constant fields addressable.  */
  4543.     my_friendly_assert (DECL_LANG_SPECIFIC (x) == 0
  4544.                 || DECL_IN_AGGR_P (x) == 0
  4545.                 || TREE_STATIC (x)
  4546.                 || DECL_EXTERNAL (x), 314);
  4547.  
  4548.       case CONST_DECL:
  4549.       case RESULT_DECL:
  4550.     /* For C++, we don't warn about taking the address of a register
  4551.        variable for CONST_DECLs; ARM p97 explicitly says it's okay.  */
  4552.     put_var_into_stack (x);
  4553.     TREE_ADDRESSABLE (x) = 1;
  4554.     return 1;
  4555.  
  4556.       case FUNCTION_DECL:
  4557.     /* We have to test both conditions here.  The first may
  4558.        be non-zero in the case of processing a default function.
  4559.        The second may be non-zero in the case of a template function.  */
  4560.     x = DECL_MAIN_VARIANT (x);
  4561.     if ((DECL_THIS_INLINE (x) || DECL_PENDING_INLINE_INFO (x))
  4562.         && (DECL_CONTEXT (x) == NULL_TREE
  4563.         || TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (x))) != 't'
  4564.         || ! CLASSTYPE_INTERFACE_ONLY (DECL_CONTEXT (x))))
  4565.       {
  4566.         mark_inline_for_output (x);
  4567.         if (x == current_function_decl)
  4568.           DECL_EXTERNAL (x) = 0;
  4569.       }
  4570.     TREE_ADDRESSABLE (x) = 1;
  4571.     TREE_USED (x) = 1;
  4572.     TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
  4573.     if (asm_out_file)
  4574.       assemble_external (x);
  4575.     return 1;
  4576.  
  4577.       default:
  4578.     return 1;
  4579.     }
  4580. }
  4581.  
  4582. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  4583.  
  4584. tree
  4585. build_x_conditional_expr (ifexp, op1, op2)
  4586.      tree ifexp, op1, op2;
  4587. {
  4588.   tree rval = NULL_TREE;
  4589.  
  4590.   /* See comments in `build_x_binary_op'.  */
  4591.   if (op1 != 0)
  4592.     rval = build_opfncall (COND_EXPR, LOOKUP_SPECULATIVELY, ifexp, op1, op2);
  4593.   if (rval)
  4594.     return build_opfncall (COND_EXPR, LOOKUP_NORMAL, ifexp, op1, op2);
  4595.   
  4596.   return build_conditional_expr (ifexp, op1, op2);
  4597. }
  4598.  
  4599. tree
  4600. build_conditional_expr (ifexp, op1, op2)
  4601.      tree ifexp, op1, op2;
  4602. {
  4603.   register tree type1;
  4604.   register tree type2;
  4605.   register enum tree_code code1;
  4606.   register enum tree_code code2;
  4607.   register tree result_type = NULL_TREE;
  4608.   tree orig_op1 = op1, orig_op2 = op2;
  4609.  
  4610.   /* If second operand is omitted, it is the same as the first one;
  4611.      make sure it is calculated only once.  */
  4612.   if (op1 == 0)
  4613.     {
  4614.       if (pedantic)
  4615.     pedwarn ("ANSI C++ forbids omitting the middle term of a ?: expression");
  4616.       ifexp = op1 = save_expr (ifexp);
  4617.     }
  4618.  
  4619.   ifexp = convert (boolean_type_node, ifexp);
  4620.  
  4621.   if (TREE_CODE (ifexp) == ERROR_MARK)
  4622.     return error_mark_node;
  4623.  
  4624.   op1 = require_instantiated_type (TREE_TYPE (op2), op1, error_mark_node);
  4625.   if (op1 == error_mark_node)
  4626.     return error_mark_node;
  4627.   op2 = require_instantiated_type (TREE_TYPE (op1), op2, error_mark_node);
  4628.   if (op2 == error_mark_node)
  4629.     return error_mark_node;
  4630.  
  4631.   /* C++: REFERENCE_TYPES must be dereferenced.  */
  4632.   type1 = TREE_TYPE (op1);
  4633.   code1 = TREE_CODE (type1);
  4634.   type2 = TREE_TYPE (op2);
  4635.   code2 = TREE_CODE (type2);
  4636.  
  4637.   if (code1 == REFERENCE_TYPE)
  4638.     {
  4639.       op1 = convert_from_reference (op1);
  4640.       type1 = TREE_TYPE (op1);
  4641.       code1 = TREE_CODE (type1);
  4642.     }
  4643.   if (code2 == REFERENCE_TYPE)
  4644.     {
  4645.       op2 = convert_from_reference (op2);
  4646.       type2 = TREE_TYPE (op2);
  4647.       code2 = TREE_CODE (type2);
  4648.     }
  4649.  
  4650. #if 1 /* Produces wrong result if within sizeof.  Sorry.  */
  4651.   /* Don't promote the operands separately if they promote
  4652.      the same way.  Return the unpromoted type and let the combined
  4653.      value get promoted if necessary.  */
  4654.  
  4655.   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2)
  4656.       && code2 != ARRAY_TYPE
  4657. #if 0
  4658.       /* For C++, let the enumeral type come through.  */
  4659.       && code2 != ENUMERAL_TYPE
  4660. #endif
  4661.       && code2 != FUNCTION_TYPE
  4662.       && code2 != METHOD_TYPE)
  4663.     {
  4664.       tree result;
  4665.  
  4666.       if (TREE_CONSTANT (ifexp)
  4667.       && (TREE_CODE (ifexp) == INTEGER_CST
  4668.           || TREE_CODE (ifexp) == ADDR_EXPR))
  4669.     return (integer_zerop (ifexp) ? op2 : op1);
  4670.  
  4671.       if (TREE_CODE (op1) == CONST_DECL)
  4672.     op1 = DECL_INITIAL (op1);
  4673.       else if (TREE_READONLY_DECL_P (op1))
  4674.     op1 = decl_constant_value (op1);
  4675.       if (TREE_CODE (op2) == CONST_DECL)
  4676.     op2 = DECL_INITIAL (op2);
  4677.       else if (TREE_READONLY_DECL_P (op2))
  4678.     op2 = decl_constant_value (op2);
  4679.       if (type1 != type2)
  4680.     type1 = cp_build_type_variant
  4681.             (type1,
  4682.              TREE_READONLY (op1) || TREE_READONLY (op2),
  4683.              TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
  4684.       /* ??? This is a kludge to deal with the fact that
  4685.      we don't sort out integers and enums properly, yet.  */
  4686.       result = fold (build (COND_EXPR, type1, ifexp, op1, op2));
  4687.       if (TREE_TYPE (result) != type1)
  4688.     result = build1 (NOP_EXPR, type1, result);
  4689.       return result;
  4690.     }
  4691. #endif
  4692.  
  4693.   /* They don't match; promote them both and then try to reconcile them.
  4694.      But don't permit mismatching enum types.  */
  4695.   if (code1 == ENUMERAL_TYPE)
  4696.     {
  4697.       if (code2 == ENUMERAL_TYPE)
  4698.     {
  4699.       cp_error ("enumeral mismatch in conditional expression: `%T' vs `%T'", type1, type2);
  4700.       return error_mark_node;
  4701.     }
  4702.       else if (extra_warnings && ! IS_AGGR_TYPE_CODE (code2)
  4703.            && type2 != type_promotes_to (type1))
  4704.     warning ("enumeral and non-enumeral type in conditional expression");
  4705.     }
  4706.   else if (extra_warnings
  4707.        && code2 == ENUMERAL_TYPE && ! IS_AGGR_TYPE_CODE (code1)
  4708.        && type1 != type_promotes_to (type2))
  4709.     warning ("enumeral and non-enumeral type in conditional expression");
  4710.  
  4711.   if (code1 != VOID_TYPE)
  4712.     {
  4713.       op1 = default_conversion (op1);
  4714.       type1 = TREE_TYPE (op1);
  4715.       if (TYPE_PTRMEMFUNC_P (type1))
  4716.     type1 = TYPE_PTRMEMFUNC_FN_TYPE (type1);
  4717.       code1 = TREE_CODE (type1);
  4718.     }
  4719.   if (code2 != VOID_TYPE)
  4720.     {
  4721.       op2 = default_conversion (op2);
  4722.       type2 = TREE_TYPE (op2);
  4723.       if (TYPE_PTRMEMFUNC_P (type2))
  4724.     type2 = TYPE_PTRMEMFUNC_FN_TYPE (type2);
  4725.       code2 = TREE_CODE (type2);
  4726.     }
  4727.  
  4728.   if (code1 == RECORD_TYPE && code2 == RECORD_TYPE
  4729.       && real_lvalue_p (op1) && real_lvalue_p (op2)
  4730.       && comptypes (type1, type2, -1))
  4731.     {
  4732.       type1 = build_reference_type (type1);
  4733.       type2 = build_reference_type (type2);
  4734.       result_type = common_type (type1, type2);
  4735.       op1 = convert_to_reference (result_type, op1, CONV_IMPLICIT,
  4736.                   LOOKUP_NORMAL, NULL_TREE);
  4737.       op2 = convert_to_reference (result_type, op2, CONV_IMPLICIT,
  4738.                   LOOKUP_NORMAL, NULL_TREE);
  4739.     }
  4740.   /* Quickly detect the usual case where op1 and op2 have the same type
  4741.      after promotion.  */
  4742.   else if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
  4743.     {
  4744.       if (type1 == type2)
  4745.     result_type = type1;
  4746.       else
  4747.     result_type = cp_build_type_variant
  4748.             (type1,
  4749.              TREE_READONLY (op1) || TREE_READONLY (op2),
  4750.              TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
  4751.     }
  4752.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  4753.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  4754.     {
  4755.       result_type = common_type (type1, type2);
  4756.     }
  4757.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  4758.     {
  4759.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  4760.     pedwarn ("ANSI C++ forbids conditional expr with only one void side");
  4761.       result_type = void_type_node;
  4762.     }
  4763.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  4764.     {
  4765.       if (comp_target_types (type1, type2, 1))
  4766.     result_type = common_type (type1, type2);
  4767.       else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
  4768.            && TREE_CODE (orig_op1) != NOP_EXPR)
  4769.     result_type = qualify_type (type2, type1);
  4770.       else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
  4771.            && TREE_CODE (orig_op2) != NOP_EXPR)
  4772.     result_type = qualify_type (type1, type2);
  4773.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  4774.     {
  4775.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  4776.         pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
  4777.       result_type = qualify_type (type1, type2);
  4778.     }
  4779.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  4780.     {
  4781.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  4782.         pedwarn ("ANSI C++ forbids conditional expr between `void *' and function pointer");
  4783.       result_type = qualify_type (type2, type1);
  4784.     }
  4785.       /* C++ */
  4786.       else if (comptypes (type2, type1, 0))
  4787.     result_type = type2;
  4788.       else if (IS_AGGR_TYPE (TREE_TYPE (type1))
  4789.            && IS_AGGR_TYPE (TREE_TYPE (type2))
  4790.            && (result_type = common_base_type (TREE_TYPE (type1), TREE_TYPE (type2))))
  4791.     {
  4792.       if (result_type == error_mark_node)
  4793.         {
  4794.           cp_error ("common base type of types `%T' and `%T' is ambiguous",
  4795.             TREE_TYPE (type1), TREE_TYPE (type2));
  4796.           result_type = ptr_type_node;
  4797.         }
  4798.       else
  4799.         {
  4800.           if (pedantic
  4801.           && result_type != TREE_TYPE (type1)
  4802.           && result_type != TREE_TYPE (type2))
  4803.         cp_pedwarn ("`%T' and `%T' converted to `%T *' in conditional expression",
  4804.                 type1, type2, result_type);
  4805.  
  4806.           result_type = build_pointer_type (result_type);
  4807.         }
  4808.     }
  4809.       else
  4810.     {
  4811.       pedwarn ("pointer type mismatch in conditional expression");
  4812.       result_type = ptr_type_node;
  4813.     }
  4814.     }
  4815.   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
  4816.     {
  4817.       if (!integer_zerop (op2))
  4818.     pedwarn ("pointer/integer type mismatch in conditional expression");
  4819.       else
  4820.     {
  4821.       op2 = null_pointer_node;
  4822. #if 0                /* Sez who? */
  4823.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  4824.         pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
  4825. #endif
  4826.     }
  4827.       result_type = type1;
  4828.     }
  4829.   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
  4830.     {
  4831.       if (!integer_zerop (op1))
  4832.     pedwarn ("pointer/integer type mismatch in conditional expression");
  4833.       else
  4834.     {
  4835.       op1 = null_pointer_node;
  4836. #if 0                /* Sez who? */
  4837.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  4838.         pedwarn ("ANSI C++ forbids conditional expr between 0 and function pointer");
  4839. #endif
  4840.     }
  4841.       result_type = type2;
  4842.     }
  4843.  
  4844.   if (!result_type)
  4845.     {
  4846.       /* The match does not look good.  If either is
  4847.      an aggregate value, try converting to a scalar type.  */
  4848.       if (code1 == RECORD_TYPE && code2 == RECORD_TYPE)
  4849.     {
  4850.       cp_error ("aggregate mismatch in conditional expression: `%T' vs `%T'", type1, type2);
  4851.       return error_mark_node;
  4852.     }
  4853.       if (code1 == RECORD_TYPE && TYPE_HAS_CONVERSION (type1))
  4854.     {
  4855.       tree tmp = build_type_conversion (CONVERT_EXPR, type2, op1, 0);
  4856.       if (tmp == NULL_TREE)
  4857.         {
  4858.           cp_error ("aggregate type `%T' could not convert on lhs of `:'", type1);
  4859.           return error_mark_node;
  4860.         }
  4861.       if (tmp == error_mark_node)
  4862.         error ("ambiguous pointer conversion");
  4863.       result_type = type2;
  4864.       op1 = tmp;
  4865.     }
  4866.       else if (code2 == RECORD_TYPE && TYPE_HAS_CONVERSION (type2))
  4867.     {
  4868.       tree tmp = build_type_conversion (CONVERT_EXPR, type1, op2, 0);
  4869.       if (tmp == NULL_TREE)
  4870.         {
  4871.           cp_error ("aggregate type `%T' could not convert on rhs of `:'", type2);
  4872.           return error_mark_node;
  4873.         }
  4874.       if (tmp == error_mark_node)
  4875.         error ("ambiguous pointer conversion");
  4876.       result_type = type1;
  4877.       op2 = tmp;
  4878.     }
  4879.       else if (flag_cond_mismatch)
  4880.     result_type = void_type_node;
  4881.       else
  4882.     {
  4883.       error ("type mismatch in conditional expression");
  4884.       return error_mark_node;
  4885.     }
  4886.     }
  4887.  
  4888.   if (TREE_CODE (result_type) == POINTER_TYPE
  4889.       && TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
  4890.     result_type = build_ptrmemfunc_type (result_type);
  4891.  
  4892.   if (result_type != TREE_TYPE (op1))
  4893.     op1 = convert_and_check (result_type, op1);
  4894.   if (result_type != TREE_TYPE (op2))
  4895.     op2 = convert_and_check (result_type, op2);
  4896.  
  4897. #if 0
  4898.   /* XXX delete me, I've been here for years.  */
  4899.   if (IS_AGGR_TYPE_CODE (code1))
  4900.     {
  4901.       result_type = TREE_TYPE (op1);
  4902.       if (TREE_CONSTANT (ifexp))
  4903.     return (integer_zerop (ifexp) ? op2 : op1);
  4904.  
  4905.       if (TYPE_MODE (result_type) == BLKmode)
  4906.     {
  4907.       register tree tempvar
  4908.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  4909.       register tree xop1 = build_modify_expr (tempvar, NOP_EXPR, op1);
  4910.       register tree xop2 = build_modify_expr (tempvar, NOP_EXPR, op2);
  4911.       register tree result = fold (build (COND_EXPR, result_type,
  4912.                           ifexp, xop1, xop2));
  4913.  
  4914.       layout_decl (tempvar, 0);
  4915.       /* No way to handle variable-sized objects here.
  4916.          I fear that the entire handling of BLKmode conditional exprs
  4917.          needs to be redone.  */
  4918.       my_friendly_assert (TREE_CONSTANT (DECL_SIZE (tempvar)), 315);
  4919.       DECL_RTL (tempvar)
  4920.         = assign_stack_local (DECL_MODE (tempvar),
  4921.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  4922.                    + BITS_PER_UNIT - 1)
  4923.                   / BITS_PER_UNIT,
  4924.                   0);
  4925.  
  4926.       TREE_SIDE_EFFECTS (result)
  4927.         = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
  4928.           | TREE_SIDE_EFFECTS (op2);
  4929.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  4930.     }
  4931.     }
  4932. #endif /* 0 */
  4933.  
  4934.   if (TREE_CONSTANT (ifexp))
  4935.     return integer_zerop (ifexp) ? op2 : op1;
  4936.  
  4937.   return convert_from_reference
  4938.     (fold (build (COND_EXPR, result_type, ifexp, op1, op2)));
  4939. }
  4940.  
  4941. /* Handle overloading of the ',' operator when needed.  Otherwise,
  4942.    this function just builds an expression list.  */
  4943. tree
  4944. build_x_compound_expr (list)
  4945.      tree list;
  4946. {
  4947.   tree rest = TREE_CHAIN (list);
  4948.   tree result;
  4949.  
  4950.   if (rest == NULL_TREE)
  4951.     return build_compound_expr (list);
  4952.  
  4953.   result = build_opfncall (COMPOUND_EXPR, LOOKUP_NORMAL,
  4954.                TREE_VALUE (list), TREE_VALUE (rest), NULL_TREE);
  4955.   if (result)
  4956.     return build_x_compound_expr (tree_cons (NULL_TREE, result, TREE_CHAIN (rest)));
  4957.  
  4958.   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
  4959.     {
  4960.       /* the left-hand operand of a comma expression is like an expression
  4961.          statement: we should warn if it doesn't have any side-effects,
  4962.          unless it was explicitly cast to (void).  */
  4963.       if ((extra_warnings || warn_unused)
  4964.            && !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
  4965.                 && TREE_TYPE (TREE_VALUE(list)) == void_type_node))
  4966.         warning("left-hand operand of comma expression has no effect");
  4967.     }
  4968. #if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
  4969.   else if (warn_unused)
  4970.     warn_if_unused_value (TREE_VALUE(list));
  4971. #endif
  4972.  
  4973.   return build_compound_expr (tree_cons (NULL_TREE, TREE_VALUE (list),
  4974.                      build_tree_list (NULL_TREE, build_x_compound_expr (rest))));
  4975. }
  4976.  
  4977. /* Given a list of expressions, return a compound expression
  4978.    that performs them all and returns the value of the last of them.  */
  4979.  
  4980. tree
  4981. build_compound_expr (list)
  4982.      tree list;
  4983. {
  4984.   register tree rest;
  4985.  
  4986.   if (TREE_READONLY_DECL_P (TREE_VALUE (list)))
  4987.     TREE_VALUE (list) = decl_constant_value (TREE_VALUE (list));
  4988.  
  4989.   if (TREE_CHAIN (list) == 0)
  4990.     {
  4991.       /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  4992.      Strip such NOP_EXPRs, since LIST is used in non-lvalue context.  */
  4993.       if (TREE_CODE (list) == NOP_EXPR
  4994.       && TREE_TYPE (list) == TREE_TYPE (TREE_OPERAND (list, 0)))
  4995.     list = TREE_OPERAND (list, 0);
  4996.  
  4997.       /* Convert arrays to pointers.  */
  4998.       if (TREE_CODE (TREE_TYPE (TREE_VALUE (list))) == ARRAY_TYPE)
  4999.     return default_conversion (TREE_VALUE (list));
  5000.       else
  5001.     return TREE_VALUE (list);
  5002.     }
  5003.  
  5004.   rest = build_compound_expr (TREE_CHAIN (list));
  5005.  
  5006.   /* When pedantic, a compound expression cannot be a constant expression.  */
  5007.   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic)
  5008.     return rest;
  5009.  
  5010.   return build (COMPOUND_EXPR, TREE_TYPE (rest),
  5011.         break_out_cleanups (TREE_VALUE (list)), rest);
  5012. }
  5013.  
  5014. #ifdef __GNUC__
  5015. __inline
  5016. #endif
  5017. int
  5018. null_ptr_cst_p (t)
  5019.      tree t;
  5020. {
  5021.   return (TREE_CODE (t) == INTEGER_CST && integer_zerop (t));
  5022. }
  5023.  
  5024. tree build_static_cast (type, expr)
  5025.    tree type, expr;
  5026. {
  5027.   return build_c_cast (type, expr, 0);
  5028. }
  5029.  
  5030. tree build_reinterpret_cast (type, expr)
  5031.    tree type, expr;
  5032. {
  5033.   tree intype = TREE_TYPE (expr);
  5034.  
  5035.   if (TYPE_PTRMEMFUNC_P (type))
  5036.     type = TYPE_PTRMEMFUNC_FN_TYPE (type);
  5037.   if (TYPE_PTRMEMFUNC_P (intype))
  5038.     intype = TYPE_PTRMEMFUNC_FN_TYPE (intype);
  5039.  
  5040.   if (! POINTER_TYPE_P (type) && ! TREE_CODE (type) == INTEGER_TYPE)
  5041.     {
  5042.       cp_error ("reinterpret_cast cannot convert to type `%T'", type);
  5043.       return error_mark_node;
  5044.     }
  5045.   if (! POINTER_TYPE_P (intype) && ! TREE_CODE (intype) == INTEGER_TYPE)
  5046.     {
  5047.       cp_error ("reinterpret_cast cannot convert from type `%T'", type);
  5048.       return error_mark_node;
  5049.     }
  5050.   if (TREE_CODE (type) == INTEGER_TYPE && TREE_CODE (intype) != POINTER_TYPE)
  5051.     {
  5052.       cp_error ("reinterpret_cast cannot convert non-pointer type `%T' to `%T'",
  5053.         intype, type);
  5054.       return error_mark_node;
  5055.     }
  5056.   if (TREE_CODE (intype) == INTEGER_TYPE && TREE_CODE (type) != POINTER_TYPE)
  5057.     {
  5058.       cp_error ("reinterpret_cast cannot convert `%T' to non-pointer type `%T'",
  5059.         intype, type);
  5060.       return error_mark_node;
  5061.     }
  5062.  
  5063.   if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (intype) == POINTER_TYPE)
  5064.     expr = convert (ptr_type_node, expr);
  5065.  
  5066.   return build_c_cast (type, expr, 0);
  5067. }
  5068.  
  5069. tree build_const_cast (type, expr)
  5070.    tree type, expr;
  5071. {
  5072.   tree intype = TREE_TYPE (expr);
  5073.   tree t1, t2;
  5074.  
  5075.   if (type == error_mark_node || expr == error_mark_node)
  5076.     return error_mark_node;
  5077.  
  5078.   if (TYPE_PTRMEMFUNC_P (type))
  5079.     type = TYPE_PTRMEMFUNC_FN_TYPE (type);
  5080.   if (TYPE_PTRMEMFUNC_P (intype))
  5081.     intype = TYPE_PTRMEMFUNC_FN_TYPE (intype);
  5082.  
  5083.   if (! POINTER_TYPE_P (type))
  5084.     {
  5085.       cp_error ("const_cast cannot convert to non-pointer type `%T'", type);
  5086.       return error_mark_node;
  5087.     }
  5088.   if (TREE_CODE (type) == REFERENCE_TYPE && ! real_lvalue_p (expr))
  5089.     {
  5090.       cp_error ("const_cast cannot convert rvalue to type `%T'", type);
  5091.       return error_mark_node;
  5092.     }
  5093.   if (TREE_CODE (type) == POINTER_TYPE && TREE_CODE (intype) != POINTER_TYPE)
  5094.     {
  5095.       cp_error ("const_cast cannot convert non-pointer type `%T' to type `%T'",
  5096.         intype, type);
  5097.       return error_mark_node;
  5098.     }
  5099.  
  5100.   if (TREE_CODE (type) == REFERENCE_TYPE)
  5101.     {
  5102.       t1 = TREE_TYPE (type);
  5103.       t2 = intype;
  5104.     }
  5105.   else
  5106.     {
  5107.       t1 = TREE_TYPE (type);
  5108.       t2 = TREE_TYPE (intype);
  5109.  
  5110.       for (; TREE_CODE (t1) == POINTER_TYPE && TREE_CODE (t2) == POINTER_TYPE;
  5111.        t1 = TREE_TYPE (t1), t2 = TREE_TYPE (t2))
  5112.     ;
  5113.     }
  5114.  
  5115.   if (TREE_CODE (t1) == OFFSET_TYPE && TREE_CODE (t2) == OFFSET_TYPE)
  5116.     {
  5117.       if (TYPE_OFFSET_BASETYPE (t1) != TYPE_OFFSET_BASETYPE (t2))
  5118.     {
  5119.       cp_error ("const_cast cannot convert between pointers to members of different types `%T' and `%T'",
  5120.             TYPE_OFFSET_BASETYPE (t2), TYPE_OFFSET_BASETYPE (t1));
  5121.       return error_mark_node;
  5122.     }
  5123.       t1 = TREE_TYPE (t1);
  5124.       t2 = TREE_TYPE (t2);
  5125.     }
  5126.  
  5127.   if (TYPE_MAIN_VARIANT (t1) != TYPE_MAIN_VARIANT (t2))
  5128.     {
  5129.       cp_error ("const_cast cannot convert unrelated type `%T' to `%T'",
  5130.         t2, t1);
  5131.       return error_mark_node;
  5132.     }
  5133.  
  5134.   return build_c_cast (type, expr, 0);
  5135. }
  5136.  
  5137. /* Build an expression representing a cast to type TYPE of expression EXPR.
  5138.  
  5139.    ALLOW_NONCONVERTING is true if we should allow non-converting constructors
  5140.    when doing the cast.  */
  5141.  
  5142. tree
  5143. build_c_cast (type, expr, allow_nonconverting)
  5144.      register tree type;
  5145.      tree expr;
  5146.      int allow_nonconverting;
  5147. {
  5148.   register tree value = expr;
  5149.  
  5150.   if (type == error_mark_node || expr == error_mark_node)
  5151.     return error_mark_node;
  5152.  
  5153.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  5154.      Strip such NOP_EXPRs if VALUE is being used in non-lvalue context.  */
  5155.   if (TREE_CODE (type) != REFERENCE_TYPE
  5156.       && TREE_CODE (value) == NOP_EXPR
  5157.       && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
  5158.     value = TREE_OPERAND (value, 0);
  5159.  
  5160.   if (TREE_TYPE (expr)
  5161.       && TREE_CODE (TREE_TYPE (expr)) == OFFSET_TYPE
  5162.       && TREE_CODE (type) != OFFSET_TYPE)
  5163.     value = resolve_offset_ref (value);
  5164.  
  5165.   if (TREE_CODE (type) == ARRAY_TYPE)
  5166.     {
  5167.       /* Allow casting from T1* to T2[] because Cfront allows it.
  5168.      NIHCL uses it. It is not valid ANSI C however, and hence, not
  5169.      valid ANSI C++.  */
  5170.       if (TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)
  5171.     {
  5172.       if (pedantic)
  5173.         pedwarn ("ANSI C++ forbids casting to an array type");
  5174.       type = build_pointer_type (TREE_TYPE (type));
  5175.     }
  5176.       else
  5177.     {
  5178.       error ("ANSI C++ forbids casting to an array type");
  5179.       return error_mark_node;
  5180.     }
  5181.     }
  5182.  
  5183.   if (TREE_CODE (type) == FUNCTION_TYPE
  5184.       || TREE_CODE (type) == METHOD_TYPE)
  5185.     {
  5186.       cp_error ("casting to function type `%T'", type);
  5187.       return error_mark_node;
  5188.     }
  5189.  
  5190.   if (IS_SIGNATURE (type))
  5191.     {
  5192.       error ("cast specifies signature type");
  5193.       return error_mark_node;
  5194.     }
  5195.  
  5196.   /* If there's only one function in the overloaded space,
  5197.      just take it.  */
  5198.   if (TREE_CODE (value) == TREE_LIST
  5199.       && TREE_CHAIN (value) == NULL_TREE)
  5200.     value = TREE_VALUE (value);
  5201.  
  5202.   if (TREE_CODE (type) == VOID_TYPE)
  5203.     value = build1 (CONVERT_EXPR, type, value);
  5204.   else if (TREE_TYPE (value) == NULL_TREE
  5205.       || type_unknown_p (value))
  5206.     {
  5207.       value = instantiate_type (type, value, 1);
  5208.       /* Did we lose?  */
  5209.       if (value == error_mark_node)
  5210.     return error_mark_node;
  5211.     }
  5212.   else
  5213.     {
  5214.       tree otype;
  5215.       int flag;
  5216.  
  5217.       /* Convert functions and arrays to pointers and
  5218.      convert references to their expanded types,
  5219.      but don't convert any other types.  */
  5220.       if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
  5221.       || TREE_CODE (TREE_TYPE (value)) == METHOD_TYPE
  5222.       || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
  5223.       || TREE_CODE (TREE_TYPE (value)) == REFERENCE_TYPE)
  5224.     value = default_conversion (value);
  5225.       otype = TREE_TYPE (value);
  5226.  
  5227.       /* Optionally warn about potentially worrisome casts.  */
  5228.  
  5229.       if (warn_cast_qual
  5230.       && TREE_CODE (type) == POINTER_TYPE
  5231.       && TREE_CODE (otype) == POINTER_TYPE)
  5232.     {
  5233.       /* For C++ we make these regular warnings, rather than
  5234.          softening them into pedwarns.  */
  5235.       if (TYPE_VOLATILE (TREE_TYPE (otype))
  5236.           && ! TYPE_VOLATILE (TREE_TYPE (type)))
  5237.         warning ("cast discards `volatile' from pointer target type");
  5238.       if (TYPE_READONLY (TREE_TYPE (otype))
  5239.           && ! TYPE_READONLY (TREE_TYPE (type)))
  5240.         warning ("cast discards `const' from pointer target type");
  5241.     }
  5242.  
  5243.       /* Warn about possible alignment problems.  */
  5244.       if (STRICT_ALIGNMENT && warn_cast_align
  5245.       && TREE_CODE (type) == POINTER_TYPE
  5246.       && TREE_CODE (otype) == POINTER_TYPE
  5247.       && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
  5248.       && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
  5249.       && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
  5250.     warning ("cast increases required alignment of target type");
  5251.  
  5252. #if 0
  5253.       if (TREE_CODE (type) == INTEGER_TYPE
  5254.       && TREE_CODE (otype) == POINTER_TYPE
  5255.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype))
  5256.     warning ("cast from pointer to integer of different size");
  5257.  
  5258.       if (TREE_CODE (type) == POINTER_TYPE
  5259.       && TREE_CODE (otype) == INTEGER_TYPE
  5260.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
  5261.       /* Don't warn about converting 0 to pointer,
  5262.          provided the 0 was explicit--not cast or made by folding.  */
  5263.       && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value)))
  5264.     warning ("cast to pointer from integer of different size");
  5265. #endif
  5266.  
  5267.       flag = allow_nonconverting ? CONV_NONCONVERTING : 0;
  5268.  
  5269.       if (TREE_CODE (type) == REFERENCE_TYPE)
  5270.     value = (convert_from_reference
  5271.          (convert_to_reference (type, value, CONV_OLD_CONVERT|flag,
  5272.                     LOOKUP_COMPLAIN, NULL_TREE)));
  5273.       else
  5274.     {
  5275.       tree ovalue;
  5276.  
  5277.       if (TREE_READONLY_DECL_P (value))
  5278.         value = decl_constant_value (value);
  5279.  
  5280.       ovalue = value;
  5281.       value = convert_force (type, value, flag);
  5282.  
  5283.       /* Ignore any integer overflow caused by the cast.  */
  5284.       if (TREE_CODE (value) == INTEGER_CST)
  5285.         {
  5286.           TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
  5287.           TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
  5288.         }
  5289.     }
  5290.     }
  5291.  
  5292.     /* Always produce some operator for an explicit cast,
  5293.        so we can tell (for -pedantic) that the cast is no lvalue.
  5294.        Also, pedantically, don't let (void *) (FOO *) 0 be a null
  5295.        pointer constant.  */
  5296.   if (TREE_CODE (type) != REFERENCE_TYPE
  5297.       && (value == expr
  5298.       || (pedantic
  5299.           && TREE_CODE (value) == INTEGER_CST
  5300.           && TREE_CODE (expr) == INTEGER_CST
  5301.           && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)))
  5302.     value = non_lvalue (value);
  5303.  
  5304.   return value;
  5305. }
  5306.  
  5307. #if 0
  5308. /* Build an assignment expression of lvalue LHS from value RHS.
  5309.  
  5310.    In C++, if the left hand side of the assignment is a REFERENCE_TYPE,
  5311.    that reference becomes deferenced down to it base type. */
  5312.  
  5313. /* Return a reference to the BASE_INDEX part of EXPR.  TYPE is
  5314.    the type to which BASE_INDEX applies.  */
  5315. static tree
  5316. get_base_ref (type, base_index, expr)
  5317.      tree type;
  5318.      int base_index;
  5319.      tree expr;
  5320. {
  5321.   tree binfos = TYPE_BINFO_BASETYPES (type);
  5322.   tree base_binfo = TREE_VEC_ELT (binfos, base_index);
  5323.   tree ref;
  5324.  
  5325.   if (TREE_CODE (expr) == ARRAY_REF
  5326.       || ! BINFO_OFFSET_ZEROP (base_binfo)
  5327.       || TREE_VIA_VIRTUAL (base_binfo)
  5328.       || TYPE_MODE (type) != TYPE_MODE (BINFO_TYPE (base_binfo)))
  5329.     {
  5330.       tree addr = build_unary_op (ADDR_EXPR, expr, 0);
  5331.       ref = build_indirect_ref (convert_pointer_to (base_binfo, addr),
  5332.                 NULL_PTR);
  5333.     }
  5334.   else
  5335.     {
  5336.       ref = copy_node (expr);
  5337.       TREE_TYPE (ref) = BINFO_TYPE (base_binfo);
  5338.     }
  5339.   return ref;
  5340. }
  5341.  
  5342. /* Build an assignment expression of lvalue LHS from value RHS.
  5343.    MODIFYCODE is the code for a binary operator that we use
  5344.    to combine the old value of LHS with RHS to get the new value.
  5345.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
  5346.  
  5347.    C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
  5348.  
  5349.    `build_modify_expr_1' implements recursive part of memberwise
  5350.    assignment operation.  */
  5351. static tree
  5352. build_modify_expr_1 (lhs, modifycode, rhs, basetype_path)
  5353.      tree lhs, rhs;
  5354.      enum tree_code modifycode;
  5355.      tree basetype_path;
  5356. {
  5357.   register tree result;
  5358.   tree newrhs = rhs;
  5359.   tree lhstype = TREE_TYPE (lhs);
  5360.   tree olhstype = lhstype;
  5361.  
  5362.   /* Avoid duplicate error messages from operands that had errors.  */
  5363.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  5364.     return error_mark_node;
  5365.  
  5366.   /* If a binary op has been requested, combine the old LHS value with the RHS
  5367.      producing the value we should actually store into the LHS.  */
  5368.  
  5369.   if (modifycode == INIT_EXPR)
  5370.     ;
  5371.   else if (modifycode == NOP_EXPR)
  5372.     {
  5373.       /* must deal with overloading of `operator=' here.  */
  5374.       if (TREE_CODE (lhstype) == REFERENCE_TYPE)
  5375.     lhstype = TREE_TYPE (lhstype);
  5376.       else
  5377.     lhstype = olhstype;
  5378.     }
  5379.   else
  5380.     {
  5381.       lhs = stabilize_reference (lhs);
  5382.       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
  5383.       modifycode = NOP_EXPR;
  5384.     }
  5385.  
  5386.   /* If storing into a structure or union member,
  5387.      it has probably been given type `int'.
  5388.      Compute the type that would go with
  5389.      the actual amount of storage the member occupies.  */
  5390.  
  5391.   if (TREE_CODE (lhs) == COMPONENT_REF
  5392.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  5393.       || TREE_CODE (lhstype) == REAL_TYPE
  5394.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  5395.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  5396.  
  5397.   /* C++: The semantics of C++ differ from those of C when an
  5398.      assignment of an aggregate is desired.  Assignment in C++ is
  5399.      now defined as memberwise assignment of non-static members
  5400.      and base class objects.  This rule applies recursively
  5401.      until a member of a built-in type is found.
  5402.  
  5403.      Also, we cannot do a bit-wise copy of aggregates which
  5404.      contain virtual function table pointers.  Those
  5405.      pointer values must be preserved through the copy.
  5406.      However, this is handled in expand_expr, and not here.
  5407.      This is because much better code can be generated at
  5408.      that stage than this one.  */
  5409.   if (TREE_CODE (lhstype) == RECORD_TYPE
  5410.       && TYPE_LANG_SPECIFIC (lhstype)
  5411.       && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
  5412.     {
  5413.       register tree elt;
  5414.       int i;
  5415.  
  5416.       /* Perform operation on object.  */
  5417.       if (modifycode == INIT_EXPR && TYPE_HAS_INIT_REF (lhstype))
  5418.     {
  5419.       result = build_method_call (lhs, constructor_name_full (lhstype),
  5420.                       build_tree_list (NULL_TREE, rhs),
  5421.                       basetype_path, LOOKUP_NORMAL);
  5422.       return build_indirect_ref (result, NULL_PTR);
  5423.     }
  5424.       else if (modifycode == NOP_EXPR)
  5425.     {
  5426.       /* `operator=' is not an inheritable operator; see 13.4.3.  */
  5427.       if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_HAS_ASSIGNMENT (lhstype))
  5428.         {
  5429.           result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  5430.                        lhs, rhs, make_node (NOP_EXPR));
  5431.           if (result == NULL_TREE)
  5432.         return error_mark_node;
  5433.           return result;
  5434.         }
  5435.     }
  5436.  
  5437.       if (TYPE_USES_VIRTUAL_BASECLASSES (lhstype)
  5438.       || (modifycode == NOP_EXPR && TYPE_GETS_ASSIGNMENT (lhstype))
  5439.       || (modifycode == INIT_EXPR && TYPE_GETS_INIT_REF (lhstype)))
  5440.     {
  5441.       tree binfos = BINFO_BASETYPES (TYPE_BINFO (lhstype));
  5442.       result = NULL_TREE;
  5443.  
  5444.       if (binfos != NULL_TREE)
  5445.         /* Perform operation on each member, depth-first, left-right.  */
  5446.         for (i = 0; i <= TREE_VEC_LENGTH (binfos)-1; i++)
  5447.           {
  5448.         tree base_binfo = TREE_VEC_ELT (binfos, i);
  5449.         tree base_lhs, base_rhs;
  5450.         tree new_result;
  5451.  
  5452.         /* Assignments from virtual baseclasses handled elsewhere.  */
  5453.         if (TREE_VIA_VIRTUAL (base_binfo))
  5454.           continue;
  5455.  
  5456.         base_lhs = get_base_ref (lhstype, i, lhs);
  5457.         base_rhs = get_base_ref (lhstype, i, newrhs);
  5458.  
  5459.         BINFO_INHERITANCE_CHAIN (base_binfo) = basetype_path;
  5460.         new_result
  5461.           = build_modify_expr_1 (base_lhs, modifycode, base_rhs,
  5462.                      base_binfo);
  5463.  
  5464.         /* We either get back a compound stmt, or a simple one.  */
  5465.         if (new_result && TREE_CODE (new_result) == TREE_LIST)
  5466.           new_result = build_compound_expr (new_result);
  5467.         result = tree_cons (NULL_TREE, new_result, result);
  5468.           }
  5469.  
  5470.       for (elt = TYPE_FIELDS (lhstype); elt; elt = TREE_CHAIN (elt))
  5471.         {
  5472.           tree vbases = NULL_TREE;
  5473.           tree elt_lhs, elt_rhs;
  5474.  
  5475.           if (TREE_CODE (elt) != FIELD_DECL)
  5476.         continue;
  5477.           if (DECL_NAME (elt)
  5478.           && (VFIELD_NAME_P (DECL_NAME (elt))
  5479.               || VBASE_NAME_P (DECL_NAME (elt))))
  5480.         continue;
  5481.  
  5482.           if (TREE_READONLY (elt)
  5483.           || TREE_CODE (TREE_TYPE (elt)) == REFERENCE_TYPE)
  5484.         {
  5485.           cp_error ("cannot generate default `%T::operator ='",
  5486.                 lhstype);
  5487.           if (TREE_CODE (TREE_TYPE (elt)) == REFERENCE_TYPE)
  5488.             cp_error_at ("because member `%#D' is a reference", elt);
  5489.           else
  5490.             cp_error_at ("because member `%#D' is const", elt);
  5491.  
  5492.           return error_mark_node;
  5493.         }
  5494.  
  5495.           if (IS_AGGR_TYPE (TREE_TYPE (elt))
  5496.           && TYPE_LANG_SPECIFIC (TREE_TYPE (elt)))
  5497.         vbases = CLASSTYPE_VBASECLASSES (TREE_TYPE (elt));
  5498.  
  5499.           elt_lhs = build (COMPONENT_REF, TREE_TYPE (elt), lhs, elt);
  5500.           elt_rhs = build (COMPONENT_REF, TREE_TYPE (elt), newrhs, elt);
  5501.           /* It is not always safe to go through `build_modify_expr_1'
  5502.          when performing element-wise copying.  This is because
  5503.          an element may be of ARRAY_TYPE, which will not
  5504.          be properly copied as a naked element.  */
  5505.           if (TREE_CODE (TREE_TYPE (elt)) == RECORD_TYPE
  5506.           && TYPE_LANG_SPECIFIC (TREE_TYPE (elt)))
  5507.         basetype_path = TYPE_BINFO (TREE_TYPE (elt));
  5508.  
  5509.           while (vbases)
  5510.         {
  5511.           tree elt_lhs_addr = build_unary_op (ADDR_EXPR, elt_lhs, 0);
  5512.           tree elt_rhs_addr = build_unary_op (ADDR_EXPR, elt_rhs, 0);
  5513.  
  5514.           elt_lhs_addr = convert_pointer_to (vbases, elt_lhs_addr);
  5515.           elt_rhs_addr = convert_pointer_to (vbases, elt_rhs_addr);
  5516.           result
  5517.             = tree_cons (NULL_TREE,
  5518.                  build_modify_expr_1
  5519.                  (build_indirect_ref (elt_lhs_addr, NULL_PTR),
  5520.                   modifycode,
  5521.                   build_indirect_ref (elt_rhs_addr, NULL_PTR),
  5522.                   basetype_path),
  5523.                  result);
  5524.           if (TREE_VALUE (result) == error_mark_node)
  5525.             return error_mark_node;
  5526.           vbases = TREE_CHAIN (vbases);
  5527.         }
  5528.           elt_lhs = build_modify_expr_1 (elt_lhs, modifycode, elt_rhs,
  5529.                          basetype_path);
  5530.           result = tree_cons (NULL_TREE, elt_lhs, result);
  5531.         }
  5532.  
  5533.       if (result)
  5534.         return build_compound_expr (result);
  5535.       /* No fields to move.  */
  5536.       return integer_zero_node;
  5537.     }
  5538.       else
  5539.     {
  5540.       result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  5541.               void_type_node, lhs, rhs);
  5542.       TREE_SIDE_EFFECTS (result) = 1;
  5543.       return result;
  5544.     }
  5545.     }
  5546.  
  5547.   result = build_modify_expr (lhs, modifycode, newrhs);
  5548.   /* ARRAY_TYPEs cannot be converted to anything meaningful,
  5549.      and leaving it there screws up `build_compound_expr' when
  5550.      it tries to defaultly convert everything.  */
  5551.   if (TREE_CODE (TREE_TYPE (result)) == ARRAY_TYPE)
  5552.     TREE_TYPE (result) = void_type_node;
  5553.   return result;
  5554. }
  5555. #endif
  5556.  
  5557. /* Taken from expr.c:
  5558.    Subroutine of expand_expr:
  5559.    record the non-copied parts (LIST) of an expr (LHS), and return a list
  5560.    which specifies the initial values of these parts.  */
  5561.  
  5562. static tree
  5563. init_noncopied_parts (lhs, list)
  5564.      tree lhs;
  5565.      tree list;
  5566. {
  5567.   tree tail;
  5568.   tree parts = 0;
  5569.  
  5570.   for (tail = list; tail; tail = TREE_CHAIN (tail))
  5571.     if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
  5572.       parts = chainon (parts, init_noncopied_parts (lhs, TREE_VALUE (tail)));
  5573.     else
  5574.       {
  5575.     tree part = TREE_VALUE (tail);
  5576.     tree part_type = TREE_TYPE (part);
  5577.     tree to_be_initialized = build (COMPONENT_REF, part_type, lhs, part);
  5578.     parts = tree_cons (TREE_PURPOSE (tail), to_be_initialized, parts);
  5579.       }
  5580.   return parts;
  5581. }
  5582.  
  5583. tree
  5584. expand_target_expr (t)
  5585.      tree t;
  5586. {
  5587.   tree xval = make_node (RTL_EXPR);
  5588.   rtx rtxval;
  5589.  
  5590.   do_pending_stack_adjust ();
  5591.   start_sequence_for_rtl_expr (xval);
  5592.   emit_note (0, -1);
  5593.   rtxval = expand_expr (t, NULL, VOIDmode, 0);
  5594.   do_pending_stack_adjust ();
  5595.   TREE_SIDE_EFFECTS (xval) = 1;
  5596.   RTL_EXPR_SEQUENCE (xval) = get_insns ();
  5597.   end_sequence ();
  5598.   RTL_EXPR_RTL (xval) = rtxval;
  5599.   TREE_TYPE (xval) = TREE_TYPE (t);
  5600.   return xval;
  5601. }
  5602.  
  5603. /* Build an assignment expression of lvalue LHS from value RHS.
  5604.    MODIFYCODE is the code for a binary operator that we use
  5605.    to combine the old value of LHS with RHS to get the new value.
  5606.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.
  5607.  
  5608.    C++: If MODIFYCODE is INIT_EXPR, then leave references unbashed.
  5609. */
  5610. tree
  5611. build_modify_expr (lhs, modifycode, rhs)
  5612.      tree lhs;
  5613.      enum tree_code modifycode;
  5614.      tree rhs;
  5615. {
  5616.   register tree result;
  5617.   tree newrhs = rhs;
  5618.   tree lhstype = TREE_TYPE (lhs);
  5619.   tree olhstype = lhstype;
  5620.   tree olhs = lhs;
  5621.  
  5622.   /* Avoid duplicate error messages from operands that had errors.  */
  5623.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  5624.     return error_mark_node;
  5625.  
  5626.   /* Types that aren't fully specified cannot be used in assignments.  */
  5627.   lhs = require_complete_type (lhs);
  5628.  
  5629.   /* Decide early if we are going to protect RHS from GC
  5630.      before assigning it to LHS.  */
  5631.   if (type_needs_gc_entry (TREE_TYPE (rhs))
  5632.       && ! value_safe_from_gc (lhs, rhs))
  5633.     rhs = protect_value_from_gc (lhs, rhs);
  5634.  
  5635.   newrhs = rhs;
  5636.  
  5637.   /* Handle assignment to signature pointers/refs.  */
  5638.  
  5639.   if (TYPE_LANG_SPECIFIC (lhstype) &&
  5640.       (IS_SIGNATURE_POINTER (lhstype) || IS_SIGNATURE_REFERENCE (lhstype)))
  5641.     {
  5642.       return build_signature_pointer_constructor (lhs, rhs);
  5643.     }
  5644.  
  5645.   /* Handle control structure constructs used as "lvalues".  */
  5646.  
  5647.   switch (TREE_CODE (lhs))
  5648.     {
  5649.       /* Handle --foo = 5; as these are valid constructs in C++ */
  5650.     case PREDECREMENT_EXPR:
  5651.     case PREINCREMENT_EXPR:
  5652.       if (TREE_SIDE_EFFECTS (TREE_OPERAND (lhs, 0)))
  5653.     lhs = build (TREE_CODE (lhs), TREE_TYPE (lhs),
  5654.              stabilize_reference (TREE_OPERAND (lhs, 0)));
  5655.       return build (COMPOUND_EXPR, lhstype,
  5656.             lhs,
  5657.             build_modify_expr (TREE_OPERAND (lhs, 0),
  5658.                        modifycode, rhs));
  5659.  
  5660.       /* Handle (a, b) used as an "lvalue".  */
  5661.     case COMPOUND_EXPR:
  5662.       newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
  5663.                   modifycode, rhs);
  5664.       if (TREE_CODE (newrhs) == ERROR_MARK)
  5665.     return error_mark_node;
  5666.       return build (COMPOUND_EXPR, lhstype,
  5667.             TREE_OPERAND (lhs, 0), newrhs);
  5668.  
  5669.     case MODIFY_EXPR:
  5670.       newrhs = build_modify_expr (TREE_OPERAND (lhs, 0), modifycode, rhs);
  5671.       if (TREE_CODE (newrhs) == ERROR_MARK)
  5672.     return error_mark_node;
  5673.       return build (COMPOUND_EXPR, lhstype, lhs, newrhs);
  5674.  
  5675.       /* Handle (a ? b : c) used as an "lvalue".  */
  5676.     case COND_EXPR:
  5677.       rhs = save_expr (rhs);
  5678.       {
  5679.     /* Produce (a ? (b = rhs) : (c = rhs))
  5680.        except that the RHS goes through a save-expr
  5681.        so the code to compute it is only emitted once.  */
  5682.     tree cond
  5683.       = build_conditional_expr (TREE_OPERAND (lhs, 0),
  5684.                     build_modify_expr (convert (TREE_TYPE (lhs), TREE_OPERAND (lhs, 1)),
  5685.                                modifycode, rhs),
  5686.                     build_modify_expr (convert (TREE_TYPE (lhs), TREE_OPERAND (lhs, 2)),
  5687.                                modifycode, rhs));
  5688.     if (TREE_CODE (cond) == ERROR_MARK)
  5689.       return cond;
  5690.     /* Make sure the code to compute the rhs comes out
  5691.        before the split.  */
  5692.     return build (COMPOUND_EXPR, TREE_TYPE (lhs),
  5693.               /* Case to void to suppress warning
  5694.              from warn_if_unused_value.  */
  5695.               convert (void_type_node, rhs), cond);
  5696.       }
  5697.     }
  5698.  
  5699.   if (TREE_CODE (lhs) == OFFSET_REF)
  5700.     {
  5701.       if (TREE_OPERAND (lhs, 0) == NULL_TREE)
  5702.     {
  5703.       /* Static class member?  */
  5704.       tree member = TREE_OPERAND (lhs, 1);
  5705.       if (TREE_CODE (member) == VAR_DECL)
  5706.         lhs = member;
  5707.       else
  5708.         {
  5709.           compiler_error ("invalid static class member");
  5710.           return error_mark_node;
  5711.         }
  5712.     }
  5713.       else
  5714.     lhs = resolve_offset_ref (lhs);
  5715.  
  5716.       olhstype = lhstype = TREE_TYPE (lhs);
  5717.     }
  5718.  
  5719.   if (TREE_CODE (lhstype) == REFERENCE_TYPE
  5720.       && modifycode != INIT_EXPR)
  5721.     {
  5722.       lhs = convert_from_reference (lhs);
  5723.       olhstype = lhstype = TREE_TYPE (lhs);
  5724.     }
  5725.  
  5726.   /* If a binary op has been requested, combine the old LHS value with the RHS
  5727.      producing the value we should actually store into the LHS.  */
  5728.  
  5729.   if (modifycode == INIT_EXPR)
  5730.     {
  5731.       if (! IS_AGGR_TYPE (lhstype))
  5732.     /* Do the default thing */;
  5733.       else if (! TYPE_HAS_CONSTRUCTOR (lhstype))
  5734.     {
  5735.       cp_error ("`%T' has no constructors", lhstype);
  5736.       return error_mark_node;
  5737.     }
  5738.       else if (TYPE_HAS_TRIVIAL_INIT_REF (lhstype)
  5739.            && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
  5740.     /* Do the default thing */;
  5741.       else
  5742.     {
  5743.       result = build_method_call (lhs, constructor_name_full (lhstype),
  5744.                       build_tree_list (NULL_TREE, rhs),
  5745.                       NULL_TREE, LOOKUP_NORMAL);
  5746.       if (result == NULL_TREE)
  5747.         return error_mark_node;
  5748.       return result;
  5749.     }
  5750.     }
  5751.   else if (modifycode == NOP_EXPR)
  5752.     {
  5753. #if 1
  5754.       /* `operator=' is not an inheritable operator.  */
  5755.       if (! IS_AGGR_TYPE (lhstype))
  5756.     /* Do the default thing */;
  5757.       else if (! TYPE_HAS_ASSIGNMENT (lhstype))
  5758.     {
  5759.       cp_error ("`%T' does not define operator=", lhstype);
  5760.       return error_mark_node;
  5761.     }
  5762.       else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (lhstype)
  5763.            && TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs)))
  5764.     {
  5765.       if (warn_synth)
  5766.         /* If we care about this, do overload resolution.  */
  5767.         build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  5768.                 lhs, rhs, make_node (NOP_EXPR));
  5769.  
  5770.       /* Do the default thing */;
  5771.     }
  5772.       else
  5773.     {
  5774.       result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  5775.                    lhs, rhs, make_node (NOP_EXPR));
  5776.       if (result == NULL_TREE)
  5777.         return error_mark_node;
  5778.       return result;
  5779.     }
  5780. #else
  5781.       /* Treat `operator=' as an inheritable operator.  */
  5782.       if (TYPE_LANG_SPECIFIC (lhstype) && TYPE_GETS_ASSIGNMENT (lhstype))
  5783.     {
  5784.       tree orig_lhstype = lhstype;
  5785.       while (! TYPE_HAS_ASSIGNMENT (lhstype))
  5786.         {
  5787.           int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (lhstype);
  5788.           tree basetype = NULL_TREE;
  5789.           for (i = 0; i < n_baseclasses; i++)
  5790.         if (TYPE_GETS_ASSIGNMENT (TYPE_BINFO_BASETYPE (lhstype, i)))
  5791.           {
  5792.             if (basetype != NULL_TREE)
  5793.               {
  5794.             message_2_types (error, "base classes `%s' and `%s' both have operator ='",
  5795.                      basetype,
  5796.                      TYPE_BINFO_BASETYPE (lhstype, i));
  5797.             return error_mark_node;
  5798.               }
  5799.             basetype = TYPE_BINFO_BASETYPE (lhstype, i);
  5800.           }
  5801.           lhstype = basetype;
  5802.         }
  5803.       if (orig_lhstype != lhstype)
  5804.         {
  5805.           lhs = build_indirect_ref (convert_pointer_to (lhstype,
  5806.                                 build_unary_op (ADDR_EXPR, lhs, 0)), NULL_PTR);
  5807.           if (lhs == error_mark_node)
  5808.         {
  5809.           cp_error ("conversion to private basetype `%T'", lhstype);
  5810.           return error_mark_node;
  5811.         }
  5812.         }
  5813.       result = build_opfncall (MODIFY_EXPR, LOOKUP_NORMAL,
  5814.                    lhs, rhs, make_node (NOP_EXPR));
  5815.       if (result == NULL_TREE)
  5816.         return error_mark_node;
  5817.       return result;
  5818.     }
  5819. #endif
  5820.       lhstype = olhstype;
  5821.     }
  5822.   else if (PROMOTES_TO_AGGR_TYPE (lhstype, REFERENCE_TYPE))
  5823.     {
  5824.       /* This case must convert to some sort of lvalue that
  5825.      can participate in an op= operation.  */
  5826.       tree lhs_tmp = lhs;
  5827.       tree rhs_tmp = rhs;
  5828.       if (build_default_binary_type_conversion (modifycode, &lhs_tmp, &rhs_tmp))
  5829.     {
  5830.       lhs = stabilize_reference (lhs_tmp);
  5831.       /* Forget is was ever anything else.  */
  5832.       olhstype = lhstype = TREE_TYPE (lhs);
  5833.       newrhs = build_binary_op (modifycode, lhs, rhs_tmp, 1);
  5834.     }
  5835.       else
  5836.     {
  5837.       cp_error ("no match for `%O(%#T, %#T)'", modifycode,
  5838.             TREE_TYPE (lhs), TREE_TYPE (rhs));
  5839.       return error_mark_node;
  5840.     }
  5841.     }
  5842.   else
  5843.     {
  5844.       lhs = stabilize_reference (lhs);
  5845.       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
  5846.     }
  5847.  
  5848.   /* Handle a cast used as an "lvalue".
  5849.      We have already performed any binary operator using the value as cast.
  5850.      Now convert the result to the cast type of the lhs,
  5851.      and then true type of the lhs and store it there;
  5852.      then convert result back to the cast type to be the value
  5853.      of the assignment.  */
  5854.  
  5855.   switch (TREE_CODE (lhs))
  5856.     {
  5857.     case NOP_EXPR:
  5858.     case CONVERT_EXPR:
  5859.     case FLOAT_EXPR:
  5860.     case FIX_TRUNC_EXPR:
  5861.     case FIX_FLOOR_EXPR:
  5862.     case FIX_ROUND_EXPR:
  5863.     case FIX_CEIL_EXPR:
  5864.       if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  5865.       || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE
  5866.       || TREE_CODE (TREE_TYPE (newrhs)) == METHOD_TYPE
  5867.       || TREE_CODE (TREE_TYPE (newrhs)) == OFFSET_TYPE)
  5868.     newrhs = default_conversion (newrhs);
  5869.       {
  5870.     tree inner_lhs = TREE_OPERAND (lhs, 0);
  5871.     tree result;
  5872.     if (! lvalue_p (lhs) && pedantic)
  5873.       pedwarn ("cast to non-reference type used as lvalue");
  5874.  
  5875.     result = build_modify_expr (inner_lhs, NOP_EXPR,
  5876.                     convert (TREE_TYPE (inner_lhs),
  5877.                          convert (lhstype, newrhs)));
  5878.     if (TREE_CODE (result) == ERROR_MARK)
  5879.       return result;
  5880.     return convert (TREE_TYPE (lhs), result);
  5881.       }
  5882.     }
  5883.  
  5884.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  5885.      Reject anything strange now.  */
  5886.  
  5887.   if (!lvalue_or_else (lhs, "assignment"))
  5888.     return error_mark_node;
  5889.  
  5890.   GNU_xref_assign (lhs);
  5891.  
  5892.   /* Warn about storing in something that is `const'.  */
  5893.   /* For C++, don't warn if this is initialization.  */
  5894.   if (modifycode != INIT_EXPR
  5895.       /* For assignment to `const' signature pointer/reference fields,
  5896.      don't warn either, we already printed a better message before.  */
  5897.       && ! (TREE_CODE (lhs) == COMPONENT_REF
  5898.         && (IS_SIGNATURE_POINTER (TREE_TYPE (TREE_OPERAND (lhs, 0)))
  5899.         || IS_SIGNATURE_REFERENCE (TREE_TYPE (TREE_OPERAND (lhs, 0)))))
  5900.       && (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
  5901.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  5902.            || TREE_CODE (lhstype) == UNION_TYPE)
  5903.           && C_TYPE_FIELDS_READONLY (lhstype))
  5904.       || (TREE_CODE (lhstype) == REFERENCE_TYPE
  5905.           && TYPE_READONLY (TREE_TYPE (lhstype)))))
  5906.     readonly_error (lhs, "assignment", 0);
  5907.  
  5908.   /* If storing into a structure or union member,
  5909.      it has probably been given type `int'.
  5910.      Compute the type that would go with
  5911.      the actual amount of storage the member occupies.  */
  5912.  
  5913.   if (TREE_CODE (lhs) == COMPONENT_REF
  5914.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  5915.       || TREE_CODE (lhstype) == REAL_TYPE
  5916.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  5917.     {
  5918.       lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  5919.  
  5920.       /* If storing in a field that is in actuality a short or narrower
  5921.      than one, we must store in the field in its actual type.  */
  5922.  
  5923.       if (lhstype != TREE_TYPE (lhs))
  5924.     {
  5925.       lhs = copy_node (lhs);
  5926.       TREE_TYPE (lhs) = lhstype;
  5927.     }
  5928.     }
  5929.  
  5930.   /* check to see if there is an assignment to `this' */
  5931.   if (lhs == current_class_decl)
  5932.     {
  5933.       if (flag_this_is_variable > 0
  5934.       && DECL_NAME (current_function_decl) != NULL_TREE
  5935.       && (DECL_NAME (current_function_decl)
  5936.           != constructor_name (current_class_type)))
  5937.     warning ("assignment to `this' not in constructor or destructor");
  5938.       current_function_just_assigned_this = 1;
  5939.     }
  5940.  
  5941.   /* The TREE_TYPE of RHS may be TYPE_UNKNOWN.  This can happen
  5942.      when the type of RHS is not yet known, i.e. its type
  5943.      is inherited from LHS.  */
  5944.   rhs = require_instantiated_type (lhstype, newrhs, error_mark_node);
  5945.   if (rhs == error_mark_node)
  5946.     return error_mark_node;
  5947.   newrhs = rhs;
  5948.  
  5949.   if (modifycode != INIT_EXPR)
  5950.     {
  5951.       /* Make modifycode now either a NOP_EXPR or an INIT_EXPR.  */
  5952.       modifycode = NOP_EXPR;
  5953.       /* Reference-bashing */
  5954.       if (TREE_CODE (lhstype) == REFERENCE_TYPE)
  5955.     {
  5956.       tree tmp = convert_from_reference (lhs);
  5957.       lhstype = TREE_TYPE (tmp);
  5958.       if (TYPE_SIZE (lhstype) == 0)
  5959.         {
  5960.           incomplete_type_error (lhs, lhstype);
  5961.           return error_mark_node;
  5962.         }
  5963.       lhs = tmp;
  5964.       olhstype = lhstype;
  5965.     }
  5966.       if (TREE_CODE (TREE_TYPE (newrhs)) == REFERENCE_TYPE)
  5967.     {
  5968.       tree tmp = convert_from_reference (newrhs);
  5969.       if (TYPE_SIZE (TREE_TYPE (tmp)) == 0)
  5970.         {
  5971.           incomplete_type_error (newrhs, TREE_TYPE (tmp));
  5972.           return error_mark_node;
  5973.         }
  5974.       newrhs = tmp;
  5975.     }
  5976.     }
  5977.  
  5978.   if (TREE_SIDE_EFFECTS (lhs))
  5979.     lhs = stabilize_reference (lhs);
  5980.   if (TREE_SIDE_EFFECTS (newrhs))
  5981.     newrhs = stabilize_reference (newrhs);
  5982.  
  5983. #if 0
  5984.   /* This is now done by generating X(X&) and operator=(X&). */
  5985.   /* C++: The semantics of C++ differ from those of C when an
  5986.      assignment of an aggregate is desired.  Assignment in C++ is
  5987.      now defined as memberwise assignment of non-static members
  5988.      and base class objects.  This rule applies recursively
  5989.      until a member of a built-in type is found.
  5990.  
  5991.      Also, we cannot do a bit-wise copy of aggregates which
  5992.      contain virtual function table pointers.  Those
  5993.      pointer values must be preserved through the copy.
  5994.      However, this is handled in expand_expr, and not here.
  5995.      This is because much better code can be generated at
  5996.      that stage than this one.  */
  5997.   if (TREE_CODE (lhstype) == RECORD_TYPE
  5998.       && ! TYPE_PTRMEMFUNC_P (lhstype)
  5999.       && (TYPE_MAIN_VARIANT (lhstype) == TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))
  6000.       || (TREE_CODE (TREE_TYPE (newrhs)) == RECORD_TYPE
  6001.           && UNIQUELY_DERIVED_FROM_P (lhstype, TREE_TYPE (newrhs)))))
  6002.     {
  6003.       tree vbases = CLASSTYPE_VBASECLASSES (lhstype);
  6004.       tree lhs_addr = build_unary_op (ADDR_EXPR, lhs, 0);
  6005.       tree rhs_addr;
  6006.       
  6007.       /* Memberwise assignment would cause NEWRHS to be
  6008.      evaluated for every member that gets assigned.
  6009.      By wrapping side-effecting exprs in a SAVE_EXPR,
  6010.      NEWRHS will only be evaluated once.  */
  6011.       if (IS_AGGR_TYPE (TREE_TYPE (newrhs))
  6012.       && TREE_SIDE_EFFECTS (newrhs)
  6013.       /* This are things we don't have to save.  */
  6014.       && TREE_CODE (newrhs) != COND_EXPR
  6015.       && TREE_CODE (newrhs) != TARGET_EXPR
  6016.       && TREE_CODE (newrhs) != WITH_CLEANUP_EXPR)
  6017.     /* Call `break_out_cleanups' on NEWRHS in case there are cleanups.
  6018.        If NEWRHS is a CALL_EXPR that needs a cleanup, failure to do so
  6019.        will result in expand_expr expanding the call without knowing
  6020.        that it should run the cleanup.  */
  6021.     newrhs = save_expr (break_out_cleanups (newrhs));
  6022.       
  6023.       if (TREE_CODE (newrhs) == COND_EXPR)
  6024.     rhs_addr = rationalize_conditional_expr (ADDR_EXPR, newrhs);
  6025.       else
  6026.     rhs_addr = build_unary_op (ADDR_EXPR, newrhs, 0);
  6027.  
  6028.       result = tree_cons (NULL_TREE,
  6029.               convert (build_reference_type (lhstype), lhs),
  6030.               NULL_TREE);
  6031.  
  6032.       if (! comptypes (TREE_TYPE (lhs_addr), TREE_TYPE (rhs_addr), 1))
  6033.     rhs_addr = convert_pointer_to (TREE_TYPE (TREE_TYPE (lhs_addr)), rhs_addr);
  6034.       {
  6035.     tree noncopied_parts = NULL_TREE;
  6036.  
  6037.     if (TYPE_NONCOPIED_PARTS (lhstype) != 0)
  6038.       noncopied_parts = init_noncopied_parts (lhs,
  6039.                           TYPE_NONCOPIED_PARTS (lhstype));
  6040.     while (noncopied_parts != 0)
  6041.       {
  6042.         result = tree_cons (NULL_TREE,
  6043.                 build_modify_expr (convert (ptr_type_node, TREE_VALUE (noncopied_parts)),
  6044.                            NOP_EXPR,
  6045.                            TREE_PURPOSE (noncopied_parts)),
  6046.                 result);
  6047.         noncopied_parts = TREE_CHAIN (noncopied_parts);
  6048.       }
  6049.       }
  6050.       /* Once we have our hands on an address, we must change NEWRHS
  6051.      to work from there.  Otherwise we can get multiple evaluations
  6052.      of NEWRHS.  */
  6053.       if (TREE_CODE (newrhs) != SAVE_EXPR)
  6054.     newrhs = build_indirect_ref (rhs_addr, NULL_PTR);
  6055.  
  6056.       while (vbases)
  6057.     {
  6058.       tree elt_lhs = convert_pointer_to (vbases, lhs_addr);
  6059.       tree elt_rhs = convert_pointer_to (vbases, rhs_addr);
  6060.       result
  6061.         = tree_cons (NULL_TREE,
  6062.              build_modify_expr_1 (build_indirect_ref (elt_lhs, NULL_PTR),
  6063.                           modifycode,
  6064.                           build_indirect_ref (elt_rhs, NULL_PTR),
  6065.                           TYPE_BINFO (lhstype)),
  6066.              result);
  6067.       if (TREE_VALUE (result) == error_mark_node)
  6068.         return error_mark_node;
  6069.       vbases = TREE_CHAIN (vbases);
  6070.     }
  6071.       result = tree_cons (NULL_TREE,
  6072.               build_modify_expr_1 (lhs,
  6073.                            modifycode,
  6074.                            newrhs,
  6075.                            TYPE_BINFO (lhstype)),
  6076.               result);
  6077.       return build_compound_expr (result);
  6078.     }
  6079. #endif
  6080.  
  6081.   /* Convert new value to destination type.  */
  6082.  
  6083.   if (TREE_CODE (lhstype) == ARRAY_TYPE)
  6084.     {
  6085.       int from_array;
  6086.       
  6087.       if (! comptypes (lhstype, TREE_TYPE (rhs), 0))
  6088.     {
  6089.       cp_error ("incompatible types in assignment of `%T' to `%T'",
  6090.             TREE_TYPE (rhs), lhstype);
  6091.       return error_mark_node;
  6092.     }
  6093.  
  6094.       /* Allow array assignment in compiler-generated code.  */
  6095.       if (pedantic && ! DECL_ARTIFICIAL (current_function_decl))
  6096.     pedwarn ("ANSI C++ forbids assignment of arrays");
  6097.  
  6098.       /* Have to wrap this in RTL_EXPR for two cases:
  6099.      in base or member initialization and if we
  6100.      are a branch of a ?: operator.  Since we
  6101.      can't easily know the latter, just do it always.  */
  6102.  
  6103.       result = make_node (RTL_EXPR);
  6104.  
  6105.       TREE_TYPE (result) = void_type_node;
  6106.       do_pending_stack_adjust ();
  6107.       start_sequence_for_rtl_expr (result);
  6108.  
  6109.       /* As a matter of principle, `start_sequence' should do this.  */
  6110.       emit_note (0, -1);
  6111.  
  6112.       from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  6113.                ? 1 + (modifycode != INIT_EXPR): 0;
  6114.       expand_vec_init (lhs, lhs, array_type_nelts (lhstype), newrhs,
  6115.                from_array);
  6116.  
  6117.       do_pending_stack_adjust ();
  6118.  
  6119.       TREE_SIDE_EFFECTS (result) = 1;
  6120.       RTL_EXPR_SEQUENCE (result) = get_insns ();
  6121.       RTL_EXPR_RTL (result) = const0_rtx;
  6122.       end_sequence ();
  6123.       return result;
  6124.     }
  6125.  
  6126.   if (modifycode == INIT_EXPR)
  6127.     {
  6128.       newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL,
  6129.                        "assignment", NULL_TREE, 0);
  6130.       if (lhs == DECL_RESULT (current_function_decl))
  6131.     {
  6132.       if (DECL_INITIAL (lhs))
  6133.         warning ("return value from function receives multiple initializations");
  6134.       DECL_INITIAL (lhs) = newrhs;
  6135.     }
  6136.     }
  6137.   else
  6138.     {
  6139. #if 0
  6140.       if (IS_AGGR_TYPE (lhstype))
  6141.     {
  6142.       if (result = build_opfncall (MODIFY_EXPR,
  6143.                        LOOKUP_NORMAL, lhs, newrhs,
  6144.                        make_node (NOP_EXPR)))
  6145.         return result;
  6146.     }
  6147. #endif
  6148.       /* Avoid warnings on enum bit fields. */
  6149.       if (TREE_CODE (olhstype) == ENUMERAL_TYPE
  6150.       && TREE_CODE (lhstype) == INTEGER_TYPE)
  6151.     {
  6152.       newrhs = convert_for_assignment (olhstype, newrhs, "assignment",
  6153.                        NULL_TREE, 0);
  6154.       newrhs = convert_force (lhstype, newrhs, 0);
  6155.     }
  6156.       else
  6157.     newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
  6158.                      NULL_TREE, 0);
  6159.       if (TREE_CODE (newrhs) == CALL_EXPR
  6160.       && TYPE_NEEDS_CONSTRUCTING (lhstype))
  6161.     newrhs = build_cplus_new (lhstype, newrhs, 0);
  6162.  
  6163.       /* Can't initialize directly from a TARGET_EXPR, since that would
  6164.      cause the lhs to be constructed twice, and possibly result in
  6165.      accidental self-initialization.  So we force the TARGET_EXPR to be
  6166.      expanded.  expand_expr should really do this by itself.  */
  6167.       if (TREE_CODE (newrhs) == TARGET_EXPR)
  6168.     newrhs = expand_target_expr (newrhs);
  6169.     }
  6170.  
  6171.   if (TREE_CODE (newrhs) == ERROR_MARK)
  6172.     return error_mark_node;
  6173.  
  6174.   if (TREE_CODE (newrhs) == COND_EXPR)
  6175.     {
  6176.       tree lhs1;
  6177.       tree cond = TREE_OPERAND (newrhs, 0);
  6178.  
  6179.       if (TREE_SIDE_EFFECTS (lhs))
  6180.     cond = build_compound_expr (tree_cons
  6181.                     (NULL_TREE, lhs,
  6182.                      build_tree_list (NULL_TREE, cond)));
  6183.  
  6184.       /* Cannot have two identical lhs on this one tree (result) as preexpand
  6185.      calls will rip them out and fill in RTL for them, but when the
  6186.      rtl is generated, the calls will only be in the first side of the
  6187.      condition, not on both, or before the conditional jump! (mrs) */
  6188.       lhs1 = break_out_calls (lhs);
  6189.  
  6190.       if (lhs == lhs1)
  6191.     /* If there's no change, the COND_EXPR behaves like any other rhs.  */
  6192.     result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  6193.             lhstype, lhs, newrhs);
  6194.       else
  6195.     {
  6196.       tree result_type = TREE_TYPE (newrhs);
  6197.       /* We have to convert each arm to the proper type because the
  6198.          types may have been munged by constant folding.  */
  6199.       result
  6200.         = build (COND_EXPR, result_type, cond,
  6201.              build_modify_expr (lhs, modifycode,
  6202.                     convert (result_type,
  6203.                          TREE_OPERAND (newrhs, 1))),
  6204.              build_modify_expr (lhs1, modifycode,
  6205.                     convert (result_type,
  6206.                          TREE_OPERAND (newrhs, 2))));
  6207.     }
  6208.     }
  6209.   else if (modifycode != INIT_EXPR && TREE_CODE (newrhs) == WITH_CLEANUP_EXPR)
  6210.     {
  6211.       tree cleanup = TREE_OPERAND (newrhs, 2);
  6212.       tree slot;
  6213.  
  6214.       /* Finish up by running cleanups and having the "value" of the lhs.  */
  6215.       tree exprlist = tree_cons (NULL_TREE, cleanup,
  6216.                  build_tree_list (NULL_TREE, lhs));
  6217.       newrhs = TREE_OPERAND (newrhs, 0);
  6218.       if (TREE_CODE (newrhs) == TARGET_EXPR)
  6219.       slot = TREE_OPERAND (newrhs, 0);
  6220.       else if (TREE_CODE (newrhs) == ADDR_EXPR)
  6221.     {
  6222.       /* Bad but valid.  */
  6223.       slot = newrhs;
  6224.       warning ("address taken of temporary object");
  6225.     }
  6226.       else
  6227.     my_friendly_abort (118);
  6228.  
  6229.       /* Copy the value computed in SLOT into LHS.  */
  6230.       exprlist = tree_cons (NULL_TREE,
  6231.                 build_modify_expr (lhs, modifycode, slot),
  6232.                 exprlist);
  6233.       /* Evaluate the expression that needs CLEANUP.  This will
  6234.      compute the value into SLOT.  */
  6235.       exprlist = tree_cons (NULL_TREE, newrhs, exprlist);
  6236.       result = convert (lhstype, build_compound_expr (exprlist));
  6237.     }
  6238.   else
  6239.     result = build (modifycode == NOP_EXPR ? MODIFY_EXPR : INIT_EXPR,
  6240.             lhstype, lhs, newrhs);
  6241.   TREE_SIDE_EFFECTS (result) = 1;
  6242.  
  6243.   /* If we got the LHS in a different type for storing in,
  6244.      convert the result back to the nominal type of LHS
  6245.      so that the value we return always has the same type
  6246.      as the LHS argument.  */
  6247.  
  6248.   if (olhstype == TREE_TYPE (result))
  6249.     return result;
  6250.   /* Avoid warnings converting integral types back into enums
  6251.      for enum bit fields. */
  6252.   if (TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
  6253.       && TREE_CODE (olhstype) == ENUMERAL_TYPE)
  6254.     {
  6255.       result = build (COMPOUND_EXPR, olhstype, result, olhs);
  6256.       TREE_NO_UNUSED_WARNING (result) = 1;
  6257.       return result;
  6258.     }
  6259.   return convert_for_assignment (olhstype, result, "assignment",
  6260.                  NULL_TREE, 0);
  6261. }
  6262.  
  6263.  
  6264. /* Return 0 if EXP is not a valid lvalue in this language
  6265.    even though `lvalue_or_else' would accept it.  */
  6266.  
  6267. int
  6268. language_lvalue_valid (exp)
  6269.      tree exp;
  6270. {
  6271.   return 1;
  6272. }
  6273.  
  6274. /* Get difference in deltas for different pointer to member function
  6275.    types.  Return integer_zero_node, if FROM cannot be converted to a
  6276.    TO type.  If FORCE is true, then allow reverse conversions as well.  */
  6277. static tree
  6278. get_delta_difference (from, to, force)
  6279.      tree from, to;
  6280.      int force;
  6281. {
  6282.   tree delta = integer_zero_node;
  6283.   tree binfo;
  6284.   
  6285.   if (to == from)
  6286.     return delta;
  6287.  
  6288.   /* Should get_base_distance here, so we can check if any thing along the
  6289.      path is virtual, and we need to make sure we stay
  6290.      inside the real binfos when going through virtual bases.
  6291.      Maybe we should replace virtual bases with
  6292.      binfo_member (...CLASSTYPE_VBASECLASSES...)...  (mrs) */
  6293.   binfo = get_binfo (from, to, 1);
  6294.   if (binfo == error_mark_node)
  6295.     {
  6296.       error ("   in pointer to member function conversion");
  6297.       return delta;
  6298.     }
  6299.   if (binfo == 0)
  6300.     {
  6301.       if (!force)
  6302.     {
  6303.       error_not_base_type (from, to);
  6304.       error ("   in pointer to member function conversion");
  6305.       return delta;
  6306.     }
  6307.       binfo = get_binfo (to, from, 1);
  6308.       if (binfo == error_mark_node)
  6309.     {
  6310.       error ("   in pointer to member function conversion");
  6311.       return delta;
  6312.     }
  6313.       if (binfo == 0)
  6314.     {
  6315.       error ("cannot convert pointer to member of type %T to unrelated pointer to member of type %T", from, to);
  6316.       return delta;
  6317.     }
  6318.       if (TREE_VIA_VIRTUAL (binfo))
  6319.     {
  6320.       warning ("pointer to member conversion to virtual base class will only work if you are very careful");
  6321.     }
  6322.       return build_binary_op (MINUS_EXPR,
  6323.                   integer_zero_node,
  6324.                   BINFO_OFFSET (binfo), 1);
  6325.     }
  6326.   if (TREE_VIA_VIRTUAL (binfo))
  6327.     {
  6328.       warning ("pointer to member conversion from virtual base class will only work if you are very careful");
  6329.     }
  6330.   return BINFO_OFFSET (binfo);
  6331. }
  6332.  
  6333. /* Build a constructor for a pointer to member function.  It can be
  6334.    used to initialize global variables, local variable, or used
  6335.    as a value in expressions.  TYPE is the POINTER to METHOD_TYPE we
  6336.    want to be.
  6337.  
  6338.    If FORCE is non-zero, then force this conversion, even if
  6339.    we would rather not do it.  Usually set when using an explicit
  6340.    cast.
  6341.  
  6342.    Return error_mark_node, if something goes wrong.  */
  6343.  
  6344. tree
  6345. build_ptrmemfunc (type, pfn, force)
  6346.      tree type, pfn;
  6347.      int force;
  6348. {
  6349.   tree index = integer_zero_node;
  6350.   tree delta = integer_zero_node;
  6351.   tree delta2 = integer_zero_node;
  6352.   tree vfield_offset;
  6353.   tree npfn;
  6354.   tree u;
  6355.  
  6356.   /* Handle multiple conversions of pointer to member functions. */
  6357.   if (TYPE_PTRMEMFUNC_P (TREE_TYPE (pfn)))
  6358.     {
  6359.       tree ndelta, ndelta2, nindex;
  6360.       /* Is is already the right type? */
  6361. #if 0
  6362.       /* Sorry, can't do this, the backend is too stupid. */
  6363.       if (TYPE_METHOD_BASETYPE (TREE_TYPE (type))
  6364.       == TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))))
  6365.     {
  6366.       if (type != TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))
  6367.         {
  6368.           npfn = build1 (NOP_EXPR, TYPE_GET_PTRMEMFUNC_TYPE (type), pfn);
  6369.           TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
  6370.         }
  6371.       return pfn;
  6372.     }
  6373. #else
  6374.       if (type == TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))
  6375.     return pfn;
  6376. #endif
  6377.  
  6378.       if (TREE_CODE (pfn) != CONSTRUCTOR)
  6379.     {
  6380.       tree e1, e2, e3;
  6381.       ndelta = convert (ptrdiff_type_node, build_component_ref (pfn, delta_identifier, 0, 0));
  6382.       ndelta2 = convert (ptrdiff_type_node, DELTA2_FROM_PTRMEMFUNC (pfn));
  6383.       index = build_component_ref (pfn, index_identifier, 0, 0);
  6384.       delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))),
  6385.                     TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
  6386.                     force);
  6387.       delta = build_binary_op (PLUS_EXPR, delta, ndelta, 1);
  6388.       delta2 = build_binary_op (PLUS_EXPR, ndelta2, delta2, 1);
  6389.       e1 = fold (build (GT_EXPR, boolean_type_node, index, integer_zero_node));
  6390.       
  6391.       u = build_nt (CONSTRUCTOR, 0, tree_cons (delta2_identifier, delta2, NULL_TREE));
  6392.       u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
  6393.                            tree_cons (NULL_TREE, index,
  6394.                                   tree_cons (NULL_TREE, u, NULL_TREE))));
  6395.       e2 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
  6396.  
  6397.       pfn = PFN_FROM_PTRMEMFUNC (pfn);
  6398.       npfn = build1 (NOP_EXPR, type, pfn);
  6399.       TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
  6400.  
  6401.       u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, npfn, NULL_TREE));
  6402.       u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
  6403.                            tree_cons (NULL_TREE, index,
  6404.                                   tree_cons (NULL_TREE, u, NULL_TREE))));
  6405.       e3 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
  6406.       return build_conditional_expr (e1, e2, e3);
  6407.     }
  6408.  
  6409.       ndelta = TREE_VALUE (CONSTRUCTOR_ELTS (pfn));
  6410.       nindex = TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn)));
  6411.       npfn = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (CONSTRUCTOR_ELTS (pfn))));
  6412.       npfn = TREE_VALUE (CONSTRUCTOR_ELTS (npfn));
  6413.       if (integer_zerop (nindex))
  6414.     pfn = integer_zero_node;
  6415.       else if (integer_zerop (fold (size_binop (PLUS_EXPR, nindex, integer_one_node))))
  6416.     {
  6417.       tree e3;
  6418.       delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn)))),
  6419.                     TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
  6420.                     force);
  6421.       delta = build_binary_op (PLUS_EXPR, delta, ndelta, 1);
  6422.       pfn = build1 (NOP_EXPR, type, npfn);
  6423.       TREE_CONSTANT (pfn) = TREE_CONSTANT (npfn);
  6424.  
  6425.       u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, pfn, NULL_TREE));
  6426.       u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
  6427.                            tree_cons (NULL_TREE, nindex,
  6428.                                   tree_cons (NULL_TREE, u, NULL_TREE))));
  6429.       e3 = digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
  6430.       return e3;
  6431.     }
  6432.       else
  6433.     {
  6434.       sorry ("value casting of variable nonnull pointer to member functions not supported");
  6435.       return error_mark_node;
  6436.     }
  6437.     }
  6438.  
  6439.   /* Handle null pointer to member function conversions. */
  6440.   if (integer_zerop (pfn))
  6441.     {
  6442.       pfn = build_c_cast (type, integer_zero_node, 0);
  6443.       u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, pfn, NULL_TREE));
  6444.       u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, integer_zero_node,
  6445.                            tree_cons (NULL_TREE, integer_zero_node,
  6446.                               tree_cons (NULL_TREE, u, NULL_TREE))));
  6447.       return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
  6448.     }
  6449.  
  6450.   if (TREE_CODE (pfn) == TREE_LIST
  6451.       || (TREE_CODE (pfn) == ADDR_EXPR
  6452.       && TREE_CODE (TREE_OPERAND (pfn, 0)) == TREE_LIST))
  6453.     {
  6454.       pfn = instantiate_type (type, pfn, 1);
  6455.       if (pfn == error_mark_node)
  6456.     return error_mark_node;
  6457.       if (TREE_CODE (pfn) != ADDR_EXPR)
  6458.     pfn = build_unary_op (ADDR_EXPR, pfn, 0);
  6459.     }
  6460.  
  6461.   /* Allow pointer to member conversions here. */
  6462.   delta = get_delta_difference (TYPE_METHOD_BASETYPE (TREE_TYPE (TREE_TYPE (pfn))),
  6463.                 TYPE_METHOD_BASETYPE (TREE_TYPE (type)),
  6464.                 force);
  6465.   delta2 = build_binary_op (PLUS_EXPR, delta2, delta, 1);
  6466.  
  6467.   if (TREE_CODE (TREE_OPERAND (pfn, 0)) != FUNCTION_DECL)
  6468.     warning ("assuming pointer to member function is non-virtual");
  6469.  
  6470.   if (TREE_CODE (TREE_OPERAND (pfn, 0)) == FUNCTION_DECL
  6471.       && DECL_VINDEX (TREE_OPERAND (pfn, 0)))
  6472.     {
  6473.       /* Find the offset to the vfield pointer in the object. */
  6474.       vfield_offset = get_binfo (DECL_CONTEXT (TREE_OPERAND (pfn, 0)),
  6475.                  DECL_CLASS_CONTEXT (TREE_OPERAND (pfn, 0)),
  6476.                  0);
  6477.       vfield_offset = get_vfield_offset (vfield_offset);
  6478.       delta2 = size_binop (PLUS_EXPR, vfield_offset, delta2);
  6479.  
  6480.       /* Map everything down one to make room for the null pointer to member.  */
  6481.       index = size_binop (PLUS_EXPR,
  6482.               DECL_VINDEX (TREE_OPERAND (pfn, 0)),
  6483.               integer_one_node);
  6484.       u = build_nt (CONSTRUCTOR, 0, tree_cons (delta2_identifier, delta2, NULL_TREE));
  6485.     }
  6486.   else
  6487.     {
  6488.       index = size_binop (MINUS_EXPR, integer_zero_node, integer_one_node);
  6489.  
  6490.       npfn = build1 (NOP_EXPR, type, pfn);
  6491.       TREE_CONSTANT (npfn) = TREE_CONSTANT (pfn);
  6492.  
  6493.       u = build_nt (CONSTRUCTOR, 0, tree_cons (pfn_identifier, npfn, NULL_TREE));
  6494.     }
  6495.  
  6496.   u = build_nt (CONSTRUCTOR, 0, tree_cons (NULL_TREE, delta,
  6497.                        tree_cons (NULL_TREE, index,
  6498.                               tree_cons (NULL_TREE, u, NULL_TREE))));
  6499.   return digest_init (TYPE_GET_PTRMEMFUNC_TYPE (type), u, (tree*)0);
  6500. }
  6501.  
  6502. /* Convert value RHS to type TYPE as preparation for an assignment
  6503.    to an lvalue of type TYPE.
  6504.    The real work of conversion is done by `convert'.
  6505.    The purpose of this function is to generate error messages
  6506.    for assignments that are not allowed in C.
  6507.    ERRTYPE is a string to use in error messages:
  6508.    "assignment", "return", etc.
  6509.  
  6510.    C++: attempts to allow `convert' to find conversions involving
  6511.    implicit type conversion between aggregate and scalar types
  6512.    as per 8.5.6 of C++ manual.  Does not randomly dereference
  6513.    pointers to aggregates!  */
  6514.  
  6515. static tree
  6516. convert_for_assignment (type, rhs, errtype, fndecl, parmnum)
  6517.      tree type, rhs;
  6518.      char *errtype;
  6519.      tree fndecl;
  6520.      int parmnum;
  6521. {
  6522.   register enum tree_code codel = TREE_CODE (type);
  6523.   register tree rhstype;
  6524.   register enum tree_code coder = TREE_CODE (TREE_TYPE (rhs));
  6525.  
  6526.   if (coder == UNKNOWN_TYPE)
  6527.     rhs = instantiate_type (type, rhs, 1);
  6528.  
  6529.   if (coder == ERROR_MARK)
  6530.     return error_mark_node;
  6531.  
  6532.   if (codel == OFFSET_TYPE)
  6533.     {
  6534.       type = TREE_TYPE (type);
  6535.       codel = TREE_CODE (type);
  6536.     }
  6537.  
  6538.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  6539.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  6540.     rhs = TREE_OPERAND (rhs, 0);
  6541.  
  6542.   if (rhs == error_mark_node)
  6543.     return error_mark_node;
  6544.  
  6545.   if (TREE_VALUE (rhs) == error_mark_node)
  6546.     return error_mark_node;
  6547.  
  6548.   if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  6549.     {
  6550.       rhs = resolve_offset_ref (rhs);
  6551.       if (rhs == error_mark_node)
  6552.     return error_mark_node;
  6553.       rhstype = TREE_TYPE (rhs);
  6554.       coder = TREE_CODE (rhstype);
  6555.     }
  6556.  
  6557.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  6558.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
  6559.       || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  6560.     rhs = default_conversion (rhs);
  6561.   else if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
  6562.     rhs = convert_from_reference (rhs);
  6563.  
  6564.   rhstype = TREE_TYPE (rhs);
  6565.   coder = TREE_CODE (rhstype);
  6566.  
  6567.   /* This should no longer change types on us.  */
  6568.   if (TREE_CODE (rhs) == CONST_DECL)
  6569.     rhs = DECL_INITIAL (rhs);
  6570.   else if (TREE_READONLY_DECL_P (rhs))
  6571.     rhs = decl_constant_value (rhs);
  6572.  
  6573.   if (type == rhstype)
  6574.     {
  6575.       overflow_warning (rhs);
  6576.       return rhs;
  6577.     }
  6578.  
  6579. #ifdef OBJCPLUS
  6580.   /* Check for Objective-C protocols.  */
  6581.   if (maybe_objc_comptypes (type, rhstype, 0) == 1)
  6582.     return rhs;
  6583. #endif /* OBJCPLUS */
  6584.  
  6585.   if (coder == VOID_TYPE)
  6586.     {
  6587.       error ("void value not ignored as it ought to be");
  6588.       return error_mark_node;
  6589.     }
  6590.   /* Arithmetic types all interconvert.  */
  6591.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == BOOLEAN_TYPE)
  6592.        && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == BOOLEAN_TYPE))
  6593.     {
  6594.       /* But we should warn if assigning REAL_TYPE to INTEGER_TYPE.  */
  6595.       if (coder == REAL_TYPE && codel == INTEGER_TYPE)
  6596.     {
  6597.       if (fndecl)
  6598.         cp_warning ("`%T' used for argument %P of `%D'",
  6599.             rhstype, parmnum, fndecl);
  6600.       else
  6601.         cp_warning ("%s to `%T' from `%T'", errtype, type, rhstype);
  6602.     }
  6603.       /* And we should warn if assigning a negative value to
  6604.      an unsigned variable.  */
  6605.       else if (TREE_UNSIGNED (type) && codel != BOOLEAN_TYPE)
  6606.     {
  6607.       if (TREE_CODE (rhs) == INTEGER_CST
  6608.           && TREE_NEGATED_INT (rhs))
  6609.         {
  6610.           if (fndecl)
  6611.         cp_warning ("negative value `%E' passed as argument %P of `%D'",
  6612.                 rhs, parmnum, fndecl);
  6613.           else
  6614.         cp_warning ("%s of negative value `%E' to `%T'",
  6615.                 errtype, rhs, type);
  6616.         }
  6617.       overflow_warning (rhs);
  6618.       if (TREE_CONSTANT (rhs))
  6619.         rhs = fold (rhs);
  6620.     }
  6621.  
  6622.       return convert_and_check (type, rhs);
  6623.     }
  6624.   /* Conversions involving enums.  */
  6625.   else if ((codel == ENUMERAL_TYPE
  6626.         && (INTEGRAL_CODE_P (coder) || coder == REAL_TYPE))
  6627.        || (coder == ENUMERAL_TYPE
  6628.            && (INTEGRAL_CODE_P (codel) || codel == REAL_TYPE)))
  6629.     {
  6630.       return cp_convert (type, rhs, CONV_IMPLICIT, LOOKUP_NORMAL);
  6631.     }
  6632.   /* Conversions among pointers */
  6633.   else if (codel == POINTER_TYPE
  6634.        && (coder == POINTER_TYPE
  6635.            || (coder == RECORD_TYPE
  6636.            && (IS_SIGNATURE_POINTER (rhstype)
  6637.                || IS_SIGNATURE_REFERENCE (rhstype)))))
  6638.     {
  6639.       register tree ttl = TREE_TYPE (type);
  6640.       register tree ttr;
  6641.       int ctt = 0;
  6642.  
  6643.       if (coder == RECORD_TYPE)
  6644.     {
  6645.       rhs = build_optr_ref (rhs);
  6646.       rhstype = TREE_TYPE (rhs);
  6647.     }
  6648.       ttr = TREE_TYPE (rhstype);
  6649.  
  6650. #ifdef OBJCPLUS
  6651.       if (maybe_objc_comptypes (ttl, ttr, 0) == 1)
  6652.         return convert (type, rhs);
  6653. #endif /* OBJCPLUS */
  6654.  
  6655.       /* If both pointers are of aggregate type, then we
  6656.      can give better error messages, and save some work
  6657.      as well.  */
  6658.       if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE)
  6659.     {
  6660.       tree binfo;
  6661.  
  6662.       if (TYPE_MAIN_VARIANT (ttl) == TYPE_MAIN_VARIANT (ttr)
  6663.           || type == class_star_type_node
  6664.           || rhstype == class_star_type_node)
  6665.         binfo = TYPE_BINFO (ttl);
  6666.       else
  6667.         binfo = get_binfo (ttl, ttr, 1);
  6668.  
  6669.       if (binfo == error_mark_node)
  6670.         return error_mark_node;
  6671.       if (binfo == 0)
  6672.         return error_not_base_type (ttl, ttr);
  6673.  
  6674.       if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  6675.         {
  6676.           if (fndecl)
  6677.         cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
  6678.                 rhstype, parmnum, fndecl);
  6679.           else
  6680.         cp_pedwarn ("%s to `%T' from `%T' discards const",
  6681.                 errtype, type, rhstype);
  6682.         }
  6683.       if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  6684.         {
  6685.           if (fndecl)
  6686.         cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
  6687.                 rhstype, parmnum, fndecl);
  6688.           else
  6689.         cp_pedwarn ("%s to `%T' from `%T' discards volatile",
  6690.                 errtype, type, rhstype);
  6691.         }
  6692.     }
  6693.  
  6694.       /* Any non-function converts to a [const][volatile] void *
  6695.      and vice versa; otherwise, targets must be the same.
  6696.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  6697.       else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  6698.            || TYPE_MAIN_VARIANT (ttr) == void_type_node
  6699.            || (ctt = comp_target_types (type, rhstype, 1))
  6700.            || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
  6701.            == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
  6702.     {
  6703.       /* ARM $4.8, commentary on p39.  */
  6704.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  6705.           && TREE_CODE (ttr) == OFFSET_TYPE)
  6706.         {
  6707.           cp_error ("no standard conversion from `%T' to `void *'", ttr);
  6708.           return error_mark_node;
  6709.         }
  6710.  
  6711.       if (ctt < 0)
  6712.         cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
  6713.             rhstype, type);
  6714.  
  6715.       if (TYPE_MAIN_VARIANT (ttl) != void_type_node
  6716.           && TYPE_MAIN_VARIANT (ttr) == void_type_node
  6717.           && rhs != null_pointer_node)
  6718.         {
  6719.           if (coder == RECORD_TYPE)
  6720.         cp_pedwarn ("implicit conversion of signature pointer to type `%T'",
  6721.                 type);
  6722.           else
  6723. #ifdef OBJCPLUS
  6724.                 {
  6725.                 extern int doing_objc_thang;
  6726.                 if (!doing_objc_thang)
  6727.           pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s", errtype);
  6728.                 }
  6729. #else
  6730.         pedwarn ("ANSI C++ forbids implicit conversion from `void *' in %s",
  6731.              errtype);
  6732. #endif
  6733.         }
  6734.       /* Const and volatile mean something different for function types,
  6735.          so the usual warnings are not appropriate.  */
  6736.       else if ((TREE_CODE (ttr) != FUNCTION_TYPE && TREE_CODE (ttr) != METHOD_TYPE)
  6737.            || (TREE_CODE (ttl) != FUNCTION_TYPE && TREE_CODE (ttl) != METHOD_TYPE))
  6738.         {
  6739.           if (TREE_CODE (ttl) == OFFSET_TYPE
  6740.           && binfo_member (TYPE_OFFSET_BASETYPE (ttr),
  6741.                    CLASSTYPE_VBASECLASSES (TYPE_OFFSET_BASETYPE (ttl))))
  6742.         {
  6743.           sorry ("%s between pointer to members converting across virtual baseclasses", errtype);
  6744.           return error_mark_node;
  6745.         }
  6746.           else if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  6747.         {
  6748.           if (fndecl)
  6749.             cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
  6750.                 rhstype, parmnum, fndecl);
  6751.           else
  6752.             cp_pedwarn ("%s to `%T' from `%T' discards const",
  6753.                 errtype, type, rhstype);
  6754.         }
  6755.           else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  6756.         {
  6757.           if (fndecl)
  6758.             cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
  6759.                 rhstype, parmnum, fndecl);
  6760.           else
  6761.             cp_pedwarn ("%s to `%T' from `%T' discards volatile",
  6762.                 errtype, type, rhstype);
  6763.         }
  6764.           else if (TREE_CODE (ttl) == TREE_CODE (ttr)
  6765.                && ! comp_target_types (type, rhstype, 1))
  6766.         {
  6767.           if (fndecl)
  6768.             cp_pedwarn ("passing `%T' as argument %P of `%D' changes signedness",
  6769.                 rhstype, parmnum, fndecl);
  6770.           else
  6771.             cp_pedwarn ("%s to `%T' from `%T' changes signedness",
  6772.                 errtype, type, rhstype);
  6773.         }
  6774.         }
  6775.     }
  6776.       else if (TREE_CODE (ttr) == OFFSET_TYPE
  6777.            && TREE_CODE (ttl) != OFFSET_TYPE)
  6778.     {
  6779.       /* Normally, pointers to different type codes (other
  6780.          than void) are not compatible, but we perform
  6781.          some type instantiation if that resolves the
  6782.          ambiguity of (X Y::*) and (X *).  */
  6783.  
  6784.       if (current_class_decl)
  6785.         {
  6786.           if (TREE_CODE (rhs) == INTEGER_CST)
  6787.         {
  6788.           rhs = build (PLUS_EXPR, build_pointer_type (TREE_TYPE (ttr)),
  6789.                    current_class_decl, rhs);
  6790.           return convert_for_assignment (type, rhs,
  6791.                          errtype, fndecl, parmnum);
  6792.         }
  6793.         }
  6794.       if (TREE_CODE (ttl) == METHOD_TYPE)
  6795.         error ("%s between pointer-to-method and pointer-to-member types",
  6796.            errtype);
  6797.       else
  6798.         error ("%s between pointer and pointer-to-member types", errtype);
  6799.       return error_mark_node;
  6800.     }
  6801.       else
  6802.     {
  6803.       int add_quals = 0, const_parity = 0, volatile_parity = 0;
  6804.       int left_const = 1;
  6805.       int unsigned_parity;
  6806.       int nptrs = 0;
  6807.  
  6808.       /* This code is basically a duplicate of comp_ptr_ttypes_real.  */
  6809.       for (; ; ttl = TREE_TYPE (ttl), ttr = TREE_TYPE (ttr))
  6810.         {
  6811.           nptrs -= 1;
  6812.           const_parity |= TYPE_READONLY (ttl) < TYPE_READONLY (ttr);
  6813.           volatile_parity |= TYPE_VOLATILE (ttl) < TYPE_VOLATILE (ttr);
  6814.  
  6815.           if (! left_const
  6816.           && (TYPE_READONLY (ttl) > TYPE_READONLY (ttr)
  6817.               || TYPE_VOLATILE (ttl) > TYPE_VOLATILE (ttr)))
  6818.         add_quals = 1;
  6819.           left_const &= TYPE_READONLY (ttl);
  6820.  
  6821.           if (TREE_CODE (ttl) != POINTER_TYPE
  6822.           || TREE_CODE (ttr) != POINTER_TYPE)
  6823.         break;
  6824.         }
  6825.       unsigned_parity = TREE_UNSIGNED (ttl) - TREE_UNSIGNED (ttr);
  6826.       if (unsigned_parity)
  6827.         {
  6828.           if (TREE_UNSIGNED (ttl))
  6829.         ttr = unsigned_type (ttr);
  6830.           else
  6831.         ttl = unsigned_type (ttl);
  6832.         }
  6833.  
  6834.       if (comp_target_types (ttl, ttr, nptrs) > 0)
  6835.         {
  6836.           if (add_quals)
  6837.         {
  6838.           if (fndecl)
  6839.             cp_pedwarn ("passing `%T' as argument %P of `%D' adds cv-quals without intervening `const'",
  6840.                 rhstype, parmnum, fndecl);
  6841.           else
  6842.             cp_pedwarn ("%s to `%T' from `%T' adds cv-quals without intervening `const'",
  6843.                 errtype, type, rhstype);
  6844.         }
  6845.           if (const_parity)
  6846.         {
  6847.           if (fndecl)
  6848.             cp_pedwarn ("passing `%T' as argument %P of `%D' discards const",
  6849.                 rhstype, parmnum, fndecl);
  6850.           else
  6851.             cp_pedwarn ("%s to `%T' from `%T' discards const",
  6852.                 errtype, type, rhstype);
  6853.         }
  6854.           if (volatile_parity)
  6855.         {
  6856.           if (fndecl)
  6857.             cp_pedwarn ("passing `%T' as argument %P of `%D' discards volatile",
  6858.                 rhstype, parmnum, fndecl);
  6859.           else
  6860.             cp_pedwarn ("%s to `%T' from `%T' discards volatile",
  6861.                 errtype, type, rhstype);
  6862.         }
  6863.           if (unsigned_parity > 0)
  6864.         {
  6865.           if (fndecl)
  6866.             cp_pedwarn ("passing `%T' as argument %P of `%D' changes signed to unsigned",
  6867.                 rhstype, parmnum, fndecl);
  6868.           else
  6869.             cp_pedwarn ("%s to `%T' from `%T' changes signed to unsigned",
  6870.                 errtype, type, rhstype);
  6871.         }
  6872.           else if (unsigned_parity < 0)
  6873.         {
  6874.           if (fndecl)
  6875.             cp_pedwarn ("passing `%T' as argument %P of `%D' changes unsigned to signed",
  6876.                 rhstype, parmnum, fndecl);
  6877.           else
  6878.             cp_pedwarn ("%s to `%T' from `%T' changes unsigned to signed",
  6879.                 errtype, type, rhstype);
  6880.         }
  6881.  
  6882.           /* C++ is not so friendly about converting function and
  6883.          member function pointers as C.  Emit warnings here.  */
  6884.           if (TREE_CODE (ttl) == FUNCTION_TYPE
  6885.           || TREE_CODE (ttl) == METHOD_TYPE)
  6886.         if (! comptypes (ttl, ttr, 0))
  6887.           {
  6888.             warning ("conflicting function types in %s:", errtype);
  6889.             cp_warning ("\t`%T' != `%T'", type, rhstype);
  6890.           }
  6891.         }
  6892.       else if (TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  6893.         {
  6894.           /* When does this happen?  */
  6895.           my_friendly_abort (119);
  6896.           /* Conversion of a pointer-to-member type to void *.  */
  6897.           rhs = build_unary_op (ADDR_EXPR, rhs, 0);
  6898.           TREE_TYPE (rhs) = type;
  6899.           return rhs;
  6900.         }
  6901.       else if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  6902.         {
  6903.           /* When does this happen?  */
  6904.           my_friendly_abort (120);
  6905.           /* Conversion of a pointer-to-member type to void *.  */
  6906.           rhs = build_unary_op (ADDR_EXPR, rhs, 0);
  6907.           TREE_TYPE (rhs) = type;
  6908.           return rhs;
  6909.         }
  6910.       else
  6911.         {
  6912.           if (fndecl)
  6913.         cp_error ("passing `%T' as argument %P of `%D'",
  6914.               rhstype, parmnum, fndecl);
  6915.           else
  6916.         cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
  6917.           return error_mark_node;
  6918.         }
  6919.     }
  6920.       return convert (type, rhs);
  6921.     }
  6922.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  6923.     {
  6924.       /* An explicit constant 0 can convert to a pointer,
  6925.          but not a 0 that results from casting or folding.  */
  6926.       if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs)))
  6927.     {
  6928.       if (fndecl)
  6929.         cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
  6930.             rhstype, parmnum, fndecl);
  6931.       else
  6932.         cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
  6933.             errtype, type, rhstype);
  6934.       return convert (type, rhs);
  6935.     }
  6936.       return null_pointer_node;
  6937.     }
  6938.   else if (codel == INTEGER_TYPE
  6939.        && (coder == POINTER_TYPE
  6940.            || (coder == RECORD_TYPE
  6941.            && (IS_SIGNATURE_POINTER (rhstype)
  6942.                || TYPE_PTRMEMFUNC_FLAG (rhstype)
  6943.                || IS_SIGNATURE_REFERENCE (rhstype)))))
  6944.     {
  6945.       if (fndecl)
  6946.     cp_pedwarn ("passing `%T' to argument %P of `%D' lacks a cast",
  6947.             rhstype, parmnum, fndecl);
  6948.       else
  6949.     cp_pedwarn ("%s to `%T' from `%T' lacks a cast",
  6950.             errtype, type, rhstype);
  6951.       return convert (type, rhs);
  6952.     }
  6953.   else if (codel == BOOLEAN_TYPE
  6954.        && (coder == POINTER_TYPE
  6955.            || (coder == RECORD_TYPE
  6956.            && (IS_SIGNATURE_POINTER (rhstype)
  6957.                || TYPE_PTRMEMFUNC_FLAG (rhstype)
  6958.                || IS_SIGNATURE_REFERENCE (rhstype)))))
  6959.     return convert (type, rhs);
  6960.  
  6961.   /* C++ */
  6962.   else if (((coder == POINTER_TYPE
  6963.          && TREE_CODE (TREE_TYPE (rhstype)) == METHOD_TYPE)
  6964.         || integer_zerop (rhs)
  6965.         || TYPE_PTRMEMFUNC_P (rhstype))
  6966.        && TYPE_PTRMEMFUNC_P (type))
  6967.     {
  6968.       tree ttl = TYPE_PTRMEMFUNC_FN_TYPE (type);
  6969.       tree ttr = (TREE_CODE (rhstype) == POINTER_TYPE ? rhstype
  6970.             : TYPE_PTRMEMFUNC_FN_TYPE (type));
  6971.       int ctt = comp_target_types (ttl, ttr, 1);
  6972.  
  6973.       if (ctt < 0)
  6974.     cp_pedwarn ("converting `%T' to `%T' is a contravariance violation",
  6975.             ttr, ttl);
  6976.       else if (ctt == 0)
  6977.     cp_error ("%s to `%T' from `%T'", errtype, ttl, ttr);
  6978.  
  6979.       /* compatible pointer to member functions. */
  6980.       return build_ptrmemfunc (ttl, rhs, 0);
  6981.     }
  6982.   else if (codel == ERROR_MARK || coder == ERROR_MARK)
  6983.     return error_mark_node;
  6984.  
  6985.   /* This should no longer happen.  References are initialized via
  6986.      `convert_for_initialization'.  They should otherwise be
  6987.      bashed before coming here.  */
  6988.   else if (codel == REFERENCE_TYPE)
  6989.     my_friendly_abort (317);
  6990.   else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (rhs)))
  6991.     {
  6992.       tree nrhs = build1 (NOP_EXPR, type, rhs);
  6993.       TREE_CONSTANT (nrhs) = TREE_CONSTANT (rhs);
  6994.       return nrhs;
  6995.     }
  6996.   else if (TYPE_HAS_CONSTRUCTOR (type) || IS_AGGR_TYPE (TREE_TYPE (rhs)))
  6997.     return convert (type, rhs);
  6998.  
  6999.   cp_error ("%s to `%T' from `%T'", errtype, type, rhstype);
  7000.   return error_mark_node;
  7001. }
  7002.  
  7003. /* Convert RHS to be of type TYPE.  If EXP is non-zero,
  7004.    it is the target of the initialization.
  7005.    ERRTYPE is a string to use in error messages.
  7006.  
  7007.    Two major differences between the behavior of
  7008.    `convert_for_assignment' and `convert_for_initialization'
  7009.    are that references are bashed in the former, while
  7010.    copied in the latter, and aggregates are assigned in
  7011.    the former (operator=) while initialized in the
  7012.    latter (X(X&)).
  7013.  
  7014.    If using constructor make sure no conversion operator exists, if one does
  7015.    exist, an ambiguity exists.
  7016.  
  7017.    If flags doesn't include LOOKUP_COMPLAIN, don't complain about anything.  */
  7018. tree
  7019. convert_for_initialization (exp, type, rhs, flags, errtype, fndecl, parmnum)
  7020.      tree exp, type, rhs;
  7021.      int flags;
  7022.      char *errtype;
  7023.      tree fndecl;
  7024.      int parmnum;
  7025. {
  7026.   register enum tree_code codel = TREE_CODE (type);
  7027.   register tree rhstype;
  7028.   register enum tree_code coder;
  7029.  
  7030.   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
  7031.      Strip such NOP_EXPRs, since RHS is used in non-lvalue context.  */
  7032.   if (TREE_CODE (rhs) == NOP_EXPR
  7033.       && TREE_TYPE (rhs) == TREE_TYPE (TREE_OPERAND (rhs, 0))
  7034.       && codel != REFERENCE_TYPE)
  7035.     rhs = TREE_OPERAND (rhs, 0);
  7036.  
  7037.   if (rhs == error_mark_node
  7038.       || (TREE_CODE (rhs) == TREE_LIST && TREE_VALUE (rhs) == error_mark_node))
  7039.     return error_mark_node;
  7040.  
  7041.   if (TREE_CODE (TREE_TYPE (rhs)) == OFFSET_TYPE)
  7042.     {
  7043.       rhs = resolve_offset_ref (rhs);
  7044.       if (rhs == error_mark_node)
  7045.     return error_mark_node;
  7046.     }
  7047.  
  7048.   if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
  7049.     rhs = convert_from_reference (rhs);
  7050.  
  7051.   if ((TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  7052.        && TREE_CODE (type) != ARRAY_TYPE
  7053.        && (TREE_CODE (type) != REFERENCE_TYPE
  7054.        || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE))
  7055.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE
  7056.       || TREE_CODE (TREE_TYPE (rhs)) == METHOD_TYPE)
  7057.     rhs = default_conversion (rhs);
  7058.  
  7059.   rhstype = TREE_TYPE (rhs);
  7060.   coder = TREE_CODE (rhstype);
  7061.  
  7062.   if (coder == UNKNOWN_TYPE)
  7063.     {
  7064.       rhs = instantiate_type (type, rhs, 1);
  7065.       rhstype = TREE_TYPE (rhs);
  7066.       coder = TREE_CODE (rhstype);
  7067.     }
  7068.  
  7069.   if (coder == ERROR_MARK)
  7070.     return error_mark_node;
  7071.  
  7072. #if 0
  7073.   /* This is *not* the quick way out!  It is the way to disaster.  */
  7074.   if (type == rhstype)
  7075.     goto converted;
  7076. #endif
  7077.  
  7078.   /* We accept references to incomplete types, so we can
  7079.      return here before checking if RHS is of complete type.  */
  7080.      
  7081.   if (codel == REFERENCE_TYPE)
  7082.     {
  7083.       /* This should eventually happen in convert_arguments.  */
  7084.       extern int warningcount, errorcount;
  7085.       int savew, savee;
  7086.  
  7087.       if (fndecl)
  7088.     savew = warningcount, savee = errorcount;
  7089.       rhs = convert_to_reference (type, rhs, CONV_IMPLICIT, flags,
  7090.                   exp ? exp : error_mark_node);
  7091.       if (fndecl)
  7092.     {
  7093.       if (warningcount > savew)
  7094.         cp_warning_at ("in passing argument %P of `%+D'", parmnum, fndecl);
  7095.       else if (errorcount > savee)
  7096.         cp_error_at ("in passing argument %P of `%+D'", parmnum, fndecl);
  7097.     }
  7098.       return rhs;
  7099.     }      
  7100.  
  7101.   rhs = require_complete_type (rhs);
  7102.   if (rhs == error_mark_node)
  7103.     return error_mark_node;
  7104.  
  7105.   if (exp != 0) exp = require_complete_type (exp);
  7106.   if (exp == error_mark_node)
  7107.     return error_mark_node;
  7108.  
  7109.   if (TREE_CODE (rhstype) == REFERENCE_TYPE)
  7110.     rhstype = TREE_TYPE (rhstype);
  7111.  
  7112.   if (TYPE_LANG_SPECIFIC (type)
  7113.       && (IS_SIGNATURE_POINTER (type) || IS_SIGNATURE_REFERENCE (type)))
  7114.     return build_signature_pointer_constructor (type, rhs);
  7115.  
  7116.   if (IS_AGGR_TYPE (type)
  7117.       && (TYPE_NEEDS_CONSTRUCTING (type) || TREE_HAS_CONSTRUCTOR (rhs)))
  7118.     {
  7119.       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  7120.     {
  7121.       /* This is sufficient to perform initialization.  No need,
  7122.          apparently, to go through X(X&) to do first-cut
  7123.          initialization.  Return through a TARGET_EXPR so that we get
  7124.          cleanups if it is used.  */
  7125.       if (TREE_CODE (rhs) == CALL_EXPR)
  7126.         {
  7127.           rhs = build_cplus_new (type, rhs, 0);
  7128.           return rhs;
  7129.         }
  7130.       /* Handle the case of default parameter initialization and
  7131.          initialization of static variables.  */
  7132.       else if (TREE_CODE (rhs) == TARGET_EXPR)
  7133.         return rhs;
  7134.       else if (TREE_CODE (rhs) == INDIRECT_REF && TREE_HAS_CONSTRUCTOR (rhs))
  7135.         {
  7136.           my_friendly_assert (TREE_CODE (TREE_OPERAND (rhs, 0)) == CALL_EXPR, 318);
  7137.           if (exp)
  7138.         {
  7139.           my_friendly_assert (TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1)) == NULL_TREE, 316);
  7140.           TREE_VALUE (TREE_OPERAND (TREE_OPERAND (rhs, 0), 1))
  7141.             = build_unary_op (ADDR_EXPR, exp, 0);
  7142.         }
  7143.           else
  7144.         rhs = build_cplus_new (type, TREE_OPERAND (rhs, 0), 0);
  7145.           return rhs;
  7146.         }
  7147.       else if (TYPE_HAS_TRIVIAL_INIT_REF (type))
  7148.         return rhs;
  7149.     }
  7150.       if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)
  7151.       || (IS_AGGR_TYPE (rhstype) && UNIQUELY_DERIVED_FROM_P (type, rhstype)))
  7152.     {
  7153.       if (TYPE_HAS_INIT_REF (type))
  7154.         {
  7155.           tree init = build_method_call (exp, constructor_name_full (type),
  7156.                          build_tree_list (NULL_TREE, rhs),
  7157.                          TYPE_BINFO (type), LOOKUP_NORMAL);
  7158.  
  7159.           if (init == error_mark_node)
  7160.         return error_mark_node;
  7161.  
  7162.           if (exp == 0)
  7163.         {
  7164.           exp = build_cplus_new (type, init, 0);
  7165.           return exp;
  7166.         }
  7167.  
  7168.           return build (COMPOUND_EXPR, type, init, exp);
  7169.         }
  7170.  
  7171.       /* ??? The following warnings are turned off because
  7172.          this is another place where the default X(X&) constructor
  7173.          is implemented.  */
  7174.       if (TYPE_HAS_ASSIGNMENT (type))
  7175.         cp_warning ("bitwise copy: `%T' defines operator=", type);
  7176.  
  7177.       if (TREE_CODE (TREE_TYPE (rhs)) == REFERENCE_TYPE)
  7178.         rhs = convert_from_reference (rhs);
  7179.       if (type != rhstype)
  7180.         {
  7181.           tree nrhs = build1 (NOP_EXPR, type, rhs);
  7182.           TREE_CONSTANT (nrhs) = TREE_CONSTANT (rhs);
  7183.           rhs = nrhs;
  7184.         }
  7185.       return rhs;
  7186.     }
  7187.  
  7188.       return cp_convert (type, rhs, CONV_OLD_CONVERT, flags);
  7189.     }
  7190.  
  7191.   if (type == TREE_TYPE (rhs))
  7192.     {
  7193.       if (TREE_READONLY_DECL_P (rhs))
  7194.     rhs = decl_constant_value (rhs);
  7195.       return rhs;
  7196.     }
  7197.  
  7198.   return convert_for_assignment (type, rhs, errtype, fndecl, parmnum);
  7199. }
  7200.  
  7201. /* Expand an ASM statement with operands, handling output operands
  7202.    that are not variables or INDIRECT_REFS by transforming such
  7203.    cases into cases that expand_asm_operands can handle.
  7204.  
  7205.    Arguments are same as for expand_asm_operands.
  7206.  
  7207.    We don't do default conversions on all inputs, because it can screw
  7208.    up operands that are expected to be in memory.  */
  7209.  
  7210. void
  7211. c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  7212.      tree string, outputs, inputs, clobbers;
  7213.      int vol;
  7214.      char *filename;
  7215.      int line;
  7216. {
  7217.   int noutputs = list_length (outputs);
  7218.   register int i;
  7219.   /* o[I] is the place that output number I should be written.  */
  7220.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  7221.   register tree tail;
  7222.  
  7223.   /* Record the contents of OUTPUTS before it is modified.  */
  7224.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  7225.     o[i] = TREE_VALUE (tail);
  7226.  
  7227.   /* Generate the ASM_OPERANDS insn;
  7228.      store into the TREE_VALUEs of OUTPUTS some trees for
  7229.      where the values were actually stored.  */
  7230.   expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
  7231.  
  7232.   /* Copy all the intermediate outputs into the specified outputs.  */
  7233.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  7234.     {
  7235.       if (o[i] != TREE_VALUE (tail))
  7236.     {
  7237.       expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  7238.                const0_rtx, VOIDmode, 0);
  7239.       free_temp_slots ();
  7240.     }
  7241.       /* Detect modification of read-only values.
  7242.      (Otherwise done by build_modify_expr.)  */
  7243.       else
  7244.     {
  7245.       tree type = TREE_TYPE (o[i]);
  7246.       if (TYPE_READONLY (type)
  7247.           || ((TREE_CODE (type) == RECORD_TYPE
  7248.            || TREE_CODE (type) == UNION_TYPE)
  7249.           && C_TYPE_FIELDS_READONLY (type)))
  7250.         readonly_error (o[i], "modification by `asm'", 1);
  7251.     }
  7252.     }
  7253.  
  7254.   /* Those MODIFY_EXPRs could do autoincrements.  */
  7255.   emit_queue ();
  7256. }
  7257.  
  7258. /* Expand a C `return' statement.
  7259.    RETVAL is the expression for what to return,
  7260.    or a null pointer for `return;' with no value.
  7261.  
  7262.    C++: upon seeing a `return', we must call destructors on all
  7263.    variables in scope which had constructors called on them.
  7264.    This means that if in a destructor, the base class destructors
  7265.    must be called before returning.
  7266.  
  7267.    The RETURN statement in C++ has initialization semantics.  */
  7268.  
  7269. void
  7270. c_expand_return (retval)
  7271.      tree retval;
  7272. {
  7273.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  7274.   extern tree dtor_label, ctor_label;
  7275.   tree result = DECL_RESULT (current_function_decl);
  7276.   tree valtype = TREE_TYPE (result);
  7277.   register int use_temp = 0;
  7278.   int returns_value = 1;
  7279.  
  7280.   if (TREE_THIS_VOLATILE (current_function_decl))
  7281.     warning ("function declared `noreturn' has a `return' statement");
  7282.  
  7283.   if (retval == error_mark_node)
  7284.     {
  7285.       current_function_returns_null = 1;
  7286.       return;
  7287.     }
  7288.  
  7289.   if (retval == NULL_TREE)
  7290.     {
  7291.       /* A non-named return value does not count.  */
  7292.  
  7293.       /* Can't just return from a destructor.  */
  7294.       if (dtor_label)
  7295.     {
  7296.       expand_goto (dtor_label);
  7297.       return;
  7298.     }
  7299.  
  7300.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  7301.     retval = current_class_decl;
  7302.       else if (DECL_NAME (result) != NULL_TREE
  7303.            && TREE_CODE (valtype) != VOID_TYPE)
  7304.     retval = result;
  7305.       else
  7306.     {
  7307.       current_function_returns_null = 1;
  7308.  
  7309.       if (valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE)
  7310.         {
  7311.           if (DECL_NAME (DECL_RESULT (current_function_decl)) == NULL_TREE)
  7312.         {
  7313.           pedwarn ("`return' with no value, in function returning non-void");
  7314.           /* Clear this, so finish_function won't say that we
  7315.              reach the end of a non-void function (which we don't,
  7316.              we gave a return!).  */
  7317.           current_function_returns_null = 0;
  7318.         }
  7319.         }
  7320.  
  7321.       expand_null_return ();
  7322.       return;
  7323.     }
  7324.     }
  7325.   else if (DECL_CONSTRUCTOR_P (current_function_decl)
  7326.        && retval != current_class_decl)
  7327.     {
  7328.       error ("return from a constructor: use `this = ...' instead");
  7329.       retval = current_class_decl;
  7330.     }
  7331.  
  7332.   if (valtype == NULL_TREE || TREE_CODE (valtype) == VOID_TYPE)
  7333.     {
  7334.       current_function_returns_null = 1;
  7335.       /* We do this here so we'll avoid a warning about how the function
  7336.      "may or may not return a value" in finish_function.  */
  7337.       returns_value = 0;
  7338.  
  7339.       if (retval)
  7340.     pedwarn ("`return' with a value, in function returning void");
  7341.       expand_return (retval);
  7342.     }
  7343.   /* Add some useful error checking for C++.  */
  7344.   else if (TREE_CODE (valtype) == REFERENCE_TYPE)
  7345.     {
  7346.       tree whats_returned;
  7347.       tree tmp_result = result;
  7348.  
  7349.       /* Don't initialize directly into a non-BLKmode retval, since that
  7350.      could lose when being inlined by another caller.  (GCC can't
  7351.      read the function return register in an inline function when
  7352.      the return value is being ignored).  */
  7353.       if (result && TYPE_MODE (TREE_TYPE (tmp_result)) != BLKmode)
  7354.     tmp_result = 0;
  7355.  
  7356.       /* convert to reference now, so we can give error if we
  7357.      return an reference to a non-lvalue.  */
  7358.       retval = convert_for_initialization (tmp_result, valtype, retval,
  7359.                        LOOKUP_NORMAL, "return",
  7360.                        NULL_TREE, 0);
  7361.  
  7362.       /* Sort through common things to see what it is
  7363.      we are returning.  */
  7364.       whats_returned = retval;
  7365.       if (TREE_CODE (whats_returned) == COMPOUND_EXPR)
  7366.     {
  7367.       whats_returned = TREE_OPERAND (whats_returned, 1);
  7368.       if (TREE_CODE (whats_returned) == ADDR_EXPR)
  7369.         whats_returned = TREE_OPERAND (whats_returned, 0);
  7370.     }
  7371.       if (TREE_CODE (whats_returned) == ADDR_EXPR)
  7372.     {
  7373.       whats_returned = TREE_OPERAND (whats_returned, 0);
  7374.       while (TREE_CODE (whats_returned) == NEW_EXPR
  7375.          || TREE_CODE (whats_returned) == TARGET_EXPR
  7376.          || TREE_CODE (whats_returned) == WITH_CLEANUP_EXPR)
  7377.         {
  7378.           /* Get the target.  */
  7379.           whats_returned = TREE_OPERAND (whats_returned, 0);
  7380.           warning ("returning reference to temporary");
  7381.         }
  7382.     }
  7383.  
  7384.       if (TREE_CODE (whats_returned) == VAR_DECL && DECL_NAME (whats_returned))
  7385.     {
  7386.       if (TEMP_NAME_P (DECL_NAME (whats_returned)))
  7387.         warning ("reference to non-lvalue returned");
  7388.       else if (! TREE_STATIC (whats_returned)
  7389.            && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned)))
  7390.         cp_warning_at ("reference to local variable `%D' returned", whats_returned);
  7391.     }
  7392.     }
  7393.   else if (TREE_CODE (retval) == ADDR_EXPR)
  7394.     {
  7395.       tree whats_returned = TREE_OPERAND (retval, 0);
  7396.  
  7397.       if (TREE_CODE (whats_returned) == VAR_DECL
  7398.       && DECL_NAME (whats_returned)
  7399.       && IDENTIFIER_LOCAL_VALUE (DECL_NAME (whats_returned))
  7400.       && !TREE_STATIC (whats_returned))
  7401.     cp_warning_at ("address of local variable `%D' returned", whats_returned);
  7402.     }
  7403.   
  7404.   /* Now deal with possible C++ hair:
  7405.      (1) Compute the return value.
  7406.      (2) If there are aggregate values with destructors which
  7407.      must be cleaned up, clean them (taking care
  7408.      not to clobber the return value).
  7409.      (3) If an X(X&) constructor is defined, the return
  7410.      value must be returned via that.  */
  7411.  
  7412.   /* If we're returning in a register, we can't initialize the
  7413.      return value from a TARGET_EXPR.  */
  7414.   if (TREE_CODE (retval) == TARGET_EXPR
  7415.       && TYPE_MAIN_VARIANT (TREE_TYPE (retval)) == TYPE_MAIN_VARIANT (valtype)
  7416.       && ! current_function_returns_struct)
  7417.     retval = expand_target_expr (retval);
  7418.  
  7419.   if (retval == result
  7420.       /* Watch out for constructors, which "return" aggregates
  7421.      via initialization, but which otherwise "return" a pointer.  */
  7422.       || DECL_CONSTRUCTOR_P (current_function_decl))
  7423.     {
  7424.       /* This is just an error--it's already been reported.  */
  7425.       if (TYPE_SIZE (valtype) == NULL_TREE)
  7426.     return;
  7427.  
  7428.       if (TYPE_MODE (valtype) != BLKmode
  7429.       && any_pending_cleanups (1))
  7430.     {
  7431.       retval = get_temp_regvar (valtype, retval);
  7432.       use_temp = obey_regdecls;
  7433.     }
  7434.     }
  7435.   else if (IS_AGGR_TYPE (valtype) && current_function_returns_struct)
  7436.     {
  7437.       expand_aggr_init (result, retval, 0, LOOKUP_ONLYCONVERTING);
  7438.       expand_cleanups_to (NULL_TREE);
  7439.       DECL_INITIAL (result) = NULL_TREE;
  7440.       retval = 0;
  7441.     }
  7442.   else
  7443.     {
  7444.       if (TYPE_MODE (valtype) == VOIDmode)
  7445.     {
  7446.       if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode
  7447.           && warn_return_type)
  7448.         warning ("return of void value in function returning non-void");
  7449.       expand_expr_stmt (retval);
  7450.       retval = 0;
  7451.       result = 0;
  7452.     }
  7453.       else if (TYPE_MODE (valtype) != BLKmode
  7454.            && any_pending_cleanups (1))
  7455.     {
  7456.       retval = get_temp_regvar (valtype, retval);
  7457.       expand_cleanups_to (NULL_TREE);
  7458.       use_temp = obey_regdecls;
  7459.       result = 0;
  7460.     }
  7461.       else
  7462.     {
  7463.       retval = convert_for_initialization (result, valtype, retval,
  7464.                            LOOKUP_NORMAL,
  7465.                            "return", NULL_TREE, 0);
  7466.       DECL_INITIAL (result) = NULL_TREE;
  7467.     }
  7468.       if (retval == error_mark_node)
  7469.     return;
  7470.     }
  7471.  
  7472.   emit_queue ();
  7473.  
  7474.   if (retval != NULL_TREE
  7475.       && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd'
  7476.       && cond_stack == 0 && loop_stack == 0 && case_stack == 0)
  7477.     current_function_return_value = retval;
  7478.  
  7479.   if (result)
  7480.     {
  7481.       /* Everything's great--RETVAL is in RESULT.  */
  7482.       if (original_result_rtx)
  7483.     {
  7484.       store_expr (result, original_result_rtx, 0);
  7485.       expand_cleanups_to (NULL_TREE);
  7486.       use_variable (DECL_RTL (result));
  7487.       if (ctor_label  && TREE_CODE (ctor_label) != ERROR_MARK)
  7488.         expand_goto (ctor_label);
  7489.       else
  7490.         expand_null_return ();
  7491.     }
  7492.       else if (retval && retval != result)
  7493.     {
  7494.       /* Clear this out so the later call to decl_function_context
  7495.          won't end up bombing on us.  */
  7496.       if (DECL_CONTEXT (result) == error_mark_node)
  7497.         DECL_CONTEXT (result) = NULL_TREE;
  7498.       /* Here is where we finally get RETVAL into RESULT.
  7499.          `expand_return' does the magic of protecting
  7500.          RESULT from cleanups.  */
  7501.       retval = fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (result),
  7502.                  retval));
  7503.       /* This part _must_ come second, because expand_return looks for
  7504.          the INIT_EXPR as the toplevel node only.  :-( */
  7505.       retval = build (INIT_EXPR, TREE_TYPE (result), result, retval);
  7506.       TREE_SIDE_EFFECTS (retval) = 1;
  7507.       expand_return (retval);
  7508.     }
  7509.       else
  7510.     expand_return (result);
  7511.     }
  7512.   else
  7513.     {
  7514.       /* We may still need to put RETVAL into RESULT.  */
  7515.       result = DECL_RESULT (current_function_decl);
  7516.       if (original_result_rtx)
  7517.     {
  7518.       /* Here we have a named return value that went
  7519.          into memory.  We can compute RETVAL into that.  */
  7520.       if (retval)
  7521.         expand_assignment (result, retval, 0, 0);
  7522.       else
  7523.         store_expr (result, original_result_rtx, 0);
  7524.       result = make_tree (TREE_TYPE (result), original_result_rtx);
  7525.     }
  7526.       else if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK)
  7527.     {
  7528.       /* Here RETVAL is CURRENT_CLASS_DECL, so there's nothing to do.  */
  7529.       expand_goto (ctor_label);
  7530.     }
  7531.       else if (retval)
  7532.     {
  7533.       /* Here is where we finally get RETVAL into RESULT.
  7534.          `expand_return' does the magic of protecting
  7535.          RESULT from cleanups.  */
  7536.       result = build (INIT_EXPR, TREE_TYPE (result), result, retval);
  7537.       TREE_SIDE_EFFECTS (result) = 1;
  7538.       expand_return (result);
  7539.     }
  7540.       else if (TYPE_MODE (TREE_TYPE (result)) != VOIDmode)
  7541.     expand_return (result);
  7542.     }
  7543.  
  7544.   current_function_returns_value = returns_value;
  7545. #if 0
  7546.   /* These wind up after the BARRIER, which causes problems for
  7547.      expand_end_binding.  What purpose were they supposed to serve?  */
  7548.   if (original_result_rtx)
  7549.     use_variable (original_result_rtx);
  7550.   if (use_temp)
  7551.     use_variable (DECL_RTL (DECL_RESULT (current_function_decl)));
  7552. #endif
  7553.  
  7554.   /* One way to clear out cleanups that EXPR might
  7555.      generate.  Note that this code will really be
  7556.      dead code, but that is ok--cleanups that were
  7557.      needed were handled by the magic of `return'.  */
  7558.   expand_cleanups_to (NULL_TREE);
  7559. }
  7560.  
  7561. /* Start a C switch statement, testing expression EXP.
  7562.    Return EXP if it is valid, an error node otherwise.  */
  7563.  
  7564. tree
  7565. c_expand_start_case (exp)
  7566.      tree exp;
  7567. {
  7568.   tree type;
  7569.   register enum tree_code code;
  7570.  
  7571.   /* Convert from references, etc.  */
  7572.   exp = default_conversion (exp);
  7573.   type = TREE_TYPE (exp);
  7574.   code = TREE_CODE (type);
  7575.  
  7576.   if (IS_AGGR_TYPE_CODE (code))
  7577.     exp = build_type_conversion (CONVERT_EXPR, integer_type_node, exp, 1);
  7578.  
  7579.   if (exp == NULL_TREE)
  7580.     {
  7581.       error ("switch quantity not an integer");
  7582.       exp = error_mark_node;
  7583.     }
  7584.   type = TREE_TYPE (exp);
  7585.   code = TREE_CODE (type);
  7586.  
  7587.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  7588.     {
  7589.       error ("switch quantity not an integer");
  7590.       exp = error_mark_node;
  7591.     }
  7592.   else
  7593.     {
  7594.       tree index;
  7595.  
  7596.       exp = default_conversion (exp);
  7597.       type = TREE_TYPE (exp);
  7598.       index = get_unwidened (exp, 0);
  7599.       /* We can't strip a conversion from a signed type to an unsigned,
  7600.      because if we did, int_fits_type_p would do the wrong thing
  7601.      when checking case values for being in range,
  7602.      and it's too hard to do the right thing.  */
  7603.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  7604.       == TREE_UNSIGNED (TREE_TYPE (index)))
  7605.     exp = index;
  7606.     }
  7607.  
  7608.   expand_start_case
  7609.     (1, fold (build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp)),
  7610.      type, "switch statement");
  7611.  
  7612.   return exp;
  7613. }
  7614.  
  7615. /* CONSTP remembers whether or not all the intervening pointers in the `to'
  7616.    type have been const.  */
  7617. int
  7618. comp_ptr_ttypes_real (to, from, constp)
  7619.      tree to, from;
  7620.      int constp;
  7621. {
  7622.   for (; ; to = TREE_TYPE (to), from = TREE_TYPE (from))
  7623.     {
  7624.       if (TREE_CODE (to) != TREE_CODE (from))
  7625.     return 0;
  7626.  
  7627.       /* Const and volatile mean something different for function types,
  7628.      so the usual checks are not appropriate.  */
  7629.       if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
  7630.     {
  7631.       if (TYPE_READONLY (from) > TYPE_READONLY (to)
  7632.           || TYPE_VOLATILE (from) > TYPE_VOLATILE (to))
  7633.         return 0;
  7634.  
  7635.       if (! constp
  7636.           && (TYPE_READONLY (to) > TYPE_READONLY (from)
  7637.           || TYPE_VOLATILE (to) > TYPE_READONLY (from)))
  7638.         return 0;
  7639.       constp &= TYPE_READONLY (to);
  7640.     }
  7641.  
  7642.       if (TREE_CODE (to) != POINTER_TYPE)
  7643.     return comptypes (TYPE_MAIN_VARIANT (to), TYPE_MAIN_VARIANT (from), 1);
  7644.     }
  7645. }
  7646.  
  7647. /* When comparing, say, char ** to char const **, this function takes the
  7648.    'char *' and 'char const *'.  Do not pass non-pointer types to this
  7649.    function.  */
  7650. int
  7651. comp_ptr_ttypes (to, from)
  7652.      tree to, from;
  7653. {
  7654.   return comp_ptr_ttypes_real (to, from, 1);
  7655. }
  7656.