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