home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gcc-2.3.3-src.lha / GNU / src / amiga / gcc-2.3.3 / cp-typeck.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  197KB  |  6,309 lines

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