Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Multiple source language support for GDB. |
1bac305b | 2 | |
6aba47ca | 3 | Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, |
0fb0cc75 | 4 | 2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. |
1bac305b | 5 | |
c906108c SS |
6 | Contributed by the Department of Computer Science at the State University |
7 | of New York at Buffalo. | |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 13 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 14 | (at your option) any later version. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
c906108c | 20 | |
c5aa993b | 21 | You should have received a copy of the GNU General Public License |
a9762ec7 | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
23 | |
24 | /* This file contains functions that return things that are specific | |
25 | to languages. Each function should examine current_language if necessary, | |
26 | and return the appropriate result. */ | |
27 | ||
28 | /* FIXME: Most of these would be better organized as macros which | |
29 | return data out of a "language-specific" struct pointer that is set | |
30 | whenever the working language changes. That would be a lot faster. */ | |
31 | ||
32 | #include "defs.h" | |
33 | #include <ctype.h> | |
34 | #include "gdb_string.h" | |
35 | ||
36 | #include "symtab.h" | |
37 | #include "gdbtypes.h" | |
38 | #include "value.h" | |
39 | #include "gdbcmd.h" | |
c906108c SS |
40 | #include "expression.h" |
41 | #include "language.h" | |
42 | #include "target.h" | |
43 | #include "parser-defs.h" | |
8caabe69 | 44 | #include "jv-lang.h" |
9a3d7dfd | 45 | #include "demangle.h" |
8b60591b | 46 | #include "symfile.h" |
c906108c | 47 | |
a14ed312 | 48 | extern void _initialize_language (void); |
392a587b | 49 | |
63872f9d JG |
50 | static void set_case_str (void); |
51 | ||
a14ed312 | 52 | static void set_range_str (void); |
c906108c | 53 | |
a14ed312 | 54 | static void set_type_str (void); |
c906108c | 55 | |
a14ed312 | 56 | static void set_lang_str (void); |
c906108c | 57 | |
a14ed312 | 58 | static void unk_lang_error (char *); |
c906108c | 59 | |
a14ed312 | 60 | static int unk_lang_parser (void); |
c906108c | 61 | |
a14ed312 | 62 | static void show_check (char *, int); |
c906108c | 63 | |
a14ed312 | 64 | static void set_check (char *, int); |
c906108c | 65 | |
63872f9d | 66 | static void set_type_range_case (void); |
c906108c | 67 | |
6c7a06a3 TT |
68 | static void unk_lang_emit_char (int c, struct type *type, |
69 | struct ui_file *stream, int quoter); | |
c906108c | 70 | |
6c7a06a3 TT |
71 | static void unk_lang_printchar (int c, struct type *type, |
72 | struct ui_file *stream); | |
c906108c | 73 | |
d9fcf2fb JM |
74 | static void unk_lang_print_type (struct type *, char *, struct ui_file *, |
75 | int, int); | |
c906108c | 76 | |
79a45b7d TT |
77 | static int unk_lang_value_print (struct value *, struct ui_file *, |
78 | const struct value_print_options *); | |
c906108c | 79 | |
52f729a7 | 80 | static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc); |
f636b87d | 81 | |
c906108c SS |
82 | /* Forward declaration */ |
83 | extern const struct language_defn unknown_language_defn; | |
c5aa993b | 84 | |
c906108c | 85 | /* The current (default at startup) state of type and range checking. |
c5aa993b JM |
86 | (If the modes are set to "auto", though, these are changed based |
87 | on the default language at startup, and then again based on the | |
88 | language of the first source file. */ | |
c906108c SS |
89 | |
90 | enum range_mode range_mode = range_mode_auto; | |
91 | enum range_check range_check = range_check_off; | |
92 | enum type_mode type_mode = type_mode_auto; | |
93 | enum type_check type_check = type_check_off; | |
63872f9d JG |
94 | enum case_mode case_mode = case_mode_auto; |
95 | enum case_sensitivity case_sensitivity = case_sensitive_on; | |
c906108c SS |
96 | |
97 | /* The current language and language_mode (see language.h) */ | |
98 | ||
99 | const struct language_defn *current_language = &unknown_language_defn; | |
100 | enum language_mode language_mode = language_mode_auto; | |
101 | ||
102 | /* The language that the user expects to be typing in (the language | |
103 | of main(), or the last language we notified them about, or C). */ | |
104 | ||
105 | const struct language_defn *expected_language; | |
106 | ||
107 | /* The list of supported languages. The list itself is malloc'd. */ | |
108 | ||
109 | static const struct language_defn **languages; | |
110 | static unsigned languages_size; | |
111 | static unsigned languages_allocsize; | |
112 | #define DEFAULT_ALLOCSIZE 4 | |
113 | ||
114 | /* The "set language/type/range" commands all put stuff in these | |
115 | buffers. This is to make them work as set/show commands. The | |
116 | user's string is copied here, then the set_* commands look at | |
117 | them and update them to something that looks nice when it is | |
118 | printed out. */ | |
119 | ||
120 | static char *language; | |
121 | static char *type; | |
122 | static char *range; | |
63872f9d | 123 | static char *case_sensitive; |
c906108c SS |
124 | |
125 | /* Warning issued when current_language and the language of the current | |
126 | frame do not match. */ | |
127 | char lang_frame_mismatch_warn[] = | |
c5aa993b | 128 | "Warning: the current language does not match this frame."; |
c906108c SS |
129 | \f |
130 | /* This page contains the functions corresponding to GDB commands | |
131 | and their helpers. */ | |
132 | ||
133 | /* Show command. Display a warning if the language set | |
134 | does not match the frame. */ | |
135 | static void | |
4d28ad1e AC |
136 | show_language_command (struct ui_file *file, int from_tty, |
137 | struct cmd_list_element *c, const char *value) | |
c906108c | 138 | { |
c5aa993b | 139 | enum language flang; /* The language of the current frame */ |
c906108c | 140 | |
4d28ad1e | 141 | deprecated_show_value_hack (file, from_tty, c, value); |
c5aa993b JM |
142 | flang = get_frame_language (); |
143 | if (flang != language_unknown && | |
144 | language_mode == language_mode_manual && | |
145 | current_language->la_language != flang) | |
146 | printf_filtered ("%s\n", lang_frame_mismatch_warn); | |
c906108c SS |
147 | } |
148 | ||
149 | /* Set command. Change the current working language. */ | |
150 | static void | |
4d28ad1e | 151 | set_language_command (char *ignore, int from_tty, struct cmd_list_element *c) |
c906108c SS |
152 | { |
153 | int i; | |
154 | enum language flang; | |
155 | char *err_lang; | |
156 | ||
157 | if (!language || !language[0]) | |
158 | { | |
a3f17187 AC |
159 | printf_unfiltered (_("\ |
160 | The currently understood settings are:\n\n\ | |
161 | local or auto Automatic setting based on source file\n")); | |
c906108c SS |
162 | |
163 | for (i = 0; i < languages_size; ++i) | |
164 | { | |
165 | /* Already dealt with these above. */ | |
166 | if (languages[i]->la_language == language_unknown | |
167 | || languages[i]->la_language == language_auto) | |
168 | continue; | |
169 | ||
a3f17187 AC |
170 | /* FIXME: i18n: for now assume that the human-readable name |
171 | is just a capitalization of the internal name. */ | |
c906108c SS |
172 | printf_unfiltered ("%-16s Use the %c%s language\n", |
173 | languages[i]->la_name, | |
c5aa993b JM |
174 | /* Capitalize first letter of language |
175 | name. */ | |
c906108c SS |
176 | toupper (languages[i]->la_name[0]), |
177 | languages[i]->la_name + 1); | |
178 | } | |
179 | /* Restore the silly string. */ | |
c5aa993b | 180 | set_language (current_language->la_language); |
c906108c SS |
181 | return; |
182 | } | |
183 | ||
184 | /* Search the list of languages for a match. */ | |
c5aa993b JM |
185 | for (i = 0; i < languages_size; i++) |
186 | { | |
6314a349 | 187 | if (strcmp (languages[i]->la_name, language) == 0) |
c5aa993b JM |
188 | { |
189 | /* Found it! Go into manual mode, and use this language. */ | |
190 | if (languages[i]->la_language == language_auto) | |
191 | { | |
8b60591b JB |
192 | /* Enter auto mode. Set to the current frame's language, if |
193 | known, or fallback to the initial language. */ | |
c5aa993b JM |
194 | language_mode = language_mode_auto; |
195 | flang = get_frame_language (); | |
196 | if (flang != language_unknown) | |
197 | set_language (flang); | |
8b60591b JB |
198 | else |
199 | set_initial_language (); | |
c5aa993b JM |
200 | expected_language = current_language; |
201 | return; | |
202 | } | |
203 | else | |
204 | { | |
205 | /* Enter manual mode. Set the specified language. */ | |
206 | language_mode = language_mode_manual; | |
207 | current_language = languages[i]; | |
63872f9d | 208 | set_type_range_case (); |
c5aa993b JM |
209 | set_lang_str (); |
210 | expected_language = current_language; | |
211 | return; | |
212 | } | |
213 | } | |
c906108c | 214 | } |
c906108c SS |
215 | |
216 | /* Reset the language (esp. the global string "language") to the | |
217 | correct values. */ | |
1b36a34b | 218 | err_lang = xstrdup (language); |
b8c9b27d | 219 | make_cleanup (xfree, err_lang); /* Free it after error */ |
c5aa993b | 220 | set_language (current_language->la_language); |
8a3fe4f8 | 221 | error (_("Unknown language `%s'."), err_lang); |
c906108c SS |
222 | } |
223 | ||
224 | /* Show command. Display a warning if the type setting does | |
225 | not match the current language. */ | |
226 | static void | |
4d28ad1e AC |
227 | show_type_command (struct ui_file *file, int from_tty, |
228 | struct cmd_list_element *c, const char *value) | |
c906108c | 229 | { |
4d28ad1e | 230 | deprecated_show_value_hack (file, from_tty, c, value); |
c5aa993b JM |
231 | if (type_check != current_language->la_type_check) |
232 | printf_unfiltered ( | |
233 | "Warning: the current type check setting does not match the language.\n"); | |
c906108c SS |
234 | } |
235 | ||
236 | /* Set command. Change the setting for type checking. */ | |
237 | static void | |
4d28ad1e | 238 | set_type_command (char *ignore, int from_tty, struct cmd_list_element *c) |
c906108c | 239 | { |
6314a349 | 240 | if (strcmp (type, "on") == 0) |
c5aa993b | 241 | { |
c906108c SS |
242 | type_check = type_check_on; |
243 | type_mode = type_mode_manual; | |
c5aa993b | 244 | } |
6314a349 | 245 | else if (strcmp (type, "warn") == 0) |
c5aa993b | 246 | { |
c906108c SS |
247 | type_check = type_check_warn; |
248 | type_mode = type_mode_manual; | |
c5aa993b | 249 | } |
6314a349 | 250 | else if (strcmp (type, "off") == 0) |
c5aa993b | 251 | { |
c906108c SS |
252 | type_check = type_check_off; |
253 | type_mode = type_mode_manual; | |
c5aa993b | 254 | } |
6314a349 | 255 | else if (strcmp (type, "auto") == 0) |
c5aa993b | 256 | { |
c906108c | 257 | type_mode = type_mode_auto; |
63872f9d | 258 | set_type_range_case (); |
c906108c | 259 | /* Avoid hitting the set_type_str call below. We |
63872f9d | 260 | did it in set_type_range_case. */ |
c906108c | 261 | return; |
c5aa993b | 262 | } |
c4093a6a JM |
263 | else |
264 | { | |
8a3fe4f8 | 265 | warning (_("Unrecognized type check setting: \"%s\""), type); |
c4093a6a | 266 | } |
c5aa993b | 267 | set_type_str (); |
4d28ad1e | 268 | show_type_command (NULL, from_tty, NULL, NULL); |
c906108c SS |
269 | } |
270 | ||
271 | /* Show command. Display a warning if the range setting does | |
272 | not match the current language. */ | |
273 | static void | |
4d28ad1e AC |
274 | show_range_command (struct ui_file *file, int from_tty, |
275 | struct cmd_list_element *c, const char *value) | |
c906108c | 276 | { |
4d28ad1e | 277 | deprecated_show_value_hack (file, from_tty, c, value); |
c5aa993b JM |
278 | if (range_check != current_language->la_range_check) |
279 | printf_unfiltered ( | |
280 | "Warning: the current range check setting does not match the language.\n"); | |
c906108c SS |
281 | } |
282 | ||
283 | /* Set command. Change the setting for range checking. */ | |
284 | static void | |
4d28ad1e | 285 | set_range_command (char *ignore, int from_tty, struct cmd_list_element *c) |
c906108c | 286 | { |
6314a349 | 287 | if (strcmp (range, "on") == 0) |
c5aa993b | 288 | { |
c906108c SS |
289 | range_check = range_check_on; |
290 | range_mode = range_mode_manual; | |
c5aa993b | 291 | } |
6314a349 | 292 | else if (strcmp (range, "warn") == 0) |
c5aa993b | 293 | { |
c906108c SS |
294 | range_check = range_check_warn; |
295 | range_mode = range_mode_manual; | |
c5aa993b | 296 | } |
6314a349 | 297 | else if (strcmp (range, "off") == 0) |
c5aa993b | 298 | { |
c906108c SS |
299 | range_check = range_check_off; |
300 | range_mode = range_mode_manual; | |
c5aa993b | 301 | } |
6314a349 | 302 | else if (strcmp (range, "auto") == 0) |
c5aa993b | 303 | { |
c906108c | 304 | range_mode = range_mode_auto; |
63872f9d | 305 | set_type_range_case (); |
c906108c | 306 | /* Avoid hitting the set_range_str call below. We |
63872f9d | 307 | did it in set_type_range_case. */ |
c906108c | 308 | return; |
c5aa993b | 309 | } |
c4093a6a JM |
310 | else |
311 | { | |
8a3fe4f8 | 312 | warning (_("Unrecognized range check setting: \"%s\""), range); |
c4093a6a | 313 | } |
c5aa993b | 314 | set_range_str (); |
4d28ad1e | 315 | show_range_command (NULL, from_tty, NULL, NULL); |
c906108c SS |
316 | } |
317 | ||
63872f9d JG |
318 | /* Show command. Display a warning if the case sensitivity setting does |
319 | not match the current language. */ | |
320 | static void | |
4d28ad1e AC |
321 | show_case_command (struct ui_file *file, int from_tty, |
322 | struct cmd_list_element *c, const char *value) | |
63872f9d | 323 | { |
4d28ad1e AC |
324 | deprecated_show_value_hack (file, from_tty, c, value); |
325 | if (case_sensitivity != current_language->la_case_sensitivity) | |
326 | printf_unfiltered( | |
63872f9d JG |
327 | "Warning: the current case sensitivity setting does not match the language.\n"); |
328 | } | |
329 | ||
591e78ff MK |
330 | /* Set command. Change the setting for case sensitivity. */ |
331 | ||
63872f9d | 332 | static void |
4d28ad1e | 333 | set_case_command (char *ignore, int from_tty, struct cmd_list_element *c) |
63872f9d | 334 | { |
591e78ff MK |
335 | if (strcmp (case_sensitive, "on") == 0) |
336 | { | |
337 | case_sensitivity = case_sensitive_on; | |
338 | case_mode = case_mode_manual; | |
339 | } | |
340 | else if (strcmp (case_sensitive, "off") == 0) | |
341 | { | |
342 | case_sensitivity = case_sensitive_off; | |
343 | case_mode = case_mode_manual; | |
344 | } | |
345 | else if (strcmp (case_sensitive, "auto") == 0) | |
346 | { | |
347 | case_mode = case_mode_auto; | |
348 | set_type_range_case (); | |
349 | /* Avoid hitting the set_case_str call below. We did it in | |
350 | set_type_range_case. */ | |
351 | return; | |
352 | } | |
63872f9d | 353 | else |
591e78ff MK |
354 | { |
355 | warning (_("Unrecognized case-sensitive setting: \"%s\""), | |
356 | case_sensitive); | |
357 | } | |
63872f9d | 358 | set_case_str(); |
4d28ad1e | 359 | show_case_command (NULL, from_tty, NULL, NULL); |
63872f9d JG |
360 | } |
361 | ||
362 | /* Set the status of range and type checking and case sensitivity based on | |
c906108c SS |
363 | the current modes and the current language. |
364 | If SHOW is non-zero, then print out the current language, | |
365 | type and range checking status. */ | |
366 | static void | |
63872f9d | 367 | set_type_range_case (void) |
c906108c SS |
368 | { |
369 | ||
370 | if (range_mode == range_mode_auto) | |
371 | range_check = current_language->la_range_check; | |
372 | ||
373 | if (type_mode == type_mode_auto) | |
374 | type_check = current_language->la_type_check; | |
375 | ||
63872f9d JG |
376 | if (case_mode == case_mode_auto) |
377 | case_sensitivity = current_language->la_case_sensitivity; | |
378 | ||
c5aa993b JM |
379 | set_type_str (); |
380 | set_range_str (); | |
63872f9d | 381 | set_case_str (); |
c906108c SS |
382 | } |
383 | ||
384 | /* Set current language to (enum language) LANG. Returns previous language. */ | |
385 | ||
386 | enum language | |
fba45db2 | 387 | set_language (enum language lang) |
c906108c SS |
388 | { |
389 | int i; | |
390 | enum language prev_language; | |
391 | ||
392 | prev_language = current_language->la_language; | |
393 | ||
c5aa993b JM |
394 | for (i = 0; i < languages_size; i++) |
395 | { | |
396 | if (languages[i]->la_language == lang) | |
397 | { | |
398 | current_language = languages[i]; | |
63872f9d | 399 | set_type_range_case (); |
c5aa993b JM |
400 | set_lang_str (); |
401 | break; | |
402 | } | |
c906108c | 403 | } |
c906108c SS |
404 | |
405 | return prev_language; | |
406 | } | |
407 | \f | |
408 | /* This page contains functions that update the global vars | |
409 | language, type and range. */ | |
410 | static void | |
fba45db2 | 411 | set_lang_str (void) |
c906108c | 412 | { |
c5aa993b | 413 | char *prefix = ""; |
c906108c | 414 | |
ccdaf797 | 415 | if (language) |
b8c9b27d | 416 | xfree (language); |
c5aa993b JM |
417 | if (language_mode == language_mode_auto) |
418 | prefix = "auto; currently "; | |
c906108c | 419 | |
1754f103 | 420 | language = concat (prefix, current_language->la_name, (char *)NULL); |
c906108c SS |
421 | } |
422 | ||
423 | static void | |
fba45db2 | 424 | set_type_str (void) |
c906108c | 425 | { |
c4093a6a | 426 | char *tmp = NULL, *prefix = ""; |
c906108c | 427 | |
ccdaf797 | 428 | if (type) |
b8c9b27d | 429 | xfree (type); |
c5aa993b JM |
430 | if (type_mode == type_mode_auto) |
431 | prefix = "auto; currently "; | |
c906108c | 432 | |
c5aa993b JM |
433 | switch (type_check) |
434 | { | |
435 | case type_check_on: | |
c906108c SS |
436 | tmp = "on"; |
437 | break; | |
c5aa993b | 438 | case type_check_off: |
c906108c SS |
439 | tmp = "off"; |
440 | break; | |
c5aa993b | 441 | case type_check_warn: |
c906108c SS |
442 | tmp = "warn"; |
443 | break; | |
c5aa993b | 444 | default: |
8a3fe4f8 | 445 | error (_("Unrecognized type check setting.")); |
c5aa993b | 446 | } |
c906108c | 447 | |
1754f103 | 448 | type = concat (prefix, tmp, (char *)NULL); |
c906108c SS |
449 | } |
450 | ||
451 | static void | |
fba45db2 | 452 | set_range_str (void) |
c906108c | 453 | { |
c5aa993b | 454 | char *tmp, *pref = ""; |
c906108c | 455 | |
c5aa993b JM |
456 | if (range_mode == range_mode_auto) |
457 | pref = "auto; currently "; | |
c906108c | 458 | |
c5aa993b JM |
459 | switch (range_check) |
460 | { | |
461 | case range_check_on: | |
c906108c SS |
462 | tmp = "on"; |
463 | break; | |
c5aa993b | 464 | case range_check_off: |
c906108c SS |
465 | tmp = "off"; |
466 | break; | |
c5aa993b | 467 | case range_check_warn: |
c906108c SS |
468 | tmp = "warn"; |
469 | break; | |
c5aa993b | 470 | default: |
8a3fe4f8 | 471 | error (_("Unrecognized range check setting.")); |
c5aa993b | 472 | } |
c906108c | 473 | |
ccdaf797 | 474 | if (range) |
b8c9b27d | 475 | xfree (range); |
1754f103 | 476 | range = concat (pref, tmp, (char *)NULL); |
c906108c SS |
477 | } |
478 | ||
63872f9d | 479 | static void |
5ae5f592 | 480 | set_case_str (void) |
63872f9d JG |
481 | { |
482 | char *tmp = NULL, *prefix = ""; | |
483 | ||
484 | if (case_mode==case_mode_auto) | |
485 | prefix = "auto; currently "; | |
486 | ||
487 | switch (case_sensitivity) | |
488 | { | |
489 | case case_sensitive_on: | |
490 | tmp = "on"; | |
491 | break; | |
492 | case case_sensitive_off: | |
493 | tmp = "off"; | |
494 | break; | |
495 | default: | |
8a3fe4f8 | 496 | error (_("Unrecognized case-sensitive setting.")); |
63872f9d JG |
497 | } |
498 | ||
b8c9b27d | 499 | xfree (case_sensitive); |
1754f103 | 500 | case_sensitive = concat (prefix, tmp, (char *)NULL); |
63872f9d | 501 | } |
c906108c SS |
502 | |
503 | /* Print out the current language settings: language, range and | |
504 | type checking. If QUIETLY, print only what has changed. */ | |
505 | ||
506 | void | |
fba45db2 | 507 | language_info (int quietly) |
c906108c SS |
508 | { |
509 | if (quietly && expected_language == current_language) | |
510 | return; | |
511 | ||
512 | expected_language = current_language; | |
a3f17187 | 513 | printf_unfiltered (_("Current language: %s\n"), language); |
4d28ad1e | 514 | show_language_command (NULL, 1, NULL, NULL); |
c906108c SS |
515 | |
516 | if (!quietly) | |
517 | { | |
a3f17187 | 518 | printf_unfiltered (_("Type checking: %s\n"), type); |
4d28ad1e | 519 | show_type_command (NULL, 1, NULL, NULL); |
a3f17187 | 520 | printf_unfiltered (_("Range checking: %s\n"), range); |
4d28ad1e | 521 | show_range_command (NULL, 1, NULL, NULL); |
a3f17187 | 522 | printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive); |
4d28ad1e | 523 | show_case_command (NULL, 1, NULL, NULL); |
c906108c SS |
524 | } |
525 | } | |
526 | \f | |
527 | /* Return the result of a binary operation. */ | |
528 | ||
c5aa993b | 529 | #if 0 /* Currently unused */ |
c906108c SS |
530 | |
531 | struct type * | |
3d6d86c6 | 532 | binop_result_type (struct value *v1, struct value *v2) |
c906108c | 533 | { |
c5aa993b JM |
534 | int size, uns; |
535 | struct type *t1 = check_typedef (VALUE_TYPE (v1)); | |
536 | struct type *t2 = check_typedef (VALUE_TYPE (v2)); | |
537 | ||
538 | int l1 = TYPE_LENGTH (t1); | |
539 | int l2 = TYPE_LENGTH (t2); | |
540 | ||
541 | switch (current_language->la_language) | |
542 | { | |
543 | case language_c: | |
544 | case language_cplus: | |
eb392fbf | 545 | case language_objc: |
c5aa993b JM |
546 | if (TYPE_CODE (t1) == TYPE_CODE_FLT) |
547 | return TYPE_CODE (t2) == TYPE_CODE_FLT && l2 > l1 ? | |
548 | VALUE_TYPE (v2) : VALUE_TYPE (v1); | |
549 | else if (TYPE_CODE (t2) == TYPE_CODE_FLT) | |
550 | return TYPE_CODE (t1) == TYPE_CODE_FLT && l1 > l2 ? | |
551 | VALUE_TYPE (v1) : VALUE_TYPE (v2); | |
552 | else if (TYPE_UNSIGNED (t1) && l1 > l2) | |
553 | return VALUE_TYPE (v1); | |
554 | else if (TYPE_UNSIGNED (t2) && l2 > l1) | |
555 | return VALUE_TYPE (v2); | |
556 | else /* Both are signed. Result is the longer type */ | |
557 | return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); | |
c906108c | 558 | break; |
c5aa993b | 559 | case language_m2: |
c906108c | 560 | /* If we are doing type-checking, l1 should equal l2, so this is |
c5aa993b JM |
561 | not needed. */ |
562 | return l1 > l2 ? VALUE_TYPE (v1) : VALUE_TYPE (v2); | |
c906108c | 563 | break; |
c5aa993b | 564 | } |
e2e0b3e5 | 565 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c5aa993b | 566 | return (struct type *) 0; /* For lint */ |
c906108c SS |
567 | } |
568 | ||
c5aa993b | 569 | #endif /* 0 */ |
c906108c SS |
570 | #if 0 |
571 | /* This page contains functions that are used in type/range checking. | |
572 | They all return zero if the type/range check fails. | |
573 | ||
574 | It is hoped that these will make extending GDB to parse different | |
575 | languages a little easier. These are primarily used in eval.c when | |
576 | evaluating expressions and making sure that their types are correct. | |
577 | Instead of having a mess of conjucted/disjuncted expressions in an "if", | |
578 | the ideas of type can be wrapped up in the following functions. | |
579 | ||
580 | Note that some of them are not currently dependent upon which language | |
581 | is currently being parsed. For example, floats are the same in | |
582 | C and Modula-2 (ie. the only floating point type has TYPE_CODE of | |
583 | TYPE_CODE_FLT), while booleans are different. */ | |
584 | ||
585 | /* Returns non-zero if its argument is a simple type. This is the same for | |
586 | both Modula-2 and for C. In the C case, TYPE_CODE_CHAR will never occur, | |
587 | and thus will never cause the failure of the test. */ | |
588 | int | |
fba45db2 | 589 | simple_type (struct type *type) |
c906108c SS |
590 | { |
591 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
592 | switch (TYPE_CODE (type)) |
593 | { | |
594 | case TYPE_CODE_INT: | |
595 | case TYPE_CODE_CHAR: | |
596 | case TYPE_CODE_ENUM: | |
597 | case TYPE_CODE_FLT: | |
598 | case TYPE_CODE_RANGE: | |
599 | case TYPE_CODE_BOOL: | |
600 | return 1; | |
c906108c | 601 | |
c5aa993b JM |
602 | default: |
603 | return 0; | |
604 | } | |
c906108c SS |
605 | } |
606 | ||
607 | /* Returns non-zero if its argument is of an ordered type. | |
608 | An ordered type is one in which the elements can be tested for the | |
609 | properties of "greater than", "less than", etc, or for which the | |
610 | operations "increment" or "decrement" make sense. */ | |
611 | int | |
fba45db2 | 612 | ordered_type (struct type *type) |
c906108c SS |
613 | { |
614 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
615 | switch (TYPE_CODE (type)) |
616 | { | |
617 | case TYPE_CODE_INT: | |
618 | case TYPE_CODE_CHAR: | |
619 | case TYPE_CODE_ENUM: | |
620 | case TYPE_CODE_FLT: | |
621 | case TYPE_CODE_RANGE: | |
622 | return 1; | |
c906108c | 623 | |
c5aa993b JM |
624 | default: |
625 | return 0; | |
626 | } | |
c906108c SS |
627 | } |
628 | ||
629 | /* Returns non-zero if the two types are the same */ | |
630 | int | |
fba45db2 | 631 | same_type (struct type *arg1, struct type *arg2) |
c906108c SS |
632 | { |
633 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
634 | if (structured_type (arg1) ? !structured_type (arg2) : structured_type (arg2)) |
635 | /* One is structured and one isn't */ | |
636 | return 0; | |
637 | else if (structured_type (arg1) && structured_type (arg2)) | |
638 | return arg1 == arg2; | |
639 | else if (numeric_type (arg1) && numeric_type (arg2)) | |
640 | return (TYPE_CODE (arg2) == TYPE_CODE (arg1)) && | |
641 | (TYPE_UNSIGNED (arg1) == TYPE_UNSIGNED (arg2)) | |
642 | ? 1 : 0; | |
643 | else | |
644 | return arg1 == arg2; | |
c906108c SS |
645 | } |
646 | ||
647 | /* Returns non-zero if the type is integral */ | |
648 | int | |
fba45db2 | 649 | integral_type (struct type *type) |
c906108c SS |
650 | { |
651 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
652 | switch (current_language->la_language) |
653 | { | |
654 | case language_c: | |
655 | case language_cplus: | |
eb392fbf | 656 | case language_objc: |
c5aa993b JM |
657 | return (TYPE_CODE (type) != TYPE_CODE_INT) && |
658 | (TYPE_CODE (type) != TYPE_CODE_ENUM) ? 0 : 1; | |
659 | case language_m2: | |
750ba382 | 660 | case language_pascal: |
c5aa993b | 661 | return TYPE_CODE (type) != TYPE_CODE_INT ? 0 : 1; |
c5aa993b | 662 | default: |
8a3fe4f8 | 663 | error (_("Language not supported.")); |
c5aa993b | 664 | } |
c906108c SS |
665 | } |
666 | ||
667 | /* Returns non-zero if the value is numeric */ | |
668 | int | |
fba45db2 | 669 | numeric_type (struct type *type) |
c906108c SS |
670 | { |
671 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
672 | switch (TYPE_CODE (type)) |
673 | { | |
674 | case TYPE_CODE_INT: | |
675 | case TYPE_CODE_FLT: | |
676 | return 1; | |
c906108c | 677 | |
c5aa993b JM |
678 | default: |
679 | return 0; | |
680 | } | |
c906108c SS |
681 | } |
682 | ||
683 | /* Returns non-zero if the value is a character type */ | |
684 | int | |
fba45db2 | 685 | character_type (struct type *type) |
c906108c SS |
686 | { |
687 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
688 | switch (current_language->la_language) |
689 | { | |
c5aa993b | 690 | case language_m2: |
750ba382 | 691 | case language_pascal: |
c5aa993b JM |
692 | return TYPE_CODE (type) != TYPE_CODE_CHAR ? 0 : 1; |
693 | ||
694 | case language_c: | |
695 | case language_cplus: | |
eb392fbf | 696 | case language_objc: |
c5aa993b JM |
697 | return (TYPE_CODE (type) == TYPE_CODE_INT) && |
698 | TYPE_LENGTH (type) == sizeof (char) | |
699 | ? 1 : 0; | |
700 | default: | |
c906108c | 701 | return (0); |
c5aa993b | 702 | } |
c906108c SS |
703 | } |
704 | ||
705 | /* Returns non-zero if the value is a string type */ | |
706 | int | |
fba45db2 | 707 | string_type (struct type *type) |
c906108c SS |
708 | { |
709 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
710 | switch (current_language->la_language) |
711 | { | |
c5aa993b | 712 | case language_m2: |
750ba382 | 713 | case language_pascal: |
c5aa993b JM |
714 | return TYPE_CODE (type) != TYPE_CODE_STRING ? 0 : 1; |
715 | ||
716 | case language_c: | |
717 | case language_cplus: | |
eb392fbf | 718 | case language_objc: |
c906108c SS |
719 | /* C does not have distinct string type. */ |
720 | return (0); | |
c5aa993b | 721 | default: |
c906108c | 722 | return (0); |
c5aa993b | 723 | } |
c906108c SS |
724 | } |
725 | ||
726 | /* Returns non-zero if the value is a boolean type */ | |
727 | int | |
fba45db2 | 728 | boolean_type (struct type *type) |
c906108c SS |
729 | { |
730 | CHECK_TYPEDEF (type); | |
731 | if (TYPE_CODE (type) == TYPE_CODE_BOOL) | |
732 | return 1; | |
c5aa993b | 733 | switch (current_language->la_language) |
c906108c SS |
734 | { |
735 | case language_c: | |
736 | case language_cplus: | |
eb392fbf | 737 | case language_objc: |
db034ac5 | 738 | /* Might be more cleanly handled by having a |
1b831c93 | 739 | TYPE_CODE_INT_NOT_BOOL for (the deleted) CHILL and such |
db034ac5 | 740 | languages, or a TYPE_CODE_INT_OR_BOOL for C. */ |
c906108c SS |
741 | if (TYPE_CODE (type) == TYPE_CODE_INT) |
742 | return 1; | |
c5aa993b | 743 | default: |
c906108c | 744 | break; |
c5aa993b | 745 | } |
c906108c SS |
746 | return 0; |
747 | } | |
748 | ||
749 | /* Returns non-zero if the value is a floating-point type */ | |
750 | int | |
fba45db2 | 751 | float_type (struct type *type) |
c906108c SS |
752 | { |
753 | CHECK_TYPEDEF (type); | |
c5aa993b | 754 | return TYPE_CODE (type) == TYPE_CODE_FLT; |
c906108c SS |
755 | } |
756 | ||
757 | /* Returns non-zero if the value is a pointer type */ | |
758 | int | |
fba45db2 | 759 | pointer_type (struct type *type) |
c906108c | 760 | { |
c5aa993b JM |
761 | return TYPE_CODE (type) == TYPE_CODE_PTR || |
762 | TYPE_CODE (type) == TYPE_CODE_REF; | |
c906108c SS |
763 | } |
764 | ||
765 | /* Returns non-zero if the value is a structured type */ | |
766 | int | |
fba45db2 | 767 | structured_type (struct type *type) |
c906108c SS |
768 | { |
769 | CHECK_TYPEDEF (type); | |
c5aa993b JM |
770 | switch (current_language->la_language) |
771 | { | |
772 | case language_c: | |
773 | case language_cplus: | |
eb392fbf | 774 | case language_objc: |
c5aa993b JM |
775 | return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || |
776 | (TYPE_CODE (type) == TYPE_CODE_UNION) || | |
777 | (TYPE_CODE (type) == TYPE_CODE_ARRAY); | |
750ba382 PM |
778 | case language_pascal: |
779 | return (TYPE_CODE(type) == TYPE_CODE_STRUCT) || | |
780 | (TYPE_CODE(type) == TYPE_CODE_UNION) || | |
781 | (TYPE_CODE(type) == TYPE_CODE_SET) || | |
782 | (TYPE_CODE(type) == TYPE_CODE_ARRAY); | |
c5aa993b JM |
783 | case language_m2: |
784 | return (TYPE_CODE (type) == TYPE_CODE_STRUCT) || | |
785 | (TYPE_CODE (type) == TYPE_CODE_SET) || | |
786 | (TYPE_CODE (type) == TYPE_CODE_ARRAY); | |
c5aa993b | 787 | default: |
c906108c | 788 | return (0); |
c5aa993b | 789 | } |
c906108c SS |
790 | } |
791 | #endif | |
792 | \f | |
c906108c SS |
793 | /* This page contains functions that return info about |
794 | (struct value) values used in GDB. */ | |
795 | ||
796 | /* Returns non-zero if the value VAL represents a true value. */ | |
797 | int | |
3d6d86c6 | 798 | value_true (struct value *val) |
c906108c SS |
799 | { |
800 | /* It is possible that we should have some sort of error if a non-boolean | |
801 | value is used in this context. Possibly dependent on some kind of | |
802 | "boolean-checking" option like range checking. But it should probably | |
803 | not depend on the language except insofar as is necessary to identify | |
804 | a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean | |
805 | should be an error, probably). */ | |
806 | return !value_logical_not (val); | |
807 | } | |
808 | \f | |
c906108c SS |
809 | /* This page contains functions for the printing out of |
810 | error messages that occur during type- and range- | |
811 | checking. */ | |
812 | ||
ddfe3c15 AC |
813 | /* These are called when a language fails a type- or range-check. The |
814 | first argument should be a printf()-style format string, and the | |
815 | rest of the arguments should be its arguments. If | |
816 | [type|range]_check is [type|range]_check_on, an error is printed; | |
817 | if [type|range]_check_warn, a warning; otherwise just the | |
818 | message. */ | |
c906108c SS |
819 | |
820 | void | |
ddfe3c15 | 821 | type_error (const char *string,...) |
c906108c | 822 | { |
c5aa993b | 823 | va_list args; |
c5aa993b | 824 | va_start (args, string); |
c906108c | 825 | |
ddfe3c15 AC |
826 | switch (type_check) |
827 | { | |
828 | case type_check_warn: | |
829 | vwarning (string, args); | |
830 | break; | |
831 | case type_check_on: | |
832 | verror (string, args); | |
833 | break; | |
834 | case type_check_off: | |
835 | /* FIXME: cagney/2002-01-30: Should this function print anything | |
836 | when type error is off? */ | |
837 | vfprintf_filtered (gdb_stderr, string, args); | |
838 | fprintf_filtered (gdb_stderr, "\n"); | |
839 | break; | |
840 | default: | |
e2e0b3e5 | 841 | internal_error (__FILE__, __LINE__, _("bad switch")); |
ddfe3c15 | 842 | } |
c5aa993b | 843 | va_end (args); |
c906108c SS |
844 | } |
845 | ||
846 | void | |
ddfe3c15 | 847 | range_error (const char *string,...) |
c906108c | 848 | { |
c5aa993b | 849 | va_list args; |
c5aa993b | 850 | va_start (args, string); |
c906108c | 851 | |
ddfe3c15 AC |
852 | switch (range_check) |
853 | { | |
854 | case range_check_warn: | |
855 | vwarning (string, args); | |
856 | break; | |
857 | case range_check_on: | |
858 | verror (string, args); | |
859 | break; | |
860 | case range_check_off: | |
861 | /* FIXME: cagney/2002-01-30: Should this function print anything | |
862 | when range error is off? */ | |
863 | vfprintf_filtered (gdb_stderr, string, args); | |
864 | fprintf_filtered (gdb_stderr, "\n"); | |
865 | break; | |
866 | default: | |
e2e0b3e5 | 867 | internal_error (__FILE__, __LINE__, _("bad switch")); |
ddfe3c15 | 868 | } |
c5aa993b | 869 | va_end (args); |
c906108c | 870 | } |
c906108c | 871 | \f |
c5aa993b | 872 | |
c906108c SS |
873 | /* This page contains miscellaneous functions */ |
874 | ||
875 | /* Return the language enum for a given language string. */ | |
876 | ||
877 | enum language | |
fba45db2 | 878 | language_enum (char *str) |
c906108c SS |
879 | { |
880 | int i; | |
881 | ||
c5aa993b | 882 | for (i = 0; i < languages_size; i++) |
591e78ff | 883 | if (strcmp (languages[i]->la_name, str) == 0) |
c906108c SS |
884 | return languages[i]->la_language; |
885 | ||
886 | return language_unknown; | |
887 | } | |
888 | ||
889 | /* Return the language struct for a given language enum. */ | |
890 | ||
891 | const struct language_defn * | |
fba45db2 | 892 | language_def (enum language lang) |
c906108c SS |
893 | { |
894 | int i; | |
895 | ||
c5aa993b JM |
896 | for (i = 0; i < languages_size; i++) |
897 | { | |
898 | if (languages[i]->la_language == lang) | |
899 | { | |
900 | return languages[i]; | |
901 | } | |
c906108c | 902 | } |
c906108c SS |
903 | return NULL; |
904 | } | |
905 | ||
906 | /* Return the language as a string */ | |
907 | char * | |
fba45db2 | 908 | language_str (enum language lang) |
c906108c SS |
909 | { |
910 | int i; | |
911 | ||
c5aa993b JM |
912 | for (i = 0; i < languages_size; i++) |
913 | { | |
914 | if (languages[i]->la_language == lang) | |
915 | { | |
916 | return languages[i]->la_name; | |
917 | } | |
c906108c | 918 | } |
c906108c SS |
919 | return "Unknown"; |
920 | } | |
921 | ||
922 | static void | |
fba45db2 | 923 | set_check (char *ignore, int from_tty) |
c906108c | 924 | { |
c5aa993b JM |
925 | printf_unfiltered ( |
926 | "\"set check\" must be followed by the name of a check subcommand.\n"); | |
927 | help_list (setchecklist, "set check ", -1, gdb_stdout); | |
c906108c SS |
928 | } |
929 | ||
930 | static void | |
fba45db2 | 931 | show_check (char *ignore, int from_tty) |
c906108c | 932 | { |
c5aa993b | 933 | cmd_show_list (showchecklist, from_tty, ""); |
c906108c SS |
934 | } |
935 | \f | |
936 | /* Add a language to the set of known languages. */ | |
937 | ||
938 | void | |
fba45db2 | 939 | add_language (const struct language_defn *lang) |
c906108c SS |
940 | { |
941 | if (lang->la_magic != LANG_MAGIC) | |
942 | { | |
c5aa993b JM |
943 | fprintf_unfiltered (gdb_stderr, "Magic number of %s language struct wrong\n", |
944 | lang->la_name); | |
e2e0b3e5 | 945 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c906108c SS |
946 | } |
947 | ||
948 | if (!languages) | |
949 | { | |
950 | languages_allocsize = DEFAULT_ALLOCSIZE; | |
951 | languages = (const struct language_defn **) xmalloc | |
952 | (languages_allocsize * sizeof (*languages)); | |
953 | } | |
954 | if (languages_size >= languages_allocsize) | |
955 | { | |
956 | languages_allocsize *= 2; | |
957 | languages = (const struct language_defn **) xrealloc ((char *) languages, | |
c5aa993b | 958 | languages_allocsize * sizeof (*languages)); |
c906108c SS |
959 | } |
960 | languages[languages_size++] = lang; | |
961 | } | |
962 | ||
f636b87d AF |
963 | /* Iterate through all registered languages looking for and calling |
964 | any non-NULL struct language_defn.skip_trampoline() functions. | |
965 | Return the result from the first that returns non-zero, or 0 if all | |
966 | `fail'. */ | |
967 | CORE_ADDR | |
52f729a7 | 968 | skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc) |
f636b87d AF |
969 | { |
970 | int i; | |
971 | ||
972 | for (i = 0; i < languages_size; i++) | |
973 | { | |
974 | if (languages[i]->skip_trampoline) | |
975 | { | |
52f729a7 | 976 | CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc); |
f636b87d AF |
977 | if (real_pc) |
978 | return real_pc; | |
979 | } | |
980 | } | |
981 | ||
982 | return 0; | |
983 | } | |
984 | ||
9a3d7dfd AF |
985 | /* Return demangled language symbol, or NULL. |
986 | FIXME: Options are only useful for certain languages and ignored | |
987 | by others, so it would be better to remove them here and have a | |
988 | more flexible demangler for the languages that need it. | |
989 | FIXME: Sometimes the demangler is invoked when we don't know the | |
990 | language, so we can't use this everywhere. */ | |
991 | char * | |
992 | language_demangle (const struct language_defn *current_language, | |
993 | const char *mangled, int options) | |
994 | { | |
995 | if (current_language != NULL && current_language->la_demangle) | |
996 | return current_language->la_demangle (mangled, options); | |
997 | return NULL; | |
998 | } | |
999 | ||
31c27f77 JJ |
1000 | /* Return class name from physname or NULL. */ |
1001 | char * | |
1002 | language_class_name_from_physname (const struct language_defn *current_language, | |
1003 | const char *physname) | |
1004 | { | |
1005 | if (current_language != NULL && current_language->la_class_name_from_physname) | |
1006 | return current_language->la_class_name_from_physname (physname); | |
1007 | return NULL; | |
1008 | } | |
1009 | ||
41f1b697 DJ |
1010 | /* Return non-zero if TYPE should be passed (and returned) by |
1011 | reference at the language level. */ | |
1012 | int | |
1013 | language_pass_by_reference (struct type *type) | |
1014 | { | |
1015 | return current_language->la_pass_by_reference (type); | |
1016 | } | |
1017 | ||
1018 | /* Return zero; by default, types are passed by value at the language | |
1019 | level. The target ABI may pass or return some structs by reference | |
1020 | independent of this. */ | |
1021 | int | |
1022 | default_pass_by_reference (struct type *type) | |
1023 | { | |
1024 | return 0; | |
1025 | } | |
1026 | ||
9f0a5303 JB |
1027 | /* Return the default string containing the list of characters |
1028 | delimiting words. This is a reasonable default value that | |
1029 | most languages should be able to use. */ | |
1030 | ||
1031 | char * | |
1032 | default_word_break_characters (void) | |
1033 | { | |
1034 | return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; | |
1035 | } | |
f636b87d | 1036 | |
e79af960 JB |
1037 | /* Print the index of array elements using the C99 syntax. */ |
1038 | ||
1039 | void | |
1040 | default_print_array_index (struct value *index_value, struct ui_file *stream, | |
79a45b7d | 1041 | const struct value_print_options *options) |
e79af960 JB |
1042 | { |
1043 | fprintf_filtered (stream, "["); | |
79a45b7d | 1044 | LA_VALUE_PRINT (index_value, stream, options); |
e79af960 JB |
1045 | fprintf_filtered (stream, "] = "); |
1046 | } | |
1047 | ||
ae6a3a4c TJB |
1048 | void |
1049 | default_get_string (struct value *value, gdb_byte **buffer, int *length, | |
1050 | const char **charset) | |
1051 | { | |
1052 | error (_("Getting a string is unsupported in this language.")); | |
1053 | } | |
1054 | ||
c906108c SS |
1055 | /* Define the language that is no language. */ |
1056 | ||
1057 | static int | |
fba45db2 | 1058 | unk_lang_parser (void) |
c906108c SS |
1059 | { |
1060 | return 1; | |
1061 | } | |
1062 | ||
1063 | static void | |
fba45db2 | 1064 | unk_lang_error (char *msg) |
c906108c | 1065 | { |
8a3fe4f8 | 1066 | error (_("Attempted to parse an expression with unknown language")); |
c906108c SS |
1067 | } |
1068 | ||
1069 | static void | |
6c7a06a3 TT |
1070 | unk_lang_emit_char (int c, struct type *type, struct ui_file *stream, |
1071 | int quoter) | |
c906108c | 1072 | { |
8a3fe4f8 | 1073 | error (_("internal error - unimplemented function unk_lang_emit_char called.")); |
c906108c SS |
1074 | } |
1075 | ||
1076 | static void | |
6c7a06a3 | 1077 | unk_lang_printchar (int c, struct type *type, struct ui_file *stream) |
c906108c | 1078 | { |
8a3fe4f8 | 1079 | error (_("internal error - unimplemented function unk_lang_printchar called.")); |
c906108c SS |
1080 | } |
1081 | ||
1082 | static void | |
6c7a06a3 TT |
1083 | unk_lang_printstr (struct ui_file *stream, struct type *type, |
1084 | const gdb_byte *string, unsigned int length, | |
1085 | int force_ellipses, | |
79a45b7d | 1086 | const struct value_print_options *options) |
c906108c | 1087 | { |
8a3fe4f8 | 1088 | error (_("internal error - unimplemented function unk_lang_printstr called.")); |
c906108c SS |
1089 | } |
1090 | ||
c906108c | 1091 | static void |
fba45db2 KB |
1092 | unk_lang_print_type (struct type *type, char *varstring, struct ui_file *stream, |
1093 | int show, int level) | |
c906108c | 1094 | { |
8a3fe4f8 | 1095 | error (_("internal error - unimplemented function unk_lang_print_type called.")); |
c906108c SS |
1096 | } |
1097 | ||
1098 | static int | |
fc1a4b47 | 1099 | unk_lang_val_print (struct type *type, const gdb_byte *valaddr, |
a2bd3dcd | 1100 | int embedded_offset, CORE_ADDR address, |
79a45b7d TT |
1101 | struct ui_file *stream, int recurse, |
1102 | const struct value_print_options *options) | |
c906108c | 1103 | { |
8a3fe4f8 | 1104 | error (_("internal error - unimplemented function unk_lang_val_print called.")); |
c906108c SS |
1105 | } |
1106 | ||
1107 | static int | |
79a45b7d TT |
1108 | unk_lang_value_print (struct value *val, struct ui_file *stream, |
1109 | const struct value_print_options *options) | |
c906108c | 1110 | { |
8a3fe4f8 | 1111 | error (_("internal error - unimplemented function unk_lang_value_print called.")); |
c906108c SS |
1112 | } |
1113 | ||
52f729a7 | 1114 | static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) |
f636b87d AF |
1115 | { |
1116 | return 0; | |
1117 | } | |
1118 | ||
9a3d7dfd AF |
1119 | /* Unknown languages just use the cplus demangler. */ |
1120 | static char *unk_lang_demangle (const char *mangled, int options) | |
1121 | { | |
1122 | return cplus_demangle (mangled, options); | |
1123 | } | |
1124 | ||
31c27f77 JJ |
1125 | static char *unk_lang_class_name (const char *mangled) |
1126 | { | |
1127 | return NULL; | |
1128 | } | |
9a3d7dfd | 1129 | |
c5aa993b JM |
1130 | static const struct op_print unk_op_print_tab[] = |
1131 | { | |
1132 | {NULL, OP_NULL, PREC_NULL, 0} | |
c906108c SS |
1133 | }; |
1134 | ||
f290d38e AC |
1135 | static void |
1136 | unknown_language_arch_info (struct gdbarch *gdbarch, | |
1137 | struct language_arch_info *lai) | |
1138 | { | |
1139 | lai->string_char_type = builtin_type (gdbarch)->builtin_char; | |
fbb06eb1 | 1140 | lai->bool_type_default = builtin_type (gdbarch)->builtin_int; |
5a44ea29 | 1141 | lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, |
f290d38e AC |
1142 | struct type *); |
1143 | } | |
1144 | ||
c5aa993b JM |
1145 | const struct language_defn unknown_language_defn = |
1146 | { | |
c906108c SS |
1147 | "unknown", |
1148 | language_unknown, | |
c906108c SS |
1149 | range_check_off, |
1150 | type_check_off, | |
63872f9d | 1151 | case_sensitive_on, |
9a044a89 TT |
1152 | array_row_major, |
1153 | macro_expansion_no, | |
5f9769d1 | 1154 | &exp_descriptor_standard, |
c906108c SS |
1155 | unk_lang_parser, |
1156 | unk_lang_error, | |
e85c3284 | 1157 | null_post_parser, |
c906108c SS |
1158 | unk_lang_printchar, /* Print character constant */ |
1159 | unk_lang_printstr, | |
1160 | unk_lang_emit_char, | |
c906108c | 1161 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
5c6ce71d | 1162 | default_print_typedef, /* Print a typedef using appropriate syntax */ |
c906108c SS |
1163 | unk_lang_val_print, /* Print a value using appropriate syntax */ |
1164 | unk_lang_value_print, /* Print a top-level value */ | |
f636b87d | 1165 | unk_lang_trampoline, /* Language specific skip_trampoline */ |
2b2d9e11 | 1166 | "this", /* name_of_this */ |
5f9a71c3 | 1167 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
b368761e | 1168 | basic_lookup_transparent_type,/* lookup_transparent_type */ |
9a3d7dfd | 1169 | unk_lang_demangle, /* Language specific symbol demangler */ |
31c27f77 | 1170 | unk_lang_class_name, /* Language specific class_name_from_physname */ |
c906108c SS |
1171 | unk_op_print_tab, /* expression operators for printing */ |
1172 | 1, /* c-style arrays */ | |
1173 | 0, /* String lower bound */ | |
6084f43a | 1174 | default_word_break_characters, |
41d27058 | 1175 | default_make_symbol_completion_list, |
f290d38e | 1176 | unknown_language_arch_info, /* la_language_arch_info. */ |
e79af960 | 1177 | default_print_array_index, |
41f1b697 | 1178 | default_pass_by_reference, |
ae6a3a4c | 1179 | default_get_string, |
c906108c SS |
1180 | LANG_MAGIC |
1181 | }; | |
1182 | ||
1183 | /* These two structs define fake entries for the "local" and "auto" options. */ | |
c5aa993b JM |
1184 | const struct language_defn auto_language_defn = |
1185 | { | |
c906108c SS |
1186 | "auto", |
1187 | language_auto, | |
c906108c SS |
1188 | range_check_off, |
1189 | type_check_off, | |
63872f9d | 1190 | case_sensitive_on, |
9a044a89 TT |
1191 | array_row_major, |
1192 | macro_expansion_no, | |
5f9769d1 | 1193 | &exp_descriptor_standard, |
c906108c SS |
1194 | unk_lang_parser, |
1195 | unk_lang_error, | |
e85c3284 | 1196 | null_post_parser, |
c906108c SS |
1197 | unk_lang_printchar, /* Print character constant */ |
1198 | unk_lang_printstr, | |
1199 | unk_lang_emit_char, | |
c906108c | 1200 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
5c6ce71d | 1201 | default_print_typedef, /* Print a typedef using appropriate syntax */ |
c906108c SS |
1202 | unk_lang_val_print, /* Print a value using appropriate syntax */ |
1203 | unk_lang_value_print, /* Print a top-level value */ | |
f636b87d | 1204 | unk_lang_trampoline, /* Language specific skip_trampoline */ |
2b2d9e11 | 1205 | "this", /* name_of_this */ |
5f9a71c3 | 1206 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
b368761e | 1207 | basic_lookup_transparent_type,/* lookup_transparent_type */ |
9a3d7dfd | 1208 | unk_lang_demangle, /* Language specific symbol demangler */ |
31c27f77 | 1209 | unk_lang_class_name, /* Language specific class_name_from_physname */ |
c906108c SS |
1210 | unk_op_print_tab, /* expression operators for printing */ |
1211 | 1, /* c-style arrays */ | |
1212 | 0, /* String lower bound */ | |
6084f43a | 1213 | default_word_break_characters, |
41d27058 | 1214 | default_make_symbol_completion_list, |
f290d38e | 1215 | unknown_language_arch_info, /* la_language_arch_info. */ |
e79af960 | 1216 | default_print_array_index, |
41f1b697 | 1217 | default_pass_by_reference, |
ae6a3a4c | 1218 | default_get_string, |
c906108c SS |
1219 | LANG_MAGIC |
1220 | }; | |
1221 | ||
c5aa993b JM |
1222 | const struct language_defn local_language_defn = |
1223 | { | |
c906108c SS |
1224 | "local", |
1225 | language_auto, | |
c906108c SS |
1226 | range_check_off, |
1227 | type_check_off, | |
63872f9d | 1228 | case_sensitive_on, |
7ca2d3a3 | 1229 | array_row_major, |
9a044a89 | 1230 | macro_expansion_no, |
5f9769d1 | 1231 | &exp_descriptor_standard, |
c906108c SS |
1232 | unk_lang_parser, |
1233 | unk_lang_error, | |
e85c3284 | 1234 | null_post_parser, |
c906108c SS |
1235 | unk_lang_printchar, /* Print character constant */ |
1236 | unk_lang_printstr, | |
1237 | unk_lang_emit_char, | |
c906108c | 1238 | unk_lang_print_type, /* Print a type using appropriate syntax */ |
5c6ce71d | 1239 | default_print_typedef, /* Print a typedef using appropriate syntax */ |
c906108c SS |
1240 | unk_lang_val_print, /* Print a value using appropriate syntax */ |
1241 | unk_lang_value_print, /* Print a top-level value */ | |
f636b87d | 1242 | unk_lang_trampoline, /* Language specific skip_trampoline */ |
2b2d9e11 | 1243 | "this", /* name_of_this */ |
5f9a71c3 | 1244 | basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ |
b368761e | 1245 | basic_lookup_transparent_type,/* lookup_transparent_type */ |
9a3d7dfd | 1246 | unk_lang_demangle, /* Language specific symbol demangler */ |
31c27f77 | 1247 | unk_lang_class_name, /* Language specific class_name_from_physname */ |
c906108c SS |
1248 | unk_op_print_tab, /* expression operators for printing */ |
1249 | 1, /* c-style arrays */ | |
1250 | 0, /* String lower bound */ | |
6084f43a | 1251 | default_word_break_characters, |
41d27058 | 1252 | default_make_symbol_completion_list, |
f290d38e | 1253 | unknown_language_arch_info, /* la_language_arch_info. */ |
e79af960 | 1254 | default_print_array_index, |
41f1b697 | 1255 | default_pass_by_reference, |
ae6a3a4c | 1256 | default_get_string, |
c906108c SS |
1257 | LANG_MAGIC |
1258 | }; | |
1259 | \f | |
f290d38e AC |
1260 | /* Per-architecture language information. */ |
1261 | ||
1262 | static struct gdbarch_data *language_gdbarch_data; | |
1263 | ||
1264 | struct language_gdbarch | |
1265 | { | |
1266 | /* A vector of per-language per-architecture info. Indexed by "enum | |
1267 | language". */ | |
1268 | struct language_arch_info arch_info[nr_languages]; | |
1269 | }; | |
1270 | ||
1271 | static void * | |
1272 | language_gdbarch_post_init (struct gdbarch *gdbarch) | |
1273 | { | |
1274 | struct language_gdbarch *l; | |
1275 | int i; | |
1276 | ||
1277 | l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); | |
1285b746 | 1278 | for (i = 0; i < languages_size; i++) |
f290d38e AC |
1279 | { |
1280 | if (languages[i] != NULL | |
1281 | && languages[i]->la_language_arch_info != NULL) | |
1282 | languages[i]->la_language_arch_info | |
1283 | (gdbarch, l->arch_info + languages[i]->la_language); | |
1284 | } | |
1285 | return l; | |
1286 | } | |
1287 | ||
1288 | struct type * | |
1289 | language_string_char_type (const struct language_defn *la, | |
1290 | struct gdbarch *gdbarch) | |
1291 | { | |
1292 | struct language_gdbarch *ld = gdbarch_data (gdbarch, | |
1293 | language_gdbarch_data); | |
aba2dd37 | 1294 | return ld->arch_info[la->la_language].string_char_type; |
f290d38e AC |
1295 | } |
1296 | ||
fbb06eb1 UW |
1297 | struct type * |
1298 | language_bool_type (const struct language_defn *la, | |
1299 | struct gdbarch *gdbarch) | |
1300 | { | |
1301 | struct language_gdbarch *ld = gdbarch_data (gdbarch, | |
1302 | language_gdbarch_data); | |
1303 | ||
1304 | if (ld->arch_info[la->la_language].bool_type_symbol) | |
1305 | { | |
1306 | struct symbol *sym; | |
1307 | sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, | |
1308 | NULL, VAR_DOMAIN, NULL); | |
1309 | if (sym) | |
1310 | { | |
1311 | struct type *type = SYMBOL_TYPE (sym); | |
1312 | if (type && TYPE_CODE (type) == TYPE_CODE_BOOL) | |
1313 | return type; | |
1314 | } | |
1315 | } | |
1316 | ||
1317 | return ld->arch_info[la->la_language].bool_type_default; | |
1318 | } | |
1319 | ||
f290d38e | 1320 | struct type * |
5a44ea29 | 1321 | language_lookup_primitive_type_by_name (const struct language_defn *la, |
f290d38e AC |
1322 | struct gdbarch *gdbarch, |
1323 | const char *name) | |
1324 | { | |
1325 | struct language_gdbarch *ld = gdbarch_data (gdbarch, | |
1326 | language_gdbarch_data); | |
aba2dd37 UW |
1327 | struct type *const *p; |
1328 | for (p = ld->arch_info[la->la_language].primitive_type_vector; | |
1329 | (*p) != NULL; | |
1330 | p++) | |
f290d38e | 1331 | { |
aba2dd37 UW |
1332 | if (strcmp (TYPE_NAME (*p), name) == 0) |
1333 | return (*p); | |
f290d38e AC |
1334 | } |
1335 | return (NULL); | |
1336 | } | |
1337 | ||
c906108c SS |
1338 | /* Initialize the language routines */ |
1339 | ||
1340 | void | |
fba45db2 | 1341 | _initialize_language (void) |
c906108c | 1342 | { |
c5aa993b JM |
1343 | struct cmd_list_element *set, *show; |
1344 | ||
f290d38e AC |
1345 | language_gdbarch_data |
1346 | = gdbarch_data_register_post_init (language_gdbarch_post_init); | |
1347 | ||
c5aa993b JM |
1348 | /* GDB commands for language specific stuff */ |
1349 | ||
4d28ad1e AC |
1350 | /* FIXME: cagney/2005-02-20: This should be implemented using an |
1351 | enum. */ | |
1352 | add_setshow_string_noescape_cmd ("language", class_support, &language, _("\ | |
1353 | Set the current source language."), _("\ | |
1354 | Show the current source language."), NULL, | |
1355 | set_language_command, | |
1356 | show_language_command, | |
1357 | &setlist, &showlist); | |
c5aa993b JM |
1358 | |
1359 | add_prefix_cmd ("check", no_class, set_check, | |
1bedd215 | 1360 | _("Set the status of the type/range checker."), |
c5aa993b JM |
1361 | &setchecklist, "set check ", 0, &setlist); |
1362 | add_alias_cmd ("c", "check", no_class, 1, &setlist); | |
1363 | add_alias_cmd ("ch", "check", no_class, 1, &setlist); | |
1364 | ||
1365 | add_prefix_cmd ("check", no_class, show_check, | |
1bedd215 | 1366 | _("Show the status of the type/range checker."), |
c5aa993b JM |
1367 | &showchecklist, "show check ", 0, &showlist); |
1368 | add_alias_cmd ("c", "check", no_class, 1, &showlist); | |
1369 | add_alias_cmd ("ch", "check", no_class, 1, &showlist); | |
1370 | ||
4d28ad1e AC |
1371 | /* FIXME: cagney/2005-02-20: This should be implemented using an |
1372 | enum. */ | |
1373 | add_setshow_string_noescape_cmd ("type", class_support, &type, _("\ | |
1374 | Set type checking. (on/warn/off/auto)"), _("\ | |
1375 | Show type checking. (on/warn/off/auto)"), NULL, | |
1376 | set_type_command, | |
1377 | show_type_command, | |
1378 | &setchecklist, &showchecklist); | |
1379 | ||
1380 | /* FIXME: cagney/2005-02-20: This should be implemented using an | |
1381 | enum. */ | |
1382 | add_setshow_string_noescape_cmd ("range", class_support, &range, _("\ | |
1383 | Set range checking. (on/warn/off/auto)"), _("\ | |
1384 | Show range checking. (on/warn/off/auto)"), NULL, | |
1385 | set_range_command, | |
1386 | show_range_command, | |
1387 | &setchecklist, &showchecklist); | |
1388 | ||
1389 | /* FIXME: cagney/2005-02-20: This should be implemented using an | |
1390 | enum. */ | |
1391 | add_setshow_string_noescape_cmd ("case-sensitive", class_support, | |
1392 | &case_sensitive, _("\ | |
1393 | Set case sensitivity in name search. (on/off/auto)"), _("\ | |
1394 | Show case sensitivity in name search. (on/off/auto)"), _("\ | |
1395 | For Fortran the default is off; for other languages the default is on."), | |
1396 | set_case_command, | |
1397 | show_case_command, | |
1398 | &setlist, &showlist); | |
63872f9d | 1399 | |
c5aa993b JM |
1400 | add_language (&unknown_language_defn); |
1401 | add_language (&local_language_defn); | |
1402 | add_language (&auto_language_defn); | |
1403 | ||
1b36a34b JK |
1404 | language = xstrdup ("auto"); |
1405 | type = xstrdup ("auto"); | |
1406 | range = xstrdup ("auto"); | |
1407 | case_sensitive = xstrdup ("auto"); | |
63872f9d JG |
1408 | |
1409 | /* Have the above take effect */ | |
1410 | set_language (language_auto); | |
c906108c | 1411 | } |