home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / GDB / GDB-4.13 / GDB-4 / gdb-4.13 / gdb / eval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  35.1 KB  |  1,227 lines

  1. /* Evaluate expressions for GDB.
  2.    Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994
  3.    Free Software Foundation, Inc.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22. #include <string.h>
  23. #include "symtab.h"
  24. #include "gdbtypes.h"
  25. #include "value.h"
  26. #include "expression.h"
  27. #include "target.h"
  28. #include "frame.h"
  29. #include "demangle.h"
  30. #include "language.h"    /* For CAST_IS_CONVERSION */
  31.  
  32. /* Values of NOSIDE argument to eval_subexp.  */
  33. enum noside
  34. { EVAL_NORMAL,
  35.   EVAL_SKIP,            /* Only effect is to increment pos.  */
  36.   EVAL_AVOID_SIDE_EFFECTS    /* Don't modify any variables or
  37.                    call any functions.  The value
  38.                    returned will have the correct
  39.                    type, and will have an
  40.                    approximately correct lvalue
  41.                    type (inaccuracy: anything that is
  42.                    listed as being in a register in
  43.                    the function in which it was
  44.                    declared will be lval_register).  */
  45. };
  46.  
  47. /* Prototypes for local functions. */
  48.  
  49. static value_ptr
  50. evaluate_subexp_for_sizeof PARAMS ((struct expression *, int *));
  51.  
  52. static value_ptr
  53. evaluate_subexp_with_coercion PARAMS ((struct expression *, int *,
  54.                        enum noside));
  55.  
  56. static value_ptr
  57. evaluate_subexp_for_address PARAMS ((struct expression *, int *,
  58.                      enum noside));
  59.  
  60. static value_ptr
  61. evaluate_subexp PARAMS ((struct type *, struct expression *, int *,
  62.              enum noside));
  63.  
  64.  
  65. /* Parse the string EXP as a C expression, evaluate it,
  66.    and return the result as a number.  */
  67.  
  68. CORE_ADDR
  69. parse_and_eval_address (exp)
  70.      char *exp;
  71. {
  72.   struct expression *expr = parse_expression (exp);
  73.   register CORE_ADDR addr;
  74.   register struct cleanup *old_chain = 
  75.       make_cleanup (free_current_contents, &expr);
  76.  
  77.   addr = value_as_pointer (evaluate_expression (expr));
  78.   do_cleanups (old_chain);
  79.   return addr;
  80. }
  81.  
  82. /* Like parse_and_eval_address but takes a pointer to a char * variable
  83.    and advanced that variable across the characters parsed.  */
  84.  
  85. CORE_ADDR
  86. parse_and_eval_address_1 (expptr)
  87.      char **expptr;
  88. {
  89.   struct expression *expr = parse_exp_1 (expptr, (struct block *)0, 0);
  90.   register CORE_ADDR addr;
  91.   register struct cleanup *old_chain =
  92.       make_cleanup (free_current_contents, &expr);
  93.  
  94.   addr = value_as_pointer (evaluate_expression (expr));
  95.   do_cleanups (old_chain);
  96.   return addr;
  97. }
  98.  
  99. value_ptr
  100. parse_and_eval (exp)
  101.      char *exp;
  102. {
  103.   struct expression *expr = parse_expression (exp);
  104.   register value_ptr val;
  105.   register struct cleanup *old_chain
  106.     = make_cleanup (free_current_contents, &expr);
  107.  
  108.   val = evaluate_expression (expr);
  109.   do_cleanups (old_chain);
  110.   return val;
  111. }
  112.  
  113. /* Parse up to a comma (or to a closeparen)
  114.    in the string EXPP as an expression, evaluate it, and return the value.
  115.    EXPP is advanced to point to the comma.  */
  116.  
  117. value_ptr
  118. parse_to_comma_and_eval (expp)
  119.      char **expp;
  120. {
  121.   struct expression *expr = parse_exp_1 (expp, (struct block *) 0, 1);
  122.   register value_ptr val;
  123.   register struct cleanup *old_chain
  124.     = make_cleanup (free_current_contents, &expr);
  125.  
  126.   val = evaluate_expression (expr);
  127.   do_cleanups (old_chain);
  128.   return val;
  129. }
  130.  
  131. /* Evaluate an expression in internal prefix form
  132.    such as is constructed by parse.y.
  133.  
  134.    See expression.h for info on the format of an expression.  */
  135.  
  136. value_ptr
  137. evaluate_expression (exp)
  138.      struct expression *exp;
  139. {
  140.   int pc = 0;
  141.   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
  142. }
  143.  
  144. /* Evaluate an expression, avoiding all memory references
  145.    and getting a value whose type alone is correct.  */
  146.  
  147. value_ptr
  148. evaluate_type (exp)
  149.      struct expression *exp;
  150. {
  151.   int pc = 0;
  152.   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
  153. }
  154.  
  155. static value_ptr
  156. evaluate_subexp (expect_type, exp, pos, noside)
  157.      struct type *expect_type;
  158.      register struct expression *exp;
  159.      register int *pos;
  160.      enum noside noside;
  161. {
  162.   enum exp_opcode op;
  163.   int tem, tem2, tem3;
  164.   register int pc, pc2 = 0, oldpos;
  165.   register value_ptr arg1 = NULL, arg2 = NULL, arg3;
  166.   struct type *type;
  167.   int nargs;
  168.   value_ptr *argvec;
  169.  
  170.   pc = (*pos)++;
  171.   op = exp->elts[pc].opcode;
  172.  
  173.   switch (op)
  174.     {
  175.     case OP_SCOPE:
  176.       tem = longest_to_int (exp->elts[pc + 2].longconst);
  177.       (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
  178.       arg1 = value_struct_elt_for_reference (exp->elts[pc + 1].type,
  179.                          0,
  180.                          exp->elts[pc + 1].type,
  181.                          &exp->elts[pc + 3].string,
  182.                          expect_type);
  183.       if (arg1 == NULL)
  184.     error ("There is no field named %s", &exp->elts[pc + 3].string);
  185.       return arg1;
  186.  
  187.     case OP_LONG:
  188.       (*pos) += 3;
  189.       return value_from_longest (exp->elts[pc + 1].type,
  190.                  exp->elts[pc + 2].longconst);
  191.  
  192.     case OP_DOUBLE:
  193.       (*pos) += 3;
  194.       return value_from_double (exp->elts[pc + 1].type,
  195.                 exp->elts[pc + 2].doubleconst);
  196.  
  197.     case OP_VAR_VALUE:
  198.       (*pos) += 3;
  199.       if (noside == EVAL_SKIP)
  200.     goto nosideret;
  201.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  202.     {
  203.       struct symbol * sym = exp->elts[pc + 2].symbol;
  204.       enum lval_type lv;
  205.  
  206.       switch (SYMBOL_CLASS (sym))
  207.         {
  208.         case LOC_CONST:
  209.         case LOC_LABEL:
  210.         case LOC_CONST_BYTES:
  211.           lv = not_lval;
  212.           break;
  213.  
  214.         case LOC_REGISTER:
  215.         case LOC_REGPARM:
  216.           lv = lval_register;
  217.           break;
  218.  
  219.         default:
  220.           lv = lval_memory;
  221.           break;
  222.         }
  223.  
  224.       return value_zero (SYMBOL_TYPE (sym), lv);
  225.     }
  226.       else
  227.     return value_of_variable (exp->elts[pc + 2].symbol,
  228.                   exp->elts[pc + 1].block);
  229.  
  230.     case OP_LAST:
  231.       (*pos) += 2;
  232.       return
  233.     access_value_history (longest_to_int (exp->elts[pc + 1].longconst));
  234.  
  235.     case OP_REGISTER:
  236.       (*pos) += 2;
  237.       return value_of_register (longest_to_int (exp->elts[pc + 1].longconst));
  238.  
  239.     case OP_BOOL:
  240.       (*pos) += 2;
  241.       return value_from_longest (builtin_type_chill_bool,
  242.                  exp->elts[pc + 1].longconst);
  243.  
  244.     case OP_INTERNALVAR:
  245.       (*pos) += 2;
  246.       return value_of_internalvar (exp->elts[pc + 1].internalvar);
  247.  
  248.     case OP_STRING:
  249.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  250.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  251.       if (noside == EVAL_SKIP)
  252.     goto nosideret;
  253.       return value_string (&exp->elts[pc + 2].string, tem);
  254.  
  255.     case OP_BITSTRING:
  256.       error ("support for OP_BITSTRING unimplemented");
  257.       break;
  258.  
  259.     case OP_ARRAY:
  260.       (*pos) += 3;
  261.       tem2 = longest_to_int (exp->elts[pc + 1].longconst);
  262.       tem3 = longest_to_int (exp->elts[pc + 2].longconst);
  263.       nargs = tem3 - tem2 + 1;
  264.       argvec = (value_ptr *) alloca (sizeof (value_ptr) * nargs);
  265.       for (tem = 0; tem < nargs; tem++)
  266.     {
  267.       /* Ensure that array expressions are coerced into pointer objects. */
  268.       argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
  269.     }
  270.       if (noside == EVAL_SKIP)
  271.     goto nosideret;
  272.       return (value_array (tem2, tem3, argvec));
  273.       break;
  274.  
  275.     case TERNOP_COND:
  276.       /* Skip third and second args to evaluate the first one.  */
  277.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  278.       if (value_logical_not (arg1))
  279.     {
  280.       evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  281.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  282.     }
  283.       else
  284.     {
  285.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  286.       evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  287.       return arg2;
  288.     }
  289.  
  290.     case OP_FUNCALL:
  291.       (*pos) += 2;
  292.       op = exp->elts[*pos].opcode;
  293.       if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
  294.     {
  295.       int fnptr;
  296.  
  297.       nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1;
  298.       /* First, evaluate the structure into arg2 */
  299.       pc2 = (*pos)++;
  300.  
  301.       if (noside == EVAL_SKIP)
  302.         goto nosideret;
  303.  
  304.       if (op == STRUCTOP_MEMBER)
  305.         {
  306.           arg2 = evaluate_subexp_for_address (exp, pos, noside);
  307.         }
  308.       else
  309.         {
  310.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  311.         }
  312.  
  313.       /* If the function is a virtual function, then the
  314.          aggregate value (providing the structure) plays
  315.          its part by providing the vtable.  Otherwise,
  316.          it is just along for the ride: call the function
  317.          directly.  */
  318.  
  319.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  320.  
  321.       fnptr = longest_to_int (value_as_long (arg1));
  322.  
  323.       if (METHOD_PTR_IS_VIRTUAL(fnptr))
  324.         {
  325.           int fnoffset = METHOD_PTR_TO_VOFFSET(fnptr);
  326.           struct type *basetype;
  327.           struct type *domain_type =
  328.           TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)));
  329.           int i, j;
  330.           basetype = TYPE_TARGET_TYPE (VALUE_TYPE (arg2));
  331.           if (domain_type != basetype)
  332.           arg2 = value_cast(lookup_pointer_type (domain_type), arg2);
  333.           basetype = TYPE_VPTR_BASETYPE (domain_type);
  334.           for (i = TYPE_NFN_FIELDS (basetype) - 1; i >= 0; i--)
  335.         {
  336.           struct fn_field *f = TYPE_FN_FIELDLIST1 (basetype, i);
  337.           /* If one is virtual, then all are virtual.  */
  338.           if (TYPE_FN_FIELD_VIRTUAL_P (f, 0))
  339.             for (j = TYPE_FN_FIELDLIST_LENGTH (basetype, i) - 1; j >= 0; --j)
  340.               if (TYPE_FN_FIELD_VOFFSET (f, j) == fnoffset)
  341.             {
  342.               value_ptr temp = value_ind (arg2);
  343.               arg1 = value_virtual_fn_field (&temp, f, j, domain_type, 0);
  344.               arg2 = value_addr (temp);
  345.               goto got_it;
  346.             }
  347.         }
  348.           if (i < 0)
  349.         error ("virtual function at index %d not found", fnoffset);
  350.         }
  351.       else
  352.         {
  353.           VALUE_TYPE (arg1) = lookup_pointer_type (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)));
  354.         }
  355.     got_it:
  356.  
  357.       /* Now, say which argument to start evaluating from */
  358.       tem = 2;
  359.     }
  360.       else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
  361.     {
  362.       /* Hair for method invocations */
  363.       int tem2;
  364.  
  365.       nargs = longest_to_int (exp->elts[pc + 1].longconst) + 1;
  366.       /* First, evaluate the structure into arg2 */
  367.       pc2 = (*pos)++;
  368.       tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
  369.       *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);
  370.       if (noside == EVAL_SKIP)
  371.         goto nosideret;
  372.  
  373.       if (op == STRUCTOP_STRUCT)
  374.         {
  375.           /* If v is a variable in a register, and the user types
  376.          v.method (), this will produce an error, because v has
  377.          no address.
  378.  
  379.          A possible way around this would be to allocate a
  380.          copy of the variable on the stack, copy in the
  381.          contents, call the function, and copy out the
  382.          contents.  I.e. convert this from call by reference
  383.          to call by copy-return (or whatever it's called).
  384.          However, this does not work because it is not the
  385.          same: the method being called could stash a copy of
  386.          the address, and then future uses through that address
  387.          (after the method returns) would be expected to
  388.          use the variable itself, not some copy of it.  */
  389.           arg2 = evaluate_subexp_for_address (exp, pos, noside);
  390.         }
  391.       else
  392.         {
  393.           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  394.         }
  395.       /* Now, say which argument to start evaluating from */
  396.       tem = 2;
  397.     }
  398.       else
  399.     {
  400.       nargs = longest_to_int (exp->elts[pc + 1].longconst);
  401.       tem = 0;
  402.     }
  403.       /* Allocate arg vector, including space for the function to be
  404.      called in argvec[0] and a terminating NULL */
  405.       argvec = (value_ptr *) alloca (sizeof (value_ptr) * (nargs + 2));
  406.       for (; tem <= nargs; tem++)
  407.     /* Ensure that array expressions are coerced into pointer objects. */
  408.     argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
  409.  
  410.       /* signal end of arglist */
  411.       argvec[tem] = 0;
  412.  
  413.       if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
  414.     {
  415.       int static_memfuncp;
  416.       value_ptr temp = arg2;
  417.       char tstr[64];
  418.  
  419.       argvec[1] = arg2;
  420.       argvec[0] = 0;
  421.       strcpy(tstr, &exp->elts[pc2+2].string);
  422.           if (!argvec[0]) 
  423.         {
  424.           temp = arg2;
  425.           argvec[0] =
  426.           value_struct_elt (&temp, argvec+1, tstr,
  427.                   &static_memfuncp,
  428.                   op == STRUCTOP_STRUCT
  429.                   ? "structure" : "structure pointer");
  430.         }
  431.       arg2 = value_from_longest (lookup_pointer_type(VALUE_TYPE (temp)),
  432.              VALUE_ADDRESS (temp)+VALUE_OFFSET (temp));
  433.       argvec[1] = arg2;
  434.  
  435.       if (static_memfuncp)
  436.         {
  437.           argvec[1] = argvec[0];
  438.           nargs--;
  439.           argvec++;
  440.         }
  441.     }
  442.       else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
  443.     {
  444.       argvec[1] = arg2;
  445.       argvec[0] = arg1;
  446.     }
  447.  
  448.       if (noside == EVAL_SKIP)
  449.     goto nosideret;
  450.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  451.     {
  452.       /* If the return type doesn't look like a function type, call an
  453.          error.  This can happen if somebody tries to turn a variable into
  454.          a function call. This is here because people often want to
  455.          call, eg, strcmp, which gdb doesn't know is a function.  If
  456.          gdb isn't asked for it's opinion (ie. through "whatis"),
  457.          it won't offer it. */
  458.  
  459.       struct type *ftype =
  460.         TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0]));
  461.  
  462.       if (ftype)
  463.         return allocate_value (TYPE_TARGET_TYPE (VALUE_TYPE (argvec[0])));
  464.       else
  465.         error ("Expression of type other than \"Function returning ...\" used as function");
  466.     }
  467.       return call_function_by_hand (argvec[0], nargs, argvec + 1);
  468.  
  469.     case STRUCTOP_STRUCT:
  470.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  471.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  472.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  473.       if (noside == EVAL_SKIP)
  474.     goto nosideret;
  475.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  476.     return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1),
  477.                            &exp->elts[pc + 2].string,
  478.                            0),
  479.                lval_memory);
  480.       else
  481.     {
  482.       value_ptr temp = arg1;
  483.       return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
  484.                    NULL, "structure");
  485.     }
  486.  
  487.     case STRUCTOP_PTR:
  488.       tem = longest_to_int (exp->elts[pc + 1].longconst);
  489.       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
  490.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  491.       if (noside == EVAL_SKIP)
  492.     goto nosideret;
  493.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  494.     return value_zero (lookup_struct_elt_type (VALUE_TYPE (arg1),
  495.                            &exp->elts[pc + 2].string,
  496.                            0),
  497.                lval_memory);
  498.       else
  499.     {
  500.       value_ptr temp = arg1;
  501.       return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
  502.                    NULL, "structure pointer");
  503.     }
  504.  
  505.     case STRUCTOP_MEMBER:
  506.       arg1 = evaluate_subexp_for_address (exp, pos, noside);
  507.       goto handle_pointer_to_member;
  508.     case STRUCTOP_MPTR:
  509.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  510.     handle_pointer_to_member:
  511.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  512.       if (noside == EVAL_SKIP)
  513.     goto nosideret;
  514.       if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_PTR)
  515.     goto bad_pointer_to_member;
  516.       type = TYPE_TARGET_TYPE (VALUE_TYPE (arg2));
  517.       if (TYPE_CODE (type) == TYPE_CODE_METHOD)
  518.     error ("not implemented: pointer-to-method in pointer-to-member construct");
  519.       if (TYPE_CODE (type) != TYPE_CODE_MEMBER)
  520.     goto bad_pointer_to_member;
  521.       /* Now, convert these values to an address.  */
  522.       arg1 = value_cast (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
  523.              arg1);
  524.       arg3 = value_from_longest (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
  525.                  value_as_long (arg1) + value_as_long (arg2));
  526.       return value_ind (arg3);
  527.     bad_pointer_to_member:
  528.       error("non-pointer-to-member value used in pointer-to-member construct");
  529.  
  530.     case BINOP_CONCAT:
  531.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  532.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  533.       if (noside == EVAL_SKIP)
  534.     goto nosideret;
  535.       if (binop_user_defined_p (op, arg1, arg2))
  536.     return value_x_binop (arg1, arg2, op, OP_NULL);
  537.       else
  538.     return value_concat (arg1, arg2);
  539.  
  540.     case BINOP_ASSIGN:
  541.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  542.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  543.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  544.     return arg1;
  545.       if (binop_user_defined_p (op, arg1, arg2))
  546.     return value_x_binop (arg1, arg2, op, OP_NULL);
  547.       else
  548.     return value_assign (arg1, arg2);
  549.  
  550.     case BINOP_ASSIGN_MODIFY:
  551.       (*pos) += 2;
  552.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  553.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  554.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  555.     return arg1;
  556.       op = exp->elts[pc + 1].opcode;
  557.       if (binop_user_defined_p (op, arg1, arg2))
  558.     return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op);
  559.       else if (op == BINOP_ADD)
  560.     arg2 = value_add (arg1, arg2);
  561.       else if (op == BINOP_SUB)
  562.     arg2 = value_sub (arg1, arg2);
  563.       else
  564.     arg2 = value_binop (arg1, arg2, op);
  565.       return value_assign (arg1, arg2);
  566.  
  567.     case BINOP_ADD:
  568.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  569.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  570.       if (noside == EVAL_SKIP)
  571.     goto nosideret;
  572.       if (binop_user_defined_p (op, arg1, arg2))
  573.     return value_x_binop (arg1, arg2, op, OP_NULL);
  574.       else
  575.     return value_add (arg1, arg2);
  576.  
  577.     case BINOP_SUB:
  578.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  579.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  580.       if (noside == EVAL_SKIP)
  581.     goto nosideret;
  582.       if (binop_user_defined_p (op, arg1, arg2))
  583.     return value_x_binop (arg1, arg2, op, OP_NULL);
  584.       else
  585.     return value_sub (arg1, arg2);
  586.  
  587.     case BINOP_MUL:
  588.     case BINOP_DIV:
  589.     case BINOP_REM:
  590.     case BINOP_MOD:
  591.     case BINOP_LSH:
  592.     case BINOP_RSH:
  593.     case BINOP_BITWISE_AND:
  594.     case BINOP_BITWISE_IOR:
  595.     case BINOP_BITWISE_XOR:
  596.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  597.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  598.       if (noside == EVAL_SKIP)
  599.     goto nosideret;
  600.       if (binop_user_defined_p (op, arg1, arg2))
  601.     return value_x_binop (arg1, arg2, op, OP_NULL);
  602.       else
  603.     if (noside == EVAL_AVOID_SIDE_EFFECTS
  604.         && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
  605.       return value_zero (VALUE_TYPE (arg1), not_lval);
  606.       else
  607.     return value_binop (arg1, arg2, op);
  608.  
  609.     case BINOP_SUBSCRIPT:
  610.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  611.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  612.       if (noside == EVAL_SKIP)
  613.     goto nosideret;
  614.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  615.     {
  616.       /* If the user attempts to subscript something that has no target
  617.          type (like a plain int variable for example), then report this
  618.          as an error. */
  619.  
  620.       type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1));
  621.       if (type)
  622.         return value_zero (type, VALUE_LVAL (arg1));
  623.       else
  624.         error ("cannot subscript something of type `%s'",
  625.            TYPE_NAME (VALUE_TYPE (arg1)));
  626.     }
  627.                
  628.       if (binop_user_defined_p (op, arg1, arg2))
  629.     return value_x_binop (arg1, arg2, op, OP_NULL);
  630.       else
  631.     return value_subscript (arg1, arg2);
  632.  
  633.     case BINOP_IN:
  634.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  635.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  636.       if (noside == EVAL_SKIP)
  637.     goto nosideret;
  638.       return value_in (arg1, arg2);
  639.       
  640.     case MULTI_SUBSCRIPT:
  641.       (*pos) += 2;
  642.       nargs = longest_to_int (exp->elts[pc + 1].longconst);
  643.       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
  644.       while (nargs-- > 0)
  645.     {
  646.       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
  647.       /* FIXME:  EVAL_SKIP handling may not be correct. */
  648.       if (noside == EVAL_SKIP)
  649.         {
  650.           if (nargs > 0)
  651.         {
  652.           continue;
  653.         }
  654.           else
  655.         {
  656.           goto nosideret;
  657.         }
  658.         }
  659.       /* FIXME:  EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
  660.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  661.         {
  662.           /* If the user attempts to subscript something that has no target
  663.          type (like a plain int variable for example), then report this
  664.          as an error. */
  665.           
  666.           type = TYPE_TARGET_TYPE (VALUE_TYPE (arg1));
  667.           if (type != NULL)
  668.         {
  669.           arg1 = value_zero (type, VALUE_LVAL (arg1));
  670.           noside = EVAL_SKIP;
  671.           continue;
  672.         }
  673.           else
  674.         {
  675.           error ("cannot subscript something of type `%s'",
  676.              TYPE_NAME (VALUE_TYPE (arg1)));
  677.         }
  678.         }
  679.       
  680.       if (binop_user_defined_p (op, arg1, arg2))
  681.         {
  682.           arg1 = value_x_binop (arg1, arg2, op, OP_NULL);
  683.         }
  684.       else
  685.         {
  686.           arg1 = value_subscript (arg1, arg2);
  687.         }
  688.     }
  689.       return (arg1);
  690.  
  691.     case BINOP_LOGICAL_AND:
  692.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  693.       if (noside == EVAL_SKIP)
  694.     {
  695.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  696.       goto nosideret;
  697.     }
  698.       
  699.       oldpos = *pos;
  700.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  701.       *pos = oldpos;
  702.       
  703.       if (binop_user_defined_p (op, arg1, arg2)) 
  704.     {
  705.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  706.       return value_x_binop (arg1, arg2, op, OP_NULL);
  707.     }
  708.       else
  709.     {
  710.       tem = value_logical_not (arg1);
  711.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
  712.                   (tem ? EVAL_SKIP : noside));
  713.       return value_from_longest (builtin_type_int,
  714.                   (LONGEST) (!tem && !value_logical_not (arg2)));
  715.     }
  716.  
  717.     case BINOP_LOGICAL_OR:
  718.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  719.       if (noside == EVAL_SKIP)
  720.     {
  721.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  722.       goto nosideret;
  723.     }
  724.       
  725.       oldpos = *pos;
  726.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  727.       *pos = oldpos;
  728.       
  729.       if (binop_user_defined_p (op, arg1, arg2)) 
  730.     {
  731.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  732.       return value_x_binop (arg1, arg2, op, OP_NULL);
  733.     }
  734.       else
  735.     {
  736.       tem = value_logical_not (arg1);
  737.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
  738.                   (!tem ? EVAL_SKIP : noside));
  739.       return value_from_longest (builtin_type_int,
  740.                   (LONGEST) (!tem || !value_logical_not (arg2)));
  741.     }
  742.  
  743.     case BINOP_EQUAL:
  744.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  745.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  746.       if (noside == EVAL_SKIP)
  747.     goto nosideret;
  748.       if (binop_user_defined_p (op, arg1, arg2))
  749.     {
  750.       return value_x_binop (arg1, arg2, op, OP_NULL);
  751.     }
  752.       else
  753.     {
  754.       tem = value_equal (arg1, arg2);
  755.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  756.     }
  757.  
  758.     case BINOP_NOTEQUAL:
  759.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  760.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  761.       if (noside == EVAL_SKIP)
  762.     goto nosideret;
  763.       if (binop_user_defined_p (op, arg1, arg2))
  764.     {
  765.       return value_x_binop (arg1, arg2, op, OP_NULL);
  766.     }
  767.       else
  768.     {
  769.       tem = value_equal (arg1, arg2);
  770.       return value_from_longest (builtin_type_int, (LONGEST) ! tem);
  771.     }
  772.  
  773.     case BINOP_LESS:
  774.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  775.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  776.       if (noside == EVAL_SKIP)
  777.     goto nosideret;
  778.       if (binop_user_defined_p (op, arg1, arg2))
  779.     {
  780.       return value_x_binop (arg1, arg2, op, OP_NULL);
  781.     }
  782.       else
  783.     {
  784.       tem = value_less (arg1, arg2);
  785.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  786.     }
  787.  
  788.     case BINOP_GTR:
  789.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  790.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  791.       if (noside == EVAL_SKIP)
  792.     goto nosideret;
  793.       if (binop_user_defined_p (op, arg1, arg2))
  794.     {
  795.       return value_x_binop (arg1, arg2, op, OP_NULL);
  796.     }
  797.       else
  798.     {
  799.       tem = value_less (arg2, arg1);
  800.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  801.     }
  802.  
  803.     case BINOP_GEQ:
  804.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  805.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  806.       if (noside == EVAL_SKIP)
  807.     goto nosideret;
  808.       if (binop_user_defined_p (op, arg1, arg2))
  809.     {
  810.       return value_x_binop (arg1, arg2, op, OP_NULL);
  811.     }
  812.       else
  813.     {
  814.       tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
  815.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  816.     }
  817.  
  818.     case BINOP_LEQ:
  819.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  820.       arg2 = evaluate_subexp (VALUE_TYPE (arg1), exp, pos, noside);
  821.       if (noside == EVAL_SKIP)
  822.     goto nosideret;
  823.       if (binop_user_defined_p (op, arg1, arg2))
  824.     {
  825.       return value_x_binop (arg1, arg2, op, OP_NULL);
  826.     }
  827.       else 
  828.     {
  829.       tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
  830.       return value_from_longest (builtin_type_int, (LONGEST) tem);
  831.     }
  832.  
  833.     case BINOP_REPEAT:
  834.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  835.       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  836.       if (noside == EVAL_SKIP)
  837.     goto nosideret;
  838.       if (TYPE_CODE (VALUE_TYPE (arg2)) != TYPE_CODE_INT)
  839.     error ("Non-integral right operand for \"@\" operator.");
  840.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  841.     return allocate_repeat_value (VALUE_TYPE (arg1),
  842.                       longest_to_int (value_as_long (arg2)));
  843.       else
  844.     return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
  845.  
  846.     case BINOP_COMMA:
  847.       evaluate_subexp (NULL_TYPE, exp, pos, noside);
  848.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  849.  
  850.     case UNOP_NEG:
  851.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  852.       if (noside == EVAL_SKIP)
  853.     goto nosideret;
  854.       if (unop_user_defined_p (op, arg1))
  855.     return value_x_unop (arg1, op);
  856.       else
  857.     return value_neg (arg1);
  858.  
  859.     case UNOP_COMPLEMENT:
  860.       /* C++: check for and handle destructor names.  */
  861.       op = exp->elts[*pos].opcode;
  862.  
  863.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  864.       if (noside == EVAL_SKIP)
  865.     goto nosideret;
  866.       if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
  867.     return value_x_unop (arg1, UNOP_COMPLEMENT);
  868.       else
  869.     return value_complement (arg1);
  870.  
  871.     case UNOP_LOGICAL_NOT:
  872.       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  873.       if (noside == EVAL_SKIP)
  874.     goto nosideret;
  875.       if (unop_user_defined_p (op, arg1))
  876.     return value_x_unop (arg1, op);
  877.       else
  878.     return value_from_longest (builtin_type_int,
  879.                    (LONGEST) value_logical_not (arg1));
  880.  
  881.     case UNOP_IND:
  882.       if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
  883.         expect_type = TYPE_TARGET_TYPE (expect_type);
  884.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  885.       if (noside == EVAL_SKIP)
  886.     goto nosideret;
  887.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  888.     {
  889.       if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR
  890.           || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_REF
  891.           /* In C you can dereference an array to get the 1st elt.  */
  892.           || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY
  893.           )
  894.         return value_zero (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
  895.                    lval_memory);
  896.       else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_INT)
  897.         /* GDB allows dereferencing an int.  */
  898.         return value_zero (builtin_type_int, lval_memory);
  899.       else
  900.         error ("Attempt to take contents of a non-pointer value.");
  901.     }
  902.       return value_ind (arg1);
  903.  
  904.     case UNOP_ADDR:
  905.       /* C++: check for and handle pointer to members.  */
  906.       
  907.       op = exp->elts[*pos].opcode;
  908.  
  909.       if (noside == EVAL_SKIP)
  910.     {
  911.       if (op == OP_SCOPE)
  912.         {
  913.           int temm = longest_to_int (exp->elts[pc+3].longconst);
  914.           (*pos) += 3 + BYTES_TO_EXP_ELEM (temm + 1);
  915.         }
  916.       else
  917.         evaluate_subexp (expect_type, exp, pos, EVAL_SKIP);
  918.       goto nosideret;
  919.     }
  920.  
  921.       return evaluate_subexp_for_address (exp, pos, noside);
  922.  
  923.     case UNOP_SIZEOF:
  924.       if (noside == EVAL_SKIP)
  925.     {
  926.       evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
  927.       goto nosideret;
  928.     }
  929.       return evaluate_subexp_for_sizeof (exp, pos);
  930.  
  931.     case UNOP_CAST:
  932.       (*pos) += 2;
  933.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  934.       if (noside == EVAL_SKIP)
  935.     goto nosideret;
  936.       return value_cast (exp->elts[pc + 1].type, arg1);
  937.  
  938.     case UNOP_MEMVAL:
  939.       (*pos) += 2;
  940.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  941.       if (noside == EVAL_SKIP)
  942.     goto nosideret;
  943.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  944.     return value_zero (exp->elts[pc + 1].type, lval_memory);
  945.       else
  946.     return value_at_lazy (exp->elts[pc + 1].type,
  947.                   value_as_pointer (arg1));
  948.  
  949.     case UNOP_PREINCREMENT:
  950.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  951.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  952.     return arg1;
  953.       else if (unop_user_defined_p (op, arg1))
  954.     {
  955.       return value_x_unop (arg1, op);
  956.     }
  957.       else
  958.     {
  959.       arg2 = value_add (arg1, value_from_longest (builtin_type_char, 
  960.                            (LONGEST) 1));
  961.       return value_assign (arg1, arg2);
  962.     }
  963.  
  964.     case UNOP_PREDECREMENT:
  965.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  966.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  967.     return arg1;
  968.       else if (unop_user_defined_p (op, arg1))
  969.     {
  970.       return value_x_unop (arg1, op);
  971.     }
  972.       else
  973.     {
  974.       arg2 = value_sub (arg1, value_from_longest (builtin_type_char, 
  975.                            (LONGEST) 1));
  976.       return value_assign (arg1, arg2);
  977.     }
  978.  
  979.     case UNOP_POSTINCREMENT:
  980.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  981.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  982.     return arg1;
  983.       else if (unop_user_defined_p (op, arg1))
  984.     {
  985.       return value_x_unop (arg1, op);
  986.     }
  987.       else
  988.     {
  989.       arg2 = value_add (arg1, value_from_longest (builtin_type_char, 
  990.                            (LONGEST) 1));
  991.       value_assign (arg1, arg2);
  992.       return arg1;
  993.     }
  994.  
  995.     case UNOP_POSTDECREMENT:
  996.       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
  997.       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
  998.     return arg1;
  999.       else if (unop_user_defined_p (op, arg1))
  1000.     {
  1001.       return value_x_unop (arg1, op);
  1002.     }
  1003.       else
  1004.     {
  1005.       arg2 = value_sub (arg1, value_from_longest (builtin_type_char, 
  1006.                            (LONGEST) 1));
  1007.       value_assign (arg1, arg2);
  1008.       return arg1;
  1009.     }
  1010.     
  1011.     case OP_THIS:
  1012.       (*pos) += 1;
  1013.       return value_of_this (1);
  1014.  
  1015.     case OP_TYPE:
  1016.       error ("Attempt to use a type name as an expression");
  1017.  
  1018.     default:
  1019.       /* Removing this case and compiling with gcc -Wall reveals that
  1020.      a lot of cases are hitting this case.  Some of these should
  1021.      probably be removed from expression.h (e.g. do we need a BINOP_SCOPE
  1022.      and an OP_SCOPE?); others are legitimate expressions which are
  1023.      (apparently) not fully implemented.
  1024.  
  1025.      If there are any cases landing here which mean a user error,
  1026.      then they should be separate cases, with more descriptive
  1027.      error messages.  */
  1028.  
  1029.       error ("\
  1030. GDB does not (yet) know how to evaluated that kind of expression");
  1031.     }
  1032.  
  1033.  nosideret:
  1034.   return value_from_longest (builtin_type_long, (LONGEST) 1);
  1035. }
  1036.  
  1037. /* Evaluate a subexpression of EXP, at index *POS,
  1038.    and return the address of that subexpression.
  1039.    Advance *POS over the subexpression.
  1040.    If the subexpression isn't an lvalue, get an error.
  1041.    NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
  1042.    then only the type of the result need be correct.  */
  1043.  
  1044. static value_ptr
  1045. evaluate_subexp_for_address (exp, pos, noside)
  1046.      register struct expression *exp;
  1047.      register int *pos;
  1048.      enum noside noside;
  1049. {
  1050.   enum exp_opcode op;
  1051.   register int pc;
  1052.   struct symbol *var;
  1053.  
  1054.   pc = (*pos);
  1055.   op = exp->elts[pc].opcode;
  1056.  
  1057.   switch (op)
  1058.     {
  1059.     case UNOP_IND:
  1060.       (*pos)++;
  1061.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1062.  
  1063.     case UNOP_MEMVAL:
  1064.       (*pos) += 3;
  1065.       return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
  1066.              evaluate_subexp (NULL_TYPE, exp, pos, noside));
  1067.  
  1068.     case OP_VAR_VALUE:
  1069.       var = exp->elts[pc + 2].symbol;
  1070.  
  1071.       /* C++: The "address" of a reference should yield the address
  1072.        * of the object pointed to. Let value_addr() deal with it. */
  1073.       if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
  1074.         goto default_case;
  1075.  
  1076.       (*pos) += 4;
  1077.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1078.     {
  1079.       struct type *type =
  1080.         lookup_pointer_type (SYMBOL_TYPE (var));
  1081.       enum address_class sym_class = SYMBOL_CLASS (var);
  1082.  
  1083.       if (sym_class == LOC_CONST
  1084.           || sym_class == LOC_CONST_BYTES
  1085.           || sym_class == LOC_REGISTER
  1086.           || sym_class == LOC_REGPARM)
  1087.         error ("Attempt to take address of register or constant.");
  1088.  
  1089.     return
  1090.       value_zero (type, not_lval);
  1091.     }
  1092.       else
  1093.     return
  1094.       locate_var_value
  1095.         (var,
  1096.          block_innermost_frame (exp->elts[pc + 1].block));
  1097.  
  1098.     default:
  1099.     default_case:
  1100.       if (noside == EVAL_AVOID_SIDE_EFFECTS)
  1101.     {
  1102.       value_ptr x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1103.       if (VALUE_LVAL (x) == lval_memory)
  1104.         return value_zero (lookup_pointer_type (VALUE_TYPE (x)),
  1105.                    not_lval);
  1106.       else
  1107.         error ("Attempt to take address of non-lval");
  1108.     }
  1109.       return value_addr (evaluate_subexp (NULL_TYPE, exp, pos, noside));
  1110.     }
  1111. }
  1112.  
  1113. /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
  1114.    When used in contexts where arrays will be coerced anyway, this is
  1115.    equivalent to `evaluate_subexp' but much faster because it avoids
  1116.    actually fetching array contents (perhaps obsolete now that we have
  1117.    VALUE_LAZY).
  1118.  
  1119.    Note that we currently only do the coercion for C expressions, where
  1120.    arrays are zero based and the coercion is correct.  For other languages,
  1121.    with nonzero based arrays, coercion loses.  Use CAST_IS_CONVERSION
  1122.    to decide if coercion is appropriate.
  1123.  
  1124.    */
  1125.  
  1126. static value_ptr
  1127. evaluate_subexp_with_coercion (exp, pos, noside)
  1128.      register struct expression *exp;
  1129.      register int *pos;
  1130.      enum noside noside;
  1131. {
  1132.   register enum exp_opcode op;
  1133.   register int pc;
  1134.   register value_ptr val;
  1135.   struct symbol *var;
  1136.  
  1137.   pc = (*pos);
  1138.   op = exp->elts[pc].opcode;
  1139.  
  1140.   switch (op)
  1141.     {
  1142.     case OP_VAR_VALUE:
  1143.       var = exp->elts[pc + 2].symbol;
  1144.       if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_ARRAY
  1145.       && CAST_IS_CONVERSION)
  1146.     {
  1147.       (*pos) += 4;
  1148.       val =
  1149.         locate_var_value
  1150.           (var, block_innermost_frame (exp->elts[pc + 1].block));
  1151.       return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var))),
  1152.                  val);
  1153.     }
  1154.       /* FALLTHROUGH */
  1155.  
  1156.     default:
  1157.       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
  1158.     }
  1159. }
  1160.  
  1161. /* Evaluate a subexpression of EXP, at index *POS,
  1162.    and return a value for the size of that subexpression.
  1163.    Advance *POS over the subexpression.  */
  1164.  
  1165. static value_ptr
  1166. evaluate_subexp_for_sizeof (exp, pos)
  1167.      register struct expression *exp;
  1168.      register int *pos;
  1169. {
  1170.   enum exp_opcode op;
  1171.   register int pc;
  1172.   value_ptr val;
  1173.  
  1174.   pc = (*pos);
  1175.   op = exp->elts[pc].opcode;
  1176.  
  1177.   switch (op)
  1178.     {
  1179.       /* This case is handled specially
  1180.      so that we avoid creating a value for the result type.
  1181.      If the result type is very big, it's desirable not to
  1182.      create a value unnecessarily.  */
  1183.     case UNOP_IND:
  1184.       (*pos)++;
  1185.       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  1186.       return value_from_longest (builtin_type_int, (LONGEST)
  1187.               TYPE_LENGTH (TYPE_TARGET_TYPE (VALUE_TYPE (val))));
  1188.  
  1189.     case UNOP_MEMVAL:
  1190.       (*pos) += 3;
  1191.       return value_from_longest (builtin_type_int, 
  1192.                   (LONGEST) TYPE_LENGTH (exp->elts[pc + 1].type));
  1193.  
  1194.     case OP_VAR_VALUE:
  1195.       (*pos) += 4;
  1196.       return
  1197.     value_from_longest
  1198.       (builtin_type_int,
  1199.        (LONGEST) TYPE_LENGTH (SYMBOL_TYPE (exp->elts[pc + 2].symbol)));
  1200.  
  1201.     default:
  1202.       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
  1203.       return value_from_longest (builtin_type_int,
  1204.                   (LONGEST) TYPE_LENGTH (VALUE_TYPE (val)));
  1205.     }
  1206. }
  1207.  
  1208. /* Parse a type expression in the string [P..P+LENGTH). */
  1209.  
  1210. struct type *
  1211. parse_and_eval_type (p, length)
  1212.      char *p;
  1213.      int length;
  1214. {
  1215.     char *tmp = (char *)alloca (length + 4);
  1216.     struct expression *expr;
  1217.     tmp[0] = '(';
  1218.     memcpy (tmp+1, p, length);
  1219.     tmp[length+1] = ')';
  1220.     tmp[length+2] = '0';
  1221.     tmp[length+3] = '\0';
  1222.     expr = parse_expression (tmp);
  1223.     if (expr->elts[0].opcode != UNOP_CAST)
  1224.     error ("Internal error in eval_type.");
  1225.     return expr->elts[1].type;
  1226. }
  1227.