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