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