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