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