gdb/eval.c - gdb

Functions defined

Source code

  1. /* Evaluate expressions for GDB.

  2.    Copyright (C) 1986-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "symtab.h"
  16. #include "gdbtypes.h"
  17. #include "value.h"
  18. #include "expression.h"
  19. #include "target.h"
  20. #include "frame.h"
  21. #include "gdbthread.h"
  22. #include "language.h"                /* For CAST_IS_CONVERSION.  */
  23. #include "f-lang.h"                /* For array bound stuff.  */
  24. #include "cp-abi.h"
  25. #include "infcall.h"
  26. #include "objc-lang.h"
  27. #include "block.h"
  28. #include "parser-defs.h"
  29. #include "cp-support.h"
  30. #include "ui-out.h"
  31. #include "regcache.h"
  32. #include "user-regs.h"
  33. #include "valprint.h"
  34. #include "gdb_obstack.h"
  35. #include "objfiles.h"
  36. #include <ctype.h>

  37. /* This is defined in valops.c */
  38. extern int overload_resolution;

  39. /* Prototypes for local functions.  */

  40. static struct value *evaluate_subexp_for_sizeof (struct expression *, int *,
  41.                                                  enum noside);

  42. static struct value *evaluate_subexp_for_address (struct expression *,
  43.                                                   int *, enum noside);

  44. static struct value *evaluate_struct_tuple (struct value *,
  45.                                             struct expression *, int *,
  46.                                             enum noside, int);

  47. static LONGEST init_array_element (struct value *, struct value *,
  48.                                    struct expression *, int *, enum noside,
  49.                                    LONGEST, LONGEST);

  50. struct value *
  51. evaluate_subexp (struct type *expect_type, struct expression *exp,
  52.                  int *pos, enum noside noside)
  53. {
  54.   struct cleanup *cleanups;
  55.   struct value *retval;
  56.   int cleanup_temps = 0;

  57.   if (*pos == 0 && target_has_execution
  58.       && exp->language_defn->la_language == language_cplus
  59.       && !thread_stack_temporaries_enabled_p (inferior_ptid))
  60.     {
  61.       cleanups = enable_thread_stack_temporaries (inferior_ptid);
  62.       cleanup_temps = 1;
  63.     }

  64.   retval = (*exp->language_defn->la_exp_desc->evaluate_exp)
  65.     (expect_type, exp, pos, noside);

  66.   if (cleanup_temps)
  67.     {
  68.       if (value_in_thread_stack_temporaries (retval, inferior_ptid))
  69.         retval = value_non_lval (retval);
  70.       do_cleanups (cleanups);
  71.     }

  72.   return retval;
  73. }

  74. /* Parse the string EXP as a C expression, evaluate it,
  75.    and return the result as a number.  */

  76. CORE_ADDR
  77. parse_and_eval_address (const char *exp)
  78. {
  79.   struct expression *expr = parse_expression (exp);
  80.   CORE_ADDR addr;
  81.   struct cleanup *old_chain =
  82.     make_cleanup (free_current_contents, &expr);

  83.   addr = value_as_address (evaluate_expression (expr));
  84.   do_cleanups (old_chain);
  85.   return addr;
  86. }

  87. /* Like parse_and_eval_address, but treats the value of the expression
  88.    as an integer, not an address, returns a LONGEST, not a CORE_ADDR.  */
  89. LONGEST
  90. parse_and_eval_long (const char *exp)
  91. {
  92.   struct expression *expr = parse_expression (exp);
  93.   LONGEST retval;
  94.   struct cleanup *old_chain =
  95.     make_cleanup (free_current_contents, &expr);

  96.   retval = value_as_long (evaluate_expression (expr));
  97.   do_cleanups (old_chain);
  98.   return (retval);
  99. }

  100. struct value *
  101. parse_and_eval (const char *exp)
  102. {
  103.   struct expression *expr = parse_expression (exp);
  104.   struct value *val;
  105.   struct cleanup *old_chain =
  106.     make_cleanup (free_current_contents, &expr);

  107.   val = evaluate_expression (expr);
  108.   do_cleanups (old_chain);
  109.   return val;
  110. }

  111. /* Parse up to a comma (or to a closeparen)
  112.    in the string EXPP as an expression, evaluate it, and return the value.
  113.    EXPP is advanced to point to the comma.  */

  114. struct value *
  115. parse_to_comma_and_eval (const char **expp)
  116. {
  117.   struct expression *expr = parse_exp_1 (expp, 0, (struct block *) 0, 1);
  118.   struct value *val;
  119.   struct cleanup *old_chain =
  120.     make_cleanup (free_current_contents, &expr);

  121.   val = evaluate_expression (expr);
  122.   do_cleanups (old_chain);
  123.   return val;
  124. }

  125. /* Evaluate an expression in internal prefix form
  126.    such as is constructed by parse.y.

  127.    See expression.h for info on the format of an expression.  */

  128. struct value *
  129. evaluate_expression (struct expression *exp)
  130. {
  131.   int pc = 0;

  132.   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
  133. }

  134. /* Evaluate an expression, avoiding all memory references
  135.    and getting a value whose type alone is correct.  */

  136. struct value *
  137. evaluate_type (struct expression *exp)
  138. {
  139.   int pc = 0;

  140.   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
  141. }

  142. /* Evaluate a subexpression, avoiding all memory references and
  143.    getting a value whose type alone is correct.  */

  144. struct value *
  145. evaluate_subexpression_type (struct expression *exp, int subexp)
  146. {
  147.   return evaluate_subexp (NULL_TYPE, exp, &subexp, EVAL_AVOID_SIDE_EFFECTS);
  148. }

  149. /* Find the current value of a watchpoint on EXP.  Return the value in
  150.    *VALP and *RESULTP and the chain of intermediate and final values
  151.    in *VAL_CHAIN.  RESULTP and VAL_CHAIN may be NULL if the caller does
  152.    not need them.

  153.    If PRESERVE_ERRORS is true, then exceptions are passed through.
  154.    Otherwise, if PRESERVE_ERRORS is false, then if a memory error
  155.    occurs while evaluating the expression, *RESULTP will be set to
  156.    NULL.  *RESULTP may be a lazy value, if the result could not be
  157.    read from memory.  It is used to determine whether a value is
  158.    user-specified (we should watch the whole value) or intermediate
  159.    (we should watch only the bit used to locate the final value).

  160.    If the final value, or any intermediate value, could not be read
  161.    from memory, *VALP will be set to NULL.  *VAL_CHAIN will still be
  162.    set to any referenced values.  *VALP will never be a lazy value.
  163.    This is the value which we store in struct breakpoint.

  164.    If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
  165.    value chain.  The caller must free the values individually.  If
  166.    VAL_CHAIN is NULL, all generated values will be left on the value
  167.    chain.  */

  168. void
  169. fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
  170.                     struct value **resultp, struct value **val_chain,
  171.                     int preserve_errors)
  172. {
  173.   struct value *mark, *new_mark, *result;
  174.   volatile struct gdb_exception ex;

  175.   *valp = NULL;
  176.   if (resultp)
  177.     *resultp = NULL;
  178.   if (val_chain)
  179.     *val_chain = NULL;

  180.   /* Evaluate the expression.  */
  181.   mark = value_mark ();
  182.   result = NULL;

  183.   TRY_CATCH (ex, RETURN_MASK_ALL)
  184.     {
  185.       result = evaluate_subexp (NULL_TYPE, exp, pc, EVAL_NORMAL);
  186.     }
  187.   if (ex.reason < 0)
  188.     {
  189.       /* Ignore memory errors if we want watchpoints pointing at
  190.          inaccessible memory to still be created; otherwise, throw the
  191.          error to some higher catcher.  */
  192.       switch (ex.error)
  193.         {
  194.         case MEMORY_ERROR:
  195.           if (!preserve_errors)
  196.             break;
  197.         default:
  198.           throw_exception (ex);
  199.           break;
  200.         }
  201.     }

  202.   new_mark = value_mark ();
  203.   if (mark == new_mark)
  204.     return;
  205.   if (resultp)
  206.     *resultp = result;

  207.   /* Make sure it's not lazy, so that after the target stops again we
  208.      have a non-lazy previous value to compare with.  */
  209.   if (result != NULL)
  210.     {
  211.       if (!value_lazy (result))
  212.         *valp = result;
  213.       else
  214.         {
  215.           volatile struct gdb_exception except;

  216.           TRY_CATCH (except, RETURN_MASK_ERROR)
  217.             {
  218.               value_fetch_lazy (result);
  219.               *valp = result;
  220.             }
  221.         }
  222.     }

  223.   if (val_chain)
  224.     {
  225.       /* Return the chain of intermediate values.  We use this to
  226.          decide which addresses to watch.  */
  227.       *val_chain = new_mark;
  228.       value_release_to_mark (mark);
  229.     }
  230. }

  231. /* Extract a field operation from an expression.  If the subexpression
  232.    of EXP starting at *SUBEXP is not a structure dereference
  233.    operation, return NULL.  Otherwise, return the name of the
  234.    dereferenced field, and advance *SUBEXP to point to the
  235.    subexpression of the left-hand-side of the dereference.  This is
  236.    used when completing field names.  */

  237. char *
  238. extract_field_op (struct expression *exp, int *subexp)
  239. {
  240.   int tem;
  241.   char *result;

  242.   if (exp->elts[*subexp].opcode != STRUCTOP_STRUCT
  243.       && exp->elts[*subexp].opcode != STRUCTOP_PTR)
  244.     return NULL;
  245.   tem = longest_to_int (exp->elts[*subexp + 1].longconst);
  246.   result = &exp->elts[*subexp + 2].string;
  247.   (*subexp) += 1 + 3 + BYTES_TO_EXP_ELEM (tem + 1);
  248.   return result;
  249. }

  250. /* This function evaluates brace-initializers (in C/C++) for
  251.    structure types.  */

  252. static struct value *
  253. evaluate_struct_tuple (struct value *struct_val,
  254.                        struct expression *exp,
  255.                        int *pos, enum noside noside, int nargs)
  256. {
  257.   struct type *struct_type = check_typedef (value_type (struct_val));
  258.   struct type *field_type;
  259.   int fieldno = -1;

  260.   while (--nargs >= 0)
  261.     {
  262.       struct value *val = NULL;
  263.       int bitpos, bitsize;
  264.       bfd_byte *addr;

  265.       fieldno++;
  266.       /* Skip static fields.  */
  267.       while (fieldno < TYPE_NFIELDS (struct_type)
  268.              && field_is_static (&TYPE_FIELD (struct_type,
  269.                                               fieldno)))
  270.         fieldno++;
  271.       if (fieldno >= TYPE_NFIELDS (struct_type))
  272.         error (_("too many initializers"));
  273.       field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
  274.       if (TYPE_CODE (field_type) == TYPE_CODE_UNION
  275.           && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
  276.         error (_("don't know which variant you want to set"));

  277.       /* Here, struct_type is the type of the inner struct,
  278.          while substruct_type is the type of the inner struct.
  279.          These are the same for normal structures, but a variant struct
  280.          contains anonymous union fields that contain substruct fields.
  281.          The value fieldno is the index of the top-level (normal or
  282.          anonymous union) field in struct_field, while the value
  283.          subfieldno is the index of the actual real (named inner) field
  284.          in substruct_type.  */

  285.       field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
  286.       if (val == 0)
  287.         val = evaluate_subexp (field_type, exp, pos, noside);

  288.       /* Now actually set the field in struct_val.  */

  289.       /* Assign val to field fieldno.  */
  290.       if (value_type (val) != field_type)
  291.         val = value_cast (field_type, val);

  292.       bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
  293.       bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
  294.       addr = value_contents_writeable (struct_val) + bitpos / 8;
  295.       if (bitsize)
  296.         modify_field (struct_type, addr,
  297.                       value_as_long (val), bitpos % 8, bitsize);
  298.       else
  299.         memcpy (addr, value_contents (val),
  300.                 TYPE_LENGTH (value_type (val)));

  301.     }
  302.   return struct_val;
  303. }

  304. /* Recursive helper function for setting elements of array tuples.
  305.    The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND); the
  306.    element value is ELEMENT; EXP, POS and NOSIDE are as usual.
  307.    Evaluates index expresions and sets the specified element(s) of
  308.    ARRAY to ELEMENT.  Returns last index value.  */

  309. static LONGEST
  310. init_array_element (struct value *array, struct value *element,
  311.                     struct expression *exp, int *pos,
  312.                     enum noside noside, LONGEST low_bound, LONGEST high_bound)
  313. {
  314.   LONGEST index;
  315.   int element_size = TYPE_LENGTH (value_type (element));

  316.   if (exp->elts[*pos].opcode == BINOP_COMMA)
  317.     {
  318.       (*pos)++;
  319.       init_array_element (array, element, exp, pos, noside,
  320.                           low_bound, high_bound);
  321.       return init_array_element (array, element,
  322.                                  exp, pos, noside, low_bound, high_bound);
  323.     }
  324.   else
  325.     {
  326.       index = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
  327.       if (index < low_bound || index > high_bound)
  328.         error (_("tuple index out of range"));
  329.       memcpy (value_contents_raw (array) + (index - low_bound) * element_size,
  330.               value_contents (element), element_size);
  331.     }
  332.   return index;
  333. }

  334. static struct value *
  335. value_f90_subarray (struct value *array,
  336.                     struct expression *exp, int *pos, enum noside noside)
  337. {
  338.   int pc = (*pos) + 1;
  339.   LONGEST low_bound, high_bound;
  340.   struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
  341.   enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);

  342.   *pos += 3;

  343.   if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
  344.     low_bound = TYPE_LOW_BOUND (range);
  345.   else
  346.     low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));

  347.   if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
  348.     high_bound = TYPE_HIGH_BOUND (range);
  349.   else
  350.     high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));

  351.   return value_slice (array, low_bound, high_bound - low_bound + 1);
  352. }


  353. /* Promote value ARG1 as appropriate before performing a unary operation
  354.    on this argument.
  355.    If the result is not appropriate for any particular language then it
  356.    needs to patch this function.  */

  357. void
  358. unop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
  359.               struct value **arg1)
  360. {
  361.   struct type *type1;

  362.   *arg1 = coerce_ref (*arg1);
  363.   type1 = check_typedef (value_type (*arg1));

  364.   if (is_integral_type (type1))
  365.     {
  366.       switch (language->la_language)
  367.         {
  368.         default:
  369.           /* Perform integral promotion for ANSI C/C++.
  370.              If not appropropriate for any particular language
  371.              it needs to modify this function.  */
  372.           {
  373.             struct type *builtin_int = builtin_type (gdbarch)->builtin_int;

  374.             if (TYPE_LENGTH (type1) < TYPE_LENGTH (builtin_int))
  375.               *arg1 = value_cast (builtin_int, *arg1);
  376.           }
  377.           break;
  378.         }
  379.     }
  380. }

  381. /* Promote values ARG1 and ARG2 as appropriate before performing a binary
  382.    operation on those two operands.
  383.    If the result is not appropriate for any particular language then it
  384.    needs to patch this function.  */

  385. void
  386. binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
  387.                struct value **arg1, struct value **arg2)
  388. {
  389.   struct type *promoted_type = NULL;
  390.   struct type *type1;
  391.   struct type *type2;

  392.   *arg1 = coerce_ref (*arg1);
  393.   *arg2 = coerce_ref (*arg2);

  394.   type1 = check_typedef (value_type (*arg1));
  395.   type2 = check_typedef (value_type (*arg2));

  396.   if ((TYPE_CODE (type1) != TYPE_CODE_FLT
  397.        && TYPE_CODE (type1) != TYPE_CODE_DECFLOAT
  398.        && !is_integral_type (type1))
  399.       || (TYPE_CODE (type2) != TYPE_CODE_FLT
  400.           && TYPE_CODE (type2) != TYPE_CODE_DECFLOAT
  401.           && !is_integral_type (type2)))
  402.     return;

  403.   if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT
  404.       || TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
  405.     {
  406.       /* No promotion required.  */
  407.     }
  408.   else if (TYPE_CODE (type1) == TYPE_CODE_FLT
  409.            || TYPE_CODE (type2) == TYPE_CODE_FLT)
  410.     {
  411.       switch (language->la_language)
  412.         {
  413.         case language_c:
  414.         case language_cplus:
  415.         case language_asm:
  416.         case language_objc:
  417.         case language_opencl:
  418.           /* No promotion required.  */
  419.           break;

  420.         default:
  421.           /* For other languages the result type is unchanged from gdb
  422.              version 6.7 for backward compatibility.
  423.              If either arg was long double, make sure that value is also long
  424.              double.  Otherwise use double.  */
  425.           if (TYPE_LENGTH (type1) * 8 > gdbarch_double_bit (gdbarch)
  426.               || TYPE_LENGTH (type2) * 8 > gdbarch_double_bit (gdbarch))
  427.             promoted_type = builtin_type (gdbarch)->builtin_long_double;
  428.           else
  429.             promoted_type = builtin_type (gdbarch)->builtin_double;
  430.           break;
  431.         }
  432.     }
  433.   else if (TYPE_CODE (type1) == TYPE_CODE_BOOL
  434.            && TYPE_CODE (type2) == TYPE_CODE_BOOL)
  435.     {
  436.       /* No promotion required.  */
  437.     }
  438.   else
  439.     /* Integral operations here.  */
  440.     /* FIXME: Also mixed integral/booleans, with result an integer.  */
  441.     {
  442.       const struct builtin_type *builtin = builtin_type (gdbarch);
  443.       unsigned int promoted_len1 = TYPE_LENGTH (type1);
  444.       unsigned int promoted_len2 = TYPE_LENGTH (type2);
  445.       int is_unsigned1 = TYPE_UNSIGNED (type1);
  446.       int is_unsigned2 = TYPE_UNSIGNED (type2);
  447.       unsigned int result_len;
  448.       int unsigned_operation;

  449.       /* Determine type length and signedness after promotion for
  450.          both operands.  */
  451.       if (promoted_len1 < TYPE_LENGTH (builtin->builtin_int))
  452.         {
  453.           is_unsigned1 = 0;
  454.           promoted_len1 = TYPE_LENGTH (builtin->builtin_int);
  455.         }
  456.       if (promoted_len2 < TYPE_LENGTH (builtin->builtin_int))
  457.         {
  458.           is_unsigned2 = 0;
  459.           promoted_len2 = TYPE_LENGTH (builtin->builtin_int);
  460.         }

  461.       if (promoted_len1 > promoted_len2)
  462.         {
  463.           unsigned_operation = is_unsigned1;
  464.           result_len = promoted_len1;
  465.         }
  466.       else if (promoted_len2 > promoted_len1)
  467.         {
  468.           unsigned_operation = is_unsigned2;
  469.           result_len = promoted_len2;
  470.         }
  471.       else
  472.         {
  473.           unsigned_operation = is_unsigned1 || is_unsigned2;
  474.           result_len = promoted_len1;
  475.         }

  476.       switch (language->la_language)
  477.         {
  478.         case language_c:
  479.         case language_cplus:
  480.         case language_asm:
  481.         case language_objc:
  482.           if (result_len <= TYPE_LENGTH (builtin->builtin_int))
  483.             {
  484.               promoted_type = (unsigned_operation
  485.                                ? builtin->builtin_unsigned_int
  486.                                : builtin->builtin_int);
  487.             }
  488.           else if (result_len <= TYPE_LENGTH (builtin->builtin_long))
  489.             {
  490.               promoted_type = (unsigned_operation
  491.                                ? builtin->builtin_unsigned_long
  492.                                : builtin->builtin_long);
  493.             }
  494.           else
  495.             {
  496.               promoted_type = (unsigned_operation
  497.                                ? builtin->builtin_unsigned_long_long
  498.                                : builtin->builtin_long_long);
  499.             }
  500.           break;
  501.         case language_opencl:
  502.           if (result_len <= TYPE_LENGTH (lookup_signed_typename
  503.                                          (language, gdbarch, "int")))
  504.             {
  505.               promoted_type =
  506.                 (unsigned_operation
  507.                  ? lookup_unsigned_typename (language, gdbarch, "int")
  508.                  : lookup_signed_typename (language, gdbarch, "int"));
  509.             }
  510.           else if (result_len <= TYPE_LENGTH (lookup_signed_typename
  511.                                               (language, gdbarch, "long")))
  512.             {
  513.               promoted_type =
  514.                 (unsigned_operation
  515.                  ? lookup_unsigned_typename (language, gdbarch, "long")
  516.                  : lookup_signed_typename (language, gdbarch,"long"));
  517.             }
  518.           break;
  519.         default:
  520.           /* For other languages the result type is unchanged from gdb
  521.              version 6.7 for backward compatibility.
  522.              If either arg was long long, make sure that value is also long
  523.              long.  Otherwise use long.  */
  524.           if (unsigned_operation)
  525.             {
  526.               if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
  527.                 promoted_type = builtin->builtin_unsigned_long_long;
  528.               else
  529.                 promoted_type = builtin->builtin_unsigned_long;
  530.             }
  531.           else
  532.             {
  533.               if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
  534.                 promoted_type = builtin->builtin_long_long;
  535.               else
  536.                 promoted_type = builtin->builtin_long;
  537.             }
  538.           break;
  539.         }
  540.     }

  541.   if (promoted_type)
  542.     {
  543.       /* Promote both operands to common type.  */
  544.       *arg1 = value_cast (promoted_type, *arg1);
  545.       *arg2 = value_cast (promoted_type, *arg2);
  546.     }
  547. }

  548. static int
  549. ptrmath_type_p (const struct language_defn *lang, struct type *type)
  550. {
  551.   type = check_typedef (type);
  552.   if (TYPE_CODE (type) == TYPE_CODE_REF)
  553.     type = TYPE_TARGET_TYPE (type);

  554.   switch (TYPE_CODE (type))
  555.     {
  556.     case TYPE_CODE_PTR:
  557.     case TYPE_CODE_FUNC:
  558.       return 1;

  559.     case TYPE_CODE_ARRAY:
  560.       return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays;

  561.     default:
  562.       return 0;
  563.     }
  564. }

  565. /* Constructs a fake method with the given parameter types.
  566.    This function is used by the parser to construct an "expected"
  567.    type for method overload resolution.  */

  568. static struct type *
  569. make_params (int num_types, struct type **param_types)
  570. {
  571.   struct type *type = XCNEW (struct type);
  572.   TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
  573.   TYPE_LENGTH (type) = 1;
  574.   TYPE_CODE (type) = TYPE_CODE_METHOD;
  575.   TYPE_VPTR_FIELDNO (type) = -1;
  576.   TYPE_CHAIN (type) = type;
  577.   if (num_types > 0)
  578.     {
  579.       if (param_types[num_types - 1] == NULL)
  580.         {
  581.           --num_types;
  582.           TYPE_VARARGS (type) = 1;
  583.         }
  584.       else if (TYPE_CODE (check_typedef (param_types[num_types - 1]))
  585.                == TYPE_CODE_VOID)
  586.         {
  587.           --num_types;
  588.           /* Caller should have ensured this.  */
  589.           gdb_assert (num_types == 0);
  590.           TYPE_PROTOTYPED (type) = 1;
  591.         }
  592.     }

  593.   TYPE_NFIELDS (type) = num_types;
  594.   TYPE_FIELDS (type) = (struct field *)
  595.     TYPE_ZALLOC (type, sizeof (struct field) * num_types);

  596.   while (num_types-- > 0)
  597.     TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];

  598.   return type;
  599. }

  600. struct value *
  601. evaluate_subexp_standard (struct type *expect_type,
  602.                           struct expression *exp, int *pos,
  603.                           enum noside noside)
  604. {
  605.   enum exp_opcode op;
  606.   int tem, tem2, tem3;
  607.   int pc, pc2 = 0, oldpos;
  608.   struct value *arg1 = NULL;
  609.   struct value *arg2 = NULL;
  610.   struct value *arg3;
  611.   struct type *type;
  612.   int nargs;
  613.   struct value **argvec;
  614.   int code;
  615.   int ix;
  616.   long mem_offset;
  617.   struct type **arg_types;
  618.   int save_pos1;
  619.   struct symbol *function = NULL;
  620.   char *function_name = NULL;

  621.   pc = (*pos)++;
  622.   op = exp->elts[pc].opcode;

  623.   switch (op)
  624.     {
  625.     case OP_SCOPE:
  626.       tem = longest_to_int (exp->elts[pc + 2].longconst);
  627.       (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
  628.       if (noside == EVAL_SKIP)
  629.         goto nosideret;
  630.       arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
  631.                                   &exp->elts[pc + 3].string,
  632.                                   expect_type, 0, noside);
  633.       if (arg1 == NULL)
  634.         error (_("There is no field named %s"), &exp->elts[pc + 3].string);
  635.       return arg1;

  636.     case OP_LONG:
  637.       (*pos) += 3;
  638.       return value_from_longest (exp->elts[pc + 1].type,
  639.                                  exp->elts[pc + 2].longconst);

  640.     case OP_DOUBLE:
  641.       (*pos) += 3;
  642.       return value_from_double (exp->elts[pc + 1].type,
  643.                                 exp->elts[pc + 2].doubleconst);

  644.     case OP_DECFLOAT:
  645.       (*pos) += 3;
  646.       return value_from_decfloat (exp->elts[pc + 1].type,
  647.                                   exp->elts[pc + 2].decfloatconst);

  648.     case OP_ADL_FUNC:
  649.     case OP_VAR_VALUE:
  650.       (*pos) += 3;
  651.       if (noside == EVAL_SKIP)
  652.         goto nosideret;

  653.       /* JYG: We used to just return value_zero of the symbol type
  654.          if we're asked to avoid side effects.  Otherwise we return
  655.          value_of_variable (...).  However I'm not sure if
  656.          value_of_variable () has any side effect.
  657.          We need a full value object returned here for whatis_exp ()
  658.          to call evaluate_type () and then pass the full value to
  659.          value_rtti_target_type () if we are dealing with a pointer
  660.          or reference to a base class and print object is on.  */

  661.       {
  662.         volatile struct gdb_exception except;
  663.         struct value *ret = NULL;

  664.         TRY_CATCH (except, RETURN_MASK_ERROR)
  665.           {
  666.             ret = value_of_variable (exp->elts[pc + 2].symbol,
  667.                                      exp->elts[pc + 1].block);
  668.           }

  669.         if (except.reason < 0)
  670.           {
  671.             if (noside == EVAL_AVOID_SIDE_EFFECTS)
  672.               ret = value_zero (SYMBOL_TYPE (exp->elts[pc + 2].symbol),
  673.                                 not_lval);
  674.             else
  675.               throw_exception (except);
  676.           }

  677.         return ret;
  678.       }

  679.     case OP_VAR_ENTRY_VALUE:
  680.       (*pos) += 2;
  681.       if (noside == EVAL_SKIP)
  682.         goto nosideret;

  683.       {
  684.         struct symbol *sym = exp->elts[pc + 1].symbol;
  685.         struct frame_info *frame;

  686.         if (noside == EVAL_AVOID_SIDE_EFFECTS)
  687.           return value_zero (SYMBOL_TYPE (sym), not_lval);

  688.         if (SYMBOL_COMPUTED_OPS (sym) == NULL
  689.             || SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
  690.           error (_("Symbol \"%s\" does not have any specific entry value"),
  691.                  SYMBOL_PRINT_NAME (sym));

  692.         frame = get_selected_frame (NULL);
  693.         return SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry (sym, frame);
  694.       }

  695.     case OP_LAST:
  696.       (*pos) += 2;
  697.       return
  698.         access_value_history (longest_to_int (exp->elts[pc + 1].longconst));

  699.     case OP_REGISTER:
  700.       {
  701.         const char *name = &exp->elts[pc + 2].string;
  702.         int regno;
  703.         struct value *val;

  704.         (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
  705.         regno = user_reg_map_name_to_regnum (exp->gdbarch,
  706.                                              name, strlen (name));
  707.         if (regno == -1)
  708.           error (_("Register $%s not available."), name);

  709.         /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
  710.            a value with the appropriate register type.  Unfortunately,
  711.            we don't have easy access to the type of user registers.
  712.            So for these registers, we fetch the register value regardless
  713.            of the evaluation mode.  */
  714.         if (noside == EVAL_AVOID_SIDE_EFFECTS
  715.             && regno < gdbarch_num_regs (exp->gdbarch)
  716.                         + gdbarch_num_pseudo_regs (exp->gdbarch))
  717.           val = value_zero (register_type (exp->gdbarch, regno), not_lval);
  718.         else
  719.           val = value_of_register (regno, get_selected_frame (NULL));
  720.         if (val == NULL)
  721.           error (_("Value of register %s not available."), name);
  722.         else
  723.           return val;
  724.       }
  725.     case OP_BOOL:
  726.       (*pos) += 2;
  727.       type = language_bool_type (exp->language_defn, exp->gdbarch);
  728.       return value_from_longest (type, exp->elts[pc + 1].longconst);

  729.     case OP_INTERNALVAR:
  730.       (*pos) += 2;
  731.       return value_of_internalvar (exp->gdbarch,
  732.                                    exp->elts[pc + 1].internalvar);

  733.     case OP_STRING:
  734.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  735.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  736.       if (noside == EVAL_SKIP)
  737.         goto nosideret;
  738.       type = language_string_char_type (exp->language_defn, exp->gdbarch);
  739.       return value_string (&exp->elts[pc + 2].string, tem, type);

  740.     case OP_OBJC_NSSTRING:                /* Objective C Foundation Class
  741.                                            NSString constant.  */
  742.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  743.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  744.       if (noside == EVAL_SKIP)
  745.         {
  746.           goto nosideret;
  747.         }
  748.       return value_nsstring (exp->gdbarch, &exp->elts[pc + 2].string, tem + 1);

  749.     case OP_ARRAY:
  750.       (*pos) += 3;
  751.       tem2 = longest_to_int (exp->elts[pc + 1].longconst);
  752.       tem3 = longest_to_int (exp->elts[pc + 2].longconst);
  753.       nargs = tem3 - tem2 + 1;
  754.       type = expect_type ? check_typedef (expect_type) : NULL_TYPE;

  755.       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
  756.           && TYPE_CODE (type) == TYPE_CODE_STRUCT)
  757.         {
  758.           struct value *rec = allocate_value (expect_type);

  759.           memset (value_contents_raw (rec), '\0', TYPE_LENGTH (type));
  760.           return evaluate_struct_tuple (rec, exp, pos, noside, nargs);
  761.         }

  762.       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
  763.           && TYPE_CODE (type) == TYPE_CODE_ARRAY)
  764.         {
  765.           struct type *range_type = TYPE_INDEX_TYPE (type);
  766.           struct type *element_type = TYPE_TARGET_TYPE (type);
  767.           struct value *array = allocate_value (expect_type);
  768.           int element_size = TYPE_LENGTH (check_typedef (element_type));
  769.           LONGEST low_bound, high_bound, index;

  770.           if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
  771.             {
  772.               low_bound = 0;
  773.               high_bound = (TYPE_LENGTH (type) / element_size) - 1;
  774.             }
  775.           index = low_bound;
  776.           memset (value_contents_raw (array), 0, TYPE_LENGTH (expect_type));
  777.           for (tem = nargs; --nargs >= 0;)
  778.             {
  779.               struct value *element;
  780.               int index_pc = 0;

  781.               element = evaluate_subexp (element_type, exp, pos, noside);
  782.               if (value_type (element) != element_type)
  783.                 element = value_cast (element_type, element);
  784.               if (index_pc)
  785.                 {
  786.                   int continue_pc = *pos;

  787.                   *pos = index_pc;
  788.                   index = init_array_element (array, element, exp, pos, noside,
  789.                                               low_bound, high_bound);
  790.                   *pos = continue_pc;
  791.                 }
  792.               else
  793.                 {
  794.                   if (index > high_bound)
  795.                     /* To avoid memory corruption.  */
  796.                     error (_("Too many array elements"));
  797.                   memcpy (value_contents_raw (array)
  798.                           + (index - low_bound) * element_size,
  799.                           value_contents (element),
  800.                           element_size);
  801.                 }
  802.               index++;
  803.             }
  804.           return array;
  805.         }

  806.       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
  807.           && TYPE_CODE (type) == TYPE_CODE_SET)
  808.         {
  809.           struct value *set = allocate_value (expect_type);
  810.           gdb_byte *valaddr = value_contents_raw (set);
  811.           struct type *element_type = TYPE_INDEX_TYPE (type);
  812.           struct type *check_type = element_type;
  813.           LONGEST low_bound, high_bound;

  814.           /* Get targettype of elementtype.  */
  815.           while (TYPE_CODE (check_type) == TYPE_CODE_RANGE
  816.                  || TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
  817.             check_type = TYPE_TARGET_TYPE (check_type);

  818.           if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
  819.             error (_("(power)set type with unknown size"));
  820.           memset (valaddr, '\0', TYPE_LENGTH (type));
  821.           for (tem = 0; tem < nargs; tem++)
  822.             {
  823.               LONGEST range_low, range_high;
  824.               struct type *range_low_type, *range_high_type;
  825.               struct value *elem_val;

  826.               elem_val = evaluate_subexp (element_type, exp, pos, noside);
  827.               range_low_type = range_high_type = value_type (elem_val);
  828.               range_low = range_high = value_as_long (elem_val);

  829.               /* Check types of elements to avoid mixture of elements from
  830.                  different types. Also check if type of element is "compatible"
  831.                  with element type of powerset.  */
  832.               if (TYPE_CODE (range_low_type) == TYPE_CODE_RANGE)
  833.                 range_low_type = TYPE_TARGET_TYPE (range_low_type);
  834.               if (TYPE_CODE (range_high_type) == TYPE_CODE_RANGE)
  835.                 range_high_type = TYPE_TARGET_TYPE (range_high_type);
  836.               if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type))
  837.                   || (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM
  838.                       && (range_low_type != range_high_type)))
  839.                 /* different element modes.  */
  840.                 error (_("POWERSET tuple elements of different mode"));
  841.               if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type))
  842.                   || (TYPE_CODE (check_type) == TYPE_CODE_ENUM
  843.                       && range_low_type != check_type))
  844.                 error (_("incompatible POWERSET tuple elements"));
  845.               if (range_low > range_high)
  846.                 {
  847.                   warning (_("empty POWERSET tuple range"));
  848.                   continue;
  849.                 }
  850.               if (range_low < low_bound || range_high > high_bound)
  851.                 error (_("POWERSET tuple element out of range"));
  852.               range_low -= low_bound;
  853.               range_high -= low_bound;
  854.               for (; range_low <= range_high; range_low++)
  855.                 {
  856.                   int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;

  857.                   if (gdbarch_bits_big_endian (exp->gdbarch))
  858.                     bit_index = TARGET_CHAR_BIT - 1 - bit_index;
  859.                   valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
  860.                     |= 1 << bit_index;
  861.                 }
  862.             }
  863.           return set;
  864.         }

  865.       argvec = (struct value **) alloca (sizeof (struct value *) * nargs);
  866.       for (tem = 0; tem < nargs; tem++)
  867.         {
  868.           /* Ensure that array expressions are coerced into pointer
  869.              objects.  */
  870.           argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
  871.         }
  872.       if (noside == EVAL_SKIP)
  873.         goto nosideret;
  874.       return value_array (tem2, tem3, argvec);

  875.     case TERNOP_SLICE:
  876.       {
  877.         struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  878.         int lowbound
  879.           = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
  880.         int upper
  881.           = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));

  882.         if (noside == EVAL_SKIP)
  883.           goto nosideret;
  884.         return value_slice (array, lowbound, upper - lowbound + 1);
  885.       }

  886.     case TERNOP_COND:
  887.       /* Skip third and second args to evaluate the first one.  */
  888.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  889.       if (value_logical_not (arg1))
  890.         {
  891.           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  892.           return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  893.         }
  894.       else
  895.         {
  896.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  897.           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  898.           return arg2;
  899.         }

  900.     case OP_OBJC_SELECTOR:
  901.       {                                /* Objective C @selector operator.  */
  902.         char *sel = &exp->elts[pc + 2].string;
  903.         int len = longest_to_int (exp->elts[pc + 1].longconst);
  904.         struct type *selector_type;

  905.         (*pos) += 3 + BYTES_TO_EXP_ELEM (len + 1);
  906.         if (noside == EVAL_SKIP)
  907.           goto nosideret;

  908.         if (sel[len] != 0)
  909.           sel[len] = 0;                /* Make sure it's terminated.  */

  910.         selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
  911.         return value_from_longest (selector_type,
  912.                                    lookup_child_selector (exp->gdbarch, sel));
  913.       }

  914.     case OP_OBJC_MSGCALL:
  915.       {                                /* Objective C message (method) call.  */

  916.         CORE_ADDR responds_selector = 0;
  917.         CORE_ADDR method_selector = 0;

  918.         CORE_ADDR selector = 0;

  919.         int struct_return = 0;
  920.         int sub_no_side = 0;

  921.         struct value *msg_send = NULL;
  922.         struct value *msg_send_stret = NULL;
  923.         int gnu_runtime = 0;

  924.         struct value *target = NULL;
  925.         struct value *method = NULL;
  926.         struct value *called_method = NULL;

  927.         struct type *selector_type = NULL;
  928.         struct type *long_type;

  929.         struct value *ret = NULL;
  930.         CORE_ADDR addr = 0;

  931.         selector = exp->elts[pc + 1].longconst;
  932.         nargs = exp->elts[pc + 2].longconst;
  933.         argvec = (struct value **) alloca (sizeof (struct value *)
  934.                                            * (nargs + 5));

  935.         (*pos) += 3;

  936.         long_type = builtin_type (exp->gdbarch)->builtin_long;
  937.         selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;

  938.         if (noside == EVAL_AVOID_SIDE_EFFECTS)
  939.           sub_no_side = EVAL_NORMAL;
  940.         else
  941.           sub_no_side = noside;

  942.         target = evaluate_subexp (selector_type, exp, pos, sub_no_side);

  943.         if (value_as_long (target) == 0)
  944.            return value_from_longest (long_type, 0);

  945.         if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0).minsym)
  946.           gnu_runtime = 1;

  947.         /* Find the method dispatch (Apple runtime) or method lookup
  948.            (GNU runtime) function for Objective-C.  These will be used
  949.            to lookup the symbol information for the method.  If we
  950.            can't find any symbol information, then we'll use these to
  951.            call the method, otherwise we can call the method
  952.            directly.  The msg_send_stret function is used in the special
  953.            case of a method that returns a structure (Apple runtime
  954.            only).  */
  955.         if (gnu_runtime)
  956.           {
  957.             struct type *type = selector_type;

  958.             type = lookup_function_type (type);
  959.             type = lookup_pointer_type (type);
  960.             type = lookup_function_type (type);
  961.             type = lookup_pointer_type (type);

  962.             msg_send = find_function_in_inferior ("objc_msg_lookup", NULL);
  963.             msg_send_stret
  964.               = find_function_in_inferior ("objc_msg_lookup", NULL);

  965.             msg_send = value_from_pointer (type, value_as_address (msg_send));
  966.             msg_send_stret = value_from_pointer (type,
  967.                                         value_as_address (msg_send_stret));
  968.           }
  969.         else
  970.           {
  971.             msg_send = find_function_in_inferior ("objc_msgSend", NULL);
  972.             /* Special dispatcher for methods returning structs.  */
  973.             msg_send_stret
  974.               = find_function_in_inferior ("objc_msgSend_stret", NULL);
  975.           }

  976.         /* Verify the target object responds to this method.  The
  977.            standard top-level 'Object' class uses a different name for
  978.            the verification method than the non-standard, but more
  979.            often used, 'NSObject' class.  Make sure we check for both.  */

  980.         responds_selector
  981.           = lookup_child_selector (exp->gdbarch, "respondsToSelector:");
  982.         if (responds_selector == 0)
  983.           responds_selector
  984.             = lookup_child_selector (exp->gdbarch, "respondsTo:");

  985.         if (responds_selector == 0)
  986.           error (_("no 'respondsTo:' or 'respondsToSelector:' method"));

  987.         method_selector
  988.           = lookup_child_selector (exp->gdbarch, "methodForSelector:");
  989.         if (method_selector == 0)
  990.           method_selector
  991.             = lookup_child_selector (exp->gdbarch, "methodFor:");

  992.         if (method_selector == 0)
  993.           error (_("no 'methodFor:' or 'methodForSelector:' method"));

  994.         /* Call the verification method, to make sure that the target
  995.          class implements the desired method.  */

  996.         argvec[0] = msg_send;
  997.         argvec[1] = target;
  998.         argvec[2] = value_from_longest (long_type, responds_selector);
  999.         argvec[3] = value_from_longest (long_type, selector);
  1000.         argvec[4] = 0;

  1001.         ret = call_function_by_hand (argvec[0], 3, argvec + 1);
  1002.         if (gnu_runtime)
  1003.           {
  1004.             /* Function objc_msg_lookup returns a pointer.  */
  1005.             argvec[0] = ret;
  1006.             ret = call_function_by_hand (argvec[0], 3, argvec + 1);
  1007.           }
  1008.         if (value_as_long (ret) == 0)
  1009.           error (_("Target does not respond to this message selector."));

  1010.         /* Call "methodForSelector:" method, to get the address of a
  1011.            function method that implements this selector for this
  1012.            class.  If we can find a symbol at that address, then we
  1013.            know the return type, parameter types etc.  (that's a good
  1014.            thing).  */

  1015.         argvec[0] = msg_send;
  1016.         argvec[1] = target;
  1017.         argvec[2] = value_from_longest (long_type, method_selector);
  1018.         argvec[3] = value_from_longest (long_type, selector);
  1019.         argvec[4] = 0;

  1020.         ret = call_function_by_hand (argvec[0], 3, argvec + 1);
  1021.         if (gnu_runtime)
  1022.           {
  1023.             argvec[0] = ret;
  1024.             ret = call_function_by_hand (argvec[0], 3, argvec + 1);
  1025.           }

  1026.         /* ret should now be the selector.  */

  1027.         addr = value_as_long (ret);
  1028.         if (addr)
  1029.           {
  1030.             struct symbol *sym = NULL;

  1031.             /* The address might point to a function descriptor;
  1032.                resolve it to the actual code address instead.  */
  1033.             addr = gdbarch_convert_from_func_ptr_addr (exp->gdbarch, addr,
  1034.                                                        &current_target);

  1035.             /* Is it a high_level symbol?  */
  1036.             sym = find_pc_function (addr);
  1037.             if (sym != NULL)
  1038.               method = value_of_variable (sym, 0);
  1039.           }

  1040.         /* If we found a method with symbol information, check to see
  1041.            if it returns a struct.  Otherwise assume it doesn't.  */

  1042.         if (method)
  1043.           {
  1044.             CORE_ADDR funaddr;
  1045.             struct type *val_type;

  1046.             funaddr = find_function_addr (method, &val_type);

  1047.             block_for_pc (funaddr);

  1048.             CHECK_TYPEDEF (val_type);

  1049.             if ((val_type == NULL)
  1050.                 || (TYPE_CODE(val_type) == TYPE_CODE_ERROR))
  1051.               {
  1052.                 if (expect_type != NULL)
  1053.                   val_type = expect_type;
  1054.               }

  1055.             struct_return = using_struct_return (exp->gdbarch, method,
  1056.                                                  val_type);
  1057.           }
  1058.         else if (expect_type != NULL)
  1059.           {
  1060.             struct_return = using_struct_return (exp->gdbarch, NULL,
  1061.                                                  check_typedef (expect_type));
  1062.           }

  1063.         /* Found a function symbol.  Now we will substitute its
  1064.            value in place of the message dispatcher (obj_msgSend),
  1065.            so that we call the method directly instead of thru
  1066.            the dispatcher.  The main reason for doing this is that
  1067.            we can now evaluate the return value and parameter values
  1068.            according to their known data types, in case we need to
  1069.            do things like promotion, dereferencing, special handling
  1070.            of structs and doubles, etc.

  1071.            We want to use the type signature of 'method', but still
  1072.            jump to objc_msgSend() or objc_msgSend_stret() to better
  1073.            mimic the behavior of the runtime.  */

  1074.         if (method)
  1075.           {
  1076.             if (TYPE_CODE (value_type (method)) != TYPE_CODE_FUNC)
  1077.               error (_("method address has symbol information "
  1078.                        "with non-function type; skipping"));

  1079.             /* Create a function pointer of the appropriate type, and
  1080.                replace its value with the value of msg_send or
  1081.                msg_send_stret.  We must use a pointer here, as
  1082.                msg_send and msg_send_stret are of pointer type, and
  1083.                the representation may be different on systems that use
  1084.                function descriptors.  */
  1085.             if (struct_return)
  1086.               called_method
  1087.                 = value_from_pointer (lookup_pointer_type (value_type (method)),
  1088.                                       value_as_address (msg_send_stret));
  1089.             else
  1090.               called_method
  1091.                 = value_from_pointer (lookup_pointer_type (value_type (method)),
  1092.                                       value_as_address (msg_send));
  1093.           }
  1094.         else
  1095.           {
  1096.             if (struct_return)
  1097.               called_method = msg_send_stret;
  1098.             else
  1099.               called_method = msg_send;
  1100.           }

  1101.         if (noside == EVAL_SKIP)
  1102.           goto nosideret;

  1103.         if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1104.           {
  1105.             /* If the return type doesn't look like a function type,
  1106.                call an error.  This can happen if somebody tries to
  1107.                turn a variable into a function call.  This is here
  1108.                because people often want to call, eg, strcmp, which
  1109.                gdb doesn't know is a function.  If gdb isn't asked for
  1110.                it's opinion (ie. through "whatis"), it won't offer
  1111.                it.  */

  1112.             struct type *type = value_type (called_method);

  1113.             if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
  1114.               type = TYPE_TARGET_TYPE (type);
  1115.             type = TYPE_TARGET_TYPE (type);

  1116.             if (type)
  1117.             {
  1118.               if ((TYPE_CODE (type) == TYPE_CODE_ERROR) && expect_type)
  1119.                 return allocate_value (expect_type);
  1120.               else
  1121.                 return allocate_value (type);
  1122.             }
  1123.             else
  1124.               error (_("Expression of type other than "
  1125.                        "\"method returning ...\" used as a method"));
  1126.           }

  1127.         /* Now depending on whether we found a symbol for the method,
  1128.            we will either call the runtime dispatcher or the method
  1129.            directly.  */

  1130.         argvec[0] = called_method;
  1131.         argvec[1] = target;
  1132.         argvec[2] = value_from_longest (long_type, selector);
  1133.         /* User-supplied arguments.  */
  1134.         for (tem = 0; tem < nargs; tem++)
  1135.           argvec[tem + 3] = evaluate_subexp_with_coercion (exp, pos, noside);
  1136.         argvec[tem + 3] = 0;

  1137.         if (gnu_runtime && (method != NULL))
  1138.           {
  1139.             /* Function objc_msg_lookup returns a pointer.  */
  1140.             deprecated_set_value_type (argvec[0],
  1141.                                        lookup_pointer_type (lookup_function_type (value_type (argvec[0]))));
  1142.             argvec[0]
  1143.               = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
  1144.           }

  1145.         ret = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
  1146.         return ret;
  1147.       }
  1148.       break;

  1149.     case OP_FUNCALL:
  1150.       (*pos) += 2;
  1151.       op = exp->elts[*pos].opcode;
  1152.       nargs = longest_to_int (exp->elts[pc + 1].longconst);
  1153.       /* Allocate arg vector, including space for the function to be
  1154.          called in argvec[0], a potential `this', and a terminating NULL.  */
  1155.       argvec = (struct value **)
  1156.         alloca (sizeof (struct value *) * (nargs + 3));
  1157.       if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
  1158.         {
  1159.           /* First, evaluate the structure into arg2.  */
  1160.           pc2 = (*pos)++;

  1161.           if (op == STRUCTOP_MEMBER)
  1162.             {
  1163.               arg2 = evaluate_subexp_for_address (exp, pos, noside);
  1164.             }
  1165.           else
  1166.             {
  1167.               arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1168.             }

  1169.           /* If the function is a virtual function, then the
  1170.              aggregate value (providing the structure) plays
  1171.              its part by providing the vtable.  Otherwise,
  1172.              it is just along for the ride: call the function
  1173.              directly.  */

  1174.           arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);

  1175.           type = check_typedef (value_type (arg1));
  1176.           if (noside == EVAL_SKIP)
  1177.             tem = 1/* Set it to the right arg index so that all arguments
  1178.                          can also be skipped.  */
  1179.           else if (TYPE_CODE (type) == TYPE_CODE_METHODPTR)
  1180.             {
  1181.               if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1182.                 arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
  1183.               else
  1184.                 arg1 = cplus_method_ptr_to_value (&arg2, arg1);

  1185.               /* Now, say which argument to start evaluating from.  */
  1186.               nargs++;
  1187.               tem = 2;
  1188.               argvec[1] = arg2;
  1189.             }
  1190.           else if (TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
  1191.             {
  1192.               struct type *type_ptr
  1193.                 = lookup_pointer_type (TYPE_DOMAIN_TYPE (type));
  1194.               struct type *target_type_ptr
  1195.                 = lookup_pointer_type (TYPE_TARGET_TYPE (type));

  1196.               /* Now, convert these values to an address.  */
  1197.               arg2 = value_cast (type_ptr, arg2);

  1198.               mem_offset = value_as_long (arg1);

  1199.               arg1 = value_from_pointer (target_type_ptr,
  1200.                                          value_as_long (arg2) + mem_offset);
  1201.               arg1 = value_ind (arg1);
  1202.               tem = 1;
  1203.             }
  1204.           else
  1205.             error (_("Non-pointer-to-member value used in pointer-to-member "
  1206.                      "construct"));
  1207.         }
  1208.       else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
  1209.         {
  1210.           /* Hair for method invocations.  */
  1211.           int tem2;

  1212.           nargs++;
  1213.           /* First, evaluate the structure into arg2.  */
  1214.           pc2 = (*pos)++;
  1215.           tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
  1216.           *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);

  1217.           if (op == STRUCTOP_STRUCT)
  1218.             {
  1219.               /* If v is a variable in a register, and the user types
  1220.                  v.method (), this will produce an error, because v has
  1221.                  no address.

  1222.                  A possible way around this would be to allocate a
  1223.                  copy of the variable on the stack, copy in the
  1224.                  contents, call the function, and copy out the
  1225.                  contents.  I.e. convert this from call by reference
  1226.                  to call by copy-return (or whatever it's called).
  1227.                  However, this does not work because it is not the
  1228.                  same: the method being called could stash a copy of
  1229.                  the address, and then future uses through that address
  1230.                  (after the method returns) would be expected to
  1231.                  use the variable itself, not some copy of it.  */
  1232.               arg2 = evaluate_subexp_for_address (exp, pos, noside);
  1233.             }
  1234.           else
  1235.             {
  1236.               arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);

  1237.               /* Check to see if the operator '->' has been
  1238.                  overloaded.  If the operator has been overloaded
  1239.                  replace arg2 with the value returned by the custom
  1240.                  operator and continue evaluation.  */
  1241.               while (unop_user_defined_p (op, arg2))
  1242.                 {
  1243.                   volatile struct gdb_exception except;
  1244.                   struct value *value = NULL;
  1245.                   TRY_CATCH (except, RETURN_MASK_ERROR)
  1246.                     {
  1247.                       value = value_x_unop (arg2, op, noside);
  1248.                     }

  1249.                   if (except.reason < 0)
  1250.                     {
  1251.                       if (except.error == NOT_FOUND_ERROR)
  1252.                         break;
  1253.                       else
  1254.                         throw_exception (except);
  1255.                     }
  1256.                   arg2 = value;
  1257.                 }
  1258.             }
  1259.           /* Now, say which argument to start evaluating from.  */
  1260.           tem = 2;
  1261.         }
  1262.       else if (op == OP_SCOPE
  1263.                && overload_resolution
  1264.                && (exp->language_defn->la_language == language_cplus))
  1265.         {
  1266.           /* Unpack it locally so we can properly handle overload
  1267.              resolution.  */
  1268.           char *name;
  1269.           int local_tem;

  1270.           pc2 = (*pos)++;
  1271.           local_tem = longest_to_int (exp->elts[pc2 + 2].longconst);
  1272.           (*pos) += 4 + BYTES_TO_EXP_ELEM (local_tem + 1);
  1273.           type = exp->elts[pc2 + 1].type;
  1274.           name = &exp->elts[pc2 + 3].string;

  1275.           function = NULL;
  1276.           function_name = NULL;
  1277.           if (TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
  1278.             {
  1279.               function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type),
  1280.                                                      name,
  1281.                                                      get_selected_block (0),
  1282.                                                      VAR_DOMAIN);
  1283.               if (function == NULL)
  1284.                 error (_("No symbol \"%s\" in namespace \"%s\"."),
  1285.                        name, TYPE_TAG_NAME (type));

  1286.               tem = 1;
  1287.               /* arg2 is left as NULL on purpose.  */
  1288.             }
  1289.           else
  1290.             {
  1291.               gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
  1292.                           || TYPE_CODE (type) == TYPE_CODE_UNION);
  1293.               function_name = name;

  1294.               /* We need a properly typed value for method lookup.  For
  1295.                  static methods arg2 is otherwise unused.  */
  1296.               arg2 = value_zero (type, lval_memory);
  1297.               ++nargs;
  1298.               tem = 2;
  1299.             }
  1300.         }
  1301.       else if (op == OP_ADL_FUNC)
  1302.         {
  1303.           /* Save the function position and move pos so that the arguments
  1304.              can be evaluated.  */
  1305.           int func_name_len;

  1306.           save_pos1 = *pos;
  1307.           tem = 1;

  1308.           func_name_len = longest_to_int (exp->elts[save_pos1 + 3].longconst);
  1309.           (*pos) += 6 + BYTES_TO_EXP_ELEM (func_name_len + 1);
  1310.         }
  1311.       else
  1312.         {
  1313.           /* Non-method function call.  */
  1314.           save_pos1 = *pos;
  1315.           tem = 1;

  1316.           /* If this is a C++ function wait until overload resolution.  */
  1317.           if (op == OP_VAR_VALUE
  1318.               && overload_resolution
  1319.               && (exp->language_defn->la_language == language_cplus))
  1320.             {
  1321.               (*pos) += 4; /* Skip the evaluation of the symbol.  */
  1322.               argvec[0] = NULL;
  1323.             }
  1324.           else
  1325.             {
  1326.               argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
  1327.               type = value_type (argvec[0]);
  1328.               if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
  1329.                 type = TYPE_TARGET_TYPE (type);
  1330.               if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
  1331.                 {
  1332.                   for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
  1333.                     {
  1334.                       argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type,
  1335.                                                                       tem - 1),
  1336.                                                      exp, pos, noside);
  1337.                     }
  1338.                 }
  1339.             }
  1340.         }

  1341.       /* Evaluate arguments (if not already done, e.g., namespace::func()
  1342.          and overload-resolution is off).  */
  1343.       for (; tem <= nargs; tem++)
  1344.         {
  1345.           /* Ensure that array expressions are coerced into pointer
  1346.              objects.  */
  1347.           argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
  1348.         }

  1349.       /* Signal end of arglist.  */
  1350.       argvec[tem] = 0;

  1351.       if (noside == EVAL_SKIP)
  1352.         goto nosideret;

  1353.       if (op == OP_ADL_FUNC)
  1354.         {
  1355.           struct symbol *symp;
  1356.           char *func_name;
  1357.           int  name_len;
  1358.           int string_pc = save_pos1 + 3;

  1359.           /* Extract the function name.  */
  1360.           name_len = longest_to_int (exp->elts[string_pc].longconst);
  1361.           func_name = (char *) alloca (name_len + 1);
  1362.           strcpy (func_name, &exp->elts[string_pc + 1].string);

  1363.           find_overload_match (&argvec[1], nargs, func_name,
  1364.                                NON_METHOD, /* not method */
  1365.                                NULL, NULL, /* pass NULL symbol since
  1366.                                               symbol is unknown */
  1367.                                NULL, &symp, NULL, 0, noside);

  1368.           /* Now fix the expression being evaluated.  */
  1369.           exp->elts[save_pos1 + 2].symbol = symp;
  1370.           argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
  1371.         }

  1372.       if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR
  1373.           || (op == OP_SCOPE && function_name != NULL))
  1374.         {
  1375.           int static_memfuncp;
  1376.           char *tstr;

  1377.           /* Method invocation: stuff "this" as first parameter.
  1378.              If the method turns out to be static we undo this below.  */
  1379.           argvec[1] = arg2;

  1380.           if (op != OP_SCOPE)
  1381.             {
  1382.               /* Name of method from expression.  */
  1383.               tstr = &exp->elts[pc2 + 2].string;
  1384.             }
  1385.           else
  1386.             tstr = function_name;

  1387.           if (overload_resolution && (exp->language_defn->la_language
  1388.                                       == language_cplus))
  1389.             {
  1390.               /* Language is C++, do some overload resolution before
  1391.                  evaluation.  */
  1392.               struct value *valp = NULL;

  1393.               (void) find_overload_match (&argvec[1], nargs, tstr,
  1394.                                           METHOD, /* method */
  1395.                                           &arg2,  /* the object */
  1396.                                           NULL, &valp, NULL,
  1397.                                           &static_memfuncp, 0, noside);

  1398.               if (op == OP_SCOPE && !static_memfuncp)
  1399.                 {
  1400.                   /* For the time being, we don't handle this.  */
  1401.                   error (_("Call to overloaded function %s requires "
  1402.                            "`this' pointer"),
  1403.                          function_name);
  1404.                 }
  1405.               argvec[1] = arg2;        /* the ``this'' pointer */
  1406.               argvec[0] = valp;        /* Use the method found after overload
  1407.                                    resolution.  */
  1408.             }
  1409.           else
  1410.             /* Non-C++ case -- or no overload resolution.  */
  1411.             {
  1412.               struct value *temp = arg2;

  1413.               argvec[0] = value_struct_elt (&temp, argvec + 1, tstr,
  1414.                                             &static_memfuncp,
  1415.                                             op == STRUCTOP_STRUCT
  1416.                                        ? "structure" : "structure pointer");
  1417.               /* value_struct_elt updates temp with the correct value
  1418.                   of the ``this'' pointer if necessary, so modify argvec[1] to
  1419.                  reflect any ``this'' changes.  */
  1420.               arg2
  1421.                 = value_from_longest (lookup_pointer_type(value_type (temp)),
  1422.                                       value_address (temp)
  1423.                                       + value_embedded_offset (temp));
  1424.               argvec[1] = arg2;        /* the ``this'' pointer */
  1425.             }

  1426.           /* Take out `this' if needed.  */
  1427.           if (static_memfuncp)
  1428.             {
  1429.               argvec[1] = argvec[0];
  1430.               nargs--;
  1431.               argvec++;
  1432.             }
  1433.         }
  1434.       else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
  1435.         {
  1436.           /* Pointer to member.  argvec[1] is already set up.  */
  1437.           argvec[0] = arg1;
  1438.         }
  1439.       else if (op == OP_VAR_VALUE || (op == OP_SCOPE && function != NULL))
  1440.         {
  1441.           /* Non-member function being called.  */
  1442.           /* fn: This can only be done for C++ functions.  A C-style function
  1443.              in a C++ program, for instance, does not have the fields that
  1444.              are expected here.  */

  1445.           if (overload_resolution && (exp->language_defn->la_language
  1446.                                       == language_cplus))
  1447.             {
  1448.               /* Language is C++, do some overload resolution before
  1449.                  evaluation.  */
  1450.               struct symbol *symp;
  1451.               int no_adl = 0;

  1452.               /* If a scope has been specified disable ADL.  */
  1453.               if (op == OP_SCOPE)
  1454.                 no_adl = 1;

  1455.               if (op == OP_VAR_VALUE)
  1456.                 function = exp->elts[save_pos1+2].symbol;

  1457.               (void) find_overload_match (&argvec[1], nargs,
  1458.                                           NULL,        /* no need for name */
  1459.                                           NON_METHOD,  /* not method */
  1460.                                           NULL, function, /* the function */
  1461.                                           NULL, &symp, NULL, no_adl, noside);

  1462.               if (op == OP_VAR_VALUE)
  1463.                 {
  1464.                   /* Now fix the expression being evaluated.  */
  1465.                   exp->elts[save_pos1+2].symbol = symp;
  1466.                   argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1,
  1467.                                                              noside);
  1468.                 }
  1469.               else
  1470.                 argvec[0] = value_of_variable (symp, get_selected_block (0));
  1471.             }
  1472.           else
  1473.             {
  1474.               /* Not C++, or no overload resolution allowed.  */
  1475.               /* Nothing to be done; argvec already correctly set up.  */
  1476.             }
  1477.         }
  1478.       else
  1479.         {
  1480.           /* It is probably a C-style function.  */
  1481.           /* Nothing to be done; argvec already correctly set up.  */
  1482.         }

  1483.     do_call_it:

  1484.       if (argvec[0] == NULL)
  1485.         error (_("Cannot evaluate function -- may be inlined"));
  1486.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1487.         {
  1488.           /* If the return type doesn't look like a function type, call an
  1489.              error.  This can happen if somebody tries to turn a variable into
  1490.              a function call.  This is here because people often want to
  1491.              call, eg, strcmp, which gdb doesn't know is a function.  If
  1492.              gdb isn't asked for it's opinion (ie. through "whatis"),
  1493.              it won't offer it.  */

  1494.           struct type *ftype = value_type (argvec[0]);

  1495.           if (TYPE_CODE (ftype) == TYPE_CODE_INTERNAL_FUNCTION)
  1496.             {
  1497.               /* We don't know anything about what the internal
  1498.                  function might return, but we have to return
  1499.                  something.  */
  1500.               return value_zero (builtin_type (exp->gdbarch)->builtin_int,
  1501.                                  not_lval);
  1502.             }
  1503.           else if (TYPE_GNU_IFUNC (ftype))
  1504.             return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype)));
  1505.           else if (TYPE_TARGET_TYPE (ftype))
  1506.             return allocate_value (TYPE_TARGET_TYPE (ftype));
  1507.           else
  1508.             error (_("Expression of type other than "
  1509.                      "\"Function returning ...\" used as function"));
  1510.         }
  1511.       switch (TYPE_CODE (value_type (argvec[0])))
  1512.         {
  1513.         case TYPE_CODE_INTERNAL_FUNCTION:
  1514.           return call_internal_function (exp->gdbarch, exp->language_defn,
  1515.                                          argvec[0], nargs, argvec + 1);
  1516.         case TYPE_CODE_XMETHOD:
  1517.           return call_xmethod (argvec[0], nargs, argvec + 1);
  1518.         default:
  1519.           return call_function_by_hand (argvec[0], nargs, argvec + 1);
  1520.         }
  1521.       /* pai: FIXME save value from call_function_by_hand, then adjust
  1522.          pc by adjust_fn_pc if +ve.  */

  1523.     case OP_F77_UNDETERMINED_ARGLIST:

  1524.       /* Remember that in F77, functions, substring ops and
  1525.          array subscript operations cannot be disambiguated
  1526.          at parse time.  We have made all array subscript operations,
  1527.          substring operations as well as function calls  come here
  1528.          and we now have to discover what the heck this thing actually was.
  1529.          If it is a function, we process just as if we got an OP_FUNCALL.  */

  1530.       nargs = longest_to_int (exp->elts[pc + 1].longconst);
  1531.       (*pos) += 2;

  1532.       /* First determine the type code we are dealing with.  */
  1533.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1534.       type = check_typedef (value_type (arg1));
  1535.       code = TYPE_CODE (type);

  1536.       if (code == TYPE_CODE_PTR)
  1537.         {
  1538.           /* Fortran always passes variable to subroutines as pointer.
  1539.              So we need to look into its target type to see if it is
  1540.              array, string or function.  If it is, we need to switch
  1541.              to the target value the original one points to.  */
  1542.           struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));

  1543.           if (TYPE_CODE (target_type) == TYPE_CODE_ARRAY
  1544.               || TYPE_CODE (target_type) == TYPE_CODE_STRING
  1545.               || TYPE_CODE (target_type) == TYPE_CODE_FUNC)
  1546.             {
  1547.               arg1 = value_ind (arg1);
  1548.               type = check_typedef (value_type (arg1));
  1549.               code = TYPE_CODE (type);
  1550.             }
  1551.         }

  1552.       switch (code)
  1553.         {
  1554.         case TYPE_CODE_ARRAY:
  1555.           if (exp->elts[*pos].opcode == OP_F90_RANGE)
  1556.             return value_f90_subarray (arg1, exp, pos, noside);
  1557.           else
  1558.             goto multi_f77_subscript;

  1559.         case TYPE_CODE_STRING:
  1560.           if (exp->elts[*pos].opcode == OP_F90_RANGE)
  1561.             return value_f90_subarray (arg1, exp, pos, noside);
  1562.           else
  1563.             {
  1564.               arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  1565.               return value_subscript (arg1, value_as_long (arg2));
  1566.             }

  1567.         case TYPE_CODE_PTR:
  1568.         case TYPE_CODE_FUNC:
  1569.           /* It's a function call.  */
  1570.           /* Allocate arg vector, including space for the function to be
  1571.              called in argvec[0] and a terminating NULL.  */
  1572.           argvec = (struct value **)
  1573.             alloca (sizeof (struct value *) * (nargs + 2));
  1574.           argvec[0] = arg1;
  1575.           tem = 1;
  1576.           for (; tem <= nargs; tem++)
  1577.             argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
  1578.           argvec[tem] = 0;        /* signal end of arglist */
  1579.           if (noside == EVAL_SKIP)
  1580.             goto nosideret;
  1581.           goto do_call_it;

  1582.         default:
  1583.           error (_("Cannot perform substring on this type"));
  1584.         }

  1585.     case OP_COMPLEX:
  1586.       /* We have a complex number, There should be 2 floating
  1587.          point numbers that compose it.  */
  1588.       (*pos) += 2;
  1589.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1590.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);

  1591.       return value_literal_complex (arg1, arg2, exp->elts[pc + 1].type);

  1592.     case STRUCTOP_STRUCT:
  1593.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  1594.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  1595.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1596.       if (noside == EVAL_SKIP)
  1597.         goto nosideret;
  1598.       arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
  1599.                                NULL, "structure");
  1600.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1601.         arg3 = value_zero (value_type (arg3), not_lval);
  1602.       return arg3;

  1603.     case STRUCTOP_PTR:
  1604.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  1605.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  1606.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1607.       if (noside == EVAL_SKIP)
  1608.         goto nosideret;

  1609.       /* Check to see if operator '->' has been overloaded.  If so replace
  1610.          arg1 with the value returned by evaluating operator->().  */
  1611.       while (unop_user_defined_p (op, arg1))
  1612.         {
  1613.           volatile struct gdb_exception except;
  1614.           struct value *value = NULL;
  1615.           TRY_CATCH (except, RETURN_MASK_ERROR)
  1616.             {
  1617.               value = value_x_unop (arg1, op, noside);
  1618.             }

  1619.           if (except.reason < 0)
  1620.             {
  1621.               if (except.error == NOT_FOUND_ERROR)
  1622.                 break;
  1623.               else
  1624.                 throw_exception (except);
  1625.             }
  1626.           arg1 = value;
  1627.         }

  1628.       /* JYG: if print object is on we need to replace the base type
  1629.          with rtti type in order to continue on with successful
  1630.          lookup of member / method only available in the rtti type.  */
  1631.       {
  1632.         struct type *type = value_type (arg1);
  1633.         struct type *real_type;
  1634.         int full, top, using_enc;
  1635.         struct value_print_options opts;

  1636.         get_user_print_options (&opts);
  1637.         if (opts.objectprint && TYPE_TARGET_TYPE(type)
  1638.             && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
  1639.           {
  1640.             real_type = value_rtti_indirect_type (arg1, &full, &top,
  1641.                                                   &using_enc);
  1642.             if (real_type)
  1643.                 arg1 = value_cast (real_type, arg1);
  1644.           }
  1645.       }

  1646.       arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
  1647.                                NULL, "structure pointer");
  1648.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1649.         arg3 = value_zero (value_type (arg3), not_lval);
  1650.       return arg3;

  1651.     case STRUCTOP_MEMBER:
  1652.     case STRUCTOP_MPTR:
  1653.       if (op == STRUCTOP_MEMBER)
  1654.         arg1 = evaluate_subexp_for_address (exp, pos, noside);
  1655.       else
  1656.         arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);

  1657.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);

  1658.       if (noside == EVAL_SKIP)
  1659.         goto nosideret;

  1660.       type = check_typedef (value_type (arg2));
  1661.       switch (TYPE_CODE (type))
  1662.         {
  1663.         case TYPE_CODE_METHODPTR:
  1664.           if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1665.             return value_zero (TYPE_TARGET_TYPE (type), not_lval);
  1666.           else
  1667.             {
  1668.               arg2 = cplus_method_ptr_to_value (&arg1, arg2);
  1669.               gdb_assert (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR);
  1670.               return value_ind (arg2);
  1671.             }

  1672.         case TYPE_CODE_MEMBERPTR:
  1673.           /* Now, convert these values to an address.  */
  1674.           arg1 = value_cast_pointers (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
  1675.                                       arg1, 1);

  1676.           mem_offset = value_as_long (arg2);

  1677.           arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
  1678.                                      value_as_long (arg1) + mem_offset);
  1679.           return value_ind (arg3);

  1680.         default:
  1681.           error (_("non-pointer-to-member value used "
  1682.                    "in pointer-to-member construct"));
  1683.         }

  1684.     case TYPE_INSTANCE:
  1685.       nargs = longest_to_int (exp->elts[pc + 1].longconst);
  1686.       arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
  1687.       for (ix = 0; ix < nargs; ++ix)
  1688.         arg_types[ix] = exp->elts[pc + 1 + ix + 1].type;

  1689.       expect_type = make_params (nargs, arg_types);
  1690.       *(pos) += 3 + nargs;
  1691.       arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
  1692.       xfree (TYPE_FIELDS (expect_type));
  1693.       xfree (TYPE_MAIN_TYPE (expect_type));
  1694.       xfree (expect_type);
  1695.       return arg1;

  1696.     case BINOP_CONCAT:
  1697.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  1698.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  1699.       if (noside == EVAL_SKIP)
  1700.         goto nosideret;
  1701.       if (binop_user_defined_p (op, arg1, arg2))
  1702.         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1703.       else
  1704.         return value_concat (arg1, arg2);

  1705.     case BINOP_ASSIGN:
  1706.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1707.       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);

  1708.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  1709.         return arg1;
  1710.       if (binop_user_defined_p (op, arg1, arg2))
  1711.         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1712.       else
  1713.         return value_assign (arg1, arg2);

  1714.     case BINOP_ASSIGN_MODIFY:
  1715.       (*pos) += 2;
  1716.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1717.       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
  1718.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  1719.         return arg1;
  1720.       op = exp->elts[pc + 1].opcode;
  1721.       if (binop_user_defined_p (op, arg1, arg2))
  1722.         return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
  1723.       else if (op == BINOP_ADD && ptrmath_type_p (exp->language_defn,
  1724.                                                   value_type (arg1))
  1725.                && is_integral_type (value_type (arg2)))
  1726.         arg2 = value_ptradd (arg1, value_as_long (arg2));
  1727.       else if (op == BINOP_SUB && ptrmath_type_p (exp->language_defn,
  1728.                                                   value_type (arg1))
  1729.                && is_integral_type (value_type (arg2)))
  1730.         arg2 = value_ptradd (arg1, - value_as_long (arg2));
  1731.       else
  1732.         {
  1733.           struct value *tmp = arg1;

  1734.           /* For shift and integer exponentiation operations,
  1735.              only promote the first argument.  */
  1736.           if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
  1737.               && is_integral_type (value_type (arg2)))
  1738.             unop_promote (exp->language_defn, exp->gdbarch, &tmp);
  1739.           else
  1740.             binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);

  1741.           arg2 = value_binop (tmp, arg2, op);
  1742.         }
  1743.       return value_assign (arg1, arg2);

  1744.     case BINOP_ADD:
  1745.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  1746.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  1747.       if (noside == EVAL_SKIP)
  1748.         goto nosideret;
  1749.       if (binop_user_defined_p (op, arg1, arg2))
  1750.         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1751.       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
  1752.                && is_integral_type (value_type (arg2)))
  1753.         return value_ptradd (arg1, value_as_long (arg2));
  1754.       else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
  1755.                && is_integral_type (value_type (arg1)))
  1756.         return value_ptradd (arg2, value_as_long (arg1));
  1757.       else
  1758.         {
  1759.           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
  1760.           return value_binop (arg1, arg2, BINOP_ADD);
  1761.         }

  1762.     case BINOP_SUB:
  1763.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  1764.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  1765.       if (noside == EVAL_SKIP)
  1766.         goto nosideret;
  1767.       if (binop_user_defined_p (op, arg1, arg2))
  1768.         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1769.       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
  1770.                && ptrmath_type_p (exp->language_defn, value_type (arg2)))
  1771.         {
  1772.           /* FIXME -- should be ptrdiff_t */
  1773.           type = builtin_type (exp->gdbarch)->builtin_long;
  1774.           return value_from_longest (type, value_ptrdiff (arg1, arg2));
  1775.         }
  1776.       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
  1777.                && is_integral_type (value_type (arg2)))
  1778.         return value_ptradd (arg1, - value_as_long (arg2));
  1779.       else
  1780.         {
  1781.           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
  1782.           return value_binop (arg1, arg2, BINOP_SUB);
  1783.         }

  1784.     case BINOP_EXP:
  1785.     case BINOP_MUL:
  1786.     case BINOP_DIV:
  1787.     case BINOP_INTDIV:
  1788.     case BINOP_REM:
  1789.     case BINOP_MOD:
  1790.     case BINOP_LSH:
  1791.     case BINOP_RSH:
  1792.     case BINOP_BITWISE_AND:
  1793.     case BINOP_BITWISE_IOR:
  1794.     case BINOP_BITWISE_XOR:
  1795.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1796.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1797.       if (noside == EVAL_SKIP)
  1798.         goto nosideret;
  1799.       if (binop_user_defined_p (op, arg1, arg2))
  1800.         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1801.       else
  1802.         {
  1803.           /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
  1804.              fudge arg2 to avoid division-by-zero, the caller is
  1805.              (theoretically) only looking for the type of the result.  */
  1806.           if (noside == EVAL_AVOID_SIDE_EFFECTS
  1807.               /* ??? Do we really want to test for BINOP_MOD here?
  1808.                  The implementation of value_binop gives it a well-defined
  1809.                  value.  */
  1810.               && (op == BINOP_DIV
  1811.                   || op == BINOP_INTDIV
  1812.                   || op == BINOP_REM
  1813.                   || op == BINOP_MOD)
  1814.               && value_logical_not (arg2))
  1815.             {
  1816.               struct value *v_one, *retval;

  1817.               v_one = value_one (value_type (arg2));
  1818.               binop_promote (exp->language_defn, exp->gdbarch, &arg1, &v_one);
  1819.               retval = value_binop (arg1, v_one, op);
  1820.               return retval;
  1821.             }
  1822.           else
  1823.             {
  1824.               /* For shift and integer exponentiation operations,
  1825.                  only promote the first argument.  */
  1826.               if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
  1827.                   && is_integral_type (value_type (arg2)))
  1828.                 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
  1829.               else
  1830.                 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);

  1831.               return value_binop (arg1, arg2, op);
  1832.             }
  1833.         }

  1834.     case BINOP_SUBSCRIPT:
  1835.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1836.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1837.       if (noside == EVAL_SKIP)
  1838.         goto nosideret;
  1839.       if (binop_user_defined_p (op, arg1, arg2))
  1840.         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1841.       else
  1842.         {
  1843.           /* If the user attempts to subscript something that is not an
  1844.              array or pointer type (like a plain int variable for example),
  1845.              then report this as an error.  */

  1846.           arg1 = coerce_ref (arg1);
  1847.           type = check_typedef (value_type (arg1));
  1848.           if (TYPE_CODE (type) != TYPE_CODE_ARRAY
  1849.               && TYPE_CODE (type) != TYPE_CODE_PTR)
  1850.             {
  1851.               if (TYPE_NAME (type))
  1852.                 error (_("cannot subscript something of type `%s'"),
  1853.                        TYPE_NAME (type));
  1854.               else
  1855.                 error (_("cannot subscript requested type"));
  1856.             }

  1857.           if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1858.             return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
  1859.           else
  1860.             return value_subscript (arg1, value_as_long (arg2));
  1861.         }
  1862.     case MULTI_SUBSCRIPT:
  1863.       (*pos) += 2;
  1864.       nargs = longest_to_int (exp->elts[pc + 1].longconst);
  1865.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  1866.       while (nargs-- > 0)
  1867.         {
  1868.           arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  1869.           /* FIXME:  EVAL_SKIP handling may not be correct.  */
  1870.           if (noside == EVAL_SKIP)
  1871.             {
  1872.               if (nargs > 0)
  1873.                 {
  1874.                   continue;
  1875.                 }
  1876.               else
  1877.                 {
  1878.                   goto nosideret;
  1879.                 }
  1880.             }
  1881.           /* FIXME:  EVAL_AVOID_SIDE_EFFECTS handling may not be correct.  */
  1882.           if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1883.             {
  1884.               /* If the user attempts to subscript something that has no target
  1885.                  type (like a plain int variable for example), then report this
  1886.                  as an error.  */

  1887.               type = TYPE_TARGET_TYPE (check_typedef (value_type (arg1)));
  1888.               if (type != NULL)
  1889.                 {
  1890.                   arg1 = value_zero (type, VALUE_LVAL (arg1));
  1891.                   noside = EVAL_SKIP;
  1892.                   continue;
  1893.                 }
  1894.               else
  1895.                 {
  1896.                   error (_("cannot subscript something of type `%s'"),
  1897.                          TYPE_NAME (value_type (arg1)));
  1898.                 }
  1899.             }

  1900.           if (binop_user_defined_p (op, arg1, arg2))
  1901.             {
  1902.               arg1 = value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1903.             }
  1904.           else
  1905.             {
  1906.               arg1 = coerce_ref (arg1);
  1907.               type = check_typedef (value_type (arg1));

  1908.               switch (TYPE_CODE (type))
  1909.                 {
  1910.                 case TYPE_CODE_PTR:
  1911.                 case TYPE_CODE_ARRAY:
  1912.                 case TYPE_CODE_STRING:
  1913.                   arg1 = value_subscript (arg1, value_as_long (arg2));
  1914.                   break;

  1915.                 default:
  1916.                   if (TYPE_NAME (type))
  1917.                     error (_("cannot subscript something of type `%s'"),
  1918.                            TYPE_NAME (type));
  1919.                   else
  1920.                     error (_("cannot subscript requested type"));
  1921.                 }
  1922.             }
  1923.         }
  1924.       return (arg1);

  1925.     multi_f77_subscript:
  1926.       {
  1927.         LONGEST subscript_array[MAX_FORTRAN_DIMS];
  1928.         int ndimensions = 1, i;
  1929.         struct value *array = arg1;

  1930.         if (nargs > MAX_FORTRAN_DIMS)
  1931.           error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);

  1932.         ndimensions = calc_f77_array_dims (type);

  1933.         if (nargs != ndimensions)
  1934.           error (_("Wrong number of subscripts"));

  1935.         gdb_assert (nargs > 0);

  1936.         /* Now that we know we have a legal array subscript expression
  1937.            let us actually find out where this element exists in the array.  */

  1938.         /* Take array indices left to right.  */
  1939.         for (i = 0; i < nargs; i++)
  1940.           {
  1941.             /* Evaluate each subscript; it must be a legal integer in F77.  */
  1942.             arg2 = evaluate_subexp_with_coercion (exp, pos, noside);

  1943.             /* Fill in the subscript array.  */

  1944.             subscript_array[i] = value_as_long (arg2);
  1945.           }

  1946.         /* Internal type of array is arranged right to left.  */
  1947.         for (i = nargs; i > 0; i--)
  1948.           {
  1949.             struct type *array_type = check_typedef (value_type (array));
  1950.             LONGEST index = subscript_array[i - 1];

  1951.             array = value_subscripted_rvalue (array, index,
  1952.                                               f77_get_lowerbound (array_type));
  1953.           }

  1954.         return array;
  1955.       }

  1956.     case BINOP_LOGICAL_AND:
  1957.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1958.       if (noside == EVAL_SKIP)
  1959.         {
  1960.           evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1961.           goto nosideret;
  1962.         }

  1963.       oldpos = *pos;
  1964.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  1965.       *pos = oldpos;

  1966.       if (binop_user_defined_p (op, arg1, arg2))
  1967.         {
  1968.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1969.           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1970.         }
  1971.       else
  1972.         {
  1973.           tem = value_logical_not (arg1);
  1974.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
  1975.                                   (tem ? EVAL_SKIP : noside));
  1976.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  1977.           return value_from_longest (type,
  1978.                              (LONGEST) (!tem && !value_logical_not (arg2)));
  1979.         }

  1980.     case BINOP_LOGICAL_OR:
  1981.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1982.       if (noside == EVAL_SKIP)
  1983.         {
  1984.           evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1985.           goto nosideret;
  1986.         }

  1987.       oldpos = *pos;
  1988.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  1989.       *pos = oldpos;

  1990.       if (binop_user_defined_p (op, arg1, arg2))
  1991.         {
  1992.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1993.           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  1994.         }
  1995.       else
  1996.         {
  1997.           tem = value_logical_not (arg1);
  1998.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
  1999.                                   (!tem ? EVAL_SKIP : noside));
  2000.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  2001.           return value_from_longest (type,
  2002.                              (LONGEST) (!tem || !value_logical_not (arg2)));
  2003.         }

  2004.     case BINOP_EQUAL:
  2005.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2006.       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
  2007.       if (noside == EVAL_SKIP)
  2008.         goto nosideret;
  2009.       if (binop_user_defined_p (op, arg1, arg2))
  2010.         {
  2011.           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  2012.         }
  2013.       else
  2014.         {
  2015.           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
  2016.           tem = value_equal (arg1, arg2);
  2017.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  2018.           return value_from_longest (type, (LONGEST) tem);
  2019.         }

  2020.     case BINOP_NOTEQUAL:
  2021.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2022.       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
  2023.       if (noside == EVAL_SKIP)
  2024.         goto nosideret;
  2025.       if (binop_user_defined_p (op, arg1, arg2))
  2026.         {
  2027.           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  2028.         }
  2029.       else
  2030.         {
  2031.           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
  2032.           tem = value_equal (arg1, arg2);
  2033.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  2034.           return value_from_longest (type, (LONGEST) ! tem);
  2035.         }

  2036.     case BINOP_LESS:
  2037.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2038.       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
  2039.       if (noside == EVAL_SKIP)
  2040.         goto nosideret;
  2041.       if (binop_user_defined_p (op, arg1, arg2))
  2042.         {
  2043.           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  2044.         }
  2045.       else
  2046.         {
  2047.           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
  2048.           tem = value_less (arg1, arg2);
  2049.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  2050.           return value_from_longest (type, (LONGEST) tem);
  2051.         }

  2052.     case BINOP_GTR:
  2053.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2054.       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
  2055.       if (noside == EVAL_SKIP)
  2056.         goto nosideret;
  2057.       if (binop_user_defined_p (op, arg1, arg2))
  2058.         {
  2059.           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  2060.         }
  2061.       else
  2062.         {
  2063.           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
  2064.           tem = value_less (arg2, arg1);
  2065.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  2066.           return value_from_longest (type, (LONGEST) tem);
  2067.         }

  2068.     case BINOP_GEQ:
  2069.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2070.       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
  2071.       if (noside == EVAL_SKIP)
  2072.         goto nosideret;
  2073.       if (binop_user_defined_p (op, arg1, arg2))
  2074.         {
  2075.           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  2076.         }
  2077.       else
  2078.         {
  2079.           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
  2080.           tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
  2081.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  2082.           return value_from_longest (type, (LONGEST) tem);
  2083.         }

  2084.     case BINOP_LEQ:
  2085.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2086.       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
  2087.       if (noside == EVAL_SKIP)
  2088.         goto nosideret;
  2089.       if (binop_user_defined_p (op, arg1, arg2))
  2090.         {
  2091.           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
  2092.         }
  2093.       else
  2094.         {
  2095.           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
  2096.           tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
  2097.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  2098.           return value_from_longest (type, (LONGEST) tem);
  2099.         }

  2100.     case BINOP_REPEAT:
  2101.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2102.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2103.       if (noside == EVAL_SKIP)
  2104.         goto nosideret;
  2105.       type = check_typedef (value_type (arg2));
  2106.       if (TYPE_CODE (type) != TYPE_CODE_INT)
  2107.         error (_("Non-integral right operand for \"@\" operator."));
  2108.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2109.         {
  2110.           return allocate_repeat_value (value_type (arg1),
  2111.                                      longest_to_int (value_as_long (arg2)));
  2112.         }
  2113.       else
  2114.         return value_repeat (arg1, longest_to_int (value_as_long (arg2)));

  2115.     case BINOP_COMMA:
  2116.       evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2117.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);

  2118.     case UNOP_PLUS:
  2119.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2120.       if (noside == EVAL_SKIP)
  2121.         goto nosideret;
  2122.       if (unop_user_defined_p (op, arg1))
  2123.         return value_x_unop (arg1, op, noside);
  2124.       else
  2125.         {
  2126.           unop_promote (exp->language_defn, exp->gdbarch, &arg1);
  2127.           return value_pos (arg1);
  2128.         }

  2129.     case UNOP_NEG:
  2130.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2131.       if (noside == EVAL_SKIP)
  2132.         goto nosideret;
  2133.       if (unop_user_defined_p (op, arg1))
  2134.         return value_x_unop (arg1, op, noside);
  2135.       else
  2136.         {
  2137.           unop_promote (exp->language_defn, exp->gdbarch, &arg1);
  2138.           return value_neg (arg1);
  2139.         }

  2140.     case UNOP_COMPLEMENT:
  2141.       /* C++: check for and handle destructor names.  */
  2142.       op = exp->elts[*pos].opcode;

  2143.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2144.       if (noside == EVAL_SKIP)
  2145.         goto nosideret;
  2146.       if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
  2147.         return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
  2148.       else
  2149.         {
  2150.           unop_promote (exp->language_defn, exp->gdbarch, &arg1);
  2151.           return value_complement (arg1);
  2152.         }

  2153.     case UNOP_LOGICAL_NOT:
  2154.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2155.       if (noside == EVAL_SKIP)
  2156.         goto nosideret;
  2157.       if (unop_user_defined_p (op, arg1))
  2158.         return value_x_unop (arg1, op, noside);
  2159.       else
  2160.         {
  2161.           type = language_bool_type (exp->language_defn, exp->gdbarch);
  2162.           return value_from_longest (type, (LONGEST) value_logical_not (arg1));
  2163.         }

  2164.     case UNOP_IND:
  2165.       if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
  2166.         expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
  2167.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  2168.       type = check_typedef (value_type (arg1));
  2169.       if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
  2170.           || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
  2171.         error (_("Attempt to dereference pointer "
  2172.                  "to member without an object"));
  2173.       if (noside == EVAL_SKIP)
  2174.         goto nosideret;
  2175.       if (unop_user_defined_p (op, arg1))
  2176.         return value_x_unop (arg1, op, noside);
  2177.       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2178.         {
  2179.           type = check_typedef (value_type (arg1));
  2180.           if (TYPE_CODE (type) == TYPE_CODE_PTR
  2181.               || TYPE_CODE (type) == TYPE_CODE_REF
  2182.           /* In C you can dereference an array to get the 1st elt.  */
  2183.               || TYPE_CODE (type) == TYPE_CODE_ARRAY
  2184.             )
  2185.             return value_zero (TYPE_TARGET_TYPE (type),
  2186.                                lval_memory);
  2187.           else if (TYPE_CODE (type) == TYPE_CODE_INT)
  2188.             /* GDB allows dereferencing an int.  */
  2189.             return value_zero (builtin_type (exp->gdbarch)->builtin_int,
  2190.                                lval_memory);
  2191.           else
  2192.             error (_("Attempt to take contents of a non-pointer value."));
  2193.         }

  2194.       /* Allow * on an integer so we can cast it to whatever we want.
  2195.          This returns an int, which seems like the most C-like thing to
  2196.          do.  "long long" variables are rare enough that
  2197.          BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
  2198.       if (TYPE_CODE (type) == TYPE_CODE_INT)
  2199.         return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
  2200.                               (CORE_ADDR) value_as_address (arg1));
  2201.       return value_ind (arg1);

  2202.     case UNOP_ADDR:
  2203.       /* C++: check for and handle pointer to members.  */

  2204.       op = exp->elts[*pos].opcode;

  2205.       if (noside == EVAL_SKIP)
  2206.         {
  2207.           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  2208.           goto nosideret;
  2209.         }
  2210.       else
  2211.         {
  2212.           struct value *retvalp = evaluate_subexp_for_address (exp, pos,
  2213.                                                                noside);

  2214.           return retvalp;
  2215.         }

  2216.     case UNOP_SIZEOF:
  2217.       if (noside == EVAL_SKIP)
  2218.         {
  2219.           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  2220.           goto nosideret;
  2221.         }
  2222.       return evaluate_subexp_for_sizeof (exp, pos, noside);

  2223.     case UNOP_CAST:
  2224.       (*pos) += 2;
  2225.       type = exp->elts[pc + 1].type;
  2226.       arg1 = evaluate_subexp (type, exp, pos, noside);
  2227.       if (noside == EVAL_SKIP)
  2228.         goto nosideret;
  2229.       if (type != value_type (arg1))
  2230.         arg1 = value_cast (type, arg1);
  2231.       return arg1;

  2232.     case UNOP_CAST_TYPE:
  2233.       arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  2234.       type = value_type (arg1);
  2235.       arg1 = evaluate_subexp (type, exp, pos, noside);
  2236.       if (noside == EVAL_SKIP)
  2237.         goto nosideret;
  2238.       if (type != value_type (arg1))
  2239.         arg1 = value_cast (type, arg1);
  2240.       return arg1;

  2241.     case UNOP_DYNAMIC_CAST:
  2242.       arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  2243.       type = value_type (arg1);
  2244.       arg1 = evaluate_subexp (type, exp, pos, noside);
  2245.       if (noside == EVAL_SKIP)
  2246.         goto nosideret;
  2247.       return value_dynamic_cast (type, arg1);

  2248.     case UNOP_REINTERPRET_CAST:
  2249.       arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  2250.       type = value_type (arg1);
  2251.       arg1 = evaluate_subexp (type, exp, pos, noside);
  2252.       if (noside == EVAL_SKIP)
  2253.         goto nosideret;
  2254.       return value_reinterpret_cast (type, arg1);

  2255.     case UNOP_MEMVAL:
  2256.       (*pos) += 2;
  2257.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  2258.       if (noside == EVAL_SKIP)
  2259.         goto nosideret;
  2260.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2261.         return value_zero (exp->elts[pc + 1].type, lval_memory);
  2262.       else
  2263.         return value_at_lazy (exp->elts[pc + 1].type,
  2264.                               value_as_address (arg1));

  2265.     case UNOP_MEMVAL_TYPE:
  2266.       arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  2267.       type = value_type (arg1);
  2268.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  2269.       if (noside == EVAL_SKIP)
  2270.         goto nosideret;
  2271.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2272.         return value_zero (type, lval_memory);
  2273.       else
  2274.         return value_at_lazy (type, value_as_address (arg1));

  2275.     case UNOP_MEMVAL_TLS:
  2276.       (*pos) += 3;
  2277.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  2278.       if (noside == EVAL_SKIP)
  2279.         goto nosideret;
  2280.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2281.         return value_zero (exp->elts[pc + 2].type, lval_memory);
  2282.       else
  2283.         {
  2284.           CORE_ADDR tls_addr;

  2285.           tls_addr = target_translate_tls_address (exp->elts[pc + 1].objfile,
  2286.                                                    value_as_address (arg1));
  2287.           return value_at_lazy (exp->elts[pc + 2].type, tls_addr);
  2288.         }

  2289.     case UNOP_PREINCREMENT:
  2290.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  2291.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  2292.         return arg1;
  2293.       else if (unop_user_defined_p (op, arg1))
  2294.         {
  2295.           return value_x_unop (arg1, op, noside);
  2296.         }
  2297.       else
  2298.         {
  2299.           if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
  2300.             arg2 = value_ptradd (arg1, 1);
  2301.           else
  2302.             {
  2303.               struct value *tmp = arg1;

  2304.               arg2 = value_one (value_type (arg1));
  2305.               binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
  2306.               arg2 = value_binop (tmp, arg2, BINOP_ADD);
  2307.             }

  2308.           return value_assign (arg1, arg2);
  2309.         }

  2310.     case UNOP_PREDECREMENT:
  2311.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  2312.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  2313.         return arg1;
  2314.       else if (unop_user_defined_p (op, arg1))
  2315.         {
  2316.           return value_x_unop (arg1, op, noside);
  2317.         }
  2318.       else
  2319.         {
  2320.           if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
  2321.             arg2 = value_ptradd (arg1, -1);
  2322.           else
  2323.             {
  2324.               struct value *tmp = arg1;

  2325.               arg2 = value_one (value_type (arg1));
  2326.               binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
  2327.               arg2 = value_binop (tmp, arg2, BINOP_SUB);
  2328.             }

  2329.           return value_assign (arg1, arg2);
  2330.         }

  2331.     case UNOP_POSTINCREMENT:
  2332.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  2333.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  2334.         return arg1;
  2335.       else if (unop_user_defined_p (op, arg1))
  2336.         {
  2337.           return value_x_unop (arg1, op, noside);
  2338.         }
  2339.       else
  2340.         {
  2341.           arg3 = value_non_lval (arg1);

  2342.           if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
  2343.             arg2 = value_ptradd (arg1, 1);
  2344.           else
  2345.             {
  2346.               struct value *tmp = arg1;

  2347.               arg2 = value_one (value_type (arg1));
  2348.               binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
  2349.               arg2 = value_binop (tmp, arg2, BINOP_ADD);
  2350.             }

  2351.           value_assign (arg1, arg2);
  2352.           return arg3;
  2353.         }

  2354.     case UNOP_POSTDECREMENT:
  2355.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  2356.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  2357.         return arg1;
  2358.       else if (unop_user_defined_p (op, arg1))
  2359.         {
  2360.           return value_x_unop (arg1, op, noside);
  2361.         }
  2362.       else
  2363.         {
  2364.           arg3 = value_non_lval (arg1);

  2365.           if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
  2366.             arg2 = value_ptradd (arg1, -1);
  2367.           else
  2368.             {
  2369.               struct value *tmp = arg1;

  2370.               arg2 = value_one (value_type (arg1));
  2371.               binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
  2372.               arg2 = value_binop (tmp, arg2, BINOP_SUB);
  2373.             }

  2374.           value_assign (arg1, arg2);
  2375.           return arg3;
  2376.         }

  2377.     case OP_THIS:
  2378.       (*pos) += 1;
  2379.       return value_of_this (exp->language_defn);

  2380.     case OP_TYPE:
  2381.       /* The value is not supposed to be used.  This is here to make it
  2382.          easier to accommodate expressions that contain types.  */
  2383.       (*pos) += 2;
  2384.       if (noside == EVAL_SKIP)
  2385.         goto nosideret;
  2386.       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2387.         {
  2388.           struct type *type = exp->elts[pc + 1].type;

  2389.           /* If this is a typedef, then find its immediate target.  We
  2390.              use check_typedef to resolve stubs, but we ignore its
  2391.              result because we do not want to dig past all
  2392.              typedefs.  */
  2393.           check_typedef (type);
  2394.           if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
  2395.             type = TYPE_TARGET_TYPE (type);
  2396.           return allocate_value (type);
  2397.         }
  2398.       else
  2399.         error (_("Attempt to use a type name as an expression"));

  2400.     case OP_TYPEOF:
  2401.     case OP_DECLTYPE:
  2402.       if (noside == EVAL_SKIP)
  2403.         {
  2404.           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  2405.           goto nosideret;
  2406.         }
  2407.       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2408.         {
  2409.           enum exp_opcode sub_op = exp->elts[*pos].opcode;
  2410.           struct value *result;

  2411.           result = evaluate_subexp (NULL_TYPE, exp, pos,
  2412.                                     EVAL_AVOID_SIDE_EFFECTS);

  2413.           /* 'decltype' has special semantics for lvalues.  */
  2414.           if (op == OP_DECLTYPE
  2415.               && (sub_op == BINOP_SUBSCRIPT
  2416.                   || sub_op == STRUCTOP_MEMBER
  2417.                   || sub_op == STRUCTOP_MPTR
  2418.                   || sub_op == UNOP_IND
  2419.                   || sub_op == STRUCTOP_STRUCT
  2420.                   || sub_op == STRUCTOP_PTR
  2421.                   || sub_op == OP_SCOPE))
  2422.             {
  2423.               struct type *type = value_type (result);

  2424.               if (TYPE_CODE (check_typedef (type)) != TYPE_CODE_REF)
  2425.                 {
  2426.                   type = lookup_reference_type (type);
  2427.                   result = allocate_value (type);
  2428.                 }
  2429.             }

  2430.           return result;
  2431.         }
  2432.       else
  2433.         error (_("Attempt to use a type as an expression"));

  2434.     case OP_TYPEID:
  2435.       {
  2436.         struct value *result;
  2437.         enum exp_opcode sub_op = exp->elts[*pos].opcode;

  2438.         if (sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
  2439.           result = evaluate_subexp (NULL_TYPE, exp, pos,
  2440.                                     EVAL_AVOID_SIDE_EFFECTS);
  2441.         else
  2442.           result = evaluate_subexp (NULL_TYPE, exp, pos, noside);

  2443.         if (noside != EVAL_NORMAL)
  2444.           return allocate_value (cplus_typeid_type (exp->gdbarch));

  2445.         return cplus_typeid (result);
  2446.       }

  2447.     default:
  2448.       /* Removing this case and compiling with gcc -Wall reveals that
  2449.          a lot of cases are hitting this case.  Some of these should
  2450.          probably be removed from expression.h; others are legitimate
  2451.          expressions which are (apparently) not fully implemented.

  2452.          If there are any cases landing here which mean a user error,
  2453.          then they should be separate cases, with more descriptive
  2454.          error messages.  */

  2455.       error (_("GDB does not (yet) know how to "
  2456.                "evaluate that kind of expression"));
  2457.     }

  2458. nosideret:
  2459.   return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
  2460. }

  2461. /* Evaluate a subexpression of EXP, at index *POS,
  2462.    and return the address of that subexpression.
  2463.    Advance *POS over the subexpression.
  2464.    If the subexpression isn't an lvalue, get an error.
  2465.    NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
  2466.    then only the type of the result need be correct.  */

  2467. static struct value *
  2468. evaluate_subexp_for_address (struct expression *exp, int *pos,
  2469.                              enum noside noside)
  2470. {
  2471.   enum exp_opcode op;
  2472.   int pc;
  2473.   struct symbol *var;
  2474.   struct value *x;
  2475.   int tem;

  2476.   pc = (*pos);
  2477.   op = exp->elts[pc].opcode;

  2478.   switch (op)
  2479.     {
  2480.     case UNOP_IND:
  2481.       (*pos)++;
  2482.       x = evaluate_subexp (NULL_TYPE, exp, pos, noside);

  2483.       /* We can't optimize out "&*" if there's a user-defined operator*.  */
  2484.       if (unop_user_defined_p (op, x))
  2485.         {
  2486.           x = value_x_unop (x, op, noside);
  2487.           goto default_case_after_eval;
  2488.         }

  2489.       return coerce_array (x);

  2490.     case UNOP_MEMVAL:
  2491.       (*pos) += 3;
  2492.       return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
  2493.                          evaluate_subexp (NULL_TYPE, exp, pos, noside));

  2494.     case UNOP_MEMVAL_TYPE:
  2495.       {
  2496.         struct type *type;

  2497.         (*pos) += 1;
  2498.         x = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  2499.         type = value_type (x);
  2500.         return value_cast (lookup_pointer_type (type),
  2501.                            evaluate_subexp (NULL_TYPE, exp, pos, noside));
  2502.       }

  2503.     case OP_VAR_VALUE:
  2504.       var = exp->elts[pc + 2].symbol;

  2505.       /* C++: The "address" of a reference should yield the address
  2506.        * of the object pointed to.  Let value_addr() deal with it.  */
  2507.       if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
  2508.         goto default_case;

  2509.       (*pos) += 4;
  2510.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2511.         {
  2512.           struct type *type =
  2513.             lookup_pointer_type (SYMBOL_TYPE (var));
  2514.           enum address_class sym_class = SYMBOL_CLASS (var);

  2515.           if (sym_class == LOC_CONST
  2516.               || sym_class == LOC_CONST_BYTES
  2517.               || sym_class == LOC_REGISTER)
  2518.             error (_("Attempt to take address of register or constant."));

  2519.           return
  2520.             value_zero (type, not_lval);
  2521.         }
  2522.       else
  2523.         return address_of_variable (var, exp->elts[pc + 1].block);

  2524.     case OP_SCOPE:
  2525.       tem = longest_to_int (exp->elts[pc + 2].longconst);
  2526.       (*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
  2527.       x = value_aggregate_elt (exp->elts[pc + 1].type,
  2528.                                &exp->elts[pc + 3].string,
  2529.                                NULL, 1, noside);
  2530.       if (x == NULL)
  2531.         error (_("There is no field named %s"), &exp->elts[pc + 3].string);
  2532.       return x;

  2533.     default:
  2534.     default_case:
  2535.       x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2536.     default_case_after_eval:
  2537.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  2538.         {
  2539.           struct type *type = check_typedef (value_type (x));

  2540.           if (TYPE_CODE (type) == TYPE_CODE_REF)
  2541.             return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
  2542.                                not_lval);
  2543.           else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
  2544.             return value_zero (lookup_pointer_type (value_type (x)),
  2545.                                not_lval);
  2546.           else
  2547.             error (_("Attempt to take address of "
  2548.                      "value not located in memory."));
  2549.         }
  2550.       return value_addr (x);
  2551.     }
  2552. }

  2553. /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
  2554.    When used in contexts where arrays will be coerced anyway, this is
  2555.    equivalent to `evaluate_subexp' but much faster because it avoids
  2556.    actually fetching array contents (perhaps obsolete now that we have
  2557.    value_lazy()).

  2558.    Note that we currently only do the coercion for C expressions, where
  2559.    arrays are zero based and the coercion is correct.  For other languages,
  2560.    with nonzero based arrays, coercion loses.  Use CAST_IS_CONVERSION
  2561.    to decide if coercion is appropriate.  */

  2562. struct value *
  2563. evaluate_subexp_with_coercion (struct expression *exp,
  2564.                                int *pos, enum noside noside)
  2565. {
  2566.   enum exp_opcode op;
  2567.   int pc;
  2568.   struct value *val;
  2569.   struct symbol *var;
  2570.   struct type *type;

  2571.   pc = (*pos);
  2572.   op = exp->elts[pc].opcode;

  2573.   switch (op)
  2574.     {
  2575.     case OP_VAR_VALUE:
  2576.       var = exp->elts[pc + 2].symbol;
  2577.       type = check_typedef (SYMBOL_TYPE (var));
  2578.       if (TYPE_CODE (type) == TYPE_CODE_ARRAY
  2579.           && !TYPE_VECTOR (type)
  2580.           && CAST_IS_CONVERSION (exp->language_defn))
  2581.         {
  2582.           (*pos) += 4;
  2583.           val = address_of_variable (var, exp->elts[pc + 1].block);
  2584.           return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
  2585.                              val);
  2586.         }
  2587.       /* FALLTHROUGH */

  2588.     default:
  2589.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  2590.     }
  2591. }

  2592. /* Evaluate a subexpression of EXP, at index *POS,
  2593.    and return a value for the size of that subexpression.
  2594.    Advance *POS over the subexpression.  If NOSIDE is EVAL_NORMAL
  2595.    we allow side-effects on the operand if its type is a variable
  2596.    length array.   */

  2597. static struct value *
  2598. evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
  2599.                             enum noside noside)
  2600. {
  2601.   /* FIXME: This should be size_t.  */
  2602.   struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
  2603.   enum exp_opcode op;
  2604.   int pc;
  2605.   struct type *type;
  2606.   struct value *val;

  2607.   pc = (*pos);
  2608.   op = exp->elts[pc].opcode;

  2609.   switch (op)
  2610.     {
  2611.       /* This case is handled specially
  2612.          so that we avoid creating a value for the result type.
  2613.          If the result type is very big, it's desirable not to
  2614.          create a value unnecessarily.  */
  2615.     case UNOP_IND:
  2616.       (*pos)++;
  2617.       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  2618.       type = check_typedef (value_type (val));
  2619.       if (TYPE_CODE (type) != TYPE_CODE_PTR
  2620.           && TYPE_CODE (type) != TYPE_CODE_REF
  2621.           && TYPE_CODE (type) != TYPE_CODE_ARRAY)
  2622.         error (_("Attempt to take contents of a non-pointer value."));
  2623.       type = TYPE_TARGET_TYPE (type);
  2624.       if (is_dynamic_type (type))
  2625.         type = value_type (value_ind (val));
  2626.       return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));

  2627.     case UNOP_MEMVAL:
  2628.       (*pos) += 3;
  2629.       type = exp->elts[pc + 1].type;
  2630.       break;

  2631.     case UNOP_MEMVAL_TYPE:
  2632.       (*pos) += 1;
  2633.       val = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  2634.       type = value_type (val);
  2635.       break;

  2636.     case OP_VAR_VALUE:
  2637.       type = SYMBOL_TYPE (exp->elts[pc + 2].symbol);
  2638.       if (is_dynamic_type (type))
  2639.         {
  2640.           val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
  2641.           type = value_type (val);
  2642.         }
  2643.       else
  2644.         (*pos) += 4;
  2645.       break;

  2646.       /* Deal with the special case if NOSIDE is EVAL_NORMAL and the resulting
  2647.          type of the subscript is a variable length array type. In this case we
  2648.          must re-evaluate the right hand side of the subcription to allow
  2649.          side-effects. */
  2650.     case BINOP_SUBSCRIPT:
  2651.       if (noside == EVAL_NORMAL)
  2652.         {
  2653.           int pc = (*pos) + 1;

  2654.           val = evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
  2655.           type = check_typedef (value_type (val));
  2656.           if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
  2657.             {
  2658.               type = check_typedef (TYPE_TARGET_TYPE (type));
  2659.               if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
  2660.                 {
  2661.                   type = TYPE_INDEX_TYPE (type);
  2662.                   /* Only re-evaluate the right hand side if the resulting type
  2663.                      is a variable length type.  */
  2664.                   if (TYPE_RANGE_DATA (type)->flag_bound_evaluated)
  2665.                     {
  2666.                       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
  2667.                       return value_from_longest
  2668.                         (size_type, (LONGEST) TYPE_LENGTH (value_type (val)));
  2669.                     }
  2670.                 }
  2671.             }
  2672.         }

  2673.       /* Fall through.  */

  2674.     default:
  2675.       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  2676.       type = value_type (val);
  2677.       break;
  2678.     }

  2679.   /* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
  2680.      "When applied to a reference or a reference type, the result is
  2681.      the size of the referenced type."  */
  2682.   CHECK_TYPEDEF (type);
  2683.   if (exp->language_defn->la_language == language_cplus
  2684.       && TYPE_CODE (type) == TYPE_CODE_REF)
  2685.     type = check_typedef (TYPE_TARGET_TYPE (type));
  2686.   return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
  2687. }

  2688. /* Parse a type expression in the string [P..P+LENGTH).  */

  2689. struct type *
  2690. parse_and_eval_type (char *p, int length)
  2691. {
  2692.   char *tmp = (char *) alloca (length + 4);
  2693.   struct expression *expr;

  2694.   tmp[0] = '(';
  2695.   memcpy (tmp + 1, p, length);
  2696.   tmp[length + 1] = ')';
  2697.   tmp[length + 2] = '0';
  2698.   tmp[length + 3] = '\0';
  2699.   expr = parse_expression (tmp);
  2700.   if (expr->elts[0].opcode != UNOP_CAST)
  2701.     error (_("Internal error in eval_type."));
  2702.   return expr->elts[1].type;
  2703. }

  2704. int
  2705. calc_f77_array_dims (struct type *array_type)
  2706. {
  2707.   int ndimen = 1;
  2708.   struct type *tmp_type;

  2709.   if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
  2710.     error (_("Can't get dimensions for a non-array type"));

  2711.   tmp_type = array_type;

  2712.   while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
  2713.     {
  2714.       if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
  2715.         ++ndimen;
  2716.     }
  2717.   return ndimen;
  2718. }