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