GDB (API)
/home/stan/gdb/src/gdb/eval.c
Go to the documentation of this file.
00001 /* Evaluate expressions for GDB.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "gdb_string.h"
00022 #include "symtab.h"
00023 #include "gdbtypes.h"
00024 #include "value.h"
00025 #include "expression.h"
00026 #include "target.h"
00027 #include "frame.h"
00028 #include "language.h"           /* For CAST_IS_CONVERSION.  */
00029 #include "f-lang.h"             /* For array bound stuff.  */
00030 #include "cp-abi.h"
00031 #include "infcall.h"
00032 #include "objc-lang.h"
00033 #include "block.h"
00034 #include "parser-defs.h"
00035 #include "cp-support.h"
00036 #include "ui-out.h"
00037 #include "exceptions.h"
00038 #include "regcache.h"
00039 #include "user-regs.h"
00040 #include "valprint.h"
00041 #include "gdb_obstack.h"
00042 #include "objfiles.h"
00043 #include "python/python.h"
00044 
00045 #include "gdb_assert.h"
00046 
00047 #include <ctype.h>
00048 
00049 /* This is defined in valops.c */
00050 extern int overload_resolution;
00051 
00052 /* Prototypes for local functions.  */
00053 
00054 static struct value *evaluate_subexp_for_sizeof (struct expression *, int *);
00055 
00056 static struct value *evaluate_subexp_for_address (struct expression *,
00057                                                   int *, enum noside);
00058 
00059 static struct value *evaluate_struct_tuple (struct value *,
00060                                             struct expression *, int *,
00061                                             enum noside, int);
00062 
00063 static LONGEST init_array_element (struct value *, struct value *,
00064                                    struct expression *, int *, enum noside,
00065                                    LONGEST, LONGEST);
00066 
00067 struct value *
00068 evaluate_subexp (struct type *expect_type, struct expression *exp,
00069                  int *pos, enum noside noside)
00070 {
00071   return (*exp->language_defn->la_exp_desc->evaluate_exp) 
00072     (expect_type, exp, pos, noside);
00073 }
00074 
00075 /* Parse the string EXP as a C expression, evaluate it,
00076    and return the result as a number.  */
00077 
00078 CORE_ADDR
00079 parse_and_eval_address (const char *exp)
00080 {
00081   struct expression *expr = parse_expression (exp);
00082   CORE_ADDR addr;
00083   struct cleanup *old_chain =
00084     make_cleanup (free_current_contents, &expr);
00085 
00086   addr = value_as_address (evaluate_expression (expr));
00087   do_cleanups (old_chain);
00088   return addr;
00089 }
00090 
00091 /* Like parse_and_eval_address, but treats the value of the expression
00092    as an integer, not an address, returns a LONGEST, not a CORE_ADDR.  */
00093 LONGEST
00094 parse_and_eval_long (const char *exp)
00095 {
00096   struct expression *expr = parse_expression (exp);
00097   LONGEST retval;
00098   struct cleanup *old_chain =
00099     make_cleanup (free_current_contents, &expr);
00100 
00101   retval = value_as_long (evaluate_expression (expr));
00102   do_cleanups (old_chain);
00103   return (retval);
00104 }
00105 
00106 struct value *
00107 parse_and_eval (const char *exp)
00108 {
00109   struct expression *expr = parse_expression (exp);
00110   struct value *val;
00111   struct cleanup *old_chain =
00112     make_cleanup (free_current_contents, &expr);
00113 
00114   val = evaluate_expression (expr);
00115   do_cleanups (old_chain);
00116   return val;
00117 }
00118 
00119 /* Parse up to a comma (or to a closeparen)
00120    in the string EXPP as an expression, evaluate it, and return the value.
00121    EXPP is advanced to point to the comma.  */
00122 
00123 struct value *
00124 parse_to_comma_and_eval (const char **expp)
00125 {
00126   struct expression *expr = parse_exp_1 (expp, 0, (struct block *) 0, 1);
00127   struct value *val;
00128   struct cleanup *old_chain =
00129     make_cleanup (free_current_contents, &expr);
00130 
00131   val = evaluate_expression (expr);
00132   do_cleanups (old_chain);
00133   return val;
00134 }
00135 
00136 /* Evaluate an expression in internal prefix form
00137    such as is constructed by parse.y.
00138 
00139    See expression.h for info on the format of an expression.  */
00140 
00141 struct value *
00142 evaluate_expression (struct expression *exp)
00143 {
00144   int pc = 0;
00145 
00146   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
00147 }
00148 
00149 /* Evaluate an expression, avoiding all memory references
00150    and getting a value whose type alone is correct.  */
00151 
00152 struct value *
00153 evaluate_type (struct expression *exp)
00154 {
00155   int pc = 0;
00156 
00157   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
00158 }
00159 
00160 /* Evaluate a subexpression, avoiding all memory references and
00161    getting a value whose type alone is correct.  */
00162 
00163 struct value *
00164 evaluate_subexpression_type (struct expression *exp, int subexp)
00165 {
00166   return evaluate_subexp (NULL_TYPE, exp, &subexp, EVAL_AVOID_SIDE_EFFECTS);
00167 }
00168 
00169 /* Find the current value of a watchpoint on EXP.  Return the value in
00170    *VALP and *RESULTP and the chain of intermediate and final values
00171    in *VAL_CHAIN.  RESULTP and VAL_CHAIN may be NULL if the caller does
00172    not need them.
00173 
00174    If PRESERVE_ERRORS is true, then exceptions are passed through.
00175    Otherwise, if PRESERVE_ERRORS is false, then if a memory error
00176    occurs while evaluating the expression, *RESULTP will be set to
00177    NULL.  *RESULTP may be a lazy value, if the result could not be
00178    read from memory.  It is used to determine whether a value is
00179    user-specified (we should watch the whole value) or intermediate
00180    (we should watch only the bit used to locate the final value).
00181 
00182    If the final value, or any intermediate value, could not be read
00183    from memory, *VALP will be set to NULL.  *VAL_CHAIN will still be
00184    set to any referenced values.  *VALP will never be a lazy value.
00185    This is the value which we store in struct breakpoint.
00186 
00187    If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
00188    value chain.  The caller must free the values individually.  If
00189    VAL_CHAIN is NULL, all generated values will be left on the value
00190    chain.  */
00191 
00192 void
00193 fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
00194                     struct value **resultp, struct value **val_chain,
00195                     int preserve_errors)
00196 {
00197   struct value *mark, *new_mark, *result;
00198   volatile struct gdb_exception ex;
00199 
00200   *valp = NULL;
00201   if (resultp)
00202     *resultp = NULL;
00203   if (val_chain)
00204     *val_chain = NULL;
00205 
00206   /* Evaluate the expression.  */
00207   mark = value_mark ();
00208   result = NULL;
00209 
00210   TRY_CATCH (ex, RETURN_MASK_ALL)
00211     {
00212       result = evaluate_subexp (NULL_TYPE, exp, pc, EVAL_NORMAL);
00213     }
00214   if (ex.reason < 0)
00215     {
00216       /* Ignore memory errors if we want watchpoints pointing at
00217          inaccessible memory to still be created; otherwise, throw the
00218          error to some higher catcher.  */
00219       switch (ex.error)
00220         {
00221         case MEMORY_ERROR:
00222           if (!preserve_errors)
00223             break;
00224         default:
00225           throw_exception (ex);
00226           break;
00227         }
00228     }
00229 
00230   new_mark = value_mark ();
00231   if (mark == new_mark)
00232     return;
00233   if (resultp)
00234     *resultp = result;
00235 
00236   /* Make sure it's not lazy, so that after the target stops again we
00237      have a non-lazy previous value to compare with.  */
00238   if (result != NULL)
00239     {
00240       if (!value_lazy (result))
00241         *valp = result;
00242       else
00243         {
00244           volatile struct gdb_exception except;
00245 
00246           TRY_CATCH (except, RETURN_MASK_ERROR)
00247             {
00248               value_fetch_lazy (result);
00249               *valp = result;
00250             }
00251         }
00252     }
00253 
00254   if (val_chain)
00255     {
00256       /* Return the chain of intermediate values.  We use this to
00257          decide which addresses to watch.  */
00258       *val_chain = new_mark;
00259       value_release_to_mark (mark);
00260     }
00261 }
00262 
00263 /* Extract a field operation from an expression.  If the subexpression
00264    of EXP starting at *SUBEXP is not a structure dereference
00265    operation, return NULL.  Otherwise, return the name of the
00266    dereferenced field, and advance *SUBEXP to point to the
00267    subexpression of the left-hand-side of the dereference.  This is
00268    used when completing field names.  */
00269 
00270 char *
00271 extract_field_op (struct expression *exp, int *subexp)
00272 {
00273   int tem;
00274   char *result;
00275 
00276   if (exp->elts[*subexp].opcode != STRUCTOP_STRUCT
00277       && exp->elts[*subexp].opcode != STRUCTOP_PTR)
00278     return NULL;
00279   tem = longest_to_int (exp->elts[*subexp + 1].longconst);
00280   result = &exp->elts[*subexp + 2].string;
00281   (*subexp) += 1 + 3 + BYTES_TO_EXP_ELEM (tem + 1);
00282   return result;
00283 }
00284 
00285 /* This function evaluates brace-initializers (in C/C++) for
00286    structure types.  */
00287 
00288 static struct value *
00289 evaluate_struct_tuple (struct value *struct_val,
00290                        struct expression *exp,
00291                        int *pos, enum noside noside, int nargs)
00292 {
00293   struct type *struct_type = check_typedef (value_type (struct_val));
00294   struct type *field_type;
00295   int fieldno = -1;
00296 
00297   while (--nargs >= 0)
00298     {
00299       struct value *val = NULL;
00300       int bitpos, bitsize;
00301       bfd_byte *addr;
00302 
00303       fieldno++;
00304       /* Skip static fields.  */
00305       while (fieldno < TYPE_NFIELDS (struct_type)
00306              && field_is_static (&TYPE_FIELD (struct_type,
00307                                               fieldno)))
00308         fieldno++;
00309       if (fieldno >= TYPE_NFIELDS (struct_type))
00310         error (_("too many initializers"));
00311       field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
00312       if (TYPE_CODE (field_type) == TYPE_CODE_UNION
00313           && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
00314         error (_("don't know which variant you want to set"));
00315 
00316       /* Here, struct_type is the type of the inner struct,
00317          while substruct_type is the type of the inner struct.
00318          These are the same for normal structures, but a variant struct
00319          contains anonymous union fields that contain substruct fields.
00320          The value fieldno is the index of the top-level (normal or
00321          anonymous union) field in struct_field, while the value
00322          subfieldno is the index of the actual real (named inner) field
00323          in substruct_type.  */
00324 
00325       field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
00326       if (val == 0)
00327         val = evaluate_subexp (field_type, exp, pos, noside);
00328 
00329       /* Now actually set the field in struct_val.  */
00330 
00331       /* Assign val to field fieldno.  */
00332       if (value_type (val) != field_type)
00333         val = value_cast (field_type, val);
00334 
00335       bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
00336       bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
00337       addr = value_contents_writeable (struct_val) + bitpos / 8;
00338       if (bitsize)
00339         modify_field (struct_type, addr,
00340                       value_as_long (val), bitpos % 8, bitsize);
00341       else
00342         memcpy (addr, value_contents (val),
00343                 TYPE_LENGTH (value_type (val)));
00344 
00345     }
00346   return struct_val;
00347 }
00348 
00349 /* Recursive helper function for setting elements of array tuples for
00350    (the deleted) Chill.  The target is ARRAY (which has bounds
00351    LOW_BOUND to HIGH_BOUND); the element value is ELEMENT; EXP, POS
00352    and NOSIDE are as usual.  Evaluates index expresions and sets the
00353    specified element(s) of ARRAY to ELEMENT.  Returns last index
00354    value.  */
00355 
00356 static LONGEST
00357 init_array_element (struct value *array, struct value *element,
00358                     struct expression *exp, int *pos,
00359                     enum noside noside, LONGEST low_bound, LONGEST high_bound)
00360 {
00361   LONGEST index;
00362   int element_size = TYPE_LENGTH (value_type (element));
00363 
00364   if (exp->elts[*pos].opcode == BINOP_COMMA)
00365     {
00366       (*pos)++;
00367       init_array_element (array, element, exp, pos, noside,
00368                           low_bound, high_bound);
00369       return init_array_element (array, element,
00370                                  exp, pos, noside, low_bound, high_bound);
00371     }
00372   else if (exp->elts[*pos].opcode == BINOP_RANGE)
00373     {
00374       LONGEST low, high;
00375 
00376       (*pos)++;
00377       low = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
00378       high = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
00379       if (low < low_bound || high > high_bound)
00380         error (_("tuple range index out of range"));
00381       for (index = low; index <= high; index++)
00382         {
00383           memcpy (value_contents_raw (array)
00384                   + (index - low_bound) * element_size,
00385                   value_contents (element), element_size);
00386         }
00387     }
00388   else
00389     {
00390       index = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
00391       if (index < low_bound || index > high_bound)
00392         error (_("tuple index out of range"));
00393       memcpy (value_contents_raw (array) + (index - low_bound) * element_size,
00394               value_contents (element), element_size);
00395     }
00396   return index;
00397 }
00398 
00399 static struct value *
00400 value_f90_subarray (struct value *array,
00401                     struct expression *exp, int *pos, enum noside noside)
00402 {
00403   int pc = (*pos) + 1;
00404   LONGEST low_bound, high_bound;
00405   struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
00406   enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
00407  
00408   *pos += 3;
00409 
00410   if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
00411     low_bound = TYPE_LOW_BOUND (range);
00412   else
00413     low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
00414 
00415   if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
00416     high_bound = TYPE_HIGH_BOUND (range);
00417   else
00418     high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
00419 
00420   return value_slice (array, low_bound, high_bound - low_bound + 1);
00421 }
00422 
00423 
00424 /* Promote value ARG1 as appropriate before performing a unary operation
00425    on this argument.
00426    If the result is not appropriate for any particular language then it
00427    needs to patch this function.  */
00428 
00429 void
00430 unop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
00431               struct value **arg1)
00432 {
00433   struct type *type1;
00434 
00435   *arg1 = coerce_ref (*arg1);
00436   type1 = check_typedef (value_type (*arg1));
00437 
00438   if (is_integral_type (type1))
00439     {
00440       switch (language->la_language)
00441         {
00442         default:
00443           /* Perform integral promotion for ANSI C/C++.
00444              If not appropropriate for any particular language
00445              it needs to modify this function.  */
00446           {
00447             struct type *builtin_int = builtin_type (gdbarch)->builtin_int;
00448 
00449             if (TYPE_LENGTH (type1) < TYPE_LENGTH (builtin_int))
00450               *arg1 = value_cast (builtin_int, *arg1);
00451           }
00452           break;
00453         }
00454     }
00455 }
00456 
00457 /* Promote values ARG1 and ARG2 as appropriate before performing a binary
00458    operation on those two operands.
00459    If the result is not appropriate for any particular language then it
00460    needs to patch this function.  */
00461 
00462 void
00463 binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
00464                struct value **arg1, struct value **arg2)
00465 {
00466   struct type *promoted_type = NULL;
00467   struct type *type1;
00468   struct type *type2;
00469 
00470   *arg1 = coerce_ref (*arg1);
00471   *arg2 = coerce_ref (*arg2);
00472 
00473   type1 = check_typedef (value_type (*arg1));
00474   type2 = check_typedef (value_type (*arg2));
00475 
00476   if ((TYPE_CODE (type1) != TYPE_CODE_FLT
00477        && TYPE_CODE (type1) != TYPE_CODE_DECFLOAT
00478        && !is_integral_type (type1))
00479       || (TYPE_CODE (type2) != TYPE_CODE_FLT
00480           && TYPE_CODE (type2) != TYPE_CODE_DECFLOAT
00481           && !is_integral_type (type2)))
00482     return;
00483 
00484   if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT
00485       || TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
00486     {
00487       /* No promotion required.  */
00488     }
00489   else if (TYPE_CODE (type1) == TYPE_CODE_FLT
00490            || TYPE_CODE (type2) == TYPE_CODE_FLT)
00491     {
00492       switch (language->la_language)
00493         {
00494         case language_c:
00495         case language_cplus:
00496         case language_asm:
00497         case language_objc:
00498         case language_opencl:
00499           /* No promotion required.  */
00500           break;
00501 
00502         default:
00503           /* For other languages the result type is unchanged from gdb
00504              version 6.7 for backward compatibility.
00505              If either arg was long double, make sure that value is also long
00506              double.  Otherwise use double.  */
00507           if (TYPE_LENGTH (type1) * 8 > gdbarch_double_bit (gdbarch)
00508               || TYPE_LENGTH (type2) * 8 > gdbarch_double_bit (gdbarch))
00509             promoted_type = builtin_type (gdbarch)->builtin_long_double;
00510           else
00511             promoted_type = builtin_type (gdbarch)->builtin_double;
00512           break;
00513         }
00514     }
00515   else if (TYPE_CODE (type1) == TYPE_CODE_BOOL
00516            && TYPE_CODE (type2) == TYPE_CODE_BOOL)
00517     {
00518       /* No promotion required.  */
00519     }
00520   else
00521     /* Integral operations here.  */
00522     /* FIXME: Also mixed integral/booleans, with result an integer.  */
00523     {
00524       const struct builtin_type *builtin = builtin_type (gdbarch);
00525       unsigned int promoted_len1 = TYPE_LENGTH (type1);
00526       unsigned int promoted_len2 = TYPE_LENGTH (type2);
00527       int is_unsigned1 = TYPE_UNSIGNED (type1);
00528       int is_unsigned2 = TYPE_UNSIGNED (type2);
00529       unsigned int result_len;
00530       int unsigned_operation;
00531 
00532       /* Determine type length and signedness after promotion for
00533          both operands.  */
00534       if (promoted_len1 < TYPE_LENGTH (builtin->builtin_int))
00535         {
00536           is_unsigned1 = 0;
00537           promoted_len1 = TYPE_LENGTH (builtin->builtin_int);
00538         }
00539       if (promoted_len2 < TYPE_LENGTH (builtin->builtin_int))
00540         {
00541           is_unsigned2 = 0;
00542           promoted_len2 = TYPE_LENGTH (builtin->builtin_int);
00543         }
00544 
00545       if (promoted_len1 > promoted_len2)
00546         {
00547           unsigned_operation = is_unsigned1;
00548           result_len = promoted_len1;
00549         }
00550       else if (promoted_len2 > promoted_len1)
00551         {
00552           unsigned_operation = is_unsigned2;
00553           result_len = promoted_len2;
00554         }
00555       else
00556         {
00557           unsigned_operation = is_unsigned1 || is_unsigned2;
00558           result_len = promoted_len1;
00559         }
00560 
00561       switch (language->la_language)
00562         {
00563         case language_c:
00564         case language_cplus:
00565         case language_asm:
00566         case language_objc:
00567           if (result_len <= TYPE_LENGTH (builtin->builtin_int))
00568             {
00569               promoted_type = (unsigned_operation
00570                                ? builtin->builtin_unsigned_int
00571                                : builtin->builtin_int);
00572             }
00573           else if (result_len <= TYPE_LENGTH (builtin->builtin_long))
00574             {
00575               promoted_type = (unsigned_operation
00576                                ? builtin->builtin_unsigned_long
00577                                : builtin->builtin_long);
00578             }
00579           else
00580             {
00581               promoted_type = (unsigned_operation
00582                                ? builtin->builtin_unsigned_long_long
00583                                : builtin->builtin_long_long);
00584             }
00585           break;
00586         case language_opencl:
00587           if (result_len <= TYPE_LENGTH (lookup_signed_typename
00588                                          (language, gdbarch, "int")))
00589             {
00590               promoted_type =
00591                 (unsigned_operation
00592                  ? lookup_unsigned_typename (language, gdbarch, "int")
00593                  : lookup_signed_typename (language, gdbarch, "int"));
00594             }
00595           else if (result_len <= TYPE_LENGTH (lookup_signed_typename
00596                                               (language, gdbarch, "long")))
00597             {
00598               promoted_type =
00599                 (unsigned_operation
00600                  ? lookup_unsigned_typename (language, gdbarch, "long")
00601                  : lookup_signed_typename (language, gdbarch,"long"));
00602             }
00603           break;
00604         default:
00605           /* For other languages the result type is unchanged from gdb
00606              version 6.7 for backward compatibility.
00607              If either arg was long long, make sure that value is also long
00608              long.  Otherwise use long.  */
00609           if (unsigned_operation)
00610             {
00611               if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
00612                 promoted_type = builtin->builtin_unsigned_long_long;
00613               else
00614                 promoted_type = builtin->builtin_unsigned_long;
00615             }
00616           else
00617             {
00618               if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
00619                 promoted_type = builtin->builtin_long_long;
00620               else
00621                 promoted_type = builtin->builtin_long;
00622             }
00623           break;
00624         }
00625     }
00626 
00627   if (promoted_type)
00628     {
00629       /* Promote both operands to common type.  */
00630       *arg1 = value_cast (promoted_type, *arg1);
00631       *arg2 = value_cast (promoted_type, *arg2);
00632     }
00633 }
00634 
00635 static int
00636 ptrmath_type_p (const struct language_defn *lang, struct type *type)
00637 {
00638   type = check_typedef (type);
00639   if (TYPE_CODE (type) == TYPE_CODE_REF)
00640     type = TYPE_TARGET_TYPE (type);
00641 
00642   switch (TYPE_CODE (type))
00643     {
00644     case TYPE_CODE_PTR:
00645     case TYPE_CODE_FUNC:
00646       return 1;
00647 
00648     case TYPE_CODE_ARRAY:
00649       return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays;
00650 
00651     default:
00652       return 0;
00653     }
00654 }
00655 
00656 /* Constructs a fake method with the given parameter types.
00657    This function is used by the parser to construct an "expected"
00658    type for method overload resolution.  */
00659 
00660 static struct type *
00661 make_params (int num_types, struct type **param_types)
00662 {
00663   struct type *type = XZALLOC (struct type);
00664   TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
00665   TYPE_LENGTH (type) = 1;
00666   TYPE_CODE (type) = TYPE_CODE_METHOD;
00667   TYPE_VPTR_FIELDNO (type) = -1;
00668   TYPE_CHAIN (type) = type;
00669   if (num_types > 0)
00670     {
00671       if (param_types[num_types - 1] == NULL)
00672         {
00673           --num_types;
00674           TYPE_VARARGS (type) = 1;
00675         }
00676       else if (TYPE_CODE (check_typedef (param_types[num_types - 1]))
00677                == TYPE_CODE_VOID)
00678         {
00679           --num_types;
00680           /* Caller should have ensured this.  */
00681           gdb_assert (num_types == 0);
00682           TYPE_PROTOTYPED (type) = 1;
00683         }
00684     }
00685 
00686   TYPE_NFIELDS (type) = num_types;
00687   TYPE_FIELDS (type) = (struct field *)
00688     TYPE_ZALLOC (type, sizeof (struct field) * num_types);
00689 
00690   while (num_types-- > 0)
00691     TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
00692 
00693   return type;
00694 }
00695 
00696 struct value *
00697 evaluate_subexp_standard (struct type *expect_type,
00698                           struct expression *exp, int *pos,
00699                           enum noside noside)
00700 {
00701   enum exp_opcode op;
00702   int tem, tem2, tem3;
00703   int pc, pc2 = 0, oldpos;
00704   struct value *arg1 = NULL;
00705   struct value *arg2 = NULL;
00706   struct value *arg3;
00707   struct type *type;
00708   int nargs;
00709   struct value **argvec;
00710   int code;
00711   int ix;
00712   long mem_offset;
00713   struct type **arg_types;
00714   int save_pos1;
00715   struct symbol *function = NULL;
00716   char *function_name = NULL;
00717 
00718   pc = (*pos)++;
00719   op = exp->elts[pc].opcode;
00720 
00721   switch (op)
00722     {
00723     case OP_SCOPE:
00724       tem = longest_to_int (exp->elts[pc + 2].longconst);
00725       (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
00726       if (noside == EVAL_SKIP)
00727         goto nosideret;
00728       arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
00729                                   &exp->elts[pc + 3].string,
00730                                   expect_type, 0, noside);
00731       if (arg1 == NULL)
00732         error (_("There is no field named %s"), &exp->elts[pc + 3].string);
00733       return arg1;
00734 
00735     case OP_LONG:
00736       (*pos) += 3;
00737       return value_from_longest (exp->elts[pc + 1].type,
00738                                  exp->elts[pc + 2].longconst);
00739 
00740     case OP_DOUBLE:
00741       (*pos) += 3;
00742       return value_from_double (exp->elts[pc + 1].type,
00743                                 exp->elts[pc + 2].doubleconst);
00744 
00745     case OP_DECFLOAT:
00746       (*pos) += 3;
00747       return value_from_decfloat (exp->elts[pc + 1].type,
00748                                   exp->elts[pc + 2].decfloatconst);
00749 
00750     case OP_ADL_FUNC:
00751     case OP_VAR_VALUE:
00752       (*pos) += 3;
00753       if (noside == EVAL_SKIP)
00754         goto nosideret;
00755 
00756       /* JYG: We used to just return value_zero of the symbol type
00757          if we're asked to avoid side effects.  Otherwise we return
00758          value_of_variable (...).  However I'm not sure if
00759          value_of_variable () has any side effect.
00760          We need a full value object returned here for whatis_exp ()
00761          to call evaluate_type () and then pass the full value to
00762          value_rtti_target_type () if we are dealing with a pointer
00763          or reference to a base class and print object is on.  */
00764 
00765       {
00766         volatile struct gdb_exception except;
00767         struct value *ret = NULL;
00768 
00769         TRY_CATCH (except, RETURN_MASK_ERROR)
00770           {
00771             ret = value_of_variable (exp->elts[pc + 2].symbol,
00772                                      exp->elts[pc + 1].block);
00773           }
00774 
00775         if (except.reason < 0)
00776           {
00777             if (noside == EVAL_AVOID_SIDE_EFFECTS)
00778               ret = value_zero (SYMBOL_TYPE (exp->elts[pc + 2].symbol),
00779                                 not_lval);
00780             else
00781               throw_exception (except);
00782           }
00783 
00784         return ret;
00785       }
00786 
00787     case OP_VAR_ENTRY_VALUE:
00788       (*pos) += 2;
00789       if (noside == EVAL_SKIP)
00790         goto nosideret;
00791 
00792       {
00793         struct symbol *sym = exp->elts[pc + 1].symbol;
00794         struct frame_info *frame;
00795 
00796         if (noside == EVAL_AVOID_SIDE_EFFECTS)
00797           return value_zero (SYMBOL_TYPE (sym), not_lval);
00798 
00799         if (SYMBOL_COMPUTED_OPS (sym) == NULL
00800             || SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
00801           error (_("Symbol \"%s\" does not have any specific entry value"),
00802                  SYMBOL_PRINT_NAME (sym));
00803 
00804         frame = get_selected_frame (NULL);
00805         return SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry (sym, frame);
00806       }
00807 
00808     case OP_LAST:
00809       (*pos) += 2;
00810       return
00811         access_value_history (longest_to_int (exp->elts[pc + 1].longconst));
00812 
00813     case OP_REGISTER:
00814       {
00815         const char *name = &exp->elts[pc + 2].string;
00816         int regno;
00817         struct value *val;
00818 
00819         (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
00820         regno = user_reg_map_name_to_regnum (exp->gdbarch,
00821                                              name, strlen (name));
00822         if (regno == -1)
00823           error (_("Register $%s not available."), name);
00824 
00825         /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
00826            a value with the appropriate register type.  Unfortunately,
00827            we don't have easy access to the type of user registers.
00828            So for these registers, we fetch the register value regardless
00829            of the evaluation mode.  */
00830         if (noside == EVAL_AVOID_SIDE_EFFECTS
00831             && regno < gdbarch_num_regs (exp->gdbarch)
00832                         + gdbarch_num_pseudo_regs (exp->gdbarch))
00833           val = value_zero (register_type (exp->gdbarch, regno), not_lval);
00834         else
00835           val = value_of_register (regno, get_selected_frame (NULL));
00836         if (val == NULL)
00837           error (_("Value of register %s not available."), name);
00838         else
00839           return val;
00840       }
00841     case OP_BOOL:
00842       (*pos) += 2;
00843       type = language_bool_type (exp->language_defn, exp->gdbarch);
00844       return value_from_longest (type, exp->elts[pc + 1].longconst);
00845 
00846     case OP_INTERNALVAR:
00847       (*pos) += 2;
00848       return value_of_internalvar (exp->gdbarch,
00849                                    exp->elts[pc + 1].internalvar);
00850 
00851     case OP_STRING:
00852       tem = longest_to_int (exp->elts[pc + 1].longconst);
00853       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
00854       if (noside == EVAL_SKIP)
00855         goto nosideret;
00856       type = language_string_char_type (exp->language_defn, exp->gdbarch);
00857       return value_string (&exp->elts[pc + 2].string, tem, type);
00858 
00859     case OP_OBJC_NSSTRING:              /* Objective C Foundation Class
00860                                            NSString constant.  */
00861       tem = longest_to_int (exp->elts[pc + 1].longconst);
00862       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
00863       if (noside == EVAL_SKIP)
00864         {
00865           goto nosideret;
00866         }
00867       return value_nsstring (exp->gdbarch, &exp->elts[pc + 2].string, tem + 1);
00868 
00869     case OP_ARRAY:
00870       (*pos) += 3;
00871       tem2 = longest_to_int (exp->elts[pc + 1].longconst);
00872       tem3 = longest_to_int (exp->elts[pc + 2].longconst);
00873       nargs = tem3 - tem2 + 1;
00874       type = expect_type ? check_typedef (expect_type) : NULL_TYPE;
00875 
00876       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
00877           && TYPE_CODE (type) == TYPE_CODE_STRUCT)
00878         {
00879           struct value *rec = allocate_value (expect_type);
00880 
00881           memset (value_contents_raw (rec), '\0', TYPE_LENGTH (type));
00882           return evaluate_struct_tuple (rec, exp, pos, noside, nargs);
00883         }
00884 
00885       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
00886           && TYPE_CODE (type) == TYPE_CODE_ARRAY)
00887         {
00888           struct type *range_type = TYPE_INDEX_TYPE (type);
00889           struct type *element_type = TYPE_TARGET_TYPE (type);
00890           struct value *array = allocate_value (expect_type);
00891           int element_size = TYPE_LENGTH (check_typedef (element_type));
00892           LONGEST low_bound, high_bound, index;
00893 
00894           if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
00895             {
00896               low_bound = 0;
00897               high_bound = (TYPE_LENGTH (type) / element_size) - 1;
00898             }
00899           index = low_bound;
00900           memset (value_contents_raw (array), 0, TYPE_LENGTH (expect_type));
00901           for (tem = nargs; --nargs >= 0;)
00902             {
00903               struct value *element;
00904               int index_pc = 0;
00905 
00906               if (exp->elts[*pos].opcode == BINOP_RANGE)
00907                 {
00908                   index_pc = ++(*pos);
00909                   evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
00910                 }
00911               element = evaluate_subexp (element_type, exp, pos, noside);
00912               if (value_type (element) != element_type)
00913                 element = value_cast (element_type, element);
00914               if (index_pc)
00915                 {
00916                   int continue_pc = *pos;
00917 
00918                   *pos = index_pc;
00919                   index = init_array_element (array, element, exp, pos, noside,
00920                                               low_bound, high_bound);
00921                   *pos = continue_pc;
00922                 }
00923               else
00924                 {
00925                   if (index > high_bound)
00926                     /* To avoid memory corruption.  */
00927                     error (_("Too many array elements"));
00928                   memcpy (value_contents_raw (array)
00929                           + (index - low_bound) * element_size,
00930                           value_contents (element),
00931                           element_size);
00932                 }
00933               index++;
00934             }
00935           return array;
00936         }
00937 
00938       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
00939           && TYPE_CODE (type) == TYPE_CODE_SET)
00940         {
00941           struct value *set = allocate_value (expect_type);
00942           gdb_byte *valaddr = value_contents_raw (set);
00943           struct type *element_type = TYPE_INDEX_TYPE (type);
00944           struct type *check_type = element_type;
00945           LONGEST low_bound, high_bound;
00946 
00947           /* Get targettype of elementtype.  */
00948           while (TYPE_CODE (check_type) == TYPE_CODE_RANGE
00949                  || TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
00950             check_type = TYPE_TARGET_TYPE (check_type);
00951 
00952           if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
00953             error (_("(power)set type with unknown size"));
00954           memset (valaddr, '\0', TYPE_LENGTH (type));
00955           for (tem = 0; tem < nargs; tem++)
00956             {
00957               LONGEST range_low, range_high;
00958               struct type *range_low_type, *range_high_type;
00959               struct value *elem_val;
00960 
00961               if (exp->elts[*pos].opcode == BINOP_RANGE)
00962                 {
00963                   (*pos)++;
00964                   elem_val = evaluate_subexp (element_type, exp, pos, noside);
00965                   range_low_type = value_type (elem_val);
00966                   range_low = value_as_long (elem_val);
00967                   elem_val = evaluate_subexp (element_type, exp, pos, noside);
00968                   range_high_type = value_type (elem_val);
00969                   range_high = value_as_long (elem_val);
00970                 }
00971               else
00972                 {
00973                   elem_val = evaluate_subexp (element_type, exp, pos, noside);
00974                   range_low_type = range_high_type = value_type (elem_val);
00975                   range_low = range_high = value_as_long (elem_val);
00976                 }
00977               /* Check types of elements to avoid mixture of elements from
00978                  different types. Also check if type of element is "compatible"
00979                  with element type of powerset.  */
00980               if (TYPE_CODE (range_low_type) == TYPE_CODE_RANGE)
00981                 range_low_type = TYPE_TARGET_TYPE (range_low_type);
00982               if (TYPE_CODE (range_high_type) == TYPE_CODE_RANGE)
00983                 range_high_type = TYPE_TARGET_TYPE (range_high_type);
00984               if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type))
00985                   || (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM
00986                       && (range_low_type != range_high_type)))
00987                 /* different element modes.  */
00988                 error (_("POWERSET tuple elements of different mode"));
00989               if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type))
00990                   || (TYPE_CODE (check_type) == TYPE_CODE_ENUM
00991                       && range_low_type != check_type))
00992                 error (_("incompatible POWERSET tuple elements"));
00993               if (range_low > range_high)
00994                 {
00995                   warning (_("empty POWERSET tuple range"));
00996                   continue;
00997                 }
00998               if (range_low < low_bound || range_high > high_bound)
00999                 error (_("POWERSET tuple element out of range"));
01000               range_low -= low_bound;
01001               range_high -= low_bound;
01002               for (; range_low <= range_high; range_low++)
01003                 {
01004                   int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;
01005 
01006                   if (gdbarch_bits_big_endian (exp->gdbarch))
01007                     bit_index = TARGET_CHAR_BIT - 1 - bit_index;
01008                   valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
01009                     |= 1 << bit_index;
01010                 }
01011             }
01012           return set;
01013         }
01014 
01015       argvec = (struct value **) alloca (sizeof (struct value *) * nargs);
01016       for (tem = 0; tem < nargs; tem++)
01017         {
01018           /* Ensure that array expressions are coerced into pointer
01019              objects.  */
01020           argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
01021         }
01022       if (noside == EVAL_SKIP)
01023         goto nosideret;
01024       return value_array (tem2, tem3, argvec);
01025 
01026     case TERNOP_SLICE:
01027       {
01028         struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01029         int lowbound
01030           = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
01031         int upper
01032           = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
01033 
01034         if (noside == EVAL_SKIP)
01035           goto nosideret;
01036         return value_slice (array, lowbound, upper - lowbound + 1);
01037       }
01038 
01039     case TERNOP_COND:
01040       /* Skip third and second args to evaluate the first one.  */
01041       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01042       if (value_logical_not (arg1))
01043         {
01044           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
01045           return evaluate_subexp (NULL_TYPE, exp, pos, noside);
01046         }
01047       else
01048         {
01049           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01050           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
01051           return arg2;
01052         }
01053 
01054     case OP_OBJC_SELECTOR:
01055       {                         /* Objective C @selector operator.  */
01056         char *sel = &exp->elts[pc + 2].string;
01057         int len = longest_to_int (exp->elts[pc + 1].longconst);
01058         struct type *selector_type;
01059 
01060         (*pos) += 3 + BYTES_TO_EXP_ELEM (len + 1);
01061         if (noside == EVAL_SKIP)
01062           goto nosideret;
01063 
01064         if (sel[len] != 0)
01065           sel[len] = 0;         /* Make sure it's terminated.  */
01066 
01067         selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
01068         return value_from_longest (selector_type,
01069                                    lookup_child_selector (exp->gdbarch, sel));
01070       }
01071 
01072     case OP_OBJC_MSGCALL:
01073       {                         /* Objective C message (method) call.  */
01074 
01075         CORE_ADDR responds_selector = 0;
01076         CORE_ADDR method_selector = 0;
01077 
01078         CORE_ADDR selector = 0;
01079 
01080         int struct_return = 0;
01081         int sub_no_side = 0;
01082 
01083         struct value *msg_send = NULL;
01084         struct value *msg_send_stret = NULL;
01085         int gnu_runtime = 0;
01086 
01087         struct value *target = NULL;
01088         struct value *method = NULL;
01089         struct value *called_method = NULL; 
01090 
01091         struct type *selector_type = NULL;
01092         struct type *long_type;
01093 
01094         struct value *ret = NULL;
01095         CORE_ADDR addr = 0;
01096 
01097         selector = exp->elts[pc + 1].longconst;
01098         nargs = exp->elts[pc + 2].longconst;
01099         argvec = (struct value **) alloca (sizeof (struct value *) 
01100                                            * (nargs + 5));
01101 
01102         (*pos) += 3;
01103 
01104         long_type = builtin_type (exp->gdbarch)->builtin_long;
01105         selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
01106 
01107         if (noside == EVAL_AVOID_SIDE_EFFECTS)
01108           sub_no_side = EVAL_NORMAL;
01109         else
01110           sub_no_side = noside;
01111 
01112         target = evaluate_subexp (selector_type, exp, pos, sub_no_side);
01113 
01114         if (value_as_long (target) == 0)
01115           return value_from_longest (long_type, 0);
01116         
01117         if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0))
01118           gnu_runtime = 1;
01119         
01120         /* Find the method dispatch (Apple runtime) or method lookup
01121            (GNU runtime) function for Objective-C.  These will be used
01122            to lookup the symbol information for the method.  If we
01123            can't find any symbol information, then we'll use these to
01124            call the method, otherwise we can call the method
01125            directly.  The msg_send_stret function is used in the special
01126            case of a method that returns a structure (Apple runtime 
01127            only).  */
01128         if (gnu_runtime)
01129           {
01130             struct type *type = selector_type;
01131 
01132             type = lookup_function_type (type);
01133             type = lookup_pointer_type (type);
01134             type = lookup_function_type (type);
01135             type = lookup_pointer_type (type);
01136 
01137             msg_send = find_function_in_inferior ("objc_msg_lookup", NULL);
01138             msg_send_stret
01139               = find_function_in_inferior ("objc_msg_lookup", NULL);
01140 
01141             msg_send = value_from_pointer (type, value_as_address (msg_send));
01142             msg_send_stret = value_from_pointer (type, 
01143                                         value_as_address (msg_send_stret));
01144           }
01145         else
01146           {
01147             msg_send = find_function_in_inferior ("objc_msgSend", NULL);
01148             /* Special dispatcher for methods returning structs.  */
01149             msg_send_stret
01150               = find_function_in_inferior ("objc_msgSend_stret", NULL);
01151           }
01152 
01153         /* Verify the target object responds to this method.  The
01154            standard top-level 'Object' class uses a different name for
01155            the verification method than the non-standard, but more
01156            often used, 'NSObject' class.  Make sure we check for both.  */
01157 
01158         responds_selector
01159           = lookup_child_selector (exp->gdbarch, "respondsToSelector:");
01160         if (responds_selector == 0)
01161           responds_selector
01162             = lookup_child_selector (exp->gdbarch, "respondsTo:");
01163         
01164         if (responds_selector == 0)
01165           error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
01166         
01167         method_selector
01168           = lookup_child_selector (exp->gdbarch, "methodForSelector:");
01169         if (method_selector == 0)
01170           method_selector
01171             = lookup_child_selector (exp->gdbarch, "methodFor:");
01172         
01173         if (method_selector == 0)
01174           error (_("no 'methodFor:' or 'methodForSelector:' method"));
01175 
01176         /* Call the verification method, to make sure that the target
01177          class implements the desired method.  */
01178 
01179         argvec[0] = msg_send;
01180         argvec[1] = target;
01181         argvec[2] = value_from_longest (long_type, responds_selector);
01182         argvec[3] = value_from_longest (long_type, selector);
01183         argvec[4] = 0;
01184 
01185         ret = call_function_by_hand (argvec[0], 3, argvec + 1);
01186         if (gnu_runtime)
01187           {
01188             /* Function objc_msg_lookup returns a pointer.  */
01189             argvec[0] = ret;
01190             ret = call_function_by_hand (argvec[0], 3, argvec + 1);
01191           }
01192         if (value_as_long (ret) == 0)
01193           error (_("Target does not respond to this message selector."));
01194 
01195         /* Call "methodForSelector:" method, to get the address of a
01196            function method that implements this selector for this
01197            class.  If we can find a symbol at that address, then we
01198            know the return type, parameter types etc.  (that's a good
01199            thing).  */
01200 
01201         argvec[0] = msg_send;
01202         argvec[1] = target;
01203         argvec[2] = value_from_longest (long_type, method_selector);
01204         argvec[3] = value_from_longest (long_type, selector);
01205         argvec[4] = 0;
01206 
01207         ret = call_function_by_hand (argvec[0], 3, argvec + 1);
01208         if (gnu_runtime)
01209           {
01210             argvec[0] = ret;
01211             ret = call_function_by_hand (argvec[0], 3, argvec + 1);
01212           }
01213 
01214         /* ret should now be the selector.  */
01215 
01216         addr = value_as_long (ret);
01217         if (addr)
01218           {
01219             struct symbol *sym = NULL;
01220 
01221             /* The address might point to a function descriptor;
01222                resolve it to the actual code address instead.  */
01223             addr = gdbarch_convert_from_func_ptr_addr (exp->gdbarch, addr,
01224                                                        &current_target);
01225 
01226             /* Is it a high_level symbol?  */
01227             sym = find_pc_function (addr);
01228             if (sym != NULL) 
01229               method = value_of_variable (sym, 0);
01230           }
01231 
01232         /* If we found a method with symbol information, check to see
01233            if it returns a struct.  Otherwise assume it doesn't.  */
01234 
01235         if (method)
01236           {
01237             CORE_ADDR funaddr;
01238             struct type *val_type;
01239 
01240             funaddr = find_function_addr (method, &val_type);
01241 
01242             block_for_pc (funaddr);
01243 
01244             CHECK_TYPEDEF (val_type);
01245           
01246             if ((val_type == NULL) 
01247                 || (TYPE_CODE(val_type) == TYPE_CODE_ERROR))
01248               {
01249                 if (expect_type != NULL)
01250                   val_type = expect_type;
01251               }
01252 
01253             struct_return = using_struct_return (exp->gdbarch, method,
01254                                                  val_type);
01255           }
01256         else if (expect_type != NULL)
01257           {
01258             struct_return = using_struct_return (exp->gdbarch, NULL,
01259                                                  check_typedef (expect_type));
01260           }
01261         
01262         /* Found a function symbol.  Now we will substitute its
01263            value in place of the message dispatcher (obj_msgSend),
01264            so that we call the method directly instead of thru
01265            the dispatcher.  The main reason for doing this is that
01266            we can now evaluate the return value and parameter values
01267            according to their known data types, in case we need to
01268            do things like promotion, dereferencing, special handling
01269            of structs and doubles, etc.
01270           
01271            We want to use the type signature of 'method', but still
01272            jump to objc_msgSend() or objc_msgSend_stret() to better
01273            mimic the behavior of the runtime.  */
01274         
01275         if (method)
01276           {
01277             if (TYPE_CODE (value_type (method)) != TYPE_CODE_FUNC)
01278               error (_("method address has symbol information "
01279                        "with non-function type; skipping"));
01280 
01281             /* Create a function pointer of the appropriate type, and
01282                replace its value with the value of msg_send or
01283                msg_send_stret.  We must use a pointer here, as
01284                msg_send and msg_send_stret are of pointer type, and
01285                the representation may be different on systems that use
01286                function descriptors.  */
01287             if (struct_return)
01288               called_method
01289                 = value_from_pointer (lookup_pointer_type (value_type (method)),
01290                                       value_as_address (msg_send_stret));
01291             else
01292               called_method
01293                 = value_from_pointer (lookup_pointer_type (value_type (method)),
01294                                       value_as_address (msg_send));
01295           }
01296         else
01297           {
01298             if (struct_return)
01299               called_method = msg_send_stret;
01300             else
01301               called_method = msg_send;
01302           }
01303 
01304         if (noside == EVAL_SKIP)
01305           goto nosideret;
01306 
01307         if (noside == EVAL_AVOID_SIDE_EFFECTS)
01308           {
01309             /* If the return type doesn't look like a function type,
01310                call an error.  This can happen if somebody tries to
01311                turn a variable into a function call.  This is here
01312                because people often want to call, eg, strcmp, which
01313                gdb doesn't know is a function.  If gdb isn't asked for
01314                it's opinion (ie. through "whatis"), it won't offer
01315                it.  */
01316 
01317             struct type *type = value_type (called_method);
01318 
01319             if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
01320               type = TYPE_TARGET_TYPE (type);
01321             type = TYPE_TARGET_TYPE (type);
01322 
01323             if (type)
01324             {
01325               if ((TYPE_CODE (type) == TYPE_CODE_ERROR) && expect_type)
01326                 return allocate_value (expect_type);
01327               else
01328                 return allocate_value (type);
01329             }
01330             else
01331               error (_("Expression of type other than "
01332                        "\"method returning ...\" used as a method"));
01333           }
01334 
01335         /* Now depending on whether we found a symbol for the method,
01336            we will either call the runtime dispatcher or the method
01337            directly.  */
01338 
01339         argvec[0] = called_method;
01340         argvec[1] = target;
01341         argvec[2] = value_from_longest (long_type, selector);
01342         /* User-supplied arguments.  */
01343         for (tem = 0; tem < nargs; tem++)
01344           argvec[tem + 3] = evaluate_subexp_with_coercion (exp, pos, noside);
01345         argvec[tem + 3] = 0;
01346 
01347         if (gnu_runtime && (method != NULL))
01348           {
01349             /* Function objc_msg_lookup returns a pointer.  */
01350             deprecated_set_value_type (argvec[0],
01351                                        lookup_pointer_type (lookup_function_type (value_type (argvec[0]))));
01352             argvec[0]
01353               = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
01354           }
01355 
01356         ret = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
01357         return ret;
01358       }
01359       break;
01360 
01361     case OP_FUNCALL:
01362       (*pos) += 2;
01363       op = exp->elts[*pos].opcode;
01364       nargs = longest_to_int (exp->elts[pc + 1].longconst);
01365       /* Allocate arg vector, including space for the function to be
01366          called in argvec[0] and a terminating NULL.  */
01367       argvec = (struct value **)
01368         alloca (sizeof (struct value *) * (nargs + 3));
01369       if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
01370         {
01371           /* First, evaluate the structure into arg2.  */
01372           pc2 = (*pos)++;
01373 
01374           if (noside == EVAL_SKIP)
01375             goto nosideret;
01376 
01377           if (op == STRUCTOP_MEMBER)
01378             {
01379               arg2 = evaluate_subexp_for_address (exp, pos, noside);
01380             }
01381           else
01382             {
01383               arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01384             }
01385 
01386           /* If the function is a virtual function, then the
01387              aggregate value (providing the structure) plays
01388              its part by providing the vtable.  Otherwise,
01389              it is just along for the ride: call the function
01390              directly.  */
01391 
01392           arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01393 
01394           type = check_typedef (value_type (arg1));
01395           if (TYPE_CODE (type) == TYPE_CODE_METHODPTR)
01396             {
01397               if (noside == EVAL_AVOID_SIDE_EFFECTS)
01398                 arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
01399               else
01400                 arg1 = cplus_method_ptr_to_value (&arg2, arg1);
01401 
01402               /* Now, say which argument to start evaluating from.  */
01403               nargs++;
01404               tem = 2;
01405               argvec[1] = arg2;
01406             }
01407           else if (TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
01408             {
01409               struct type *type_ptr
01410                 = lookup_pointer_type (TYPE_DOMAIN_TYPE (type));
01411               struct type *target_type_ptr
01412                 = lookup_pointer_type (TYPE_TARGET_TYPE (type));
01413 
01414               /* Now, convert these values to an address.  */
01415               arg2 = value_cast (type_ptr, arg2);
01416 
01417               mem_offset = value_as_long (arg1);
01418 
01419               arg1 = value_from_pointer (target_type_ptr,
01420                                          value_as_long (arg2) + mem_offset);
01421               arg1 = value_ind (arg1);
01422               tem = 1;
01423             }
01424           else
01425             error (_("Non-pointer-to-member value used in pointer-to-member "
01426                      "construct"));
01427         }
01428       else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
01429         {
01430           /* Hair for method invocations.  */
01431           int tem2;
01432 
01433           nargs++;
01434           /* First, evaluate the structure into arg2.  */
01435           pc2 = (*pos)++;
01436           tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
01437           *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);
01438           if (noside == EVAL_SKIP)
01439             goto nosideret;
01440 
01441           if (op == STRUCTOP_STRUCT)
01442             {
01443               /* If v is a variable in a register, and the user types
01444                  v.method (), this will produce an error, because v has
01445                  no address.
01446 
01447                  A possible way around this would be to allocate a
01448                  copy of the variable on the stack, copy in the
01449                  contents, call the function, and copy out the
01450                  contents.  I.e. convert this from call by reference
01451                  to call by copy-return (or whatever it's called).
01452                  However, this does not work because it is not the
01453                  same: the method being called could stash a copy of
01454                  the address, and then future uses through that address
01455                  (after the method returns) would be expected to
01456                  use the variable itself, not some copy of it.  */
01457               arg2 = evaluate_subexp_for_address (exp, pos, noside);
01458             }
01459           else
01460             {
01461               arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01462 
01463               /* Check to see if the operator '->' has been
01464                  overloaded.  If the operator has been overloaded
01465                  replace arg2 with the value returned by the custom
01466                  operator and continue evaluation.  */
01467               while (unop_user_defined_p (op, arg2))
01468                 {
01469                   volatile struct gdb_exception except;
01470                   struct value *value = NULL;
01471                   TRY_CATCH (except, RETURN_MASK_ERROR)
01472                     {
01473                       value = value_x_unop (arg2, op, noside);
01474                     }
01475 
01476                   if (except.reason < 0)
01477                     {
01478                       if (except.error == NOT_FOUND_ERROR)
01479                         break;
01480                       else
01481                         throw_exception (except);
01482                     }
01483                   arg2 = value;
01484                 }
01485             }
01486           /* Now, say which argument to start evaluating from.  */
01487           tem = 2;
01488         }
01489       else if (op == OP_SCOPE
01490                && overload_resolution
01491                && (exp->language_defn->la_language == language_cplus))
01492         {
01493           /* Unpack it locally so we can properly handle overload
01494              resolution.  */
01495           char *name;
01496           int local_tem;
01497 
01498           pc2 = (*pos)++;
01499           local_tem = longest_to_int (exp->elts[pc2 + 2].longconst);
01500           (*pos) += 4 + BYTES_TO_EXP_ELEM (local_tem + 1);
01501           type = exp->elts[pc2 + 1].type;
01502           name = &exp->elts[pc2 + 3].string;
01503 
01504           function = NULL;
01505           function_name = NULL;
01506           if (TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
01507             {
01508               function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type),
01509                                                      name,
01510                                                      get_selected_block (0),
01511                                                      VAR_DOMAIN);
01512               if (function == NULL)
01513                 error (_("No symbol \"%s\" in namespace \"%s\"."), 
01514                        name, TYPE_TAG_NAME (type));
01515 
01516               tem = 1;
01517             }
01518           else
01519             {
01520               gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
01521                           || TYPE_CODE (type) == TYPE_CODE_UNION);
01522               function_name = name;
01523 
01524               arg2 = value_zero (type, lval_memory);
01525               ++nargs;
01526               tem = 2;
01527             }
01528         }
01529       else if (op == OP_ADL_FUNC)
01530         {
01531           /* Save the function position and move pos so that the arguments
01532              can be evaluated.  */
01533           int func_name_len;
01534 
01535           save_pos1 = *pos;
01536           tem = 1;
01537 
01538           func_name_len = longest_to_int (exp->elts[save_pos1 + 3].longconst);
01539           (*pos) += 6 + BYTES_TO_EXP_ELEM (func_name_len + 1);
01540         }
01541       else
01542         {
01543           /* Non-method function call.  */
01544           save_pos1 = *pos;
01545           tem = 1;
01546 
01547           /* If this is a C++ function wait until overload resolution.  */
01548           if (op == OP_VAR_VALUE
01549               && overload_resolution
01550               && (exp->language_defn->la_language == language_cplus))
01551             {
01552               (*pos) += 4; /* Skip the evaluation of the symbol.  */
01553               argvec[0] = NULL;
01554             }
01555           else
01556             {
01557               argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
01558               type = value_type (argvec[0]);
01559               if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
01560                 type = TYPE_TARGET_TYPE (type);
01561               if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
01562                 {
01563                   for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
01564                     {
01565                       argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type,
01566                                                                       tem - 1),
01567                                                      exp, pos, noside);
01568                     }
01569                 }
01570             }
01571         }
01572 
01573       /* Evaluate arguments.  */
01574       for (; tem <= nargs; tem++)
01575         {
01576           /* Ensure that array expressions are coerced into pointer
01577              objects.  */
01578           argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
01579         }
01580 
01581       /* Signal end of arglist.  */
01582       argvec[tem] = 0;
01583       if (op == OP_ADL_FUNC)
01584         {
01585           struct symbol *symp;
01586           char *func_name;
01587           int  name_len;
01588           int string_pc = save_pos1 + 3;
01589 
01590           /* Extract the function name.  */
01591           name_len = longest_to_int (exp->elts[string_pc].longconst);
01592           func_name = (char *) alloca (name_len + 1);
01593           strcpy (func_name, &exp->elts[string_pc + 1].string);
01594 
01595           find_overload_match (&argvec[1], nargs, func_name,
01596                                NON_METHOD, /* not method */
01597                                NULL, NULL, /* pass NULL symbol since
01598                                               symbol is unknown */
01599                                NULL, &symp, NULL, 0);
01600 
01601           /* Now fix the expression being evaluated.  */
01602           exp->elts[save_pos1 + 2].symbol = symp;
01603           argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
01604         }
01605 
01606       if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR
01607           || (op == OP_SCOPE && function_name != NULL))
01608         {
01609           int static_memfuncp;
01610           char *tstr;
01611 
01612           /* Method invocation : stuff "this" as first parameter.  */
01613           argvec[1] = arg2;
01614 
01615           if (op != OP_SCOPE)
01616             {
01617               /* Name of method from expression.  */
01618               tstr = &exp->elts[pc2 + 2].string;
01619             }
01620           else
01621             tstr = function_name;
01622 
01623           if (overload_resolution && (exp->language_defn->la_language
01624                                       == language_cplus))
01625             {
01626               /* Language is C++, do some overload resolution before
01627                  evaluation.  */
01628               struct value *valp = NULL;
01629 
01630               (void) find_overload_match (&argvec[1], nargs, tstr,
01631                                           METHOD, /* method */
01632                                           &arg2,  /* the object */
01633                                           NULL, &valp, NULL,
01634                                           &static_memfuncp, 0);
01635 
01636               if (op == OP_SCOPE && !static_memfuncp)
01637                 {
01638                   /* For the time being, we don't handle this.  */
01639                   error (_("Call to overloaded function %s requires "
01640                            "`this' pointer"),
01641                          function_name);
01642                 }
01643               argvec[1] = arg2; /* the ``this'' pointer */
01644               argvec[0] = valp; /* Use the method found after overload
01645                                    resolution.  */
01646             }
01647           else
01648             /* Non-C++ case -- or no overload resolution.  */
01649             {
01650               struct value *temp = arg2;
01651 
01652               argvec[0] = value_struct_elt (&temp, argvec + 1, tstr,
01653                                             &static_memfuncp,
01654                                             op == STRUCTOP_STRUCT
01655                                        ? "structure" : "structure pointer");
01656               /* value_struct_elt updates temp with the correct value
01657                  of the ``this'' pointer if necessary, so modify argvec[1] to
01658                  reflect any ``this'' changes.  */
01659               arg2
01660                 = value_from_longest (lookup_pointer_type(value_type (temp)),
01661                                       value_address (temp)
01662                                       + value_embedded_offset (temp));
01663               argvec[1] = arg2; /* the ``this'' pointer */
01664             }
01665 
01666           if (static_memfuncp)
01667             {
01668               argvec[1] = argvec[0];
01669               nargs--;
01670               argvec++;
01671             }
01672         }
01673       else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
01674         {
01675           /* Pointer to member.  argvec[1] is already set up.  */
01676           argvec[0] = arg1;
01677         }
01678       else if (op == OP_VAR_VALUE || (op == OP_SCOPE && function != NULL))
01679         {
01680           /* Non-member function being called.  */
01681           /* fn: This can only be done for C++ functions.  A C-style function
01682              in a C++ program, for instance, does not have the fields that 
01683              are expected here.  */
01684 
01685           if (overload_resolution && (exp->language_defn->la_language
01686                                       == language_cplus))
01687             {
01688               /* Language is C++, do some overload resolution before
01689                  evaluation.  */
01690               struct symbol *symp;
01691               int no_adl = 0;
01692 
01693               /* If a scope has been specified disable ADL.  */
01694               if (op == OP_SCOPE)
01695                 no_adl = 1;
01696 
01697               if (op == OP_VAR_VALUE)
01698                 function = exp->elts[save_pos1+2].symbol;
01699 
01700               (void) find_overload_match (&argvec[1], nargs,
01701                                           NULL,        /* no need for name */
01702                                           NON_METHOD,  /* not method */
01703                                           NULL, function, /* the function */
01704                                           NULL, &symp, NULL, no_adl);
01705 
01706               if (op == OP_VAR_VALUE)
01707                 {
01708                   /* Now fix the expression being evaluated.  */
01709                   exp->elts[save_pos1+2].symbol = symp;
01710                   argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1,
01711                                                              noside);
01712                 }
01713               else
01714                 argvec[0] = value_of_variable (symp, get_selected_block (0));
01715             }
01716           else
01717             {
01718               /* Not C++, or no overload resolution allowed.  */
01719               /* Nothing to be done; argvec already correctly set up.  */
01720             }
01721         }
01722       else
01723         {
01724           /* It is probably a C-style function.  */
01725           /* Nothing to be done; argvec already correctly set up.  */
01726         }
01727 
01728     do_call_it:
01729 
01730       if (noside == EVAL_SKIP)
01731         goto nosideret;
01732       if (argvec[0] == NULL)
01733         error (_("Cannot evaluate function -- may be inlined"));
01734       if (noside == EVAL_AVOID_SIDE_EFFECTS)
01735         {
01736           /* If the return type doesn't look like a function type, call an
01737              error.  This can happen if somebody tries to turn a variable into
01738              a function call.  This is here because people often want to
01739              call, eg, strcmp, which gdb doesn't know is a function.  If
01740              gdb isn't asked for it's opinion (ie. through "whatis"),
01741              it won't offer it.  */
01742 
01743           struct type *ftype = value_type (argvec[0]);
01744 
01745           if (TYPE_CODE (ftype) == TYPE_CODE_INTERNAL_FUNCTION)
01746             {
01747               /* We don't know anything about what the internal
01748                  function might return, but we have to return
01749                  something.  */
01750               return value_zero (builtin_type (exp->gdbarch)->builtin_int,
01751                                  not_lval);
01752             }
01753           else if (TYPE_GNU_IFUNC (ftype))
01754             return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype)));
01755           else if (TYPE_TARGET_TYPE (ftype))
01756             return allocate_value (TYPE_TARGET_TYPE (ftype));
01757           else
01758             error (_("Expression of type other than "
01759                      "\"Function returning ...\" used as function"));
01760         }
01761       if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_INTERNAL_FUNCTION)
01762         return call_internal_function (exp->gdbarch, exp->language_defn,
01763                                        argvec[0], nargs, argvec + 1);
01764 
01765       return call_function_by_hand (argvec[0], nargs, argvec + 1);
01766       /* pai: FIXME save value from call_function_by_hand, then adjust
01767          pc by adjust_fn_pc if +ve.  */
01768 
01769     case OP_F77_UNDETERMINED_ARGLIST:
01770 
01771       /* Remember that in F77, functions, substring ops and 
01772          array subscript operations cannot be disambiguated 
01773          at parse time.  We have made all array subscript operations, 
01774          substring operations as well as function calls  come here 
01775          and we now have to discover what the heck this thing actually was.
01776          If it is a function, we process just as if we got an OP_FUNCALL.  */
01777 
01778       nargs = longest_to_int (exp->elts[pc + 1].longconst);
01779       (*pos) += 2;
01780 
01781       /* First determine the type code we are dealing with.  */
01782       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01783       type = check_typedef (value_type (arg1));
01784       code = TYPE_CODE (type);
01785 
01786       if (code == TYPE_CODE_PTR)
01787         {
01788           /* Fortran always passes variable to subroutines as pointer.
01789              So we need to look into its target type to see if it is
01790              array, string or function.  If it is, we need to switch
01791              to the target value the original one points to.  */ 
01792           struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
01793 
01794           if (TYPE_CODE (target_type) == TYPE_CODE_ARRAY
01795               || TYPE_CODE (target_type) == TYPE_CODE_STRING
01796               || TYPE_CODE (target_type) == TYPE_CODE_FUNC)
01797             {
01798               arg1 = value_ind (arg1);
01799               type = check_typedef (value_type (arg1));
01800               code = TYPE_CODE (type);
01801             }
01802         } 
01803 
01804       switch (code)
01805         {
01806         case TYPE_CODE_ARRAY:
01807           if (exp->elts[*pos].opcode == OP_F90_RANGE)
01808             return value_f90_subarray (arg1, exp, pos, noside);
01809           else
01810             goto multi_f77_subscript;
01811 
01812         case TYPE_CODE_STRING:
01813           if (exp->elts[*pos].opcode == OP_F90_RANGE)
01814             return value_f90_subarray (arg1, exp, pos, noside);
01815           else
01816             {
01817               arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
01818               return value_subscript (arg1, value_as_long (arg2));
01819             }
01820 
01821         case TYPE_CODE_PTR:
01822         case TYPE_CODE_FUNC:
01823           /* It's a function call.  */
01824           /* Allocate arg vector, including space for the function to be
01825              called in argvec[0] and a terminating NULL.  */
01826           argvec = (struct value **)
01827             alloca (sizeof (struct value *) * (nargs + 2));
01828           argvec[0] = arg1;
01829           tem = 1;
01830           for (; tem <= nargs; tem++)
01831             argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
01832           argvec[tem] = 0;      /* signal end of arglist */
01833           goto do_call_it;
01834 
01835         default:
01836           error (_("Cannot perform substring on this type"));
01837         }
01838 
01839     case OP_COMPLEX:
01840       /* We have a complex number, There should be 2 floating 
01841          point numbers that compose it.  */
01842       (*pos) += 2;
01843       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01844       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01845 
01846       return value_literal_complex (arg1, arg2, exp->elts[pc + 1].type);
01847 
01848     case STRUCTOP_STRUCT:
01849       tem = longest_to_int (exp->elts[pc + 1].longconst);
01850       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
01851       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01852       if (noside == EVAL_SKIP)
01853         goto nosideret;
01854       arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
01855                                NULL, "structure");
01856       if (noside == EVAL_AVOID_SIDE_EFFECTS)
01857         arg3 = value_zero (value_type (arg3), not_lval);
01858       return arg3;
01859 
01860     case STRUCTOP_PTR:
01861       tem = longest_to_int (exp->elts[pc + 1].longconst);
01862       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
01863       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01864       if (noside == EVAL_SKIP)
01865         goto nosideret;
01866 
01867       /* Check to see if operator '->' has been overloaded.  If so replace
01868          arg1 with the value returned by evaluating operator->().  */
01869       while (unop_user_defined_p (op, arg1))
01870         {
01871           volatile struct gdb_exception except;
01872           struct value *value = NULL;
01873           TRY_CATCH (except, RETURN_MASK_ERROR)
01874             {
01875               value = value_x_unop (arg1, op, noside);
01876             }
01877 
01878           if (except.reason < 0)
01879             {
01880               if (except.error == NOT_FOUND_ERROR)
01881                 break;
01882               else
01883                 throw_exception (except);
01884             }
01885           arg1 = value;
01886         }
01887 
01888       /* JYG: if print object is on we need to replace the base type
01889          with rtti type in order to continue on with successful
01890          lookup of member / method only available in the rtti type.  */
01891       {
01892         struct type *type = value_type (arg1);
01893         struct type *real_type;
01894         int full, top, using_enc;
01895         struct value_print_options opts;
01896 
01897         get_user_print_options (&opts);
01898         if (opts.objectprint && TYPE_TARGET_TYPE(type)
01899             && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
01900           {
01901             real_type = value_rtti_indirect_type (arg1, &full, &top,
01902                                                   &using_enc);
01903             if (real_type)
01904                 arg1 = value_cast (real_type, arg1);
01905           }
01906       }
01907 
01908       arg3 = value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
01909                                NULL, "structure pointer");
01910       if (noside == EVAL_AVOID_SIDE_EFFECTS)
01911         arg3 = value_zero (value_type (arg3), not_lval);
01912       return arg3;
01913 
01914     case STRUCTOP_MEMBER:
01915     case STRUCTOP_MPTR:
01916       if (op == STRUCTOP_MEMBER)
01917         arg1 = evaluate_subexp_for_address (exp, pos, noside);
01918       else
01919         arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01920 
01921       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01922 
01923       if (noside == EVAL_SKIP)
01924         goto nosideret;
01925 
01926       type = check_typedef (value_type (arg2));
01927       switch (TYPE_CODE (type))
01928         {
01929         case TYPE_CODE_METHODPTR:
01930           if (noside == EVAL_AVOID_SIDE_EFFECTS)
01931             return value_zero (TYPE_TARGET_TYPE (type), not_lval);
01932           else
01933             {
01934               arg2 = cplus_method_ptr_to_value (&arg1, arg2);
01935               gdb_assert (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR);
01936               return value_ind (arg2);
01937             }
01938 
01939         case TYPE_CODE_MEMBERPTR:
01940           /* Now, convert these values to an address.  */
01941           arg1 = value_cast_pointers (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
01942                                       arg1, 1);
01943 
01944           mem_offset = value_as_long (arg2);
01945 
01946           arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
01947                                      value_as_long (arg1) + mem_offset);
01948           return value_ind (arg3);
01949 
01950         default:
01951           error (_("non-pointer-to-member value used "
01952                    "in pointer-to-member construct"));
01953         }
01954 
01955     case TYPE_INSTANCE:
01956       nargs = longest_to_int (exp->elts[pc + 1].longconst);
01957       arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
01958       for (ix = 0; ix < nargs; ++ix)
01959         arg_types[ix] = exp->elts[pc + 1 + ix + 1].type;
01960 
01961       expect_type = make_params (nargs, arg_types);
01962       *(pos) += 3 + nargs;
01963       arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
01964       xfree (TYPE_FIELDS (expect_type));
01965       xfree (TYPE_MAIN_TYPE (expect_type));
01966       xfree (expect_type);
01967       return arg1;
01968 
01969     case BINOP_CONCAT:
01970       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
01971       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
01972       if (noside == EVAL_SKIP)
01973         goto nosideret;
01974       if (binop_user_defined_p (op, arg1, arg2))
01975         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
01976       else
01977         return value_concat (arg1, arg2);
01978 
01979     case BINOP_ASSIGN:
01980       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01981       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
01982 
01983       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
01984         return arg1;
01985       if (binop_user_defined_p (op, arg1, arg2))
01986         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
01987       else
01988         return value_assign (arg1, arg2);
01989 
01990     case BINOP_ASSIGN_MODIFY:
01991       (*pos) += 2;
01992       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
01993       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
01994       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
01995         return arg1;
01996       op = exp->elts[pc + 1].opcode;
01997       if (binop_user_defined_p (op, arg1, arg2))
01998         return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
01999       else if (op == BINOP_ADD && ptrmath_type_p (exp->language_defn,
02000                                                   value_type (arg1))
02001                && is_integral_type (value_type (arg2)))
02002         arg2 = value_ptradd (arg1, value_as_long (arg2));
02003       else if (op == BINOP_SUB && ptrmath_type_p (exp->language_defn,
02004                                                   value_type (arg1))
02005                && is_integral_type (value_type (arg2)))
02006         arg2 = value_ptradd (arg1, - value_as_long (arg2));
02007       else
02008         {
02009           struct value *tmp = arg1;
02010 
02011           /* For shift and integer exponentiation operations,
02012              only promote the first argument.  */
02013           if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
02014               && is_integral_type (value_type (arg2)))
02015             unop_promote (exp->language_defn, exp->gdbarch, &tmp);
02016           else
02017             binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
02018 
02019           arg2 = value_binop (tmp, arg2, op);
02020         }
02021       return value_assign (arg1, arg2);
02022 
02023     case BINOP_ADD:
02024       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
02025       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
02026       if (noside == EVAL_SKIP)
02027         goto nosideret;
02028       if (binop_user_defined_p (op, arg1, arg2))
02029         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02030       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
02031                && is_integral_type (value_type (arg2)))
02032         return value_ptradd (arg1, value_as_long (arg2));
02033       else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
02034                && is_integral_type (value_type (arg1)))
02035         return value_ptradd (arg2, value_as_long (arg1));
02036       else
02037         {
02038           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02039           return value_binop (arg1, arg2, BINOP_ADD);
02040         }
02041 
02042     case BINOP_SUB:
02043       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
02044       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
02045       if (noside == EVAL_SKIP)
02046         goto nosideret;
02047       if (binop_user_defined_p (op, arg1, arg2))
02048         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02049       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
02050                && ptrmath_type_p (exp->language_defn, value_type (arg2)))
02051         {
02052           /* FIXME -- should be ptrdiff_t */
02053           type = builtin_type (exp->gdbarch)->builtin_long;
02054           return value_from_longest (type, value_ptrdiff (arg1, arg2));
02055         }
02056       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
02057                && is_integral_type (value_type (arg2)))
02058         return value_ptradd (arg1, - value_as_long (arg2));
02059       else
02060         {
02061           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02062           return value_binop (arg1, arg2, BINOP_SUB);
02063         }
02064 
02065     case BINOP_EXP:
02066     case BINOP_MUL:
02067     case BINOP_DIV:
02068     case BINOP_INTDIV:
02069     case BINOP_REM:
02070     case BINOP_MOD:
02071     case BINOP_LSH:
02072     case BINOP_RSH:
02073     case BINOP_BITWISE_AND:
02074     case BINOP_BITWISE_IOR:
02075     case BINOP_BITWISE_XOR:
02076       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02077       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02078       if (noside == EVAL_SKIP)
02079         goto nosideret;
02080       if (binop_user_defined_p (op, arg1, arg2))
02081         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02082       else
02083         {
02084           /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
02085              fudge arg2 to avoid division-by-zero, the caller is
02086              (theoretically) only looking for the type of the result.  */
02087           if (noside == EVAL_AVOID_SIDE_EFFECTS
02088               /* ??? Do we really want to test for BINOP_MOD here?
02089                  The implementation of value_binop gives it a well-defined
02090                  value.  */
02091               && (op == BINOP_DIV
02092                   || op == BINOP_INTDIV
02093                   || op == BINOP_REM
02094                   || op == BINOP_MOD)
02095               && value_logical_not (arg2))
02096             {
02097               struct value *v_one, *retval;
02098 
02099               v_one = value_one (value_type (arg2));
02100               binop_promote (exp->language_defn, exp->gdbarch, &arg1, &v_one);
02101               retval = value_binop (arg1, v_one, op);
02102               return retval;
02103             }
02104           else
02105             {
02106               /* For shift and integer exponentiation operations,
02107                  only promote the first argument.  */
02108               if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
02109                   && is_integral_type (value_type (arg2)))
02110                 unop_promote (exp->language_defn, exp->gdbarch, &arg1);
02111               else
02112                 binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02113 
02114               return value_binop (arg1, arg2, op);
02115             }
02116         }
02117 
02118     case BINOP_RANGE:
02119       evaluate_subexp (NULL_TYPE, exp, pos, noside);
02120       evaluate_subexp (NULL_TYPE, exp, pos, noside);
02121       if (noside == EVAL_SKIP)
02122         goto nosideret;
02123       error (_("':' operator used in invalid context"));
02124 
02125     case BINOP_SUBSCRIPT:
02126       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02127       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02128       if (noside == EVAL_SKIP)
02129         goto nosideret;
02130       if (binop_user_defined_p (op, arg1, arg2))
02131         return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02132       else
02133         {
02134           /* If the user attempts to subscript something that is not an
02135              array or pointer type (like a plain int variable for example),
02136              then report this as an error.  */
02137 
02138           arg1 = coerce_ref (arg1);
02139           type = check_typedef (value_type (arg1));
02140           if (TYPE_CODE (type) != TYPE_CODE_ARRAY
02141               && TYPE_CODE (type) != TYPE_CODE_PTR)
02142             {
02143               if (TYPE_NAME (type))
02144                 error (_("cannot subscript something of type `%s'"),
02145                        TYPE_NAME (type));
02146               else
02147                 error (_("cannot subscript requested type"));
02148             }
02149 
02150           if (noside == EVAL_AVOID_SIDE_EFFECTS)
02151             return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
02152           else
02153             return value_subscript (arg1, value_as_long (arg2));
02154         }
02155 
02156     case BINOP_IN:
02157       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
02158       arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
02159       if (noside == EVAL_SKIP)
02160         goto nosideret;
02161       type = language_bool_type (exp->language_defn, exp->gdbarch);
02162       return value_from_longest (type, (LONGEST) value_in (arg1, arg2));
02163 
02164     case MULTI_SUBSCRIPT:
02165       (*pos) += 2;
02166       nargs = longest_to_int (exp->elts[pc + 1].longconst);
02167       arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
02168       while (nargs-- > 0)
02169         {
02170           arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
02171           /* FIXME:  EVAL_SKIP handling may not be correct.  */
02172           if (noside == EVAL_SKIP)
02173             {
02174               if (nargs > 0)
02175                 {
02176                   continue;
02177                 }
02178               else
02179                 {
02180                   goto nosideret;
02181                 }
02182             }
02183           /* FIXME:  EVAL_AVOID_SIDE_EFFECTS handling may not be correct.  */
02184           if (noside == EVAL_AVOID_SIDE_EFFECTS)
02185             {
02186               /* If the user attempts to subscript something that has no target
02187                  type (like a plain int variable for example), then report this
02188                  as an error.  */
02189 
02190               type = TYPE_TARGET_TYPE (check_typedef (value_type (arg1)));
02191               if (type != NULL)
02192                 {
02193                   arg1 = value_zero (type, VALUE_LVAL (arg1));
02194                   noside = EVAL_SKIP;
02195                   continue;
02196                 }
02197               else
02198                 {
02199                   error (_("cannot subscript something of type `%s'"),
02200                          TYPE_NAME (value_type (arg1)));
02201                 }
02202             }
02203 
02204           if (binop_user_defined_p (op, arg1, arg2))
02205             {
02206               arg1 = value_x_binop (arg1, arg2, op, OP_NULL, noside);
02207             }
02208           else
02209             {
02210               arg1 = coerce_ref (arg1);
02211               type = check_typedef (value_type (arg1));
02212 
02213               switch (TYPE_CODE (type))
02214                 {
02215                 case TYPE_CODE_PTR:
02216                 case TYPE_CODE_ARRAY:
02217                 case TYPE_CODE_STRING:
02218                   arg1 = value_subscript (arg1, value_as_long (arg2));
02219                   break;
02220 
02221                 default:
02222                   if (TYPE_NAME (type))
02223                     error (_("cannot subscript something of type `%s'"),
02224                            TYPE_NAME (type));
02225                   else
02226                     error (_("cannot subscript requested type"));
02227                 }
02228             }
02229         }
02230       return (arg1);
02231 
02232     multi_f77_subscript:
02233       {
02234         LONGEST subscript_array[MAX_FORTRAN_DIMS];
02235         int ndimensions = 1, i;
02236         struct value *array = arg1;
02237 
02238         if (nargs > MAX_FORTRAN_DIMS)
02239           error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
02240 
02241         ndimensions = calc_f77_array_dims (type);
02242 
02243         if (nargs != ndimensions)
02244           error (_("Wrong number of subscripts"));
02245 
02246         gdb_assert (nargs > 0);
02247 
02248         /* Now that we know we have a legal array subscript expression 
02249            let us actually find out where this element exists in the array.  */
02250 
02251         /* Take array indices left to right.  */
02252         for (i = 0; i < nargs; i++)
02253           {
02254             /* Evaluate each subscript; it must be a legal integer in F77.  */
02255             arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
02256 
02257             /* Fill in the subscript array.  */
02258 
02259             subscript_array[i] = value_as_long (arg2);
02260           }
02261 
02262         /* Internal type of array is arranged right to left.  */
02263         for (i = nargs; i > 0; i--)
02264           {
02265             struct type *array_type = check_typedef (value_type (array));
02266             LONGEST index = subscript_array[i - 1];
02267 
02268             array = value_subscripted_rvalue (array, index,
02269                                               f77_get_lowerbound (array_type));
02270           }
02271 
02272         return array;
02273       }
02274 
02275     case BINOP_LOGICAL_AND:
02276       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02277       if (noside == EVAL_SKIP)
02278         {
02279           evaluate_subexp (NULL_TYPE, exp, pos, noside);
02280           goto nosideret;
02281         }
02282 
02283       oldpos = *pos;
02284       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
02285       *pos = oldpos;
02286 
02287       if (binop_user_defined_p (op, arg1, arg2))
02288         {
02289           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02290           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02291         }
02292       else
02293         {
02294           tem = value_logical_not (arg1);
02295           arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
02296                                   (tem ? EVAL_SKIP : noside));
02297           type = language_bool_type (exp->language_defn, exp->gdbarch);
02298           return value_from_longest (type,
02299                              (LONGEST) (!tem && !value_logical_not (arg2)));
02300         }
02301 
02302     case BINOP_LOGICAL_OR:
02303       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02304       if (noside == EVAL_SKIP)
02305         {
02306           evaluate_subexp (NULL_TYPE, exp, pos, noside);
02307           goto nosideret;
02308         }
02309 
02310       oldpos = *pos;
02311       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
02312       *pos = oldpos;
02313 
02314       if (binop_user_defined_p (op, arg1, arg2))
02315         {
02316           arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02317           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02318         }
02319       else
02320         {
02321           tem = value_logical_not (arg1);
02322           arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
02323                                   (!tem ? EVAL_SKIP : noside));
02324           type = language_bool_type (exp->language_defn, exp->gdbarch);
02325           return value_from_longest (type,
02326                              (LONGEST) (!tem || !value_logical_not (arg2)));
02327         }
02328 
02329     case BINOP_EQUAL:
02330       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02331       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
02332       if (noside == EVAL_SKIP)
02333         goto nosideret;
02334       if (binop_user_defined_p (op, arg1, arg2))
02335         {
02336           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02337         }
02338       else
02339         {
02340           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02341           tem = value_equal (arg1, arg2);
02342           type = language_bool_type (exp->language_defn, exp->gdbarch);
02343           return value_from_longest (type, (LONGEST) tem);
02344         }
02345 
02346     case BINOP_NOTEQUAL:
02347       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02348       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
02349       if (noside == EVAL_SKIP)
02350         goto nosideret;
02351       if (binop_user_defined_p (op, arg1, arg2))
02352         {
02353           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02354         }
02355       else
02356         {
02357           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02358           tem = value_equal (arg1, arg2);
02359           type = language_bool_type (exp->language_defn, exp->gdbarch);
02360           return value_from_longest (type, (LONGEST) ! tem);
02361         }
02362 
02363     case BINOP_LESS:
02364       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02365       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
02366       if (noside == EVAL_SKIP)
02367         goto nosideret;
02368       if (binop_user_defined_p (op, arg1, arg2))
02369         {
02370           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02371         }
02372       else
02373         {
02374           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02375           tem = value_less (arg1, arg2);
02376           type = language_bool_type (exp->language_defn, exp->gdbarch);
02377           return value_from_longest (type, (LONGEST) tem);
02378         }
02379 
02380     case BINOP_GTR:
02381       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02382       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
02383       if (noside == EVAL_SKIP)
02384         goto nosideret;
02385       if (binop_user_defined_p (op, arg1, arg2))
02386         {
02387           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02388         }
02389       else
02390         {
02391           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02392           tem = value_less (arg2, arg1);
02393           type = language_bool_type (exp->language_defn, exp->gdbarch);
02394           return value_from_longest (type, (LONGEST) tem);
02395         }
02396 
02397     case BINOP_GEQ:
02398       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02399       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
02400       if (noside == EVAL_SKIP)
02401         goto nosideret;
02402       if (binop_user_defined_p (op, arg1, arg2))
02403         {
02404           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02405         }
02406       else
02407         {
02408           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02409           tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
02410           type = language_bool_type (exp->language_defn, exp->gdbarch);
02411           return value_from_longest (type, (LONGEST) tem);
02412         }
02413 
02414     case BINOP_LEQ:
02415       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02416       arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
02417       if (noside == EVAL_SKIP)
02418         goto nosideret;
02419       if (binop_user_defined_p (op, arg1, arg2))
02420         {
02421           return value_x_binop (arg1, arg2, op, OP_NULL, noside);
02422         }
02423       else
02424         {
02425           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
02426           tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
02427           type = language_bool_type (exp->language_defn, exp->gdbarch);
02428           return value_from_longest (type, (LONGEST) tem);
02429         }
02430 
02431     case BINOP_REPEAT:
02432       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02433       arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02434       if (noside == EVAL_SKIP)
02435         goto nosideret;
02436       type = check_typedef (value_type (arg2));
02437       if (TYPE_CODE (type) != TYPE_CODE_INT)
02438         error (_("Non-integral right operand for \"@\" operator."));
02439       if (noside == EVAL_AVOID_SIDE_EFFECTS)
02440         {
02441           return allocate_repeat_value (value_type (arg1),
02442                                      longest_to_int (value_as_long (arg2)));
02443         }
02444       else
02445         return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
02446 
02447     case BINOP_COMMA:
02448       evaluate_subexp (NULL_TYPE, exp, pos, noside);
02449       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
02450 
02451     case UNOP_PLUS:
02452       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02453       if (noside == EVAL_SKIP)
02454         goto nosideret;
02455       if (unop_user_defined_p (op, arg1))
02456         return value_x_unop (arg1, op, noside);
02457       else
02458         {
02459           unop_promote (exp->language_defn, exp->gdbarch, &arg1);
02460           return value_pos (arg1);
02461         }
02462       
02463     case UNOP_NEG:
02464       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02465       if (noside == EVAL_SKIP)
02466         goto nosideret;
02467       if (unop_user_defined_p (op, arg1))
02468         return value_x_unop (arg1, op, noside);
02469       else
02470         {
02471           unop_promote (exp->language_defn, exp->gdbarch, &arg1);
02472           return value_neg (arg1);
02473         }
02474 
02475     case UNOP_COMPLEMENT:
02476       /* C++: check for and handle destructor names.  */
02477       op = exp->elts[*pos].opcode;
02478 
02479       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02480       if (noside == EVAL_SKIP)
02481         goto nosideret;
02482       if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
02483         return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
02484       else
02485         {
02486           unop_promote (exp->language_defn, exp->gdbarch, &arg1);
02487           return value_complement (arg1);
02488         }
02489 
02490     case UNOP_LOGICAL_NOT:
02491       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02492       if (noside == EVAL_SKIP)
02493         goto nosideret;
02494       if (unop_user_defined_p (op, arg1))
02495         return value_x_unop (arg1, op, noside);
02496       else
02497         {
02498           type = language_bool_type (exp->language_defn, exp->gdbarch);
02499           return value_from_longest (type, (LONGEST) value_logical_not (arg1));
02500         }
02501 
02502     case UNOP_IND:
02503       if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
02504         expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
02505       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
02506       type = check_typedef (value_type (arg1));
02507       if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
02508           || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
02509         error (_("Attempt to dereference pointer "
02510                  "to member without an object"));
02511       if (noside == EVAL_SKIP)
02512         goto nosideret;
02513       if (unop_user_defined_p (op, arg1))
02514         return value_x_unop (arg1, op, noside);
02515       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
02516         {
02517           type = check_typedef (value_type (arg1));
02518           if (TYPE_CODE (type) == TYPE_CODE_PTR
02519               || TYPE_CODE (type) == TYPE_CODE_REF
02520           /* In C you can dereference an array to get the 1st elt.  */
02521               || TYPE_CODE (type) == TYPE_CODE_ARRAY
02522             )
02523             return value_zero (TYPE_TARGET_TYPE (type),
02524                                lval_memory);
02525           else if (TYPE_CODE (type) == TYPE_CODE_INT)
02526             /* GDB allows dereferencing an int.  */
02527             return value_zero (builtin_type (exp->gdbarch)->builtin_int,
02528                                lval_memory);
02529           else
02530             error (_("Attempt to take contents of a non-pointer value."));
02531         }
02532 
02533       /* Allow * on an integer so we can cast it to whatever we want.
02534          This returns an int, which seems like the most C-like thing to
02535          do.  "long long" variables are rare enough that
02536          BUILTIN_TYPE_LONGEST would seem to be a mistake.  */
02537       if (TYPE_CODE (type) == TYPE_CODE_INT)
02538         return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
02539                               (CORE_ADDR) value_as_address (arg1));
02540       return value_ind (arg1);
02541 
02542     case UNOP_ADDR:
02543       /* C++: check for and handle pointer to members.  */
02544 
02545       op = exp->elts[*pos].opcode;
02546 
02547       if (noside == EVAL_SKIP)
02548         {
02549           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
02550           goto nosideret;
02551         }
02552       else
02553         {
02554           struct value *retvalp = evaluate_subexp_for_address (exp, pos,
02555                                                                noside);
02556 
02557           return retvalp;
02558         }
02559 
02560     case UNOP_SIZEOF:
02561       if (noside == EVAL_SKIP)
02562         {
02563           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
02564           goto nosideret;
02565         }
02566       return evaluate_subexp_for_sizeof (exp, pos);
02567 
02568     case UNOP_CAST:
02569       (*pos) += 2;
02570       type = exp->elts[pc + 1].type;
02571       arg1 = evaluate_subexp (type, exp, pos, noside);
02572       if (noside == EVAL_SKIP)
02573         goto nosideret;
02574       if (type != value_type (arg1))
02575         arg1 = value_cast (type, arg1);
02576       return arg1;
02577 
02578     case UNOP_CAST_TYPE:
02579       arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
02580       type = value_type (arg1);
02581       arg1 = evaluate_subexp (type, exp, pos, noside);
02582       if (noside == EVAL_SKIP)
02583         goto nosideret;
02584       if (type != value_type (arg1))
02585         arg1 = value_cast (type, arg1);
02586       return arg1;
02587 
02588     case UNOP_DYNAMIC_CAST:
02589       arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
02590       type = value_type (arg1);
02591       arg1 = evaluate_subexp (type, exp, pos, noside);
02592       if (noside == EVAL_SKIP)
02593         goto nosideret;
02594       return value_dynamic_cast (type, arg1);
02595 
02596     case UNOP_REINTERPRET_CAST:
02597       arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
02598       type = value_type (arg1);
02599       arg1 = evaluate_subexp (type, exp, pos, noside);
02600       if (noside == EVAL_SKIP)
02601         goto nosideret;
02602       return value_reinterpret_cast (type, arg1);
02603 
02604     case UNOP_MEMVAL:
02605       (*pos) += 2;
02606       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
02607       if (noside == EVAL_SKIP)
02608         goto nosideret;
02609       if (noside == EVAL_AVOID_SIDE_EFFECTS)
02610         return value_zero (exp->elts[pc + 1].type, lval_memory);
02611       else
02612         return value_at_lazy (exp->elts[pc + 1].type,
02613                               value_as_address (arg1));
02614 
02615     case UNOP_MEMVAL_TYPE:
02616       arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
02617       type = value_type (arg1);
02618       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
02619       if (noside == EVAL_SKIP)
02620         goto nosideret;
02621       if (noside == EVAL_AVOID_SIDE_EFFECTS)
02622         return value_zero (type, lval_memory);
02623       else
02624         return value_at_lazy (type, value_as_address (arg1));
02625 
02626     case UNOP_MEMVAL_TLS:
02627       (*pos) += 3;
02628       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
02629       if (noside == EVAL_SKIP)
02630         goto nosideret;
02631       if (noside == EVAL_AVOID_SIDE_EFFECTS)
02632         return value_zero (exp->elts[pc + 2].type, lval_memory);
02633       else
02634         {
02635           CORE_ADDR tls_addr;
02636 
02637           tls_addr = target_translate_tls_address (exp->elts[pc + 1].objfile,
02638                                                    value_as_address (arg1));
02639           return value_at_lazy (exp->elts[pc + 2].type, tls_addr);
02640         }
02641 
02642     case UNOP_PREINCREMENT:
02643       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
02644       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
02645         return arg1;
02646       else if (unop_user_defined_p (op, arg1))
02647         {
02648           return value_x_unop (arg1, op, noside);
02649         }
02650       else
02651         {
02652           if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
02653             arg2 = value_ptradd (arg1, 1);
02654           else
02655             {
02656               struct value *tmp = arg1;
02657 
02658               arg2 = value_one (value_type (arg1));
02659               binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
02660               arg2 = value_binop (tmp, arg2, BINOP_ADD);
02661             }
02662 
02663           return value_assign (arg1, arg2);
02664         }
02665 
02666     case UNOP_PREDECREMENT:
02667       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
02668       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
02669         return arg1;
02670       else if (unop_user_defined_p (op, arg1))
02671         {
02672           return value_x_unop (arg1, op, noside);
02673         }
02674       else
02675         {
02676           if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
02677             arg2 = value_ptradd (arg1, -1);
02678           else
02679             {
02680               struct value *tmp = arg1;
02681 
02682               arg2 = value_one (value_type (arg1));
02683               binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
02684               arg2 = value_binop (tmp, arg2, BINOP_SUB);
02685             }
02686 
02687           return value_assign (arg1, arg2);
02688         }
02689 
02690     case UNOP_POSTINCREMENT:
02691       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
02692       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
02693         return arg1;
02694       else if (unop_user_defined_p (op, arg1))
02695         {
02696           return value_x_unop (arg1, op, noside);
02697         }
02698       else
02699         {
02700           arg3 = value_non_lval (arg1);
02701 
02702           if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
02703             arg2 = value_ptradd (arg1, 1);
02704           else
02705             {
02706               struct value *tmp = arg1;
02707 
02708               arg2 = value_one (value_type (arg1));
02709               binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
02710               arg2 = value_binop (tmp, arg2, BINOP_ADD);
02711             }
02712 
02713           value_assign (arg1, arg2);
02714           return arg3;
02715         }
02716 
02717     case UNOP_POSTDECREMENT:
02718       arg1 = evaluate_subexp (expect_type, exp, pos, noside);
02719       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
02720         return arg1;
02721       else if (unop_user_defined_p (op, arg1))
02722         {
02723           return value_x_unop (arg1, op, noside);
02724         }
02725       else
02726         {
02727           arg3 = value_non_lval (arg1);
02728 
02729           if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
02730             arg2 = value_ptradd (arg1, -1);
02731           else
02732             {
02733               struct value *tmp = arg1;
02734 
02735               arg2 = value_one (value_type (arg1));
02736               binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
02737               arg2 = value_binop (tmp, arg2, BINOP_SUB);
02738             }
02739 
02740           value_assign (arg1, arg2);
02741           return arg3;
02742         }
02743 
02744     case OP_THIS:
02745       (*pos) += 1;
02746       return value_of_this (exp->language_defn);
02747 
02748     case OP_TYPE:
02749       /* The value is not supposed to be used.  This is here to make it
02750          easier to accommodate expressions that contain types.  */
02751       (*pos) += 2;
02752       if (noside == EVAL_SKIP)
02753         goto nosideret;
02754       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
02755         {
02756           struct type *type = exp->elts[pc + 1].type;
02757 
02758           /* If this is a typedef, then find its immediate target.  We
02759              use check_typedef to resolve stubs, but we ignore its
02760              result because we do not want to dig past all
02761              typedefs.  */
02762           check_typedef (type);
02763           if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
02764             type = TYPE_TARGET_TYPE (type);
02765           return allocate_value (type);
02766         }
02767       else
02768         error (_("Attempt to use a type name as an expression"));
02769 
02770     case OP_TYPEOF:
02771     case OP_DECLTYPE:
02772       if (noside == EVAL_SKIP)
02773         {
02774           evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
02775           goto nosideret;
02776         }
02777       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
02778         {
02779           enum exp_opcode sub_op = exp->elts[*pos].opcode;
02780           struct value *result;
02781 
02782           result = evaluate_subexp (NULL_TYPE, exp, pos,
02783                                     EVAL_AVOID_SIDE_EFFECTS);
02784 
02785           /* 'decltype' has special semantics for lvalues.  */
02786           if (op == OP_DECLTYPE
02787               && (sub_op == BINOP_SUBSCRIPT
02788                   || sub_op == STRUCTOP_MEMBER
02789                   || sub_op == STRUCTOP_MPTR
02790                   || sub_op == UNOP_IND
02791                   || sub_op == STRUCTOP_STRUCT
02792                   || sub_op == STRUCTOP_PTR
02793                   || sub_op == OP_SCOPE))
02794             {
02795               struct type *type = value_type (result);
02796 
02797               if (TYPE_CODE (check_typedef (type)) != TYPE_CODE_REF)
02798                 {
02799                   type = lookup_reference_type (type);
02800                   result = allocate_value (type);
02801                 }
02802             }
02803 
02804           return result;
02805         }
02806       else
02807         error (_("Attempt to use a type as an expression"));
02808 
02809     case OP_TYPEID:
02810       {
02811         struct value *result;
02812         enum exp_opcode sub_op = exp->elts[*pos].opcode;
02813 
02814         if (sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
02815           result = evaluate_subexp (NULL_TYPE, exp, pos,
02816                                     EVAL_AVOID_SIDE_EFFECTS);
02817         else
02818           result = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02819 
02820         if (noside != EVAL_NORMAL)
02821           return allocate_value (cplus_typeid_type (exp->gdbarch));
02822 
02823         return cplus_typeid (result);
02824       }
02825 
02826     default:
02827       /* Removing this case and compiling with gcc -Wall reveals that
02828          a lot of cases are hitting this case.  Some of these should
02829          probably be removed from expression.h; others are legitimate
02830          expressions which are (apparently) not fully implemented.
02831 
02832          If there are any cases landing here which mean a user error,
02833          then they should be separate cases, with more descriptive
02834          error messages.  */
02835 
02836       error (_("GDB does not (yet) know how to "
02837                "evaluate that kind of expression"));
02838     }
02839 
02840 nosideret:
02841   return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
02842 }
02843 
02844 /* Evaluate a subexpression of EXP, at index *POS,
02845    and return the address of that subexpression.
02846    Advance *POS over the subexpression.
02847    If the subexpression isn't an lvalue, get an error.
02848    NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
02849    then only the type of the result need be correct.  */
02850 
02851 static struct value *
02852 evaluate_subexp_for_address (struct expression *exp, int *pos,
02853                              enum noside noside)
02854 {
02855   enum exp_opcode op;
02856   int pc;
02857   struct symbol *var;
02858   struct value *x;
02859   int tem;
02860 
02861   pc = (*pos);
02862   op = exp->elts[pc].opcode;
02863 
02864   switch (op)
02865     {
02866     case UNOP_IND:
02867       (*pos)++;
02868       x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02869 
02870       /* We can't optimize out "&*" if there's a user-defined operator*.  */
02871       if (unop_user_defined_p (op, x))
02872         {
02873           x = value_x_unop (x, op, noside);
02874           goto default_case_after_eval;
02875         }
02876 
02877       return coerce_array (x);
02878 
02879     case UNOP_MEMVAL:
02880       (*pos) += 3;
02881       return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
02882                          evaluate_subexp (NULL_TYPE, exp, pos, noside));
02883 
02884     case UNOP_MEMVAL_TYPE:
02885       {
02886         struct type *type;
02887 
02888         (*pos) += 1;
02889         x = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
02890         type = value_type (x);
02891         return value_cast (lookup_pointer_type (type),
02892                            evaluate_subexp (NULL_TYPE, exp, pos, noside));
02893       }
02894 
02895     case OP_VAR_VALUE:
02896       var = exp->elts[pc + 2].symbol;
02897 
02898       /* C++: The "address" of a reference should yield the address
02899        * of the object pointed to.  Let value_addr() deal with it.  */
02900       if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
02901         goto default_case;
02902 
02903       (*pos) += 4;
02904       if (noside == EVAL_AVOID_SIDE_EFFECTS)
02905         {
02906           struct type *type =
02907             lookup_pointer_type (SYMBOL_TYPE (var));
02908           enum address_class sym_class = SYMBOL_CLASS (var);
02909 
02910           if (sym_class == LOC_CONST
02911               || sym_class == LOC_CONST_BYTES
02912               || sym_class == LOC_REGISTER)
02913             error (_("Attempt to take address of register or constant."));
02914 
02915           return
02916             value_zero (type, not_lval);
02917         }
02918       else
02919         return address_of_variable (var, exp->elts[pc + 1].block);
02920 
02921     case OP_SCOPE:
02922       tem = longest_to_int (exp->elts[pc + 2].longconst);
02923       (*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
02924       x = value_aggregate_elt (exp->elts[pc + 1].type,
02925                                &exp->elts[pc + 3].string,
02926                                NULL, 1, noside);
02927       if (x == NULL)
02928         error (_("There is no field named %s"), &exp->elts[pc + 3].string);
02929       return x;
02930 
02931     default:
02932     default_case:
02933       x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
02934     default_case_after_eval:
02935       if (noside == EVAL_AVOID_SIDE_EFFECTS)
02936         {
02937           struct type *type = check_typedef (value_type (x));
02938 
02939           if (TYPE_CODE (type) == TYPE_CODE_REF)
02940             return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
02941                                not_lval);
02942           else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
02943             return value_zero (lookup_pointer_type (value_type (x)),
02944                                not_lval);
02945           else
02946             error (_("Attempt to take address of "
02947                      "value not located in memory."));
02948         }
02949       return value_addr (x);
02950     }
02951 }
02952 
02953 /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
02954    When used in contexts where arrays will be coerced anyway, this is
02955    equivalent to `evaluate_subexp' but much faster because it avoids
02956    actually fetching array contents (perhaps obsolete now that we have
02957    value_lazy()).
02958 
02959    Note that we currently only do the coercion for C expressions, where
02960    arrays are zero based and the coercion is correct.  For other languages,
02961    with nonzero based arrays, coercion loses.  Use CAST_IS_CONVERSION
02962    to decide if coercion is appropriate.  */
02963 
02964 struct value *
02965 evaluate_subexp_with_coercion (struct expression *exp,
02966                                int *pos, enum noside noside)
02967 {
02968   enum exp_opcode op;
02969   int pc;
02970   struct value *val;
02971   struct symbol *var;
02972   struct type *type;
02973 
02974   pc = (*pos);
02975   op = exp->elts[pc].opcode;
02976 
02977   switch (op)
02978     {
02979     case OP_VAR_VALUE:
02980       var = exp->elts[pc + 2].symbol;
02981       type = check_typedef (SYMBOL_TYPE (var));
02982       if (TYPE_CODE (type) == TYPE_CODE_ARRAY
02983           && !TYPE_VECTOR (type)
02984           && CAST_IS_CONVERSION (exp->language_defn))
02985         {
02986           (*pos) += 4;
02987           val = address_of_variable (var, exp->elts[pc + 1].block);
02988           return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
02989                              val);
02990         }
02991       /* FALLTHROUGH */
02992 
02993     default:
02994       return evaluate_subexp (NULL_TYPE, exp, pos, noside);
02995     }
02996 }
02997 
02998 /* Evaluate a subexpression of EXP, at index *POS,
02999    and return a value for the size of that subexpression.
03000    Advance *POS over the subexpression.  */
03001 
03002 static struct value *
03003 evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
03004 {
03005   /* FIXME: This should be size_t.  */
03006   struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
03007   enum exp_opcode op;
03008   int pc;
03009   struct type *type;
03010   struct value *val;
03011 
03012   pc = (*pos);
03013   op = exp->elts[pc].opcode;
03014 
03015   switch (op)
03016     {
03017       /* This case is handled specially
03018          so that we avoid creating a value for the result type.
03019          If the result type is very big, it's desirable not to
03020          create a value unnecessarily.  */
03021     case UNOP_IND:
03022       (*pos)++;
03023       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
03024       type = check_typedef (value_type (val));
03025       if (TYPE_CODE (type) != TYPE_CODE_PTR
03026           && TYPE_CODE (type) != TYPE_CODE_REF
03027           && TYPE_CODE (type) != TYPE_CODE_ARRAY)
03028         error (_("Attempt to take contents of a non-pointer value."));
03029       type = check_typedef (TYPE_TARGET_TYPE (type));
03030       return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
03031 
03032     case UNOP_MEMVAL:
03033       (*pos) += 3;
03034       type = check_typedef (exp->elts[pc + 1].type);
03035       return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
03036 
03037     case UNOP_MEMVAL_TYPE:
03038       (*pos) += 1;
03039       val = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
03040       type = check_typedef (value_type (val));
03041       return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
03042 
03043     case OP_VAR_VALUE:
03044       (*pos) += 4;
03045       type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
03046       return
03047         value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
03048 
03049     default:
03050       val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
03051       return value_from_longest (size_type,
03052                                  (LONGEST) TYPE_LENGTH (value_type (val)));
03053     }
03054 }
03055 
03056 /* Parse a type expression in the string [P..P+LENGTH).  */
03057 
03058 struct type *
03059 parse_and_eval_type (char *p, int length)
03060 {
03061   char *tmp = (char *) alloca (length + 4);
03062   struct expression *expr;
03063 
03064   tmp[0] = '(';
03065   memcpy (tmp + 1, p, length);
03066   tmp[length + 1] = ')';
03067   tmp[length + 2] = '0';
03068   tmp[length + 3] = '\0';
03069   expr = parse_expression (tmp);
03070   if (expr->elts[0].opcode != UNOP_CAST)
03071     error (_("Internal error in eval_type."));
03072   return expr->elts[1].type;
03073 }
03074 
03075 int
03076 calc_f77_array_dims (struct type *array_type)
03077 {
03078   int ndimen = 1;
03079   struct type *tmp_type;
03080 
03081   if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
03082     error (_("Can't get dimensions for a non-array type"));
03083 
03084   tmp_type = array_type;
03085 
03086   while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
03087     {
03088       if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
03089         ++ndimen;
03090     }
03091   return ndimen;
03092 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines