Upgrade GDB from 7.4.1 to 7.6.1 on the vendor branch
[dragonfly.git] / contrib / gdb-7 / gdb / language.c
CommitLineData
5796c8dc
SS
1/* Multiple source language support for GDB.
2
ef5ccd6c 3 Copyright (C) 1991-2013 Free Software Foundation, Inc.
5796c8dc
SS
4
5 Contributed by the Department of Computer Science at the State University
6 of New York at Buffalo.
7
8 This file is part of GDB.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23/* This file contains functions that return things that are specific
24 to languages. Each function should examine current_language if necessary,
c50c785c 25 and return the appropriate result. */
5796c8dc
SS
26
27/* FIXME: Most of these would be better organized as macros which
28 return data out of a "language-specific" struct pointer that is set
29 whenever the working language changes. That would be a lot faster. */
30
31#include "defs.h"
32#include <ctype.h>
33#include "gdb_string.h"
34
35#include "symtab.h"
36#include "gdbtypes.h"
37#include "value.h"
38#include "gdbcmd.h"
39#include "expression.h"
40#include "language.h"
41#include "target.h"
42#include "parser-defs.h"
43#include "jv-lang.h"
44#include "demangle.h"
45#include "symfile.h"
46
47extern void _initialize_language (void);
48
49static void unk_lang_error (char *);
50
51static int unk_lang_parser (void);
52
53static void show_check (char *, int);
54
55static void set_check (char *, int);
56
ef5ccd6c 57static void set_range_case (void);
5796c8dc
SS
58
59static void unk_lang_emit_char (int c, struct type *type,
60 struct ui_file *stream, int quoter);
61
62static void unk_lang_printchar (int c, struct type *type,
63 struct ui_file *stream);
64
ef5ccd6c
JM
65static void unk_lang_value_print (struct value *, struct ui_file *,
66 const struct value_print_options *);
5796c8dc
SS
67
68static CORE_ADDR unk_lang_trampoline (struct frame_info *, CORE_ADDR pc);
69
70/* Forward declaration */
71extern const struct language_defn unknown_language_defn;
72
73/* The current (default at startup) state of type and range checking.
74 (If the modes are set to "auto", though, these are changed based
75 on the default language at startup, and then again based on the
76 language of the first source file. */
77
78enum range_mode range_mode = range_mode_auto;
79enum range_check range_check = range_check_off;
5796c8dc
SS
80enum case_mode case_mode = case_mode_auto;
81enum case_sensitivity case_sensitivity = case_sensitive_on;
82
c50c785c 83/* The current language and language_mode (see language.h). */
5796c8dc
SS
84
85const struct language_defn *current_language = &unknown_language_defn;
86enum language_mode language_mode = language_mode_auto;
87
88/* The language that the user expects to be typing in (the language
89 of main(), or the last language we notified them about, or C). */
90
91const struct language_defn *expected_language;
92
93/* The list of supported languages. The list itself is malloc'd. */
94
95static const struct language_defn **languages;
96static unsigned languages_size;
97static unsigned languages_allocsize;
98#define DEFAULT_ALLOCSIZE 4
99
100/* The current values of the "set language/type/range" enum
101 commands. */
102static const char *language;
103static const char *type;
104static const char *range;
105static const char *case_sensitive;
106
107/* Warning issued when current_language and the language of the current
c50c785c 108 frame do not match. */
5796c8dc
SS
109char lang_frame_mismatch_warn[] =
110"Warning: the current language does not match this frame.";
111\f
112/* This page contains the functions corresponding to GDB commands
c50c785c 113 and their helpers. */
5796c8dc
SS
114
115/* Show command. Display a warning if the language set
c50c785c 116 does not match the frame. */
5796c8dc
SS
117static void
118show_language_command (struct ui_file *file, int from_tty,
119 struct cmd_list_element *c, const char *value)
120{
c50c785c 121 enum language flang; /* The language of the current frame. */
5796c8dc
SS
122
123 if (language_mode == language_mode_auto)
124 fprintf_filtered (gdb_stdout,
125 _("The current source language is "
126 "\"auto; currently %s\".\n"),
127 current_language->la_name);
128 else
c50c785c
JM
129 fprintf_filtered (gdb_stdout,
130 _("The current source language is \"%s\".\n"),
5796c8dc
SS
131 current_language->la_name);
132
133 flang = get_frame_language ();
134 if (flang != language_unknown &&
135 language_mode == language_mode_manual &&
136 current_language->la_language != flang)
137 printf_filtered ("%s\n", lang_frame_mismatch_warn);
138}
139
c50c785c 140/* Set command. Change the current working language. */
5796c8dc
SS
141static void
142set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
143{
144 int i;
145 enum language flang;
146
147 /* Search the list of languages for a match. */
148 for (i = 0; i < languages_size; i++)
149 {
150 if (strcmp (languages[i]->la_name, language) == 0)
151 {
152 /* Found it! Go into manual mode, and use this language. */
153 if (languages[i]->la_language == language_auto)
154 {
155 /* Enter auto mode. Set to the current frame's language, if
156 known, or fallback to the initial language. */
157 language_mode = language_mode_auto;
158 flang = get_frame_language ();
159 if (flang != language_unknown)
160 set_language (flang);
161 else
162 set_initial_language ();
163 expected_language = current_language;
164 return;
165 }
166 else
167 {
168 /* Enter manual mode. Set the specified language. */
169 language_mode = language_mode_manual;
170 current_language = languages[i];
ef5ccd6c 171 set_range_case ();
5796c8dc
SS
172 expected_language = current_language;
173 return;
174 }
175 }
176 }
177
178 internal_error (__FILE__, __LINE__,
179 "Couldn't find language `%s' in known languages list.",
180 language);
181}
182
5796c8dc 183/* Show command. Display a warning if the range setting does
c50c785c 184 not match the current language. */
5796c8dc
SS
185static void
186show_range_command (struct ui_file *file, int from_tty,
187 struct cmd_list_element *c, const char *value)
188{
189 if (range_mode == range_mode_auto)
190 {
191 char *tmp;
192
193 switch (range_check)
194 {
195 case range_check_on:
196 tmp = "on";
197 break;
198 case range_check_off:
199 tmp = "off";
200 break;
201 case range_check_warn:
202 tmp = "warn";
203 break;
204 default:
205 internal_error (__FILE__, __LINE__,
206 "Unrecognized range check setting.");
207 }
208
209 fprintf_filtered (gdb_stdout,
210 _("Range checking is \"auto; currently %s\".\n"),
211 tmp);
212 }
213 else
214 fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"),
215 value);
216
217 if (range_check != current_language->la_range_check)
218 warning (_("the current range check setting "
219 "does not match the language.\n"));
220}
221
c50c785c 222/* Set command. Change the setting for range checking. */
5796c8dc
SS
223static void
224set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
225{
226 if (strcmp (range, "on") == 0)
227 {
228 range_check = range_check_on;
229 range_mode = range_mode_manual;
230 }
231 else if (strcmp (range, "warn") == 0)
232 {
233 range_check = range_check_warn;
234 range_mode = range_mode_manual;
235 }
236 else if (strcmp (range, "off") == 0)
237 {
238 range_check = range_check_off;
239 range_mode = range_mode_manual;
240 }
241 else if (strcmp (range, "auto") == 0)
242 {
243 range_mode = range_mode_auto;
ef5ccd6c 244 set_range_case ();
5796c8dc
SS
245 return;
246 }
247 else
248 {
249 internal_error (__FILE__, __LINE__,
250 _("Unrecognized range check setting: \"%s\""), range);
251 }
252 if (range_check != current_language->la_range_check)
253 warning (_("the current range check setting "
254 "does not match the language.\n"));
255}
256
257/* Show command. Display a warning if the case sensitivity setting does
c50c785c 258 not match the current language. */
5796c8dc
SS
259static void
260show_case_command (struct ui_file *file, int from_tty,
261 struct cmd_list_element *c, const char *value)
262{
263 if (case_mode == case_mode_auto)
264 {
265 char *tmp = NULL;
266
267 switch (case_sensitivity)
268 {
269 case case_sensitive_on:
270 tmp = "on";
271 break;
272 case case_sensitive_off:
273 tmp = "off";
274 break;
275 default:
276 internal_error (__FILE__, __LINE__,
277 "Unrecognized case-sensitive setting.");
278 }
279
280 fprintf_filtered (gdb_stdout,
281 _("Case sensitivity in "
282 "name search is \"auto; currently %s\".\n"),
283 tmp);
284 }
285 else
c50c785c
JM
286 fprintf_filtered (gdb_stdout,
287 _("Case sensitivity in name search is \"%s\".\n"),
5796c8dc
SS
288 value);
289
290 if (case_sensitivity != current_language->la_case_sensitivity)
291 warning (_("the current case sensitivity setting does not match "
292 "the language.\n"));
293}
294
295/* Set command. Change the setting for case sensitivity. */
296
297static void
298set_case_command (char *ignore, int from_tty, struct cmd_list_element *c)
299{
300 if (strcmp (case_sensitive, "on") == 0)
301 {
302 case_sensitivity = case_sensitive_on;
303 case_mode = case_mode_manual;
304 }
305 else if (strcmp (case_sensitive, "off") == 0)
306 {
307 case_sensitivity = case_sensitive_off;
308 case_mode = case_mode_manual;
309 }
310 else if (strcmp (case_sensitive, "auto") == 0)
311 {
312 case_mode = case_mode_auto;
ef5ccd6c 313 set_range_case ();
5796c8dc
SS
314 return;
315 }
316 else
317 {
318 internal_error (__FILE__, __LINE__,
319 "Unrecognized case-sensitive setting: \"%s\"",
320 case_sensitive);
321 }
322
323 if (case_sensitivity != current_language->la_case_sensitivity)
324 warning (_("the current case sensitivity setting does not match "
325 "the language.\n"));
326}
327
328/* Set the status of range and type checking and case sensitivity based on
329 the current modes and the current language.
330 If SHOW is non-zero, then print out the current language,
c50c785c 331 type and range checking status. */
5796c8dc 332static void
ef5ccd6c 333set_range_case (void)
5796c8dc
SS
334{
335 if (range_mode == range_mode_auto)
336 range_check = current_language->la_range_check;
337
5796c8dc
SS
338 if (case_mode == case_mode_auto)
339 case_sensitivity = current_language->la_case_sensitivity;
340}
341
c50c785c
JM
342/* Set current language to (enum language) LANG. Returns previous
343 language. */
5796c8dc
SS
344
345enum language
346set_language (enum language lang)
347{
348 int i;
349 enum language prev_language;
350
351 prev_language = current_language->la_language;
352
353 for (i = 0; i < languages_size; i++)
354 {
355 if (languages[i]->la_language == lang)
356 {
357 current_language = languages[i];
ef5ccd6c 358 set_range_case ();
5796c8dc
SS
359 break;
360 }
361 }
362
363 return prev_language;
364}
365\f
366
367/* Print out the current language settings: language, range and
368 type checking. If QUIETLY, print only what has changed. */
369
370void
371language_info (int quietly)
372{
373 if (quietly && expected_language == current_language)
374 return;
375
376 expected_language = current_language;
377 printf_unfiltered (_("Current language: %s\n"), language);
378 show_language_command (NULL, 1, NULL, NULL);
379
380 if (!quietly)
381 {
5796c8dc
SS
382 printf_unfiltered (_("Range checking: %s\n"), range);
383 show_range_command (NULL, 1, NULL, NULL);
384 printf_unfiltered (_("Case sensitivity: %s\n"), case_sensitive);
385 show_case_command (NULL, 1, NULL, NULL);
386 }
387}
388\f
5796c8dc 389
c50c785c 390/* Returns non-zero if the value is a pointer type. */
5796c8dc
SS
391int
392pointer_type (struct type *type)
393{
394 return TYPE_CODE (type) == TYPE_CODE_PTR ||
395 TYPE_CODE (type) == TYPE_CODE_REF;
396}
397
5796c8dc
SS
398\f
399/* This page contains functions that return info about
c50c785c 400 (struct value) values used in GDB. */
5796c8dc 401
c50c785c 402/* Returns non-zero if the value VAL represents a true value. */
5796c8dc
SS
403int
404value_true (struct value *val)
405{
406 /* It is possible that we should have some sort of error if a non-boolean
407 value is used in this context. Possibly dependent on some kind of
408 "boolean-checking" option like range checking. But it should probably
409 not depend on the language except insofar as is necessary to identify
410 a "boolean" value (i.e. in C using a float, pointer, etc., as a boolean
411 should be an error, probably). */
412 return !value_logical_not (val);
413}
414\f
415/* This page contains functions for the printing out of
416 error messages that occur during type- and range-
c50c785c 417 checking. */
5796c8dc 418
ef5ccd6c 419/* This is called when a language fails a range-check. The
5796c8dc 420 first argument should be a printf()-style format string, and the
ef5ccd6c
JM
421 rest of the arguments should be its arguments. If range_check is
422 range_check_on, an error is printed; if range_check_warn, a warning;
423 otherwise just the message. */
5796c8dc
SS
424
425void
426range_error (const char *string,...)
427{
428 va_list args;
5796c8dc 429
cf7f2e2d 430 va_start (args, string);
5796c8dc
SS
431 switch (range_check)
432 {
433 case range_check_warn:
434 vwarning (string, args);
435 break;
436 case range_check_on:
437 verror (string, args);
438 break;
439 case range_check_off:
440 /* FIXME: cagney/2002-01-30: Should this function print anything
441 when range error is off? */
442 vfprintf_filtered (gdb_stderr, string, args);
443 fprintf_filtered (gdb_stderr, "\n");
444 break;
445 default:
446 internal_error (__FILE__, __LINE__, _("bad switch"));
447 }
448 va_end (args);
449}
450\f
451
c50c785c 452/* This page contains miscellaneous functions. */
5796c8dc 453
c50c785c 454/* Return the language enum for a given language string. */
5796c8dc
SS
455
456enum language
457language_enum (char *str)
458{
459 int i;
460
461 for (i = 0; i < languages_size; i++)
462 if (strcmp (languages[i]->la_name, str) == 0)
463 return languages[i]->la_language;
464
465 return language_unknown;
466}
467
c50c785c 468/* Return the language struct for a given language enum. */
5796c8dc
SS
469
470const struct language_defn *
471language_def (enum language lang)
472{
473 int i;
474
475 for (i = 0; i < languages_size; i++)
476 {
477 if (languages[i]->la_language == lang)
478 {
479 return languages[i];
480 }
481 }
482 return NULL;
483}
484
c50c785c 485/* Return the language as a string. */
5796c8dc
SS
486char *
487language_str (enum language lang)
488{
489 int i;
490
491 for (i = 0; i < languages_size; i++)
492 {
493 if (languages[i]->la_language == lang)
494 {
495 return languages[i]->la_name;
496 }
497 }
498 return "Unknown";
499}
500
501static void
502set_check (char *ignore, int from_tty)
503{
504 printf_unfiltered (
505 "\"set check\" must be followed by the name of a check subcommand.\n");
506 help_list (setchecklist, "set check ", -1, gdb_stdout);
507}
508
509static void
510show_check (char *ignore, int from_tty)
511{
512 cmd_show_list (showchecklist, from_tty, "");
513}
514\f
515/* Add a language to the set of known languages. */
516
517void
518add_language (const struct language_defn *lang)
519{
520 /* For the "set language" command. */
521 static char **language_names = NULL;
522 /* For the "help set language" command. */
523 char *language_set_doc = NULL;
524
525 int i;
526 struct ui_file *tmp_stream;
527
528 if (lang->la_magic != LANG_MAGIC)
529 {
c50c785c
JM
530 fprintf_unfiltered (gdb_stderr,
531 "Magic number of %s language struct wrong\n",
5796c8dc 532 lang->la_name);
c50c785c
JM
533 internal_error (__FILE__, __LINE__,
534 _("failed internal consistency check"));
5796c8dc
SS
535 }
536
537 if (!languages)
538 {
539 languages_allocsize = DEFAULT_ALLOCSIZE;
540 languages = (const struct language_defn **) xmalloc
541 (languages_allocsize * sizeof (*languages));
542 }
543 if (languages_size >= languages_allocsize)
544 {
545 languages_allocsize *= 2;
546 languages = (const struct language_defn **) xrealloc ((char *) languages,
547 languages_allocsize * sizeof (*languages));
548 }
549 languages[languages_size++] = lang;
550
551 /* Build the language names array, to be used as enumeration in the
552 set language" enum command. */
553 language_names = xrealloc (language_names,
554 (languages_size + 1) * sizeof (const char *));
555 for (i = 0; i < languages_size; ++i)
556 language_names[i] = languages[i]->la_name;
557 language_names[i] = NULL;
558
559 /* Build the "help set language" docs. */
560 tmp_stream = mem_fileopen ();
561
c50c785c
JM
562 fprintf_unfiltered (tmp_stream,
563 _("Set the current source language.\n"
564 "The currently understood settings are:\n\nlocal or "
565 "auto Automatic setting based on source file\n"));
5796c8dc
SS
566
567 for (i = 0; i < languages_size; ++i)
568 {
569 /* Already dealt with these above. */
570 if (languages[i]->la_language == language_unknown
571 || languages[i]->la_language == language_auto)
572 continue;
573
574 /* FIXME: i18n: for now assume that the human-readable name
575 is just a capitalization of the internal name. */
576 fprintf_unfiltered (tmp_stream, "%-16s Use the %c%s language\n",
577 languages[i]->la_name,
578 /* Capitalize first letter of language
579 name. */
580 toupper (languages[i]->la_name[0]),
581 languages[i]->la_name + 1);
582 }
583
584 language_set_doc = ui_file_xstrdup (tmp_stream, NULL);
585 ui_file_delete (tmp_stream);
586
587 add_setshow_enum_cmd ("language", class_support,
588 (const char **) language_names,
589 &language,
c50c785c
JM
590 language_set_doc,
591 _("Show the current source language."),
592 NULL, set_language_command,
5796c8dc
SS
593 show_language_command,
594 &setlist, &showlist);
595
596 xfree (language_set_doc);
597}
598
599/* Iterate through all registered languages looking for and calling
600 any non-NULL struct language_defn.skip_trampoline() functions.
601 Return the result from the first that returns non-zero, or 0 if all
602 `fail'. */
603CORE_ADDR
604skip_language_trampoline (struct frame_info *frame, CORE_ADDR pc)
605{
606 int i;
607
608 for (i = 0; i < languages_size; i++)
609 {
610 if (languages[i]->skip_trampoline)
611 {
612 CORE_ADDR real_pc = (languages[i]->skip_trampoline) (frame, pc);
cf7f2e2d 613
5796c8dc
SS
614 if (real_pc)
615 return real_pc;
616 }
617 }
618
619 return 0;
620}
621
c50c785c 622/* Return demangled language symbol, or NULL.
5796c8dc
SS
623 FIXME: Options are only useful for certain languages and ignored
624 by others, so it would be better to remove them here and have a
c50c785c 625 more flexible demangler for the languages that need it.
5796c8dc
SS
626 FIXME: Sometimes the demangler is invoked when we don't know the
627 language, so we can't use this everywhere. */
628char *
629language_demangle (const struct language_defn *current_language,
630 const char *mangled, int options)
631{
632 if (current_language != NULL && current_language->la_demangle)
633 return current_language->la_demangle (mangled, options);
634 return NULL;
635}
636
637/* Return class name from physname or NULL. */
638char *
c50c785c 639language_class_name_from_physname (const struct language_defn *lang,
5796c8dc
SS
640 const char *physname)
641{
c50c785c
JM
642 if (lang != NULL && lang->la_class_name_from_physname)
643 return lang->la_class_name_from_physname (physname);
5796c8dc
SS
644 return NULL;
645}
646
647/* Return non-zero if TYPE should be passed (and returned) by
648 reference at the language level. */
649int
650language_pass_by_reference (struct type *type)
651{
652 return current_language->la_pass_by_reference (type);
653}
654
655/* Return zero; by default, types are passed by value at the language
656 level. The target ABI may pass or return some structs by reference
657 independent of this. */
658int
659default_pass_by_reference (struct type *type)
660{
661 return 0;
662}
663
664/* Return the default string containing the list of characters
665 delimiting words. This is a reasonable default value that
666 most languages should be able to use. */
667
668char *
669default_word_break_characters (void)
670{
671 return " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
672}
673
674/* Print the index of array elements using the C99 syntax. */
675
676void
677default_print_array_index (struct value *index_value, struct ui_file *stream,
678 const struct value_print_options *options)
679{
680 fprintf_filtered (stream, "[");
681 LA_VALUE_PRINT (index_value, stream, options);
682 fprintf_filtered (stream, "] = ");
683}
684
685void
686default_get_string (struct value *value, gdb_byte **buffer, int *length,
cf7f2e2d 687 struct type **char_type, const char **charset)
5796c8dc
SS
688{
689 error (_("Getting a string is unsupported in this language."));
690}
691
692/* Define the language that is no language. */
693
694static int
695unk_lang_parser (void)
696{
697 return 1;
698}
699
700static void
701unk_lang_error (char *msg)
702{
703 error (_("Attempted to parse an expression with unknown language"));
704}
705
706static void
707unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
708 int quoter)
709{
c50c785c
JM
710 error (_("internal error - unimplemented "
711 "function unk_lang_emit_char called."));
5796c8dc
SS
712}
713
714static void
715unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
716{
c50c785c
JM
717 error (_("internal error - unimplemented "
718 "function unk_lang_printchar called."));
5796c8dc
SS
719}
720
721static void
722unk_lang_printstr (struct ui_file *stream, struct type *type,
723 const gdb_byte *string, unsigned int length,
cf7f2e2d 724 const char *encoding, int force_ellipses,
5796c8dc
SS
725 const struct value_print_options *options)
726{
c50c785c
JM
727 error (_("internal error - unimplemented "
728 "function unk_lang_printstr called."));
5796c8dc
SS
729}
730
731static void
cf7f2e2d 732unk_lang_print_type (struct type *type, const char *varstring,
ef5ccd6c
JM
733 struct ui_file *stream, int show, int level,
734 const struct type_print_options *flags)
5796c8dc 735{
c50c785c
JM
736 error (_("internal error - unimplemented "
737 "function unk_lang_print_type called."));
5796c8dc
SS
738}
739
ef5ccd6c 740static void
5796c8dc
SS
741unk_lang_val_print (struct type *type, const gdb_byte *valaddr,
742 int embedded_offset, CORE_ADDR address,
743 struct ui_file *stream, int recurse,
cf7f2e2d 744 const struct value *val,
5796c8dc
SS
745 const struct value_print_options *options)
746{
c50c785c
JM
747 error (_("internal error - unimplemented "
748 "function unk_lang_val_print called."));
5796c8dc
SS
749}
750
ef5ccd6c 751static void
5796c8dc
SS
752unk_lang_value_print (struct value *val, struct ui_file *stream,
753 const struct value_print_options *options)
754{
c50c785c
JM
755 error (_("internal error - unimplemented "
756 "function unk_lang_value_print called."));
5796c8dc
SS
757}
758
759static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc)
760{
761 return 0;
762}
763
764/* Unknown languages just use the cplus demangler. */
765static char *unk_lang_demangle (const char *mangled, int options)
766{
767 return cplus_demangle (mangled, options);
768}
769
770static char *unk_lang_class_name (const char *mangled)
771{
772 return NULL;
773}
774
775static const struct op_print unk_op_print_tab[] =
776{
777 {NULL, OP_NULL, PREC_NULL, 0}
778};
779
780static void
781unknown_language_arch_info (struct gdbarch *gdbarch,
782 struct language_arch_info *lai)
783{
784 lai->string_char_type = builtin_type (gdbarch)->builtin_char;
785 lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
786 lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
787 struct type *);
788}
789
790const struct language_defn unknown_language_defn =
791{
792 "unknown",
793 language_unknown,
794 range_check_off,
5796c8dc
SS
795 case_sensitive_on,
796 array_row_major,
797 macro_expansion_no,
798 &exp_descriptor_standard,
799 unk_lang_parser,
800 unk_lang_error,
801 null_post_parser,
802 unk_lang_printchar, /* Print character constant */
803 unk_lang_printstr,
804 unk_lang_emit_char,
805 unk_lang_print_type, /* Print a type using appropriate syntax */
806 default_print_typedef, /* Print a typedef using appropriate syntax */
807 unk_lang_val_print, /* Print a value using appropriate syntax */
808 unk_lang_value_print, /* Print a top-level value */
ef5ccd6c 809 default_read_var_value, /* la_read_var_value */
5796c8dc
SS
810 unk_lang_trampoline, /* Language specific skip_trampoline */
811 "this", /* name_of_this */
812 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
813 basic_lookup_transparent_type,/* lookup_transparent_type */
814 unk_lang_demangle, /* Language specific symbol demangler */
c50c785c
JM
815 unk_lang_class_name, /* Language specific
816 class_name_from_physname */
5796c8dc
SS
817 unk_op_print_tab, /* expression operators for printing */
818 1, /* c-style arrays */
819 0, /* String lower bound */
820 default_word_break_characters,
821 default_make_symbol_completion_list,
822 unknown_language_arch_info, /* la_language_arch_info. */
823 default_print_array_index,
824 default_pass_by_reference,
825 default_get_string,
ef5ccd6c 826 NULL, /* la_get_symbol_name_cmp */
a45ae5f8 827 iterate_over_symbols,
5796c8dc
SS
828 LANG_MAGIC
829};
830
c50c785c
JM
831/* These two structs define fake entries for the "local" and "auto"
832 options. */
5796c8dc
SS
833const struct language_defn auto_language_defn =
834{
835 "auto",
836 language_auto,
837 range_check_off,
5796c8dc
SS
838 case_sensitive_on,
839 array_row_major,
840 macro_expansion_no,
841 &exp_descriptor_standard,
842 unk_lang_parser,
843 unk_lang_error,
844 null_post_parser,
845 unk_lang_printchar, /* Print character constant */
846 unk_lang_printstr,
847 unk_lang_emit_char,
848 unk_lang_print_type, /* Print a type using appropriate syntax */
849 default_print_typedef, /* Print a typedef using appropriate syntax */
850 unk_lang_val_print, /* Print a value using appropriate syntax */
851 unk_lang_value_print, /* Print a top-level value */
ef5ccd6c 852 default_read_var_value, /* la_read_var_value */
5796c8dc
SS
853 unk_lang_trampoline, /* Language specific skip_trampoline */
854 "this", /* name_of_this */
855 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
856 basic_lookup_transparent_type,/* lookup_transparent_type */
857 unk_lang_demangle, /* Language specific symbol demangler */
c50c785c
JM
858 unk_lang_class_name, /* Language specific
859 class_name_from_physname */
5796c8dc
SS
860 unk_op_print_tab, /* expression operators for printing */
861 1, /* c-style arrays */
862 0, /* String lower bound */
863 default_word_break_characters,
864 default_make_symbol_completion_list,
865 unknown_language_arch_info, /* la_language_arch_info. */
866 default_print_array_index,
867 default_pass_by_reference,
868 default_get_string,
ef5ccd6c 869 NULL, /* la_get_symbol_name_cmp */
a45ae5f8 870 iterate_over_symbols,
5796c8dc
SS
871 LANG_MAGIC
872};
873
874const struct language_defn local_language_defn =
875{
876 "local",
877 language_auto,
878 range_check_off,
5796c8dc
SS
879 case_sensitive_on,
880 array_row_major,
881 macro_expansion_no,
882 &exp_descriptor_standard,
883 unk_lang_parser,
884 unk_lang_error,
885 null_post_parser,
886 unk_lang_printchar, /* Print character constant */
887 unk_lang_printstr,
888 unk_lang_emit_char,
889 unk_lang_print_type, /* Print a type using appropriate syntax */
890 default_print_typedef, /* Print a typedef using appropriate syntax */
891 unk_lang_val_print, /* Print a value using appropriate syntax */
892 unk_lang_value_print, /* Print a top-level value */
ef5ccd6c 893 default_read_var_value, /* la_read_var_value */
5796c8dc
SS
894 unk_lang_trampoline, /* Language specific skip_trampoline */
895 "this", /* name_of_this */
896 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
897 basic_lookup_transparent_type,/* lookup_transparent_type */
898 unk_lang_demangle, /* Language specific symbol demangler */
c50c785c
JM
899 unk_lang_class_name, /* Language specific
900 class_name_from_physname */
5796c8dc
SS
901 unk_op_print_tab, /* expression operators for printing */
902 1, /* c-style arrays */
903 0, /* String lower bound */
904 default_word_break_characters,
905 default_make_symbol_completion_list,
906 unknown_language_arch_info, /* la_language_arch_info. */
907 default_print_array_index,
908 default_pass_by_reference,
909 default_get_string,
ef5ccd6c 910 NULL, /* la_get_symbol_name_cmp */
a45ae5f8 911 iterate_over_symbols,
5796c8dc
SS
912 LANG_MAGIC
913};
914\f
915/* Per-architecture language information. */
916
917static struct gdbarch_data *language_gdbarch_data;
918
919struct language_gdbarch
920{
921 /* A vector of per-language per-architecture info. Indexed by "enum
922 language". */
923 struct language_arch_info arch_info[nr_languages];
924};
925
926static void *
927language_gdbarch_post_init (struct gdbarch *gdbarch)
928{
929 struct language_gdbarch *l;
930 int i;
931
932 l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch);
933 for (i = 0; i < languages_size; i++)
934 {
935 if (languages[i] != NULL
936 && languages[i]->la_language_arch_info != NULL)
937 languages[i]->la_language_arch_info
938 (gdbarch, l->arch_info + languages[i]->la_language);
939 }
940 return l;
941}
942
943struct type *
944language_string_char_type (const struct language_defn *la,
945 struct gdbarch *gdbarch)
946{
947 struct language_gdbarch *ld = gdbarch_data (gdbarch,
948 language_gdbarch_data);
cf7f2e2d 949
5796c8dc
SS
950 return ld->arch_info[la->la_language].string_char_type;
951}
952
953struct type *
954language_bool_type (const struct language_defn *la,
955 struct gdbarch *gdbarch)
956{
957 struct language_gdbarch *ld = gdbarch_data (gdbarch,
958 language_gdbarch_data);
959
960 if (ld->arch_info[la->la_language].bool_type_symbol)
961 {
962 struct symbol *sym;
cf7f2e2d 963
5796c8dc
SS
964 sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
965 NULL, VAR_DOMAIN, NULL);
966 if (sym)
967 {
968 struct type *type = SYMBOL_TYPE (sym);
cf7f2e2d 969
5796c8dc
SS
970 if (type && TYPE_CODE (type) == TYPE_CODE_BOOL)
971 return type;
972 }
973 }
974
975 return ld->arch_info[la->la_language].bool_type_default;
976}
977
978struct type *
979language_lookup_primitive_type_by_name (const struct language_defn *la,
980 struct gdbarch *gdbarch,
981 const char *name)
982{
983 struct language_gdbarch *ld = gdbarch_data (gdbarch,
984 language_gdbarch_data);
985 struct type *const *p;
cf7f2e2d 986
5796c8dc
SS
987 for (p = ld->arch_info[la->la_language].primitive_type_vector;
988 (*p) != NULL;
989 p++)
990 {
991 if (strcmp (TYPE_NAME (*p), name) == 0)
992 return (*p);
993 }
994 return (NULL);
995}
996
c50c785c 997/* Initialize the language routines. */
5796c8dc
SS
998
999void
1000_initialize_language (void)
1001{
ef5ccd6c 1002 static const char *const type_or_range_names[]
5796c8dc
SS
1003 = { "on", "off", "warn", "auto", NULL };
1004
ef5ccd6c 1005 static const char *const case_sensitive_names[]
5796c8dc
SS
1006 = { "on", "off", "auto", NULL };
1007
1008 language_gdbarch_data
1009 = gdbarch_data_register_post_init (language_gdbarch_post_init);
1010
c50c785c 1011 /* GDB commands for language specific stuff. */
5796c8dc
SS
1012
1013 add_prefix_cmd ("check", no_class, set_check,
1014 _("Set the status of the type/range checker."),
1015 &setchecklist, "set check ", 0, &setlist);
1016 add_alias_cmd ("c", "check", no_class, 1, &setlist);
1017 add_alias_cmd ("ch", "check", no_class, 1, &setlist);
1018
1019 add_prefix_cmd ("check", no_class, show_check,
1020 _("Show the status of the type/range checker."),
1021 &showchecklist, "show check ", 0, &showlist);
1022 add_alias_cmd ("c", "check", no_class, 1, &showlist);
1023 add_alias_cmd ("ch", "check", no_class, 1, &showlist);
1024
5796c8dc 1025 add_setshow_enum_cmd ("range", class_support, type_or_range_names,
c50c785c
JM
1026 &range,
1027 _("Set range checking. (on/warn/off/auto)"),
1028 _("Show range checking. (on/warn/off/auto)"),
1029 NULL, set_range_command,
5796c8dc
SS
1030 show_range_command,
1031 &setchecklist, &showchecklist);
1032
1033 add_setshow_enum_cmd ("case-sensitive", class_support, case_sensitive_names,
1034 &case_sensitive, _("\
1035Set case sensitivity in name search. (on/off/auto)"), _("\
1036Show case sensitivity in name search. (on/off/auto)"), _("\
1037For Fortran the default is off; for other languages the default is on."),
1038 set_case_command,
1039 show_case_command,
1040 &setlist, &showlist);
1041
1042 add_language (&auto_language_defn);
1043 add_language (&local_language_defn);
1044 add_language (&unknown_language_defn);
1045
1046 language = xstrdup ("auto");
1047 type = xstrdup ("auto");
1048 range = xstrdup ("auto");
1049 case_sensitive = xstrdup ("auto");
1050
c50c785c 1051 /* Have the above take effect. */
5796c8dc
SS
1052 set_language (language_auto);
1053}