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