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