2004-04-26 Orjan Friberg <orjanf@axis.com>
[deliverable/binutils-gdb.git] / gdb / valops.c
CommitLineData
c906108c 1/* Perform non-arithmetic operations on values, for GDB.
f23631e4 2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
63d06c5c 3 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
f23631e4 4 Free Software Foundation, Inc.
c906108c 5
c5aa993b 6 This file is part of GDB.
c906108c 7
c5aa993b
JM
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
c906108c 12
c5aa993b
JM
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
c906108c 17
c5aa993b
JM
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
c906108c
SS
22
23#include "defs.h"
24#include "symtab.h"
25#include "gdbtypes.h"
26#include "value.h"
27#include "frame.h"
28#include "inferior.h"
29#include "gdbcore.h"
30#include "target.h"
31#include "demangle.h"
32#include "language.h"
33#include "gdbcmd.h"
4e052eda 34#include "regcache.h"
015a42b4 35#include "cp-abi.h"
fe898f56 36#include "block.h"
04714b91 37#include "infcall.h"
de4f826b 38#include "dictionary.h"
b6429628 39#include "cp-support.h"
c906108c
SS
40
41#include <errno.h>
42#include "gdb_string.h"
4a1970e4 43#include "gdb_assert.h"
79c2c32d 44#include "cp-support.h"
c906108c 45
070ad9f0 46extern int overload_debug;
c906108c
SS
47/* Local functions. */
48
ad2f7632
DJ
49static int typecmp (int staticp, int varargs, int nargs,
50 struct field t1[], struct value *t2[]);
c906108c 51
f23631e4 52static CORE_ADDR value_push (CORE_ADDR, struct value *);
c906108c 53
f23631e4 54static struct value *search_struct_field (char *, struct value *, int,
a14ed312 55 struct type *, int);
c906108c 56
f23631e4
AC
57static struct value *search_struct_method (char *, struct value **,
58 struct value **,
a14ed312 59 int, int *, struct type *);
c906108c 60
8d577d32
DC
61static int find_oload_champ_namespace (struct type **arg_types, int nargs,
62 const char *func_name,
63 const char *qualified_name,
64 struct symbol ***oload_syms,
65 struct badness_vector **oload_champ_bv);
66
67static
68int find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
69 const char *func_name,
70 const char *qualified_name,
71 int namespace_len,
72 struct symbol ***oload_syms,
73 struct badness_vector **oload_champ_bv,
74 int *oload_champ);
75
76static int find_oload_champ (struct type **arg_types, int nargs, int method,
77 int num_fns,
78 struct fn_field *fns_ptr,
79 struct symbol **oload_syms,
80 struct badness_vector **oload_champ_bv);
81
82static int oload_method_static (int method, struct fn_field *fns_ptr,
83 int index);
84
85enum oload_classification { STANDARD, NON_STANDARD, INCOMPATIBLE };
86
87static enum
88oload_classification classify_oload_match (struct badness_vector
89 * oload_champ_bv,
90 int nargs,
91 int static_offset);
92
a14ed312 93static int check_field_in (struct type *, const char *);
c906108c 94
79c2c32d
DC
95static struct value *value_struct_elt_for_reference (struct type *domain,
96 int offset,
97 struct type *curtype,
98 char *name,
63d06c5c
DC
99 struct type *intype,
100 enum noside noside);
79c2c32d
DC
101
102static struct value *value_namespace_elt (const struct type *curtype,
63d06c5c 103 char *name,
79c2c32d
DC
104 enum noside noside);
105
63d06c5c
DC
106static struct value *value_maybe_namespace_elt (const struct type *curtype,
107 char *name,
108 enum noside noside);
109
a14ed312 110static CORE_ADDR allocate_space_in_inferior (int);
c906108c 111
f23631e4 112static struct value *cast_into_complex (struct type *, struct value *);
c906108c 113
f23631e4 114static struct fn_field *find_method_list (struct value ** argp, char *method,
4a1970e4 115 int offset,
a14ed312
KB
116 struct type *type, int *num_fns,
117 struct type **basetype,
118 int *boffset);
7a292a7a 119
a14ed312 120void _initialize_valops (void);
c906108c 121
c906108c
SS
122/* Flag for whether we want to abandon failed expression evals by default. */
123
124#if 0
125static int auto_abandon = 0;
126#endif
127
128int overload_resolution = 0;
242bfc55 129
c906108c
SS
130/* Find the address of function name NAME in the inferior. */
131
f23631e4 132struct value *
3bada2a2 133find_function_in_inferior (const char *name)
c906108c 134{
52f0bd74 135 struct symbol *sym;
176620f1 136 sym = lookup_symbol (name, 0, VAR_DOMAIN, 0, NULL);
c906108c
SS
137 if (sym != NULL)
138 {
139 if (SYMBOL_CLASS (sym) != LOC_BLOCK)
140 {
141 error ("\"%s\" exists in this program but is not a function.",
142 name);
143 }
144 return value_of_variable (sym, NULL);
145 }
146 else
147 {
c5aa993b 148 struct minimal_symbol *msymbol = lookup_minimal_symbol (name, NULL, NULL);
c906108c
SS
149 if (msymbol != NULL)
150 {
151 struct type *type;
4478b372 152 CORE_ADDR maddr;
c906108c
SS
153 type = lookup_pointer_type (builtin_type_char);
154 type = lookup_function_type (type);
155 type = lookup_pointer_type (type);
4478b372
JB
156 maddr = SYMBOL_VALUE_ADDRESS (msymbol);
157 return value_from_pointer (type, maddr);
c906108c
SS
158 }
159 else
160 {
c5aa993b 161 if (!target_has_execution)
c906108c 162 error ("evaluation of this expression requires the target program to be active");
c5aa993b 163 else
c906108c
SS
164 error ("evaluation of this expression requires the program to have a function \"%s\".", name);
165 }
166 }
167}
168
169/* Allocate NBYTES of space in the inferior using the inferior's malloc
170 and return a value that is a pointer to the allocated space. */
171
f23631e4 172struct value *
fba45db2 173value_allocate_space_in_inferior (int len)
c906108c 174{
f23631e4 175 struct value *blocklen;
5720643c 176 struct value *val = find_function_in_inferior (NAME_OF_MALLOC);
c906108c
SS
177
178 blocklen = value_from_longest (builtin_type_int, (LONGEST) len);
179 val = call_function_by_hand (val, 1, &blocklen);
180 if (value_logical_not (val))
181 {
182 if (!target_has_execution)
c5aa993b
JM
183 error ("No memory available to program now: you need to start the target first");
184 else
185 error ("No memory available to program: call to malloc failed");
c906108c
SS
186 }
187 return val;
188}
189
190static CORE_ADDR
fba45db2 191allocate_space_in_inferior (int len)
c906108c
SS
192{
193 return value_as_long (value_allocate_space_in_inferior (len));
194}
195
196/* Cast value ARG2 to type TYPE and return as a value.
197 More general than a C cast: accepts any two types of the same length,
198 and if ARG2 is an lvalue it can be cast into anything at all. */
199/* In C++, casts may change pointer or object representations. */
200
f23631e4
AC
201struct value *
202value_cast (struct type *type, struct value *arg2)
c906108c 203{
52f0bd74
AC
204 enum type_code code1;
205 enum type_code code2;
206 int scalar;
c906108c
SS
207 struct type *type2;
208
209 int convert_to_boolean = 0;
c5aa993b 210
c906108c
SS
211 if (VALUE_TYPE (arg2) == type)
212 return arg2;
213
214 CHECK_TYPEDEF (type);
215 code1 = TYPE_CODE (type);
c5aa993b 216 COERCE_REF (arg2);
c906108c
SS
217 type2 = check_typedef (VALUE_TYPE (arg2));
218
219 /* A cast to an undetermined-length array_type, such as (TYPE [])OBJECT,
220 is treated like a cast to (TYPE [N])OBJECT,
221 where N is sizeof(OBJECT)/sizeof(TYPE). */
222 if (code1 == TYPE_CODE_ARRAY)
223 {
224 struct type *element_type = TYPE_TARGET_TYPE (type);
225 unsigned element_length = TYPE_LENGTH (check_typedef (element_type));
226 if (element_length > 0
c5aa993b 227 && TYPE_ARRAY_UPPER_BOUND_TYPE (type) == BOUND_CANNOT_BE_DETERMINED)
c906108c
SS
228 {
229 struct type *range_type = TYPE_INDEX_TYPE (type);
230 int val_length = TYPE_LENGTH (type2);
231 LONGEST low_bound, high_bound, new_length;
232 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
233 low_bound = 0, high_bound = 0;
234 new_length = val_length / element_length;
235 if (val_length % element_length != 0)
c5aa993b 236 warning ("array element type size does not divide object size in cast");
c906108c
SS
237 /* FIXME-type-allocation: need a way to free this type when we are
238 done with it. */
239 range_type = create_range_type ((struct type *) NULL,
240 TYPE_TARGET_TYPE (range_type),
241 low_bound,
242 new_length + low_bound - 1);
243 VALUE_TYPE (arg2) = create_array_type ((struct type *) NULL,
244 element_type, range_type);
245 return arg2;
246 }
247 }
248
249 if (current_language->c_style_arrays
250 && TYPE_CODE (type2) == TYPE_CODE_ARRAY)
251 arg2 = value_coerce_array (arg2);
252
253 if (TYPE_CODE (type2) == TYPE_CODE_FUNC)
254 arg2 = value_coerce_function (arg2);
255
256 type2 = check_typedef (VALUE_TYPE (arg2));
257 COERCE_VARYING_ARRAY (arg2, type2);
258 code2 = TYPE_CODE (type2);
259
260 if (code1 == TYPE_CODE_COMPLEX)
261 return cast_into_complex (type, arg2);
262 if (code1 == TYPE_CODE_BOOL)
263 {
264 code1 = TYPE_CODE_INT;
265 convert_to_boolean = 1;
266 }
267 if (code1 == TYPE_CODE_CHAR)
268 code1 = TYPE_CODE_INT;
269 if (code2 == TYPE_CODE_BOOL || code2 == TYPE_CODE_CHAR)
270 code2 = TYPE_CODE_INT;
271
272 scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
273 || code2 == TYPE_CODE_ENUM || code2 == TYPE_CODE_RANGE);
274
c5aa993b 275 if (code1 == TYPE_CODE_STRUCT
c906108c
SS
276 && code2 == TYPE_CODE_STRUCT
277 && TYPE_NAME (type) != 0)
278 {
279 /* Look in the type of the source to see if it contains the
7b83ea04
AC
280 type of the target as a superclass. If so, we'll need to
281 offset the object in addition to changing its type. */
f23631e4 282 struct value *v = search_struct_field (type_name_no_tag (type),
c906108c
SS
283 arg2, 0, type2, 1);
284 if (v)
285 {
286 VALUE_TYPE (v) = type;
287 return v;
288 }
289 }
290 if (code1 == TYPE_CODE_FLT && scalar)
291 return value_from_double (type, value_as_double (arg2));
292 else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM
293 || code1 == TYPE_CODE_RANGE)
294 && (scalar || code2 == TYPE_CODE_PTR))
295 {
296 LONGEST longest;
c5aa993b 297
f83f82bc
AC
298 if (deprecated_hp_som_som_object_present /* if target compiled by HP aCC */
299 && (code2 == TYPE_CODE_PTR))
c5aa993b
JM
300 {
301 unsigned int *ptr;
f23631e4 302 struct value *retvalp;
c5aa993b
JM
303
304 switch (TYPE_CODE (TYPE_TARGET_TYPE (type2)))
305 {
306 /* With HP aCC, pointers to data members have a bias */
307 case TYPE_CODE_MEMBER:
308 retvalp = value_from_longest (type, value_as_long (arg2));
716c501e 309 /* force evaluation */
802db21b 310 ptr = (unsigned int *) VALUE_CONTENTS (retvalp);
c5aa993b
JM
311 *ptr &= ~0x20000000; /* zap 29th bit to remove bias */
312 return retvalp;
313
314 /* While pointers to methods don't really point to a function */
315 case TYPE_CODE_METHOD:
316 error ("Pointers to methods not supported with HP aCC");
317
318 default:
319 break; /* fall out and go to normal handling */
320 }
321 }
2bf1f4a1
JB
322
323 /* When we cast pointers to integers, we mustn't use
324 POINTER_TO_ADDRESS to find the address the pointer
325 represents, as value_as_long would. GDB should evaluate
326 expressions just as the compiler would --- and the compiler
327 sees a cast as a simple reinterpretation of the pointer's
328 bits. */
329 if (code2 == TYPE_CODE_PTR)
330 longest = extract_unsigned_integer (VALUE_CONTENTS (arg2),
331 TYPE_LENGTH (type2));
332 else
333 longest = value_as_long (arg2);
802db21b 334 return value_from_longest (type, convert_to_boolean ?
716c501e 335 (LONGEST) (longest ? 1 : 0) : longest);
c906108c 336 }
802db21b 337 else if (code1 == TYPE_CODE_PTR && (code2 == TYPE_CODE_INT ||
23e04971
MS
338 code2 == TYPE_CODE_ENUM ||
339 code2 == TYPE_CODE_RANGE))
634acd5f 340 {
4603e466
DT
341 /* TYPE_LENGTH (type) is the length of a pointer, but we really
342 want the length of an address! -- we are really dealing with
343 addresses (i.e., gdb representations) not pointers (i.e.,
344 target representations) here.
345
346 This allows things like "print *(int *)0x01000234" to work
347 without printing a misleading message -- which would
348 otherwise occur when dealing with a target having two byte
349 pointers and four byte addresses. */
350
351 int addr_bit = TARGET_ADDR_BIT;
352
634acd5f 353 LONGEST longest = value_as_long (arg2);
4603e466 354 if (addr_bit < sizeof (LONGEST) * HOST_CHAR_BIT)
634acd5f 355 {
4603e466
DT
356 if (longest >= ((LONGEST) 1 << addr_bit)
357 || longest <= -((LONGEST) 1 << addr_bit))
634acd5f
AC
358 warning ("value truncated");
359 }
360 return value_from_longest (type, longest);
361 }
c906108c
SS
362 else if (TYPE_LENGTH (type) == TYPE_LENGTH (type2))
363 {
364 if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
365 {
366 struct type *t1 = check_typedef (TYPE_TARGET_TYPE (type));
367 struct type *t2 = check_typedef (TYPE_TARGET_TYPE (type2));
c5aa993b 368 if (TYPE_CODE (t1) == TYPE_CODE_STRUCT
c906108c
SS
369 && TYPE_CODE (t2) == TYPE_CODE_STRUCT
370 && !value_logical_not (arg2))
371 {
f23631e4 372 struct value *v;
c906108c
SS
373
374 /* Look in the type of the source to see if it contains the
7b83ea04
AC
375 type of the target as a superclass. If so, we'll need to
376 offset the pointer rather than just change its type. */
c906108c
SS
377 if (TYPE_NAME (t1) != NULL)
378 {
379 v = search_struct_field (type_name_no_tag (t1),
380 value_ind (arg2), 0, t2, 1);
381 if (v)
382 {
383 v = value_addr (v);
384 VALUE_TYPE (v) = type;
385 return v;
386 }
387 }
388
389 /* Look in the type of the target to see if it contains the
7b83ea04
AC
390 type of the source as a superclass. If so, we'll need to
391 offset the pointer rather than just change its type.
392 FIXME: This fails silently with virtual inheritance. */
c906108c
SS
393 if (TYPE_NAME (t2) != NULL)
394 {
395 v = search_struct_field (type_name_no_tag (t2),
c5aa993b 396 value_zero (t1, not_lval), 0, t1, 1);
c906108c
SS
397 if (v)
398 {
d174216d
JB
399 CORE_ADDR addr2 = value_as_address (arg2);
400 addr2 -= (VALUE_ADDRESS (v)
401 + VALUE_OFFSET (v)
402 + VALUE_EMBEDDED_OFFSET (v));
403 return value_from_pointer (type, addr2);
c906108c
SS
404 }
405 }
406 }
407 /* No superclass found, just fall through to change ptr type. */
408 }
409 VALUE_TYPE (arg2) = type;
2b127877 410 arg2 = value_change_enclosing_type (arg2, type);
c5aa993b 411 VALUE_POINTED_TO_OFFSET (arg2) = 0; /* pai: chk_val */
c906108c
SS
412 return arg2;
413 }
c906108c
SS
414 else if (VALUE_LVAL (arg2) == lval_memory)
415 {
416 return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2),
417 VALUE_BFD_SECTION (arg2));
418 }
419 else if (code1 == TYPE_CODE_VOID)
420 {
421 return value_zero (builtin_type_void, not_lval);
422 }
423 else
424 {
425 error ("Invalid cast.");
426 return 0;
427 }
428}
429
430/* Create a value of type TYPE that is zero, and return it. */
431
f23631e4 432struct value *
fba45db2 433value_zero (struct type *type, enum lval_type lv)
c906108c 434{
f23631e4 435 struct value *val = allocate_value (type);
c906108c
SS
436
437 memset (VALUE_CONTENTS (val), 0, TYPE_LENGTH (check_typedef (type)));
438 VALUE_LVAL (val) = lv;
439
440 return val;
441}
442
070ad9f0 443/* Return a value with type TYPE located at ADDR.
c906108c
SS
444
445 Call value_at only if the data needs to be fetched immediately;
446 if we can be 'lazy' and defer the fetch, perhaps indefinately, call
447 value_at_lazy instead. value_at_lazy simply records the address of
070ad9f0
DB
448 the data and sets the lazy-evaluation-required flag. The lazy flag
449 is tested in the VALUE_CONTENTS macro, which is used if and when
450 the contents are actually required.
c906108c
SS
451
452 Note: value_at does *NOT* handle embedded offsets; perform such
453 adjustments before or after calling it. */
454
f23631e4 455struct value *
fba45db2 456value_at (struct type *type, CORE_ADDR addr, asection *sect)
c906108c 457{
f23631e4 458 struct value *val;
c906108c
SS
459
460 if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
461 error ("Attempt to dereference a generic pointer.");
462
463 val = allocate_value (type);
464
75af7f68 465 read_memory (addr, VALUE_CONTENTS_ALL_RAW (val), TYPE_LENGTH (type));
c906108c
SS
466
467 VALUE_LVAL (val) = lval_memory;
468 VALUE_ADDRESS (val) = addr;
469 VALUE_BFD_SECTION (val) = sect;
470
471 return val;
472}
473
474/* Return a lazy value with type TYPE located at ADDR (cf. value_at). */
475
f23631e4 476struct value *
fba45db2 477value_at_lazy (struct type *type, CORE_ADDR addr, asection *sect)
c906108c 478{
f23631e4 479 struct value *val;
c906108c
SS
480
481 if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
482 error ("Attempt to dereference a generic pointer.");
483
484 val = allocate_value (type);
485
486 VALUE_LVAL (val) = lval_memory;
487 VALUE_ADDRESS (val) = addr;
488 VALUE_LAZY (val) = 1;
489 VALUE_BFD_SECTION (val) = sect;
490
491 return val;
492}
493
070ad9f0
DB
494/* Called only from the VALUE_CONTENTS and VALUE_CONTENTS_ALL macros,
495 if the current data for a variable needs to be loaded into
496 VALUE_CONTENTS(VAL). Fetches the data from the user's process, and
c906108c
SS
497 clears the lazy flag to indicate that the data in the buffer is valid.
498
499 If the value is zero-length, we avoid calling read_memory, which would
500 abort. We mark the value as fetched anyway -- all 0 bytes of it.
501
502 This function returns a value because it is used in the VALUE_CONTENTS
503 macro as part of an expression, where a void would not work. The
504 value is ignored. */
505
506int
f23631e4 507value_fetch_lazy (struct value *val)
c906108c
SS
508{
509 CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
510 int length = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (val));
511
c5aa993b 512 struct type *type = VALUE_TYPE (val);
75af7f68 513 if (length)
d4b2399a 514 read_memory (addr, VALUE_CONTENTS_ALL_RAW (val), length);
802db21b 515
c906108c
SS
516 VALUE_LAZY (val) = 0;
517 return 0;
518}
519
520
521/* Store the contents of FROMVAL into the location of TOVAL.
522 Return a new value with the location of TOVAL and contents of FROMVAL. */
523
f23631e4
AC
524struct value *
525value_assign (struct value *toval, struct value *fromval)
c906108c 526{
52f0bd74 527 struct type *type;
f23631e4 528 struct value *val;
d9d9c31f 529 char raw_buffer[MAX_REGISTER_SIZE];
c906108c 530 int use_buffer = 0;
cb741690 531 struct frame_id old_frame;
c906108c
SS
532
533 if (!toval->modifiable)
534 error ("Left operand of assignment is not a modifiable lvalue.");
535
536 COERCE_REF (toval);
537
538 type = VALUE_TYPE (toval);
539 if (VALUE_LVAL (toval) != lval_internalvar)
540 fromval = value_cast (type, fromval);
541 else
542 COERCE_ARRAY (fromval);
543 CHECK_TYPEDEF (type);
544
cb741690
DJ
545 /* Since modifying a register can trash the frame chain, and modifying memory
546 can trash the frame cache, we save the old frame and then restore the new
547 frame afterwards. */
548 old_frame = get_frame_id (deprecated_selected_frame);
549
c906108c
SS
550 switch (VALUE_LVAL (toval))
551 {
552 case lval_internalvar:
553 set_internalvar (VALUE_INTERNALVAR (toval), fromval);
554 val = value_copy (VALUE_INTERNALVAR (toval)->value);
2b127877 555 val = value_change_enclosing_type (val, VALUE_ENCLOSING_TYPE (fromval));
c906108c
SS
556 VALUE_EMBEDDED_OFFSET (val) = VALUE_EMBEDDED_OFFSET (fromval);
557 VALUE_POINTED_TO_OFFSET (val) = VALUE_POINTED_TO_OFFSET (fromval);
558 return val;
559
560 case lval_internalvar_component:
561 set_internalvar_component (VALUE_INTERNALVAR (toval),
562 VALUE_OFFSET (toval),
563 VALUE_BITPOS (toval),
564 VALUE_BITSIZE (toval),
565 fromval);
566 break;
567
568 case lval_memory:
569 {
570 char *dest_buffer;
c5aa993b
JM
571 CORE_ADDR changed_addr;
572 int changed_len;
c906108c 573
c5aa993b
JM
574 if (VALUE_BITSIZE (toval))
575 {
c906108c
SS
576 char buffer[sizeof (LONGEST)];
577 /* We assume that the argument to read_memory is in units of
578 host chars. FIXME: Is that correct? */
579 changed_len = (VALUE_BITPOS (toval)
c5aa993b
JM
580 + VALUE_BITSIZE (toval)
581 + HOST_CHAR_BIT - 1)
582 / HOST_CHAR_BIT;
c906108c
SS
583
584 if (changed_len > (int) sizeof (LONGEST))
585 error ("Can't handle bitfields which don't fit in a %d bit word.",
baa6f10b 586 (int) sizeof (LONGEST) * HOST_CHAR_BIT);
c906108c
SS
587
588 read_memory (VALUE_ADDRESS (toval) + VALUE_OFFSET (toval),
589 buffer, changed_len);
590 modify_field (buffer, value_as_long (fromval),
591 VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
592 changed_addr = VALUE_ADDRESS (toval) + VALUE_OFFSET (toval);
593 dest_buffer = buffer;
594 }
595 else if (use_buffer)
596 {
597 changed_addr = VALUE_ADDRESS (toval) + VALUE_OFFSET (toval);
598 changed_len = use_buffer;
599 dest_buffer = raw_buffer;
600 }
601 else
602 {
603 changed_addr = VALUE_ADDRESS (toval) + VALUE_OFFSET (toval);
604 changed_len = TYPE_LENGTH (type);
605 dest_buffer = VALUE_CONTENTS (fromval);
606 }
607
608 write_memory (changed_addr, dest_buffer, changed_len);
9a4105ab
AC
609 if (deprecated_memory_changed_hook)
610 deprecated_memory_changed_hook (changed_addr, changed_len);
e23792cc 611 target_changed_event ();
c906108c
SS
612 }
613 break;
614
c906108c 615 case lval_reg_frame_relative:
492254e9 616 case lval_register:
c906108c 617 {
c906108c 618 struct frame_info *frame;
ff2e87ac 619 int value_reg;
c906108c
SS
620
621 /* Figure out which frame this is in currently. */
492254e9
AC
622 if (VALUE_LVAL (toval) == lval_register)
623 {
624 frame = get_current_frame ();
625 value_reg = VALUE_REGNO (toval);
626 }
627 else
628 {
1df6926e 629 frame = frame_find_by_id (VALUE_FRAME_ID (toval));
492254e9
AC
630 value_reg = VALUE_FRAME_REGNUM (toval);
631 }
c906108c
SS
632
633 if (!frame)
634 error ("Value being assigned to is no longer active.");
492254e9 635
ff2e87ac
AC
636 if (VALUE_LVAL (toval) == lval_reg_frame_relative
637 && CONVERT_REGISTER_P (VALUE_FRAME_REGNUM (toval), type))
492254e9 638 {
ff2e87ac
AC
639 /* If TOVAL is a special machine register requiring
640 conversion of program values to a special raw format. */
641 VALUE_TO_REGISTER (frame, VALUE_FRAME_REGNUM (toval),
642 type, VALUE_CONTENTS (fromval));
492254e9 643 }
c906108c 644 else
492254e9 645 {
ff2e87ac
AC
646 /* TOVAL is stored in a series of registers in the frame
647 specified by the structure. Copy that value out,
648 modify it, and copy it back in. */
649 int amount_copied;
650 int amount_to_copy;
651 char *buffer;
652 int reg_offset;
653 int byte_offset;
654 int regno;
655
656 /* Locate the first register that falls in the value that
657 needs to be transfered. Compute the offset of the
658 value in that register. */
659 {
660 int offset;
661 for (reg_offset = value_reg, offset = 0;
12c266ea 662 offset + DEPRECATED_REGISTER_RAW_SIZE (reg_offset) <= VALUE_OFFSET (toval);
ff2e87ac
AC
663 reg_offset++);
664 byte_offset = VALUE_OFFSET (toval) - offset;
665 }
c906108c 666
ff2e87ac
AC
667 /* Compute the number of register aligned values that need
668 to be copied. */
669 if (VALUE_BITSIZE (toval))
670 amount_to_copy = byte_offset + 1;
671 else
672 amount_to_copy = byte_offset + TYPE_LENGTH (type);
492254e9 673
ff2e87ac
AC
674 /* And a bounce buffer. Be slightly over generous. */
675 buffer = (char *) alloca (amount_to_copy + MAX_REGISTER_SIZE);
676
677 /* Copy it in. */
678 for (regno = reg_offset, amount_copied = 0;
679 amount_copied < amount_to_copy;
12c266ea 680 amount_copied += DEPRECATED_REGISTER_RAW_SIZE (regno), regno++)
ff2e87ac 681 frame_register_read (frame, regno, buffer + amount_copied);
492254e9 682
ff2e87ac
AC
683 /* Modify what needs to be modified. */
684 if (VALUE_BITSIZE (toval))
685 modify_field (buffer + byte_offset,
686 value_as_long (fromval),
687 VALUE_BITPOS (toval), VALUE_BITSIZE (toval));
688 else if (use_buffer)
689 memcpy (buffer + VALUE_OFFSET (toval), raw_buffer, use_buffer);
c906108c 690 else
ff2e87ac
AC
691 memcpy (buffer + byte_offset, VALUE_CONTENTS (fromval),
692 TYPE_LENGTH (type));
693
694 /* Copy it out. */
695 for (regno = reg_offset, amount_copied = 0;
696 amount_copied < amount_to_copy;
12c266ea 697 amount_copied += DEPRECATED_REGISTER_RAW_SIZE (regno), regno++)
ff2e87ac 698 put_frame_register (frame, regno, buffer + amount_copied);
c906108c 699
ff2e87ac 700 }
9a4105ab
AC
701 if (deprecated_register_changed_hook)
702 deprecated_register_changed_hook (-1);
e23792cc 703 target_changed_event ();
ff2e87ac 704 break;
c906108c 705 }
492254e9 706
c906108c
SS
707 default:
708 error ("Left operand of assignment is not an lvalue.");
709 }
710
cb741690
DJ
711 /* Assigning to the stack pointer, frame pointer, and other
712 (architecture and calling convention specific) registers may
713 cause the frame cache to be out of date. Assigning to memory
714 also can. We just do this on all assignments to registers or
715 memory, for simplicity's sake; I doubt the slowdown matters. */
716 switch (VALUE_LVAL (toval))
717 {
718 case lval_memory:
719 case lval_register:
720 case lval_reg_frame_relative:
721
722 reinit_frame_cache ();
723
724 /* Having destoroyed the frame cache, restore the selected frame. */
725
726 /* FIXME: cagney/2002-11-02: There has to be a better way of
727 doing this. Instead of constantly saving/restoring the
728 frame. Why not create a get_selected_frame() function that,
729 having saved the selected frame's ID can automatically
730 re-find the previously selected frame automatically. */
731
732 {
733 struct frame_info *fi = frame_find_by_id (old_frame);
734 if (fi != NULL)
735 select_frame (fi);
736 }
737
738 break;
739 default:
740 break;
741 }
742
c906108c
SS
743 /* If the field does not entirely fill a LONGEST, then zero the sign bits.
744 If the field is signed, and is negative, then sign extend. */
745 if ((VALUE_BITSIZE (toval) > 0)
746 && (VALUE_BITSIZE (toval) < 8 * (int) sizeof (LONGEST)))
747 {
748 LONGEST fieldval = value_as_long (fromval);
749 LONGEST valmask = (((ULONGEST) 1) << VALUE_BITSIZE (toval)) - 1;
750
751 fieldval &= valmask;
752 if (!TYPE_UNSIGNED (type) && (fieldval & (valmask ^ (valmask >> 1))))
753 fieldval |= ~valmask;
754
755 fromval = value_from_longest (type, fieldval);
756 }
757
758 val = value_copy (toval);
759 memcpy (VALUE_CONTENTS_RAW (val), VALUE_CONTENTS (fromval),
760 TYPE_LENGTH (type));
761 VALUE_TYPE (val) = type;
2b127877 762 val = value_change_enclosing_type (val, VALUE_ENCLOSING_TYPE (fromval));
c906108c
SS
763 VALUE_EMBEDDED_OFFSET (val) = VALUE_EMBEDDED_OFFSET (fromval);
764 VALUE_POINTED_TO_OFFSET (val) = VALUE_POINTED_TO_OFFSET (fromval);
c5aa993b 765
c906108c
SS
766 return val;
767}
768
769/* Extend a value VAL to COUNT repetitions of its type. */
770
f23631e4
AC
771struct value *
772value_repeat (struct value *arg1, int count)
c906108c 773{
f23631e4 774 struct value *val;
c906108c
SS
775
776 if (VALUE_LVAL (arg1) != lval_memory)
777 error ("Only values in memory can be extended with '@'.");
778 if (count < 1)
779 error ("Invalid number %d of repetitions.", count);
780
781 val = allocate_repeat_value (VALUE_ENCLOSING_TYPE (arg1), count);
782
783 read_memory (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1),
784 VALUE_CONTENTS_ALL_RAW (val),
785 TYPE_LENGTH (VALUE_ENCLOSING_TYPE (val)));
786 VALUE_LVAL (val) = lval_memory;
787 VALUE_ADDRESS (val) = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1);
788
789 return val;
790}
791
f23631e4 792struct value *
fba45db2 793value_of_variable (struct symbol *var, struct block *b)
c906108c 794{
f23631e4 795 struct value *val;
c906108c
SS
796 struct frame_info *frame = NULL;
797
798 if (!b)
799 frame = NULL; /* Use selected frame. */
800 else if (symbol_read_needs_frame (var))
801 {
802 frame = block_innermost_frame (b);
803 if (!frame)
c5aa993b 804 {
c906108c 805 if (BLOCK_FUNCTION (b)
de5ad195 806 && SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)))
c906108c 807 error ("No frame is currently executing in block %s.",
de5ad195 808 SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)));
c906108c
SS
809 else
810 error ("No frame is currently executing in specified block");
c5aa993b 811 }
c906108c
SS
812 }
813
814 val = read_var_value (var, frame);
815 if (!val)
de5ad195 816 error ("Address of symbol \"%s\" is unknown.", SYMBOL_PRINT_NAME (var));
c906108c
SS
817
818 return val;
819}
820
821/* Given a value which is an array, return a value which is a pointer to its
822 first element, regardless of whether or not the array has a nonzero lower
823 bound.
824
825 FIXME: A previous comment here indicated that this routine should be
826 substracting the array's lower bound. It's not clear to me that this
827 is correct. Given an array subscripting operation, it would certainly
828 work to do the adjustment here, essentially computing:
829
830 (&array[0] - (lowerbound * sizeof array[0])) + (index * sizeof array[0])
831
832 However I believe a more appropriate and logical place to account for
833 the lower bound is to do so in value_subscript, essentially computing:
834
835 (&array[0] + ((index - lowerbound) * sizeof array[0]))
836
837 As further evidence consider what would happen with operations other
838 than array subscripting, where the caller would get back a value that
839 had an address somewhere before the actual first element of the array,
840 and the information about the lower bound would be lost because of
841 the coercion to pointer type.
c5aa993b 842 */
c906108c 843
f23631e4
AC
844struct value *
845value_coerce_array (struct value *arg1)
c906108c 846{
52f0bd74 847 struct type *type = check_typedef (VALUE_TYPE (arg1));
c906108c
SS
848
849 if (VALUE_LVAL (arg1) != lval_memory)
850 error ("Attempt to take address of value not located in memory.");
851
4478b372
JB
852 return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
853 (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
c906108c
SS
854}
855
856/* Given a value which is a function, return a value which is a pointer
857 to it. */
858
f23631e4
AC
859struct value *
860value_coerce_function (struct value *arg1)
c906108c 861{
f23631e4 862 struct value *retval;
c906108c
SS
863
864 if (VALUE_LVAL (arg1) != lval_memory)
865 error ("Attempt to take address of value not located in memory.");
866
4478b372
JB
867 retval = value_from_pointer (lookup_pointer_type (VALUE_TYPE (arg1)),
868 (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
c906108c
SS
869 VALUE_BFD_SECTION (retval) = VALUE_BFD_SECTION (arg1);
870 return retval;
c5aa993b 871}
c906108c
SS
872
873/* Return a pointer value for the object for which ARG1 is the contents. */
874
f23631e4
AC
875struct value *
876value_addr (struct value *arg1)
c906108c 877{
f23631e4 878 struct value *arg2;
c906108c
SS
879
880 struct type *type = check_typedef (VALUE_TYPE (arg1));
881 if (TYPE_CODE (type) == TYPE_CODE_REF)
882 {
883 /* Copy the value, but change the type from (T&) to (T*).
7b83ea04
AC
884 We keep the same location information, which is efficient,
885 and allows &(&X) to get the location containing the reference. */
c906108c
SS
886 arg2 = value_copy (arg1);
887 VALUE_TYPE (arg2) = lookup_pointer_type (TYPE_TARGET_TYPE (type));
888 return arg2;
889 }
890 if (TYPE_CODE (type) == TYPE_CODE_FUNC)
891 return value_coerce_function (arg1);
892
893 if (VALUE_LVAL (arg1) != lval_memory)
894 error ("Attempt to take address of value not located in memory.");
895
c5aa993b 896 /* Get target memory address */
4478b372
JB
897 arg2 = value_from_pointer (lookup_pointer_type (VALUE_TYPE (arg1)),
898 (VALUE_ADDRESS (arg1)
899 + VALUE_OFFSET (arg1)
900 + VALUE_EMBEDDED_OFFSET (arg1)));
c906108c
SS
901
902 /* This may be a pointer to a base subobject; so remember the
c5aa993b 903 full derived object's type ... */
2b127877 904 arg2 = value_change_enclosing_type (arg2, lookup_pointer_type (VALUE_ENCLOSING_TYPE (arg1)));
c5aa993b
JM
905 /* ... and also the relative position of the subobject in the full object */
906 VALUE_POINTED_TO_OFFSET (arg2) = VALUE_EMBEDDED_OFFSET (arg1);
c906108c
SS
907 VALUE_BFD_SECTION (arg2) = VALUE_BFD_SECTION (arg1);
908 return arg2;
909}
910
911/* Given a value of a pointer type, apply the C unary * operator to it. */
912
f23631e4
AC
913struct value *
914value_ind (struct value *arg1)
c906108c
SS
915{
916 struct type *base_type;
f23631e4 917 struct value *arg2;
c906108c
SS
918
919 COERCE_ARRAY (arg1);
920
921 base_type = check_typedef (VALUE_TYPE (arg1));
922
923 if (TYPE_CODE (base_type) == TYPE_CODE_MEMBER)
924 error ("not implemented: member types in value_ind");
925
926 /* Allow * on an integer so we can cast it to whatever we want.
927 This returns an int, which seems like the most C-like thing
928 to do. "long long" variables are rare enough that
929 BUILTIN_TYPE_LONGEST would seem to be a mistake. */
930 if (TYPE_CODE (base_type) == TYPE_CODE_INT)
56468235
DH
931 return value_at_lazy (builtin_type_int,
932 (CORE_ADDR) value_as_long (arg1),
933 VALUE_BFD_SECTION (arg1));
c906108c
SS
934 else if (TYPE_CODE (base_type) == TYPE_CODE_PTR)
935 {
936 struct type *enc_type;
937 /* We may be pointing to something embedded in a larger object */
c5aa993b 938 /* Get the real type of the enclosing object */
c906108c
SS
939 enc_type = check_typedef (VALUE_ENCLOSING_TYPE (arg1));
940 enc_type = TYPE_TARGET_TYPE (enc_type);
c5aa993b
JM
941 /* Retrieve the enclosing object pointed to */
942 arg2 = value_at_lazy (enc_type,
1aa20aa8 943 value_as_address (arg1) - VALUE_POINTED_TO_OFFSET (arg1),
c5aa993b
JM
944 VALUE_BFD_SECTION (arg1));
945 /* Re-adjust type */
c906108c
SS
946 VALUE_TYPE (arg2) = TYPE_TARGET_TYPE (base_type);
947 /* Add embedding info */
2b127877 948 arg2 = value_change_enclosing_type (arg2, enc_type);
c906108c
SS
949 VALUE_EMBEDDED_OFFSET (arg2) = VALUE_POINTED_TO_OFFSET (arg1);
950
951 /* We may be pointing to an object of some derived type */
952 arg2 = value_full_object (arg2, NULL, 0, 0, 0);
953 return arg2;
954 }
955
956 error ("Attempt to take contents of a non-pointer value.");
c5aa993b 957 return 0; /* For lint -- never reached */
c906108c
SS
958}
959\f
960/* Pushing small parts of stack frames. */
961
962/* Push one word (the size of object that a register holds). */
963
964CORE_ADDR
fba45db2 965push_word (CORE_ADDR sp, ULONGEST word)
c906108c 966{
52f0bd74 967 int len = DEPRECATED_REGISTER_SIZE;
eb294659 968 char buffer[MAX_REGISTER_SIZE];
c906108c
SS
969
970 store_unsigned_integer (buffer, len, word);
971 if (INNER_THAN (1, 2))
972 {
973 /* stack grows downward */
974 sp -= len;
975 write_memory (sp, buffer, len);
976 }
977 else
978 {
979 /* stack grows upward */
980 write_memory (sp, buffer, len);
981 sp += len;
982 }
983
984 return sp;
985}
986
987/* Push LEN bytes with data at BUFFER. */
988
989CORE_ADDR
fba45db2 990push_bytes (CORE_ADDR sp, char *buffer, int len)
c906108c
SS
991{
992 if (INNER_THAN (1, 2))
993 {
994 /* stack grows downward */
995 sp -= len;
996 write_memory (sp, buffer, len);
997 }
998 else
999 {
1000 /* stack grows upward */
1001 write_memory (sp, buffer, len);
1002 sp += len;
1003 }
1004
1005 return sp;
1006}
1007
2df3850c
JM
1008#ifndef PARM_BOUNDARY
1009#define PARM_BOUNDARY (0)
1010#endif
1011
1012/* Push onto the stack the specified value VALUE. Pad it correctly for
1013 it to be an argument to a function. */
c906108c 1014
c906108c 1015static CORE_ADDR
aa1ee363 1016value_push (CORE_ADDR sp, struct value *arg)
c906108c 1017{
52f0bd74
AC
1018 int len = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (arg));
1019 int container_len = len;
1020 int offset;
2df3850c
JM
1021
1022 /* How big is the container we're going to put this value in? */
1023 if (PARM_BOUNDARY)
1024 container_len = ((len + PARM_BOUNDARY / TARGET_CHAR_BIT - 1)
1025 & ~(PARM_BOUNDARY / TARGET_CHAR_BIT - 1));
1026
1027 /* Are we going to put it at the high or low end of the container? */
d7449b42 1028 if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
2df3850c
JM
1029 offset = container_len - len;
1030 else
1031 offset = 0;
c906108c
SS
1032
1033 if (INNER_THAN (1, 2))
1034 {
1035 /* stack grows downward */
2df3850c
JM
1036 sp -= container_len;
1037 write_memory (sp + offset, VALUE_CONTENTS_ALL (arg), len);
c906108c
SS
1038 }
1039 else
1040 {
1041 /* stack grows upward */
2df3850c
JM
1042 write_memory (sp + offset, VALUE_CONTENTS_ALL (arg), len);
1043 sp += container_len;
c906108c
SS
1044 }
1045
1046 return sp;
1047}
1048
392a587b 1049CORE_ADDR
b81774d8
AC
1050legacy_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1051 int struct_return, CORE_ADDR struct_addr)
392a587b
JM
1052{
1053 /* ASSERT ( !struct_return); */
1054 int i;
1055 for (i = nargs - 1; i >= 0; i--)
1056 sp = value_push (sp, args[i]);
1057 return sp;
1058}
1059
c906108c
SS
1060/* Create a value for an array by allocating space in the inferior, copying
1061 the data into that space, and then setting up an array value.
1062
1063 The array bounds are set from LOWBOUND and HIGHBOUND, and the array is
1064 populated from the values passed in ELEMVEC.
1065
1066 The element type of the array is inherited from the type of the
1067 first element, and all elements must have the same size (though we
1068 don't currently enforce any restriction on their types). */
1069
f23631e4
AC
1070struct value *
1071value_array (int lowbound, int highbound, struct value **elemvec)
c906108c
SS
1072{
1073 int nelem;
1074 int idx;
1075 unsigned int typelength;
f23631e4 1076 struct value *val;
c906108c
SS
1077 struct type *rangetype;
1078 struct type *arraytype;
1079 CORE_ADDR addr;
1080
1081 /* Validate that the bounds are reasonable and that each of the elements
1082 have the same size. */
1083
1084 nelem = highbound - lowbound + 1;
1085 if (nelem <= 0)
1086 {
1087 error ("bad array bounds (%d, %d)", lowbound, highbound);
1088 }
1089 typelength = TYPE_LENGTH (VALUE_ENCLOSING_TYPE (elemvec[0]));
1090 for (idx = 1; idx < nelem; idx++)
1091 {
1092 if (TYPE_LENGTH (VALUE_ENCLOSING_TYPE (elemvec[idx])) != typelength)
1093 {
1094 error ("array elements must all be the same size");
1095 }
1096 }
1097
1098 rangetype = create_range_type ((struct type *) NULL, builtin_type_int,
1099 lowbound, highbound);
c5aa993b
JM
1100 arraytype = create_array_type ((struct type *) NULL,
1101 VALUE_ENCLOSING_TYPE (elemvec[0]), rangetype);
c906108c
SS
1102
1103 if (!current_language->c_style_arrays)
1104 {
1105 val = allocate_value (arraytype);
1106 for (idx = 0; idx < nelem; idx++)
1107 {
1108 memcpy (VALUE_CONTENTS_ALL_RAW (val) + (idx * typelength),
1109 VALUE_CONTENTS_ALL (elemvec[idx]),
1110 typelength);
1111 }
1112 VALUE_BFD_SECTION (val) = VALUE_BFD_SECTION (elemvec[0]);
1113 return val;
1114 }
1115
1116 /* Allocate space to store the array in the inferior, and then initialize
1117 it by copying in each element. FIXME: Is it worth it to create a
1118 local buffer in which to collect each value and then write all the
1119 bytes in one operation? */
1120
1121 addr = allocate_space_in_inferior (nelem * typelength);
1122 for (idx = 0; idx < nelem; idx++)
1123 {
1124 write_memory (addr + (idx * typelength), VALUE_CONTENTS_ALL (elemvec[idx]),
1125 typelength);
1126 }
1127
1128 /* Create the array type and set up an array value to be evaluated lazily. */
1129
1130 val = value_at_lazy (arraytype, addr, VALUE_BFD_SECTION (elemvec[0]));
1131 return (val);
1132}
1133
1134/* Create a value for a string constant by allocating space in the inferior,
1135 copying the data into that space, and returning the address with type
1136 TYPE_CODE_STRING. PTR points to the string constant data; LEN is number
1137 of characters.
1138 Note that string types are like array of char types with a lower bound of
1139 zero and an upper bound of LEN - 1. Also note that the string may contain
1140 embedded null bytes. */
1141
f23631e4 1142struct value *
fba45db2 1143value_string (char *ptr, int len)
c906108c 1144{
f23631e4 1145 struct value *val;
c906108c
SS
1146 int lowbound = current_language->string_lower_bound;
1147 struct type *rangetype = create_range_type ((struct type *) NULL,
1148 builtin_type_int,
1149 lowbound, len + lowbound - 1);
1150 struct type *stringtype
c5aa993b 1151 = create_string_type ((struct type *) NULL, rangetype);
c906108c
SS
1152 CORE_ADDR addr;
1153
1154 if (current_language->c_style_arrays == 0)
1155 {
1156 val = allocate_value (stringtype);
1157 memcpy (VALUE_CONTENTS_RAW (val), ptr, len);
1158 return val;
1159 }
1160
1161
1162 /* Allocate space to store the string in the inferior, and then
1163 copy LEN bytes from PTR in gdb to that address in the inferior. */
1164
1165 addr = allocate_space_in_inferior (len);
1166 write_memory (addr, ptr, len);
1167
1168 val = value_at_lazy (stringtype, addr, NULL);
1169 return (val);
1170}
1171
f23631e4 1172struct value *
fba45db2 1173value_bitstring (char *ptr, int len)
c906108c 1174{
f23631e4 1175 struct value *val;
c906108c
SS
1176 struct type *domain_type = create_range_type (NULL, builtin_type_int,
1177 0, len - 1);
c5aa993b 1178 struct type *type = create_set_type ((struct type *) NULL, domain_type);
c906108c
SS
1179 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
1180 val = allocate_value (type);
1181 memcpy (VALUE_CONTENTS_RAW (val), ptr, TYPE_LENGTH (type));
1182 return val;
1183}
1184\f
1185/* See if we can pass arguments in T2 to a function which takes arguments
ad2f7632
DJ
1186 of types T1. T1 is a list of NARGS arguments, and T2 is a NULL-terminated
1187 vector. If some arguments need coercion of some sort, then the coerced
1188 values are written into T2. Return value is 0 if the arguments could be
1189 matched, or the position at which they differ if not.
c906108c
SS
1190
1191 STATICP is nonzero if the T1 argument list came from a
ad2f7632
DJ
1192 static member function. T2 will still include the ``this'' pointer,
1193 but it will be skipped.
c906108c
SS
1194
1195 For non-static member functions, we ignore the first argument,
1196 which is the type of the instance variable. This is because we want
1197 to handle calls with objects from derived classes. This is not
1198 entirely correct: we should actually check to make sure that a
1199 requested operation is type secure, shouldn't we? FIXME. */
1200
1201static int
ad2f7632
DJ
1202typecmp (int staticp, int varargs, int nargs,
1203 struct field t1[], struct value *t2[])
c906108c
SS
1204{
1205 int i;
1206
1207 if (t2 == 0)
ad2f7632
DJ
1208 internal_error (__FILE__, __LINE__, "typecmp: no argument list");
1209
4a1970e4
DJ
1210 /* Skip ``this'' argument if applicable. T2 will always include THIS. */
1211 if (staticp)
ad2f7632
DJ
1212 t2 ++;
1213
1214 for (i = 0;
1215 (i < nargs) && TYPE_CODE (t1[i].type) != TYPE_CODE_VOID;
1216 i++)
c906108c 1217 {
c5aa993b 1218 struct type *tt1, *tt2;
ad2f7632 1219
c5aa993b
JM
1220 if (!t2[i])
1221 return i + 1;
ad2f7632
DJ
1222
1223 tt1 = check_typedef (t1[i].type);
c5aa993b 1224 tt2 = check_typedef (VALUE_TYPE (t2[i]));
ad2f7632 1225
c906108c 1226 if (TYPE_CODE (tt1) == TYPE_CODE_REF
c5aa993b 1227 /* We should be doing hairy argument matching, as below. */
c906108c
SS
1228 && (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (tt1))) == TYPE_CODE (tt2)))
1229 {
1230 if (TYPE_CODE (tt2) == TYPE_CODE_ARRAY)
1231 t2[i] = value_coerce_array (t2[i]);
1232 else
1233 t2[i] = value_addr (t2[i]);
1234 continue;
1235 }
1236
802db21b
DB
1237 /* djb - 20000715 - Until the new type structure is in the
1238 place, and we can attempt things like implicit conversions,
1239 we need to do this so you can take something like a map<const
1240 char *>, and properly access map["hello"], because the
1241 argument to [] will be a reference to a pointer to a char,
7168a814 1242 and the argument will be a pointer to a char. */
802db21b
DB
1243 while ( TYPE_CODE(tt1) == TYPE_CODE_REF ||
1244 TYPE_CODE (tt1) == TYPE_CODE_PTR)
1245 {
1246 tt1 = check_typedef( TYPE_TARGET_TYPE(tt1) );
1247 }
1248 while ( TYPE_CODE(tt2) == TYPE_CODE_ARRAY ||
1249 TYPE_CODE(tt2) == TYPE_CODE_PTR ||
1250 TYPE_CODE(tt2) == TYPE_CODE_REF)
c906108c 1251 {
802db21b 1252 tt2 = check_typedef( TYPE_TARGET_TYPE(tt2) );
c906108c 1253 }
c5aa993b
JM
1254 if (TYPE_CODE (tt1) == TYPE_CODE (tt2))
1255 continue;
c906108c
SS
1256 /* Array to pointer is a `trivial conversion' according to the ARM. */
1257
1258 /* We should be doing much hairier argument matching (see section 13.2
7b83ea04
AC
1259 of the ARM), but as a quick kludge, just check for the same type
1260 code. */
ad2f7632 1261 if (TYPE_CODE (t1[i].type) != TYPE_CODE (VALUE_TYPE (t2[i])))
c5aa993b 1262 return i + 1;
c906108c 1263 }
ad2f7632 1264 if (varargs || t2[i] == NULL)
c5aa993b 1265 return 0;
ad2f7632 1266 return i + 1;
c906108c
SS
1267}
1268
1269/* Helper function used by value_struct_elt to recurse through baseclasses.
1270 Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
1271 and search in it assuming it has (class) type TYPE.
1272 If found, return value, else return NULL.
1273
1274 If LOOKING_FOR_BASECLASS, then instead of looking for struct fields,
1275 look for a baseclass named NAME. */
1276
f23631e4
AC
1277static struct value *
1278search_struct_field (char *name, struct value *arg1, int offset,
aa1ee363 1279 struct type *type, int looking_for_baseclass)
c906108c
SS
1280{
1281 int i;
1282 int nbases = TYPE_N_BASECLASSES (type);
1283
1284 CHECK_TYPEDEF (type);
1285
c5aa993b 1286 if (!looking_for_baseclass)
c906108c
SS
1287 for (i = TYPE_NFIELDS (type) - 1; i >= nbases; i--)
1288 {
1289 char *t_field_name = TYPE_FIELD_NAME (type, i);
1290
db577aea 1291 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
c906108c 1292 {
f23631e4 1293 struct value *v;
c906108c 1294 if (TYPE_FIELD_STATIC (type, i))
2c2738a0
DC
1295 {
1296 v = value_static_field (type, i);
1297 if (v == 0)
1298 error ("field %s is nonexistent or has been optimised out",
1299 name);
1300 }
c906108c 1301 else
2c2738a0
DC
1302 {
1303 v = value_primitive_field (arg1, offset, i, type);
1304 if (v == 0)
1305 error ("there is no field named %s", name);
1306 }
c906108c
SS
1307 return v;
1308 }
1309
1310 if (t_field_name
1311 && (t_field_name[0] == '\0'
1312 || (TYPE_CODE (type) == TYPE_CODE_UNION
db577aea 1313 && (strcmp_iw (t_field_name, "else") == 0))))
c906108c
SS
1314 {
1315 struct type *field_type = TYPE_FIELD_TYPE (type, i);
1316 if (TYPE_CODE (field_type) == TYPE_CODE_UNION
1317 || TYPE_CODE (field_type) == TYPE_CODE_STRUCT)
1318 {
1319 /* Look for a match through the fields of an anonymous union,
1320 or anonymous struct. C++ provides anonymous unions.
1321
1b831c93
AC
1322 In the GNU Chill (now deleted from GDB)
1323 implementation of variant record types, each
1324 <alternative field> has an (anonymous) union type,
1325 each member of the union represents a <variant
1326 alternative>. Each <variant alternative> is
1327 represented as a struct, with a member for each
1328 <variant field>. */
c5aa993b 1329
f23631e4 1330 struct value *v;
c906108c
SS
1331 int new_offset = offset;
1332
db034ac5
AC
1333 /* This is pretty gross. In G++, the offset in an
1334 anonymous union is relative to the beginning of the
1b831c93
AC
1335 enclosing struct. In the GNU Chill (now deleted
1336 from GDB) implementation of variant records, the
1337 bitpos is zero in an anonymous union field, so we
1338 have to add the offset of the union here. */
c906108c
SS
1339 if (TYPE_CODE (field_type) == TYPE_CODE_STRUCT
1340 || (TYPE_NFIELDS (field_type) > 0
1341 && TYPE_FIELD_BITPOS (field_type, 0) == 0))
1342 new_offset += TYPE_FIELD_BITPOS (type, i) / 8;
1343
1344 v = search_struct_field (name, arg1, new_offset, field_type,
1345 looking_for_baseclass);
1346 if (v)
1347 return v;
1348 }
1349 }
1350 }
1351
c5aa993b 1352 for (i = 0; i < nbases; i++)
c906108c 1353 {
f23631e4 1354 struct value *v;
c906108c
SS
1355 struct type *basetype = check_typedef (TYPE_BASECLASS (type, i));
1356 /* If we are looking for baseclasses, this is what we get when we
7b83ea04
AC
1357 hit them. But it could happen that the base part's member name
1358 is not yet filled in. */
c906108c
SS
1359 int found_baseclass = (looking_for_baseclass
1360 && TYPE_BASECLASS_NAME (type, i) != NULL
db577aea 1361 && (strcmp_iw (name, TYPE_BASECLASS_NAME (type, i)) == 0));
c906108c
SS
1362
1363 if (BASETYPE_VIA_VIRTUAL (type, i))
1364 {
1365 int boffset;
f23631e4 1366 struct value *v2 = allocate_value (basetype);
c906108c
SS
1367
1368 boffset = baseclass_offset (type, i,
1369 VALUE_CONTENTS (arg1) + offset,
1370 VALUE_ADDRESS (arg1)
c5aa993b 1371 + VALUE_OFFSET (arg1) + offset);
c906108c
SS
1372 if (boffset == -1)
1373 error ("virtual baseclass botch");
1374
1375 /* The virtual base class pointer might have been clobbered by the
1376 user program. Make sure that it still points to a valid memory
1377 location. */
1378
1379 boffset += offset;
1380 if (boffset < 0 || boffset >= TYPE_LENGTH (type))
1381 {
1382 CORE_ADDR base_addr;
c5aa993b 1383
c906108c
SS
1384 base_addr = VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1) + boffset;
1385 if (target_read_memory (base_addr, VALUE_CONTENTS_RAW (v2),
1386 TYPE_LENGTH (basetype)) != 0)
1387 error ("virtual baseclass botch");
1388 VALUE_LVAL (v2) = lval_memory;
1389 VALUE_ADDRESS (v2) = base_addr;
1390 }
1391 else
1392 {
1393 VALUE_LVAL (v2) = VALUE_LVAL (arg1);
1394 VALUE_ADDRESS (v2) = VALUE_ADDRESS (arg1);
1395 VALUE_OFFSET (v2) = VALUE_OFFSET (arg1) + boffset;
1396 if (VALUE_LAZY (arg1))
1397 VALUE_LAZY (v2) = 1;
1398 else
1399 memcpy (VALUE_CONTENTS_RAW (v2),
1400 VALUE_CONTENTS_RAW (arg1) + boffset,
1401 TYPE_LENGTH (basetype));
1402 }
1403
1404 if (found_baseclass)
1405 return v2;
1406 v = search_struct_field (name, v2, 0, TYPE_BASECLASS (type, i),
1407 looking_for_baseclass);
1408 }
1409 else if (found_baseclass)
1410 v = value_primitive_field (arg1, offset, i, type);
1411 else
1412 v = search_struct_field (name, arg1,
c5aa993b 1413 offset + TYPE_BASECLASS_BITPOS (type, i) / 8,
c906108c 1414 basetype, looking_for_baseclass);
c5aa993b
JM
1415 if (v)
1416 return v;
c906108c
SS
1417 }
1418 return NULL;
1419}
1420
1421
1422/* Return the offset (in bytes) of the virtual base of type BASETYPE
1423 * in an object pointed to by VALADDR (on the host), assumed to be of
1424 * type TYPE. OFFSET is number of bytes beyond start of ARG to start
1425 * looking (in case VALADDR is the contents of an enclosing object).
1426 *
1427 * This routine recurses on the primary base of the derived class because
1428 * the virtual base entries of the primary base appear before the other
1429 * virtual base entries.
1430 *
1431 * If the virtual base is not found, a negative integer is returned.
1432 * The magnitude of the negative integer is the number of entries in
1433 * the virtual table to skip over (entries corresponding to various
1434 * ancestral classes in the chain of primary bases).
1435 *
1436 * Important: This assumes the HP / Taligent C++ runtime
1437 * conventions. Use baseclass_offset() instead to deal with g++
1438 * conventions. */
1439
1440void
fba45db2
KB
1441find_rt_vbase_offset (struct type *type, struct type *basetype, char *valaddr,
1442 int offset, int *boffset_p, int *skip_p)
c906108c 1443{
c5aa993b
JM
1444 int boffset; /* offset of virtual base */
1445 int index; /* displacement to use in virtual table */
c906108c 1446 int skip;
c5aa993b 1447
f23631e4 1448 struct value *vp;
c5aa993b
JM
1449 CORE_ADDR vtbl; /* the virtual table pointer */
1450 struct type *pbc; /* the primary base class */
c906108c
SS
1451
1452 /* Look for the virtual base recursively in the primary base, first.
1453 * This is because the derived class object and its primary base
1454 * subobject share the primary virtual table. */
c5aa993b 1455
c906108c 1456 boffset = 0;
c5aa993b 1457 pbc = TYPE_PRIMARY_BASE (type);
c906108c
SS
1458 if (pbc)
1459 {
1460 find_rt_vbase_offset (pbc, basetype, valaddr, offset, &boffset, &skip);
1461 if (skip < 0)
c5aa993b
JM
1462 {
1463 *boffset_p = boffset;
1464 *skip_p = -1;
1465 return;
1466 }
c906108c
SS
1467 }
1468 else
1469 skip = 0;
1470
1471
1472 /* Find the index of the virtual base according to HP/Taligent
1473 runtime spec. (Depth-first, left-to-right.) */
1474 index = virtual_base_index_skip_primaries (basetype, type);
1475
c5aa993b
JM
1476 if (index < 0)
1477 {
1478 *skip_p = skip + virtual_base_list_length_skip_primaries (type);
1479 *boffset_p = 0;
1480 return;
1481 }
c906108c 1482
c5aa993b 1483 /* pai: FIXME -- 32x64 possible problem */
c906108c 1484 /* First word (4 bytes) in object layout is the vtable pointer */
c5aa993b 1485 vtbl = *(CORE_ADDR *) (valaddr + offset);
c906108c 1486
c5aa993b 1487 /* Before the constructor is invoked, things are usually zero'd out. */
c906108c
SS
1488 if (vtbl == 0)
1489 error ("Couldn't find virtual table -- object may not be constructed yet.");
1490
1491
1492 /* Find virtual base's offset -- jump over entries for primary base
1493 * ancestors, then use the index computed above. But also adjust by
1494 * HP_ACC_VBASE_START for the vtable slots before the start of the
1495 * virtual base entries. Offset is negative -- virtual base entries
1496 * appear _before_ the address point of the virtual table. */
c5aa993b 1497
070ad9f0 1498 /* pai: FIXME -- 32x64 problem, if word = 8 bytes, change multiplier
c5aa993b 1499 & use long type */
c906108c
SS
1500
1501 /* epstein : FIXME -- added param for overlay section. May not be correct */
c5aa993b 1502 vp = value_at (builtin_type_int, vtbl + 4 * (-skip - index - HP_ACC_VBASE_START), NULL);
c906108c
SS
1503 boffset = value_as_long (vp);
1504 *skip_p = -1;
1505 *boffset_p = boffset;
1506 return;
1507}
1508
1509
1510/* Helper function used by value_struct_elt to recurse through baseclasses.
1511 Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
1512 and search in it assuming it has (class) type TYPE.
1513 If found, return value, else if name matched and args not return (value)-1,
1514 else return NULL. */
1515
f23631e4
AC
1516static struct value *
1517search_struct_method (char *name, struct value **arg1p,
1518 struct value **args, int offset,
aa1ee363 1519 int *static_memfuncp, struct type *type)
c906108c
SS
1520{
1521 int i;
f23631e4 1522 struct value *v;
c906108c
SS
1523 int name_matched = 0;
1524 char dem_opname[64];
1525
1526 CHECK_TYPEDEF (type);
1527 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; i--)
1528 {
1529 char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1530 /* FIXME! May need to check for ARM demangling here */
c5aa993b
JM
1531 if (strncmp (t_field_name, "__", 2) == 0 ||
1532 strncmp (t_field_name, "op", 2) == 0 ||
1533 strncmp (t_field_name, "type", 4) == 0)
c906108c 1534 {
c5aa993b
JM
1535 if (cplus_demangle_opname (t_field_name, dem_opname, DMGL_ANSI))
1536 t_field_name = dem_opname;
1537 else if (cplus_demangle_opname (t_field_name, dem_opname, 0))
c906108c 1538 t_field_name = dem_opname;
c906108c 1539 }
db577aea 1540 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
c906108c
SS
1541 {
1542 int j = TYPE_FN_FIELDLIST_LENGTH (type, i) - 1;
1543 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
c5aa993b 1544 name_matched = 1;
c906108c 1545
de17c821 1546 check_stub_method_group (type, i);
c906108c
SS
1547 if (j > 0 && args == 0)
1548 error ("cannot resolve overloaded method `%s': no arguments supplied", name);
acf5ed49 1549 else if (j == 0 && args == 0)
c906108c 1550 {
acf5ed49
DJ
1551 v = value_fn_field (arg1p, f, j, type, offset);
1552 if (v != NULL)
1553 return v;
c906108c 1554 }
acf5ed49
DJ
1555 else
1556 while (j >= 0)
1557 {
acf5ed49 1558 if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
ad2f7632
DJ
1559 TYPE_VARARGS (TYPE_FN_FIELD_TYPE (f, j)),
1560 TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, j)),
acf5ed49
DJ
1561 TYPE_FN_FIELD_ARGS (f, j), args))
1562 {
1563 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1564 return value_virtual_fn_field (arg1p, f, j, type, offset);
1565 if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
1566 *static_memfuncp = 1;
1567 v = value_fn_field (arg1p, f, j, type, offset);
1568 if (v != NULL)
1569 return v;
1570 }
1571 j--;
1572 }
c906108c
SS
1573 }
1574 }
1575
1576 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1577 {
1578 int base_offset;
1579
1580 if (BASETYPE_VIA_VIRTUAL (type, i))
1581 {
c5aa993b
JM
1582 if (TYPE_HAS_VTABLE (type))
1583 {
1584 /* HP aCC compiled type, search for virtual base offset
7b83ea04 1585 according to HP/Taligent runtime spec. */
c5aa993b
JM
1586 int skip;
1587 find_rt_vbase_offset (type, TYPE_BASECLASS (type, i),
1588 VALUE_CONTENTS_ALL (*arg1p),
1589 offset + VALUE_EMBEDDED_OFFSET (*arg1p),
1590 &base_offset, &skip);
1591 if (skip >= 0)
1592 error ("Virtual base class offset not found in vtable");
1593 }
1594 else
1595 {
1596 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
1597 char *base_valaddr;
1598
1599 /* The virtual base class pointer might have been clobbered by the
7b83ea04
AC
1600 user program. Make sure that it still points to a valid memory
1601 location. */
c5aa993b
JM
1602
1603 if (offset < 0 || offset >= TYPE_LENGTH (type))
1604 {
1605 base_valaddr = (char *) alloca (TYPE_LENGTH (baseclass));
1606 if (target_read_memory (VALUE_ADDRESS (*arg1p)
1607 + VALUE_OFFSET (*arg1p) + offset,
1608 base_valaddr,
1609 TYPE_LENGTH (baseclass)) != 0)
1610 error ("virtual baseclass botch");
1611 }
1612 else
1613 base_valaddr = VALUE_CONTENTS (*arg1p) + offset;
1614
1615 base_offset =
1616 baseclass_offset (type, i, base_valaddr,
1617 VALUE_ADDRESS (*arg1p)
1618 + VALUE_OFFSET (*arg1p) + offset);
1619 if (base_offset == -1)
1620 error ("virtual baseclass botch");
1621 }
1622 }
c906108c
SS
1623 else
1624 {
1625 base_offset = TYPE_BASECLASS_BITPOS (type, i) / 8;
c5aa993b 1626 }
c906108c
SS
1627 v = search_struct_method (name, arg1p, args, base_offset + offset,
1628 static_memfuncp, TYPE_BASECLASS (type, i));
f23631e4 1629 if (v == (struct value *) - 1)
c906108c
SS
1630 {
1631 name_matched = 1;
1632 }
1633 else if (v)
1634 {
1635/* FIXME-bothner: Why is this commented out? Why is it here? */
c5aa993b 1636/* *arg1p = arg1_tmp; */
c906108c 1637 return v;
c5aa993b 1638 }
c906108c 1639 }
c5aa993b 1640 if (name_matched)
f23631e4 1641 return (struct value *) - 1;
c5aa993b
JM
1642 else
1643 return NULL;
c906108c
SS
1644}
1645
1646/* Given *ARGP, a value of type (pointer to a)* structure/union,
1647 extract the component named NAME from the ultimate target structure/union
1648 and return it as a value with its appropriate type.
1649 ERR is used in the error message if *ARGP's type is wrong.
1650
1651 C++: ARGS is a list of argument types to aid in the selection of
1652 an appropriate method. Also, handle derived types.
1653
1654 STATIC_MEMFUNCP, if non-NULL, points to a caller-supplied location
1655 where the truthvalue of whether the function that was resolved was
1656 a static member function or not is stored.
1657
1658 ERR is an error message to be printed in case the field is not found. */
1659
f23631e4
AC
1660struct value *
1661value_struct_elt (struct value **argp, struct value **args,
fba45db2 1662 char *name, int *static_memfuncp, char *err)
c906108c 1663{
52f0bd74 1664 struct type *t;
f23631e4 1665 struct value *v;
c906108c
SS
1666
1667 COERCE_ARRAY (*argp);
1668
1669 t = check_typedef (VALUE_TYPE (*argp));
1670
1671 /* Follow pointers until we get to a non-pointer. */
1672
1673 while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
1674 {
1675 *argp = value_ind (*argp);
1676 /* Don't coerce fn pointer to fn and then back again! */
1677 if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC)
1678 COERCE_ARRAY (*argp);
1679 t = check_typedef (VALUE_TYPE (*argp));
1680 }
1681
1682 if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
1683 error ("not implemented: member type in value_struct_elt");
1684
c5aa993b 1685 if (TYPE_CODE (t) != TYPE_CODE_STRUCT
c906108c
SS
1686 && TYPE_CODE (t) != TYPE_CODE_UNION)
1687 error ("Attempt to extract a component of a value that is not a %s.", err);
1688
1689 /* Assume it's not, unless we see that it is. */
1690 if (static_memfuncp)
c5aa993b 1691 *static_memfuncp = 0;
c906108c
SS
1692
1693 if (!args)
1694 {
1695 /* if there are no arguments ...do this... */
1696
1697 /* Try as a field first, because if we succeed, there
7b83ea04 1698 is less work to be done. */
c906108c
SS
1699 v = search_struct_field (name, *argp, 0, t, 0);
1700 if (v)
1701 return v;
1702
1703 /* C++: If it was not found as a data field, then try to
7b83ea04 1704 return it as a pointer to a method. */
c906108c
SS
1705
1706 if (destructor_name_p (name, t))
1707 error ("Cannot get value of destructor");
1708
1709 v = search_struct_method (name, argp, args, 0, static_memfuncp, t);
1710
f23631e4 1711 if (v == (struct value *) - 1)
c906108c
SS
1712 error ("Cannot take address of a method");
1713 else if (v == 0)
1714 {
1715 if (TYPE_NFN_FIELDS (t))
1716 error ("There is no member or method named %s.", name);
1717 else
1718 error ("There is no member named %s.", name);
1719 }
1720 return v;
1721 }
1722
1723 if (destructor_name_p (name, t))
1724 {
1725 if (!args[1])
1726 {
1727 /* Destructors are a special case. */
1728 int m_index, f_index;
1729
1730 v = NULL;
1731 if (get_destructor_fn_field (t, &m_index, &f_index))
1732 {
1733 v = value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, m_index),
1734 f_index, NULL, 0);
1735 }
1736 if (v == NULL)
1737 error ("could not find destructor function named %s.", name);
1738 else
1739 return v;
1740 }
1741 else
1742 {
1743 error ("destructor should not have any argument");
1744 }
1745 }
1746 else
1747 v = search_struct_method (name, argp, args, 0, static_memfuncp, t);
7168a814 1748
f23631e4 1749 if (v == (struct value *) - 1)
c906108c 1750 {
7168a814 1751 error ("One of the arguments you tried to pass to %s could not be converted to what the function wants.", name);
c906108c
SS
1752 }
1753 else if (v == 0)
1754 {
1755 /* See if user tried to invoke data as function. If so,
7b83ea04
AC
1756 hand it back. If it's not callable (i.e., a pointer to function),
1757 gdb should give an error. */
c906108c
SS
1758 v = search_struct_field (name, *argp, 0, t, 0);
1759 }
1760
1761 if (!v)
1762 error ("Structure has no component named %s.", name);
1763 return v;
1764}
1765
1766/* Search through the methods of an object (and its bases)
1767 * to find a specified method. Return the pointer to the
1768 * fn_field list of overloaded instances.
1769 * Helper function for value_find_oload_list.
1770 * ARGP is a pointer to a pointer to a value (the object)
1771 * METHOD is a string containing the method name
1772 * OFFSET is the offset within the value
c906108c
SS
1773 * TYPE is the assumed type of the object
1774 * NUM_FNS is the number of overloaded instances
1775 * BASETYPE is set to the actual type of the subobject where the method is found
1776 * BOFFSET is the offset of the base subobject where the method is found */
1777
7a292a7a 1778static struct fn_field *
f23631e4 1779find_method_list (struct value **argp, char *method, int offset,
4a1970e4 1780 struct type *type, int *num_fns,
fba45db2 1781 struct type **basetype, int *boffset)
c906108c
SS
1782{
1783 int i;
c5aa993b 1784 struct fn_field *f;
c906108c
SS
1785 CHECK_TYPEDEF (type);
1786
1787 *num_fns = 0;
1788
c5aa993b
JM
1789 /* First check in object itself */
1790 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; i--)
c906108c
SS
1791 {
1792 /* pai: FIXME What about operators and type conversions? */
c5aa993b 1793 char *fn_field_name = TYPE_FN_FIELDLIST_NAME (type, i);
db577aea 1794 if (fn_field_name && (strcmp_iw (fn_field_name, method) == 0))
c5aa993b 1795 {
4a1970e4
DJ
1796 int len = TYPE_FN_FIELDLIST_LENGTH (type, i);
1797 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
4a1970e4
DJ
1798
1799 *num_fns = len;
c5aa993b
JM
1800 *basetype = type;
1801 *boffset = offset;
4a1970e4 1802
de17c821
DJ
1803 /* Resolve any stub methods. */
1804 check_stub_method_group (type, i);
4a1970e4
DJ
1805
1806 return f;
c5aa993b
JM
1807 }
1808 }
1809
c906108c
SS
1810 /* Not found in object, check in base subobjects */
1811 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1812 {
1813 int base_offset;
1814 if (BASETYPE_VIA_VIRTUAL (type, i))
1815 {
c5aa993b
JM
1816 if (TYPE_HAS_VTABLE (type))
1817 {
1818 /* HP aCC compiled type, search for virtual base offset
1819 * according to HP/Taligent runtime spec. */
1820 int skip;
1821 find_rt_vbase_offset (type, TYPE_BASECLASS (type, i),
1822 VALUE_CONTENTS_ALL (*argp),
1823 offset + VALUE_EMBEDDED_OFFSET (*argp),
1824 &base_offset, &skip);
1825 if (skip >= 0)
1826 error ("Virtual base class offset not found in vtable");
1827 }
1828 else
1829 {
1830 /* probably g++ runtime model */
1831 base_offset = VALUE_OFFSET (*argp) + offset;
1832 base_offset =
1833 baseclass_offset (type, i,
1834 VALUE_CONTENTS (*argp) + base_offset,
1835 VALUE_ADDRESS (*argp) + base_offset);
1836 if (base_offset == -1)
1837 error ("virtual baseclass botch");
1838 }
1839 }
1840 else
1841 /* non-virtual base, simply use bit position from debug info */
c906108c
SS
1842 {
1843 base_offset = TYPE_BASECLASS_BITPOS (type, i) / 8;
c5aa993b 1844 }
c906108c 1845 f = find_method_list (argp, method, base_offset + offset,
4a1970e4
DJ
1846 TYPE_BASECLASS (type, i), num_fns, basetype,
1847 boffset);
c906108c 1848 if (f)
c5aa993b 1849 return f;
c906108c 1850 }
c5aa993b 1851 return NULL;
c906108c
SS
1852}
1853
1854/* Return the list of overloaded methods of a specified name.
1855 * ARGP is a pointer to a pointer to a value (the object)
1856 * METHOD is the method name
1857 * OFFSET is the offset within the value contents
c906108c
SS
1858 * NUM_FNS is the number of overloaded instances
1859 * BASETYPE is set to the type of the base subobject that defines the method
1860 * BOFFSET is the offset of the base subobject which defines the method */
1861
1862struct fn_field *
f23631e4 1863value_find_oload_method_list (struct value **argp, char *method, int offset,
4a1970e4
DJ
1864 int *num_fns, struct type **basetype,
1865 int *boffset)
c906108c 1866{
c5aa993b 1867 struct type *t;
c906108c
SS
1868
1869 t = check_typedef (VALUE_TYPE (*argp));
1870
c5aa993b 1871 /* code snarfed from value_struct_elt */
c906108c
SS
1872 while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
1873 {
1874 *argp = value_ind (*argp);
1875 /* Don't coerce fn pointer to fn and then back again! */
1876 if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC)
1877 COERCE_ARRAY (*argp);
1878 t = check_typedef (VALUE_TYPE (*argp));
1879 }
c5aa993b 1880
c906108c
SS
1881 if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
1882 error ("Not implemented: member type in value_find_oload_lis");
c5aa993b
JM
1883
1884 if (TYPE_CODE (t) != TYPE_CODE_STRUCT
1885 && TYPE_CODE (t) != TYPE_CODE_UNION)
c906108c 1886 error ("Attempt to extract a component of a value that is not a struct or union");
c5aa993b 1887
4a1970e4 1888 return find_method_list (argp, method, 0, t, num_fns, basetype, boffset);
c906108c
SS
1889}
1890
1891/* Given an array of argument types (ARGTYPES) (which includes an
1892 entry for "this" in the case of C++ methods), the number of
1893 arguments NARGS, the NAME of a function whether it's a method or
1894 not (METHOD), and the degree of laxness (LAX) in conforming to
1895 overload resolution rules in ANSI C++, find the best function that
1896 matches on the argument types according to the overload resolution
1897 rules.
1898
1899 In the case of class methods, the parameter OBJ is an object value
1900 in which to search for overloaded methods.
1901
1902 In the case of non-method functions, the parameter FSYM is a symbol
1903 corresponding to one of the overloaded functions.
1904
1905 Return value is an integer: 0 -> good match, 10 -> debugger applied
1906 non-standard coercions, 100 -> incompatible.
1907
1908 If a method is being searched for, VALP will hold the value.
1909 If a non-method is being searched for, SYMP will hold the symbol for it.
1910
1911 If a method is being searched for, and it is a static method,
1912 then STATICP will point to a non-zero value.
1913
1914 Note: This function does *not* check the value of
1915 overload_resolution. Caller must check it to see whether overload
1916 resolution is permitted.
c5aa993b 1917 */
c906108c
SS
1918
1919int
fba45db2 1920find_overload_match (struct type **arg_types, int nargs, char *name, int method,
7f8c9282 1921 int lax, struct value **objp, struct symbol *fsym,
f23631e4 1922 struct value **valp, struct symbol **symp, int *staticp)
c906108c 1923{
7f8c9282 1924 struct value *obj = (objp ? *objp : NULL);
c5aa993b 1925
8d577d32 1926 int oload_champ; /* Index of best overloaded function */
c5aa993b 1927
c5aa993b
JM
1928 struct badness_vector *oload_champ_bv = NULL; /* The measure for the current best match */
1929
f23631e4 1930 struct value *temp = obj;
c5aa993b
JM
1931 struct fn_field *fns_ptr = NULL; /* For methods, the list of overloaded methods */
1932 struct symbol **oload_syms = NULL; /* For non-methods, the list of overloaded function symbols */
1933 int num_fns = 0; /* Number of overloaded instances being considered */
1934 struct type *basetype = NULL;
c906108c 1935 int boffset;
52f0bd74 1936 int ix;
4a1970e4 1937 int static_offset;
8d577d32 1938 struct cleanup *old_cleanups = NULL;
c906108c 1939
8d577d32 1940 const char *obj_type_name = NULL;
c5aa993b 1941 char *func_name = NULL;
8d577d32 1942 enum oload_classification match_quality;
c906108c
SS
1943
1944 /* Get the list of overloaded methods or functions */
1945 if (method)
1946 {
1947 obj_type_name = TYPE_NAME (VALUE_TYPE (obj));
1948 /* Hack: evaluate_subexp_standard often passes in a pointer
7b83ea04 1949 value rather than the object itself, so try again */
c906108c 1950 if ((!obj_type_name || !*obj_type_name) &&
c5aa993b
JM
1951 (TYPE_CODE (VALUE_TYPE (obj)) == TYPE_CODE_PTR))
1952 obj_type_name = TYPE_NAME (TYPE_TARGET_TYPE (VALUE_TYPE (obj)));
c906108c
SS
1953
1954 fns_ptr = value_find_oload_method_list (&temp, name, 0,
c5aa993b
JM
1955 &num_fns,
1956 &basetype, &boffset);
c906108c 1957 if (!fns_ptr || !num_fns)
c5aa993b
JM
1958 error ("Couldn't find method %s%s%s",
1959 obj_type_name,
1960 (obj_type_name && *obj_type_name) ? "::" : "",
1961 name);
4a1970e4
DJ
1962 /* If we are dealing with stub method types, they should have
1963 been resolved by find_method_list via value_find_oload_method_list
1964 above. */
1965 gdb_assert (TYPE_DOMAIN_TYPE (fns_ptr[0].type) != NULL);
8d577d32
DC
1966 oload_champ = find_oload_champ (arg_types, nargs, method, num_fns,
1967 fns_ptr, oload_syms, &oload_champ_bv);
c906108c
SS
1968 }
1969 else
1970 {
8d577d32
DC
1971 const char *qualified_name = SYMBOL_CPLUS_DEMANGLED_NAME (fsym);
1972 func_name = cp_func_name (qualified_name);
c906108c 1973
917317f4 1974 /* If the name is NULL this must be a C-style function.
7b83ea04 1975 Just return the same symbol. */
8d577d32 1976 if (func_name == NULL)
7b83ea04 1977 {
917317f4 1978 *symp = fsym;
7b83ea04
AC
1979 return 0;
1980 }
917317f4 1981
8d577d32
DC
1982 old_cleanups = make_cleanup (xfree, func_name);
1983 make_cleanup (xfree, oload_syms);
1984 make_cleanup (xfree, oload_champ_bv);
1985
1986 oload_champ = find_oload_champ_namespace (arg_types, nargs,
1987 func_name,
1988 qualified_name,
1989 &oload_syms,
1990 &oload_champ_bv);
1991 }
1992
1993 /* Check how bad the best match is. */
1994
1995 match_quality
1996 = classify_oload_match (oload_champ_bv, nargs,
1997 oload_method_static (method, fns_ptr,
1998 oload_champ));
1999
2000 if (match_quality == INCOMPATIBLE)
2001 {
2002 if (method)
2003 error ("Cannot resolve method %s%s%s to any overloaded instance",
2004 obj_type_name,
2005 (obj_type_name && *obj_type_name) ? "::" : "",
2006 name);
2007 else
2008 error ("Cannot resolve function %s to any overloaded instance",
2009 func_name);
2010 }
2011 else if (match_quality == NON_STANDARD)
2012 {
2013 if (method)
2014 warning ("Using non-standard conversion to match method %s%s%s to supplied arguments",
2015 obj_type_name,
2016 (obj_type_name && *obj_type_name) ? "::" : "",
2017 name);
2018 else
2019 warning ("Using non-standard conversion to match function %s to supplied arguments",
2020 func_name);
2021 }
2022
2023 if (method)
2024 {
2025 if (staticp != NULL)
2026 *staticp = oload_method_static (method, fns_ptr, oload_champ);
2027 if (TYPE_FN_FIELD_VIRTUAL_P (fns_ptr, oload_champ))
2028 *valp = value_virtual_fn_field (&temp, fns_ptr, oload_champ, basetype, boffset);
2029 else
2030 *valp = value_fn_field (&temp, fns_ptr, oload_champ, basetype, boffset);
2031 }
2032 else
2033 {
2034 *symp = oload_syms[oload_champ];
2035 }
2036
2037 if (objp)
2038 {
2039 if (TYPE_CODE (VALUE_TYPE (temp)) != TYPE_CODE_PTR
2040 && TYPE_CODE (VALUE_TYPE (*objp)) == TYPE_CODE_PTR)
2041 {
2042 temp = value_addr (temp);
2043 }
2044 *objp = temp;
2045 }
2046 if (old_cleanups != NULL)
2047 do_cleanups (old_cleanups);
2048
2049 switch (match_quality)
2050 {
2051 case INCOMPATIBLE:
2052 return 100;
2053 case NON_STANDARD:
2054 return 10;
2055 default: /* STANDARD */
2056 return 0;
2057 }
2058}
2059
2060/* Find the best overload match, searching for FUNC_NAME in namespaces
2061 contained in QUALIFIED_NAME until it either finds a good match or
2062 runs out of namespaces. It stores the overloaded functions in
2063 *OLOAD_SYMS, and the badness vector in *OLOAD_CHAMP_BV. The
2064 calling function is responsible for freeing *OLOAD_SYMS and
2065 *OLOAD_CHAMP_BV. */
2066
2067static int
2068find_oload_champ_namespace (struct type **arg_types, int nargs,
2069 const char *func_name,
2070 const char *qualified_name,
2071 struct symbol ***oload_syms,
2072 struct badness_vector **oload_champ_bv)
2073{
2074 int oload_champ;
2075
2076 find_oload_champ_namespace_loop (arg_types, nargs,
2077 func_name,
2078 qualified_name, 0,
2079 oload_syms, oload_champ_bv,
2080 &oload_champ);
2081
2082 return oload_champ;
2083}
2084
2085/* Helper function for find_oload_champ_namespace; NAMESPACE_LEN is
2086 how deep we've looked for namespaces, and the champ is stored in
2087 OLOAD_CHAMP. The return value is 1 if the champ is a good one, 0
2088 if it isn't.
2089
2090 It is the caller's responsibility to free *OLOAD_SYMS and
2091 *OLOAD_CHAMP_BV. */
2092
2093static int
2094find_oload_champ_namespace_loop (struct type **arg_types, int nargs,
2095 const char *func_name,
2096 const char *qualified_name,
2097 int namespace_len,
2098 struct symbol ***oload_syms,
2099 struct badness_vector **oload_champ_bv,
2100 int *oload_champ)
2101{
2102 int next_namespace_len = namespace_len;
2103 int searched_deeper = 0;
2104 int num_fns = 0;
2105 struct cleanup *old_cleanups;
2106 int new_oload_champ;
2107 struct symbol **new_oload_syms;
2108 struct badness_vector *new_oload_champ_bv;
2109 char *new_namespace;
2110
2111 if (next_namespace_len != 0)
2112 {
2113 gdb_assert (qualified_name[next_namespace_len] == ':');
2114 next_namespace_len += 2;
c906108c 2115 }
8d577d32
DC
2116 next_namespace_len
2117 += cp_find_first_component (qualified_name + next_namespace_len);
2118
2119 /* Initialize these to values that can safely be xfree'd. */
2120 *oload_syms = NULL;
2121 *oload_champ_bv = NULL;
c5aa993b 2122
8d577d32
DC
2123 /* First, see if we have a deeper namespace we can search in. If we
2124 get a good match there, use it. */
2125
2126 if (qualified_name[next_namespace_len] == ':')
2127 {
2128 searched_deeper = 1;
2129
2130 if (find_oload_champ_namespace_loop (arg_types, nargs,
2131 func_name, qualified_name,
2132 next_namespace_len,
2133 oload_syms, oload_champ_bv,
2134 oload_champ))
2135 {
2136 return 1;
2137 }
2138 };
2139
2140 /* If we reach here, either we're in the deepest namespace or we
2141 didn't find a good match in a deeper namespace. But, in the
2142 latter case, we still have a bad match in a deeper namespace;
2143 note that we might not find any match at all in the current
2144 namespace. (There's always a match in the deepest namespace,
2145 because this overload mechanism only gets called if there's a
2146 function symbol to start off with.) */
2147
2148 old_cleanups = make_cleanup (xfree, *oload_syms);
2149 old_cleanups = make_cleanup (xfree, *oload_champ_bv);
2150 new_namespace = alloca (namespace_len + 1);
2151 strncpy (new_namespace, qualified_name, namespace_len);
2152 new_namespace[namespace_len] = '\0';
2153 new_oload_syms = make_symbol_overload_list (func_name,
2154 new_namespace);
2155 while (new_oload_syms[num_fns])
2156 ++num_fns;
2157
2158 new_oload_champ = find_oload_champ (arg_types, nargs, 0, num_fns,
2159 NULL, new_oload_syms,
2160 &new_oload_champ_bv);
2161
2162 /* Case 1: We found a good match. Free earlier matches (if any),
2163 and return it. Case 2: We didn't find a good match, but we're
2164 not the deepest function. Then go with the bad match that the
2165 deeper function found. Case 3: We found a bad match, and we're
2166 the deepest function. Then return what we found, even though
2167 it's a bad match. */
2168
2169 if (new_oload_champ != -1
2170 && classify_oload_match (new_oload_champ_bv, nargs, 0) == STANDARD)
2171 {
2172 *oload_syms = new_oload_syms;
2173 *oload_champ = new_oload_champ;
2174 *oload_champ_bv = new_oload_champ_bv;
2175 do_cleanups (old_cleanups);
2176 return 1;
2177 }
2178 else if (searched_deeper)
2179 {
2180 xfree (new_oload_syms);
2181 xfree (new_oload_champ_bv);
2182 discard_cleanups (old_cleanups);
2183 return 0;
2184 }
2185 else
2186 {
2187 gdb_assert (new_oload_champ != -1);
2188 *oload_syms = new_oload_syms;
2189 *oload_champ = new_oload_champ;
2190 *oload_champ_bv = new_oload_champ_bv;
2191 discard_cleanups (old_cleanups);
2192 return 0;
2193 }
2194}
2195
2196/* Look for a function to take NARGS args of types ARG_TYPES. Find
2197 the best match from among the overloaded methods or functions
2198 (depending on METHOD) given by FNS_PTR or OLOAD_SYMS, respectively.
2199 The number of methods/functions in the list is given by NUM_FNS.
2200 Return the index of the best match; store an indication of the
2201 quality of the match in OLOAD_CHAMP_BV.
2202
2203 It is the caller's responsibility to free *OLOAD_CHAMP_BV. */
2204
2205static int
2206find_oload_champ (struct type **arg_types, int nargs, int method,
2207 int num_fns, struct fn_field *fns_ptr,
2208 struct symbol **oload_syms,
2209 struct badness_vector **oload_champ_bv)
2210{
2211 int ix;
2212 struct badness_vector *bv; /* A measure of how good an overloaded instance is */
2213 int oload_champ = -1; /* Index of best overloaded function */
2214 int oload_ambiguous = 0; /* Current ambiguity state for overload resolution */
2215 /* 0 => no ambiguity, 1 => two good funcs, 2 => incomparable funcs */
2216
2217 *oload_champ_bv = NULL;
c906108c 2218
c5aa993b 2219 /* Consider each candidate in turn */
c906108c
SS
2220 for (ix = 0; ix < num_fns; ix++)
2221 {
8d577d32
DC
2222 int jj;
2223 int static_offset = oload_method_static (method, fns_ptr, ix);
2224 int nparms;
2225 struct type **parm_types;
2226
db577aea
AC
2227 if (method)
2228 {
ad2f7632 2229 nparms = TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (fns_ptr, ix));
db577aea
AC
2230 }
2231 else
2232 {
2233 /* If it's not a method, this is the proper place */
2234 nparms=TYPE_NFIELDS(SYMBOL_TYPE(oload_syms[ix]));
2235 }
c906108c 2236
c5aa993b 2237 /* Prepare array of parameter types */
c906108c
SS
2238 parm_types = (struct type **) xmalloc (nparms * (sizeof (struct type *)));
2239 for (jj = 0; jj < nparms; jj++)
db577aea 2240 parm_types[jj] = (method
ad2f7632 2241 ? (TYPE_FN_FIELD_ARGS (fns_ptr, ix)[jj].type)
db577aea 2242 : TYPE_FIELD_TYPE (SYMBOL_TYPE (oload_syms[ix]), jj));
c906108c 2243
4a1970e4
DJ
2244 /* Compare parameter types to supplied argument types. Skip THIS for
2245 static methods. */
2246 bv = rank_function (parm_types, nparms, arg_types + static_offset,
2247 nargs - static_offset);
c5aa993b 2248
8d577d32 2249 if (!*oload_champ_bv)
c5aa993b 2250 {
8d577d32 2251 *oload_champ_bv = bv;
c5aa993b 2252 oload_champ = 0;
c5aa993b 2253 }
c906108c 2254 else
c5aa993b 2255 /* See whether current candidate is better or worse than previous best */
8d577d32 2256 switch (compare_badness (bv, *oload_champ_bv))
c5aa993b
JM
2257 {
2258 case 0:
2259 oload_ambiguous = 1; /* top two contenders are equally good */
c5aa993b
JM
2260 break;
2261 case 1:
2262 oload_ambiguous = 2; /* incomparable top contenders */
c5aa993b
JM
2263 break;
2264 case 2:
8d577d32 2265 *oload_champ_bv = bv; /* new champion, record details */
c5aa993b
JM
2266 oload_ambiguous = 0;
2267 oload_champ = ix;
c5aa993b
JM
2268 break;
2269 case 3:
2270 default:
2271 break;
2272 }
b8c9b27d 2273 xfree (parm_types);
6b1ba9a0
ND
2274 if (overload_debug)
2275 {
2276 if (method)
2277 fprintf_filtered (gdb_stderr,"Overloaded method instance %s, # of parms %d\n", fns_ptr[ix].physname, nparms);
2278 else
2279 fprintf_filtered (gdb_stderr,"Overloaded function instance %s # of parms %d\n", SYMBOL_DEMANGLED_NAME (oload_syms[ix]), nparms);
4a1970e4 2280 for (jj = 0; jj < nargs - static_offset; jj++)
6b1ba9a0
ND
2281 fprintf_filtered (gdb_stderr,"...Badness @ %d : %d\n", jj, bv->rank[jj]);
2282 fprintf_filtered (gdb_stderr,"Overload resolution champion is %d, ambiguous? %d\n", oload_champ, oload_ambiguous);
2283 }
c906108c
SS
2284 }
2285
8d577d32
DC
2286 return oload_champ;
2287}
6b1ba9a0 2288
8d577d32
DC
2289/* Return 1 if we're looking at a static method, 0 if we're looking at
2290 a non-static method or a function that isn't a method. */
c906108c 2291
8d577d32
DC
2292static int
2293oload_method_static (int method, struct fn_field *fns_ptr, int index)
2294{
2295 if (method && TYPE_FN_FIELD_STATIC_P (fns_ptr, index))
2296 return 1;
c906108c 2297 else
8d577d32
DC
2298 return 0;
2299}
c906108c 2300
8d577d32
DC
2301/* Check how good an overload match OLOAD_CHAMP_BV represents. */
2302
2303static enum oload_classification
2304classify_oload_match (struct badness_vector *oload_champ_bv,
2305 int nargs,
2306 int static_offset)
2307{
2308 int ix;
2309
2310 for (ix = 1; ix <= nargs - static_offset; ix++)
7f8c9282 2311 {
8d577d32
DC
2312 if (oload_champ_bv->rank[ix] >= 100)
2313 return INCOMPATIBLE; /* truly mismatched types */
2314 else if (oload_champ_bv->rank[ix] >= 10)
2315 return NON_STANDARD; /* non-standard type conversions needed */
7f8c9282 2316 }
02f0d45d 2317
8d577d32 2318 return STANDARD; /* Only standard conversions needed. */
c906108c
SS
2319}
2320
2321/* C++: return 1 is NAME is a legitimate name for the destructor
2322 of type TYPE. If TYPE does not have a destructor, or
2323 if NAME is inappropriate for TYPE, an error is signaled. */
2324int
fba45db2 2325destructor_name_p (const char *name, const struct type *type)
c906108c
SS
2326{
2327 /* destructors are a special case. */
2328
2329 if (name[0] == '~')
2330 {
2331 char *dname = type_name_no_tag (type);
2332 char *cp = strchr (dname, '<');
2333 unsigned int len;
2334
2335 /* Do not compare the template part for template classes. */
2336 if (cp == NULL)
2337 len = strlen (dname);
2338 else
2339 len = cp - dname;
bf896cb0 2340 if (strlen (name + 1) != len || strncmp (dname, name + 1, len) != 0)
c906108c
SS
2341 error ("name of destructor must equal name of class");
2342 else
2343 return 1;
2344 }
2345 return 0;
2346}
2347
2348/* Helper function for check_field: Given TYPE, a structure/union,
2349 return 1 if the component named NAME from the ultimate
2350 target structure/union is defined, otherwise, return 0. */
2351
2352static int
aa1ee363 2353check_field_in (struct type *type, const char *name)
c906108c 2354{
52f0bd74 2355 int i;
c906108c
SS
2356
2357 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
2358 {
2359 char *t_field_name = TYPE_FIELD_NAME (type, i);
db577aea 2360 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
c906108c
SS
2361 return 1;
2362 }
2363
2364 /* C++: If it was not found as a data field, then try to
2365 return it as a pointer to a method. */
2366
2367 /* Destructors are a special case. */
2368 if (destructor_name_p (name, type))
2369 {
2370 int m_index, f_index;
2371
2372 return get_destructor_fn_field (type, &m_index, &f_index);
2373 }
2374
2375 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
2376 {
db577aea 2377 if (strcmp_iw (TYPE_FN_FIELDLIST_NAME (type, i), name) == 0)
c906108c
SS
2378 return 1;
2379 }
2380
2381 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
2382 if (check_field_in (TYPE_BASECLASS (type, i), name))
2383 return 1;
c5aa993b 2384
c906108c
SS
2385 return 0;
2386}
2387
2388
2389/* C++: Given ARG1, a value of type (pointer to a)* structure/union,
2390 return 1 if the component named NAME from the ultimate
2391 target structure/union is defined, otherwise, return 0. */
2392
2393int
f23631e4 2394check_field (struct value *arg1, const char *name)
c906108c 2395{
52f0bd74 2396 struct type *t;
c906108c
SS
2397
2398 COERCE_ARRAY (arg1);
2399
2400 t = VALUE_TYPE (arg1);
2401
2402 /* Follow pointers until we get to a non-pointer. */
2403
2404 for (;;)
2405 {
2406 CHECK_TYPEDEF (t);
2407 if (TYPE_CODE (t) != TYPE_CODE_PTR && TYPE_CODE (t) != TYPE_CODE_REF)
2408 break;
2409 t = TYPE_TARGET_TYPE (t);
2410 }
2411
2412 if (TYPE_CODE (t) == TYPE_CODE_MEMBER)
2413 error ("not implemented: member type in check_field");
2414
c5aa993b 2415 if (TYPE_CODE (t) != TYPE_CODE_STRUCT
c906108c
SS
2416 && TYPE_CODE (t) != TYPE_CODE_UNION)
2417 error ("Internal error: `this' is not an aggregate");
2418
2419 return check_field_in (t, name);
2420}
2421
79c2c32d
DC
2422/* C++: Given an aggregate type CURTYPE, and a member name NAME,
2423 return the appropriate member. This function is used to resolve
2424 user expressions of the form "DOMAIN::NAME". For more details on
2425 what happens, see the comment before
2426 value_struct_elt_for_reference. */
2427
2428struct value *
2429value_aggregate_elt (struct type *curtype,
2430 char *name,
2431 enum noside noside)
2432{
2433 switch (TYPE_CODE (curtype))
2434 {
2435 case TYPE_CODE_STRUCT:
2436 case TYPE_CODE_UNION:
63d06c5c
DC
2437 return value_struct_elt_for_reference (curtype, 0, curtype, name, NULL,
2438 noside);
79c2c32d
DC
2439 case TYPE_CODE_NAMESPACE:
2440 return value_namespace_elt (curtype, name, noside);
2441 default:
2442 internal_error (__FILE__, __LINE__,
2443 "non-aggregate type in value_aggregate_elt");
2444 }
2445}
2446
c906108c
SS
2447/* C++: Given an aggregate type CURTYPE, and a member name NAME,
2448 return the address of this member as a "pointer to member"
2449 type. If INTYPE is non-null, then it will be the type
2450 of the member we are looking for. This will help us resolve
2451 "pointers to member functions". This function is used
2452 to resolve user expressions of the form "DOMAIN::NAME". */
2453
63d06c5c 2454static struct value *
fba45db2
KB
2455value_struct_elt_for_reference (struct type *domain, int offset,
2456 struct type *curtype, char *name,
63d06c5c
DC
2457 struct type *intype,
2458 enum noside noside)
c906108c 2459{
52f0bd74
AC
2460 struct type *t = curtype;
2461 int i;
f23631e4 2462 struct value *v;
c906108c 2463
c5aa993b 2464 if (TYPE_CODE (t) != TYPE_CODE_STRUCT
c906108c
SS
2465 && TYPE_CODE (t) != TYPE_CODE_UNION)
2466 error ("Internal error: non-aggregate type to value_struct_elt_for_reference");
2467
2468 for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); i--)
2469 {
2470 char *t_field_name = TYPE_FIELD_NAME (t, i);
c5aa993b 2471
6314a349 2472 if (t_field_name && strcmp (t_field_name, name) == 0)
c906108c
SS
2473 {
2474 if (TYPE_FIELD_STATIC (t, i))
2475 {
2476 v = value_static_field (t, i);
2477 if (v == NULL)
2c2738a0 2478 error ("static field %s has been optimized out",
c906108c
SS
2479 name);
2480 return v;
2481 }
2482 if (TYPE_FIELD_PACKED (t, i))
2483 error ("pointers to bitfield members not allowed");
c5aa993b 2484
c906108c
SS
2485 return value_from_longest
2486 (lookup_reference_type (lookup_member_type (TYPE_FIELD_TYPE (t, i),
2487 domain)),
2488 offset + (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
2489 }
2490 }
2491
2492 /* C++: If it was not found as a data field, then try to
2493 return it as a pointer to a method. */
2494
2495 /* Destructors are a special case. */
2496 if (destructor_name_p (name, t))
2497 {
2498 error ("member pointers to destructors not implemented yet");
2499 }
2500
2501 /* Perform all necessary dereferencing. */
2502 while (intype && TYPE_CODE (intype) == TYPE_CODE_PTR)
2503 intype = TYPE_TARGET_TYPE (intype);
2504
2505 for (i = TYPE_NFN_FIELDS (t) - 1; i >= 0; --i)
2506 {
2507 char *t_field_name = TYPE_FN_FIELDLIST_NAME (t, i);
2508 char dem_opname[64];
2509
c5aa993b
JM
2510 if (strncmp (t_field_name, "__", 2) == 0 ||
2511 strncmp (t_field_name, "op", 2) == 0 ||
2512 strncmp (t_field_name, "type", 4) == 0)
c906108c 2513 {
c5aa993b
JM
2514 if (cplus_demangle_opname (t_field_name, dem_opname, DMGL_ANSI))
2515 t_field_name = dem_opname;
2516 else if (cplus_demangle_opname (t_field_name, dem_opname, 0))
c906108c 2517 t_field_name = dem_opname;
c906108c 2518 }
6314a349 2519 if (t_field_name && strcmp (t_field_name, name) == 0)
c906108c
SS
2520 {
2521 int j = TYPE_FN_FIELDLIST_LENGTH (t, i);
2522 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
c5aa993b 2523
de17c821
DJ
2524 check_stub_method_group (t, i);
2525
c906108c
SS
2526 if (intype == 0 && j > 1)
2527 error ("non-unique member `%s' requires type instantiation", name);
2528 if (intype)
2529 {
2530 while (j--)
2531 if (TYPE_FN_FIELD_TYPE (f, j) == intype)
2532 break;
2533 if (j < 0)
2534 error ("no member function matches that type instantiation");
2535 }
2536 else
2537 j = 0;
c5aa993b 2538
c906108c
SS
2539 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
2540 {
2541 return value_from_longest
2542 (lookup_reference_type
2543 (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),
2544 domain)),
2545 (LONGEST) METHOD_PTR_FROM_VOFFSET (TYPE_FN_FIELD_VOFFSET (f, j)));
2546 }
2547 else
2548 {
2549 struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
176620f1 2550 0, VAR_DOMAIN, 0, NULL);
c906108c
SS
2551 if (s == NULL)
2552 {
2553 v = 0;
2554 }
2555 else
2556 {
2557 v = read_var_value (s, 0);
2558#if 0
2559 VALUE_TYPE (v) = lookup_reference_type
2560 (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),
2561 domain));
2562#endif
2563 }
2564 return v;
2565 }
2566 }
2567 }
2568 for (i = TYPE_N_BASECLASSES (t) - 1; i >= 0; i--)
2569 {
f23631e4 2570 struct value *v;
c906108c
SS
2571 int base_offset;
2572
2573 if (BASETYPE_VIA_VIRTUAL (t, i))
2574 base_offset = 0;
2575 else
2576 base_offset = TYPE_BASECLASS_BITPOS (t, i) / 8;
2577 v = value_struct_elt_for_reference (domain,
2578 offset + base_offset,
2579 TYPE_BASECLASS (t, i),
2580 name,
63d06c5c
DC
2581 intype,
2582 noside);
c906108c
SS
2583 if (v)
2584 return v;
2585 }
63d06c5c
DC
2586
2587 /* As a last chance, pretend that CURTYPE is a namespace, and look
2588 it up that way; this (frequently) works for types nested inside
2589 classes. */
2590
2591 return value_maybe_namespace_elt (curtype, name, noside);
c906108c
SS
2592}
2593
79c2c32d
DC
2594/* C++: Return the member NAME of the namespace given by the type
2595 CURTYPE. */
2596
2597static struct value *
2598value_namespace_elt (const struct type *curtype,
63d06c5c 2599 char *name,
79c2c32d 2600 enum noside noside)
63d06c5c
DC
2601{
2602 struct value *retval = value_maybe_namespace_elt (curtype, name,
2603 noside);
2604
2605 if (retval == NULL)
2606 error ("No symbol \"%s\" in namespace \"%s\".", name,
2607 TYPE_TAG_NAME (curtype));
2608
2609 return retval;
2610}
2611
2612/* A helper function used by value_namespace_elt and
2613 value_struct_elt_for_reference. It looks up NAME inside the
2614 context CURTYPE; this works if CURTYPE is a namespace or if CURTYPE
2615 is a class and NAME refers to a type in CURTYPE itself (as opposed
2616 to, say, some base class of CURTYPE). */
2617
2618static struct value *
2619value_maybe_namespace_elt (const struct type *curtype,
2620 char *name,
2621 enum noside noside)
79c2c32d
DC
2622{
2623 const char *namespace_name = TYPE_TAG_NAME (curtype);
2624 struct symbol *sym;
79c2c32d
DC
2625
2626 sym = cp_lookup_symbol_namespace (namespace_name, name, NULL,
2627 get_selected_block (0), VAR_DOMAIN,
2628 NULL);
2629
2630 if (sym == NULL)
63d06c5c 2631 return NULL;
79c2c32d
DC
2632 else if ((noside == EVAL_AVOID_SIDE_EFFECTS)
2633 && (SYMBOL_CLASS (sym) == LOC_TYPEDEF))
63d06c5c 2634 return allocate_value (SYMBOL_TYPE (sym));
79c2c32d 2635 else
63d06c5c 2636 return value_of_variable (sym, get_selected_block (0));
79c2c32d
DC
2637}
2638
c906108c
SS
2639/* Given a pointer value V, find the real (RTTI) type
2640 of the object it points to.
2641 Other parameters FULL, TOP, USING_ENC as with value_rtti_type()
2642 and refer to the values computed for the object pointed to. */
2643
2644struct type *
f23631e4 2645value_rtti_target_type (struct value *v, int *full, int *top, int *using_enc)
c906108c 2646{
f23631e4 2647 struct value *target;
c906108c
SS
2648
2649 target = value_ind (v);
2650
2651 return value_rtti_type (target, full, top, using_enc);
2652}
2653
2654/* Given a value pointed to by ARGP, check its real run-time type, and
2655 if that is different from the enclosing type, create a new value
2656 using the real run-time type as the enclosing type (and of the same
2657 type as ARGP) and return it, with the embedded offset adjusted to
2658 be the correct offset to the enclosed object
2659 RTYPE is the type, and XFULL, XTOP, and XUSING_ENC are the other
2660 parameters, computed by value_rtti_type(). If these are available,
2661 they can be supplied and a second call to value_rtti_type() is avoided.
2662 (Pass RTYPE == NULL if they're not available */
2663
f23631e4
AC
2664struct value *
2665value_full_object (struct value *argp, struct type *rtype, int xfull, int xtop,
fba45db2 2666 int xusing_enc)
c906108c 2667{
c5aa993b 2668 struct type *real_type;
c906108c
SS
2669 int full = 0;
2670 int top = -1;
2671 int using_enc = 0;
f23631e4 2672 struct value *new_val;
c906108c
SS
2673
2674 if (rtype)
2675 {
2676 real_type = rtype;
2677 full = xfull;
2678 top = xtop;
2679 using_enc = xusing_enc;
2680 }
2681 else
2682 real_type = value_rtti_type (argp, &full, &top, &using_enc);
2683
2684 /* If no RTTI data, or if object is already complete, do nothing */
2685 if (!real_type || real_type == VALUE_ENCLOSING_TYPE (argp))
2686 return argp;
2687
2688 /* If we have the full object, but for some reason the enclosing
c5aa993b 2689 type is wrong, set it *//* pai: FIXME -- sounds iffy */
c906108c
SS
2690 if (full)
2691 {
2b127877 2692 argp = value_change_enclosing_type (argp, real_type);
c906108c
SS
2693 return argp;
2694 }
2695
2696 /* Check if object is in memory */
2697 if (VALUE_LVAL (argp) != lval_memory)
2698 {
2699 warning ("Couldn't retrieve complete object of RTTI type %s; object may be in register(s).", TYPE_NAME (real_type));
c5aa993b 2700
c906108c
SS
2701 return argp;
2702 }
c5aa993b 2703
c906108c
SS
2704 /* All other cases -- retrieve the complete object */
2705 /* Go back by the computed top_offset from the beginning of the object,
2706 adjusting for the embedded offset of argp if that's what value_rtti_type
2707 used for its computation. */
2708 new_val = value_at_lazy (real_type, VALUE_ADDRESS (argp) - top +
c5aa993b
JM
2709 (using_enc ? 0 : VALUE_EMBEDDED_OFFSET (argp)),
2710 VALUE_BFD_SECTION (argp));
c906108c
SS
2711 VALUE_TYPE (new_val) = VALUE_TYPE (argp);
2712 VALUE_EMBEDDED_OFFSET (new_val) = using_enc ? top + VALUE_EMBEDDED_OFFSET (argp) : top;
2713 return new_val;
2714}
2715
389e51db
AC
2716
2717
2718
d069f99d 2719/* Return the value of the local variable, if one exists.
c906108c
SS
2720 Flag COMPLAIN signals an error if the request is made in an
2721 inappropriate context. */
2722
f23631e4 2723struct value *
d069f99d 2724value_of_local (const char *name, int complain)
c906108c
SS
2725{
2726 struct symbol *func, *sym;
2727 struct block *b;
d069f99d 2728 struct value * ret;
c906108c 2729
6e7f8b9c 2730 if (deprecated_selected_frame == 0)
c906108c
SS
2731 {
2732 if (complain)
c5aa993b
JM
2733 error ("no frame selected");
2734 else
2735 return 0;
c906108c
SS
2736 }
2737
6e7f8b9c 2738 func = get_frame_function (deprecated_selected_frame);
c906108c
SS
2739 if (!func)
2740 {
2741 if (complain)
2625d86c 2742 error ("no `%s' in nameless context", name);
c5aa993b
JM
2743 else
2744 return 0;
c906108c
SS
2745 }
2746
2747 b = SYMBOL_BLOCK_VALUE (func);
de4f826b 2748 if (dict_empty (BLOCK_DICT (b)))
c906108c
SS
2749 {
2750 if (complain)
2625d86c 2751 error ("no args, no `%s'", name);
c5aa993b
JM
2752 else
2753 return 0;
c906108c
SS
2754 }
2755
2756 /* Calling lookup_block_symbol is necessary to get the LOC_REGISTER
2757 symbol instead of the LOC_ARG one (if both exist). */
176620f1 2758 sym = lookup_block_symbol (b, name, NULL, VAR_DOMAIN);
c906108c
SS
2759 if (sym == NULL)
2760 {
2761 if (complain)
2625d86c 2762 error ("current stack frame does not contain a variable named `%s'", name);
c906108c
SS
2763 else
2764 return NULL;
2765 }
2766
6e7f8b9c 2767 ret = read_var_value (sym, deprecated_selected_frame);
d069f99d 2768 if (ret == 0 && complain)
2625d86c 2769 error ("`%s' argument unreadable", name);
d069f99d
AF
2770 return ret;
2771}
2772
2773/* C++/Objective-C: return the value of the class instance variable,
2774 if one exists. Flag COMPLAIN signals an error if the request is
2775 made in an inappropriate context. */
2776
2777struct value *
2778value_of_this (int complain)
2779{
2780 if (current_language->la_language == language_objc)
2781 return value_of_local ("self", complain);
2782 else
2783 return value_of_local ("this", complain);
c906108c
SS
2784}
2785
2786/* Create a slice (sub-string, sub-array) of ARRAY, that is LENGTH elements
2787 long, starting at LOWBOUND. The result has the same lower bound as
2788 the original ARRAY. */
2789
f23631e4
AC
2790struct value *
2791value_slice (struct value *array, int lowbound, int length)
c906108c
SS
2792{
2793 struct type *slice_range_type, *slice_type, *range_type;
7a67d0fe 2794 LONGEST lowerbound, upperbound;
f23631e4 2795 struct value *slice;
c906108c
SS
2796 struct type *array_type;
2797 array_type = check_typedef (VALUE_TYPE (array));
2798 COERCE_VARYING_ARRAY (array, array_type);
2799 if (TYPE_CODE (array_type) != TYPE_CODE_ARRAY
2800 && TYPE_CODE (array_type) != TYPE_CODE_STRING
2801 && TYPE_CODE (array_type) != TYPE_CODE_BITSTRING)
2802 error ("cannot take slice of non-array");
2803 range_type = TYPE_INDEX_TYPE (array_type);
2804 if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
2805 error ("slice from bad array or bitstring");
2806 if (lowbound < lowerbound || length < 0
db034ac5 2807 || lowbound + length - 1 > upperbound)
c906108c
SS
2808 error ("slice out of range");
2809 /* FIXME-type-allocation: need a way to free this type when we are
2810 done with it. */
c5aa993b 2811 slice_range_type = create_range_type ((struct type *) NULL,
c906108c
SS
2812 TYPE_TARGET_TYPE (range_type),
2813 lowbound, lowbound + length - 1);
2814 if (TYPE_CODE (array_type) == TYPE_CODE_BITSTRING)
2815 {
2816 int i;
c5aa993b 2817 slice_type = create_set_type ((struct type *) NULL, slice_range_type);
c906108c
SS
2818 TYPE_CODE (slice_type) = TYPE_CODE_BITSTRING;
2819 slice = value_zero (slice_type, not_lval);
2820 for (i = 0; i < length; i++)
2821 {
2822 int element = value_bit_index (array_type,
2823 VALUE_CONTENTS (array),
2824 lowbound + i);
2825 if (element < 0)
2826 error ("internal error accessing bitstring");
2827 else if (element > 0)
2828 {
2829 int j = i % TARGET_CHAR_BIT;
2830 if (BITS_BIG_ENDIAN)
2831 j = TARGET_CHAR_BIT - 1 - j;
2832 VALUE_CONTENTS_RAW (slice)[i / TARGET_CHAR_BIT] |= (1 << j);
2833 }
2834 }
2835 /* We should set the address, bitssize, and bitspos, so the clice
7b83ea04
AC
2836 can be used on the LHS, but that may require extensions to
2837 value_assign. For now, just leave as a non_lval. FIXME. */
c906108c
SS
2838 }
2839 else
2840 {
2841 struct type *element_type = TYPE_TARGET_TYPE (array_type);
7a67d0fe 2842 LONGEST offset
c906108c 2843 = (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
c5aa993b 2844 slice_type = create_array_type ((struct type *) NULL, element_type,
c906108c
SS
2845 slice_range_type);
2846 TYPE_CODE (slice_type) = TYPE_CODE (array_type);
2847 slice = allocate_value (slice_type);
2848 if (VALUE_LAZY (array))
2849 VALUE_LAZY (slice) = 1;
2850 else
2851 memcpy (VALUE_CONTENTS (slice), VALUE_CONTENTS (array) + offset,
2852 TYPE_LENGTH (slice_type));
2853 if (VALUE_LVAL (array) == lval_internalvar)
2854 VALUE_LVAL (slice) = lval_internalvar_component;
2855 else
2856 VALUE_LVAL (slice) = VALUE_LVAL (array);
2857 VALUE_ADDRESS (slice) = VALUE_ADDRESS (array);
2858 VALUE_OFFSET (slice) = VALUE_OFFSET (array) + offset;
2859 }
2860 return slice;
2861}
2862
070ad9f0
DB
2863/* Create a value for a FORTRAN complex number. Currently most of
2864 the time values are coerced to COMPLEX*16 (i.e. a complex number
2865 composed of 2 doubles. This really should be a smarter routine
2866 that figures out precision inteligently as opposed to assuming
c5aa993b 2867 doubles. FIXME: fmb */
c906108c 2868
f23631e4
AC
2869struct value *
2870value_literal_complex (struct value *arg1, struct value *arg2, struct type *type)
c906108c 2871{
f23631e4 2872 struct value *val;
c906108c
SS
2873 struct type *real_type = TYPE_TARGET_TYPE (type);
2874
2875 val = allocate_value (type);
2876 arg1 = value_cast (real_type, arg1);
2877 arg2 = value_cast (real_type, arg2);
2878
2879 memcpy (VALUE_CONTENTS_RAW (val),
2880 VALUE_CONTENTS (arg1), TYPE_LENGTH (real_type));
2881 memcpy (VALUE_CONTENTS_RAW (val) + TYPE_LENGTH (real_type),
2882 VALUE_CONTENTS (arg2), TYPE_LENGTH (real_type));
2883 return val;
2884}
2885
2886/* Cast a value into the appropriate complex data type. */
2887
f23631e4
AC
2888static struct value *
2889cast_into_complex (struct type *type, struct value *val)
c906108c
SS
2890{
2891 struct type *real_type = TYPE_TARGET_TYPE (type);
2892 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_COMPLEX)
2893 {
2894 struct type *val_real_type = TYPE_TARGET_TYPE (VALUE_TYPE (val));
f23631e4
AC
2895 struct value *re_val = allocate_value (val_real_type);
2896 struct value *im_val = allocate_value (val_real_type);
c906108c
SS
2897
2898 memcpy (VALUE_CONTENTS_RAW (re_val),
2899 VALUE_CONTENTS (val), TYPE_LENGTH (val_real_type));
2900 memcpy (VALUE_CONTENTS_RAW (im_val),
2901 VALUE_CONTENTS (val) + TYPE_LENGTH (val_real_type),
c5aa993b 2902 TYPE_LENGTH (val_real_type));
c906108c
SS
2903
2904 return value_literal_complex (re_val, im_val, type);
2905 }
2906 else if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_FLT
2907 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
2908 return value_literal_complex (val, value_zero (real_type, not_lval), type);
2909 else
2910 error ("cannot cast non-number to complex");
2911}
2912
2913void
fba45db2 2914_initialize_valops (void)
c906108c
SS
2915{
2916#if 0
2917 add_show_from_set
c5aa993b 2918 (add_set_cmd ("abandon", class_support, var_boolean, (char *) &auto_abandon,
c906108c
SS
2919 "Set automatic abandonment of expressions upon failure.",
2920 &setlist),
2921 &showlist);
2922#endif
2923
2924 add_show_from_set
c5aa993b 2925 (add_set_cmd ("overload-resolution", class_support, var_boolean, (char *) &overload_resolution,
c906108c
SS
2926 "Set overload resolution in evaluating C++ functions.",
2927 &setlist),
2928 &showlist);
2929 overload_resolution = 1;
c906108c 2930}
This page took 0.642104 seconds and 4 git commands to generate.