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