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