File: | src/gnu/usr.bin/binutils/gdb/ada-lang.c |
Warning: | line 1622, column 3 Value stored to 'type' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* Ada language support routines for GDB, the GNU debugger. Copyright |
2 | 1992, 1993, 1994, 1997, 1998, 1999, 2000, 2003, 2004. |
3 | Free Software Foundation, Inc. |
4 | |
5 | This file is part of GDB. |
6 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
20 | |
21 | |
22 | #include "defs.h" |
23 | #include <stdio.h> |
24 | #include "gdb_string.h" |
25 | #include <ctype.h> |
26 | #include <stdarg.h> |
27 | #include "demangle.h" |
28 | #include "gdb_regex.h" |
29 | #include "frame.h" |
30 | #include "symtab.h" |
31 | #include "gdbtypes.h" |
32 | #include "gdbcmd.h" |
33 | #include "expression.h" |
34 | #include "parser-defs.h" |
35 | #include "language.h" |
36 | #include "c-lang.h" |
37 | #include "inferior.h" |
38 | #include "symfile.h" |
39 | #include "objfiles.h" |
40 | #include "breakpoint.h" |
41 | #include "gdbcore.h" |
42 | #include "hashtab.h" |
43 | #include "gdb_obstack.h" |
44 | #include "ada-lang.h" |
45 | #include "completer.h" |
46 | #include "gdb_stat.h" |
47 | #ifdef UI_OUT |
48 | #include "ui-out.h" |
49 | #endif |
50 | #include "block.h" |
51 | #include "infcall.h" |
52 | #include "dictionary.h" |
53 | |
54 | #ifndef ADA_RETAIN_DOTS0 |
55 | #define ADA_RETAIN_DOTS0 0 |
56 | #endif |
57 | |
58 | /* Define whether or not the C operator '/' truncates towards zero for |
59 | differently signed operands (truncation direction is undefined in C). |
60 | Copied from valarith.c. */ |
61 | |
62 | #ifndef TRUNCATION_TOWARDS_ZERO((-5 / 2) == -2) |
63 | #define TRUNCATION_TOWARDS_ZERO((-5 / 2) == -2) ((-5 / 2) == -2) |
64 | #endif |
65 | |
66 | |
67 | static void extract_string (CORE_ADDR addr, char *buf); |
68 | |
69 | static struct type *ada_create_fundamental_type (struct objfile *, int); |
70 | |
71 | static void modify_general_field (char *, LONGESTlong, int, int); |
72 | |
73 | static struct type *desc_base_type (struct type *); |
74 | |
75 | static struct type *desc_bounds_type (struct type *); |
76 | |
77 | static struct value *desc_bounds (struct value *); |
78 | |
79 | static int fat_pntr_bounds_bitpos (struct type *); |
80 | |
81 | static int fat_pntr_bounds_bitsize (struct type *); |
82 | |
83 | static struct type *desc_data_type (struct type *); |
84 | |
85 | static struct value *desc_data (struct value *); |
86 | |
87 | static int fat_pntr_data_bitpos (struct type *); |
88 | |
89 | static int fat_pntr_data_bitsize (struct type *); |
90 | |
91 | static struct value *desc_one_bound (struct value *, int, int); |
92 | |
93 | static int desc_bound_bitpos (struct type *, int, int); |
94 | |
95 | static int desc_bound_bitsize (struct type *, int, int); |
96 | |
97 | static struct type *desc_index_type (struct type *, int); |
98 | |
99 | static int desc_arity (struct type *); |
100 | |
101 | static int ada_type_match (struct type *, struct type *, int); |
102 | |
103 | static int ada_args_match (struct symbol *, struct value **, int); |
104 | |
105 | static struct value *ensure_lval (struct value *, CORE_ADDR *); |
106 | |
107 | static struct value *convert_actual (struct value *, struct type *, |
108 | CORE_ADDR *); |
109 | |
110 | static struct value *make_array_descriptor (struct type *, struct value *, |
111 | CORE_ADDR *); |
112 | |
113 | static void ada_add_block_symbols (struct obstack *, |
114 | struct block *, const char *, |
115 | domain_enum, struct objfile *, |
116 | struct symtab *, int); |
117 | |
118 | static int is_nonfunction (struct ada_symbol_info *, int); |
119 | |
120 | static void add_defn_to_vec (struct obstack *, struct symbol *, |
121 | struct block *, struct symtab *); |
122 | |
123 | static int num_defns_collected (struct obstack *); |
124 | |
125 | static struct ada_symbol_info *defns_collected (struct obstack *, int); |
126 | |
127 | static struct partial_symbol *ada_lookup_partial_symbol (struct partial_symtab |
128 | *, const char *, int, |
129 | domain_enum, int); |
130 | |
131 | static struct symtab *symtab_for_sym (struct symbol *); |
132 | |
133 | static struct value *resolve_subexp (struct expression **, int *, int, |
134 | struct type *); |
135 | |
136 | static void replace_operator_with_call (struct expression **, int, int, int, |
137 | struct symbol *, struct block *); |
138 | |
139 | static int possible_user_operator_p (enum exp_opcode, struct value **); |
140 | |
141 | static char *ada_op_name (enum exp_opcode); |
142 | |
143 | static const char *ada_decoded_op_name (enum exp_opcode); |
144 | |
145 | static int numeric_type_p (struct type *); |
146 | |
147 | static int integer_type_p (struct type *); |
148 | |
149 | static int scalar_type_p (struct type *); |
150 | |
151 | static int discrete_type_p (struct type *); |
152 | |
153 | static struct type *ada_lookup_struct_elt_type (struct type *, char *, |
154 | int, int, int *); |
155 | |
156 | static struct value *evaluate_subexp (struct type *, struct expression *, |
157 | int *, enum noside); |
158 | |
159 | static struct value *evaluate_subexp_type (struct expression *, int *); |
160 | |
161 | static int is_dynamic_field (struct type *, int); |
162 | |
163 | static struct type *to_fixed_variant_branch_type (struct type *, char *, |
164 | CORE_ADDR, struct value *); |
165 | |
166 | static struct type *to_fixed_array_type (struct type *, struct value *, int); |
167 | |
168 | static struct type *to_fixed_range_type (char *, struct value *, |
169 | struct objfile *); |
170 | |
171 | static struct type *to_static_fixed_type (struct type *); |
172 | |
173 | static struct value *unwrap_value (struct value *); |
174 | |
175 | static struct type *packed_array_type (struct type *, long *); |
176 | |
177 | static struct type *decode_packed_array_type (struct type *); |
178 | |
179 | static struct value *decode_packed_array (struct value *); |
180 | |
181 | static struct value *value_subscript_packed (struct value *, int, |
182 | struct value **); |
183 | |
184 | static struct value *coerce_unspec_val_to_type (struct value *, |
185 | struct type *); |
186 | |
187 | static struct value *get_var_value (char *, char *); |
188 | |
189 | static int lesseq_defined_than (struct symbol *, struct symbol *); |
190 | |
191 | static int equiv_types (struct type *, struct type *); |
192 | |
193 | static int is_name_suffix (const char *); |
194 | |
195 | static int wild_match (const char *, int, const char *); |
196 | |
197 | static struct value *ada_coerce_ref (struct value *); |
198 | |
199 | static LONGESTlong pos_atr (struct value *); |
200 | |
201 | static struct value *value_pos_atr (struct value *); |
202 | |
203 | static struct value *value_val_atr (struct type *, struct value *); |
204 | |
205 | static struct symbol *standard_lookup (const char *, const struct block *, |
206 | domain_enum); |
207 | |
208 | static struct value *ada_search_struct_field (char *, struct value *, int, |
209 | struct type *); |
210 | |
211 | static struct value *ada_value_primitive_field (struct value *, int, int, |
212 | struct type *); |
213 | |
214 | static int find_struct_field (char *, struct type *, int, |
215 | struct type **, int *, int *, int *); |
216 | |
217 | static struct value *ada_to_fixed_value_create (struct type *, CORE_ADDR, |
218 | struct value *); |
219 | |
220 | static struct value *ada_to_fixed_value (struct value *); |
221 | |
222 | static int ada_resolve_function (struct ada_symbol_info *, int, |
223 | struct value **, int, const char *, |
224 | struct type *); |
225 | |
226 | static struct value *ada_coerce_to_simple_array (struct value *); |
227 | |
228 | static int ada_is_direct_array_type (struct type *); |
229 | |
230 | static void ada_language_arch_info (struct gdbarch *, |
231 | struct language_arch_info *); |
232 | |
233 | static void check_size (const struct type *); |
234 | |
235 | |
236 | |
237 | /* Maximum-sized dynamic type. */ |
238 | static unsigned int varsize_limit; |
239 | |
240 | /* FIXME: brobecker/2003-09-17: No longer a const because it is |
241 | returned by a function that does not return a const char *. */ |
242 | static char *ada_completer_word_break_characters = |
243 | #ifdef VMS |
244 | " \t\n!@#%^&*()+=|~`}{[]\";:?/,-"; |
245 | #else |
246 | " \t\n!@#$%^&*()+=|~`}{[]\";:?/,-"; |
247 | #endif |
248 | |
249 | /* The name of the symbol to use to get the name of the main subprogram. */ |
250 | static const char ADA_MAIN_PROGRAM_SYMBOL_NAME[] |
251 | = "__gnat_ada_main_program_name"; |
252 | |
253 | /* The name of the runtime function called when an exception is raised. */ |
254 | static const char raise_sym_name[] = "__gnat_raise_nodefer_with_msg"; |
255 | |
256 | /* The name of the runtime function called when an unhandled exception |
257 | is raised. */ |
258 | static const char raise_unhandled_sym_name[] = "__gnat_unhandled_exception"; |
259 | |
260 | /* The name of the runtime function called when an assert failure is |
261 | raised. */ |
262 | static const char raise_assert_sym_name[] = |
263 | "system__assertions__raise_assert_failure"; |
264 | |
265 | /* When GDB stops on an unhandled exception, GDB will go up the stack until |
266 | if finds a frame corresponding to this function, in order to extract the |
267 | name of the exception that has been raised from one of the parameters. */ |
268 | static const char process_raise_exception_name[] = |
269 | "ada__exceptions__process_raise_exception"; |
270 | |
271 | /* A string that reflects the longest exception expression rewrite, |
272 | aside from the exception name. */ |
273 | static const char longest_exception_template[] = |
274 | "'__gnat_raise_nodefer_with_msg' if long_integer(e) = long_integer(&)"; |
275 | |
276 | /* Limit on the number of warnings to raise per expression evaluation. */ |
277 | static int warning_limit = 2; |
278 | |
279 | /* Number of warning messages issued; reset to 0 by cleanups after |
280 | expression evaluation. */ |
281 | static int warnings_issued = 0; |
282 | |
283 | static const char *known_runtime_file_name_patterns[] = { |
284 | ADA_KNOWN_RUNTIME_FILE_NAME_PATTERNS"^[agis]-.*\\.ad[bs]$", NULL((void*)0) |
285 | }; |
286 | |
287 | static const char *known_auxiliary_function_name_patterns[] = { |
288 | ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS"___clean[.a-zA-Z0-9_]*$", NULL((void*)0) |
289 | }; |
290 | |
291 | /* Space for allocating results of ada_lookup_symbol_list. */ |
292 | static struct obstack symbol_list_obstack; |
293 | |
294 | /* Utilities */ |
295 | |
296 | |
297 | static char * |
298 | ada_get_gdb_completer_word_break_characters (void) |
299 | { |
300 | return ada_completer_word_break_characters; |
301 | } |
302 | |
303 | /* Read the string located at ADDR from the inferior and store the |
304 | result into BUF. */ |
305 | |
306 | static void |
307 | extract_string (CORE_ADDR addr, char *buf) |
308 | { |
309 | int char_index = 0; |
310 | |
311 | /* Loop, reading one byte at a time, until we reach the '\000' |
312 | end-of-string marker. */ |
313 | do |
314 | { |
315 | target_read_memory (addr + char_index * sizeof (char), |
316 | buf + char_index * sizeof (char), sizeof (char)); |
317 | char_index++; |
318 | } |
319 | while (buf[char_index - 1] != '\000'); |
320 | } |
321 | |
322 | /* Assuming *OLD_VECT points to an array of *SIZE objects of size |
323 | ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects, |
324 | updating *OLD_VECT and *SIZE as necessary. */ |
325 | |
326 | void |
327 | grow_vect (void **old_vect, size_t * size, size_t min_size, int element_size) |
328 | { |
329 | if (*size < min_size) |
330 | { |
331 | *size *= 2; |
332 | if (*size < min_size) |
333 | *size = min_size; |
334 | *old_vect = xrealloc (*old_vect, *size * element_size); |
335 | } |
336 | } |
337 | |
338 | /* True (non-zero) iff TARGET matches FIELD_NAME up to any trailing |
339 | suffix of FIELD_NAME beginning "___". */ |
340 | |
341 | static int |
342 | field_name_match (const char *field_name, const char *target) |
343 | { |
344 | int len = strlen (target); |
345 | return |
346 | (strncmp (field_name, target, len) == 0 |
347 | && (field_name[len] == '\0' |
348 | || (strncmp (field_name + len, "___", 3) == 0 |
349 | && strcmp (field_name + strlen (field_name) - 6, |
350 | "___XVN") != 0))); |
351 | } |
352 | |
353 | |
354 | /* Assuming TYPE is a TYPE_CODE_STRUCT, find the field whose name matches |
355 | FIELD_NAME, and return its index. This function also handles fields |
356 | whose name have ___ suffixes because the compiler sometimes alters |
357 | their name by adding such a suffix to represent fields with certain |
358 | constraints. If the field could not be found, return a negative |
359 | number if MAYBE_MISSING is set. Otherwise raise an error. */ |
360 | |
361 | int |
362 | ada_get_field_index (const struct type *type, const char *field_name, |
363 | int maybe_missing) |
364 | { |
365 | int fieldno; |
366 | for (fieldno = 0; fieldno < TYPE_NFIELDS (type)(type)->main_type->nfields; fieldno++) |
367 | if (field_name_match (TYPE_FIELD_NAME (type, fieldno)(((type)->main_type->fields[fieldno]).name), field_name)) |
368 | return fieldno; |
369 | |
370 | if (!maybe_missing) |
371 | error ("Unable to find field %s in struct %s. Aborting", |
372 | field_name, TYPE_NAME (type)(type)->main_type->name); |
373 | |
374 | return -1; |
375 | } |
376 | |
377 | /* The length of the prefix of NAME prior to any "___" suffix. */ |
378 | |
379 | int |
380 | ada_name_prefix_len (const char *name) |
381 | { |
382 | if (name == NULL((void*)0)) |
383 | return 0; |
384 | else |
385 | { |
386 | const char *p = strstr (name, "___"); |
387 | if (p == NULL((void*)0)) |
388 | return strlen (name); |
389 | else |
390 | return p - name; |
391 | } |
392 | } |
393 | |
394 | /* Return non-zero if SUFFIX is a suffix of STR. |
395 | Return zero if STR is null. */ |
396 | |
397 | static int |
398 | is_suffix (const char *str, const char *suffix) |
399 | { |
400 | int len1, len2; |
401 | if (str == NULL((void*)0)) |
402 | return 0; |
403 | len1 = strlen (str); |
404 | len2 = strlen (suffix); |
405 | return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0); |
406 | } |
407 | |
408 | /* Create a value of type TYPE whose contents come from VALADDR, if it |
409 | is non-null, and whose memory address (in the inferior) is |
410 | ADDRESS. */ |
411 | |
412 | struct value * |
413 | value_from_contents_and_address (struct type *type, char *valaddr, |
414 | CORE_ADDR address) |
415 | { |
416 | struct value *v = allocate_value (type); |
417 | if (valaddr == NULL((void*)0)) |
418 | VALUE_LAZY (v)(v)->lazy = 1; |
419 | else |
420 | memcpy (VALUE_CONTENTS_RAW (v)((char *) (v)->aligner.contents + (v)->embedded_offset), valaddr, TYPE_LENGTH (type)(type)->length); |
421 | VALUE_ADDRESS (v)(v)->location.address = address; |
422 | if (address != 0) |
423 | VALUE_LVAL (v)(v)->lval = lval_memory; |
424 | return v; |
425 | } |
426 | |
427 | /* The contents of value VAL, treated as a value of type TYPE. The |
428 | result is an lval in memory if VAL is. */ |
429 | |
430 | static struct value * |
431 | coerce_unspec_val_to_type (struct value *val, struct type *type) |
432 | { |
433 | type = ada_check_typedef (type); |
434 | if (VALUE_TYPE (val)(val)->type == type) |
435 | return val; |
436 | else |
437 | { |
438 | struct value *result; |
439 | |
440 | /* Make sure that the object size is not unreasonable before |
441 | trying to allocate some memory for it. */ |
442 | check_size (type); |
443 | |
444 | result = allocate_value (type); |
445 | VALUE_LVAL (result)(result)->lval = VALUE_LVAL (val)(val)->lval; |
446 | VALUE_BITSIZE (result)(result)->bitsize = VALUE_BITSIZE (val)(val)->bitsize; |
447 | VALUE_BITPOS (result)(result)->bitpos = VALUE_BITPOS (val)(val)->bitpos; |
448 | VALUE_ADDRESS (result)(result)->location.address = VALUE_ADDRESS (val)(val)->location.address + VALUE_OFFSET (val)(val)->offset; |
449 | if (VALUE_LAZY (val)(val)->lazy |
450 | || TYPE_LENGTH (type)(type)->length > TYPE_LENGTH (VALUE_TYPE (val))((val)->type)->length) |
451 | VALUE_LAZY (result)(result)->lazy = 1; |
452 | else |
453 | memcpy (VALUE_CONTENTS_RAW (result)((char *) (result)->aligner.contents + (result)->embedded_offset ), VALUE_CONTENTS (val)((void)((val)->lazy && value_fetch_lazy(val)), ((char *) (val)->aligner.contents + (val)->embedded_offset)), |
454 | TYPE_LENGTH (type)(type)->length); |
455 | return result; |
456 | } |
457 | } |
458 | |
459 | static char * |
460 | cond_offset_host (char *valaddr, long offset) |
461 | { |
462 | if (valaddr == NULL((void*)0)) |
463 | return NULL((void*)0); |
464 | else |
465 | return valaddr + offset; |
466 | } |
467 | |
468 | static CORE_ADDR |
469 | cond_offset_target (CORE_ADDR address, long offset) |
470 | { |
471 | if (address == 0) |
472 | return 0; |
473 | else |
474 | return address + offset; |
475 | } |
476 | |
477 | /* Issue a warning (as for the definition of warning in utils.c, but |
478 | with exactly one argument rather than ...), unless the limit on the |
479 | number of warnings has passed during the evaluation of the current |
480 | expression. */ |
481 | |
482 | /* FIXME: cagney/2004-10-10: This function is mimicking the behavior |
483 | provided by "complaint". */ |
484 | static void lim_warning (const char *format, ...) ATTR_FORMAT (printf, 1, 2)__attribute__ ((format(printf, 1, 2))); |
485 | |
486 | static void |
487 | lim_warning (const char *format, ...) |
488 | { |
489 | va_list args; |
490 | va_start (args, format)__builtin_va_start(args, format); |
491 | |
492 | warnings_issued += 1; |
493 | if (warnings_issued <= warning_limit) |
494 | vwarning (format, args); |
495 | |
496 | va_end (args)__builtin_va_end(args); |
497 | } |
498 | |
499 | /* Issue an error if the size of an object of type T is unreasonable, |
500 | i.e. if it would be a bad idea to allocate a value of this type in |
501 | GDB. */ |
502 | |
503 | static void |
504 | check_size (const struct type *type) |
505 | { |
506 | if (TYPE_LENGTH (type)(type)->length > varsize_limit) |
507 | error ("object size is larger than varsize-limit"); |
508 | } |
509 | |
510 | |
511 | /* Note: would have used MAX_OF_TYPE and MIN_OF_TYPE macros from |
512 | gdbtypes.h, but some of the necessary definitions in that file |
513 | seem to have gone missing. */ |
514 | |
515 | /* Maximum value of a SIZE-byte signed integer type. */ |
516 | static LONGESTlong |
517 | max_of_size (int size) |
518 | { |
519 | LONGESTlong top_bit = (LONGESTlong) 1 << (size * 8 - 2); |
520 | return top_bit | (top_bit - 1); |
521 | } |
522 | |
523 | /* Minimum value of a SIZE-byte signed integer type. */ |
524 | static LONGESTlong |
525 | min_of_size (int size) |
526 | { |
527 | return -max_of_size (size) - 1; |
528 | } |
529 | |
530 | /* Maximum value of a SIZE-byte unsigned integer type. */ |
531 | static ULONGESTunsigned long |
532 | umax_of_size (int size) |
533 | { |
534 | ULONGESTunsigned long top_bit = (ULONGESTunsigned long) 1 << (size * 8 - 1); |
535 | return top_bit | (top_bit - 1); |
536 | } |
537 | |
538 | /* Maximum value of integral type T, as a signed quantity. */ |
539 | static LONGESTlong |
540 | max_of_type (struct type *t) |
541 | { |
542 | if (TYPE_UNSIGNED (t)((t)->main_type->flags & (1 << 0))) |
543 | return (LONGESTlong) umax_of_size (TYPE_LENGTH (t)(t)->length); |
544 | else |
545 | return max_of_size (TYPE_LENGTH (t)(t)->length); |
546 | } |
547 | |
548 | /* Minimum value of integral type T, as a signed quantity. */ |
549 | static LONGESTlong |
550 | min_of_type (struct type *t) |
551 | { |
552 | if (TYPE_UNSIGNED (t)((t)->main_type->flags & (1 << 0))) |
553 | return 0; |
554 | else |
555 | return min_of_size (TYPE_LENGTH (t)(t)->length); |
556 | } |
557 | |
558 | /* The largest value in the domain of TYPE, a discrete type, as an integer. */ |
559 | static struct value * |
560 | discrete_type_high_bound (struct type *type) |
561 | { |
562 | switch (TYPE_CODE (type)(type)->main_type->code) |
563 | { |
564 | case TYPE_CODE_RANGE: |
565 | return value_from_longest (TYPE_TARGET_TYPE (type)(type)->main_type->target_type, |
566 | TYPE_HIGH_BOUND (type)(((type)->main_type->fields[1]).loc.bitpos)); |
567 | case TYPE_CODE_ENUM: |
568 | return |
569 | value_from_longest (type, |
570 | TYPE_FIELD_BITPOS (type,(((type)->main_type->fields[(type)->main_type->nfields - 1]).loc.bitpos) |
571 | TYPE_NFIELDS (type) - 1)(((type)->main_type->fields[(type)->main_type->nfields - 1]).loc.bitpos)); |
572 | case TYPE_CODE_INT: |
573 | return value_from_longest (type, max_of_type (type)); |
574 | default: |
575 | error ("Unexpected type in discrete_type_high_bound."); |
576 | } |
577 | } |
578 | |
579 | /* The largest value in the domain of TYPE, a discrete type, as an integer. */ |
580 | static struct value * |
581 | discrete_type_low_bound (struct type *type) |
582 | { |
583 | switch (TYPE_CODE (type)(type)->main_type->code) |
584 | { |
585 | case TYPE_CODE_RANGE: |
586 | return value_from_longest (TYPE_TARGET_TYPE (type)(type)->main_type->target_type, |
587 | TYPE_LOW_BOUND (type)(((type)->main_type->fields[0]).loc.bitpos)); |
588 | case TYPE_CODE_ENUM: |
589 | return value_from_longest (type, TYPE_FIELD_BITPOS (type, 0)(((type)->main_type->fields[0]).loc.bitpos)); |
590 | case TYPE_CODE_INT: |
591 | return value_from_longest (type, min_of_type (type)); |
592 | default: |
593 | error ("Unexpected type in discrete_type_low_bound."); |
594 | } |
595 | } |
596 | |
597 | /* The identity on non-range types. For range types, the underlying |
598 | non-range scalar type. */ |
599 | |
600 | static struct type * |
601 | base_type (struct type *type) |
602 | { |
603 | while (type != NULL((void*)0) && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_RANGE) |
604 | { |
605 | if (type == TYPE_TARGET_TYPE (type)(type)->main_type->target_type || TYPE_TARGET_TYPE (type)(type)->main_type->target_type == NULL((void*)0)) |
606 | return type; |
607 | type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type; |
608 | } |
609 | return type; |
610 | } |
611 | |
612 | |
613 | /* Language Selection */ |
614 | |
615 | /* If the main program is in Ada, return language_ada, otherwise return LANG |
616 | (the main program is in Ada iif the adainit symbol is found). |
617 | |
618 | MAIN_PST is not used. */ |
619 | |
620 | enum language |
621 | ada_update_initial_language (enum language lang, |
622 | struct partial_symtab *main_pst) |
623 | { |
624 | if (lookup_minimal_symbol ("adainit", (const char *) NULL((void*)0), |
625 | (struct objfile *) NULL((void*)0)) != NULL((void*)0)) |
626 | return language_ada; |
627 | |
628 | return lang; |
629 | } |
630 | |
631 | /* If the main procedure is written in Ada, then return its name. |
632 | The result is good until the next call. Return NULL if the main |
633 | procedure doesn't appear to be in Ada. */ |
634 | |
635 | char * |
636 | ada_main_name (void) |
637 | { |
638 | struct minimal_symbol *msym; |
639 | CORE_ADDR main_program_name_addr; |
640 | static char main_program_name[1024]; |
641 | |
642 | /* For Ada, the name of the main procedure is stored in a specific |
643 | string constant, generated by the binder. Look for that symbol, |
644 | extract its address, and then read that string. If we didn't find |
645 | that string, then most probably the main procedure is not written |
646 | in Ada. */ |
647 | msym = lookup_minimal_symbol (ADA_MAIN_PROGRAM_SYMBOL_NAME, NULL((void*)0), NULL((void*)0)); |
648 | |
649 | if (msym != NULL((void*)0)) |
650 | { |
651 | main_program_name_addr = SYMBOL_VALUE_ADDRESS (msym)(msym)->ginfo.value.address; |
652 | if (main_program_name_addr == 0) |
653 | error ("Invalid address for Ada main program name."); |
654 | |
655 | extract_string (main_program_name_addr, main_program_name); |
656 | return main_program_name; |
657 | } |
658 | |
659 | /* The main procedure doesn't seem to be in Ada. */ |
660 | return NULL((void*)0); |
661 | } |
662 | |
663 | /* Symbols */ |
664 | |
665 | /* Table of Ada operators and their GNAT-encoded names. Last entry is pair |
666 | of NULLs. */ |
667 | |
668 | const struct ada_opname_map ada_opname_table[] = { |
669 | {"Oadd", "\"+\"", BINOP_ADD}, |
670 | {"Osubtract", "\"-\"", BINOP_SUB}, |
671 | {"Omultiply", "\"*\"", BINOP_MUL}, |
672 | {"Odivide", "\"/\"", BINOP_DIV}, |
673 | {"Omod", "\"mod\"", BINOP_MOD}, |
674 | {"Orem", "\"rem\"", BINOP_REM}, |
675 | {"Oexpon", "\"**\"", BINOP_EXP}, |
676 | {"Olt", "\"<\"", BINOP_LESS}, |
677 | {"Ole", "\"<=\"", BINOP_LEQ}, |
678 | {"Ogt", "\">\"", BINOP_GTR}, |
679 | {"Oge", "\">=\"", BINOP_GEQ}, |
680 | {"Oeq", "\"=\"", BINOP_EQUAL}, |
681 | {"One", "\"/=\"", BINOP_NOTEQUAL}, |
682 | {"Oand", "\"and\"", BINOP_BITWISE_AND}, |
683 | {"Oor", "\"or\"", BINOP_BITWISE_IOR}, |
684 | {"Oxor", "\"xor\"", BINOP_BITWISE_XOR}, |
685 | {"Oconcat", "\"&\"", BINOP_CONCAT}, |
686 | {"Oabs", "\"abs\"", UNOP_ABS}, |
687 | {"Onot", "\"not\"", UNOP_LOGICAL_NOT}, |
688 | {"Oadd", "\"+\"", UNOP_PLUS}, |
689 | {"Osubtract", "\"-\"", UNOP_NEG}, |
690 | {NULL((void*)0), NULL((void*)0)} |
691 | }; |
692 | |
693 | /* Return non-zero if STR should be suppressed in info listings. */ |
694 | |
695 | static int |
696 | is_suppressed_name (const char *str) |
697 | { |
698 | if (strncmp (str, "_ada_", 5) == 0) |
699 | str += 5; |
700 | if (str[0] == '_' || str[0] == '\000') |
701 | return 1; |
702 | else |
703 | { |
704 | const char *p; |
705 | const char *suffix = strstr (str, "___"); |
706 | if (suffix != NULL((void*)0) && suffix[3] != 'X') |
707 | return 1; |
708 | if (suffix == NULL((void*)0)) |
709 | suffix = str + strlen (str); |
710 | for (p = suffix - 1; p != str; p -= 1) |
711 | if (isupper (*p)) |
712 | { |
713 | int i; |
714 | if (p[0] == 'X' && p[-1] != '_') |
715 | goto OK; |
716 | if (*p != 'O') |
717 | return 1; |
718 | for (i = 0; ada_opname_table[i].encoded != NULL((void*)0); i += 1) |
719 | if (strncmp (ada_opname_table[i].encoded, p, |
720 | strlen (ada_opname_table[i].encoded)) == 0) |
721 | goto OK; |
722 | return 1; |
723 | OK:; |
724 | } |
725 | return 0; |
726 | } |
727 | } |
728 | |
729 | /* The "encoded" form of DECODED, according to GNAT conventions. |
730 | The result is valid until the next call to ada_encode. */ |
731 | |
732 | char * |
733 | ada_encode (const char *decoded) |
734 | { |
735 | static char *encoding_buffer = NULL((void*)0); |
736 | static size_t encoding_buffer_size = 0; |
737 | const char *p; |
738 | int k; |
739 | |
740 | if (decoded == NULL((void*)0)) |
741 | return NULL((void*)0); |
742 | |
743 | GROW_VECT (encoding_buffer, encoding_buffer_size,if ((encoding_buffer_size) < (2 * strlen (decoded) + 10)) grow_vect ((void**) &(encoding_buffer), &(encoding_buffer_size ), (2 * strlen (decoded) + 10), sizeof(*(encoding_buffer))); |
744 | 2 * strlen (decoded) + 10)if ((encoding_buffer_size) < (2 * strlen (decoded) + 10)) grow_vect ((void**) &(encoding_buffer), &(encoding_buffer_size ), (2 * strlen (decoded) + 10), sizeof(*(encoding_buffer)));; |
745 | |
746 | k = 0; |
747 | for (p = decoded; *p != '\0'; p += 1) |
748 | { |
749 | if (!ADA_RETAIN_DOTS0 && *p == '.') |
750 | { |
751 | encoding_buffer[k] = encoding_buffer[k + 1] = '_'; |
752 | k += 2; |
753 | } |
754 | else if (*p == '"') |
755 | { |
756 | const struct ada_opname_map *mapping; |
757 | |
758 | for (mapping = ada_opname_table; |
759 | mapping->encoded != NULL((void*)0) |
760 | && strncmp (mapping->decoded, p, |
761 | strlen (mapping->decoded)) != 0; mapping += 1) |
762 | ; |
763 | if (mapping->encoded == NULL((void*)0)) |
764 | error ("invalid Ada operator name: %s", p); |
765 | strcpy (encoding_buffer + k, mapping->encoded); |
766 | k += strlen (mapping->encoded); |
767 | break; |
768 | } |
769 | else |
770 | { |
771 | encoding_buffer[k] = *p; |
772 | k += 1; |
773 | } |
774 | } |
775 | |
776 | encoding_buffer[k] = '\0'; |
777 | return encoding_buffer; |
778 | } |
779 | |
780 | /* Return NAME folded to lower case, or, if surrounded by single |
781 | quotes, unfolded, but with the quotes stripped away. Result good |
782 | to next call. */ |
783 | |
784 | char * |
785 | ada_fold_name (const char *name) |
786 | { |
787 | static char *fold_buffer = NULL((void*)0); |
788 | static size_t fold_buffer_size = 0; |
789 | |
790 | int len = strlen (name); |
791 | GROW_VECT (fold_buffer, fold_buffer_size, len + 1)if ((fold_buffer_size) < (len + 1)) grow_vect ((void**) & (fold_buffer), &(fold_buffer_size), (len + 1), sizeof(*(fold_buffer )));; |
792 | |
793 | if (name[0] == '\'') |
794 | { |
795 | strncpy (fold_buffer, name + 1, len - 2); |
796 | fold_buffer[len - 2] = '\000'; |
797 | } |
798 | else |
799 | { |
800 | int i; |
801 | for (i = 0; i <= len; i += 1) |
802 | fold_buffer[i] = tolower (name[i]); |
803 | } |
804 | |
805 | return fold_buffer; |
806 | } |
807 | |
808 | /* decode: |
809 | 0. Discard trailing .{DIGIT}+ or trailing ___{DIGIT}+ |
810 | These are suffixes introduced by GNAT5 to nested subprogram |
811 | names, and do not serve any purpose for the debugger. |
812 | 1. Discard final __{DIGIT}+ or $({DIGIT}+(__{DIGIT}+)*) |
813 | 2. Convert other instances of embedded "__" to `.'. |
814 | 3. Discard leading _ada_. |
815 | 4. Convert operator names to the appropriate quoted symbols. |
816 | 5. Remove everything after first ___ if it is followed by |
817 | 'X'. |
818 | 6. Replace TK__ with __, and a trailing B or TKB with nothing. |
819 | 7. Put symbols that should be suppressed in <...> brackets. |
820 | 8. Remove trailing X[bn]* suffix (indicating names in package bodies). |
821 | |
822 | The resulting string is valid until the next call of ada_decode. |
823 | If the string is unchanged by demangling, the original string pointer |
824 | is returned. */ |
825 | |
826 | const char * |
827 | ada_decode (const char *encoded) |
828 | { |
829 | int i, j; |
830 | int len0; |
831 | const char *p; |
832 | char *decoded; |
833 | int at_start_name; |
834 | static char *decoding_buffer = NULL((void*)0); |
835 | static size_t decoding_buffer_size = 0; |
836 | |
837 | if (strncmp (encoded, "_ada_", 5) == 0) |
838 | encoded += 5; |
839 | |
840 | if (encoded[0] == '_' || encoded[0] == '<') |
841 | goto Suppress; |
842 | |
843 | /* Remove trailing .{DIGIT}+ or ___{DIGIT}+. */ |
844 | len0 = strlen (encoded); |
845 | if (len0 > 1 && isdigit (encoded[len0 - 1])) |
846 | { |
847 | i = len0 - 2; |
848 | while (i > 0 && isdigit (encoded[i])) |
849 | i--; |
850 | if (i >= 0 && encoded[i] == '.') |
851 | len0 = i; |
852 | else if (i >= 2 && strncmp (encoded + i - 2, "___", 3) == 0) |
853 | len0 = i - 2; |
854 | } |
855 | |
856 | /* Remove the ___X.* suffix if present. Do not forget to verify that |
857 | the suffix is located before the current "end" of ENCODED. We want |
858 | to avoid re-matching parts of ENCODED that have previously been |
859 | marked as discarded (by decrementing LEN0). */ |
860 | p = strstr (encoded, "___"); |
861 | if (p != NULL((void*)0) && p - encoded < len0 - 3) |
862 | { |
863 | if (p[3] == 'X') |
864 | len0 = p - encoded; |
865 | else |
866 | goto Suppress; |
867 | } |
868 | |
869 | if (len0 > 3 && strncmp (encoded + len0 - 3, "TKB", 3) == 0) |
870 | len0 -= 3; |
871 | |
872 | if (len0 > 1 && strncmp (encoded + len0 - 1, "B", 1) == 0) |
873 | len0 -= 1; |
874 | |
875 | /* Make decoded big enough for possible expansion by operator name. */ |
876 | GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1)if ((decoding_buffer_size) < (2 * len0 + 1)) grow_vect ((void **) &(decoding_buffer), &(decoding_buffer_size), (2 * len0 + 1), sizeof(*(decoding_buffer)));; |
877 | decoded = decoding_buffer; |
878 | |
879 | if (len0 > 1 && isdigit (encoded[len0 - 1])) |
880 | { |
881 | i = len0 - 2; |
882 | while ((i >= 0 && isdigit (encoded[i])) |
883 | || (i >= 1 && encoded[i] == '_' && isdigit (encoded[i - 1]))) |
884 | i -= 1; |
885 | if (i > 1 && encoded[i] == '_' && encoded[i - 1] == '_') |
886 | len0 = i - 1; |
887 | else if (encoded[i] == '$') |
888 | len0 = i; |
889 | } |
890 | |
891 | for (i = 0, j = 0; i < len0 && !isalpha (encoded[i]); i += 1, j += 1) |
892 | decoded[j] = encoded[i]; |
893 | |
894 | at_start_name = 1; |
895 | while (i < len0) |
896 | { |
897 | if (at_start_name && encoded[i] == 'O') |
898 | { |
899 | int k; |
900 | for (k = 0; ada_opname_table[k].encoded != NULL((void*)0); k += 1) |
901 | { |
902 | int op_len = strlen (ada_opname_table[k].encoded); |
903 | if ((strncmp (ada_opname_table[k].encoded + 1, encoded + i + 1, |
904 | op_len - 1) == 0) |
905 | && !isalnum (encoded[i + op_len])) |
906 | { |
907 | strcpy (decoded + j, ada_opname_table[k].decoded); |
908 | at_start_name = 0; |
909 | i += op_len; |
910 | j += strlen (ada_opname_table[k].decoded); |
911 | break; |
912 | } |
913 | } |
914 | if (ada_opname_table[k].encoded != NULL((void*)0)) |
915 | continue; |
916 | } |
917 | at_start_name = 0; |
918 | |
919 | if (i < len0 - 4 && strncmp (encoded + i, "TK__", 4) == 0) |
920 | i += 2; |
921 | if (encoded[i] == 'X' && i != 0 && isalnum (encoded[i - 1])) |
922 | { |
923 | do |
924 | i += 1; |
925 | while (i < len0 && (encoded[i] == 'b' || encoded[i] == 'n')); |
926 | if (i < len0) |
927 | goto Suppress; |
928 | } |
929 | else if (!ADA_RETAIN_DOTS0 |
930 | && i < len0 - 2 && encoded[i] == '_' && encoded[i + 1] == '_') |
931 | { |
932 | decoded[j] = '.'; |
933 | at_start_name = 1; |
934 | i += 2; |
935 | j += 1; |
936 | } |
937 | else |
938 | { |
939 | decoded[j] = encoded[i]; |
940 | i += 1; |
941 | j += 1; |
942 | } |
943 | } |
944 | decoded[j] = '\000'; |
945 | |
946 | for (i = 0; decoded[i] != '\0'; i += 1) |
947 | if (isupper (decoded[i]) || decoded[i] == ' ') |
948 | goto Suppress; |
949 | |
950 | if (strcmp (decoded, encoded) == 0) |
951 | return encoded; |
952 | else |
953 | return decoded; |
954 | |
955 | Suppress: |
956 | GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3)if ((decoding_buffer_size) < (strlen (encoded) + 3)) grow_vect ((void**) &(decoding_buffer), &(decoding_buffer_size ), (strlen (encoded) + 3), sizeof(*(decoding_buffer)));; |
957 | decoded = decoding_buffer; |
958 | if (encoded[0] == '<') |
959 | strcpy (decoded, encoded); |
960 | else |
961 | sprintf (decoded, "<%s>", encoded); |
962 | return decoded; |
963 | |
964 | } |
965 | |
966 | /* Table for keeping permanent unique copies of decoded names. Once |
967 | allocated, names in this table are never released. While this is a |
968 | storage leak, it should not be significant unless there are massive |
969 | changes in the set of decoded names in successive versions of a |
970 | symbol table loaded during a single session. */ |
971 | static struct htab *decoded_names_store; |
972 | |
973 | /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it |
974 | in the language-specific part of GSYMBOL, if it has not been |
975 | previously computed. Tries to save the decoded name in the same |
976 | obstack as GSYMBOL, if possible, and otherwise on the heap (so that, |
977 | in any case, the decoded symbol has a lifetime at least that of |
978 | GSYMBOL). |
979 | The GSYMBOL parameter is "mutable" in the C++ sense: logically |
980 | const, but nevertheless modified to a semantically equivalent form |
981 | when a decoded name is cached in it. |
982 | */ |
983 | |
984 | char * |
985 | ada_decode_symbol (const struct general_symbol_info *gsymbol) |
986 | { |
987 | char **resultp = |
988 | (char **) &gsymbol->language_specific.cplus_specific.demangled_name; |
989 | if (*resultp == NULL((void*)0)) |
990 | { |
991 | const char *decoded = ada_decode (gsymbol->name); |
992 | if (gsymbol->bfd_section != NULL((void*)0)) |
993 | { |
994 | bfd *obfd = gsymbol->bfd_section->owner; |
995 | if (obfd != NULL((void*)0)) |
996 | { |
997 | struct objfile *objf; |
998 | ALL_OBJFILES (objf)for ((objf) = object_files; (objf) != ((void*)0); (objf) = (objf )->next) |
999 | { |
1000 | if (obfd == objf->obfd) |
1001 | { |
1002 | *resultp = obsavestring (decoded, strlen (decoded), |
1003 | &objf->objfile_obstack); |
1004 | break; |
1005 | } |
1006 | } |
1007 | } |
1008 | } |
1009 | /* Sometimes, we can't find a corresponding objfile, in which |
1010 | case, we put the result on the heap. Since we only decode |
1011 | when needed, we hope this usually does not cause a |
1012 | significant memory leak (FIXME). */ |
1013 | if (*resultp == NULL((void*)0)) |
1014 | { |
1015 | char **slot = (char **) htab_find_slot (decoded_names_store, |
1016 | decoded, INSERT); |
1017 | if (*slot == NULL((void*)0)) |
1018 | *slot = xstrdup (decoded); |
1019 | *resultp = *slot; |
1020 | } |
1021 | } |
1022 | |
1023 | return *resultp; |
1024 | } |
1025 | |
1026 | char * |
1027 | ada_la_decode (const char *encoded, int options) |
1028 | { |
1029 | return xstrdup (ada_decode (encoded)); |
1030 | } |
1031 | |
1032 | /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing |
1033 | suffixes that encode debugging information or leading _ada_ on |
1034 | SYM_NAME (see is_name_suffix commentary for the debugging |
1035 | information that is ignored). If WILD, then NAME need only match a |
1036 | suffix of SYM_NAME minus the same suffixes. Also returns 0 if |
1037 | either argument is NULL. */ |
1038 | |
1039 | int |
1040 | ada_match_name (const char *sym_name, const char *name, int wild) |
1041 | { |
1042 | if (sym_name == NULL((void*)0) || name == NULL((void*)0)) |
1043 | return 0; |
1044 | else if (wild) |
1045 | return wild_match (name, strlen (name), sym_name); |
1046 | else |
1047 | { |
1048 | int len_name = strlen (name); |
1049 | return (strncmp (sym_name, name, len_name) == 0 |
1050 | && is_name_suffix (sym_name + len_name)) |
1051 | || (strncmp (sym_name, "_ada_", 5) == 0 |
1052 | && strncmp (sym_name + 5, name, len_name) == 0 |
1053 | && is_name_suffix (sym_name + len_name + 5)); |
1054 | } |
1055 | } |
1056 | |
1057 | /* True (non-zero) iff, in Ada mode, the symbol SYM should be |
1058 | suppressed in info listings. */ |
1059 | |
1060 | int |
1061 | ada_suppress_symbol_printing (struct symbol *sym) |
1062 | { |
1063 | if (SYMBOL_DOMAIN (sym)(sym)->domain == STRUCT_DOMAIN) |
1064 | return 1; |
1065 | else |
1066 | return is_suppressed_name (SYMBOL_LINKAGE_NAME (sym)(sym)->ginfo.name); |
1067 | } |
1068 | |
1069 | |
1070 | /* Arrays */ |
1071 | |
1072 | /* Names of MAX_ADA_DIMENS bounds in P_BOUNDS fields of array descriptors. */ |
1073 | |
1074 | static char *bound_name[] = { |
1075 | "LB0", "UB0", "LB1", "UB1", "LB2", "UB2", "LB3", "UB3", |
1076 | "LB4", "UB4", "LB5", "UB5", "LB6", "UB6", "LB7", "UB7" |
1077 | }; |
1078 | |
1079 | /* Maximum number of array dimensions we are prepared to handle. */ |
1080 | |
1081 | #define MAX_ADA_DIMENS(sizeof(bound_name) / (2*sizeof(char *))) (sizeof(bound_name) / (2*sizeof(char *))) |
1082 | |
1083 | /* Like modify_field, but allows bitpos > wordlength. */ |
1084 | |
1085 | static void |
1086 | modify_general_field (char *addr, LONGESTlong fieldval, int bitpos, int bitsize) |
1087 | { |
1088 | modify_field (addr + bitpos / 8, fieldval, bitpos % 8, bitsize); |
1089 | } |
1090 | |
1091 | |
1092 | /* The desc_* routines return primitive portions of array descriptors |
1093 | (fat pointers). */ |
1094 | |
1095 | /* The descriptor or array type, if any, indicated by TYPE; removes |
1096 | level of indirection, if needed. */ |
1097 | |
1098 | static struct type * |
1099 | desc_base_type (struct type *type) |
1100 | { |
1101 | if (type == NULL((void*)0)) |
1102 | return NULL((void*)0); |
1103 | type = ada_check_typedef (type); |
1104 | if (type != NULL((void*)0) |
1105 | && (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR |
1106 | || TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_REF)) |
1107 | return ada_check_typedef (TYPE_TARGET_TYPE (type)(type)->main_type->target_type); |
1108 | else |
1109 | return type; |
1110 | } |
1111 | |
1112 | /* True iff TYPE indicates a "thin" array pointer type. */ |
1113 | |
1114 | static int |
1115 | is_thin_pntr (struct type *type) |
1116 | { |
1117 | return |
1118 | is_suffix (ada_type_name (desc_base_type (type)), "___XUT") |
1119 | || is_suffix (ada_type_name (desc_base_type (type)), "___XUT___XVE"); |
1120 | } |
1121 | |
1122 | /* The descriptor type for thin pointer type TYPE. */ |
1123 | |
1124 | static struct type * |
1125 | thin_descriptor_type (struct type *type) |
1126 | { |
1127 | struct type *base_type = desc_base_type (type); |
1128 | if (base_type == NULL((void*)0)) |
1129 | return NULL((void*)0); |
1130 | if (is_suffix (ada_type_name (base_type), "___XVE")) |
1131 | return base_type; |
1132 | else |
1133 | { |
1134 | struct type *alt_type = ada_find_parallel_type (base_type, "___XVE"); |
1135 | if (alt_type == NULL((void*)0)) |
1136 | return base_type; |
1137 | else |
1138 | return alt_type; |
1139 | } |
1140 | } |
1141 | |
1142 | /* A pointer to the array data for thin-pointer value VAL. */ |
1143 | |
1144 | static struct value * |
1145 | thin_data_pntr (struct value *val) |
1146 | { |
1147 | struct type *type = VALUE_TYPE (val)(val)->type; |
1148 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR) |
1149 | return value_cast (desc_data_type (thin_descriptor_type (type)), |
1150 | value_copy (val)); |
1151 | else |
1152 | return value_from_longest (desc_data_type (thin_descriptor_type (type)), |
1153 | VALUE_ADDRESS (val)(val)->location.address + VALUE_OFFSET (val)(val)->offset); |
1154 | } |
1155 | |
1156 | /* True iff TYPE indicates a "thick" array pointer type. */ |
1157 | |
1158 | static int |
1159 | is_thick_pntr (struct type *type) |
1160 | { |
1161 | type = desc_base_type (type); |
1162 | return (type != NULL((void*)0) && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT |
1163 | && lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL((void*)0)); |
1164 | } |
1165 | |
1166 | /* If TYPE is the type of an array descriptor (fat or thin pointer) or a |
1167 | pointer to one, the type of its bounds data; otherwise, NULL. */ |
1168 | |
1169 | static struct type * |
1170 | desc_bounds_type (struct type *type) |
1171 | { |
1172 | struct type *r; |
1173 | |
1174 | type = desc_base_type (type); |
1175 | |
1176 | if (type == NULL((void*)0)) |
1177 | return NULL((void*)0); |
1178 | else if (is_thin_pntr (type)) |
1179 | { |
1180 | type = thin_descriptor_type (type); |
1181 | if (type == NULL((void*)0)) |
1182 | return NULL((void*)0); |
1183 | r = lookup_struct_elt_type (type, "BOUNDS", 1); |
1184 | if (r != NULL((void*)0)) |
1185 | return ada_check_typedef (r); |
1186 | } |
1187 | else if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT) |
1188 | { |
1189 | r = lookup_struct_elt_type (type, "P_BOUNDS", 1); |
1190 | if (r != NULL((void*)0)) |
1191 | return ada_check_typedef (TYPE_TARGET_TYPE (ada_check_typedef (r))(ada_check_typedef (r))->main_type->target_type); |
1192 | } |
1193 | return NULL((void*)0); |
1194 | } |
1195 | |
1196 | /* If ARR is an array descriptor (fat or thin pointer), or pointer to |
1197 | one, a pointer to its bounds data. Otherwise NULL. */ |
1198 | |
1199 | static struct value * |
1200 | desc_bounds (struct value *arr) |
1201 | { |
1202 | struct type *type = ada_check_typedef (VALUE_TYPE (arr)(arr)->type); |
1203 | if (is_thin_pntr (type)) |
1204 | { |
1205 | struct type *bounds_type = |
1206 | desc_bounds_type (thin_descriptor_type (type)); |
1207 | LONGESTlong addr; |
1208 | |
1209 | if (desc_bounds_type == NULL((void*)0)) |
1210 | error ("Bad GNAT array descriptor"); |
1211 | |
1212 | /* NOTE: The following calculation is not really kosher, but |
1213 | since desc_type is an XVE-encoded type (and shouldn't be), |
1214 | the correct calculation is a real pain. FIXME (and fix GCC). */ |
1215 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR) |
1216 | addr = value_as_long (arr); |
1217 | else |
1218 | addr = VALUE_ADDRESS (arr)(arr)->location.address + VALUE_OFFSET (arr)(arr)->offset; |
1219 | |
1220 | return |
1221 | value_from_longest (lookup_pointer_type (bounds_type), |
1222 | addr - TYPE_LENGTH (bounds_type)(bounds_type)->length); |
1223 | } |
1224 | |
1225 | else if (is_thick_pntr (type)) |
1226 | return value_struct_elt (&arr, NULL((void*)0), "P_BOUNDS", NULL((void*)0), |
1227 | "Bad GNAT array descriptor"); |
1228 | else |
1229 | return NULL((void*)0); |
1230 | } |
1231 | |
1232 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit |
1233 | position of the field containing the address of the bounds data. */ |
1234 | |
1235 | static int |
1236 | fat_pntr_bounds_bitpos (struct type *type) |
1237 | { |
1238 | return TYPE_FIELD_BITPOS (desc_base_type (type), 1)(((desc_base_type (type))->main_type->fields[1]).loc.bitpos ); |
1239 | } |
1240 | |
1241 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit |
1242 | size of the field containing the address of the bounds data. */ |
1243 | |
1244 | static int |
1245 | fat_pntr_bounds_bitsize (struct type *type) |
1246 | { |
1247 | type = desc_base_type (type); |
1248 | |
1249 | if (TYPE_FIELD_BITSIZE (type, 1)(((type)->main_type->fields[1]).bitsize) > 0) |
1250 | return TYPE_FIELD_BITSIZE (type, 1)(((type)->main_type->fields[1]).bitsize); |
1251 | else |
1252 | return 8 * TYPE_LENGTH (ada_check_typedef (TYPE_FIELD_TYPE (type, 1)))(ada_check_typedef ((((type)->main_type->fields[1]).type )))->length; |
1253 | } |
1254 | |
1255 | /* If TYPE is the type of an array descriptor (fat or thin pointer) or a |
1256 | pointer to one, the type of its array data (a |
1257 | pointer-to-array-with-no-bounds type); otherwise, NULL. Use |
1258 | ada_type_of_array to get an array type with bounds data. */ |
1259 | |
1260 | static struct type * |
1261 | desc_data_type (struct type *type) |
1262 | { |
1263 | type = desc_base_type (type); |
1264 | |
1265 | /* NOTE: The following is bogus; see comment in desc_bounds. */ |
1266 | if (is_thin_pntr (type)) |
1267 | return lookup_pointer_type |
1268 | (desc_base_type (TYPE_FIELD_TYPE (thin_descriptor_type (type), 1)(((thin_descriptor_type (type))->main_type->fields[1]). type))); |
1269 | else if (is_thick_pntr (type)) |
1270 | return lookup_struct_elt_type (type, "P_ARRAY", 1); |
1271 | else |
1272 | return NULL((void*)0); |
1273 | } |
1274 | |
1275 | /* If ARR is an array descriptor (fat or thin pointer), a pointer to |
1276 | its array data. */ |
1277 | |
1278 | static struct value * |
1279 | desc_data (struct value *arr) |
1280 | { |
1281 | struct type *type = VALUE_TYPE (arr)(arr)->type; |
1282 | if (is_thin_pntr (type)) |
1283 | return thin_data_pntr (arr); |
1284 | else if (is_thick_pntr (type)) |
1285 | return value_struct_elt (&arr, NULL((void*)0), "P_ARRAY", NULL((void*)0), |
1286 | "Bad GNAT array descriptor"); |
1287 | else |
1288 | return NULL((void*)0); |
1289 | } |
1290 | |
1291 | |
1292 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit |
1293 | position of the field containing the address of the data. */ |
1294 | |
1295 | static int |
1296 | fat_pntr_data_bitpos (struct type *type) |
1297 | { |
1298 | return TYPE_FIELD_BITPOS (desc_base_type (type), 0)(((desc_base_type (type))->main_type->fields[0]).loc.bitpos ); |
1299 | } |
1300 | |
1301 | /* If TYPE is the type of an array-descriptor (fat pointer), the bit |
1302 | size of the field containing the address of the data. */ |
1303 | |
1304 | static int |
1305 | fat_pntr_data_bitsize (struct type *type) |
1306 | { |
1307 | type = desc_base_type (type); |
1308 | |
1309 | if (TYPE_FIELD_BITSIZE (type, 0)(((type)->main_type->fields[0]).bitsize) > 0) |
1310 | return TYPE_FIELD_BITSIZE (type, 0)(((type)->main_type->fields[0]).bitsize); |
1311 | else |
1312 | return TARGET_CHAR_BIT8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0))((((type)->main_type->fields[0]).type))->length; |
1313 | } |
1314 | |
1315 | /* If BOUNDS is an array-bounds structure (or pointer to one), return |
1316 | the Ith lower bound stored in it, if WHICH is 0, and the Ith upper |
1317 | bound, if WHICH is 1. The first bound is I=1. */ |
1318 | |
1319 | static struct value * |
1320 | desc_one_bound (struct value *bounds, int i, int which) |
1321 | { |
1322 | return value_struct_elt (&bounds, NULL((void*)0), bound_name[2 * i + which - 2], NULL((void*)0), |
1323 | "Bad GNAT array descriptor bounds"); |
1324 | } |
1325 | |
1326 | /* If BOUNDS is an array-bounds structure type, return the bit position |
1327 | of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper |
1328 | bound, if WHICH is 1. The first bound is I=1. */ |
1329 | |
1330 | static int |
1331 | desc_bound_bitpos (struct type *type, int i, int which) |
1332 | { |
1333 | return TYPE_FIELD_BITPOS (desc_base_type (type), 2 * i + which - 2)(((desc_base_type (type))->main_type->fields[2 * i + which - 2]).loc.bitpos); |
1334 | } |
1335 | |
1336 | /* If BOUNDS is an array-bounds structure type, return the bit field size |
1337 | of the Ith lower bound stored in it, if WHICH is 0, and the Ith upper |
1338 | bound, if WHICH is 1. The first bound is I=1. */ |
1339 | |
1340 | static int |
1341 | desc_bound_bitsize (struct type *type, int i, int which) |
1342 | { |
1343 | type = desc_base_type (type); |
1344 | |
1345 | if (TYPE_FIELD_BITSIZE (type, 2 * i + which - 2)(((type)->main_type->fields[2 * i + which - 2]).bitsize ) > 0) |
1346 | return TYPE_FIELD_BITSIZE (type, 2 * i + which - 2)(((type)->main_type->fields[2 * i + which - 2]).bitsize ); |
1347 | else |
1348 | return 8 * TYPE_LENGTH (TYPE_FIELD_TYPE (type, 2 * i + which - 2))((((type)->main_type->fields[2 * i + which - 2]).type)) ->length; |
1349 | } |
1350 | |
1351 | /* If TYPE is the type of an array-bounds structure, the type of its |
1352 | Ith bound (numbering from 1). Otherwise, NULL. */ |
1353 | |
1354 | static struct type * |
1355 | desc_index_type (struct type *type, int i) |
1356 | { |
1357 | type = desc_base_type (type); |
1358 | |
1359 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT) |
1360 | return lookup_struct_elt_type (type, bound_name[2 * i - 2], 1); |
1361 | else |
1362 | return NULL((void*)0); |
1363 | } |
1364 | |
1365 | /* The number of index positions in the array-bounds type TYPE. |
1366 | Return 0 if TYPE is NULL. */ |
1367 | |
1368 | static int |
1369 | desc_arity (struct type *type) |
1370 | { |
1371 | type = desc_base_type (type); |
1372 | |
1373 | if (type != NULL((void*)0)) |
1374 | return TYPE_NFIELDS (type)(type)->main_type->nfields / 2; |
1375 | return 0; |
1376 | } |
1377 | |
1378 | /* Non-zero iff TYPE is a simple array type (not a pointer to one) or |
1379 | an array descriptor type (representing an unconstrained array |
1380 | type). */ |
1381 | |
1382 | static int |
1383 | ada_is_direct_array_type (struct type *type) |
1384 | { |
1385 | if (type == NULL((void*)0)) |
1386 | return 0; |
1387 | type = ada_check_typedef (type); |
1388 | return (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY |
1389 | || ada_is_array_descriptor_type (type)); |
1390 | } |
1391 | |
1392 | /* Non-zero iff TYPE is a simple array type or pointer to one. */ |
1393 | |
1394 | int |
1395 | ada_is_simple_array_type (struct type *type) |
1396 | { |
1397 | if (type == NULL((void*)0)) |
1398 | return 0; |
1399 | type = ada_check_typedef (type); |
1400 | return (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY |
1401 | || (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR |
1402 | && TYPE_CODE (TYPE_TARGET_TYPE (type))((type)->main_type->target_type)->main_type->code == TYPE_CODE_ARRAY)); |
1403 | } |
1404 | |
1405 | /* Non-zero iff TYPE belongs to a GNAT array descriptor. */ |
1406 | |
1407 | int |
1408 | ada_is_array_descriptor_type (struct type *type) |
1409 | { |
1410 | struct type *data_type = desc_data_type (type); |
1411 | |
1412 | if (type == NULL((void*)0)) |
1413 | return 0; |
1414 | type = ada_check_typedef (type); |
1415 | return |
1416 | data_type != NULL((void*)0) |
1417 | && ((TYPE_CODE (data_type)(data_type)->main_type->code == TYPE_CODE_PTR |
1418 | && TYPE_TARGET_TYPE (data_type)(data_type)->main_type->target_type != NULL((void*)0) |
1419 | && TYPE_CODE (TYPE_TARGET_TYPE (data_type))((data_type)->main_type->target_type)->main_type-> code == TYPE_CODE_ARRAY) |
1420 | || TYPE_CODE (data_type)(data_type)->main_type->code == TYPE_CODE_ARRAY) |
1421 | && desc_arity (desc_bounds_type (type)) > 0; |
1422 | } |
1423 | |
1424 | /* Non-zero iff type is a partially mal-formed GNAT array |
1425 | descriptor. FIXME: This is to compensate for some problems with |
1426 | debugging output from GNAT. Re-examine periodically to see if it |
1427 | is still needed. */ |
1428 | |
1429 | int |
1430 | ada_is_bogus_array_descriptor (struct type *type) |
1431 | { |
1432 | return |
1433 | type != NULL((void*)0) |
1434 | && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT |
1435 | && (lookup_struct_elt_type (type, "P_BOUNDS", 1) != NULL((void*)0) |
1436 | || lookup_struct_elt_type (type, "P_ARRAY", 1) != NULL((void*)0)) |
1437 | && !ada_is_array_descriptor_type (type); |
1438 | } |
1439 | |
1440 | |
1441 | /* If ARR has a record type in the form of a standard GNAT array descriptor, |
1442 | (fat pointer) returns the type of the array data described---specifically, |
1443 | a pointer-to-array type. If BOUNDS is non-zero, the bounds data are filled |
1444 | in from the descriptor; otherwise, they are left unspecified. If |
1445 | the ARR denotes a null array descriptor and BOUNDS is non-zero, |
1446 | returns NULL. The result is simply the type of ARR if ARR is not |
1447 | a descriptor. */ |
1448 | struct type * |
1449 | ada_type_of_array (struct value *arr, int bounds) |
1450 | { |
1451 | if (ada_is_packed_array_type (VALUE_TYPE (arr)(arr)->type)) |
1452 | return decode_packed_array_type (VALUE_TYPE (arr)(arr)->type); |
1453 | |
1454 | if (!ada_is_array_descriptor_type (VALUE_TYPE (arr)(arr)->type)) |
1455 | return VALUE_TYPE (arr)(arr)->type; |
1456 | |
1457 | if (!bounds) |
1458 | return |
1459 | ada_check_typedef (TYPE_TARGET_TYPE (desc_data_type (VALUE_TYPE (arr)))(desc_data_type ((arr)->type))->main_type->target_type); |
1460 | else |
1461 | { |
1462 | struct type *elt_type; |
1463 | int arity; |
1464 | struct value *descriptor; |
1465 | struct objfile *objf = TYPE_OBJFILE (VALUE_TYPE (arr))((arr)->type)->main_type->objfile; |
1466 | |
1467 | elt_type = ada_array_element_type (VALUE_TYPE (arr)(arr)->type, -1); |
1468 | arity = ada_array_arity (VALUE_TYPE (arr)(arr)->type); |
1469 | |
1470 | if (elt_type == NULL((void*)0) || arity == 0) |
1471 | return ada_check_typedef (VALUE_TYPE (arr)(arr)->type); |
1472 | |
1473 | descriptor = desc_bounds (arr); |
1474 | if (value_as_long (descriptor) == 0) |
1475 | return NULL((void*)0); |
1476 | while (arity > 0) |
1477 | { |
1478 | struct type *range_type = alloc_type (objf); |
1479 | struct type *array_type = alloc_type (objf); |
1480 | struct value *low = desc_one_bound (descriptor, arity, 0); |
1481 | struct value *high = desc_one_bound (descriptor, arity, 1); |
1482 | arity -= 1; |
1483 | |
1484 | create_range_type (range_type, VALUE_TYPE (low)(low)->type, |
1485 | (int) value_as_long (low), |
1486 | (int) value_as_long (high)); |
1487 | elt_type = create_array_type (array_type, elt_type, range_type); |
1488 | } |
1489 | |
1490 | return lookup_pointer_type (elt_type); |
1491 | } |
1492 | } |
1493 | |
1494 | /* If ARR does not represent an array, returns ARR unchanged. |
1495 | Otherwise, returns either a standard GDB array with bounds set |
1496 | appropriately or, if ARR is a non-null fat pointer, a pointer to a standard |
1497 | GDB array. Returns NULL if ARR is a null fat pointer. */ |
1498 | |
1499 | struct value * |
1500 | ada_coerce_to_simple_array_ptr (struct value *arr) |
1501 | { |
1502 | if (ada_is_array_descriptor_type (VALUE_TYPE (arr)(arr)->type)) |
1503 | { |
1504 | struct type *arrType = ada_type_of_array (arr, 1); |
1505 | if (arrType == NULL((void*)0)) |
1506 | return NULL((void*)0); |
1507 | return value_cast (arrType, value_copy (desc_data (arr))); |
1508 | } |
1509 | else if (ada_is_packed_array_type (VALUE_TYPE (arr)(arr)->type)) |
1510 | return decode_packed_array (arr); |
1511 | else |
1512 | return arr; |
1513 | } |
1514 | |
1515 | /* If ARR does not represent an array, returns ARR unchanged. |
1516 | Otherwise, returns a standard GDB array describing ARR (which may |
1517 | be ARR itself if it already is in the proper form). */ |
1518 | |
1519 | static struct value * |
1520 | ada_coerce_to_simple_array (struct value *arr) |
1521 | { |
1522 | if (ada_is_array_descriptor_type (VALUE_TYPE (arr)(arr)->type)) |
1523 | { |
1524 | struct value *arrVal = ada_coerce_to_simple_array_ptr (arr); |
1525 | if (arrVal == NULL((void*)0)) |
1526 | error ("Bounds unavailable for null array pointer."); |
1527 | return value_ind (arrVal); |
1528 | } |
1529 | else if (ada_is_packed_array_type (VALUE_TYPE (arr)(arr)->type)) |
1530 | return decode_packed_array (arr); |
1531 | else |
1532 | return arr; |
1533 | } |
1534 | |
1535 | /* If TYPE represents a GNAT array type, return it translated to an |
1536 | ordinary GDB array type (possibly with BITSIZE fields indicating |
1537 | packing). For other types, is the identity. */ |
1538 | |
1539 | struct type * |
1540 | ada_coerce_to_simple_array_type (struct type *type) |
1541 | { |
1542 | struct value *mark = value_mark (); |
1543 | struct value *dummy = value_from_longest (builtin_type_long, 0); |
1544 | struct type *result; |
1545 | VALUE_TYPE (dummy)(dummy)->type = type; |
1546 | result = ada_type_of_array (dummy, 0); |
1547 | value_free_to_mark (mark); |
1548 | return result; |
1549 | } |
1550 | |
1551 | /* Non-zero iff TYPE represents a standard GNAT packed-array type. */ |
1552 | |
1553 | int |
1554 | ada_is_packed_array_type (struct type *type) |
1555 | { |
1556 | if (type == NULL((void*)0)) |
1557 | return 0; |
1558 | type = desc_base_type (type); |
1559 | type = ada_check_typedef (type); |
1560 | return |
1561 | ada_type_name (type) != NULL((void*)0) |
1562 | && strstr (ada_type_name (type), "___XP") != NULL((void*)0); |
1563 | } |
1564 | |
1565 | /* Given that TYPE is a standard GDB array type with all bounds filled |
1566 | in, and that the element size of its ultimate scalar constituents |
1567 | (that is, either its elements, or, if it is an array of arrays, its |
1568 | elements' elements, etc.) is *ELT_BITS, return an identical type, |
1569 | but with the bit sizes of its elements (and those of any |
1570 | constituent arrays) recorded in the BITSIZE components of its |
1571 | TYPE_FIELD_BITSIZE values, and with *ELT_BITS set to its total size |
1572 | in bits. */ |
1573 | |
1574 | static struct type * |
1575 | packed_array_type (struct type *type, long *elt_bits) |
1576 | { |
1577 | struct type *new_elt_type; |
1578 | struct type *new_type; |
1579 | LONGESTlong low_bound, high_bound; |
1580 | |
1581 | type = ada_check_typedef (type); |
1582 | if (TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_ARRAY) |
1583 | return type; |
1584 | |
1585 | new_type = alloc_type (TYPE_OBJFILE (type)(type)->main_type->objfile); |
1586 | new_elt_type = packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)(type)->main_type->target_type), |
1587 | elt_bits); |
1588 | create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0)(((type)->main_type->fields[0]).type)); |
1589 | TYPE_FIELD_BITSIZE (new_type, 0)(((new_type)->main_type->fields[0]).bitsize) = *elt_bits; |
1590 | TYPE_NAME (new_type)(new_type)->main_type->name = ada_type_name (type); |
1591 | |
1592 | if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0)(((type)->main_type->fields[0]).type), |
1593 | &low_bound, &high_bound) < 0) |
1594 | low_bound = high_bound = 0; |
1595 | if (high_bound < low_bound) |
1596 | *elt_bits = TYPE_LENGTH (new_type)(new_type)->length = 0; |
1597 | else |
1598 | { |
1599 | *elt_bits *= (high_bound - low_bound + 1); |
1600 | TYPE_LENGTH (new_type)(new_type)->length = |
1601 | (*elt_bits + HOST_CHAR_BIT8 - 1) / HOST_CHAR_BIT8; |
1602 | } |
1603 | |
1604 | TYPE_FLAGS (new_type)(new_type)->main_type->flags |= TYPE_FLAG_FIXED_INSTANCE(1 << 15); |
1605 | return new_type; |
1606 | } |
1607 | |
1608 | /* The array type encoded by TYPE, where ada_is_packed_array_type (TYPE). */ |
1609 | |
1610 | static struct type * |
1611 | decode_packed_array_type (struct type *type) |
1612 | { |
1613 | struct symbol *sym; |
1614 | struct block **blocks; |
1615 | const char *raw_name = ada_type_name (ada_check_typedef (type)); |
1616 | char *name = (char *) alloca (strlen (raw_name) + 1)__builtin_alloca(strlen (raw_name) + 1); |
1617 | char *tail = strstr (raw_name, "___XP"); |
1618 | struct type *shadow_type; |
1619 | long bits; |
1620 | int i, n; |
1621 | |
1622 | type = desc_base_type (type); |
Value stored to 'type' is never read | |
1623 | |
1624 | memcpy (name, raw_name, tail - raw_name); |
1625 | name[tail - raw_name] = '\000'; |
1626 | |
1627 | sym = standard_lookup (name, get_selected_block (0), VAR_DOMAIN); |
1628 | if (sym == NULL((void*)0) || SYMBOL_TYPE (sym)(sym)->type == NULL((void*)0)) |
1629 | { |
1630 | lim_warning ("could not find bounds information on packed array"); |
1631 | return NULL((void*)0); |
1632 | } |
1633 | shadow_type = SYMBOL_TYPE (sym)(sym)->type; |
1634 | |
1635 | if (TYPE_CODE (shadow_type)(shadow_type)->main_type->code != TYPE_CODE_ARRAY) |
1636 | { |
1637 | lim_warning ("could not understand bounds information on packed array"); |
1638 | return NULL((void*)0); |
1639 | } |
1640 | |
1641 | if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1) |
1642 | { |
1643 | lim_warning |
1644 | ("could not understand bit size information on packed array"); |
1645 | return NULL((void*)0); |
1646 | } |
1647 | |
1648 | return packed_array_type (shadow_type, &bits); |
1649 | } |
1650 | |
1651 | /* Given that ARR is a struct value *indicating a GNAT packed array, |
1652 | returns a simple array that denotes that array. Its type is a |
1653 | standard GDB array type except that the BITSIZEs of the array |
1654 | target types are set to the number of bits in each element, and the |
1655 | type length is set appropriately. */ |
1656 | |
1657 | static struct value * |
1658 | decode_packed_array (struct value *arr) |
1659 | { |
1660 | struct type *type; |
1661 | |
1662 | arr = ada_coerce_ref (arr); |
1663 | if (TYPE_CODE (VALUE_TYPE (arr))((arr)->type)->main_type->code == TYPE_CODE_PTR) |
1664 | arr = ada_value_ind (arr); |
1665 | |
1666 | type = decode_packed_array_type (VALUE_TYPE (arr)(arr)->type); |
1667 | if (type == NULL((void*)0)) |
1668 | { |
1669 | error ("can't unpack array"); |
1670 | return NULL((void*)0); |
1671 | } |
1672 | |
1673 | if (BITS_BIG_ENDIAN((gdbarch_byte_order (current_gdbarch)) == BFD_ENDIAN_BIG) && ada_is_modular_type (VALUE_TYPE (arr)(arr)->type)) |
1674 | { |
1675 | /* This is a (right-justified) modular type representing a packed |
1676 | array with no wrapper. In order to interpret the value through |
1677 | the (left-justified) packed array type we just built, we must |
1678 | first left-justify it. */ |
1679 | int bit_size, bit_pos; |
1680 | ULONGESTunsigned long mod; |
1681 | |
1682 | mod = ada_modulus (VALUE_TYPE (arr)(arr)->type) - 1; |
1683 | bit_size = 0; |
1684 | while (mod > 0) |
1685 | { |
1686 | bit_size += 1; |
1687 | mod >>= 1; |
1688 | } |
1689 | bit_pos = HOST_CHAR_BIT8 * TYPE_LENGTH (VALUE_TYPE (arr))((arr)->type)->length - bit_size; |
1690 | arr = ada_value_primitive_packed_val (arr, NULL((void*)0), |
1691 | bit_pos / HOST_CHAR_BIT8, |
1692 | bit_pos % HOST_CHAR_BIT8, |
1693 | bit_size, |
1694 | type); |
1695 | } |
1696 | |
1697 | return coerce_unspec_val_to_type (arr, type); |
1698 | } |
1699 | |
1700 | |
1701 | /* The value of the element of packed array ARR at the ARITY indices |
1702 | given in IND. ARR must be a simple array. */ |
1703 | |
1704 | static struct value * |
1705 | value_subscript_packed (struct value *arr, int arity, struct value **ind) |
1706 | { |
1707 | int i; |
1708 | int bits, elt_off, bit_off; |
1709 | long elt_total_bit_offset; |
1710 | struct type *elt_type; |
1711 | struct value *v; |
1712 | |
1713 | bits = 0; |
1714 | elt_total_bit_offset = 0; |
1715 | elt_type = ada_check_typedef (VALUE_TYPE (arr)(arr)->type); |
1716 | for (i = 0; i < arity; i += 1) |
1717 | { |
1718 | if (TYPE_CODE (elt_type)(elt_type)->main_type->code != TYPE_CODE_ARRAY |
1719 | || TYPE_FIELD_BITSIZE (elt_type, 0)(((elt_type)->main_type->fields[0]).bitsize) == 0) |
1720 | error |
1721 | ("attempt to do packed indexing of something other than a packed array"); |
1722 | else |
1723 | { |
1724 | struct type *range_type = TYPE_INDEX_TYPE (elt_type)(((elt_type)->main_type->fields[0]).type); |
1725 | LONGESTlong lowerbound, upperbound; |
1726 | LONGESTlong idx; |
1727 | |
1728 | if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0) |
1729 | { |
1730 | lim_warning ("don't know bounds of array"); |
1731 | lowerbound = upperbound = 0; |
1732 | } |
1733 | |
1734 | idx = value_as_long (value_pos_atr (ind[i])); |
1735 | if (idx < lowerbound || idx > upperbound) |
1736 | lim_warning ("packed array index %ld out of bounds", (long) idx); |
1737 | bits = TYPE_FIELD_BITSIZE (elt_type, 0)(((elt_type)->main_type->fields[0]).bitsize); |
1738 | elt_total_bit_offset += (idx - lowerbound) * bits; |
1739 | elt_type = ada_check_typedef (TYPE_TARGET_TYPE (elt_type)(elt_type)->main_type->target_type); |
1740 | } |
1741 | } |
1742 | elt_off = elt_total_bit_offset / HOST_CHAR_BIT8; |
1743 | bit_off = elt_total_bit_offset % HOST_CHAR_BIT8; |
1744 | |
1745 | v = ada_value_primitive_packed_val (arr, NULL((void*)0), elt_off, bit_off, |
1746 | bits, elt_type); |
1747 | if (VALUE_LVAL (arr)(arr)->lval == lval_internalvar) |
1748 | VALUE_LVAL (v)(v)->lval = lval_internalvar_component; |
1749 | else |
1750 | VALUE_LVAL (v)(v)->lval = VALUE_LVAL (arr)(arr)->lval; |
1751 | return v; |
1752 | } |
1753 | |
1754 | /* Non-zero iff TYPE includes negative integer values. */ |
1755 | |
1756 | static int |
1757 | has_negatives (struct type *type) |
1758 | { |
1759 | switch (TYPE_CODE (type)(type)->main_type->code) |
1760 | { |
1761 | default: |
1762 | return 0; |
1763 | case TYPE_CODE_INT: |
1764 | return !TYPE_UNSIGNED (type)((type)->main_type->flags & (1 << 0)); |
1765 | case TYPE_CODE_RANGE: |
1766 | return TYPE_LOW_BOUND (type)(((type)->main_type->fields[0]).loc.bitpos) < 0; |
1767 | } |
1768 | } |
1769 | |
1770 | |
1771 | /* Create a new value of type TYPE from the contents of OBJ starting |
1772 | at byte OFFSET, and bit offset BIT_OFFSET within that byte, |
1773 | proceeding for BIT_SIZE bits. If OBJ is an lval in memory, then |
1774 | assigning through the result will set the field fetched from. |
1775 | VALADDR is ignored unless OBJ is NULL, in which case, |
1776 | VALADDR+OFFSET must address the start of storage containing the |
1777 | packed value. The value returned in this case is never an lval. |
1778 | Assumes 0 <= BIT_OFFSET < HOST_CHAR_BIT. */ |
1779 | |
1780 | struct value * |
1781 | ada_value_primitive_packed_val (struct value *obj, char *valaddr, long offset, |
1782 | int bit_offset, int bit_size, |
1783 | struct type *type) |
1784 | { |
1785 | struct value *v; |
1786 | int src, /* Index into the source area */ |
1787 | targ, /* Index into the target area */ |
1788 | srcBitsLeft, /* Number of source bits left to move */ |
1789 | nsrc, ntarg, /* Number of source and target bytes */ |
1790 | unusedLS, /* Number of bits in next significant |
1791 | byte of source that are unused */ |
1792 | accumSize; /* Number of meaningful bits in accum */ |
1793 | unsigned char *bytes; /* First byte containing data to unpack */ |
1794 | unsigned char *unpacked; |
1795 | unsigned long accum; /* Staging area for bits being transferred */ |
1796 | unsigned char sign; |
1797 | int len = (bit_size + bit_offset + HOST_CHAR_BIT8 - 1) / 8; |
1798 | /* Transmit bytes from least to most significant; delta is the direction |
1799 | the indices move. */ |
1800 | int delta = BITS_BIG_ENDIAN((gdbarch_byte_order (current_gdbarch)) == BFD_ENDIAN_BIG) ? -1 : 1; |
1801 | |
1802 | type = ada_check_typedef (type); |
1803 | |
1804 | if (obj == NULL((void*)0)) |
1805 | { |
1806 | v = allocate_value (type); |
1807 | bytes = (unsigned char *) (valaddr + offset); |
1808 | } |
1809 | else if (VALUE_LAZY (obj)(obj)->lazy) |
1810 | { |
1811 | v = value_at (type, |
1812 | VALUE_ADDRESS (obj)(obj)->location.address + VALUE_OFFSET (obj)(obj)->offset + offset, NULL((void*)0)); |
1813 | bytes = (unsigned char *) alloca (len)__builtin_alloca(len); |
1814 | read_memory (VALUE_ADDRESS (v)(v)->location.address, bytes, len); |
1815 | } |
1816 | else |
1817 | { |
1818 | v = allocate_value (type); |
1819 | bytes = (unsigned char *) VALUE_CONTENTS (obj)((void)((obj)->lazy && value_fetch_lazy(obj)), ((char *) (obj)->aligner.contents + (obj)->embedded_offset)) + offset; |
1820 | } |
1821 | |
1822 | if (obj != NULL((void*)0)) |
1823 | { |
1824 | VALUE_LVAL (v)(v)->lval = VALUE_LVAL (obj)(obj)->lval; |
1825 | if (VALUE_LVAL (obj)(obj)->lval == lval_internalvar) |
1826 | VALUE_LVAL (v)(v)->lval = lval_internalvar_component; |
1827 | VALUE_ADDRESS (v)(v)->location.address = VALUE_ADDRESS (obj)(obj)->location.address + VALUE_OFFSET (obj)(obj)->offset + offset; |
1828 | VALUE_BITPOS (v)(v)->bitpos = bit_offset + VALUE_BITPOS (obj)(obj)->bitpos; |
1829 | VALUE_BITSIZE (v)(v)->bitsize = bit_size; |
1830 | if (VALUE_BITPOS (v)(v)->bitpos >= HOST_CHAR_BIT8) |
1831 | { |
1832 | VALUE_ADDRESS (v)(v)->location.address += 1; |
1833 | VALUE_BITPOS (v)(v)->bitpos -= HOST_CHAR_BIT8; |
1834 | } |
1835 | } |
1836 | else |
1837 | VALUE_BITSIZE (v)(v)->bitsize = bit_size; |
1838 | unpacked = (unsigned char *) VALUE_CONTENTS (v)((void)((v)->lazy && value_fetch_lazy(v)), ((char * ) (v)->aligner.contents + (v)->embedded_offset)); |
1839 | |
1840 | srcBitsLeft = bit_size; |
1841 | nsrc = len; |
1842 | ntarg = TYPE_LENGTH (type)(type)->length; |
1843 | sign = 0; |
1844 | if (bit_size == 0) |
1845 | { |
1846 | memset (unpacked, 0, TYPE_LENGTH (type)(type)->length); |
1847 | return v; |
1848 | } |
1849 | else if (BITS_BIG_ENDIAN((gdbarch_byte_order (current_gdbarch)) == BFD_ENDIAN_BIG)) |
1850 | { |
1851 | src = len - 1; |
1852 | if (has_negatives (type) |
1853 | && ((bytes[0] << bit_offset) & (1 << (HOST_CHAR_BIT8 - 1)))) |
1854 | sign = ~0; |
1855 | |
1856 | unusedLS = |
1857 | (HOST_CHAR_BIT8 - (bit_size + bit_offset) % HOST_CHAR_BIT8) |
1858 | % HOST_CHAR_BIT8; |
1859 | |
1860 | switch (TYPE_CODE (type)(type)->main_type->code) |
1861 | { |
1862 | case TYPE_CODE_ARRAY: |
1863 | case TYPE_CODE_UNION: |
1864 | case TYPE_CODE_STRUCT: |
1865 | /* Non-scalar values must be aligned at a byte boundary... */ |
1866 | accumSize = |
1867 | (HOST_CHAR_BIT8 - bit_size % HOST_CHAR_BIT8) % HOST_CHAR_BIT8; |
1868 | /* ... And are placed at the beginning (most-significant) bytes |
1869 | of the target. */ |
1870 | targ = src; |
1871 | break; |
1872 | default: |
1873 | accumSize = 0; |
1874 | targ = TYPE_LENGTH (type)(type)->length - 1; |
1875 | break; |
1876 | } |
1877 | } |
1878 | else |
1879 | { |
1880 | int sign_bit_offset = (bit_size + bit_offset - 1) % 8; |
1881 | |
1882 | src = targ = 0; |
1883 | unusedLS = bit_offset; |
1884 | accumSize = 0; |
1885 | |
1886 | if (has_negatives (type) && (bytes[len - 1] & (1 << sign_bit_offset))) |
1887 | sign = ~0; |
1888 | } |
1889 | |
1890 | accum = 0; |
1891 | while (nsrc > 0) |
1892 | { |
1893 | /* Mask for removing bits of the next source byte that are not |
1894 | part of the value. */ |
1895 | unsigned int unusedMSMask = |
1896 | (1 << (srcBitsLeft >= HOST_CHAR_BIT8 ? HOST_CHAR_BIT8 : srcBitsLeft)) - |
1897 | 1; |
1898 | /* Sign-extend bits for this byte. */ |
1899 | unsigned int signMask = sign & ~unusedMSMask; |
1900 | accum |= |
1901 | (((bytes[src] >> unusedLS) & unusedMSMask) | signMask) << accumSize; |
1902 | accumSize += HOST_CHAR_BIT8 - unusedLS; |
1903 | if (accumSize >= HOST_CHAR_BIT8) |
1904 | { |
1905 | unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT8); |
1906 | accumSize -= HOST_CHAR_BIT8; |
1907 | accum >>= HOST_CHAR_BIT8; |
1908 | ntarg -= 1; |
1909 | targ += delta; |
1910 | } |
1911 | srcBitsLeft -= HOST_CHAR_BIT8 - unusedLS; |
1912 | unusedLS = 0; |
1913 | nsrc -= 1; |
1914 | src += delta; |
1915 | } |
1916 | while (ntarg > 0) |
1917 | { |
1918 | accum |= sign << accumSize; |
1919 | unpacked[targ] = accum & ~(~0L << HOST_CHAR_BIT8); |
1920 | accumSize -= HOST_CHAR_BIT8; |
1921 | accum >>= HOST_CHAR_BIT8; |
1922 | ntarg -= 1; |
1923 | targ += delta; |
1924 | } |
1925 | |
1926 | return v; |
1927 | } |
1928 | |
1929 | /* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to |
1930 | TARGET, starting at bit offset TARG_OFFSET. SOURCE and TARGET must |
1931 | not overlap. */ |
1932 | static void |
1933 | move_bits (char *target, int targ_offset, char *source, int src_offset, int n) |
1934 | { |
1935 | unsigned int accum, mask; |
1936 | int accum_bits, chunk_size; |
1937 | |
1938 | target += targ_offset / HOST_CHAR_BIT8; |
1939 | targ_offset %= HOST_CHAR_BIT8; |
1940 | source += src_offset / HOST_CHAR_BIT8; |
1941 | src_offset %= HOST_CHAR_BIT8; |
1942 | if (BITS_BIG_ENDIAN((gdbarch_byte_order (current_gdbarch)) == BFD_ENDIAN_BIG)) |
1943 | { |
1944 | accum = (unsigned char) *source; |
1945 | source += 1; |
1946 | accum_bits = HOST_CHAR_BIT8 - src_offset; |
1947 | |
1948 | while (n > 0) |
1949 | { |
1950 | int unused_right; |
1951 | accum = (accum << HOST_CHAR_BIT8) + (unsigned char) *source; |
1952 | accum_bits += HOST_CHAR_BIT8; |
1953 | source += 1; |
1954 | chunk_size = HOST_CHAR_BIT8 - targ_offset; |
1955 | if (chunk_size > n) |
1956 | chunk_size = n; |
1957 | unused_right = HOST_CHAR_BIT8 - (chunk_size + targ_offset); |
1958 | mask = ((1 << chunk_size) - 1) << unused_right; |
1959 | *target = |
1960 | (*target & ~mask) |
1961 | | ((accum >> (accum_bits - chunk_size - unused_right)) & mask); |
1962 | n -= chunk_size; |
1963 | accum_bits -= chunk_size; |
1964 | target += 1; |
1965 | targ_offset = 0; |
1966 | } |
1967 | } |
1968 | else |
1969 | { |
1970 | accum = (unsigned char) *source >> src_offset; |
1971 | source += 1; |
1972 | accum_bits = HOST_CHAR_BIT8 - src_offset; |
1973 | |
1974 | while (n > 0) |
1975 | { |
1976 | accum = accum + ((unsigned char) *source << accum_bits); |
1977 | accum_bits += HOST_CHAR_BIT8; |
1978 | source += 1; |
1979 | chunk_size = HOST_CHAR_BIT8 - targ_offset; |
1980 | if (chunk_size > n) |
1981 | chunk_size = n; |
1982 | mask = ((1 << chunk_size) - 1) << targ_offset; |
1983 | *target = (*target & ~mask) | ((accum << targ_offset) & mask); |
1984 | n -= chunk_size; |
1985 | accum_bits -= chunk_size; |
1986 | accum >>= chunk_size; |
1987 | target += 1; |
1988 | targ_offset = 0; |
1989 | } |
1990 | } |
1991 | } |
1992 | |
1993 | |
1994 | /* Store the contents of FROMVAL into the location of TOVAL. |
1995 | Return a new value with the location of TOVAL and contents of |
1996 | FROMVAL. Handles assignment into packed fields that have |
1997 | floating-point or non-scalar types. */ |
1998 | |
1999 | static struct value * |
2000 | ada_value_assign (struct value *toval, struct value *fromval) |
2001 | { |
2002 | struct type *type = VALUE_TYPE (toval)(toval)->type; |
2003 | int bits = VALUE_BITSIZE (toval)(toval)->bitsize; |
2004 | |
2005 | if (!toval->modifiable) |
2006 | error ("Left operand of assignment is not a modifiable lvalue."); |
2007 | |
2008 | COERCE_REF (toval)do { struct type *value_type_arg_tmp = check_typedef ((toval) ->type); if ((value_type_arg_tmp)->main_type->code == TYPE_CODE_REF) toval = value_at_lazy ((value_type_arg_tmp)-> main_type->target_type, unpack_pointer ((toval)->type, ( (void)((toval)->lazy && value_fetch_lazy(toval)), ( (char *) (toval)->aligner.contents + (toval)->embedded_offset ))), ((toval)->bfd_section)); } while (0); |
2009 | |
2010 | if (VALUE_LVAL (toval)(toval)->lval == lval_memory |
2011 | && bits > 0 |
2012 | && (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_FLT |
2013 | || TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT)) |
2014 | { |
2015 | int len = |
2016 | (VALUE_BITPOS (toval)(toval)->bitpos + bits + HOST_CHAR_BIT8 - 1) / HOST_CHAR_BIT8; |
2017 | char *buffer = (char *) alloca (len)__builtin_alloca(len); |
2018 | struct value *val; |
2019 | |
2020 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_FLT) |
2021 | fromval = value_cast (type, fromval); |
2022 | |
2023 | read_memory (VALUE_ADDRESS (toval)(toval)->location.address + VALUE_OFFSET (toval)(toval)->offset, buffer, len); |
2024 | if (BITS_BIG_ENDIAN((gdbarch_byte_order (current_gdbarch)) == BFD_ENDIAN_BIG)) |
2025 | move_bits (buffer, VALUE_BITPOS (toval)(toval)->bitpos, |
2026 | VALUE_CONTENTS (fromval)((void)((fromval)->lazy && value_fetch_lazy(fromval )), ((char *) (fromval)->aligner.contents + (fromval)-> embedded_offset)), |
2027 | TYPE_LENGTH (VALUE_TYPE (fromval))((fromval)->type)->length * TARGET_CHAR_BIT8 - |
2028 | bits, bits); |
2029 | else |
2030 | move_bits (buffer, VALUE_BITPOS (toval)(toval)->bitpos, VALUE_CONTENTS (fromval)((void)((fromval)->lazy && value_fetch_lazy(fromval )), ((char *) (fromval)->aligner.contents + (fromval)-> embedded_offset)), |
2031 | 0, bits); |
2032 | write_memory (VALUE_ADDRESS (toval)(toval)->location.address + VALUE_OFFSET (toval)(toval)->offset, buffer, |
2033 | len); |
2034 | |
2035 | val = value_copy (toval); |
2036 | memcpy (VALUE_CONTENTS_RAW (val)((char *) (val)->aligner.contents + (val)->embedded_offset ), VALUE_CONTENTS (fromval)((void)((fromval)->lazy && value_fetch_lazy(fromval )), ((char *) (fromval)->aligner.contents + (fromval)-> embedded_offset)), |
2037 | TYPE_LENGTH (type)(type)->length); |
2038 | VALUE_TYPE (val)(val)->type = type; |
2039 | |
2040 | return val; |
2041 | } |
2042 | |
2043 | return value_assign (toval, fromval); |
2044 | } |
2045 | |
2046 | |
2047 | /* The value of the element of array ARR at the ARITY indices given in IND. |
2048 | ARR may be either a simple array, GNAT array descriptor, or pointer |
2049 | thereto. */ |
2050 | |
2051 | struct value * |
2052 | ada_value_subscript (struct value *arr, int arity, struct value **ind) |
2053 | { |
2054 | int k; |
2055 | struct value *elt; |
2056 | struct type *elt_type; |
2057 | |
2058 | elt = ada_coerce_to_simple_array (arr); |
2059 | |
2060 | elt_type = ada_check_typedef (VALUE_TYPE (elt)(elt)->type); |
2061 | if (TYPE_CODE (elt_type)(elt_type)->main_type->code == TYPE_CODE_ARRAY |
2062 | && TYPE_FIELD_BITSIZE (elt_type, 0)(((elt_type)->main_type->fields[0]).bitsize) > 0) |
2063 | return value_subscript_packed (elt, arity, ind); |
2064 | |
2065 | for (k = 0; k < arity; k += 1) |
2066 | { |
2067 | if (TYPE_CODE (elt_type)(elt_type)->main_type->code != TYPE_CODE_ARRAY) |
2068 | error ("too many subscripts (%d expected)", k); |
2069 | elt = value_subscript (elt, value_pos_atr (ind[k])); |
2070 | } |
2071 | return elt; |
2072 | } |
2073 | |
2074 | /* Assuming ARR is a pointer to a standard GDB array of type TYPE, the |
2075 | value of the element of *ARR at the ARITY indices given in |
2076 | IND. Does not read the entire array into memory. */ |
2077 | |
2078 | struct value * |
2079 | ada_value_ptr_subscript (struct value *arr, struct type *type, int arity, |
2080 | struct value **ind) |
2081 | { |
2082 | int k; |
2083 | |
2084 | for (k = 0; k < arity; k += 1) |
2085 | { |
2086 | LONGESTlong lwb, upb; |
2087 | struct value *idx; |
2088 | |
2089 | if (TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_ARRAY) |
2090 | error ("too many subscripts (%d expected)", k); |
2091 | arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)(type)->main_type->target_type), |
2092 | value_copy (arr)); |
2093 | get_discrete_bounds (TYPE_INDEX_TYPE (type)(((type)->main_type->fields[0]).type), &lwb, &upb); |
2094 | idx = value_pos_atr (ind[k]); |
2095 | if (lwb != 0) |
2096 | idx = value_sub (idx, value_from_longest (builtin_type_int, lwb)); |
2097 | arr = value_add (arr, idx); |
2098 | type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type; |
2099 | } |
2100 | |
2101 | return value_ind (arr); |
2102 | } |
2103 | |
2104 | /* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the |
2105 | actual type of ARRAY_PTR is ignored), returns a reference to |
2106 | the Ada slice of HIGH-LOW+1 elements starting at index LOW. The lower |
2107 | bound of this array is LOW, as per Ada rules. */ |
2108 | static struct value * |
2109 | ada_value_slice_ptr (struct value *array_ptr, struct type *type, |
2110 | int low, int high) |
2111 | { |
2112 | CORE_ADDR base = value_as_address (array_ptr) |
2113 | + ((low - TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type))((((((type)->main_type->fields[0]).type))->main_type ->fields[0]).loc.bitpos)) |
2114 | * TYPE_LENGTH (TYPE_TARGET_TYPE (type))((type)->main_type->target_type)->length); |
2115 | struct type *index_type = |
2116 | create_range_type (NULL((void*)0), TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type))((((type)->main_type->fields[0]).type))->main_type-> target_type, |
2117 | low, high); |
2118 | struct type *slice_type = |
2119 | create_array_type (NULL((void*)0), TYPE_TARGET_TYPE (type)(type)->main_type->target_type, index_type); |
2120 | return value_from_pointer (lookup_reference_type (slice_type), base); |
2121 | } |
2122 | |
2123 | |
2124 | static struct value * |
2125 | ada_value_slice (struct value *array, int low, int high) |
2126 | { |
2127 | struct type *type = VALUE_TYPE (array)(array)->type; |
2128 | struct type *index_type = |
2129 | create_range_type (NULL((void*)0), TYPE_INDEX_TYPE (type)(((type)->main_type->fields[0]).type), low, high); |
2130 | struct type *slice_type = |
2131 | create_array_type (NULL((void*)0), TYPE_TARGET_TYPE (type)(type)->main_type->target_type, index_type); |
2132 | return value_cast (slice_type, value_slice (array, low, high - low + 1)); |
2133 | } |
2134 | |
2135 | /* If type is a record type in the form of a standard GNAT array |
2136 | descriptor, returns the number of dimensions for type. If arr is a |
2137 | simple array, returns the number of "array of"s that prefix its |
2138 | type designation. Otherwise, returns 0. */ |
2139 | |
2140 | int |
2141 | ada_array_arity (struct type *type) |
2142 | { |
2143 | int arity; |
2144 | |
2145 | if (type == NULL((void*)0)) |
2146 | return 0; |
2147 | |
2148 | type = desc_base_type (type); |
2149 | |
2150 | arity = 0; |
2151 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT) |
2152 | return desc_arity (desc_bounds_type (type)); |
2153 | else |
2154 | while (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY) |
2155 | { |
2156 | arity += 1; |
2157 | type = ada_check_typedef (TYPE_TARGET_TYPE (type)(type)->main_type->target_type); |
2158 | } |
2159 | |
2160 | return arity; |
2161 | } |
2162 | |
2163 | /* If TYPE is a record type in the form of a standard GNAT array |
2164 | descriptor or a simple array type, returns the element type for |
2165 | TYPE after indexing by NINDICES indices, or by all indices if |
2166 | NINDICES is -1. Otherwise, returns NULL. */ |
2167 | |
2168 | struct type * |
2169 | ada_array_element_type (struct type *type, int nindices) |
2170 | { |
2171 | type = desc_base_type (type); |
2172 | |
2173 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT) |
2174 | { |
2175 | int k; |
2176 | struct type *p_array_type; |
2177 | |
2178 | p_array_type = desc_data_type (type); |
2179 | |
2180 | k = ada_array_arity (type); |
2181 | if (k == 0) |
2182 | return NULL((void*)0); |
2183 | |
2184 | /* Initially p_array_type = elt_type(*)[]...(k times)...[]. */ |
2185 | if (nindices >= 0 && k > nindices) |
2186 | k = nindices; |
2187 | p_array_type = TYPE_TARGET_TYPE (p_array_type)(p_array_type)->main_type->target_type; |
2188 | while (k > 0 && p_array_type != NULL((void*)0)) |
2189 | { |
2190 | p_array_type = ada_check_typedef (TYPE_TARGET_TYPE (p_array_type)(p_array_type)->main_type->target_type); |
2191 | k -= 1; |
2192 | } |
2193 | return p_array_type; |
2194 | } |
2195 | else if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY) |
2196 | { |
2197 | while (nindices != 0 && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY) |
2198 | { |
2199 | type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type; |
2200 | nindices -= 1; |
2201 | } |
2202 | return type; |
2203 | } |
2204 | |
2205 | return NULL((void*)0); |
2206 | } |
2207 | |
2208 | /* The type of nth index in arrays of given type (n numbering from 1). |
2209 | Does not examine memory. */ |
2210 | |
2211 | struct type * |
2212 | ada_index_type (struct type *type, int n) |
2213 | { |
2214 | struct type *result_type; |
2215 | |
2216 | type = desc_base_type (type); |
2217 | |
2218 | if (n > ada_array_arity (type)) |
2219 | return NULL((void*)0); |
2220 | |
2221 | if (ada_is_simple_array_type (type)) |
2222 | { |
2223 | int i; |
2224 | |
2225 | for (i = 1; i < n; i += 1) |
2226 | type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type; |
2227 | result_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0))((((type)->main_type->fields[0]).type))->main_type-> target_type; |
2228 | /* FIXME: The stabs type r(0,0);bound;bound in an array type |
2229 | has a target type of TYPE_CODE_UNDEF. We compensate here, but |
2230 | perhaps stabsread.c would make more sense. */ |
2231 | if (result_type == NULL((void*)0) || TYPE_CODE (result_type)(result_type)->main_type->code == TYPE_CODE_UNDEF) |
2232 | result_type = builtin_type_int; |
2233 | |
2234 | return result_type; |
2235 | } |
2236 | else |
2237 | return desc_index_type (desc_bounds_type (type), n); |
2238 | } |
2239 | |
2240 | /* Given that arr is an array type, returns the lower bound of the |
2241 | Nth index (numbering from 1) if WHICH is 0, and the upper bound if |
2242 | WHICH is 1. This returns bounds 0 .. -1 if ARR_TYPE is an |
2243 | array-descriptor type. If TYPEP is non-null, *TYPEP is set to the |
2244 | bounds type. It works for other arrays with bounds supplied by |
2245 | run-time quantities other than discriminants. */ |
2246 | |
2247 | LONGESTlong |
2248 | ada_array_bound_from_type (struct type * arr_type, int n, int which, |
2249 | struct type ** typep) |
2250 | { |
2251 | struct type *type; |
2252 | struct type *index_type_desc; |
2253 | |
2254 | if (ada_is_packed_array_type (arr_type)) |
2255 | arr_type = decode_packed_array_type (arr_type); |
2256 | |
2257 | if (arr_type == NULL((void*)0) || !ada_is_simple_array_type (arr_type)) |
2258 | { |
2259 | if (typep != NULL((void*)0)) |
2260 | *typep = builtin_type_int; |
2261 | return (LONGESTlong) - which; |
2262 | } |
2263 | |
2264 | if (TYPE_CODE (arr_type)(arr_type)->main_type->code == TYPE_CODE_PTR) |
2265 | type = TYPE_TARGET_TYPE (arr_type)(arr_type)->main_type->target_type; |
2266 | else |
2267 | type = arr_type; |
2268 | |
2269 | index_type_desc = ada_find_parallel_type (type, "___XA"); |
2270 | if (index_type_desc == NULL((void*)0)) |
2271 | { |
2272 | struct type *range_type; |
2273 | struct type *index_type; |
2274 | |
2275 | while (n > 1) |
2276 | { |
2277 | type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type; |
2278 | n -= 1; |
2279 | } |
2280 | |
2281 | range_type = TYPE_INDEX_TYPE (type)(((type)->main_type->fields[0]).type); |
2282 | index_type = TYPE_TARGET_TYPE (range_type)(range_type)->main_type->target_type; |
2283 | if (TYPE_CODE (index_type)(index_type)->main_type->code == TYPE_CODE_UNDEF) |
2284 | index_type = builtin_type_long; |
2285 | if (typep != NULL((void*)0)) |
2286 | *typep = index_type; |
2287 | return |
2288 | (LONGESTlong) (which == 0 |
2289 | ? TYPE_LOW_BOUND (range_type)(((range_type)->main_type->fields[0]).loc.bitpos) |
2290 | : TYPE_HIGH_BOUND (range_type)(((range_type)->main_type->fields[1]).loc.bitpos)); |
2291 | } |
2292 | else |
2293 | { |
2294 | struct type *index_type = |
2295 | to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1)(((index_type_desc)->main_type->fields[n - 1]).name), |
2296 | NULL((void*)0), TYPE_OBJFILE (arr_type)(arr_type)->main_type->objfile); |
2297 | if (typep != NULL((void*)0)) |
2298 | *typep = TYPE_TARGET_TYPE (index_type)(index_type)->main_type->target_type; |
2299 | return |
2300 | (LONGESTlong) (which == 0 |
2301 | ? TYPE_LOW_BOUND (index_type)(((index_type)->main_type->fields[0]).loc.bitpos) |
2302 | : TYPE_HIGH_BOUND (index_type)(((index_type)->main_type->fields[1]).loc.bitpos)); |
2303 | } |
2304 | } |
2305 | |
2306 | /* Given that arr is an array value, returns the lower bound of the |
2307 | nth index (numbering from 1) if which is 0, and the upper bound if |
2308 | which is 1. This routine will also work for arrays with bounds |
2309 | supplied by run-time quantities other than discriminants. */ |
2310 | |
2311 | struct value * |
2312 | ada_array_bound (struct value *arr, int n, int which) |
2313 | { |
2314 | struct type *arr_type = VALUE_TYPE (arr)(arr)->type; |
2315 | |
2316 | if (ada_is_packed_array_type (arr_type)) |
2317 | return ada_array_bound (decode_packed_array (arr), n, which); |
2318 | else if (ada_is_simple_array_type (arr_type)) |
2319 | { |
2320 | struct type *type; |
2321 | LONGESTlong v = ada_array_bound_from_type (arr_type, n, which, &type); |
2322 | return value_from_longest (type, v); |
2323 | } |
2324 | else |
2325 | return desc_one_bound (desc_bounds (arr), n, which); |
2326 | } |
2327 | |
2328 | /* Given that arr is an array value, returns the length of the |
2329 | nth index. This routine will also work for arrays with bounds |
2330 | supplied by run-time quantities other than discriminants. |
2331 | Does not work for arrays indexed by enumeration types with representation |
2332 | clauses at the moment. */ |
2333 | |
2334 | struct value * |
2335 | ada_array_length (struct value *arr, int n) |
2336 | { |
2337 | struct type *arr_type = ada_check_typedef (VALUE_TYPE (arr)(arr)->type); |
2338 | |
2339 | if (ada_is_packed_array_type (arr_type)) |
2340 | return ada_array_length (decode_packed_array (arr), n); |
2341 | |
2342 | if (ada_is_simple_array_type (arr_type)) |
2343 | { |
2344 | struct type *type; |
2345 | LONGESTlong v = |
2346 | ada_array_bound_from_type (arr_type, n, 1, &type) - |
2347 | ada_array_bound_from_type (arr_type, n, 0, NULL((void*)0)) + 1; |
2348 | return value_from_longest (type, v); |
2349 | } |
2350 | else |
2351 | return |
2352 | value_from_longest (builtin_type_int, |
2353 | value_as_long (desc_one_bound (desc_bounds (arr), |
2354 | n, 1)) |
2355 | - value_as_long (desc_one_bound (desc_bounds (arr), |
2356 | n, 0)) + 1); |
2357 | } |
2358 | |
2359 | /* An empty array whose type is that of ARR_TYPE (an array type), |
2360 | with bounds LOW to LOW-1. */ |
2361 | |
2362 | static struct value * |
2363 | empty_array (struct type *arr_type, int low) |
2364 | { |
2365 | struct type *index_type = |
2366 | create_range_type (NULL((void*)0), TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type))((((arr_type)->main_type->fields[0]).type))->main_type ->target_type, |
2367 | low, low - 1); |
2368 | struct type *elt_type = ada_array_element_type (arr_type, 1); |
2369 | return allocate_value (create_array_type (NULL((void*)0), elt_type, index_type)); |
2370 | } |
2371 | |
2372 | |
2373 | /* Name resolution */ |
2374 | |
2375 | /* The "decoded" name for the user-definable Ada operator corresponding |
2376 | to OP. */ |
2377 | |
2378 | static const char * |
2379 | ada_decoded_op_name (enum exp_opcode op) |
2380 | { |
2381 | int i; |
2382 | |
2383 | for (i = 0; ada_opname_table[i].encoded != NULL((void*)0); i += 1) |
2384 | { |
2385 | if (ada_opname_table[i].op == op) |
2386 | return ada_opname_table[i].decoded; |
2387 | } |
2388 | error ("Could not find operator name for opcode"); |
2389 | } |
2390 | |
2391 | |
2392 | /* Same as evaluate_type (*EXP), but resolves ambiguous symbol |
2393 | references (marked by OP_VAR_VALUE nodes in which the symbol has an |
2394 | undefined namespace) and converts operators that are |
2395 | user-defined into appropriate function calls. If CONTEXT_TYPE is |
2396 | non-null, it provides a preferred result type [at the moment, only |
2397 | type void has any effect---causing procedures to be preferred over |
2398 | functions in calls]. A null CONTEXT_TYPE indicates that a non-void |
2399 | return type is preferred. May change (expand) *EXP. */ |
2400 | |
2401 | static void |
2402 | resolve (struct expression **expp, int void_context_p) |
2403 | { |
2404 | int pc; |
2405 | pc = 0; |
2406 | resolve_subexp (expp, &pc, 1, void_context_p ? builtin_type_void : NULL((void*)0)); |
2407 | } |
2408 | |
2409 | /* Resolve the operator of the subexpression beginning at |
2410 | position *POS of *EXPP. "Resolving" consists of replacing |
2411 | the symbols that have undefined namespaces in OP_VAR_VALUE nodes |
2412 | with their resolutions, replacing built-in operators with |
2413 | function calls to user-defined operators, where appropriate, and, |
2414 | when DEPROCEDURE_P is non-zero, converting function-valued variables |
2415 | into parameterless calls. May expand *EXPP. The CONTEXT_TYPE functions |
2416 | are as in ada_resolve, above. */ |
2417 | |
2418 | static struct value * |
2419 | resolve_subexp (struct expression **expp, int *pos, int deprocedure_p, |
2420 | struct type *context_type) |
2421 | { |
2422 | int pc = *pos; |
2423 | int i; |
2424 | struct expression *exp; /* Convenience: == *expp. */ |
2425 | enum exp_opcode op = (*expp)->elts[pc].opcode; |
2426 | struct value **argvec; /* Vector of operand types (alloca'ed). */ |
2427 | int nargs; /* Number of operands. */ |
2428 | |
2429 | argvec = NULL((void*)0); |
2430 | nargs = 0; |
2431 | exp = *expp; |
2432 | |
2433 | /* Pass one: resolve operands, saving their types and updating *pos. */ |
2434 | switch (op) |
2435 | { |
2436 | case OP_FUNCALL: |
2437 | if (exp->elts[pc + 3].opcode == OP_VAR_VALUE |
2438 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol)(exp->elts[pc + 5].symbol)->domain == UNDEF_DOMAIN) |
2439 | *pos += 7; |
2440 | else |
2441 | { |
2442 | *pos += 3; |
2443 | resolve_subexp (expp, pos, 0, NULL((void*)0)); |
2444 | } |
2445 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
2446 | break; |
2447 | |
2448 | case UNOP_QUAL: |
2449 | *pos += 3; |
2450 | resolve_subexp (expp, pos, 1, exp->elts[pc + 1].type); |
2451 | break; |
2452 | |
2453 | case UNOP_ADDR: |
2454 | *pos += 1; |
2455 | resolve_subexp (expp, pos, 0, NULL((void*)0)); |
2456 | break; |
2457 | |
2458 | case OP_ATR_MODULUS: |
2459 | *pos += 4; |
2460 | break; |
2461 | |
2462 | case OP_ATR_SIZE: |
2463 | case OP_ATR_TAG: |
2464 | *pos += 1; |
2465 | nargs = 1; |
2466 | break; |
2467 | |
2468 | case OP_ATR_FIRST: |
2469 | case OP_ATR_LAST: |
2470 | case OP_ATR_LENGTH: |
2471 | case OP_ATR_POS: |
2472 | case OP_ATR_VAL: |
2473 | *pos += 1; |
2474 | nargs = 2; |
2475 | break; |
2476 | |
2477 | case OP_ATR_MIN: |
2478 | case OP_ATR_MAX: |
2479 | *pos += 1; |
2480 | nargs = 3; |
2481 | break; |
2482 | |
2483 | case BINOP_ASSIGN: |
2484 | { |
2485 | struct value *arg1; |
2486 | |
2487 | *pos += 1; |
2488 | arg1 = resolve_subexp (expp, pos, 0, NULL((void*)0)); |
2489 | if (arg1 == NULL((void*)0)) |
2490 | resolve_subexp (expp, pos, 1, NULL((void*)0)); |
2491 | else |
2492 | resolve_subexp (expp, pos, 1, VALUE_TYPE (arg1)(arg1)->type); |
2493 | break; |
2494 | } |
2495 | |
2496 | case UNOP_CAST: |
2497 | case UNOP_IN_RANGE: |
2498 | *pos += 3; |
2499 | nargs = 1; |
2500 | break; |
2501 | |
2502 | case BINOP_ADD: |
2503 | case BINOP_SUB: |
2504 | case BINOP_MUL: |
2505 | case BINOP_DIV: |
2506 | case BINOP_REM: |
2507 | case BINOP_MOD: |
2508 | case BINOP_EXP: |
2509 | case BINOP_CONCAT: |
2510 | case BINOP_LOGICAL_AND: |
2511 | case BINOP_LOGICAL_OR: |
2512 | case BINOP_BITWISE_AND: |
2513 | case BINOP_BITWISE_IOR: |
2514 | case BINOP_BITWISE_XOR: |
2515 | |
2516 | case BINOP_EQUAL: |
2517 | case BINOP_NOTEQUAL: |
2518 | case BINOP_LESS: |
2519 | case BINOP_GTR: |
2520 | case BINOP_LEQ: |
2521 | case BINOP_GEQ: |
2522 | |
2523 | case BINOP_REPEAT: |
2524 | case BINOP_SUBSCRIPT: |
2525 | case BINOP_COMMA: |
2526 | *pos += 1; |
2527 | nargs = 2; |
2528 | break; |
2529 | |
2530 | case UNOP_NEG: |
2531 | case UNOP_PLUS: |
2532 | case UNOP_LOGICAL_NOT: |
2533 | case UNOP_ABS: |
2534 | case UNOP_IND: |
2535 | *pos += 1; |
2536 | nargs = 1; |
2537 | break; |
2538 | |
2539 | case OP_LONG: |
2540 | case OP_DOUBLE: |
2541 | case OP_VAR_VALUE: |
2542 | *pos += 4; |
2543 | break; |
2544 | |
2545 | case OP_TYPE: |
2546 | case OP_BOOL: |
2547 | case OP_LAST: |
2548 | case OP_REGISTER: |
2549 | case OP_INTERNALVAR: |
2550 | *pos += 3; |
2551 | break; |
2552 | |
2553 | case UNOP_MEMVAL: |
2554 | *pos += 3; |
2555 | nargs = 1; |
2556 | break; |
2557 | |
2558 | case STRUCTOP_STRUCT: |
2559 | *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1)(((exp->elts[pc + 1].longconst + 1) + sizeof (union exp_element ) - 1) / sizeof (union exp_element)); |
2560 | nargs = 1; |
2561 | break; |
2562 | |
2563 | case OP_STRING: |
2564 | (*pos) += 3 |
2565 | + BYTES_TO_EXP_ELEM (longest_to_int (exp->elts[pc + 1].longconst)(((longest_to_int (exp->elts[pc + 1].longconst) + 1) + sizeof (union exp_element) - 1) / sizeof (union exp_element)) |
2566 | + 1)(((longest_to_int (exp->elts[pc + 1].longconst) + 1) + sizeof (union exp_element) - 1) / sizeof (union exp_element)); |
2567 | break; |
2568 | |
2569 | case TERNOP_SLICE: |
2570 | case TERNOP_IN_RANGE: |
2571 | *pos += 1; |
2572 | nargs = 3; |
2573 | break; |
2574 | |
2575 | case BINOP_IN_BOUNDS: |
2576 | *pos += 3; |
2577 | nargs = 2; |
2578 | break; |
2579 | |
2580 | default: |
2581 | error ("Unexpected operator during name resolution"); |
2582 | } |
2583 | |
2584 | argvec = (struct value * *) alloca (sizeof (struct value *) * (nargs + 1))__builtin_alloca(sizeof (struct value *) * (nargs + 1)); |
2585 | for (i = 0; i < nargs; i += 1) |
2586 | argvec[i] = resolve_subexp (expp, pos, 1, NULL((void*)0)); |
2587 | argvec[i] = NULL((void*)0); |
2588 | exp = *expp; |
2589 | |
2590 | /* Pass two: perform any resolution on principal operator. */ |
2591 | switch (op) |
2592 | { |
2593 | default: |
2594 | break; |
2595 | |
2596 | case OP_VAR_VALUE: |
2597 | if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol)(exp->elts[pc + 2].symbol)->domain == UNDEF_DOMAIN) |
2598 | { |
2599 | struct ada_symbol_info *candidates; |
2600 | int n_candidates; |
2601 | |
2602 | n_candidates = |
2603 | ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME(exp->elts[pc + 2].symbol)->ginfo.name |
2604 | (exp->elts[pc + 2].symbol)(exp->elts[pc + 2].symbol)->ginfo.name, |
2605 | exp->elts[pc + 1].block, VAR_DOMAIN, |
2606 | &candidates); |
2607 | |
2608 | if (n_candidates > 1) |
2609 | { |
2610 | /* Types tend to get re-introduced locally, so if there |
2611 | are any local symbols that are not types, first filter |
2612 | out all types. */ |
2613 | int j; |
2614 | for (j = 0; j < n_candidates; j += 1) |
2615 | switch (SYMBOL_CLASS (candidates[j].sym)(candidates[j].sym)->aclass) |
2616 | { |
2617 | case LOC_REGISTER: |
2618 | case LOC_ARG: |
2619 | case LOC_REF_ARG: |
2620 | case LOC_REGPARM: |
2621 | case LOC_REGPARM_ADDR: |
2622 | case LOC_LOCAL: |
2623 | case LOC_LOCAL_ARG: |
2624 | case LOC_BASEREG: |
2625 | case LOC_BASEREG_ARG: |
2626 | case LOC_COMPUTED: |
2627 | case LOC_COMPUTED_ARG: |
2628 | goto FoundNonType; |
2629 | default: |
2630 | break; |
2631 | } |
2632 | FoundNonType: |
2633 | if (j < n_candidates) |
2634 | { |
2635 | j = 0; |
2636 | while (j < n_candidates) |
2637 | { |
2638 | if (SYMBOL_CLASS (candidates[j].sym)(candidates[j].sym)->aclass == LOC_TYPEDEF) |
2639 | { |
2640 | candidates[j] = candidates[n_candidates - 1]; |
2641 | n_candidates -= 1; |
2642 | } |
2643 | else |
2644 | j += 1; |
2645 | } |
2646 | } |
2647 | } |
2648 | |
2649 | if (n_candidates == 0) |
2650 | error ("No definition found for %s", |
2651 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)(demangle ? (symbol_natural_name (&(exp->elts[pc + 2]. symbol)->ginfo)) : (exp->elts[pc + 2].symbol)->ginfo .name)); |
2652 | else if (n_candidates == 1) |
2653 | i = 0; |
2654 | else if (deprocedure_p |
2655 | && !is_nonfunction (candidates, n_candidates)) |
2656 | { |
2657 | i = ada_resolve_function |
2658 | (candidates, n_candidates, NULL((void*)0), 0, |
2659 | SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol)(exp->elts[pc + 2].symbol)->ginfo.name, |
2660 | context_type); |
2661 | if (i < 0) |
2662 | error ("Could not find a match for %s", |
2663 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)(demangle ? (symbol_natural_name (&(exp->elts[pc + 2]. symbol)->ginfo)) : (exp->elts[pc + 2].symbol)->ginfo .name)); |
2664 | } |
2665 | else |
2666 | { |
2667 | printf_filtered ("Multiple matches for %s\n", |
2668 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)(demangle ? (symbol_natural_name (&(exp->elts[pc + 2]. symbol)->ginfo)) : (exp->elts[pc + 2].symbol)->ginfo .name)); |
2669 | user_select_syms (candidates, n_candidates, 1); |
2670 | i = 0; |
2671 | } |
2672 | |
2673 | exp->elts[pc + 1].block = candidates[i].block; |
2674 | exp->elts[pc + 2].symbol = candidates[i].sym; |
2675 | if (innermost_block == NULL((void*)0) |
2676 | || contained_in (candidates[i].block, innermost_block)) |
2677 | innermost_block = candidates[i].block; |
2678 | } |
2679 | |
2680 | if (deprocedure_p |
2681 | && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol))((exp->elts[pc + 2].symbol)->type)->main_type->code |
2682 | == TYPE_CODE_FUNC)) |
2683 | { |
2684 | replace_operator_with_call (expp, pc, 0, 0, |
2685 | exp->elts[pc + 2].symbol, |
2686 | exp->elts[pc + 1].block); |
2687 | exp = *expp; |
2688 | } |
2689 | break; |
2690 | |
2691 | case OP_FUNCALL: |
2692 | { |
2693 | if (exp->elts[pc + 3].opcode == OP_VAR_VALUE |
2694 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol)(exp->elts[pc + 5].symbol)->domain == UNDEF_DOMAIN) |
2695 | { |
2696 | struct ada_symbol_info *candidates; |
2697 | int n_candidates; |
2698 | |
2699 | n_candidates = |
2700 | ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME(exp->elts[pc + 5].symbol)->ginfo.name |
2701 | (exp->elts[pc + 5].symbol)(exp->elts[pc + 5].symbol)->ginfo.name, |
2702 | exp->elts[pc + 4].block, VAR_DOMAIN, |
2703 | &candidates); |
2704 | if (n_candidates == 1) |
2705 | i = 0; |
2706 | else |
2707 | { |
2708 | i = ada_resolve_function |
2709 | (candidates, n_candidates, |
2710 | argvec, nargs, |
2711 | SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol)(exp->elts[pc + 5].symbol)->ginfo.name, |
2712 | context_type); |
2713 | if (i < 0) |
2714 | error ("Could not find a match for %s", |
2715 | SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol)(demangle ? (symbol_natural_name (&(exp->elts[pc + 5]. symbol)->ginfo)) : (exp->elts[pc + 5].symbol)->ginfo .name)); |
2716 | } |
2717 | |
2718 | exp->elts[pc + 4].block = candidates[i].block; |
2719 | exp->elts[pc + 5].symbol = candidates[i].sym; |
2720 | if (innermost_block == NULL((void*)0) |
2721 | || contained_in (candidates[i].block, innermost_block)) |
2722 | innermost_block = candidates[i].block; |
2723 | } |
2724 | } |
2725 | break; |
2726 | case BINOP_ADD: |
2727 | case BINOP_SUB: |
2728 | case BINOP_MUL: |
2729 | case BINOP_DIV: |
2730 | case BINOP_REM: |
2731 | case BINOP_MOD: |
2732 | case BINOP_CONCAT: |
2733 | case BINOP_BITWISE_AND: |
2734 | case BINOP_BITWISE_IOR: |
2735 | case BINOP_BITWISE_XOR: |
2736 | case BINOP_EQUAL: |
2737 | case BINOP_NOTEQUAL: |
2738 | case BINOP_LESS: |
2739 | case BINOP_GTR: |
2740 | case BINOP_LEQ: |
2741 | case BINOP_GEQ: |
2742 | case BINOP_EXP: |
2743 | case UNOP_NEG: |
2744 | case UNOP_PLUS: |
2745 | case UNOP_LOGICAL_NOT: |
2746 | case UNOP_ABS: |
2747 | if (possible_user_operator_p (op, argvec)) |
2748 | { |
2749 | struct ada_symbol_info *candidates; |
2750 | int n_candidates; |
2751 | |
2752 | n_candidates = |
2753 | ada_lookup_symbol_list (ada_encode (ada_decoded_op_name (op)), |
2754 | (struct block *) NULL((void*)0), VAR_DOMAIN, |
2755 | &candidates); |
2756 | i = ada_resolve_function (candidates, n_candidates, argvec, nargs, |
2757 | ada_decoded_op_name (op), NULL((void*)0)); |
2758 | if (i < 0) |
2759 | break; |
2760 | |
2761 | replace_operator_with_call (expp, pc, nargs, 1, |
2762 | candidates[i].sym, candidates[i].block); |
2763 | exp = *expp; |
2764 | } |
2765 | break; |
2766 | |
2767 | case OP_TYPE: |
2768 | return NULL((void*)0); |
2769 | } |
2770 | |
2771 | *pos = pc; |
2772 | return evaluate_subexp_type (exp, pos); |
2773 | } |
2774 | |
2775 | /* Return non-zero if formal type FTYPE matches actual type ATYPE. If |
2776 | MAY_DEREF is non-zero, the formal may be a pointer and the actual |
2777 | a non-pointer. A type of 'void' (which is never a valid expression type) |
2778 | by convention matches anything. */ |
2779 | /* The term "match" here is rather loose. The match is heuristic and |
2780 | liberal. FIXME: TOO liberal, in fact. */ |
2781 | |
2782 | static int |
2783 | ada_type_match (struct type *ftype, struct type *atype, int may_deref) |
2784 | { |
2785 | ftype = ada_check_typedef (ftype); |
2786 | atype = ada_check_typedef (atype); |
2787 | |
2788 | if (TYPE_CODE (ftype)(ftype)->main_type->code == TYPE_CODE_REF) |
2789 | ftype = TYPE_TARGET_TYPE (ftype)(ftype)->main_type->target_type; |
2790 | if (TYPE_CODE (atype)(atype)->main_type->code == TYPE_CODE_REF) |
2791 | atype = TYPE_TARGET_TYPE (atype)(atype)->main_type->target_type; |
2792 | |
2793 | if (TYPE_CODE (ftype)(ftype)->main_type->code == TYPE_CODE_VOID |
2794 | || TYPE_CODE (atype)(atype)->main_type->code == TYPE_CODE_VOID) |
2795 | return 1; |
2796 | |
2797 | switch (TYPE_CODE (ftype)(ftype)->main_type->code) |
2798 | { |
2799 | default: |
2800 | return 1; |
2801 | case TYPE_CODE_PTR: |
2802 | if (TYPE_CODE (atype)(atype)->main_type->code == TYPE_CODE_PTR) |
2803 | return ada_type_match (TYPE_TARGET_TYPE (ftype)(ftype)->main_type->target_type, |
2804 | TYPE_TARGET_TYPE (atype)(atype)->main_type->target_type, 0); |
2805 | else |
2806 | return (may_deref |
2807 | && ada_type_match (TYPE_TARGET_TYPE (ftype)(ftype)->main_type->target_type, atype, 0)); |
2808 | case TYPE_CODE_INT: |
2809 | case TYPE_CODE_ENUM: |
2810 | case TYPE_CODE_RANGE: |
2811 | switch (TYPE_CODE (atype)(atype)->main_type->code) |
2812 | { |
2813 | case TYPE_CODE_INT: |
2814 | case TYPE_CODE_ENUM: |
2815 | case TYPE_CODE_RANGE: |
2816 | return 1; |
2817 | default: |
2818 | return 0; |
2819 | } |
2820 | |
2821 | case TYPE_CODE_ARRAY: |
2822 | return (TYPE_CODE (atype)(atype)->main_type->code == TYPE_CODE_ARRAY |
2823 | || ada_is_array_descriptor_type (atype)); |
2824 | |
2825 | case TYPE_CODE_STRUCT: |
2826 | if (ada_is_array_descriptor_type (ftype)) |
2827 | return (TYPE_CODE (atype)(atype)->main_type->code == TYPE_CODE_ARRAY |
2828 | || ada_is_array_descriptor_type (atype)); |
2829 | else |
2830 | return (TYPE_CODE (atype)(atype)->main_type->code == TYPE_CODE_STRUCT |
2831 | && !ada_is_array_descriptor_type (atype)); |
2832 | |
2833 | case TYPE_CODE_UNION: |
2834 | case TYPE_CODE_FLT: |
2835 | return (TYPE_CODE (atype)(atype)->main_type->code == TYPE_CODE (ftype)(ftype)->main_type->code); |
2836 | } |
2837 | } |
2838 | |
2839 | /* Return non-zero if the formals of FUNC "sufficiently match" the |
2840 | vector of actual argument types ACTUALS of size N_ACTUALS. FUNC |
2841 | may also be an enumeral, in which case it is treated as a 0- |
2842 | argument function. */ |
2843 | |
2844 | static int |
2845 | ada_args_match (struct symbol *func, struct value **actuals, int n_actuals) |
2846 | { |
2847 | int i; |
2848 | struct type *func_type = SYMBOL_TYPE (func)(func)->type; |
2849 | |
2850 | if (SYMBOL_CLASS (func)(func)->aclass == LOC_CONST |
2851 | && TYPE_CODE (func_type)(func_type)->main_type->code == TYPE_CODE_ENUM) |
2852 | return (n_actuals == 0); |
2853 | else if (func_type == NULL((void*)0) || TYPE_CODE (func_type)(func_type)->main_type->code != TYPE_CODE_FUNC) |
2854 | return 0; |
2855 | |
2856 | if (TYPE_NFIELDS (func_type)(func_type)->main_type->nfields != n_actuals) |
2857 | return 0; |
2858 | |
2859 | for (i = 0; i < n_actuals; i += 1) |
2860 | { |
2861 | if (actuals[i] == NULL((void*)0)) |
2862 | return 0; |
2863 | else |
2864 | { |
2865 | struct type *ftype = ada_check_typedef (TYPE_FIELD_TYPE (func_type, i)(((func_type)->main_type->fields[i]).type)); |
2866 | struct type *atype = ada_check_typedef (VALUE_TYPE (actuals[i])(actuals[i])->type); |
2867 | |
2868 | if (!ada_type_match (ftype, atype, 1)) |
2869 | return 0; |
2870 | } |
2871 | } |
2872 | return 1; |
2873 | } |
2874 | |
2875 | /* False iff function type FUNC_TYPE definitely does not produce a value |
2876 | compatible with type CONTEXT_TYPE. Conservatively returns 1 if |
2877 | FUNC_TYPE is not a valid function type with a non-null return type |
2878 | or an enumerated type. A null CONTEXT_TYPE indicates any non-void type. */ |
2879 | |
2880 | static int |
2881 | return_match (struct type *func_type, struct type *context_type) |
2882 | { |
2883 | struct type *return_type; |
2884 | |
2885 | if (func_type == NULL((void*)0)) |
2886 | return 1; |
2887 | |
2888 | if (TYPE_CODE (func_type)(func_type)->main_type->code == TYPE_CODE_FUNC) |
2889 | return_type = base_type (TYPE_TARGET_TYPE (func_type)(func_type)->main_type->target_type); |
2890 | else |
2891 | return_type = base_type (func_type); |
2892 | if (return_type == NULL((void*)0)) |
2893 | return 1; |
2894 | |
2895 | context_type = base_type (context_type); |
2896 | |
2897 | if (TYPE_CODE (return_type)(return_type)->main_type->code == TYPE_CODE_ENUM) |
2898 | return context_type == NULL((void*)0) || return_type == context_type; |
2899 | else if (context_type == NULL((void*)0)) |
2900 | return TYPE_CODE (return_type)(return_type)->main_type->code != TYPE_CODE_VOID; |
2901 | else |
2902 | return TYPE_CODE (return_type)(return_type)->main_type->code == TYPE_CODE (context_type)(context_type)->main_type->code; |
2903 | } |
2904 | |
2905 | |
2906 | /* Returns the index in SYMS[0..NSYMS-1] that contains the symbol for the |
2907 | function (if any) that matches the types of the NARGS arguments in |
2908 | ARGS. If CONTEXT_TYPE is non-null and there is at least one match |
2909 | that returns that type, then eliminate matches that don't. If |
2910 | CONTEXT_TYPE is void and there is at least one match that does not |
2911 | return void, eliminate all matches that do. |
2912 | |
2913 | Asks the user if there is more than one match remaining. Returns -1 |
2914 | if there is no such symbol or none is selected. NAME is used |
2915 | solely for messages. May re-arrange and modify SYMS in |
2916 | the process; the index returned is for the modified vector. */ |
2917 | |
2918 | static int |
2919 | ada_resolve_function (struct ada_symbol_info syms[], |
2920 | int nsyms, struct value **args, int nargs, |
2921 | const char *name, struct type *context_type) |
2922 | { |
2923 | int k; |
2924 | int m; /* Number of hits */ |
2925 | struct type *fallback; |
2926 | struct type *return_type; |
2927 | |
2928 | return_type = context_type; |
2929 | if (context_type == NULL((void*)0)) |
2930 | fallback = builtin_type_void; |
2931 | else |
2932 | fallback = NULL((void*)0); |
2933 | |
2934 | m = 0; |
2935 | while (1) |
2936 | { |
2937 | for (k = 0; k < nsyms; k += 1) |
2938 | { |
2939 | struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].sym)(syms[k].sym)->type); |
2940 | |
2941 | if (ada_args_match (syms[k].sym, args, nargs) |
2942 | && return_match (type, return_type)) |
2943 | { |
2944 | syms[m] = syms[k]; |
2945 | m += 1; |
2946 | } |
2947 | } |
2948 | if (m > 0 || return_type == fallback) |
2949 | break; |
2950 | else |
2951 | return_type = fallback; |
2952 | } |
2953 | |
2954 | if (m == 0) |
2955 | return -1; |
2956 | else if (m > 1) |
2957 | { |
2958 | printf_filtered ("Multiple matches for %s\n", name); |
2959 | user_select_syms (syms, m, 1); |
2960 | return 0; |
2961 | } |
2962 | return 0; |
2963 | } |
2964 | |
2965 | /* Returns true (non-zero) iff decoded name N0 should appear before N1 |
2966 | in a listing of choices during disambiguation (see sort_choices, below). |
2967 | The idea is that overloadings of a subprogram name from the |
2968 | same package should sort in their source order. We settle for ordering |
2969 | such symbols by their trailing number (__N or $N). */ |
2970 | |
2971 | static int |
2972 | encoded_ordered_before (char *N0, char *N1) |
2973 | { |
2974 | if (N1 == NULL((void*)0)) |
2975 | return 0; |
2976 | else if (N0 == NULL((void*)0)) |
2977 | return 1; |
2978 | else |
2979 | { |
2980 | int k0, k1; |
2981 | for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1) |
2982 | ; |
2983 | for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1) |
2984 | ; |
2985 | if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000' |
2986 | && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000') |
2987 | { |
2988 | int n0, n1; |
2989 | n0 = k0; |
2990 | while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_') |
2991 | n0 -= 1; |
2992 | n1 = k1; |
2993 | while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_') |
2994 | n1 -= 1; |
2995 | if (n0 == n1 && strncmp (N0, N1, n0) == 0) |
2996 | return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1)); |
2997 | } |
2998 | return (strcmp (N0, N1) < 0); |
2999 | } |
3000 | } |
3001 | |
3002 | /* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the |
3003 | encoded names. */ |
3004 | |
3005 | static void |
3006 | sort_choices (struct ada_symbol_info syms[], int nsyms) |
3007 | { |
3008 | int i; |
3009 | for (i = 1; i < nsyms; i += 1) |
3010 | { |
3011 | struct ada_symbol_info sym = syms[i]; |
3012 | int j; |
3013 | |
3014 | for (j = i - 1; j >= 0; j -= 1) |
3015 | { |
3016 | if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms[j].sym)(syms[j].sym)->ginfo.name, |
3017 | SYMBOL_LINKAGE_NAME (sym.sym)(sym.sym)->ginfo.name)) |
3018 | break; |
3019 | syms[j + 1] = syms[j]; |
3020 | } |
3021 | syms[j + 1] = sym; |
3022 | } |
3023 | } |
3024 | |
3025 | /* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0 |
3026 | by asking the user (if necessary), returning the number selected, |
3027 | and setting the first elements of SYMS items. Error if no symbols |
3028 | selected. */ |
3029 | |
3030 | /* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought |
3031 | to be re-integrated one of these days. */ |
3032 | |
3033 | int |
3034 | user_select_syms (struct ada_symbol_info *syms, int nsyms, int max_results) |
3035 | { |
3036 | int i; |
3037 | int *chosen = (int *) alloca (sizeof (int) * nsyms)__builtin_alloca(sizeof (int) * nsyms); |
3038 | int n_chosen; |
3039 | int first_choice = (max_results == 1) ? 1 : 2; |
3040 | |
3041 | if (max_results < 1) |
3042 | error ("Request to select 0 symbols!"); |
3043 | if (nsyms <= 1) |
3044 | return nsyms; |
3045 | |
3046 | printf_unfiltered ("[0] cancel\n"); |
3047 | if (max_results > 1) |
3048 | printf_unfiltered ("[1] all\n"); |
3049 | |
3050 | sort_choices (syms, nsyms); |
3051 | |
3052 | for (i = 0; i < nsyms; i += 1) |
3053 | { |
3054 | if (syms[i].sym == NULL((void*)0)) |
3055 | continue; |
3056 | |
3057 | if (SYMBOL_CLASS (syms[i].sym)(syms[i].sym)->aclass == LOC_BLOCK) |
3058 | { |
3059 | struct symtab_and_line sal = |
3060 | find_function_start_sal (syms[i].sym, 1); |
3061 | printf_unfiltered ("[%d] %s at %s:%d\n", i + first_choice, |
3062 | SYMBOL_PRINT_NAME (syms[i].sym)(demangle ? (symbol_natural_name (&(syms[i].sym)->ginfo )) : (syms[i].sym)->ginfo.name), |
3063 | (sal.symtab == NULL((void*)0) |
3064 | ? "<no source file available>" |
3065 | : sal.symtab->filename), sal.line); |
3066 | continue; |
3067 | } |
3068 | else |
3069 | { |
3070 | int is_enumeral = |
3071 | (SYMBOL_CLASS (syms[i].sym)(syms[i].sym)->aclass == LOC_CONST |
3072 | && SYMBOL_TYPE (syms[i].sym)(syms[i].sym)->type != NULL((void*)0) |
3073 | && TYPE_CODE (SYMBOL_TYPE (syms[i].sym))((syms[i].sym)->type)->main_type->code == TYPE_CODE_ENUM); |
3074 | struct symtab *symtab = symtab_for_sym (syms[i].sym); |
3075 | |
3076 | if (SYMBOL_LINE (syms[i].sym)(syms[i].sym)->line != 0 && symtab != NULL((void*)0)) |
3077 | printf_unfiltered ("[%d] %s at %s:%d\n", |
3078 | i + first_choice, |
3079 | SYMBOL_PRINT_NAME (syms[i].sym)(demangle ? (symbol_natural_name (&(syms[i].sym)->ginfo )) : (syms[i].sym)->ginfo.name), |
3080 | symtab->filename, SYMBOL_LINE (syms[i].sym)(syms[i].sym)->line); |
3081 | else if (is_enumeral |
3082 | && TYPE_NAME (SYMBOL_TYPE (syms[i].sym))((syms[i].sym)->type)->main_type->name != NULL((void*)0)) |
3083 | { |
3084 | printf_unfiltered ("[%d] ", i + first_choice); |
3085 | ada_print_type (SYMBOL_TYPE (syms[i].sym)(syms[i].sym)->type, NULL((void*)0), |
3086 | gdb_stdout, -1, 0); |
3087 | printf_unfiltered ("'(%s) (enumeral)\n", |
3088 | SYMBOL_PRINT_NAME (syms[i].sym)(demangle ? (symbol_natural_name (&(syms[i].sym)->ginfo )) : (syms[i].sym)->ginfo.name)); |
3089 | } |
3090 | else if (symtab != NULL((void*)0)) |
3091 | printf_unfiltered (is_enumeral |
3092 | ? "[%d] %s in %s (enumeral)\n" |
3093 | : "[%d] %s at %s:?\n", |
3094 | i + first_choice, |
3095 | SYMBOL_PRINT_NAME (syms[i].sym)(demangle ? (symbol_natural_name (&(syms[i].sym)->ginfo )) : (syms[i].sym)->ginfo.name), |
3096 | symtab->filename); |
3097 | else |
3098 | printf_unfiltered (is_enumeral |
3099 | ? "[%d] %s (enumeral)\n" |
3100 | : "[%d] %s at ?\n", |
3101 | i + first_choice, |
3102 | SYMBOL_PRINT_NAME (syms[i].sym)(demangle ? (symbol_natural_name (&(syms[i].sym)->ginfo )) : (syms[i].sym)->ginfo.name)); |
3103 | } |
3104 | } |
3105 | |
3106 | n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1, |
3107 | "overload-choice"); |
3108 | |
3109 | for (i = 0; i < n_chosen; i += 1) |
3110 | syms[i] = syms[chosen[i]]; |
3111 | |
3112 | return n_chosen; |
3113 | } |
3114 | |
3115 | /* Read and validate a set of numeric choices from the user in the |
3116 | range 0 .. N_CHOICES-1. Place the results in increasing |
3117 | order in CHOICES[0 .. N-1], and return N. |
3118 | |
3119 | The user types choices as a sequence of numbers on one line |
3120 | separated by blanks, encoding them as follows: |
3121 | |
3122 | + A choice of 0 means to cancel the selection, throwing an error. |
3123 | + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1. |
3124 | + The user chooses k by typing k+IS_ALL_CHOICE+1. |
3125 | |
3126 | The user is not allowed to choose more than MAX_RESULTS values. |
3127 | |
3128 | ANNOTATION_SUFFIX, if present, is used to annotate the input |
3129 | prompts (for use with the -f switch). */ |
3130 | |
3131 | int |
3132 | get_selections (int *choices, int n_choices, int max_results, |
3133 | int is_all_choice, char *annotation_suffix) |
3134 | { |
3135 | char *args; |
3136 | const char *prompt; |
3137 | int n_chosen; |
3138 | int first_choice = is_all_choice ? 2 : 1; |
3139 | |
3140 | prompt = getenv ("PS2"); |
3141 | if (prompt == NULL((void*)0)) |
3142 | prompt = ">"; |
3143 | |
3144 | printf_unfiltered ("%s ", prompt); |
3145 | gdb_flush (gdb_stdout); |
3146 | |
3147 | args = command_line_input ((char *) NULL((void*)0), 0, annotation_suffix); |
3148 | |
3149 | if (args == NULL((void*)0)) |
3150 | error_no_arg ("one or more choice numbers"); |
3151 | |
3152 | n_chosen = 0; |
3153 | |
3154 | /* Set choices[0 .. n_chosen-1] to the users' choices in ascending |
3155 | order, as given in args. Choices are validated. */ |
3156 | while (1) |
3157 | { |
3158 | char *args2; |
3159 | int choice, j; |
3160 | |
3161 | while (isspace (*args)) |
3162 | args += 1; |
3163 | if (*args == '\0' && n_chosen == 0) |
3164 | error_no_arg ("one or more choice numbers"); |
3165 | else if (*args == '\0') |
3166 | break; |
3167 | |
3168 | choice = strtol (args, &args2, 10); |
3169 | if (args == args2 || choice < 0 |
3170 | || choice > n_choices + first_choice - 1) |
3171 | error ("Argument must be choice number"); |
3172 | args = args2; |
3173 | |
3174 | if (choice == 0) |
3175 | error ("cancelled"); |
3176 | |
3177 | if (choice < first_choice) |
3178 | { |
3179 | n_chosen = n_choices; |
3180 | for (j = 0; j < n_choices; j += 1) |
3181 | choices[j] = j; |
3182 | break; |
3183 | } |
3184 | choice -= first_choice; |
3185 | |
3186 | for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1) |
3187 | { |
3188 | } |
3189 | |
3190 | if (j < 0 || choice != choices[j]) |
3191 | { |
3192 | int k; |
3193 | for (k = n_chosen - 1; k > j; k -= 1) |
3194 | choices[k + 1] = choices[k]; |
3195 | choices[j + 1] = choice; |
3196 | n_chosen += 1; |
3197 | } |
3198 | } |
3199 | |
3200 | if (n_chosen > max_results) |
3201 | error ("Select no more than %d of the above", max_results); |
3202 | |
3203 | return n_chosen; |
3204 | } |
3205 | |
3206 | /* Replace the operator of length OPLEN at position PC in *EXPP with a call |
3207 | on the function identified by SYM and BLOCK, and taking NARGS |
3208 | arguments. Update *EXPP as needed to hold more space. */ |
3209 | |
3210 | static void |
3211 | replace_operator_with_call (struct expression **expp, int pc, int nargs, |
3212 | int oplen, struct symbol *sym, |
3213 | struct block *block) |
3214 | { |
3215 | /* A new expression, with 6 more elements (3 for funcall, 4 for function |
3216 | symbol, -oplen for operator being replaced). */ |
3217 | struct expression *newexp = (struct expression *) |
3218 | xmalloc (sizeof (struct expression) |
3219 | + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen)(((*expp)->nelts + 7 - oplen) * sizeof (union exp_element) )); |
3220 | struct expression *exp = *expp; |
3221 | |
3222 | newexp->nelts = exp->nelts + 7 - oplen; |
3223 | newexp->language_defn = exp->language_defn; |
3224 | memcpy (newexp->elts, exp->elts, EXP_ELEM_TO_BYTES (pc)((pc) * sizeof (union exp_element))); |
3225 | memcpy (newexp->elts + pc + 7, exp->elts + pc + oplen, |
3226 | EXP_ELEM_TO_BYTES (exp->nelts - pc - oplen)((exp->nelts - pc - oplen) * sizeof (union exp_element))); |
3227 | |
3228 | newexp->elts[pc].opcode = newexp->elts[pc + 2].opcode = OP_FUNCALL; |
3229 | newexp->elts[pc + 1].longconst = (LONGESTlong) nargs; |
3230 | |
3231 | newexp->elts[pc + 3].opcode = newexp->elts[pc + 6].opcode = OP_VAR_VALUE; |
3232 | newexp->elts[pc + 4].block = block; |
3233 | newexp->elts[pc + 5].symbol = sym; |
3234 | |
3235 | *expp = newexp; |
3236 | xfree (exp); |
3237 | } |
3238 | |
3239 | /* Type-class predicates */ |
3240 | |
3241 | /* True iff TYPE is numeric (i.e., an INT, RANGE (of numeric type), |
3242 | or FLOAT). */ |
3243 | |
3244 | static int |
3245 | numeric_type_p (struct type *type) |
3246 | { |
3247 | if (type == NULL((void*)0)) |
3248 | return 0; |
3249 | else |
3250 | { |
3251 | switch (TYPE_CODE (type)(type)->main_type->code) |
3252 | { |
3253 | case TYPE_CODE_INT: |
3254 | case TYPE_CODE_FLT: |
3255 | return 1; |
3256 | case TYPE_CODE_RANGE: |
3257 | return (type == TYPE_TARGET_TYPE (type)(type)->main_type->target_type |
3258 | || numeric_type_p (TYPE_TARGET_TYPE (type)(type)->main_type->target_type)); |
3259 | default: |
3260 | return 0; |
3261 | } |
3262 | } |
3263 | } |
3264 | |
3265 | /* True iff TYPE is integral (an INT or RANGE of INTs). */ |
3266 | |
3267 | static int |
3268 | integer_type_p (struct type *type) |
3269 | { |
3270 | if (type == NULL((void*)0)) |
3271 | return 0; |
3272 | else |
3273 | { |
3274 | switch (TYPE_CODE (type)(type)->main_type->code) |
3275 | { |
3276 | case TYPE_CODE_INT: |
3277 | return 1; |
3278 | case TYPE_CODE_RANGE: |
3279 | return (type == TYPE_TARGET_TYPE (type)(type)->main_type->target_type |
3280 | || integer_type_p (TYPE_TARGET_TYPE (type)(type)->main_type->target_type)); |
3281 | default: |
3282 | return 0; |
3283 | } |
3284 | } |
3285 | } |
3286 | |
3287 | /* True iff TYPE is scalar (INT, RANGE, FLOAT, ENUM). */ |
3288 | |
3289 | static int |
3290 | scalar_type_p (struct type *type) |
3291 | { |
3292 | if (type == NULL((void*)0)) |
3293 | return 0; |
3294 | else |
3295 | { |
3296 | switch (TYPE_CODE (type)(type)->main_type->code) |
3297 | { |
3298 | case TYPE_CODE_INT: |
3299 | case TYPE_CODE_RANGE: |
3300 | case TYPE_CODE_ENUM: |
3301 | case TYPE_CODE_FLT: |
3302 | return 1; |
3303 | default: |
3304 | return 0; |
3305 | } |
3306 | } |
3307 | } |
3308 | |
3309 | /* True iff TYPE is discrete (INT, RANGE, ENUM). */ |
3310 | |
3311 | static int |
3312 | discrete_type_p (struct type *type) |
3313 | { |
3314 | if (type == NULL((void*)0)) |
3315 | return 0; |
3316 | else |
3317 | { |
3318 | switch (TYPE_CODE (type)(type)->main_type->code) |
3319 | { |
3320 | case TYPE_CODE_INT: |
3321 | case TYPE_CODE_RANGE: |
3322 | case TYPE_CODE_ENUM: |
3323 | return 1; |
3324 | default: |
3325 | return 0; |
3326 | } |
3327 | } |
3328 | } |
3329 | |
3330 | /* Returns non-zero if OP with operands in the vector ARGS could be |
3331 | a user-defined function. Errs on the side of pre-defined operators |
3332 | (i.e., result 0). */ |
3333 | |
3334 | static int |
3335 | possible_user_operator_p (enum exp_opcode op, struct value *args[]) |
3336 | { |
3337 | struct type *type0 = |
3338 | (args[0] == NULL((void*)0)) ? NULL((void*)0) : ada_check_typedef (VALUE_TYPE (args[0])(args[0])->type); |
3339 | struct type *type1 = |
3340 | (args[1] == NULL((void*)0)) ? NULL((void*)0) : ada_check_typedef (VALUE_TYPE (args[1])(args[1])->type); |
3341 | |
3342 | if (type0 == NULL((void*)0)) |
3343 | return 0; |
3344 | |
3345 | switch (op) |
3346 | { |
3347 | default: |
3348 | return 0; |
3349 | |
3350 | case BINOP_ADD: |
3351 | case BINOP_SUB: |
3352 | case BINOP_MUL: |
3353 | case BINOP_DIV: |
3354 | return (!(numeric_type_p (type0) && numeric_type_p (type1))); |
3355 | |
3356 | case BINOP_REM: |
3357 | case BINOP_MOD: |
3358 | case BINOP_BITWISE_AND: |
3359 | case BINOP_BITWISE_IOR: |
3360 | case BINOP_BITWISE_XOR: |
3361 | return (!(integer_type_p (type0) && integer_type_p (type1))); |
3362 | |
3363 | case BINOP_EQUAL: |
3364 | case BINOP_NOTEQUAL: |
3365 | case BINOP_LESS: |
3366 | case BINOP_GTR: |
3367 | case BINOP_LEQ: |
3368 | case BINOP_GEQ: |
3369 | return (!(scalar_type_p (type0) && scalar_type_p (type1))); |
3370 | |
3371 | case BINOP_CONCAT: |
3372 | return |
3373 | ((TYPE_CODE (type0)(type0)->main_type->code != TYPE_CODE_ARRAY |
3374 | && (TYPE_CODE (type0)(type0)->main_type->code != TYPE_CODE_PTR |
3375 | || TYPE_CODE (TYPE_TARGET_TYPE (type0))((type0)->main_type->target_type)->main_type->code != TYPE_CODE_ARRAY)) |
3376 | || (TYPE_CODE (type1)(type1)->main_type->code != TYPE_CODE_ARRAY |
3377 | && (TYPE_CODE (type1)(type1)->main_type->code != TYPE_CODE_PTR |
3378 | || (TYPE_CODE (TYPE_TARGET_TYPE (type1))((type1)->main_type->target_type)->main_type->code |
3379 | != TYPE_CODE_ARRAY)))); |
3380 | |
3381 | case BINOP_EXP: |
3382 | return (!(numeric_type_p (type0) && integer_type_p (type1))); |
3383 | |
3384 | case UNOP_NEG: |
3385 | case UNOP_PLUS: |
3386 | case UNOP_LOGICAL_NOT: |
3387 | case UNOP_ABS: |
3388 | return (!numeric_type_p (type0)); |
3389 | |
3390 | } |
3391 | } |
3392 | |
3393 | /* Renaming */ |
3394 | |
3395 | /* NOTE: In the following, we assume that a renaming type's name may |
3396 | have an ___XD suffix. It would be nice if this went away at some |
3397 | point. */ |
3398 | |
3399 | /* If TYPE encodes a renaming, returns the renaming suffix, which |
3400 | is XR for an object renaming, XRP for a procedure renaming, XRE for |
3401 | an exception renaming, and XRS for a subprogram renaming. Returns |
3402 | NULL if NAME encodes none of these. */ |
3403 | |
3404 | const char * |
3405 | ada_renaming_type (struct type *type) |
3406 | { |
3407 | if (type != NULL((void*)0) && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ENUM) |
3408 | { |
3409 | const char *name = type_name_no_tag (type); |
3410 | const char *suffix = (name == NULL((void*)0)) ? NULL((void*)0) : strstr (name, "___XR"); |
3411 | if (suffix == NULL((void*)0) |
3412 | || (suffix[5] != '\000' && strchr ("PES_", suffix[5]) == NULL((void*)0))) |
3413 | return NULL((void*)0); |
3414 | else |
3415 | return suffix + 3; |
3416 | } |
3417 | else |
3418 | return NULL((void*)0); |
3419 | } |
3420 | |
3421 | /* Return non-zero iff SYM encodes an object renaming. */ |
3422 | |
3423 | int |
3424 | ada_is_object_renaming (struct symbol *sym) |
3425 | { |
3426 | const char *renaming_type = ada_renaming_type (SYMBOL_TYPE (sym)(sym)->type); |
3427 | return renaming_type != NULL((void*)0) |
3428 | && (renaming_type[2] == '\0' || renaming_type[2] == '_'); |
3429 | } |
3430 | |
3431 | /* Assuming that SYM encodes a non-object renaming, returns the original |
3432 | name of the renamed entity. The name is good until the end of |
3433 | parsing. */ |
3434 | |
3435 | char * |
3436 | ada_simple_renamed_entity (struct symbol *sym) |
3437 | { |
3438 | struct type *type; |
3439 | const char *raw_name; |
3440 | int len; |
3441 | char *result; |
3442 | |
3443 | type = SYMBOL_TYPE (sym)(sym)->type; |
3444 | if (type == NULL((void*)0) || TYPE_NFIELDS (type)(type)->main_type->nfields < 1) |
3445 | error ("Improperly encoded renaming."); |
3446 | |
3447 | raw_name = TYPE_FIELD_NAME (type, 0)(((type)->main_type->fields[0]).name); |
3448 | len = (raw_name == NULL((void*)0) ? 0 : strlen (raw_name)) - 5; |
3449 | if (len <= 0) |
3450 | error ("Improperly encoded renaming."); |
3451 | |
3452 | result = xmalloc (len + 1); |
3453 | strncpy (result, raw_name, len); |
3454 | result[len] = '\000'; |
3455 | return result; |
3456 | } |
3457 | |
3458 | |
3459 | /* Evaluation: Function Calls */ |
3460 | |
3461 | /* Return an lvalue containing the value VAL. This is the identity on |
3462 | lvalues, and otherwise has the side-effect of pushing a copy of VAL |
3463 | on the stack, using and updating *SP as the stack pointer, and |
3464 | returning an lvalue whose VALUE_ADDRESS points to the copy. */ |
3465 | |
3466 | static struct value * |
3467 | ensure_lval (struct value *val, CORE_ADDR *sp) |
3468 | { |
3469 | if (! VALUE_LVAL (val)(val)->lval) |
3470 | { |
3471 | int len = TYPE_LENGTH (ada_check_typedef (VALUE_TYPE (val)))(ada_check_typedef ((val)->type))->length; |
3472 | |
3473 | /* The following is taken from the structure-return code in |
3474 | call_function_by_hand. FIXME: Therefore, some refactoring seems |
3475 | indicated. */ |
3476 | if (INNER_THAN (1, 2)(gdbarch_inner_than (current_gdbarch, 1, 2))) |
3477 | { |
3478 | /* Stack grows downward. Align SP and VALUE_ADDRESS (val) after |
3479 | reserving sufficient space. */ |
3480 | *sp -= len; |
3481 | if (gdbarch_frame_align_p (current_gdbarch)) |
3482 | *sp = gdbarch_frame_align (current_gdbarch, *sp); |
3483 | VALUE_ADDRESS (val)(val)->location.address = *sp; |
3484 | } |
3485 | else |
3486 | { |
3487 | /* Stack grows upward. Align the frame, allocate space, and |
3488 | then again, re-align the frame. */ |
3489 | if (gdbarch_frame_align_p (current_gdbarch)) |
3490 | *sp = gdbarch_frame_align (current_gdbarch, *sp); |
3491 | VALUE_ADDRESS (val)(val)->location.address = *sp; |
3492 | *sp += len; |
3493 | if (gdbarch_frame_align_p (current_gdbarch)) |
3494 | *sp = gdbarch_frame_align (current_gdbarch, *sp); |
3495 | } |
3496 | |
3497 | write_memory (VALUE_ADDRESS (val)(val)->location.address, VALUE_CONTENTS_RAW (val)((char *) (val)->aligner.contents + (val)->embedded_offset ), len); |
3498 | } |
3499 | |
3500 | return val; |
3501 | } |
3502 | |
3503 | /* Return the value ACTUAL, converted to be an appropriate value for a |
3504 | formal of type FORMAL_TYPE. Use *SP as a stack pointer for |
3505 | allocating any necessary descriptors (fat pointers), or copies of |
3506 | values not residing in memory, updating it as needed. */ |
3507 | |
3508 | static struct value * |
3509 | convert_actual (struct value *actual, struct type *formal_type0, |
3510 | CORE_ADDR *sp) |
3511 | { |
3512 | struct type *actual_type = ada_check_typedef (VALUE_TYPE (actual)(actual)->type); |
3513 | struct type *formal_type = ada_check_typedef (formal_type0); |
3514 | struct type *formal_target = |
3515 | TYPE_CODE (formal_type)(formal_type)->main_type->code == TYPE_CODE_PTR |
3516 | ? ada_check_typedef (TYPE_TARGET_TYPE (formal_type)(formal_type)->main_type->target_type) : formal_type; |
3517 | struct type *actual_target = |
3518 | TYPE_CODE (actual_type)(actual_type)->main_type->code == TYPE_CODE_PTR |
3519 | ? ada_check_typedef (TYPE_TARGET_TYPE (actual_type)(actual_type)->main_type->target_type) : actual_type; |
3520 | |
3521 | if (ada_is_array_descriptor_type (formal_target) |
3522 | && TYPE_CODE (actual_target)(actual_target)->main_type->code == TYPE_CODE_ARRAY) |
3523 | return make_array_descriptor (formal_type, actual, sp); |
3524 | else if (TYPE_CODE (formal_type)(formal_type)->main_type->code == TYPE_CODE_PTR) |
3525 | { |
3526 | if (TYPE_CODE (formal_target)(formal_target)->main_type->code == TYPE_CODE_ARRAY |
3527 | && ada_is_array_descriptor_type (actual_target)) |
3528 | return desc_data (actual); |
3529 | else if (TYPE_CODE (actual_type)(actual_type)->main_type->code != TYPE_CODE_PTR) |
3530 | { |
3531 | if (VALUE_LVAL (actual)(actual)->lval != lval_memory) |
3532 | { |
3533 | struct value *val; |
3534 | actual_type = ada_check_typedef (VALUE_TYPE (actual)(actual)->type); |
3535 | val = allocate_value (actual_type); |
3536 | memcpy ((char *) VALUE_CONTENTS_RAW (val)((char *) (val)->aligner.contents + (val)->embedded_offset ), |
3537 | (char *) VALUE_CONTENTS (actual)((void)((actual)->lazy && value_fetch_lazy(actual) ), ((char *) (actual)->aligner.contents + (actual)->embedded_offset )), |
3538 | TYPE_LENGTH (actual_type)(actual_type)->length); |
3539 | actual = ensure_lval (val, sp); |
3540 | } |
3541 | return value_addr (actual); |
3542 | } |
3543 | } |
3544 | else if (TYPE_CODE (actual_type)(actual_type)->main_type->code == TYPE_CODE_PTR) |
3545 | return ada_value_ind (actual); |
3546 | |
3547 | return actual; |
3548 | } |
3549 | |
3550 | |
3551 | /* Push a descriptor of type TYPE for array value ARR on the stack at |
3552 | *SP, updating *SP to reflect the new descriptor. Return either |
3553 | an lvalue representing the new descriptor, or (if TYPE is a pointer- |
3554 | to-descriptor type rather than a descriptor type), a struct value * |
3555 | representing a pointer to this descriptor. */ |
3556 | |
3557 | static struct value * |
3558 | make_array_descriptor (struct type *type, struct value *arr, CORE_ADDR *sp) |
3559 | { |
3560 | struct type *bounds_type = desc_bounds_type (type); |
3561 | struct type *desc_type = desc_base_type (type); |
3562 | struct value *descriptor = allocate_value (desc_type); |
3563 | struct value *bounds = allocate_value (bounds_type); |
3564 | int i; |
3565 | |
3566 | for (i = ada_array_arity (ada_check_typedef (VALUE_TYPE (arr)(arr)->type)); i > 0; i -= 1) |
3567 | { |
3568 | modify_general_field (VALUE_CONTENTS (bounds)((void)((bounds)->lazy && value_fetch_lazy(bounds) ), ((char *) (bounds)->aligner.contents + (bounds)->embedded_offset )), |
3569 | value_as_long (ada_array_bound (arr, i, 0)), |
3570 | desc_bound_bitpos (bounds_type, i, 0), |
3571 | desc_bound_bitsize (bounds_type, i, 0)); |
3572 | modify_general_field (VALUE_CONTENTS (bounds)((void)((bounds)->lazy && value_fetch_lazy(bounds) ), ((char *) (bounds)->aligner.contents + (bounds)->embedded_offset )), |
3573 | value_as_long (ada_array_bound (arr, i, 1)), |
3574 | desc_bound_bitpos (bounds_type, i, 1), |
3575 | desc_bound_bitsize (bounds_type, i, 1)); |
3576 | } |
3577 | |
3578 | bounds = ensure_lval (bounds, sp); |
3579 | |
3580 | modify_general_field (VALUE_CONTENTS (descriptor)((void)((descriptor)->lazy && value_fetch_lazy(descriptor )), ((char *) (descriptor)->aligner.contents + (descriptor )->embedded_offset)), |
3581 | VALUE_ADDRESS (ensure_lval (arr, sp))(ensure_lval (arr, sp))->location.address, |
3582 | fat_pntr_data_bitpos (desc_type), |
3583 | fat_pntr_data_bitsize (desc_type)); |
3584 | |
3585 | modify_general_field (VALUE_CONTENTS (descriptor)((void)((descriptor)->lazy && value_fetch_lazy(descriptor )), ((char *) (descriptor)->aligner.contents + (descriptor )->embedded_offset)), |
3586 | VALUE_ADDRESS (bounds)(bounds)->location.address, |
3587 | fat_pntr_bounds_bitpos (desc_type), |
3588 | fat_pntr_bounds_bitsize (desc_type)); |
3589 | |
3590 | descriptor = ensure_lval (descriptor, sp); |
3591 | |
3592 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR) |
3593 | return value_addr (descriptor); |
3594 | else |
3595 | return descriptor; |
3596 | } |
3597 | |
3598 | |
3599 | /* Assuming a dummy frame has been established on the target, perform any |
3600 | conversions needed for calling function FUNC on the NARGS actual |
3601 | parameters in ARGS, other than standard C conversions. Does |
3602 | nothing if FUNC does not have Ada-style prototype data, or if NARGS |
3603 | does not match the number of arguments expected. Use *SP as a |
3604 | stack pointer for additional data that must be pushed, updating its |
3605 | value as needed. */ |
3606 | |
3607 | void |
3608 | ada_convert_actuals (struct value *func, int nargs, struct value *args[], |
3609 | CORE_ADDR *sp) |
3610 | { |
3611 | int i; |
3612 | |
3613 | if (TYPE_NFIELDS (VALUE_TYPE (func))((func)->type)->main_type->nfields == 0 |
3614 | || nargs != TYPE_NFIELDS (VALUE_TYPE (func))((func)->type)->main_type->nfields) |
3615 | return; |
3616 | |
3617 | for (i = 0; i < nargs; i += 1) |
3618 | args[i] = |
3619 | convert_actual (args[i], TYPE_FIELD_TYPE (VALUE_TYPE (func), i)((((func)->type)->main_type->fields[i]).type), sp); |
3620 | } |
3621 | |
3622 | /* Dummy definitions for an experimental caching module that is not |
3623 | * used in the public sources. */ |
3624 | |
3625 | static int |
3626 | lookup_cached_symbol (const char *name, domain_enum namespace, |
3627 | struct symbol **sym, struct block **block, |
3628 | struct symtab **symtab) |
3629 | { |
3630 | return 0; |
3631 | } |
3632 | |
3633 | static void |
3634 | cache_symbol (const char *name, domain_enum namespace, struct symbol *sym, |
3635 | struct block *block, struct symtab *symtab) |
3636 | { |
3637 | } |
3638 | |
3639 | /* Symbol Lookup */ |
3640 | |
3641 | /* Return the result of a standard (literal, C-like) lookup of NAME in |
3642 | given DOMAIN, visible from lexical block BLOCK. */ |
3643 | |
3644 | static struct symbol * |
3645 | standard_lookup (const char *name, const struct block *block, |
3646 | domain_enum domain) |
3647 | { |
3648 | struct symbol *sym; |
3649 | struct symtab *symtab; |
3650 | |
3651 | if (lookup_cached_symbol (name, domain, &sym, NULL((void*)0), NULL((void*)0))) |
3652 | return sym; |
3653 | sym = |
3654 | lookup_symbol_in_language (name, block, domain, language_c, 0, &symtab); |
3655 | cache_symbol (name, domain, sym, block_found, symtab); |
3656 | return sym; |
3657 | } |
3658 | |
3659 | |
3660 | /* Non-zero iff there is at least one non-function/non-enumeral symbol |
3661 | in the symbol fields of SYMS[0..N-1]. We treat enumerals as functions, |
3662 | since they contend in overloading in the same way. */ |
3663 | static int |
3664 | is_nonfunction (struct ada_symbol_info syms[], int n) |
3665 | { |
3666 | int i; |
3667 | |
3668 | for (i = 0; i < n; i += 1) |
3669 | if (TYPE_CODE (SYMBOL_TYPE (syms[i].sym))((syms[i].sym)->type)->main_type->code != TYPE_CODE_FUNC |
3670 | && (TYPE_CODE (SYMBOL_TYPE (syms[i].sym))((syms[i].sym)->type)->main_type->code != TYPE_CODE_ENUM |
3671 | || SYMBOL_CLASS (syms[i].sym)(syms[i].sym)->aclass != LOC_CONST)) |
3672 | return 1; |
3673 | |
3674 | return 0; |
3675 | } |
3676 | |
3677 | /* If true (non-zero), then TYPE0 and TYPE1 represent equivalent |
3678 | struct types. Otherwise, they may not. */ |
3679 | |
3680 | static int |
3681 | equiv_types (struct type *type0, struct type *type1) |
3682 | { |
3683 | if (type0 == type1) |
3684 | return 1; |
3685 | if (type0 == NULL((void*)0) || type1 == NULL((void*)0) |
3686 | || TYPE_CODE (type0)(type0)->main_type->code != TYPE_CODE (type1)(type1)->main_type->code) |
3687 | return 0; |
3688 | if ((TYPE_CODE (type0)(type0)->main_type->code == TYPE_CODE_STRUCT |
3689 | || TYPE_CODE (type0)(type0)->main_type->code == TYPE_CODE_ENUM) |
3690 | && ada_type_name (type0) != NULL((void*)0) && ada_type_name (type1) != NULL((void*)0) |
3691 | && strcmp (ada_type_name (type0), ada_type_name (type1)) == 0) |
3692 | return 1; |
3693 | |
3694 | return 0; |
3695 | } |
3696 | |
3697 | /* True iff SYM0 represents the same entity as SYM1, or one that is |
3698 | no more defined than that of SYM1. */ |
3699 | |
3700 | static int |
3701 | lesseq_defined_than (struct symbol *sym0, struct symbol *sym1) |
3702 | { |
3703 | if (sym0 == sym1) |
3704 | return 1; |
3705 | if (SYMBOL_DOMAIN (sym0)(sym0)->domain != SYMBOL_DOMAIN (sym1)(sym1)->domain |
3706 | || SYMBOL_CLASS (sym0)(sym0)->aclass != SYMBOL_CLASS (sym1)(sym1)->aclass) |
3707 | return 0; |
3708 | |
3709 | switch (SYMBOL_CLASS (sym0)(sym0)->aclass) |
3710 | { |
3711 | case LOC_UNDEF: |
3712 | return 1; |
3713 | case LOC_TYPEDEF: |
3714 | { |
3715 | struct type *type0 = SYMBOL_TYPE (sym0)(sym0)->type; |
3716 | struct type *type1 = SYMBOL_TYPE (sym1)(sym1)->type; |
3717 | char *name0 = SYMBOL_LINKAGE_NAME (sym0)(sym0)->ginfo.name; |
3718 | char *name1 = SYMBOL_LINKAGE_NAME (sym1)(sym1)->ginfo.name; |
3719 | int len0 = strlen (name0); |
3720 | return |
3721 | TYPE_CODE (type0)(type0)->main_type->code == TYPE_CODE (type1)(type1)->main_type->code |
3722 | && (equiv_types (type0, type1) |
3723 | || (len0 < strlen (name1) && strncmp (name0, name1, len0) == 0 |
3724 | && strncmp (name1 + len0, "___XV", 5) == 0)); |
3725 | } |
3726 | case LOC_CONST: |
3727 | return SYMBOL_VALUE (sym0)(sym0)->ginfo.value.ivalue == SYMBOL_VALUE (sym1)(sym1)->ginfo.value.ivalue |
3728 | && equiv_types (SYMBOL_TYPE (sym0)(sym0)->type, SYMBOL_TYPE (sym1)(sym1)->type); |
3729 | default: |
3730 | return 0; |
3731 | } |
3732 | } |
3733 | |
3734 | /* Append (SYM,BLOCK,SYMTAB) to the end of the array of struct ada_symbol_info |
3735 | records in OBSTACKP. Do nothing if SYM is a duplicate. */ |
3736 | |
3737 | static void |
3738 | add_defn_to_vec (struct obstack *obstackp, |
3739 | struct symbol *sym, |
3740 | struct block *block, struct symtab *symtab) |
3741 | { |
3742 | int i; |
3743 | size_t tmp; |
3744 | struct ada_symbol_info *prevDefns = defns_collected (obstackp, 0); |
3745 | |
3746 | if (SYMBOL_TYPE (sym)(sym)->type != NULL((void*)0)) |
3747 | SYMBOL_TYPE (sym)(sym)->type = ada_check_typedef (SYMBOL_TYPE (sym)(sym)->type); |
3748 | for (i = num_defns_collected (obstackp) - 1; i >= 0; i -= 1) |
3749 | { |
3750 | if (lesseq_defined_than (sym, prevDefns[i].sym)) |
3751 | return; |
3752 | else if (lesseq_defined_than (prevDefns[i].sym, sym)) |
3753 | { |
3754 | prevDefns[i].sym = sym; |
3755 | prevDefns[i].block = block; |
3756 | prevDefns[i].symtab = symtab; |
3757 | return; |
3758 | } |
3759 | } |
3760 | |
3761 | { |
3762 | struct ada_symbol_info info; |
3763 | |
3764 | info.sym = sym; |
3765 | info.block = block; |
3766 | info.symtab = symtab; |
3767 | obstack_grow (obstackp, &info, sizeof (struct ada_symbol_info))__extension__ ({ struct obstack *__o = (obstackp); int __len = (sizeof (struct ada_symbol_info)); if (__o->next_free + __len > __o->chunk_limit) _obstack_newchunk (__o, __len); memcpy ((__o->next_free), ((&info)), (__len)); __o->next_free += __len; (void) 0; }); |
3768 | } |
3769 | } |
3770 | |
3771 | /* Number of ada_symbol_info structures currently collected in |
3772 | current vector in *OBSTACKP. */ |
3773 | |
3774 | static int |
3775 | num_defns_collected (struct obstack *obstackp) |
3776 | { |
3777 | return obstack_object_size (obstackp)__extension__ ({ struct obstack *__o = (obstackp); (unsigned) (__o->next_free - __o->object_base); }) / sizeof (struct ada_symbol_info); |
3778 | } |
3779 | |
3780 | /* Vector of ada_symbol_info structures currently collected in current |
3781 | vector in *OBSTACKP. If FINISH, close off the vector and return |
3782 | its final address. */ |
3783 | |
3784 | static struct ada_symbol_info * |
3785 | defns_collected (struct obstack *obstackp, int finish) |
3786 | { |
3787 | if (finish) |
3788 | return obstack_finish (obstackp)__extension__ ({ struct obstack *__o1 = (obstackp); void *value ; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); |
3789 | else |
3790 | return (struct ada_symbol_info *) obstack_base (obstackp)((obstackp)->object_base); |
3791 | } |
3792 | |
3793 | /* Look, in partial_symtab PST, for symbol NAME in given namespace. |
3794 | Check the global symbols if GLOBAL, the static symbols if not. |
3795 | Do wild-card match if WILD. */ |
3796 | |
3797 | static struct partial_symbol * |
3798 | ada_lookup_partial_symbol (struct partial_symtab *pst, const char *name, |
3799 | int global, domain_enum namespace, int wild) |
3800 | { |
3801 | struct partial_symbol **start; |
3802 | int name_len = strlen (name); |
3803 | int length = (global ? pst->n_global_syms : pst->n_static_syms); |
3804 | int i; |
3805 | |
3806 | if (length == 0) |
3807 | { |
3808 | return (NULL((void*)0)); |
3809 | } |
3810 | |
3811 | start = (global ? |
3812 | pst->objfile->global_psymbols.list + pst->globals_offset : |
3813 | pst->objfile->static_psymbols.list + pst->statics_offset); |
3814 | |
3815 | if (wild) |
3816 | { |
3817 | for (i = 0; i < length; i += 1) |
3818 | { |
3819 | struct partial_symbol *psym = start[i]; |
3820 | |
3821 | if (SYMBOL_DOMAIN (psym)(psym)->domain == namespace |
3822 | && wild_match (name, name_len, SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name)) |
3823 | return psym; |
3824 | } |
3825 | return NULL((void*)0); |
3826 | } |
3827 | else |
3828 | { |
3829 | if (global) |
3830 | { |
3831 | int U; |
3832 | i = 0; |
3833 | U = length - 1; |
3834 | while (U - i > 4) |
3835 | { |
3836 | int M = (U + i) >> 1; |
3837 | struct partial_symbol *psym = start[M]; |
3838 | if (SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name[0] < name[0]) |
3839 | i = M + 1; |
3840 | else if (SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name[0] > name[0]) |
3841 | U = M - 1; |
3842 | else if (strcmp (SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name, name) < 0) |
3843 | i = M + 1; |
3844 | else |
3845 | U = M; |
3846 | } |
3847 | } |
3848 | else |
3849 | i = 0; |
3850 | |
3851 | while (i < length) |
3852 | { |
3853 | struct partial_symbol *psym = start[i]; |
3854 | |
3855 | if (SYMBOL_DOMAIN (psym)(psym)->domain == namespace) |
3856 | { |
3857 | int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name, name_len); |
3858 | |
3859 | if (cmp < 0) |
3860 | { |
3861 | if (global) |
3862 | break; |
3863 | } |
3864 | else if (cmp == 0 |
3865 | && is_name_suffix (SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name |
3866 | + name_len)) |
3867 | return psym; |
3868 | } |
3869 | i += 1; |
3870 | } |
3871 | |
3872 | if (global) |
3873 | { |
3874 | int U; |
3875 | i = 0; |
3876 | U = length - 1; |
3877 | while (U - i > 4) |
3878 | { |
3879 | int M = (U + i) >> 1; |
3880 | struct partial_symbol *psym = start[M]; |
3881 | if (SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name[0] < '_') |
3882 | i = M + 1; |
3883 | else if (SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name[0] > '_') |
3884 | U = M - 1; |
3885 | else if (strcmp (SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name, "_ada_") < 0) |
3886 | i = M + 1; |
3887 | else |
3888 | U = M; |
3889 | } |
3890 | } |
3891 | else |
3892 | i = 0; |
3893 | |
3894 | while (i < length) |
3895 | { |
3896 | struct partial_symbol *psym = start[i]; |
3897 | |
3898 | if (SYMBOL_DOMAIN (psym)(psym)->domain == namespace) |
3899 | { |
3900 | int cmp; |
3901 | |
3902 | cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name[0]; |
3903 | if (cmp == 0) |
3904 | { |
3905 | cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name, 5); |
3906 | if (cmp == 0) |
3907 | cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name + 5, |
3908 | name_len); |
3909 | } |
3910 | |
3911 | if (cmp < 0) |
3912 | { |
3913 | if (global) |
3914 | break; |
3915 | } |
3916 | else if (cmp == 0 |
3917 | && is_name_suffix (SYMBOL_LINKAGE_NAME (psym)(psym)->ginfo.name |
3918 | + name_len + 5)) |
3919 | return psym; |
3920 | } |
3921 | i += 1; |
3922 | } |
3923 | } |
3924 | return NULL((void*)0); |
3925 | } |
3926 | |
3927 | /* Find a symbol table containing symbol SYM or NULL if none. */ |
3928 | |
3929 | static struct symtab * |
3930 | symtab_for_sym (struct symbol *sym) |
3931 | { |
3932 | struct symtab *s; |
3933 | struct objfile *objfile; |
3934 | struct block *b; |
3935 | struct symbol *tmp_sym; |
3936 | struct dict_iterator iter; |
3937 | int j; |
3938 | |
3939 | ALL_SYMTABS (objfile, s)for ((objfile) = object_files; (objfile) != ((void*)0); (objfile ) = (objfile)->next) for ((s) = (objfile) -> symtabs; ( s) != ((void*)0); (s) = (s) -> next) |
3940 | { |
3941 | switch (SYMBOL_CLASS (sym)(sym)->aclass) |
3942 | { |
3943 | case LOC_CONST: |
3944 | case LOC_STATIC: |
3945 | case LOC_TYPEDEF: |
3946 | case LOC_REGISTER: |
3947 | case LOC_LABEL: |
3948 | case LOC_BLOCK: |
3949 | case LOC_CONST_BYTES: |
3950 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK)((s)->blockvector)->block[GLOBAL_BLOCK]; |
3951 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym)for ((tmp_sym) = dict_iterator_first (((b)->dict), &(iter )); (tmp_sym); (tmp_sym) = dict_iterator_next (&(iter))) if (sym == tmp_sym) |
3952 | return s; |
3953 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)((s)->blockvector)->block[STATIC_BLOCK]; |
3954 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym)for ((tmp_sym) = dict_iterator_first (((b)->dict), &(iter )); (tmp_sym); (tmp_sym) = dict_iterator_next (&(iter))) if (sym == tmp_sym) |
3955 | return s; |
3956 | break; |
3957 | default: |
3958 | break; |
3959 | } |
3960 | switch (SYMBOL_CLASS (sym)(sym)->aclass) |
3961 | { |
3962 | case LOC_REGISTER: |
3963 | case LOC_ARG: |
3964 | case LOC_REF_ARG: |
3965 | case LOC_REGPARM: |
3966 | case LOC_REGPARM_ADDR: |
3967 | case LOC_LOCAL: |
3968 | case LOC_TYPEDEF: |
3969 | case LOC_LOCAL_ARG: |
3970 | case LOC_BASEREG: |
3971 | case LOC_BASEREG_ARG: |
3972 | case LOC_COMPUTED: |
3973 | case LOC_COMPUTED_ARG: |
3974 | for (j = FIRST_LOCAL_BLOCK; |
3975 | j < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s))((s)->blockvector)->nblocks; j += 1) |
3976 | { |
3977 | b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), j)((s)->blockvector)->block[j]; |
3978 | ALL_BLOCK_SYMBOLS (b, iter, tmp_sym)for ((tmp_sym) = dict_iterator_first (((b)->dict), &(iter )); (tmp_sym); (tmp_sym) = dict_iterator_next (&(iter))) if (sym == tmp_sym) |
3979 | return s; |
3980 | } |
3981 | break; |
3982 | default: |
3983 | break; |
3984 | } |
3985 | } |
3986 | return NULL((void*)0); |
3987 | } |
3988 | |
3989 | /* Return a minimal symbol matching NAME according to Ada decoding |
3990 | rules. Returns NULL if there is no such minimal symbol. Names |
3991 | prefixed with "standard__" are handled specially: "standard__" is |
3992 | first stripped off, and only static and global symbols are searched. */ |
3993 | |
3994 | struct minimal_symbol * |
3995 | ada_lookup_simple_minsym (const char *name) |
3996 | { |
3997 | struct objfile *objfile; |
3998 | struct minimal_symbol *msymbol; |
3999 | int wild_match; |
4000 | |
4001 | if (strncmp (name, "standard__", sizeof ("standard__") - 1) == 0) |
4002 | { |
4003 | name += sizeof ("standard__") - 1; |
4004 | wild_match = 0; |
4005 | } |
4006 | else |
4007 | wild_match = (strstr (name, "__") == NULL((void*)0)); |
4008 | |
4009 | ALL_MSYMBOLS (objfile, msymbol)for ((objfile) = object_files; (objfile) != ((void*)0); (objfile ) = (objfile)->next) for ((msymbol) = (objfile) -> msymbols ; (msymbol)->ginfo.name != ((void*)0); (msymbol)++) |
4010 | { |
4011 | if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol)(msymbol)->ginfo.name, name, wild_match) |
4012 | && MSYMBOL_TYPE (msymbol)(msymbol)->type != mst_solib_trampoline) |
4013 | return msymbol; |
4014 | } |
4015 | |
4016 | return NULL((void*)0); |
4017 | } |
4018 | |
4019 | /* For all subprograms that statically enclose the subprogram of the |
4020 | selected frame, add symbols matching identifier NAME in DOMAIN |
4021 | and their blocks to the list of data in OBSTACKP, as for |
4022 | ada_add_block_symbols (q.v.). If WILD, treat as NAME with a |
4023 | wildcard prefix. */ |
4024 | |
4025 | static void |
4026 | add_symbols_from_enclosing_procs (struct obstack *obstackp, |
4027 | const char *name, domain_enum namespace, |
4028 | int wild_match) |
4029 | { |
4030 | } |
4031 | |
4032 | /* FIXME: The next two routines belong in symtab.c */ |
4033 | |
4034 | static void |
4035 | restore_language (void *lang) |
4036 | { |
4037 | set_language ((enum language) lang); |
4038 | } |
4039 | |
4040 | /* As for lookup_symbol, but performed as if the current language |
4041 | were LANG. */ |
4042 | |
4043 | struct symbol * |
4044 | lookup_symbol_in_language (const char *name, const struct block *block, |
4045 | domain_enum domain, enum language lang, |
4046 | int *is_a_field_of_this, struct symtab **symtab) |
4047 | { |
4048 | struct cleanup *old_chain |
4049 | = make_cleanup (restore_language, (void *) current_language->la_language); |
4050 | struct symbol *result; |
4051 | set_language (lang); |
4052 | result = lookup_symbol (name, block, domain, is_a_field_of_this, symtab); |
4053 | do_cleanups (old_chain); |
4054 | return result; |
4055 | } |
4056 | |
4057 | /* True if TYPE is definitely an artificial type supplied to a symbol |
4058 | for which no debugging information was given in the symbol file. */ |
4059 | |
4060 | static int |
4061 | is_nondebugging_type (struct type *type) |
4062 | { |
4063 | char *name = ada_type_name (type); |
4064 | return (name != NULL((void*)0) && strcmp (name, "<variable, no debug info>") == 0); |
4065 | } |
4066 | |
4067 | /* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely |
4068 | duplicate other symbols in the list (The only case I know of where |
4069 | this happens is when object files containing stabs-in-ecoff are |
4070 | linked with files containing ordinary ecoff debugging symbols (or no |
4071 | debugging symbols)). Modifies SYMS to squeeze out deleted entries. |
4072 | Returns the number of items in the modified list. */ |
4073 | |
4074 | static int |
4075 | remove_extra_symbols (struct ada_symbol_info *syms, int nsyms) |
4076 | { |
4077 | int i, j; |
4078 | |
4079 | i = 0; |
4080 | while (i < nsyms) |
4081 | { |
4082 | if (SYMBOL_LINKAGE_NAME (syms[i].sym)(syms[i].sym)->ginfo.name != NULL((void*)0) |
4083 | && SYMBOL_CLASS (syms[i].sym)(syms[i].sym)->aclass == LOC_STATIC |
4084 | && is_nondebugging_type (SYMBOL_TYPE (syms[i].sym)(syms[i].sym)->type)) |
4085 | { |
4086 | for (j = 0; j < nsyms; j += 1) |
4087 | { |
4088 | if (i != j |
4089 | && SYMBOL_LINKAGE_NAME (syms[j].sym)(syms[j].sym)->ginfo.name != NULL((void*)0) |
4090 | && strcmp (SYMBOL_LINKAGE_NAME (syms[i].sym)(syms[i].sym)->ginfo.name, |
4091 | SYMBOL_LINKAGE_NAME (syms[j].sym)(syms[j].sym)->ginfo.name) == 0 |
4092 | && SYMBOL_CLASS (syms[i].sym)(syms[i].sym)->aclass == SYMBOL_CLASS (syms[j].sym)(syms[j].sym)->aclass |
4093 | && SYMBOL_VALUE_ADDRESS (syms[i].sym)(syms[i].sym)->ginfo.value.address |
4094 | == SYMBOL_VALUE_ADDRESS (syms[j].sym)(syms[j].sym)->ginfo.value.address) |
4095 | { |
4096 | int k; |
4097 | for (k = i + 1; k < nsyms; k += 1) |
4098 | syms[k - 1] = syms[k]; |
4099 | nsyms -= 1; |
4100 | goto NextSymbol; |
4101 | } |
4102 | } |
4103 | } |
4104 | i += 1; |
4105 | NextSymbol: |
4106 | ; |
4107 | } |
4108 | return nsyms; |
4109 | } |
4110 | |
4111 | /* Given a type that corresponds to a renaming entity, use the type name |
4112 | to extract the scope (package name or function name, fully qualified, |
4113 | and following the GNAT encoding convention) where this renaming has been |
4114 | defined. The string returned needs to be deallocated after use. */ |
4115 | |
4116 | static char * |
4117 | xget_renaming_scope (struct type *renaming_type) |
4118 | { |
4119 | /* The renaming types adhere to the following convention: |
4120 | <scope>__<rename>___<XR extension>. |
4121 | So, to extract the scope, we search for the "___XR" extension, |
4122 | and then backtrack until we find the first "__". */ |
4123 | |
4124 | const char *name = type_name_no_tag (renaming_type); |
4125 | char *suffix = strstr (name, "___XR"); |
4126 | char *last; |
4127 | int scope_len; |
4128 | char *scope; |
4129 | |
4130 | /* Now, backtrack a bit until we find the first "__". Start looking |
4131 | at suffix - 3, as the <rename> part is at least one character long. */ |
4132 | |
4133 | for (last = suffix - 3; last > name; last--) |
4134 | if (last[0] == '_' && last[1] == '_') |
4135 | break; |
4136 | |
4137 | /* Make a copy of scope and return it. */ |
4138 | |
4139 | scope_len = last - name; |
4140 | scope = (char *) xmalloc ((scope_len + 1) * sizeof (char)); |
4141 | |
4142 | strncpy (scope, name, scope_len); |
4143 | scope[scope_len] = '\0'; |
4144 | |
4145 | return scope; |
4146 | } |
4147 | |
4148 | /* Return nonzero if NAME corresponds to a package name. */ |
4149 | |
4150 | static int |
4151 | is_package_name (const char *name) |
4152 | { |
4153 | /* Here, We take advantage of the fact that no symbols are generated |
4154 | for packages, while symbols are generated for each function. |
4155 | So the condition for NAME represent a package becomes equivalent |
4156 | to NAME not existing in our list of symbols. There is only one |
4157 | small complication with library-level functions (see below). */ |
4158 | |
4159 | char *fun_name; |
4160 | |
4161 | /* If it is a function that has not been defined at library level, |
4162 | then we should be able to look it up in the symbols. */ |
4163 | if (standard_lookup (name, NULL((void*)0), VAR_DOMAIN) != NULL((void*)0)) |
4164 | return 0; |
4165 | |
4166 | /* Library-level function names start with "_ada_". See if function |
4167 | "_ada_" followed by NAME can be found. */ |
4168 | |
4169 | /* Do a quick check that NAME does not contain "__", since library-level |
4170 | functions names can not contain "__" in them. */ |
4171 | if (strstr (name, "__") != NULL((void*)0)) |
4172 | return 0; |
4173 | |
4174 | fun_name = xstrprintf ("_ada_%s", name); |
4175 | |
4176 | return (standard_lookup (fun_name, NULL((void*)0), VAR_DOMAIN) == NULL((void*)0)); |
4177 | } |
4178 | |
4179 | /* Return nonzero if SYM corresponds to a renaming entity that is |
4180 | visible from FUNCTION_NAME. */ |
4181 | |
4182 | static int |
4183 | renaming_is_visible (const struct symbol *sym, char *function_name) |
4184 | { |
4185 | char *scope = xget_renaming_scope (SYMBOL_TYPE (sym)(sym)->type); |
4186 | |
4187 | make_cleanup (xfree, scope); |
4188 | |
4189 | /* If the rename has been defined in a package, then it is visible. */ |
4190 | if (is_package_name (scope)) |
4191 | return 1; |
4192 | |
4193 | /* Check that the rename is in the current function scope by checking |
4194 | that its name starts with SCOPE. */ |
4195 | |
4196 | /* If the function name starts with "_ada_", it means that it is |
4197 | a library-level function. Strip this prefix before doing the |
4198 | comparison, as the encoding for the renaming does not contain |
4199 | this prefix. */ |
4200 | if (strncmp (function_name, "_ada_", 5) == 0) |
4201 | function_name += 5; |
4202 | |
4203 | return (strncmp (function_name, scope, strlen (scope)) == 0); |
4204 | } |
4205 | |
4206 | /* Iterates over the SYMS list and remove any entry that corresponds to |
4207 | a renaming entity that is not visible from the function associated |
4208 | with CURRENT_BLOCK. |
4209 | |
4210 | Rationale: |
4211 | GNAT emits a type following a specified encoding for each renaming |
4212 | entity. Unfortunately, STABS currently does not support the definition |
4213 | of types that are local to a given lexical block, so all renamings types |
4214 | are emitted at library level. As a consequence, if an application |
4215 | contains two renaming entities using the same name, and a user tries to |
4216 | print the value of one of these entities, the result of the ada symbol |
4217 | lookup will also contain the wrong renaming type. |
4218 | |
4219 | This function partially covers for this limitation by attempting to |
4220 | remove from the SYMS list renaming symbols that should be visible |
4221 | from CURRENT_BLOCK. However, there does not seem be a 100% reliable |
4222 | method with the current information available. The implementation |
4223 | below has a couple of limitations (FIXME: brobecker-2003-05-12): |
4224 | |
4225 | - When the user tries to print a rename in a function while there |
4226 | is another rename entity defined in a package: Normally, the |
4227 | rename in the function has precedence over the rename in the |
4228 | package, so the latter should be removed from the list. This is |
4229 | currently not the case. |
4230 | |
4231 | - This function will incorrectly remove valid renames if |
4232 | the CURRENT_BLOCK corresponds to a function which symbol name |
4233 | has been changed by an "Export" pragma. As a consequence, |
4234 | the user will be unable to print such rename entities. */ |
4235 | |
4236 | static int |
4237 | remove_out_of_scope_renamings (struct ada_symbol_info *syms, |
4238 | int nsyms, struct block *current_block) |
4239 | { |
4240 | struct symbol *current_function; |
4241 | char *current_function_name; |
4242 | int i; |
4243 | |
4244 | /* Extract the function name associated to CURRENT_BLOCK. |
4245 | Abort if unable to do so. */ |
4246 | |
4247 | if (current_block == NULL((void*)0)) |
4248 | return nsyms; |
4249 | |
4250 | current_function = block_function (current_block); |
4251 | if (current_function == NULL((void*)0)) |
4252 | return nsyms; |
4253 | |
4254 | current_function_name = SYMBOL_LINKAGE_NAME (current_function)(current_function)->ginfo.name; |
4255 | if (current_function_name == NULL((void*)0)) |
4256 | return nsyms; |
4257 | |
4258 | /* Check each of the symbols, and remove it from the list if it is |
4259 | a type corresponding to a renaming that is out of the scope of |
4260 | the current block. */ |
4261 | |
4262 | i = 0; |
4263 | while (i < nsyms) |
4264 | { |
4265 | if (ada_is_object_renaming (syms[i].sym) |
4266 | && !renaming_is_visible (syms[i].sym, current_function_name)) |
4267 | { |
4268 | int j; |
4269 | for (j = i + 1; j < nsyms; j++) |
4270 | syms[j - 1] = syms[j]; |
4271 | nsyms -= 1; |
4272 | } |
4273 | else |
4274 | i += 1; |
4275 | } |
4276 | |
4277 | return nsyms; |
4278 | } |
4279 | |
4280 | /* Find symbols in DOMAIN matching NAME0, in BLOCK0 and enclosing |
4281 | scope and in global scopes, returning the number of matches. Sets |
4282 | *RESULTS to point to a vector of (SYM,BLOCK,SYMTAB) triples, |
4283 | indicating the symbols found and the blocks and symbol tables (if |
4284 | any) in which they were found. This vector are transient---good only to |
4285 | the next call of ada_lookup_symbol_list. Any non-function/non-enumeral |
4286 | symbol match within the nest of blocks whose innermost member is BLOCK0, |
4287 | is the one match returned (no other matches in that or |
4288 | enclosing blocks is returned). If there are any matches in or |
4289 | surrounding BLOCK0, then these alone are returned. Otherwise, the |
4290 | search extends to global and file-scope (static) symbol tables. |
4291 | Names prefixed with "standard__" are handled specially: "standard__" |
4292 | is first stripped off, and only static and global symbols are searched. */ |
4293 | |
4294 | int |
4295 | ada_lookup_symbol_list (const char *name0, const struct block *block0, |
4296 | domain_enum namespace, |
4297 | struct ada_symbol_info **results) |
4298 | { |
4299 | struct symbol *sym; |
4300 | struct symtab *s; |
4301 | struct partial_symtab *ps; |
4302 | struct blockvector *bv; |
4303 | struct objfile *objfile; |
4304 | struct block *block; |
4305 | const char *name; |
4306 | struct minimal_symbol *msymbol; |
4307 | int wild_match; |
4308 | int cacheIfUnique; |
4309 | int block_depth; |
4310 | int ndefns; |
4311 | |
4312 | obstack_free (&symbol_list_obstack, NULL)__extension__ ({ struct obstack *__o = (&symbol_list_obstack ); void *__obj = (((void*)0)); if (__obj > (void *)__o-> chunk && __obj < (void *)__o->chunk_limit) __o-> next_free = __o->object_base = __obj; else (obstack_free) ( __o, __obj); }); |
4313 | obstack_init (&symbol_list_obstack)_obstack_begin ((&symbol_list_obstack), 0, 0, (void *(*) ( long)) xmalloc, (void (*) (void *)) xfree); |
4314 | |
4315 | cacheIfUnique = 0; |
4316 | |
4317 | /* Search specified block and its superiors. */ |
4318 | |
4319 | wild_match = (strstr (name0, "__") == NULL((void*)0)); |
4320 | name = name0; |
4321 | block = (struct block *) block0; /* FIXME: No cast ought to be |
4322 | needed, but adding const will |
4323 | have a cascade effect. */ |
4324 | if (strncmp (name0, "standard__", sizeof ("standard__") - 1) == 0) |
4325 | { |
4326 | wild_match = 0; |
4327 | block = NULL((void*)0); |
4328 | name = name0 + sizeof ("standard__") - 1; |
4329 | } |
4330 | |
4331 | block_depth = 0; |
4332 | while (block != NULL((void*)0)) |
4333 | { |
4334 | block_depth += 1; |
4335 | ada_add_block_symbols (&symbol_list_obstack, block, name, |
4336 | namespace, NULL((void*)0), NULL((void*)0), wild_match); |
4337 | |
4338 | /* If we found a non-function match, assume that's the one. */ |
4339 | if (is_nonfunction (defns_collected (&symbol_list_obstack, 0), |
4340 | num_defns_collected (&symbol_list_obstack))) |
4341 | goto done; |
4342 | |
4343 | block = BLOCK_SUPERBLOCK (block)(block)->superblock; |
4344 | } |
4345 | |
4346 | /* If no luck so far, try to find NAME as a local symbol in some lexically |
4347 | enclosing subprogram. */ |
4348 | if (num_defns_collected (&symbol_list_obstack) == 0 && block_depth > 2) |
4349 | add_symbols_from_enclosing_procs (&symbol_list_obstack, |
4350 | name, namespace, wild_match); |
4351 | |
4352 | /* If we found ANY matches among non-global symbols, we're done. */ |
4353 | |
4354 | if (num_defns_collected (&symbol_list_obstack) > 0) |
4355 | goto done; |
4356 | |
4357 | cacheIfUnique = 1; |
4358 | if (lookup_cached_symbol (name0, namespace, &sym, &block, &s)) |
4359 | { |
4360 | if (sym != NULL((void*)0)) |
4361 | add_defn_to_vec (&symbol_list_obstack, sym, block, s); |
4362 | goto done; |
4363 | } |
4364 | |
4365 | /* Now add symbols from all global blocks: symbol tables, minimal symbol |
4366 | tables, and psymtab's. */ |
4367 | |
4368 | ALL_SYMTABS (objfile, s)for ((objfile) = object_files; (objfile) != ((void*)0); (objfile ) = (objfile)->next) for ((s) = (objfile) -> symtabs; ( s) != ((void*)0); (s) = (s) -> next) |
4369 | { |
4370 | QUIT{ if (quit_flag) quit (); if (deprecated_interactive_hook) deprecated_interactive_hook (); }; |
4371 | if (!s->primary) |
4372 | continue; |
4373 | bv = BLOCKVECTOR (s)(s)->blockvector; |
4374 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)(bv)->block[GLOBAL_BLOCK]; |
4375 | ada_add_block_symbols (&symbol_list_obstack, block, name, namespace, |
4376 | objfile, s, wild_match); |
4377 | } |
4378 | |
4379 | if (namespace == VAR_DOMAIN) |
4380 | { |
4381 | ALL_MSYMBOLS (objfile, msymbol)for ((objfile) = object_files; (objfile) != ((void*)0); (objfile ) = (objfile)->next) for ((msymbol) = (objfile) -> msymbols ; (msymbol)->ginfo.name != ((void*)0); (msymbol)++) |
4382 | { |
4383 | if (ada_match_name (SYMBOL_LINKAGE_NAME (msymbol)(msymbol)->ginfo.name, name, wild_match)) |
4384 | { |
4385 | switch (MSYMBOL_TYPE (msymbol)(msymbol)->type) |
4386 | { |
4387 | case mst_solib_trampoline: |
4388 | break; |
4389 | default: |
4390 | s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)(msymbol)->ginfo.value.address); |
4391 | if (s != NULL((void*)0)) |
4392 | { |
4393 | int ndefns0 = num_defns_collected (&symbol_list_obstack); |
4394 | QUIT{ if (quit_flag) quit (); if (deprecated_interactive_hook) deprecated_interactive_hook (); }; |
4395 | bv = BLOCKVECTOR (s)(s)->blockvector; |
4396 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)(bv)->block[GLOBAL_BLOCK]; |
4397 | ada_add_block_symbols (&symbol_list_obstack, block, |
4398 | SYMBOL_LINKAGE_NAME (msymbol)(msymbol)->ginfo.name, |
4399 | namespace, objfile, s, wild_match); |
4400 | |
4401 | if (num_defns_collected (&symbol_list_obstack) == ndefns0) |
4402 | { |
4403 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)(bv)->block[STATIC_BLOCK]; |
4404 | ada_add_block_symbols (&symbol_list_obstack, block, |
4405 | SYMBOL_LINKAGE_NAME (msymbol)(msymbol)->ginfo.name, |
4406 | namespace, objfile, s, |
4407 | wild_match); |
4408 | } |
4409 | } |
4410 | } |
4411 | } |
4412 | } |
4413 | } |
4414 | |
4415 | ALL_PSYMTABS (objfile, ps)for ((objfile) = object_files; (objfile) != ((void*)0); (objfile ) = (objfile)->next) for ((ps) = (objfile) -> psymtabs; (ps) != ((void*)0); (ps) = (ps) -> next) |
4416 | { |
4417 | QUIT{ if (quit_flag) quit (); if (deprecated_interactive_hook) deprecated_interactive_hook (); }; |
4418 | if (!ps->readin |
4419 | && ada_lookup_partial_symbol (ps, name, 1, namespace, wild_match)) |
4420 | { |
4421 | s = PSYMTAB_TO_SYMTAB (ps)((ps) -> symtab != ((void*)0) ? (ps) -> symtab : psymtab_to_symtab (ps)); |
4422 | if (!s->primary) |
4423 | continue; |
4424 | bv = BLOCKVECTOR (s)(s)->blockvector; |
4425 | block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)(bv)->block[GLOBAL_BLOCK]; |
4426 | ada_add_block_symbols (&symbol_list_obstack, block, name, |
4427 | namespace, objfile, s, wild_match); |
4428 | } |
4429 | } |
4430 | |
4431 | /* Now add symbols from all per-file blocks if we've gotten no hits |
4432 | (Not strictly correct, but perhaps better than an error). |
4433 | Do the symtabs first, then check the psymtabs. */ |
4434 | |
4435 | if (num_defns_collected (&symbol_list_obstack) == 0) |
4436 | { |
4437 | |
4438 | ALL_SYMTABS (objfile, s)for ((objfile) = object_files; (objfile) != ((void*)0); (objfile ) = (objfile)->next) for ((s) = (objfile) -> symtabs; ( s) != ((void*)0); (s) = (s) -> next) |
4439 | { |
4440 | QUIT{ if (quit_flag) quit (); if (deprecated_interactive_hook) deprecated_interactive_hook (); }; |
4441 | if (!s->primary) |
4442 | continue; |
4443 | bv = BLOCKVECTOR (s)(s)->blockvector; |
4444 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)(bv)->block[STATIC_BLOCK]; |
4445 | ada_add_block_symbols (&symbol_list_obstack, block, name, namespace, |
4446 | objfile, s, wild_match); |
4447 | } |
4448 | |
4449 | ALL_PSYMTABS (objfile, ps)for ((objfile) = object_files; (objfile) != ((void*)0); (objfile ) = (objfile)->next) for ((ps) = (objfile) -> psymtabs; (ps) != ((void*)0); (ps) = (ps) -> next) |
4450 | { |
4451 | QUIT{ if (quit_flag) quit (); if (deprecated_interactive_hook) deprecated_interactive_hook (); }; |
4452 | if (!ps->readin |
4453 | && ada_lookup_partial_symbol (ps, name, 0, namespace, wild_match)) |
4454 | { |
4455 | s = PSYMTAB_TO_SYMTAB (ps)((ps) -> symtab != ((void*)0) ? (ps) -> symtab : psymtab_to_symtab (ps)); |
4456 | bv = BLOCKVECTOR (s)(s)->blockvector; |
4457 | if (!s->primary) |
4458 | continue; |
4459 | block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)(bv)->block[STATIC_BLOCK]; |
4460 | ada_add_block_symbols (&symbol_list_obstack, block, name, |
4461 | namespace, objfile, s, wild_match); |
4462 | } |
4463 | } |
4464 | } |
4465 | |
4466 | done: |
4467 | ndefns = num_defns_collected (&symbol_list_obstack); |
4468 | *results = defns_collected (&symbol_list_obstack, 1); |
4469 | |
4470 | ndefns = remove_extra_symbols (*results, ndefns); |
4471 | |
4472 | if (ndefns == 0) |
4473 | cache_symbol (name0, namespace, NULL((void*)0), NULL((void*)0), NULL((void*)0)); |
4474 | |
4475 | if (ndefns == 1 && cacheIfUnique) |
4476 | cache_symbol (name0, namespace, (*results)[0].sym, (*results)[0].block, |
4477 | (*results)[0].symtab); |
4478 | |
4479 | ndefns = remove_out_of_scope_renamings (*results, ndefns, |
4480 | (struct block *) block0); |
4481 | |
4482 | return ndefns; |
4483 | } |
4484 | |
4485 | /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing |
4486 | scope and in global scopes, or NULL if none. NAME is folded and |
4487 | encoded first. Otherwise, the result is as for ada_lookup_symbol_list, |
4488 | choosing the first symbol if there are multiple choices. |
4489 | *IS_A_FIELD_OF_THIS is set to 0 and *SYMTAB is set to the symbol |
4490 | table in which the symbol was found (in both cases, these |
4491 | assignments occur only if the pointers are non-null). */ |
4492 | |
4493 | struct symbol * |
4494 | ada_lookup_symbol (const char *name, const struct block *block0, |
4495 | domain_enum namespace, int *is_a_field_of_this, |
4496 | struct symtab **symtab) |
4497 | { |
4498 | struct ada_symbol_info *candidates; |
4499 | int n_candidates; |
4500 | |
4501 | n_candidates = ada_lookup_symbol_list (ada_encode (ada_fold_name (name)), |
4502 | block0, namespace, &candidates); |
4503 | |
4504 | if (n_candidates == 0) |
4505 | return NULL((void*)0); |
4506 | |
4507 | if (is_a_field_of_this != NULL((void*)0)) |
4508 | *is_a_field_of_this = 0; |
4509 | |
4510 | if (symtab != NULL((void*)0)) |
4511 | { |
4512 | *symtab = candidates[0].symtab; |
4513 | if (*symtab == NULL((void*)0) && candidates[0].block != NULL((void*)0)) |
4514 | { |
4515 | struct objfile *objfile; |
4516 | struct symtab *s; |
4517 | struct block *b; |
4518 | struct blockvector *bv; |
4519 | |
4520 | /* Search the list of symtabs for one which contains the |
4521 | address of the start of this block. */ |
4522 | ALL_SYMTABS (objfile, s)for ((objfile) = object_files; (objfile) != ((void*)0); (objfile ) = (objfile)->next) for ((s) = (objfile) -> symtabs; ( s) != ((void*)0); (s) = (s) -> next) |
4523 | { |
4524 | bv = BLOCKVECTOR (s)(s)->blockvector; |
4525 | b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)(bv)->block[GLOBAL_BLOCK]; |
4526 | if (BLOCK_START (b)(b)->startaddr <= BLOCK_START (candidates[0].block)(candidates[0].block)->startaddr |
4527 | && BLOCK_END (b)(b)->endaddr > BLOCK_START (candidates[0].block)(candidates[0].block)->startaddr) |
4528 | { |
4529 | *symtab = s; |
4530 | return fixup_symbol_section (candidates[0].sym, objfile); |
4531 | } |
4532 | return fixup_symbol_section (candidates[0].sym, NULL((void*)0)); |
4533 | } |
4534 | } |
4535 | } |
4536 | return candidates[0].sym; |
4537 | } |
4538 | |
4539 | static struct symbol * |
4540 | ada_lookup_symbol_nonlocal (const char *name, |
4541 | const char *linkage_name, |
4542 | const struct block *block, |
4543 | const domain_enum domain, struct symtab **symtab) |
4544 | { |
4545 | if (linkage_name == NULL((void*)0)) |
4546 | linkage_name = name; |
4547 | return ada_lookup_symbol (linkage_name, block_static_block (block), domain, |
4548 | NULL((void*)0), symtab); |
4549 | } |
4550 | |
4551 | |
4552 | /* True iff STR is a possible encoded suffix of a normal Ada name |
4553 | that is to be ignored for matching purposes. Suffixes of parallel |
4554 | names (e.g., XVE) are not included here. Currently, the possible suffixes |
4555 | are given by either of the regular expression: |
4556 | |
4557 | (__[0-9]+)?\.[0-9]+ [nested subprogram suffix, on platforms such |
4558 | as GNU/Linux] |
4559 | ___[0-9]+ [nested subprogram suffix, on platforms such as HP/UX] |
4560 | (X[nb]*)?((\$|__)[0-9](_?[0-9]+)|___(JM|LJM|X([FDBUP].*|R[^T]?)))?$ |
4561 | */ |
4562 | |
4563 | static int |
4564 | is_name_suffix (const char *str) |
4565 | { |
4566 | int k; |
4567 | const char *matching; |
4568 | const int len = strlen (str); |
4569 | |
4570 | /* (__[0-9]+)?\.[0-9]+ */ |
4571 | matching = str; |
4572 | if (len > 3 && str[0] == '_' && str[1] == '_' && isdigit (str[2])) |
4573 | { |
4574 | matching += 3; |
4575 | while (isdigit (matching[0])) |
4576 | matching += 1; |
4577 | if (matching[0] == '\0') |
4578 | return 1; |
4579 | } |
4580 | |
4581 | if (matching[0] == '.') |
4582 | { |
4583 | matching += 1; |
4584 | while (isdigit (matching[0])) |
4585 | matching += 1; |
4586 | if (matching[0] == '\0') |
4587 | return 1; |
4588 | } |
4589 | |
4590 | /* ___[0-9]+ */ |
4591 | if (len > 3 && str[0] == '_' && str[1] == '_' && str[2] == '_') |
4592 | { |
4593 | matching = str + 3; |
4594 | while (isdigit (matching[0])) |
4595 | matching += 1; |
4596 | if (matching[0] == '\0') |
4597 | return 1; |
4598 | } |
4599 | |
4600 | /* ??? We should not modify STR directly, as we are doing below. This |
4601 | is fine in this case, but may become problematic later if we find |
4602 | that this alternative did not work, and want to try matching |
4603 | another one from the begining of STR. Since we modified it, we |
4604 | won't be able to find the begining of the string anymore! */ |
4605 | if (str[0] == 'X') |
4606 | { |
4607 | str += 1; |
4608 | while (str[0] != '_' && str[0] != '\0') |
4609 | { |
4610 | if (str[0] != 'n' && str[0] != 'b') |
4611 | return 0; |
4612 | str += 1; |
4613 | } |
4614 | } |
4615 | if (str[0] == '\000') |
4616 | return 1; |
4617 | if (str[0] == '_') |
4618 | { |
4619 | if (str[1] != '_' || str[2] == '\000') |
4620 | return 0; |
4621 | if (str[2] == '_') |
4622 | { |
4623 | if (strcmp (str + 3, "JM") == 0) |
4624 | return 1; |
4625 | /* FIXME: brobecker/2004-09-30: GNAT will soon stop using |
4626 | the LJM suffix in favor of the JM one. But we will |
4627 | still accept LJM as a valid suffix for a reasonable |
4628 | amount of time, just to allow ourselves to debug programs |
4629 | compiled using an older version of GNAT. */ |
4630 | if (strcmp (str + 3, "LJM") == 0) |
4631 | return 1; |
4632 | if (str[3] != 'X') |
4633 | return 0; |
4634 | if (str[4] == 'F' || str[4] == 'D' || str[4] == 'B' |
4635 | || str[4] == 'U' || str[4] == 'P') |
4636 | return 1; |
4637 | if (str[4] == 'R' && str[5] != 'T') |
4638 | return 1; |
4639 | return 0; |
4640 | } |
4641 | if (!isdigit (str[2])) |
4642 | return 0; |
4643 | for (k = 3; str[k] != '\0'; k += 1) |
4644 | if (!isdigit (str[k]) && str[k] != '_') |
4645 | return 0; |
4646 | return 1; |
4647 | } |
4648 | if (str[0] == '$' && isdigit (str[1])) |
4649 | { |
4650 | for (k = 2; str[k] != '\0'; k += 1) |
4651 | if (!isdigit (str[k]) && str[k] != '_') |
4652 | return 0; |
4653 | return 1; |
4654 | } |
4655 | return 0; |
4656 | } |
4657 | |
4658 | /* Return nonzero if the given string starts with a dot ('.') |
4659 | followed by zero or more digits. |
4660 | |
4661 | Note: brobecker/2003-11-10: A forward declaration has not been |
4662 | added at the begining of this file yet, because this function |
4663 | is only used to work around a problem found during wild matching |
4664 | when trying to match minimal symbol names against symbol names |
4665 | obtained from dwarf-2 data. This function is therefore currently |
4666 | only used in wild_match() and is likely to be deleted when the |
4667 | problem in dwarf-2 is fixed. */ |
4668 | |
4669 | static int |
4670 | is_dot_digits_suffix (const char *str) |
4671 | { |
4672 | if (str[0] != '.') |
4673 | return 0; |
4674 | |
4675 | str++; |
4676 | while (isdigit (str[0])) |
4677 | str++; |
4678 | return (str[0] == '\0'); |
4679 | } |
4680 | |
4681 | /* True if NAME represents a name of the form A1.A2....An, n>=1 and |
4682 | PATN[0..PATN_LEN-1] = Ak.Ak+1.....An for some k >= 1. Ignores |
4683 | informational suffixes of NAME (i.e., for which is_name_suffix is |
4684 | true). */ |
4685 | |
4686 | static int |
4687 | wild_match (const char *patn0, int patn_len, const char *name0) |
4688 | { |
4689 | int name_len; |
4690 | char *name; |
4691 | char *patn; |
4692 | |
4693 | /* FIXME: brobecker/2003-11-10: For some reason, the symbol name |
4694 | stored in the symbol table for nested function names is sometimes |
4695 | different from the name of the associated entity stored in |
4696 | the dwarf-2 data: This is the case for nested subprograms, where |
4697 | the minimal symbol name contains a trailing ".[:digit:]+" suffix, |
4698 | while the symbol name from the dwarf-2 data does not. |
4699 | |
4700 | Although the DWARF-2 standard documents that entity names stored |
4701 | in the dwarf-2 data should be identical to the name as seen in |
4702 | the source code, GNAT takes a different approach as we already use |
4703 | a special encoding mechanism to convey the information so that |
4704 | a C debugger can still use the information generated to debug |
4705 | Ada programs. A corollary is that the symbol names in the dwarf-2 |
4706 | data should match the names found in the symbol table. I therefore |
4707 | consider this issue as a compiler defect. |
4708 | |
4709 | Until the compiler is properly fixed, we work-around the problem |
4710 | by ignoring such suffixes during the match. We do so by making |
4711 | a copy of PATN0 and NAME0, and then by stripping such a suffix |
4712 | if present. We then perform the match on the resulting strings. */ |
4713 | { |
4714 | char *dot; |
4715 | name_len = strlen (name0); |
4716 | |
4717 | name = (char *) alloca ((name_len + 1) * sizeof (char))__builtin_alloca((name_len + 1) * sizeof (char)); |
4718 | strcpy (name, name0); |
4719 | dot = strrchr (name, '.'); |
4720 | if (dot != NULL((void*)0) && is_dot_digits_suffix (dot)) |
4721 | *dot = '\0'; |
4722 | |
4723 | patn = (char *) alloca ((patn_len + 1) * sizeof (char))__builtin_alloca((patn_len + 1) * sizeof (char)); |
4724 | strncpy (patn, patn0, patn_len); |
4725 | patn[patn_len] = '\0'; |
4726 | dot = strrchr (patn, '.'); |
4727 | if (dot != NULL((void*)0) && is_dot_digits_suffix (dot)) |
4728 | { |
4729 | *dot = '\0'; |
4730 | patn_len = dot - patn; |
4731 | } |
4732 | } |
4733 | |
4734 | /* Now perform the wild match. */ |
4735 | |
4736 | name_len = strlen (name); |
4737 | if (name_len >= patn_len + 5 && strncmp (name, "_ada_", 5) == 0 |
4738 | && strncmp (patn, name + 5, patn_len) == 0 |
4739 | && is_name_suffix (name + patn_len + 5)) |
4740 | return 1; |
4741 | |
4742 | while (name_len >= patn_len) |
4743 | { |
4744 | if (strncmp (patn, name, patn_len) == 0 |
4745 | && is_name_suffix (name + patn_len)) |
4746 | return 1; |
4747 | do |
4748 | { |
4749 | name += 1; |
4750 | name_len -= 1; |
4751 | } |
4752 | while (name_len > 0 |
4753 | && name[0] != '.' && (name[0] != '_' || name[1] != '_')); |
4754 | if (name_len <= 0) |
4755 | return 0; |
4756 | if (name[0] == '_') |
4757 | { |
4758 | if (!islower (name[2])) |
4759 | return 0; |
4760 | name += 2; |
4761 | name_len -= 2; |
4762 | } |
4763 | else |
4764 | { |
4765 | if (!islower (name[1])) |
4766 | return 0; |
4767 | name += 1; |
4768 | name_len -= 1; |
4769 | } |
4770 | } |
4771 | |
4772 | return 0; |
4773 | } |
4774 | |
4775 | |
4776 | /* Add symbols from BLOCK matching identifier NAME in DOMAIN to |
4777 | vector *defn_symbols, updating the list of symbols in OBSTACKP |
4778 | (if necessary). If WILD, treat as NAME with a wildcard prefix. |
4779 | OBJFILE is the section containing BLOCK. |
4780 | SYMTAB is recorded with each symbol added. */ |
4781 | |
4782 | static void |
4783 | ada_add_block_symbols (struct obstack *obstackp, |
4784 | struct block *block, const char *name, |
4785 | domain_enum domain, struct objfile *objfile, |
4786 | struct symtab *symtab, int wild) |
4787 | { |
4788 | struct dict_iterator iter; |
4789 | int name_len = strlen (name); |
4790 | /* A matching argument symbol, if any. */ |
4791 | struct symbol *arg_sym; |
4792 | /* Set true when we find a matching non-argument symbol. */ |
4793 | int found_sym; |
4794 | struct symbol *sym; |
4795 | |
4796 | arg_sym = NULL((void*)0); |
4797 | found_sym = 0; |
4798 | if (wild) |
4799 | { |
4800 | struct symbol *sym; |
4801 | ALL_BLOCK_SYMBOLS (block, iter, sym)for ((sym) = dict_iterator_first (((block)->dict), &(iter )); (sym); (sym) = dict_iterator_next (&(iter))) |
4802 | { |
4803 | if (SYMBOL_DOMAIN (sym)(sym)->domain == domain |
4804 | && wild_match (name, name_len, SYMBOL_LINKAGE_NAME (sym)(sym)->ginfo.name)) |
4805 | { |
4806 | switch (SYMBOL_CLASS (sym)(sym)->aclass) |
4807 | { |
4808 | case LOC_ARG: |
4809 | case LOC_LOCAL_ARG: |
4810 | case LOC_REF_ARG: |
4811 | case LOC_REGPARM: |
4812 | case LOC_REGPARM_ADDR: |
4813 | case LOC_BASEREG_ARG: |
4814 | case LOC_COMPUTED_ARG: |
4815 | arg_sym = sym; |
4816 | break; |
4817 | case LOC_UNRESOLVED: |
4818 | continue; |
4819 | default: |
4820 | found_sym = 1; |
4821 | add_defn_to_vec (obstackp, |
4822 | fixup_symbol_section (sym, objfile), |
4823 | block, symtab); |
4824 | break; |
4825 | } |
4826 | } |
4827 | } |
4828 | } |
4829 | else |
4830 | { |
4831 | ALL_BLOCK_SYMBOLS (block, iter, sym)for ((sym) = dict_iterator_first (((block)->dict), &(iter )); (sym); (sym) = dict_iterator_next (&(iter))) |
4832 | { |
4833 | if (SYMBOL_DOMAIN (sym)(sym)->domain == domain) |
4834 | { |
4835 | int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym)(sym)->ginfo.name, name_len); |
4836 | if (cmp == 0 |
4837 | && is_name_suffix (SYMBOL_LINKAGE_NAME (sym)(sym)->ginfo.name + name_len)) |
4838 | { |
4839 | switch (SYMBOL_CLASS (sym)(sym)->aclass) |
4840 | { |
4841 | case LOC_ARG: |
4842 | case LOC_LOCAL_ARG: |
4843 | case LOC_REF_ARG: |
4844 | case LOC_REGPARM: |
4845 | case LOC_REGPARM_ADDR: |
4846 | case LOC_BASEREG_ARG: |
4847 | case LOC_COMPUTED_ARG: |
4848 | arg_sym = sym; |
4849 | break; |
4850 | case LOC_UNRESOLVED: |
4851 | break; |
4852 | default: |
4853 | found_sym = 1; |
4854 | add_defn_to_vec (obstackp, |
4855 | fixup_symbol_section (sym, objfile), |
4856 | block, symtab); |
4857 | break; |
4858 | } |
4859 | } |
4860 | } |
4861 | } |
4862 | } |
4863 | |
4864 | if (!found_sym && arg_sym != NULL((void*)0)) |
4865 | { |
4866 | add_defn_to_vec (obstackp, |
4867 | fixup_symbol_section (arg_sym, objfile), |
4868 | block, symtab); |
4869 | } |
4870 | |
4871 | if (!wild) |
4872 | { |
4873 | arg_sym = NULL((void*)0); |
4874 | found_sym = 0; |
4875 | |
4876 | ALL_BLOCK_SYMBOLS (block, iter, sym)for ((sym) = dict_iterator_first (((block)->dict), &(iter )); (sym); (sym) = dict_iterator_next (&(iter))) |
4877 | { |
4878 | if (SYMBOL_DOMAIN (sym)(sym)->domain == domain) |
4879 | { |
4880 | int cmp; |
4881 | |
4882 | cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)(sym)->ginfo.name[0]; |
4883 | if (cmp == 0) |
4884 | { |
4885 | cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (sym)(sym)->ginfo.name, 5); |
4886 | if (cmp == 0) |
4887 | cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym)(sym)->ginfo.name + 5, |
4888 | name_len); |
4889 | } |
4890 | |
4891 | if (cmp == 0 |
4892 | && is_name_suffix (SYMBOL_LINKAGE_NAME (sym)(sym)->ginfo.name + name_len + 5)) |
4893 | { |
4894 | switch (SYMBOL_CLASS (sym)(sym)->aclass) |
4895 | { |
4896 | case LOC_ARG: |
4897 | case LOC_LOCAL_ARG: |
4898 | case LOC_REF_ARG: |
4899 | case LOC_REGPARM: |
4900 | case LOC_REGPARM_ADDR: |
4901 | case LOC_BASEREG_ARG: |
4902 | case LOC_COMPUTED_ARG: |
4903 | arg_sym = sym; |
4904 | break; |
4905 | case LOC_UNRESOLVED: |
4906 | break; |
4907 | default: |
4908 | found_sym = 1; |
4909 | add_defn_to_vec (obstackp, |
4910 | fixup_symbol_section (sym, objfile), |
4911 | block, symtab); |
4912 | break; |
4913 | } |
4914 | } |
4915 | } |
4916 | } |
4917 | |
4918 | /* NOTE: This really shouldn't be needed for _ada_ symbols. |
4919 | They aren't parameters, right? */ |
4920 | if (!found_sym && arg_sym != NULL((void*)0)) |
4921 | { |
4922 | add_defn_to_vec (obstackp, |
4923 | fixup_symbol_section (arg_sym, objfile), |
4924 | block, symtab); |
4925 | } |
4926 | } |
4927 | } |
4928 | |
4929 | /* Field Access */ |
4930 | |
4931 | /* True if field number FIELD_NUM in struct or union type TYPE is supposed |
4932 | to be invisible to users. */ |
4933 | |
4934 | int |
4935 | ada_is_ignored_field (struct type *type, int field_num) |
4936 | { |
4937 | if (field_num < 0 || field_num > TYPE_NFIELDS (type)(type)->main_type->nfields) |
4938 | return 1; |
4939 | else |
4940 | { |
4941 | const char *name = TYPE_FIELD_NAME (type, field_num)(((type)->main_type->fields[field_num]).name); |
4942 | return (name == NULL((void*)0) |
4943 | || (name[0] == '_' && strncmp (name, "_parent", 7) != 0)); |
4944 | } |
4945 | } |
4946 | |
4947 | /* True iff TYPE has a tag field. If REFOK, then TYPE may also be a |
4948 | pointer or reference type whose ultimate target has a tag field. */ |
4949 | |
4950 | int |
4951 | ada_is_tagged_type (struct type *type, int refok) |
4952 | { |
4953 | return (ada_lookup_struct_elt_type (type, "_tag", refok, 1, NULL((void*)0)) != NULL((void*)0)); |
4954 | } |
4955 | |
4956 | /* True iff TYPE represents the type of X'Tag */ |
4957 | |
4958 | int |
4959 | ada_is_tag_type (struct type *type) |
4960 | { |
4961 | if (type == NULL((void*)0) || TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_PTR) |
4962 | return 0; |
4963 | else |
4964 | { |
4965 | const char *name = ada_type_name (TYPE_TARGET_TYPE (type)(type)->main_type->target_type); |
4966 | return (name != NULL((void*)0) |
4967 | && strcmp (name, "ada__tags__dispatch_table") == 0); |
4968 | } |
4969 | } |
4970 | |
4971 | /* The type of the tag on VAL. */ |
4972 | |
4973 | struct type * |
4974 | ada_tag_type (struct value *val) |
4975 | { |
4976 | return ada_lookup_struct_elt_type (VALUE_TYPE (val)(val)->type, "_tag", 1, 0, NULL((void*)0)); |
4977 | } |
4978 | |
4979 | /* The value of the tag on VAL. */ |
4980 | |
4981 | struct value * |
4982 | ada_value_tag (struct value *val) |
4983 | { |
4984 | return ada_value_struct_elt (val, "_tag", "record"); |
4985 | } |
4986 | |
4987 | /* The value of the tag on the object of type TYPE whose contents are |
4988 | saved at VALADDR, if it is non-null, or is at memory address |
4989 | ADDRESS. */ |
4990 | |
4991 | static struct value * |
4992 | value_tag_from_contents_and_address (struct type *type, char *valaddr, |
4993 | CORE_ADDR address) |
4994 | { |
4995 | int tag_byte_offset, dummy1, dummy2; |
4996 | struct type *tag_type; |
4997 | if (find_struct_field ("_tag", type, 0, &tag_type, &tag_byte_offset, |
4998 | &dummy1, &dummy2)) |
4999 | { |
5000 | char *valaddr1 = (valaddr == NULL((void*)0)) ? NULL((void*)0) : valaddr + tag_byte_offset; |
5001 | CORE_ADDR address1 = (address == 0) ? 0 : address + tag_byte_offset; |
5002 | |
5003 | return value_from_contents_and_address (tag_type, valaddr1, address1); |
5004 | } |
5005 | return NULL((void*)0); |
5006 | } |
5007 | |
5008 | static struct type * |
5009 | type_from_tag (struct value *tag) |
5010 | { |
5011 | const char *type_name = ada_tag_name (tag); |
5012 | if (type_name != NULL((void*)0)) |
5013 | return ada_find_any_type (ada_encode (type_name)); |
5014 | return NULL((void*)0); |
5015 | } |
5016 | |
5017 | struct tag_args |
5018 | { |
5019 | struct value *tag; |
5020 | char *name; |
5021 | }; |
5022 | |
5023 | /* Wrapper function used by ada_tag_name. Given a struct tag_args* |
5024 | value ARGS, sets ARGS->name to the tag name of ARGS->tag. |
5025 | The value stored in ARGS->name is valid until the next call to |
5026 | ada_tag_name_1. */ |
5027 | |
5028 | static int |
5029 | ada_tag_name_1 (void *args0) |
5030 | { |
5031 | struct tag_args *args = (struct tag_args *) args0; |
5032 | static char name[1024]; |
5033 | char *p; |
5034 | struct value *val; |
5035 | args->name = NULL((void*)0); |
5036 | val = ada_value_struct_elt (args->tag, "tsd", NULL((void*)0)); |
5037 | if (val == NULL((void*)0)) |
5038 | return 0; |
5039 | val = ada_value_struct_elt (val, "expanded_name", NULL((void*)0)); |
5040 | if (val == NULL((void*)0)) |
5041 | return 0; |
5042 | read_memory_string (value_as_address (val), name, sizeof (name) - 1); |
5043 | for (p = name; *p != '\0'; p += 1) |
5044 | if (isalpha (*p)) |
5045 | *p = tolower (*p); |
5046 | args->name = name; |
5047 | return 0; |
5048 | } |
5049 | |
5050 | /* The type name of the dynamic type denoted by the 'tag value TAG, as |
5051 | * a C string. */ |
5052 | |
5053 | const char * |
5054 | ada_tag_name (struct value *tag) |
5055 | { |
5056 | struct tag_args args; |
5057 | if (!ada_is_tag_type (VALUE_TYPE (tag)(tag)->type)) |
5058 | return NULL((void*)0); |
5059 | args.tag = tag; |
5060 | args.name = NULL((void*)0); |
5061 | catch_errors (ada_tag_name_1, &args, NULL((void*)0), RETURN_MASK_ALL((1 << (int)(-RETURN_QUIT)) | (1 << (int)(-RETURN_ERROR )))); |
5062 | return args.name; |
5063 | } |
5064 | |
5065 | /* The parent type of TYPE, or NULL if none. */ |
5066 | |
5067 | struct type * |
5068 | ada_parent_type (struct type *type) |
5069 | { |
5070 | int i; |
5071 | |
5072 | type = ada_check_typedef (type); |
5073 | |
5074 | if (type == NULL((void*)0) || TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_STRUCT) |
5075 | return NULL((void*)0); |
5076 | |
5077 | for (i = 0; i < TYPE_NFIELDS (type)(type)->main_type->nfields; i += 1) |
5078 | if (ada_is_parent_field (type, i)) |
5079 | return ada_check_typedef (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type)); |
5080 | |
5081 | return NULL((void*)0); |
5082 | } |
5083 | |
5084 | /* True iff field number FIELD_NUM of structure type TYPE contains the |
5085 | parent-type (inherited) fields of a derived type. Assumes TYPE is |
5086 | a structure type with at least FIELD_NUM+1 fields. */ |
5087 | |
5088 | int |
5089 | ada_is_parent_field (struct type *type, int field_num) |
5090 | { |
5091 | const char *name = TYPE_FIELD_NAME (ada_check_typedef (type), field_num)(((ada_check_typedef (type))->main_type->fields[field_num ]).name); |
5092 | return (name != NULL((void*)0) |
5093 | && (strncmp (name, "PARENT", 6) == 0 |
5094 | || strncmp (name, "_parent", 7) == 0)); |
5095 | } |
5096 | |
5097 | /* True iff field number FIELD_NUM of structure type TYPE is a |
5098 | transparent wrapper field (which should be silently traversed when doing |
5099 | field selection and flattened when printing). Assumes TYPE is a |
5100 | structure type with at least FIELD_NUM+1 fields. Such fields are always |
5101 | structures. */ |
5102 | |
5103 | int |
5104 | ada_is_wrapper_field (struct type *type, int field_num) |
5105 | { |
5106 | const char *name = TYPE_FIELD_NAME (type, field_num)(((type)->main_type->fields[field_num]).name); |
5107 | return (name != NULL((void*)0) |
5108 | && (strncmp (name, "PARENT", 6) == 0 |
5109 | || strcmp (name, "REP") == 0 |
5110 | || strncmp (name, "_parent", 7) == 0 |
5111 | || name[0] == 'S' || name[0] == 'R' || name[0] == 'O')); |
5112 | } |
5113 | |
5114 | /* True iff field number FIELD_NUM of structure or union type TYPE |
5115 | is a variant wrapper. Assumes TYPE is a structure type with at least |
5116 | FIELD_NUM+1 fields. */ |
5117 | |
5118 | int |
5119 | ada_is_variant_part (struct type *type, int field_num) |
5120 | { |
5121 | struct type *field_type = TYPE_FIELD_TYPE (type, field_num)(((type)->main_type->fields[field_num]).type); |
5122 | return (TYPE_CODE (field_type)(field_type)->main_type->code == TYPE_CODE_UNION |
5123 | || (is_dynamic_field (type, field_num) |
5124 | && (TYPE_CODE (TYPE_TARGET_TYPE (field_type))((field_type)->main_type->target_type)->main_type-> code |
5125 | == TYPE_CODE_UNION))); |
5126 | } |
5127 | |
5128 | /* Assuming that VAR_TYPE is a variant wrapper (type of the variant part) |
5129 | whose discriminants are contained in the record type OUTER_TYPE, |
5130 | returns the type of the controlling discriminant for the variant. */ |
5131 | |
5132 | struct type * |
5133 | ada_variant_discrim_type (struct type *var_type, struct type *outer_type) |
5134 | { |
5135 | char *name = ada_variant_discrim_name (var_type); |
5136 | struct type *type = |
5137 | ada_lookup_struct_elt_type (outer_type, name, 1, 1, NULL((void*)0)); |
5138 | if (type == NULL((void*)0)) |
5139 | return builtin_type_int; |
5140 | else |
5141 | return type; |
5142 | } |
5143 | |
5144 | /* Assuming that TYPE is the type of a variant wrapper, and FIELD_NUM is a |
5145 | valid field number within it, returns 1 iff field FIELD_NUM of TYPE |
5146 | represents a 'when others' clause; otherwise 0. */ |
5147 | |
5148 | int |
5149 | ada_is_others_clause (struct type *type, int field_num) |
5150 | { |
5151 | const char *name = TYPE_FIELD_NAME (type, field_num)(((type)->main_type->fields[field_num]).name); |
5152 | return (name != NULL((void*)0) && name[0] == 'O'); |
5153 | } |
5154 | |
5155 | /* Assuming that TYPE0 is the type of the variant part of a record, |
5156 | returns the name of the discriminant controlling the variant. |
5157 | The value is valid until the next call to ada_variant_discrim_name. */ |
5158 | |
5159 | char * |
5160 | ada_variant_discrim_name (struct type *type0) |
5161 | { |
5162 | static char *result = NULL((void*)0); |
5163 | static size_t result_len = 0; |
5164 | struct type *type; |
5165 | const char *name; |
5166 | const char *discrim_end; |
5167 | const char *discrim_start; |
5168 | |
5169 | if (TYPE_CODE (type0)(type0)->main_type->code == TYPE_CODE_PTR) |
5170 | type = TYPE_TARGET_TYPE (type0)(type0)->main_type->target_type; |
5171 | else |
5172 | type = type0; |
5173 | |
5174 | name = ada_type_name (type); |
5175 | |
5176 | if (name == NULL((void*)0) || name[0] == '\000') |
5177 | return ""; |
5178 | |
5179 | for (discrim_end = name + strlen (name) - 6; discrim_end != name; |
5180 | discrim_end -= 1) |
5181 | { |
5182 | if (strncmp (discrim_end, "___XVN", 6) == 0) |
5183 | break; |
5184 | } |
5185 | if (discrim_end == name) |
5186 | return ""; |
5187 | |
5188 | for (discrim_start = discrim_end; discrim_start != name + 3; |
5189 | discrim_start -= 1) |
5190 | { |
5191 | if (discrim_start == name + 1) |
5192 | return ""; |
5193 | if ((discrim_start > name + 3 |
5194 | && strncmp (discrim_start - 3, "___", 3) == 0) |
5195 | || discrim_start[-1] == '.') |
5196 | break; |
5197 | } |
5198 | |
5199 | GROW_VECT (result, result_len, discrim_end - discrim_start + 1)if ((result_len) < (discrim_end - discrim_start + 1)) grow_vect ((void**) &(result), &(result_len), (discrim_end - discrim_start + 1), sizeof(*(result)));; |
5200 | strncpy (result, discrim_start, discrim_end - discrim_start); |
5201 | result[discrim_end - discrim_start] = '\0'; |
5202 | return result; |
5203 | } |
5204 | |
5205 | /* Scan STR for a subtype-encoded number, beginning at position K. |
5206 | Put the position of the character just past the number scanned in |
5207 | *NEW_K, if NEW_K!=NULL. Put the scanned number in *R, if R!=NULL. |
5208 | Return 1 if there was a valid number at the given position, and 0 |
5209 | otherwise. A "subtype-encoded" number consists of the absolute value |
5210 | in decimal, followed by the letter 'm' to indicate a negative number. |
5211 | Assumes 0m does not occur. */ |
5212 | |
5213 | int |
5214 | ada_scan_number (const char str[], int k, LONGESTlong * R, int *new_k) |
5215 | { |
5216 | ULONGESTunsigned long RU; |
5217 | |
5218 | if (!isdigit (str[k])) |
5219 | return 0; |
5220 | |
5221 | /* Do it the hard way so as not to make any assumption about |
5222 | the relationship of unsigned long (%lu scan format code) and |
5223 | LONGEST. */ |
5224 | RU = 0; |
5225 | while (isdigit (str[k])) |
5226 | { |
5227 | RU = RU * 10 + (str[k] - '0'); |
5228 | k += 1; |
5229 | } |
5230 | |
5231 | if (str[k] == 'm') |
5232 | { |
5233 | if (R != NULL((void*)0)) |
5234 | *R = (-(LONGESTlong) (RU - 1)) - 1; |
5235 | k += 1; |
5236 | } |
5237 | else if (R != NULL((void*)0)) |
5238 | *R = (LONGESTlong) RU; |
5239 | |
5240 | /* NOTE on the above: Technically, C does not say what the results of |
5241 | - (LONGEST) RU or (LONGEST) -RU are for RU == largest positive |
5242 | number representable as a LONGEST (although either would probably work |
5243 | in most implementations). When RU>0, the locution in the then branch |
5244 | above is always equivalent to the negative of RU. */ |
5245 | |
5246 | if (new_k != NULL((void*)0)) |
5247 | *new_k = k; |
5248 | return 1; |
5249 | } |
5250 | |
5251 | /* Assuming that TYPE is a variant part wrapper type (a VARIANTS field), |
5252 | and FIELD_NUM is a valid field number within it, returns 1 iff VAL is |
5253 | in the range encoded by field FIELD_NUM of TYPE; otherwise 0. */ |
5254 | |
5255 | int |
5256 | ada_in_variant (LONGESTlong val, struct type *type, int field_num) |
5257 | { |
5258 | const char *name = TYPE_FIELD_NAME (type, field_num)(((type)->main_type->fields[field_num]).name); |
5259 | int p; |
5260 | |
5261 | p = 0; |
5262 | while (1) |
5263 | { |
5264 | switch (name[p]) |
5265 | { |
5266 | case '\0': |
5267 | return 0; |
5268 | case 'S': |
5269 | { |
5270 | LONGESTlong W; |
5271 | if (!ada_scan_number (name, p + 1, &W, &p)) |
5272 | return 0; |
5273 | if (val == W) |
5274 | return 1; |
5275 | break; |
5276 | } |
5277 | case 'R': |
5278 | { |
5279 | LONGESTlong L, U; |
5280 | if (!ada_scan_number (name, p + 1, &L, &p) |
5281 | || name[p] != 'T' || !ada_scan_number (name, p + 1, &U, &p)) |
5282 | return 0; |
5283 | if (val >= L && val <= U) |
5284 | return 1; |
5285 | break; |
5286 | } |
5287 | case 'O': |
5288 | return 1; |
5289 | default: |
5290 | return 0; |
5291 | } |
5292 | } |
5293 | } |
5294 | |
5295 | /* FIXME: Lots of redundancy below. Try to consolidate. */ |
5296 | |
5297 | /* Given a value ARG1 (offset by OFFSET bytes) of a struct or union type |
5298 | ARG_TYPE, extract and return the value of one of its (non-static) |
5299 | fields. FIELDNO says which field. Differs from value_primitive_field |
5300 | only in that it can handle packed values of arbitrary type. */ |
5301 | |
5302 | static struct value * |
5303 | ada_value_primitive_field (struct value *arg1, int offset, int fieldno, |
5304 | struct type *arg_type) |
5305 | { |
5306 | struct type *type; |
5307 | |
5308 | arg_type = ada_check_typedef (arg_type); |
5309 | type = TYPE_FIELD_TYPE (arg_type, fieldno)(((arg_type)->main_type->fields[fieldno]).type); |
5310 | |
5311 | /* Handle packed fields. */ |
5312 | |
5313 | if (TYPE_FIELD_BITSIZE (arg_type, fieldno)(((arg_type)->main_type->fields[fieldno]).bitsize) != 0) |
5314 | { |
5315 | int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno)(((arg_type)->main_type->fields[fieldno]).loc.bitpos); |
5316 | int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno)(((arg_type)->main_type->fields[fieldno]).bitsize); |
5317 | |
5318 | return ada_value_primitive_packed_val (arg1, VALUE_CONTENTS (arg1)((void)((arg1)->lazy && value_fetch_lazy(arg1)), ( (char *) (arg1)->aligner.contents + (arg1)->embedded_offset )), |
5319 | offset + bit_pos / 8, |
5320 | bit_pos % 8, bit_size, type); |
5321 | } |
5322 | else |
5323 | return value_primitive_field (arg1, offset, fieldno, arg_type); |
5324 | } |
5325 | |
5326 | /* Find field with name NAME in object of type TYPE. If found, return 1 |
5327 | after setting *FIELD_TYPE_P to the field's type, *BYTE_OFFSET_P to |
5328 | OFFSET + the byte offset of the field within an object of that type, |
5329 | *BIT_OFFSET_P to the bit offset modulo byte size of the field, and |
5330 | *BIT_SIZE_P to its size in bits if the field is packed, and 0 otherwise. |
5331 | Looks inside wrappers for the field. Returns 0 if field not |
5332 | found. */ |
5333 | static int |
5334 | find_struct_field (char *name, struct type *type, int offset, |
5335 | struct type **field_type_p, |
5336 | int *byte_offset_p, int *bit_offset_p, int *bit_size_p) |
5337 | { |
5338 | int i; |
5339 | |
5340 | type = ada_check_typedef (type); |
5341 | *field_type_p = NULL((void*)0); |
5342 | *byte_offset_p = *bit_offset_p = *bit_size_p = 0; |
5343 | |
5344 | for (i = TYPE_NFIELDS (type)(type)->main_type->nfields - 1; i >= 0; i -= 1) |
5345 | { |
5346 | int bit_pos = TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos); |
5347 | int fld_offset = offset + bit_pos / 8; |
5348 | char *t_field_name = TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name); |
5349 | |
5350 | if (t_field_name == NULL((void*)0)) |
5351 | continue; |
5352 | |
5353 | else if (field_name_match (t_field_name, name)) |
5354 | { |
5355 | int bit_size = TYPE_FIELD_BITSIZE (type, i)(((type)->main_type->fields[i]).bitsize); |
5356 | *field_type_p = TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type); |
5357 | *byte_offset_p = fld_offset; |
5358 | *bit_offset_p = bit_pos % 8; |
5359 | *bit_size_p = bit_size; |
5360 | return 1; |
5361 | } |
5362 | else if (ada_is_wrapper_field (type, i)) |
5363 | { |
5364 | if (find_struct_field (name, TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type), fld_offset, |
5365 | field_type_p, byte_offset_p, bit_offset_p, |
5366 | bit_size_p)) |
5367 | return 1; |
5368 | } |
5369 | else if (ada_is_variant_part (type, i)) |
5370 | { |
5371 | int j; |
5372 | struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type)); |
5373 | |
5374 | for (j = TYPE_NFIELDS (field_type)(field_type)->main_type->nfields - 1; j >= 0; j -= 1) |
5375 | { |
5376 | if (find_struct_field (name, TYPE_FIELD_TYPE (field_type, j)(((field_type)->main_type->fields[j]).type), |
5377 | fld_offset |
5378 | + TYPE_FIELD_BITPOS (field_type, j)(((field_type)->main_type->fields[j]).loc.bitpos) / 8, |
5379 | field_type_p, byte_offset_p, |
5380 | bit_offset_p, bit_size_p)) |
5381 | return 1; |
5382 | } |
5383 | } |
5384 | } |
5385 | return 0; |
5386 | } |
5387 | |
5388 | |
5389 | |
5390 | /* Look for a field NAME in ARG. Adjust the address of ARG by OFFSET bytes, |
5391 | and search in it assuming it has (class) type TYPE. |
5392 | If found, return value, else return NULL. |
5393 | |
5394 | Searches recursively through wrapper fields (e.g., '_parent'). */ |
5395 | |
5396 | static struct value * |
5397 | ada_search_struct_field (char *name, struct value *arg, int offset, |
5398 | struct type *type) |
5399 | { |
5400 | int i; |
5401 | type = ada_check_typedef (type); |
5402 | |
5403 | for (i = TYPE_NFIELDS (type)(type)->main_type->nfields - 1; i >= 0; i -= 1) |
5404 | { |
5405 | char *t_field_name = TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name); |
5406 | |
5407 | if (t_field_name == NULL((void*)0)) |
5408 | continue; |
5409 | |
5410 | else if (field_name_match (t_field_name, name)) |
5411 | return ada_value_primitive_field (arg, offset, i, type); |
5412 | |
5413 | else if (ada_is_wrapper_field (type, i)) |
5414 | { |
5415 | struct value *v = /* Do not let indent join lines here. */ |
5416 | ada_search_struct_field (name, arg, |
5417 | offset + TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos) / 8, |
5418 | TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type)); |
5419 | if (v != NULL((void*)0)) |
5420 | return v; |
5421 | } |
5422 | |
5423 | else if (ada_is_variant_part (type, i)) |
5424 | { |
5425 | int j; |
5426 | struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type)); |
5427 | int var_offset = offset + TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos) / 8; |
5428 | |
5429 | for (j = TYPE_NFIELDS (field_type)(field_type)->main_type->nfields - 1; j >= 0; j -= 1) |
5430 | { |
5431 | struct value *v = ada_search_struct_field /* Force line break. */ |
5432 | (name, arg, |
5433 | var_offset + TYPE_FIELD_BITPOS (field_type, j)(((field_type)->main_type->fields[j]).loc.bitpos) / 8, |
5434 | TYPE_FIELD_TYPE (field_type, j)(((field_type)->main_type->fields[j]).type)); |
5435 | if (v != NULL((void*)0)) |
5436 | return v; |
5437 | } |
5438 | } |
5439 | } |
5440 | return NULL((void*)0); |
5441 | } |
5442 | |
5443 | /* Given ARG, a value of type (pointer or reference to a)* |
5444 | structure/union, extract the component named NAME from the ultimate |
5445 | target structure/union and return it as a value with its |
5446 | appropriate type. If ARG is a pointer or reference and the field |
5447 | is not packed, returns a reference to the field, otherwise the |
5448 | value of the field (an lvalue if ARG is an lvalue). |
5449 | |
5450 | The routine searches for NAME among all members of the structure itself |
5451 | and (recursively) among all members of any wrapper members |
5452 | (e.g., '_parent'). |
5453 | |
5454 | ERR is a name (for use in error messages) that identifies the class |
5455 | of entity that ARG is supposed to be. ERR may be null, indicating |
5456 | that on error, the function simply returns NULL, and does not |
5457 | throw an error. (FIXME: True only if ARG is a pointer or reference |
5458 | at the moment). */ |
5459 | |
5460 | struct value * |
5461 | ada_value_struct_elt (struct value *arg, char *name, char *err) |
5462 | { |
5463 | struct type *t, *t1; |
5464 | struct value *v; |
5465 | |
5466 | v = NULL((void*)0); |
5467 | t1 = t = ada_check_typedef (VALUE_TYPE (arg)(arg)->type); |
5468 | if (TYPE_CODE (t)(t)->main_type->code == TYPE_CODE_REF) |
5469 | { |
5470 | t1 = TYPE_TARGET_TYPE (t)(t)->main_type->target_type; |
5471 | if (t1 == NULL((void*)0)) |
5472 | { |
5473 | if (err == NULL((void*)0)) |
5474 | return NULL((void*)0); |
5475 | else |
5476 | error ("Bad value type in a %s.", err); |
5477 | } |
5478 | t1 = ada_check_typedef (t1); |
5479 | if (TYPE_CODE (t1)(t1)->main_type->code == TYPE_CODE_PTR) |
5480 | { |
5481 | COERCE_REF (arg)do { struct type *value_type_arg_tmp = check_typedef ((arg)-> type); if ((value_type_arg_tmp)->main_type->code == TYPE_CODE_REF ) arg = value_at_lazy ((value_type_arg_tmp)->main_type-> target_type, unpack_pointer ((arg)->type, ((void)((arg)-> lazy && value_fetch_lazy(arg)), ((char *) (arg)->aligner .contents + (arg)->embedded_offset))), ((arg)->bfd_section )); } while (0); |
5482 | t = t1; |
5483 | } |
5484 | } |
5485 | |
5486 | while (TYPE_CODE (t)(t)->main_type->code == TYPE_CODE_PTR) |
5487 | { |
5488 | t1 = TYPE_TARGET_TYPE (t)(t)->main_type->target_type; |
5489 | if (t1 == NULL((void*)0)) |
5490 | { |
5491 | if (err == NULL((void*)0)) |
5492 | return NULL((void*)0); |
5493 | else |
5494 | error ("Bad value type in a %s.", err); |
5495 | } |
5496 | t1 = ada_check_typedef (t1); |
5497 | if (TYPE_CODE (t1)(t1)->main_type->code == TYPE_CODE_PTR) |
5498 | { |
5499 | arg = value_ind (arg); |
5500 | t = t1; |
5501 | } |
5502 | else |
5503 | break; |
5504 | } |
5505 | |
5506 | if (TYPE_CODE (t1)(t1)->main_type->code != TYPE_CODE_STRUCT && TYPE_CODE (t1)(t1)->main_type->code != TYPE_CODE_UNION) |
5507 | { |
5508 | if (err == NULL((void*)0)) |
5509 | return NULL((void*)0); |
5510 | else |
5511 | error ("Attempt to extract a component of a value that is not a %s.", |
5512 | err); |
5513 | } |
5514 | |
5515 | if (t1 == t) |
5516 | v = ada_search_struct_field (name, arg, 0, t); |
5517 | else |
5518 | { |
5519 | int bit_offset, bit_size, byte_offset; |
5520 | struct type *field_type; |
5521 | CORE_ADDR address; |
5522 | |
5523 | if (TYPE_CODE (t)(t)->main_type->code == TYPE_CODE_PTR) |
5524 | address = value_as_address (arg); |
5525 | else |
5526 | address = unpack_pointer (t, VALUE_CONTENTS (arg)((void)((arg)->lazy && value_fetch_lazy(arg)), ((char *) (arg)->aligner.contents + (arg)->embedded_offset))); |
5527 | |
5528 | t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL((void*)0), address, NULL((void*)0)); |
5529 | if (find_struct_field (name, t1, 0, |
5530 | &field_type, &byte_offset, &bit_offset, |
5531 | &bit_size)) |
5532 | { |
5533 | if (bit_size != 0) |
5534 | { |
5535 | if (TYPE_CODE (t)(t)->main_type->code == TYPE_CODE_REF) |
5536 | arg = ada_coerce_ref (arg); |
5537 | else |
5538 | arg = ada_value_ind (arg); |
5539 | v = ada_value_primitive_packed_val (arg, NULL((void*)0), byte_offset, |
5540 | bit_offset, bit_size, |
5541 | field_type); |
5542 | } |
5543 | else |
5544 | v = value_from_pointer (lookup_reference_type (field_type), |
5545 | address + byte_offset); |
5546 | } |
5547 | } |
5548 | |
5549 | if (v == NULL((void*)0) && err != NULL((void*)0)) |
5550 | error ("There is no member named %s.", name); |
5551 | |
5552 | return v; |
5553 | } |
5554 | |
5555 | /* Given a type TYPE, look up the type of the component of type named NAME. |
5556 | If DISPP is non-null, add its byte displacement from the beginning of a |
5557 | structure (pointed to by a value) of type TYPE to *DISPP (does not |
5558 | work for packed fields). |
5559 | |
5560 | Matches any field whose name has NAME as a prefix, possibly |
5561 | followed by "___". |
5562 | |
5563 | TYPE can be either a struct or union. If REFOK, TYPE may also |
5564 | be a (pointer or reference)+ to a struct or union, and the |
5565 | ultimate target type will be searched. |
5566 | |
5567 | Looks recursively into variant clauses and parent types. |
5568 | |
5569 | If NOERR is nonzero, return NULL if NAME is not suitably defined or |
5570 | TYPE is not a type of the right kind. */ |
5571 | |
5572 | static struct type * |
5573 | ada_lookup_struct_elt_type (struct type *type, char *name, int refok, |
5574 | int noerr, int *dispp) |
5575 | { |
5576 | int i; |
5577 | |
5578 | if (name == NULL((void*)0)) |
5579 | goto BadName; |
5580 | |
5581 | if (refok && type != NULL((void*)0)) |
5582 | while (1) |
5583 | { |
5584 | type = ada_check_typedef (type); |
5585 | if (TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_PTR |
5586 | && TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_REF) |
5587 | break; |
5588 | type = TYPE_TARGET_TYPE (type)(type)->main_type->target_type; |
5589 | } |
5590 | |
5591 | if (type == NULL((void*)0) |
5592 | || (TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_STRUCT |
5593 | && TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_UNION)) |
5594 | { |
5595 | if (noerr) |
5596 | return NULL((void*)0); |
5597 | else |
5598 | { |
5599 | target_terminal_ours ()(*current_target.to_terminal_ours) (); |
5600 | gdb_flush (gdb_stdout); |
5601 | fprintf_unfiltered (gdb_stderr, "Type "); |
5602 | if (type == NULL((void*)0)) |
5603 | fprintf_unfiltered (gdb_stderr, "(null)"); |
5604 | else |
5605 | type_print (type, "", gdb_stderr, -1); |
5606 | error (" is not a structure or union type"); |
5607 | } |
5608 | } |
5609 | |
5610 | type = to_static_fixed_type (type); |
5611 | |
5612 | for (i = 0; i < TYPE_NFIELDS (type)(type)->main_type->nfields; i += 1) |
5613 | { |
5614 | char *t_field_name = TYPE_FIELD_NAME (type, i)(((type)->main_type->fields[i]).name); |
5615 | struct type *t; |
5616 | int disp; |
5617 | |
5618 | if (t_field_name == NULL((void*)0)) |
5619 | continue; |
5620 | |
5621 | else if (field_name_match (t_field_name, name)) |
5622 | { |
5623 | if (dispp != NULL((void*)0)) |
5624 | *dispp += TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos) / 8; |
5625 | return ada_check_typedef (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type)); |
5626 | } |
5627 | |
5628 | else if (ada_is_wrapper_field (type, i)) |
5629 | { |
5630 | disp = 0; |
5631 | t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type), name, |
5632 | 0, 1, &disp); |
5633 | if (t != NULL((void*)0)) |
5634 | { |
5635 | if (dispp != NULL((void*)0)) |
5636 | *dispp += disp + TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos) / 8; |
5637 | return t; |
5638 | } |
5639 | } |
5640 | |
5641 | else if (ada_is_variant_part (type, i)) |
5642 | { |
5643 | int j; |
5644 | struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type, i)(((type)->main_type->fields[i]).type)); |
5645 | |
5646 | for (j = TYPE_NFIELDS (field_type)(field_type)->main_type->nfields - 1; j >= 0; j -= 1) |
5647 | { |
5648 | disp = 0; |
5649 | t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (field_type, j)(((field_type)->main_type->fields[j]).type), |
5650 | name, 0, 1, &disp); |
5651 | if (t != NULL((void*)0)) |
5652 | { |
5653 | if (dispp != NULL((void*)0)) |
5654 | *dispp += disp + TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos) / 8; |
5655 | return t; |
5656 | } |
5657 | } |
5658 | } |
5659 | |
5660 | } |
5661 | |
5662 | BadName: |
5663 | if (!noerr) |
5664 | { |
5665 | target_terminal_ours ()(*current_target.to_terminal_ours) (); |
5666 | gdb_flush (gdb_stdout); |
5667 | fprintf_unfiltered (gdb_stderr, "Type "); |
5668 | type_print (type, "", gdb_stderr, -1); |
5669 | fprintf_unfiltered (gdb_stderr, " has no component named "); |
5670 | error ("%s", name == NULL((void*)0) ? "<null>" : name); |
5671 | } |
5672 | |
5673 | return NULL((void*)0); |
5674 | } |
5675 | |
5676 | /* Assuming that VAR_TYPE is the type of a variant part of a record (a union), |
5677 | within a value of type OUTER_TYPE that is stored in GDB at |
5678 | OUTER_VALADDR, determine which variant clause (field number in VAR_TYPE, |
5679 | numbering from 0) is applicable. Returns -1 if none are. */ |
5680 | |
5681 | int |
5682 | ada_which_variant_applies (struct type *var_type, struct type *outer_type, |
5683 | char *outer_valaddr) |
5684 | { |
5685 | int others_clause; |
5686 | int i; |
5687 | int disp; |
5688 | struct type *discrim_type; |
5689 | char *discrim_name = ada_variant_discrim_name (var_type); |
5690 | LONGESTlong discrim_val; |
5691 | |
5692 | disp = 0; |
5693 | discrim_type = |
5694 | ada_lookup_struct_elt_type (outer_type, discrim_name, 1, 1, &disp); |
5695 | if (discrim_type == NULL((void*)0)) |
5696 | return -1; |
5697 | discrim_val = unpack_long (discrim_type, outer_valaddr + disp); |
5698 | |
5699 | others_clause = -1; |
5700 | for (i = 0; i < TYPE_NFIELDS (var_type)(var_type)->main_type->nfields; i += 1) |
5701 | { |
5702 | if (ada_is_others_clause (var_type, i)) |
5703 | others_clause = i; |
5704 | else if (ada_in_variant (discrim_val, var_type, i)) |
5705 | return i; |
5706 | } |
5707 | |
5708 | return others_clause; |
5709 | } |
5710 | |
5711 | |
5712 | |
5713 | /* Dynamic-Sized Records */ |
5714 | |
5715 | /* Strategy: The type ostensibly attached to a value with dynamic size |
5716 | (i.e., a size that is not statically recorded in the debugging |
5717 | data) does not accurately reflect the size or layout of the value. |
5718 | Our strategy is to convert these values to values with accurate, |
5719 | conventional types that are constructed on the fly. */ |
5720 | |
5721 | /* There is a subtle and tricky problem here. In general, we cannot |
5722 | determine the size of dynamic records without its data. However, |
5723 | the 'struct value' data structure, which GDB uses to represent |
5724 | quantities in the inferior process (the target), requires the size |
5725 | of the type at the time of its allocation in order to reserve space |
5726 | for GDB's internal copy of the data. That's why the |
5727 | 'to_fixed_xxx_type' routines take (target) addresses as parameters, |
5728 | rather than struct value*s. |
5729 | |
5730 | However, GDB's internal history variables ($1, $2, etc.) are |
5731 | struct value*s containing internal copies of the data that are not, in |
5732 | general, the same as the data at their corresponding addresses in |
5733 | the target. Fortunately, the types we give to these values are all |
5734 | conventional, fixed-size types (as per the strategy described |
5735 | above), so that we don't usually have to perform the |
5736 | 'to_fixed_xxx_type' conversions to look at their values. |
5737 | Unfortunately, there is one exception: if one of the internal |
5738 | history variables is an array whose elements are unconstrained |
5739 | records, then we will need to create distinct fixed types for each |
5740 | element selected. */ |
5741 | |
5742 | /* The upshot of all of this is that many routines take a (type, host |
5743 | address, target address) triple as arguments to represent a value. |
5744 | The host address, if non-null, is supposed to contain an internal |
5745 | copy of the relevant data; otherwise, the program is to consult the |
5746 | target at the target address. */ |
5747 | |
5748 | /* Assuming that VAL0 represents a pointer value, the result of |
5749 | dereferencing it. Differs from value_ind in its treatment of |
5750 | dynamic-sized types. */ |
5751 | |
5752 | struct value * |
5753 | ada_value_ind (struct value *val0) |
5754 | { |
5755 | struct value *val = unwrap_value (value_ind (val0)); |
5756 | return ada_to_fixed_value (val); |
5757 | } |
5758 | |
5759 | /* The value resulting from dereferencing any "reference to" |
5760 | qualifiers on VAL0. */ |
5761 | |
5762 | static struct value * |
5763 | ada_coerce_ref (struct value *val0) |
5764 | { |
5765 | if (TYPE_CODE (VALUE_TYPE (val0))((val0)->type)->main_type->code == TYPE_CODE_REF) |
5766 | { |
5767 | struct value *val = val0; |
5768 | COERCE_REF (val)do { struct type *value_type_arg_tmp = check_typedef ((val)-> type); if ((value_type_arg_tmp)->main_type->code == TYPE_CODE_REF ) val = value_at_lazy ((value_type_arg_tmp)->main_type-> target_type, unpack_pointer ((val)->type, ((void)((val)-> lazy && value_fetch_lazy(val)), ((char *) (val)->aligner .contents + (val)->embedded_offset))), ((val)->bfd_section )); } while (0); |
5769 | val = unwrap_value (val); |
5770 | return ada_to_fixed_value (val); |
5771 | } |
5772 | else |
5773 | return val0; |
5774 | } |
5775 | |
5776 | /* Return OFF rounded upward if necessary to a multiple of |
5777 | ALIGNMENT (a power of 2). */ |
5778 | |
5779 | static unsigned int |
5780 | align_value (unsigned int off, unsigned int alignment) |
5781 | { |
5782 | return (off + alignment - 1) & ~(alignment - 1); |
5783 | } |
5784 | |
5785 | /* Return the bit alignment required for field #F of template type TYPE. */ |
5786 | |
5787 | static unsigned int |
5788 | field_alignment (struct type *type, int f) |
5789 | { |
5790 | const char *name = TYPE_FIELD_NAME (type, f)(((type)->main_type->fields[f]).name); |
5791 | int len = (name == NULL((void*)0)) ? 0 : strlen (name); |
5792 | int align_offset; |
5793 | |
5794 | if (!isdigit (name[len - 1])) |
5795 | return 1; |
5796 | |
5797 | if (isdigit (name[len - 2])) |
5798 | align_offset = len - 2; |
5799 | else |
5800 | align_offset = len - 1; |
5801 | |
5802 | if (align_offset < 7 || strncmp ("___XV", name + align_offset - 6, 5) != 0) |
5803 | return TARGET_CHAR_BIT8; |
5804 | |
5805 | return atoi (name + align_offset) * TARGET_CHAR_BIT8; |
5806 | } |
5807 | |
5808 | /* Find a symbol named NAME. Ignores ambiguity. */ |
5809 | |
5810 | struct symbol * |
5811 | ada_find_any_symbol (const char *name) |
5812 | { |
5813 | struct symbol *sym; |
5814 | |
5815 | sym = standard_lookup (name, get_selected_block (NULL((void*)0)), VAR_DOMAIN); |
5816 | if (sym != NULL((void*)0) && SYMBOL_CLASS (sym)(sym)->aclass == LOC_TYPEDEF) |
5817 | return sym; |
5818 | |
5819 | sym = standard_lookup (name, NULL((void*)0), STRUCT_DOMAIN); |
5820 | return sym; |
5821 | } |
5822 | |
5823 | /* Find a type named NAME. Ignores ambiguity. */ |
5824 | |
5825 | struct type * |
5826 | ada_find_any_type (const char *name) |
5827 | { |
5828 | struct symbol *sym = ada_find_any_symbol (name); |
5829 | |
5830 | if (sym != NULL((void*)0)) |
5831 | return SYMBOL_TYPE (sym)(sym)->type; |
5832 | |
5833 | return NULL((void*)0); |
5834 | } |
5835 | |
5836 | /* Given a symbol NAME and its associated BLOCK, search all symbols |
5837 | for its ___XR counterpart, which is the ``renaming'' symbol |
5838 | associated to NAME. Return this symbol if found, return |
5839 | NULL otherwise. */ |
5840 | |
5841 | struct symbol * |
5842 | ada_find_renaming_symbol (const char *name, struct block *block) |
5843 | { |
5844 | const struct symbol *function_sym = block_function (block); |
5845 | char *rename; |
5846 | |
5847 | if (function_sym != NULL((void*)0)) |
5848 | { |
5849 | /* If the symbol is defined inside a function, NAME is not fully |
5850 | qualified. This means we need to prepend the function name |
5851 | as well as adding the ``___XR'' suffix to build the name of |
5852 | the associated renaming symbol. */ |
5853 | char *function_name = SYMBOL_LINKAGE_NAME (function_sym)(function_sym)->ginfo.name; |
5854 | const int function_name_len = strlen (function_name); |
5855 | const int rename_len = function_name_len + 2 /* "__" */ |
5856 | + strlen (name) + 6 /* "___XR\0" */ ; |
5857 | |
5858 | /* Library-level functions are a special case, as GNAT adds |
5859 | a ``_ada_'' prefix to the function name to avoid namespace |
5860 | pollution. However, the renaming symbol themselves do not |
5861 | have this prefix, so we need to skip this prefix if present. */ |
5862 | if (function_name_len > 5 /* "_ada_" */ |
5863 | && strstr (function_name, "_ada_") == function_name) |
5864 | function_name = function_name + 5; |
5865 | |
5866 | rename = (char *) alloca (rename_len * sizeof (char))__builtin_alloca(rename_len * sizeof (char)); |
5867 | sprintf (rename, "%s__%s___XR", function_name, name); |
5868 | } |
5869 | else |
5870 | { |
5871 | const int rename_len = strlen (name) + 6; |
5872 | rename = (char *) alloca (rename_len * sizeof (char))__builtin_alloca(rename_len * sizeof (char)); |
5873 | sprintf (rename, "%s___XR", name); |
5874 | } |
5875 | |
5876 | return ada_find_any_symbol (rename); |
5877 | } |
5878 | |
5879 | /* Because of GNAT encoding conventions, several GDB symbols may match a |
5880 | given type name. If the type denoted by TYPE0 is to be preferred to |
5881 | that of TYPE1 for purposes of type printing, return non-zero; |
5882 | otherwise return 0. */ |
5883 | |
5884 | int |
5885 | ada_prefer_type (struct type *type0, struct type *type1) |
5886 | { |
5887 | if (type1 == NULL((void*)0)) |
5888 | return 1; |
5889 | else if (type0 == NULL((void*)0)) |
5890 | return 0; |
5891 | else if (TYPE_CODE (type1)(type1)->main_type->code == TYPE_CODE_VOID) |
5892 | return 1; |
5893 | else if (TYPE_CODE (type0)(type0)->main_type->code == TYPE_CODE_VOID) |
5894 | return 0; |
5895 | else if (TYPE_NAME (type1)(type1)->main_type->name == NULL((void*)0) && TYPE_NAME (type0)(type0)->main_type->name != NULL((void*)0)) |
5896 | return 1; |
5897 | else if (ada_is_packed_array_type (type0)) |
5898 | return 1; |
5899 | else if (ada_is_array_descriptor_type (type0) |
5900 | && !ada_is_array_descriptor_type (type1)) |
5901 | return 1; |
5902 | else if (ada_renaming_type (type0) != NULL((void*)0) |
5903 | && ada_renaming_type (type1) == NULL((void*)0)) |
5904 | return 1; |
5905 | return 0; |
5906 | } |
5907 | |
5908 | /* The name of TYPE, which is either its TYPE_NAME, or, if that is |
5909 | null, its TYPE_TAG_NAME. Null if TYPE is null. */ |
5910 | |
5911 | char * |
5912 | ada_type_name (struct type *type) |
5913 | { |
5914 | if (type == NULL((void*)0)) |
5915 | return NULL((void*)0); |
5916 | else if (TYPE_NAME (type)(type)->main_type->name != NULL((void*)0)) |
5917 | return TYPE_NAME (type)(type)->main_type->name; |
5918 | else |
5919 | return TYPE_TAG_NAME (type)(type)->main_type->tag_name; |
5920 | } |
5921 | |
5922 | /* Find a parallel type to TYPE whose name is formed by appending |
5923 | SUFFIX to the name of TYPE. */ |
5924 | |
5925 | struct type * |
5926 | ada_find_parallel_type (struct type *type, const char *suffix) |
5927 | { |
5928 | static char *name; |
5929 | static size_t name_len = 0; |
5930 | int len; |
5931 | char *typename = ada_type_name (type); |
5932 | |
5933 | if (typename == NULL((void*)0)) |
5934 | return NULL((void*)0); |
5935 | |
5936 | len = strlen (typename); |
5937 | |
5938 | GROW_VECT (name, name_len, len + strlen (suffix) + 1)if ((name_len) < (len + strlen (suffix) + 1)) grow_vect (( void**) &(name), &(name_len), (len + strlen (suffix) + 1), sizeof(*(name)));; |
5939 | |
5940 | strcpy (name, typename); |
5941 | strcpy (name + len, suffix); |
5942 | |
5943 | return ada_find_any_type (name); |
5944 | } |
5945 | |
5946 | |
5947 | /* If TYPE is a variable-size record type, return the corresponding template |
5948 | type describing its fields. Otherwise, return NULL. */ |
5949 | |
5950 | static struct type * |
5951 | dynamic_template_type (struct type *type) |
5952 | { |
5953 | type = ada_check_typedef (type); |
5954 | |
5955 | if (type == NULL((void*)0) || TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_STRUCT |
5956 | || ada_type_name (type) == NULL((void*)0)) |
5957 | return NULL((void*)0); |
5958 | else |
5959 | { |
5960 | int len = strlen (ada_type_name (type)); |
5961 | if (len > 6 && strcmp (ada_type_name (type) + len - 6, "___XVE") == 0) |
5962 | return type; |
5963 | else |
5964 | return ada_find_parallel_type (type, "___XVE"); |
5965 | } |
5966 | } |
5967 | |
5968 | /* Assuming that TEMPL_TYPE is a union or struct type, returns |
5969 | non-zero iff field FIELD_NUM of TEMPL_TYPE has dynamic size. */ |
5970 | |
5971 | static int |
5972 | is_dynamic_field (struct type *templ_type, int field_num) |
5973 | { |
5974 | const char *name = TYPE_FIELD_NAME (templ_type, field_num)(((templ_type)->main_type->fields[field_num]).name); |
5975 | return name != NULL((void*)0) |
5976 | && TYPE_CODE (TYPE_FIELD_TYPE (templ_type, field_num))((((templ_type)->main_type->fields[field_num]).type))-> main_type->code == TYPE_CODE_PTR |
5977 | && strstr (name, "___XVL") != NULL((void*)0); |
5978 | } |
5979 | |
5980 | /* The index of the variant field of TYPE, or -1 if TYPE does not |
5981 | represent a variant record type. */ |
5982 | |
5983 | static int |
5984 | variant_field_index (struct type *type) |
5985 | { |
5986 | int f; |
5987 | |
5988 | if (type == NULL((void*)0) || TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_STRUCT) |
5989 | return -1; |
5990 | |
5991 | for (f = 0; f < TYPE_NFIELDS (type)(type)->main_type->nfields; f += 1) |
5992 | { |
5993 | if (ada_is_variant_part (type, f)) |
5994 | return f; |
5995 | } |
5996 | return -1; |
5997 | } |
5998 | |
5999 | /* A record type with no fields. */ |
6000 | |
6001 | static struct type * |
6002 | empty_record (struct objfile *objfile) |
6003 | { |
6004 | struct type *type = alloc_type (objfile); |
6005 | TYPE_CODE (type)(type)->main_type->code = TYPE_CODE_STRUCT; |
6006 | TYPE_NFIELDS (type)(type)->main_type->nfields = 0; |
6007 | TYPE_FIELDS (type)(type)->main_type->fields = NULL((void*)0); |
6008 | TYPE_NAME (type)(type)->main_type->name = "<empty>"; |
6009 | TYPE_TAG_NAME (type)(type)->main_type->tag_name = NULL((void*)0); |
6010 | TYPE_FLAGS (type)(type)->main_type->flags = 0; |
6011 | TYPE_LENGTH (type)(type)->length = 0; |
6012 | return type; |
6013 | } |
6014 | |
6015 | /* An ordinary record type (with fixed-length fields) that describes |
6016 | the value of type TYPE at VALADDR or ADDRESS (see comments at |
6017 | the beginning of this section) VAL according to GNAT conventions. |
6018 | DVAL0 should describe the (portion of a) record that contains any |
6019 | necessary discriminants. It should be NULL if VALUE_TYPE (VAL) is |
6020 | an outer-level type (i.e., as opposed to a branch of a variant.) A |
6021 | variant field (unless unchecked) is replaced by a particular branch |
6022 | of the variant. |
6023 | |
6024 | If not KEEP_DYNAMIC_FIELDS, then all fields whose position or |
6025 | length are not statically known are discarded. As a consequence, |
6026 | VALADDR, ADDRESS and DVAL0 are ignored. |
6027 | |
6028 | NOTE: Limitations: For now, we assume that dynamic fields and |
6029 | variants occupy whole numbers of bytes. However, they need not be |
6030 | byte-aligned. */ |
6031 | |
6032 | struct type * |
6033 | ada_template_to_fixed_record_type_1 (struct type *type, char *valaddr, |
6034 | CORE_ADDR address, struct value *dval0, |
6035 | int keep_dynamic_fields) |
6036 | { |
6037 | struct value *mark = value_mark (); |
6038 | struct value *dval; |
6039 | struct type *rtype; |
6040 | int nfields, bit_len; |
6041 | int variant_field; |
6042 | long off; |
6043 | int fld_bit_len, bit_incr; |
6044 | int f; |
6045 | |
6046 | /* Compute the number of fields in this record type that are going |
6047 | to be processed: unless keep_dynamic_fields, this includes only |
6048 | fields whose position and length are static will be processed. */ |
6049 | if (keep_dynamic_fields) |
6050 | nfields = TYPE_NFIELDS (type)(type)->main_type->nfields; |
6051 | else |
6052 | { |
6053 | nfields = 0; |
6054 | while (nfields < TYPE_NFIELDS (type)(type)->main_type->nfields |
6055 | && !ada_is_variant_part (type, nfields) |
6056 | && !is_dynamic_field (type, nfields)) |
6057 | nfields++; |
6058 | } |
6059 | |
6060 | rtype = alloc_type (TYPE_OBJFILE (type)(type)->main_type->objfile); |
6061 | TYPE_CODE (rtype)(rtype)->main_type->code = TYPE_CODE_STRUCT; |
6062 | INIT_CPLUS_SPECIFIC (rtype)((rtype)->main_type->type_specific.cplus_stuff=(struct cplus_struct_type *)&cplus_struct_default); |
6063 | TYPE_NFIELDS (rtype)(rtype)->main_type->nfields = nfields; |
6064 | TYPE_FIELDS (rtype)(rtype)->main_type->fields = (struct field *) |
6065 | TYPE_ALLOC (rtype, nfields * sizeof (struct field))((rtype)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(rtype)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((nfields * sizeof (struct field))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (nfields * sizeof (struct field))); |
6066 | memset (TYPE_FIELDS (rtype)(rtype)->main_type->fields, 0, sizeof (struct field) * nfields); |
6067 | TYPE_NAME (rtype)(rtype)->main_type->name = ada_type_name (type); |
6068 | TYPE_TAG_NAME (rtype)(rtype)->main_type->tag_name = NULL((void*)0); |
6069 | TYPE_FLAGS (rtype)(rtype)->main_type->flags |= TYPE_FLAG_FIXED_INSTANCE(1 << 15); |
6070 | |
6071 | off = 0; |
6072 | bit_len = 0; |
6073 | variant_field = -1; |
6074 | |
6075 | for (f = 0; f < nfields; f += 1) |
6076 | { |
6077 | off = align_value (off, field_alignment (type, f)) |
6078 | + TYPE_FIELD_BITPOS (type, f)(((type)->main_type->fields[f]).loc.bitpos); |
6079 | TYPE_FIELD_BITPOS (rtype, f)(((rtype)->main_type->fields[f]).loc.bitpos) = off; |
6080 | TYPE_FIELD_BITSIZE (rtype, f)(((rtype)->main_type->fields[f]).bitsize) = 0; |
6081 | |
6082 | if (ada_is_variant_part (type, f)) |
6083 | { |
6084 | variant_field = f; |
6085 | fld_bit_len = bit_incr = 0; |
6086 | } |
6087 | else if (is_dynamic_field (type, f)) |
6088 | { |
6089 | if (dval0 == NULL((void*)0)) |
6090 | dval = value_from_contents_and_address (rtype, valaddr, address); |
6091 | else |
6092 | dval = dval0; |
6093 | |
6094 | TYPE_FIELD_TYPE (rtype, f)(((rtype)->main_type->fields[f]).type) = |
6095 | ada_to_fixed_type |
6096 | (ada_get_base_type |
6097 | (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, f))((((type)->main_type->fields[f]).type))->main_type-> target_type), |
6098 | cond_offset_host (valaddr, off / TARGET_CHAR_BIT8), |
6099 | cond_offset_target (address, off / TARGET_CHAR_BIT8), dval); |
6100 | TYPE_FIELD_NAME (rtype, f)(((rtype)->main_type->fields[f]).name) = TYPE_FIELD_NAME (type, f)(((type)->main_type->fields[f]).name); |
6101 | bit_incr = fld_bit_len = |
6102 | TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, f))((((rtype)->main_type->fields[f]).type))->length * TARGET_CHAR_BIT8; |
6103 | } |
6104 | else |
6105 | { |
6106 | TYPE_FIELD_TYPE (rtype, f)(((rtype)->main_type->fields[f]).type) = TYPE_FIELD_TYPE (type, f)(((type)->main_type->fields[f]).type); |
6107 | TYPE_FIELD_NAME (rtype, f)(((rtype)->main_type->fields[f]).name) = TYPE_FIELD_NAME (type, f)(((type)->main_type->fields[f]).name); |
6108 | if (TYPE_FIELD_BITSIZE (type, f)(((type)->main_type->fields[f]).bitsize) > 0) |
6109 | bit_incr = fld_bit_len = |
6110 | TYPE_FIELD_BITSIZE (rtype, f)(((rtype)->main_type->fields[f]).bitsize) = TYPE_FIELD_BITSIZE (type, f)(((type)->main_type->fields[f]).bitsize); |
6111 | else |
6112 | bit_incr = fld_bit_len = |
6113 | TYPE_LENGTH (TYPE_FIELD_TYPE (type, f))((((type)->main_type->fields[f]).type))->length * TARGET_CHAR_BIT8; |
6114 | } |
6115 | if (off + fld_bit_len > bit_len) |
6116 | bit_len = off + fld_bit_len; |
6117 | off += bit_incr; |
6118 | TYPE_LENGTH (rtype)(rtype)->length = |
6119 | align_value (bit_len, TARGET_CHAR_BIT8) / TARGET_CHAR_BIT8; |
6120 | } |
6121 | |
6122 | /* We handle the variant part, if any, at the end because of certain |
6123 | odd cases in which it is re-ordered so as NOT the last field of |
6124 | the record. This can happen in the presence of representation |
6125 | clauses. */ |
6126 | if (variant_field >= 0) |
6127 | { |
6128 | struct type *branch_type; |
6129 | |
6130 | off = TYPE_FIELD_BITPOS (rtype, variant_field)(((rtype)->main_type->fields[variant_field]).loc.bitpos ); |
6131 | |
6132 | if (dval0 == NULL((void*)0)) |
6133 | dval = value_from_contents_and_address (rtype, valaddr, address); |
6134 | else |
6135 | dval = dval0; |
6136 | |
6137 | branch_type = |
6138 | to_fixed_variant_branch_type |
6139 | (TYPE_FIELD_TYPE (type, variant_field)(((type)->main_type->fields[variant_field]).type), |
6140 | cond_offset_host (valaddr, off / TARGET_CHAR_BIT8), |
6141 | cond_offset_target (address, off / TARGET_CHAR_BIT8), dval); |
6142 | if (branch_type == NULL((void*)0)) |
6143 | { |
6144 | for (f = variant_field + 1; f < TYPE_NFIELDS (rtype)(rtype)->main_type->nfields; f += 1) |
6145 | TYPE_FIELDS (rtype)(rtype)->main_type->fields[f - 1] = TYPE_FIELDS (rtype)(rtype)->main_type->fields[f]; |
6146 | TYPE_NFIELDS (rtype)(rtype)->main_type->nfields -= 1; |
6147 | } |
6148 | else |
6149 | { |
6150 | TYPE_FIELD_TYPE (rtype, variant_field)(((rtype)->main_type->fields[variant_field]).type) = branch_type; |
6151 | TYPE_FIELD_NAME (rtype, variant_field)(((rtype)->main_type->fields[variant_field]).name) = "S"; |
6152 | fld_bit_len = |
6153 | TYPE_LENGTH (TYPE_FIELD_TYPE (rtype, variant_field))((((rtype)->main_type->fields[variant_field]).type))-> length * |
6154 | TARGET_CHAR_BIT8; |
6155 | if (off + fld_bit_len > bit_len) |
6156 | bit_len = off + fld_bit_len; |
6157 | TYPE_LENGTH (rtype)(rtype)->length = |
6158 | align_value (bit_len, TARGET_CHAR_BIT8) / TARGET_CHAR_BIT8; |
6159 | } |
6160 | } |
6161 | |
6162 | /* According to exp_dbug.ads, the size of TYPE for variable-size records |
6163 | should contain the alignment of that record, which should be a strictly |
6164 | positive value. If null or negative, then something is wrong, most |
6165 | probably in the debug info. In that case, we don't round up the size |
6166 | of the resulting type. If this record is not part of another structure, |
6167 | the current RTYPE length might be good enough for our purposes. */ |
6168 | if (TYPE_LENGTH (type)(type)->length <= 0) |
6169 | { |
6170 | warning ("Invalid type size for `%s' detected: %d.", |
6171 | TYPE_NAME (rtype)(rtype)->main_type->name ? TYPE_NAME (rtype)(rtype)->main_type->name : "<unnamed>", |
6172 | TYPE_LENGTH (type)(type)->length); |
6173 | } |
6174 | else |
6175 | { |
6176 | TYPE_LENGTH (rtype)(rtype)->length = align_value (TYPE_LENGTH (rtype)(rtype)->length, |
6177 | TYPE_LENGTH (type)(type)->length); |
6178 | } |
6179 | |
6180 | value_free_to_mark (mark); |
6181 | if (TYPE_LENGTH (rtype)(rtype)->length > varsize_limit) |
6182 | error ("record type with dynamic size is larger than varsize-limit"); |
6183 | return rtype; |
6184 | } |
6185 | |
6186 | /* As for ada_template_to_fixed_record_type_1 with KEEP_DYNAMIC_FIELDS |
6187 | of 1. */ |
6188 | |
6189 | static struct type * |
6190 | template_to_fixed_record_type (struct type *type, char *valaddr, |
6191 | CORE_ADDR address, struct value *dval0) |
6192 | { |
6193 | return ada_template_to_fixed_record_type_1 (type, valaddr, |
6194 | address, dval0, 1); |
6195 | } |
6196 | |
6197 | /* An ordinary record type in which ___XVL-convention fields and |
6198 | ___XVU- and ___XVN-convention field types in TYPE0 are replaced with |
6199 | static approximations, containing all possible fields. Uses |
6200 | no runtime values. Useless for use in values, but that's OK, |
6201 | since the results are used only for type determinations. Works on both |
6202 | structs and unions. Representation note: to save space, we memorize |
6203 | the result of this function in the TYPE_TARGET_TYPE of the |
6204 | template type. */ |
6205 | |
6206 | static struct type * |
6207 | template_to_static_fixed_type (struct type *type0) |
6208 | { |
6209 | struct type *type; |
6210 | int nfields; |
6211 | int f; |
6212 | |
6213 | if (TYPE_TARGET_TYPE (type0)(type0)->main_type->target_type != NULL((void*)0)) |
6214 | return TYPE_TARGET_TYPE (type0)(type0)->main_type->target_type; |
6215 | |
6216 | nfields = TYPE_NFIELDS (type0)(type0)->main_type->nfields; |
6217 | type = type0; |
6218 | |
6219 | for (f = 0; f < nfields; f += 1) |
6220 | { |
6221 | struct type *field_type = ada_check_typedef (TYPE_FIELD_TYPE (type0, f)(((type0)->main_type->fields[f]).type)); |
6222 | struct type *new_type; |
6223 | |
6224 | if (is_dynamic_field (type0, f)) |
6225 | new_type = to_static_fixed_type (TYPE_TARGET_TYPE (field_type)(field_type)->main_type->target_type); |
6226 | else |
6227 | new_type = to_static_fixed_type (field_type); |
6228 | if (type == type0 && new_type != field_type) |
6229 | { |
6230 | TYPE_TARGET_TYPE (type0)(type0)->main_type->target_type = type = alloc_type (TYPE_OBJFILE (type0)(type0)->main_type->objfile); |
6231 | TYPE_CODE (type)(type)->main_type->code = TYPE_CODE (type0)(type0)->main_type->code; |
6232 | INIT_CPLUS_SPECIFIC (type)((type)->main_type->type_specific.cplus_stuff=(struct cplus_struct_type *)&cplus_struct_default); |
6233 | TYPE_NFIELDS (type)(type)->main_type->nfields = nfields; |
6234 | TYPE_FIELDS (type)(type)->main_type->fields = (struct field *) |
6235 | TYPE_ALLOC (type, nfields * sizeof (struct field))((type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(type)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((nfields * sizeof (struct field))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (nfields * sizeof (struct field))); |
6236 | memcpy (TYPE_FIELDS (type)(type)->main_type->fields, TYPE_FIELDS (type0)(type0)->main_type->fields, |
6237 | sizeof (struct field) * nfields); |
6238 | TYPE_NAME (type)(type)->main_type->name = ada_type_name (type0); |
6239 | TYPE_TAG_NAME (type)(type)->main_type->tag_name = NULL((void*)0); |
6240 | TYPE_FLAGS (type)(type)->main_type->flags |= TYPE_FLAG_FIXED_INSTANCE(1 << 15); |
6241 | TYPE_LENGTH (type)(type)->length = 0; |
6242 | } |
6243 | TYPE_FIELD_TYPE (type, f)(((type)->main_type->fields[f]).type) = new_type; |
6244 | TYPE_FIELD_NAME (type, f)(((type)->main_type->fields[f]).name) = TYPE_FIELD_NAME (type0, f)(((type0)->main_type->fields[f]).name); |
6245 | } |
6246 | return type; |
6247 | } |
6248 | |
6249 | /* Given an object of type TYPE whose contents are at VALADDR and |
6250 | whose address in memory is ADDRESS, returns a revision of TYPE -- |
6251 | a non-dynamic-sized record with a variant part -- in which |
6252 | the variant part is replaced with the appropriate branch. Looks |
6253 | for discriminant values in DVAL0, which can be NULL if the record |
6254 | contains the necessary discriminant values. */ |
6255 | |
6256 | static struct type * |
6257 | to_record_with_fixed_variant_part (struct type *type, char *valaddr, |
6258 | CORE_ADDR address, struct value *dval0) |
6259 | { |
6260 | struct value *mark = value_mark (); |
6261 | struct value *dval; |
6262 | struct type *rtype; |
6263 | struct type *branch_type; |
6264 | int nfields = TYPE_NFIELDS (type)(type)->main_type->nfields; |
6265 | int variant_field = variant_field_index (type); |
6266 | |
6267 | if (variant_field == -1) |
6268 | return type; |
6269 | |
6270 | if (dval0 == NULL((void*)0)) |
6271 | dval = value_from_contents_and_address (type, valaddr, address); |
6272 | else |
6273 | dval = dval0; |
6274 | |
6275 | rtype = alloc_type (TYPE_OBJFILE (type)(type)->main_type->objfile); |
6276 | TYPE_CODE (rtype)(rtype)->main_type->code = TYPE_CODE_STRUCT; |
6277 | INIT_CPLUS_SPECIFIC (rtype)((rtype)->main_type->type_specific.cplus_stuff=(struct cplus_struct_type *)&cplus_struct_default); |
6278 | TYPE_NFIELDS (rtype)(rtype)->main_type->nfields = nfields; |
6279 | TYPE_FIELDS (rtype)(rtype)->main_type->fields = |
6280 | (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field))((rtype)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(rtype)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((nfields * sizeof (struct field))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (nfields * sizeof (struct field))); |
6281 | memcpy (TYPE_FIELDS (rtype)(rtype)->main_type->fields, TYPE_FIELDS (type)(type)->main_type->fields, |
6282 | sizeof (struct field) * nfields); |
6283 | TYPE_NAME (rtype)(rtype)->main_type->name = ada_type_name (type); |
6284 | TYPE_TAG_NAME (rtype)(rtype)->main_type->tag_name = NULL((void*)0); |
6285 | TYPE_FLAGS (rtype)(rtype)->main_type->flags |= TYPE_FLAG_FIXED_INSTANCE(1 << 15); |
6286 | TYPE_LENGTH (rtype)(rtype)->length = TYPE_LENGTH (type)(type)->length; |
6287 | |
6288 | branch_type = to_fixed_variant_branch_type |
6289 | (TYPE_FIELD_TYPE (type, variant_field)(((type)->main_type->fields[variant_field]).type), |
6290 | cond_offset_host (valaddr, |
6291 | TYPE_FIELD_BITPOS (type, variant_field)(((type)->main_type->fields[variant_field]).loc.bitpos) |
6292 | / TARGET_CHAR_BIT8), |
6293 | cond_offset_target (address, |
6294 | TYPE_FIELD_BITPOS (type, variant_field)(((type)->main_type->fields[variant_field]).loc.bitpos) |
6295 | / TARGET_CHAR_BIT8), dval); |
6296 | if (branch_type == NULL((void*)0)) |
6297 | { |
6298 | int f; |
6299 | for (f = variant_field + 1; f < nfields; f += 1) |
6300 | TYPE_FIELDS (rtype)(rtype)->main_type->fields[f - 1] = TYPE_FIELDS (rtype)(rtype)->main_type->fields[f]; |
6301 | TYPE_NFIELDS (rtype)(rtype)->main_type->nfields -= 1; |
6302 | } |
6303 | else |
6304 | { |
6305 | TYPE_FIELD_TYPE (rtype, variant_field)(((rtype)->main_type->fields[variant_field]).type) = branch_type; |
6306 | TYPE_FIELD_NAME (rtype, variant_field)(((rtype)->main_type->fields[variant_field]).name) = "S"; |
6307 | TYPE_FIELD_BITSIZE (rtype, variant_field)(((rtype)->main_type->fields[variant_field]).bitsize) = 0; |
6308 | TYPE_LENGTH (rtype)(rtype)->length += TYPE_LENGTH (branch_type)(branch_type)->length; |
6309 | } |
6310 | TYPE_LENGTH (rtype)(rtype)->length -= TYPE_LENGTH (TYPE_FIELD_TYPE (type, variant_field))((((type)->main_type->fields[variant_field]).type))-> length; |
6311 | |
6312 | value_free_to_mark (mark); |
6313 | return rtype; |
6314 | } |
6315 | |
6316 | /* An ordinary record type (with fixed-length fields) that describes |
6317 | the value at (TYPE0, VALADDR, ADDRESS) [see explanation at |
6318 | beginning of this section]. Any necessary discriminants' values |
6319 | should be in DVAL, a record value; it may be NULL if the object |
6320 | at ADDR itself contains any necessary discriminant values. |
6321 | Additionally, VALADDR and ADDRESS may also be NULL if no discriminant |
6322 | values from the record are needed. Except in the case that DVAL, |
6323 | VALADDR, and ADDRESS are all 0 or NULL, a variant field (unless |
6324 | unchecked) is replaced by a particular branch of the variant. |
6325 | |
6326 | NOTE: the case in which DVAL and VALADDR are NULL and ADDRESS is 0 |
6327 | is questionable and may be removed. It can arise during the |
6328 | processing of an unconstrained-array-of-record type where all the |
6329 | variant branches have exactly the same size. This is because in |
6330 | such cases, the compiler does not bother to use the XVS convention |
6331 | when encoding the record. I am currently dubious of this |
6332 | shortcut and suspect the compiler should be altered. FIXME. */ |
6333 | |
6334 | static struct type * |
6335 | to_fixed_record_type (struct type *type0, char *valaddr, |
6336 | CORE_ADDR address, struct value *dval) |
6337 | { |
6338 | struct type *templ_type; |
6339 | |
6340 | if (TYPE_FLAGS (type0)(type0)->main_type->flags & TYPE_FLAG_FIXED_INSTANCE(1 << 15)) |
6341 | return type0; |
6342 | |
6343 | templ_type = dynamic_template_type (type0); |
6344 | |
6345 | if (templ_type != NULL((void*)0)) |
6346 | return template_to_fixed_record_type (templ_type, valaddr, address, dval); |
6347 | else if (variant_field_index (type0) >= 0) |
6348 | { |
6349 | if (dval == NULL((void*)0) && valaddr == NULL((void*)0) && address == 0) |
6350 | return type0; |
6351 | return to_record_with_fixed_variant_part (type0, valaddr, address, |
6352 | dval); |
6353 | } |
6354 | else |
6355 | { |
6356 | TYPE_FLAGS (type0)(type0)->main_type->flags |= TYPE_FLAG_FIXED_INSTANCE(1 << 15); |
6357 | return type0; |
6358 | } |
6359 | |
6360 | } |
6361 | |
6362 | /* An ordinary record type (with fixed-length fields) that describes |
6363 | the value at (VAR_TYPE0, VALADDR, ADDRESS), where VAR_TYPE0 is a |
6364 | union type. Any necessary discriminants' values should be in DVAL, |
6365 | a record value. That is, this routine selects the appropriate |
6366 | branch of the union at ADDR according to the discriminant value |
6367 | indicated in the union's type name. */ |
6368 | |
6369 | static struct type * |
6370 | to_fixed_variant_branch_type (struct type *var_type0, char *valaddr, |
6371 | CORE_ADDR address, struct value *dval) |
6372 | { |
6373 | int which; |
6374 | struct type *templ_type; |
6375 | struct type *var_type; |
6376 | |
6377 | if (TYPE_CODE (var_type0)(var_type0)->main_type->code == TYPE_CODE_PTR) |
6378 | var_type = TYPE_TARGET_TYPE (var_type0)(var_type0)->main_type->target_type; |
6379 | else |
6380 | var_type = var_type0; |
6381 | |
6382 | templ_type = ada_find_parallel_type (var_type, "___XVU"); |
6383 | |
6384 | if (templ_type != NULL((void*)0)) |
6385 | var_type = templ_type; |
6386 | |
6387 | which = |
6388 | ada_which_variant_applies (var_type, |
6389 | VALUE_TYPE (dval)(dval)->type, VALUE_CONTENTS (dval)((void)((dval)->lazy && value_fetch_lazy(dval)), ( (char *) (dval)->aligner.contents + (dval)->embedded_offset ))); |
6390 | |
6391 | if (which < 0) |
6392 | return empty_record (TYPE_OBJFILE (var_type)(var_type)->main_type->objfile); |
6393 | else if (is_dynamic_field (var_type, which)) |
6394 | return to_fixed_record_type |
6395 | (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (var_type, which))((((var_type)->main_type->fields[which]).type))->main_type ->target_type, |
6396 | valaddr, address, dval); |
6397 | else if (variant_field_index (TYPE_FIELD_TYPE (var_type, which)(((var_type)->main_type->fields[which]).type)) >= 0) |
6398 | return |
6399 | to_fixed_record_type |
6400 | (TYPE_FIELD_TYPE (var_type, which)(((var_type)->main_type->fields[which]).type), valaddr, address, dval); |
6401 | else |
6402 | return TYPE_FIELD_TYPE (var_type, which)(((var_type)->main_type->fields[which]).type); |
6403 | } |
6404 | |
6405 | /* Assuming that TYPE0 is an array type describing the type of a value |
6406 | at ADDR, and that DVAL describes a record containing any |
6407 | discriminants used in TYPE0, returns a type for the value that |
6408 | contains no dynamic components (that is, no components whose sizes |
6409 | are determined by run-time quantities). Unless IGNORE_TOO_BIG is |
6410 | true, gives an error message if the resulting type's size is over |
6411 | varsize_limit. */ |
6412 | |
6413 | static struct type * |
6414 | to_fixed_array_type (struct type *type0, struct value *dval, |
6415 | int ignore_too_big) |
6416 | { |
6417 | struct type *index_type_desc; |
6418 | struct type *result; |
6419 | |
6420 | if (ada_is_packed_array_type (type0) /* revisit? */ |
6421 | || (TYPE_FLAGS (type0)(type0)->main_type->flags & TYPE_FLAG_FIXED_INSTANCE(1 << 15))) |
6422 | return type0; |
6423 | |
6424 | index_type_desc = ada_find_parallel_type (type0, "___XA"); |
6425 | if (index_type_desc == NULL((void*)0)) |
6426 | { |
6427 | struct type *elt_type0 = ada_check_typedef (TYPE_TARGET_TYPE (type0)(type0)->main_type->target_type); |
6428 | /* NOTE: elt_type---the fixed version of elt_type0---should never |
6429 | depend on the contents of the array in properly constructed |
6430 | debugging data. */ |
6431 | struct type *elt_type = ada_to_fixed_type (elt_type0, 0, 0, dval); |
6432 | |
6433 | if (elt_type0 == elt_type) |
6434 | result = type0; |
6435 | else |
6436 | result = create_array_type (alloc_type (TYPE_OBJFILE (type0)(type0)->main_type->objfile), |
6437 | elt_type, TYPE_INDEX_TYPE (type0)(((type0)->main_type->fields[0]).type)); |
6438 | } |
6439 | else |
6440 | { |
6441 | int i; |
6442 | struct type *elt_type0; |
6443 | |
6444 | elt_type0 = type0; |
6445 | for (i = TYPE_NFIELDS (index_type_desc)(index_type_desc)->main_type->nfields; i > 0; i -= 1) |
6446 | elt_type0 = TYPE_TARGET_TYPE (elt_type0)(elt_type0)->main_type->target_type; |
6447 | |
6448 | /* NOTE: result---the fixed version of elt_type0---should never |
6449 | depend on the contents of the array in properly constructed |
6450 | debugging data. */ |
6451 | result = ada_to_fixed_type (ada_check_typedef (elt_type0), 0, 0, dval); |
6452 | for (i = TYPE_NFIELDS (index_type_desc)(index_type_desc)->main_type->nfields - 1; i >= 0; i -= 1) |
6453 | { |
6454 | struct type *range_type = |
6455 | to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, i)(((index_type_desc)->main_type->fields[i]).name), |
6456 | dval, TYPE_OBJFILE (type0)(type0)->main_type->objfile); |
6457 | result = create_array_type (alloc_type (TYPE_OBJFILE (type0)(type0)->main_type->objfile), |
6458 | result, range_type); |
6459 | } |
6460 | if (!ignore_too_big && TYPE_LENGTH (result)(result)->length > varsize_limit) |
6461 | error ("array type with dynamic size is larger than varsize-limit"); |
6462 | } |
6463 | |
6464 | TYPE_FLAGS (result)(result)->main_type->flags |= TYPE_FLAG_FIXED_INSTANCE(1 << 15); |
6465 | return result; |
6466 | } |
6467 | |
6468 | |
6469 | /* A standard type (containing no dynamically sized components) |
6470 | corresponding to TYPE for the value (TYPE, VALADDR, ADDRESS) |
6471 | DVAL describes a record containing any discriminants used in TYPE0, |
6472 | and may be NULL if there are none, or if the object of type TYPE at |
6473 | ADDRESS or in VALADDR contains these discriminants. */ |
6474 | |
6475 | struct type * |
6476 | ada_to_fixed_type (struct type *type, char *valaddr, |
6477 | CORE_ADDR address, struct value *dval) |
6478 | { |
6479 | type = ada_check_typedef (type); |
6480 | switch (TYPE_CODE (type)(type)->main_type->code) |
6481 | { |
6482 | default: |
6483 | return type; |
6484 | case TYPE_CODE_STRUCT: |
6485 | { |
6486 | struct type *static_type = to_static_fixed_type (type); |
6487 | if (ada_is_tagged_type (static_type, 0)) |
6488 | { |
6489 | struct type *real_type = |
6490 | type_from_tag (value_tag_from_contents_and_address (static_type, |
6491 | valaddr, |
6492 | address)); |
6493 | if (real_type != NULL((void*)0)) |
6494 | type = real_type; |
6495 | } |
6496 | return to_fixed_record_type (type, valaddr, address, NULL((void*)0)); |
6497 | } |
6498 | case TYPE_CODE_ARRAY: |
6499 | return to_fixed_array_type (type, dval, 1); |
6500 | case TYPE_CODE_UNION: |
6501 | if (dval == NULL((void*)0)) |
6502 | return type; |
6503 | else |
6504 | return to_fixed_variant_branch_type (type, valaddr, address, dval); |
6505 | } |
6506 | } |
6507 | |
6508 | /* A standard (static-sized) type corresponding as well as possible to |
6509 | TYPE0, but based on no runtime data. */ |
6510 | |
6511 | static struct type * |
6512 | to_static_fixed_type (struct type *type0) |
6513 | { |
6514 | struct type *type; |
6515 | |
6516 | if (type0 == NULL((void*)0)) |
6517 | return NULL((void*)0); |
6518 | |
6519 | if (TYPE_FLAGS (type0)(type0)->main_type->flags & TYPE_FLAG_FIXED_INSTANCE(1 << 15)) |
6520 | return type0; |
6521 | |
6522 | type0 = ada_check_typedef (type0); |
6523 | |
6524 | switch (TYPE_CODE (type0)(type0)->main_type->code) |
6525 | { |
6526 | default: |
6527 | return type0; |
6528 | case TYPE_CODE_STRUCT: |
6529 | type = dynamic_template_type (type0); |
6530 | if (type != NULL((void*)0)) |
6531 | return template_to_static_fixed_type (type); |
6532 | else |
6533 | return template_to_static_fixed_type (type0); |
6534 | case TYPE_CODE_UNION: |
6535 | type = ada_find_parallel_type (type0, "___XVU"); |
6536 | if (type != NULL((void*)0)) |
6537 | return template_to_static_fixed_type (type); |
6538 | else |
6539 | return template_to_static_fixed_type (type0); |
6540 | } |
6541 | } |
6542 | |
6543 | /* A static approximation of TYPE with all type wrappers removed. */ |
6544 | |
6545 | static struct type * |
6546 | static_unwrap_type (struct type *type) |
6547 | { |
6548 | if (ada_is_aligner_type (type)) |
6549 | { |
6550 | struct type *type1 = TYPE_FIELD_TYPE (ada_check_typedef (type), 0)(((ada_check_typedef (type))->main_type->fields[0]).type ); |
6551 | if (ada_type_name (type1) == NULL((void*)0)) |
6552 | TYPE_NAME (type1)(type1)->main_type->name = ada_type_name (type); |
6553 | |
6554 | return static_unwrap_type (type1); |
6555 | } |
6556 | else |
6557 | { |
6558 | struct type *raw_real_type = ada_get_base_type (type); |
6559 | if (raw_real_type == type) |
6560 | return type; |
6561 | else |
6562 | return to_static_fixed_type (raw_real_type); |
6563 | } |
6564 | } |
6565 | |
6566 | /* In some cases, incomplete and private types require |
6567 | cross-references that are not resolved as records (for example, |
6568 | type Foo; |
6569 | type FooP is access Foo; |
6570 | V: FooP; |
6571 | type Foo is array ...; |
6572 | ). In these cases, since there is no mechanism for producing |
6573 | cross-references to such types, we instead substitute for FooP a |
6574 | stub enumeration type that is nowhere resolved, and whose tag is |
6575 | the name of the actual type. Call these types "non-record stubs". */ |
6576 | |
6577 | /* A type equivalent to TYPE that is not a non-record stub, if one |
6578 | exists, otherwise TYPE. */ |
6579 | |
6580 | struct type * |
6581 | ada_check_typedef (struct type *type) |
6582 | { |
6583 | CHECK_TYPEDEF (type)(type) = check_typedef (type); |
6584 | if (type == NULL((void*)0) || TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_ENUM |
6585 | || (TYPE_FLAGS (type)(type)->main_type->flags & TYPE_FLAG_STUB(1 << 2)) == 0 |
6586 | || TYPE_TAG_NAME (type)(type)->main_type->tag_name == NULL((void*)0)) |
6587 | return type; |
6588 | else |
6589 | { |
6590 | char *name = TYPE_TAG_NAME (type)(type)->main_type->tag_name; |
6591 | struct type *type1 = ada_find_any_type (name); |
6592 | return (type1 == NULL((void*)0)) ? type : type1; |
6593 | } |
6594 | } |
6595 | |
6596 | /* A value representing the data at VALADDR/ADDRESS as described by |
6597 | type TYPE0, but with a standard (static-sized) type that correctly |
6598 | describes it. If VAL0 is not NULL and TYPE0 already is a standard |
6599 | type, then return VAL0 [this feature is simply to avoid redundant |
6600 | creation of struct values]. */ |
6601 | |
6602 | static struct value * |
6603 | ada_to_fixed_value_create (struct type *type0, CORE_ADDR address, |
6604 | struct value *val0) |
6605 | { |
6606 | struct type *type = ada_to_fixed_type (type0, 0, address, NULL((void*)0)); |
6607 | if (type == type0 && val0 != NULL((void*)0)) |
6608 | return val0; |
6609 | else |
6610 | return value_from_contents_and_address (type, 0, address); |
6611 | } |
6612 | |
6613 | /* A value representing VAL, but with a standard (static-sized) type |
6614 | that correctly describes it. Does not necessarily create a new |
6615 | value. */ |
6616 | |
6617 | static struct value * |
6618 | ada_to_fixed_value (struct value *val) |
6619 | { |
6620 | return ada_to_fixed_value_create (VALUE_TYPE (val)(val)->type, |
6621 | VALUE_ADDRESS (val)(val)->location.address + VALUE_OFFSET (val)(val)->offset, |
6622 | val); |
6623 | } |
6624 | |
6625 | /* A value representing VAL, but with a standard (static-sized) type |
6626 | chosen to approximate the real type of VAL as well as possible, but |
6627 | without consulting any runtime values. For Ada dynamic-sized |
6628 | types, therefore, the type of the result is likely to be inaccurate. */ |
6629 | |
6630 | struct value * |
6631 | ada_to_static_fixed_value (struct value *val) |
6632 | { |
6633 | struct type *type = |
6634 | to_static_fixed_type (static_unwrap_type (VALUE_TYPE (val)(val)->type)); |
6635 | if (type == VALUE_TYPE (val)(val)->type) |
6636 | return val; |
6637 | else |
6638 | return coerce_unspec_val_to_type (val, type); |
6639 | } |
6640 | |
6641 | |
6642 | /* Attributes */ |
6643 | |
6644 | /* Table mapping attribute numbers to names. |
6645 | NOTE: Keep up to date with enum ada_attribute definition in ada-lang.h. */ |
6646 | |
6647 | static const char *attribute_names[] = { |
6648 | "<?>", |
6649 | |
6650 | "first", |
6651 | "last", |
6652 | "length", |
6653 | "image", |
6654 | "max", |
6655 | "min", |
6656 | "modulus", |
6657 | "pos", |
6658 | "size", |
6659 | "tag", |
6660 | "val", |
6661 | 0 |
6662 | }; |
6663 | |
6664 | const char * |
6665 | ada_attribute_name (enum exp_opcode n) |
6666 | { |
6667 | if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL) |
6668 | return attribute_names[n - OP_ATR_FIRST + 1]; |
6669 | else |
6670 | return attribute_names[0]; |
6671 | } |
6672 | |
6673 | /* Evaluate the 'POS attribute applied to ARG. */ |
6674 | |
6675 | static LONGESTlong |
6676 | pos_atr (struct value *arg) |
6677 | { |
6678 | struct type *type = VALUE_TYPE (arg)(arg)->type; |
6679 | |
6680 | if (!discrete_type_p (type)) |
6681 | error ("'POS only defined on discrete types"); |
6682 | |
6683 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ENUM) |
6684 | { |
6685 | int i; |
6686 | LONGESTlong v = value_as_long (arg); |
6687 | |
6688 | for (i = 0; i < TYPE_NFIELDS (type)(type)->main_type->nfields; i += 1) |
6689 | { |
6690 | if (v == TYPE_FIELD_BITPOS (type, i)(((type)->main_type->fields[i]).loc.bitpos)) |
6691 | return i; |
6692 | } |
6693 | error ("enumeration value is invalid: can't find 'POS"); |
6694 | } |
6695 | else |
6696 | return value_as_long (arg); |
6697 | } |
6698 | |
6699 | static struct value * |
6700 | value_pos_atr (struct value *arg) |
6701 | { |
6702 | return value_from_longest (builtin_type_int, pos_atr (arg)); |
6703 | } |
6704 | |
6705 | /* Evaluate the TYPE'VAL attribute applied to ARG. */ |
6706 | |
6707 | static struct value * |
6708 | value_val_atr (struct type *type, struct value *arg) |
6709 | { |
6710 | if (!discrete_type_p (type)) |
6711 | error ("'VAL only defined on discrete types"); |
6712 | if (!integer_type_p (VALUE_TYPE (arg)(arg)->type)) |
6713 | error ("'VAL requires integral argument"); |
6714 | |
6715 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ENUM) |
6716 | { |
6717 | long pos = value_as_long (arg); |
6718 | if (pos < 0 || pos >= TYPE_NFIELDS (type)(type)->main_type->nfields) |
6719 | error ("argument to 'VAL out of range"); |
6720 | return value_from_longest (type, TYPE_FIELD_BITPOS (type, pos)(((type)->main_type->fields[pos]).loc.bitpos)); |
6721 | } |
6722 | else |
6723 | return value_from_longest (type, value_as_long (arg)); |
6724 | } |
6725 | |
6726 | |
6727 | /* Evaluation */ |
6728 | |
6729 | /* True if TYPE appears to be an Ada character type. |
6730 | [At the moment, this is true only for Character and Wide_Character; |
6731 | It is a heuristic test that could stand improvement]. */ |
6732 | |
6733 | int |
6734 | ada_is_character_type (struct type *type) |
6735 | { |
6736 | const char *name = ada_type_name (type); |
6737 | return |
6738 | name != NULL((void*)0) |
6739 | && (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_CHAR |
6740 | || TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_INT |
6741 | || TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_RANGE) |
6742 | && (strcmp (name, "character") == 0 |
6743 | || strcmp (name, "wide_character") == 0 |
6744 | || strcmp (name, "unsigned char") == 0); |
6745 | } |
6746 | |
6747 | /* True if TYPE appears to be an Ada string type. */ |
6748 | |
6749 | int |
6750 | ada_is_string_type (struct type *type) |
6751 | { |
6752 | type = ada_check_typedef (type); |
6753 | if (type != NULL((void*)0) |
6754 | && TYPE_CODE (type)(type)->main_type->code != TYPE_CODE_PTR |
6755 | && (ada_is_simple_array_type (type) |
6756 | || ada_is_array_descriptor_type (type)) |
6757 | && ada_array_arity (type) == 1) |
6758 | { |
6759 | struct type *elttype = ada_array_element_type (type, 1); |
6760 | |
6761 | return ada_is_character_type (elttype); |
6762 | } |
6763 | else |
6764 | return 0; |
6765 | } |
6766 | |
6767 | |
6768 | /* True if TYPE is a struct type introduced by the compiler to force the |
6769 | alignment of a value. Such types have a single field with a |
6770 | distinctive name. */ |
6771 | |
6772 | int |
6773 | ada_is_aligner_type (struct type *type) |
6774 | { |
6775 | type = ada_check_typedef (type); |
6776 | |
6777 | /* If we can find a parallel XVS type, then the XVS type should |
6778 | be used instead of this type. And hence, this is not an aligner |
6779 | type. */ |
6780 | if (ada_find_parallel_type (type, "___XVS") != NULL((void*)0)) |
6781 | return 0; |
6782 | |
6783 | return (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_STRUCT |
6784 | && TYPE_NFIELDS (type)(type)->main_type->nfields == 1 |
6785 | && strcmp (TYPE_FIELD_NAME (type, 0)(((type)->main_type->fields[0]).name), "F") == 0); |
6786 | } |
6787 | |
6788 | /* If there is an ___XVS-convention type parallel to SUBTYPE, return |
6789 | the parallel type. */ |
6790 | |
6791 | struct type * |
6792 | ada_get_base_type (struct type *raw_type) |
6793 | { |
6794 | struct type *real_type_namer; |
6795 | struct type *raw_real_type; |
6796 | |
6797 | if (raw_type == NULL((void*)0) || TYPE_CODE (raw_type)(raw_type)->main_type->code != TYPE_CODE_STRUCT) |
6798 | return raw_type; |
6799 | |
6800 | real_type_namer = ada_find_parallel_type (raw_type, "___XVS"); |
6801 | if (real_type_namer == NULL((void*)0) |
6802 | || TYPE_CODE (real_type_namer)(real_type_namer)->main_type->code != TYPE_CODE_STRUCT |
6803 | || TYPE_NFIELDS (real_type_namer)(real_type_namer)->main_type->nfields != 1) |
6804 | return raw_type; |
6805 | |
6806 | raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0)(((real_type_namer)->main_type->fields[0]).name)); |
6807 | if (raw_real_type == NULL((void*)0)) |
6808 | return raw_type; |
6809 | else |
6810 | return raw_real_type; |
6811 | } |
6812 | |
6813 | /* The type of value designated by TYPE, with all aligners removed. */ |
6814 | |
6815 | struct type * |
6816 | ada_aligned_type (struct type *type) |
6817 | { |
6818 | if (ada_is_aligner_type (type)) |
6819 | return ada_aligned_type (TYPE_FIELD_TYPE (type, 0)(((type)->main_type->fields[0]).type)); |
6820 | else |
6821 | return ada_get_base_type (type); |
6822 | } |
6823 | |
6824 | |
6825 | /* The address of the aligned value in an object at address VALADDR |
6826 | having type TYPE. Assumes ada_is_aligner_type (TYPE). */ |
6827 | |
6828 | char * |
6829 | ada_aligned_value_addr (struct type *type, char *valaddr) |
6830 | { |
6831 | if (ada_is_aligner_type (type)) |
6832 | return ada_aligned_value_addr (TYPE_FIELD_TYPE (type, 0)(((type)->main_type->fields[0]).type), |
6833 | valaddr + |
6834 | TYPE_FIELD_BITPOS (type,(((type)->main_type->fields[0]).loc.bitpos) |
6835 | 0)(((type)->main_type->fields[0]).loc.bitpos) / TARGET_CHAR_BIT8); |
6836 | else |
6837 | return valaddr; |
6838 | } |
6839 | |
6840 | |
6841 | |
6842 | /* The printed representation of an enumeration literal with encoded |
6843 | name NAME. The value is good to the next call of ada_enum_name. */ |
6844 | const char * |
6845 | ada_enum_name (const char *name) |
6846 | { |
6847 | static char *result; |
6848 | static size_t result_len = 0; |
6849 | char *tmp; |
6850 | |
6851 | /* First, unqualify the enumeration name: |
6852 | 1. Search for the last '.' character. If we find one, then skip |
6853 | all the preceeding characters, the unqualified name starts |
6854 | right after that dot. |
6855 | 2. Otherwise, we may be debugging on a target where the compiler |
6856 | translates dots into "__". Search forward for double underscores, |
6857 | but stop searching when we hit an overloading suffix, which is |
6858 | of the form "__" followed by digits. */ |
6859 | |
6860 | tmp = strrchr (name, '.'); |
6861 | if (tmp != NULL((void*)0)) |
6862 | name = tmp + 1; |
6863 | else |
6864 | { |
6865 | while ((tmp = strstr (name, "__")) != NULL((void*)0)) |
6866 | { |
6867 | if (isdigit (tmp[2])) |
6868 | break; |
6869 | else |
6870 | name = tmp + 2; |
6871 | } |
6872 | } |
6873 | |
6874 | if (name[0] == 'Q') |
6875 | { |
6876 | int v; |
6877 | if (name[1] == 'U' || name[1] == 'W') |
6878 | { |
6879 | if (sscanf (name + 2, "%x", &v) != 1) |
6880 | return name; |
6881 | } |
6882 | else |
6883 | return name; |
6884 | |
6885 | GROW_VECT (result, result_len, 16)if ((result_len) < (16)) grow_vect ((void**) &(result) , &(result_len), (16), sizeof(*(result)));; |
6886 | if (isascii (v) && isprint (v)) |
6887 | sprintf (result, "'%c'", v); |
6888 | else if (name[1] == 'U') |
6889 | sprintf (result, "[\"%02x\"]", v); |
6890 | else |
6891 | sprintf (result, "[\"%04x\"]", v); |
6892 | |
6893 | return result; |
6894 | } |
6895 | else |
6896 | { |
6897 | tmp = strstr (name, "__"); |
6898 | if (tmp == NULL((void*)0)) |
6899 | tmp = strstr (name, "$"); |
6900 | if (tmp != NULL((void*)0)) |
6901 | { |
6902 | GROW_VECT (result, result_len, tmp - name + 1)if ((result_len) < (tmp - name + 1)) grow_vect ((void**) & (result), &(result_len), (tmp - name + 1), sizeof(*(result )));; |
6903 | strncpy (result, name, tmp - name); |
6904 | result[tmp - name] = '\0'; |
6905 | return result; |
6906 | } |
6907 | |
6908 | return name; |
6909 | } |
6910 | } |
6911 | |
6912 | static struct value * |
6913 | evaluate_subexp (struct type *expect_type, struct expression *exp, int *pos, |
6914 | enum noside noside) |
6915 | { |
6916 | return (*exp->language_defn->la_exp_desc->evaluate_exp) |
6917 | (expect_type, exp, pos, noside); |
6918 | } |
6919 | |
6920 | /* Evaluate the subexpression of EXP starting at *POS as for |
6921 | evaluate_type, updating *POS to point just past the evaluated |
6922 | expression. */ |
6923 | |
6924 | static struct value * |
6925 | evaluate_subexp_type (struct expression *exp, int *pos) |
6926 | { |
6927 | return (*exp->language_defn->la_exp_desc->evaluate_exp) |
6928 | (NULL_TYPE((struct type *) 0), exp, pos, EVAL_AVOID_SIDE_EFFECTS); |
6929 | } |
6930 | |
6931 | /* If VAL is wrapped in an aligner or subtype wrapper, return the |
6932 | value it wraps. */ |
6933 | |
6934 | static struct value * |
6935 | unwrap_value (struct value *val) |
6936 | { |
6937 | struct type *type = ada_check_typedef (VALUE_TYPE (val)(val)->type); |
6938 | if (ada_is_aligner_type (type)) |
6939 | { |
6940 | struct value *v = value_struct_elt (&val, NULL((void*)0), "F", |
6941 | NULL((void*)0), "internal structure"); |
6942 | struct type *val_type = ada_check_typedef (VALUE_TYPE (v)(v)->type); |
6943 | if (ada_type_name (val_type) == NULL((void*)0)) |
6944 | TYPE_NAME (val_type)(val_type)->main_type->name = ada_type_name (type); |
6945 | |
6946 | return unwrap_value (v); |
6947 | } |
6948 | else |
6949 | { |
6950 | struct type *raw_real_type = |
6951 | ada_check_typedef (ada_get_base_type (type)); |
6952 | |
6953 | if (type == raw_real_type) |
6954 | return val; |
6955 | |
6956 | return |
6957 | coerce_unspec_val_to_type |
6958 | (val, ada_to_fixed_type (raw_real_type, 0, |
6959 | VALUE_ADDRESS (val)(val)->location.address + VALUE_OFFSET (val)(val)->offset, |
6960 | NULL((void*)0))); |
6961 | } |
6962 | } |
6963 | |
6964 | static struct value * |
6965 | cast_to_fixed (struct type *type, struct value *arg) |
6966 | { |
6967 | LONGESTlong val; |
6968 | |
6969 | if (type == VALUE_TYPE (arg)(arg)->type) |
6970 | return arg; |
6971 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg)(arg)->type)) |
6972 | val = ada_float_to_fixed (type, |
6973 | ada_fixed_to_float (VALUE_TYPE (arg)(arg)->type, |
6974 | value_as_long (arg))); |
6975 | else |
6976 | { |
6977 | DOUBLEST argd = |
6978 | value_as_double (value_cast (builtin_type_double, value_copy (arg))); |
6979 | val = ada_float_to_fixed (type, argd); |
6980 | } |
6981 | |
6982 | return value_from_longest (type, val); |
6983 | } |
6984 | |
6985 | static struct value * |
6986 | cast_from_fixed_to_double (struct value *arg) |
6987 | { |
6988 | DOUBLEST val = ada_fixed_to_float (VALUE_TYPE (arg)(arg)->type, |
6989 | value_as_long (arg)); |
6990 | return value_from_double (builtin_type_double, val); |
6991 | } |
6992 | |
6993 | /* Coerce VAL as necessary for assignment to an lval of type TYPE, and |
6994 | return the converted value. */ |
6995 | |
6996 | static struct value * |
6997 | coerce_for_assign (struct type *type, struct value *val) |
6998 | { |
6999 | struct type *type2 = VALUE_TYPE (val)(val)->type; |
7000 | if (type == type2) |
7001 | return val; |
7002 | |
7003 | type2 = ada_check_typedef (type2); |
7004 | type = ada_check_typedef (type); |
7005 | |
7006 | if (TYPE_CODE (type2)(type2)->main_type->code == TYPE_CODE_PTR |
7007 | && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY) |
7008 | { |
7009 | val = ada_value_ind (val); |
7010 | type2 = VALUE_TYPE (val)(val)->type; |
7011 | } |
7012 | |
7013 | if (TYPE_CODE (type2)(type2)->main_type->code == TYPE_CODE_ARRAY |
7014 | && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY) |
7015 | { |
7016 | if (TYPE_LENGTH (type2)(type2)->length != TYPE_LENGTH (type)(type)->length |
7017 | || TYPE_LENGTH (TYPE_TARGET_TYPE (type2))((type2)->main_type->target_type)->length |
7018 | != TYPE_LENGTH (TYPE_TARGET_TYPE (type2))((type2)->main_type->target_type)->length) |
7019 | error ("Incompatible types in assignment"); |
7020 | VALUE_TYPE (val)(val)->type = type; |
7021 | } |
7022 | return val; |
7023 | } |
7024 | |
7025 | static struct value * |
7026 | ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) |
7027 | { |
7028 | struct value *val; |
7029 | struct type *type1, *type2; |
7030 | LONGESTlong v, v1, v2; |
7031 | |
7032 | COERCE_REF (arg1)do { struct type *value_type_arg_tmp = check_typedef ((arg1)-> type); if ((value_type_arg_tmp)->main_type->code == TYPE_CODE_REF ) arg1 = value_at_lazy ((value_type_arg_tmp)->main_type-> target_type, unpack_pointer ((arg1)->type, ((void)((arg1)-> lazy && value_fetch_lazy(arg1)), ((char *) (arg1)-> aligner.contents + (arg1)->embedded_offset))), ((arg1)-> bfd_section)); } while (0); |
7033 | COERCE_REF (arg2)do { struct type *value_type_arg_tmp = check_typedef ((arg2)-> type); if ((value_type_arg_tmp)->main_type->code == TYPE_CODE_REF ) arg2 = value_at_lazy ((value_type_arg_tmp)->main_type-> target_type, unpack_pointer ((arg2)->type, ((void)((arg2)-> lazy && value_fetch_lazy(arg2)), ((char *) (arg2)-> aligner.contents + (arg2)->embedded_offset))), ((arg2)-> bfd_section)); } while (0); |
7034 | type1 = base_type (ada_check_typedef (VALUE_TYPE (arg1)(arg1)->type)); |
7035 | type2 = base_type (ada_check_typedef (VALUE_TYPE (arg2)(arg2)->type)); |
7036 | |
7037 | if (TYPE_CODE (type1)(type1)->main_type->code != TYPE_CODE_INT |
7038 | || TYPE_CODE (type2)(type2)->main_type->code != TYPE_CODE_INT) |
7039 | return value_binop (arg1, arg2, op); |
7040 | |
7041 | switch (op) |
7042 | { |
7043 | case BINOP_MOD: |
7044 | case BINOP_DIV: |
7045 | case BINOP_REM: |
7046 | break; |
7047 | default: |
7048 | return value_binop (arg1, arg2, op); |
7049 | } |
7050 | |
7051 | v2 = value_as_long (arg2); |
7052 | if (v2 == 0) |
7053 | error ("second operand of %s must not be zero.", op_string (op)); |
7054 | |
7055 | if (TYPE_UNSIGNED (type1)((type1)->main_type->flags & (1 << 0)) || op == BINOP_MOD) |
7056 | return value_binop (arg1, arg2, op); |
7057 | |
7058 | v1 = value_as_long (arg1); |
7059 | switch (op) |
7060 | { |
7061 | case BINOP_DIV: |
7062 | v = v1 / v2; |
7063 | if (!TRUNCATION_TOWARDS_ZERO((-5 / 2) == -2) && v1 * (v1 % v2) < 0) |
7064 | v += v > 0 ? -1 : 1; |
7065 | break; |
7066 | case BINOP_REM: |
7067 | v = v1 % v2; |
7068 | if (v * v1 < 0) |
7069 | v -= v2; |
7070 | break; |
7071 | default: |
7072 | /* Should not reach this point. */ |
7073 | v = 0; |
7074 | } |
7075 | |
7076 | val = allocate_value (type1); |
7077 | store_unsigned_integer (VALUE_CONTENTS_RAW (val)((char *) (val)->aligner.contents + (val)->embedded_offset ), |
7078 | TYPE_LENGTH (VALUE_TYPE (val))((val)->type)->length, v); |
7079 | return val; |
7080 | } |
7081 | |
7082 | static int |
7083 | ada_value_equal (struct value *arg1, struct value *arg2) |
7084 | { |
7085 | if (ada_is_direct_array_type (VALUE_TYPE (arg1)(arg1)->type) |
7086 | || ada_is_direct_array_type (VALUE_TYPE (arg2)(arg2)->type)) |
7087 | { |
7088 | arg1 = ada_coerce_to_simple_array (arg1); |
7089 | arg2 = ada_coerce_to_simple_array (arg2); |
7090 | if (TYPE_CODE (VALUE_TYPE (arg1))((arg1)->type)->main_type->code != TYPE_CODE_ARRAY |
7091 | || TYPE_CODE (VALUE_TYPE (arg2))((arg2)->type)->main_type->code != TYPE_CODE_ARRAY) |
7092 | error ("Attempt to compare array with non-array"); |
7093 | /* FIXME: The following works only for types whose |
7094 | representations use all bits (no padding or undefined bits) |
7095 | and do not have user-defined equality. */ |
7096 | return |
7097 | TYPE_LENGTH (VALUE_TYPE (arg1))((arg1)->type)->length == TYPE_LENGTH (VALUE_TYPE (arg2))((arg2)->type)->length |
7098 | && memcmp (VALUE_CONTENTS (arg1)((void)((arg1)->lazy && value_fetch_lazy(arg1)), ( (char *) (arg1)->aligner.contents + (arg1)->embedded_offset )), VALUE_CONTENTS (arg2)((void)((arg2)->lazy && value_fetch_lazy(arg2)), ( (char *) (arg2)->aligner.contents + (arg2)->embedded_offset )), |
7099 | TYPE_LENGTH (VALUE_TYPE (arg1))((arg1)->type)->length) == 0; |
7100 | } |
7101 | return value_equal (arg1, arg2); |
7102 | } |
7103 | |
7104 | struct value * |
7105 | ada_evaluate_subexp (struct type *expect_type, struct expression *exp, |
7106 | int *pos, enum noside noside) |
7107 | { |
7108 | enum exp_opcode op; |
7109 | int tem, tem2, tem3; |
7110 | int pc; |
7111 | struct value *arg1 = NULL((void*)0), *arg2 = NULL((void*)0), *arg3; |
7112 | struct type *type; |
7113 | int nargs; |
7114 | struct value **argvec; |
7115 | |
7116 | pc = *pos; |
7117 | *pos += 1; |
7118 | op = exp->elts[pc].opcode; |
7119 | |
7120 | switch (op) |
7121 | { |
7122 | default: |
7123 | *pos -= 1; |
7124 | return |
7125 | unwrap_value (evaluate_subexp_standard |
7126 | (expect_type, exp, pos, noside)); |
7127 | |
7128 | case OP_STRING: |
7129 | { |
7130 | struct value *result; |
7131 | *pos -= 1; |
7132 | result = evaluate_subexp_standard (expect_type, exp, pos, noside); |
7133 | /* The result type will have code OP_STRING, bashed there from |
7134 | OP_ARRAY. Bash it back. */ |
7135 | if (TYPE_CODE (VALUE_TYPE (result))((result)->type)->main_type->code == TYPE_CODE_STRING) |
7136 | TYPE_CODE (VALUE_TYPE (result))((result)->type)->main_type->code = TYPE_CODE_ARRAY; |
7137 | return result; |
7138 | } |
7139 | |
7140 | case UNOP_CAST: |
7141 | (*pos) += 2; |
7142 | type = exp->elts[pc + 1].type; |
7143 | arg1 = evaluate_subexp (type, exp, pos, noside); |
7144 | if (noside == EVAL_SKIP) |
7145 | goto nosideret; |
7146 | if (type != ada_check_typedef (VALUE_TYPE (arg1)(arg1)->type)) |
7147 | { |
7148 | if (ada_is_fixed_point_type (type)) |
7149 | arg1 = cast_to_fixed (type, arg1); |
7150 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg1)(arg1)->type)) |
7151 | arg1 = value_cast (type, cast_from_fixed_to_double (arg1)); |
7152 | else if (VALUE_LVAL (arg1)(arg1)->lval == lval_memory) |
7153 | { |
7154 | /* This is in case of the really obscure (and undocumented, |
7155 | but apparently expected) case of (Foo) Bar.all, where Bar |
7156 | is an integer constant and Foo is a dynamic-sized type. |
7157 | If we don't do this, ARG1 will simply be relabeled with |
7158 | TYPE. */ |
7159 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7160 | return value_zero (to_static_fixed_type (type), not_lval); |
7161 | arg1 = |
7162 | ada_to_fixed_value_create |
7163 | (type, VALUE_ADDRESS (arg1)(arg1)->location.address + VALUE_OFFSET (arg1)(arg1)->offset, 0); |
7164 | } |
7165 | else |
7166 | arg1 = value_cast (type, arg1); |
7167 | } |
7168 | return arg1; |
7169 | |
7170 | case UNOP_QUAL: |
7171 | (*pos) += 2; |
7172 | type = exp->elts[pc + 1].type; |
7173 | return ada_evaluate_subexp (type, exp, pos, noside); |
7174 | |
7175 | case BINOP_ASSIGN: |
7176 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7177 | arg2 = evaluate_subexp (VALUE_TYPE (arg1)(arg1)->type, exp, pos, noside); |
7178 | if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS) |
7179 | return arg1; |
7180 | if (ada_is_fixed_point_type (VALUE_TYPE (arg1)(arg1)->type)) |
7181 | arg2 = cast_to_fixed (VALUE_TYPE (arg1)(arg1)->type, arg2); |
7182 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg2)(arg2)->type)) |
7183 | error |
7184 | ("Fixed-point values must be assigned to fixed-point variables"); |
7185 | else |
7186 | arg2 = coerce_for_assign (VALUE_TYPE (arg1)(arg1)->type, arg2); |
7187 | return ada_value_assign (arg1, arg2); |
7188 | |
7189 | case BINOP_ADD: |
7190 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); |
7191 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); |
7192 | if (noside == EVAL_SKIP) |
7193 | goto nosideret; |
7194 | if ((ada_is_fixed_point_type (VALUE_TYPE (arg1)(arg1)->type) |
7195 | || ada_is_fixed_point_type (VALUE_TYPE (arg2)(arg2)->type)) |
7196 | && VALUE_TYPE (arg1)(arg1)->type != VALUE_TYPE (arg2)(arg2)->type) |
7197 | error ("Operands of fixed-point addition must have the same type"); |
7198 | return value_cast (VALUE_TYPE (arg1)(arg1)->type, value_add (arg1, arg2)); |
7199 | |
7200 | case BINOP_SUB: |
7201 | arg1 = evaluate_subexp_with_coercion (exp, pos, noside); |
7202 | arg2 = evaluate_subexp_with_coercion (exp, pos, noside); |
7203 | if (noside == EVAL_SKIP) |
7204 | goto nosideret; |
7205 | if ((ada_is_fixed_point_type (VALUE_TYPE (arg1)(arg1)->type) |
7206 | || ada_is_fixed_point_type (VALUE_TYPE (arg2)(arg2)->type)) |
7207 | && VALUE_TYPE (arg1)(arg1)->type != VALUE_TYPE (arg2)(arg2)->type) |
7208 | error ("Operands of fixed-point subtraction must have the same type"); |
7209 | return value_cast (VALUE_TYPE (arg1)(arg1)->type, value_sub (arg1, arg2)); |
7210 | |
7211 | case BINOP_MUL: |
7212 | case BINOP_DIV: |
7213 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7214 | arg2 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7215 | if (noside == EVAL_SKIP) |
7216 | goto nosideret; |
7217 | else if (noside == EVAL_AVOID_SIDE_EFFECTS |
7218 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) |
7219 | return value_zero (VALUE_TYPE (arg1)(arg1)->type, not_lval); |
7220 | else |
7221 | { |
7222 | if (ada_is_fixed_point_type (VALUE_TYPE (arg1)(arg1)->type)) |
7223 | arg1 = cast_from_fixed_to_double (arg1); |
7224 | if (ada_is_fixed_point_type (VALUE_TYPE (arg2)(arg2)->type)) |
7225 | arg2 = cast_from_fixed_to_double (arg2); |
7226 | return ada_value_binop (arg1, arg2, op); |
7227 | } |
7228 | |
7229 | case BINOP_REM: |
7230 | case BINOP_MOD: |
7231 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7232 | arg2 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7233 | if (noside == EVAL_SKIP) |
7234 | goto nosideret; |
7235 | else if (noside == EVAL_AVOID_SIDE_EFFECTS |
7236 | && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) |
7237 | return value_zero (VALUE_TYPE (arg1)(arg1)->type, not_lval); |
7238 | else |
7239 | return ada_value_binop (arg1, arg2, op); |
7240 | |
7241 | case BINOP_EQUAL: |
7242 | case BINOP_NOTEQUAL: |
7243 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7244 | arg2 = evaluate_subexp (VALUE_TYPE (arg1)(arg1)->type, exp, pos, noside); |
7245 | if (noside == EVAL_SKIP) |
7246 | goto nosideret; |
7247 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7248 | tem = 0; |
7249 | else |
7250 | tem = ada_value_equal (arg1, arg2); |
7251 | if (op == BINOP_NOTEQUAL) |
7252 | tem = !tem; |
7253 | return value_from_longest (LA_BOOL_TYPElang_bool_type (), (LONGESTlong) tem); |
7254 | |
7255 | case UNOP_NEG: |
7256 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7257 | if (noside == EVAL_SKIP) |
7258 | goto nosideret; |
7259 | else if (ada_is_fixed_point_type (VALUE_TYPE (arg1)(arg1)->type)) |
7260 | return value_cast (VALUE_TYPE (arg1)(arg1)->type, value_neg (arg1)); |
7261 | else |
7262 | return value_neg (arg1); |
7263 | |
7264 | case OP_VAR_VALUE: |
7265 | *pos -= 1; |
7266 | if (noside == EVAL_SKIP) |
7267 | { |
7268 | *pos += 4; |
7269 | goto nosideret; |
7270 | } |
7271 | else if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol)(exp->elts[pc + 2].symbol)->domain == UNDEF_DOMAIN) |
7272 | /* Only encountered when an unresolved symbol occurs in a |
7273 | context other than a function call, in which case, it is |
7274 | illegal. */ |
7275 | error ("Unexpected unresolved symbol, %s, during evaluation", |
7276 | SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)(demangle ? (symbol_natural_name (&(exp->elts[pc + 2]. symbol)->ginfo)) : (exp->elts[pc + 2].symbol)->ginfo .name)); |
7277 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7278 | { |
7279 | *pos += 4; |
7280 | return value_zero |
7281 | (to_static_fixed_type |
7282 | (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol)(exp->elts[pc + 2].symbol)->type)), |
7283 | not_lval); |
7284 | } |
7285 | else |
7286 | { |
7287 | arg1 = |
7288 | unwrap_value (evaluate_subexp_standard |
7289 | (expect_type, exp, pos, noside)); |
7290 | return ada_to_fixed_value (arg1); |
7291 | } |
7292 | |
7293 | case OP_FUNCALL: |
7294 | (*pos) += 2; |
7295 | |
7296 | /* Allocate arg vector, including space for the function to be |
7297 | called in argvec[0] and a terminating NULL. */ |
7298 | nargs = longest_to_int (exp->elts[pc + 1].longconst); |
7299 | argvec = |
7300 | (struct value **) alloca (sizeof (struct value *) * (nargs + 2))__builtin_alloca(sizeof (struct value *) * (nargs + 2)); |
7301 | |
7302 | if (exp->elts[*pos].opcode == OP_VAR_VALUE |
7303 | && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol)(exp->elts[pc + 5].symbol)->domain == UNDEF_DOMAIN) |
7304 | error ("Unexpected unresolved symbol, %s, during evaluation", |
7305 | SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol)(demangle ? (symbol_natural_name (&(exp->elts[pc + 5]. symbol)->ginfo)) : (exp->elts[pc + 5].symbol)->ginfo .name)); |
7306 | else |
7307 | { |
7308 | for (tem = 0; tem <= nargs; tem += 1) |
7309 | argvec[tem] = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7310 | argvec[tem] = 0; |
7311 | |
7312 | if (noside == EVAL_SKIP) |
7313 | goto nosideret; |
7314 | } |
7315 | |
7316 | if (ada_is_packed_array_type (desc_base_type (VALUE_TYPE (argvec[0])(argvec[0])->type))) |
7317 | argvec[0] = ada_coerce_to_simple_array (argvec[0]); |
7318 | else if (TYPE_CODE (VALUE_TYPE (argvec[0]))((argvec[0])->type)->main_type->code == TYPE_CODE_REF |
7319 | || (TYPE_CODE (VALUE_TYPE (argvec[0]))((argvec[0])->type)->main_type->code == TYPE_CODE_ARRAY |
7320 | && VALUE_LVAL (argvec[0])(argvec[0])->lval == lval_memory)) |
7321 | argvec[0] = value_addr (argvec[0]); |
7322 | |
7323 | type = ada_check_typedef (VALUE_TYPE (argvec[0])(argvec[0])->type); |
7324 | if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR) |
7325 | { |
7326 | switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type)))(ada_check_typedef ((type)->main_type->target_type))-> main_type->code) |
7327 | { |
7328 | case TYPE_CODE_FUNC: |
7329 | type = ada_check_typedef (TYPE_TARGET_TYPE (type)(type)->main_type->target_type); |
7330 | break; |
7331 | case TYPE_CODE_ARRAY: |
7332 | break; |
7333 | case TYPE_CODE_STRUCT: |
7334 | if (noside != EVAL_AVOID_SIDE_EFFECTS) |
7335 | argvec[0] = ada_value_ind (argvec[0]); |
7336 | type = ada_check_typedef (TYPE_TARGET_TYPE (type)(type)->main_type->target_type); |
7337 | break; |
7338 | default: |
7339 | error ("cannot subscript or call something of type `%s'", |
7340 | ada_type_name (VALUE_TYPE (argvec[0])(argvec[0])->type)); |
7341 | break; |
7342 | } |
7343 | } |
7344 | |
7345 | switch (TYPE_CODE (type)(type)->main_type->code) |
7346 | { |
7347 | case TYPE_CODE_FUNC: |
7348 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7349 | return allocate_value (TYPE_TARGET_TYPE (type)(type)->main_type->target_type); |
7350 | return call_function_by_hand (argvec[0], nargs, argvec + 1); |
7351 | case TYPE_CODE_STRUCT: |
7352 | { |
7353 | int arity; |
7354 | |
7355 | arity = ada_array_arity (type); |
7356 | type = ada_array_element_type (type, nargs); |
7357 | if (type == NULL((void*)0)) |
7358 | error ("cannot subscript or call a record"); |
7359 | if (arity != nargs) |
7360 | error ("wrong number of subscripts; expecting %d", arity); |
7361 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7362 | return allocate_value (ada_aligned_type (type)); |
7363 | return |
7364 | unwrap_value (ada_value_subscript |
7365 | (argvec[0], nargs, argvec + 1)); |
7366 | } |
7367 | case TYPE_CODE_ARRAY: |
7368 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7369 | { |
7370 | type = ada_array_element_type (type, nargs); |
7371 | if (type == NULL((void*)0)) |
7372 | error ("element type of array unknown"); |
7373 | else |
7374 | return allocate_value (ada_aligned_type (type)); |
7375 | } |
7376 | return |
7377 | unwrap_value (ada_value_subscript |
7378 | (ada_coerce_to_simple_array (argvec[0]), |
7379 | nargs, argvec + 1)); |
7380 | case TYPE_CODE_PTR: /* Pointer to array */ |
7381 | type = to_fixed_array_type (TYPE_TARGET_TYPE (type)(type)->main_type->target_type, NULL((void*)0), 1); |
7382 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7383 | { |
7384 | type = ada_array_element_type (type, nargs); |
7385 | if (type == NULL((void*)0)) |
7386 | error ("element type of array unknown"); |
7387 | else |
7388 | return allocate_value (ada_aligned_type (type)); |
7389 | } |
7390 | return |
7391 | unwrap_value (ada_value_ptr_subscript (argvec[0], type, |
7392 | nargs, argvec + 1)); |
7393 | |
7394 | default: |
7395 | error ("Attempt to index or call something other than an " |
7396 | "array or function"); |
7397 | } |
7398 | |
7399 | case TERNOP_SLICE: |
7400 | { |
7401 | struct value *array = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7402 | struct value *low_bound_val = |
7403 | evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7404 | struct value *high_bound_val = |
7405 | evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7406 | LONGESTlong low_bound; |
7407 | LONGESTlong high_bound; |
7408 | COERCE_REF (low_bound_val)do { struct type *value_type_arg_tmp = check_typedef ((low_bound_val )->type); if ((value_type_arg_tmp)->main_type->code == TYPE_CODE_REF) low_bound_val = value_at_lazy ((value_type_arg_tmp )->main_type->target_type, unpack_pointer ((low_bound_val )->type, ((void)((low_bound_val)->lazy && value_fetch_lazy (low_bound_val)), ((char *) (low_bound_val)->aligner.contents + (low_bound_val)->embedded_offset))), ((low_bound_val)-> bfd_section)); } while (0); |
7409 | COERCE_REF (high_bound_val)do { struct type *value_type_arg_tmp = check_typedef ((high_bound_val )->type); if ((value_type_arg_tmp)->main_type->code == TYPE_CODE_REF) high_bound_val = value_at_lazy ((value_type_arg_tmp )->main_type->target_type, unpack_pointer ((high_bound_val )->type, ((void)((high_bound_val)->lazy && value_fetch_lazy (high_bound_val)), ((char *) (high_bound_val)->aligner.contents + (high_bound_val)->embedded_offset))), ((high_bound_val) ->bfd_section)); } while (0); |
7410 | low_bound = pos_atr (low_bound_val); |
7411 | high_bound = pos_atr (high_bound_val); |
7412 | |
7413 | if (noside == EVAL_SKIP) |
7414 | goto nosideret; |
7415 | |
7416 | /* If this is a reference to an aligner type, then remove all |
7417 | the aligners. */ |
7418 | if (TYPE_CODE (VALUE_TYPE (array))((array)->type)->main_type->code == TYPE_CODE_REF |
7419 | && ada_is_aligner_type (TYPE_TARGET_TYPE (VALUE_TYPE (array))((array)->type)->main_type->target_type)) |
7420 | TYPE_TARGET_TYPE (VALUE_TYPE (array))((array)->type)->main_type->target_type = |
7421 | ada_aligned_type (TYPE_TARGET_TYPE (VALUE_TYPE (array))((array)->type)->main_type->target_type); |
7422 | |
7423 | if (ada_is_packed_array_type (VALUE_TYPE (array)(array)->type)) |
7424 | error ("cannot slice a packed array"); |
7425 | |
7426 | /* If this is a reference to an array or an array lvalue, |
7427 | convert to a pointer. */ |
7428 | if (TYPE_CODE (VALUE_TYPE (array))((array)->type)->main_type->code == TYPE_CODE_REF |
7429 | || (TYPE_CODE (VALUE_TYPE (array))((array)->type)->main_type->code == TYPE_CODE_ARRAY |
7430 | && VALUE_LVAL (array)(array)->lval == lval_memory)) |
7431 | array = value_addr (array); |
7432 | |
7433 | if (noside == EVAL_AVOID_SIDE_EFFECTS |
7434 | && ada_is_array_descriptor_type (ada_check_typedef |
7435 | (VALUE_TYPE (array)(array)->type))) |
7436 | return empty_array (ada_type_of_array (array, 0), low_bound); |
7437 | |
7438 | array = ada_coerce_to_simple_array_ptr (array); |
7439 | |
7440 | /* If we have more than one level of pointer indirection, |
7441 | dereference the value until we get only one level. */ |
7442 | while (TYPE_CODE (VALUE_TYPE (array))((array)->type)->main_type->code == TYPE_CODE_PTR |
7443 | && (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (array)))(((array)->type)->main_type->target_type)->main_type ->code |
7444 | == TYPE_CODE_PTR)) |
7445 | array = value_ind (array); |
7446 | |
7447 | /* Make sure we really do have an array type before going further, |
7448 | to avoid a SEGV when trying to get the index type or the target |
7449 | type later down the road if the debug info generated by |
7450 | the compiler is incorrect or incomplete. */ |
7451 | if (!ada_is_simple_array_type (VALUE_TYPE (array)(array)->type)) |
7452 | error ("cannot take slice of non-array"); |
7453 | |
7454 | if (TYPE_CODE (VALUE_TYPE (array))((array)->type)->main_type->code == TYPE_CODE_PTR) |
7455 | { |
7456 | if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS) |
7457 | return empty_array (TYPE_TARGET_TYPE (VALUE_TYPE (array))((array)->type)->main_type->target_type, |
7458 | low_bound); |
7459 | else |
7460 | { |
7461 | struct type *arr_type0 = |
7462 | to_fixed_array_type (TYPE_TARGET_TYPE (VALUE_TYPE (array))((array)->type)->main_type->target_type, |
7463 | NULL((void*)0), 1); |
7464 | return ada_value_slice_ptr (array, arr_type0, |
7465 | (int) low_bound, |
7466 | (int) high_bound); |
7467 | } |
7468 | } |
7469 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7470 | return array; |
7471 | else if (high_bound < low_bound) |
7472 | return empty_array (VALUE_TYPE (array)(array)->type, low_bound); |
7473 | else |
7474 | return ada_value_slice (array, (int) low_bound, (int) high_bound); |
7475 | } |
7476 | |
7477 | case UNOP_IN_RANGE: |
7478 | (*pos) += 2; |
7479 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7480 | type = exp->elts[pc + 1].type; |
7481 | |
7482 | if (noside == EVAL_SKIP) |
7483 | goto nosideret; |
7484 | |
7485 | switch (TYPE_CODE (type)(type)->main_type->code) |
7486 | { |
7487 | default: |
7488 | lim_warning ("Membership test incompletely implemented; " |
7489 | "always returns true"); |
7490 | return value_from_longest (builtin_type_int, (LONGESTlong) 1); |
7491 | |
7492 | case TYPE_CODE_RANGE: |
7493 | arg2 = value_from_longest (builtin_type_int, TYPE_LOW_BOUND (type)(((type)->main_type->fields[0]).loc.bitpos)); |
7494 | arg3 = value_from_longest (builtin_type_int, |
7495 | TYPE_HIGH_BOUND (type)(((type)->main_type->fields[1]).loc.bitpos)); |
7496 | return |
7497 | value_from_longest (builtin_type_int, |
7498 | (value_less (arg1, arg3) |
7499 | || value_equal (arg1, arg3)) |
7500 | && (value_less (arg2, arg1) |
7501 | || value_equal (arg2, arg1))); |
7502 | } |
7503 | |
7504 | case BINOP_IN_BOUNDS: |
7505 | (*pos) += 2; |
7506 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7507 | arg2 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7508 | |
7509 | if (noside == EVAL_SKIP) |
7510 | goto nosideret; |
7511 | |
7512 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7513 | return value_zero (builtin_type_int, not_lval); |
7514 | |
7515 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
7516 | |
7517 | if (tem < 1 || tem > ada_array_arity (VALUE_TYPE (arg2)(arg2)->type)) |
7518 | error ("invalid dimension number to '%s", "range"); |
7519 | |
7520 | arg3 = ada_array_bound (arg2, tem, 1); |
7521 | arg2 = ada_array_bound (arg2, tem, 0); |
7522 | |
7523 | return |
7524 | value_from_longest (builtin_type_int, |
7525 | (value_less (arg1, arg3) |
7526 | || value_equal (arg1, arg3)) |
7527 | && (value_less (arg2, arg1) |
7528 | || value_equal (arg2, arg1))); |
7529 | |
7530 | case TERNOP_IN_RANGE: |
7531 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7532 | arg2 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7533 | arg3 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7534 | |
7535 | if (noside == EVAL_SKIP) |
7536 | goto nosideret; |
7537 | |
7538 | return |
7539 | value_from_longest (builtin_type_int, |
7540 | (value_less (arg1, arg3) |
7541 | || value_equal (arg1, arg3)) |
7542 | && (value_less (arg2, arg1) |
7543 | || value_equal (arg2, arg1))); |
7544 | |
7545 | case OP_ATR_FIRST: |
7546 | case OP_ATR_LAST: |
7547 | case OP_ATR_LENGTH: |
7548 | { |
7549 | struct type *type_arg; |
7550 | if (exp->elts[*pos].opcode == OP_TYPE) |
7551 | { |
7552 | evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, EVAL_SKIP); |
7553 | arg1 = NULL((void*)0); |
7554 | type_arg = exp->elts[pc + 2].type; |
7555 | } |
7556 | else |
7557 | { |
7558 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7559 | type_arg = NULL((void*)0); |
7560 | } |
7561 | |
7562 | if (exp->elts[*pos].opcode != OP_LONG) |
7563 | error ("illegal operand to '%s", ada_attribute_name (op)); |
7564 | tem = longest_to_int (exp->elts[*pos + 2].longconst); |
7565 | *pos += 4; |
7566 | |
7567 | if (noside == EVAL_SKIP) |
7568 | goto nosideret; |
7569 | |
7570 | if (type_arg == NULL((void*)0)) |
7571 | { |
7572 | arg1 = ada_coerce_ref (arg1); |
7573 | |
7574 | if (ada_is_packed_array_type (VALUE_TYPE (arg1)(arg1)->type)) |
7575 | arg1 = ada_coerce_to_simple_array (arg1); |
7576 | |
7577 | if (tem < 1 || tem > ada_array_arity (VALUE_TYPE (arg1)(arg1)->type)) |
7578 | error ("invalid dimension number to '%s", |
7579 | ada_attribute_name (op)); |
7580 | |
7581 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7582 | { |
7583 | type = ada_index_type (VALUE_TYPE (arg1)(arg1)->type, tem); |
7584 | if (type == NULL((void*)0)) |
7585 | error |
7586 | ("attempt to take bound of something that is not an array"); |
7587 | return allocate_value (type); |
7588 | } |
7589 | |
7590 | switch (op) |
7591 | { |
7592 | default: /* Should never happen. */ |
7593 | error ("unexpected attribute encountered"); |
7594 | case OP_ATR_FIRST: |
7595 | return ada_array_bound (arg1, tem, 0); |
7596 | case OP_ATR_LAST: |
7597 | return ada_array_bound (arg1, tem, 1); |
7598 | case OP_ATR_LENGTH: |
7599 | return ada_array_length (arg1, tem); |
7600 | } |
7601 | } |
7602 | else if (discrete_type_p (type_arg)) |
7603 | { |
7604 | struct type *range_type; |
7605 | char *name = ada_type_name (type_arg); |
7606 | range_type = NULL((void*)0); |
7607 | if (name != NULL((void*)0) && TYPE_CODE (type_arg)(type_arg)->main_type->code != TYPE_CODE_ENUM) |
7608 | range_type = |
7609 | to_fixed_range_type (name, NULL((void*)0), TYPE_OBJFILE (type_arg)(type_arg)->main_type->objfile); |
7610 | if (range_type == NULL((void*)0)) |
7611 | range_type = type_arg; |
7612 | switch (op) |
7613 | { |
7614 | default: |
7615 | error ("unexpected attribute encountered"); |
7616 | case OP_ATR_FIRST: |
7617 | return discrete_type_low_bound (range_type); |
7618 | case OP_ATR_LAST: |
7619 | return discrete_type_high_bound (range_type); |
7620 | case OP_ATR_LENGTH: |
7621 | error ("the 'length attribute applies only to array types"); |
7622 | } |
7623 | } |
7624 | else if (TYPE_CODE (type_arg)(type_arg)->main_type->code == TYPE_CODE_FLT) |
7625 | error ("unimplemented type attribute"); |
7626 | else |
7627 | { |
7628 | LONGESTlong low, high; |
7629 | |
7630 | if (ada_is_packed_array_type (type_arg)) |
7631 | type_arg = decode_packed_array_type (type_arg); |
7632 | |
7633 | if (tem < 1 || tem > ada_array_arity (type_arg)) |
7634 | error ("invalid dimension number to '%s", |
7635 | ada_attribute_name (op)); |
7636 | |
7637 | type = ada_index_type (type_arg, tem); |
7638 | if (type == NULL((void*)0)) |
7639 | error |
7640 | ("attempt to take bound of something that is not an array"); |
7641 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7642 | return allocate_value (type); |
7643 | |
7644 | switch (op) |
7645 | { |
7646 | default: |
7647 | error ("unexpected attribute encountered"); |
7648 | case OP_ATR_FIRST: |
7649 | low = ada_array_bound_from_type (type_arg, tem, 0, &type); |
7650 | return value_from_longest (type, low); |
7651 | case OP_ATR_LAST: |
7652 | high = ada_array_bound_from_type (type_arg, tem, 1, &type); |
7653 | return value_from_longest (type, high); |
7654 | case OP_ATR_LENGTH: |
7655 | low = ada_array_bound_from_type (type_arg, tem, 0, &type); |
7656 | high = ada_array_bound_from_type (type_arg, tem, 1, NULL((void*)0)); |
7657 | return value_from_longest (type, high - low + 1); |
7658 | } |
7659 | } |
7660 | } |
7661 | |
7662 | case OP_ATR_TAG: |
7663 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7664 | if (noside == EVAL_SKIP) |
7665 | goto nosideret; |
7666 | |
7667 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7668 | return value_zero (ada_tag_type (arg1), not_lval); |
7669 | |
7670 | return ada_value_tag (arg1); |
7671 | |
7672 | case OP_ATR_MIN: |
7673 | case OP_ATR_MAX: |
7674 | evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, EVAL_SKIP); |
7675 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7676 | arg2 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7677 | if (noside == EVAL_SKIP) |
7678 | goto nosideret; |
7679 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7680 | return value_zero (VALUE_TYPE (arg1)(arg1)->type, not_lval); |
7681 | else |
7682 | return value_binop (arg1, arg2, |
7683 | op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX); |
7684 | |
7685 | case OP_ATR_MODULUS: |
7686 | { |
7687 | struct type *type_arg = exp->elts[pc + 2].type; |
7688 | evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, EVAL_SKIP); |
7689 | |
7690 | if (noside == EVAL_SKIP) |
7691 | goto nosideret; |
7692 | |
7693 | if (!ada_is_modular_type (type_arg)) |
7694 | error ("'modulus must be applied to modular type"); |
7695 | |
7696 | return value_from_longest (TYPE_TARGET_TYPE (type_arg)(type_arg)->main_type->target_type, |
7697 | ada_modulus (type_arg)); |
7698 | } |
7699 | |
7700 | |
7701 | case OP_ATR_POS: |
7702 | evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, EVAL_SKIP); |
7703 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7704 | if (noside == EVAL_SKIP) |
7705 | goto nosideret; |
7706 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7707 | return value_zero (builtin_type_int, not_lval); |
7708 | else |
7709 | return value_pos_atr (arg1); |
7710 | |
7711 | case OP_ATR_SIZE: |
7712 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7713 | if (noside == EVAL_SKIP) |
7714 | goto nosideret; |
7715 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7716 | return value_zero (builtin_type_int, not_lval); |
7717 | else |
7718 | return value_from_longest (builtin_type_int, |
7719 | TARGET_CHAR_BIT8 |
7720 | * TYPE_LENGTH (VALUE_TYPE (arg1))((arg1)->type)->length); |
7721 | |
7722 | case OP_ATR_VAL: |
7723 | evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, EVAL_SKIP); |
7724 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7725 | type = exp->elts[pc + 2].type; |
7726 | if (noside == EVAL_SKIP) |
7727 | goto nosideret; |
7728 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7729 | return value_zero (type, not_lval); |
7730 | else |
7731 | return value_val_atr (type, arg1); |
7732 | |
7733 | case BINOP_EXP: |
7734 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7735 | arg2 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7736 | if (noside == EVAL_SKIP) |
7737 | goto nosideret; |
7738 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7739 | return value_zero (VALUE_TYPE (arg1)(arg1)->type, not_lval); |
7740 | else |
7741 | return value_binop (arg1, arg2, op); |
7742 | |
7743 | case UNOP_PLUS: |
7744 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7745 | if (noside == EVAL_SKIP) |
7746 | goto nosideret; |
7747 | else |
7748 | return arg1; |
7749 | |
7750 | case UNOP_ABS: |
7751 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7752 | if (noside == EVAL_SKIP) |
7753 | goto nosideret; |
7754 | if (value_less (arg1, value_zero (VALUE_TYPE (arg1)(arg1)->type, not_lval))) |
7755 | return value_neg (arg1); |
7756 | else |
7757 | return arg1; |
7758 | |
7759 | case UNOP_IND: |
7760 | if (expect_type && TYPE_CODE (expect_type)(expect_type)->main_type->code == TYPE_CODE_PTR) |
7761 | expect_type = TYPE_TARGET_TYPE (ada_check_typedef (expect_type))(ada_check_typedef (expect_type))->main_type->target_type; |
7762 | arg1 = evaluate_subexp (expect_type, exp, pos, noside); |
7763 | if (noside == EVAL_SKIP) |
7764 | goto nosideret; |
7765 | type = ada_check_typedef (VALUE_TYPE (arg1)(arg1)->type); |
7766 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7767 | { |
7768 | if (ada_is_array_descriptor_type (type)) |
7769 | /* GDB allows dereferencing GNAT array descriptors. */ |
7770 | { |
7771 | struct type *arrType = ada_type_of_array (arg1, 0); |
7772 | if (arrType == NULL((void*)0)) |
7773 | error ("Attempt to dereference null array pointer."); |
7774 | return value_at_lazy (arrType, 0, NULL((void*)0)); |
7775 | } |
7776 | else if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_PTR |
7777 | || TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_REF |
7778 | /* In C you can dereference an array to get the 1st elt. */ |
7779 | || TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_ARRAY) |
7780 | { |
7781 | type = to_static_fixed_type |
7782 | (ada_aligned_type |
7783 | (ada_check_typedef (TYPE_TARGET_TYPE (type)(type)->main_type->target_type))); |
7784 | check_size (type); |
7785 | return value_zero (type, lval_memory); |
7786 | } |
7787 | else if (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_INT) |
7788 | /* GDB allows dereferencing an int. */ |
7789 | return value_zero (builtin_type_int, lval_memory); |
7790 | else |
7791 | error ("Attempt to take contents of a non-pointer value."); |
7792 | } |
7793 | arg1 = ada_coerce_ref (arg1); /* FIXME: What is this for?? */ |
7794 | type = ada_check_typedef (VALUE_TYPE (arg1)(arg1)->type); |
7795 | |
7796 | if (ada_is_array_descriptor_type (type)) |
7797 | /* GDB allows dereferencing GNAT array descriptors. */ |
7798 | return ada_coerce_to_simple_array (arg1); |
7799 | else |
7800 | return ada_value_ind (arg1); |
7801 | |
7802 | case STRUCTOP_STRUCT: |
7803 | tem = longest_to_int (exp->elts[pc + 1].longconst); |
7804 | (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1)(((tem + 1) + sizeof (union exp_element) - 1) / sizeof (union exp_element)); |
7805 | arg1 = evaluate_subexp (NULL_TYPE((struct type *) 0), exp, pos, noside); |
7806 | if (noside == EVAL_SKIP) |
7807 | goto nosideret; |
7808 | if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7809 | { |
7810 | struct type *type1 = VALUE_TYPE (arg1)(arg1)->type; |
7811 | if (ada_is_tagged_type (type1, 1)) |
7812 | { |
7813 | type = ada_lookup_struct_elt_type (type1, |
7814 | &exp->elts[pc + 2].string, |
7815 | 1, 1, NULL((void*)0)); |
7816 | if (type == NULL((void*)0)) |
7817 | /* In this case, we assume that the field COULD exist |
7818 | in some extension of the type. Return an object of |
7819 | "type" void, which will match any formal |
7820 | (see ada_type_match). */ |
7821 | return value_zero (builtin_type_void, lval_memory); |
7822 | } |
7823 | else |
7824 | type = |
7825 | ada_lookup_struct_elt_type (type1, &exp->elts[pc + 2].string, 1, |
7826 | 0, NULL((void*)0)); |
7827 | |
7828 | return value_zero (ada_aligned_type (type), lval_memory); |
7829 | } |
7830 | else |
7831 | return |
7832 | ada_to_fixed_value (unwrap_value |
7833 | (ada_value_struct_elt |
7834 | (arg1, &exp->elts[pc + 2].string, "record"))); |
7835 | case OP_TYPE: |
7836 | /* The value is not supposed to be used. This is here to make it |
7837 | easier to accommodate expressions that contain types. */ |
7838 | (*pos) += 2; |
7839 | if (noside == EVAL_SKIP) |
7840 | goto nosideret; |
7841 | else if (noside == EVAL_AVOID_SIDE_EFFECTS) |
7842 | return allocate_value (builtin_type_void); |
7843 | else |
7844 | error ("Attempt to use a type name as an expression"); |
7845 | } |
7846 | |
7847 | nosideret: |
7848 | return value_from_longest (builtin_type_long, (LONGESTlong) 1); |
7849 | } |
7850 | |
7851 | |
7852 | /* Fixed point */ |
7853 | |
7854 | /* If TYPE encodes an Ada fixed-point type, return the suffix of the |
7855 | type name that encodes the 'small and 'delta information. |
7856 | Otherwise, return NULL. */ |
7857 | |
7858 | static const char * |
7859 | fixed_type_info (struct type *type) |
7860 | { |
7861 | const char *name = ada_type_name (type); |
7862 | enum type_code code = (type == NULL((void*)0)) ? TYPE_CODE_UNDEF : TYPE_CODE (type)(type)->main_type->code; |
7863 | |
7864 | if ((code == TYPE_CODE_INT || code == TYPE_CODE_RANGE) && name != NULL((void*)0)) |
7865 | { |
7866 | const char *tail = strstr (name, "___XF_"); |
7867 | if (tail == NULL((void*)0)) |
7868 | return NULL((void*)0); |
7869 | else |
7870 | return tail + 5; |
7871 | } |
7872 | else if (code == TYPE_CODE_RANGE && TYPE_TARGET_TYPE (type)(type)->main_type->target_type != type) |
7873 | return fixed_type_info (TYPE_TARGET_TYPE (type)(type)->main_type->target_type); |
7874 | else |
7875 | return NULL((void*)0); |
7876 | } |
7877 | |
7878 | /* Returns non-zero iff TYPE represents an Ada fixed-point type. */ |
7879 | |
7880 | int |
7881 | ada_is_fixed_point_type (struct type *type) |
7882 | { |
7883 | return fixed_type_info (type) != NULL((void*)0); |
7884 | } |
7885 | |
7886 | /* Return non-zero iff TYPE represents a System.Address type. */ |
7887 | |
7888 | int |
7889 | ada_is_system_address_type (struct type *type) |
7890 | { |
7891 | return (TYPE_NAME (type)(type)->main_type->name |
7892 | && strcmp (TYPE_NAME (type)(type)->main_type->name, "system__address") == 0); |
7893 | } |
7894 | |
7895 | /* Assuming that TYPE is the representation of an Ada fixed-point |
7896 | type, return its delta, or -1 if the type is malformed and the |
7897 | delta cannot be determined. */ |
7898 | |
7899 | DOUBLEST |
7900 | ada_delta (struct type *type) |
7901 | { |
7902 | const char *encoding = fixed_type_info (type); |
7903 | long num, den; |
7904 | |
7905 | if (sscanf (encoding, "_%ld_%ld", &num, &den) < 2) |
7906 | return -1.0; |
7907 | else |
7908 | return (DOUBLEST) num / (DOUBLEST) den; |
7909 | } |
7910 | |
7911 | /* Assuming that ada_is_fixed_point_type (TYPE), return the scaling |
7912 | factor ('SMALL value) associated with the type. */ |
7913 | |
7914 | static DOUBLEST |
7915 | scaling_factor (struct type *type) |
7916 | { |
7917 | const char *encoding = fixed_type_info (type); |
7918 | unsigned long num0, den0, num1, den1; |
7919 | int n; |
7920 | |
7921 | n = sscanf (encoding, "_%lu_%lu_%lu_%lu", &num0, &den0, &num1, &den1); |
7922 | |
7923 | if (n < 2) |
7924 | return 1.0; |
7925 | else if (n == 4) |
7926 | return (DOUBLEST) num1 / (DOUBLEST) den1; |
7927 | else |
7928 | return (DOUBLEST) num0 / (DOUBLEST) den0; |
7929 | } |
7930 | |
7931 | |
7932 | /* Assuming that X is the representation of a value of fixed-point |
7933 | type TYPE, return its floating-point equivalent. */ |
7934 | |
7935 | DOUBLEST |
7936 | ada_fixed_to_float (struct type *type, LONGESTlong x) |
7937 | { |
7938 | return (DOUBLEST) x *scaling_factor (type); |
7939 | } |
7940 | |
7941 | /* The representation of a fixed-point value of type TYPE |
7942 | corresponding to the value X. */ |
7943 | |
7944 | LONGESTlong |
7945 | ada_float_to_fixed (struct type *type, DOUBLEST x) |
7946 | { |
7947 | return (LONGESTlong) (x / scaling_factor (type) + 0.5); |
7948 | } |
7949 | |
7950 | |
7951 | /* VAX floating formats */ |
7952 | |
7953 | /* Non-zero iff TYPE represents one of the special VAX floating-point |
7954 | types. */ |
7955 | |
7956 | int |
7957 | ada_is_vax_floating_type (struct type *type) |
7958 | { |
7959 | int name_len = |
7960 | (ada_type_name (type) == NULL((void*)0)) ? 0 : strlen (ada_type_name (type)); |
7961 | return |
7962 | name_len > 6 |
7963 | && (TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_INT |
7964 | || TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_RANGE) |
7965 | && strncmp (ada_type_name (type) + name_len - 6, "___XF", 5) == 0; |
7966 | } |
7967 | |
7968 | /* The type of special VAX floating-point type this is, assuming |
7969 | ada_is_vax_floating_point. */ |
7970 | |
7971 | int |
7972 | ada_vax_float_type_suffix (struct type *type) |
7973 | { |
7974 | return ada_type_name (type)[strlen (ada_type_name (type)) - 1]; |
7975 | } |
7976 | |
7977 | /* A value representing the special debugging function that outputs |
7978 | VAX floating-point values of the type represented by TYPE. Assumes |
7979 | ada_is_vax_floating_type (TYPE). */ |
7980 | |
7981 | struct value * |
7982 | ada_vax_float_print_function (struct type *type) |
7983 | { |
7984 | switch (ada_vax_float_type_suffix (type)) |
7985 | { |
7986 | case 'F': |
7987 | return get_var_value ("DEBUG_STRING_F", 0); |
7988 | case 'D': |
7989 | return get_var_value ("DEBUG_STRING_D", 0); |
7990 | case 'G': |
7991 | return get_var_value ("DEBUG_STRING_G", 0); |
7992 | default: |
7993 | error ("invalid VAX floating-point type"); |
7994 | } |
7995 | } |
7996 | |
7997 | |
7998 | /* Range types */ |
7999 | |
8000 | /* Scan STR beginning at position K for a discriminant name, and |
8001 | return the value of that discriminant field of DVAL in *PX. If |
8002 | PNEW_K is not null, put the position of the character beyond the |
8003 | name scanned in *PNEW_K. Return 1 if successful; return 0 and do |
8004 | not alter *PX and *PNEW_K if unsuccessful. */ |
8005 | |
8006 | static int |
8007 | scan_discrim_bound (char *str, int k, struct value *dval, LONGESTlong * px, |
8008 | int *pnew_k) |
8009 | { |
8010 | static char *bound_buffer = NULL((void*)0); |
8011 | static size_t bound_buffer_len = 0; |
8012 | char *bound; |
8013 | char *pend; |
8014 | struct value *bound_val; |
8015 | |
8016 | if (dval == NULL((void*)0) || str == NULL((void*)0) || str[k] == '\0') |
8017 | return 0; |
8018 | |
8019 | pend = strstr (str + k, "__"); |
8020 | if (pend == NULL((void*)0)) |
8021 | { |
8022 | bound = str + k; |
8023 | k += strlen (bound); |
8024 | } |
8025 | else |
8026 | { |
8027 | GROW_VECT (bound_buffer, bound_buffer_len, pend - (str + k) + 1)if ((bound_buffer_len) < (pend - (str + k) + 1)) grow_vect ((void**) &(bound_buffer), &(bound_buffer_len), (pend - (str + k) + 1), sizeof(*(bound_buffer)));; |
8028 | bound = bound_buffer; |
8029 | strncpy (bound_buffer, str + k, pend - (str + k)); |
8030 | bound[pend - (str + k)] = '\0'; |
8031 | k = pend - str; |
8032 | } |
8033 | |
8034 | bound_val = ada_search_struct_field (bound, dval, 0, VALUE_TYPE (dval)(dval)->type); |
8035 | if (bound_val == NULL((void*)0)) |
8036 | return 0; |
8037 | |
8038 | *px = value_as_long (bound_val); |
8039 | if (pnew_k != NULL((void*)0)) |
8040 | *pnew_k = k; |
8041 | return 1; |
8042 | } |
8043 | |
8044 | /* Value of variable named NAME in the current environment. If |
8045 | no such variable found, then if ERR_MSG is null, returns 0, and |
8046 | otherwise causes an error with message ERR_MSG. */ |
8047 | |
8048 | static struct value * |
8049 | get_var_value (char *name, char *err_msg) |
8050 | { |
8051 | struct ada_symbol_info *syms; |
8052 | int nsyms; |
8053 | |
8054 | nsyms = ada_lookup_symbol_list (name, get_selected_block (0), VAR_DOMAIN, |
8055 | &syms); |
8056 | |
8057 | if (nsyms != 1) |
8058 | { |
8059 | if (err_msg == NULL((void*)0)) |
8060 | return 0; |
8061 | else |
8062 | error ("%s", err_msg); |
8063 | } |
8064 | |
8065 | return value_of_variable (syms[0].sym, syms[0].block); |
8066 | } |
8067 | |
8068 | /* Value of integer variable named NAME in the current environment. If |
8069 | no such variable found, returns 0, and sets *FLAG to 0. If |
8070 | successful, sets *FLAG to 1. */ |
8071 | |
8072 | LONGESTlong |
8073 | get_int_var_value (char *name, int *flag) |
8074 | { |
8075 | struct value *var_val = get_var_value (name, 0); |
8076 | |
8077 | if (var_val == 0) |
8078 | { |
8079 | if (flag != NULL((void*)0)) |
8080 | *flag = 0; |
8081 | return 0; |
8082 | } |
8083 | else |
8084 | { |
8085 | if (flag != NULL((void*)0)) |
8086 | *flag = 1; |
8087 | return value_as_long (var_val); |
8088 | } |
8089 | } |
8090 | |
8091 | |
8092 | /* Return a range type whose base type is that of the range type named |
8093 | NAME in the current environment, and whose bounds are calculated |
8094 | from NAME according to the GNAT range encoding conventions. |
8095 | Extract discriminant values, if needed, from DVAL. If a new type |
8096 | must be created, allocate in OBJFILE's space. The bounds |
8097 | information, in general, is encoded in NAME, the base type given in |
8098 | the named range type. */ |
8099 | |
8100 | static struct type * |
8101 | to_fixed_range_type (char *name, struct value *dval, struct objfile *objfile) |
8102 | { |
8103 | struct type *raw_type = ada_find_any_type (name); |
8104 | struct type *base_type; |
8105 | char *subtype_info; |
8106 | |
8107 | if (raw_type == NULL((void*)0)) |
8108 | base_type = builtin_type_int; |
8109 | else if (TYPE_CODE (raw_type)(raw_type)->main_type->code == TYPE_CODE_RANGE) |
8110 | base_type = TYPE_TARGET_TYPE (raw_type)(raw_type)->main_type->target_type; |
8111 | else |
8112 | base_type = raw_type; |
8113 | |
8114 | subtype_info = strstr (name, "___XD"); |
8115 | if (subtype_info == NULL((void*)0)) |
8116 | return raw_type; |
8117 | else |
8118 | { |
8119 | static char *name_buf = NULL((void*)0); |
8120 | static size_t name_len = 0; |
8121 | int prefix_len = subtype_info - name; |
8122 | LONGESTlong L, U; |
8123 | struct type *type; |
8124 | char *bounds_str; |
8125 | int n; |
8126 | |
8127 | GROW_VECT (name_buf, name_len, prefix_len + 5)if ((name_len) < (prefix_len + 5)) grow_vect ((void**) & (name_buf), &(name_len), (prefix_len + 5), sizeof(*(name_buf )));; |
8128 | strncpy (name_buf, name, prefix_len); |
8129 | name_buf[prefix_len] = '\0'; |
8130 | |
8131 | subtype_info += 5; |
8132 | bounds_str = strchr (subtype_info, '_'); |
8133 | n = 1; |
8134 | |
8135 | if (*subtype_info == 'L') |
8136 | { |
8137 | if (!ada_scan_number (bounds_str, n, &L, &n) |
8138 | && !scan_discrim_bound (bounds_str, n, dval, &L, &n)) |
8139 | return raw_type; |
8140 | if (bounds_str[n] == '_') |
8141 | n += 2; |
8142 | else if (bounds_str[n] == '.') /* FIXME? SGI Workshop kludge. */ |
8143 | n += 1; |
8144 | subtype_info += 1; |
8145 | } |
8146 | else |
8147 | { |
8148 | int ok; |
8149 | strcpy (name_buf + prefix_len, "___L"); |
8150 | L = get_int_var_value (name_buf, &ok); |
8151 | if (!ok) |
8152 | { |
8153 | lim_warning ("Unknown lower bound, using 1."); |
8154 | L = 1; |
8155 | } |
8156 | } |
8157 | |
8158 | if (*subtype_info == 'U') |
8159 | { |
8160 | if (!ada_scan_number (bounds_str, n, &U, &n) |
8161 | && !scan_discrim_bound (bounds_str, n, dval, &U, &n)) |
8162 | return raw_type; |
8163 | } |
8164 | else |
8165 | { |
8166 | int ok; |
8167 | strcpy (name_buf + prefix_len, "___U"); |
8168 | U = get_int_var_value (name_buf, &ok); |
8169 | if (!ok) |
8170 | { |
8171 | lim_warning ("Unknown upper bound, using %ld.", (long) L); |
8172 | U = L; |
8173 | } |
8174 | } |
8175 | |
8176 | if (objfile == NULL((void*)0)) |
8177 | objfile = TYPE_OBJFILE (base_type)(base_type)->main_type->objfile; |
8178 | type = create_range_type (alloc_type (objfile), base_type, L, U); |
8179 | TYPE_NAME (type)(type)->main_type->name = name; |
8180 | return type; |
8181 | } |
8182 | } |
8183 | |
8184 | /* True iff NAME is the name of a range type. */ |
8185 | |
8186 | int |
8187 | ada_is_range_type_name (const char *name) |
8188 | { |
8189 | return (name != NULL((void*)0) && strstr (name, "___XD")); |
8190 | } |
8191 | |
8192 | |
8193 | /* Modular types */ |
8194 | |
8195 | /* True iff TYPE is an Ada modular type. */ |
8196 | |
8197 | int |
8198 | ada_is_modular_type (struct type *type) |
8199 | { |
8200 | struct type *subranged_type = base_type (type); |
8201 | |
8202 | return (subranged_type != NULL((void*)0) && TYPE_CODE (type)(type)->main_type->code == TYPE_CODE_RANGE |
8203 | && TYPE_CODE (subranged_type)(subranged_type)->main_type->code != TYPE_CODE_ENUM |
8204 | && TYPE_UNSIGNED (subranged_type)((subranged_type)->main_type->flags & (1 << 0 ))); |
8205 | } |
8206 | |
8207 | /* Assuming ada_is_modular_type (TYPE), the modulus of TYPE. */ |
8208 | |
8209 | ULONGESTunsigned long |
8210 | ada_modulus (struct type * type) |
8211 | { |
8212 | return (ULONGESTunsigned long) TYPE_HIGH_BOUND (type)(((type)->main_type->fields[1]).loc.bitpos) + 1; |
8213 | } |
8214 | |
8215 | /* Operators */ |
8216 | /* Information about operators given special treatment in functions |
8217 | below. */ |
8218 | /* Format: OP_DEFN (<operator>, <operator length>, <# args>, <binop>). */ |
8219 | |
8220 | #define ADA_OPERATORSOP_DEFN (OP_VAR_VALUE, 4, 0, 0) OP_DEFN (BINOP_IN_BOUNDS, 3, 2 , 0) OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) OP_DEFN (OP_ATR_FIRST , 1, 2, 0) OP_DEFN (OP_ATR_LAST, 1, 2, 0) OP_DEFN (OP_ATR_LENGTH , 1, 2, 0) OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) OP_DEFN (OP_ATR_MAX , 1, 3, 0) OP_DEFN (OP_ATR_MIN, 1, 3, 0) OP_DEFN (OP_ATR_MODULUS , 1, 1, 0) OP_DEFN (OP_ATR_POS, 1, 2, 0) OP_DEFN (OP_ATR_SIZE , 1, 1, 0) OP_DEFN (OP_ATR_TAG, 1, 1, 0) OP_DEFN (OP_ATR_VAL, 1, 2, 0) OP_DEFN (UNOP_QUAL, 3, 1, 0) OP_DEFN (UNOP_IN_RANGE , 3, 1, 0) \ |
8221 | OP_DEFN (OP_VAR_VALUE, 4, 0, 0) \ |
8222 | OP_DEFN (BINOP_IN_BOUNDS, 3, 2, 0) \ |
8223 | OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) \ |
8224 | OP_DEFN (OP_ATR_FIRST, 1, 2, 0) \ |
8225 | OP_DEFN (OP_ATR_LAST, 1, 2, 0) \ |
8226 | OP_DEFN (OP_ATR_LENGTH, 1, 2, 0) \ |
8227 | OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) \ |
8228 | OP_DEFN (OP_ATR_MAX, 1, 3, 0) \ |
8229 | OP_DEFN (OP_ATR_MIN, 1, 3, 0) \ |
8230 | OP_DEFN (OP_ATR_MODULUS, 1, 1, 0) \ |
8231 | OP_DEFN (OP_ATR_POS, 1, 2, 0) \ |
8232 | OP_DEFN (OP_ATR_SIZE, 1, 1, 0) \ |
8233 | OP_DEFN (OP_ATR_TAG, 1, 1, 0) \ |
8234 | OP_DEFN (OP_ATR_VAL, 1, 2, 0) \ |
8235 | OP_DEFN (UNOP_QUAL, 3, 1, 0) \ |
8236 | OP_DEFN (UNOP_IN_RANGE, 3, 1, 0) |
8237 | |
8238 | static void |
8239 | ada_operator_length (struct expression *exp, int pc, int *oplenp, int *argsp) |
8240 | { |
8241 | switch (exp->elts[pc - 1].opcode) |
8242 | { |
8243 | default: |
8244 | operator_length_standard (exp, pc, oplenp, argsp); |
8245 | break; |
8246 | |
8247 | #define OP_DEFN(op, len, args, binop) \ |
8248 | case op: *oplenp = len; *argsp = args; break; |
8249 | ADA_OPERATORSOP_DEFN (OP_VAR_VALUE, 4, 0, 0) OP_DEFN (BINOP_IN_BOUNDS, 3, 2 , 0) OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) OP_DEFN (OP_ATR_FIRST , 1, 2, 0) OP_DEFN (OP_ATR_LAST, 1, 2, 0) OP_DEFN (OP_ATR_LENGTH , 1, 2, 0) OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) OP_DEFN (OP_ATR_MAX , 1, 3, 0) OP_DEFN (OP_ATR_MIN, 1, 3, 0) OP_DEFN (OP_ATR_MODULUS , 1, 1, 0) OP_DEFN (OP_ATR_POS, 1, 2, 0) OP_DEFN (OP_ATR_SIZE , 1, 1, 0) OP_DEFN (OP_ATR_TAG, 1, 1, 0) OP_DEFN (OP_ATR_VAL, 1, 2, 0) OP_DEFN (UNOP_QUAL, 3, 1, 0) OP_DEFN (UNOP_IN_RANGE , 3, 1, 0); |
8250 | #undef OP_DEFN |
8251 | } |
8252 | } |
8253 | |
8254 | static char * |
8255 | ada_op_name (enum exp_opcode opcode) |
8256 | { |
8257 | switch (opcode) |
8258 | { |
8259 | default: |
8260 | return op_name_standard (opcode); |
8261 | #define OP_DEFN(op, len, args, binop) case op: return #op; |
8262 | ADA_OPERATORSOP_DEFN (OP_VAR_VALUE, 4, 0, 0) OP_DEFN (BINOP_IN_BOUNDS, 3, 2 , 0) OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) OP_DEFN (OP_ATR_FIRST , 1, 2, 0) OP_DEFN (OP_ATR_LAST, 1, 2, 0) OP_DEFN (OP_ATR_LENGTH , 1, 2, 0) OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) OP_DEFN (OP_ATR_MAX , 1, 3, 0) OP_DEFN (OP_ATR_MIN, 1, 3, 0) OP_DEFN (OP_ATR_MODULUS , 1, 1, 0) OP_DEFN (OP_ATR_POS, 1, 2, 0) OP_DEFN (OP_ATR_SIZE , 1, 1, 0) OP_DEFN (OP_ATR_TAG, 1, 1, 0) OP_DEFN (OP_ATR_VAL, 1, 2, 0) OP_DEFN (UNOP_QUAL, 3, 1, 0) OP_DEFN (UNOP_IN_RANGE , 3, 1, 0); |
8263 | #undef OP_DEFN |
8264 | } |
8265 | } |
8266 | |
8267 | /* As for operator_length, but assumes PC is pointing at the first |
8268 | element of the operator, and gives meaningful results only for the |
8269 | Ada-specific operators. */ |
8270 | |
8271 | static void |
8272 | ada_forward_operator_length (struct expression *exp, int pc, |
8273 | int *oplenp, int *argsp) |
8274 | { |
8275 | switch (exp->elts[pc].opcode) |
8276 | { |
8277 | default: |
8278 | *oplenp = *argsp = 0; |
8279 | break; |
8280 | #define OP_DEFN(op, len, args, binop) \ |
8281 | case op: *oplenp = len; *argsp = args; break; |
8282 | ADA_OPERATORSOP_DEFN (OP_VAR_VALUE, 4, 0, 0) OP_DEFN (BINOP_IN_BOUNDS, 3, 2 , 0) OP_DEFN (TERNOP_IN_RANGE, 1, 3, 0) OP_DEFN (OP_ATR_FIRST , 1, 2, 0) OP_DEFN (OP_ATR_LAST, 1, 2, 0) OP_DEFN (OP_ATR_LENGTH , 1, 2, 0) OP_DEFN (OP_ATR_IMAGE, 1, 2, 0) OP_DEFN (OP_ATR_MAX , 1, 3, 0) OP_DEFN (OP_ATR_MIN, 1, 3, 0) OP_DEFN (OP_ATR_MODULUS , 1, 1, 0) OP_DEFN (OP_ATR_POS, 1, 2, 0) OP_DEFN (OP_ATR_SIZE , 1, 1, 0) OP_DEFN (OP_ATR_TAG, 1, 1, 0) OP_DEFN (OP_ATR_VAL, 1, 2, 0) OP_DEFN (UNOP_QUAL, 3, 1, 0) OP_DEFN (UNOP_IN_RANGE , 3, 1, 0); |
8283 | #undef OP_DEFN |
8284 | } |
8285 | } |
8286 | |
8287 | static int |
8288 | ada_dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt) |
8289 | { |
8290 | enum exp_opcode op = exp->elts[elt].opcode; |
8291 | int oplen, nargs; |
8292 | int pc = elt; |
8293 | int i; |
8294 | |
8295 | ada_forward_operator_length (exp, elt, &oplen, &nargs); |
8296 | |
8297 | switch (op) |
8298 | { |
8299 | /* Ada attributes ('Foo). */ |
8300 | case OP_ATR_FIRST: |
8301 | case OP_ATR_LAST: |
8302 | case OP_ATR_LENGTH: |
8303 | case OP_ATR_IMAGE: |
8304 | case OP_ATR_MAX: |
8305 | case OP_ATR_MIN: |
8306 | case OP_ATR_MODULUS: |
8307 | case OP_ATR_POS: |
8308 | case OP_ATR_SIZE: |
8309 | case OP_ATR_TAG: |
8310 | case OP_ATR_VAL: |
8311 | break; |
8312 | |
8313 | case UNOP_IN_RANGE: |
8314 | case UNOP_QUAL: |
8315 | fprintf_filtered (stream, "Type @"); |
8316 | gdb_print_host_address (exp->elts[pc + 1].type, stream); |
8317 | fprintf_filtered (stream, " ("); |
8318 | type_print (exp->elts[pc + 1].type, NULL((void*)0), stream, 0); |
8319 | fprintf_filtered (stream, ")"); |
8320 | break; |
8321 | case BINOP_IN_BOUNDS: |
8322 | fprintf_filtered (stream, " (%d)", (int) exp->elts[pc + 2].longconst); |
8323 | break; |
8324 | case TERNOP_IN_RANGE: |
8325 | break; |
8326 | |
8327 | default: |
8328 | return dump_subexp_body_standard (exp, stream, elt); |
8329 | } |
8330 | |
8331 | elt += oplen; |
8332 | for (i = 0; i < nargs; i += 1) |
8333 | elt = dump_subexp (exp, stream, elt); |
8334 | |
8335 | return elt; |
8336 | } |
8337 | |
8338 | /* The Ada extension of print_subexp (q.v.). */ |
8339 | |
8340 | static void |
8341 | ada_print_subexp (struct expression *exp, int *pos, |
8342 | struct ui_file *stream, enum precedence prec) |
8343 | { |
8344 | int oplen, nargs; |
8345 | int pc = *pos; |
8346 | enum exp_opcode op = exp->elts[pc].opcode; |
8347 | |
8348 | ada_forward_operator_length (exp, pc, &oplen, &nargs); |
8349 | |
8350 | switch (op) |
8351 | { |
8352 | default: |
8353 | print_subexp_standard (exp, pos, stream, prec); |
8354 | return; |
8355 | |
8356 | case OP_VAR_VALUE: |
8357 | *pos += oplen; |
8358 | fputs_filtered (SYMBOL_NATURAL_NAME (exp->elts[pc + 2].symbol)(symbol_natural_name (&(exp->elts[pc + 2].symbol)-> ginfo)), stream); |
8359 | return; |
8360 | |
8361 | case BINOP_IN_BOUNDS: |
8362 | *pos += oplen; |
8363 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
8364 | fputs_filtered (" in ", stream); |
8365 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
8366 | fputs_filtered ("'range", stream); |
8367 | if (exp->elts[pc + 1].longconst > 1) |
8368 | fprintf_filtered (stream, "(%ld)", |
8369 | (long) exp->elts[pc + 1].longconst); |
8370 | return; |
8371 | |
8372 | case TERNOP_IN_RANGE: |
8373 | *pos += oplen; |
8374 | if (prec >= PREC_EQUAL) |
8375 | fputs_filtered ("(", stream); |
8376 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
8377 | fputs_filtered (" in ", stream); |
8378 | print_subexp (exp, pos, stream, PREC_EQUAL); |
8379 | fputs_filtered (" .. ", stream); |
8380 | print_subexp (exp, pos, stream, PREC_EQUAL); |
8381 | if (prec >= PREC_EQUAL) |
8382 | fputs_filtered (")", stream); |
8383 | return; |
8384 | |
8385 | case OP_ATR_FIRST: |
8386 | case OP_ATR_LAST: |
8387 | case OP_ATR_LENGTH: |
8388 | case OP_ATR_IMAGE: |
8389 | case OP_ATR_MAX: |
8390 | case OP_ATR_MIN: |
8391 | case OP_ATR_MODULUS: |
8392 | case OP_ATR_POS: |
8393 | case OP_ATR_SIZE: |
8394 | case OP_ATR_TAG: |
8395 | case OP_ATR_VAL: |
8396 | *pos += oplen; |
8397 | if (exp->elts[*pos].opcode == OP_TYPE) |
8398 | { |
8399 | if (TYPE_CODE (exp->elts[*pos + 1].type)(exp->elts[*pos + 1].type)->main_type->code != TYPE_CODE_VOID) |
8400 | LA_PRINT_TYPE (exp->elts[*pos + 1].type, "", stream, 0, 0)(current_language->la_print_type(exp->elts[*pos + 1].type ,"",stream,0,0)); |
8401 | *pos += 3; |
8402 | } |
8403 | else |
8404 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
8405 | fprintf_filtered (stream, "'%s", ada_attribute_name (op)); |
8406 | if (nargs > 1) |
8407 | { |
8408 | int tem; |
8409 | for (tem = 1; tem < nargs; tem += 1) |
8410 | { |
8411 | fputs_filtered ((tem == 1) ? " (" : ", ", stream); |
8412 | print_subexp (exp, pos, stream, PREC_ABOVE_COMMA); |
8413 | } |
8414 | fputs_filtered (")", stream); |
8415 | } |
8416 | return; |
8417 | |
8418 | case UNOP_QUAL: |
8419 | *pos += oplen; |
8420 | type_print (exp->elts[pc + 1].type, "", stream, 0); |
8421 | fputs_filtered ("'(", stream); |
8422 | print_subexp (exp, pos, stream, PREC_PREFIX); |
8423 | fputs_filtered (")", stream); |
8424 | return; |
8425 | |
8426 | case UNOP_IN_RANGE: |
8427 | *pos += oplen; |
8428 | print_subexp (exp, pos, stream, PREC_SUFFIX); |
8429 | fputs_filtered (" in ", stream); |
8430 | LA_PRINT_TYPE (exp->elts[pc + 1].type, "", stream, 1, 0)(current_language->la_print_type(exp->elts[pc + 1].type ,"",stream,1,0)); |
8431 | return; |
8432 | } |
8433 | } |
8434 | |
8435 | /* Table mapping opcodes into strings for printing operators |
8436 | and precedences of the operators. */ |
8437 | |
8438 | static const struct op_print ada_op_print_tab[] = { |
8439 | {":=", BINOP_ASSIGN, PREC_ASSIGN, 1}, |
8440 | {"or else", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, |
8441 | {"and then", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, |
8442 | {"or", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0}, |
8443 | {"xor", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0}, |
8444 | {"and", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0}, |
8445 | {"=", BINOP_EQUAL, PREC_EQUAL, 0}, |
8446 | {"/=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, |
8447 | {"<=", BINOP_LEQ, PREC_ORDER, 0}, |
8448 | {">=", BINOP_GEQ, PREC_ORDER, 0}, |
8449 | {">", BINOP_GTR, PREC_ORDER, 0}, |
8450 | {"<", BINOP_LESS, PREC_ORDER, 0}, |
8451 | {">>", BINOP_RSH, PREC_SHIFT, 0}, |
8452 | {"<<", BINOP_LSH, PREC_SHIFT, 0}, |
8453 | {"+", BINOP_ADD, PREC_ADD, 0}, |
8454 | {"-", BINOP_SUB, PREC_ADD, 0}, |
8455 | {"&", BINOP_CONCAT, PREC_ADD, 0}, |
8456 | {"*", BINOP_MUL, PREC_MUL, 0}, |
8457 | {"/", BINOP_DIV, PREC_MUL, 0}, |
8458 | {"rem", BINOP_REM, PREC_MUL, 0}, |
8459 | {"mod", BINOP_MOD, PREC_MUL, 0}, |
8460 | {"**", BINOP_EXP, PREC_REPEAT, 0}, |
8461 | {"@", BINOP_REPEAT, PREC_REPEAT, 0}, |
8462 | {"-", UNOP_NEG, PREC_PREFIX, 0}, |
8463 | {"+", UNOP_PLUS, PREC_PREFIX, 0}, |
8464 | {"not ", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, |
8465 | {"not ", UNOP_COMPLEMENT, PREC_PREFIX, 0}, |
8466 | {"abs ", UNOP_ABS, PREC_PREFIX, 0}, |
8467 | {".all", UNOP_IND, PREC_SUFFIX, 1}, |
8468 | {"'access", UNOP_ADDR, PREC_SUFFIX, 1}, |
8469 | {"'size", OP_ATR_SIZE, PREC_SUFFIX, 1}, |
8470 | {NULL((void*)0), 0, 0, 0} |
8471 | }; |
8472 | |
8473 | /* Fundamental Ada Types */ |
8474 | |
8475 | /* Create a fundamental Ada type using default reasonable for the current |
8476 | target machine. |
8477 | |
8478 | Some object/debugging file formats (DWARF version 1, COFF, etc) do not |
8479 | define fundamental types such as "int" or "double". Others (stabs or |
8480 | DWARF version 2, etc) do define fundamental types. For the formats which |
8481 | don't provide fundamental types, gdb can create such types using this |
8482 | function. |
8483 | |
8484 | FIXME: Some compilers distinguish explicitly signed integral types |
8485 | (signed short, signed int, signed long) from "regular" integral types |
8486 | (short, int, long) in the debugging information. There is some dis- |
8487 | agreement as to how useful this feature is. In particular, gcc does |
8488 | not support this. Also, only some debugging formats allow the |
8489 | distinction to be passed on to a debugger. For now, we always just |
8490 | use "short", "int", or "long" as the type name, for both the implicit |
8491 | and explicitly signed types. This also makes life easier for the |
8492 | gdb test suite since we don't have to account for the differences |
8493 | in output depending upon what the compiler and debugging format |
8494 | support. We will probably have to re-examine the issue when gdb |
8495 | starts taking it's fundamental type information directly from the |
8496 | debugging information supplied by the compiler. fnf@cygnus.com */ |
8497 | |
8498 | static struct type * |
8499 | ada_create_fundamental_type (struct objfile *objfile, int typeid) |
8500 | { |
8501 | struct type *type = NULL((void*)0); |
8502 | |
8503 | switch (typeid) |
8504 | { |
8505 | default: |
8506 | /* FIXME: For now, if we are asked to produce a type not in this |
8507 | language, create the equivalent of a C integer type with the |
8508 | name "<?type?>". When all the dust settles from the type |
8509 | reconstruction work, this should probably become an error. */ |
8510 | type = init_type (TYPE_CODE_INT, |
8511 | TARGET_INT_BIT(gdbarch_int_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8512 | 0, "<?type?>", objfile); |
8513 | warning ("internal error: no Ada fundamental type %d", typeid); |
8514 | break; |
8515 | case FT_VOID0: |
8516 | type = init_type (TYPE_CODE_VOID, |
8517 | TARGET_CHAR_BIT8 / TARGET_CHAR_BIT8, |
8518 | 0, "void", objfile); |
8519 | break; |
8520 | case FT_CHAR2: |
8521 | type = init_type (TYPE_CODE_INT, |
8522 | TARGET_CHAR_BIT8 / TARGET_CHAR_BIT8, |
8523 | 0, "character", objfile); |
8524 | break; |
8525 | case FT_SIGNED_CHAR3: |
8526 | type = init_type (TYPE_CODE_INT, |
8527 | TARGET_CHAR_BIT8 / TARGET_CHAR_BIT8, |
8528 | 0, "signed char", objfile); |
8529 | break; |
8530 | case FT_UNSIGNED_CHAR4: |
8531 | type = init_type (TYPE_CODE_INT, |
8532 | TARGET_CHAR_BIT8 / TARGET_CHAR_BIT8, |
8533 | TYPE_FLAG_UNSIGNED(1 << 0), "unsigned char", objfile); |
8534 | break; |
8535 | case FT_SHORT5: |
8536 | type = init_type (TYPE_CODE_INT, |
8537 | TARGET_SHORT_BIT(gdbarch_short_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8538 | 0, "short_integer", objfile); |
8539 | break; |
8540 | case FT_SIGNED_SHORT6: |
8541 | type = init_type (TYPE_CODE_INT, |
8542 | TARGET_SHORT_BIT(gdbarch_short_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8543 | 0, "short_integer", objfile); |
8544 | break; |
8545 | case FT_UNSIGNED_SHORT7: |
8546 | type = init_type (TYPE_CODE_INT, |
8547 | TARGET_SHORT_BIT(gdbarch_short_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8548 | TYPE_FLAG_UNSIGNED(1 << 0), "unsigned short", objfile); |
8549 | break; |
8550 | case FT_INTEGER8: |
8551 | type = init_type (TYPE_CODE_INT, |
8552 | TARGET_INT_BIT(gdbarch_int_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8553 | 0, "integer", objfile); |
8554 | break; |
8555 | case FT_SIGNED_INTEGER9: |
8556 | type = init_type (TYPE_CODE_INT, TARGET_INT_BIT(gdbarch_int_bit (current_gdbarch)) / |
8557 | TARGET_CHAR_BIT8, |
8558 | 0, "integer", objfile); /* FIXME -fnf */ |
8559 | break; |
8560 | case FT_UNSIGNED_INTEGER10: |
8561 | type = init_type (TYPE_CODE_INT, |
8562 | TARGET_INT_BIT(gdbarch_int_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8563 | TYPE_FLAG_UNSIGNED(1 << 0), "unsigned int", objfile); |
8564 | break; |
8565 | case FT_LONG11: |
8566 | type = init_type (TYPE_CODE_INT, |
8567 | TARGET_LONG_BIT(gdbarch_long_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8568 | 0, "long_integer", objfile); |
8569 | break; |
8570 | case FT_SIGNED_LONG12: |
8571 | type = init_type (TYPE_CODE_INT, |
8572 | TARGET_LONG_BIT(gdbarch_long_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8573 | 0, "long_integer", objfile); |
8574 | break; |
8575 | case FT_UNSIGNED_LONG13: |
8576 | type = init_type (TYPE_CODE_INT, |
8577 | TARGET_LONG_BIT(gdbarch_long_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8578 | TYPE_FLAG_UNSIGNED(1 << 0), "unsigned long", objfile); |
8579 | break; |
8580 | case FT_LONG_LONG14: |
8581 | type = init_type (TYPE_CODE_INT, |
8582 | TARGET_LONG_LONG_BIT(gdbarch_long_long_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8583 | 0, "long_long_integer", objfile); |
8584 | break; |
8585 | case FT_SIGNED_LONG_LONG15: |
8586 | type = init_type (TYPE_CODE_INT, |
8587 | TARGET_LONG_LONG_BIT(gdbarch_long_long_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8588 | 0, "long_long_integer", objfile); |
8589 | break; |
8590 | case FT_UNSIGNED_LONG_LONG16: |
8591 | type = init_type (TYPE_CODE_INT, |
8592 | TARGET_LONG_LONG_BIT(gdbarch_long_long_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8593 | TYPE_FLAG_UNSIGNED(1 << 0), "unsigned long long", objfile); |
8594 | break; |
8595 | case FT_FLOAT17: |
8596 | type = init_type (TYPE_CODE_FLT, |
8597 | TARGET_FLOAT_BIT(gdbarch_float_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8598 | 0, "float", objfile); |
8599 | break; |
8600 | case FT_DBL_PREC_FLOAT18: |
8601 | type = init_type (TYPE_CODE_FLT, |
8602 | TARGET_DOUBLE_BIT(gdbarch_double_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8603 | 0, "long_float", objfile); |
8604 | break; |
8605 | case FT_EXT_PREC_FLOAT19: |
8606 | type = init_type (TYPE_CODE_FLT, |
8607 | TARGET_LONG_DOUBLE_BIT(gdbarch_long_double_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8608 | 0, "long_long_float", objfile); |
8609 | break; |
8610 | } |
8611 | return (type); |
8612 | } |
8613 | |
8614 | enum ada_primitive_types { |
8615 | ada_primitive_type_int, |
8616 | ada_primitive_type_long, |
8617 | ada_primitive_type_short, |
8618 | ada_primitive_type_char, |
8619 | ada_primitive_type_float, |
8620 | ada_primitive_type_double, |
8621 | ada_primitive_type_void, |
8622 | ada_primitive_type_long_long, |
8623 | ada_primitive_type_long_double, |
8624 | ada_primitive_type_natural, |
8625 | ada_primitive_type_positive, |
8626 | ada_primitive_type_system_address, |
8627 | nr_ada_primitive_types |
8628 | }; |
8629 | |
8630 | static void |
8631 | ada_language_arch_info (struct gdbarch *current_gdbarch, |
8632 | struct language_arch_info *lai) |
8633 | { |
8634 | const struct builtin_type *builtin = builtin_type (current_gdbarch); |
8635 | lai->primitive_type_vector |
8636 | = GDBARCH_OBSTACK_CALLOC (current_gdbarch, nr_ada_primitive_types + 1,((struct type * *) gdbarch_obstack_zalloc ((current_gdbarch), (nr_ada_primitive_types + 1) * sizeof (struct type *))) |
8637 | struct type *)((struct type * *) gdbarch_obstack_zalloc ((current_gdbarch), (nr_ada_primitive_types + 1) * sizeof (struct type *))); |
8638 | lai->primitive_type_vector [ada_primitive_type_int] = |
8639 | init_type (TYPE_CODE_INT, TARGET_INT_BIT(gdbarch_int_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8640 | 0, "integer", (struct objfile *) NULL((void*)0)); |
8641 | lai->primitive_type_vector [ada_primitive_type_long] = |
8642 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT(gdbarch_long_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8643 | 0, "long_integer", (struct objfile *) NULL((void*)0)); |
8644 | lai->primitive_type_vector [ada_primitive_type_short] = |
8645 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT(gdbarch_short_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8646 | 0, "short_integer", (struct objfile *) NULL((void*)0)); |
8647 | lai->string_char_type = |
8648 | lai->primitive_type_vector [ada_primitive_type_char] = |
8649 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT8 / TARGET_CHAR_BIT8, |
8650 | 0, "character", (struct objfile *) NULL((void*)0)); |
8651 | lai->primitive_type_vector [ada_primitive_type_float] = |
8652 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT(gdbarch_float_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8653 | 0, "float", (struct objfile *) NULL((void*)0)); |
8654 | lai->primitive_type_vector [ada_primitive_type_double] = |
8655 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT(gdbarch_double_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8656 | 0, "long_float", (struct objfile *) NULL((void*)0)); |
8657 | lai->primitive_type_vector [ada_primitive_type_long_long] = |
8658 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT(gdbarch_long_long_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8659 | 0, "long_long_integer", (struct objfile *) NULL((void*)0)); |
8660 | lai->primitive_type_vector [ada_primitive_type_long_double] = |
8661 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT(gdbarch_long_double_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8662 | 0, "long_long_float", (struct objfile *) NULL((void*)0)); |
8663 | lai->primitive_type_vector [ada_primitive_type_natural] = |
8664 | init_type (TYPE_CODE_INT, TARGET_INT_BIT(gdbarch_int_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8665 | 0, "natural", (struct objfile *) NULL((void*)0)); |
8666 | lai->primitive_type_vector [ada_primitive_type_positive] = |
8667 | init_type (TYPE_CODE_INT, TARGET_INT_BIT(gdbarch_int_bit (current_gdbarch)) / TARGET_CHAR_BIT8, |
8668 | 0, "positive", (struct objfile *) NULL((void*)0)); |
8669 | lai->primitive_type_vector [ada_primitive_type_void] = builtin->builtin_void; |
8670 | |
8671 | lai->primitive_type_vector [ada_primitive_type_system_address] = |
8672 | lookup_pointer_type (init_type (TYPE_CODE_VOID, 1, 0, "void", |
8673 | (struct objfile *) NULL((void*)0))); |
8674 | TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])(lai->primitive_type_vector [ada_primitive_type_system_address ])->main_type->name |
8675 | = "system__address"; |
8676 | } |
8677 | |
8678 | /* Language vector */ |
8679 | |
8680 | /* Not really used, but needed in the ada_language_defn. */ |
8681 | |
8682 | static void |
8683 | emit_char (int c, struct ui_file *stream, int quoter) |
8684 | { |
8685 | ada_emit_char (c, stream, quoter, 1); |
8686 | } |
8687 | |
8688 | static int |
8689 | parse (void) |
8690 | { |
8691 | warnings_issued = 0; |
8692 | return ada_parse (); |
8693 | } |
8694 | |
8695 | static const struct exp_descriptor ada_exp_descriptor = { |
8696 | ada_print_subexp, |
8697 | ada_operator_length, |
8698 | ada_op_name, |
8699 | ada_dump_subexp_body, |
8700 | ada_evaluate_subexp |
8701 | }; |
8702 | |
8703 | const struct language_defn ada_language_defn = { |
8704 | "ada", /* Language name */ |
8705 | language_ada, |
8706 | NULL((void*)0), |
8707 | range_check_off, |
8708 | type_check_off, |
8709 | case_sensitive_on, /* Yes, Ada is case-insensitive, but |
8710 | that's not quite what this means. */ |
8711 | array_row_major, |
8712 | &ada_exp_descriptor, |
8713 | parse, |
8714 | ada_error, |
8715 | resolve, |
8716 | ada_printchar, /* Print a character constant */ |
8717 | ada_printstr, /* Function to print string constant */ |
8718 | emit_char, /* Function to print single char (not used) */ |
8719 | ada_create_fundamental_type, /* Create fundamental type in this language */ |
8720 | ada_print_type, /* Print a type using appropriate syntax */ |
8721 | ada_val_print, /* Print a value using appropriate syntax */ |
8722 | ada_value_print, /* Print a top-level value */ |
8723 | NULL((void*)0), /* Language specific skip_trampoline */ |
8724 | NULL((void*)0), /* value_of_this */ |
8725 | ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */ |
8726 | basic_lookup_transparent_type, /* lookup_transparent_type */ |
8727 | ada_la_decode, /* Language specific symbol demangler */ |
8728 | NULL((void*)0), /* Language specific class_name_from_physname */ |
8729 | ada_op_print_tab, /* expression operators for printing */ |
8730 | 0, /* c-style arrays */ |
8731 | 1, /* String lower bound */ |
8732 | NULL((void*)0), |
8733 | ada_get_gdb_completer_word_break_characters, |
8734 | ada_language_arch_info, |
8735 | LANG_MAGIC910823L |
8736 | }; |
8737 | |
8738 | void |
8739 | _initialize_ada_language (void) |
8740 | { |
8741 | add_language (&ada_language_defn); |
8742 | |
8743 | varsize_limit = 65536; |
8744 | |
8745 | obstack_init (&symbol_list_obstack)_obstack_begin ((&symbol_list_obstack), 0, 0, (void *(*) ( long)) xmalloc, (void (*) (void *)) xfree); |
8746 | |
8747 | decoded_names_store = htab_create_alloc |
8748 | (256, htab_hash_string, (int (*)(const void *, const void *)) streq, |
8749 | NULL((void*)0), xcalloc, xfree); |
8750 | } |