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