15796c8dcSSimon Schubert /* Evaluate expressions for GDB.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert This file is part of GDB.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert (at your option) any later version.
115796c8dcSSimon Schubert
125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155796c8dcSSimon Schubert GNU General Public License for more details.
165796c8dcSSimon Schubert
175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "gdb_string.h"
225796c8dcSSimon Schubert #include "symtab.h"
235796c8dcSSimon Schubert #include "gdbtypes.h"
245796c8dcSSimon Schubert #include "value.h"
255796c8dcSSimon Schubert #include "expression.h"
265796c8dcSSimon Schubert #include "target.h"
275796c8dcSSimon Schubert #include "frame.h"
28c50c785cSJohn Marino #include "language.h" /* For CAST_IS_CONVERSION. */
29c50c785cSJohn Marino #include "f-lang.h" /* For array bound stuff. */
305796c8dcSSimon Schubert #include "cp-abi.h"
315796c8dcSSimon Schubert #include "infcall.h"
325796c8dcSSimon Schubert #include "objc-lang.h"
335796c8dcSSimon Schubert #include "block.h"
345796c8dcSSimon Schubert #include "parser-defs.h"
355796c8dcSSimon Schubert #include "cp-support.h"
365796c8dcSSimon Schubert #include "ui-out.h"
375796c8dcSSimon Schubert #include "exceptions.h"
385796c8dcSSimon Schubert #include "regcache.h"
395796c8dcSSimon Schubert #include "user-regs.h"
405796c8dcSSimon Schubert #include "valprint.h"
41cf7f2e2dSJohn Marino #include "gdb_obstack.h"
42cf7f2e2dSJohn Marino #include "objfiles.h"
435796c8dcSSimon Schubert #include "python/python.h"
445796c8dcSSimon Schubert
455796c8dcSSimon Schubert #include "gdb_assert.h"
465796c8dcSSimon Schubert
475796c8dcSSimon Schubert #include <ctype.h>
485796c8dcSSimon Schubert
495796c8dcSSimon Schubert /* This is defined in valops.c */
505796c8dcSSimon Schubert extern int overload_resolution;
515796c8dcSSimon Schubert
525796c8dcSSimon Schubert /* Prototypes for local functions. */
535796c8dcSSimon Schubert
545796c8dcSSimon Schubert static struct value *evaluate_subexp_for_sizeof (struct expression *, int *);
555796c8dcSSimon Schubert
565796c8dcSSimon Schubert static struct value *evaluate_subexp_for_address (struct expression *,
575796c8dcSSimon Schubert int *, enum noside);
585796c8dcSSimon Schubert
595796c8dcSSimon Schubert static struct value *evaluate_struct_tuple (struct value *,
605796c8dcSSimon Schubert struct expression *, int *,
615796c8dcSSimon Schubert enum noside, int);
625796c8dcSSimon Schubert
635796c8dcSSimon Schubert static LONGEST init_array_element (struct value *, struct value *,
645796c8dcSSimon Schubert struct expression *, int *, enum noside,
655796c8dcSSimon Schubert LONGEST, LONGEST);
665796c8dcSSimon Schubert
675796c8dcSSimon Schubert struct value *
evaluate_subexp(struct type * expect_type,struct expression * exp,int * pos,enum noside noside)685796c8dcSSimon Schubert evaluate_subexp (struct type *expect_type, struct expression *exp,
695796c8dcSSimon Schubert int *pos, enum noside noside)
705796c8dcSSimon Schubert {
715796c8dcSSimon Schubert return (*exp->language_defn->la_exp_desc->evaluate_exp)
725796c8dcSSimon Schubert (expect_type, exp, pos, noside);
735796c8dcSSimon Schubert }
745796c8dcSSimon Schubert
755796c8dcSSimon Schubert /* Parse the string EXP as a C expression, evaluate it,
765796c8dcSSimon Schubert and return the result as a number. */
775796c8dcSSimon Schubert
785796c8dcSSimon Schubert CORE_ADDR
parse_and_eval_address(const char * exp)79*ef5ccd6cSJohn Marino parse_and_eval_address (const char *exp)
805796c8dcSSimon Schubert {
815796c8dcSSimon Schubert struct expression *expr = parse_expression (exp);
825796c8dcSSimon Schubert CORE_ADDR addr;
835796c8dcSSimon Schubert struct cleanup *old_chain =
845796c8dcSSimon Schubert make_cleanup (free_current_contents, &expr);
855796c8dcSSimon Schubert
865796c8dcSSimon Schubert addr = value_as_address (evaluate_expression (expr));
875796c8dcSSimon Schubert do_cleanups (old_chain);
885796c8dcSSimon Schubert return addr;
895796c8dcSSimon Schubert }
905796c8dcSSimon Schubert
915796c8dcSSimon Schubert /* Like parse_and_eval_address, but treats the value of the expression
92c50c785cSJohn Marino as an integer, not an address, returns a LONGEST, not a CORE_ADDR. */
935796c8dcSSimon Schubert LONGEST
parse_and_eval_long(char * exp)945796c8dcSSimon Schubert parse_and_eval_long (char *exp)
955796c8dcSSimon Schubert {
965796c8dcSSimon Schubert struct expression *expr = parse_expression (exp);
975796c8dcSSimon Schubert LONGEST retval;
985796c8dcSSimon Schubert struct cleanup *old_chain =
995796c8dcSSimon Schubert make_cleanup (free_current_contents, &expr);
1005796c8dcSSimon Schubert
1015796c8dcSSimon Schubert retval = value_as_long (evaluate_expression (expr));
1025796c8dcSSimon Schubert do_cleanups (old_chain);
1035796c8dcSSimon Schubert return (retval);
1045796c8dcSSimon Schubert }
1055796c8dcSSimon Schubert
1065796c8dcSSimon Schubert struct value *
parse_and_eval(const char * exp)107*ef5ccd6cSJohn Marino parse_and_eval (const char *exp)
1085796c8dcSSimon Schubert {
1095796c8dcSSimon Schubert struct expression *expr = parse_expression (exp);
1105796c8dcSSimon Schubert struct value *val;
1115796c8dcSSimon Schubert struct cleanup *old_chain =
1125796c8dcSSimon Schubert make_cleanup (free_current_contents, &expr);
1135796c8dcSSimon Schubert
1145796c8dcSSimon Schubert val = evaluate_expression (expr);
1155796c8dcSSimon Schubert do_cleanups (old_chain);
1165796c8dcSSimon Schubert return val;
1175796c8dcSSimon Schubert }
1185796c8dcSSimon Schubert
1195796c8dcSSimon Schubert /* Parse up to a comma (or to a closeparen)
1205796c8dcSSimon Schubert in the string EXPP as an expression, evaluate it, and return the value.
1215796c8dcSSimon Schubert EXPP is advanced to point to the comma. */
1225796c8dcSSimon Schubert
1235796c8dcSSimon Schubert struct value *
parse_to_comma_and_eval(const char ** expp)124*ef5ccd6cSJohn Marino parse_to_comma_and_eval (const char **expp)
1255796c8dcSSimon Schubert {
126*ef5ccd6cSJohn Marino struct expression *expr = parse_exp_1 (expp, 0, (struct block *) 0, 1);
1275796c8dcSSimon Schubert struct value *val;
1285796c8dcSSimon Schubert struct cleanup *old_chain =
1295796c8dcSSimon Schubert make_cleanup (free_current_contents, &expr);
1305796c8dcSSimon Schubert
1315796c8dcSSimon Schubert val = evaluate_expression (expr);
1325796c8dcSSimon Schubert do_cleanups (old_chain);
1335796c8dcSSimon Schubert return val;
1345796c8dcSSimon Schubert }
1355796c8dcSSimon Schubert
1365796c8dcSSimon Schubert /* Evaluate an expression in internal prefix form
1375796c8dcSSimon Schubert such as is constructed by parse.y.
1385796c8dcSSimon Schubert
1395796c8dcSSimon Schubert See expression.h for info on the format of an expression. */
1405796c8dcSSimon Schubert
1415796c8dcSSimon Schubert struct value *
evaluate_expression(struct expression * exp)1425796c8dcSSimon Schubert evaluate_expression (struct expression *exp)
1435796c8dcSSimon Schubert {
1445796c8dcSSimon Schubert int pc = 0;
145cf7f2e2dSJohn Marino
1465796c8dcSSimon Schubert return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
1475796c8dcSSimon Schubert }
1485796c8dcSSimon Schubert
1495796c8dcSSimon Schubert /* Evaluate an expression, avoiding all memory references
1505796c8dcSSimon Schubert and getting a value whose type alone is correct. */
1515796c8dcSSimon Schubert
1525796c8dcSSimon Schubert struct value *
evaluate_type(struct expression * exp)1535796c8dcSSimon Schubert evaluate_type (struct expression *exp)
1545796c8dcSSimon Schubert {
1555796c8dcSSimon Schubert int pc = 0;
156cf7f2e2dSJohn Marino
1575796c8dcSSimon Schubert return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
1585796c8dcSSimon Schubert }
1595796c8dcSSimon Schubert
1605796c8dcSSimon Schubert /* Evaluate a subexpression, avoiding all memory references and
1615796c8dcSSimon Schubert getting a value whose type alone is correct. */
1625796c8dcSSimon Schubert
1635796c8dcSSimon Schubert struct value *
evaluate_subexpression_type(struct expression * exp,int subexp)1645796c8dcSSimon Schubert evaluate_subexpression_type (struct expression *exp, int subexp)
1655796c8dcSSimon Schubert {
1665796c8dcSSimon Schubert return evaluate_subexp (NULL_TYPE, exp, &subexp, EVAL_AVOID_SIDE_EFFECTS);
1675796c8dcSSimon Schubert }
1685796c8dcSSimon Schubert
169cf7f2e2dSJohn Marino /* Find the current value of a watchpoint on EXP. Return the value in
170cf7f2e2dSJohn Marino *VALP and *RESULTP and the chain of intermediate and final values
171cf7f2e2dSJohn Marino in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does
172cf7f2e2dSJohn Marino not need them.
173cf7f2e2dSJohn Marino
174cf7f2e2dSJohn Marino If a memory error occurs while evaluating the expression, *RESULTP will
175cf7f2e2dSJohn Marino be set to NULL. *RESULTP may be a lazy value, if the result could
176cf7f2e2dSJohn Marino not be read from memory. It is used to determine whether a value
177cf7f2e2dSJohn Marino is user-specified (we should watch the whole value) or intermediate
178cf7f2e2dSJohn Marino (we should watch only the bit used to locate the final value).
179cf7f2e2dSJohn Marino
180cf7f2e2dSJohn Marino If the final value, or any intermediate value, could not be read
181cf7f2e2dSJohn Marino from memory, *VALP will be set to NULL. *VAL_CHAIN will still be
182cf7f2e2dSJohn Marino set to any referenced values. *VALP will never be a lazy value.
183cf7f2e2dSJohn Marino This is the value which we store in struct breakpoint.
184cf7f2e2dSJohn Marino
185cf7f2e2dSJohn Marino If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
186cf7f2e2dSJohn Marino value chain. The caller must free the values individually. If
187cf7f2e2dSJohn Marino VAL_CHAIN is NULL, all generated values will be left on the value
188cf7f2e2dSJohn Marino chain. */
189cf7f2e2dSJohn Marino
190cf7f2e2dSJohn Marino void
fetch_subexp_value(struct expression * exp,int * pc,struct value ** valp,struct value ** resultp,struct value ** val_chain)191cf7f2e2dSJohn Marino fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
192cf7f2e2dSJohn Marino struct value **resultp, struct value **val_chain)
193cf7f2e2dSJohn Marino {
194cf7f2e2dSJohn Marino struct value *mark, *new_mark, *result;
195cf7f2e2dSJohn Marino volatile struct gdb_exception ex;
196cf7f2e2dSJohn Marino
197cf7f2e2dSJohn Marino *valp = NULL;
198cf7f2e2dSJohn Marino if (resultp)
199cf7f2e2dSJohn Marino *resultp = NULL;
200cf7f2e2dSJohn Marino if (val_chain)
201cf7f2e2dSJohn Marino *val_chain = NULL;
202cf7f2e2dSJohn Marino
203cf7f2e2dSJohn Marino /* Evaluate the expression. */
204cf7f2e2dSJohn Marino mark = value_mark ();
205cf7f2e2dSJohn Marino result = NULL;
206cf7f2e2dSJohn Marino
207cf7f2e2dSJohn Marino TRY_CATCH (ex, RETURN_MASK_ALL)
208cf7f2e2dSJohn Marino {
209cf7f2e2dSJohn Marino result = evaluate_subexp (NULL_TYPE, exp, pc, EVAL_NORMAL);
210cf7f2e2dSJohn Marino }
211cf7f2e2dSJohn Marino if (ex.reason < 0)
212cf7f2e2dSJohn Marino {
213cf7f2e2dSJohn Marino /* Ignore memory errors, we want watchpoints pointing at
214cf7f2e2dSJohn Marino inaccessible memory to still be created; otherwise, throw the
215cf7f2e2dSJohn Marino error to some higher catcher. */
216cf7f2e2dSJohn Marino switch (ex.error)
217cf7f2e2dSJohn Marino {
218cf7f2e2dSJohn Marino case MEMORY_ERROR:
219cf7f2e2dSJohn Marino break;
220cf7f2e2dSJohn Marino default:
221cf7f2e2dSJohn Marino throw_exception (ex);
222cf7f2e2dSJohn Marino break;
223cf7f2e2dSJohn Marino }
224cf7f2e2dSJohn Marino }
225cf7f2e2dSJohn Marino
226cf7f2e2dSJohn Marino new_mark = value_mark ();
227cf7f2e2dSJohn Marino if (mark == new_mark)
228cf7f2e2dSJohn Marino return;
229cf7f2e2dSJohn Marino if (resultp)
230cf7f2e2dSJohn Marino *resultp = result;
231cf7f2e2dSJohn Marino
232cf7f2e2dSJohn Marino /* Make sure it's not lazy, so that after the target stops again we
233cf7f2e2dSJohn Marino have a non-lazy previous value to compare with. */
234*ef5ccd6cSJohn Marino if (result != NULL)
235*ef5ccd6cSJohn Marino {
236*ef5ccd6cSJohn Marino if (!value_lazy (result))
237cf7f2e2dSJohn Marino *valp = result;
238*ef5ccd6cSJohn Marino else
239*ef5ccd6cSJohn Marino {
240*ef5ccd6cSJohn Marino volatile struct gdb_exception except;
241*ef5ccd6cSJohn Marino
242*ef5ccd6cSJohn Marino TRY_CATCH (except, RETURN_MASK_ERROR)
243*ef5ccd6cSJohn Marino {
244*ef5ccd6cSJohn Marino value_fetch_lazy (result);
245*ef5ccd6cSJohn Marino *valp = result;
246*ef5ccd6cSJohn Marino }
247*ef5ccd6cSJohn Marino }
248*ef5ccd6cSJohn Marino }
249cf7f2e2dSJohn Marino
250cf7f2e2dSJohn Marino if (val_chain)
251cf7f2e2dSJohn Marino {
252cf7f2e2dSJohn Marino /* Return the chain of intermediate values. We use this to
253cf7f2e2dSJohn Marino decide which addresses to watch. */
254cf7f2e2dSJohn Marino *val_chain = new_mark;
255cf7f2e2dSJohn Marino value_release_to_mark (mark);
256cf7f2e2dSJohn Marino }
257cf7f2e2dSJohn Marino }
258cf7f2e2dSJohn Marino
2595796c8dcSSimon Schubert /* Extract a field operation from an expression. If the subexpression
2605796c8dcSSimon Schubert of EXP starting at *SUBEXP is not a structure dereference
2615796c8dcSSimon Schubert operation, return NULL. Otherwise, return the name of the
2625796c8dcSSimon Schubert dereferenced field, and advance *SUBEXP to point to the
2635796c8dcSSimon Schubert subexpression of the left-hand-side of the dereference. This is
2645796c8dcSSimon Schubert used when completing field names. */
2655796c8dcSSimon Schubert
2665796c8dcSSimon Schubert char *
extract_field_op(struct expression * exp,int * subexp)2675796c8dcSSimon Schubert extract_field_op (struct expression *exp, int *subexp)
2685796c8dcSSimon Schubert {
2695796c8dcSSimon Schubert int tem;
2705796c8dcSSimon Schubert char *result;
271cf7f2e2dSJohn Marino
2725796c8dcSSimon Schubert if (exp->elts[*subexp].opcode != STRUCTOP_STRUCT
2735796c8dcSSimon Schubert && exp->elts[*subexp].opcode != STRUCTOP_PTR)
2745796c8dcSSimon Schubert return NULL;
2755796c8dcSSimon Schubert tem = longest_to_int (exp->elts[*subexp + 1].longconst);
2765796c8dcSSimon Schubert result = &exp->elts[*subexp + 2].string;
2775796c8dcSSimon Schubert (*subexp) += 1 + 3 + BYTES_TO_EXP_ELEM (tem + 1);
2785796c8dcSSimon Schubert return result;
2795796c8dcSSimon Schubert }
2805796c8dcSSimon Schubert
281*ef5ccd6cSJohn Marino /* This function evaluates brace-initializers (in C/C++) for
282*ef5ccd6cSJohn Marino structure types. */
2835796c8dcSSimon Schubert
2845796c8dcSSimon Schubert static struct value *
evaluate_struct_tuple(struct value * struct_val,struct expression * exp,int * pos,enum noside noside,int nargs)2855796c8dcSSimon Schubert evaluate_struct_tuple (struct value *struct_val,
2865796c8dcSSimon Schubert struct expression *exp,
2875796c8dcSSimon Schubert int *pos, enum noside noside, int nargs)
2885796c8dcSSimon Schubert {
2895796c8dcSSimon Schubert struct type *struct_type = check_typedef (value_type (struct_val));
2905796c8dcSSimon Schubert struct type *field_type;
2915796c8dcSSimon Schubert int fieldno = -1;
292cf7f2e2dSJohn Marino
2935796c8dcSSimon Schubert while (--nargs >= 0)
2945796c8dcSSimon Schubert {
2955796c8dcSSimon Schubert struct value *val = NULL;
2965796c8dcSSimon Schubert int bitpos, bitsize;
2975796c8dcSSimon Schubert bfd_byte *addr;
2985796c8dcSSimon Schubert
2995796c8dcSSimon Schubert fieldno++;
3005796c8dcSSimon Schubert /* Skip static fields. */
3015796c8dcSSimon Schubert while (fieldno < TYPE_NFIELDS (struct_type)
3025796c8dcSSimon Schubert && field_is_static (&TYPE_FIELD (struct_type,
3035796c8dcSSimon Schubert fieldno)))
3045796c8dcSSimon Schubert fieldno++;
3055796c8dcSSimon Schubert if (fieldno >= TYPE_NFIELDS (struct_type))
3065796c8dcSSimon Schubert error (_("too many initializers"));
3075796c8dcSSimon Schubert field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
3085796c8dcSSimon Schubert if (TYPE_CODE (field_type) == TYPE_CODE_UNION
3095796c8dcSSimon Schubert && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
3105796c8dcSSimon Schubert error (_("don't know which variant you want to set"));
3115796c8dcSSimon Schubert
3125796c8dcSSimon Schubert /* Here, struct_type is the type of the inner struct,
3135796c8dcSSimon Schubert while substruct_type is the type of the inner struct.
3145796c8dcSSimon Schubert These are the same for normal structures, but a variant struct
3155796c8dcSSimon Schubert contains anonymous union fields that contain substruct fields.
3165796c8dcSSimon Schubert The value fieldno is the index of the top-level (normal or
3175796c8dcSSimon Schubert anonymous union) field in struct_field, while the value
3185796c8dcSSimon Schubert subfieldno is the index of the actual real (named inner) field
3195796c8dcSSimon Schubert in substruct_type. */
3205796c8dcSSimon Schubert
321*ef5ccd6cSJohn Marino field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
3225796c8dcSSimon Schubert if (val == 0)
3235796c8dcSSimon Schubert val = evaluate_subexp (field_type, exp, pos, noside);
3245796c8dcSSimon Schubert
3255796c8dcSSimon Schubert /* Now actually set the field in struct_val. */
3265796c8dcSSimon Schubert
3275796c8dcSSimon Schubert /* Assign val to field fieldno. */
3285796c8dcSSimon Schubert if (value_type (val) != field_type)
3295796c8dcSSimon Schubert val = value_cast (field_type, val);
3305796c8dcSSimon Schubert
331*ef5ccd6cSJohn Marino bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
3325796c8dcSSimon Schubert bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
3335796c8dcSSimon Schubert addr = value_contents_writeable (struct_val) + bitpos / 8;
3345796c8dcSSimon Schubert if (bitsize)
3355796c8dcSSimon Schubert modify_field (struct_type, addr,
3365796c8dcSSimon Schubert value_as_long (val), bitpos % 8, bitsize);
3375796c8dcSSimon Schubert else
3385796c8dcSSimon Schubert memcpy (addr, value_contents (val),
3395796c8dcSSimon Schubert TYPE_LENGTH (value_type (val)));
340*ef5ccd6cSJohn Marino
3415796c8dcSSimon Schubert }
3425796c8dcSSimon Schubert return struct_val;
3435796c8dcSSimon Schubert }
3445796c8dcSSimon Schubert
3455796c8dcSSimon Schubert /* Recursive helper function for setting elements of array tuples for
3465796c8dcSSimon Schubert (the deleted) Chill. The target is ARRAY (which has bounds
3475796c8dcSSimon Schubert LOW_BOUND to HIGH_BOUND); the element value is ELEMENT; EXP, POS
3485796c8dcSSimon Schubert and NOSIDE are as usual. Evaluates index expresions and sets the
3495796c8dcSSimon Schubert specified element(s) of ARRAY to ELEMENT. Returns last index
3505796c8dcSSimon Schubert value. */
3515796c8dcSSimon Schubert
3525796c8dcSSimon Schubert static LONGEST
init_array_element(struct value * array,struct value * element,struct expression * exp,int * pos,enum noside noside,LONGEST low_bound,LONGEST high_bound)3535796c8dcSSimon Schubert init_array_element (struct value *array, struct value *element,
3545796c8dcSSimon Schubert struct expression *exp, int *pos,
3555796c8dcSSimon Schubert enum noside noside, LONGEST low_bound, LONGEST high_bound)
3565796c8dcSSimon Schubert {
3575796c8dcSSimon Schubert LONGEST index;
3585796c8dcSSimon Schubert int element_size = TYPE_LENGTH (value_type (element));
359cf7f2e2dSJohn Marino
3605796c8dcSSimon Schubert if (exp->elts[*pos].opcode == BINOP_COMMA)
3615796c8dcSSimon Schubert {
3625796c8dcSSimon Schubert (*pos)++;
3635796c8dcSSimon Schubert init_array_element (array, element, exp, pos, noside,
3645796c8dcSSimon Schubert low_bound, high_bound);
3655796c8dcSSimon Schubert return init_array_element (array, element,
3665796c8dcSSimon Schubert exp, pos, noside, low_bound, high_bound);
3675796c8dcSSimon Schubert }
3685796c8dcSSimon Schubert else if (exp->elts[*pos].opcode == BINOP_RANGE)
3695796c8dcSSimon Schubert {
3705796c8dcSSimon Schubert LONGEST low, high;
371cf7f2e2dSJohn Marino
3725796c8dcSSimon Schubert (*pos)++;
3735796c8dcSSimon Schubert low = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
3745796c8dcSSimon Schubert high = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
3755796c8dcSSimon Schubert if (low < low_bound || high > high_bound)
3765796c8dcSSimon Schubert error (_("tuple range index out of range"));
3775796c8dcSSimon Schubert for (index = low; index <= high; index++)
3785796c8dcSSimon Schubert {
3795796c8dcSSimon Schubert memcpy (value_contents_raw (array)
3805796c8dcSSimon Schubert + (index - low_bound) * element_size,
3815796c8dcSSimon Schubert value_contents (element), element_size);
3825796c8dcSSimon Schubert }
3835796c8dcSSimon Schubert }
3845796c8dcSSimon Schubert else
3855796c8dcSSimon Schubert {
3865796c8dcSSimon Schubert index = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
3875796c8dcSSimon Schubert if (index < low_bound || index > high_bound)
3885796c8dcSSimon Schubert error (_("tuple index out of range"));
3895796c8dcSSimon Schubert memcpy (value_contents_raw (array) + (index - low_bound) * element_size,
3905796c8dcSSimon Schubert value_contents (element), element_size);
3915796c8dcSSimon Schubert }
3925796c8dcSSimon Schubert return index;
3935796c8dcSSimon Schubert }
3945796c8dcSSimon Schubert
3955796c8dcSSimon Schubert static struct value *
value_f90_subarray(struct value * array,struct expression * exp,int * pos,enum noside noside)3965796c8dcSSimon Schubert value_f90_subarray (struct value *array,
3975796c8dcSSimon Schubert struct expression *exp, int *pos, enum noside noside)
3985796c8dcSSimon Schubert {
3995796c8dcSSimon Schubert int pc = (*pos) + 1;
4005796c8dcSSimon Schubert LONGEST low_bound, high_bound;
4015796c8dcSSimon Schubert struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
4025796c8dcSSimon Schubert enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
4035796c8dcSSimon Schubert
4045796c8dcSSimon Schubert *pos += 3;
4055796c8dcSSimon Schubert
4065796c8dcSSimon Schubert if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
4075796c8dcSSimon Schubert low_bound = TYPE_LOW_BOUND (range);
4085796c8dcSSimon Schubert else
4095796c8dcSSimon Schubert low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
4105796c8dcSSimon Schubert
4115796c8dcSSimon Schubert if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
4125796c8dcSSimon Schubert high_bound = TYPE_HIGH_BOUND (range);
4135796c8dcSSimon Schubert else
4145796c8dcSSimon Schubert high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
4155796c8dcSSimon Schubert
4165796c8dcSSimon Schubert return value_slice (array, low_bound, high_bound - low_bound + 1);
4175796c8dcSSimon Schubert }
4185796c8dcSSimon Schubert
4195796c8dcSSimon Schubert
4205796c8dcSSimon Schubert /* Promote value ARG1 as appropriate before performing a unary operation
4215796c8dcSSimon Schubert on this argument.
4225796c8dcSSimon Schubert If the result is not appropriate for any particular language then it
4235796c8dcSSimon Schubert needs to patch this function. */
4245796c8dcSSimon Schubert
4255796c8dcSSimon Schubert void
unop_promote(const struct language_defn * language,struct gdbarch * gdbarch,struct value ** arg1)4265796c8dcSSimon Schubert unop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
4275796c8dcSSimon Schubert struct value **arg1)
4285796c8dcSSimon Schubert {
4295796c8dcSSimon Schubert struct type *type1;
4305796c8dcSSimon Schubert
4315796c8dcSSimon Schubert *arg1 = coerce_ref (*arg1);
4325796c8dcSSimon Schubert type1 = check_typedef (value_type (*arg1));
4335796c8dcSSimon Schubert
4345796c8dcSSimon Schubert if (is_integral_type (type1))
4355796c8dcSSimon Schubert {
4365796c8dcSSimon Schubert switch (language->la_language)
4375796c8dcSSimon Schubert {
4385796c8dcSSimon Schubert default:
4395796c8dcSSimon Schubert /* Perform integral promotion for ANSI C/C++.
4405796c8dcSSimon Schubert If not appropropriate for any particular language
4415796c8dcSSimon Schubert it needs to modify this function. */
4425796c8dcSSimon Schubert {
4435796c8dcSSimon Schubert struct type *builtin_int = builtin_type (gdbarch)->builtin_int;
444cf7f2e2dSJohn Marino
4455796c8dcSSimon Schubert if (TYPE_LENGTH (type1) < TYPE_LENGTH (builtin_int))
4465796c8dcSSimon Schubert *arg1 = value_cast (builtin_int, *arg1);
4475796c8dcSSimon Schubert }
4485796c8dcSSimon Schubert break;
4495796c8dcSSimon Schubert }
4505796c8dcSSimon Schubert }
4515796c8dcSSimon Schubert }
4525796c8dcSSimon Schubert
4535796c8dcSSimon Schubert /* Promote values ARG1 and ARG2 as appropriate before performing a binary
4545796c8dcSSimon Schubert operation on those two operands.
4555796c8dcSSimon Schubert If the result is not appropriate for any particular language then it
4565796c8dcSSimon Schubert needs to patch this function. */
4575796c8dcSSimon Schubert
4585796c8dcSSimon Schubert void
binop_promote(const struct language_defn * language,struct gdbarch * gdbarch,struct value ** arg1,struct value ** arg2)4595796c8dcSSimon Schubert binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
4605796c8dcSSimon Schubert struct value **arg1, struct value **arg2)
4615796c8dcSSimon Schubert {
4625796c8dcSSimon Schubert struct type *promoted_type = NULL;
4635796c8dcSSimon Schubert struct type *type1;
4645796c8dcSSimon Schubert struct type *type2;
4655796c8dcSSimon Schubert
4665796c8dcSSimon Schubert *arg1 = coerce_ref (*arg1);
4675796c8dcSSimon Schubert *arg2 = coerce_ref (*arg2);
4685796c8dcSSimon Schubert
4695796c8dcSSimon Schubert type1 = check_typedef (value_type (*arg1));
4705796c8dcSSimon Schubert type2 = check_typedef (value_type (*arg2));
4715796c8dcSSimon Schubert
4725796c8dcSSimon Schubert if ((TYPE_CODE (type1) != TYPE_CODE_FLT
4735796c8dcSSimon Schubert && TYPE_CODE (type1) != TYPE_CODE_DECFLOAT
4745796c8dcSSimon Schubert && !is_integral_type (type1))
4755796c8dcSSimon Schubert || (TYPE_CODE (type2) != TYPE_CODE_FLT
4765796c8dcSSimon Schubert && TYPE_CODE (type2) != TYPE_CODE_DECFLOAT
4775796c8dcSSimon Schubert && !is_integral_type (type2)))
4785796c8dcSSimon Schubert return;
4795796c8dcSSimon Schubert
4805796c8dcSSimon Schubert if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT
4815796c8dcSSimon Schubert || TYPE_CODE (type2) == TYPE_CODE_DECFLOAT)
4825796c8dcSSimon Schubert {
4835796c8dcSSimon Schubert /* No promotion required. */
4845796c8dcSSimon Schubert }
4855796c8dcSSimon Schubert else if (TYPE_CODE (type1) == TYPE_CODE_FLT
4865796c8dcSSimon Schubert || TYPE_CODE (type2) == TYPE_CODE_FLT)
4875796c8dcSSimon Schubert {
4885796c8dcSSimon Schubert switch (language->la_language)
4895796c8dcSSimon Schubert {
4905796c8dcSSimon Schubert case language_c:
4915796c8dcSSimon Schubert case language_cplus:
4925796c8dcSSimon Schubert case language_asm:
4935796c8dcSSimon Schubert case language_objc:
494c50c785cSJohn Marino case language_opencl:
4955796c8dcSSimon Schubert /* No promotion required. */
4965796c8dcSSimon Schubert break;
4975796c8dcSSimon Schubert
4985796c8dcSSimon Schubert default:
4995796c8dcSSimon Schubert /* For other languages the result type is unchanged from gdb
5005796c8dcSSimon Schubert version 6.7 for backward compatibility.
5015796c8dcSSimon Schubert If either arg was long double, make sure that value is also long
5025796c8dcSSimon Schubert double. Otherwise use double. */
5035796c8dcSSimon Schubert if (TYPE_LENGTH (type1) * 8 > gdbarch_double_bit (gdbarch)
5045796c8dcSSimon Schubert || TYPE_LENGTH (type2) * 8 > gdbarch_double_bit (gdbarch))
5055796c8dcSSimon Schubert promoted_type = builtin_type (gdbarch)->builtin_long_double;
5065796c8dcSSimon Schubert else
5075796c8dcSSimon Schubert promoted_type = builtin_type (gdbarch)->builtin_double;
5085796c8dcSSimon Schubert break;
5095796c8dcSSimon Schubert }
5105796c8dcSSimon Schubert }
5115796c8dcSSimon Schubert else if (TYPE_CODE (type1) == TYPE_CODE_BOOL
5125796c8dcSSimon Schubert && TYPE_CODE (type2) == TYPE_CODE_BOOL)
5135796c8dcSSimon Schubert {
5145796c8dcSSimon Schubert /* No promotion required. */
5155796c8dcSSimon Schubert }
5165796c8dcSSimon Schubert else
5175796c8dcSSimon Schubert /* Integral operations here. */
5185796c8dcSSimon Schubert /* FIXME: Also mixed integral/booleans, with result an integer. */
5195796c8dcSSimon Schubert {
5205796c8dcSSimon Schubert const struct builtin_type *builtin = builtin_type (gdbarch);
5215796c8dcSSimon Schubert unsigned int promoted_len1 = TYPE_LENGTH (type1);
5225796c8dcSSimon Schubert unsigned int promoted_len2 = TYPE_LENGTH (type2);
5235796c8dcSSimon Schubert int is_unsigned1 = TYPE_UNSIGNED (type1);
5245796c8dcSSimon Schubert int is_unsigned2 = TYPE_UNSIGNED (type2);
5255796c8dcSSimon Schubert unsigned int result_len;
5265796c8dcSSimon Schubert int unsigned_operation;
5275796c8dcSSimon Schubert
5285796c8dcSSimon Schubert /* Determine type length and signedness after promotion for
5295796c8dcSSimon Schubert both operands. */
5305796c8dcSSimon Schubert if (promoted_len1 < TYPE_LENGTH (builtin->builtin_int))
5315796c8dcSSimon Schubert {
5325796c8dcSSimon Schubert is_unsigned1 = 0;
5335796c8dcSSimon Schubert promoted_len1 = TYPE_LENGTH (builtin->builtin_int);
5345796c8dcSSimon Schubert }
5355796c8dcSSimon Schubert if (promoted_len2 < TYPE_LENGTH (builtin->builtin_int))
5365796c8dcSSimon Schubert {
5375796c8dcSSimon Schubert is_unsigned2 = 0;
5385796c8dcSSimon Schubert promoted_len2 = TYPE_LENGTH (builtin->builtin_int);
5395796c8dcSSimon Schubert }
5405796c8dcSSimon Schubert
5415796c8dcSSimon Schubert if (promoted_len1 > promoted_len2)
5425796c8dcSSimon Schubert {
5435796c8dcSSimon Schubert unsigned_operation = is_unsigned1;
5445796c8dcSSimon Schubert result_len = promoted_len1;
5455796c8dcSSimon Schubert }
5465796c8dcSSimon Schubert else if (promoted_len2 > promoted_len1)
5475796c8dcSSimon Schubert {
5485796c8dcSSimon Schubert unsigned_operation = is_unsigned2;
5495796c8dcSSimon Schubert result_len = promoted_len2;
5505796c8dcSSimon Schubert }
5515796c8dcSSimon Schubert else
5525796c8dcSSimon Schubert {
5535796c8dcSSimon Schubert unsigned_operation = is_unsigned1 || is_unsigned2;
5545796c8dcSSimon Schubert result_len = promoted_len1;
5555796c8dcSSimon Schubert }
5565796c8dcSSimon Schubert
5575796c8dcSSimon Schubert switch (language->la_language)
5585796c8dcSSimon Schubert {
5595796c8dcSSimon Schubert case language_c:
5605796c8dcSSimon Schubert case language_cplus:
5615796c8dcSSimon Schubert case language_asm:
5625796c8dcSSimon Schubert case language_objc:
5635796c8dcSSimon Schubert if (result_len <= TYPE_LENGTH (builtin->builtin_int))
5645796c8dcSSimon Schubert {
5655796c8dcSSimon Schubert promoted_type = (unsigned_operation
5665796c8dcSSimon Schubert ? builtin->builtin_unsigned_int
5675796c8dcSSimon Schubert : builtin->builtin_int);
5685796c8dcSSimon Schubert }
5695796c8dcSSimon Schubert else if (result_len <= TYPE_LENGTH (builtin->builtin_long))
5705796c8dcSSimon Schubert {
5715796c8dcSSimon Schubert promoted_type = (unsigned_operation
5725796c8dcSSimon Schubert ? builtin->builtin_unsigned_long
5735796c8dcSSimon Schubert : builtin->builtin_long);
5745796c8dcSSimon Schubert }
5755796c8dcSSimon Schubert else
5765796c8dcSSimon Schubert {
5775796c8dcSSimon Schubert promoted_type = (unsigned_operation
5785796c8dcSSimon Schubert ? builtin->builtin_unsigned_long_long
5795796c8dcSSimon Schubert : builtin->builtin_long_long);
5805796c8dcSSimon Schubert }
5815796c8dcSSimon Schubert break;
582c50c785cSJohn Marino case language_opencl:
583c50c785cSJohn Marino if (result_len <= TYPE_LENGTH (lookup_signed_typename
584c50c785cSJohn Marino (language, gdbarch, "int")))
585c50c785cSJohn Marino {
586c50c785cSJohn Marino promoted_type =
587c50c785cSJohn Marino (unsigned_operation
588c50c785cSJohn Marino ? lookup_unsigned_typename (language, gdbarch, "int")
589c50c785cSJohn Marino : lookup_signed_typename (language, gdbarch, "int"));
590c50c785cSJohn Marino }
591c50c785cSJohn Marino else if (result_len <= TYPE_LENGTH (lookup_signed_typename
592c50c785cSJohn Marino (language, gdbarch, "long")))
593c50c785cSJohn Marino {
594c50c785cSJohn Marino promoted_type =
595c50c785cSJohn Marino (unsigned_operation
596c50c785cSJohn Marino ? lookup_unsigned_typename (language, gdbarch, "long")
597c50c785cSJohn Marino : lookup_signed_typename (language, gdbarch,"long"));
598c50c785cSJohn Marino }
599c50c785cSJohn Marino break;
6005796c8dcSSimon Schubert default:
6015796c8dcSSimon Schubert /* For other languages the result type is unchanged from gdb
6025796c8dcSSimon Schubert version 6.7 for backward compatibility.
6035796c8dcSSimon Schubert If either arg was long long, make sure that value is also long
6045796c8dcSSimon Schubert long. Otherwise use long. */
6055796c8dcSSimon Schubert if (unsigned_operation)
6065796c8dcSSimon Schubert {
6075796c8dcSSimon Schubert if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
6085796c8dcSSimon Schubert promoted_type = builtin->builtin_unsigned_long_long;
6095796c8dcSSimon Schubert else
6105796c8dcSSimon Schubert promoted_type = builtin->builtin_unsigned_long;
6115796c8dcSSimon Schubert }
6125796c8dcSSimon Schubert else
6135796c8dcSSimon Schubert {
6145796c8dcSSimon Schubert if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
6155796c8dcSSimon Schubert promoted_type = builtin->builtin_long_long;
6165796c8dcSSimon Schubert else
6175796c8dcSSimon Schubert promoted_type = builtin->builtin_long;
6185796c8dcSSimon Schubert }
6195796c8dcSSimon Schubert break;
6205796c8dcSSimon Schubert }
6215796c8dcSSimon Schubert }
6225796c8dcSSimon Schubert
6235796c8dcSSimon Schubert if (promoted_type)
6245796c8dcSSimon Schubert {
6255796c8dcSSimon Schubert /* Promote both operands to common type. */
6265796c8dcSSimon Schubert *arg1 = value_cast (promoted_type, *arg1);
6275796c8dcSSimon Schubert *arg2 = value_cast (promoted_type, *arg2);
6285796c8dcSSimon Schubert }
6295796c8dcSSimon Schubert }
6305796c8dcSSimon Schubert
6315796c8dcSSimon Schubert static int
ptrmath_type_p(const struct language_defn * lang,struct type * type)632cf7f2e2dSJohn Marino ptrmath_type_p (const struct language_defn *lang, struct type *type)
6335796c8dcSSimon Schubert {
6345796c8dcSSimon Schubert type = check_typedef (type);
6355796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_REF)
6365796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
6375796c8dcSSimon Schubert
6385796c8dcSSimon Schubert switch (TYPE_CODE (type))
6395796c8dcSSimon Schubert {
6405796c8dcSSimon Schubert case TYPE_CODE_PTR:
6415796c8dcSSimon Schubert case TYPE_CODE_FUNC:
6425796c8dcSSimon Schubert return 1;
6435796c8dcSSimon Schubert
6445796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
645c50c785cSJohn Marino return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays;
6465796c8dcSSimon Schubert
6475796c8dcSSimon Schubert default:
6485796c8dcSSimon Schubert return 0;
6495796c8dcSSimon Schubert }
6505796c8dcSSimon Schubert }
6515796c8dcSSimon Schubert
652cf7f2e2dSJohn Marino /* Constructs a fake method with the given parameter types.
653cf7f2e2dSJohn Marino This function is used by the parser to construct an "expected"
654cf7f2e2dSJohn Marino type for method overload resolution. */
655cf7f2e2dSJohn Marino
656cf7f2e2dSJohn Marino static struct type *
make_params(int num_types,struct type ** param_types)657cf7f2e2dSJohn Marino make_params (int num_types, struct type **param_types)
658cf7f2e2dSJohn Marino {
659cf7f2e2dSJohn Marino struct type *type = XZALLOC (struct type);
660cf7f2e2dSJohn Marino TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
661cf7f2e2dSJohn Marino TYPE_LENGTH (type) = 1;
662cf7f2e2dSJohn Marino TYPE_CODE (type) = TYPE_CODE_METHOD;
663cf7f2e2dSJohn Marino TYPE_VPTR_FIELDNO (type) = -1;
664cf7f2e2dSJohn Marino TYPE_CHAIN (type) = type;
665*ef5ccd6cSJohn Marino if (num_types > 0)
666*ef5ccd6cSJohn Marino {
667*ef5ccd6cSJohn Marino if (param_types[num_types - 1] == NULL)
668*ef5ccd6cSJohn Marino {
669*ef5ccd6cSJohn Marino --num_types;
670*ef5ccd6cSJohn Marino TYPE_VARARGS (type) = 1;
671*ef5ccd6cSJohn Marino }
672*ef5ccd6cSJohn Marino else if (TYPE_CODE (check_typedef (param_types[num_types - 1]))
673*ef5ccd6cSJohn Marino == TYPE_CODE_VOID)
674*ef5ccd6cSJohn Marino {
675*ef5ccd6cSJohn Marino --num_types;
676*ef5ccd6cSJohn Marino /* Caller should have ensured this. */
677*ef5ccd6cSJohn Marino gdb_assert (num_types == 0);
678*ef5ccd6cSJohn Marino TYPE_PROTOTYPED (type) = 1;
679*ef5ccd6cSJohn Marino }
680*ef5ccd6cSJohn Marino }
681*ef5ccd6cSJohn Marino
682cf7f2e2dSJohn Marino TYPE_NFIELDS (type) = num_types;
683cf7f2e2dSJohn Marino TYPE_FIELDS (type) = (struct field *)
684cf7f2e2dSJohn Marino TYPE_ZALLOC (type, sizeof (struct field) * num_types);
685cf7f2e2dSJohn Marino
686cf7f2e2dSJohn Marino while (num_types-- > 0)
687cf7f2e2dSJohn Marino TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
688cf7f2e2dSJohn Marino
689cf7f2e2dSJohn Marino return type;
690cf7f2e2dSJohn Marino }
691cf7f2e2dSJohn Marino
6925796c8dcSSimon Schubert struct value *
evaluate_subexp_standard(struct type * expect_type,struct expression * exp,int * pos,enum noside noside)6935796c8dcSSimon Schubert evaluate_subexp_standard (struct type *expect_type,
6945796c8dcSSimon Schubert struct expression *exp, int *pos,
6955796c8dcSSimon Schubert enum noside noside)
6965796c8dcSSimon Schubert {
6975796c8dcSSimon Schubert enum exp_opcode op;
6985796c8dcSSimon Schubert int tem, tem2, tem3;
6995796c8dcSSimon Schubert int pc, pc2 = 0, oldpos;
7005796c8dcSSimon Schubert struct value *arg1 = NULL;
7015796c8dcSSimon Schubert struct value *arg2 = NULL;
7025796c8dcSSimon Schubert struct value *arg3;
7035796c8dcSSimon Schubert struct type *type;
7045796c8dcSSimon Schubert int nargs;
7055796c8dcSSimon Schubert struct value **argvec;
7065796c8dcSSimon Schubert int code;
7075796c8dcSSimon Schubert int ix;
7085796c8dcSSimon Schubert long mem_offset;
7095796c8dcSSimon Schubert struct type **arg_types;
7105796c8dcSSimon Schubert int save_pos1;
711cf7f2e2dSJohn Marino struct symbol *function = NULL;
712cf7f2e2dSJohn Marino char *function_name = NULL;
7135796c8dcSSimon Schubert
7145796c8dcSSimon Schubert pc = (*pos)++;
7155796c8dcSSimon Schubert op = exp->elts[pc].opcode;
7165796c8dcSSimon Schubert
7175796c8dcSSimon Schubert switch (op)
7185796c8dcSSimon Schubert {
7195796c8dcSSimon Schubert case OP_SCOPE:
7205796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 2].longconst);
7215796c8dcSSimon Schubert (*pos) += 4 + BYTES_TO_EXP_ELEM (tem + 1);
7225796c8dcSSimon Schubert if (noside == EVAL_SKIP)
7235796c8dcSSimon Schubert goto nosideret;
7245796c8dcSSimon Schubert arg1 = value_aggregate_elt (exp->elts[pc + 1].type,
7255796c8dcSSimon Schubert &exp->elts[pc + 3].string,
726cf7f2e2dSJohn Marino expect_type, 0, noside);
7275796c8dcSSimon Schubert if (arg1 == NULL)
7285796c8dcSSimon Schubert error (_("There is no field named %s"), &exp->elts[pc + 3].string);
7295796c8dcSSimon Schubert return arg1;
7305796c8dcSSimon Schubert
7315796c8dcSSimon Schubert case OP_LONG:
7325796c8dcSSimon Schubert (*pos) += 3;
7335796c8dcSSimon Schubert return value_from_longest (exp->elts[pc + 1].type,
7345796c8dcSSimon Schubert exp->elts[pc + 2].longconst);
7355796c8dcSSimon Schubert
7365796c8dcSSimon Schubert case OP_DOUBLE:
7375796c8dcSSimon Schubert (*pos) += 3;
7385796c8dcSSimon Schubert return value_from_double (exp->elts[pc + 1].type,
7395796c8dcSSimon Schubert exp->elts[pc + 2].doubleconst);
7405796c8dcSSimon Schubert
7415796c8dcSSimon Schubert case OP_DECFLOAT:
7425796c8dcSSimon Schubert (*pos) += 3;
7435796c8dcSSimon Schubert return value_from_decfloat (exp->elts[pc + 1].type,
7445796c8dcSSimon Schubert exp->elts[pc + 2].decfloatconst);
7455796c8dcSSimon Schubert
746cf7f2e2dSJohn Marino case OP_ADL_FUNC:
7475796c8dcSSimon Schubert case OP_VAR_VALUE:
7485796c8dcSSimon Schubert (*pos) += 3;
7495796c8dcSSimon Schubert if (noside == EVAL_SKIP)
7505796c8dcSSimon Schubert goto nosideret;
7515796c8dcSSimon Schubert
7525796c8dcSSimon Schubert /* JYG: We used to just return value_zero of the symbol type
7535796c8dcSSimon Schubert if we're asked to avoid side effects. Otherwise we return
7545796c8dcSSimon Schubert value_of_variable (...). However I'm not sure if
7555796c8dcSSimon Schubert value_of_variable () has any side effect.
7565796c8dcSSimon Schubert We need a full value object returned here for whatis_exp ()
7575796c8dcSSimon Schubert to call evaluate_type () and then pass the full value to
7585796c8dcSSimon Schubert value_rtti_target_type () if we are dealing with a pointer
7595796c8dcSSimon Schubert or reference to a base class and print object is on. */
7605796c8dcSSimon Schubert
7615796c8dcSSimon Schubert {
7625796c8dcSSimon Schubert volatile struct gdb_exception except;
7635796c8dcSSimon Schubert struct value *ret = NULL;
7645796c8dcSSimon Schubert
7655796c8dcSSimon Schubert TRY_CATCH (except, RETURN_MASK_ERROR)
7665796c8dcSSimon Schubert {
7675796c8dcSSimon Schubert ret = value_of_variable (exp->elts[pc + 2].symbol,
7685796c8dcSSimon Schubert exp->elts[pc + 1].block);
7695796c8dcSSimon Schubert }
7705796c8dcSSimon Schubert
7715796c8dcSSimon Schubert if (except.reason < 0)
7725796c8dcSSimon Schubert {
7735796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
774c50c785cSJohn Marino ret = value_zero (SYMBOL_TYPE (exp->elts[pc + 2].symbol),
775c50c785cSJohn Marino not_lval);
7765796c8dcSSimon Schubert else
7775796c8dcSSimon Schubert throw_exception (except);
7785796c8dcSSimon Schubert }
7795796c8dcSSimon Schubert
7805796c8dcSSimon Schubert return ret;
7815796c8dcSSimon Schubert }
7825796c8dcSSimon Schubert
783a45ae5f8SJohn Marino case OP_VAR_ENTRY_VALUE:
784a45ae5f8SJohn Marino (*pos) += 2;
785a45ae5f8SJohn Marino if (noside == EVAL_SKIP)
786a45ae5f8SJohn Marino goto nosideret;
787a45ae5f8SJohn Marino
788a45ae5f8SJohn Marino {
789a45ae5f8SJohn Marino struct symbol *sym = exp->elts[pc + 1].symbol;
790a45ae5f8SJohn Marino struct frame_info *frame;
791a45ae5f8SJohn Marino
792a45ae5f8SJohn Marino if (noside == EVAL_AVOID_SIDE_EFFECTS)
793a45ae5f8SJohn Marino return value_zero (SYMBOL_TYPE (sym), not_lval);
794a45ae5f8SJohn Marino
795a45ae5f8SJohn Marino if (SYMBOL_CLASS (sym) != LOC_COMPUTED
796a45ae5f8SJohn Marino || SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
797a45ae5f8SJohn Marino error (_("Symbol \"%s\" does not have any specific entry value"),
798a45ae5f8SJohn Marino SYMBOL_PRINT_NAME (sym));
799a45ae5f8SJohn Marino
800a45ae5f8SJohn Marino frame = get_selected_frame (NULL);
801a45ae5f8SJohn Marino return SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry (sym, frame);
802a45ae5f8SJohn Marino }
803a45ae5f8SJohn Marino
8045796c8dcSSimon Schubert case OP_LAST:
8055796c8dcSSimon Schubert (*pos) += 2;
8065796c8dcSSimon Schubert return
8075796c8dcSSimon Schubert access_value_history (longest_to_int (exp->elts[pc + 1].longconst));
8085796c8dcSSimon Schubert
8095796c8dcSSimon Schubert case OP_REGISTER:
8105796c8dcSSimon Schubert {
8115796c8dcSSimon Schubert const char *name = &exp->elts[pc + 2].string;
8125796c8dcSSimon Schubert int regno;
8135796c8dcSSimon Schubert struct value *val;
8145796c8dcSSimon Schubert
8155796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
8165796c8dcSSimon Schubert regno = user_reg_map_name_to_regnum (exp->gdbarch,
8175796c8dcSSimon Schubert name, strlen (name));
8185796c8dcSSimon Schubert if (regno == -1)
8195796c8dcSSimon Schubert error (_("Register $%s not available."), name);
8205796c8dcSSimon Schubert
8215796c8dcSSimon Schubert /* In EVAL_AVOID_SIDE_EFFECTS mode, we only need to return
8225796c8dcSSimon Schubert a value with the appropriate register type. Unfortunately,
8235796c8dcSSimon Schubert we don't have easy access to the type of user registers.
8245796c8dcSSimon Schubert So for these registers, we fetch the register value regardless
8255796c8dcSSimon Schubert of the evaluation mode. */
8265796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS
8275796c8dcSSimon Schubert && regno < gdbarch_num_regs (exp->gdbarch)
8285796c8dcSSimon Schubert + gdbarch_num_pseudo_regs (exp->gdbarch))
8295796c8dcSSimon Schubert val = value_zero (register_type (exp->gdbarch, regno), not_lval);
8305796c8dcSSimon Schubert else
8315796c8dcSSimon Schubert val = value_of_register (regno, get_selected_frame (NULL));
8325796c8dcSSimon Schubert if (val == NULL)
8335796c8dcSSimon Schubert error (_("Value of register %s not available."), name);
8345796c8dcSSimon Schubert else
8355796c8dcSSimon Schubert return val;
8365796c8dcSSimon Schubert }
8375796c8dcSSimon Schubert case OP_BOOL:
8385796c8dcSSimon Schubert (*pos) += 2;
8395796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
8405796c8dcSSimon Schubert return value_from_longest (type, exp->elts[pc + 1].longconst);
8415796c8dcSSimon Schubert
8425796c8dcSSimon Schubert case OP_INTERNALVAR:
8435796c8dcSSimon Schubert (*pos) += 2;
8445796c8dcSSimon Schubert return value_of_internalvar (exp->gdbarch,
8455796c8dcSSimon Schubert exp->elts[pc + 1].internalvar);
8465796c8dcSSimon Schubert
8475796c8dcSSimon Schubert case OP_STRING:
8485796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst);
8495796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
8505796c8dcSSimon Schubert if (noside == EVAL_SKIP)
8515796c8dcSSimon Schubert goto nosideret;
8525796c8dcSSimon Schubert type = language_string_char_type (exp->language_defn, exp->gdbarch);
8535796c8dcSSimon Schubert return value_string (&exp->elts[pc + 2].string, tem, type);
8545796c8dcSSimon Schubert
855c50c785cSJohn Marino case OP_OBJC_NSSTRING: /* Objective C Foundation Class
856c50c785cSJohn Marino NSString constant. */
8575796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst);
8585796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
8595796c8dcSSimon Schubert if (noside == EVAL_SKIP)
8605796c8dcSSimon Schubert {
8615796c8dcSSimon Schubert goto nosideret;
8625796c8dcSSimon Schubert }
8635796c8dcSSimon Schubert return value_nsstring (exp->gdbarch, &exp->elts[pc + 2].string, tem + 1);
8645796c8dcSSimon Schubert
8655796c8dcSSimon Schubert case OP_ARRAY:
8665796c8dcSSimon Schubert (*pos) += 3;
8675796c8dcSSimon Schubert tem2 = longest_to_int (exp->elts[pc + 1].longconst);
8685796c8dcSSimon Schubert tem3 = longest_to_int (exp->elts[pc + 2].longconst);
8695796c8dcSSimon Schubert nargs = tem3 - tem2 + 1;
8705796c8dcSSimon Schubert type = expect_type ? check_typedef (expect_type) : NULL_TYPE;
8715796c8dcSSimon Schubert
8725796c8dcSSimon Schubert if (expect_type != NULL_TYPE && noside != EVAL_SKIP
8735796c8dcSSimon Schubert && TYPE_CODE (type) == TYPE_CODE_STRUCT)
8745796c8dcSSimon Schubert {
8755796c8dcSSimon Schubert struct value *rec = allocate_value (expect_type);
876cf7f2e2dSJohn Marino
8775796c8dcSSimon Schubert memset (value_contents_raw (rec), '\0', TYPE_LENGTH (type));
8785796c8dcSSimon Schubert return evaluate_struct_tuple (rec, exp, pos, noside, nargs);
8795796c8dcSSimon Schubert }
8805796c8dcSSimon Schubert
8815796c8dcSSimon Schubert if (expect_type != NULL_TYPE && noside != EVAL_SKIP
8825796c8dcSSimon Schubert && TYPE_CODE (type) == TYPE_CODE_ARRAY)
8835796c8dcSSimon Schubert {
8845796c8dcSSimon Schubert struct type *range_type = TYPE_INDEX_TYPE (type);
8855796c8dcSSimon Schubert struct type *element_type = TYPE_TARGET_TYPE (type);
8865796c8dcSSimon Schubert struct value *array = allocate_value (expect_type);
8875796c8dcSSimon Schubert int element_size = TYPE_LENGTH (check_typedef (element_type));
8885796c8dcSSimon Schubert LONGEST low_bound, high_bound, index;
889cf7f2e2dSJohn Marino
8905796c8dcSSimon Schubert if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
8915796c8dcSSimon Schubert {
8925796c8dcSSimon Schubert low_bound = 0;
8935796c8dcSSimon Schubert high_bound = (TYPE_LENGTH (type) / element_size) - 1;
8945796c8dcSSimon Schubert }
8955796c8dcSSimon Schubert index = low_bound;
8965796c8dcSSimon Schubert memset (value_contents_raw (array), 0, TYPE_LENGTH (expect_type));
8975796c8dcSSimon Schubert for (tem = nargs; --nargs >= 0;)
8985796c8dcSSimon Schubert {
8995796c8dcSSimon Schubert struct value *element;
9005796c8dcSSimon Schubert int index_pc = 0;
901cf7f2e2dSJohn Marino
9025796c8dcSSimon Schubert if (exp->elts[*pos].opcode == BINOP_RANGE)
9035796c8dcSSimon Schubert {
9045796c8dcSSimon Schubert index_pc = ++(*pos);
9055796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
9065796c8dcSSimon Schubert }
9075796c8dcSSimon Schubert element = evaluate_subexp (element_type, exp, pos, noside);
9085796c8dcSSimon Schubert if (value_type (element) != element_type)
9095796c8dcSSimon Schubert element = value_cast (element_type, element);
9105796c8dcSSimon Schubert if (index_pc)
9115796c8dcSSimon Schubert {
9125796c8dcSSimon Schubert int continue_pc = *pos;
913cf7f2e2dSJohn Marino
9145796c8dcSSimon Schubert *pos = index_pc;
9155796c8dcSSimon Schubert index = init_array_element (array, element, exp, pos, noside,
9165796c8dcSSimon Schubert low_bound, high_bound);
9175796c8dcSSimon Schubert *pos = continue_pc;
9185796c8dcSSimon Schubert }
9195796c8dcSSimon Schubert else
9205796c8dcSSimon Schubert {
9215796c8dcSSimon Schubert if (index > high_bound)
922c50c785cSJohn Marino /* To avoid memory corruption. */
9235796c8dcSSimon Schubert error (_("Too many array elements"));
9245796c8dcSSimon Schubert memcpy (value_contents_raw (array)
9255796c8dcSSimon Schubert + (index - low_bound) * element_size,
9265796c8dcSSimon Schubert value_contents (element),
9275796c8dcSSimon Schubert element_size);
9285796c8dcSSimon Schubert }
9295796c8dcSSimon Schubert index++;
9305796c8dcSSimon Schubert }
9315796c8dcSSimon Schubert return array;
9325796c8dcSSimon Schubert }
9335796c8dcSSimon Schubert
9345796c8dcSSimon Schubert if (expect_type != NULL_TYPE && noside != EVAL_SKIP
9355796c8dcSSimon Schubert && TYPE_CODE (type) == TYPE_CODE_SET)
9365796c8dcSSimon Schubert {
9375796c8dcSSimon Schubert struct value *set = allocate_value (expect_type);
9385796c8dcSSimon Schubert gdb_byte *valaddr = value_contents_raw (set);
9395796c8dcSSimon Schubert struct type *element_type = TYPE_INDEX_TYPE (type);
9405796c8dcSSimon Schubert struct type *check_type = element_type;
9415796c8dcSSimon Schubert LONGEST low_bound, high_bound;
9425796c8dcSSimon Schubert
943c50c785cSJohn Marino /* Get targettype of elementtype. */
944cf7f2e2dSJohn Marino while (TYPE_CODE (check_type) == TYPE_CODE_RANGE
945cf7f2e2dSJohn Marino || TYPE_CODE (check_type) == TYPE_CODE_TYPEDEF)
9465796c8dcSSimon Schubert check_type = TYPE_TARGET_TYPE (check_type);
9475796c8dcSSimon Schubert
9485796c8dcSSimon Schubert if (get_discrete_bounds (element_type, &low_bound, &high_bound) < 0)
9495796c8dcSSimon Schubert error (_("(power)set type with unknown size"));
9505796c8dcSSimon Schubert memset (valaddr, '\0', TYPE_LENGTH (type));
9515796c8dcSSimon Schubert for (tem = 0; tem < nargs; tem++)
9525796c8dcSSimon Schubert {
9535796c8dcSSimon Schubert LONGEST range_low, range_high;
9545796c8dcSSimon Schubert struct type *range_low_type, *range_high_type;
9555796c8dcSSimon Schubert struct value *elem_val;
956cf7f2e2dSJohn Marino
9575796c8dcSSimon Schubert if (exp->elts[*pos].opcode == BINOP_RANGE)
9585796c8dcSSimon Schubert {
9595796c8dcSSimon Schubert (*pos)++;
9605796c8dcSSimon Schubert elem_val = evaluate_subexp (element_type, exp, pos, noside);
9615796c8dcSSimon Schubert range_low_type = value_type (elem_val);
9625796c8dcSSimon Schubert range_low = value_as_long (elem_val);
9635796c8dcSSimon Schubert elem_val = evaluate_subexp (element_type, exp, pos, noside);
9645796c8dcSSimon Schubert range_high_type = value_type (elem_val);
9655796c8dcSSimon Schubert range_high = value_as_long (elem_val);
9665796c8dcSSimon Schubert }
9675796c8dcSSimon Schubert else
9685796c8dcSSimon Schubert {
9695796c8dcSSimon Schubert elem_val = evaluate_subexp (element_type, exp, pos, noside);
9705796c8dcSSimon Schubert range_low_type = range_high_type = value_type (elem_val);
9715796c8dcSSimon Schubert range_low = range_high = value_as_long (elem_val);
9725796c8dcSSimon Schubert }
973c50c785cSJohn Marino /* Check types of elements to avoid mixture of elements from
9745796c8dcSSimon Schubert different types. Also check if type of element is "compatible"
975c50c785cSJohn Marino with element type of powerset. */
9765796c8dcSSimon Schubert if (TYPE_CODE (range_low_type) == TYPE_CODE_RANGE)
9775796c8dcSSimon Schubert range_low_type = TYPE_TARGET_TYPE (range_low_type);
9785796c8dcSSimon Schubert if (TYPE_CODE (range_high_type) == TYPE_CODE_RANGE)
9795796c8dcSSimon Schubert range_high_type = TYPE_TARGET_TYPE (range_high_type);
980cf7f2e2dSJohn Marino if ((TYPE_CODE (range_low_type) != TYPE_CODE (range_high_type))
981cf7f2e2dSJohn Marino || (TYPE_CODE (range_low_type) == TYPE_CODE_ENUM
982cf7f2e2dSJohn Marino && (range_low_type != range_high_type)))
983c50c785cSJohn Marino /* different element modes. */
9845796c8dcSSimon Schubert error (_("POWERSET tuple elements of different mode"));
985cf7f2e2dSJohn Marino if ((TYPE_CODE (check_type) != TYPE_CODE (range_low_type))
986cf7f2e2dSJohn Marino || (TYPE_CODE (check_type) == TYPE_CODE_ENUM
987cf7f2e2dSJohn Marino && range_low_type != check_type))
9885796c8dcSSimon Schubert error (_("incompatible POWERSET tuple elements"));
9895796c8dcSSimon Schubert if (range_low > range_high)
9905796c8dcSSimon Schubert {
9915796c8dcSSimon Schubert warning (_("empty POWERSET tuple range"));
9925796c8dcSSimon Schubert continue;
9935796c8dcSSimon Schubert }
9945796c8dcSSimon Schubert if (range_low < low_bound || range_high > high_bound)
9955796c8dcSSimon Schubert error (_("POWERSET tuple element out of range"));
9965796c8dcSSimon Schubert range_low -= low_bound;
9975796c8dcSSimon Schubert range_high -= low_bound;
9985796c8dcSSimon Schubert for (; range_low <= range_high; range_low++)
9995796c8dcSSimon Schubert {
10005796c8dcSSimon Schubert int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;
1001cf7f2e2dSJohn Marino
10025796c8dcSSimon Schubert if (gdbarch_bits_big_endian (exp->gdbarch))
10035796c8dcSSimon Schubert bit_index = TARGET_CHAR_BIT - 1 - bit_index;
10045796c8dcSSimon Schubert valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
10055796c8dcSSimon Schubert |= 1 << bit_index;
10065796c8dcSSimon Schubert }
10075796c8dcSSimon Schubert }
10085796c8dcSSimon Schubert return set;
10095796c8dcSSimon Schubert }
10105796c8dcSSimon Schubert
10115796c8dcSSimon Schubert argvec = (struct value **) alloca (sizeof (struct value *) * nargs);
10125796c8dcSSimon Schubert for (tem = 0; tem < nargs; tem++)
10135796c8dcSSimon Schubert {
1014c50c785cSJohn Marino /* Ensure that array expressions are coerced into pointer
1015c50c785cSJohn Marino objects. */
10165796c8dcSSimon Schubert argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
10175796c8dcSSimon Schubert }
10185796c8dcSSimon Schubert if (noside == EVAL_SKIP)
10195796c8dcSSimon Schubert goto nosideret;
10205796c8dcSSimon Schubert return value_array (tem2, tem3, argvec);
10215796c8dcSSimon Schubert
10225796c8dcSSimon Schubert case TERNOP_SLICE:
10235796c8dcSSimon Schubert {
10245796c8dcSSimon Schubert struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
10255796c8dcSSimon Schubert int lowbound
10265796c8dcSSimon Schubert = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
10275796c8dcSSimon Schubert int upper
10285796c8dcSSimon Schubert = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
1029cf7f2e2dSJohn Marino
10305796c8dcSSimon Schubert if (noside == EVAL_SKIP)
10315796c8dcSSimon Schubert goto nosideret;
10325796c8dcSSimon Schubert return value_slice (array, lowbound, upper - lowbound + 1);
10335796c8dcSSimon Schubert }
10345796c8dcSSimon Schubert
10355796c8dcSSimon Schubert case TERNOP_COND:
10365796c8dcSSimon Schubert /* Skip third and second args to evaluate the first one. */
10375796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
10385796c8dcSSimon Schubert if (value_logical_not (arg1))
10395796c8dcSSimon Schubert {
10405796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
10415796c8dcSSimon Schubert return evaluate_subexp (NULL_TYPE, exp, pos, noside);
10425796c8dcSSimon Schubert }
10435796c8dcSSimon Schubert else
10445796c8dcSSimon Schubert {
10455796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
10465796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
10475796c8dcSSimon Schubert return arg2;
10485796c8dcSSimon Schubert }
10495796c8dcSSimon Schubert
10505796c8dcSSimon Schubert case OP_OBJC_SELECTOR:
10515796c8dcSSimon Schubert { /* Objective C @selector operator. */
10525796c8dcSSimon Schubert char *sel = &exp->elts[pc + 2].string;
10535796c8dcSSimon Schubert int len = longest_to_int (exp->elts[pc + 1].longconst);
10545796c8dcSSimon Schubert struct type *selector_type;
10555796c8dcSSimon Schubert
10565796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (len + 1);
10575796c8dcSSimon Schubert if (noside == EVAL_SKIP)
10585796c8dcSSimon Schubert goto nosideret;
10595796c8dcSSimon Schubert
10605796c8dcSSimon Schubert if (sel[len] != 0)
10615796c8dcSSimon Schubert sel[len] = 0; /* Make sure it's terminated. */
10625796c8dcSSimon Schubert
10635796c8dcSSimon Schubert selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
10645796c8dcSSimon Schubert return value_from_longest (selector_type,
10655796c8dcSSimon Schubert lookup_child_selector (exp->gdbarch, sel));
10665796c8dcSSimon Schubert }
10675796c8dcSSimon Schubert
10685796c8dcSSimon Schubert case OP_OBJC_MSGCALL:
10695796c8dcSSimon Schubert { /* Objective C message (method) call. */
10705796c8dcSSimon Schubert
10715796c8dcSSimon Schubert CORE_ADDR responds_selector = 0;
10725796c8dcSSimon Schubert CORE_ADDR method_selector = 0;
10735796c8dcSSimon Schubert
10745796c8dcSSimon Schubert CORE_ADDR selector = 0;
10755796c8dcSSimon Schubert
10765796c8dcSSimon Schubert int struct_return = 0;
10775796c8dcSSimon Schubert int sub_no_side = 0;
10785796c8dcSSimon Schubert
10795796c8dcSSimon Schubert struct value *msg_send = NULL;
10805796c8dcSSimon Schubert struct value *msg_send_stret = NULL;
10815796c8dcSSimon Schubert int gnu_runtime = 0;
10825796c8dcSSimon Schubert
10835796c8dcSSimon Schubert struct value *target = NULL;
10845796c8dcSSimon Schubert struct value *method = NULL;
10855796c8dcSSimon Schubert struct value *called_method = NULL;
10865796c8dcSSimon Schubert
10875796c8dcSSimon Schubert struct type *selector_type = NULL;
10885796c8dcSSimon Schubert struct type *long_type;
10895796c8dcSSimon Schubert
10905796c8dcSSimon Schubert struct value *ret = NULL;
10915796c8dcSSimon Schubert CORE_ADDR addr = 0;
10925796c8dcSSimon Schubert
10935796c8dcSSimon Schubert selector = exp->elts[pc + 1].longconst;
10945796c8dcSSimon Schubert nargs = exp->elts[pc + 2].longconst;
10955796c8dcSSimon Schubert argvec = (struct value **) alloca (sizeof (struct value *)
10965796c8dcSSimon Schubert * (nargs + 5));
10975796c8dcSSimon Schubert
10985796c8dcSSimon Schubert (*pos) += 3;
10995796c8dcSSimon Schubert
11005796c8dcSSimon Schubert long_type = builtin_type (exp->gdbarch)->builtin_long;
11015796c8dcSSimon Schubert selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
11025796c8dcSSimon Schubert
11035796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
11045796c8dcSSimon Schubert sub_no_side = EVAL_NORMAL;
11055796c8dcSSimon Schubert else
11065796c8dcSSimon Schubert sub_no_side = noside;
11075796c8dcSSimon Schubert
11085796c8dcSSimon Schubert target = evaluate_subexp (selector_type, exp, pos, sub_no_side);
11095796c8dcSSimon Schubert
11105796c8dcSSimon Schubert if (value_as_long (target) == 0)
11115796c8dcSSimon Schubert return value_from_longest (long_type, 0);
11125796c8dcSSimon Schubert
11135796c8dcSSimon Schubert if (lookup_minimal_symbol ("objc_msg_lookup", 0, 0))
11145796c8dcSSimon Schubert gnu_runtime = 1;
11155796c8dcSSimon Schubert
11165796c8dcSSimon Schubert /* Find the method dispatch (Apple runtime) or method lookup
11175796c8dcSSimon Schubert (GNU runtime) function for Objective-C. These will be used
11185796c8dcSSimon Schubert to lookup the symbol information for the method. If we
11195796c8dcSSimon Schubert can't find any symbol information, then we'll use these to
11205796c8dcSSimon Schubert call the method, otherwise we can call the method
11215796c8dcSSimon Schubert directly. The msg_send_stret function is used in the special
11225796c8dcSSimon Schubert case of a method that returns a structure (Apple runtime
11235796c8dcSSimon Schubert only). */
11245796c8dcSSimon Schubert if (gnu_runtime)
11255796c8dcSSimon Schubert {
11265796c8dcSSimon Schubert struct type *type = selector_type;
1127cf7f2e2dSJohn Marino
11285796c8dcSSimon Schubert type = lookup_function_type (type);
11295796c8dcSSimon Schubert type = lookup_pointer_type (type);
11305796c8dcSSimon Schubert type = lookup_function_type (type);
11315796c8dcSSimon Schubert type = lookup_pointer_type (type);
11325796c8dcSSimon Schubert
11335796c8dcSSimon Schubert msg_send = find_function_in_inferior ("objc_msg_lookup", NULL);
11345796c8dcSSimon Schubert msg_send_stret
11355796c8dcSSimon Schubert = find_function_in_inferior ("objc_msg_lookup", NULL);
11365796c8dcSSimon Schubert
11375796c8dcSSimon Schubert msg_send = value_from_pointer (type, value_as_address (msg_send));
11385796c8dcSSimon Schubert msg_send_stret = value_from_pointer (type,
11395796c8dcSSimon Schubert value_as_address (msg_send_stret));
11405796c8dcSSimon Schubert }
11415796c8dcSSimon Schubert else
11425796c8dcSSimon Schubert {
11435796c8dcSSimon Schubert msg_send = find_function_in_inferior ("objc_msgSend", NULL);
1144c50c785cSJohn Marino /* Special dispatcher for methods returning structs. */
11455796c8dcSSimon Schubert msg_send_stret
11465796c8dcSSimon Schubert = find_function_in_inferior ("objc_msgSend_stret", NULL);
11475796c8dcSSimon Schubert }
11485796c8dcSSimon Schubert
11495796c8dcSSimon Schubert /* Verify the target object responds to this method. The
11505796c8dcSSimon Schubert standard top-level 'Object' class uses a different name for
11515796c8dcSSimon Schubert the verification method than the non-standard, but more
11525796c8dcSSimon Schubert often used, 'NSObject' class. Make sure we check for both. */
11535796c8dcSSimon Schubert
11545796c8dcSSimon Schubert responds_selector
11555796c8dcSSimon Schubert = lookup_child_selector (exp->gdbarch, "respondsToSelector:");
11565796c8dcSSimon Schubert if (responds_selector == 0)
11575796c8dcSSimon Schubert responds_selector
11585796c8dcSSimon Schubert = lookup_child_selector (exp->gdbarch, "respondsTo:");
11595796c8dcSSimon Schubert
11605796c8dcSSimon Schubert if (responds_selector == 0)
11615796c8dcSSimon Schubert error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
11625796c8dcSSimon Schubert
11635796c8dcSSimon Schubert method_selector
11645796c8dcSSimon Schubert = lookup_child_selector (exp->gdbarch, "methodForSelector:");
11655796c8dcSSimon Schubert if (method_selector == 0)
11665796c8dcSSimon Schubert method_selector
11675796c8dcSSimon Schubert = lookup_child_selector (exp->gdbarch, "methodFor:");
11685796c8dcSSimon Schubert
11695796c8dcSSimon Schubert if (method_selector == 0)
11705796c8dcSSimon Schubert error (_("no 'methodFor:' or 'methodForSelector:' method"));
11715796c8dcSSimon Schubert
11725796c8dcSSimon Schubert /* Call the verification method, to make sure that the target
11735796c8dcSSimon Schubert class implements the desired method. */
11745796c8dcSSimon Schubert
11755796c8dcSSimon Schubert argvec[0] = msg_send;
11765796c8dcSSimon Schubert argvec[1] = target;
11775796c8dcSSimon Schubert argvec[2] = value_from_longest (long_type, responds_selector);
11785796c8dcSSimon Schubert argvec[3] = value_from_longest (long_type, selector);
11795796c8dcSSimon Schubert argvec[4] = 0;
11805796c8dcSSimon Schubert
11815796c8dcSSimon Schubert ret = call_function_by_hand (argvec[0], 3, argvec + 1);
11825796c8dcSSimon Schubert if (gnu_runtime)
11835796c8dcSSimon Schubert {
11845796c8dcSSimon Schubert /* Function objc_msg_lookup returns a pointer. */
11855796c8dcSSimon Schubert argvec[0] = ret;
11865796c8dcSSimon Schubert ret = call_function_by_hand (argvec[0], 3, argvec + 1);
11875796c8dcSSimon Schubert }
11885796c8dcSSimon Schubert if (value_as_long (ret) == 0)
11895796c8dcSSimon Schubert error (_("Target does not respond to this message selector."));
11905796c8dcSSimon Schubert
11915796c8dcSSimon Schubert /* Call "methodForSelector:" method, to get the address of a
11925796c8dcSSimon Schubert function method that implements this selector for this
11935796c8dcSSimon Schubert class. If we can find a symbol at that address, then we
11945796c8dcSSimon Schubert know the return type, parameter types etc. (that's a good
11955796c8dcSSimon Schubert thing). */
11965796c8dcSSimon Schubert
11975796c8dcSSimon Schubert argvec[0] = msg_send;
11985796c8dcSSimon Schubert argvec[1] = target;
11995796c8dcSSimon Schubert argvec[2] = value_from_longest (long_type, method_selector);
12005796c8dcSSimon Schubert argvec[3] = value_from_longest (long_type, selector);
12015796c8dcSSimon Schubert argvec[4] = 0;
12025796c8dcSSimon Schubert
12035796c8dcSSimon Schubert ret = call_function_by_hand (argvec[0], 3, argvec + 1);
12045796c8dcSSimon Schubert if (gnu_runtime)
12055796c8dcSSimon Schubert {
12065796c8dcSSimon Schubert argvec[0] = ret;
12075796c8dcSSimon Schubert ret = call_function_by_hand (argvec[0], 3, argvec + 1);
12085796c8dcSSimon Schubert }
12095796c8dcSSimon Schubert
12105796c8dcSSimon Schubert /* ret should now be the selector. */
12115796c8dcSSimon Schubert
12125796c8dcSSimon Schubert addr = value_as_long (ret);
12135796c8dcSSimon Schubert if (addr)
12145796c8dcSSimon Schubert {
12155796c8dcSSimon Schubert struct symbol *sym = NULL;
12165796c8dcSSimon Schubert
1217cf7f2e2dSJohn Marino /* The address might point to a function descriptor;
1218cf7f2e2dSJohn Marino resolve it to the actual code address instead. */
1219cf7f2e2dSJohn Marino addr = gdbarch_convert_from_func_ptr_addr (exp->gdbarch, addr,
1220cf7f2e2dSJohn Marino ¤t_target);
1221cf7f2e2dSJohn Marino
1222cf7f2e2dSJohn Marino /* Is it a high_level symbol? */
12235796c8dcSSimon Schubert sym = find_pc_function (addr);
12245796c8dcSSimon Schubert if (sym != NULL)
12255796c8dcSSimon Schubert method = value_of_variable (sym, 0);
12265796c8dcSSimon Schubert }
12275796c8dcSSimon Schubert
12285796c8dcSSimon Schubert /* If we found a method with symbol information, check to see
12295796c8dcSSimon Schubert if it returns a struct. Otherwise assume it doesn't. */
12305796c8dcSSimon Schubert
12315796c8dcSSimon Schubert if (method)
12325796c8dcSSimon Schubert {
12335796c8dcSSimon Schubert CORE_ADDR funaddr;
12345796c8dcSSimon Schubert struct type *val_type;
12355796c8dcSSimon Schubert
12365796c8dcSSimon Schubert funaddr = find_function_addr (method, &val_type);
12375796c8dcSSimon Schubert
1238c50c785cSJohn Marino block_for_pc (funaddr);
12395796c8dcSSimon Schubert
12405796c8dcSSimon Schubert CHECK_TYPEDEF (val_type);
12415796c8dcSSimon Schubert
12425796c8dcSSimon Schubert if ((val_type == NULL)
12435796c8dcSSimon Schubert || (TYPE_CODE(val_type) == TYPE_CODE_ERROR))
12445796c8dcSSimon Schubert {
12455796c8dcSSimon Schubert if (expect_type != NULL)
12465796c8dcSSimon Schubert val_type = expect_type;
12475796c8dcSSimon Schubert }
12485796c8dcSSimon Schubert
1249*ef5ccd6cSJohn Marino struct_return = using_struct_return (exp->gdbarch, method,
1250c50c785cSJohn Marino val_type);
12515796c8dcSSimon Schubert }
12525796c8dcSSimon Schubert else if (expect_type != NULL)
12535796c8dcSSimon Schubert {
12545796c8dcSSimon Schubert struct_return = using_struct_return (exp->gdbarch, NULL,
12555796c8dcSSimon Schubert check_typedef (expect_type));
12565796c8dcSSimon Schubert }
12575796c8dcSSimon Schubert
12585796c8dcSSimon Schubert /* Found a function symbol. Now we will substitute its
12595796c8dcSSimon Schubert value in place of the message dispatcher (obj_msgSend),
12605796c8dcSSimon Schubert so that we call the method directly instead of thru
12615796c8dcSSimon Schubert the dispatcher. The main reason for doing this is that
12625796c8dcSSimon Schubert we can now evaluate the return value and parameter values
12635796c8dcSSimon Schubert according to their known data types, in case we need to
12645796c8dcSSimon Schubert do things like promotion, dereferencing, special handling
12655796c8dcSSimon Schubert of structs and doubles, etc.
12665796c8dcSSimon Schubert
12675796c8dcSSimon Schubert We want to use the type signature of 'method', but still
12685796c8dcSSimon Schubert jump to objc_msgSend() or objc_msgSend_stret() to better
12695796c8dcSSimon Schubert mimic the behavior of the runtime. */
12705796c8dcSSimon Schubert
12715796c8dcSSimon Schubert if (method)
12725796c8dcSSimon Schubert {
12735796c8dcSSimon Schubert if (TYPE_CODE (value_type (method)) != TYPE_CODE_FUNC)
1274c50c785cSJohn Marino error (_("method address has symbol information "
1275c50c785cSJohn Marino "with non-function type; skipping"));
1276cf7f2e2dSJohn Marino
1277c50c785cSJohn Marino /* Create a function pointer of the appropriate type, and
1278c50c785cSJohn Marino replace its value with the value of msg_send or
1279c50c785cSJohn Marino msg_send_stret. We must use a pointer here, as
1280c50c785cSJohn Marino msg_send and msg_send_stret are of pointer type, and
1281c50c785cSJohn Marino the representation may be different on systems that use
1282cf7f2e2dSJohn Marino function descriptors. */
12835796c8dcSSimon Schubert if (struct_return)
1284cf7f2e2dSJohn Marino called_method
1285cf7f2e2dSJohn Marino = value_from_pointer (lookup_pointer_type (value_type (method)),
1286cf7f2e2dSJohn Marino value_as_address (msg_send_stret));
12875796c8dcSSimon Schubert else
1288cf7f2e2dSJohn Marino called_method
1289cf7f2e2dSJohn Marino = value_from_pointer (lookup_pointer_type (value_type (method)),
1290cf7f2e2dSJohn Marino value_as_address (msg_send));
12915796c8dcSSimon Schubert }
12925796c8dcSSimon Schubert else
12935796c8dcSSimon Schubert {
12945796c8dcSSimon Schubert if (struct_return)
12955796c8dcSSimon Schubert called_method = msg_send_stret;
12965796c8dcSSimon Schubert else
12975796c8dcSSimon Schubert called_method = msg_send;
12985796c8dcSSimon Schubert }
12995796c8dcSSimon Schubert
13005796c8dcSSimon Schubert if (noside == EVAL_SKIP)
13015796c8dcSSimon Schubert goto nosideret;
13025796c8dcSSimon Schubert
13035796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
13045796c8dcSSimon Schubert {
13055796c8dcSSimon Schubert /* If the return type doesn't look like a function type,
13065796c8dcSSimon Schubert call an error. This can happen if somebody tries to
13075796c8dcSSimon Schubert turn a variable into a function call. This is here
13085796c8dcSSimon Schubert because people often want to call, eg, strcmp, which
13095796c8dcSSimon Schubert gdb doesn't know is a function. If gdb isn't asked for
13105796c8dcSSimon Schubert it's opinion (ie. through "whatis"), it won't offer
13115796c8dcSSimon Schubert it. */
13125796c8dcSSimon Schubert
13135796c8dcSSimon Schubert struct type *type = value_type (called_method);
1314cf7f2e2dSJohn Marino
13155796c8dcSSimon Schubert if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
13165796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
13175796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
13185796c8dcSSimon Schubert
13195796c8dcSSimon Schubert if (type)
13205796c8dcSSimon Schubert {
13215796c8dcSSimon Schubert if ((TYPE_CODE (type) == TYPE_CODE_ERROR) && expect_type)
13225796c8dcSSimon Schubert return allocate_value (expect_type);
13235796c8dcSSimon Schubert else
13245796c8dcSSimon Schubert return allocate_value (type);
13255796c8dcSSimon Schubert }
13265796c8dcSSimon Schubert else
1327c50c785cSJohn Marino error (_("Expression of type other than "
1328c50c785cSJohn Marino "\"method returning ...\" used as a method"));
13295796c8dcSSimon Schubert }
13305796c8dcSSimon Schubert
13315796c8dcSSimon Schubert /* Now depending on whether we found a symbol for the method,
13325796c8dcSSimon Schubert we will either call the runtime dispatcher or the method
13335796c8dcSSimon Schubert directly. */
13345796c8dcSSimon Schubert
13355796c8dcSSimon Schubert argvec[0] = called_method;
13365796c8dcSSimon Schubert argvec[1] = target;
13375796c8dcSSimon Schubert argvec[2] = value_from_longest (long_type, selector);
13385796c8dcSSimon Schubert /* User-supplied arguments. */
13395796c8dcSSimon Schubert for (tem = 0; tem < nargs; tem++)
13405796c8dcSSimon Schubert argvec[tem + 3] = evaluate_subexp_with_coercion (exp, pos, noside);
13415796c8dcSSimon Schubert argvec[tem + 3] = 0;
13425796c8dcSSimon Schubert
13435796c8dcSSimon Schubert if (gnu_runtime && (method != NULL))
13445796c8dcSSimon Schubert {
13455796c8dcSSimon Schubert /* Function objc_msg_lookup returns a pointer. */
13465796c8dcSSimon Schubert deprecated_set_value_type (argvec[0],
1347cf7f2e2dSJohn Marino lookup_pointer_type (lookup_function_type (value_type (argvec[0]))));
1348c50c785cSJohn Marino argvec[0]
1349c50c785cSJohn Marino = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
13505796c8dcSSimon Schubert }
13515796c8dcSSimon Schubert
13525796c8dcSSimon Schubert ret = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
13535796c8dcSSimon Schubert return ret;
13545796c8dcSSimon Schubert }
13555796c8dcSSimon Schubert break;
13565796c8dcSSimon Schubert
13575796c8dcSSimon Schubert case OP_FUNCALL:
13585796c8dcSSimon Schubert (*pos) += 2;
13595796c8dcSSimon Schubert op = exp->elts[*pos].opcode;
13605796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst);
13615796c8dcSSimon Schubert /* Allocate arg vector, including space for the function to be
1362c50c785cSJohn Marino called in argvec[0] and a terminating NULL. */
1363c50c785cSJohn Marino argvec = (struct value **)
1364c50c785cSJohn Marino alloca (sizeof (struct value *) * (nargs + 3));
13655796c8dcSSimon Schubert if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
13665796c8dcSSimon Schubert {
1367c50c785cSJohn Marino /* First, evaluate the structure into arg2. */
13685796c8dcSSimon Schubert pc2 = (*pos)++;
13695796c8dcSSimon Schubert
13705796c8dcSSimon Schubert if (noside == EVAL_SKIP)
13715796c8dcSSimon Schubert goto nosideret;
13725796c8dcSSimon Schubert
13735796c8dcSSimon Schubert if (op == STRUCTOP_MEMBER)
13745796c8dcSSimon Schubert {
13755796c8dcSSimon Schubert arg2 = evaluate_subexp_for_address (exp, pos, noside);
13765796c8dcSSimon Schubert }
13775796c8dcSSimon Schubert else
13785796c8dcSSimon Schubert {
13795796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
13805796c8dcSSimon Schubert }
13815796c8dcSSimon Schubert
13825796c8dcSSimon Schubert /* If the function is a virtual function, then the
13835796c8dcSSimon Schubert aggregate value (providing the structure) plays
13845796c8dcSSimon Schubert its part by providing the vtable. Otherwise,
13855796c8dcSSimon Schubert it is just along for the ride: call the function
13865796c8dcSSimon Schubert directly. */
13875796c8dcSSimon Schubert
13885796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
13895796c8dcSSimon Schubert
1390*ef5ccd6cSJohn Marino type = check_typedef (value_type (arg1));
1391*ef5ccd6cSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_METHODPTR)
13925796c8dcSSimon Schubert {
1393*ef5ccd6cSJohn Marino if (noside == EVAL_AVOID_SIDE_EFFECTS)
1394*ef5ccd6cSJohn Marino arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
13955796c8dcSSimon Schubert else
13965796c8dcSSimon Schubert arg1 = cplus_method_ptr_to_value (&arg2, arg1);
13975796c8dcSSimon Schubert
1398c50c785cSJohn Marino /* Now, say which argument to start evaluating from. */
1399*ef5ccd6cSJohn Marino nargs++;
14005796c8dcSSimon Schubert tem = 2;
1401*ef5ccd6cSJohn Marino argvec[1] = arg2;
1402*ef5ccd6cSJohn Marino }
1403*ef5ccd6cSJohn Marino else if (TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
1404*ef5ccd6cSJohn Marino {
1405*ef5ccd6cSJohn Marino struct type *type_ptr
1406*ef5ccd6cSJohn Marino = lookup_pointer_type (TYPE_DOMAIN_TYPE (type));
1407*ef5ccd6cSJohn Marino struct type *target_type_ptr
1408*ef5ccd6cSJohn Marino = lookup_pointer_type (TYPE_TARGET_TYPE (type));
1409*ef5ccd6cSJohn Marino
1410*ef5ccd6cSJohn Marino /* Now, convert these values to an address. */
1411*ef5ccd6cSJohn Marino arg2 = value_cast (type_ptr, arg2);
1412*ef5ccd6cSJohn Marino
1413*ef5ccd6cSJohn Marino mem_offset = value_as_long (arg1);
1414*ef5ccd6cSJohn Marino
1415*ef5ccd6cSJohn Marino arg1 = value_from_pointer (target_type_ptr,
1416*ef5ccd6cSJohn Marino value_as_long (arg2) + mem_offset);
1417*ef5ccd6cSJohn Marino arg1 = value_ind (arg1);
1418*ef5ccd6cSJohn Marino tem = 1;
1419*ef5ccd6cSJohn Marino }
1420*ef5ccd6cSJohn Marino else
1421*ef5ccd6cSJohn Marino error (_("Non-pointer-to-member value used in pointer-to-member "
1422*ef5ccd6cSJohn Marino "construct"));
14235796c8dcSSimon Schubert }
14245796c8dcSSimon Schubert else if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR)
14255796c8dcSSimon Schubert {
1426c50c785cSJohn Marino /* Hair for method invocations. */
14275796c8dcSSimon Schubert int tem2;
14285796c8dcSSimon Schubert
14295796c8dcSSimon Schubert nargs++;
1430c50c785cSJohn Marino /* First, evaluate the structure into arg2. */
14315796c8dcSSimon Schubert pc2 = (*pos)++;
14325796c8dcSSimon Schubert tem2 = longest_to_int (exp->elts[pc2 + 1].longconst);
14335796c8dcSSimon Schubert *pos += 3 + BYTES_TO_EXP_ELEM (tem2 + 1);
14345796c8dcSSimon Schubert if (noside == EVAL_SKIP)
14355796c8dcSSimon Schubert goto nosideret;
14365796c8dcSSimon Schubert
14375796c8dcSSimon Schubert if (op == STRUCTOP_STRUCT)
14385796c8dcSSimon Schubert {
14395796c8dcSSimon Schubert /* If v is a variable in a register, and the user types
14405796c8dcSSimon Schubert v.method (), this will produce an error, because v has
14415796c8dcSSimon Schubert no address.
14425796c8dcSSimon Schubert
14435796c8dcSSimon Schubert A possible way around this would be to allocate a
14445796c8dcSSimon Schubert copy of the variable on the stack, copy in the
14455796c8dcSSimon Schubert contents, call the function, and copy out the
14465796c8dcSSimon Schubert contents. I.e. convert this from call by reference
14475796c8dcSSimon Schubert to call by copy-return (or whatever it's called).
14485796c8dcSSimon Schubert However, this does not work because it is not the
14495796c8dcSSimon Schubert same: the method being called could stash a copy of
14505796c8dcSSimon Schubert the address, and then future uses through that address
14515796c8dcSSimon Schubert (after the method returns) would be expected to
14525796c8dcSSimon Schubert use the variable itself, not some copy of it. */
14535796c8dcSSimon Schubert arg2 = evaluate_subexp_for_address (exp, pos, noside);
14545796c8dcSSimon Schubert }
14555796c8dcSSimon Schubert else
14565796c8dcSSimon Schubert {
14575796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
1458c50c785cSJohn Marino
1459c50c785cSJohn Marino /* Check to see if the operator '->' has been
1460c50c785cSJohn Marino overloaded. If the operator has been overloaded
1461c50c785cSJohn Marino replace arg2 with the value returned by the custom
1462c50c785cSJohn Marino operator and continue evaluation. */
1463c50c785cSJohn Marino while (unop_user_defined_p (op, arg2))
1464c50c785cSJohn Marino {
1465c50c785cSJohn Marino volatile struct gdb_exception except;
1466c50c785cSJohn Marino struct value *value = NULL;
1467c50c785cSJohn Marino TRY_CATCH (except, RETURN_MASK_ERROR)
1468c50c785cSJohn Marino {
1469c50c785cSJohn Marino value = value_x_unop (arg2, op, noside);
14705796c8dcSSimon Schubert }
1471c50c785cSJohn Marino
1472c50c785cSJohn Marino if (except.reason < 0)
1473c50c785cSJohn Marino {
1474c50c785cSJohn Marino if (except.error == NOT_FOUND_ERROR)
1475c50c785cSJohn Marino break;
1476c50c785cSJohn Marino else
1477c50c785cSJohn Marino throw_exception (except);
1478c50c785cSJohn Marino }
1479c50c785cSJohn Marino arg2 = value;
1480c50c785cSJohn Marino }
1481c50c785cSJohn Marino }
1482c50c785cSJohn Marino /* Now, say which argument to start evaluating from. */
14835796c8dcSSimon Schubert tem = 2;
14845796c8dcSSimon Schubert }
1485cf7f2e2dSJohn Marino else if (op == OP_SCOPE
1486cf7f2e2dSJohn Marino && overload_resolution
1487cf7f2e2dSJohn Marino && (exp->language_defn->la_language == language_cplus))
1488cf7f2e2dSJohn Marino {
1489cf7f2e2dSJohn Marino /* Unpack it locally so we can properly handle overload
1490cf7f2e2dSJohn Marino resolution. */
1491cf7f2e2dSJohn Marino char *name;
1492cf7f2e2dSJohn Marino int local_tem;
1493cf7f2e2dSJohn Marino
1494cf7f2e2dSJohn Marino pc2 = (*pos)++;
1495cf7f2e2dSJohn Marino local_tem = longest_to_int (exp->elts[pc2 + 2].longconst);
1496cf7f2e2dSJohn Marino (*pos) += 4 + BYTES_TO_EXP_ELEM (local_tem + 1);
1497cf7f2e2dSJohn Marino type = exp->elts[pc2 + 1].type;
1498cf7f2e2dSJohn Marino name = &exp->elts[pc2 + 3].string;
1499cf7f2e2dSJohn Marino
1500cf7f2e2dSJohn Marino function = NULL;
1501cf7f2e2dSJohn Marino function_name = NULL;
1502cf7f2e2dSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
1503cf7f2e2dSJohn Marino {
1504cf7f2e2dSJohn Marino function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type),
1505cf7f2e2dSJohn Marino name,
1506cf7f2e2dSJohn Marino get_selected_block (0),
1507cf7f2e2dSJohn Marino VAR_DOMAIN);
1508cf7f2e2dSJohn Marino if (function == NULL)
1509cf7f2e2dSJohn Marino error (_("No symbol \"%s\" in namespace \"%s\"."),
1510cf7f2e2dSJohn Marino name, TYPE_TAG_NAME (type));
1511cf7f2e2dSJohn Marino
1512cf7f2e2dSJohn Marino tem = 1;
1513cf7f2e2dSJohn Marino }
1514cf7f2e2dSJohn Marino else
1515cf7f2e2dSJohn Marino {
1516cf7f2e2dSJohn Marino gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
1517cf7f2e2dSJohn Marino || TYPE_CODE (type) == TYPE_CODE_UNION);
1518cf7f2e2dSJohn Marino function_name = name;
1519cf7f2e2dSJohn Marino
1520cf7f2e2dSJohn Marino arg2 = value_zero (type, lval_memory);
1521cf7f2e2dSJohn Marino ++nargs;
1522cf7f2e2dSJohn Marino tem = 2;
1523cf7f2e2dSJohn Marino }
1524cf7f2e2dSJohn Marino }
1525cf7f2e2dSJohn Marino else if (op == OP_ADL_FUNC)
1526cf7f2e2dSJohn Marino {
1527cf7f2e2dSJohn Marino /* Save the function position and move pos so that the arguments
1528cf7f2e2dSJohn Marino can be evaluated. */
1529cf7f2e2dSJohn Marino int func_name_len;
1530cf7f2e2dSJohn Marino
1531cf7f2e2dSJohn Marino save_pos1 = *pos;
1532cf7f2e2dSJohn Marino tem = 1;
1533cf7f2e2dSJohn Marino
1534cf7f2e2dSJohn Marino func_name_len = longest_to_int (exp->elts[save_pos1 + 3].longconst);
1535cf7f2e2dSJohn Marino (*pos) += 6 + BYTES_TO_EXP_ELEM (func_name_len + 1);
1536cf7f2e2dSJohn Marino }
15375796c8dcSSimon Schubert else
15385796c8dcSSimon Schubert {
1539c50c785cSJohn Marino /* Non-method function call. */
15405796c8dcSSimon Schubert save_pos1 = *pos;
15415796c8dcSSimon Schubert tem = 1;
1542c50c785cSJohn Marino
1543c50c785cSJohn Marino /* If this is a C++ function wait until overload resolution. */
1544c50c785cSJohn Marino if (op == OP_VAR_VALUE
1545c50c785cSJohn Marino && overload_resolution
1546c50c785cSJohn Marino && (exp->language_defn->la_language == language_cplus))
1547c50c785cSJohn Marino {
1548c50c785cSJohn Marino (*pos) += 4; /* Skip the evaluation of the symbol. */
1549c50c785cSJohn Marino argvec[0] = NULL;
1550c50c785cSJohn Marino }
1551c50c785cSJohn Marino else
1552c50c785cSJohn Marino {
1553c50c785cSJohn Marino argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
15545796c8dcSSimon Schubert type = value_type (argvec[0]);
15555796c8dcSSimon Schubert if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
15565796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
15575796c8dcSSimon Schubert if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
15585796c8dcSSimon Schubert {
15595796c8dcSSimon Schubert for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
15605796c8dcSSimon Schubert {
1561c50c785cSJohn Marino argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type,
1562c50c785cSJohn Marino tem - 1),
15635796c8dcSSimon Schubert exp, pos, noside);
15645796c8dcSSimon Schubert }
15655796c8dcSSimon Schubert }
15665796c8dcSSimon Schubert }
1567c50c785cSJohn Marino }
15685796c8dcSSimon Schubert
1569c50c785cSJohn Marino /* Evaluate arguments. */
15705796c8dcSSimon Schubert for (; tem <= nargs; tem++)
15715796c8dcSSimon Schubert {
1572c50c785cSJohn Marino /* Ensure that array expressions are coerced into pointer
1573c50c785cSJohn Marino objects. */
15745796c8dcSSimon Schubert argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
15755796c8dcSSimon Schubert }
15765796c8dcSSimon Schubert
1577c50c785cSJohn Marino /* Signal end of arglist. */
15785796c8dcSSimon Schubert argvec[tem] = 0;
1579cf7f2e2dSJohn Marino if (op == OP_ADL_FUNC)
1580cf7f2e2dSJohn Marino {
1581cf7f2e2dSJohn Marino struct symbol *symp;
1582cf7f2e2dSJohn Marino char *func_name;
1583cf7f2e2dSJohn Marino int name_len;
1584cf7f2e2dSJohn Marino int string_pc = save_pos1 + 3;
15855796c8dcSSimon Schubert
1586cf7f2e2dSJohn Marino /* Extract the function name. */
1587cf7f2e2dSJohn Marino name_len = longest_to_int (exp->elts[string_pc].longconst);
1588cf7f2e2dSJohn Marino func_name = (char *) alloca (name_len + 1);
1589cf7f2e2dSJohn Marino strcpy (func_name, &exp->elts[string_pc + 1].string);
1590cf7f2e2dSJohn Marino
1591a45ae5f8SJohn Marino find_overload_match (&argvec[1], nargs, func_name,
1592c50c785cSJohn Marino NON_METHOD, /* not method */
1593c50c785cSJohn Marino NULL, NULL, /* pass NULL symbol since
1594c50c785cSJohn Marino symbol is unknown */
1595cf7f2e2dSJohn Marino NULL, &symp, NULL, 0);
1596cf7f2e2dSJohn Marino
1597cf7f2e2dSJohn Marino /* Now fix the expression being evaluated. */
1598cf7f2e2dSJohn Marino exp->elts[save_pos1 + 2].symbol = symp;
1599cf7f2e2dSJohn Marino argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1, noside);
1600cf7f2e2dSJohn Marino }
1601cf7f2e2dSJohn Marino
1602cf7f2e2dSJohn Marino if (op == STRUCTOP_STRUCT || op == STRUCTOP_PTR
1603cf7f2e2dSJohn Marino || (op == OP_SCOPE && function_name != NULL))
16045796c8dcSSimon Schubert {
16055796c8dcSSimon Schubert int static_memfuncp;
1606cf7f2e2dSJohn Marino char *tstr;
16075796c8dcSSimon Schubert
1608c50c785cSJohn Marino /* Method invocation : stuff "this" as first parameter. */
16095796c8dcSSimon Schubert argvec[1] = arg2;
1610cf7f2e2dSJohn Marino
1611cf7f2e2dSJohn Marino if (op != OP_SCOPE)
1612cf7f2e2dSJohn Marino {
1613c50c785cSJohn Marino /* Name of method from expression. */
1614cf7f2e2dSJohn Marino tstr = &exp->elts[pc2 + 2].string;
1615cf7f2e2dSJohn Marino }
1616cf7f2e2dSJohn Marino else
1617cf7f2e2dSJohn Marino tstr = function_name;
16185796c8dcSSimon Schubert
1619c50c785cSJohn Marino if (overload_resolution && (exp->language_defn->la_language
1620c50c785cSJohn Marino == language_cplus))
16215796c8dcSSimon Schubert {
1622c50c785cSJohn Marino /* Language is C++, do some overload resolution before
1623c50c785cSJohn Marino evaluation. */
16245796c8dcSSimon Schubert struct value *valp = NULL;
16255796c8dcSSimon Schubert
1626a45ae5f8SJohn Marino (void) find_overload_match (&argvec[1], nargs, tstr,
1627c50c785cSJohn Marino METHOD, /* method */
1628c50c785cSJohn Marino &arg2, /* the object */
1629c50c785cSJohn Marino NULL, &valp, NULL,
1630c50c785cSJohn Marino &static_memfuncp, 0);
16315796c8dcSSimon Schubert
1632cf7f2e2dSJohn Marino if (op == OP_SCOPE && !static_memfuncp)
1633cf7f2e2dSJohn Marino {
1634cf7f2e2dSJohn Marino /* For the time being, we don't handle this. */
1635cf7f2e2dSJohn Marino error (_("Call to overloaded function %s requires "
1636cf7f2e2dSJohn Marino "`this' pointer"),
1637cf7f2e2dSJohn Marino function_name);
1638cf7f2e2dSJohn Marino }
16395796c8dcSSimon Schubert argvec[1] = arg2; /* the ``this'' pointer */
1640c50c785cSJohn Marino argvec[0] = valp; /* Use the method found after overload
1641c50c785cSJohn Marino resolution. */
16425796c8dcSSimon Schubert }
16435796c8dcSSimon Schubert else
1644c50c785cSJohn Marino /* Non-C++ case -- or no overload resolution. */
16455796c8dcSSimon Schubert {
16465796c8dcSSimon Schubert struct value *temp = arg2;
1647cf7f2e2dSJohn Marino
16485796c8dcSSimon Schubert argvec[0] = value_struct_elt (&temp, argvec + 1, tstr,
16495796c8dcSSimon Schubert &static_memfuncp,
16505796c8dcSSimon Schubert op == STRUCTOP_STRUCT
16515796c8dcSSimon Schubert ? "structure" : "structure pointer");
16525796c8dcSSimon Schubert /* value_struct_elt updates temp with the correct value
16535796c8dcSSimon Schubert of the ``this'' pointer if necessary, so modify argvec[1] to
16545796c8dcSSimon Schubert reflect any ``this'' changes. */
1655c50c785cSJohn Marino arg2
1656c50c785cSJohn Marino = value_from_longest (lookup_pointer_type(value_type (temp)),
16575796c8dcSSimon Schubert value_address (temp)
16585796c8dcSSimon Schubert + value_embedded_offset (temp));
16595796c8dcSSimon Schubert argvec[1] = arg2; /* the ``this'' pointer */
16605796c8dcSSimon Schubert }
16615796c8dcSSimon Schubert
16625796c8dcSSimon Schubert if (static_memfuncp)
16635796c8dcSSimon Schubert {
16645796c8dcSSimon Schubert argvec[1] = argvec[0];
16655796c8dcSSimon Schubert nargs--;
16665796c8dcSSimon Schubert argvec++;
16675796c8dcSSimon Schubert }
16685796c8dcSSimon Schubert }
16695796c8dcSSimon Schubert else if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
16705796c8dcSSimon Schubert {
1671*ef5ccd6cSJohn Marino /* Pointer to member. argvec[1] is already set up. */
16725796c8dcSSimon Schubert argvec[0] = arg1;
16735796c8dcSSimon Schubert }
1674cf7f2e2dSJohn Marino else if (op == OP_VAR_VALUE || (op == OP_SCOPE && function != NULL))
16755796c8dcSSimon Schubert {
1676c50c785cSJohn Marino /* Non-member function being called. */
16775796c8dcSSimon Schubert /* fn: This can only be done for C++ functions. A C-style function
16785796c8dcSSimon Schubert in a C++ program, for instance, does not have the fields that
1679c50c785cSJohn Marino are expected here. */
16805796c8dcSSimon Schubert
1681c50c785cSJohn Marino if (overload_resolution && (exp->language_defn->la_language
1682c50c785cSJohn Marino == language_cplus))
16835796c8dcSSimon Schubert {
1684c50c785cSJohn Marino /* Language is C++, do some overload resolution before
1685c50c785cSJohn Marino evaluation. */
16865796c8dcSSimon Schubert struct symbol *symp;
1687cf7f2e2dSJohn Marino int no_adl = 0;
1688cf7f2e2dSJohn Marino
1689cf7f2e2dSJohn Marino /* If a scope has been specified disable ADL. */
1690cf7f2e2dSJohn Marino if (op == OP_SCOPE)
1691cf7f2e2dSJohn Marino no_adl = 1;
1692cf7f2e2dSJohn Marino
1693cf7f2e2dSJohn Marino if (op == OP_VAR_VALUE)
1694cf7f2e2dSJohn Marino function = exp->elts[save_pos1+2].symbol;
16955796c8dcSSimon Schubert
1696a45ae5f8SJohn Marino (void) find_overload_match (&argvec[1], nargs,
1697c50c785cSJohn Marino NULL, /* no need for name */
1698c50c785cSJohn Marino NON_METHOD, /* not method */
1699c50c785cSJohn Marino NULL, function, /* the function */
1700cf7f2e2dSJohn Marino NULL, &symp, NULL, no_adl);
17015796c8dcSSimon Schubert
1702cf7f2e2dSJohn Marino if (op == OP_VAR_VALUE)
1703cf7f2e2dSJohn Marino {
1704c50c785cSJohn Marino /* Now fix the expression being evaluated. */
17055796c8dcSSimon Schubert exp->elts[save_pos1+2].symbol = symp;
1706cf7f2e2dSJohn Marino argvec[0] = evaluate_subexp_with_coercion (exp, &save_pos1,
1707cf7f2e2dSJohn Marino noside);
1708cf7f2e2dSJohn Marino }
1709cf7f2e2dSJohn Marino else
1710cf7f2e2dSJohn Marino argvec[0] = value_of_variable (symp, get_selected_block (0));
17115796c8dcSSimon Schubert }
17125796c8dcSSimon Schubert else
17135796c8dcSSimon Schubert {
1714c50c785cSJohn Marino /* Not C++, or no overload resolution allowed. */
1715c50c785cSJohn Marino /* Nothing to be done; argvec already correctly set up. */
17165796c8dcSSimon Schubert }
17175796c8dcSSimon Schubert }
17185796c8dcSSimon Schubert else
17195796c8dcSSimon Schubert {
1720c50c785cSJohn Marino /* It is probably a C-style function. */
1721c50c785cSJohn Marino /* Nothing to be done; argvec already correctly set up. */
17225796c8dcSSimon Schubert }
17235796c8dcSSimon Schubert
17245796c8dcSSimon Schubert do_call_it:
17255796c8dcSSimon Schubert
17265796c8dcSSimon Schubert if (noside == EVAL_SKIP)
17275796c8dcSSimon Schubert goto nosideret;
17285796c8dcSSimon Schubert if (argvec[0] == NULL)
17295796c8dcSSimon Schubert error (_("Cannot evaluate function -- may be inlined"));
17305796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
17315796c8dcSSimon Schubert {
17325796c8dcSSimon Schubert /* If the return type doesn't look like a function type, call an
17335796c8dcSSimon Schubert error. This can happen if somebody tries to turn a variable into
17345796c8dcSSimon Schubert a function call. This is here because people often want to
17355796c8dcSSimon Schubert call, eg, strcmp, which gdb doesn't know is a function. If
17365796c8dcSSimon Schubert gdb isn't asked for it's opinion (ie. through "whatis"),
17375796c8dcSSimon Schubert it won't offer it. */
17385796c8dcSSimon Schubert
17395796c8dcSSimon Schubert struct type *ftype = value_type (argvec[0]);
17405796c8dcSSimon Schubert
17415796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_INTERNAL_FUNCTION)
17425796c8dcSSimon Schubert {
17435796c8dcSSimon Schubert /* We don't know anything about what the internal
17445796c8dcSSimon Schubert function might return, but we have to return
17455796c8dcSSimon Schubert something. */
17465796c8dcSSimon Schubert return value_zero (builtin_type (exp->gdbarch)->builtin_int,
17475796c8dcSSimon Schubert not_lval);
17485796c8dcSSimon Schubert }
1749c50c785cSJohn Marino else if (TYPE_GNU_IFUNC (ftype))
1750c50c785cSJohn Marino return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype)));
17515796c8dcSSimon Schubert else if (TYPE_TARGET_TYPE (ftype))
17525796c8dcSSimon Schubert return allocate_value (TYPE_TARGET_TYPE (ftype));
17535796c8dcSSimon Schubert else
1754c50c785cSJohn Marino error (_("Expression of type other than "
1755c50c785cSJohn Marino "\"Function returning ...\" used as function"));
17565796c8dcSSimon Schubert }
17575796c8dcSSimon Schubert if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_INTERNAL_FUNCTION)
17585796c8dcSSimon Schubert return call_internal_function (exp->gdbarch, exp->language_defn,
17595796c8dcSSimon Schubert argvec[0], nargs, argvec + 1);
17605796c8dcSSimon Schubert
17615796c8dcSSimon Schubert return call_function_by_hand (argvec[0], nargs, argvec + 1);
1762c50c785cSJohn Marino /* pai: FIXME save value from call_function_by_hand, then adjust
1763c50c785cSJohn Marino pc by adjust_fn_pc if +ve. */
17645796c8dcSSimon Schubert
17655796c8dcSSimon Schubert case OP_F77_UNDETERMINED_ARGLIST:
17665796c8dcSSimon Schubert
17675796c8dcSSimon Schubert /* Remember that in F77, functions, substring ops and
17685796c8dcSSimon Schubert array subscript operations cannot be disambiguated
17695796c8dcSSimon Schubert at parse time. We have made all array subscript operations,
17705796c8dcSSimon Schubert substring operations as well as function calls come here
17715796c8dcSSimon Schubert and we now have to discover what the heck this thing actually was.
17725796c8dcSSimon Schubert If it is a function, we process just as if we got an OP_FUNCALL. */
17735796c8dcSSimon Schubert
17745796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst);
17755796c8dcSSimon Schubert (*pos) += 2;
17765796c8dcSSimon Schubert
17775796c8dcSSimon Schubert /* First determine the type code we are dealing with. */
17785796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
17795796c8dcSSimon Schubert type = check_typedef (value_type (arg1));
17805796c8dcSSimon Schubert code = TYPE_CODE (type);
17815796c8dcSSimon Schubert
17825796c8dcSSimon Schubert if (code == TYPE_CODE_PTR)
17835796c8dcSSimon Schubert {
17845796c8dcSSimon Schubert /* Fortran always passes variable to subroutines as pointer.
17855796c8dcSSimon Schubert So we need to look into its target type to see if it is
17865796c8dcSSimon Schubert array, string or function. If it is, we need to switch
17875796c8dcSSimon Schubert to the target value the original one points to. */
17885796c8dcSSimon Schubert struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
17895796c8dcSSimon Schubert
17905796c8dcSSimon Schubert if (TYPE_CODE (target_type) == TYPE_CODE_ARRAY
17915796c8dcSSimon Schubert || TYPE_CODE (target_type) == TYPE_CODE_STRING
17925796c8dcSSimon Schubert || TYPE_CODE (target_type) == TYPE_CODE_FUNC)
17935796c8dcSSimon Schubert {
17945796c8dcSSimon Schubert arg1 = value_ind (arg1);
17955796c8dcSSimon Schubert type = check_typedef (value_type (arg1));
17965796c8dcSSimon Schubert code = TYPE_CODE (type);
17975796c8dcSSimon Schubert }
17985796c8dcSSimon Schubert }
17995796c8dcSSimon Schubert
18005796c8dcSSimon Schubert switch (code)
18015796c8dcSSimon Schubert {
18025796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
18035796c8dcSSimon Schubert if (exp->elts[*pos].opcode == OP_F90_RANGE)
18045796c8dcSSimon Schubert return value_f90_subarray (arg1, exp, pos, noside);
18055796c8dcSSimon Schubert else
18065796c8dcSSimon Schubert goto multi_f77_subscript;
18075796c8dcSSimon Schubert
18085796c8dcSSimon Schubert case TYPE_CODE_STRING:
18095796c8dcSSimon Schubert if (exp->elts[*pos].opcode == OP_F90_RANGE)
18105796c8dcSSimon Schubert return value_f90_subarray (arg1, exp, pos, noside);
18115796c8dcSSimon Schubert else
18125796c8dcSSimon Schubert {
18135796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
18145796c8dcSSimon Schubert return value_subscript (arg1, value_as_long (arg2));
18155796c8dcSSimon Schubert }
18165796c8dcSSimon Schubert
18175796c8dcSSimon Schubert case TYPE_CODE_PTR:
18185796c8dcSSimon Schubert case TYPE_CODE_FUNC:
18195796c8dcSSimon Schubert /* It's a function call. */
18205796c8dcSSimon Schubert /* Allocate arg vector, including space for the function to be
1821c50c785cSJohn Marino called in argvec[0] and a terminating NULL. */
1822c50c785cSJohn Marino argvec = (struct value **)
1823c50c785cSJohn Marino alloca (sizeof (struct value *) * (nargs + 2));
18245796c8dcSSimon Schubert argvec[0] = arg1;
18255796c8dcSSimon Schubert tem = 1;
18265796c8dcSSimon Schubert for (; tem <= nargs; tem++)
18275796c8dcSSimon Schubert argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
18285796c8dcSSimon Schubert argvec[tem] = 0; /* signal end of arglist */
18295796c8dcSSimon Schubert goto do_call_it;
18305796c8dcSSimon Schubert
18315796c8dcSSimon Schubert default:
18325796c8dcSSimon Schubert error (_("Cannot perform substring on this type"));
18335796c8dcSSimon Schubert }
18345796c8dcSSimon Schubert
18355796c8dcSSimon Schubert case OP_COMPLEX:
18365796c8dcSSimon Schubert /* We have a complex number, There should be 2 floating
1837c50c785cSJohn Marino point numbers that compose it. */
18385796c8dcSSimon Schubert (*pos) += 2;
18395796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
18405796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
18415796c8dcSSimon Schubert
18425796c8dcSSimon Schubert return value_literal_complex (arg1, arg2, exp->elts[pc + 1].type);
18435796c8dcSSimon Schubert
18445796c8dcSSimon Schubert case STRUCTOP_STRUCT:
18455796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst);
18465796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
18475796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
18485796c8dcSSimon Schubert if (noside == EVAL_SKIP)
18495796c8dcSSimon Schubert goto nosideret;
18505796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
18515796c8dcSSimon Schubert return value_zero (lookup_struct_elt_type (value_type (arg1),
18525796c8dcSSimon Schubert &exp->elts[pc + 2].string,
18535796c8dcSSimon Schubert 0),
18545796c8dcSSimon Schubert lval_memory);
18555796c8dcSSimon Schubert else
18565796c8dcSSimon Schubert {
18575796c8dcSSimon Schubert struct value *temp = arg1;
1858cf7f2e2dSJohn Marino
18595796c8dcSSimon Schubert return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
18605796c8dcSSimon Schubert NULL, "structure");
18615796c8dcSSimon Schubert }
18625796c8dcSSimon Schubert
18635796c8dcSSimon Schubert case STRUCTOP_PTR:
18645796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 1].longconst);
18655796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
18665796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
18675796c8dcSSimon Schubert if (noside == EVAL_SKIP)
18685796c8dcSSimon Schubert goto nosideret;
18695796c8dcSSimon Schubert
1870c50c785cSJohn Marino /* Check to see if operator '->' has been overloaded. If so replace
1871c50c785cSJohn Marino arg1 with the value returned by evaluating operator->(). */
1872c50c785cSJohn Marino while (unop_user_defined_p (op, arg1))
1873c50c785cSJohn Marino {
1874c50c785cSJohn Marino volatile struct gdb_exception except;
1875c50c785cSJohn Marino struct value *value = NULL;
1876c50c785cSJohn Marino TRY_CATCH (except, RETURN_MASK_ERROR)
1877c50c785cSJohn Marino {
1878c50c785cSJohn Marino value = value_x_unop (arg1, op, noside);
1879c50c785cSJohn Marino }
1880c50c785cSJohn Marino
1881c50c785cSJohn Marino if (except.reason < 0)
1882c50c785cSJohn Marino {
1883c50c785cSJohn Marino if (except.error == NOT_FOUND_ERROR)
1884c50c785cSJohn Marino break;
1885c50c785cSJohn Marino else
1886c50c785cSJohn Marino throw_exception (except);
1887c50c785cSJohn Marino }
1888c50c785cSJohn Marino arg1 = value;
1889c50c785cSJohn Marino }
1890c50c785cSJohn Marino
18915796c8dcSSimon Schubert /* JYG: if print object is on we need to replace the base type
18925796c8dcSSimon Schubert with rtti type in order to continue on with successful
18935796c8dcSSimon Schubert lookup of member / method only available in the rtti type. */
18945796c8dcSSimon Schubert {
18955796c8dcSSimon Schubert struct type *type = value_type (arg1);
18965796c8dcSSimon Schubert struct type *real_type;
18975796c8dcSSimon Schubert int full, top, using_enc;
18985796c8dcSSimon Schubert struct value_print_options opts;
18995796c8dcSSimon Schubert
19005796c8dcSSimon Schubert get_user_print_options (&opts);
1901cf7f2e2dSJohn Marino if (opts.objectprint && TYPE_TARGET_TYPE(type)
1902cf7f2e2dSJohn Marino && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
19035796c8dcSSimon Schubert {
1904*ef5ccd6cSJohn Marino real_type = value_rtti_indirect_type (arg1, &full, &top,
1905*ef5ccd6cSJohn Marino &using_enc);
19065796c8dcSSimon Schubert if (real_type)
19075796c8dcSSimon Schubert arg1 = value_cast (real_type, arg1);
19085796c8dcSSimon Schubert }
19095796c8dcSSimon Schubert }
19105796c8dcSSimon Schubert
19115796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
19125796c8dcSSimon Schubert return value_zero (lookup_struct_elt_type (value_type (arg1),
19135796c8dcSSimon Schubert &exp->elts[pc + 2].string,
19145796c8dcSSimon Schubert 0),
19155796c8dcSSimon Schubert lval_memory);
19165796c8dcSSimon Schubert else
19175796c8dcSSimon Schubert {
19185796c8dcSSimon Schubert struct value *temp = arg1;
1919cf7f2e2dSJohn Marino
19205796c8dcSSimon Schubert return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
19215796c8dcSSimon Schubert NULL, "structure pointer");
19225796c8dcSSimon Schubert }
19235796c8dcSSimon Schubert
19245796c8dcSSimon Schubert case STRUCTOP_MEMBER:
19255796c8dcSSimon Schubert case STRUCTOP_MPTR:
19265796c8dcSSimon Schubert if (op == STRUCTOP_MEMBER)
19275796c8dcSSimon Schubert arg1 = evaluate_subexp_for_address (exp, pos, noside);
19285796c8dcSSimon Schubert else
19295796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
19305796c8dcSSimon Schubert
19315796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
19325796c8dcSSimon Schubert
19335796c8dcSSimon Schubert if (noside == EVAL_SKIP)
19345796c8dcSSimon Schubert goto nosideret;
19355796c8dcSSimon Schubert
19365796c8dcSSimon Schubert type = check_typedef (value_type (arg2));
19375796c8dcSSimon Schubert switch (TYPE_CODE (type))
19385796c8dcSSimon Schubert {
19395796c8dcSSimon Schubert case TYPE_CODE_METHODPTR:
19405796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
19415796c8dcSSimon Schubert return value_zero (TYPE_TARGET_TYPE (type), not_lval);
19425796c8dcSSimon Schubert else
19435796c8dcSSimon Schubert {
19445796c8dcSSimon Schubert arg2 = cplus_method_ptr_to_value (&arg1, arg2);
19455796c8dcSSimon Schubert gdb_assert (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR);
19465796c8dcSSimon Schubert return value_ind (arg2);
19475796c8dcSSimon Schubert }
19485796c8dcSSimon Schubert
19495796c8dcSSimon Schubert case TYPE_CODE_MEMBERPTR:
19505796c8dcSSimon Schubert /* Now, convert these values to an address. */
1951*ef5ccd6cSJohn Marino arg1 = value_cast_pointers (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
1952*ef5ccd6cSJohn Marino arg1, 1);
19535796c8dcSSimon Schubert
19545796c8dcSSimon Schubert mem_offset = value_as_long (arg2);
19555796c8dcSSimon Schubert
19565796c8dcSSimon Schubert arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
19575796c8dcSSimon Schubert value_as_long (arg1) + mem_offset);
19585796c8dcSSimon Schubert return value_ind (arg3);
19595796c8dcSSimon Schubert
19605796c8dcSSimon Schubert default:
1961c50c785cSJohn Marino error (_("non-pointer-to-member value used "
1962c50c785cSJohn Marino "in pointer-to-member construct"));
19635796c8dcSSimon Schubert }
19645796c8dcSSimon Schubert
1965cf7f2e2dSJohn Marino case TYPE_INSTANCE:
1966cf7f2e2dSJohn Marino nargs = longest_to_int (exp->elts[pc + 1].longconst);
1967cf7f2e2dSJohn Marino arg_types = (struct type **) alloca (nargs * sizeof (struct type *));
1968cf7f2e2dSJohn Marino for (ix = 0; ix < nargs; ++ix)
1969cf7f2e2dSJohn Marino arg_types[ix] = exp->elts[pc + 1 + ix + 1].type;
1970cf7f2e2dSJohn Marino
1971cf7f2e2dSJohn Marino expect_type = make_params (nargs, arg_types);
1972cf7f2e2dSJohn Marino *(pos) += 3 + nargs;
1973cf7f2e2dSJohn Marino arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
1974cf7f2e2dSJohn Marino xfree (TYPE_FIELDS (expect_type));
1975cf7f2e2dSJohn Marino xfree (TYPE_MAIN_TYPE (expect_type));
1976cf7f2e2dSJohn Marino xfree (expect_type);
1977cf7f2e2dSJohn Marino return arg1;
1978cf7f2e2dSJohn Marino
19795796c8dcSSimon Schubert case BINOP_CONCAT:
19805796c8dcSSimon Schubert arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
19815796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
19825796c8dcSSimon Schubert if (noside == EVAL_SKIP)
19835796c8dcSSimon Schubert goto nosideret;
19845796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
19855796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
19865796c8dcSSimon Schubert else
19875796c8dcSSimon Schubert return value_concat (arg1, arg2);
19885796c8dcSSimon Schubert
19895796c8dcSSimon Schubert case BINOP_ASSIGN:
19905796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
19915796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
19925796c8dcSSimon Schubert
19935796c8dcSSimon Schubert if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
19945796c8dcSSimon Schubert return arg1;
19955796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
19965796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
19975796c8dcSSimon Schubert else
19985796c8dcSSimon Schubert return value_assign (arg1, arg2);
19995796c8dcSSimon Schubert
20005796c8dcSSimon Schubert case BINOP_ASSIGN_MODIFY:
20015796c8dcSSimon Schubert (*pos) += 2;
20025796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
20035796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
20045796c8dcSSimon Schubert if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
20055796c8dcSSimon Schubert return arg1;
20065796c8dcSSimon Schubert op = exp->elts[pc + 1].opcode;
20075796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
20085796c8dcSSimon Schubert return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
2009cf7f2e2dSJohn Marino else if (op == BINOP_ADD && ptrmath_type_p (exp->language_defn,
2010cf7f2e2dSJohn Marino value_type (arg1))
20115796c8dcSSimon Schubert && is_integral_type (value_type (arg2)))
20125796c8dcSSimon Schubert arg2 = value_ptradd (arg1, value_as_long (arg2));
2013cf7f2e2dSJohn Marino else if (op == BINOP_SUB && ptrmath_type_p (exp->language_defn,
2014cf7f2e2dSJohn Marino value_type (arg1))
20155796c8dcSSimon Schubert && is_integral_type (value_type (arg2)))
20165796c8dcSSimon Schubert arg2 = value_ptradd (arg1, - value_as_long (arg2));
20175796c8dcSSimon Schubert else
20185796c8dcSSimon Schubert {
20195796c8dcSSimon Schubert struct value *tmp = arg1;
20205796c8dcSSimon Schubert
20215796c8dcSSimon Schubert /* For shift and integer exponentiation operations,
20225796c8dcSSimon Schubert only promote the first argument. */
20235796c8dcSSimon Schubert if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
20245796c8dcSSimon Schubert && is_integral_type (value_type (arg2)))
20255796c8dcSSimon Schubert unop_promote (exp->language_defn, exp->gdbarch, &tmp);
20265796c8dcSSimon Schubert else
20275796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
20285796c8dcSSimon Schubert
20295796c8dcSSimon Schubert arg2 = value_binop (tmp, arg2, op);
20305796c8dcSSimon Schubert }
20315796c8dcSSimon Schubert return value_assign (arg1, arg2);
20325796c8dcSSimon Schubert
20335796c8dcSSimon Schubert case BINOP_ADD:
20345796c8dcSSimon Schubert arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
20355796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
20365796c8dcSSimon Schubert if (noside == EVAL_SKIP)
20375796c8dcSSimon Schubert goto nosideret;
20385796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
20395796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2040cf7f2e2dSJohn Marino else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
20415796c8dcSSimon Schubert && is_integral_type (value_type (arg2)))
20425796c8dcSSimon Schubert return value_ptradd (arg1, value_as_long (arg2));
2043cf7f2e2dSJohn Marino else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
20445796c8dcSSimon Schubert && is_integral_type (value_type (arg1)))
20455796c8dcSSimon Schubert return value_ptradd (arg2, value_as_long (arg1));
20465796c8dcSSimon Schubert else
20475796c8dcSSimon Schubert {
20485796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
20495796c8dcSSimon Schubert return value_binop (arg1, arg2, BINOP_ADD);
20505796c8dcSSimon Schubert }
20515796c8dcSSimon Schubert
20525796c8dcSSimon Schubert case BINOP_SUB:
20535796c8dcSSimon Schubert arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
20545796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
20555796c8dcSSimon Schubert if (noside == EVAL_SKIP)
20565796c8dcSSimon Schubert goto nosideret;
20575796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
20585796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
2059cf7f2e2dSJohn Marino else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
2060cf7f2e2dSJohn Marino && ptrmath_type_p (exp->language_defn, value_type (arg2)))
20615796c8dcSSimon Schubert {
20625796c8dcSSimon Schubert /* FIXME -- should be ptrdiff_t */
20635796c8dcSSimon Schubert type = builtin_type (exp->gdbarch)->builtin_long;
20645796c8dcSSimon Schubert return value_from_longest (type, value_ptrdiff (arg1, arg2));
20655796c8dcSSimon Schubert }
2066cf7f2e2dSJohn Marino else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
20675796c8dcSSimon Schubert && is_integral_type (value_type (arg2)))
20685796c8dcSSimon Schubert return value_ptradd (arg1, - value_as_long (arg2));
20695796c8dcSSimon Schubert else
20705796c8dcSSimon Schubert {
20715796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
20725796c8dcSSimon Schubert return value_binop (arg1, arg2, BINOP_SUB);
20735796c8dcSSimon Schubert }
20745796c8dcSSimon Schubert
20755796c8dcSSimon Schubert case BINOP_EXP:
20765796c8dcSSimon Schubert case BINOP_MUL:
20775796c8dcSSimon Schubert case BINOP_DIV:
20785796c8dcSSimon Schubert case BINOP_INTDIV:
20795796c8dcSSimon Schubert case BINOP_REM:
20805796c8dcSSimon Schubert case BINOP_MOD:
20815796c8dcSSimon Schubert case BINOP_LSH:
20825796c8dcSSimon Schubert case BINOP_RSH:
20835796c8dcSSimon Schubert case BINOP_BITWISE_AND:
20845796c8dcSSimon Schubert case BINOP_BITWISE_IOR:
20855796c8dcSSimon Schubert case BINOP_BITWISE_XOR:
20865796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
20875796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
20885796c8dcSSimon Schubert if (noside == EVAL_SKIP)
20895796c8dcSSimon Schubert goto nosideret;
20905796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
20915796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
20925796c8dcSSimon Schubert else
20935796c8dcSSimon Schubert {
20945796c8dcSSimon Schubert /* If EVAL_AVOID_SIDE_EFFECTS and we're dividing by zero,
20955796c8dcSSimon Schubert fudge arg2 to avoid division-by-zero, the caller is
20965796c8dcSSimon Schubert (theoretically) only looking for the type of the result. */
20975796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS
20985796c8dcSSimon Schubert /* ??? Do we really want to test for BINOP_MOD here?
20995796c8dcSSimon Schubert The implementation of value_binop gives it a well-defined
21005796c8dcSSimon Schubert value. */
21015796c8dcSSimon Schubert && (op == BINOP_DIV
21025796c8dcSSimon Schubert || op == BINOP_INTDIV
21035796c8dcSSimon Schubert || op == BINOP_REM
21045796c8dcSSimon Schubert || op == BINOP_MOD)
21055796c8dcSSimon Schubert && value_logical_not (arg2))
21065796c8dcSSimon Schubert {
21075796c8dcSSimon Schubert struct value *v_one, *retval;
21085796c8dcSSimon Schubert
2109a45ae5f8SJohn Marino v_one = value_one (value_type (arg2));
21105796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &v_one);
21115796c8dcSSimon Schubert retval = value_binop (arg1, v_one, op);
21125796c8dcSSimon Schubert return retval;
21135796c8dcSSimon Schubert }
21145796c8dcSSimon Schubert else
21155796c8dcSSimon Schubert {
21165796c8dcSSimon Schubert /* For shift and integer exponentiation operations,
21175796c8dcSSimon Schubert only promote the first argument. */
21185796c8dcSSimon Schubert if ((op == BINOP_LSH || op == BINOP_RSH || op == BINOP_EXP)
21195796c8dcSSimon Schubert && is_integral_type (value_type (arg2)))
21205796c8dcSSimon Schubert unop_promote (exp->language_defn, exp->gdbarch, &arg1);
21215796c8dcSSimon Schubert else
21225796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
21235796c8dcSSimon Schubert
21245796c8dcSSimon Schubert return value_binop (arg1, arg2, op);
21255796c8dcSSimon Schubert }
21265796c8dcSSimon Schubert }
21275796c8dcSSimon Schubert
21285796c8dcSSimon Schubert case BINOP_RANGE:
2129c50c785cSJohn Marino evaluate_subexp (NULL_TYPE, exp, pos, noside);
2130c50c785cSJohn Marino evaluate_subexp (NULL_TYPE, exp, pos, noside);
21315796c8dcSSimon Schubert if (noside == EVAL_SKIP)
21325796c8dcSSimon Schubert goto nosideret;
21335796c8dcSSimon Schubert error (_("':' operator used in invalid context"));
21345796c8dcSSimon Schubert
21355796c8dcSSimon Schubert case BINOP_SUBSCRIPT:
2136cf7f2e2dSJohn Marino arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
2137cf7f2e2dSJohn Marino arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
21385796c8dcSSimon Schubert if (noside == EVAL_SKIP)
21395796c8dcSSimon Schubert goto nosideret;
21405796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
21415796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
21425796c8dcSSimon Schubert else
21435796c8dcSSimon Schubert {
21445796c8dcSSimon Schubert /* If the user attempts to subscript something that is not an
21455796c8dcSSimon Schubert array or pointer type (like a plain int variable for example),
21465796c8dcSSimon Schubert then report this as an error. */
21475796c8dcSSimon Schubert
21485796c8dcSSimon Schubert arg1 = coerce_ref (arg1);
21495796c8dcSSimon Schubert type = check_typedef (value_type (arg1));
21505796c8dcSSimon Schubert if (TYPE_CODE (type) != TYPE_CODE_ARRAY
21515796c8dcSSimon Schubert && TYPE_CODE (type) != TYPE_CODE_PTR)
21525796c8dcSSimon Schubert {
21535796c8dcSSimon Schubert if (TYPE_NAME (type))
21545796c8dcSSimon Schubert error (_("cannot subscript something of type `%s'"),
21555796c8dcSSimon Schubert TYPE_NAME (type));
21565796c8dcSSimon Schubert else
21575796c8dcSSimon Schubert error (_("cannot subscript requested type"));
21585796c8dcSSimon Schubert }
21595796c8dcSSimon Schubert
21605796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
21615796c8dcSSimon Schubert return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
21625796c8dcSSimon Schubert else
21635796c8dcSSimon Schubert return value_subscript (arg1, value_as_long (arg2));
21645796c8dcSSimon Schubert }
21655796c8dcSSimon Schubert
21665796c8dcSSimon Schubert case BINOP_IN:
21675796c8dcSSimon Schubert arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
21685796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
21695796c8dcSSimon Schubert if (noside == EVAL_SKIP)
21705796c8dcSSimon Schubert goto nosideret;
21715796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
21725796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) value_in (arg1, arg2));
21735796c8dcSSimon Schubert
21745796c8dcSSimon Schubert case MULTI_SUBSCRIPT:
21755796c8dcSSimon Schubert (*pos) += 2;
21765796c8dcSSimon Schubert nargs = longest_to_int (exp->elts[pc + 1].longconst);
21775796c8dcSSimon Schubert arg1 = evaluate_subexp_with_coercion (exp, pos, noside);
21785796c8dcSSimon Schubert while (nargs-- > 0)
21795796c8dcSSimon Schubert {
21805796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
21815796c8dcSSimon Schubert /* FIXME: EVAL_SKIP handling may not be correct. */
21825796c8dcSSimon Schubert if (noside == EVAL_SKIP)
21835796c8dcSSimon Schubert {
21845796c8dcSSimon Schubert if (nargs > 0)
21855796c8dcSSimon Schubert {
21865796c8dcSSimon Schubert continue;
21875796c8dcSSimon Schubert }
21885796c8dcSSimon Schubert else
21895796c8dcSSimon Schubert {
21905796c8dcSSimon Schubert goto nosideret;
21915796c8dcSSimon Schubert }
21925796c8dcSSimon Schubert }
21935796c8dcSSimon Schubert /* FIXME: EVAL_AVOID_SIDE_EFFECTS handling may not be correct. */
21945796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
21955796c8dcSSimon Schubert {
21965796c8dcSSimon Schubert /* If the user attempts to subscript something that has no target
21975796c8dcSSimon Schubert type (like a plain int variable for example), then report this
21985796c8dcSSimon Schubert as an error. */
21995796c8dcSSimon Schubert
22005796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (check_typedef (value_type (arg1)));
22015796c8dcSSimon Schubert if (type != NULL)
22025796c8dcSSimon Schubert {
22035796c8dcSSimon Schubert arg1 = value_zero (type, VALUE_LVAL (arg1));
22045796c8dcSSimon Schubert noside = EVAL_SKIP;
22055796c8dcSSimon Schubert continue;
22065796c8dcSSimon Schubert }
22075796c8dcSSimon Schubert else
22085796c8dcSSimon Schubert {
22095796c8dcSSimon Schubert error (_("cannot subscript something of type `%s'"),
22105796c8dcSSimon Schubert TYPE_NAME (value_type (arg1)));
22115796c8dcSSimon Schubert }
22125796c8dcSSimon Schubert }
22135796c8dcSSimon Schubert
22145796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
22155796c8dcSSimon Schubert {
22165796c8dcSSimon Schubert arg1 = value_x_binop (arg1, arg2, op, OP_NULL, noside);
22175796c8dcSSimon Schubert }
22185796c8dcSSimon Schubert else
22195796c8dcSSimon Schubert {
22205796c8dcSSimon Schubert arg1 = coerce_ref (arg1);
22215796c8dcSSimon Schubert type = check_typedef (value_type (arg1));
22225796c8dcSSimon Schubert
22235796c8dcSSimon Schubert switch (TYPE_CODE (type))
22245796c8dcSSimon Schubert {
22255796c8dcSSimon Schubert case TYPE_CODE_PTR:
22265796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
22275796c8dcSSimon Schubert case TYPE_CODE_STRING:
22285796c8dcSSimon Schubert arg1 = value_subscript (arg1, value_as_long (arg2));
22295796c8dcSSimon Schubert break;
22305796c8dcSSimon Schubert
22315796c8dcSSimon Schubert default:
22325796c8dcSSimon Schubert if (TYPE_NAME (type))
22335796c8dcSSimon Schubert error (_("cannot subscript something of type `%s'"),
22345796c8dcSSimon Schubert TYPE_NAME (type));
22355796c8dcSSimon Schubert else
22365796c8dcSSimon Schubert error (_("cannot subscript requested type"));
22375796c8dcSSimon Schubert }
22385796c8dcSSimon Schubert }
22395796c8dcSSimon Schubert }
22405796c8dcSSimon Schubert return (arg1);
22415796c8dcSSimon Schubert
22425796c8dcSSimon Schubert multi_f77_subscript:
22435796c8dcSSimon Schubert {
2244c50c785cSJohn Marino LONGEST subscript_array[MAX_FORTRAN_DIMS];
22455796c8dcSSimon Schubert int ndimensions = 1, i;
2246c50c785cSJohn Marino struct value *array = arg1;
22475796c8dcSSimon Schubert
22485796c8dcSSimon Schubert if (nargs > MAX_FORTRAN_DIMS)
22495796c8dcSSimon Schubert error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
22505796c8dcSSimon Schubert
22515796c8dcSSimon Schubert ndimensions = calc_f77_array_dims (type);
22525796c8dcSSimon Schubert
22535796c8dcSSimon Schubert if (nargs != ndimensions)
22545796c8dcSSimon Schubert error (_("Wrong number of subscripts"));
22555796c8dcSSimon Schubert
22565796c8dcSSimon Schubert gdb_assert (nargs > 0);
22575796c8dcSSimon Schubert
22585796c8dcSSimon Schubert /* Now that we know we have a legal array subscript expression
22595796c8dcSSimon Schubert let us actually find out where this element exists in the array. */
22605796c8dcSSimon Schubert
2261c50c785cSJohn Marino /* Take array indices left to right. */
22625796c8dcSSimon Schubert for (i = 0; i < nargs; i++)
22635796c8dcSSimon Schubert {
2264c50c785cSJohn Marino /* Evaluate each subscript; it must be a legal integer in F77. */
22655796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
22665796c8dcSSimon Schubert
2267c50c785cSJohn Marino /* Fill in the subscript array. */
22685796c8dcSSimon Schubert
22695796c8dcSSimon Schubert subscript_array[i] = value_as_long (arg2);
22705796c8dcSSimon Schubert }
22715796c8dcSSimon Schubert
2272c50c785cSJohn Marino /* Internal type of array is arranged right to left. */
2273c50c785cSJohn Marino for (i = nargs; i > 0; i--)
22745796c8dcSSimon Schubert {
2275c50c785cSJohn Marino struct type *array_type = check_typedef (value_type (array));
2276c50c785cSJohn Marino LONGEST index = subscript_array[i - 1];
22775796c8dcSSimon Schubert
2278*ef5ccd6cSJohn Marino array = value_subscripted_rvalue (array, index,
2279*ef5ccd6cSJohn Marino f77_get_lowerbound (array_type));
22805796c8dcSSimon Schubert }
22815796c8dcSSimon Schubert
2282c50c785cSJohn Marino return array;
22835796c8dcSSimon Schubert }
22845796c8dcSSimon Schubert
22855796c8dcSSimon Schubert case BINOP_LOGICAL_AND:
22865796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
22875796c8dcSSimon Schubert if (noside == EVAL_SKIP)
22885796c8dcSSimon Schubert {
2289c50c785cSJohn Marino evaluate_subexp (NULL_TYPE, exp, pos, noside);
22905796c8dcSSimon Schubert goto nosideret;
22915796c8dcSSimon Schubert }
22925796c8dcSSimon Schubert
22935796c8dcSSimon Schubert oldpos = *pos;
22945796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
22955796c8dcSSimon Schubert *pos = oldpos;
22965796c8dcSSimon Schubert
22975796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
22985796c8dcSSimon Schubert {
22995796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
23005796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
23015796c8dcSSimon Schubert }
23025796c8dcSSimon Schubert else
23035796c8dcSSimon Schubert {
23045796c8dcSSimon Schubert tem = value_logical_not (arg1);
23055796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
23065796c8dcSSimon Schubert (tem ? EVAL_SKIP : noside));
23075796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
23085796c8dcSSimon Schubert return value_from_longest (type,
23095796c8dcSSimon Schubert (LONGEST) (!tem && !value_logical_not (arg2)));
23105796c8dcSSimon Schubert }
23115796c8dcSSimon Schubert
23125796c8dcSSimon Schubert case BINOP_LOGICAL_OR:
23135796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
23145796c8dcSSimon Schubert if (noside == EVAL_SKIP)
23155796c8dcSSimon Schubert {
2316c50c785cSJohn Marino evaluate_subexp (NULL_TYPE, exp, pos, noside);
23175796c8dcSSimon Schubert goto nosideret;
23185796c8dcSSimon Schubert }
23195796c8dcSSimon Schubert
23205796c8dcSSimon Schubert oldpos = *pos;
23215796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
23225796c8dcSSimon Schubert *pos = oldpos;
23235796c8dcSSimon Schubert
23245796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
23255796c8dcSSimon Schubert {
23265796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
23275796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
23285796c8dcSSimon Schubert }
23295796c8dcSSimon Schubert else
23305796c8dcSSimon Schubert {
23315796c8dcSSimon Schubert tem = value_logical_not (arg1);
23325796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos,
23335796c8dcSSimon Schubert (!tem ? EVAL_SKIP : noside));
23345796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
23355796c8dcSSimon Schubert return value_from_longest (type,
23365796c8dcSSimon Schubert (LONGEST) (!tem || !value_logical_not (arg2)));
23375796c8dcSSimon Schubert }
23385796c8dcSSimon Schubert
23395796c8dcSSimon Schubert case BINOP_EQUAL:
23405796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
23415796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
23425796c8dcSSimon Schubert if (noside == EVAL_SKIP)
23435796c8dcSSimon Schubert goto nosideret;
23445796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
23455796c8dcSSimon Schubert {
23465796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
23475796c8dcSSimon Schubert }
23485796c8dcSSimon Schubert else
23495796c8dcSSimon Schubert {
23505796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
23515796c8dcSSimon Schubert tem = value_equal (arg1, arg2);
23525796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
23535796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) tem);
23545796c8dcSSimon Schubert }
23555796c8dcSSimon Schubert
23565796c8dcSSimon Schubert case BINOP_NOTEQUAL:
23575796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
23585796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
23595796c8dcSSimon Schubert if (noside == EVAL_SKIP)
23605796c8dcSSimon Schubert goto nosideret;
23615796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
23625796c8dcSSimon Schubert {
23635796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
23645796c8dcSSimon Schubert }
23655796c8dcSSimon Schubert else
23665796c8dcSSimon Schubert {
23675796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
23685796c8dcSSimon Schubert tem = value_equal (arg1, arg2);
23695796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
23705796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) ! tem);
23715796c8dcSSimon Schubert }
23725796c8dcSSimon Schubert
23735796c8dcSSimon Schubert case BINOP_LESS:
23745796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
23755796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
23765796c8dcSSimon Schubert if (noside == EVAL_SKIP)
23775796c8dcSSimon Schubert goto nosideret;
23785796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
23795796c8dcSSimon Schubert {
23805796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
23815796c8dcSSimon Schubert }
23825796c8dcSSimon Schubert else
23835796c8dcSSimon Schubert {
23845796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
23855796c8dcSSimon Schubert tem = value_less (arg1, arg2);
23865796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
23875796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) tem);
23885796c8dcSSimon Schubert }
23895796c8dcSSimon Schubert
23905796c8dcSSimon Schubert case BINOP_GTR:
23915796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
23925796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
23935796c8dcSSimon Schubert if (noside == EVAL_SKIP)
23945796c8dcSSimon Schubert goto nosideret;
23955796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
23965796c8dcSSimon Schubert {
23975796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
23985796c8dcSSimon Schubert }
23995796c8dcSSimon Schubert else
24005796c8dcSSimon Schubert {
24015796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
24025796c8dcSSimon Schubert tem = value_less (arg2, arg1);
24035796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
24045796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) tem);
24055796c8dcSSimon Schubert }
24065796c8dcSSimon Schubert
24075796c8dcSSimon Schubert case BINOP_GEQ:
24085796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
24095796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
24105796c8dcSSimon Schubert if (noside == EVAL_SKIP)
24115796c8dcSSimon Schubert goto nosideret;
24125796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
24135796c8dcSSimon Schubert {
24145796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
24155796c8dcSSimon Schubert }
24165796c8dcSSimon Schubert else
24175796c8dcSSimon Schubert {
24185796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
24195796c8dcSSimon Schubert tem = value_less (arg2, arg1) || value_equal (arg1, arg2);
24205796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
24215796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) tem);
24225796c8dcSSimon Schubert }
24235796c8dcSSimon Schubert
24245796c8dcSSimon Schubert case BINOP_LEQ:
24255796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
24265796c8dcSSimon Schubert arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
24275796c8dcSSimon Schubert if (noside == EVAL_SKIP)
24285796c8dcSSimon Schubert goto nosideret;
24295796c8dcSSimon Schubert if (binop_user_defined_p (op, arg1, arg2))
24305796c8dcSSimon Schubert {
24315796c8dcSSimon Schubert return value_x_binop (arg1, arg2, op, OP_NULL, noside);
24325796c8dcSSimon Schubert }
24335796c8dcSSimon Schubert else
24345796c8dcSSimon Schubert {
24355796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
24365796c8dcSSimon Schubert tem = value_less (arg1, arg2) || value_equal (arg1, arg2);
24375796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
24385796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) tem);
24395796c8dcSSimon Schubert }
24405796c8dcSSimon Schubert
24415796c8dcSSimon Schubert case BINOP_REPEAT:
24425796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
24435796c8dcSSimon Schubert arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
24445796c8dcSSimon Schubert if (noside == EVAL_SKIP)
24455796c8dcSSimon Schubert goto nosideret;
24465796c8dcSSimon Schubert type = check_typedef (value_type (arg2));
24475796c8dcSSimon Schubert if (TYPE_CODE (type) != TYPE_CODE_INT)
24485796c8dcSSimon Schubert error (_("Non-integral right operand for \"@\" operator."));
24495796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
24505796c8dcSSimon Schubert {
24515796c8dcSSimon Schubert return allocate_repeat_value (value_type (arg1),
24525796c8dcSSimon Schubert longest_to_int (value_as_long (arg2)));
24535796c8dcSSimon Schubert }
24545796c8dcSSimon Schubert else
24555796c8dcSSimon Schubert return value_repeat (arg1, longest_to_int (value_as_long (arg2)));
24565796c8dcSSimon Schubert
24575796c8dcSSimon Schubert case BINOP_COMMA:
24585796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, noside);
24595796c8dcSSimon Schubert return evaluate_subexp (NULL_TYPE, exp, pos, noside);
24605796c8dcSSimon Schubert
24615796c8dcSSimon Schubert case UNOP_PLUS:
24625796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
24635796c8dcSSimon Schubert if (noside == EVAL_SKIP)
24645796c8dcSSimon Schubert goto nosideret;
24655796c8dcSSimon Schubert if (unop_user_defined_p (op, arg1))
24665796c8dcSSimon Schubert return value_x_unop (arg1, op, noside);
24675796c8dcSSimon Schubert else
24685796c8dcSSimon Schubert {
24695796c8dcSSimon Schubert unop_promote (exp->language_defn, exp->gdbarch, &arg1);
24705796c8dcSSimon Schubert return value_pos (arg1);
24715796c8dcSSimon Schubert }
24725796c8dcSSimon Schubert
24735796c8dcSSimon Schubert case UNOP_NEG:
24745796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
24755796c8dcSSimon Schubert if (noside == EVAL_SKIP)
24765796c8dcSSimon Schubert goto nosideret;
24775796c8dcSSimon Schubert if (unop_user_defined_p (op, arg1))
24785796c8dcSSimon Schubert return value_x_unop (arg1, op, noside);
24795796c8dcSSimon Schubert else
24805796c8dcSSimon Schubert {
24815796c8dcSSimon Schubert unop_promote (exp->language_defn, exp->gdbarch, &arg1);
24825796c8dcSSimon Schubert return value_neg (arg1);
24835796c8dcSSimon Schubert }
24845796c8dcSSimon Schubert
24855796c8dcSSimon Schubert case UNOP_COMPLEMENT:
24865796c8dcSSimon Schubert /* C++: check for and handle destructor names. */
24875796c8dcSSimon Schubert op = exp->elts[*pos].opcode;
24885796c8dcSSimon Schubert
24895796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
24905796c8dcSSimon Schubert if (noside == EVAL_SKIP)
24915796c8dcSSimon Schubert goto nosideret;
24925796c8dcSSimon Schubert if (unop_user_defined_p (UNOP_COMPLEMENT, arg1))
24935796c8dcSSimon Schubert return value_x_unop (arg1, UNOP_COMPLEMENT, noside);
24945796c8dcSSimon Schubert else
24955796c8dcSSimon Schubert {
24965796c8dcSSimon Schubert unop_promote (exp->language_defn, exp->gdbarch, &arg1);
24975796c8dcSSimon Schubert return value_complement (arg1);
24985796c8dcSSimon Schubert }
24995796c8dcSSimon Schubert
25005796c8dcSSimon Schubert case UNOP_LOGICAL_NOT:
25015796c8dcSSimon Schubert arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
25025796c8dcSSimon Schubert if (noside == EVAL_SKIP)
25035796c8dcSSimon Schubert goto nosideret;
25045796c8dcSSimon Schubert if (unop_user_defined_p (op, arg1))
25055796c8dcSSimon Schubert return value_x_unop (arg1, op, noside);
25065796c8dcSSimon Schubert else
25075796c8dcSSimon Schubert {
25085796c8dcSSimon Schubert type = language_bool_type (exp->language_defn, exp->gdbarch);
25095796c8dcSSimon Schubert return value_from_longest (type, (LONGEST) value_logical_not (arg1));
25105796c8dcSSimon Schubert }
25115796c8dcSSimon Schubert
25125796c8dcSSimon Schubert case UNOP_IND:
25135796c8dcSSimon Schubert if (expect_type && TYPE_CODE (expect_type) == TYPE_CODE_PTR)
25145796c8dcSSimon Schubert expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
25155796c8dcSSimon Schubert arg1 = evaluate_subexp (expect_type, exp, pos, noside);
25165796c8dcSSimon Schubert type = check_typedef (value_type (arg1));
25175796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
25185796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
2519c50c785cSJohn Marino error (_("Attempt to dereference pointer "
2520c50c785cSJohn Marino "to member without an object"));
25215796c8dcSSimon Schubert if (noside == EVAL_SKIP)
25225796c8dcSSimon Schubert goto nosideret;
25235796c8dcSSimon Schubert if (unop_user_defined_p (op, arg1))
25245796c8dcSSimon Schubert return value_x_unop (arg1, op, noside);
25255796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
25265796c8dcSSimon Schubert {
25275796c8dcSSimon Schubert type = check_typedef (value_type (arg1));
25285796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR
25295796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_REF
25305796c8dcSSimon Schubert /* In C you can dereference an array to get the 1st elt. */
25315796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_ARRAY
25325796c8dcSSimon Schubert )
25335796c8dcSSimon Schubert return value_zero (TYPE_TARGET_TYPE (type),
25345796c8dcSSimon Schubert lval_memory);
25355796c8dcSSimon Schubert else if (TYPE_CODE (type) == TYPE_CODE_INT)
25365796c8dcSSimon Schubert /* GDB allows dereferencing an int. */
25375796c8dcSSimon Schubert return value_zero (builtin_type (exp->gdbarch)->builtin_int,
25385796c8dcSSimon Schubert lval_memory);
25395796c8dcSSimon Schubert else
25405796c8dcSSimon Schubert error (_("Attempt to take contents of a non-pointer value."));
25415796c8dcSSimon Schubert }
25425796c8dcSSimon Schubert
25435796c8dcSSimon Schubert /* Allow * on an integer so we can cast it to whatever we want.
25445796c8dcSSimon Schubert This returns an int, which seems like the most C-like thing to
25455796c8dcSSimon Schubert do. "long long" variables are rare enough that
25465796c8dcSSimon Schubert BUILTIN_TYPE_LONGEST would seem to be a mistake. */
25475796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_INT)
25485796c8dcSSimon Schubert return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
25495796c8dcSSimon Schubert (CORE_ADDR) value_as_address (arg1));
25505796c8dcSSimon Schubert return value_ind (arg1);
25515796c8dcSSimon Schubert
25525796c8dcSSimon Schubert case UNOP_ADDR:
25535796c8dcSSimon Schubert /* C++: check for and handle pointer to members. */
25545796c8dcSSimon Schubert
25555796c8dcSSimon Schubert op = exp->elts[*pos].opcode;
25565796c8dcSSimon Schubert
25575796c8dcSSimon Schubert if (noside == EVAL_SKIP)
25585796c8dcSSimon Schubert {
25595796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
25605796c8dcSSimon Schubert goto nosideret;
25615796c8dcSSimon Schubert }
25625796c8dcSSimon Schubert else
25635796c8dcSSimon Schubert {
2564c50c785cSJohn Marino struct value *retvalp = evaluate_subexp_for_address (exp, pos,
2565c50c785cSJohn Marino noside);
2566cf7f2e2dSJohn Marino
25675796c8dcSSimon Schubert return retvalp;
25685796c8dcSSimon Schubert }
25695796c8dcSSimon Schubert
25705796c8dcSSimon Schubert case UNOP_SIZEOF:
25715796c8dcSSimon Schubert if (noside == EVAL_SKIP)
25725796c8dcSSimon Schubert {
25735796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
25745796c8dcSSimon Schubert goto nosideret;
25755796c8dcSSimon Schubert }
25765796c8dcSSimon Schubert return evaluate_subexp_for_sizeof (exp, pos);
25775796c8dcSSimon Schubert
25785796c8dcSSimon Schubert case UNOP_CAST:
25795796c8dcSSimon Schubert (*pos) += 2;
25805796c8dcSSimon Schubert type = exp->elts[pc + 1].type;
25815796c8dcSSimon Schubert arg1 = evaluate_subexp (type, exp, pos, noside);
25825796c8dcSSimon Schubert if (noside == EVAL_SKIP)
25835796c8dcSSimon Schubert goto nosideret;
25845796c8dcSSimon Schubert if (type != value_type (arg1))
25855796c8dcSSimon Schubert arg1 = value_cast (type, arg1);
25865796c8dcSSimon Schubert return arg1;
25875796c8dcSSimon Schubert
2588*ef5ccd6cSJohn Marino case UNOP_CAST_TYPE:
2589*ef5ccd6cSJohn Marino arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2590*ef5ccd6cSJohn Marino type = value_type (arg1);
2591*ef5ccd6cSJohn Marino arg1 = evaluate_subexp (type, exp, pos, noside);
2592*ef5ccd6cSJohn Marino if (noside == EVAL_SKIP)
2593*ef5ccd6cSJohn Marino goto nosideret;
2594*ef5ccd6cSJohn Marino if (type != value_type (arg1))
2595*ef5ccd6cSJohn Marino arg1 = value_cast (type, arg1);
2596*ef5ccd6cSJohn Marino return arg1;
2597*ef5ccd6cSJohn Marino
2598cf7f2e2dSJohn Marino case UNOP_DYNAMIC_CAST:
2599*ef5ccd6cSJohn Marino arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2600*ef5ccd6cSJohn Marino type = value_type (arg1);
2601cf7f2e2dSJohn Marino arg1 = evaluate_subexp (type, exp, pos, noside);
2602cf7f2e2dSJohn Marino if (noside == EVAL_SKIP)
2603cf7f2e2dSJohn Marino goto nosideret;
2604cf7f2e2dSJohn Marino return value_dynamic_cast (type, arg1);
2605cf7f2e2dSJohn Marino
2606cf7f2e2dSJohn Marino case UNOP_REINTERPRET_CAST:
2607*ef5ccd6cSJohn Marino arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2608*ef5ccd6cSJohn Marino type = value_type (arg1);
2609cf7f2e2dSJohn Marino arg1 = evaluate_subexp (type, exp, pos, noside);
2610cf7f2e2dSJohn Marino if (noside == EVAL_SKIP)
2611cf7f2e2dSJohn Marino goto nosideret;
2612cf7f2e2dSJohn Marino return value_reinterpret_cast (type, arg1);
2613cf7f2e2dSJohn Marino
26145796c8dcSSimon Schubert case UNOP_MEMVAL:
26155796c8dcSSimon Schubert (*pos) += 2;
26165796c8dcSSimon Schubert arg1 = evaluate_subexp (expect_type, exp, pos, noside);
26175796c8dcSSimon Schubert if (noside == EVAL_SKIP)
26185796c8dcSSimon Schubert goto nosideret;
26195796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
26205796c8dcSSimon Schubert return value_zero (exp->elts[pc + 1].type, lval_memory);
26215796c8dcSSimon Schubert else
26225796c8dcSSimon Schubert return value_at_lazy (exp->elts[pc + 1].type,
26235796c8dcSSimon Schubert value_as_address (arg1));
26245796c8dcSSimon Schubert
2625*ef5ccd6cSJohn Marino case UNOP_MEMVAL_TYPE:
2626*ef5ccd6cSJohn Marino arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2627*ef5ccd6cSJohn Marino type = value_type (arg1);
2628*ef5ccd6cSJohn Marino arg1 = evaluate_subexp (expect_type, exp, pos, noside);
2629*ef5ccd6cSJohn Marino if (noside == EVAL_SKIP)
2630*ef5ccd6cSJohn Marino goto nosideret;
2631*ef5ccd6cSJohn Marino if (noside == EVAL_AVOID_SIDE_EFFECTS)
2632*ef5ccd6cSJohn Marino return value_zero (type, lval_memory);
2633*ef5ccd6cSJohn Marino else
2634*ef5ccd6cSJohn Marino return value_at_lazy (type, value_as_address (arg1));
2635*ef5ccd6cSJohn Marino
26365796c8dcSSimon Schubert case UNOP_MEMVAL_TLS:
26375796c8dcSSimon Schubert (*pos) += 3;
26385796c8dcSSimon Schubert arg1 = evaluate_subexp (expect_type, exp, pos, noside);
26395796c8dcSSimon Schubert if (noside == EVAL_SKIP)
26405796c8dcSSimon Schubert goto nosideret;
26415796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
26425796c8dcSSimon Schubert return value_zero (exp->elts[pc + 2].type, lval_memory);
26435796c8dcSSimon Schubert else
26445796c8dcSSimon Schubert {
26455796c8dcSSimon Schubert CORE_ADDR tls_addr;
2646cf7f2e2dSJohn Marino
26475796c8dcSSimon Schubert tls_addr = target_translate_tls_address (exp->elts[pc + 1].objfile,
26485796c8dcSSimon Schubert value_as_address (arg1));
26495796c8dcSSimon Schubert return value_at_lazy (exp->elts[pc + 2].type, tls_addr);
26505796c8dcSSimon Schubert }
26515796c8dcSSimon Schubert
26525796c8dcSSimon Schubert case UNOP_PREINCREMENT:
26535796c8dcSSimon Schubert arg1 = evaluate_subexp (expect_type, exp, pos, noside);
26545796c8dcSSimon Schubert if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
26555796c8dcSSimon Schubert return arg1;
26565796c8dcSSimon Schubert else if (unop_user_defined_p (op, arg1))
26575796c8dcSSimon Schubert {
26585796c8dcSSimon Schubert return value_x_unop (arg1, op, noside);
26595796c8dcSSimon Schubert }
26605796c8dcSSimon Schubert else
26615796c8dcSSimon Schubert {
2662cf7f2e2dSJohn Marino if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
26635796c8dcSSimon Schubert arg2 = value_ptradd (arg1, 1);
26645796c8dcSSimon Schubert else
26655796c8dcSSimon Schubert {
26665796c8dcSSimon Schubert struct value *tmp = arg1;
2667cf7f2e2dSJohn Marino
2668a45ae5f8SJohn Marino arg2 = value_one (value_type (arg1));
26695796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
26705796c8dcSSimon Schubert arg2 = value_binop (tmp, arg2, BINOP_ADD);
26715796c8dcSSimon Schubert }
26725796c8dcSSimon Schubert
26735796c8dcSSimon Schubert return value_assign (arg1, arg2);
26745796c8dcSSimon Schubert }
26755796c8dcSSimon Schubert
26765796c8dcSSimon Schubert case UNOP_PREDECREMENT:
26775796c8dcSSimon Schubert arg1 = evaluate_subexp (expect_type, exp, pos, noside);
26785796c8dcSSimon Schubert if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
26795796c8dcSSimon Schubert return arg1;
26805796c8dcSSimon Schubert else if (unop_user_defined_p (op, arg1))
26815796c8dcSSimon Schubert {
26825796c8dcSSimon Schubert return value_x_unop (arg1, op, noside);
26835796c8dcSSimon Schubert }
26845796c8dcSSimon Schubert else
26855796c8dcSSimon Schubert {
2686cf7f2e2dSJohn Marino if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
26875796c8dcSSimon Schubert arg2 = value_ptradd (arg1, -1);
26885796c8dcSSimon Schubert else
26895796c8dcSSimon Schubert {
26905796c8dcSSimon Schubert struct value *tmp = arg1;
2691cf7f2e2dSJohn Marino
2692a45ae5f8SJohn Marino arg2 = value_one (value_type (arg1));
26935796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
26945796c8dcSSimon Schubert arg2 = value_binop (tmp, arg2, BINOP_SUB);
26955796c8dcSSimon Schubert }
26965796c8dcSSimon Schubert
26975796c8dcSSimon Schubert return value_assign (arg1, arg2);
26985796c8dcSSimon Schubert }
26995796c8dcSSimon Schubert
27005796c8dcSSimon Schubert case UNOP_POSTINCREMENT:
27015796c8dcSSimon Schubert arg1 = evaluate_subexp (expect_type, exp, pos, noside);
27025796c8dcSSimon Schubert if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
27035796c8dcSSimon Schubert return arg1;
27045796c8dcSSimon Schubert else if (unop_user_defined_p (op, arg1))
27055796c8dcSSimon Schubert {
27065796c8dcSSimon Schubert return value_x_unop (arg1, op, noside);
27075796c8dcSSimon Schubert }
27085796c8dcSSimon Schubert else
27095796c8dcSSimon Schubert {
2710c50c785cSJohn Marino arg3 = value_non_lval (arg1);
2711c50c785cSJohn Marino
2712cf7f2e2dSJohn Marino if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
27135796c8dcSSimon Schubert arg2 = value_ptradd (arg1, 1);
27145796c8dcSSimon Schubert else
27155796c8dcSSimon Schubert {
27165796c8dcSSimon Schubert struct value *tmp = arg1;
2717cf7f2e2dSJohn Marino
2718a45ae5f8SJohn Marino arg2 = value_one (value_type (arg1));
27195796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
27205796c8dcSSimon Schubert arg2 = value_binop (tmp, arg2, BINOP_ADD);
27215796c8dcSSimon Schubert }
27225796c8dcSSimon Schubert
27235796c8dcSSimon Schubert value_assign (arg1, arg2);
2724c50c785cSJohn Marino return arg3;
27255796c8dcSSimon Schubert }
27265796c8dcSSimon Schubert
27275796c8dcSSimon Schubert case UNOP_POSTDECREMENT:
27285796c8dcSSimon Schubert arg1 = evaluate_subexp (expect_type, exp, pos, noside);
27295796c8dcSSimon Schubert if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
27305796c8dcSSimon Schubert return arg1;
27315796c8dcSSimon Schubert else if (unop_user_defined_p (op, arg1))
27325796c8dcSSimon Schubert {
27335796c8dcSSimon Schubert return value_x_unop (arg1, op, noside);
27345796c8dcSSimon Schubert }
27355796c8dcSSimon Schubert else
27365796c8dcSSimon Schubert {
2737c50c785cSJohn Marino arg3 = value_non_lval (arg1);
2738c50c785cSJohn Marino
2739cf7f2e2dSJohn Marino if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
27405796c8dcSSimon Schubert arg2 = value_ptradd (arg1, -1);
27415796c8dcSSimon Schubert else
27425796c8dcSSimon Schubert {
27435796c8dcSSimon Schubert struct value *tmp = arg1;
2744cf7f2e2dSJohn Marino
2745a45ae5f8SJohn Marino arg2 = value_one (value_type (arg1));
27465796c8dcSSimon Schubert binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
27475796c8dcSSimon Schubert arg2 = value_binop (tmp, arg2, BINOP_SUB);
27485796c8dcSSimon Schubert }
27495796c8dcSSimon Schubert
27505796c8dcSSimon Schubert value_assign (arg1, arg2);
2751c50c785cSJohn Marino return arg3;
27525796c8dcSSimon Schubert }
27535796c8dcSSimon Schubert
27545796c8dcSSimon Schubert case OP_THIS:
27555796c8dcSSimon Schubert (*pos) += 1;
2756a45ae5f8SJohn Marino return value_of_this (exp->language_defn);
27575796c8dcSSimon Schubert
27585796c8dcSSimon Schubert case OP_TYPE:
27595796c8dcSSimon Schubert /* The value is not supposed to be used. This is here to make it
27605796c8dcSSimon Schubert easier to accommodate expressions that contain types. */
27615796c8dcSSimon Schubert (*pos) += 2;
27625796c8dcSSimon Schubert if (noside == EVAL_SKIP)
27635796c8dcSSimon Schubert goto nosideret;
27645796c8dcSSimon Schubert else if (noside == EVAL_AVOID_SIDE_EFFECTS)
27655796c8dcSSimon Schubert {
27665796c8dcSSimon Schubert struct type *type = exp->elts[pc + 1].type;
2767cf7f2e2dSJohn Marino
27685796c8dcSSimon Schubert /* If this is a typedef, then find its immediate target. We
27695796c8dcSSimon Schubert use check_typedef to resolve stubs, but we ignore its
27705796c8dcSSimon Schubert result because we do not want to dig past all
27715796c8dcSSimon Schubert typedefs. */
27725796c8dcSSimon Schubert check_typedef (type);
27735796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
27745796c8dcSSimon Schubert type = TYPE_TARGET_TYPE (type);
27755796c8dcSSimon Schubert return allocate_value (type);
27765796c8dcSSimon Schubert }
27775796c8dcSSimon Schubert else
27785796c8dcSSimon Schubert error (_("Attempt to use a type name as an expression"));
27795796c8dcSSimon Schubert
2780*ef5ccd6cSJohn Marino case OP_TYPEOF:
2781*ef5ccd6cSJohn Marino case OP_DECLTYPE:
2782*ef5ccd6cSJohn Marino if (noside == EVAL_SKIP)
2783*ef5ccd6cSJohn Marino {
2784*ef5ccd6cSJohn Marino evaluate_subexp (NULL_TYPE, exp, pos, EVAL_SKIP);
2785*ef5ccd6cSJohn Marino goto nosideret;
2786*ef5ccd6cSJohn Marino }
2787*ef5ccd6cSJohn Marino else if (noside == EVAL_AVOID_SIDE_EFFECTS)
2788*ef5ccd6cSJohn Marino {
2789*ef5ccd6cSJohn Marino enum exp_opcode sub_op = exp->elts[*pos].opcode;
2790*ef5ccd6cSJohn Marino struct value *result;
2791*ef5ccd6cSJohn Marino
2792*ef5ccd6cSJohn Marino result = evaluate_subexp (NULL_TYPE, exp, pos,
2793*ef5ccd6cSJohn Marino EVAL_AVOID_SIDE_EFFECTS);
2794*ef5ccd6cSJohn Marino
2795*ef5ccd6cSJohn Marino /* 'decltype' has special semantics for lvalues. */
2796*ef5ccd6cSJohn Marino if (op == OP_DECLTYPE
2797*ef5ccd6cSJohn Marino && (sub_op == BINOP_SUBSCRIPT
2798*ef5ccd6cSJohn Marino || sub_op == STRUCTOP_MEMBER
2799*ef5ccd6cSJohn Marino || sub_op == STRUCTOP_MPTR
2800*ef5ccd6cSJohn Marino || sub_op == UNOP_IND
2801*ef5ccd6cSJohn Marino || sub_op == STRUCTOP_STRUCT
2802*ef5ccd6cSJohn Marino || sub_op == STRUCTOP_PTR
2803*ef5ccd6cSJohn Marino || sub_op == OP_SCOPE))
2804*ef5ccd6cSJohn Marino {
2805*ef5ccd6cSJohn Marino struct type *type = value_type (result);
2806*ef5ccd6cSJohn Marino
2807*ef5ccd6cSJohn Marino if (TYPE_CODE (check_typedef (type)) != TYPE_CODE_REF)
2808*ef5ccd6cSJohn Marino {
2809*ef5ccd6cSJohn Marino type = lookup_reference_type (type);
2810*ef5ccd6cSJohn Marino result = allocate_value (type);
2811*ef5ccd6cSJohn Marino }
2812*ef5ccd6cSJohn Marino }
2813*ef5ccd6cSJohn Marino
2814*ef5ccd6cSJohn Marino return result;
2815*ef5ccd6cSJohn Marino }
2816*ef5ccd6cSJohn Marino else
2817*ef5ccd6cSJohn Marino error (_("Attempt to use a type as an expression"));
2818*ef5ccd6cSJohn Marino
28195796c8dcSSimon Schubert default:
28205796c8dcSSimon Schubert /* Removing this case and compiling with gcc -Wall reveals that
28215796c8dcSSimon Schubert a lot of cases are hitting this case. Some of these should
28225796c8dcSSimon Schubert probably be removed from expression.h; others are legitimate
28235796c8dcSSimon Schubert expressions which are (apparently) not fully implemented.
28245796c8dcSSimon Schubert
28255796c8dcSSimon Schubert If there are any cases landing here which mean a user error,
28265796c8dcSSimon Schubert then they should be separate cases, with more descriptive
28275796c8dcSSimon Schubert error messages. */
28285796c8dcSSimon Schubert
2829c50c785cSJohn Marino error (_("GDB does not (yet) know how to "
2830c50c785cSJohn Marino "evaluate that kind of expression"));
28315796c8dcSSimon Schubert }
28325796c8dcSSimon Schubert
28335796c8dcSSimon Schubert nosideret:
28345796c8dcSSimon Schubert return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
28355796c8dcSSimon Schubert }
28365796c8dcSSimon Schubert
28375796c8dcSSimon Schubert /* Evaluate a subexpression of EXP, at index *POS,
28385796c8dcSSimon Schubert and return the address of that subexpression.
28395796c8dcSSimon Schubert Advance *POS over the subexpression.
28405796c8dcSSimon Schubert If the subexpression isn't an lvalue, get an error.
28415796c8dcSSimon Schubert NOSIDE may be EVAL_AVOID_SIDE_EFFECTS;
28425796c8dcSSimon Schubert then only the type of the result need be correct. */
28435796c8dcSSimon Schubert
28445796c8dcSSimon Schubert static struct value *
evaluate_subexp_for_address(struct expression * exp,int * pos,enum noside noside)28455796c8dcSSimon Schubert evaluate_subexp_for_address (struct expression *exp, int *pos,
28465796c8dcSSimon Schubert enum noside noside)
28475796c8dcSSimon Schubert {
28485796c8dcSSimon Schubert enum exp_opcode op;
28495796c8dcSSimon Schubert int pc;
28505796c8dcSSimon Schubert struct symbol *var;
28515796c8dcSSimon Schubert struct value *x;
28525796c8dcSSimon Schubert int tem;
28535796c8dcSSimon Schubert
28545796c8dcSSimon Schubert pc = (*pos);
28555796c8dcSSimon Schubert op = exp->elts[pc].opcode;
28565796c8dcSSimon Schubert
28575796c8dcSSimon Schubert switch (op)
28585796c8dcSSimon Schubert {
28595796c8dcSSimon Schubert case UNOP_IND:
28605796c8dcSSimon Schubert (*pos)++;
28615796c8dcSSimon Schubert x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
28625796c8dcSSimon Schubert
28635796c8dcSSimon Schubert /* We can't optimize out "&*" if there's a user-defined operator*. */
28645796c8dcSSimon Schubert if (unop_user_defined_p (op, x))
28655796c8dcSSimon Schubert {
28665796c8dcSSimon Schubert x = value_x_unop (x, op, noside);
28675796c8dcSSimon Schubert goto default_case_after_eval;
28685796c8dcSSimon Schubert }
28695796c8dcSSimon Schubert
2870cf7f2e2dSJohn Marino return coerce_array (x);
28715796c8dcSSimon Schubert
28725796c8dcSSimon Schubert case UNOP_MEMVAL:
28735796c8dcSSimon Schubert (*pos) += 3;
28745796c8dcSSimon Schubert return value_cast (lookup_pointer_type (exp->elts[pc + 1].type),
28755796c8dcSSimon Schubert evaluate_subexp (NULL_TYPE, exp, pos, noside));
28765796c8dcSSimon Schubert
2877*ef5ccd6cSJohn Marino case UNOP_MEMVAL_TYPE:
2878*ef5ccd6cSJohn Marino {
2879*ef5ccd6cSJohn Marino struct type *type;
2880*ef5ccd6cSJohn Marino
2881*ef5ccd6cSJohn Marino (*pos) += 1;
2882*ef5ccd6cSJohn Marino x = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
2883*ef5ccd6cSJohn Marino type = value_type (x);
2884*ef5ccd6cSJohn Marino return value_cast (lookup_pointer_type (type),
2885*ef5ccd6cSJohn Marino evaluate_subexp (NULL_TYPE, exp, pos, noside));
2886*ef5ccd6cSJohn Marino }
2887*ef5ccd6cSJohn Marino
28885796c8dcSSimon Schubert case OP_VAR_VALUE:
28895796c8dcSSimon Schubert var = exp->elts[pc + 2].symbol;
28905796c8dcSSimon Schubert
28915796c8dcSSimon Schubert /* C++: The "address" of a reference should yield the address
28925796c8dcSSimon Schubert * of the object pointed to. Let value_addr() deal with it. */
28935796c8dcSSimon Schubert if (TYPE_CODE (SYMBOL_TYPE (var)) == TYPE_CODE_REF)
28945796c8dcSSimon Schubert goto default_case;
28955796c8dcSSimon Schubert
28965796c8dcSSimon Schubert (*pos) += 4;
28975796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
28985796c8dcSSimon Schubert {
28995796c8dcSSimon Schubert struct type *type =
29005796c8dcSSimon Schubert lookup_pointer_type (SYMBOL_TYPE (var));
29015796c8dcSSimon Schubert enum address_class sym_class = SYMBOL_CLASS (var);
29025796c8dcSSimon Schubert
29035796c8dcSSimon Schubert if (sym_class == LOC_CONST
29045796c8dcSSimon Schubert || sym_class == LOC_CONST_BYTES
29055796c8dcSSimon Schubert || sym_class == LOC_REGISTER)
29065796c8dcSSimon Schubert error (_("Attempt to take address of register or constant."));
29075796c8dcSSimon Schubert
29085796c8dcSSimon Schubert return
29095796c8dcSSimon Schubert value_zero (type, not_lval);
29105796c8dcSSimon Schubert }
29115796c8dcSSimon Schubert else
29125796c8dcSSimon Schubert return address_of_variable (var, exp->elts[pc + 1].block);
29135796c8dcSSimon Schubert
29145796c8dcSSimon Schubert case OP_SCOPE:
29155796c8dcSSimon Schubert tem = longest_to_int (exp->elts[pc + 2].longconst);
29165796c8dcSSimon Schubert (*pos) += 5 + BYTES_TO_EXP_ELEM (tem + 1);
29175796c8dcSSimon Schubert x = value_aggregate_elt (exp->elts[pc + 1].type,
29185796c8dcSSimon Schubert &exp->elts[pc + 3].string,
2919cf7f2e2dSJohn Marino NULL, 1, noside);
29205796c8dcSSimon Schubert if (x == NULL)
29215796c8dcSSimon Schubert error (_("There is no field named %s"), &exp->elts[pc + 3].string);
29225796c8dcSSimon Schubert return x;
29235796c8dcSSimon Schubert
29245796c8dcSSimon Schubert default:
29255796c8dcSSimon Schubert default_case:
29265796c8dcSSimon Schubert x = evaluate_subexp (NULL_TYPE, exp, pos, noside);
29275796c8dcSSimon Schubert default_case_after_eval:
29285796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS)
29295796c8dcSSimon Schubert {
29305796c8dcSSimon Schubert struct type *type = check_typedef (value_type (x));
29315796c8dcSSimon Schubert
2932*ef5ccd6cSJohn Marino if (TYPE_CODE (type) == TYPE_CODE_REF)
29335796c8dcSSimon Schubert return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
29345796c8dcSSimon Schubert not_lval);
2935*ef5ccd6cSJohn Marino else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
2936*ef5ccd6cSJohn Marino return value_zero (lookup_pointer_type (value_type (x)),
2937*ef5ccd6cSJohn Marino not_lval);
29385796c8dcSSimon Schubert else
2939c50c785cSJohn Marino error (_("Attempt to take address of "
2940c50c785cSJohn Marino "value not located in memory."));
29415796c8dcSSimon Schubert }
29425796c8dcSSimon Schubert return value_addr (x);
29435796c8dcSSimon Schubert }
29445796c8dcSSimon Schubert }
29455796c8dcSSimon Schubert
29465796c8dcSSimon Schubert /* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
29475796c8dcSSimon Schubert When used in contexts where arrays will be coerced anyway, this is
29485796c8dcSSimon Schubert equivalent to `evaluate_subexp' but much faster because it avoids
29495796c8dcSSimon Schubert actually fetching array contents (perhaps obsolete now that we have
29505796c8dcSSimon Schubert value_lazy()).
29515796c8dcSSimon Schubert
29525796c8dcSSimon Schubert Note that we currently only do the coercion for C expressions, where
29535796c8dcSSimon Schubert arrays are zero based and the coercion is correct. For other languages,
29545796c8dcSSimon Schubert with nonzero based arrays, coercion loses. Use CAST_IS_CONVERSION
2955c50c785cSJohn Marino to decide if coercion is appropriate. */
29565796c8dcSSimon Schubert
29575796c8dcSSimon Schubert struct value *
evaluate_subexp_with_coercion(struct expression * exp,int * pos,enum noside noside)29585796c8dcSSimon Schubert evaluate_subexp_with_coercion (struct expression *exp,
29595796c8dcSSimon Schubert int *pos, enum noside noside)
29605796c8dcSSimon Schubert {
29615796c8dcSSimon Schubert enum exp_opcode op;
29625796c8dcSSimon Schubert int pc;
29635796c8dcSSimon Schubert struct value *val;
29645796c8dcSSimon Schubert struct symbol *var;
29655796c8dcSSimon Schubert struct type *type;
29665796c8dcSSimon Schubert
29675796c8dcSSimon Schubert pc = (*pos);
29685796c8dcSSimon Schubert op = exp->elts[pc].opcode;
29695796c8dcSSimon Schubert
29705796c8dcSSimon Schubert switch (op)
29715796c8dcSSimon Schubert {
29725796c8dcSSimon Schubert case OP_VAR_VALUE:
29735796c8dcSSimon Schubert var = exp->elts[pc + 2].symbol;
29745796c8dcSSimon Schubert type = check_typedef (SYMBOL_TYPE (var));
29755796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_ARRAY
2976c50c785cSJohn Marino && !TYPE_VECTOR (type)
2977cf7f2e2dSJohn Marino && CAST_IS_CONVERSION (exp->language_defn))
29785796c8dcSSimon Schubert {
29795796c8dcSSimon Schubert (*pos) += 4;
29805796c8dcSSimon Schubert val = address_of_variable (var, exp->elts[pc + 1].block);
29815796c8dcSSimon Schubert return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
29825796c8dcSSimon Schubert val);
29835796c8dcSSimon Schubert }
29845796c8dcSSimon Schubert /* FALLTHROUGH */
29855796c8dcSSimon Schubert
29865796c8dcSSimon Schubert default:
29875796c8dcSSimon Schubert return evaluate_subexp (NULL_TYPE, exp, pos, noside);
29885796c8dcSSimon Schubert }
29895796c8dcSSimon Schubert }
29905796c8dcSSimon Schubert
29915796c8dcSSimon Schubert /* Evaluate a subexpression of EXP, at index *POS,
29925796c8dcSSimon Schubert and return a value for the size of that subexpression.
29935796c8dcSSimon Schubert Advance *POS over the subexpression. */
29945796c8dcSSimon Schubert
29955796c8dcSSimon Schubert static struct value *
evaluate_subexp_for_sizeof(struct expression * exp,int * pos)29965796c8dcSSimon Schubert evaluate_subexp_for_sizeof (struct expression *exp, int *pos)
29975796c8dcSSimon Schubert {
29985796c8dcSSimon Schubert /* FIXME: This should be size_t. */
29995796c8dcSSimon Schubert struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
30005796c8dcSSimon Schubert enum exp_opcode op;
30015796c8dcSSimon Schubert int pc;
30025796c8dcSSimon Schubert struct type *type;
30035796c8dcSSimon Schubert struct value *val;
30045796c8dcSSimon Schubert
30055796c8dcSSimon Schubert pc = (*pos);
30065796c8dcSSimon Schubert op = exp->elts[pc].opcode;
30075796c8dcSSimon Schubert
30085796c8dcSSimon Schubert switch (op)
30095796c8dcSSimon Schubert {
30105796c8dcSSimon Schubert /* This case is handled specially
30115796c8dcSSimon Schubert so that we avoid creating a value for the result type.
30125796c8dcSSimon Schubert If the result type is very big, it's desirable not to
30135796c8dcSSimon Schubert create a value unnecessarily. */
30145796c8dcSSimon Schubert case UNOP_IND:
30155796c8dcSSimon Schubert (*pos)++;
30165796c8dcSSimon Schubert val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
30175796c8dcSSimon Schubert type = check_typedef (value_type (val));
30185796c8dcSSimon Schubert if (TYPE_CODE (type) != TYPE_CODE_PTR
30195796c8dcSSimon Schubert && TYPE_CODE (type) != TYPE_CODE_REF
30205796c8dcSSimon Schubert && TYPE_CODE (type) != TYPE_CODE_ARRAY)
30215796c8dcSSimon Schubert error (_("Attempt to take contents of a non-pointer value."));
30225796c8dcSSimon Schubert type = check_typedef (TYPE_TARGET_TYPE (type));
30235796c8dcSSimon Schubert return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
30245796c8dcSSimon Schubert
30255796c8dcSSimon Schubert case UNOP_MEMVAL:
30265796c8dcSSimon Schubert (*pos) += 3;
30275796c8dcSSimon Schubert type = check_typedef (exp->elts[pc + 1].type);
30285796c8dcSSimon Schubert return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
30295796c8dcSSimon Schubert
3030*ef5ccd6cSJohn Marino case UNOP_MEMVAL_TYPE:
3031*ef5ccd6cSJohn Marino (*pos) += 1;
3032*ef5ccd6cSJohn Marino val = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
3033*ef5ccd6cSJohn Marino type = check_typedef (value_type (val));
3034*ef5ccd6cSJohn Marino return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
3035*ef5ccd6cSJohn Marino
30365796c8dcSSimon Schubert case OP_VAR_VALUE:
30375796c8dcSSimon Schubert (*pos) += 4;
30385796c8dcSSimon Schubert type = check_typedef (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
30395796c8dcSSimon Schubert return
30405796c8dcSSimon Schubert value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
30415796c8dcSSimon Schubert
30425796c8dcSSimon Schubert default:
30435796c8dcSSimon Schubert val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
30445796c8dcSSimon Schubert return value_from_longest (size_type,
30455796c8dcSSimon Schubert (LONGEST) TYPE_LENGTH (value_type (val)));
30465796c8dcSSimon Schubert }
30475796c8dcSSimon Schubert }
30485796c8dcSSimon Schubert
30495796c8dcSSimon Schubert /* Parse a type expression in the string [P..P+LENGTH). */
30505796c8dcSSimon Schubert
30515796c8dcSSimon Schubert struct type *
parse_and_eval_type(char * p,int length)30525796c8dcSSimon Schubert parse_and_eval_type (char *p, int length)
30535796c8dcSSimon Schubert {
30545796c8dcSSimon Schubert char *tmp = (char *) alloca (length + 4);
30555796c8dcSSimon Schubert struct expression *expr;
3056cf7f2e2dSJohn Marino
30575796c8dcSSimon Schubert tmp[0] = '(';
30585796c8dcSSimon Schubert memcpy (tmp + 1, p, length);
30595796c8dcSSimon Schubert tmp[length + 1] = ')';
30605796c8dcSSimon Schubert tmp[length + 2] = '0';
30615796c8dcSSimon Schubert tmp[length + 3] = '\0';
30625796c8dcSSimon Schubert expr = parse_expression (tmp);
30635796c8dcSSimon Schubert if (expr->elts[0].opcode != UNOP_CAST)
30645796c8dcSSimon Schubert error (_("Internal error in eval_type."));
30655796c8dcSSimon Schubert return expr->elts[1].type;
30665796c8dcSSimon Schubert }
30675796c8dcSSimon Schubert
30685796c8dcSSimon Schubert int
calc_f77_array_dims(struct type * array_type)30695796c8dcSSimon Schubert calc_f77_array_dims (struct type *array_type)
30705796c8dcSSimon Schubert {
30715796c8dcSSimon Schubert int ndimen = 1;
30725796c8dcSSimon Schubert struct type *tmp_type;
30735796c8dcSSimon Schubert
30745796c8dcSSimon Schubert if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
30755796c8dcSSimon Schubert error (_("Can't get dimensions for a non-array type"));
30765796c8dcSSimon Schubert
30775796c8dcSSimon Schubert tmp_type = array_type;
30785796c8dcSSimon Schubert
30795796c8dcSSimon Schubert while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
30805796c8dcSSimon Schubert {
30815796c8dcSSimon Schubert if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
30825796c8dcSSimon Schubert ++ndimen;
30835796c8dcSSimon Schubert }
30845796c8dcSSimon Schubert return ndimen;
30855796c8dcSSimon Schubert }
3086