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