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