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